aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-12-15 21:06:13 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2014-12-15 21:06:13 -0500
commitdab363f938a53ddaee60bfecc1aebdbb3d3af5f0 (patch)
treeccdb11a6e6191ba71fbc7716714c47b79172070d
parenta68db9cb858d10820add66682ad4d412f9914288 (diff)
parent17d2c6439be65777245914be354c5a97c76ad246 (diff)
Merge tag 'staging-3.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging
Pull staging driver updates from Greg KH: "Here's the big staging tree pull request for 3.19-rc1. We continued to delete more lines than were added, always a good thing, but not at a huge rate this release, only about 70k lines removed overall mostly from removing the horrid bcm driver. Lots of normal staging driver cleanups and fixes all over the place, well over a thousand of them, the shortlog shows all the horrid details. The "contentious" thing here is the movement of the Android binder code out of staging into the "real" part of the kernel. This is code that has been stable for a few years now and is working as-is in the tens of millions of devices with no issues. Yes, the code is horrid, and the userspace api leaves a lot to be desired, but it's not going to change due to legacy issues that we have no control over. Because so many devices and companies rely on this, and the code is stable, might as well promote it out of staging. This was all discussed at the Linux Plumbers conference, and everyone participating agreed that this was the best way forward. There is work happening to replace the binder code with something new that is happening right now, but I don't expect to see the results of that work for another year at the earliest. If that ever happens, and Android switches over to it, I'll gladly remove this version. As for maintainers, I'll be glad to maintain this code, I've been doing it for the past few years with no problems. I'll send a MAINTAINERS entry for it before 3.19-final is out, still need to talk to the Google developers about if they are willing to help with it or not, last I checked they were, which was good. All of these patches have been in linux-next for a while with no reported issues" * tag 'staging-3.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging: (1382 commits) Staging: slicoss: Fix long line issues in slicoss.c staging: rtl8712: remove unnecessary else after return staging: comedi: change some printk calls to pr_err staging: rtl8723au: hal: Removed the extra semicolon lustre: Deletion of unnecessary checks before three function calls staging: lustre: fix sparse warnings: static function declaration staging: lustre: fixed sparse warnings related to static declarations staging: unisys: remove duplicate header staging: unisys: remove unneeded structure staging: ft1000 : replace __attribute ((__packed__) with __packed drivers: staging: rtl8192e: Include "asm/unaligned.h" instead of "access_ok.h" in "rtl819x_BAProc.c" Drivers:staging:rtl8192e: Fixed checkpatch warning Drivers:staging:clocking-wizard: Added a newline staging: clocking-wizard: check for a valid clk_name pointer staging: rtl8723au: Hal_InitPGData() avoid unnecessary typecasts staging: rtl8723au: _DisableAnalog(): Avoid zero-init variables unnecessarily staging: rtl8723au: Remove unnecessary wrapper _ResetDigitalProcedure1() staging: rtl8723au: _ResetDigitalProcedure1_92C() reduce code obfuscation staging: rtl8723au: Remove unnecessary wrapper _DisableRFAFEAndResetBB() staging: rtl8723au: _DisableRFAFEAndResetBB8192C(): Reduce code obfuscation ...
-rw-r--r--Documentation/ABI/testing/sysfs-bus-iio23
-rw-r--r--Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt11
-rw-r--r--Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt46
-rw-r--r--Documentation/devicetree/bindings/iio/adc/rockchip-saradc.txt2
-rw-r--r--MAINTAINERS7
-rw-r--r--arch/arm/boot/dts/exynos3250.dtsi3
-rw-r--r--arch/arm/boot/dts/exynos4x12.dtsi3
-rw-r--r--arch/arm/boot/dts/exynos5250.dtsi3
-rw-r--r--arch/arm/boot/dts/exynos5420.dtsi3
-rw-r--r--drivers/Kconfig2
-rw-r--r--drivers/Makefile1
-rw-r--r--drivers/android/Kconfig37
-rw-r--r--drivers/android/Makefile3
-rw-r--r--drivers/android/binder.c (renamed from drivers/staging/android/binder.c)6
-rw-r--r--drivers/android/binder_trace.h (renamed from drivers/staging/android/binder_trace.h)0
-rw-r--r--drivers/gpu/drm/imx/Kconfig7
-rw-r--r--drivers/gpu/drm/imx/imx-drm-core.c5
-rw-r--r--drivers/gpu/drm/imx/imx-ldb.c5
-rw-r--r--drivers/gpu/drm/imx/imx-tve.c8
-rw-r--r--drivers/gpu/drm/imx/ipuv3-crtc.c5
-rw-r--r--drivers/gpu/drm/imx/ipuv3-plane.c43
-rw-r--r--drivers/gpu/drm/imx/ipuv3-plane.h2
-rw-r--r--drivers/gpu/drm/imx/parallel-display.c13
-rw-r--r--drivers/iio/accel/st_accel.h3
-rw-r--r--drivers/iio/accel/st_accel_core.c22
-rw-r--r--drivers/iio/accel/st_accel_i2c.c3
-rw-r--r--drivers/iio/accel/st_accel_spi.c3
-rw-r--r--drivers/iio/adc/Kconfig14
-rw-r--r--drivers/iio/adc/Makefile1
-rw-r--r--drivers/iio/adc/exynos_adc.c62
-rw-r--r--drivers/iio/adc/mcp320x.c222
-rw-r--r--drivers/iio/adc/qcom-spmi-iadc.c595
-rw-r--r--drivers/iio/adc/rockchip_saradc.c64
-rw-r--r--drivers/iio/adc/vf610_adc.c45
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_core.c126
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_i2c.c1
-rw-r--r--drivers/iio/common/st_sensors/st_sensors_spi.c1
-rw-r--r--drivers/iio/gyro/st_gyro.h3
-rw-r--r--drivers/iio/gyro/st_gyro_core.c19
-rw-r--r--drivers/iio/gyro/st_gyro_i2c.c4
-rw-r--r--drivers/iio/gyro/st_gyro_spi.c4
-rw-r--r--drivers/iio/humidity/Kconfig10
-rw-r--r--drivers/iio/humidity/Makefile1
-rw-r--r--drivers/iio/humidity/si7020.c161
-rw-r--r--drivers/iio/inkern.c33
-rw-r--r--drivers/iio/magnetometer/st_magn.h3
-rw-r--r--drivers/iio/magnetometer/st_magn_core.c18
-rw-r--r--drivers/iio/magnetometer/st_magn_i2c.c3
-rw-r--r--drivers/iio/magnetometer/st_magn_spi.c3
-rw-r--r--drivers/iio/pressure/Kconfig11
-rw-r--r--drivers/iio/pressure/Makefile1
-rw-r--r--drivers/iio/pressure/bmp280.c455
-rw-r--r--drivers/iio/pressure/st_pressure.h3
-rw-r--r--drivers/iio/pressure/st_pressure_buffer.c12
-rw-r--r--drivers/iio/pressure/st_pressure_core.c49
-rw-r--r--drivers/iio/pressure/st_pressure_i2c.c11
-rw-r--r--drivers/iio/pressure/st_pressure_spi.c11
-rw-r--r--drivers/iio/proximity/as3935.c16
-rw-r--r--drivers/staging/Kconfig4
-rw-r--r--drivers/staging/Makefile2
-rw-r--r--drivers/staging/android/Kconfig30
-rw-r--r--drivers/staging/android/Makefile1
-rw-r--r--drivers/staging/android/TODO7
-rw-r--r--drivers/staging/android/binder.h30
-rw-r--r--drivers/staging/android/ion/ion.c10
-rw-r--r--drivers/staging/android/ion/ion.h2
-rw-r--r--drivers/staging/android/ion/ion_dummy_driver.c6
-rw-r--r--drivers/staging/android/ion/ion_page_pool.c2
-rw-r--r--drivers/staging/android/ion/ion_priv.h4
-rw-r--r--drivers/staging/android/ion/tegra/tegra_ion.c6
-rw-r--r--drivers/staging/android/sync_debug.c5
-rw-r--r--drivers/staging/android/timed_gpio.c7
-rw-r--r--drivers/staging/bcm/Adapter.h474
-rw-r--r--drivers/staging/bcm/Bcmchar.c2652
-rw-r--r--drivers/staging/bcm/Bcmnet.c240
-rw-r--r--drivers/staging/bcm/CmHost.c2254
-rw-r--r--drivers/staging/bcm/CmHost.h62
-rw-r--r--drivers/staging/bcm/DDRInit.c1355
-rw-r--r--drivers/staging/bcm/DDRInit.h9
-rw-r--r--drivers/staging/bcm/Debug.h242
-rw-r--r--drivers/staging/bcm/HandleControlPacket.c241
-rw-r--r--drivers/staging/bcm/HostMIBSInterface.h192
-rw-r--r--drivers/staging/bcm/IPv6Protocol.c476
-rw-r--r--drivers/staging/bcm/IPv6ProtocolHdr.h85
-rw-r--r--drivers/staging/bcm/InterfaceAdapter.h79
-rw-r--r--drivers/staging/bcm/InterfaceDld.c317
-rw-r--r--drivers/staging/bcm/InterfaceIdleMode.c274
-rw-r--r--drivers/staging/bcm/InterfaceIdleMode.h15
-rw-r--r--drivers/staging/bcm/InterfaceInit.c729
-rw-r--r--drivers/staging/bcm/InterfaceInit.h26
-rw-r--r--drivers/staging/bcm/InterfaceIsr.c190
-rw-r--r--drivers/staging/bcm/InterfaceIsr.h15
-rw-r--r--drivers/staging/bcm/InterfaceMacros.h18
-rw-r--r--drivers/staging/bcm/InterfaceMisc.c247
-rw-r--r--drivers/staging/bcm/InterfaceMisc.h42
-rw-r--r--drivers/staging/bcm/InterfaceRx.c289
-rw-r--r--drivers/staging/bcm/InterfaceRx.h7
-rw-r--r--drivers/staging/bcm/InterfaceTx.c213
-rw-r--r--drivers/staging/bcm/InterfaceTx.h7
-rw-r--r--drivers/staging/bcm/Ioctl.h226
-rw-r--r--drivers/staging/bcm/Kconfig6
-rw-r--r--drivers/staging/bcm/LeakyBucket.c364
-rw-r--r--drivers/staging/bcm/Macros.h352
-rw-r--r--drivers/staging/bcm/Makefile12
-rw-r--r--drivers/staging/bcm/Misc.c1587
-rw-r--r--drivers/staging/bcm/PHSDefines.h94
-rw-r--r--drivers/staging/bcm/PHSModule.c1703
-rw-r--r--drivers/staging/bcm/PHSModule.h59
-rw-r--r--drivers/staging/bcm/Protocol.h128
-rw-r--r--drivers/staging/bcm/Prototypes.h217
-rw-r--r--drivers/staging/bcm/Qos.c1200
-rw-r--r--drivers/staging/bcm/Queue.h29
-rw-r--r--drivers/staging/bcm/TODO26
-rw-r--r--drivers/staging/bcm/Transmit.c271
-rw-r--r--drivers/staging/bcm/Typedefs.h47
-rw-r--r--drivers/staging/bcm/cntrl_SignalingInterface.h311
-rw-r--r--drivers/staging/bcm/headers.h78
-rw-r--r--drivers/staging/bcm/hostmibs.c164
-rw-r--r--drivers/staging/bcm/led_control.c952
-rw-r--r--drivers/staging/bcm/led_control.h84
-rw-r--r--drivers/staging/bcm/nvm.c4661
-rw-r--r--drivers/staging/bcm/nvm.h286
-rw-r--r--drivers/staging/bcm/sort.c52
-rw-r--r--drivers/staging/bcm/target_params.h57
-rw-r--r--drivers/staging/bcm/vendorspecificextn.c145
-rw-r--r--drivers/staging/bcm/vendorspecificextn.h18
-rw-r--r--drivers/staging/clocking-wizard/Kconfig9
-rw-r--r--drivers/staging/clocking-wizard/Makefile1
-rw-r--r--drivers/staging/clocking-wizard/TODO12
-rw-r--r--drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c341
-rw-r--r--drivers/staging/clocking-wizard/dt-binding.txt30
-rw-r--r--drivers/staging/comedi/Kconfig28
-rw-r--r--drivers/staging/comedi/Makefile7
-rw-r--r--drivers/staging/comedi/comedi.h13
-rw-r--r--drivers/staging/comedi/comedi_buf.c157
-rw-r--r--drivers/staging/comedi/comedi_compat32.c2
-rw-r--r--drivers/staging/comedi/comedi_fops.c279
-rw-r--r--drivers/staging/comedi/comedi_pci.c16
-rw-r--r--drivers/staging/comedi/comedi_pcmcia.c16
-rw-r--r--drivers/staging/comedi/comedi_usb.c16
-rw-r--r--drivers/staging/comedi/comedidev.h139
-rw-r--r--drivers/staging/comedi/drivers.c102
-rw-r--r--drivers/staging/comedi/drivers/Makefile1
-rw-r--r--drivers/staging/comedi/drivers/addi-data/addi_common.c274
-rw-r--r--drivers/staging/comedi/drivers/addi-data/addi_common.h144
-rw-r--r--drivers/staging/comedi/drivers/addi-data/addi_eeprom.c360
-rw-r--r--drivers/staging/comedi/drivers/addi-data/hwdrv_apci035.c480
-rw-r--r--drivers/staging/comedi/drivers/addi-data/hwdrv_apci1500.c28
-rw-r--r--drivers/staging/comedi/drivers/addi-data/hwdrv_apci1564.c381
-rw-r--r--drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c2050
-rw-r--r--drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c3003
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_035.c77
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_1032.c5
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_1500.c117
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_1516.c2
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_1564.c268
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_16xx.c2
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_2032.c32
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_2200.c2
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_3120.c1153
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_3200.c125
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_3501.c7
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_3xxx.c11
-rw-r--r--drivers/staging/comedi/drivers/addi_tcw.h56
-rw-r--r--drivers/staging/comedi/drivers/addi_watchdog.c32
-rw-r--r--drivers/staging/comedi/drivers/adl_pci6208.c1
-rw-r--r--drivers/staging/comedi/drivers/adl_pci9111.c40
-rw-r--r--drivers/staging/comedi/drivers/adl_pci9118.c202
-rw-r--r--drivers/staging/comedi/drivers/adv_pci1710.c76
-rw-r--r--drivers/staging/comedi/drivers/adv_pci1723.c338
-rw-r--r--drivers/staging/comedi/drivers/adv_pci1724.c471
-rw-r--r--drivers/staging/comedi/drivers/adv_pci_dio.c8
-rw-r--r--drivers/staging/comedi/drivers/aio_aio12_8.c1
-rw-r--r--drivers/staging/comedi/drivers/amcc_s5933.h2
-rw-r--r--drivers/staging/comedi/drivers/amplc_dio200_common.c34
-rw-r--r--drivers/staging/comedi/drivers/amplc_pc236_common.c5
-rw-r--r--drivers/staging/comedi/drivers/amplc_pc263.c2
-rw-r--r--drivers/staging/comedi/drivers/amplc_pci224.c53
-rw-r--r--drivers/staging/comedi/drivers/amplc_pci230.c193
-rw-r--r--drivers/staging/comedi/drivers/amplc_pci263.c2
-rw-r--r--drivers/staging/comedi/drivers/c6xdigio.c2
-rw-r--r--drivers/staging/comedi/drivers/cb_das16_cs.c1
-rw-r--r--drivers/staging/comedi/drivers/cb_pcidas.c283
-rw-r--r--drivers/staging/comedi/drivers/cb_pcidas64.c295
-rw-r--r--drivers/staging/comedi/drivers/cb_pcimdas.c83
-rw-r--r--drivers/staging/comedi/drivers/comedi_bond.c9
-rw-r--r--drivers/staging/comedi/drivers/comedi_fc.h43
-rw-r--r--drivers/staging/comedi/drivers/comedi_parport.c5
-rw-r--r--drivers/staging/comedi/drivers/comedi_test.c63
-rw-r--r--drivers/staging/comedi/drivers/dac02.c1
-rw-r--r--drivers/staging/comedi/drivers/daqboard2000.c1
-rw-r--r--drivers/staging/comedi/drivers/das08.c3
-rw-r--r--drivers/staging/comedi/drivers/das16.c23
-rw-r--r--drivers/staging/comedi/drivers/das16m1.c7
-rw-r--r--drivers/staging/comedi/drivers/das1800.c62
-rw-r--r--drivers/staging/comedi/drivers/das6402.c202
-rw-r--r--drivers/staging/comedi/drivers/das800.c38
-rw-r--r--drivers/staging/comedi/drivers/dmm32at.c702
-rw-r--r--drivers/staging/comedi/drivers/dt2801.c1
-rw-r--r--drivers/staging/comedi/drivers/dt2811.c1
-rw-r--r--drivers/staging/comedi/drivers/dt2814.c2
-rw-r--r--drivers/staging/comedi/drivers/dt282x.c62
-rw-r--r--drivers/staging/comedi/drivers/dt3000.c9
-rw-r--r--drivers/staging/comedi/drivers/dt9812.c4
-rw-r--r--drivers/staging/comedi/drivers/dyna_pci10xx.c4
-rw-r--r--drivers/staging/comedi/drivers/fl512.c1
-rw-r--r--drivers/staging/comedi/drivers/gsc_hpdi.c8
-rw-r--r--drivers/staging/comedi/drivers/icp_multi.c9
-rw-r--r--drivers/staging/comedi/drivers/ii_pci20kc.c1
-rw-r--r--drivers/staging/comedi/drivers/me4000.c120
-rw-r--r--drivers/staging/comedi/drivers/me_daq.c5
-rw-r--r--drivers/staging/comedi/drivers/mf6x4.c1
-rw-r--r--drivers/staging/comedi/drivers/mite.c9
-rw-r--r--drivers/staging/comedi/drivers/multiq3.c1
-rw-r--r--drivers/staging/comedi/drivers/ni_6527.c8
-rw-r--r--drivers/staging/comedi/drivers/ni_65xx.c9
-rw-r--r--drivers/staging/comedi/drivers/ni_660x.c2
-rw-r--r--drivers/staging/comedi/drivers/ni_670x.c1
-rw-r--r--drivers/staging/comedi/drivers/ni_at_a2150.c21
-rw-r--r--drivers/staging/comedi/drivers/ni_at_ao.c56
-rw-r--r--drivers/staging/comedi/drivers/ni_atmio16d.c8
-rw-r--r--drivers/staging/comedi/drivers/ni_labpc.h6
-rw-r--r--drivers/staging/comedi/drivers/ni_labpc_common.c152
-rw-r--r--drivers/staging/comedi/drivers/ni_labpc_isadma.c7
-rw-r--r--drivers/staging/comedi/drivers/ni_mio_common.c166
-rw-r--r--drivers/staging/comedi/drivers/ni_pcidio.c14
-rw-r--r--drivers/staging/comedi/drivers/ni_stc.h16
-rw-r--r--drivers/staging/comedi/drivers/ni_tiocmd.c6
-rw-r--r--drivers/staging/comedi/drivers/ni_usb6501.c2
-rw-r--r--drivers/staging/comedi/drivers/pcl711.c25
-rw-r--r--drivers/staging/comedi/drivers/pcl726.c6
-rw-r--r--drivers/staging/comedi/drivers/pcl812.c40
-rw-r--r--drivers/staging/comedi/drivers/pcl816.c26
-rw-r--r--drivers/staging/comedi/drivers/pcl818.c34
-rw-r--r--drivers/staging/comedi/drivers/pcmmio.c32
-rw-r--r--drivers/staging/comedi/drivers/pcmuio.c34
-rw-r--r--drivers/staging/comedi/drivers/quatech_daqp_cs.c38
-rw-r--r--drivers/staging/comedi/drivers/rtd520.c77
-rw-r--r--drivers/staging/comedi/drivers/rti800.c1
-rw-r--r--drivers/staging/comedi/drivers/rti802.c1
-rw-r--r--drivers/staging/comedi/drivers/s526.c1
-rw-r--r--drivers/staging/comedi/drivers/s626.c38
-rw-r--r--drivers/staging/comedi/drivers/serial2002.c4
-rw-r--r--drivers/staging/comedi/drivers/usbdux.c400
-rw-r--r--drivers/staging/comedi/drivers/usbduxfast.c145
-rw-r--r--drivers/staging/comedi/drivers/usbduxsigma.c350
-rw-r--r--drivers/staging/comedi/drivers/vmk80xx.c8
-rw-r--r--drivers/staging/comedi/range.c36
-rw-r--r--drivers/staging/cptm1217/clearpad_tm1217.c2
-rw-r--r--drivers/staging/dgap/dgap.c7462
-rw-r--r--drivers/staging/dgap/dgap.h3
-rw-r--r--drivers/staging/dgnc/dgnc_cls.c30
-rw-r--r--drivers/staging/dgnc/dgnc_driver.c33
-rw-r--r--drivers/staging/dgnc/dgnc_driver.h61
-rw-r--r--drivers/staging/dgnc/dgnc_kcompat.h18
-rw-r--r--drivers/staging/dgnc/dgnc_neo.c30
-rw-r--r--drivers/staging/dgnc/dgnc_sysfs.c37
-rw-r--r--drivers/staging/dgnc/dgnc_tty.c146
-rw-r--r--drivers/staging/dgnc/dgnc_tty.h2
-rw-r--r--drivers/staging/emxx_udc/emxx_udc.c7
-rw-r--r--drivers/staging/ft1000/ft1000-pcmcia/boot.h34
-rw-r--r--drivers/staging/ft1000/ft1000-pcmcia/ft1000.h30
-rw-r--r--drivers/staging/ft1000/ft1000-pcmcia/ft1000_cs.c50
-rw-r--r--drivers/staging/ft1000/ft1000-pcmcia/ft1000_dnld.c212
-rw-r--r--drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c935
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_debug.c1204
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_download.c400
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_hw.c436
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_ioctl.h60
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_usb.c97
-rw-r--r--drivers/staging/ft1000/ft1000-usb/ft1000_usb.h4
-rw-r--r--drivers/staging/fwserial/fwserial.c3
-rw-r--r--drivers/staging/gdm724x/gdm_lte.c10
-rw-r--r--drivers/staging/gdm724x/gdm_mux.h8
-rw-r--r--drivers/staging/gdm72xx/gdm_wimax.c6
-rw-r--r--drivers/staging/gs_fpgaboot/gs_fpgaboot.c57
-rw-r--r--drivers/staging/iio/Documentation/generic_buffer.c81
-rw-r--r--drivers/staging/iio/Documentation/iio_event_monitor.c32
-rw-r--r--drivers/staging/iio/Documentation/iio_utils.h7
-rw-r--r--drivers/staging/iio/Documentation/lsiio.c20
-rw-r--r--drivers/staging/iio/accel/Kconfig39
-rw-r--r--drivers/staging/iio/accel/lis3l02dq_ring.c1
-rw-r--r--drivers/staging/iio/adc/ad7192.c3
-rw-r--r--drivers/staging/iio/adc/ad7280a.c2
-rw-r--r--drivers/staging/iio/adc/ad7606_spi.c2
-rw-r--r--drivers/staging/iio/adc/ad7816.c3
-rw-r--r--drivers/staging/iio/adc/lpc32xx_adc.c2
-rw-r--r--drivers/staging/iio/adc/mxs-lradc.c6
-rw-r--r--drivers/staging/iio/adc/spear_adc.c4
-rw-r--r--drivers/staging/iio/addac/Kconfig9
-rw-r--r--drivers/staging/iio/addac/adt7316.h3
-rw-r--r--drivers/staging/iio/gyro/Kconfig5
-rw-r--r--drivers/staging/iio/light/tsl2x7x_core.c17
-rw-r--r--drivers/staging/iio/meter/Kconfig15
-rw-r--r--drivers/staging/iio/trigger/Kconfig5
-rw-r--r--drivers/staging/iio/trigger/iio-trig-periodic-rtc.c3
-rw-r--r--drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h12
-rw-r--r--drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c17
-rw-r--r--drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c34
-rw-r--r--drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c3
-rw-r--r--drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c60
-rw-r--r--drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c89
-rw-r--r--drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c15
-rw-r--r--drivers/staging/lustre/lnet/lnet/api-ni.c18
-rw-r--r--drivers/staging/lustre/lnet/lnet/lib-md.c2
-rw-r--r--drivers/staging/lustre/lnet/lnet/lib-move.c98
-rw-r--r--drivers/staging/lustre/lnet/lnet/lib-ptl.c3
-rw-r--r--drivers/staging/lustre/lnet/lnet/lo.c8
-rw-r--r--drivers/staging/lustre/lnet/lnet/module.c10
-rw-r--r--drivers/staging/lustre/lnet/lnet/router.c52
-rw-r--r--drivers/staging/lustre/lnet/lnet/router_proc.c25
-rw-r--r--drivers/staging/lustre/lnet/selftest/brw_test.c8
-rw-r--r--drivers/staging/lustre/lnet/selftest/conctl.c34
-rw-r--r--drivers/staging/lustre/lnet/selftest/conrpc.c20
-rw-r--r--drivers/staging/lustre/lnet/selftest/console.c6
-rw-r--r--drivers/staging/lustre/lnet/selftest/framework.c75
-rw-r--r--drivers/staging/lustre/lnet/selftest/module.c19
-rw-r--r--drivers/staging/lustre/lnet/selftest/ping_test.c2
-rw-r--r--drivers/staging/lustre/lnet/selftest/rpc.c63
-rw-r--r--drivers/staging/lustre/lnet/selftest/timer.c8
-rw-r--r--drivers/staging/lustre/lustre/Kconfig2
-rw-r--r--drivers/staging/lustre/lustre/include/dt_object.h4
-rw-r--r--drivers/staging/lustre/lustre/include/linux/lustre_compat25.h8
-rw-r--r--drivers/staging/lustre/lustre/include/linux/obd.h3
-rw-r--r--drivers/staging/lustre/lustre/include/lprocfs_status.h8
-rw-r--r--drivers/staging/lustre/lustre/include/lu_object.h4
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_capa.h2
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_disk.h3
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_dlm.h2
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_eacl.h2
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_lib.h2
-rw-r--r--drivers/staging/lustre/lustre/include/lustre_net.h7
-rw-r--r--drivers/staging/lustre/lustre/include/obd_class.h2
-rw-r--r--drivers/staging/lustre/lustre/ldlm/interval_tree.c5
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_extent.c4
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_flock.c10
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_internal.h8
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_lib.c7
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_lock.c219
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c28
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_pool.c63
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_request.c78
-rw-r--r--drivers/staging/lustre/lustre/ldlm/ldlm_resource.c45
-rw-r--r--drivers/staging/lustre/lustre/libcfs/debug.c18
-rw-r--r--drivers/staging/lustre/lustre/libcfs/fail.c24
-rw-r--r--drivers/staging/lustre/lustre/libcfs/hash.c28
-rw-r--r--drivers/staging/lustre/lustre/libcfs/libcfs_cpu.c2
-rw-r--r--drivers/staging/lustre/lustre/libcfs/linux/linux-cpu.c32
-rw-r--r--drivers/staging/lustre/lustre/libcfs/linux/linux-debug.c6
-rw-r--r--drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c2
-rw-r--r--drivers/staging/lustre/lustre/libcfs/linux/linux-tcpip.c3
-rw-r--r--drivers/staging/lustre/lustre/libcfs/tracefile.c38
-rw-r--r--drivers/staging/lustre/lustre/llite/dcache.c4
-rw-r--r--drivers/staging/lustre/lustre/llite/dir.c96
-rw-r--r--drivers/staging/lustre/lustre/llite/file.c22
-rw-r--r--drivers/staging/lustre/lustre/llite/llite_capa.c3
-rw-r--r--drivers/staging/lustre/lustre/llite/llite_close.c16
-rw-r--r--drivers/staging/lustre/lustre/llite/llite_internal.h30
-rw-r--r--drivers/staging/lustre/lustre/llite/llite_lib.c116
-rw-r--r--drivers/staging/lustre/lustre/llite/llite_mmap.c9
-rw-r--r--drivers/staging/lustre/lustre/llite/llite_rmtacl.c7
-rw-r--r--drivers/staging/lustre/lustre/llite/lloop.c8
-rw-r--r--drivers/staging/lustre/lustre/llite/lproc_llite.c89
-rw-r--r--drivers/staging/lustre/lustre/llite/namei.c10
-rw-r--r--drivers/staging/lustre/lustre/llite/remote_perm.c5
-rw-r--r--drivers/staging/lustre/lustre/llite/rw.c22
-rw-r--r--drivers/staging/lustre/lustre/llite/rw26.c6
-rw-r--r--drivers/staging/lustre/lustre/llite/statahead.c16
-rw-r--r--drivers/staging/lustre/lustre/llite/super25.c2
-rw-r--r--drivers/staging/lustre/lustre/llite/symlink.c4
-rw-r--r--drivers/staging/lustre/lustre/llite/vvp_io.c7
-rw-r--r--drivers/staging/lustre/lustre/llite/vvp_page.c3
-rw-r--r--drivers/staging/lustre/lustre/llite/xattr.c6
-rw-r--r--drivers/staging/lustre/lustre/llite/xattr_cache.c5
-rw-r--r--drivers/staging/lustre/lustre/lmv/lmv_fld.c3
-rw-r--r--drivers/staging/lustre/lustre/lmv/lmv_intent.c8
-rw-r--r--drivers/staging/lustre/lustre/lmv/lmv_internal.h4
-rw-r--r--drivers/staging/lustre/lustre/lmv/lmv_obd.c41
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_ea.c5
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_obd.c35
-rw-r--r--drivers/staging/lustre/lustre/lov/lov_pack.c3
-rw-r--r--drivers/staging/lustre/lustre/mdc/mdc_lib.c4
-rw-r--r--drivers/staging/lustre/lustre/mdc/mdc_locks.c4
-rw-r--r--drivers/staging/lustre/lustre/mdc/mdc_request.c12
-rw-r--r--drivers/staging/lustre/lustre/mgc/mgc_request.c14
-rw-r--r--drivers/staging/lustre/lustre/obdclass/acl.c8
-rw-r--r--drivers/staging/lustre/lustre/obdclass/capa.c14
-rw-r--r--drivers/staging/lustre/lustre/obdclass/cl_io.c3
-rw-r--r--drivers/staging/lustre/lustre/obdclass/cl_lock.c3
-rw-r--r--drivers/staging/lustre/lustre/obdclass/class_obd.c6
-rw-r--r--drivers/staging/lustre/lustre/obdclass/debug.c12
-rw-r--r--drivers/staging/lustre/lustre/obdclass/dt_object.c15
-rw-r--r--drivers/staging/lustre/lustre/obdclass/genops.c28
-rw-r--r--drivers/staging/lustre/lustre/obdclass/linux/linux-module.c4
-rw-r--r--drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c5
-rw-r--r--drivers/staging/lustre/lustre/obdclass/llog.c4
-rw-r--r--drivers/staging/lustre/lustre/obdclass/llog_cat.c10
-rw-r--r--drivers/staging/lustre/lustre/obdclass/llog_obd.c2
-rw-r--r--drivers/staging/lustre/lustre/obdclass/llog_swab.c3
-rw-r--r--drivers/staging/lustre/lustre/obdclass/lprocfs_status.c14
-rw-r--r--drivers/staging/lustre/lustre/obdclass/lu_object.c3
-rw-r--r--drivers/staging/lustre/lustre/obdclass/obd_config.c11
-rw-r--r--drivers/staging/lustre/lustre/obdclass/obd_mount.c38
-rw-r--r--drivers/staging/lustre/lustre/obdecho/echo_client.c140
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_cache.c176
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_cl_internal.h2
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_lock.c6
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_object.c3
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_page.c11
-rw-r--r--drivers/staging/lustre/lustre/osc/osc_request.c51
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/client.c48
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/events.c7
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/import.c115
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/layout.c37
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/llog_client.c3
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c18
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/niobuf.c7
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/nrs.c33
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/pack_generic.c59
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/pinger.c22
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c7
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/recover.c7
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/sec.c27
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c3
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/sec_null.c18
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/sec_plain.c4
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/service.c90
-rw-r--r--drivers/staging/media/cxd2099/cxd2099.c2
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_ipipe.h4
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_ipipe_hw.c62
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_ipipe_hw.h58
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_ipipeif.c4
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_ipipeif.h2
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_isif.c11
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_isif.h6
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_resizer.c8
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_resizer.h2
-rw-r--r--drivers/staging/media/lirc/lirc_bt829.c14
-rw-r--r--drivers/staging/media/lirc/lirc_imon.c27
-rw-r--r--drivers/staging/media/lirc/lirc_sasem.c4
-rw-r--r--drivers/staging/media/lirc/lirc_sir.c18
-rw-r--r--drivers/staging/media/lirc/lirc_zilog.c137
-rw-r--r--drivers/staging/media/omap4iss/iss.c4
-rw-r--r--drivers/staging/media/omap4iss/iss_csi2.c2
-rw-r--r--drivers/staging/octeon-usb/octeon-hcd.c69
-rw-r--r--drivers/staging/octeon/ethernet-rx.c156
-rw-r--r--drivers/staging/octeon/ethernet-tx.c11
-rw-r--r--drivers/staging/octeon/ethernet.c8
-rw-r--r--drivers/staging/octeon/octeon-ethernet.h1
-rw-r--r--drivers/staging/olpc_dcon/olpc_dcon.c3
-rw-r--r--drivers/staging/ozwpan/ozhcd.c22
-rw-r--r--drivers/staging/ozwpan/ozusbsvc1.c12
-rw-r--r--drivers/staging/panel/TODO1
-rw-r--r--drivers/staging/panel/panel.c807
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_ap.c17
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_cmd.c9
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_debug.c14
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_efuse.c47
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_ieee80211.c16
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_ioctl_set.c1
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_led.c12
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_mlme.c10
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_mlme_ext.c34
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_pwrctrl.c7
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_recv.c20
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_security.c24
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_sta_mgt.c2
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_wlan_util.c1
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_xmit.c14
-rw-r--r--drivers/staging/rtl8188eu/hal/bb_cfg.c4
-rw-r--r--drivers/staging/rtl8188eu/hal/fw.c8
-rw-r--r--drivers/staging/rtl8188eu/hal/hal_intf.c16
-rw-r--r--drivers/staging/rtl8188eu/hal/mac_cfg.c2
-rw-r--r--drivers/staging/rtl8188eu/hal/odm.c8
-rw-r--r--drivers/staging/rtl8188eu/hal/odm_HWConfig.c2
-rw-r--r--drivers/staging/rtl8188eu/hal/odm_RTL8188E.c2
-rw-r--r--drivers/staging/rtl8188eu/hal/phy.c2
-rw-r--r--drivers/staging/rtl8188eu/hal/rf.c2
-rw-r--r--drivers/staging/rtl8188eu/hal/rf_cfg.c4
-rw-r--r--drivers/staging/rtl8188eu/hal/rtl8188e_cmd.c6
-rw-r--r--drivers/staging/rtl8188eu/hal/rtl8188e_dm.c30
-rw-r--r--drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c3
-rw-r--r--drivers/staging/rtl8188eu/hal/rtl8188e_xmit.c2
-rw-r--r--drivers/staging/rtl8188eu/hal/rtl8188eu_xmit.c2
-rw-r--r--drivers/staging/rtl8188eu/hal/usb_halinit.c4
-rw-r--r--drivers/staging/rtl8188eu/include/hal_intf.h3
-rw-r--r--drivers/staging/rtl8188eu/include/ieee80211_ext.h20
-rw-r--r--drivers/staging/rtl8188eu/include/odm_debug.h31
-rw-r--r--drivers/staging/rtl8188eu/include/osdep_service.h4
-rw-r--r--drivers/staging/rtl8188eu/include/rtw_debug.h2
-rw-r--r--drivers/staging/rtl8188eu/include/rtw_led.h8
-rw-r--r--drivers/staging/rtl8188eu/include/rtw_mlme_ext.h26
-rw-r--r--drivers/staging/rtl8188eu/include/wifi.h36
-rw-r--r--drivers/staging/rtl8188eu/os_dep/ioctl_linux.c31
-rw-r--r--drivers/staging/rtl8188eu/os_dep/os_intfs.c11
-rw-r--r--drivers/staging/rtl8188eu/os_dep/osdep_service.c2
-rw-r--r--drivers/staging/rtl8188eu/os_dep/rtw_android.c41
-rw-r--r--drivers/staging/rtl8188eu/os_dep/usb_intf.c35
-rw-r--r--drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c8
-rw-r--r--drivers/staging/rtl8188eu/os_dep/xmit_linux.c10
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c4
-rw-r--r--drivers/staging/rtl8192e/rtl8192e/rtl_dm.c8
-rw-r--r--drivers/staging/rtl8192e/rtl819x_BAProc.c24
-rw-r--r--drivers/staging/rtl8192e/rtllib.h6
-rw-r--r--drivers/staging/rtl8192e/rtllib_rx.c6
-rw-r--r--drivers/staging/rtl8192e/rtllib_softmac.c12
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c22
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c26
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c2
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c3
-rw-r--r--drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c2
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c20
-rw-r--r--drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c11
-rw-r--r--drivers/staging/rtl8192u/r8192U_core.c22
-rw-r--r--drivers/staging/rtl8192u/r8192U_dm.c91
-rw-r--r--drivers/staging/rtl8192u/r8192U_wx.c6
-rw-r--r--drivers/staging/rtl8192u/r819xU_firmware.c20
-rw-r--r--drivers/staging/rtl8192u/r819xU_firmware.h8
-rw-r--r--drivers/staging/rtl8192u/r819xU_phy.c1
-rw-r--r--drivers/staging/rtl8712/hal_init.c11
-rw-r--r--drivers/staging/rtl8712/ieee80211.c17
-rw-r--r--drivers/staging/rtl8712/osdep_service.h8
-rw-r--r--drivers/staging/rtl8712/recv_linux.c2
-rw-r--r--drivers/staging/rtl8712/rtl8712_cmd.c13
-rw-r--r--drivers/staging/rtl8712/rtl8712_efuse.c43
-rw-r--r--drivers/staging/rtl8712/rtl8712_recv.c24
-rw-r--r--drivers/staging/rtl8712/rtl871x_cmd.c58
-rw-r--r--drivers/staging/rtl8712/rtl871x_io.c6
-rw-r--r--drivers/staging/rtl8712/rtl871x_ioctl_linux.c23
-rw-r--r--drivers/staging/rtl8712/rtl871x_ioctl_set.c24
-rw-r--r--drivers/staging/rtl8712/rtl871x_mlme.c27
-rw-r--r--drivers/staging/rtl8712/rtl871x_mp.c4
-rw-r--r--drivers/staging/rtl8712/rtl871x_mp_ioctl.c3
-rw-r--r--drivers/staging/rtl8712/rtl871x_pwrctrl.c4
-rw-r--r--drivers/staging/rtl8712/rtl871x_recv.c19
-rw-r--r--drivers/staging/rtl8712/rtl871x_recv.h3
-rw-r--r--drivers/staging/rtl8712/rtl871x_security.c10
-rw-r--r--drivers/staging/rtl8712/rtl871x_sta_mgt.c11
-rw-r--r--drivers/staging/rtl8712/rtl871x_xmit.c15
-rw-r--r--drivers/staging/rtl8712/usb_intf.c16
-rw-r--r--drivers/staging/rtl8712/usb_ops_linux.c9
-rw-r--r--drivers/staging/rtl8712/xmit_linux.c4
-rw-r--r--drivers/staging/rtl8723au/Makefile3
-rw-r--r--drivers/staging/rtl8723au/core/rtw_ap.c159
-rw-r--r--drivers/staging/rtl8723au/core/rtw_cmd.c181
-rw-r--r--drivers/staging/rtl8723au/core/rtw_efuse.c23
-rw-r--r--drivers/staging/rtl8723au/core/rtw_ieee80211.c4
-rw-r--r--drivers/staging/rtl8723au/core/rtw_led.c1893
-rw-r--r--drivers/staging/rtl8723au/core/rtw_mlme.c76
-rw-r--r--drivers/staging/rtl8723au/core/rtw_mlme_ext.c67
-rw-r--r--drivers/staging/rtl8723au/core/rtw_pwrctrl.c8
-rw-r--r--drivers/staging/rtl8723au/core/rtw_recv.c165
-rw-r--r--drivers/staging/rtl8723au/core/rtw_security.c98
-rw-r--r--drivers/staging/rtl8723au/core/rtw_sreset.c2
-rw-r--r--drivers/staging/rtl8723au/core/rtw_wlan_util.c15
-rw-r--r--drivers/staging/rtl8723au/core/rtw_xmit.c94
-rw-r--r--drivers/staging/rtl8723au/hal/HalDMOutSrc8723A_CE.c2
-rw-r--r--drivers/staging/rtl8723au/hal/hal_com.c4
-rw-r--r--drivers/staging/rtl8723au/hal/odm_HWConfig.c13
-rw-r--r--drivers/staging/rtl8723au/hal/rtl8723a_bt-coexist.c44
-rw-r--r--drivers/staging/rtl8723au/hal/rtl8723a_cmd.c7
-rw-r--r--drivers/staging/rtl8723au/hal/rtl8723a_hal_init.c493
-rw-r--r--drivers/staging/rtl8723au/hal/rtl8723a_phycfg.c3
-rw-r--r--drivers/staging/rtl8723au/hal/rtl8723a_rf6052.c229
-rw-r--r--drivers/staging/rtl8723au/hal/rtl8723a_xmit.c31
-rw-r--r--drivers/staging/rtl8723au/hal/rtl8723au_led.c124
-rw-r--r--drivers/staging/rtl8723au/hal/rtl8723au_xmit.c33
-rw-r--r--drivers/staging/rtl8723au/hal/usb_halinit.c479
-rw-r--r--drivers/staging/rtl8723au/hal/usb_ops_linux.c21
-rw-r--r--drivers/staging/rtl8723au/include/Hal8723UHWImg_CE.h2
-rw-r--r--drivers/staging/rtl8723au/include/drv_types.h2
-rw-r--r--drivers/staging/rtl8723au/include/odm_debug.h30
-rw-r--r--drivers/staging/rtl8723au/include/rtl8723a_dm.h3
-rw-r--r--drivers/staging/rtl8723au/include/rtl8723a_hal.h11
-rw-r--r--drivers/staging/rtl8723au/include/rtl8723a_led.h30
-rw-r--r--drivers/staging/rtl8723au/include/rtl8723a_recv.h6
-rw-r--r--drivers/staging/rtl8723au/include/rtl8723a_xmit.h1
-rw-r--r--drivers/staging/rtl8723au/include/rtw_cmd.h4
-rw-r--r--drivers/staging/rtl8723au/include/rtw_ht.h3
-rw-r--r--drivers/staging/rtl8723au/include/rtw_led.h181
-rw-r--r--drivers/staging/rtl8723au/include/rtw_mlme.h2
-rw-r--r--drivers/staging/rtl8723au/include/rtw_mlme_ext.h6
-rw-r--r--drivers/staging/rtl8723au/include/rtw_recv.h3
-rw-r--r--drivers/staging/rtl8723au/include/rtw_xmit.h18
-rw-r--r--drivers/staging/rtl8723au/include/usb_ops.h2
-rw-r--r--drivers/staging/rtl8723au/include/usb_ops_linux.h4
-rw-r--r--drivers/staging/rtl8723au/include/wlan_bssdef.h21
-rw-r--r--drivers/staging/rtl8723au/os_dep/ioctl_cfg80211.c20
-rw-r--r--drivers/staging/rtl8723au/os_dep/os_intfs.c19
-rw-r--r--drivers/staging/rtl8723au/os_dep/usb_intf.c37
-rw-r--r--drivers/staging/rtl8723au/os_dep/usb_ops_linux.c23
-rw-r--r--drivers/staging/rts5208/ms.c4
-rw-r--r--drivers/staging/rts5208/rtsx.c4
-rw-r--r--drivers/staging/rts5208/rtsx_chip.c459
-rw-r--r--drivers/staging/rts5208/rtsx_scsi.c3
-rw-r--r--drivers/staging/rts5208/rtsx_transport.c8
-rw-r--r--drivers/staging/rts5208/rtsx_transport.h2
-rw-r--r--drivers/staging/skein/Kconfig24
-rw-r--r--drivers/staging/skein/Makefile13
-rw-r--r--drivers/staging/skein/skein_api.c2
-rw-r--r--drivers/staging/skein/skein_api.h2
-rw-r--r--drivers/staging/skein/skein_base.c (renamed from drivers/staging/skein/skein.c)23
-rw-r--r--drivers/staging/skein/skein_base.h (renamed from drivers/staging/skein/skein.h)39
-rw-r--r--drivers/staging/skein/skein_block.c932
-rw-r--r--drivers/staging/skein/skein_block.h2
-rw-r--r--drivers/staging/skein/skein_generic.c216
-rw-r--r--drivers/staging/skein/skein_iv.h2
-rw-r--r--drivers/staging/skein/threefish_api.h2
-rw-r--r--drivers/staging/slicoss/slicoss.c46
-rw-r--r--drivers/staging/speakup/kobjects.c6
-rw-r--r--drivers/staging/speakup/main.c2
-rw-r--r--drivers/staging/speakup/speakup_dtlk.c2
-rw-r--r--drivers/staging/speakup/speakup_keypc.c2
-rw-r--r--drivers/staging/unisys/channels/channel.c114
-rw-r--r--drivers/staging/unisys/channels/chanstub.c8
-rw-r--r--drivers/staging/unisys/channels/chanstub.h8
-rw-r--r--drivers/staging/unisys/common-spar/include/channels/channel.h505
-rw-r--r--drivers/staging/unisys/common-spar/include/channels/channel_guid.h27
-rw-r--r--drivers/staging/unisys/common-spar/include/channels/controlframework.h47
-rw-r--r--drivers/staging/unisys/common-spar/include/channels/controlvmchannel.h623
-rw-r--r--drivers/staging/unisys/common-spar/include/channels/diagchannel.h168
-rw-r--r--drivers/staging/unisys/common-spar/include/channels/iochannel.h292
-rw-r--r--drivers/staging/unisys/common-spar/include/channels/vbuschannel.h80
-rw-r--r--drivers/staging/unisys/common-spar/include/vbusdeviceinfo.h37
-rw-r--r--drivers/staging/unisys/common-spar/include/vmcallinterface.h47
-rw-r--r--drivers/staging/unisys/include/timskmod.h17
-rw-r--r--drivers/staging/unisys/include/uisqueue.h75
-rw-r--r--drivers/staging/unisys/include/uisutils.h162
-rw-r--r--drivers/staging/unisys/include/vbushelper.h16
-rw-r--r--drivers/staging/unisys/uislib/uislib.c521
-rw-r--r--drivers/staging/unisys/uislib/uisqueue.c8
-rw-r--r--drivers/staging/unisys/uislib/uisutils.c109
-rw-r--r--drivers/staging/unisys/virthba/virthba.c104
-rw-r--r--drivers/staging/unisys/virthba/virthba.h4
-rw-r--r--drivers/staging/unisys/virtpci/virtpci.c332
-rw-r--r--drivers/staging/unisys/virtpci/virtpci.h20
-rw-r--r--drivers/staging/unisys/visorchannel/globals.h1
-rw-r--r--drivers/staging/unisys/visorchannel/visorchannel.h2
-rw-r--r--drivers/staging/unisys/visorchannel/visorchannel_funcs.c301
-rw-r--r--drivers/staging/unisys/visorchipset/file.c6
-rw-r--r--drivers/staging/unisys/visorchipset/parser.c52
-rw-r--r--drivers/staging/unisys/visorchipset/testing.h5
-rw-r--r--drivers/staging/unisys/visorchipset/visorchipset.h275
-rw-r--r--drivers/staging/unisys/visorchipset/visorchipset_main.c702
-rw-r--r--drivers/staging/unisys/visorutil/charqueue.c40
-rw-r--r--drivers/staging/unisys/visorutil/charqueue.h17
-rw-r--r--drivers/staging/unisys/visorutil/easyproc.c6
-rw-r--r--drivers/staging/unisys/visorutil/memregion.h28
-rw-r--r--drivers/staging/unisys/visorutil/memregion_direct.c64
-rw-r--r--drivers/staging/unisys/visorutil/periodic_work.c19
-rw-r--r--drivers/staging/unisys/visorutil/procobjecttree.c15
-rw-r--r--drivers/staging/unisys/visorutil/visorkmodutils.c26
-rw-r--r--drivers/staging/vme/devices/Kconfig3
-rw-r--r--drivers/staging/vme/devices/vme_pio2_gpio.c4
-rw-r--r--drivers/staging/vt6655/80211hdr.h318
-rw-r--r--drivers/staging/vt6655/80211mgr.c1019
-rw-r--r--drivers/staging/vt6655/80211mgr.h725
-rw-r--r--drivers/staging/vt6655/IEEE11h.c141
-rw-r--r--drivers/staging/vt6655/IEEE11h.h42
-rw-r--r--drivers/staging/vt6655/Kconfig4
-rw-r--r--drivers/staging/vt6655/Makefile23
-rw-r--r--drivers/staging/vt6655/aes_ccmp.c374
-rw-r--r--drivers/staging/vt6655/aes_ccmp.h37
-rw-r--r--drivers/staging/vt6655/baseband.c777
-rw-r--r--drivers/staging/vt6655/baseband.h39
-rw-r--r--drivers/staging/vt6655/bssdb.c1512
-rw-r--r--drivers/staging/vt6655/bssdb.h326
-rw-r--r--drivers/staging/vt6655/card.c1259
-rw-r--r--drivers/staging/vt6655/card.h120
-rw-r--r--drivers/staging/vt6655/channel.c844
-rw-r--r--drivers/staging/vt6655/channel.h22
-rw-r--r--drivers/staging/vt6655/country.h161
-rw-r--r--drivers/staging/vt6655/datarate.c410
-rw-r--r--drivers/staging/vt6655/datarate.h78
-rw-r--r--drivers/staging/vt6655/desc.h134
-rw-r--r--drivers/staging/vt6655/device.h476
-rw-r--r--drivers/staging/vt6655/device_cfg.h2
-rw-r--r--drivers/staging/vt6655/device_main.c2533
-rw-r--r--drivers/staging/vt6655/dpc.c1312
-rw-r--r--drivers/staging/vt6655/dpc.h10
-rw-r--r--drivers/staging/vt6655/hostap.c765
-rw-r--r--drivers/staging/vt6655/hostap.h58
-rw-r--r--drivers/staging/vt6655/iocmd.h408
-rw-r--r--drivers/staging/vt6655/ioctl.c658
-rw-r--r--drivers/staging/vt6655/ioctl.h36
-rw-r--r--drivers/staging/vt6655/iowpa.h130
-rw-r--r--drivers/staging/vt6655/iwctl.c1937
-rw-r--r--drivers/staging/vt6655/iwctl.h206
-rw-r--r--drivers/staging/vt6655/key.c838
-rw-r--r--drivers/staging/vt6655/key.h131
-rw-r--r--drivers/staging/vt6655/mac.c780
-rw-r--r--drivers/staging/vt6655/mac.h53
-rw-r--r--drivers/staging/vt6655/mib.c423
-rw-r--r--drivers/staging/vt6655/mib.h261
-rw-r--r--drivers/staging/vt6655/michael.c148
-rw-r--r--drivers/staging/vt6655/michael.h52
-rw-r--r--drivers/staging/vt6655/power.c208
-rw-r--r--drivers/staging/vt6655/power.h16
-rw-r--r--drivers/staging/vt6655/rc4.c88
-rw-r--r--drivers/staging/vt6655/rc4.h47
-rw-r--r--drivers/staging/vt6655/rf.c381
-rw-r--r--drivers/staging/vt6655/rf.h9
-rw-r--r--drivers/staging/vt6655/rxtx.c2112
-rw-r--r--drivers/staging/vt6655/rxtx.h52
-rw-r--r--drivers/staging/vt6655/srom.c252
-rw-r--r--drivers/staging/vt6655/srom.h49
-rw-r--r--drivers/staging/vt6655/tcrc.c191
-rw-r--r--drivers/staging/vt6655/tcrc.h50
-rw-r--r--drivers/staging/vt6655/tether.c105
-rw-r--r--drivers/staging/vt6655/tether.h192
-rw-r--r--drivers/staging/vt6655/tkip.c268
-rw-r--r--drivers/staging/vt6655/tkip.h57
-rw-r--r--drivers/staging/vt6655/tmacro.h2
-rw-r--r--drivers/staging/vt6655/ttype.h42
-rw-r--r--drivers/staging/vt6655/upc.h1
-rw-r--r--drivers/staging/vt6655/vntconfiguration.dat1
-rw-r--r--drivers/staging/vt6655/vntwifi.c700
-rw-r--r--drivers/staging/vt6655/vntwifi.h273
-rw-r--r--drivers/staging/vt6655/wcmd.c1023
-rw-r--r--drivers/staging/vt6655/wcmd.h123
-rw-r--r--drivers/staging/vt6655/wctl.c233
-rw-r--r--drivers/staging/vt6655/wctl.h105
-rw-r--r--drivers/staging/vt6655/wmgr.c4602
-rw-r--r--drivers/staging/vt6655/wmgr.h420
-rw-r--r--drivers/staging/vt6655/wpa.c300
-rw-r--r--drivers/staging/vt6655/wpa.h83
-rw-r--r--drivers/staging/vt6655/wpa2.c359
-rw-r--r--drivers/staging/vt6655/wpa2.h77
-rw-r--r--drivers/staging/vt6655/wpactl.c896
-rw-r--r--drivers/staging/vt6655/wpactl.h64
-rw-r--r--drivers/staging/vt6655/wroute.c187
-rw-r--r--drivers/staging/vt6655/wroute.h45
-rw-r--r--drivers/staging/vt6656/main_usb.c10
-rw-r--r--drivers/staging/wlan-ng/hfa384x.h3
-rw-r--r--drivers/staging/wlan-ng/hfa384x_usb.c6
-rw-r--r--drivers/staging/wlan-ng/p80211conv.c2
-rw-r--r--drivers/staging/wlan-ng/p80211hdr.h2
-rw-r--r--drivers/staging/wlan-ng/p80211netdev.c4
-rw-r--r--drivers/staging/wlan-ng/prism2fw.c9
-rw-r--r--drivers/staging/xgifb/XGI_main_26.c2
-rw-r--r--drivers/staging/xgifb/vb_def.h1
-rw-r--r--drivers/staging/xgifb/vb_setmode.c2
-rw-r--r--drivers/staging/xgifb/vb_util.c5
-rw-r--r--include/linux/iio/common/st_sensors.h10
-rw-r--r--include/linux/iio/iio.h8
-rw-r--r--include/uapi/linux/Kbuild1
-rw-r--r--include/uapi/linux/android/Kbuild2
-rw-r--r--include/uapi/linux/android/binder.h (renamed from drivers/staging/android/uapi/binder.h)1
748 files changed, 20649 insertions, 82639 deletions
diff --git a/Documentation/ABI/testing/sysfs-bus-iio b/Documentation/ABI/testing/sysfs-bus-iio
index d760b0224ef7..117521dbf2b3 100644
--- a/Documentation/ABI/testing/sysfs-bus-iio
+++ b/Documentation/ABI/testing/sysfs-bus-iio
@@ -200,6 +200,13 @@ Description:
200 Raw pressure measurement from channel Y. Units after 200 Raw pressure measurement from channel Y. Units after
201 application of scale and offset are kilopascal. 201 application of scale and offset are kilopascal.
202 202
203What: /sys/bus/iio/devices/iio:deviceX/in_pressureY_input
204What: /sys/bus/iio/devices/iio:deviceX/in_pressure_input
205KernelVersion: 3.8
206Contact: linux-iio@vger.kernel.org
207Description:
208 Scaled pressure measurement from channel Y, in kilopascal.
209
203What: /sys/bus/iio/devices/iio:deviceX/in_humidityrelative_raw 210What: /sys/bus/iio/devices/iio:deviceX/in_humidityrelative_raw
204KernelVersion: 3.14 211KernelVersion: 3.14
205Contact: linux-iio@vger.kernel.org 212Contact: linux-iio@vger.kernel.org
@@ -231,6 +238,7 @@ What: /sys/bus/iio/devices/iio:deviceX/in_tempY_offset
231What: /sys/bus/iio/devices/iio:deviceX/in_temp_offset 238What: /sys/bus/iio/devices/iio:deviceX/in_temp_offset
232What: /sys/bus/iio/devices/iio:deviceX/in_pressureY_offset 239What: /sys/bus/iio/devices/iio:deviceX/in_pressureY_offset
233What: /sys/bus/iio/devices/iio:deviceX/in_pressure_offset 240What: /sys/bus/iio/devices/iio:deviceX/in_pressure_offset
241What: /sys/bus/iio/devices/iio:deviceX/in_humidityrelative_offset
234KernelVersion: 2.6.35 242KernelVersion: 2.6.35
235Contact: linux-iio@vger.kernel.org 243Contact: linux-iio@vger.kernel.org
236Description: 244Description:
@@ -251,6 +259,7 @@ Description:
251What: /sys/bus/iio/devices/iio:deviceX/in_voltageY_scale 259What: /sys/bus/iio/devices/iio:deviceX/in_voltageY_scale
252What: /sys/bus/iio/devices/iio:deviceX/in_voltageY_supply_scale 260What: /sys/bus/iio/devices/iio:deviceX/in_voltageY_supply_scale
253What: /sys/bus/iio/devices/iio:deviceX/in_voltage_scale 261What: /sys/bus/iio/devices/iio:deviceX/in_voltage_scale
262What: /sys/bus/iio/devices/iio:deviceX/in_voltage-voltage_scale
254What: /sys/bus/iio/devices/iio:deviceX/out_voltageY_scale 263What: /sys/bus/iio/devices/iio:deviceX/out_voltageY_scale
255What: /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_scale 264What: /sys/bus/iio/devices/iio:deviceX/out_altvoltageY_scale
256What: /sys/bus/iio/devices/iio:deviceX/in_accel_scale 265What: /sys/bus/iio/devices/iio:deviceX/in_accel_scale
@@ -266,6 +275,7 @@ What: /sys/bus/iio/devices/iio:deviceX/in_rot_from_north_magnetic_tilt_comp_sca
266What: /sys/bus/iio/devices/iio:deviceX/in_rot_from_north_true_tilt_comp_scale 275What: /sys/bus/iio/devices/iio:deviceX/in_rot_from_north_true_tilt_comp_scale
267What: /sys/bus/iio/devices/iio:deviceX/in_pressureY_scale 276What: /sys/bus/iio/devices/iio:deviceX/in_pressureY_scale
268What: /sys/bus/iio/devices/iio:deviceX/in_pressure_scale 277What: /sys/bus/iio/devices/iio:deviceX/in_pressure_scale
278What: /sys/bus/iio/devices/iio:deviceX/in_humidityrelative_scale
269KernelVersion: 2.6.35 279KernelVersion: 2.6.35
270Contact: linux-iio@vger.kernel.org 280Contact: linux-iio@vger.kernel.org
271Description: 281Description:
@@ -328,6 +338,10 @@ Description:
328 are listed in this attribute. 338 are listed in this attribute.
329 339
330What /sys/bus/iio/devices/iio:deviceX/out_voltageY_hardwaregain 340What /sys/bus/iio/devices/iio:deviceX/out_voltageY_hardwaregain
341What: /sys/bus/iio/devices/iio:deviceX/in_intensity_red_hardwaregain
342What: /sys/bus/iio/devices/iio:deviceX/in_intensity_green_hardwaregain
343What: /sys/bus/iio/devices/iio:deviceX/in_intensity_blue_hardwaregain
344What: /sys/bus/iio/devices/iio:deviceX/in_intensity_clear_hardwaregain
331KernelVersion: 2.6.35 345KernelVersion: 2.6.35
332Contact: linux-iio@vger.kernel.org 346Contact: linux-iio@vger.kernel.org
333Description: 347Description:
@@ -1028,3 +1042,12 @@ Contact: linux-iio@vger.kernel.org
1028Description: 1042Description:
1029 Raw value of rotation from true/magnetic north measured with 1043 Raw value of rotation from true/magnetic north measured with
1030 or without compensation from tilt sensors. 1044 or without compensation from tilt sensors.
1045
1046What: /sys/bus/iio/devices/iio:deviceX/in_currentX_raw
1047KernelVersion: 3.18
1048Contact: linux-iio@vger.kernel.org
1049Description:
1050 Raw current measurement from channel X. Units are in milliamps
1051 after application of scale and offset. If no offset or scale is
1052 present, output should be considered as processed with the
1053 unit in milliamps.
diff --git a/Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt b/Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt
index 709efaa30841..f46ca9a316a2 100644
--- a/Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt
+++ b/Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt
@@ -16,6 +16,8 @@ Required properties:
16 future controllers. 16 future controllers.
17 Must be "samsung,exynos3250-adc" for 17 Must be "samsung,exynos3250-adc" for
18 controllers compatible with ADC of Exynos3250. 18 controllers compatible with ADC of Exynos3250.
19 Must be "samsung,exynos7-adc" for
20 the ADC in Exynos7 and compatibles
19 Must be "samsung,s3c2410-adc" for 21 Must be "samsung,s3c2410-adc" for
20 the ADC in s3c2410 and compatibles 22 the ADC in s3c2410 and compatibles
21 Must be "samsung,s3c2416-adc" for 23 Must be "samsung,s3c2416-adc" for
@@ -43,13 +45,16 @@ Required properties:
43 compatible ADC block) 45 compatible ADC block)
44- vdd-supply VDD input supply. 46- vdd-supply VDD input supply.
45 47
48- samsung,syscon-phandle Contains the PMU system controller node
49 (To access the ADC_PHY register on Exynos5250/5420/5800/3250)
50
46Note: child nodes can be added for auto probing from device tree. 51Note: child nodes can be added for auto probing from device tree.
47 52
48Example: adding device info in dtsi file 53Example: adding device info in dtsi file
49 54
50adc: adc@12D10000 { 55adc: adc@12D10000 {
51 compatible = "samsung,exynos-adc-v1"; 56 compatible = "samsung,exynos-adc-v1";
52 reg = <0x12D10000 0x100>, <0x10040718 0x4>; 57 reg = <0x12D10000 0x100>;
53 interrupts = <0 106 0>; 58 interrupts = <0 106 0>;
54 #io-channel-cells = <1>; 59 #io-channel-cells = <1>;
55 io-channel-ranges; 60 io-channel-ranges;
@@ -58,13 +63,14 @@ adc: adc@12D10000 {
58 clock-names = "adc"; 63 clock-names = "adc";
59 64
60 vdd-supply = <&buck5_reg>; 65 vdd-supply = <&buck5_reg>;
66 samsung,syscon-phandle = <&pmu_system_controller>;
61}; 67};
62 68
63Example: adding device info in dtsi file for Exynos3250 with additional sclk 69Example: adding device info in dtsi file for Exynos3250 with additional sclk
64 70
65adc: adc@126C0000 { 71adc: adc@126C0000 {
66 compatible = "samsung,exynos3250-adc", "samsung,exynos-adc-v2; 72 compatible = "samsung,exynos3250-adc", "samsung,exynos-adc-v2;
67 reg = <0x126C0000 0x100>, <0x10020718 0x4>; 73 reg = <0x126C0000 0x100>;
68 interrupts = <0 137 0>; 74 interrupts = <0 137 0>;
69 #io-channel-cells = <1>; 75 #io-channel-cells = <1>;
70 io-channel-ranges; 76 io-channel-ranges;
@@ -73,6 +79,7 @@ adc: adc@126C0000 {
73 clock-names = "adc", "sclk"; 79 clock-names = "adc", "sclk";
74 80
75 vdd-supply = <&buck5_reg>; 81 vdd-supply = <&buck5_reg>;
82 samsung,syscon-phandle = <&pmu_system_controller>;
76}; 83};
77 84
78Example: Adding child nodes in dts file 85Example: Adding child nodes in dts file
diff --git a/Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt b/Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt
new file mode 100644
index 000000000000..4e36d6e2f7b6
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/adc/qcom,spmi-iadc.txt
@@ -0,0 +1,46 @@
1Qualcomm's SPMI PMIC current ADC
2
3QPNP PMIC current ADC (IADC) provides interface to clients to read current.
4A 16 bit ADC is used for current measurements. IADC can measure the current
5through an external resistor (channel 1) or internal (built-in) resistor
6(channel 0). When using an external resistor it is to be described by
7qcom,external-resistor-micro-ohms property.
8
9IADC node:
10
11- compatible:
12 Usage: required
13 Value type: <string>
14 Definition: Should contain "qcom,spmi-iadc".
15
16- reg:
17 Usage: required
18 Value type: <prop-encoded-array>
19 Definition: IADC base address and length in the SPMI PMIC register map
20
21- interrupts:
22 Usage: optional
23 Value type: <prop-encoded-array>
24 Definition: End of ADC conversion.
25
26- qcom,external-resistor-micro-ohms:
27 Usage: optional
28 Value type: <u32>
29 Definition: Sense resister value in micro Ohm.
30 If not defined value of 10000 micro Ohms will be used.
31
32Example:
33 /* IADC node */
34 pmic_iadc: iadc@3600 {
35 compatible = "qcom,spmi-iadc";
36 reg = <0x3600 0x100>;
37 interrupts = <0x0 0x36 0x0 IRQ_TYPE_EDGE_RISING>;
38 qcom,external-resistor-micro-ohms = <10000>;
39 #io-channel-cells = <1>;
40 };
41
42 /* IIO client node */
43 bat {
44 io-channels = <&pmic_iadc 0>;
45 io-channel-names = "iadc";
46 };
diff --git a/Documentation/devicetree/bindings/iio/adc/rockchip-saradc.txt b/Documentation/devicetree/bindings/iio/adc/rockchip-saradc.txt
index 5d3ec1df226d..a9a5fe19ff2a 100644
--- a/Documentation/devicetree/bindings/iio/adc/rockchip-saradc.txt
+++ b/Documentation/devicetree/bindings/iio/adc/rockchip-saradc.txt
@@ -1,7 +1,7 @@
1Rockchip Successive Approximation Register (SAR) A/D Converter bindings 1Rockchip Successive Approximation Register (SAR) A/D Converter bindings
2 2
3Required properties: 3Required properties:
4- compatible: Should be "rockchip,saradc" 4- compatible: Should be "rockchip,saradc" or "rockchip,rk3066-tsadc"
5- reg: physical base address of the controller and length of memory mapped 5- reg: physical base address of the controller and length of memory mapped
6 region. 6 region.
7- interrupts: The interrupt number to the cpu. The interrupt specifier format 7- interrupts: The interrupt number to the cpu. The interrupt specifier format
diff --git a/MAINTAINERS b/MAINTAINERS
index c690b5a0d7b7..993a43a43882 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1925,13 +1925,6 @@ W: http://bcache.evilpiepirate.org
1925S: Maintained: 1925S: Maintained:
1926F: drivers/md/bcache/ 1926F: drivers/md/bcache/
1927 1927
1928BECEEM BCS200/BCS220-3/BCSM250 WIMAX SUPPORT
1929M: Kevin McKinney <klmckinney1@gmail.com>
1930M: Matthias Beyer <mail@beyermatthias.de>
1931L: devel@driverdev.osuosl.org
1932S: Maintained
1933F: drivers/staging/bcm*
1934
1935BEFS FILE SYSTEM 1928BEFS FILE SYSTEM
1936S: Orphan 1929S: Orphan
1937F: Documentation/filesystems/befs.txt 1930F: Documentation/filesystems/befs.txt
diff --git a/arch/arm/boot/dts/exynos3250.dtsi b/arch/arm/boot/dts/exynos3250.dtsi
index 242ddda0a8cd..22465494b796 100644
--- a/arch/arm/boot/dts/exynos3250.dtsi
+++ b/arch/arm/boot/dts/exynos3250.dtsi
@@ -311,12 +311,13 @@
311 adc: adc@126C0000 { 311 adc: adc@126C0000 {
312 compatible = "samsung,exynos3250-adc", 312 compatible = "samsung,exynos3250-adc",
313 "samsung,exynos-adc-v2"; 313 "samsung,exynos-adc-v2";
314 reg = <0x126C0000 0x100>, <0x10020718 0x4>; 314 reg = <0x126C0000 0x100>;
315 interrupts = <0 137 0>; 315 interrupts = <0 137 0>;
316 clock-names = "adc", "sclk"; 316 clock-names = "adc", "sclk";
317 clocks = <&cmu CLK_TSADC>, <&cmu CLK_SCLK_TSADC>; 317 clocks = <&cmu CLK_TSADC>, <&cmu CLK_SCLK_TSADC>;
318 #io-channel-cells = <1>; 318 #io-channel-cells = <1>;
319 io-channel-ranges; 319 io-channel-ranges;
320 samsung,syscon-phandle = <&pmu_system_controller>;
320 status = "disabled"; 321 status = "disabled";
321 }; 322 };
322 323
diff --git a/arch/arm/boot/dts/exynos4x12.dtsi b/arch/arm/boot/dts/exynos4x12.dtsi
index 2e9f1f7be77b..93b70402e943 100644
--- a/arch/arm/boot/dts/exynos4x12.dtsi
+++ b/arch/arm/boot/dts/exynos4x12.dtsi
@@ -108,13 +108,14 @@
108 108
109 adc: adc@126C0000 { 109 adc: adc@126C0000 {
110 compatible = "samsung,exynos-adc-v1"; 110 compatible = "samsung,exynos-adc-v1";
111 reg = <0x126C0000 0x100>, <0x10020718 0x4>; 111 reg = <0x126C0000 0x100>;
112 interrupt-parent = <&combiner>; 112 interrupt-parent = <&combiner>;
113 interrupts = <10 3>; 113 interrupts = <10 3>;
114 clocks = <&clock CLK_TSADC>; 114 clocks = <&clock CLK_TSADC>;
115 clock-names = "adc"; 115 clock-names = "adc";
116 #io-channel-cells = <1>; 116 #io-channel-cells = <1>;
117 io-channel-ranges; 117 io-channel-ranges;
118 samsung,syscon-phandle = <&pmu_system_controller>;
118 status = "disabled"; 119 status = "disabled";
119 }; 120 };
120 121
diff --git a/arch/arm/boot/dts/exynos5250.dtsi b/arch/arm/boot/dts/exynos5250.dtsi
index d45a07ea3402..0a229fcd7acf 100644
--- a/arch/arm/boot/dts/exynos5250.dtsi
+++ b/arch/arm/boot/dts/exynos5250.dtsi
@@ -754,12 +754,13 @@
754 754
755 adc: adc@12D10000 { 755 adc: adc@12D10000 {
756 compatible = "samsung,exynos-adc-v1"; 756 compatible = "samsung,exynos-adc-v1";
757 reg = <0x12D10000 0x100>, <0x10040718 0x4>; 757 reg = <0x12D10000 0x100>;
758 interrupts = <0 106 0>; 758 interrupts = <0 106 0>;
759 clocks = <&clock CLK_ADC>; 759 clocks = <&clock CLK_ADC>;
760 clock-names = "adc"; 760 clock-names = "adc";
761 #io-channel-cells = <1>; 761 #io-channel-cells = <1>;
762 io-channel-ranges; 762 io-channel-ranges;
763 samsung,syscon-phandle = <&pmu_system_controller>;
763 status = "disabled"; 764 status = "disabled";
764 }; 765 };
765 766
diff --git a/arch/arm/boot/dts/exynos5420.dtsi b/arch/arm/boot/dts/exynos5420.dtsi
index 90bf4011e319..517e50f6760b 100644
--- a/arch/arm/boot/dts/exynos5420.dtsi
+++ b/arch/arm/boot/dts/exynos5420.dtsi
@@ -541,12 +541,13 @@
541 541
542 adc: adc@12D10000 { 542 adc: adc@12D10000 {
543 compatible = "samsung,exynos-adc-v2"; 543 compatible = "samsung,exynos-adc-v2";
544 reg = <0x12D10000 0x100>, <0x10040720 0x4>; 544 reg = <0x12D10000 0x100>;
545 interrupts = <0 106 0>; 545 interrupts = <0 106 0>;
546 clocks = <&clock CLK_TSADC>; 546 clocks = <&clock CLK_TSADC>;
547 clock-names = "adc"; 547 clock-names = "adc";
548 #io-channel-cells = <1>; 548 #io-channel-cells = <1>;
549 io-channel-ranges; 549 io-channel-ranges;
550 samsung,syscon-phandle = <&pmu_system_controller>;
550 status = "disabled"; 551 status = "disabled";
551 }; 552 };
552 553
diff --git a/drivers/Kconfig b/drivers/Kconfig
index af02a8a8ec4a..694d5a70d6ce 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -184,4 +184,6 @@ source "drivers/ras/Kconfig"
184 184
185source "drivers/thunderbolt/Kconfig" 185source "drivers/thunderbolt/Kconfig"
186 186
187source "drivers/android/Kconfig"
188
187endmenu 189endmenu
diff --git a/drivers/Makefile b/drivers/Makefile
index 628b512b625b..67d2334dc41e 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -162,3 +162,4 @@ obj-$(CONFIG_MCB) += mcb/
162obj-$(CONFIG_RAS) += ras/ 162obj-$(CONFIG_RAS) += ras/
163obj-$(CONFIG_THUNDERBOLT) += thunderbolt/ 163obj-$(CONFIG_THUNDERBOLT) += thunderbolt/
164obj-$(CONFIG_CORESIGHT) += coresight/ 164obj-$(CONFIG_CORESIGHT) += coresight/
165obj-$(CONFIG_ANDROID) += android/
diff --git a/drivers/android/Kconfig b/drivers/android/Kconfig
new file mode 100644
index 000000000000..bdfc6c6f4f5a
--- /dev/null
+++ b/drivers/android/Kconfig
@@ -0,0 +1,37 @@
1menu "Android"
2
3config ANDROID
4 bool "Android Drivers"
5 ---help---
6 Enable support for various drivers needed on the Android platform
7
8if ANDROID
9
10config ANDROID_BINDER_IPC
11 bool "Android Binder IPC Driver"
12 depends on MMU
13 default n
14 ---help---
15 Binder is used in Android for both communication between processes,
16 and remote method invocation.
17
18 This means one Android process can call a method/routine in another
19 Android process, using Binder to identify, invoke and pass arguments
20 between said processes.
21
22config ANDROID_BINDER_IPC_32BIT
23 bool
24 depends on !64BIT && ANDROID_BINDER_IPC
25 default y
26 ---help---
27 The Binder API has been changed to support both 32 and 64bit
28 applications in a mixed environment.
29
30 Enable this to support an old 32-bit Android user-space (v4.4 and
31 earlier).
32
33 Note that enabling this will break newer Android user-space.
34
35endif # if ANDROID
36
37endmenu
diff --git a/drivers/android/Makefile b/drivers/android/Makefile
new file mode 100644
index 000000000000..3b7e4b072c58
--- /dev/null
+++ b/drivers/android/Makefile
@@ -0,0 +1,3 @@
1ccflags-y += -I$(src) # needed for trace events
2
3obj-$(CONFIG_ANDROID_BINDER_IPC) += binder.o
diff --git a/drivers/staging/android/binder.c b/drivers/android/binder.c
index c69c40d69d5c..8c43521d3f11 100644
--- a/drivers/staging/android/binder.c
+++ b/drivers/android/binder.c
@@ -38,7 +38,11 @@
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/pid_namespace.h> 39#include <linux/pid_namespace.h>
40 40
41#include "binder.h" 41#ifdef CONFIG_ANDROID_BINDER_IPC_32BIT
42#define BINDER_IPC_32BIT 1
43#endif
44
45#include <uapi/linux/android/binder.h>
42#include "binder_trace.h" 46#include "binder_trace.h"
43 47
44static DEFINE_MUTEX(binder_main_lock); 48static DEFINE_MUTEX(binder_main_lock);
diff --git a/drivers/staging/android/binder_trace.h b/drivers/android/binder_trace.h
index 7f20f3dc8369..7f20f3dc8369 100644
--- a/drivers/staging/android/binder_trace.h
+++ b/drivers/android/binder_trace.h
diff --git a/drivers/gpu/drm/imx/Kconfig b/drivers/gpu/drm/imx/Kconfig
index 82fb758a29bc..ab31848e92cf 100644
--- a/drivers/gpu/drm/imx/Kconfig
+++ b/drivers/gpu/drm/imx/Kconfig
@@ -6,6 +6,7 @@ config DRM_IMX
6 select DRM_GEM_CMA_HELPER 6 select DRM_GEM_CMA_HELPER
7 select DRM_KMS_CMA_HELPER 7 select DRM_KMS_CMA_HELPER
8 depends on DRM && (ARCH_MXC || ARCH_MULTIPLATFORM) 8 depends on DRM && (ARCH_MXC || ARCH_MULTIPLATFORM)
9 depends on IMX_IPUV3_CORE
9 help 10 help
10 enable i.MX graphics support 11 enable i.MX graphics support
11 12
@@ -40,11 +41,11 @@ config DRM_IMX_LDB
40 found on i.MX53 and i.MX6 processors. 41 found on i.MX53 and i.MX6 processors.
41 42
42config DRM_IMX_IPUV3 43config DRM_IMX_IPUV3
43 tristate "DRM Support for i.MX IPUv3" 44 tristate
44 depends on DRM_IMX 45 depends on DRM_IMX
45 depends on IMX_IPUV3_CORE 46 depends on IMX_IPUV3_CORE
46 help 47 default y if DRM_IMX=y
47 Choose this if you have a i.MX5 or i.MX6 processor. 48 default m if DRM_IMX=m
48 49
49config DRM_IMX_HDMI 50config DRM_IMX_HDMI
50 tristate "Freescale i.MX DRM HDMI" 51 tristate "Freescale i.MX DRM HDMI"
diff --git a/drivers/gpu/drm/imx/imx-drm-core.c b/drivers/gpu/drm/imx/imx-drm-core.c
index e48b2211d2d6..b250130debc8 100644
--- a/drivers/gpu/drm/imx/imx-drm-core.c
+++ b/drivers/gpu/drm/imx/imx-drm-core.c
@@ -30,8 +30,6 @@
30 30
31#define MAX_CRTC 4 31#define MAX_CRTC 4
32 32
33struct imx_drm_crtc;
34
35struct imx_drm_component { 33struct imx_drm_component {
36 struct device_node *of_node; 34 struct device_node *of_node;
37 struct list_head list; 35 struct list_head list;
@@ -633,7 +631,8 @@ static int imx_drm_platform_probe(struct platform_device *pdev)
633 continue; 631 continue;
634 } 632 }
635 633
636 component_match_add(&pdev->dev, &match, compare_of, remote); 634 component_match_add(&pdev->dev, &match, compare_of,
635 remote);
637 of_node_put(remote); 636 of_node_put(remote);
638 } 637 }
639 of_node_put(port); 638 of_node_put(port);
diff --git a/drivers/gpu/drm/imx/imx-ldb.c b/drivers/gpu/drm/imx/imx-ldb.c
index 2638dc1671d0..c60460043e24 100644
--- a/drivers/gpu/drm/imx/imx-ldb.c
+++ b/drivers/gpu/drm/imx/imx-ldb.c
@@ -11,11 +11,6 @@
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 * MA 02110-1301, USA.
19 */ 14 */
20 15
21#include <linux/module.h> 16#include <linux/module.h>
diff --git a/drivers/gpu/drm/imx/imx-tve.c b/drivers/gpu/drm/imx/imx-tve.c
index 64b54d7f996c..a729f4f7074c 100644
--- a/drivers/gpu/drm/imx/imx-tve.c
+++ b/drivers/gpu/drm/imx/imx-tve.c
@@ -11,11 +11,6 @@
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 * MA 02110-1301, USA.
19 */ 14 */
20 15
21#include <linux/clk.h> 16#include <linux/clk.h>
@@ -665,7 +660,8 @@ static int imx_tve_bind(struct device *dev, struct device *master, void *data)
665 660
666 ret = regmap_read(tve->regmap, TVE_COM_CONF_REG, &val); 661 ret = regmap_read(tve->regmap, TVE_COM_CONF_REG, &val);
667 if (ret < 0) { 662 if (ret < 0) {
668 dev_err(dev, "failed to read configuration register: %d\n", ret); 663 dev_err(dev, "failed to read configuration register: %d\n",
664 ret);
669 return ret; 665 return ret;
670 } 666 }
671 if (val != 0x00100000) { 667 if (val != 0x00100000) {
diff --git a/drivers/gpu/drm/imx/ipuv3-crtc.c b/drivers/gpu/drm/imx/ipuv3-crtc.c
index 11e84a251773..ebee59cb96d8 100644
--- a/drivers/gpu/drm/imx/ipuv3-crtc.c
+++ b/drivers/gpu/drm/imx/ipuv3-crtc.c
@@ -11,11 +11,6 @@
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 * MA 02110-1301, USA.
19 */ 14 */
20#include <linux/component.h> 15#include <linux/component.h>
21#include <linux/module.h> 16#include <linux/module.h>
diff --git a/drivers/gpu/drm/imx/ipuv3-plane.c b/drivers/gpu/drm/imx/ipuv3-plane.c
index 944962b692bb..6987e16fe99b 100644
--- a/drivers/gpu/drm/imx/ipuv3-plane.c
+++ b/drivers/gpu/drm/imx/ipuv3-plane.c
@@ -64,6 +64,7 @@ int ipu_plane_set_base(struct ipu_plane *ipu_plane, struct drm_framebuffer *fb,
64{ 64{
65 struct drm_gem_cma_object *cma_obj; 65 struct drm_gem_cma_object *cma_obj;
66 unsigned long eba; 66 unsigned long eba;
67 int active;
67 68
68 cma_obj = drm_fb_cma_get_gem_obj(fb, 0); 69 cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
69 if (!cma_obj) { 70 if (!cma_obj) {
@@ -74,12 +75,17 @@ int ipu_plane_set_base(struct ipu_plane *ipu_plane, struct drm_framebuffer *fb,
74 dev_dbg(ipu_plane->base.dev->dev, "phys = %pad, x = %d, y = %d", 75 dev_dbg(ipu_plane->base.dev->dev, "phys = %pad, x = %d, y = %d",
75 &cma_obj->paddr, x, y); 76 &cma_obj->paddr, x, y);
76 77
77 ipu_cpmem_set_stride(ipu_plane->ipu_ch, fb->pitches[0]);
78
79 eba = cma_obj->paddr + fb->offsets[0] + 78 eba = cma_obj->paddr + fb->offsets[0] +
80 fb->pitches[0] * y + (fb->bits_per_pixel >> 3) * x; 79 fb->pitches[0] * y + (fb->bits_per_pixel >> 3) * x;
81 ipu_cpmem_set_buffer(ipu_plane->ipu_ch, 0, eba); 80
82 ipu_cpmem_set_buffer(ipu_plane->ipu_ch, 1, eba); 81 if (ipu_plane->enabled) {
82 active = ipu_idmac_get_current_buffer(ipu_plane->ipu_ch);
83 ipu_cpmem_set_buffer(ipu_plane->ipu_ch, !active, eba);
84 ipu_idmac_select_buffer(ipu_plane->ipu_ch, !active);
85 } else {
86 ipu_cpmem_set_buffer(ipu_plane->ipu_ch, 0, eba);
87 ipu_cpmem_set_buffer(ipu_plane->ipu_ch, 1, eba);
88 }
83 89
84 /* cache offsets for subsequent pageflips */ 90 /* cache offsets for subsequent pageflips */
85 ipu_plane->x = x; 91 ipu_plane->x = x;
@@ -137,6 +143,18 @@ int ipu_plane_mode_set(struct ipu_plane *ipu_plane, struct drm_crtc *crtc,
137 if (crtc_h < 2) 143 if (crtc_h < 2)
138 return -EINVAL; 144 return -EINVAL;
139 145
146 /*
147 * since we cannot touch active IDMAC channels, we do not support
148 * resizing the enabled plane or changing its format
149 */
150 if (ipu_plane->enabled) {
151 if (src_w != ipu_plane->w || src_h != ipu_plane->h ||
152 fb->pixel_format != ipu_plane->base.fb->pixel_format)
153 return -EINVAL;
154
155 return ipu_plane_set_base(ipu_plane, fb, src_x, src_y);
156 }
157
140 switch (ipu_plane->dp_flow) { 158 switch (ipu_plane->dp_flow) {
141 case IPU_DP_FLOW_SYNC_BG: 159 case IPU_DP_FLOW_SYNC_BG:
142 ret = ipu_dp_setup_channel(ipu_plane->dp, 160 ret = ipu_dp_setup_channel(ipu_plane->dp,
@@ -148,14 +166,22 @@ int ipu_plane_mode_set(struct ipu_plane *ipu_plane, struct drm_crtc *crtc,
148 ret); 166 ret);
149 return ret; 167 return ret;
150 } 168 }
151 ipu_dp_set_global_alpha(ipu_plane->dp, 1, 0, 1); 169 ipu_dp_set_global_alpha(ipu_plane->dp, true, 0, true);
152 break; 170 break;
153 case IPU_DP_FLOW_SYNC_FG: 171 case IPU_DP_FLOW_SYNC_FG:
154 ipu_dp_setup_channel(ipu_plane->dp, 172 ipu_dp_setup_channel(ipu_plane->dp,
155 ipu_drm_fourcc_to_colorspace(fb->pixel_format), 173 ipu_drm_fourcc_to_colorspace(fb->pixel_format),
156 IPUV3_COLORSPACE_UNKNOWN); 174 IPUV3_COLORSPACE_UNKNOWN);
157 ipu_dp_set_window_pos(ipu_plane->dp, crtc_x, crtc_y); 175 ipu_dp_set_window_pos(ipu_plane->dp, crtc_x, crtc_y);
158 break; 176 /* Enable local alpha on partial plane */
177 switch (fb->pixel_format) {
178 case DRM_FORMAT_ARGB8888:
179 case DRM_FORMAT_ABGR8888:
180 ipu_dp_set_global_alpha(ipu_plane->dp, false, 0, false);
181 break;
182 default:
183 break;
184 }
159 } 185 }
160 186
161 ret = ipu_dmfc_init_channel(ipu_plane->dmfc, crtc_w); 187 ret = ipu_dmfc_init_channel(ipu_plane->dmfc, crtc_w);
@@ -181,11 +207,16 @@ int ipu_plane_mode_set(struct ipu_plane *ipu_plane, struct drm_crtc *crtc,
181 return ret; 207 return ret;
182 } 208 }
183 ipu_cpmem_set_high_priority(ipu_plane->ipu_ch); 209 ipu_cpmem_set_high_priority(ipu_plane->ipu_ch);
210 ipu_idmac_set_double_buffer(ipu_plane->ipu_ch, 1);
211 ipu_cpmem_set_stride(ipu_plane->ipu_ch, fb->pitches[0]);
184 212
185 ret = ipu_plane_set_base(ipu_plane, fb, src_x, src_y); 213 ret = ipu_plane_set_base(ipu_plane, fb, src_x, src_y);
186 if (ret < 0) 214 if (ret < 0)
187 return ret; 215 return ret;
188 216
217 ipu_plane->w = src_w;
218 ipu_plane->h = src_h;
219
189 return 0; 220 return 0;
190} 221}
191 222
diff --git a/drivers/gpu/drm/imx/ipuv3-plane.h b/drivers/gpu/drm/imx/ipuv3-plane.h
index c0aae5bcb5d4..af125fb40ef5 100644
--- a/drivers/gpu/drm/imx/ipuv3-plane.h
+++ b/drivers/gpu/drm/imx/ipuv3-plane.h
@@ -26,6 +26,8 @@ struct ipu_plane {
26 26
27 int x; 27 int x;
28 int y; 28 int y;
29 int w;
30 int h;
29 31
30 bool enabled; 32 bool enabled;
31}; 33};
diff --git a/drivers/gpu/drm/imx/parallel-display.c b/drivers/gpu/drm/imx/parallel-display.c
index 8a76a5c1c34b..796c3c1c170a 100644
--- a/drivers/gpu/drm/imx/parallel-display.c
+++ b/drivers/gpu/drm/imx/parallel-display.c
@@ -11,11 +11,6 @@
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 * MA 02110-1301, USA.
19 */ 14 */
20 15
21#include <linux/component.h> 16#include <linux/component.h>
@@ -128,6 +123,10 @@ static void imx_pd_encoder_prepare(struct drm_encoder *encoder)
128 123
129static void imx_pd_encoder_commit(struct drm_encoder *encoder) 124static void imx_pd_encoder_commit(struct drm_encoder *encoder)
130{ 125{
126 struct imx_parallel_display *imxpd = enc_to_imxpd(encoder);
127
128 drm_panel_prepare(imxpd->panel);
129 drm_panel_enable(imxpd->panel);
131} 130}
132 131
133static void imx_pd_encoder_mode_set(struct drm_encoder *encoder, 132static void imx_pd_encoder_mode_set(struct drm_encoder *encoder,
@@ -138,6 +137,10 @@ static void imx_pd_encoder_mode_set(struct drm_encoder *encoder,
138 137
139static void imx_pd_encoder_disable(struct drm_encoder *encoder) 138static void imx_pd_encoder_disable(struct drm_encoder *encoder)
140{ 139{
140 struct imx_parallel_display *imxpd = enc_to_imxpd(encoder);
141
142 drm_panel_disable(imxpd->panel);
143 drm_panel_unprepare(imxpd->panel);
141} 144}
142 145
143static struct drm_connector_funcs imx_pd_connector_funcs = { 146static struct drm_connector_funcs imx_pd_connector_funcs = {
diff --git a/drivers/iio/accel/st_accel.h b/drivers/iio/accel/st_accel.h
index c3877630b2e4..fa9646034305 100644
--- a/drivers/iio/accel/st_accel.h
+++ b/drivers/iio/accel/st_accel.h
@@ -33,8 +33,7 @@ static const struct st_sensors_platform_data default_accel_pdata = {
33 .drdy_int_pin = 1, 33 .drdy_int_pin = 1,
34}; 34};
35 35
36int st_accel_common_probe(struct iio_dev *indio_dev, 36int st_accel_common_probe(struct iio_dev *indio_dev);
37 struct st_sensors_platform_data *pdata);
38void st_accel_common_remove(struct iio_dev *indio_dev); 37void st_accel_common_remove(struct iio_dev *indio_dev);
39 38
40#ifdef CONFIG_IIO_BUFFER 39#ifdef CONFIG_IIO_BUFFER
diff --git a/drivers/iio/accel/st_accel_core.c b/drivers/iio/accel/st_accel_core.c
index 087864854c61..53f32629283a 100644
--- a/drivers/iio/accel/st_accel_core.c
+++ b/drivers/iio/accel/st_accel_core.c
@@ -161,7 +161,7 @@ static const struct iio_chan_spec st_accel_16bit_channels[] = {
161 IIO_CHAN_SOFT_TIMESTAMP(3) 161 IIO_CHAN_SOFT_TIMESTAMP(3)
162}; 162};
163 163
164static const struct st_sensors st_accel_sensors[] = { 164static const struct st_sensor_settings st_accel_sensors_settings[] = {
165 { 165 {
166 .wai = ST_ACCEL_1_WAI_EXP, 166 .wai = ST_ACCEL_1_WAI_EXP,
167 .sensors_supported = { 167 .sensors_supported = {
@@ -457,8 +457,7 @@ static const struct iio_trigger_ops st_accel_trigger_ops = {
457#define ST_ACCEL_TRIGGER_OPS NULL 457#define ST_ACCEL_TRIGGER_OPS NULL
458#endif 458#endif
459 459
460int st_accel_common_probe(struct iio_dev *indio_dev, 460int st_accel_common_probe(struct iio_dev *indio_dev)
461 struct st_sensors_platform_data *plat_data)
462{ 461{
463 struct st_sensor_data *adata = iio_priv(indio_dev); 462 struct st_sensor_data *adata = iio_priv(indio_dev);
464 int irq = adata->get_irq_data_ready(indio_dev); 463 int irq = adata->get_irq_data_ready(indio_dev);
@@ -470,24 +469,25 @@ int st_accel_common_probe(struct iio_dev *indio_dev,
470 st_sensors_power_enable(indio_dev); 469 st_sensors_power_enable(indio_dev);
471 470
472 err = st_sensors_check_device_support(indio_dev, 471 err = st_sensors_check_device_support(indio_dev,
473 ARRAY_SIZE(st_accel_sensors), st_accel_sensors); 472 ARRAY_SIZE(st_accel_sensors_settings),
473 st_accel_sensors_settings);
474 if (err < 0) 474 if (err < 0)
475 return err; 475 return err;
476 476
477 adata->num_data_channels = ST_ACCEL_NUMBER_DATA_CHANNELS; 477 adata->num_data_channels = ST_ACCEL_NUMBER_DATA_CHANNELS;
478 adata->multiread_bit = adata->sensor->multi_read_bit; 478 adata->multiread_bit = adata->sensor_settings->multi_read_bit;
479 indio_dev->channels = adata->sensor->ch; 479 indio_dev->channels = adata->sensor_settings->ch;
480 indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS; 480 indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;
481 481
482 adata->current_fullscale = (struct st_sensor_fullscale_avl *) 482 adata->current_fullscale = (struct st_sensor_fullscale_avl *)
483 &adata->sensor->fs.fs_avl[0]; 483 &adata->sensor_settings->fs.fs_avl[0];
484 adata->odr = adata->sensor->odr.odr_avl[0].hz; 484 adata->odr = adata->sensor_settings->odr.odr_avl[0].hz;
485 485
486 if (!plat_data) 486 if (!adata->dev->platform_data)
487 plat_data = 487 adata->dev->platform_data =
488 (struct st_sensors_platform_data *)&default_accel_pdata; 488 (struct st_sensors_platform_data *)&default_accel_pdata;
489 489
490 err = st_sensors_init_sensor(indio_dev, plat_data); 490 err = st_sensors_init_sensor(indio_dev, adata->dev->platform_data);
491 if (err < 0) 491 if (err < 0)
492 return err; 492 return err;
493 493
diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c
index 7164aeff3ab1..c7246bdd30b9 100644
--- a/drivers/iio/accel/st_accel_i2c.c
+++ b/drivers/iio/accel/st_accel_i2c.c
@@ -79,12 +79,11 @@ static int st_accel_i2c_probe(struct i2c_client *client,
79 return -ENOMEM; 79 return -ENOMEM;
80 80
81 adata = iio_priv(indio_dev); 81 adata = iio_priv(indio_dev);
82 adata->dev = &client->dev;
83 st_sensors_of_i2c_probe(client, st_accel_of_match); 82 st_sensors_of_i2c_probe(client, st_accel_of_match);
84 83
85 st_sensors_i2c_configure(indio_dev, client, adata); 84 st_sensors_i2c_configure(indio_dev, client, adata);
86 85
87 err = st_accel_common_probe(indio_dev, client->dev.platform_data); 86 err = st_accel_common_probe(indio_dev);
88 if (err < 0) 87 if (err < 0)
89 return err; 88 return err;
90 89
diff --git a/drivers/iio/accel/st_accel_spi.c b/drivers/iio/accel/st_accel_spi.c
index 195639646e34..12ec29389e4b 100644
--- a/drivers/iio/accel/st_accel_spi.c
+++ b/drivers/iio/accel/st_accel_spi.c
@@ -29,11 +29,10 @@ static int st_accel_spi_probe(struct spi_device *spi)
29 return -ENOMEM; 29 return -ENOMEM;
30 30
31 adata = iio_priv(indio_dev); 31 adata = iio_priv(indio_dev);
32 adata->dev = &spi->dev;
33 32
34 st_sensors_spi_configure(indio_dev, spi, adata); 33 st_sensors_spi_configure(indio_dev, spi, adata);
35 34
36 err = st_accel_common_probe(indio_dev, spi->dev.platform_data); 35 err = st_accel_common_probe(indio_dev);
37 if (err < 0) 36 if (err < 0)
38 return err; 37 return err;
39 38
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index bc4e787096e8..0f79e4725763 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -214,6 +214,20 @@ config NAU7802
214 To compile this driver as a module, choose M here: the 214 To compile this driver as a module, choose M here: the
215 module will be called nau7802. 215 module will be called nau7802.
216 216
217config QCOM_SPMI_IADC
218 tristate "Qualcomm SPMI PMIC current ADC"
219 depends on SPMI
220 select REGMAP_SPMI
221 help
222 This is the IIO Current ADC driver for Qualcomm QPNP IADC Chip.
223
224 The driver supports single mode operation to read from one of two
225 channels (external or internal). Hardware have additional
226 channels internally used for gain and offset calibration.
227
228 To compile this driver as a module, choose M here: the module will
229 be called qcom-spmi-iadc.
230
217config ROCKCHIP_SARADC 231config ROCKCHIP_SARADC
218 tristate "Rockchip SARADC driver" 232 tristate "Rockchip SARADC driver"
219 depends on ARCH_ROCKCHIP || (ARM && COMPILE_TEST) 233 depends on ARCH_ROCKCHIP || (ARM && COMPILE_TEST)
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index f30093f5b67a..701fdb7c96aa 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_MCP320X) += mcp320x.o
23obj-$(CONFIG_MCP3422) += mcp3422.o 23obj-$(CONFIG_MCP3422) += mcp3422.o
24obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o 24obj-$(CONFIG_MEN_Z188_ADC) += men_z188_adc.o
25obj-$(CONFIG_NAU7802) += nau7802.o 25obj-$(CONFIG_NAU7802) += nau7802.o
26obj-$(CONFIG_QCOM_SPMI_IADC) += qcom-spmi-iadc.o
26obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o 27obj-$(CONFIG_ROCKCHIP_SARADC) += rockchip_saradc.o
27obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o 28obj-$(CONFIG_TI_ADC081C) += ti-adc081c.o
28obj-$(CONFIG_TI_ADC128S052) += ti-adc128s052.o 29obj-$(CONFIG_TI_ADC128S052) += ti-adc128s052.o
diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
index 43620fd4c66a..3a2dbb3b4926 100644
--- a/drivers/iio/adc/exynos_adc.c
+++ b/drivers/iio/adc/exynos_adc.c
@@ -39,6 +39,8 @@
39#include <linux/iio/iio.h> 39#include <linux/iio/iio.h>
40#include <linux/iio/machine.h> 40#include <linux/iio/machine.h>
41#include <linux/iio/driver.h> 41#include <linux/iio/driver.h>
42#include <linux/mfd/syscon.h>
43#include <linux/regmap.h>
42 44
43/* S3C/EXYNOS4412/5250 ADC_V1 registers definitions */ 45/* S3C/EXYNOS4412/5250 ADC_V1 registers definitions */
44#define ADC_V1_CON(x) ((x) + 0x00) 46#define ADC_V1_CON(x) ((x) + 0x00)
@@ -90,11 +92,14 @@
90 92
91#define EXYNOS_ADC_TIMEOUT (msecs_to_jiffies(100)) 93#define EXYNOS_ADC_TIMEOUT (msecs_to_jiffies(100))
92 94
95#define EXYNOS_ADCV1_PHY_OFFSET 0x0718
96#define EXYNOS_ADCV2_PHY_OFFSET 0x0720
97
93struct exynos_adc { 98struct exynos_adc {
94 struct exynos_adc_data *data; 99 struct exynos_adc_data *data;
95 struct device *dev; 100 struct device *dev;
96 void __iomem *regs; 101 void __iomem *regs;
97 void __iomem *enable_reg; 102 struct regmap *pmu_map;
98 struct clk *clk; 103 struct clk *clk;
99 struct clk *sclk; 104 struct clk *sclk;
100 unsigned int irq; 105 unsigned int irq;
@@ -110,6 +115,7 @@ struct exynos_adc_data {
110 int num_channels; 115 int num_channels;
111 bool needs_sclk; 116 bool needs_sclk;
112 bool needs_adc_phy; 117 bool needs_adc_phy;
118 int phy_offset;
113 u32 mask; 119 u32 mask;
114 120
115 void (*init_hw)(struct exynos_adc *info); 121 void (*init_hw)(struct exynos_adc *info);
@@ -183,7 +189,7 @@ static void exynos_adc_v1_init_hw(struct exynos_adc *info)
183 u32 con1; 189 u32 con1;
184 190
185 if (info->data->needs_adc_phy) 191 if (info->data->needs_adc_phy)
186 writel(1, info->enable_reg); 192 regmap_write(info->pmu_map, info->data->phy_offset, 1);
187 193
188 /* set default prescaler values and Enable prescaler */ 194 /* set default prescaler values and Enable prescaler */
189 con1 = ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN; 195 con1 = ADC_V1_CON_PRSCLV(49) | ADC_V1_CON_PRSCEN;
@@ -198,7 +204,7 @@ static void exynos_adc_v1_exit_hw(struct exynos_adc *info)
198 u32 con; 204 u32 con;
199 205
200 if (info->data->needs_adc_phy) 206 if (info->data->needs_adc_phy)
201 writel(0, info->enable_reg); 207 regmap_write(info->pmu_map, info->data->phy_offset, 0);
202 208
203 con = readl(ADC_V1_CON(info->regs)); 209 con = readl(ADC_V1_CON(info->regs));
204 con |= ADC_V1_CON_STANDBY; 210 con |= ADC_V1_CON_STANDBY;
@@ -225,6 +231,7 @@ static const struct exynos_adc_data exynos_adc_v1_data = {
225 .num_channels = MAX_ADC_V1_CHANNELS, 231 .num_channels = MAX_ADC_V1_CHANNELS,
226 .mask = ADC_DATX_MASK, /* 12 bit ADC resolution */ 232 .mask = ADC_DATX_MASK, /* 12 bit ADC resolution */
227 .needs_adc_phy = true, 233 .needs_adc_phy = true,
234 .phy_offset = EXYNOS_ADCV1_PHY_OFFSET,
228 235
229 .init_hw = exynos_adc_v1_init_hw, 236 .init_hw = exynos_adc_v1_init_hw,
230 .exit_hw = exynos_adc_v1_exit_hw, 237 .exit_hw = exynos_adc_v1_exit_hw,
@@ -314,7 +321,7 @@ static void exynos_adc_v2_init_hw(struct exynos_adc *info)
314 u32 con1, con2; 321 u32 con1, con2;
315 322
316 if (info->data->needs_adc_phy) 323 if (info->data->needs_adc_phy)
317 writel(1, info->enable_reg); 324 regmap_write(info->pmu_map, info->data->phy_offset, 1);
318 325
319 con1 = ADC_V2_CON1_SOFT_RESET; 326 con1 = ADC_V2_CON1_SOFT_RESET;
320 writel(con1, ADC_V2_CON1(info->regs)); 327 writel(con1, ADC_V2_CON1(info->regs));
@@ -332,7 +339,7 @@ static void exynos_adc_v2_exit_hw(struct exynos_adc *info)
332 u32 con; 339 u32 con;
333 340
334 if (info->data->needs_adc_phy) 341 if (info->data->needs_adc_phy)
335 writel(0, info->enable_reg); 342 regmap_write(info->pmu_map, info->data->phy_offset, 0);
336 343
337 con = readl(ADC_V2_CON1(info->regs)); 344 con = readl(ADC_V2_CON1(info->regs));
338 con &= ~ADC_CON_EN_START; 345 con &= ~ADC_CON_EN_START;
@@ -362,6 +369,7 @@ static const struct exynos_adc_data exynos_adc_v2_data = {
362 .num_channels = MAX_ADC_V2_CHANNELS, 369 .num_channels = MAX_ADC_V2_CHANNELS,
363 .mask = ADC_DATX_MASK, /* 12 bit ADC resolution */ 370 .mask = ADC_DATX_MASK, /* 12 bit ADC resolution */
364 .needs_adc_phy = true, 371 .needs_adc_phy = true,
372 .phy_offset = EXYNOS_ADCV2_PHY_OFFSET,
365 373
366 .init_hw = exynos_adc_v2_init_hw, 374 .init_hw = exynos_adc_v2_init_hw,
367 .exit_hw = exynos_adc_v2_exit_hw, 375 .exit_hw = exynos_adc_v2_exit_hw,
@@ -374,6 +382,7 @@ static const struct exynos_adc_data exynos3250_adc_data = {
374 .mask = ADC_DATX_MASK, /* 12 bit ADC resolution */ 382 .mask = ADC_DATX_MASK, /* 12 bit ADC resolution */
375 .needs_sclk = true, 383 .needs_sclk = true,
376 .needs_adc_phy = true, 384 .needs_adc_phy = true,
385 .phy_offset = EXYNOS_ADCV1_PHY_OFFSET,
377 386
378 .init_hw = exynos_adc_v2_init_hw, 387 .init_hw = exynos_adc_v2_init_hw,
379 .exit_hw = exynos_adc_v2_exit_hw, 388 .exit_hw = exynos_adc_v2_exit_hw,
@@ -381,6 +390,35 @@ static const struct exynos_adc_data exynos3250_adc_data = {
381 .start_conv = exynos_adc_v2_start_conv, 390 .start_conv = exynos_adc_v2_start_conv,
382}; 391};
383 392
393static void exynos_adc_exynos7_init_hw(struct exynos_adc *info)
394{
395 u32 con1, con2;
396
397 if (info->data->needs_adc_phy)
398 regmap_write(info->pmu_map, info->data->phy_offset, 1);
399
400 con1 = ADC_V2_CON1_SOFT_RESET;
401 writel(con1, ADC_V2_CON1(info->regs));
402
403 con2 = readl(ADC_V2_CON2(info->regs));
404 con2 &= ~ADC_V2_CON2_C_TIME(7);
405 con2 |= ADC_V2_CON2_C_TIME(0);
406 writel(con2, ADC_V2_CON2(info->regs));
407
408 /* Enable interrupts */
409 writel(1, ADC_V2_INT_EN(info->regs));
410}
411
412static const struct exynos_adc_data exynos7_adc_data = {
413 .num_channels = MAX_ADC_V1_CHANNELS,
414 .mask = ADC_DATX_MASK, /* 12 bit ADC resolution */
415
416 .init_hw = exynos_adc_exynos7_init_hw,
417 .exit_hw = exynos_adc_v2_exit_hw,
418 .clear_irq = exynos_adc_v2_clear_irq,
419 .start_conv = exynos_adc_v2_start_conv,
420};
421
384static const struct of_device_id exynos_adc_match[] = { 422static const struct of_device_id exynos_adc_match[] = {
385 { 423 {
386 .compatible = "samsung,s3c2410-adc", 424 .compatible = "samsung,s3c2410-adc",
@@ -406,6 +444,9 @@ static const struct of_device_id exynos_adc_match[] = {
406 }, { 444 }, {
407 .compatible = "samsung,exynos3250-adc", 445 .compatible = "samsung,exynos3250-adc",
408 .data = &exynos3250_adc_data, 446 .data = &exynos3250_adc_data,
447 }, {
448 .compatible = "samsung,exynos7-adc",
449 .data = &exynos7_adc_data,
409 }, 450 },
410 {}, 451 {},
411}; 452};
@@ -558,10 +599,13 @@ static int exynos_adc_probe(struct platform_device *pdev)
558 599
559 600
560 if (info->data->needs_adc_phy) { 601 if (info->data->needs_adc_phy) {
561 mem = platform_get_resource(pdev, IORESOURCE_MEM, 1); 602 info->pmu_map = syscon_regmap_lookup_by_phandle(
562 info->enable_reg = devm_ioremap_resource(&pdev->dev, mem); 603 pdev->dev.of_node,
563 if (IS_ERR(info->enable_reg)) 604 "samsung,syscon-phandle");
564 return PTR_ERR(info->enable_reg); 605 if (IS_ERR(info->pmu_map)) {
606 dev_err(&pdev->dev, "syscon regmap lookup failed.\n");
607 return PTR_ERR(info->pmu_map);
608 }
565 } 609 }
566 610
567 irq = platform_get_irq(pdev, 0); 611 irq = platform_get_irq(pdev, 0);
diff --git a/drivers/iio/adc/mcp320x.c b/drivers/iio/adc/mcp320x.c
index 28a086e48776..efbfd12a4bfd 100644
--- a/drivers/iio/adc/mcp320x.c
+++ b/drivers/iio/adc/mcp320x.c
@@ -1,9 +1,30 @@
1/* 1/*
2 * Copyright (C) 2013 Oskar Andero <oskar.andero@gmail.com> 2 * Copyright (C) 2013 Oskar Andero <oskar.andero@gmail.com>
3 * Copyright (C) 2014 Rose Technology
4 * Allan Bendorff Jensen <abj@rosetechnology.dk>
5 * Soren Andersen <san@rosetechnology.dk>
6 *
7 * Driver for following ADC chips from Microchip Technology's:
8 * 10 Bit converter
9 * MCP3001
10 * MCP3002
11 * MCP3004
12 * MCP3008
13 * ------------
14 * 12 bit converter
15 * MCP3201
16 * MCP3202
17 * MCP3204
18 * MCP3208
19 * ------------
3 * 20 *
4 * Driver for Microchip Technology's MCP3204 and MCP3208 ADC chips.
5 * Datasheet can be found here: 21 * Datasheet can be found here:
6 * http://ww1.microchip.com/downloads/en/devicedoc/21298c.pdf 22 * http://ww1.microchip.com/downloads/en/DeviceDoc/21293C.pdf mcp3001
23 * http://ww1.microchip.com/downloads/en/DeviceDoc/21294E.pdf mcp3002
24 * http://ww1.microchip.com/downloads/en/DeviceDoc/21295d.pdf mcp3004/08
25 * http://ww1.microchip.com/downloads/en/DeviceDoc/21290D.pdf mcp3201
26 * http://ww1.microchip.com/downloads/en/DeviceDoc/21034D.pdf mcp3202
27 * http://ww1.microchip.com/downloads/en/DeviceDoc/21298c.pdf mcp3204/08
7 * 28 *
8 * This program is free software; you can redistribute it and/or modify 29 * 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 30 * it under the terms of the GNU General Public License version 2 as
@@ -11,19 +32,29 @@
11 */ 32 */
12 33
13#include <linux/err.h> 34#include <linux/err.h>
35#include <linux/delay.h>
14#include <linux/spi/spi.h> 36#include <linux/spi/spi.h>
15#include <linux/module.h> 37#include <linux/module.h>
16#include <linux/iio/iio.h> 38#include <linux/iio/iio.h>
17#include <linux/regulator/consumer.h> 39#include <linux/regulator/consumer.h>
18 40
19#define MCP_SINGLE_ENDED (1 << 3)
20#define MCP_START_BIT (1 << 4)
21
22enum { 41enum {
42 mcp3001,
43 mcp3002,
44 mcp3004,
45 mcp3008,
46 mcp3201,
47 mcp3202,
23 mcp3204, 48 mcp3204,
24 mcp3208, 49 mcp3208,
25}; 50};
26 51
52struct mcp320x_chip_info {
53 const struct iio_chan_spec *channels;
54 unsigned int num_channels;
55 unsigned int resolution;
56};
57
27struct mcp320x { 58struct mcp320x {
28 struct spi_device *spi; 59 struct spi_device *spi;
29 struct spi_message msg; 60 struct spi_message msg;
@@ -34,19 +65,69 @@ struct mcp320x {
34 65
35 struct regulator *reg; 66 struct regulator *reg;
36 struct mutex lock; 67 struct mutex lock;
68 const struct mcp320x_chip_info *chip_info;
37}; 69};
38 70
39static int mcp320x_adc_conversion(struct mcp320x *adc, u8 msg) 71static int mcp320x_channel_to_tx_data(int device_index,
72 const unsigned int channel, bool differential)
73{
74 int start_bit = 1;
75
76 switch (device_index) {
77 case mcp3001:
78 case mcp3201:
79 return 0;
80 case mcp3002:
81 case mcp3202:
82 return ((start_bit << 4) | (!differential << 3) |
83 (channel << 2));
84 case mcp3004:
85 case mcp3204:
86 case mcp3008:
87 case mcp3208:
88 return ((start_bit << 6) | (!differential << 5) |
89 (channel << 2));
90 default:
91 return -EINVAL;
92 }
93}
94
95static int mcp320x_adc_conversion(struct mcp320x *adc, u8 channel,
96 bool differential, int device_index)
40{ 97{
41 int ret; 98 int ret;
42 99
43 adc->tx_buf = msg; 100 adc->rx_buf[0] = 0;
44 ret = spi_sync(adc->spi, &adc->msg); 101 adc->rx_buf[1] = 0;
45 if (ret < 0) 102 adc->tx_buf = mcp320x_channel_to_tx_data(device_index,
46 return ret; 103 channel, differential);
104
105 if (device_index != mcp3001 && device_index != mcp3201) {
106 ret = spi_sync(adc->spi, &adc->msg);
107 if (ret < 0)
108 return ret;
109 } else {
110 ret = spi_read(adc->spi, &adc->rx_buf, sizeof(adc->rx_buf));
111 if (ret < 0)
112 return ret;
113 }
47 114
48 return ((adc->rx_buf[0] & 0x3f) << 6) | 115 switch (device_index) {
49 (adc->rx_buf[1] >> 2); 116 case mcp3001:
117 return (adc->rx_buf[0] << 5 | adc->rx_buf[1] >> 3);
118 case mcp3002:
119 case mcp3004:
120 case mcp3008:
121 return (adc->rx_buf[0] << 2 | adc->rx_buf[1] >> 6);
122 case mcp3201:
123 return (adc->rx_buf[0] << 7 | adc->rx_buf[1] >> 1);
124 case mcp3202:
125 case mcp3204:
126 case mcp3208:
127 return (adc->rx_buf[0] << 4 | adc->rx_buf[1] >> 4);
128 default:
129 return -EINVAL;
130 }
50} 131}
51 132
52static int mcp320x_read_raw(struct iio_dev *indio_dev, 133static int mcp320x_read_raw(struct iio_dev *indio_dev,
@@ -55,18 +136,17 @@ static int mcp320x_read_raw(struct iio_dev *indio_dev,
55{ 136{
56 struct mcp320x *adc = iio_priv(indio_dev); 137 struct mcp320x *adc = iio_priv(indio_dev);
57 int ret = -EINVAL; 138 int ret = -EINVAL;
139 int device_index = 0;
58 140
59 mutex_lock(&adc->lock); 141 mutex_lock(&adc->lock);
60 142
143 device_index = spi_get_device_id(adc->spi)->driver_data;
144
61 switch (mask) { 145 switch (mask) {
62 case IIO_CHAN_INFO_RAW: 146 case IIO_CHAN_INFO_RAW:
63 if (channel->differential) 147 ret = mcp320x_adc_conversion(adc, channel->address,
64 ret = mcp320x_adc_conversion(adc, 148 channel->differential, device_index);
65 MCP_START_BIT | channel->address); 149
66 else
67 ret = mcp320x_adc_conversion(adc,
68 MCP_START_BIT | MCP_SINGLE_ENDED |
69 channel->address);
70 if (ret < 0) 150 if (ret < 0)
71 goto out; 151 goto out;
72 152
@@ -75,18 +155,15 @@ static int mcp320x_read_raw(struct iio_dev *indio_dev,
75 break; 155 break;
76 156
77 case IIO_CHAN_INFO_SCALE: 157 case IIO_CHAN_INFO_SCALE:
78 /* Digital output code = (4096 * Vin) / Vref */
79 ret = regulator_get_voltage(adc->reg); 158 ret = regulator_get_voltage(adc->reg);
80 if (ret < 0) 159 if (ret < 0)
81 goto out; 160 goto out;
82 161
162 /* convert regulator output voltage to mV */
83 *val = ret / 1000; 163 *val = ret / 1000;
84 *val2 = 12; 164 *val2 = adc->chip_info->resolution;
85 ret = IIO_VAL_FRACTIONAL_LOG2; 165 ret = IIO_VAL_FRACTIONAL_LOG2;
86 break; 166 break;
87
88 default:
89 break;
90 } 167 }
91 168
92out: 169out:
@@ -117,6 +194,16 @@ out:
117 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) \ 194 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) \
118 } 195 }
119 196
197static const struct iio_chan_spec mcp3201_channels[] = {
198 MCP320X_VOLTAGE_CHANNEL_DIFF(0),
199};
200
201static const struct iio_chan_spec mcp3202_channels[] = {
202 MCP320X_VOLTAGE_CHANNEL(0),
203 MCP320X_VOLTAGE_CHANNEL(1),
204 MCP320X_VOLTAGE_CHANNEL_DIFF(0),
205};
206
120static const struct iio_chan_spec mcp3204_channels[] = { 207static const struct iio_chan_spec mcp3204_channels[] = {
121 MCP320X_VOLTAGE_CHANNEL(0), 208 MCP320X_VOLTAGE_CHANNEL(0),
122 MCP320X_VOLTAGE_CHANNEL(1), 209 MCP320X_VOLTAGE_CHANNEL(1),
@@ -146,19 +233,46 @@ static const struct iio_info mcp320x_info = {
146 .driver_module = THIS_MODULE, 233 .driver_module = THIS_MODULE,
147}; 234};
148 235
149struct mcp3208_chip_info { 236static const struct mcp320x_chip_info mcp320x_chip_infos[] = {
150 const struct iio_chan_spec *channels; 237 [mcp3001] = {
151 unsigned int num_channels; 238 .channels = mcp3201_channels,
152}; 239 .num_channels = ARRAY_SIZE(mcp3201_channels),
153 240 .resolution = 10
154static const struct mcp3208_chip_info mcp3208_chip_infos[] = { 241 },
242 [mcp3002] = {
243 .channels = mcp3202_channels,
244 .num_channels = ARRAY_SIZE(mcp3202_channels),
245 .resolution = 10
246 },
247 [mcp3004] = {
248 .channels = mcp3204_channels,
249 .num_channels = ARRAY_SIZE(mcp3204_channels),
250 .resolution = 10
251 },
252 [mcp3008] = {
253 .channels = mcp3208_channels,
254 .num_channels = ARRAY_SIZE(mcp3208_channels),
255 .resolution = 10
256 },
257 [mcp3201] = {
258 .channels = mcp3201_channels,
259 .num_channels = ARRAY_SIZE(mcp3201_channels),
260 .resolution = 12
261 },
262 [mcp3202] = {
263 .channels = mcp3202_channels,
264 .num_channels = ARRAY_SIZE(mcp3202_channels),
265 .resolution = 12
266 },
155 [mcp3204] = { 267 [mcp3204] = {
156 .channels = mcp3204_channels, 268 .channels = mcp3204_channels,
157 .num_channels = ARRAY_SIZE(mcp3204_channels) 269 .num_channels = ARRAY_SIZE(mcp3204_channels),
270 .resolution = 12
158 }, 271 },
159 [mcp3208] = { 272 [mcp3208] = {
160 .channels = mcp3208_channels, 273 .channels = mcp3208_channels,
161 .num_channels = ARRAY_SIZE(mcp3208_channels) 274 .num_channels = ARRAY_SIZE(mcp3208_channels),
275 .resolution = 12
162 }, 276 },
163}; 277};
164 278
@@ -166,7 +280,7 @@ static int mcp320x_probe(struct spi_device *spi)
166{ 280{
167 struct iio_dev *indio_dev; 281 struct iio_dev *indio_dev;
168 struct mcp320x *adc; 282 struct mcp320x *adc;
169 const struct mcp3208_chip_info *chip_info; 283 const struct mcp320x_chip_info *chip_info;
170 int ret; 284 int ret;
171 285
172 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc)); 286 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*adc));
@@ -181,7 +295,7 @@ static int mcp320x_probe(struct spi_device *spi)
181 indio_dev->modes = INDIO_DIRECT_MODE; 295 indio_dev->modes = INDIO_DIRECT_MODE;
182 indio_dev->info = &mcp320x_info; 296 indio_dev->info = &mcp320x_info;
183 297
184 chip_info = &mcp3208_chip_infos[spi_get_device_id(spi)->driver_data]; 298 chip_info = &mcp320x_chip_infos[spi_get_device_id(spi)->driver_data];
185 indio_dev->channels = chip_info->channels; 299 indio_dev->channels = chip_info->channels;
186 indio_dev->num_channels = chip_info->num_channels; 300 indio_dev->num_channels = chip_info->num_channels;
187 301
@@ -226,7 +340,45 @@ static int mcp320x_remove(struct spi_device *spi)
226 return 0; 340 return 0;
227} 341}
228 342
343#if defined(CONFIG_OF)
344static const struct of_device_id mcp320x_dt_ids[] = {
345 {
346 .compatible = "mcp3001",
347 .data = &mcp320x_chip_infos[mcp3001],
348 }, {
349 .compatible = "mcp3002",
350 .data = &mcp320x_chip_infos[mcp3002],
351 }, {
352 .compatible = "mcp3004",
353 .data = &mcp320x_chip_infos[mcp3004],
354 }, {
355 .compatible = "mcp3008",
356 .data = &mcp320x_chip_infos[mcp3008],
357 }, {
358 .compatible = "mcp3201",
359 .data = &mcp320x_chip_infos[mcp3201],
360 }, {
361 .compatible = "mcp3202",
362 .data = &mcp320x_chip_infos[mcp3202],
363 }, {
364 .compatible = "mcp3204",
365 .data = &mcp320x_chip_infos[mcp3204],
366 }, {
367 .compatible = "mcp3208",
368 .data = &mcp320x_chip_infos[mcp3208],
369 }, {
370 }
371};
372MODULE_DEVICE_TABLE(of, mcp320x_dt_ids);
373#endif
374
229static const struct spi_device_id mcp320x_id[] = { 375static const struct spi_device_id mcp320x_id[] = {
376 { "mcp3001", mcp3001 },
377 { "mcp3002", mcp3002 },
378 { "mcp3004", mcp3004 },
379 { "mcp3008", mcp3008 },
380 { "mcp3201", mcp3201 },
381 { "mcp3202", mcp3202 },
230 { "mcp3204", mcp3204 }, 382 { "mcp3204", mcp3204 },
231 { "mcp3208", mcp3208 }, 383 { "mcp3208", mcp3208 },
232 { } 384 { }
@@ -245,5 +397,5 @@ static struct spi_driver mcp320x_driver = {
245module_spi_driver(mcp320x_driver); 397module_spi_driver(mcp320x_driver);
246 398
247MODULE_AUTHOR("Oskar Andero <oskar.andero@gmail.com>"); 399MODULE_AUTHOR("Oskar Andero <oskar.andero@gmail.com>");
248MODULE_DESCRIPTION("Microchip Technology MCP3204/08"); 400MODULE_DESCRIPTION("Microchip Technology MCP3x01/02/04/08");
249MODULE_LICENSE("GPL v2"); 401MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/adc/qcom-spmi-iadc.c b/drivers/iio/adc/qcom-spmi-iadc.c
new file mode 100644
index 000000000000..b9666f2f5e51
--- /dev/null
+++ b/drivers/iio/adc/qcom-spmi-iadc.c
@@ -0,0 +1,595 @@
1/*
2 * Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#include <linux/bitops.h>
15#include <linux/completion.h>
16#include <linux/delay.h>
17#include <linux/err.h>
18#include <linux/iio/iio.h>
19#include <linux/interrupt.h>
20#include <linux/kernel.h>
21#include <linux/mutex.h>
22#include <linux/module.h>
23#include <linux/of.h>
24#include <linux/of_device.h>
25#include <linux/platform_device.h>
26#include <linux/regmap.h>
27#include <linux/slab.h>
28
29/* IADC register and bit definition */
30#define IADC_REVISION2 0x1
31#define IADC_REVISION2_SUPPORTED_IADC 1
32
33#define IADC_PERPH_TYPE 0x4
34#define IADC_PERPH_TYPE_ADC 8
35
36#define IADC_PERPH_SUBTYPE 0x5
37#define IADC_PERPH_SUBTYPE_IADC 3
38
39#define IADC_STATUS1 0x8
40#define IADC_STATUS1_OP_MODE 4
41#define IADC_STATUS1_REQ_STS BIT(1)
42#define IADC_STATUS1_EOC BIT(0)
43#define IADC_STATUS1_REQ_STS_EOC_MASK 0x3
44
45#define IADC_MODE_CTL 0x40
46#define IADC_OP_MODE_SHIFT 3
47#define IADC_OP_MODE_NORMAL 0
48#define IADC_TRIM_EN BIT(0)
49
50#define IADC_EN_CTL1 0x46
51#define IADC_EN_CTL1_SET BIT(7)
52
53#define IADC_CH_SEL_CTL 0x48
54
55#define IADC_DIG_PARAM 0x50
56#define IADC_DIG_DEC_RATIO_SEL_SHIFT 2
57
58#define IADC_HW_SETTLE_DELAY 0x51
59
60#define IADC_CONV_REQ 0x52
61#define IADC_CONV_REQ_SET BIT(7)
62
63#define IADC_FAST_AVG_CTL 0x5a
64#define IADC_FAST_AVG_EN 0x5b
65#define IADC_FAST_AVG_EN_SET BIT(7)
66
67#define IADC_PERH_RESET_CTL3 0xda
68#define IADC_FOLLOW_WARM_RB BIT(2)
69
70#define IADC_DATA 0x60 /* 16 bits */
71
72#define IADC_SEC_ACCESS 0xd0
73#define IADC_SEC_ACCESS_DATA 0xa5
74
75#define IADC_NOMINAL_RSENSE 0xf4
76#define IADC_NOMINAL_RSENSE_SIGN_MASK BIT(7)
77
78#define IADC_REF_GAIN_MICRO_VOLTS 17857
79
80#define IADC_INT_RSENSE_DEVIATION 15625 /* nano Ohms per bit */
81
82#define IADC_INT_RSENSE_IDEAL_VALUE 10000 /* micro Ohms */
83#define IADC_INT_RSENSE_DEFAULT_VALUE 7800 /* micro Ohms */
84#define IADC_INT_RSENSE_DEFAULT_GF 9000 /* micro Ohms */
85#define IADC_INT_RSENSE_DEFAULT_SMIC 9700 /* micro Ohms */
86
87#define IADC_CONV_TIME_MIN_US 2000
88#define IADC_CONV_TIME_MAX_US 2100
89
90#define IADC_DEF_PRESCALING 0 /* 1:1 */
91#define IADC_DEF_DECIMATION 0 /* 512 */
92#define IADC_DEF_HW_SETTLE_TIME 0 /* 0 us */
93#define IADC_DEF_AVG_SAMPLES 0 /* 1 sample */
94
95/* IADC channel list */
96#define IADC_INT_RSENSE 0
97#define IADC_EXT_RSENSE 1
98#define IADC_GAIN_17P857MV 3
99#define IADC_EXT_OFFSET_CSP_CSN 5
100#define IADC_INT_OFFSET_CSP2_CSN2 6
101
102/**
103 * struct iadc_chip - IADC Current ADC device structure.
104 * @regmap: regmap for register read/write.
105 * @dev: This device pointer.
106 * @base: base offset for the ADC peripheral.
107 * @rsense: Values of the internal and external sense resister in micro Ohms.
108 * @poll_eoc: Poll for end of conversion instead of waiting for IRQ.
109 * @offset: Raw offset values for the internal and external channels.
110 * @gain: Raw gain of the channels.
111 * @lock: ADC lock for access to the peripheral.
112 * @complete: ADC notification after end of conversion interrupt is received.
113 */
114struct iadc_chip {
115 struct regmap *regmap;
116 struct device *dev;
117 u16 base;
118 bool poll_eoc;
119 u32 rsense[2];
120 u16 offset[2];
121 u16 gain;
122 struct mutex lock;
123 struct completion complete;
124};
125
126static int iadc_read(struct iadc_chip *iadc, u16 offset, u8 *data)
127{
128 unsigned int val;
129 int ret;
130
131 ret = regmap_read(iadc->regmap, iadc->base + offset, &val);
132 if (ret < 0)
133 return ret;
134
135 *data = val;
136 return 0;
137}
138
139static int iadc_write(struct iadc_chip *iadc, u16 offset, u8 data)
140{
141 return regmap_write(iadc->regmap, iadc->base + offset, data);
142}
143
144static int iadc_reset(struct iadc_chip *iadc)
145{
146 u8 data;
147 int ret;
148
149 ret = iadc_write(iadc, IADC_SEC_ACCESS, IADC_SEC_ACCESS_DATA);
150 if (ret < 0)
151 return ret;
152
153 ret = iadc_read(iadc, IADC_PERH_RESET_CTL3, &data);
154 if (ret < 0)
155 return ret;
156
157 ret = iadc_write(iadc, IADC_SEC_ACCESS, IADC_SEC_ACCESS_DATA);
158 if (ret < 0)
159 return ret;
160
161 data |= IADC_FOLLOW_WARM_RB;
162
163 return iadc_write(iadc, IADC_PERH_RESET_CTL3, data);
164}
165
166static int iadc_set_state(struct iadc_chip *iadc, bool state)
167{
168 return iadc_write(iadc, IADC_EN_CTL1, state ? IADC_EN_CTL1_SET : 0);
169}
170
171static void iadc_status_show(struct iadc_chip *iadc)
172{
173 u8 mode, sta1, chan, dig, en, req;
174 int ret;
175
176 ret = iadc_read(iadc, IADC_MODE_CTL, &mode);
177 if (ret < 0)
178 return;
179
180 ret = iadc_read(iadc, IADC_DIG_PARAM, &dig);
181 if (ret < 0)
182 return;
183
184 ret = iadc_read(iadc, IADC_CH_SEL_CTL, &chan);
185 if (ret < 0)
186 return;
187
188 ret = iadc_read(iadc, IADC_CONV_REQ, &req);
189 if (ret < 0)
190 return;
191
192 ret = iadc_read(iadc, IADC_STATUS1, &sta1);
193 if (ret < 0)
194 return;
195
196 ret = iadc_read(iadc, IADC_EN_CTL1, &en);
197 if (ret < 0)
198 return;
199
200 dev_err(iadc->dev,
201 "mode:%02x en:%02x chan:%02x dig:%02x req:%02x sta1:%02x\n",
202 mode, en, chan, dig, req, sta1);
203}
204
205static int iadc_configure(struct iadc_chip *iadc, int channel)
206{
207 u8 decim, mode;
208 int ret;
209
210 /* Mode selection */
211 mode = (IADC_OP_MODE_NORMAL << IADC_OP_MODE_SHIFT) | IADC_TRIM_EN;
212 ret = iadc_write(iadc, IADC_MODE_CTL, mode);
213 if (ret < 0)
214 return ret;
215
216 /* Channel selection */
217 ret = iadc_write(iadc, IADC_CH_SEL_CTL, channel);
218 if (ret < 0)
219 return ret;
220
221 /* Digital parameter setup */
222 decim = IADC_DEF_DECIMATION << IADC_DIG_DEC_RATIO_SEL_SHIFT;
223 ret = iadc_write(iadc, IADC_DIG_PARAM, decim);
224 if (ret < 0)
225 return ret;
226
227 /* HW settle time delay */
228 ret = iadc_write(iadc, IADC_HW_SETTLE_DELAY, IADC_DEF_HW_SETTLE_TIME);
229 if (ret < 0)
230 return ret;
231
232 ret = iadc_write(iadc, IADC_FAST_AVG_CTL, IADC_DEF_AVG_SAMPLES);
233 if (ret < 0)
234 return ret;
235
236 if (IADC_DEF_AVG_SAMPLES)
237 ret = iadc_write(iadc, IADC_FAST_AVG_EN, IADC_FAST_AVG_EN_SET);
238 else
239 ret = iadc_write(iadc, IADC_FAST_AVG_EN, 0);
240
241 if (ret < 0)
242 return ret;
243
244 if (!iadc->poll_eoc)
245 reinit_completion(&iadc->complete);
246
247 ret = iadc_set_state(iadc, true);
248 if (ret < 0)
249 return ret;
250
251 /* Request conversion */
252 return iadc_write(iadc, IADC_CONV_REQ, IADC_CONV_REQ_SET);
253}
254
255static int iadc_poll_wait_eoc(struct iadc_chip *iadc, unsigned int interval_us)
256{
257 unsigned int count, retry;
258 int ret;
259 u8 sta1;
260
261 retry = interval_us / IADC_CONV_TIME_MIN_US;
262
263 for (count = 0; count < retry; count++) {
264 ret = iadc_read(iadc, IADC_STATUS1, &sta1);
265 if (ret < 0)
266 return ret;
267
268 sta1 &= IADC_STATUS1_REQ_STS_EOC_MASK;
269 if (sta1 == IADC_STATUS1_EOC)
270 return 0;
271
272 usleep_range(IADC_CONV_TIME_MIN_US, IADC_CONV_TIME_MAX_US);
273 }
274
275 iadc_status_show(iadc);
276
277 return -ETIMEDOUT;
278}
279
280static int iadc_read_result(struct iadc_chip *iadc, u16 *data)
281{
282 return regmap_bulk_read(iadc->regmap, iadc->base + IADC_DATA, data, 2);
283}
284
285static int iadc_do_conversion(struct iadc_chip *iadc, int chan, u16 *data)
286{
287 unsigned int wait;
288 int ret;
289
290 ret = iadc_configure(iadc, chan);
291 if (ret < 0)
292 goto exit;
293
294 wait = BIT(IADC_DEF_AVG_SAMPLES) * IADC_CONV_TIME_MIN_US * 2;
295
296 if (iadc->poll_eoc) {
297 ret = iadc_poll_wait_eoc(iadc, wait);
298 } else {
299 ret = wait_for_completion_timeout(&iadc->complete, wait);
300 if (!ret)
301 ret = -ETIMEDOUT;
302 else
303 /* double check conversion status */
304 ret = iadc_poll_wait_eoc(iadc, IADC_CONV_TIME_MIN_US);
305 }
306
307 if (!ret)
308 ret = iadc_read_result(iadc, data);
309exit:
310 iadc_set_state(iadc, false);
311 if (ret < 0)
312 dev_err(iadc->dev, "conversion failed\n");
313
314 return ret;
315}
316
317static int iadc_read_raw(struct iio_dev *indio_dev,
318 struct iio_chan_spec const *chan,
319 int *val, int *val2, long mask)
320{
321 struct iadc_chip *iadc = iio_priv(indio_dev);
322 s32 isense_ua, vsense_uv;
323 u16 adc_raw, vsense_raw;
324 int ret;
325
326 switch (mask) {
327 case IIO_CHAN_INFO_RAW:
328 mutex_lock(&iadc->lock);
329 ret = iadc_do_conversion(iadc, chan->channel, &adc_raw);
330 mutex_unlock(&iadc->lock);
331 if (ret < 0)
332 return ret;
333
334 vsense_raw = adc_raw - iadc->offset[chan->channel];
335
336 vsense_uv = vsense_raw * IADC_REF_GAIN_MICRO_VOLTS;
337 vsense_uv /= (s32)iadc->gain - iadc->offset[chan->channel];
338
339 isense_ua = vsense_uv / iadc->rsense[chan->channel];
340
341 dev_dbg(iadc->dev, "off %d gain %d adc %d %duV I %duA\n",
342 iadc->offset[chan->channel], iadc->gain,
343 adc_raw, vsense_uv, isense_ua);
344
345 *val = isense_ua;
346 return IIO_VAL_INT;
347 case IIO_CHAN_INFO_SCALE:
348 *val = 0;
349 *val2 = 1000;
350 return IIO_VAL_INT_PLUS_MICRO;
351 }
352
353 return -EINVAL;
354}
355
356static const struct iio_info iadc_info = {
357 .read_raw = iadc_read_raw,
358 .driver_module = THIS_MODULE,
359};
360
361static irqreturn_t iadc_isr(int irq, void *dev_id)
362{
363 struct iadc_chip *iadc = dev_id;
364
365 complete(&iadc->complete);
366
367 return IRQ_HANDLED;
368}
369
370static int iadc_update_offset(struct iadc_chip *iadc)
371{
372 int ret;
373
374 ret = iadc_do_conversion(iadc, IADC_GAIN_17P857MV, &iadc->gain);
375 if (ret < 0)
376 return ret;
377
378 ret = iadc_do_conversion(iadc, IADC_INT_OFFSET_CSP2_CSN2,
379 &iadc->offset[IADC_INT_RSENSE]);
380 if (ret < 0)
381 return ret;
382
383 if (iadc->gain == iadc->offset[IADC_INT_RSENSE]) {
384 dev_err(iadc->dev, "error: internal offset == gain %d\n",
385 iadc->gain);
386 return -EINVAL;
387 }
388
389 ret = iadc_do_conversion(iadc, IADC_EXT_OFFSET_CSP_CSN,
390 &iadc->offset[IADC_EXT_RSENSE]);
391 if (ret < 0)
392 return ret;
393
394 if (iadc->gain == iadc->offset[IADC_EXT_RSENSE]) {
395 dev_err(iadc->dev, "error: external offset == gain %d\n",
396 iadc->gain);
397 return -EINVAL;
398 }
399
400 return 0;
401}
402
403static int iadc_version_check(struct iadc_chip *iadc)
404{
405 u8 val;
406 int ret;
407
408 ret = iadc_read(iadc, IADC_PERPH_TYPE, &val);
409 if (ret < 0)
410 return ret;
411
412 if (val < IADC_PERPH_TYPE_ADC) {
413 dev_err(iadc->dev, "%d is not ADC\n", val);
414 return -EINVAL;
415 }
416
417 ret = iadc_read(iadc, IADC_PERPH_SUBTYPE, &val);
418 if (ret < 0)
419 return ret;
420
421 if (val < IADC_PERPH_SUBTYPE_IADC) {
422 dev_err(iadc->dev, "%d is not IADC\n", val);
423 return -EINVAL;
424 }
425
426 ret = iadc_read(iadc, IADC_REVISION2, &val);
427 if (ret < 0)
428 return ret;
429
430 if (val < IADC_REVISION2_SUPPORTED_IADC) {
431 dev_err(iadc->dev, "revision %d not supported\n", val);
432 return -EINVAL;
433 }
434
435 return 0;
436}
437
438static int iadc_rsense_read(struct iadc_chip *iadc, struct device_node *node)
439{
440 int ret, sign, int_sense;
441 u8 deviation;
442
443 ret = of_property_read_u32(node, "qcom,external-resistor-micro-ohms",
444 &iadc->rsense[IADC_EXT_RSENSE]);
445 if (ret < 0)
446 iadc->rsense[IADC_EXT_RSENSE] = IADC_INT_RSENSE_IDEAL_VALUE;
447
448 if (!iadc->rsense[IADC_EXT_RSENSE]) {
449 dev_err(iadc->dev, "external resistor can't be zero Ohms");
450 return -EINVAL;
451 }
452
453 ret = iadc_read(iadc, IADC_NOMINAL_RSENSE, &deviation);
454 if (ret < 0)
455 return ret;
456
457 /*
458 * Deviation value stored is an offset from 10 mili Ohms, bit 7 is
459 * the sign, the remaining bits have an LSB of 15625 nano Ohms.
460 */
461 sign = (deviation & IADC_NOMINAL_RSENSE_SIGN_MASK) ? -1 : 1;
462
463 deviation &= ~IADC_NOMINAL_RSENSE_SIGN_MASK;
464
465 /* Scale it to nono Ohms */
466 int_sense = IADC_INT_RSENSE_IDEAL_VALUE * 1000;
467 int_sense += sign * deviation * IADC_INT_RSENSE_DEVIATION;
468 int_sense /= 1000; /* micro Ohms */
469
470 iadc->rsense[IADC_INT_RSENSE] = int_sense;
471 return 0;
472}
473
474static const struct iio_chan_spec iadc_channels[] = {
475 {
476 .type = IIO_CURRENT,
477 .datasheet_name = "INTERNAL_RSENSE",
478 .channel = 0,
479 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
480 BIT(IIO_CHAN_INFO_SCALE),
481 .indexed = 1,
482 },
483 {
484 .type = IIO_CURRENT,
485 .datasheet_name = "EXTERNAL_RSENSE",
486 .channel = 1,
487 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
488 BIT(IIO_CHAN_INFO_SCALE),
489 .indexed = 1,
490 },
491};
492
493static int iadc_probe(struct platform_device *pdev)
494{
495 struct device_node *node = pdev->dev.of_node;
496 struct device *dev = &pdev->dev;
497 struct iio_dev *indio_dev;
498 struct iadc_chip *iadc;
499 int ret, irq_eoc;
500 u32 res;
501
502 indio_dev = devm_iio_device_alloc(dev, sizeof(*iadc));
503 if (!indio_dev)
504 return -ENOMEM;
505
506 iadc = iio_priv(indio_dev);
507 iadc->dev = dev;
508
509 iadc->regmap = dev_get_regmap(dev->parent, NULL);
510 if (!iadc->regmap)
511 return -ENODEV;
512
513 init_completion(&iadc->complete);
514 mutex_init(&iadc->lock);
515
516 ret = of_property_read_u32(node, "reg", &res);
517 if (ret < 0)
518 return -ENODEV;
519
520 iadc->base = res;
521
522 ret = iadc_version_check(iadc);
523 if (ret < 0)
524 return -ENODEV;
525
526 ret = iadc_rsense_read(iadc, node);
527 if (ret < 0)
528 return -ENODEV;
529
530 dev_dbg(iadc->dev, "sense resistors %d and %d micro Ohm\n",
531 iadc->rsense[IADC_INT_RSENSE],
532 iadc->rsense[IADC_EXT_RSENSE]);
533
534 irq_eoc = platform_get_irq(pdev, 0);
535 if (irq_eoc == -EPROBE_DEFER)
536 return irq_eoc;
537
538 if (irq_eoc < 0)
539 iadc->poll_eoc = true;
540
541 ret = iadc_reset(iadc);
542 if (ret < 0) {
543 dev_err(dev, "reset failed\n");
544 return ret;
545 }
546
547 if (!iadc->poll_eoc) {
548 ret = devm_request_irq(dev, irq_eoc, iadc_isr, 0,
549 "spmi-iadc", iadc);
550 if (!ret)
551 enable_irq_wake(irq_eoc);
552 else
553 return ret;
554 } else {
555 device_init_wakeup(iadc->dev, 1);
556 }
557
558 ret = iadc_update_offset(iadc);
559 if (ret < 0) {
560 dev_err(dev, "failed offset calibration\n");
561 return ret;
562 }
563
564 indio_dev->dev.parent = dev;
565 indio_dev->dev.of_node = node;
566 indio_dev->name = pdev->name;
567 indio_dev->modes = INDIO_DIRECT_MODE;
568 indio_dev->info = &iadc_info;
569 indio_dev->channels = iadc_channels;
570 indio_dev->num_channels = ARRAY_SIZE(iadc_channels);
571
572 return devm_iio_device_register(dev, indio_dev);
573}
574
575static const struct of_device_id iadc_match_table[] = {
576 { .compatible = "qcom,spmi-iadc" },
577 { }
578};
579
580MODULE_DEVICE_TABLE(of, iadc_match_table);
581
582static struct platform_driver iadc_driver = {
583 .driver = {
584 .name = "qcom-spmi-iadc",
585 .of_match_table = iadc_match_table,
586 },
587 .probe = iadc_probe,
588};
589
590module_platform_driver(iadc_driver);
591
592MODULE_ALIAS("platform:qcom-spmi-iadc");
593MODULE_DESCRIPTION("Qualcomm SPMI PMIC current ADC driver");
594MODULE_LICENSE("GPL v2");
595MODULE_AUTHOR("Ivan T. Ivanov <iivanov@mm-sol.com>");
diff --git a/drivers/iio/adc/rockchip_saradc.c b/drivers/iio/adc/rockchip_saradc.c
index 63a9797775cb..8d4e019ea4ca 100644
--- a/drivers/iio/adc/rockchip_saradc.c
+++ b/drivers/iio/adc/rockchip_saradc.c
@@ -18,13 +18,13 @@
18#include <linux/interrupt.h> 18#include <linux/interrupt.h>
19#include <linux/io.h> 19#include <linux/io.h>
20#include <linux/of.h> 20#include <linux/of.h>
21#include <linux/of_device.h>
21#include <linux/clk.h> 22#include <linux/clk.h>
22#include <linux/completion.h> 23#include <linux/completion.h>
23#include <linux/regulator/consumer.h> 24#include <linux/regulator/consumer.h>
24#include <linux/iio/iio.h> 25#include <linux/iio/iio.h>
25 26
26#define SARADC_DATA 0x00 27#define SARADC_DATA 0x00
27#define SARADC_DATA_MASK 0x3ff
28 28
29#define SARADC_STAS 0x04 29#define SARADC_STAS 0x04
30#define SARADC_STAS_BUSY BIT(0) 30#define SARADC_STAS_BUSY BIT(0)
@@ -38,15 +38,22 @@
38#define SARADC_DLY_PU_SOC 0x0c 38#define SARADC_DLY_PU_SOC 0x0c
39#define SARADC_DLY_PU_SOC_MASK 0x3f 39#define SARADC_DLY_PU_SOC_MASK 0x3f
40 40
41#define SARADC_BITS 10
42#define SARADC_TIMEOUT msecs_to_jiffies(100) 41#define SARADC_TIMEOUT msecs_to_jiffies(100)
43 42
43struct rockchip_saradc_data {
44 int num_bits;
45 const struct iio_chan_spec *channels;
46 int num_channels;
47 unsigned long clk_rate;
48};
49
44struct rockchip_saradc { 50struct rockchip_saradc {
45 void __iomem *regs; 51 void __iomem *regs;
46 struct clk *pclk; 52 struct clk *pclk;
47 struct clk *clk; 53 struct clk *clk;
48 struct completion completion; 54 struct completion completion;
49 struct regulator *vref; 55 struct regulator *vref;
56 const struct rockchip_saradc_data *data;
50 u16 last_val; 57 u16 last_val;
51}; 58};
52 59
@@ -90,7 +97,7 @@ static int rockchip_saradc_read_raw(struct iio_dev *indio_dev,
90 } 97 }
91 98
92 *val = ret / 1000; 99 *val = ret / 1000;
93 *val2 = SARADC_BITS; 100 *val2 = info->data->num_bits;
94 return IIO_VAL_FRACTIONAL_LOG2; 101 return IIO_VAL_FRACTIONAL_LOG2;
95 default: 102 default:
96 return -EINVAL; 103 return -EINVAL;
@@ -103,7 +110,7 @@ static irqreturn_t rockchip_saradc_isr(int irq, void *dev_id)
103 110
104 /* Read value */ 111 /* Read value */
105 info->last_val = readl_relaxed(info->regs + SARADC_DATA); 112 info->last_val = readl_relaxed(info->regs + SARADC_DATA);
106 info->last_val &= SARADC_DATA_MASK; 113 info->last_val &= GENMASK(info->data->num_bits - 1, 0);
107 114
108 /* Clear irq & power down adc */ 115 /* Clear irq & power down adc */
109 writel_relaxed(0, info->regs + SARADC_CTRL); 116 writel_relaxed(0, info->regs + SARADC_CTRL);
@@ -133,12 +140,44 @@ static const struct iio_chan_spec rockchip_saradc_iio_channels[] = {
133 ADC_CHANNEL(2, "adc2"), 140 ADC_CHANNEL(2, "adc2"),
134}; 141};
135 142
143static const struct rockchip_saradc_data saradc_data = {
144 .num_bits = 10,
145 .channels = rockchip_saradc_iio_channels,
146 .num_channels = ARRAY_SIZE(rockchip_saradc_iio_channels),
147 .clk_rate = 1000000,
148};
149
150static const struct iio_chan_spec rockchip_rk3066_tsadc_iio_channels[] = {
151 ADC_CHANNEL(0, "adc0"),
152 ADC_CHANNEL(1, "adc1"),
153};
154
155static const struct rockchip_saradc_data rk3066_tsadc_data = {
156 .num_bits = 12,
157 .channels = rockchip_rk3066_tsadc_iio_channels,
158 .num_channels = ARRAY_SIZE(rockchip_rk3066_tsadc_iio_channels),
159 .clk_rate = 50000,
160};
161
162static const struct of_device_id rockchip_saradc_match[] = {
163 {
164 .compatible = "rockchip,saradc",
165 .data = &saradc_data,
166 }, {
167 .compatible = "rockchip,rk3066-tsadc",
168 .data = &rk3066_tsadc_data,
169 },
170 {},
171};
172MODULE_DEVICE_TABLE(of, rockchip_saradc_match);
173
136static int rockchip_saradc_probe(struct platform_device *pdev) 174static int rockchip_saradc_probe(struct platform_device *pdev)
137{ 175{
138 struct rockchip_saradc *info = NULL; 176 struct rockchip_saradc *info = NULL;
139 struct device_node *np = pdev->dev.of_node; 177 struct device_node *np = pdev->dev.of_node;
140 struct iio_dev *indio_dev = NULL; 178 struct iio_dev *indio_dev = NULL;
141 struct resource *mem; 179 struct resource *mem;
180 const struct of_device_id *match;
142 int ret; 181 int ret;
143 int irq; 182 int irq;
144 183
@@ -152,6 +191,9 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
152 } 191 }
153 info = iio_priv(indio_dev); 192 info = iio_priv(indio_dev);
154 193
194 match = of_match_device(rockchip_saradc_match, &pdev->dev);
195 info->data = match->data;
196
155 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 197 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
156 info->regs = devm_ioremap_resource(&pdev->dev, mem); 198 info->regs = devm_ioremap_resource(&pdev->dev, mem);
157 if (IS_ERR(info->regs)) 199 if (IS_ERR(info->regs))
@@ -192,10 +234,10 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
192 } 234 }
193 235
194 /* 236 /*
195 * Use a default of 1MHz for the converter clock. 237 * Use a default value for the converter clock.
196 * This may become user-configurable in the future. 238 * This may become user-configurable in the future.
197 */ 239 */
198 ret = clk_set_rate(info->clk, 1000000); 240 ret = clk_set_rate(info->clk, info->data->clk_rate);
199 if (ret < 0) { 241 if (ret < 0) {
200 dev_err(&pdev->dev, "failed to set adc clk rate, %d\n", ret); 242 dev_err(&pdev->dev, "failed to set adc clk rate, %d\n", ret);
201 return ret; 243 return ret;
@@ -227,8 +269,8 @@ static int rockchip_saradc_probe(struct platform_device *pdev)
227 indio_dev->info = &rockchip_saradc_iio_info; 269 indio_dev->info = &rockchip_saradc_iio_info;
228 indio_dev->modes = INDIO_DIRECT_MODE; 270 indio_dev->modes = INDIO_DIRECT_MODE;
229 271
230 indio_dev->channels = rockchip_saradc_iio_channels; 272 indio_dev->channels = info->data->channels;
231 indio_dev->num_channels = ARRAY_SIZE(rockchip_saradc_iio_channels); 273 indio_dev->num_channels = info->data->num_channels;
232 274
233 ret = iio_device_register(indio_dev); 275 ret = iio_device_register(indio_dev);
234 if (ret) 276 if (ret)
@@ -296,12 +338,6 @@ static int rockchip_saradc_resume(struct device *dev)
296static SIMPLE_DEV_PM_OPS(rockchip_saradc_pm_ops, 338static SIMPLE_DEV_PM_OPS(rockchip_saradc_pm_ops,
297 rockchip_saradc_suspend, rockchip_saradc_resume); 339 rockchip_saradc_suspend, rockchip_saradc_resume);
298 340
299static const struct of_device_id rockchip_saradc_match[] = {
300 { .compatible = "rockchip,saradc" },
301 {},
302};
303MODULE_DEVICE_TABLE(of, rockchip_saradc_match);
304
305static struct platform_driver rockchip_saradc_driver = { 341static struct platform_driver rockchip_saradc_driver = {
306 .probe = rockchip_saradc_probe, 342 .probe = rockchip_saradc_probe,
307 .remove = rockchip_saradc_remove, 343 .remove = rockchip_saradc_remove,
diff --git a/drivers/iio/adc/vf610_adc.c b/drivers/iio/adc/vf610_adc.c
index 4a10ae97dbf2..8ec353c01d98 100644
--- a/drivers/iio/adc/vf610_adc.c
+++ b/drivers/iio/adc/vf610_adc.c
@@ -91,7 +91,7 @@
91#define VF610_ADC_CAL 0x80 91#define VF610_ADC_CAL 0x80
92 92
93/* Other field define */ 93/* Other field define */
94#define VF610_ADC_ADCHC(x) ((x) & 0xF) 94#define VF610_ADC_ADCHC(x) ((x) & 0x1F)
95#define VF610_ADC_AIEN (0x1 << 7) 95#define VF610_ADC_AIEN (0x1 << 7)
96#define VF610_ADC_CONV_DISABLE 0x1F 96#define VF610_ADC_CONV_DISABLE 0x1F
97#define VF610_ADC_HS_COCO0 0x1 97#define VF610_ADC_HS_COCO0 0x1
@@ -153,6 +153,12 @@ struct vf610_adc {
153 BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 153 BIT(IIO_CHAN_INFO_SAMP_FREQ), \
154} 154}
155 155
156#define VF610_ADC_TEMPERATURE_CHAN(_idx, _chan_type) { \
157 .type = (_chan_type), \
158 .channel = (_idx), \
159 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), \
160}
161
156static const struct iio_chan_spec vf610_adc_iio_channels[] = { 162static const struct iio_chan_spec vf610_adc_iio_channels[] = {
157 VF610_ADC_CHAN(0, IIO_VOLTAGE), 163 VF610_ADC_CHAN(0, IIO_VOLTAGE),
158 VF610_ADC_CHAN(1, IIO_VOLTAGE), 164 VF610_ADC_CHAN(1, IIO_VOLTAGE),
@@ -170,6 +176,7 @@ static const struct iio_chan_spec vf610_adc_iio_channels[] = {
170 VF610_ADC_CHAN(13, IIO_VOLTAGE), 176 VF610_ADC_CHAN(13, IIO_VOLTAGE),
171 VF610_ADC_CHAN(14, IIO_VOLTAGE), 177 VF610_ADC_CHAN(14, IIO_VOLTAGE),
172 VF610_ADC_CHAN(15, IIO_VOLTAGE), 178 VF610_ADC_CHAN(15, IIO_VOLTAGE),
179 VF610_ADC_TEMPERATURE_CHAN(26, IIO_TEMP),
173 /* sentinel */ 180 /* sentinel */
174}; 181};
175 182
@@ -451,6 +458,7 @@ static int vf610_read_raw(struct iio_dev *indio_dev,
451 458
452 switch (mask) { 459 switch (mask) {
453 case IIO_CHAN_INFO_RAW: 460 case IIO_CHAN_INFO_RAW:
461 case IIO_CHAN_INFO_PROCESSED:
454 mutex_lock(&indio_dev->mlock); 462 mutex_lock(&indio_dev->mlock);
455 reinit_completion(&info->completion); 463 reinit_completion(&info->completion);
456 464
@@ -468,7 +476,23 @@ static int vf610_read_raw(struct iio_dev *indio_dev,
468 return ret; 476 return ret;
469 } 477 }
470 478
471 *val = info->value; 479 switch (chan->type) {
480 case IIO_VOLTAGE:
481 *val = info->value;
482 break;
483 case IIO_TEMP:
484 /*
485 * Calculate in degree Celsius times 1000
486 * Using sensor slope of 1.84 mV/°C and
487 * V at 25°C of 696 mV
488 */
489 *val = 25000 - ((int)info->value - 864) * 1000000 / 1840;
490 break;
491 default:
492 mutex_unlock(&indio_dev->mlock);
493 return -EINVAL;
494 }
495
472 mutex_unlock(&indio_dev->mlock); 496 mutex_unlock(&indio_dev->mlock);
473 return IIO_VAL_INT; 497 return IIO_VAL_INT;
474 498
@@ -569,9 +593,9 @@ static int vf610_adc_probe(struct platform_device *pdev)
569 return PTR_ERR(info->regs); 593 return PTR_ERR(info->regs);
570 594
571 irq = platform_get_irq(pdev, 0); 595 irq = platform_get_irq(pdev, 0);
572 if (irq <= 0) { 596 if (irq < 0) {
573 dev_err(&pdev->dev, "no irq resource?\n"); 597 dev_err(&pdev->dev, "no irq resource?\n");
574 return -EINVAL; 598 return irq;
575 } 599 }
576 600
577 ret = devm_request_irq(info->dev, irq, 601 ret = devm_request_irq(info->dev, irq,
@@ -586,8 +610,7 @@ static int vf610_adc_probe(struct platform_device *pdev)
586 if (IS_ERR(info->clk)) { 610 if (IS_ERR(info->clk)) {
587 dev_err(&pdev->dev, "failed getting clock, err = %ld\n", 611 dev_err(&pdev->dev, "failed getting clock, err = %ld\n",
588 PTR_ERR(info->clk)); 612 PTR_ERR(info->clk));
589 ret = PTR_ERR(info->clk); 613 return PTR_ERR(info->clk);
590 return ret;
591 } 614 }
592 615
593 info->vref = devm_regulator_get(&pdev->dev, "vref"); 616 info->vref = devm_regulator_get(&pdev->dev, "vref");
@@ -681,17 +704,19 @@ static int vf610_adc_resume(struct device *dev)
681 704
682 ret = clk_prepare_enable(info->clk); 705 ret = clk_prepare_enable(info->clk);
683 if (ret) 706 if (ret)
684 return ret; 707 goto disable_reg;
685 708
686 vf610_adc_hw_init(info); 709 vf610_adc_hw_init(info);
687 710
688 return 0; 711 return 0;
712
713disable_reg:
714 regulator_disable(info->vref);
715 return ret;
689} 716}
690#endif 717#endif
691 718
692static SIMPLE_DEV_PM_OPS(vf610_adc_pm_ops, 719static SIMPLE_DEV_PM_OPS(vf610_adc_pm_ops, vf610_adc_suspend, vf610_adc_resume);
693 vf610_adc_suspend,
694 vf610_adc_resume);
695 720
696static struct platform_driver vf610_adc_driver = { 721static struct platform_driver vf610_adc_driver = {
697 .probe = vf610_adc_probe, 722 .probe = vf610_adc_probe,
diff --git a/drivers/iio/common/st_sensors/st_sensors_core.c b/drivers/iio/common/st_sensors/st_sensors_core.c
index 24cfe4e044f9..edd13d2b4121 100644
--- a/drivers/iio/common/st_sensors/st_sensors_core.c
+++ b/drivers/iio/common/st_sensors/st_sensors_core.c
@@ -44,18 +44,18 @@ st_sensors_write_data_with_mask_error:
44 return err; 44 return err;
45} 45}
46 46
47static int st_sensors_match_odr(struct st_sensors *sensor, 47static int st_sensors_match_odr(struct st_sensor_settings *sensor_settings,
48 unsigned int odr, struct st_sensor_odr_avl *odr_out) 48 unsigned int odr, struct st_sensor_odr_avl *odr_out)
49{ 49{
50 int i, ret = -EINVAL; 50 int i, ret = -EINVAL;
51 51
52 for (i = 0; i < ST_SENSORS_ODR_LIST_MAX; i++) { 52 for (i = 0; i < ST_SENSORS_ODR_LIST_MAX; i++) {
53 if (sensor->odr.odr_avl[i].hz == 0) 53 if (sensor_settings->odr.odr_avl[i].hz == 0)
54 goto st_sensors_match_odr_error; 54 goto st_sensors_match_odr_error;
55 55
56 if (sensor->odr.odr_avl[i].hz == odr) { 56 if (sensor_settings->odr.odr_avl[i].hz == odr) {
57 odr_out->hz = sensor->odr.odr_avl[i].hz; 57 odr_out->hz = sensor_settings->odr.odr_avl[i].hz;
58 odr_out->value = sensor->odr.odr_avl[i].value; 58 odr_out->value = sensor_settings->odr.odr_avl[i].value;
59 ret = 0; 59 ret = 0;
60 break; 60 break;
61 } 61 }
@@ -71,23 +71,26 @@ int st_sensors_set_odr(struct iio_dev *indio_dev, unsigned int odr)
71 struct st_sensor_odr_avl odr_out = {0, 0}; 71 struct st_sensor_odr_avl odr_out = {0, 0};
72 struct st_sensor_data *sdata = iio_priv(indio_dev); 72 struct st_sensor_data *sdata = iio_priv(indio_dev);
73 73
74 err = st_sensors_match_odr(sdata->sensor, odr, &odr_out); 74 err = st_sensors_match_odr(sdata->sensor_settings, odr, &odr_out);
75 if (err < 0) 75 if (err < 0)
76 goto st_sensors_match_odr_error; 76 goto st_sensors_match_odr_error;
77 77
78 if ((sdata->sensor->odr.addr == sdata->sensor->pw.addr) && 78 if ((sdata->sensor_settings->odr.addr ==
79 (sdata->sensor->odr.mask == sdata->sensor->pw.mask)) { 79 sdata->sensor_settings->pw.addr) &&
80 (sdata->sensor_settings->odr.mask ==
81 sdata->sensor_settings->pw.mask)) {
80 if (sdata->enabled == true) { 82 if (sdata->enabled == true) {
81 err = st_sensors_write_data_with_mask(indio_dev, 83 err = st_sensors_write_data_with_mask(indio_dev,
82 sdata->sensor->odr.addr, 84 sdata->sensor_settings->odr.addr,
83 sdata->sensor->odr.mask, 85 sdata->sensor_settings->odr.mask,
84 odr_out.value); 86 odr_out.value);
85 } else { 87 } else {
86 err = 0; 88 err = 0;
87 } 89 }
88 } else { 90 } else {
89 err = st_sensors_write_data_with_mask(indio_dev, 91 err = st_sensors_write_data_with_mask(indio_dev,
90 sdata->sensor->odr.addr, sdata->sensor->odr.mask, 92 sdata->sensor_settings->odr.addr,
93 sdata->sensor_settings->odr.mask,
91 odr_out.value); 94 odr_out.value);
92 } 95 }
93 if (err >= 0) 96 if (err >= 0)
@@ -98,16 +101,16 @@ st_sensors_match_odr_error:
98} 101}
99EXPORT_SYMBOL(st_sensors_set_odr); 102EXPORT_SYMBOL(st_sensors_set_odr);
100 103
101static int st_sensors_match_fs(struct st_sensors *sensor, 104static int st_sensors_match_fs(struct st_sensor_settings *sensor_settings,
102 unsigned int fs, int *index_fs_avl) 105 unsigned int fs, int *index_fs_avl)
103{ 106{
104 int i, ret = -EINVAL; 107 int i, ret = -EINVAL;
105 108
106 for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) { 109 for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) {
107 if (sensor->fs.fs_avl[i].num == 0) 110 if (sensor_settings->fs.fs_avl[i].num == 0)
108 goto st_sensors_match_odr_error; 111 goto st_sensors_match_odr_error;
109 112
110 if (sensor->fs.fs_avl[i].num == fs) { 113 if (sensor_settings->fs.fs_avl[i].num == fs) {
111 *index_fs_avl = i; 114 *index_fs_avl = i;
112 ret = 0; 115 ret = 0;
113 break; 116 break;
@@ -118,25 +121,24 @@ st_sensors_match_odr_error:
118 return ret; 121 return ret;
119} 122}
120 123
121static int st_sensors_set_fullscale(struct iio_dev *indio_dev, 124static int st_sensors_set_fullscale(struct iio_dev *indio_dev, unsigned int fs)
122 unsigned int fs)
123{ 125{
124 int err, i = 0; 126 int err, i = 0;
125 struct st_sensor_data *sdata = iio_priv(indio_dev); 127 struct st_sensor_data *sdata = iio_priv(indio_dev);
126 128
127 err = st_sensors_match_fs(sdata->sensor, fs, &i); 129 err = st_sensors_match_fs(sdata->sensor_settings, fs, &i);
128 if (err < 0) 130 if (err < 0)
129 goto st_accel_set_fullscale_error; 131 goto st_accel_set_fullscale_error;
130 132
131 err = st_sensors_write_data_with_mask(indio_dev, 133 err = st_sensors_write_data_with_mask(indio_dev,
132 sdata->sensor->fs.addr, 134 sdata->sensor_settings->fs.addr,
133 sdata->sensor->fs.mask, 135 sdata->sensor_settings->fs.mask,
134 sdata->sensor->fs.fs_avl[i].value); 136 sdata->sensor_settings->fs.fs_avl[i].value);
135 if (err < 0) 137 if (err < 0)
136 goto st_accel_set_fullscale_error; 138 goto st_accel_set_fullscale_error;
137 139
138 sdata->current_fullscale = (struct st_sensor_fullscale_avl *) 140 sdata->current_fullscale = (struct st_sensor_fullscale_avl *)
139 &sdata->sensor->fs.fs_avl[i]; 141 &sdata->sensor_settings->fs.fs_avl[i];
140 return err; 142 return err;
141 143
142st_accel_set_fullscale_error: 144st_accel_set_fullscale_error:
@@ -153,10 +155,12 @@ int st_sensors_set_enable(struct iio_dev *indio_dev, bool enable)
153 struct st_sensor_data *sdata = iio_priv(indio_dev); 155 struct st_sensor_data *sdata = iio_priv(indio_dev);
154 156
155 if (enable) { 157 if (enable) {
156 tmp_value = sdata->sensor->pw.value_on; 158 tmp_value = sdata->sensor_settings->pw.value_on;
157 if ((sdata->sensor->odr.addr == sdata->sensor->pw.addr) && 159 if ((sdata->sensor_settings->odr.addr ==
158 (sdata->sensor->odr.mask == sdata->sensor->pw.mask)) { 160 sdata->sensor_settings->pw.addr) &&
159 err = st_sensors_match_odr(sdata->sensor, 161 (sdata->sensor_settings->odr.mask ==
162 sdata->sensor_settings->pw.mask)) {
163 err = st_sensors_match_odr(sdata->sensor_settings,
160 sdata->odr, &odr_out); 164 sdata->odr, &odr_out);
161 if (err < 0) 165 if (err < 0)
162 goto set_enable_error; 166 goto set_enable_error;
@@ -164,8 +168,8 @@ int st_sensors_set_enable(struct iio_dev *indio_dev, bool enable)
164 found = true; 168 found = true;
165 } 169 }
166 err = st_sensors_write_data_with_mask(indio_dev, 170 err = st_sensors_write_data_with_mask(indio_dev,
167 sdata->sensor->pw.addr, 171 sdata->sensor_settings->pw.addr,
168 sdata->sensor->pw.mask, tmp_value); 172 sdata->sensor_settings->pw.mask, tmp_value);
169 if (err < 0) 173 if (err < 0)
170 goto set_enable_error; 174 goto set_enable_error;
171 175
@@ -175,9 +179,9 @@ int st_sensors_set_enable(struct iio_dev *indio_dev, bool enable)
175 sdata->odr = odr_out.hz; 179 sdata->odr = odr_out.hz;
176 } else { 180 } else {
177 err = st_sensors_write_data_with_mask(indio_dev, 181 err = st_sensors_write_data_with_mask(indio_dev,
178 sdata->sensor->pw.addr, 182 sdata->sensor_settings->pw.addr,
179 sdata->sensor->pw.mask, 183 sdata->sensor_settings->pw.mask,
180 sdata->sensor->pw.value_off); 184 sdata->sensor_settings->pw.value_off);
181 if (err < 0) 185 if (err < 0)
182 goto set_enable_error; 186 goto set_enable_error;
183 187
@@ -194,8 +198,9 @@ int st_sensors_set_axis_enable(struct iio_dev *indio_dev, u8 axis_enable)
194 struct st_sensor_data *sdata = iio_priv(indio_dev); 198 struct st_sensor_data *sdata = iio_priv(indio_dev);
195 199
196 return st_sensors_write_data_with_mask(indio_dev, 200 return st_sensors_write_data_with_mask(indio_dev,
197 sdata->sensor->enable_axis.addr, 201 sdata->sensor_settings->enable_axis.addr,
198 sdata->sensor->enable_axis.mask, axis_enable); 202 sdata->sensor_settings->enable_axis.mask,
203 axis_enable);
199} 204}
200EXPORT_SYMBOL(st_sensors_set_axis_enable); 205EXPORT_SYMBOL(st_sensors_set_axis_enable);
201 206
@@ -236,13 +241,13 @@ void st_sensors_power_disable(struct iio_dev *indio_dev)
236EXPORT_SYMBOL(st_sensors_power_disable); 241EXPORT_SYMBOL(st_sensors_power_disable);
237 242
238static int st_sensors_set_drdy_int_pin(struct iio_dev *indio_dev, 243static int st_sensors_set_drdy_int_pin(struct iio_dev *indio_dev,
239 struct st_sensors_platform_data *pdata) 244 struct st_sensors_platform_data *pdata)
240{ 245{
241 struct st_sensor_data *sdata = iio_priv(indio_dev); 246 struct st_sensor_data *sdata = iio_priv(indio_dev);
242 247
243 switch (pdata->drdy_int_pin) { 248 switch (pdata->drdy_int_pin) {
244 case 1: 249 case 1:
245 if (sdata->sensor->drdy_irq.mask_int1 == 0) { 250 if (sdata->sensor_settings->drdy_irq.mask_int1 == 0) {
246 dev_err(&indio_dev->dev, 251 dev_err(&indio_dev->dev,
247 "DRDY on INT1 not available.\n"); 252 "DRDY on INT1 not available.\n");
248 return -EINVAL; 253 return -EINVAL;
@@ -250,7 +255,7 @@ static int st_sensors_set_drdy_int_pin(struct iio_dev *indio_dev,
250 sdata->drdy_int_pin = 1; 255 sdata->drdy_int_pin = 1;
251 break; 256 break;
252 case 2: 257 case 2:
253 if (sdata->sensor->drdy_irq.mask_int2 == 0) { 258 if (sdata->sensor_settings->drdy_irq.mask_int2 == 0) {
254 dev_err(&indio_dev->dev, 259 dev_err(&indio_dev->dev,
255 "DRDY on INT2 not available.\n"); 260 "DRDY on INT2 not available.\n");
256 return -EINVAL; 261 return -EINVAL;
@@ -318,7 +323,7 @@ int st_sensors_init_sensor(struct iio_dev *indio_dev,
318 323
319 if (sdata->current_fullscale) { 324 if (sdata->current_fullscale) {
320 err = st_sensors_set_fullscale(indio_dev, 325 err = st_sensors_set_fullscale(indio_dev,
321 sdata->current_fullscale->num); 326 sdata->current_fullscale->num);
322 if (err < 0) 327 if (err < 0)
323 return err; 328 return err;
324 } else 329 } else
@@ -330,7 +335,8 @@ int st_sensors_init_sensor(struct iio_dev *indio_dev,
330 335
331 /* set BDU */ 336 /* set BDU */
332 err = st_sensors_write_data_with_mask(indio_dev, 337 err = st_sensors_write_data_with_mask(indio_dev,
333 sdata->sensor->bdu.addr, sdata->sensor->bdu.mask, true); 338 sdata->sensor_settings->bdu.addr,
339 sdata->sensor_settings->bdu.mask, true);
334 if (err < 0) 340 if (err < 0)
335 return err; 341 return err;
336 342
@@ -346,26 +352,28 @@ int st_sensors_set_dataready_irq(struct iio_dev *indio_dev, bool enable)
346 u8 drdy_mask; 352 u8 drdy_mask;
347 struct st_sensor_data *sdata = iio_priv(indio_dev); 353 struct st_sensor_data *sdata = iio_priv(indio_dev);
348 354
349 if (!sdata->sensor->drdy_irq.addr) 355 if (!sdata->sensor_settings->drdy_irq.addr)
350 return 0; 356 return 0;
351 357
352 /* Enable/Disable the interrupt generator 1. */ 358 /* Enable/Disable the interrupt generator 1. */
353 if (sdata->sensor->drdy_irq.ig1.en_addr > 0) { 359 if (sdata->sensor_settings->drdy_irq.ig1.en_addr > 0) {
354 err = st_sensors_write_data_with_mask(indio_dev, 360 err = st_sensors_write_data_with_mask(indio_dev,
355 sdata->sensor->drdy_irq.ig1.en_addr, 361 sdata->sensor_settings->drdy_irq.ig1.en_addr,
356 sdata->sensor->drdy_irq.ig1.en_mask, (int)enable); 362 sdata->sensor_settings->drdy_irq.ig1.en_mask,
363 (int)enable);
357 if (err < 0) 364 if (err < 0)
358 goto st_accel_set_dataready_irq_error; 365 goto st_accel_set_dataready_irq_error;
359 } 366 }
360 367
361 if (sdata->drdy_int_pin == 1) 368 if (sdata->drdy_int_pin == 1)
362 drdy_mask = sdata->sensor->drdy_irq.mask_int1; 369 drdy_mask = sdata->sensor_settings->drdy_irq.mask_int1;
363 else 370 else
364 drdy_mask = sdata->sensor->drdy_irq.mask_int2; 371 drdy_mask = sdata->sensor_settings->drdy_irq.mask_int2;
365 372
366 /* Enable/Disable the interrupt generator for data ready. */ 373 /* Enable/Disable the interrupt generator for data ready. */
367 err = st_sensors_write_data_with_mask(indio_dev, 374 err = st_sensors_write_data_with_mask(indio_dev,
368 sdata->sensor->drdy_irq.addr, drdy_mask, (int)enable); 375 sdata->sensor_settings->drdy_irq.addr,
376 drdy_mask, (int)enable);
369 377
370st_accel_set_dataready_irq_error: 378st_accel_set_dataready_irq_error:
371 return err; 379 return err;
@@ -378,8 +386,8 @@ int st_sensors_set_fullscale_by_gain(struct iio_dev *indio_dev, int scale)
378 struct st_sensor_data *sdata = iio_priv(indio_dev); 386 struct st_sensor_data *sdata = iio_priv(indio_dev);
379 387
380 for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) { 388 for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) {
381 if ((sdata->sensor->fs.fs_avl[i].gain == scale) && 389 if ((sdata->sensor_settings->fs.fs_avl[i].gain == scale) &&
382 (sdata->sensor->fs.fs_avl[i].gain != 0)) { 390 (sdata->sensor_settings->fs.fs_avl[i].gain != 0)) {
383 err = 0; 391 err = 0;
384 break; 392 break;
385 } 393 }
@@ -388,7 +396,7 @@ int st_sensors_set_fullscale_by_gain(struct iio_dev *indio_dev, int scale)
388 goto st_sensors_match_scale_error; 396 goto st_sensors_match_scale_error;
389 397
390 err = st_sensors_set_fullscale(indio_dev, 398 err = st_sensors_set_fullscale(indio_dev,
391 sdata->sensor->fs.fs_avl[i].num); 399 sdata->sensor_settings->fs.fs_avl[i].num);
392 400
393st_sensors_match_scale_error: 401st_sensors_match_scale_error:
394 return err; 402 return err;
@@ -439,7 +447,7 @@ int st_sensors_read_info_raw(struct iio_dev *indio_dev,
439 if (err < 0) 447 if (err < 0)
440 goto out; 448 goto out;
441 449
442 msleep((sdata->sensor->bootime * 1000) / sdata->odr); 450 msleep((sdata->sensor_settings->bootime * 1000) / sdata->odr);
443 err = st_sensors_read_axis_data(indio_dev, ch, val); 451 err = st_sensors_read_axis_data(indio_dev, ch, val);
444 if (err < 0) 452 if (err < 0)
445 goto out; 453 goto out;
@@ -456,7 +464,8 @@ out:
456EXPORT_SYMBOL(st_sensors_read_info_raw); 464EXPORT_SYMBOL(st_sensors_read_info_raw);
457 465
458int st_sensors_check_device_support(struct iio_dev *indio_dev, 466int st_sensors_check_device_support(struct iio_dev *indio_dev,
459 int num_sensors_list, const struct st_sensors *sensors) 467 int num_sensors_list,
468 const struct st_sensor_settings *sensor_settings)
460{ 469{
461 u8 wai; 470 u8 wai;
462 int i, n, err; 471 int i, n, err;
@@ -470,23 +479,24 @@ int st_sensors_check_device_support(struct iio_dev *indio_dev,
470 } 479 }
471 480
472 for (i = 0; i < num_sensors_list; i++) { 481 for (i = 0; i < num_sensors_list; i++) {
473 if (sensors[i].wai == wai) 482 if (sensor_settings[i].wai == wai)
474 break; 483 break;
475 } 484 }
476 if (i == num_sensors_list) 485 if (i == num_sensors_list)
477 goto device_not_supported; 486 goto device_not_supported;
478 487
479 for (n = 0; n < ARRAY_SIZE(sensors[i].sensors_supported); n++) { 488 for (n = 0; n < ARRAY_SIZE(sensor_settings[i].sensors_supported); n++) {
480 if (strcmp(indio_dev->name, 489 if (strcmp(indio_dev->name,
481 &sensors[i].sensors_supported[n][0]) == 0) 490 &sensor_settings[i].sensors_supported[n][0]) == 0)
482 break; 491 break;
483 } 492 }
484 if (n == ARRAY_SIZE(sensors[i].sensors_supported)) { 493 if (n == ARRAY_SIZE(sensor_settings[i].sensors_supported)) {
485 dev_err(&indio_dev->dev, "device name and WhoAmI mismatch.\n"); 494 dev_err(&indio_dev->dev, "device name and WhoAmI mismatch.\n");
486 goto sensor_name_mismatch; 495 goto sensor_name_mismatch;
487 } 496 }
488 497
489 sdata->sensor = (struct st_sensors *)&sensors[i]; 498 sdata->sensor_settings =
499 (struct st_sensor_settings *)&sensor_settings[i];
490 500
491 return i; 501 return i;
492 502
@@ -508,11 +518,11 @@ ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev,
508 518
509 mutex_lock(&indio_dev->mlock); 519 mutex_lock(&indio_dev->mlock);
510 for (i = 0; i < ST_SENSORS_ODR_LIST_MAX; i++) { 520 for (i = 0; i < ST_SENSORS_ODR_LIST_MAX; i++) {
511 if (sdata->sensor->odr.odr_avl[i].hz == 0) 521 if (sdata->sensor_settings->odr.odr_avl[i].hz == 0)
512 break; 522 break;
513 523
514 len += scnprintf(buf + len, PAGE_SIZE - len, "%d ", 524 len += scnprintf(buf + len, PAGE_SIZE - len, "%d ",
515 sdata->sensor->odr.odr_avl[i].hz); 525 sdata->sensor_settings->odr.odr_avl[i].hz);
516 } 526 }
517 mutex_unlock(&indio_dev->mlock); 527 mutex_unlock(&indio_dev->mlock);
518 buf[len - 1] = '\n'; 528 buf[len - 1] = '\n';
@@ -530,11 +540,11 @@ ssize_t st_sensors_sysfs_scale_avail(struct device *dev,
530 540
531 mutex_lock(&indio_dev->mlock); 541 mutex_lock(&indio_dev->mlock);
532 for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) { 542 for (i = 0; i < ST_SENSORS_FULLSCALE_AVL_MAX; i++) {
533 if (sdata->sensor->fs.fs_avl[i].num == 0) 543 if (sdata->sensor_settings->fs.fs_avl[i].num == 0)
534 break; 544 break;
535 545
536 len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ", 546 len += scnprintf(buf + len, PAGE_SIZE - len, "0.%06u ",
537 sdata->sensor->fs.fs_avl[i].gain); 547 sdata->sensor_settings->fs.fs_avl[i].gain);
538 } 548 }
539 mutex_unlock(&indio_dev->mlock); 549 mutex_unlock(&indio_dev->mlock);
540 buf[len - 1] = '\n'; 550 buf[len - 1] = '\n';
diff --git a/drivers/iio/common/st_sensors/st_sensors_i2c.c b/drivers/iio/common/st_sensors/st_sensors_i2c.c
index bb6f3085f57b..98cfee296d46 100644
--- a/drivers/iio/common/st_sensors/st_sensors_i2c.c
+++ b/drivers/iio/common/st_sensors/st_sensors_i2c.c
@@ -72,6 +72,7 @@ void st_sensors_i2c_configure(struct iio_dev *indio_dev,
72 indio_dev->dev.parent = &client->dev; 72 indio_dev->dev.parent = &client->dev;
73 indio_dev->name = client->name; 73 indio_dev->name = client->name;
74 74
75 sdata->dev = &client->dev;
75 sdata->tf = &st_sensors_tf_i2c; 76 sdata->tf = &st_sensors_tf_i2c;
76 sdata->get_irq_data_ready = st_sensors_i2c_get_irq; 77 sdata->get_irq_data_ready = st_sensors_i2c_get_irq;
77} 78}
diff --git a/drivers/iio/common/st_sensors/st_sensors_spi.c b/drivers/iio/common/st_sensors/st_sensors_spi.c
index 251baf6abc25..78a6a1ab3ece 100644
--- a/drivers/iio/common/st_sensors/st_sensors_spi.c
+++ b/drivers/iio/common/st_sensors/st_sensors_spi.c
@@ -111,6 +111,7 @@ void st_sensors_spi_configure(struct iio_dev *indio_dev,
111 indio_dev->dev.parent = &spi->dev; 111 indio_dev->dev.parent = &spi->dev;
112 indio_dev->name = spi->modalias; 112 indio_dev->name = spi->modalias;
113 113
114 sdata->dev = &spi->dev;
114 sdata->tf = &st_sensors_tf_spi; 115 sdata->tf = &st_sensors_tf_spi;
115 sdata->get_irq_data_ready = st_sensors_spi_get_irq; 116 sdata->get_irq_data_ready = st_sensors_spi_get_irq;
116} 117}
diff --git a/drivers/iio/gyro/st_gyro.h b/drivers/iio/gyro/st_gyro.h
index c197360c450b..5353d6328c54 100644
--- a/drivers/iio/gyro/st_gyro.h
+++ b/drivers/iio/gyro/st_gyro.h
@@ -30,8 +30,7 @@ static const struct st_sensors_platform_data gyro_pdata = {
30 .drdy_int_pin = 2, 30 .drdy_int_pin = 2,
31}; 31};
32 32
33int st_gyro_common_probe(struct iio_dev *indio_dev, 33int st_gyro_common_probe(struct iio_dev *indio_dev);
34 struct st_sensors_platform_data *pdata);
35void st_gyro_common_remove(struct iio_dev *indio_dev); 34void st_gyro_common_remove(struct iio_dev *indio_dev);
36 35
37#ifdef CONFIG_IIO_BUFFER 36#ifdef CONFIG_IIO_BUFFER
diff --git a/drivers/iio/gyro/st_gyro_core.c b/drivers/iio/gyro/st_gyro_core.c
index f156fc6c5c6c..f07a2336f7dc 100644
--- a/drivers/iio/gyro/st_gyro_core.c
+++ b/drivers/iio/gyro/st_gyro_core.c
@@ -103,7 +103,7 @@ static const struct iio_chan_spec st_gyro_16bit_channels[] = {
103 IIO_CHAN_SOFT_TIMESTAMP(3) 103 IIO_CHAN_SOFT_TIMESTAMP(3)
104}; 104};
105 105
106static const struct st_sensors st_gyro_sensors[] = { 106static const struct st_sensor_settings st_gyro_sensors_settings[] = {
107 { 107 {
108 .wai = ST_GYRO_1_WAI_EXP, 108 .wai = ST_GYRO_1_WAI_EXP,
109 .sensors_supported = { 109 .sensors_supported = {
@@ -309,8 +309,7 @@ static const struct iio_trigger_ops st_gyro_trigger_ops = {
309#define ST_GYRO_TRIGGER_OPS NULL 309#define ST_GYRO_TRIGGER_OPS NULL
310#endif 310#endif
311 311
312int st_gyro_common_probe(struct iio_dev *indio_dev, 312int st_gyro_common_probe(struct iio_dev *indio_dev)
313 struct st_sensors_platform_data *pdata)
314{ 313{
315 struct st_sensor_data *gdata = iio_priv(indio_dev); 314 struct st_sensor_data *gdata = iio_priv(indio_dev);
316 int irq = gdata->get_irq_data_ready(indio_dev); 315 int irq = gdata->get_irq_data_ready(indio_dev);
@@ -322,20 +321,22 @@ int st_gyro_common_probe(struct iio_dev *indio_dev,
322 st_sensors_power_enable(indio_dev); 321 st_sensors_power_enable(indio_dev);
323 322
324 err = st_sensors_check_device_support(indio_dev, 323 err = st_sensors_check_device_support(indio_dev,
325 ARRAY_SIZE(st_gyro_sensors), st_gyro_sensors); 324 ARRAY_SIZE(st_gyro_sensors_settings),
325 st_gyro_sensors_settings);
326 if (err < 0) 326 if (err < 0)
327 return err; 327 return err;
328 328
329 gdata->num_data_channels = ST_GYRO_NUMBER_DATA_CHANNELS; 329 gdata->num_data_channels = ST_GYRO_NUMBER_DATA_CHANNELS;
330 gdata->multiread_bit = gdata->sensor->multi_read_bit; 330 gdata->multiread_bit = gdata->sensor_settings->multi_read_bit;
331 indio_dev->channels = gdata->sensor->ch; 331 indio_dev->channels = gdata->sensor_settings->ch;
332 indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS; 332 indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;
333 333
334 gdata->current_fullscale = (struct st_sensor_fullscale_avl *) 334 gdata->current_fullscale = (struct st_sensor_fullscale_avl *)
335 &gdata->sensor->fs.fs_avl[0]; 335 &gdata->sensor_settings->fs.fs_avl[0];
336 gdata->odr = gdata->sensor->odr.odr_avl[0].hz; 336 gdata->odr = gdata->sensor_settings->odr.odr_avl[0].hz;
337 337
338 err = st_sensors_init_sensor(indio_dev, pdata); 338 err = st_sensors_init_sensor(indio_dev,
339 (struct st_sensors_platform_data *)&gyro_pdata);
339 if (err < 0) 340 if (err < 0)
340 return err; 341 return err;
341 342
diff --git a/drivers/iio/gyro/st_gyro_i2c.c b/drivers/iio/gyro/st_gyro_i2c.c
index 8fa0ad2ef4ef..64480b16c689 100644
--- a/drivers/iio/gyro/st_gyro_i2c.c
+++ b/drivers/iio/gyro/st_gyro_i2c.c
@@ -67,13 +67,11 @@ static int st_gyro_i2c_probe(struct i2c_client *client,
67 return -ENOMEM; 67 return -ENOMEM;
68 68
69 gdata = iio_priv(indio_dev); 69 gdata = iio_priv(indio_dev);
70 gdata->dev = &client->dev;
71 st_sensors_of_i2c_probe(client, st_gyro_of_match); 70 st_sensors_of_i2c_probe(client, st_gyro_of_match);
72 71
73 st_sensors_i2c_configure(indio_dev, client, gdata); 72 st_sensors_i2c_configure(indio_dev, client, gdata);
74 73
75 err = st_gyro_common_probe(indio_dev, 74 err = st_gyro_common_probe(indio_dev);
76 (struct st_sensors_platform_data *)&gyro_pdata);
77 if (err < 0) 75 if (err < 0)
78 return err; 76 return err;
79 77
diff --git a/drivers/iio/gyro/st_gyro_spi.c b/drivers/iio/gyro/st_gyro_spi.c
index b4ad3be26687..e59bead6bc3c 100644
--- a/drivers/iio/gyro/st_gyro_spi.c
+++ b/drivers/iio/gyro/st_gyro_spi.c
@@ -29,12 +29,10 @@ static int st_gyro_spi_probe(struct spi_device *spi)
29 return -ENOMEM; 29 return -ENOMEM;
30 30
31 gdata = iio_priv(indio_dev); 31 gdata = iio_priv(indio_dev);
32 gdata->dev = &spi->dev;
33 32
34 st_sensors_spi_configure(indio_dev, spi, gdata); 33 st_sensors_spi_configure(indio_dev, spi, gdata);
35 34
36 err = st_gyro_common_probe(indio_dev, 35 err = st_gyro_common_probe(indio_dev);
37 (struct st_sensors_platform_data *)&gyro_pdata);
38 if (err < 0) 36 if (err < 0)
39 return err; 37 return err;
40 38
diff --git a/drivers/iio/humidity/Kconfig b/drivers/iio/humidity/Kconfig
index e116bd8dd0e4..4813b793b9f7 100644
--- a/drivers/iio/humidity/Kconfig
+++ b/drivers/iio/humidity/Kconfig
@@ -22,4 +22,14 @@ config SI7005
22 To compile this driver as a module, choose M here: the module 22 To compile this driver as a module, choose M here: the module
23 will be called si7005. 23 will be called si7005.
24 24
25config SI7020
26 tristate "Si7013/20/21 Relative Humidity and Temperature Sensors"
27 depends on I2C
28 help
29 Say yes here to build support for the Silicon Labs Si7013/20/21
30 Relative Humidity and Temperature Sensors.
31
32 To compile this driver as a module, choose M here: the module
33 will be called si7020.
34
25endmenu 35endmenu
diff --git a/drivers/iio/humidity/Makefile b/drivers/iio/humidity/Makefile
index e3f3d942e646..86e2d26e9f4d 100644
--- a/drivers/iio/humidity/Makefile
+++ b/drivers/iio/humidity/Makefile
@@ -4,3 +4,4 @@
4 4
5obj-$(CONFIG_DHT11) += dht11.o 5obj-$(CONFIG_DHT11) += dht11.o
6obj-$(CONFIG_SI7005) += si7005.o 6obj-$(CONFIG_SI7005) += si7005.o
7obj-$(CONFIG_SI7020) += si7020.o
diff --git a/drivers/iio/humidity/si7020.c b/drivers/iio/humidity/si7020.c
new file mode 100644
index 000000000000..b54164677b89
--- /dev/null
+++ b/drivers/iio/humidity/si7020.c
@@ -0,0 +1,161 @@
1/*
2 * si7020.c - Silicon Labs Si7013/20/21 Relative Humidity and Temp Sensors
3 * Copyright (c) 2013,2014 Uplogix, Inc.
4 * David Barksdale <dbarksdale@uplogix.com>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16/*
17 * The Silicon Labs Si7013/20/21 Relative Humidity and Temperature Sensors
18 * are i2c devices which have an identical programming interface for
19 * measuring relative humidity and temperature. The Si7013 has an additional
20 * temperature input which this driver does not support.
21 *
22 * Data Sheets:
23 * Si7013: http://www.silabs.com/Support%20Documents/TechnicalDocs/Si7013.pdf
24 * Si7020: http://www.silabs.com/Support%20Documents/TechnicalDocs/Si7020.pdf
25 * Si7021: http://www.silabs.com/Support%20Documents/TechnicalDocs/Si7021.pdf
26 */
27
28#include <linux/delay.h>
29#include <linux/i2c.h>
30#include <linux/module.h>
31#include <linux/slab.h>
32#include <linux/sysfs.h>
33
34#include <linux/iio/iio.h>
35#include <linux/iio/sysfs.h>
36
37/* Measure Relative Humidity, Hold Master Mode */
38#define SI7020CMD_RH_HOLD 0xE5
39/* Measure Temperature, Hold Master Mode */
40#define SI7020CMD_TEMP_HOLD 0xE3
41/* Software Reset */
42#define SI7020CMD_RESET 0xFE
43
44static int si7020_read_raw(struct iio_dev *indio_dev,
45 struct iio_chan_spec const *chan, int *val,
46 int *val2, long mask)
47{
48 struct i2c_client *client = iio_priv(indio_dev);
49 int ret;
50
51 switch (mask) {
52 case IIO_CHAN_INFO_RAW:
53 ret = i2c_smbus_read_word_data(client,
54 chan->type == IIO_TEMP ?
55 SI7020CMD_TEMP_HOLD :
56 SI7020CMD_RH_HOLD);
57 if (ret < 0)
58 return ret;
59 *val = ret >> 2;
60 if (chan->type == IIO_HUMIDITYRELATIVE)
61 *val &= GENMASK(11, 0);
62 return IIO_VAL_INT;
63 case IIO_CHAN_INFO_SCALE:
64 if (chan->type == IIO_TEMP)
65 *val = 175720; /* = 175.72 * 1000 */
66 else
67 *val = 125 * 1000;
68 *val2 = 65536 >> 2;
69 return IIO_VAL_FRACTIONAL;
70 case IIO_CHAN_INFO_OFFSET:
71 /*
72 * Since iio_convert_raw_to_processed_unlocked assumes offset
73 * is an integer we have to round these values and lose
74 * accuracy.
75 * Relative humidity will be 0.0032959% too high and
76 * temperature will be 0.00277344 degrees too high.
77 * This is no big deal because it's within the accuracy of the
78 * sensor.
79 */
80 if (chan->type == IIO_TEMP)
81 *val = -4368; /* = -46.85 * (65536 >> 2) / 175.72 */
82 else
83 *val = -786; /* = -6 * (65536 >> 2) / 125 */
84 return IIO_VAL_INT;
85 default:
86 break;
87 }
88
89 return -EINVAL;
90}
91
92static const struct iio_chan_spec si7020_channels[] = {
93 {
94 .type = IIO_HUMIDITYRELATIVE,
95 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
96 BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OFFSET),
97 },
98 {
99 .type = IIO_TEMP,
100 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
101 BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OFFSET),
102 }
103};
104
105static const struct iio_info si7020_info = {
106 .read_raw = si7020_read_raw,
107 .driver_module = THIS_MODULE,
108};
109
110static int si7020_probe(struct i2c_client *client,
111 const struct i2c_device_id *id)
112{
113 struct iio_dev *indio_dev;
114 struct i2c_client **data;
115 int ret;
116
117 if (!i2c_check_functionality(client->adapter,
118 I2C_FUNC_SMBUS_WRITE_BYTE |
119 I2C_FUNC_SMBUS_READ_WORD_DATA))
120 return -ENODEV;
121
122 /* Reset device, loads default settings. */
123 ret = i2c_smbus_write_byte(client, SI7020CMD_RESET);
124 if (ret < 0)
125 return ret;
126 /* Wait the maximum power-up time after software reset. */
127 msleep(15);
128
129 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*client));
130 if (!indio_dev)
131 return -ENOMEM;
132
133 data = iio_priv(indio_dev);
134 *data = client;
135
136 indio_dev->dev.parent = &client->dev;
137 indio_dev->name = dev_name(&client->dev);
138 indio_dev->modes = INDIO_DIRECT_MODE;
139 indio_dev->info = &si7020_info;
140 indio_dev->channels = si7020_channels;
141 indio_dev->num_channels = ARRAY_SIZE(si7020_channels);
142
143 return devm_iio_device_register(&client->dev, indio_dev);
144}
145
146static const struct i2c_device_id si7020_id[] = {
147 { "si7020", 0 },
148 { }
149};
150MODULE_DEVICE_TABLE(i2c, si7020_id);
151
152static struct i2c_driver si7020_driver = {
153 .driver.name = "si7020",
154 .probe = si7020_probe,
155 .id_table = si7020_id,
156};
157
158module_i2c_driver(si7020_driver);
159MODULE_DESCRIPTION("Silicon Labs Si7013/20/21 Relative Humidity and Temperature Sensors");
160MODULE_AUTHOR("David Barksdale <dbarksdale@uplogix.com>");
161MODULE_LICENSE("GPL");
diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
index f0846108d006..866fe904cba2 100644
--- a/drivers/iio/inkern.c
+++ b/drivers/iio/inkern.c
@@ -100,6 +100,28 @@ static int iio_dev_node_match(struct device *dev, void *data)
100 return dev->of_node == data && dev->type == &iio_device_type; 100 return dev->of_node == data && dev->type == &iio_device_type;
101} 101}
102 102
103/**
104 * __of_iio_simple_xlate - translate iiospec to the IIO channel index
105 * @indio_dev: pointer to the iio_dev structure
106 * @iiospec: IIO specifier as found in the device tree
107 *
108 * This is simple translation function, suitable for the most 1:1 mapped
109 * channels in IIO chips. This function performs only one sanity check:
110 * whether IIO index is less than num_channels (that is specified in the
111 * iio_dev).
112 */
113static int __of_iio_simple_xlate(struct iio_dev *indio_dev,
114 const struct of_phandle_args *iiospec)
115{
116 if (!iiospec->args_count)
117 return 0;
118
119 if (iiospec->args[0] >= indio_dev->num_channels)
120 return -EINVAL;
121
122 return iiospec->args[0];
123}
124
103static int __of_iio_channel_get(struct iio_channel *channel, 125static int __of_iio_channel_get(struct iio_channel *channel,
104 struct device_node *np, int index) 126 struct device_node *np, int index)
105{ 127{
@@ -122,18 +144,19 @@ static int __of_iio_channel_get(struct iio_channel *channel,
122 144
123 indio_dev = dev_to_iio_dev(idev); 145 indio_dev = dev_to_iio_dev(idev);
124 channel->indio_dev = indio_dev; 146 channel->indio_dev = indio_dev;
125 index = iiospec.args_count ? iiospec.args[0] : 0; 147 if (indio_dev->info->of_xlate)
126 if (index >= indio_dev->num_channels) { 148 index = indio_dev->info->of_xlate(indio_dev, &iiospec);
127 err = -EINVAL; 149 else
150 index = __of_iio_simple_xlate(indio_dev, &iiospec);
151 if (index < 0)
128 goto err_put; 152 goto err_put;
129 }
130 channel->channel = &indio_dev->channels[index]; 153 channel->channel = &indio_dev->channels[index];
131 154
132 return 0; 155 return 0;
133 156
134err_put: 157err_put:
135 iio_device_put(indio_dev); 158 iio_device_put(indio_dev);
136 return err; 159 return index;
137} 160}
138 161
139static struct iio_channel *of_iio_channel_get(struct device_node *np, int index) 162static struct iio_channel *of_iio_channel_get(struct device_node *np, int index)
diff --git a/drivers/iio/magnetometer/st_magn.h b/drivers/iio/magnetometer/st_magn.h
index 694e33e0fb72..7e81d00ef0c3 100644
--- a/drivers/iio/magnetometer/st_magn.h
+++ b/drivers/iio/magnetometer/st_magn.h
@@ -18,8 +18,7 @@
18#define LSM303DLM_MAGN_DEV_NAME "lsm303dlm_magn" 18#define LSM303DLM_MAGN_DEV_NAME "lsm303dlm_magn"
19#define LIS3MDL_MAGN_DEV_NAME "lis3mdl" 19#define LIS3MDL_MAGN_DEV_NAME "lis3mdl"
20 20
21int st_magn_common_probe(struct iio_dev *indio_dev, 21int st_magn_common_probe(struct iio_dev *indio_dev);
22 struct st_sensors_platform_data *pdata);
23void st_magn_common_remove(struct iio_dev *indio_dev); 22void st_magn_common_remove(struct iio_dev *indio_dev);
24 23
25#ifdef CONFIG_IIO_BUFFER 24#ifdef CONFIG_IIO_BUFFER
diff --git a/drivers/iio/magnetometer/st_magn_core.c b/drivers/iio/magnetometer/st_magn_core.c
index 68cae86dbd29..8ade473f99fe 100644
--- a/drivers/iio/magnetometer/st_magn_core.c
+++ b/drivers/iio/magnetometer/st_magn_core.c
@@ -149,7 +149,7 @@ static const struct iio_chan_spec st_magn_2_16bit_channels[] = {
149 IIO_CHAN_SOFT_TIMESTAMP(3) 149 IIO_CHAN_SOFT_TIMESTAMP(3)
150}; 150};
151 151
152static const struct st_sensors st_magn_sensors[] = { 152static const struct st_sensor_settings st_magn_sensors_settings[] = {
153 { 153 {
154 .wai = ST_MAGN_1_WAI_EXP, 154 .wai = ST_MAGN_1_WAI_EXP,
155 .sensors_supported = { 155 .sensors_supported = {
@@ -361,8 +361,7 @@ static const struct iio_info magn_info = {
361 .write_raw = &st_magn_write_raw, 361 .write_raw = &st_magn_write_raw,
362}; 362};
363 363
364int st_magn_common_probe(struct iio_dev *indio_dev, 364int st_magn_common_probe(struct iio_dev *indio_dev)
365 struct st_sensors_platform_data *pdata)
366{ 365{
367 struct st_sensor_data *mdata = iio_priv(indio_dev); 366 struct st_sensor_data *mdata = iio_priv(indio_dev);
368 int irq = mdata->get_irq_data_ready(indio_dev); 367 int irq = mdata->get_irq_data_ready(indio_dev);
@@ -374,20 +373,21 @@ int st_magn_common_probe(struct iio_dev *indio_dev,
374 st_sensors_power_enable(indio_dev); 373 st_sensors_power_enable(indio_dev);
375 374
376 err = st_sensors_check_device_support(indio_dev, 375 err = st_sensors_check_device_support(indio_dev,
377 ARRAY_SIZE(st_magn_sensors), st_magn_sensors); 376 ARRAY_SIZE(st_magn_sensors_settings),
377 st_magn_sensors_settings);
378 if (err < 0) 378 if (err < 0)
379 return err; 379 return err;
380 380
381 mdata->num_data_channels = ST_MAGN_NUMBER_DATA_CHANNELS; 381 mdata->num_data_channels = ST_MAGN_NUMBER_DATA_CHANNELS;
382 mdata->multiread_bit = mdata->sensor->multi_read_bit; 382 mdata->multiread_bit = mdata->sensor_settings->multi_read_bit;
383 indio_dev->channels = mdata->sensor->ch; 383 indio_dev->channels = mdata->sensor_settings->ch;
384 indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS; 384 indio_dev->num_channels = ST_SENSORS_NUMBER_ALL_CHANNELS;
385 385
386 mdata->current_fullscale = (struct st_sensor_fullscale_avl *) 386 mdata->current_fullscale = (struct st_sensor_fullscale_avl *)
387 &mdata->sensor->fs.fs_avl[0]; 387 &mdata->sensor_settings->fs.fs_avl[0];
388 mdata->odr = mdata->sensor->odr.odr_avl[0].hz; 388 mdata->odr = mdata->sensor_settings->odr.odr_avl[0].hz;
389 389
390 err = st_sensors_init_sensor(indio_dev, pdata); 390 err = st_sensors_init_sensor(indio_dev, NULL);
391 if (err < 0) 391 if (err < 0)
392 return err; 392 return err;
393 393
diff --git a/drivers/iio/magnetometer/st_magn_i2c.c b/drivers/iio/magnetometer/st_magn_i2c.c
index 689250058442..92e5c15452a3 100644
--- a/drivers/iio/magnetometer/st_magn_i2c.c
+++ b/drivers/iio/magnetometer/st_magn_i2c.c
@@ -51,12 +51,11 @@ static int st_magn_i2c_probe(struct i2c_client *client,
51 return -ENOMEM; 51 return -ENOMEM;
52 52
53 mdata = iio_priv(indio_dev); 53 mdata = iio_priv(indio_dev);
54 mdata->dev = &client->dev;
55 st_sensors_of_i2c_probe(client, st_magn_of_match); 54 st_sensors_of_i2c_probe(client, st_magn_of_match);
56 55
57 st_sensors_i2c_configure(indio_dev, client, mdata); 56 st_sensors_i2c_configure(indio_dev, client, mdata);
58 57
59 err = st_magn_common_probe(indio_dev, NULL); 58 err = st_magn_common_probe(indio_dev);
60 if (err < 0) 59 if (err < 0)
61 return err; 60 return err;
62 61
diff --git a/drivers/iio/magnetometer/st_magn_spi.c b/drivers/iio/magnetometer/st_magn_spi.c
index a6143ea51dfc..7adacf160146 100644
--- a/drivers/iio/magnetometer/st_magn_spi.c
+++ b/drivers/iio/magnetometer/st_magn_spi.c
@@ -29,11 +29,10 @@ static int st_magn_spi_probe(struct spi_device *spi)
29 return -ENOMEM; 29 return -ENOMEM;
30 30
31 mdata = iio_priv(indio_dev); 31 mdata = iio_priv(indio_dev);
32 mdata->dev = &spi->dev;
33 32
34 st_sensors_spi_configure(indio_dev, spi, mdata); 33 st_sensors_spi_configure(indio_dev, spi, mdata);
35 34
36 err = st_magn_common_probe(indio_dev, NULL); 35 err = st_magn_common_probe(indio_dev);
37 if (err < 0) 36 if (err < 0)
38 return err; 37 return err;
39 38
diff --git a/drivers/iio/pressure/Kconfig b/drivers/iio/pressure/Kconfig
index 15afbc919521..a3be53792072 100644
--- a/drivers/iio/pressure/Kconfig
+++ b/drivers/iio/pressure/Kconfig
@@ -5,6 +5,17 @@
5 5
6menu "Pressure sensors" 6menu "Pressure sensors"
7 7
8config BMP280
9 tristate "Bosch Sensortec BMP280 pressure sensor driver"
10 depends on I2C
11 select REGMAP_I2C
12 help
13 Say yes here to build support for Bosch Sensortec BMP280
14 pressure and temperature sensor.
15
16 To compile this driver as a module, choose M here: the module
17 will be called bmp280.
18
8config HID_SENSOR_PRESS 19config HID_SENSOR_PRESS
9 depends on HID_SENSOR_HUB 20 depends on HID_SENSOR_HUB
10 select IIO_BUFFER 21 select IIO_BUFFER
diff --git a/drivers/iio/pressure/Makefile b/drivers/iio/pressure/Makefile
index 90a37e85cf21..88011f2ae00e 100644
--- a/drivers/iio/pressure/Makefile
+++ b/drivers/iio/pressure/Makefile
@@ -3,6 +3,7 @@
3# 3#
4 4
5# When adding new entries keep the list in alphabetical order 5# When adding new entries keep the list in alphabetical order
6obj-$(CONFIG_BMP280) += bmp280.o
6obj-$(CONFIG_HID_SENSOR_PRESS) += hid-sensor-press.o 7obj-$(CONFIG_HID_SENSOR_PRESS) += hid-sensor-press.o
7obj-$(CONFIG_MPL115) += mpl115.o 8obj-$(CONFIG_MPL115) += mpl115.o
8obj-$(CONFIG_MPL3115) += mpl3115.o 9obj-$(CONFIG_MPL3115) += mpl3115.o
diff --git a/drivers/iio/pressure/bmp280.c b/drivers/iio/pressure/bmp280.c
new file mode 100644
index 000000000000..75038dacfff1
--- /dev/null
+++ b/drivers/iio/pressure/bmp280.c
@@ -0,0 +1,455 @@
1/*
2 * Copyright (c) 2014 Intel Corporation
3 *
4 * Driver for Bosch Sensortec BMP280 digital pressure sensor.
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
12#define pr_fmt(fmt) "bmp280: " fmt
13
14#include <linux/module.h>
15#include <linux/i2c.h>
16#include <linux/acpi.h>
17#include <linux/regmap.h>
18#include <linux/iio/iio.h>
19#include <linux/iio/sysfs.h>
20
21#define BMP280_REG_TEMP_XLSB 0xFC
22#define BMP280_REG_TEMP_LSB 0xFB
23#define BMP280_REG_TEMP_MSB 0xFA
24#define BMP280_REG_PRESS_XLSB 0xF9
25#define BMP280_REG_PRESS_LSB 0xF8
26#define BMP280_REG_PRESS_MSB 0xF7
27
28#define BMP280_REG_CONFIG 0xF5
29#define BMP280_REG_CTRL_MEAS 0xF4
30#define BMP280_REG_STATUS 0xF3
31#define BMP280_REG_RESET 0xE0
32#define BMP280_REG_ID 0xD0
33
34#define BMP280_REG_COMP_TEMP_START 0x88
35#define BMP280_COMP_TEMP_REG_COUNT 6
36
37#define BMP280_REG_COMP_PRESS_START 0x8E
38#define BMP280_COMP_PRESS_REG_COUNT 18
39
40#define BMP280_FILTER_MASK (BIT(4) | BIT(3) | BIT(2))
41#define BMP280_FILTER_OFF 0
42#define BMP280_FILTER_2X BIT(2)
43#define BMP280_FILTER_4X BIT(3)
44#define BMP280_FILTER_8X (BIT(3) | BIT(2))
45#define BMP280_FILTER_16X BIT(4)
46
47#define BMP280_OSRS_TEMP_MASK (BIT(7) | BIT(6) | BIT(5))
48#define BMP280_OSRS_TEMP_SKIP 0
49#define BMP280_OSRS_TEMP_1X BIT(5)
50#define BMP280_OSRS_TEMP_2X BIT(6)
51#define BMP280_OSRS_TEMP_4X (BIT(6) | BIT(5))
52#define BMP280_OSRS_TEMP_8X BIT(7)
53#define BMP280_OSRS_TEMP_16X (BIT(7) | BIT(5))
54
55#define BMP280_OSRS_PRESS_MASK (BIT(4) | BIT(3) | BIT(2))
56#define BMP280_OSRS_PRESS_SKIP 0
57#define BMP280_OSRS_PRESS_1X BIT(2)
58#define BMP280_OSRS_PRESS_2X BIT(3)
59#define BMP280_OSRS_PRESS_4X (BIT(3) | BIT(2))
60#define BMP280_OSRS_PRESS_8X BIT(4)
61#define BMP280_OSRS_PRESS_16X (BIT(4) | BIT(2))
62
63#define BMP280_MODE_MASK (BIT(1) | BIT(0))
64#define BMP280_MODE_SLEEP 0
65#define BMP280_MODE_FORCED BIT(0)
66#define BMP280_MODE_NORMAL (BIT(1) | BIT(0))
67
68#define BMP280_CHIP_ID 0x58
69#define BMP280_SOFT_RESET_VAL 0xB6
70
71struct bmp280_data {
72 struct i2c_client *client;
73 struct mutex lock;
74 struct regmap *regmap;
75
76 /*
77 * Carryover value from temperature conversion, used in pressure
78 * calculation.
79 */
80 s32 t_fine;
81};
82
83/* Compensation parameters. */
84struct bmp280_comp_temp {
85 u16 dig_t1;
86 s16 dig_t2, dig_t3;
87};
88
89struct bmp280_comp_press {
90 u16 dig_p1;
91 s16 dig_p2, dig_p3, dig_p4, dig_p5, dig_p6, dig_p7, dig_p8, dig_p9;
92};
93
94static const struct iio_chan_spec bmp280_channels[] = {
95 {
96 .type = IIO_PRESSURE,
97 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
98 },
99 {
100 .type = IIO_TEMP,
101 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
102 },
103};
104
105static bool bmp280_is_writeable_reg(struct device *dev, unsigned int reg)
106{
107 switch (reg) {
108 case BMP280_REG_CONFIG:
109 case BMP280_REG_CTRL_MEAS:
110 case BMP280_REG_RESET:
111 return true;
112 default:
113 return false;
114 };
115}
116
117static bool bmp280_is_volatile_reg(struct device *dev, unsigned int reg)
118{
119 switch (reg) {
120 case BMP280_REG_TEMP_XLSB:
121 case BMP280_REG_TEMP_LSB:
122 case BMP280_REG_TEMP_MSB:
123 case BMP280_REG_PRESS_XLSB:
124 case BMP280_REG_PRESS_LSB:
125 case BMP280_REG_PRESS_MSB:
126 case BMP280_REG_STATUS:
127 return true;
128 default:
129 return false;
130 }
131}
132
133static const struct regmap_config bmp280_regmap_config = {
134 .reg_bits = 8,
135 .val_bits = 8,
136
137 .max_register = BMP280_REG_TEMP_XLSB,
138 .cache_type = REGCACHE_RBTREE,
139
140 .writeable_reg = bmp280_is_writeable_reg,
141 .volatile_reg = bmp280_is_volatile_reg,
142};
143
144static int bmp280_read_compensation_temp(struct bmp280_data *data,
145 struct bmp280_comp_temp *comp)
146{
147 int ret;
148 __le16 buf[BMP280_COMP_TEMP_REG_COUNT / 2];
149
150 ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_TEMP_START,
151 buf, BMP280_COMP_TEMP_REG_COUNT);
152 if (ret < 0) {
153 dev_err(&data->client->dev,
154 "failed to read temperature calibration parameters\n");
155 return ret;
156 }
157
158 comp->dig_t1 = (u16) le16_to_cpu(buf[0]);
159 comp->dig_t2 = (s16) le16_to_cpu(buf[1]);
160 comp->dig_t3 = (s16) le16_to_cpu(buf[2]);
161
162 return 0;
163}
164
165static int bmp280_read_compensation_press(struct bmp280_data *data,
166 struct bmp280_comp_press *comp)
167{
168 int ret;
169 __le16 buf[BMP280_COMP_PRESS_REG_COUNT / 2];
170
171 ret = regmap_bulk_read(data->regmap, BMP280_REG_COMP_PRESS_START,
172 buf, BMP280_COMP_PRESS_REG_COUNT);
173 if (ret < 0) {
174 dev_err(&data->client->dev,
175 "failed to read pressure calibration parameters\n");
176 return ret;
177 }
178
179 comp->dig_p1 = (u16) le16_to_cpu(buf[0]);
180 comp->dig_p2 = (s16) le16_to_cpu(buf[1]);
181 comp->dig_p3 = (s16) le16_to_cpu(buf[2]);
182 comp->dig_p4 = (s16) le16_to_cpu(buf[3]);
183 comp->dig_p5 = (s16) le16_to_cpu(buf[4]);
184 comp->dig_p6 = (s16) le16_to_cpu(buf[5]);
185 comp->dig_p7 = (s16) le16_to_cpu(buf[6]);
186 comp->dig_p8 = (s16) le16_to_cpu(buf[7]);
187 comp->dig_p9 = (s16) le16_to_cpu(buf[8]);
188
189 return 0;
190}
191
192/*
193 * Returns temperature in DegC, resolution is 0.01 DegC. Output value of
194 * "5123" equals 51.23 DegC. t_fine carries fine temperature as global
195 * value.
196 *
197 * Taken from datasheet, Section 3.11.3, "Compensation formula".
198 */
199static s32 bmp280_compensate_temp(struct bmp280_data *data,
200 struct bmp280_comp_temp *comp,
201 s32 adc_temp)
202{
203 s32 var1, var2, t;
204
205 var1 = (((adc_temp >> 3) - ((s32) comp->dig_t1 << 1)) *
206 ((s32) comp->dig_t2)) >> 11;
207 var2 = (((((adc_temp >> 4) - ((s32) comp->dig_t1)) *
208 ((adc_temp >> 4) - ((s32) comp->dig_t1))) >> 12) *
209 ((s32) comp->dig_t3)) >> 14;
210
211 data->t_fine = var1 + var2;
212 t = (data->t_fine * 5 + 128) >> 8;
213
214 return t;
215}
216
217/*
218 * Returns pressure in Pa as unsigned 32 bit integer in Q24.8 format (24
219 * integer bits and 8 fractional bits). Output value of "24674867"
220 * represents 24674867/256 = 96386.2 Pa = 963.862 hPa
221 *
222 * Taken from datasheet, Section 3.11.3, "Compensation formula".
223 */
224static u32 bmp280_compensate_press(struct bmp280_data *data,
225 struct bmp280_comp_press *comp,
226 s32 adc_press)
227{
228 s64 var1, var2, p;
229
230 var1 = ((s64) data->t_fine) - 128000;
231 var2 = var1 * var1 * (s64) comp->dig_p6;
232 var2 = var2 + ((var1 * (s64) comp->dig_p5) << 17);
233 var2 = var2 + (((s64) comp->dig_p4) << 35);
234 var1 = ((var1 * var1 * (s64) comp->dig_p3) >> 8) +
235 ((var1 * (s64) comp->dig_p2) << 12);
236 var1 = (((((s64) 1) << 47) + var1)) * ((s64) comp->dig_p1) >> 33;
237
238 if (var1 == 0)
239 return 0;
240
241 p = ((((s64) 1048576 - adc_press) << 31) - var2) * 3125;
242 p = div64_s64(p, var1);
243 var1 = (((s64) comp->dig_p9) * (p >> 13) * (p >> 13)) >> 25;
244 var2 = (((s64) comp->dig_p8) * p) >> 19;
245 p = ((p + var1 + var2) >> 8) + (((s64) comp->dig_p7) << 4);
246
247 return (u32) p;
248}
249
250static int bmp280_read_temp(struct bmp280_data *data,
251 int *val)
252{
253 int ret;
254 __be32 tmp = 0;
255 s32 adc_temp, comp_temp;
256 struct bmp280_comp_temp comp;
257
258 ret = bmp280_read_compensation_temp(data, &comp);
259 if (ret < 0)
260 return ret;
261
262 ret = regmap_bulk_read(data->regmap, BMP280_REG_TEMP_MSB,
263 (u8 *) &tmp, 3);
264 if (ret < 0) {
265 dev_err(&data->client->dev, "failed to read temperature\n");
266 return ret;
267 }
268
269 adc_temp = be32_to_cpu(tmp) >> 12;
270 comp_temp = bmp280_compensate_temp(data, &comp, adc_temp);
271
272 /*
273 * val might be NULL if we're called by the read_press routine,
274 * who only cares about the carry over t_fine value.
275 */
276 if (val) {
277 *val = comp_temp * 10;
278 return IIO_VAL_INT;
279 }
280
281 return 0;
282}
283
284static int bmp280_read_press(struct bmp280_data *data,
285 int *val, int *val2)
286{
287 int ret;
288 __be32 tmp = 0;
289 s32 adc_press;
290 u32 comp_press;
291 struct bmp280_comp_press comp;
292
293 ret = bmp280_read_compensation_press(data, &comp);
294 if (ret < 0)
295 return ret;
296
297 /* Read and compensate temperature so we get a reading of t_fine. */
298 ret = bmp280_read_temp(data, NULL);
299 if (ret < 0)
300 return ret;
301
302 ret = regmap_bulk_read(data->regmap, BMP280_REG_PRESS_MSB,
303 (u8 *) &tmp, 3);
304 if (ret < 0) {
305 dev_err(&data->client->dev, "failed to read pressure\n");
306 return ret;
307 }
308
309 adc_press = be32_to_cpu(tmp) >> 12;
310 comp_press = bmp280_compensate_press(data, &comp, adc_press);
311
312 *val = comp_press;
313 *val2 = 256000;
314
315 return IIO_VAL_FRACTIONAL;
316}
317
318static int bmp280_read_raw(struct iio_dev *indio_dev,
319 struct iio_chan_spec const *chan,
320 int *val, int *val2, long mask)
321{
322 int ret;
323 struct bmp280_data *data = iio_priv(indio_dev);
324
325 mutex_lock(&data->lock);
326
327 switch (mask) {
328 case IIO_CHAN_INFO_PROCESSED:
329 switch (chan->type) {
330 case IIO_PRESSURE:
331 ret = bmp280_read_press(data, val, val2);
332 break;
333 case IIO_TEMP:
334 ret = bmp280_read_temp(data, val);
335 break;
336 default:
337 ret = -EINVAL;
338 break;
339 }
340 break;
341 default:
342 ret = -EINVAL;
343 break;
344 }
345
346 mutex_unlock(&data->lock);
347
348 return ret;
349}
350
351static const struct iio_info bmp280_info = {
352 .driver_module = THIS_MODULE,
353 .read_raw = &bmp280_read_raw,
354};
355
356static int bmp280_chip_init(struct bmp280_data *data)
357{
358 int ret;
359
360 ret = regmap_update_bits(data->regmap, BMP280_REG_CTRL_MEAS,
361 BMP280_OSRS_TEMP_MASK |
362 BMP280_OSRS_PRESS_MASK |
363 BMP280_MODE_MASK,
364 BMP280_OSRS_TEMP_2X |
365 BMP280_OSRS_PRESS_16X |
366 BMP280_MODE_NORMAL);
367 if (ret < 0) {
368 dev_err(&data->client->dev,
369 "failed to write config register\n");
370 return ret;
371 }
372
373 ret = regmap_update_bits(data->regmap, BMP280_REG_CONFIG,
374 BMP280_FILTER_MASK,
375 BMP280_FILTER_4X);
376 if (ret < 0) {
377 dev_err(&data->client->dev,
378 "failed to write config register\n");
379 return ret;
380 }
381
382 return ret;
383}
384
385static int bmp280_probe(struct i2c_client *client,
386 const struct i2c_device_id *id)
387{
388 int ret;
389 struct iio_dev *indio_dev;
390 struct bmp280_data *data;
391 unsigned int chip_id;
392
393 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
394 if (!indio_dev)
395 return -ENOMEM;
396
397 i2c_set_clientdata(client, indio_dev);
398 data = iio_priv(indio_dev);
399 mutex_init(&data->lock);
400 data->client = client;
401
402 indio_dev->dev.parent = &client->dev;
403 indio_dev->name = id->name;
404 indio_dev->channels = bmp280_channels;
405 indio_dev->num_channels = ARRAY_SIZE(bmp280_channels);
406 indio_dev->info = &bmp280_info;
407 indio_dev->modes = INDIO_DIRECT_MODE;
408
409 data->regmap = devm_regmap_init_i2c(client, &bmp280_regmap_config);
410 if (IS_ERR(data->regmap)) {
411 dev_err(&client->dev, "failed to allocate register map\n");
412 return PTR_ERR(data->regmap);
413 }
414
415 ret = regmap_read(data->regmap, BMP280_REG_ID, &chip_id);
416 if (ret < 0)
417 return ret;
418 if (chip_id != BMP280_CHIP_ID) {
419 dev_err(&client->dev, "bad chip id. expected %x got %x\n",
420 BMP280_CHIP_ID, chip_id);
421 return -EINVAL;
422 }
423
424 ret = bmp280_chip_init(data);
425 if (ret < 0)
426 return ret;
427
428 return devm_iio_device_register(&client->dev, indio_dev);
429}
430
431static const struct acpi_device_id bmp280_acpi_match[] = {
432 {"BMP0280", 0},
433 { },
434};
435MODULE_DEVICE_TABLE(acpi, bmp280_acpi_match);
436
437static const struct i2c_device_id bmp280_id[] = {
438 {"bmp280", 0},
439 { },
440};
441MODULE_DEVICE_TABLE(i2c, bmp280_id);
442
443static struct i2c_driver bmp280_driver = {
444 .driver = {
445 .name = "bmp280",
446 .acpi_match_table = ACPI_PTR(bmp280_acpi_match),
447 },
448 .probe = bmp280_probe,
449 .id_table = bmp280_id,
450};
451module_i2c_driver(bmp280_driver);
452
453MODULE_AUTHOR("Vlad Dogaru <vlad.dogaru@intel.com>");
454MODULE_DESCRIPTION("Driver for Bosch Sensortec BMP280 pressure and temperature sensor");
455MODULE_LICENSE("GPL v2");
diff --git a/drivers/iio/pressure/st_pressure.h b/drivers/iio/pressure/st_pressure.h
index 242943c0c4e4..f5f41490060b 100644
--- a/drivers/iio/pressure/st_pressure.h
+++ b/drivers/iio/pressure/st_pressure.h
@@ -26,8 +26,7 @@ static const struct st_sensors_platform_data default_press_pdata = {
26 .drdy_int_pin = 1, 26 .drdy_int_pin = 1,
27}; 27};
28 28
29int st_press_common_probe(struct iio_dev *indio_dev, 29int st_press_common_probe(struct iio_dev *indio_dev);
30 struct st_sensors_platform_data *pdata);
31void st_press_common_remove(struct iio_dev *indio_dev); 30void st_press_common_remove(struct iio_dev *indio_dev);
32 31
33#ifdef CONFIG_IIO_BUFFER 32#ifdef CONFIG_IIO_BUFFER
diff --git a/drivers/iio/pressure/st_pressure_buffer.c b/drivers/iio/pressure/st_pressure_buffer.c
index b37b1c9ac932..2ff53f222352 100644
--- a/drivers/iio/pressure/st_pressure_buffer.c
+++ b/drivers/iio/pressure/st_pressure_buffer.c
@@ -38,10 +38,10 @@ static int st_press_buffer_preenable(struct iio_dev *indio_dev)
38static int st_press_buffer_postenable(struct iio_dev *indio_dev) 38static int st_press_buffer_postenable(struct iio_dev *indio_dev)
39{ 39{
40 int err; 40 int err;
41 struct st_sensor_data *pdata = iio_priv(indio_dev); 41 struct st_sensor_data *press_data = iio_priv(indio_dev);
42 42
43 pdata->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL); 43 press_data->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
44 if (pdata->buffer_data == NULL) { 44 if (press_data->buffer_data == NULL) {
45 err = -ENOMEM; 45 err = -ENOMEM;
46 goto allocate_memory_error; 46 goto allocate_memory_error;
47 } 47 }
@@ -53,7 +53,7 @@ static int st_press_buffer_postenable(struct iio_dev *indio_dev)
53 return err; 53 return err;
54 54
55st_press_buffer_postenable_error: 55st_press_buffer_postenable_error:
56 kfree(pdata->buffer_data); 56 kfree(press_data->buffer_data);
57allocate_memory_error: 57allocate_memory_error:
58 return err; 58 return err;
59} 59}
@@ -61,7 +61,7 @@ allocate_memory_error:
61static int st_press_buffer_predisable(struct iio_dev *indio_dev) 61static int st_press_buffer_predisable(struct iio_dev *indio_dev)
62{ 62{
63 int err; 63 int err;
64 struct st_sensor_data *pdata = iio_priv(indio_dev); 64 struct st_sensor_data *press_data = iio_priv(indio_dev);
65 65
66 err = iio_triggered_buffer_predisable(indio_dev); 66 err = iio_triggered_buffer_predisable(indio_dev);
67 if (err < 0) 67 if (err < 0)
@@ -70,7 +70,7 @@ static int st_press_buffer_predisable(struct iio_dev *indio_dev)
70 err = st_sensors_set_enable(indio_dev, false); 70 err = st_sensors_set_enable(indio_dev, false);
71 71
72st_press_buffer_predisable_error: 72st_press_buffer_predisable_error:
73 kfree(pdata->buffer_data); 73 kfree(press_data->buffer_data);
74 return err; 74 return err;
75} 75}
76 76
diff --git a/drivers/iio/pressure/st_pressure_core.c b/drivers/iio/pressure/st_pressure_core.c
index 473d914ef470..97baf40d424b 100644
--- a/drivers/iio/pressure/st_pressure_core.c
+++ b/drivers/iio/pressure/st_pressure_core.c
@@ -175,7 +175,7 @@ static const struct iio_chan_spec st_press_lps001wp_channels[] = {
175 IIO_CHAN_SOFT_TIMESTAMP(1) 175 IIO_CHAN_SOFT_TIMESTAMP(1)
176}; 176};
177 177
178static const struct st_sensors st_press_sensors[] = { 178static const struct st_sensor_settings st_press_sensors_settings[] = {
179 { 179 {
180 .wai = ST_PRESS_LPS331AP_WAI_EXP, 180 .wai = ST_PRESS_LPS331AP_WAI_EXP,
181 .sensors_supported = { 181 .sensors_supported = {
@@ -333,7 +333,7 @@ static int st_press_read_raw(struct iio_dev *indio_dev,
333 int *val2, long mask) 333 int *val2, long mask)
334{ 334{
335 int err; 335 int err;
336 struct st_sensor_data *pdata = iio_priv(indio_dev); 336 struct st_sensor_data *press_data = iio_priv(indio_dev);
337 337
338 switch (mask) { 338 switch (mask) {
339 case IIO_CHAN_INFO_RAW: 339 case IIO_CHAN_INFO_RAW:
@@ -347,10 +347,10 @@ static int st_press_read_raw(struct iio_dev *indio_dev,
347 347
348 switch (ch->type) { 348 switch (ch->type) {
349 case IIO_PRESSURE: 349 case IIO_PRESSURE:
350 *val2 = pdata->current_fullscale->gain; 350 *val2 = press_data->current_fullscale->gain;
351 break; 351 break;
352 case IIO_TEMP: 352 case IIO_TEMP:
353 *val2 = pdata->current_fullscale->gain2; 353 *val2 = press_data->current_fullscale->gain2;
354 break; 354 break;
355 default: 355 default:
356 err = -EINVAL; 356 err = -EINVAL;
@@ -371,7 +371,7 @@ static int st_press_read_raw(struct iio_dev *indio_dev,
371 371
372 return IIO_VAL_FRACTIONAL; 372 return IIO_VAL_FRACTIONAL;
373 case IIO_CHAN_INFO_SAMP_FREQ: 373 case IIO_CHAN_INFO_SAMP_FREQ:
374 *val = pdata->odr; 374 *val = press_data->odr;
375 return IIO_VAL_INT; 375 return IIO_VAL_INT;
376 default: 376 default:
377 return -EINVAL; 377 return -EINVAL;
@@ -409,11 +409,10 @@ static const struct iio_trigger_ops st_press_trigger_ops = {
409#define ST_PRESS_TRIGGER_OPS NULL 409#define ST_PRESS_TRIGGER_OPS NULL
410#endif 410#endif
411 411
412int st_press_common_probe(struct iio_dev *indio_dev, 412int st_press_common_probe(struct iio_dev *indio_dev)
413 struct st_sensors_platform_data *plat_data)
414{ 413{
415 struct st_sensor_data *pdata = iio_priv(indio_dev); 414 struct st_sensor_data *press_data = iio_priv(indio_dev);
416 int irq = pdata->get_irq_data_ready(indio_dev); 415 int irq = press_data->get_irq_data_ready(indio_dev);
417 int err; 416 int err;
418 417
419 indio_dev->modes = INDIO_DIRECT_MODE; 418 indio_dev->modes = INDIO_DIRECT_MODE;
@@ -422,28 +421,30 @@ int st_press_common_probe(struct iio_dev *indio_dev,
422 st_sensors_power_enable(indio_dev); 421 st_sensors_power_enable(indio_dev);
423 422
424 err = st_sensors_check_device_support(indio_dev, 423 err = st_sensors_check_device_support(indio_dev,
425 ARRAY_SIZE(st_press_sensors), 424 ARRAY_SIZE(st_press_sensors_settings),
426 st_press_sensors); 425 st_press_sensors_settings);
427 if (err < 0) 426 if (err < 0)
428 return err; 427 return err;
429 428
430 pdata->num_data_channels = ST_PRESS_NUMBER_DATA_CHANNELS; 429 press_data->num_data_channels = ST_PRESS_NUMBER_DATA_CHANNELS;
431 pdata->multiread_bit = pdata->sensor->multi_read_bit; 430 press_data->multiread_bit = press_data->sensor_settings->multi_read_bit;
432 indio_dev->channels = pdata->sensor->ch; 431 indio_dev->channels = press_data->sensor_settings->ch;
433 indio_dev->num_channels = pdata->sensor->num_ch; 432 indio_dev->num_channels = press_data->sensor_settings->num_ch;
434 433
435 if (pdata->sensor->fs.addr != 0) 434 if (press_data->sensor_settings->fs.addr != 0)
436 pdata->current_fullscale = (struct st_sensor_fullscale_avl *) 435 press_data->current_fullscale =
437 &pdata->sensor->fs.fs_avl[0]; 436 (struct st_sensor_fullscale_avl *)
437 &press_data->sensor_settings->fs.fs_avl[0];
438 438
439 pdata->odr = pdata->sensor->odr.odr_avl[0].hz; 439 press_data->odr = press_data->sensor_settings->odr.odr_avl[0].hz;
440 440
441 /* Some devices don't support a data ready pin. */ 441 /* Some devices don't support a data ready pin. */
442 if (!plat_data && pdata->sensor->drdy_irq.addr) 442 if (!press_data->dev->platform_data &&
443 plat_data = 443 press_data->sensor_settings->drdy_irq.addr)
444 press_data->dev->platform_data =
444 (struct st_sensors_platform_data *)&default_press_pdata; 445 (struct st_sensors_platform_data *)&default_press_pdata;
445 446
446 err = st_sensors_init_sensor(indio_dev, plat_data); 447 err = st_sensors_init_sensor(indio_dev, press_data->dev->platform_data);
447 if (err < 0) 448 if (err < 0)
448 return err; 449 return err;
449 450
@@ -479,12 +480,12 @@ EXPORT_SYMBOL(st_press_common_probe);
479 480
480void st_press_common_remove(struct iio_dev *indio_dev) 481void st_press_common_remove(struct iio_dev *indio_dev)
481{ 482{
482 struct st_sensor_data *pdata = iio_priv(indio_dev); 483 struct st_sensor_data *press_data = iio_priv(indio_dev);
483 484
484 st_sensors_power_disable(indio_dev); 485 st_sensors_power_disable(indio_dev);
485 486
486 iio_device_unregister(indio_dev); 487 iio_device_unregister(indio_dev);
487 if (pdata->get_irq_data_ready(indio_dev) > 0) 488 if (press_data->get_irq_data_ready(indio_dev) > 0)
488 st_sensors_deallocate_trigger(indio_dev); 489 st_sensors_deallocate_trigger(indio_dev);
489 490
490 st_press_deallocate_ring(indio_dev); 491 st_press_deallocate_ring(indio_dev);
diff --git a/drivers/iio/pressure/st_pressure_i2c.c b/drivers/iio/pressure/st_pressure_i2c.c
index acaf165260bb..137788bba4a3 100644
--- a/drivers/iio/pressure/st_pressure_i2c.c
+++ b/drivers/iio/pressure/st_pressure_i2c.c
@@ -43,20 +43,19 @@ static int st_press_i2c_probe(struct i2c_client *client,
43 const struct i2c_device_id *id) 43 const struct i2c_device_id *id)
44{ 44{
45 struct iio_dev *indio_dev; 45 struct iio_dev *indio_dev;
46 struct st_sensor_data *pdata; 46 struct st_sensor_data *press_data;
47 int err; 47 int err;
48 48
49 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*pdata)); 49 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*press_data));
50 if (!indio_dev) 50 if (!indio_dev)
51 return -ENOMEM; 51 return -ENOMEM;
52 52
53 pdata = iio_priv(indio_dev); 53 press_data = iio_priv(indio_dev);
54 pdata->dev = &client->dev;
55 st_sensors_of_i2c_probe(client, st_press_of_match); 54 st_sensors_of_i2c_probe(client, st_press_of_match);
56 55
57 st_sensors_i2c_configure(indio_dev, client, pdata); 56 st_sensors_i2c_configure(indio_dev, client, press_data);
58 57
59 err = st_press_common_probe(indio_dev, client->dev.platform_data); 58 err = st_press_common_probe(indio_dev);
60 if (err < 0) 59 if (err < 0)
61 return err; 60 return err;
62 61
diff --git a/drivers/iio/pressure/st_pressure_spi.c b/drivers/iio/pressure/st_pressure_spi.c
index f45d430ec529..1ffa6d4d349c 100644
--- a/drivers/iio/pressure/st_pressure_spi.c
+++ b/drivers/iio/pressure/st_pressure_spi.c
@@ -21,19 +21,18 @@
21static int st_press_spi_probe(struct spi_device *spi) 21static int st_press_spi_probe(struct spi_device *spi)
22{ 22{
23 struct iio_dev *indio_dev; 23 struct iio_dev *indio_dev;
24 struct st_sensor_data *pdata; 24 struct st_sensor_data *press_data;
25 int err; 25 int err;
26 26
27 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*pdata)); 27 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*press_data));
28 if (indio_dev == NULL) 28 if (indio_dev == NULL)
29 return -ENOMEM; 29 return -ENOMEM;
30 30
31 pdata = iio_priv(indio_dev); 31 press_data = iio_priv(indio_dev);
32 pdata->dev = &spi->dev;
33 32
34 st_sensors_spi_configure(indio_dev, spi, pdata); 33 st_sensors_spi_configure(indio_dev, spi, press_data);
35 34
36 err = st_press_common_probe(indio_dev, spi->dev.platform_data); 35 err = st_press_common_probe(indio_dev);
37 if (err < 0) 36 if (err < 0)
38 return err; 37 return err;
39 38
diff --git a/drivers/iio/proximity/as3935.c b/drivers/iio/proximity/as3935.c
index 8349cc0fdf66..466aa4314667 100644
--- a/drivers/iio/proximity/as3935.c
+++ b/drivers/iio/proximity/as3935.c
@@ -95,7 +95,7 @@ static int as3935_read(struct as3935_state *st, unsigned int reg, int *val)
95 *val = ret; 95 *val = ret;
96 96
97 return 0; 97 return 0;
98}; 98}
99 99
100static int as3935_write(struct as3935_state *st, 100static int as3935_write(struct as3935_state *st,
101 unsigned int reg, 101 unsigned int reg,
@@ -107,7 +107,7 @@ static int as3935_write(struct as3935_state *st,
107 buf[1] = val; 107 buf[1] = val;
108 108
109 return spi_write(st->spi, buf, 2); 109 return spi_write(st->spi, buf, 2);
110}; 110}
111 111
112static ssize_t as3935_sensor_sensitivity_show(struct device *dev, 112static ssize_t as3935_sensor_sensitivity_show(struct device *dev,
113 struct device_attribute *attr, 113 struct device_attribute *attr,
@@ -122,7 +122,7 @@ static ssize_t as3935_sensor_sensitivity_show(struct device *dev,
122 val = (val & AS3935_AFE_MASK) >> 1; 122 val = (val & AS3935_AFE_MASK) >> 1;
123 123
124 return sprintf(buf, "%d\n", val); 124 return sprintf(buf, "%d\n", val);
125}; 125}
126 126
127static ssize_t as3935_sensor_sensitivity_store(struct device *dev, 127static ssize_t as3935_sensor_sensitivity_store(struct device *dev,
128 struct device_attribute *attr, 128 struct device_attribute *attr,
@@ -142,7 +142,7 @@ static ssize_t as3935_sensor_sensitivity_store(struct device *dev,
142 as3935_write(st, AS3935_AFE_GAIN, val << 1); 142 as3935_write(st, AS3935_AFE_GAIN, val << 1);
143 143
144 return len; 144 return len;
145}; 145}
146 146
147static IIO_DEVICE_ATTR(sensor_sensitivity, S_IRUGO | S_IWUSR, 147static IIO_DEVICE_ATTR(sensor_sensitivity, S_IRUGO | S_IWUSR,
148 as3935_sensor_sensitivity_show, as3935_sensor_sensitivity_store, 0); 148 as3935_sensor_sensitivity_show, as3935_sensor_sensitivity_store, 0);
@@ -214,7 +214,7 @@ err_read:
214 iio_trigger_notify_done(indio_dev->trig); 214 iio_trigger_notify_done(indio_dev->trig);
215 215
216 return IRQ_HANDLED; 216 return IRQ_HANDLED;
217}; 217}
218 218
219static const struct iio_trigger_ops iio_interrupt_trigger_ops = { 219static const struct iio_trigger_ops iio_interrupt_trigger_ops = {
220 .owner = THIS_MODULE, 220 .owner = THIS_MODULE,
@@ -238,7 +238,7 @@ static void as3935_event_work(struct work_struct *work)
238 dev_warn(&st->spi->dev, "noise level is too high"); 238 dev_warn(&st->spi->dev, "noise level is too high");
239 break; 239 break;
240 } 240 }
241}; 241}
242 242
243static irqreturn_t as3935_interrupt_handler(int irq, void *private) 243static irqreturn_t as3935_interrupt_handler(int irq, void *private)
244{ 244{
@@ -417,7 +417,7 @@ unregister_trigger:
417 iio_trigger_unregister(st->trig); 417 iio_trigger_unregister(st->trig);
418 418
419 return ret; 419 return ret;
420}; 420}
421 421
422static int as3935_remove(struct spi_device *spi) 422static int as3935_remove(struct spi_device *spi)
423{ 423{
@@ -429,7 +429,7 @@ static int as3935_remove(struct spi_device *spi)
429 iio_trigger_unregister(st->trig); 429 iio_trigger_unregister(st->trig);
430 430
431 return 0; 431 return 0;
432}; 432}
433 433
434static const struct spi_device_id as3935_id[] = { 434static const struct spi_device_id as3935_id[] = {
435 {"as3935", 0}, 435 {"as3935", 0},
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index 9425728b7eb5..815de379a130 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -62,8 +62,6 @@ source "drivers/staging/xgifb/Kconfig"
62 62
63source "drivers/staging/emxx_udc/Kconfig" 63source "drivers/staging/emxx_udc/Kconfig"
64 64
65source "drivers/staging/bcm/Kconfig"
66
67source "drivers/staging/ft1000/Kconfig" 65source "drivers/staging/ft1000/Kconfig"
68 66
69source "drivers/staging/speakup/Kconfig" 67source "drivers/staging/speakup/Kconfig"
@@ -106,4 +104,6 @@ source "drivers/staging/skein/Kconfig"
106 104
107source "drivers/staging/unisys/Kconfig" 105source "drivers/staging/unisys/Kconfig"
108 106
107source "drivers/staging/clocking-wizard/Kconfig"
108
109endif # STAGING 109endif # STAGING
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index bc233dd98a95..33c640b49566 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -25,7 +25,6 @@ obj-$(CONFIG_VME_BUS) += vme/
25obj-$(CONFIG_IIO) += iio/ 25obj-$(CONFIG_IIO) += iio/
26obj-$(CONFIG_FB_XGI) += xgifb/ 26obj-$(CONFIG_FB_XGI) += xgifb/
27obj-$(CONFIG_USB_EMXX) += emxx_udc/ 27obj-$(CONFIG_USB_EMXX) += emxx_udc/
28obj-$(CONFIG_BCM_WIMAX) += bcm/
29obj-$(CONFIG_FT1000) += ft1000/ 28obj-$(CONFIG_FT1000) += ft1000/
30obj-$(CONFIG_SPEAKUP) += speakup/ 29obj-$(CONFIG_SPEAKUP) += speakup/
31obj-$(CONFIG_TOUCHSCREEN_CLEARPAD_TM1217) += cptm1217/ 30obj-$(CONFIG_TOUCHSCREEN_CLEARPAD_TM1217) += cptm1217/
@@ -45,3 +44,4 @@ obj-$(CONFIG_MTD_SPINAND_MT29F) += mt29f_spinand/
45obj-$(CONFIG_GS_FPGABOOT) += gs_fpgaboot/ 44obj-$(CONFIG_GS_FPGABOOT) += gs_fpgaboot/
46obj-$(CONFIG_CRYPTO_SKEIN) += skein/ 45obj-$(CONFIG_CRYPTO_SKEIN) += skein/
47obj-$(CONFIG_UNISYSSPAR) += unisys/ 46obj-$(CONFIG_UNISYSSPAR) += unisys/
47obj-$(CONFIG_COMMON_CLK_XLNX_CLKWZRD) += clocking-wizard/
diff --git a/drivers/staging/android/Kconfig b/drivers/staging/android/Kconfig
index 7a0e28852965..7e012f37792b 100644
--- a/drivers/staging/android/Kconfig
+++ b/drivers/staging/android/Kconfig
@@ -1,37 +1,7 @@
1menu "Android" 1menu "Android"
2 2
3config ANDROID
4 bool "Android Drivers"
5 ---help---
6 Enable support for various drivers needed on the Android platform
7
8if ANDROID 3if ANDROID
9 4
10config ANDROID_BINDER_IPC
11 bool "Android Binder IPC Driver"
12 depends on MMU
13 default n
14 ---help---
15 Binder is used in Android for both communication between processes,
16 and remote method invocation.
17
18 This means one Android process can call a method/routine in another
19 Android process, using Binder to identify, invoke and pass arguments
20 between said processes.
21
22config ANDROID_BINDER_IPC_32BIT
23 bool
24 depends on !64BIT && ANDROID_BINDER_IPC
25 default y
26 ---help---
27 The Binder API has been changed to support both 32 and 64bit
28 applications in a mixed environment.
29
30 Enable this to support an old 32-bit Android user-space (v4.4 and
31 earlier).
32
33 Note that enabling this will break newer Android user-space.
34
35config ASHMEM 5config ASHMEM
36 bool "Enable the Anonymous Shared Memory Subsystem" 6 bool "Enable the Anonymous Shared Memory Subsystem"
37 default n 7 default n
diff --git a/drivers/staging/android/Makefile b/drivers/staging/android/Makefile
index 517ad5ffa429..479b2b86f8c8 100644
--- a/drivers/staging/android/Makefile
+++ b/drivers/staging/android/Makefile
@@ -2,7 +2,6 @@ ccflags-y += -I$(src) # needed for trace events
2 2
3obj-y += ion/ 3obj-y += ion/
4 4
5obj-$(CONFIG_ANDROID_BINDER_IPC) += binder.o
6obj-$(CONFIG_ASHMEM) += ashmem.o 5obj-$(CONFIG_ASHMEM) += ashmem.o
7obj-$(CONFIG_ANDROID_LOGGER) += logger.o 6obj-$(CONFIG_ANDROID_LOGGER) += logger.o
8obj-$(CONFIG_ANDROID_TIMED_OUTPUT) += timed_output.o 7obj-$(CONFIG_ANDROID_TIMED_OUTPUT) += timed_output.o
diff --git a/drivers/staging/android/TODO b/drivers/staging/android/TODO
index b15fb0d6b152..06954cdf3dba 100644
--- a/drivers/staging/android/TODO
+++ b/drivers/staging/android/TODO
@@ -5,6 +5,13 @@ TODO:
5 - make sure things build as modules properly 5 - make sure things build as modules properly
6 - add proper arch dependencies as needed 6 - add proper arch dependencies as needed
7 - audit userspace interfaces to make sure they are sane 7 - audit userspace interfaces to make sure they are sane
8 - kuid_t should never be exposed to user space as it is
9 kernel internal type. Data structure for this kuid_t is:
10 typedef struct {
11 uid_t val;
12 } kuid_t;
13 - This bug is introduced by Xiong Zhou in the patch bd471258f2e09
14 - ("staging: android: logger: use kuid_t instead of uid_t")
8 15
9Please send patches to Greg Kroah-Hartman <greg@kroah.com> and Cc: 16Please send patches to Greg Kroah-Hartman <greg@kroah.com> and Cc:
10Brian Swetland <swetland@google.com> 17Brian Swetland <swetland@google.com>
diff --git a/drivers/staging/android/binder.h b/drivers/staging/android/binder.h
deleted file mode 100644
index eb0834656dfe..000000000000
--- a/drivers/staging/android/binder.h
+++ /dev/null
@@ -1,30 +0,0 @@
1/*
2 * Copyright (C) 2008 Google, Inc.
3 *
4 * Based on, but no longer compatible with, the original
5 * OpenBinder.org binder driver interface, which is:
6 *
7 * Copyright (c) 2005 Palmsource, Inc.
8 *
9 * This software is licensed under the terms of the GNU General Public
10 * License version 2, as published by the Free Software Foundation, and
11 * may be copied, distributed, and modified under those terms.
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 */
19
20#ifndef _LINUX_BINDER_H
21#define _LINUX_BINDER_H
22
23#ifdef CONFIG_ANDROID_BINDER_IPC_32BIT
24#define BINDER_IPC_32BIT 1
25#endif
26
27#include "uapi/binder.h"
28
29#endif /* _LINUX_BINDER_H */
30
diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c
index 56604f41ec48..296d347660fc 100644
--- a/drivers/staging/android/ion/ion.c
+++ b/drivers/staging/android/ion/ion.c
@@ -250,7 +250,7 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,
250 our systems the only dma_address space is physical addresses. 250 our systems the only dma_address space is physical addresses.
251 Additionally, we can't afford the overhead of invalidating every 251 Additionally, we can't afford the overhead of invalidating every
252 allocation via dma_map_sg. The implicit contract here is that 252 allocation via dma_map_sg. The implicit contract here is that
253 memory comming from the heaps is ready for dma, ie if it has a 253 memory coming from the heaps is ready for dma, ie if it has a
254 cached mapping that mapping has been invalidated */ 254 cached mapping that mapping has been invalidated */
255 for_each_sg(buffer->sg_table->sgl, sg, buffer->sg_table->nents, i) 255 for_each_sg(buffer->sg_table->sgl, sg, buffer->sg_table->nents, i)
256 sg_dma_address(sg) = sg_phys(sg); 256 sg_dma_address(sg) = sg_phys(sg);
@@ -263,8 +263,7 @@ err:
263 heap->ops->unmap_dma(heap, buffer); 263 heap->ops->unmap_dma(heap, buffer);
264 heap->ops->free(buffer); 264 heap->ops->free(buffer);
265err1: 265err1:
266 if (buffer->pages) 266 vfree(buffer->pages);
267 vfree(buffer->pages);
268err2: 267err2:
269 kfree(buffer); 268 kfree(buffer);
270 return ERR_PTR(ret); 269 return ERR_PTR(ret);
@@ -276,8 +275,7 @@ void ion_buffer_destroy(struct ion_buffer *buffer)
276 buffer->heap->ops->unmap_kernel(buffer->heap, buffer); 275 buffer->heap->ops->unmap_kernel(buffer->heap, buffer);
277 buffer->heap->ops->unmap_dma(buffer->heap, buffer); 276 buffer->heap->ops->unmap_dma(buffer->heap, buffer);
278 buffer->heap->ops->free(buffer); 277 buffer->heap->ops->free(buffer);
279 if (buffer->pages) 278 vfree(buffer->pages);
280 vfree(buffer->pages);
281 kfree(buffer); 279 kfree(buffer);
282} 280}
283 281
@@ -902,7 +900,7 @@ void ion_pages_sync_for_device(struct device *dev, struct page *page,
902 sg_set_page(&sg, page, size, 0); 900 sg_set_page(&sg, page, size, 0);
903 /* 901 /*
904 * This is not correct - sg_dma_address needs a dma_addr_t that is valid 902 * This is not correct - sg_dma_address needs a dma_addr_t that is valid
905 * for the the targeted device, but this works on the currently targeted 903 * for the targeted device, but this works on the currently targeted
906 * hardware. 904 * hardware.
907 */ 905 */
908 sg_dma_address(&sg) = page_to_phys(page); 906 sg_dma_address(&sg) = page_to_phys(page);
diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h
index d305bb7e9a74..443db8459a9e 100644
--- a/drivers/staging/android/ion/ion.h
+++ b/drivers/staging/android/ion/ion.h
@@ -76,7 +76,7 @@ struct ion_platform_data {
76 * size 76 * size
77 * 77 *
78 * Calls memblock reserve to set aside memory for heaps that are 78 * Calls memblock reserve to set aside memory for heaps that are
79 * located at specific memory addresses or of specfic sizes not 79 * located at specific memory addresses or of specific sizes not
80 * managed by the kernel 80 * managed by the kernel
81 */ 81 */
82void ion_reserve(struct ion_platform_data *data); 82void ion_reserve(struct ion_platform_data *data);
diff --git a/drivers/staging/android/ion/ion_dummy_driver.c b/drivers/staging/android/ion/ion_dummy_driver.c
index f3ea1c31e533..5678870bff48 100644
--- a/drivers/staging/android/ion/ion_dummy_driver.c
+++ b/drivers/staging/android/ion/ion_dummy_driver.c
@@ -112,10 +112,8 @@ static int __init ion_dummy_init(void)
112 } 112 }
113 return 0; 113 return 0;
114err: 114err:
115 for (i = 0; i < dummy_ion_pdata.nr; i++) { 115 for (i = 0; i < dummy_ion_pdata.nr; ++i)
116 if (heaps[i]) 116 ion_heap_destroy(heaps[i]);
117 ion_heap_destroy(heaps[i]);
118 }
119 kfree(heaps); 117 kfree(heaps);
120 118
121 if (carveout_ptr) { 119 if (carveout_ptr) {
diff --git a/drivers/staging/android/ion/ion_page_pool.c b/drivers/staging/android/ion/ion_page_pool.c
index 5864f3dfcbc6..4b88f11e52d3 100644
--- a/drivers/staging/android/ion/ion_page_pool.c
+++ b/drivers/staging/android/ion/ion_page_pool.c
@@ -120,7 +120,7 @@ int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask,
120 bool high; 120 bool high;
121 121
122 if (current_is_kswapd()) 122 if (current_is_kswapd())
123 high = 1; 123 high = true;
124 else 124 else
125 high = !!(gfp_mask & __GFP_HIGHMEM); 125 high = !!(gfp_mask & __GFP_HIGHMEM);
126 126
diff --git a/drivers/staging/android/ion/ion_priv.h b/drivers/staging/android/ion/ion_priv.h
index c8f01757abfa..18a5f93e13b7 100644
--- a/drivers/staging/android/ion/ion_priv.h
+++ b/drivers/staging/android/ion/ion_priv.h
@@ -345,7 +345,7 @@ void ion_carveout_free(struct ion_heap *heap, ion_phys_addr_t addr,
345 * functions for creating and destroying a heap pool -- allows you 345 * functions for creating and destroying a heap pool -- allows you
346 * to keep a pool of pre allocated memory to use from your heap. Keeping 346 * to keep a pool of pre allocated memory to use from your heap. Keeping
347 * a pool of memory that is ready for dma, ie any cached mapping have been 347 * a pool of memory that is ready for dma, ie any cached mapping have been
348 * invalidated from the cache, provides a significant peformance benefit on 348 * invalidated from the cache, provides a significant performance benefit on
349 * many systems */ 349 * many systems */
350 350
351/** 351/**
@@ -362,7 +362,7 @@ void ion_carveout_free(struct ion_heap *heap, ion_phys_addr_t addr,
362 * 362 *
363 * Allows you to keep a pool of pre allocated pages to use from your heap. 363 * Allows you to keep a pool of pre allocated pages to use from your heap.
364 * Keeping a pool of pages that is ready for dma, ie any cached mapping have 364 * Keeping a pool of pages that is ready for dma, ie any cached mapping have
365 * been invalidated from the cache, provides a significant peformance benefit 365 * been invalidated from the cache, provides a significant performance benefit
366 * on many systems 366 * on many systems
367 */ 367 */
368struct ion_page_pool { 368struct ion_page_pool {
diff --git a/drivers/staging/android/ion/tegra/tegra_ion.c b/drivers/staging/android/ion/tegra/tegra_ion.c
index 11c7cceb3c7d..5b8ef0e66010 100644
--- a/drivers/staging/android/ion/tegra/tegra_ion.c
+++ b/drivers/staging/android/ion/tegra/tegra_ion.c
@@ -54,10 +54,8 @@ static int tegra_ion_probe(struct platform_device *pdev)
54 platform_set_drvdata(pdev, idev); 54 platform_set_drvdata(pdev, idev);
55 return 0; 55 return 0;
56err: 56err:
57 for (i = 0; i < num_heaps; i++) { 57 for (i = 0; i < num_heaps; ++i)
58 if (heaps[i]) 58 ion_heap_destroy(heaps[i]);
59 ion_heap_destroy(heaps[i]);
60 }
61 return err; 59 return err;
62} 60}
63 61
diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c
index 257fc91bf02b..1532a86404be 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -25,6 +25,7 @@
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/uaccess.h> 26#include <linux/uaccess.h>
27#include <linux/anon_inodes.h> 27#include <linux/anon_inodes.h>
28#include <linux/time64.h>
28#include "sync.h" 29#include "sync.h"
29 30
30#ifdef CONFIG_DEBUG_FS 31#ifdef CONFIG_DEBUG_FS
@@ -95,9 +96,9 @@ static void sync_print_pt(struct seq_file *s, struct sync_pt *pt, bool fence)
95 sync_status_str(status)); 96 sync_status_str(status));
96 97
97 if (status <= 0) { 98 if (status <= 0) {
98 struct timeval tv = ktime_to_timeval(pt->base.timestamp); 99 struct timespec64 ts64 = ktime_to_timespec64(pt->base.timestamp);
99 100
100 seq_printf(s, "@%ld.%06ld", tv.tv_sec, tv.tv_usec); 101 seq_printf(s, "@%lld.%09ld", (s64)ts64.tv_sec, ts64.tv_nsec);
101 } 102 }
102 103
103 if (parent->ops->timeline_value_str && 104 if (parent->ops->timeline_value_str &&
diff --git a/drivers/staging/android/timed_gpio.c b/drivers/staging/android/timed_gpio.c
index c71ed64931ba..938a35cd99bb 100644
--- a/drivers/staging/android/timed_gpio.c
+++ b/drivers/staging/android/timed_gpio.c
@@ -20,6 +20,7 @@
20#include <linux/hrtimer.h> 20#include <linux/hrtimer.h>
21#include <linux/err.h> 21#include <linux/err.h>
22#include <linux/gpio.h> 22#include <linux/gpio.h>
23#include <linux/ktime.h>
23 24
24#include "timed_output.h" 25#include "timed_output.h"
25#include "timed_gpio.h" 26#include "timed_gpio.h"
@@ -46,16 +47,16 @@ static enum hrtimer_restart gpio_timer_func(struct hrtimer *timer)
46static int gpio_get_time(struct timed_output_dev *dev) 47static int gpio_get_time(struct timed_output_dev *dev)
47{ 48{
48 struct timed_gpio_data *data; 49 struct timed_gpio_data *data;
49 struct timeval t; 50 ktime_t t;
50 51
51 data = container_of(dev, struct timed_gpio_data, dev); 52 data = container_of(dev, struct timed_gpio_data, dev);
52 53
53 if (!hrtimer_active(&data->timer)) 54 if (!hrtimer_active(&data->timer))
54 return 0; 55 return 0;
55 56
56 t = ktime_to_timeval(hrtimer_get_remaining(&data->timer)); 57 t = hrtimer_get_remaining(&data->timer);
57 58
58 return t.tv_sec * 1000 + t.tv_usec / 1000; 59 return ktime_to_ms(t);
59} 60}
60 61
61static void gpio_enable(struct timed_output_dev *dev, int value) 62static void gpio_enable(struct timed_output_dev *dev, int value)
diff --git a/drivers/staging/bcm/Adapter.h b/drivers/staging/bcm/Adapter.h
deleted file mode 100644
index 940c852e17b7..000000000000
--- a/drivers/staging/bcm/Adapter.h
+++ /dev/null
@@ -1,474 +0,0 @@
1/***********************************
2* Adapter.h
3************************************/
4#ifndef __ADAPTER_H__
5#define __ADAPTER_H__
6
7#define MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES 256
8#include "Debug.h"
9
10struct bcm_leader {
11 USHORT Vcid;
12 USHORT PLength;
13 UCHAR Status;
14 UCHAR Unused[3];
15} __packed;
16
17struct bcm_packettosend {
18 struct bcm_leader Leader;
19 UCHAR ucPayload;
20} __packed;
21
22struct bcm_control_packet {
23 PVOID ControlBuff;
24 UINT ControlBuffLen;
25 struct bcm_control_packet *next;
26} __packed;
27
28struct bcm_link_request {
29 struct bcm_leader Leader;
30 UCHAR szData[4];
31} __packed;
32
33#define MAX_IP_RANGE_LENGTH 4
34#define MAX_PORT_RANGE 4
35#define MAX_PROTOCOL_LENGTH 32
36#define IPV6_ADDRESS_SIZEINBYTES 0x10
37
38union u_ip_address {
39 struct {
40 /* Source Ip Address Range */
41 ULONG ulIpv4Addr[MAX_IP_RANGE_LENGTH];
42 /* Source Ip Mask Address Range */
43 ULONG ulIpv4Mask[MAX_IP_RANGE_LENGTH];
44 };
45 struct {
46 /* Source Ip Address Range */
47 ULONG ulIpv6Addr[MAX_IP_RANGE_LENGTH * 4];
48 /* Source Ip Mask Address Range */
49 ULONG ulIpv6Mask[MAX_IP_RANGE_LENGTH * 4];
50 };
51 struct {
52 UCHAR ucIpv4Address[MAX_IP_RANGE_LENGTH * IP_LENGTH_OF_ADDRESS];
53 UCHAR ucIpv4Mask[MAX_IP_RANGE_LENGTH * IP_LENGTH_OF_ADDRESS];
54 };
55 struct {
56 UCHAR ucIpv6Address[MAX_IP_RANGE_LENGTH * IPV6_ADDRESS_SIZEINBYTES];
57 UCHAR ucIpv6Mask[MAX_IP_RANGE_LENGTH * IPV6_ADDRESS_SIZEINBYTES];
58 };
59};
60
61struct bcm_hdr_suppression_contextinfo {
62 /* Intermediate buffer to accumulate pkt Header for PHS */
63 UCHAR ucaHdrSuppressionInBuf[MAX_PHS_LENGTHS];
64 /* Intermediate buffer containing pkt Header after PHS */
65 UCHAR ucaHdrSuppressionOutBuf[MAX_PHS_LENGTHS + PHSI_LEN];
66};
67
68struct bcm_classifier_rule {
69 ULONG ulSFID;
70 UCHAR ucReserved[2];
71 B_UINT16 uiClassifierRuleIndex;
72 bool bUsed;
73 USHORT usVCID_Value;
74 /* This field detemines the Classifier Priority */
75 B_UINT8 u8ClassifierRulePriority;
76 union u_ip_address stSrcIpAddress;
77 UCHAR ucIPSourceAddressLength; /* Ip Source Address Length */
78
79 union u_ip_address stDestIpAddress;
80 /* Ip Destination Address Length */
81 UCHAR ucIPDestinationAddressLength;
82 UCHAR ucIPTypeOfServiceLength; /* Type of service Length */
83 UCHAR ucTosLow; /* Tos Low */
84 UCHAR ucTosHigh; /* Tos High */
85 UCHAR ucTosMask; /* Tos Mask */
86
87 UCHAR ucProtocolLength; /* protocol Length */
88 UCHAR ucProtocol[MAX_PROTOCOL_LENGTH]; /* protocol Length */
89 USHORT usSrcPortRangeLo[MAX_PORT_RANGE];
90 USHORT usSrcPortRangeHi[MAX_PORT_RANGE];
91 UCHAR ucSrcPortRangeLength;
92
93 USHORT usDestPortRangeLo[MAX_PORT_RANGE];
94 USHORT usDestPortRangeHi[MAX_PORT_RANGE];
95 UCHAR ucDestPortRangeLength;
96
97 bool bProtocolValid;
98 bool bTOSValid;
99 bool bDestIpValid;
100 bool bSrcIpValid;
101
102 /* For IPv6 Addressing */
103 UCHAR ucDirection;
104 bool bIpv6Protocol;
105 UINT32 u32PHSRuleID;
106 struct bcm_phs_rule sPhsRule;
107 UCHAR u8AssociatedPHSI;
108
109 /* Classification fields for ETH CS */
110 UCHAR ucEthCSSrcMACLen;
111 UCHAR au8EThCSSrcMAC[MAC_ADDRESS_SIZE];
112 UCHAR au8EThCSSrcMACMask[MAC_ADDRESS_SIZE];
113 UCHAR ucEthCSDestMACLen;
114 UCHAR au8EThCSDestMAC[MAC_ADDRESS_SIZE];
115 UCHAR au8EThCSDestMACMask[MAC_ADDRESS_SIZE];
116 UCHAR ucEtherTypeLen;
117 UCHAR au8EthCSEtherType[NUM_ETHERTYPE_BYTES];
118 UCHAR usUserPriority[2];
119 USHORT usVLANID;
120 USHORT usValidityBitMap;
121};
122
123struct bcm_fragmented_packet_info {
124 bool bUsed;
125 ULONG ulSrcIpAddress;
126 USHORT usIpIdentification;
127 struct bcm_classifier_rule *pstMatchedClassifierEntry;
128 bool bOutOfOrderFragment;
129};
130
131struct bcm_packet_info {
132 /* classification extension Rule */
133 ULONG ulSFID;
134 USHORT usVCID_Value;
135 UINT uiThreshold;
136 /* This field determines the priority of the SF Queues */
137 B_UINT8 u8TrafficPriority;
138
139 bool bValid;
140 bool bActive;
141 bool bActivateRequestSent;
142
143 B_UINT8 u8QueueType; /* BE or rtPS */
144
145 /* maximum size of the bucket for the queue */
146 UINT uiMaxBucketSize;
147 UINT uiCurrentQueueDepthOnTarget;
148 UINT uiCurrentBytesOnHost;
149 UINT uiCurrentPacketsOnHost;
150 UINT uiDroppedCountBytes;
151 UINT uiDroppedCountPackets;
152 UINT uiSentBytes;
153 UINT uiSentPackets;
154 UINT uiCurrentDrainRate;
155 UINT uiThisPeriodSentBytes;
156 LARGE_INTEGER liDrainCalculated;
157 UINT uiCurrentTokenCount;
158 LARGE_INTEGER liLastUpdateTokenAt;
159 UINT uiMaxAllowedRate;
160 UINT NumOfPacketsSent;
161 UCHAR ucDirection;
162 USHORT usCID;
163 struct bcm_mibs_parameters stMibsExtServiceFlowTable;
164 UINT uiCurrentRxRate;
165 UINT uiThisPeriodRxBytes;
166 UINT uiTotalRxBytes;
167 UINT uiTotalTxBytes;
168 UINT uiPendedLast;
169 UCHAR ucIpVersion;
170
171 union {
172 struct {
173 struct sk_buff *FirstTxQueue;
174 struct sk_buff *LastTxQueue;
175 };
176 struct {
177 struct sk_buff *ControlHead;
178 struct sk_buff *ControlTail;
179 };
180 };
181
182 bool bProtocolValid;
183 bool bTOSValid;
184 bool bDestIpValid;
185 bool bSrcIpValid;
186
187 bool bActiveSet;
188 bool bAdmittedSet;
189 bool bAuthorizedSet;
190 bool bClassifierPriority;
191 UCHAR ucServiceClassName[MAX_CLASS_NAME_LENGTH];
192 bool bHeaderSuppressionEnabled;
193 spinlock_t SFQueueLock;
194 void *pstSFIndication;
195 struct timeval stLastUpdateTokenAt;
196 atomic_t uiPerSFTxResourceCount;
197 UINT uiMaxLatency;
198 UCHAR bIPCSSupport;
199 UCHAR bEthCSSupport;
200};
201
202struct bcm_tarang_data {
203 struct bcm_tarang_data *next;
204 struct bcm_mini_adapter *Adapter;
205 struct sk_buff *RxAppControlHead;
206 struct sk_buff *RxAppControlTail;
207 int AppCtrlQueueLen;
208 bool MacTracingEnabled;
209 bool bApplicationToExit;
210 struct bcm_mibs_dropped_cntrl_msg stDroppedAppCntrlMsgs;
211 ULONG RxCntrlMsgBitMask;
212};
213
214struct bcm_targetdsx_buffer {
215 ULONG ulTargetDsxBuffer;
216 B_UINT16 tid;
217 bool valid;
218};
219
220typedef int (*FP_FLASH_WRITE)(struct bcm_mini_adapter *, UINT, PVOID);
221
222typedef int (*FP_FLASH_WRITE_STATUS)(struct bcm_mini_adapter *, UINT, PVOID);
223
224/*
225 * Driver adapter data structure
226 */
227struct bcm_mini_adapter {
228 struct bcm_mini_adapter *next;
229 struct net_device *dev;
230 u32 msg_enable;
231 CHAR *caDsxReqResp;
232 atomic_t ApplicationRunning;
233 bool AppCtrlQueueOverFlow;
234 atomic_t CurrentApplicationCount;
235 atomic_t RegisteredApplicationCount;
236 bool LinkUpStatus;
237 bool TimerActive;
238 u32 StatisticsPointer;
239 struct sk_buff *RxControlHead;
240 struct sk_buff *RxControlTail;
241 struct semaphore RxAppControlQueuelock;
242 struct semaphore fw_download_sema;
243 struct bcm_tarang_data *pTarangs;
244 spinlock_t control_queue_lock;
245 wait_queue_head_t process_read_wait_queue;
246
247 /* the pointer to the first packet we have queued in send
248 * deserialized miniport support variables
249 */
250 atomic_t TotalPacketCount;
251 atomic_t TxPktAvail;
252
253 /* this to keep track of the Tx and Rx MailBox Registers. */
254 atomic_t CurrNumFreeTxDesc;
255 /* to keep track the no of byte received */
256 USHORT PrevNumRecvDescs;
257 USHORT CurrNumRecvDescs;
258 UINT u32TotalDSD;
259 struct bcm_packet_info PackInfo[NO_OF_QUEUES];
260 struct bcm_classifier_rule astClassifierTable[MAX_CLASSIFIERS];
261 bool TransferMode;
262
263 /*************** qos ******************/
264 bool bETHCSEnabled;
265 ULONG BEBucketSize;
266 ULONG rtPSBucketSize;
267 UCHAR LinkStatus;
268 bool AutoLinkUp;
269 bool AutoSyncup;
270
271 int major;
272 int minor;
273 wait_queue_head_t tx_packet_wait_queue;
274 wait_queue_head_t process_rx_cntrlpkt;
275 atomic_t process_waiting;
276 bool fw_download_done;
277
278 char *txctlpacket[MAX_CNTRL_PKTS];
279 atomic_t cntrlpktCnt;
280 atomic_t index_app_read_cntrlpkt;
281 atomic_t index_wr_txcntrlpkt;
282 atomic_t index_rd_txcntrlpkt;
283 UINT index_datpkt;
284 struct semaphore rdmwrmsync;
285
286 struct bcm_targetdsx_buffer astTargetDsxBuffer[MAX_TARGET_DSX_BUFFERS];
287 ULONG ulFreeTargetBufferCnt;
288 ULONG ulCurrentTargetBuffer;
289 ULONG ulTotalTargetBuffersAvailable;
290 unsigned long chip_id;
291 wait_queue_head_t lowpower_mode_wait_queue;
292 bool bFlashBoot;
293 bool bBinDownloaded;
294 bool bCfgDownloaded;
295 bool bSyncUpRequestSent;
296 USHORT usBestEffortQueueIndex;
297 wait_queue_head_t ioctl_fw_dnld_wait_queue;
298 bool waiting_to_fw_download_done;
299 pid_t fw_download_process_pid;
300 struct bcm_target_params *pstargetparams;
301 bool device_removed;
302 bool DeviceAccess;
303 bool bIsAutoCorrectEnabled;
304 bool bDDRInitDone;
305 int DDRSetting;
306 ULONG ulPowerSaveMode;
307 spinlock_t txtransmitlock;
308 B_UINT8 txtransmit_running;
309 /* Thread for control packet handling */
310 struct task_struct *control_packet_handler;
311 /* thread for transmitting packets. */
312 struct task_struct *transmit_packet_thread;
313
314 /* LED Related Structures */
315 struct bcm_led_info LEDInfo;
316
317 /* Driver State for LED Blinking */
318 enum bcm_led_events DriverState;
319 /* Interface Specific */
320 PVOID pvInterfaceAdapter;
321 int (*bcm_file_download)(PVOID,
322 struct file *,
323 unsigned int);
324 int (*bcm_file_readback_from_chip)(PVOID,
325 struct file *,
326 unsigned int);
327 int (*interface_rdm)(PVOID,
328 UINT,
329 PVOID,
330 int);
331 int (*interface_wrm)(PVOID,
332 UINT,
333 PVOID,
334 int);
335 int (*interface_transmit)(PVOID, PVOID , UINT);
336 bool IdleMode;
337 bool bDregRequestSentInIdleMode;
338 bool bTriedToWakeUpFromlowPowerMode;
339 bool bShutStatus;
340 bool bWakeUpDevice;
341 unsigned int usIdleModePattern;
342 /* BOOLEAN bTriedToWakeUpFromShutdown; */
343 bool bLinkDownRequested;
344 int downloadDDR;
345 struct bcm_phs_extension stBCMPhsContext;
346 struct bcm_hdr_suppression_contextinfo stPhsTxContextInfo;
347 uint8_t ucaPHSPktRestoreBuf[2048];
348 uint8_t bPHSEnabled;
349 bool AutoFirmDld;
350 bool bMipsConfig;
351 bool bDPLLConfig;
352 UINT32 aTxPktSizeHist[MIBS_MAX_HIST_ENTRIES];
353 UINT32 aRxPktSizeHist[MIBS_MAX_HIST_ENTRIES];
354 struct bcm_fragmented_packet_info
355 astFragmentedPktClassifierTable[MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES];
356 atomic_t uiMBupdate;
357 UINT32 PmuMode;
358 enum bcm_nvm_type eNVMType;
359 UINT uiSectorSize;
360 UINT uiSectorSizeInCFG;
361 bool bSectorSizeOverride;
362 bool bStatusWrite;
363 UINT uiNVMDSDSize;
364 UINT uiVendorExtnFlag;
365 /* it will always represent chosen DSD at any point of time.
366 * Generally it is Active DSD but in case of NVM RD/WR it
367 * might be different.
368 */
369 UINT ulFlashCalStart;
370 ULONG ulFlashControlSectionStart;
371 ULONG ulFlashWriteSize;
372 ULONG ulFlashID;
373 FP_FLASH_WRITE fpFlashWrite;
374 FP_FLASH_WRITE_STATUS fpFlashWriteWithStatusCheck;
375
376 struct semaphore NVMRdmWrmLock;
377 struct device *pstCreatedClassDevice;
378
379 /* BOOLEAN InterfaceUpStatus; */
380 struct bcm_flash2x_cs_info *psFlash2xCSInfo;
381 struct bcm_flash_cs_info *psFlashCSInfo;
382 struct bcm_flash2x_vendor_info *psFlash2xVendorInfo;
383 UINT uiFlashBaseAdd; /* Flash start address */
384 /* Active ISO offset chosen before f/w download */
385 UINT uiActiveISOOffset;
386 enum bcm_flash2x_section_val eActiveISO; /* Active ISO section val */
387 /* Active DSD val chosen before f/w download */
388 enum bcm_flash2x_section_val eActiveDSD;
389 /* For accessing Active DSD chosen before f/w download */
390 UINT uiActiveDSDOffsetAtFwDld;
391 UINT uiFlashLayoutMajorVersion;
392 UINT uiFlashLayoutMinorVersion;
393 bool bAllDSDWriteAllow;
394 bool bSigCorrupted;
395 /* this should be set who so ever want to change the Headers.
396 * after Write it should be reset immediately.
397 */
398 bool bHeaderChangeAllowed;
399 int SelectedChip;
400 bool bEndPointHalted;
401 /* while bFlashRawRead will be true, Driver
402 * ignore map lay out and consider flash as of without any map.
403 */
404 bool bFlashRawRead;
405 bool bPreparingForLowPowerMode;
406 bool bDoSuspend;
407 UINT syscfgBefFwDld;
408 bool StopAllXaction;
409 /* Used to Support extended CAPI requirements from */
410 UINT32 liTimeSinceLastNetEntry;
411 struct semaphore LowPowerModeSync;
412 ULONG liDrainCalculated;
413 UINT gpioBitMap;
414 struct bcm_debug_state stDebugState;
415};
416
417#define GET_BCM_ADAPTER(net_dev) netdev_priv(net_dev)
418
419struct bcm_eth_header {
420 UCHAR au8DestinationAddress[6];
421 UCHAR au8SourceAddress[6];
422 USHORT u16Etype;
423} __packed;
424
425struct bcm_firmware_info {
426 void __user *pvMappedFirmwareAddress;
427 ULONG u32FirmwareLength;
428 ULONG u32StartingAddress;
429} __packed;
430
431/* holds the value of net_device structure.. */
432extern struct net_device *gblpnetdev;
433
434struct bcm_ddr_setting {
435 UINT ulRegAddress;
436 UINT ulRegValue;
437};
438int InitAdapter(struct bcm_mini_adapter *psAdapter);
439
440/* =====================================================================
441 * Beceem vendor request codes for EP0
442 * =====================================================================
443 */
444
445#define BCM_REQUEST_READ 0x2
446#define BCM_REQUEST_WRITE 0x1
447#define EP2_MPS_REG 0x0F0110A0
448#define EP2_MPS 0x40
449
450#define EP2_CFG_REG 0x0F0110A8
451#define EP2_CFG_INT 0x27
452#define EP2_CFG_BULK 0x25
453
454#define EP4_MPS_REG 0x0F0110F0
455#define EP4_MPS 0x8C
456
457#define EP4_CFG_REG 0x0F0110F8
458
459#define ISO_MPS_REG 0x0F0110C8
460#define ISO_MPS 0x00000000
461
462#define EP1 0
463#define EP2 1
464#define EP3 2
465#define EP4 3
466#define EP5 4
467#define EP6 5
468
469enum bcm_einterface_setting {
470 DEFAULT_SETTING_0 = 0,
471 ALTERNATE_SETTING_1 = 1,
472};
473
474#endif /* __ADAPTER_H__ */
diff --git a/drivers/staging/bcm/Bcmchar.c b/drivers/staging/bcm/Bcmchar.c
deleted file mode 100644
index 88ce2da531c6..000000000000
--- a/drivers/staging/bcm/Bcmchar.c
+++ /dev/null
@@ -1,2652 +0,0 @@
1#include <linux/fs.h>
2
3#include "headers.h"
4
5static int bcm_handle_nvm_read_cmd(struct bcm_mini_adapter *ad,
6 PUCHAR read_data,
7 struct bcm_nvm_readwrite *nvm_rw)
8{
9 INT status = STATUS_FAILURE;
10
11 down(&ad->NVMRdmWrmLock);
12
13 if ((ad->IdleMode == TRUE) || (ad->bShutStatus == TRUE) ||
14 (ad->bPreparingForLowPowerMode == TRUE)) {
15
16 BCM_DEBUG_PRINT(ad,
17 DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
18 "Device is in Idle/Shutdown Mode\n");
19 up(&ad->NVMRdmWrmLock);
20 kfree(read_data);
21 return -EACCES;
22 }
23
24 status = BeceemNVMRead(ad, (PUINT)read_data,
25 nvm_rw->uiOffset,
26 nvm_rw->uiNumBytes);
27 up(&ad->NVMRdmWrmLock);
28
29 if (status != STATUS_SUCCESS) {
30 kfree(read_data);
31 return status;
32 }
33
34 if (copy_to_user(nvm_rw->pBuffer, read_data, nvm_rw->uiNumBytes)) {
35 kfree(read_data);
36 return -EFAULT;
37 }
38
39 return STATUS_SUCCESS;
40}
41
42static int handle_flash2x_adapter(struct bcm_mini_adapter *ad,
43 PUCHAR read_data,
44 struct bcm_nvm_readwrite *nvm_rw)
45{
46 /*
47 * New Requirement:-
48 * DSD section updation will be allowed in two case:-
49 * 1. if DSD sig is present in DSD header means dongle
50 * is ok and updation is fruitfull
51 * 2. if point 1 failes then user buff should have
52 * DSD sig. this point ensures that if dongle is
53 * corrupted then user space program first modify
54 * the DSD header with valid DSD sig so that this
55 * as well as further write may be worthwhile.
56 *
57 * This restriction has been put assuming that
58 * if DSD sig is corrupted, DSD data won't be
59 * considered valid.
60 */
61 INT status;
62 ULONG dsd_magic_num_in_usr_buff = 0;
63
64 status = BcmFlash2xCorruptSig(ad, ad->eActiveDSD);
65 if (status == STATUS_SUCCESS)
66 return STATUS_SUCCESS;
67
68 if (((nvm_rw->uiOffset + nvm_rw->uiNumBytes) !=
69 ad->uiNVMDSDSize) ||
70 (nvm_rw->uiNumBytes < SIGNATURE_SIZE)) {
71
72 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
73 "DSD Sig is present neither in Flash nor User provided Input..");
74 up(&ad->NVMRdmWrmLock);
75 kfree(read_data);
76 return status;
77 }
78
79 dsd_magic_num_in_usr_buff =
80 ntohl(*(PUINT)(read_data + nvm_rw->uiNumBytes -
81 SIGNATURE_SIZE));
82 if (dsd_magic_num_in_usr_buff != DSD_IMAGE_MAGIC_NUMBER) {
83 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
84 "DSD Sig is present neither in Flash nor User provided Input..");
85 up(&ad->NVMRdmWrmLock);
86 kfree(read_data);
87 return status;
88 }
89
90 return STATUS_SUCCESS;
91}
92
93/***************************************************************
94* Function - bcm_char_open()
95*
96* Description - This is the "open" entry point for the character
97* driver.
98*
99* Parameters - inode: Pointer to the Inode structure of char device
100* filp : File pointer of the char device
101*
102* Returns - Zero(Success)
103****************************************************************/
104
105static int bcm_char_open(struct inode *inode, struct file *filp)
106{
107 struct bcm_mini_adapter *ad = NULL;
108 struct bcm_tarang_data *tarang = NULL;
109
110 ad = GET_BCM_ADAPTER(gblpnetdev);
111 tarang = kzalloc(sizeof(struct bcm_tarang_data), GFP_KERNEL);
112 if (!tarang)
113 return -ENOMEM;
114
115 tarang->Adapter = ad;
116 tarang->RxCntrlMsgBitMask = 0xFFFFFFFF & ~(1 << 0xB);
117
118 down(&ad->RxAppControlQueuelock);
119 tarang->next = ad->pTarangs;
120 ad->pTarangs = tarang;
121 up(&ad->RxAppControlQueuelock);
122
123 /* Store the Adapter structure */
124 filp->private_data = tarang;
125
126 /* Start Queuing the control response Packets */
127 atomic_inc(&ad->ApplicationRunning);
128
129 nonseekable_open(inode, filp);
130 return 0;
131}
132
133static int bcm_char_release(struct inode *inode, struct file *filp)
134{
135 struct bcm_tarang_data *tarang, *tmp, *ptmp;
136 struct bcm_mini_adapter *ad = NULL;
137 struct sk_buff *pkt, *npkt;
138
139 tarang = (struct bcm_tarang_data *)filp->private_data;
140
141 if (tarang == NULL)
142 return 0;
143
144 ad = tarang->Adapter;
145
146 down(&ad->RxAppControlQueuelock);
147
148 tmp = ad->pTarangs;
149 for (ptmp = NULL; tmp; ptmp = tmp, tmp = tmp->next) {
150 if (tmp == tarang)
151 break;
152 }
153
154 if (tmp) {
155 if (!ptmp)
156 ad->pTarangs = tmp->next;
157 else
158 ptmp->next = tmp->next;
159 } else {
160 up(&ad->RxAppControlQueuelock);
161 return 0;
162 }
163
164 pkt = tarang->RxAppControlHead;
165 while (pkt) {
166 npkt = pkt->next;
167 kfree_skb(pkt);
168 pkt = npkt;
169 }
170
171 up(&ad->RxAppControlQueuelock);
172
173 /* Stop Queuing the control response Packets */
174 atomic_dec(&ad->ApplicationRunning);
175
176 kfree(tarang);
177
178 /* remove this filp from the asynchronously notified filp's */
179 filp->private_data = NULL;
180 return 0;
181}
182
183static ssize_t bcm_char_read(struct file *filp,
184 char __user *buf,
185 size_t size,
186 loff_t *f_pos)
187{
188 struct bcm_tarang_data *tarang = filp->private_data;
189 struct bcm_mini_adapter *ad = tarang->Adapter;
190 struct sk_buff *packet = NULL;
191 ssize_t pkt_len = 0;
192 int wait_ret_val = 0;
193 unsigned long ret = 0;
194
195 wait_ret_val = wait_event_interruptible(
196 ad->process_read_wait_queue,
197 (tarang->RxAppControlHead ||
198 ad->device_removed));
199
200 if ((wait_ret_val == -ERESTARTSYS)) {
201 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
202 "Exiting as i've been asked to exit!!!\n");
203 return wait_ret_val;
204 }
205
206 if (ad->device_removed) {
207 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
208 "Device Removed... Killing the Apps...\n");
209 return -ENODEV;
210 }
211
212 if (false == ad->fw_download_done)
213 return -EACCES;
214
215 down(&ad->RxAppControlQueuelock);
216
217 if (tarang->RxAppControlHead) {
218 packet = tarang->RxAppControlHead;
219 DEQUEUEPACKET(tarang->RxAppControlHead,
220 tarang->RxAppControlTail);
221 tarang->AppCtrlQueueLen--;
222 }
223
224 up(&ad->RxAppControlQueuelock);
225
226 if (packet) {
227 pkt_len = packet->len;
228 ret = copy_to_user(buf, packet->data,
229 min_t(size_t, pkt_len, size));
230 if (ret) {
231 dev_kfree_skb(packet);
232 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
233 "Returning from copy to user failure\n");
234 return -EFAULT;
235 }
236 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
237 "Read %zd Bytes From Adapter packet = %p by process %d!\n",
238 pkt_len, packet, current->pid);
239 dev_kfree_skb(packet);
240 }
241
242 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL, "<\n");
243 return pkt_len;
244}
245
246static int bcm_char_ioctl_reg_read_private(void __user *argp,
247 struct bcm_mini_adapter *ad)
248{
249 struct bcm_rdm_buffer rdm_buff = {0};
250 struct bcm_ioctl_buffer io_buff;
251 PCHAR temp_buff;
252 INT status = STATUS_FAILURE;
253 UINT buff_len;
254 u16 temp_value;
255 int bytes;
256
257 /* Copy Ioctl Buffer structure */
258 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer)))
259 return -EFAULT;
260
261 if (io_buff.InputLength > sizeof(rdm_buff))
262 return -EINVAL;
263
264 if (copy_from_user(&rdm_buff, io_buff.InputBuffer,
265 io_buff.InputLength))
266 return -EFAULT;
267
268 if (io_buff.OutputLength > USHRT_MAX ||
269 io_buff.OutputLength == 0) {
270 return -EINVAL;
271 }
272
273 buff_len = io_buff.OutputLength;
274 temp_value = 4 - (buff_len % 4);
275 buff_len += temp_value % 4;
276
277 temp_buff = kmalloc(buff_len, GFP_KERNEL);
278 if (!temp_buff)
279 return -ENOMEM;
280
281 bytes = rdmalt(ad, (UINT)rdm_buff.Register,
282 (PUINT)temp_buff, buff_len);
283 if (bytes > 0) {
284 status = STATUS_SUCCESS;
285 if (copy_to_user(io_buff.OutputBuffer, temp_buff, bytes)) {
286 kfree(temp_buff);
287 return -EFAULT;
288 }
289 } else {
290 status = bytes;
291 }
292
293 kfree(temp_buff);
294 return status;
295}
296
297static int bcm_char_ioctl_reg_write_private(void __user *argp,
298 struct bcm_mini_adapter *ad)
299{
300 struct bcm_wrm_buffer wrm_buff = {0};
301 struct bcm_ioctl_buffer io_buff;
302 UINT tmp = 0;
303 INT status;
304
305 /* Copy Ioctl Buffer structure */
306
307 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer)))
308 return -EFAULT;
309
310 if (io_buff.InputLength > sizeof(wrm_buff))
311 return -EINVAL;
312
313 /* Get WrmBuffer structure */
314 if (copy_from_user(&wrm_buff, io_buff.InputBuffer,
315 io_buff.InputLength))
316 return -EFAULT;
317
318 tmp = wrm_buff.Register & EEPROM_REJECT_MASK;
319 if (!((ad->pstargetparams->m_u32Customize) & VSG_MODE) &&
320 ((tmp == EEPROM_REJECT_REG_1) ||
321 (tmp == EEPROM_REJECT_REG_2) ||
322 (tmp == EEPROM_REJECT_REG_3) ||
323 (tmp == EEPROM_REJECT_REG_4))) {
324
325 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
326 "EEPROM Access Denied, not in VSG Mode\n");
327 return -EFAULT;
328 }
329
330 status = wrmalt(ad, (UINT)wrm_buff.Register,
331 (PUINT)wrm_buff.Data, sizeof(ULONG));
332
333 if (status == STATUS_SUCCESS) {
334 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG,
335 DBG_LVL_ALL, "WRM Done\n");
336 } else {
337 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG,
338 DBG_LVL_ALL, "WRM Failed\n");
339 status = -EFAULT;
340 }
341 return status;
342}
343
344static int bcm_char_ioctl_eeprom_reg_read(void __user *argp,
345 struct bcm_mini_adapter *ad)
346{
347 struct bcm_rdm_buffer rdm_buff = {0};
348 struct bcm_ioctl_buffer io_buff;
349 PCHAR temp_buff = NULL;
350 UINT tmp = 0;
351 INT status;
352 int bytes;
353
354 if ((ad->IdleMode == TRUE) ||
355 (ad->bShutStatus == TRUE) ||
356 (ad->bPreparingForLowPowerMode == TRUE)) {
357
358 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
359 "Device in Idle Mode, Blocking Rdms\n");
360 return -EACCES;
361 }
362
363 /* Copy Ioctl Buffer structure */
364 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer)))
365 return -EFAULT;
366
367 if (io_buff.InputLength > sizeof(rdm_buff))
368 return -EINVAL;
369
370 if (copy_from_user(&rdm_buff, io_buff.InputBuffer,
371 io_buff.InputLength))
372 return -EFAULT;
373
374 if (io_buff.OutputLength > USHRT_MAX ||
375 io_buff.OutputLength == 0) {
376 return -EINVAL;
377 }
378
379 temp_buff = kmalloc(io_buff.OutputLength, GFP_KERNEL);
380 if (!temp_buff)
381 return STATUS_FAILURE;
382
383 if ((((ULONG)rdm_buff.Register & 0x0F000000) != 0x0F000000) ||
384 ((ULONG)rdm_buff.Register & 0x3)) {
385
386 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
387 "RDM Done On invalid Address : %x Access Denied.\n",
388 (int)rdm_buff.Register);
389
390 kfree(temp_buff);
391 return -EINVAL;
392 }
393
394 tmp = rdm_buff.Register & EEPROM_REJECT_MASK;
395 bytes = rdmaltWithLock(ad, (UINT)rdm_buff.Register,
396 (PUINT)temp_buff, io_buff.OutputLength);
397
398 if (bytes > 0) {
399 status = STATUS_SUCCESS;
400 if (copy_to_user(io_buff.OutputBuffer, temp_buff, bytes)) {
401 kfree(temp_buff);
402 return -EFAULT;
403 }
404 } else {
405 status = bytes;
406 }
407
408 kfree(temp_buff);
409 return status;
410}
411
412static int bcm_char_ioctl_eeprom_reg_write(void __user *argp,
413 struct bcm_mini_adapter *ad,
414 UINT cmd)
415{
416 struct bcm_wrm_buffer wrm_buff = {0};
417 struct bcm_ioctl_buffer io_buff;
418 UINT tmp = 0;
419 INT status;
420
421 if ((ad->IdleMode == TRUE) ||
422 (ad->bShutStatus == TRUE) ||
423 (ad->bPreparingForLowPowerMode == TRUE)) {
424
425 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
426 "Device in Idle Mode, Blocking Wrms\n");
427 return -EACCES;
428 }
429
430 /* Copy Ioctl Buffer structure */
431 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer)))
432 return -EFAULT;
433
434 if (io_buff.InputLength > sizeof(wrm_buff))
435 return -EINVAL;
436
437 /* Get WrmBuffer structure */
438 if (copy_from_user(&wrm_buff, io_buff.InputBuffer,
439 io_buff.InputLength))
440 return -EFAULT;
441
442 if ((((ULONG)wrm_buff.Register & 0x0F000000) != 0x0F000000) ||
443 ((ULONG)wrm_buff.Register & 0x3)) {
444
445 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
446 "WRM Done On invalid Address : %x Access Denied.\n",
447 (int)wrm_buff.Register);
448 return -EINVAL;
449 }
450
451 tmp = wrm_buff.Register & EEPROM_REJECT_MASK;
452 if (!((ad->pstargetparams->m_u32Customize) & VSG_MODE) &&
453 ((tmp == EEPROM_REJECT_REG_1) ||
454 (tmp == EEPROM_REJECT_REG_2) ||
455 (tmp == EEPROM_REJECT_REG_3) ||
456 (tmp == EEPROM_REJECT_REG_4)) &&
457 (cmd == IOCTL_BCM_REGISTER_WRITE)) {
458
459 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
460 "EEPROM Access Denied, not in VSG Mode\n");
461 return -EFAULT;
462 }
463
464 status = wrmaltWithLock(ad, (UINT)wrm_buff.Register,
465 (PUINT)wrm_buff.Data,
466 wrm_buff.Length);
467
468 if (status == STATUS_SUCCESS) {
469 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, OSAL_DBG,
470 DBG_LVL_ALL, "WRM Done\n");
471 } else {
472 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG,
473 DBG_LVL_ALL, "WRM Failed\n");
474 status = -EFAULT;
475 }
476 return status;
477}
478
479static int bcm_char_ioctl_gpio_set_request(void __user *argp,
480 struct bcm_mini_adapter *ad)
481{
482 struct bcm_gpio_info gpio_info = {0};
483 struct bcm_ioctl_buffer io_buff;
484 UCHAR reset_val[4];
485 UINT value = 0;
486 UINT bit = 0;
487 UINT operation = 0;
488 INT status;
489 int bytes;
490
491 if ((ad->IdleMode == TRUE) ||
492 (ad->bShutStatus == TRUE) ||
493 (ad->bPreparingForLowPowerMode == TRUE)) {
494
495 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG,
496 DBG_LVL_ALL,
497 "GPIO Can't be set/clear in Low power Mode");
498 return -EACCES;
499 }
500
501 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer)))
502 return -EFAULT;
503
504 if (io_buff.InputLength > sizeof(gpio_info))
505 return -EINVAL;
506
507 if (copy_from_user(&gpio_info, io_buff.InputBuffer,
508 io_buff.InputLength))
509 return -EFAULT;
510
511 bit = gpio_info.uiGpioNumber;
512 operation = gpio_info.uiGpioValue;
513 value = (1<<bit);
514
515 if (IsReqGpioIsLedInNVM(ad, value) == false) {
516 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG,
517 DBG_LVL_ALL,
518 "Sorry, Requested GPIO<0x%X> is not correspond to LED !!!",
519 value);
520 return -EINVAL;
521 }
522
523 /* Set - setting 1 */
524 if (operation) {
525 /* Set the gpio output register */
526 status = wrmaltWithLock(ad,
527 BCM_GPIO_OUTPUT_SET_REG,
528 (PUINT)(&value), sizeof(UINT));
529
530 if (status == STATUS_SUCCESS) {
531 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS,
532 OSAL_DBG, DBG_LVL_ALL,
533 "Set the GPIO bit\n");
534 } else {
535 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS,
536 OSAL_DBG, DBG_LVL_ALL,
537 "Failed to set the %dth GPIO\n",
538 bit);
539 return status;
540 }
541 } else {
542 /* Set the gpio output register */
543 status = wrmaltWithLock(ad,
544 BCM_GPIO_OUTPUT_CLR_REG,
545 (PUINT)(&value), sizeof(UINT));
546
547 if (status == STATUS_SUCCESS) {
548 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS,
549 OSAL_DBG, DBG_LVL_ALL,
550 "Set the GPIO bit\n");
551 } else {
552 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS,
553 OSAL_DBG, DBG_LVL_ALL,
554 "Failed to clear the %dth GPIO\n",
555 bit);
556 return status;
557 }
558 }
559
560 bytes = rdmaltWithLock(ad, (UINT)GPIO_MODE_REGISTER,
561 (PUINT)reset_val, sizeof(UINT));
562 if (bytes < 0) {
563 status = bytes;
564 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
565 "GPIO_MODE_REGISTER read failed");
566 return status;
567 }
568 status = STATUS_SUCCESS;
569
570 /* Set the gpio mode register to output */
571 *(UINT *)reset_val |= (1<<bit);
572 status = wrmaltWithLock(ad, GPIO_MODE_REGISTER,
573 (PUINT)reset_val, sizeof(UINT));
574
575 if (status == STATUS_SUCCESS) {
576 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG,
577 DBG_LVL_ALL,
578 "Set the GPIO to output Mode\n");
579 } else {
580 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG,
581 DBG_LVL_ALL,
582 "Failed to put GPIO in Output Mode\n");
583 }
584
585 return status;
586}
587
588static int bcm_char_ioctl_led_thread_state_change_req(void __user *argp,
589 struct bcm_mini_adapter *ad)
590{
591 struct bcm_user_thread_req thread_req = {0};
592 struct bcm_ioctl_buffer io_buff;
593
594 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
595 "User made LED thread InActive");
596
597 if ((ad->IdleMode == TRUE) ||
598 (ad->bShutStatus == TRUE) ||
599 (ad->bPreparingForLowPowerMode == TRUE)) {
600
601 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG,
602 DBG_LVL_ALL,
603 "GPIO Can't be set/clear in Low power Mode");
604 return -EACCES;
605 }
606
607 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer)))
608 return -EFAULT;
609
610 if (io_buff.InputLength > sizeof(thread_req))
611 return -EINVAL;
612
613 if (copy_from_user(&thread_req, io_buff.InputBuffer,
614 io_buff.InputLength))
615 return -EFAULT;
616
617 /* if LED thread is running(Actively or Inactively)
618 * set it state to make inactive
619 */
620 if (ad->LEDInfo.led_thread_running) {
621 if (thread_req.ThreadState == LED_THREAD_ACTIVATION_REQ) {
622 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS,
623 OSAL_DBG, DBG_LVL_ALL,
624 "Activating thread req");
625 ad->DriverState = LED_THREAD_ACTIVE;
626 } else {
627 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS,
628 OSAL_DBG, DBG_LVL_ALL,
629 "DeActivating Thread req.....");
630 ad->DriverState = LED_THREAD_INACTIVE;
631 }
632
633 /* signal thread. */
634 wake_up(&ad->LEDInfo.notify_led_event);
635 }
636 return STATUS_SUCCESS;
637}
638
639static int bcm_char_ioctl_gpio_status_request(void __user *argp,
640 struct bcm_mini_adapter *ad)
641{
642 struct bcm_gpio_info gpio_info = {0};
643 struct bcm_ioctl_buffer io_buff;
644 ULONG bit = 0;
645 UCHAR read[4];
646 INT status;
647 int bytes;
648
649 if ((ad->IdleMode == TRUE) ||
650 (ad->bShutStatus == TRUE) ||
651 (ad->bPreparingForLowPowerMode == TRUE))
652 return -EACCES;
653
654 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer)))
655 return -EFAULT;
656
657 if (io_buff.InputLength > sizeof(gpio_info))
658 return -EINVAL;
659
660 if (copy_from_user(&gpio_info, io_buff.InputBuffer,
661 io_buff.InputLength))
662 return -EFAULT;
663
664 bit = gpio_info.uiGpioNumber;
665
666 /* Set the gpio output register */
667 bytes = rdmaltWithLock(ad, (UINT)GPIO_PIN_STATE_REGISTER,
668 (PUINT)read, sizeof(UINT));
669
670 if (bytes < 0) {
671 status = bytes;
672 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
673 "RDM Failed\n");
674 return status;
675 }
676 status = STATUS_SUCCESS;
677 return status;
678}
679
680static int bcm_char_ioctl_gpio_multi_request(void __user *argp,
681 struct bcm_mini_adapter *ad)
682{
683 struct bcm_gpio_multi_info gpio_multi_info[MAX_IDX];
684 struct bcm_gpio_multi_info *pgpio_multi_info =
685 (struct bcm_gpio_multi_info *)gpio_multi_info;
686 struct bcm_ioctl_buffer io_buff;
687 UCHAR reset_val[4];
688 INT status = STATUS_FAILURE;
689 int bytes;
690
691 memset(pgpio_multi_info, 0,
692 MAX_IDX * sizeof(struct bcm_gpio_multi_info));
693
694 if ((ad->IdleMode == TRUE) ||
695 (ad->bShutStatus == TRUE) ||
696 (ad->bPreparingForLowPowerMode == TRUE))
697 return -EINVAL;
698
699 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer)))
700 return -EFAULT;
701
702 if (io_buff.InputLength > sizeof(gpio_multi_info))
703 return -EINVAL;
704 if (io_buff.OutputLength > sizeof(gpio_multi_info))
705 io_buff.OutputLength = sizeof(gpio_multi_info);
706
707 if (copy_from_user(&gpio_multi_info, io_buff.InputBuffer,
708 io_buff.InputLength))
709 return -EFAULT;
710
711 if (IsReqGpioIsLedInNVM(ad, pgpio_multi_info[WIMAX_IDX].uiGPIOMask)
712 == false) {
713 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG,
714 DBG_LVL_ALL,
715 "Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",
716 pgpio_multi_info[WIMAX_IDX].uiGPIOMask,
717 ad->gpioBitMap);
718 return -EINVAL;
719 }
720
721 /* Set the gpio output register */
722 if ((pgpio_multi_info[WIMAX_IDX].uiGPIOMask) &
723 (pgpio_multi_info[WIMAX_IDX].uiGPIOCommand)) {
724 /* Set 1's in GPIO OUTPUT REGISTER */
725 *(UINT *)reset_val = pgpio_multi_info[WIMAX_IDX].uiGPIOMask &
726 pgpio_multi_info[WIMAX_IDX].uiGPIOCommand &
727 pgpio_multi_info[WIMAX_IDX].uiGPIOValue;
728
729 if (*(UINT *) reset_val)
730 status = wrmaltWithLock(ad,
731 BCM_GPIO_OUTPUT_SET_REG,
732 (PUINT)reset_val, sizeof(ULONG));
733
734 if (status != STATUS_SUCCESS) {
735 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
736 "WRM to BCM_GPIO_OUTPUT_SET_REG Failed.");
737 return status;
738 }
739
740 /* Clear to 0's in GPIO OUTPUT REGISTER */
741 *(UINT *)reset_val =
742 (pgpio_multi_info[WIMAX_IDX].uiGPIOMask &
743 pgpio_multi_info[WIMAX_IDX].uiGPIOCommand &
744 (~(pgpio_multi_info[WIMAX_IDX].uiGPIOValue)));
745
746 if (*(UINT *) reset_val)
747 status = wrmaltWithLock(ad,
748 BCM_GPIO_OUTPUT_CLR_REG, (PUINT)reset_val,
749 sizeof(ULONG));
750
751 if (status != STATUS_SUCCESS) {
752 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
753 "WRM to BCM_GPIO_OUTPUT_CLR_REG Failed.");
754 return status;
755 }
756 }
757
758 if (pgpio_multi_info[WIMAX_IDX].uiGPIOMask) {
759 bytes = rdmaltWithLock(ad, (UINT)GPIO_PIN_STATE_REGISTER,
760 (PUINT)reset_val, sizeof(UINT));
761
762 if (bytes < 0) {
763 status = bytes;
764 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
765 "RDM to GPIO_PIN_STATE_REGISTER Failed.");
766 return status;
767 }
768 status = STATUS_SUCCESS;
769
770 pgpio_multi_info[WIMAX_IDX].uiGPIOValue =
771 (*(UINT *)reset_val &
772 pgpio_multi_info[WIMAX_IDX].uiGPIOMask);
773 }
774
775 status = copy_to_user(io_buff.OutputBuffer, &gpio_multi_info,
776 io_buff.OutputLength);
777 if (status) {
778 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
779 "Failed while copying Content to IOBufer for user space err:%d",
780 status);
781 return -EFAULT;
782 }
783 return status;
784}
785
786static int bcm_char_ioctl_gpio_mode_request(void __user *argp,
787 struct bcm_mini_adapter *ad)
788{
789 struct bcm_gpio_multi_mode gpio_multi_mode[MAX_IDX];
790 struct bcm_gpio_multi_mode *pgpio_multi_mode =
791 (struct bcm_gpio_multi_mode *)gpio_multi_mode;
792 struct bcm_ioctl_buffer io_buff;
793 UCHAR reset_val[4];
794 INT status;
795 int bytes;
796
797 if ((ad->IdleMode == TRUE) ||
798 (ad->bShutStatus == TRUE) ||
799 (ad->bPreparingForLowPowerMode == TRUE))
800 return -EINVAL;
801
802 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer)))
803 return -EFAULT;
804
805 if (io_buff.InputLength > sizeof(gpio_multi_mode))
806 return -EINVAL;
807 if (io_buff.OutputLength > sizeof(gpio_multi_mode))
808 io_buff.OutputLength = sizeof(gpio_multi_mode);
809
810 if (copy_from_user(&gpio_multi_mode, io_buff.InputBuffer,
811 io_buff.InputLength))
812 return -EFAULT;
813
814 bytes = rdmaltWithLock(ad, (UINT)GPIO_MODE_REGISTER,
815 (PUINT)reset_val, sizeof(UINT));
816
817 if (bytes < 0) {
818 status = bytes;
819 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
820 "Read of GPIO_MODE_REGISTER failed");
821 return status;
822 }
823 status = STATUS_SUCCESS;
824
825 /* Validating the request */
826 if (IsReqGpioIsLedInNVM(ad, pgpio_multi_mode[WIMAX_IDX].uiGPIOMask)
827 == false) {
828 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
829 "Sorry, Requested GPIO<0x%X> is not correspond to NVM LED bit map<0x%X>!!!",
830 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask,
831 ad->gpioBitMap);
832 return -EINVAL;
833 }
834
835 if (pgpio_multi_mode[WIMAX_IDX].uiGPIOMask) {
836 /* write all OUT's (1's) */
837 *(UINT *) reset_val |=
838 (pgpio_multi_mode[WIMAX_IDX].uiGPIOMode &
839 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
840
841 /* write all IN's (0's) */
842 *(UINT *) reset_val &=
843 ~((~pgpio_multi_mode[WIMAX_IDX].uiGPIOMode) &
844 pgpio_multi_mode[WIMAX_IDX].uiGPIOMask);
845
846 /* Currently implemented return the modes of all GPIO's
847 * else needs to bit AND with mask
848 */
849 pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *(UINT *)reset_val;
850
851 status = wrmaltWithLock(ad, GPIO_MODE_REGISTER,
852 (PUINT)reset_val, sizeof(ULONG));
853 if (status == STATUS_SUCCESS) {
854 BCM_DEBUG_PRINT(ad,
855 DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
856 "WRM to GPIO_MODE_REGISTER Done");
857 } else {
858 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
859 "WRM to GPIO_MODE_REGISTER Failed");
860 return -EFAULT;
861 }
862 } else {
863 /* if uiGPIOMask is 0 then return mode register configuration */
864 pgpio_multi_mode[WIMAX_IDX].uiGPIOMode = *(UINT *)reset_val;
865 }
866
867 status = copy_to_user(io_buff.OutputBuffer, &gpio_multi_mode,
868 io_buff.OutputLength);
869 if (status) {
870 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
871 "Failed while copying Content to IOBufer for user space err:%d",
872 status);
873 return -EFAULT;
874 }
875 return status;
876}
877
878static int bcm_char_ioctl_misc_request(void __user *argp,
879 struct bcm_mini_adapter *ad)
880{
881 struct bcm_ioctl_buffer io_buff;
882 PVOID buff = NULL;
883 INT status;
884
885 /* Copy Ioctl Buffer structure */
886 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer)))
887 return -EFAULT;
888
889 if (io_buff.InputLength < sizeof(struct bcm_link_request))
890 return -EINVAL;
891
892 if (io_buff.InputLength > MAX_CNTL_PKT_SIZE)
893 return -EINVAL;
894
895 buff = memdup_user(io_buff.InputBuffer,
896 io_buff.InputLength);
897 if (IS_ERR(buff))
898 return PTR_ERR(buff);
899
900 down(&ad->LowPowerModeSync);
901 status = wait_event_interruptible_timeout(
902 ad->lowpower_mode_wait_queue,
903 !ad->bPreparingForLowPowerMode,
904 (1 * HZ));
905
906 if (status == -ERESTARTSYS)
907 goto cntrlEnd;
908
909 if (ad->bPreparingForLowPowerMode) {
910 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
911 "Preparing Idle Mode is still True - Hence Rejecting control message\n");
912 status = STATUS_FAILURE;
913 goto cntrlEnd;
914 }
915 status = CopyBufferToControlPacket(ad, (PVOID)buff);
916
917cntrlEnd:
918 up(&ad->LowPowerModeSync);
919 kfree(buff);
920 return status;
921}
922
923static int bcm_char_ioctl_buffer_download_start(
924 struct bcm_mini_adapter *ad)
925{
926 INT status;
927
928 if (down_trylock(&ad->NVMRdmWrmLock)) {
929 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
930 "IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
931 return -EACCES;
932 }
933
934 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
935 "Starting the firmware download PID =0x%x!!!!\n",
936 current->pid);
937
938 if (down_trylock(&ad->fw_download_sema))
939 return -EBUSY;
940
941 ad->bBinDownloaded = false;
942 ad->fw_download_process_pid = current->pid;
943 ad->bCfgDownloaded = false;
944 ad->fw_download_done = false;
945 netif_carrier_off(ad->dev);
946 netif_stop_queue(ad->dev);
947 status = reset_card_proc(ad);
948 if (status) {
949 pr_err(PFX "%s: reset_card_proc Failed!\n", ad->dev->name);
950 up(&ad->fw_download_sema);
951 up(&ad->NVMRdmWrmLock);
952 return status;
953 }
954 mdelay(10);
955
956 up(&ad->NVMRdmWrmLock);
957 return status;
958}
959
960static int bcm_char_ioctl_buffer_download(void __user *argp,
961 struct bcm_mini_adapter *ad)
962{
963 struct bcm_firmware_info *fw_info = NULL;
964 struct bcm_ioctl_buffer io_buff;
965 INT status;
966
967 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
968 "Starting the firmware download PID =0x%x!!!!\n", current->pid);
969
970 if (!down_trylock(&ad->fw_download_sema)) {
971 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
972 "Invalid way to download buffer. Use Start and then call this!!!\n");
973 up(&ad->fw_download_sema);
974 return -EINVAL;
975 }
976
977 /* Copy Ioctl Buffer structure */
978 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer))) {
979 up(&ad->fw_download_sema);
980 return -EFAULT;
981 }
982
983 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
984 "Length for FW DLD is : %lx\n", io_buff.InputLength);
985
986 if (io_buff.InputLength > sizeof(struct bcm_firmware_info)) {
987 up(&ad->fw_download_sema);
988 return -EINVAL;
989 }
990
991 fw_info = kmalloc(sizeof(*fw_info), GFP_KERNEL);
992 if (!fw_info) {
993 up(&ad->fw_download_sema);
994 return -ENOMEM;
995 }
996
997 if (copy_from_user(fw_info, io_buff.InputBuffer,
998 io_buff.InputLength)) {
999 up(&ad->fw_download_sema);
1000 kfree(fw_info);
1001 return -EFAULT;
1002 }
1003
1004 if (!fw_info->pvMappedFirmwareAddress ||
1005 (fw_info->u32FirmwareLength == 0)) {
1006
1007 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1008 "Something else is wrong %lu\n",
1009 fw_info->u32FirmwareLength);
1010 up(&ad->fw_download_sema);
1011 kfree(fw_info);
1012 status = -EINVAL;
1013 return status;
1014 }
1015
1016 status = bcm_ioctl_fw_download(ad, fw_info);
1017
1018 if (status != STATUS_SUCCESS) {
1019 if (fw_info->u32StartingAddress == CONFIG_BEGIN_ADDR)
1020 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1021 "IOCTL: Configuration File Upload Failed\n");
1022 else
1023 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1024 "IOCTL: Firmware File Upload Failed\n");
1025
1026 /* up(&ad->fw_download_sema); */
1027
1028 if (ad->LEDInfo.led_thread_running &
1029 BCM_LED_THREAD_RUNNING_ACTIVELY) {
1030 ad->DriverState = DRIVER_INIT;
1031 ad->LEDInfo.bLedInitDone = false;
1032 wake_up(&ad->LEDInfo.notify_led_event);
1033 }
1034 }
1035
1036 if (status != STATUS_SUCCESS)
1037 up(&ad->fw_download_sema);
1038
1039 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, OSAL_DBG, DBG_LVL_ALL,
1040 "IOCTL: Firmware File Uploaded\n");
1041 kfree(fw_info);
1042 return status;
1043}
1044
1045static int bcm_char_ioctl_buffer_download_stop(void __user *argp,
1046 struct bcm_mini_adapter *ad)
1047{
1048 INT status;
1049 int timeout = 0;
1050
1051 if (!down_trylock(&ad->fw_download_sema)) {
1052 up(&ad->fw_download_sema);
1053 return -EINVAL;
1054 }
1055
1056 if (down_trylock(&ad->NVMRdmWrmLock)) {
1057 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1058 "FW download blocked as EEPROM Read/Write is in progress\n");
1059 up(&ad->fw_download_sema);
1060 return -EACCES;
1061 }
1062
1063 ad->bBinDownloaded = TRUE;
1064 ad->bCfgDownloaded = TRUE;
1065 atomic_set(&ad->CurrNumFreeTxDesc, 0);
1066 ad->CurrNumRecvDescs = 0;
1067 ad->downloadDDR = 0;
1068
1069 /* setting the Mips to Run */
1070 status = run_card_proc(ad);
1071
1072 if (status) {
1073 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1074 "Firm Download Failed\n");
1075 up(&ad->fw_download_sema);
1076 up(&ad->NVMRdmWrmLock);
1077 return status;
1078 }
1079 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG,
1080 DBG_LVL_ALL, "Firm Download Over...\n");
1081
1082 mdelay(10);
1083
1084 /* Wait for MailBox Interrupt */
1085 if (StartInterruptUrb((struct bcm_interface_adapter *)ad->pvInterfaceAdapter))
1086 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1087 "Unable to send interrupt...\n");
1088
1089 timeout = 5*HZ;
1090 ad->waiting_to_fw_download_done = false;
1091 wait_event_timeout(ad->ioctl_fw_dnld_wait_queue,
1092 ad->waiting_to_fw_download_done, timeout);
1093 ad->fw_download_process_pid = INVALID_PID;
1094 ad->fw_download_done = TRUE;
1095 atomic_set(&ad->CurrNumFreeTxDesc, 0);
1096 ad->CurrNumRecvDescs = 0;
1097 ad->PrevNumRecvDescs = 0;
1098 atomic_set(&ad->cntrlpktCnt, 0);
1099 ad->LinkUpStatus = 0;
1100 ad->LinkStatus = 0;
1101
1102 if (ad->LEDInfo.led_thread_running &
1103 BCM_LED_THREAD_RUNNING_ACTIVELY) {
1104 ad->DriverState = FW_DOWNLOAD_DONE;
1105 wake_up(&ad->LEDInfo.notify_led_event);
1106 }
1107
1108 if (!timeout)
1109 status = -ENODEV;
1110
1111 up(&ad->fw_download_sema);
1112 up(&ad->NVMRdmWrmLock);
1113 return status;
1114}
1115
1116static int bcm_char_ioctl_chip_reset(struct bcm_mini_adapter *ad)
1117{
1118 INT status;
1119 INT nvm_access;
1120
1121 nvm_access = down_trylock(&ad->NVMRdmWrmLock);
1122 if (nvm_access) {
1123 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1124 " IOCTL_BCM_CHIP_RESET not allowed as EEPROM Read/Write is in progress\n");
1125 return -EACCES;
1126 }
1127
1128 down(&ad->RxAppControlQueuelock);
1129 status = reset_card_proc(ad);
1130 flushAllAppQ();
1131 up(&ad->RxAppControlQueuelock);
1132 up(&ad->NVMRdmWrmLock);
1133 ResetCounters(ad);
1134 return status;
1135}
1136
1137static int bcm_char_ioctl_qos_threshold(ULONG arg,
1138 struct bcm_mini_adapter *ad)
1139{
1140 USHORT i;
1141
1142 for (i = 0; i < NO_OF_QUEUES; i++) {
1143 if (get_user(ad->PackInfo[i].uiThreshold,
1144 (unsigned long __user *)arg)) {
1145 return -EFAULT;
1146 }
1147 }
1148 return 0;
1149}
1150
1151static int bcm_char_ioctl_switch_transfer_mode(void __user *argp,
1152 struct bcm_mini_adapter *ad)
1153{
1154 UINT data = 0;
1155
1156 if (copy_from_user(&data, argp, sizeof(UINT)))
1157 return -EFAULT;
1158
1159 if (data) {
1160 /* Allow All Packets */
1161 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1162 "IOCTL_BCM_SWITCH_TRANSFER_MODE: ETH_PACKET_TUNNELING_MODE\n");
1163 ad->TransferMode = ETH_PACKET_TUNNELING_MODE;
1164 } else {
1165 /* Allow IP only Packets */
1166 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1167 "IOCTL_BCM_SWITCH_TRANSFER_MODE: IP_PACKET_ONLY_MODE\n");
1168 ad->TransferMode = IP_PACKET_ONLY_MODE;
1169 }
1170 return STATUS_SUCCESS;
1171}
1172
1173static int bcm_char_ioctl_get_driver_version(void __user *argp)
1174{
1175 struct bcm_ioctl_buffer io_buff;
1176 ulong len;
1177
1178 /* Copy Ioctl Buffer structure */
1179 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer)))
1180 return -EFAULT;
1181
1182 len = min_t(ulong, io_buff.OutputLength, strlen(DRV_VERSION) + 1);
1183
1184 if (copy_to_user(io_buff.OutputBuffer, DRV_VERSION, len))
1185 return -EFAULT;
1186
1187 return STATUS_SUCCESS;
1188}
1189
1190static int bcm_char_ioctl_get_current_status(void __user *argp,
1191 struct bcm_mini_adapter *ad)
1192{
1193 struct bcm_link_state link_state;
1194 struct bcm_ioctl_buffer io_buff;
1195
1196 /* Copy Ioctl Buffer structure */
1197 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer))) {
1198 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1199 "copy_from_user failed..\n");
1200 return -EFAULT;
1201 }
1202
1203 if (io_buff.OutputLength != sizeof(link_state))
1204 return -EINVAL;
1205
1206 memset(&link_state, 0, sizeof(link_state));
1207 link_state.bIdleMode = ad->IdleMode;
1208 link_state.bShutdownMode = ad->bShutStatus;
1209 link_state.ucLinkStatus = ad->LinkStatus;
1210
1211 if (copy_to_user(io_buff.OutputBuffer, &link_state, min_t(size_t,
1212 sizeof(link_state), io_buff.OutputLength))) {
1213 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1214 "Copy_to_user Failed..\n");
1215 return -EFAULT;
1216 }
1217 return STATUS_SUCCESS;
1218}
1219
1220
1221static int bcm_char_ioctl_set_mac_tracing(void __user *argp,
1222 struct bcm_mini_adapter *ad)
1223{
1224 struct bcm_ioctl_buffer io_buff;
1225 UINT tracing_flag;
1226
1227 /* copy ioctl Buffer structure */
1228 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer)))
1229 return -EFAULT;
1230
1231 if (copy_from_user(&tracing_flag, io_buff.InputBuffer, sizeof(UINT)))
1232 return -EFAULT;
1233
1234 if (tracing_flag)
1235 ad->pTarangs->MacTracingEnabled = TRUE;
1236 else
1237 ad->pTarangs->MacTracingEnabled = false;
1238
1239 return STATUS_SUCCESS;
1240}
1241
1242static int bcm_char_ioctl_get_dsx_indication(void __user *argp,
1243 struct bcm_mini_adapter *ad)
1244{
1245 struct bcm_ioctl_buffer io_buff;
1246 ULONG sf_id = 0;
1247
1248 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer)))
1249 return -EFAULT;
1250
1251 if (io_buff.OutputLength < sizeof(struct bcm_add_indication_alt)) {
1252 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1253 "Mismatch req: %lx needed is =0x%zx!!!",
1254 io_buff.OutputLength,
1255 sizeof(struct bcm_add_indication_alt));
1256 return -EINVAL;
1257 }
1258
1259 if (copy_from_user(&sf_id, io_buff.InputBuffer, sizeof(sf_id)))
1260 return -EFAULT;
1261
1262 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1263 "Get DSX Data SF ID is =%lx\n", sf_id);
1264 get_dsx_sf_data_to_application(ad, sf_id, io_buff.OutputBuffer);
1265 return STATUS_SUCCESS;
1266}
1267
1268static int bcm_char_ioctl_get_host_mibs(void __user *argp,
1269 struct bcm_mini_adapter *ad,
1270 struct bcm_tarang_data *tarang)
1271{
1272 struct bcm_ioctl_buffer io_buff;
1273 INT status = STATUS_FAILURE;
1274 PVOID temp_buff;
1275
1276 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer)))
1277 return -EFAULT;
1278
1279 if (io_buff.OutputLength != sizeof(struct bcm_host_stats_mibs)) {
1280 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1281 "Length Check failed %lu %zd\n", io_buff.OutputLength,
1282 sizeof(struct bcm_host_stats_mibs));
1283 return -EINVAL;
1284 }
1285
1286 /* FIXME: HOST_STATS are too big for kmalloc (122048)! */
1287 temp_buff = kzalloc(sizeof(struct bcm_host_stats_mibs), GFP_KERNEL);
1288 if (!temp_buff)
1289 return STATUS_FAILURE;
1290
1291 status = ProcessGetHostMibs(ad, temp_buff);
1292 GetDroppedAppCntrlPktMibs(temp_buff, tarang);
1293
1294 if (status != STATUS_FAILURE) {
1295 if (copy_to_user(io_buff.OutputBuffer, temp_buff,
1296 sizeof(struct bcm_host_stats_mibs))) {
1297 kfree(temp_buff);
1298 return -EFAULT;
1299 }
1300 }
1301
1302 kfree(temp_buff);
1303 return status;
1304}
1305
1306static int bcm_char_ioctl_bulk_wrm(void __user *argp,
1307 struct bcm_mini_adapter *ad, UINT cmd)
1308{
1309 struct bcm_bulk_wrm_buffer *bulk_buff;
1310 struct bcm_ioctl_buffer io_buff;
1311 UINT tmp = 0;
1312 INT status = STATUS_FAILURE;
1313 PCHAR buff = NULL;
1314
1315 if ((ad->IdleMode == TRUE) ||
1316 (ad->bShutStatus == TRUE) ||
1317 (ad->bPreparingForLowPowerMode == TRUE)) {
1318
1319 BCM_DEBUG_PRINT (ad, DBG_TYPE_PRINTK, 0, 0,
1320 "Device in Idle/Shutdown Mode, Blocking Wrms\n");
1321 return -EACCES;
1322 }
1323
1324 /* Copy Ioctl Buffer structure */
1325 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer)))
1326 return -EFAULT;
1327
1328 if (io_buff.InputLength < sizeof(ULONG) * 2)
1329 return -EINVAL;
1330
1331 buff = memdup_user(io_buff.InputBuffer,
1332 io_buff.InputLength);
1333 if (IS_ERR(buff))
1334 return PTR_ERR(buff);
1335
1336 bulk_buff = (struct bcm_bulk_wrm_buffer *)buff;
1337
1338 if (((ULONG)bulk_buff->Register & 0x0F000000) != 0x0F000000 ||
1339 ((ULONG)bulk_buff->Register & 0x3)) {
1340 BCM_DEBUG_PRINT (ad, DBG_TYPE_PRINTK, 0, 0,
1341 "WRM Done On invalid Address : %x Access Denied.\n",
1342 (int)bulk_buff->Register);
1343 kfree(buff);
1344 return -EINVAL;
1345 }
1346
1347 tmp = bulk_buff->Register & EEPROM_REJECT_MASK;
1348 if (!((ad->pstargetparams->m_u32Customize)&VSG_MODE) &&
1349 ((tmp == EEPROM_REJECT_REG_1) ||
1350 (tmp == EEPROM_REJECT_REG_2) ||
1351 (tmp == EEPROM_REJECT_REG_3) ||
1352 (tmp == EEPROM_REJECT_REG_4)) &&
1353 (cmd == IOCTL_BCM_REGISTER_WRITE)) {
1354
1355 kfree(buff);
1356 BCM_DEBUG_PRINT (ad, DBG_TYPE_PRINTK, 0, 0,
1357 "EEPROM Access Denied, not in VSG Mode\n");
1358 return -EFAULT;
1359 }
1360
1361 if (bulk_buff->SwapEndian == false)
1362 status = wrmWithLock(ad, (UINT)bulk_buff->Register,
1363 (PCHAR)bulk_buff->Values,
1364 io_buff.InputLength - 2*sizeof(ULONG));
1365 else
1366 status = wrmaltWithLock(ad, (UINT)bulk_buff->Register,
1367 (PUINT)bulk_buff->Values,
1368 io_buff.InputLength - 2*sizeof(ULONG));
1369
1370 if (status != STATUS_SUCCESS)
1371 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0, "WRM Failed\n");
1372
1373 kfree(buff);
1374 return status;
1375}
1376
1377static int bcm_char_ioctl_get_nvm_size(void __user *argp,
1378 struct bcm_mini_adapter *ad)
1379{
1380 struct bcm_ioctl_buffer io_buff;
1381
1382 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer)))
1383 return -EFAULT;
1384
1385 if (ad->eNVMType == NVM_EEPROM || ad->eNVMType == NVM_FLASH) {
1386 if (copy_to_user(io_buff.OutputBuffer, &ad->uiNVMDSDSize,
1387 sizeof(UINT)))
1388 return -EFAULT;
1389 }
1390
1391 return STATUS_SUCCESS;
1392}
1393
1394static int bcm_char_ioctl_cal_init(void __user *argp,
1395 struct bcm_mini_adapter *ad)
1396{
1397 struct bcm_ioctl_buffer io_buff;
1398 UINT sector_size = 0;
1399 INT status = STATUS_FAILURE;
1400
1401 if (ad->eNVMType == NVM_FLASH) {
1402 if (copy_from_user(&io_buff, argp,
1403 sizeof(struct bcm_ioctl_buffer)))
1404 return -EFAULT;
1405
1406 if (copy_from_user(&sector_size, io_buff.InputBuffer,
1407 sizeof(UINT)))
1408 return -EFAULT;
1409
1410 if ((sector_size < MIN_SECTOR_SIZE) ||
1411 (sector_size > MAX_SECTOR_SIZE)) {
1412 if (copy_to_user(io_buff.OutputBuffer,
1413 &ad->uiSectorSize, sizeof(UINT)))
1414 return -EFAULT;
1415 } else {
1416 if (IsFlash2x(ad)) {
1417 if (copy_to_user(io_buff.OutputBuffer,
1418 &ad->uiSectorSize, sizeof(UINT)))
1419 return -EFAULT;
1420 } else {
1421 if ((TRUE == ad->bShutStatus) ||
1422 (TRUE == ad->IdleMode)) {
1423 BCM_DEBUG_PRINT(ad,
1424 DBG_TYPE_PRINTK, 0, 0,
1425 "Device is in Idle/Shutdown Mode\n");
1426 return -EACCES;
1427 }
1428
1429 ad->uiSectorSize = sector_size;
1430 BcmUpdateSectorSize(ad,
1431 ad->uiSectorSize);
1432 }
1433 }
1434 status = STATUS_SUCCESS;
1435 } else {
1436 status = STATUS_FAILURE;
1437 }
1438 return status;
1439}
1440
1441static int bcm_char_ioctl_set_debug(void __user *argp,
1442 struct bcm_mini_adapter *ad)
1443{
1444#ifdef DEBUG
1445 struct bcm_ioctl_buffer io_buff;
1446 struct bcm_user_debug_state user_debug_state;
1447
1448 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1449 "In SET_DEBUG ioctl\n");
1450 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer)))
1451 return -EFAULT;
1452
1453 if (copy_from_user(&user_debug_state, io_buff.InputBuffer,
1454 sizeof(struct bcm_user_debug_state)))
1455 return -EFAULT;
1456
1457 BCM_DEBUG_PRINT (ad, DBG_TYPE_PRINTK, 0, 0,
1458 "IOCTL_BCM_SET_DEBUG: OnOff=%d Type = 0x%x ",
1459 user_debug_state.OnOff, user_debug_state.Type);
1460 /* user_debug_state.Subtype <<= 1; */
1461 user_debug_state.Subtype = 1 << user_debug_state.Subtype;
1462 BCM_DEBUG_PRINT (ad, DBG_TYPE_PRINTK, 0, 0,
1463 "actual Subtype=0x%x\n", user_debug_state.Subtype);
1464
1465 /* Update new 'DebugState' in the ad */
1466 ad->stDebugState.type |= user_debug_state.Type;
1467 /* Subtype: A bitmap of 32 bits for Subtype per Type.
1468 * Valid indexes in 'subtype' array: 1,2,4,8
1469 * corresponding to valid Type values. Hence we can use the 'Type' field
1470 * as the index value, ignoring the array entries 0,3,5,6,7 !
1471 */
1472 if (user_debug_state.OnOff)
1473 ad->stDebugState.subtype[user_debug_state.Type] |=
1474 user_debug_state.Subtype;
1475 else
1476 ad->stDebugState.subtype[user_debug_state.Type] &=
1477 ~user_debug_state.Subtype;
1478
1479 BCM_SHOW_DEBUG_BITMAP(ad);
1480#endif
1481 return STATUS_SUCCESS;
1482}
1483
1484static int bcm_char_ioctl_nvm_rw(void __user *argp,
1485 struct bcm_mini_adapter *ad, UINT cmd)
1486{
1487 struct bcm_nvm_readwrite nvm_rw;
1488 struct timeval tv0, tv1;
1489 struct bcm_ioctl_buffer io_buff;
1490 PUCHAR read_data = NULL;
1491 INT status = STATUS_FAILURE;
1492
1493 memset(&tv0, 0, sizeof(struct timeval));
1494 memset(&tv1, 0, sizeof(struct timeval));
1495 if ((ad->eNVMType == NVM_FLASH) &&
1496 (ad->uiFlashLayoutMajorVersion == 0)) {
1497 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1498 "The Flash Control Section is Corrupted. Hence Rejection on NVM Read/Write\n");
1499 return -EFAULT;
1500 }
1501
1502 if (IsFlash2x(ad)) {
1503 if ((ad->eActiveDSD != DSD0) &&
1504 (ad->eActiveDSD != DSD1) &&
1505 (ad->eActiveDSD != DSD2)) {
1506
1507 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1508 "No DSD is active..hence NVM Command is blocked");
1509 return STATUS_FAILURE;
1510 }
1511 }
1512
1513 /* Copy Ioctl Buffer structure */
1514 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer)))
1515 return -EFAULT;
1516
1517 if (copy_from_user(&nvm_rw,
1518 (IOCTL_BCM_NVM_READ == cmd) ?
1519 io_buff.OutputBuffer : io_buff.InputBuffer,
1520 sizeof(struct bcm_nvm_readwrite)))
1521 return -EFAULT;
1522
1523 /*
1524 * Deny the access if the offset crosses the cal area limit.
1525 */
1526 if (nvm_rw.uiNumBytes > ad->uiNVMDSDSize)
1527 return STATUS_FAILURE;
1528
1529 if (nvm_rw.uiOffset >
1530 ad->uiNVMDSDSize - nvm_rw.uiNumBytes)
1531 return STATUS_FAILURE;
1532
1533 read_data = memdup_user(nvm_rw.pBuffer,
1534 nvm_rw.uiNumBytes);
1535 if (IS_ERR(read_data))
1536 return PTR_ERR(read_data);
1537
1538 do_gettimeofday(&tv0);
1539 if (IOCTL_BCM_NVM_READ == cmd) {
1540 int ret = bcm_handle_nvm_read_cmd(ad, read_data,
1541 &nvm_rw);
1542 if (ret != STATUS_SUCCESS)
1543 return ret;
1544 } else {
1545 down(&ad->NVMRdmWrmLock);
1546
1547 if ((ad->IdleMode == TRUE) ||
1548 (ad->bShutStatus == TRUE) ||
1549 (ad->bPreparingForLowPowerMode == TRUE)) {
1550
1551 BCM_DEBUG_PRINT(ad,
1552 DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1553 "Device is in Idle/Shutdown Mode\n");
1554 up(&ad->NVMRdmWrmLock);
1555 kfree(read_data);
1556 return -EACCES;
1557 }
1558
1559 ad->bHeaderChangeAllowed = TRUE;
1560 if (IsFlash2x(ad)) {
1561 int ret = handle_flash2x_adapter(ad,
1562 read_data,
1563 &nvm_rw);
1564 if (ret != STATUS_SUCCESS)
1565 return ret;
1566 }
1567
1568 status = BeceemNVMWrite(ad, (PUINT)read_data,
1569 nvm_rw.uiOffset, nvm_rw.uiNumBytes,
1570 nvm_rw.bVerify);
1571 if (IsFlash2x(ad))
1572 BcmFlash2xWriteSig(ad, ad->eActiveDSD);
1573
1574 ad->bHeaderChangeAllowed = false;
1575
1576 up(&ad->NVMRdmWrmLock);
1577
1578 if (status != STATUS_SUCCESS) {
1579 kfree(read_data);
1580 return status;
1581 }
1582 }
1583
1584 do_gettimeofday(&tv1);
1585 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1586 " timetaken by Write/read :%ld msec\n",
1587 (tv1.tv_sec - tv0.tv_sec)*1000 +
1588 (tv1.tv_usec - tv0.tv_usec)/1000);
1589
1590 kfree(read_data);
1591 return STATUS_SUCCESS;
1592}
1593
1594static int bcm_char_ioctl_flash2x_section_read(void __user *argp,
1595 struct bcm_mini_adapter *ad)
1596{
1597 struct bcm_flash2x_readwrite flash_2x_read = {0};
1598 struct bcm_ioctl_buffer io_buff;
1599 PUCHAR read_buff = NULL;
1600 UINT nob = 0;
1601 UINT buff_size = 0;
1602 UINT read_bytes = 0;
1603 UINT read_offset = 0;
1604 INT status = STATUS_FAILURE;
1605 void __user *OutPutBuff;
1606
1607 if (IsFlash2x(ad) != TRUE) {
1608 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1609 "Flash Does not have 2.x map");
1610 return -EINVAL;
1611 }
1612
1613 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG,
1614 DBG_LVL_ALL, "IOCTL_BCM_FLASH2X_SECTION_READ Called");
1615 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer)))
1616 return -EFAULT;
1617
1618 /* Reading FLASH 2.x READ structure */
1619 if (copy_from_user(&flash_2x_read, io_buff.InputBuffer,
1620 sizeof(struct bcm_flash2x_readwrite)))
1621 return -EFAULT;
1622
1623 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1624 "\nflash_2x_read.Section :%x",
1625 flash_2x_read.Section);
1626 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1627 "\nflash_2x_read.offset :%x",
1628 flash_2x_read.offset);
1629 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1630 "\nflash_2x_read.numOfBytes :%x",
1631 flash_2x_read.numOfBytes);
1632 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1633 "\nflash_2x_read.bVerify :%x\n",
1634 flash_2x_read.bVerify);
1635
1636 /* This was internal to driver for raw read.
1637 * now it has ben exposed to user space app.
1638 */
1639 if (validateFlash2xReadWrite(ad, &flash_2x_read) == false)
1640 return STATUS_FAILURE;
1641
1642 nob = flash_2x_read.numOfBytes;
1643 if (nob > ad->uiSectorSize)
1644 buff_size = ad->uiSectorSize;
1645 else
1646 buff_size = nob;
1647
1648 read_offset = flash_2x_read.offset;
1649 OutPutBuff = io_buff.OutputBuffer;
1650 read_buff = kzalloc(buff_size , GFP_KERNEL);
1651
1652 if (read_buff == NULL) {
1653 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1654 "Memory allocation failed for Flash 2.x Read Structure");
1655 return -ENOMEM;
1656 }
1657 down(&ad->NVMRdmWrmLock);
1658
1659 if ((ad->IdleMode == TRUE) ||
1660 (ad->bShutStatus == TRUE) ||
1661 (ad->bPreparingForLowPowerMode == TRUE)) {
1662
1663 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG,
1664 DBG_LVL_ALL,
1665 "Device is in Idle/Shutdown Mode\n");
1666 up(&ad->NVMRdmWrmLock);
1667 kfree(read_buff);
1668 return -EACCES;
1669 }
1670
1671 while (nob) {
1672 if (nob > ad->uiSectorSize)
1673 read_bytes = ad->uiSectorSize;
1674 else
1675 read_bytes = nob;
1676
1677 /* Reading the data from Flash 2.x */
1678 status = BcmFlash2xBulkRead(ad, (PUINT)read_buff,
1679 flash_2x_read.Section, read_offset, read_bytes);
1680 if (status) {
1681 BCM_DEBUG_PRINT(ad,
1682 DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1683 "Flash 2x read err with status :%d",
1684 status);
1685 break;
1686 }
1687
1688 BCM_DEBUG_PRINT_BUFFER(ad, DBG_TYPE_OTHERS, OSAL_DBG,
1689 DBG_LVL_ALL, read_buff, read_bytes);
1690
1691 status = copy_to_user(OutPutBuff, read_buff, read_bytes);
1692 if (status) {
1693 BCM_DEBUG_PRINT(ad,
1694 DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1695 "Copy to use failed with status :%d", status);
1696 up(&ad->NVMRdmWrmLock);
1697 kfree(read_buff);
1698 return -EFAULT;
1699 }
1700 nob = nob - read_bytes;
1701 if (nob) {
1702 read_offset = read_offset + read_bytes;
1703 OutPutBuff = OutPutBuff + read_bytes;
1704 }
1705 }
1706
1707 up(&ad->NVMRdmWrmLock);
1708 kfree(read_buff);
1709 return status;
1710}
1711
1712static int bcm_char_ioctl_flash2x_section_write(void __user *argp,
1713 struct bcm_mini_adapter *ad)
1714{
1715 struct bcm_flash2x_readwrite sFlash2xWrite = {0};
1716 struct bcm_ioctl_buffer io_buff;
1717 PUCHAR write_buff;
1718 void __user *input_addr;
1719 UINT nob = 0;
1720 UINT buff_size = 0;
1721 UINT write_off = 0;
1722 UINT write_bytes = 0;
1723 INT status = STATUS_FAILURE;
1724
1725 if (IsFlash2x(ad) != TRUE) {
1726 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1727 "Flash Does not have 2.x map");
1728 return -EINVAL;
1729 }
1730
1731 /* First make this False so that we can enable the Sector
1732 * Permission Check in BeceemFlashBulkWrite
1733 */
1734 ad->bAllDSDWriteAllow = false;
1735
1736 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1737 "IOCTL_BCM_FLASH2X_SECTION_WRITE Called");
1738
1739 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer)))
1740 return -EFAULT;
1741
1742 /* Reading FLASH 2.x READ structure */
1743 if (copy_from_user(&sFlash2xWrite, io_buff.InputBuffer,
1744 sizeof(struct bcm_flash2x_readwrite)))
1745 return -EFAULT;
1746
1747 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1748 "\nsFlash2xWrite.Section :%x", sFlash2xWrite.Section);
1749 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1750 "\nsFlash2xWrite.offset :%d", sFlash2xWrite.offset);
1751 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1752 "\nsFlash2xWrite.numOfBytes :%x", sFlash2xWrite.numOfBytes);
1753 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1754 "\nsFlash2xWrite.bVerify :%x\n", sFlash2xWrite.bVerify);
1755
1756 if ((sFlash2xWrite.Section != VSA0) && (sFlash2xWrite.Section != VSA1)
1757 && (sFlash2xWrite.Section != VSA2)) {
1758 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1759 "Only VSA write is allowed");
1760 return -EINVAL;
1761 }
1762
1763 if (validateFlash2xReadWrite(ad, &sFlash2xWrite) == false)
1764 return STATUS_FAILURE;
1765
1766 input_addr = sFlash2xWrite.pDataBuff;
1767 write_off = sFlash2xWrite.offset;
1768 nob = sFlash2xWrite.numOfBytes;
1769
1770 if (nob > ad->uiSectorSize)
1771 buff_size = ad->uiSectorSize;
1772 else
1773 buff_size = nob;
1774
1775 write_buff = kmalloc(buff_size, GFP_KERNEL);
1776
1777 if (write_buff == NULL)
1778 return -ENOMEM;
1779
1780 /* extracting the remainder of the given offset. */
1781 write_bytes = ad->uiSectorSize;
1782 if (write_off % ad->uiSectorSize) {
1783 write_bytes = ad->uiSectorSize -
1784 (write_off % ad->uiSectorSize);
1785 }
1786
1787 if (nob < write_bytes)
1788 write_bytes = nob;
1789
1790 down(&ad->NVMRdmWrmLock);
1791
1792 if ((ad->IdleMode == TRUE) ||
1793 (ad->bShutStatus == TRUE) ||
1794 (ad->bPreparingForLowPowerMode == TRUE)) {
1795
1796 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1797 "Device is in Idle/Shutdown Mode\n");
1798 up(&ad->NVMRdmWrmLock);
1799 kfree(write_buff);
1800 return -EACCES;
1801 }
1802
1803 BcmFlash2xCorruptSig(ad, sFlash2xWrite.Section);
1804 do {
1805 status = copy_from_user(write_buff, input_addr, write_bytes);
1806 if (status) {
1807 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1808 "Copy to user failed with status :%d", status);
1809 up(&ad->NVMRdmWrmLock);
1810 kfree(write_buff);
1811 return -EFAULT;
1812 }
1813 BCM_DEBUG_PRINT_BUFFER(ad, DBG_TYPE_OTHERS,
1814 OSAL_DBG, DBG_LVL_ALL, write_buff, write_bytes);
1815
1816 /* Writing the data from Flash 2.x */
1817 status = BcmFlash2xBulkWrite(ad, (PUINT)write_buff,
1818 sFlash2xWrite.Section,
1819 write_off,
1820 write_bytes,
1821 sFlash2xWrite.bVerify);
1822
1823 if (status) {
1824 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1825 "Flash 2x read err with status :%d", status);
1826 break;
1827 }
1828
1829 nob = nob - write_bytes;
1830 if (nob) {
1831 write_off = write_off + write_bytes;
1832 input_addr = input_addr + write_bytes;
1833 if (nob > ad->uiSectorSize)
1834 write_bytes = ad->uiSectorSize;
1835 else
1836 write_bytes = nob;
1837 }
1838 } while (nob > 0);
1839
1840 BcmFlash2xWriteSig(ad, sFlash2xWrite.Section);
1841 up(&ad->NVMRdmWrmLock);
1842 kfree(write_buff);
1843 return status;
1844}
1845
1846static int bcm_char_ioctl_flash2x_section_bitmap(void __user *argp,
1847 struct bcm_mini_adapter *ad)
1848{
1849 struct bcm_flash2x_bitmap *flash_2x_bit_map;
1850 struct bcm_ioctl_buffer io_buff;
1851
1852BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1853 "IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP Called");
1854
1855 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer)))
1856 return -EFAULT;
1857
1858 if (io_buff.OutputLength != sizeof(struct bcm_flash2x_bitmap))
1859 return -EINVAL;
1860
1861 flash_2x_bit_map = kzalloc(sizeof(struct bcm_flash2x_bitmap),
1862 GFP_KERNEL);
1863
1864 if (flash_2x_bit_map == NULL) {
1865 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1866 "Memory is not available");
1867 return -ENOMEM;
1868 }
1869
1870 /* Reading the Flash Sectio Bit map */
1871 down(&ad->NVMRdmWrmLock);
1872
1873 if ((ad->IdleMode == TRUE) ||
1874 (ad->bShutStatus == TRUE) ||
1875 (ad->bPreparingForLowPowerMode == TRUE)) {
1876
1877 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1878 "Device is in Idle/Shutdown Mode\n");
1879 up(&ad->NVMRdmWrmLock);
1880 kfree(flash_2x_bit_map);
1881 return -EACCES;
1882 }
1883
1884 BcmGetFlash2xSectionalBitMap(ad, flash_2x_bit_map);
1885 up(&ad->NVMRdmWrmLock);
1886 if (copy_to_user(io_buff.OutputBuffer, flash_2x_bit_map,
1887 sizeof(struct bcm_flash2x_bitmap))) {
1888 kfree(flash_2x_bit_map);
1889 return -EFAULT;
1890 }
1891
1892 kfree(flash_2x_bit_map);
1893 return STATUS_FAILURE;
1894}
1895
1896static int bcm_char_ioctl_set_active_section(void __user *argp,
1897 struct bcm_mini_adapter *ad)
1898{
1899 enum bcm_flash2x_section_val flash_2x_section_val = 0;
1900 INT status = STATUS_FAILURE;
1901 struct bcm_ioctl_buffer io_buff;
1902
1903 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1904 "IOCTL_BCM_SET_ACTIVE_SECTION Called");
1905
1906 if (IsFlash2x(ad) != TRUE) {
1907 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1908 "Flash Does not have 2.x map");
1909 return -EINVAL;
1910 }
1911
1912 status = copy_from_user(&io_buff, argp,
1913 sizeof(struct bcm_ioctl_buffer));
1914 if (status) {
1915 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1916 "Copy of IOCTL BUFFER failed");
1917 return -EFAULT;
1918 }
1919
1920 status = copy_from_user(&flash_2x_section_val,
1921 io_buff.InputBuffer, sizeof(INT));
1922 if (status) {
1923 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1924 "Copy of flash section val failed");
1925 return -EFAULT;
1926 }
1927
1928 down(&ad->NVMRdmWrmLock);
1929
1930 if ((ad->IdleMode == TRUE) ||
1931 (ad->bShutStatus == TRUE) ||
1932 (ad->bPreparingForLowPowerMode == TRUE)) {
1933
1934 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1935 "Device is in Idle/Shutdown Mode\n");
1936 up(&ad->NVMRdmWrmLock);
1937 return -EACCES;
1938 }
1939
1940 status = BcmSetActiveSection(ad, flash_2x_section_val);
1941 if (status)
1942 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1943 "Failed to make it's priority Highest. status %d",
1944 status);
1945
1946 up(&ad->NVMRdmWrmLock);
1947
1948 return status;
1949}
1950
1951static int bcm_char_ioctl_copy_section(void __user *argp,
1952 struct bcm_mini_adapter *ad)
1953{
1954 struct bcm_flash2x_copy_section copy_sect_strut = {0};
1955 struct bcm_ioctl_buffer io_buff;
1956 INT status = STATUS_SUCCESS;
1957
1958 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1959 "IOCTL_BCM_COPY_SECTION Called");
1960
1961 ad->bAllDSDWriteAllow = false;
1962 if (IsFlash2x(ad) != TRUE) {
1963 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1964 "Flash Does not have 2.x map");
1965 return -EINVAL;
1966 }
1967
1968 status = copy_from_user(&io_buff, argp,
1969 sizeof(struct bcm_ioctl_buffer));
1970 if (status) {
1971 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1972 "Copy of IOCTL BUFFER failed status :%d",
1973 status);
1974 return -EFAULT;
1975 }
1976
1977 status = copy_from_user(&copy_sect_strut, io_buff.InputBuffer,
1978 sizeof(struct bcm_flash2x_copy_section));
1979 if (status) {
1980 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1981 "Copy of Copy_Section_Struct failed with status :%d",
1982 status);
1983 return -EFAULT;
1984 }
1985
1986 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1987 "Source SEction :%x", copy_sect_strut.SrcSection);
1988 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1989 "Destination SEction :%x", copy_sect_strut.DstSection);
1990 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1991 "offset :%x", copy_sect_strut.offset);
1992 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
1993 "nob :%x", copy_sect_strut.numOfBytes);
1994
1995 if (IsSectionExistInFlash(ad, copy_sect_strut.SrcSection) == false) {
1996 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
1997 "Source Section<%x> does not exist in Flash ",
1998 copy_sect_strut.SrcSection);
1999 return -EINVAL;
2000 }
2001
2002 if (IsSectionExistInFlash(ad, copy_sect_strut.DstSection) == false) {
2003 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
2004 "Destinatio Section<%x> does not exist in Flash ",
2005 copy_sect_strut.DstSection);
2006 return -EINVAL;
2007 }
2008
2009 if (copy_sect_strut.SrcSection == copy_sect_strut.DstSection) {
2010 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
2011 "Source and Destination section should be different");
2012 return -EINVAL;
2013 }
2014
2015 down(&ad->NVMRdmWrmLock);
2016
2017 if ((ad->IdleMode == TRUE) ||
2018 (ad->bShutStatus == TRUE) ||
2019 (ad->bPreparingForLowPowerMode == TRUE)) {
2020
2021 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
2022 "Device is in Idle/Shutdown Mode\n");
2023 up(&ad->NVMRdmWrmLock);
2024 return -EACCES;
2025 }
2026
2027 if (copy_sect_strut.SrcSection == ISO_IMAGE1 ||
2028 copy_sect_strut.SrcSection == ISO_IMAGE2) {
2029 if (IsNonCDLessDevice(ad)) {
2030 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
2031 "Device is Non-CDLess hence won't have ISO !!");
2032 status = -EINVAL;
2033 } else if (copy_sect_strut.numOfBytes == 0) {
2034 status = BcmCopyISO(ad, copy_sect_strut);
2035 } else {
2036 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
2037 "Partial Copy of ISO section is not Allowed..");
2038 status = STATUS_FAILURE;
2039 }
2040 up(&ad->NVMRdmWrmLock);
2041 return status;
2042 }
2043
2044 status = BcmCopySection(ad, copy_sect_strut.SrcSection,
2045 copy_sect_strut.DstSection,
2046 copy_sect_strut.offset,
2047 copy_sect_strut.numOfBytes);
2048 up(&ad->NVMRdmWrmLock);
2049 return status;
2050}
2051
2052static int bcm_char_ioctl_get_flash_cs_info(void __user *argp,
2053 struct bcm_mini_adapter *ad)
2054{
2055 struct bcm_ioctl_buffer io_buff;
2056 INT status = STATUS_SUCCESS;
2057
2058 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
2059 " IOCTL_BCM_GET_FLASH_CS_INFO Called");
2060
2061 status = copy_from_user(&io_buff, argp,
2062 sizeof(struct bcm_ioctl_buffer));
2063 if (status) {
2064 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
2065 "Copy of IOCTL BUFFER failed");
2066 return -EFAULT;
2067 }
2068
2069 if (ad->eNVMType != NVM_FLASH) {
2070 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
2071 "Connected device does not have flash");
2072 return -EINVAL;
2073 }
2074
2075 if (IsFlash2x(ad) == TRUE) {
2076 if (io_buff.OutputLength < sizeof(struct bcm_flash2x_cs_info))
2077 return -EINVAL;
2078
2079 if (copy_to_user(io_buff.OutputBuffer,
2080 ad->psFlash2xCSInfo,
2081 sizeof(struct bcm_flash2x_cs_info)))
2082 return -EFAULT;
2083 } else {
2084 if (io_buff.OutputLength < sizeof(struct bcm_flash_cs_info))
2085 return -EINVAL;
2086
2087 if (copy_to_user(io_buff.OutputBuffer, ad->psFlashCSInfo,
2088 sizeof(struct bcm_flash_cs_info)))
2089 return -EFAULT;
2090 }
2091 return status;
2092}
2093
2094static int bcm_char_ioctl_select_dsd(void __user *argp,
2095 struct bcm_mini_adapter *ad)
2096{
2097 struct bcm_ioctl_buffer io_buff;
2098 INT status = STATUS_FAILURE;
2099 UINT sect_offset = 0;
2100 enum bcm_flash2x_section_val flash_2x_section_val;
2101
2102 flash_2x_section_val = NO_SECTION_VAL;
2103 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
2104 "IOCTL_BCM_SELECT_DSD Called");
2105
2106 if (IsFlash2x(ad) != TRUE) {
2107 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
2108 "Flash Does not have 2.x map");
2109 return -EINVAL;
2110 }
2111
2112 status = copy_from_user(&io_buff, argp,
2113 sizeof(struct bcm_ioctl_buffer));
2114 if (status) {
2115 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
2116 "Copy of IOCTL BUFFER failed");
2117 return -EFAULT;
2118 }
2119 status = copy_from_user(&flash_2x_section_val, io_buff.InputBuffer,
2120 sizeof(INT));
2121 if (status) {
2122 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
2123 "Copy of flash section val failed");
2124 return -EFAULT;
2125 }
2126
2127 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
2128 "Read Section :%d", flash_2x_section_val);
2129 if ((flash_2x_section_val != DSD0) &&
2130 (flash_2x_section_val != DSD1) &&
2131 (flash_2x_section_val != DSD2)) {
2132
2133 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
2134 "Passed section<%x> is not DSD section",
2135 flash_2x_section_val);
2136 return STATUS_FAILURE;
2137 }
2138
2139 sect_offset = BcmGetSectionValStartOffset(ad, flash_2x_section_val);
2140 if (sect_offset == INVALID_OFFSET) {
2141 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
2142 "Provided Section val <%d> does not exist in Flash 2.x",
2143 flash_2x_section_val);
2144 return -EINVAL;
2145 }
2146
2147 ad->bAllDSDWriteAllow = TRUE;
2148 ad->ulFlashCalStart = sect_offset;
2149 ad->eActiveDSD = flash_2x_section_val;
2150
2151 return STATUS_SUCCESS;
2152}
2153
2154static int bcm_char_ioctl_nvm_raw_read(void __user *argp,
2155 struct bcm_mini_adapter *ad)
2156{
2157 struct bcm_nvm_readwrite nvm_read;
2158 struct bcm_ioctl_buffer io_buff;
2159 unsigned int nob;
2160 INT buff_size;
2161 INT read_offset = 0;
2162 UINT read_bytes = 0;
2163 PUCHAR read_buff;
2164 void __user *OutPutBuff;
2165 INT status = STATUS_FAILURE;
2166
2167 if (ad->eNVMType != NVM_FLASH) {
2168 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
2169 "NVM TYPE is not Flash");
2170 return -EINVAL;
2171 }
2172
2173 /* Copy Ioctl Buffer structure */
2174 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer))) {
2175 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
2176 "copy_from_user 1 failed\n");
2177 return -EFAULT;
2178 }
2179
2180 if (copy_from_user(&nvm_read, io_buff.OutputBuffer,
2181 sizeof(struct bcm_nvm_readwrite)))
2182 return -EFAULT;
2183
2184 nob = nvm_read.uiNumBytes;
2185 /* In Raw-Read max Buff size : 64MB */
2186
2187 if (nob > DEFAULT_BUFF_SIZE)
2188 buff_size = DEFAULT_BUFF_SIZE;
2189 else
2190 buff_size = nob;
2191
2192 read_offset = nvm_read.uiOffset;
2193 OutPutBuff = nvm_read.pBuffer;
2194
2195 read_buff = kzalloc(buff_size , GFP_KERNEL);
2196 if (read_buff == NULL) {
2197 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
2198 "Memory allocation failed for Flash 2.x Read Structure");
2199 return -ENOMEM;
2200 }
2201 down(&ad->NVMRdmWrmLock);
2202
2203 if ((ad->IdleMode == TRUE) ||
2204 (ad->bShutStatus == TRUE) ||
2205 (ad->bPreparingForLowPowerMode == TRUE)) {
2206
2207 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
2208 "Device is in Idle/Shutdown Mode\n");
2209 kfree(read_buff);
2210 up(&ad->NVMRdmWrmLock);
2211 return -EACCES;
2212 }
2213
2214 ad->bFlashRawRead = TRUE;
2215
2216 while (nob) {
2217 if (nob > DEFAULT_BUFF_SIZE)
2218 read_bytes = DEFAULT_BUFF_SIZE;
2219 else
2220 read_bytes = nob;
2221
2222 /* Reading the data from Flash 2.x */
2223 status = BeceemNVMRead(ad, (PUINT)read_buff,
2224 read_offset, read_bytes);
2225 if (status) {
2226 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
2227 "Flash 2x read err with status :%d",
2228 status);
2229 break;
2230 }
2231
2232 BCM_DEBUG_PRINT_BUFFER(ad, DBG_TYPE_OTHERS, OSAL_DBG,
2233 DBG_LVL_ALL, read_buff, read_bytes);
2234
2235 status = copy_to_user(OutPutBuff, read_buff, read_bytes);
2236 if (status) {
2237 BCM_DEBUG_PRINT(ad, DBG_TYPE_PRINTK, 0, 0,
2238 "Copy to use failed with status :%d",
2239 status);
2240 up(&ad->NVMRdmWrmLock);
2241 kfree(read_buff);
2242 return -EFAULT;
2243 }
2244 nob = nob - read_bytes;
2245 if (nob) {
2246 read_offset = read_offset + read_bytes;
2247 OutPutBuff = OutPutBuff + read_bytes;
2248 }
2249 }
2250 ad->bFlashRawRead = false;
2251 up(&ad->NVMRdmWrmLock);
2252 kfree(read_buff);
2253 return status;
2254}
2255
2256static int bcm_char_ioctl_cntrlmsg_mask(void __user *argp,
2257 struct bcm_mini_adapter *ad,
2258 struct bcm_tarang_data *tarang)
2259{
2260 struct bcm_ioctl_buffer io_buff;
2261 INT status = STATUS_FAILURE;
2262 ULONG rx_cntrl_msg_bit_mask = 0;
2263
2264 /* Copy Ioctl Buffer structure */
2265 status = copy_from_user(&io_buff, argp,
2266 sizeof(struct bcm_ioctl_buffer));
2267 if (status) {
2268 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
2269 "copy of Ioctl buffer is failed from user space");
2270 return -EFAULT;
2271 }
2272
2273 if (io_buff.InputLength != sizeof(unsigned long))
2274 return -EINVAL;
2275
2276 status = copy_from_user(&rx_cntrl_msg_bit_mask, io_buff.InputBuffer,
2277 io_buff.InputLength);
2278 if (status) {
2279 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
2280 "copy of control bit mask failed from user space");
2281 return -EFAULT;
2282 }
2283 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
2284 "\n Got user defined cntrl msg bit mask :%lx",
2285 rx_cntrl_msg_bit_mask);
2286 tarang->RxCntrlMsgBitMask = rx_cntrl_msg_bit_mask;
2287
2288 return status;
2289}
2290
2291static int bcm_char_ioctl_get_device_driver_info(void __user *argp,
2292 struct bcm_mini_adapter *ad)
2293{
2294 struct bcm_driver_info dev_info;
2295 struct bcm_ioctl_buffer io_buff;
2296
2297 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
2298 "Called IOCTL_BCM_GET_DEVICE_DRIVER_INFO\n");
2299
2300 memset(&dev_info, 0, sizeof(dev_info));
2301 dev_info.MaxRDMBufferSize = BUFFER_4K;
2302 dev_info.u32DSDStartOffset = EEPROM_CALPARAM_START;
2303 dev_info.u32RxAlignmentCorrection = 0;
2304 dev_info.u32NVMType = ad->eNVMType;
2305 dev_info.u32InterfaceType = BCM_USB;
2306
2307 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer)))
2308 return -EFAULT;
2309
2310 if (io_buff.OutputLength < sizeof(dev_info))
2311 return -EINVAL;
2312
2313 if (copy_to_user(io_buff.OutputBuffer, &dev_info, sizeof(dev_info)))
2314 return -EFAULT;
2315
2316 return STATUS_SUCCESS;
2317}
2318
2319static int bcm_char_ioctl_time_since_net_entry(void __user *argp,
2320 struct bcm_mini_adapter *ad)
2321{
2322 struct bcm_time_elapsed time_elapsed_since_net_entry = {0};
2323 struct bcm_ioctl_buffer io_buff;
2324
2325 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
2326 "IOCTL_BCM_TIME_SINCE_NET_ENTRY called");
2327
2328 if (copy_from_user(&io_buff, argp, sizeof(struct bcm_ioctl_buffer)))
2329 return -EFAULT;
2330
2331 if (io_buff.OutputLength < sizeof(struct bcm_time_elapsed))
2332 return -EINVAL;
2333
2334 time_elapsed_since_net_entry.ul64TimeElapsedSinceNetEntry =
2335 get_seconds() - ad->liTimeSinceLastNetEntry;
2336
2337 if (copy_to_user(io_buff.OutputBuffer, &time_elapsed_since_net_entry,
2338 sizeof(struct bcm_time_elapsed)))
2339 return -EFAULT;
2340
2341 return STATUS_SUCCESS;
2342}
2343
2344
2345static long bcm_char_ioctl(struct file *filp, UINT cmd, ULONG arg)
2346{
2347 struct bcm_tarang_data *tarang = filp->private_data;
2348 void __user *argp = (void __user *)arg;
2349 struct bcm_mini_adapter *ad = tarang->Adapter;
2350 INT status = STATUS_FAILURE;
2351
2352 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
2353 "Parameters Passed to control IOCTL cmd=0x%X arg=0x%lX",
2354 cmd, arg);
2355
2356 if (_IOC_TYPE(cmd) != BCM_IOCTL)
2357 return -EFAULT;
2358 if (_IOC_DIR(cmd) & _IOC_READ)
2359 status = !access_ok(VERIFY_WRITE, argp, _IOC_SIZE(cmd));
2360 else if (_IOC_DIR(cmd) & _IOC_WRITE)
2361 status = !access_ok(VERIFY_READ, argp, _IOC_SIZE(cmd));
2362 else if (_IOC_NONE == (_IOC_DIR(cmd) & _IOC_NONE))
2363 status = STATUS_SUCCESS;
2364
2365 if (status)
2366 return -EFAULT;
2367
2368 if (ad->device_removed)
2369 return -EFAULT;
2370
2371 if (false == ad->fw_download_done) {
2372 switch (cmd) {
2373 case IOCTL_MAC_ADDR_REQ:
2374 case IOCTL_LINK_REQ:
2375 case IOCTL_CM_REQUEST:
2376 case IOCTL_SS_INFO_REQ:
2377 case IOCTL_SEND_CONTROL_MESSAGE:
2378 case IOCTL_IDLE_REQ:
2379 case IOCTL_BCM_GPIO_SET_REQUEST:
2380 case IOCTL_BCM_GPIO_STATUS_REQUEST:
2381 return -EACCES;
2382 default:
2383 break;
2384 }
2385 }
2386
2387 status = vendorextnIoctl(ad, cmd, arg);
2388 if (status != CONTINUE_COMMON_PATH)
2389 return status;
2390
2391 switch (cmd) {
2392 /* Rdms for Swin Idle... */
2393 case IOCTL_BCM_REGISTER_READ_PRIVATE:
2394 status = bcm_char_ioctl_reg_read_private(argp, ad);
2395 return status;
2396
2397 case IOCTL_BCM_REGISTER_WRITE_PRIVATE:
2398 status = bcm_char_ioctl_reg_write_private(argp, ad);
2399 return status;
2400
2401 case IOCTL_BCM_REGISTER_READ:
2402 case IOCTL_BCM_EEPROM_REGISTER_READ:
2403 status = bcm_char_ioctl_eeprom_reg_read(argp, ad);
2404 return status;
2405
2406 case IOCTL_BCM_REGISTER_WRITE:
2407 case IOCTL_BCM_EEPROM_REGISTER_WRITE:
2408 status = bcm_char_ioctl_eeprom_reg_write(argp, ad, cmd);
2409 return status;
2410
2411 case IOCTL_BCM_GPIO_SET_REQUEST:
2412 status = bcm_char_ioctl_gpio_set_request(argp, ad);
2413 return status;
2414
2415 case BCM_LED_THREAD_STATE_CHANGE_REQ:
2416 status = bcm_char_ioctl_led_thread_state_change_req(argp,
2417 ad);
2418 return status;
2419
2420 case IOCTL_BCM_GPIO_STATUS_REQUEST:
2421 status = bcm_char_ioctl_gpio_status_request(argp, ad);
2422 return status;
2423
2424 case IOCTL_BCM_GPIO_MULTI_REQUEST:
2425 status = bcm_char_ioctl_gpio_multi_request(argp, ad);
2426 return status;
2427
2428 case IOCTL_BCM_GPIO_MODE_REQUEST:
2429 status = bcm_char_ioctl_gpio_mode_request(argp, ad);
2430 return status;
2431
2432 case IOCTL_MAC_ADDR_REQ:
2433 case IOCTL_LINK_REQ:
2434 case IOCTL_CM_REQUEST:
2435 case IOCTL_SS_INFO_REQ:
2436 case IOCTL_SEND_CONTROL_MESSAGE:
2437 case IOCTL_IDLE_REQ:
2438 status = bcm_char_ioctl_misc_request(argp, ad);
2439 return status;
2440
2441 case IOCTL_BCM_BUFFER_DOWNLOAD_START:
2442 status = bcm_char_ioctl_buffer_download_start(ad);
2443 return status;
2444
2445 case IOCTL_BCM_BUFFER_DOWNLOAD:
2446 status = bcm_char_ioctl_buffer_download(argp, ad);
2447 return status;
2448
2449 case IOCTL_BCM_BUFFER_DOWNLOAD_STOP:
2450 status = bcm_char_ioctl_buffer_download_stop(argp, ad);
2451 return status;
2452
2453
2454 case IOCTL_BE_BUCKET_SIZE:
2455 status = 0;
2456 if (get_user(ad->BEBucketSize,
2457 (unsigned long __user *)arg))
2458 status = -EFAULT;
2459 break;
2460
2461 case IOCTL_RTPS_BUCKET_SIZE:
2462 status = 0;
2463 if (get_user(ad->rtPSBucketSize,
2464 (unsigned long __user *)arg))
2465 status = -EFAULT;
2466 break;
2467
2468 case IOCTL_CHIP_RESET:
2469 status = bcm_char_ioctl_chip_reset(ad);
2470 return status;
2471
2472 case IOCTL_QOS_THRESHOLD:
2473 status = bcm_char_ioctl_qos_threshold(arg, ad);
2474 return status;
2475
2476 case IOCTL_DUMP_PACKET_INFO:
2477 DumpPackInfo(ad);
2478 DumpPhsRules(&ad->stBCMPhsContext);
2479 status = STATUS_SUCCESS;
2480 break;
2481
2482 case IOCTL_GET_PACK_INFO:
2483 if (copy_to_user(argp, &ad->PackInfo,
2484 sizeof(struct bcm_packet_info)*NO_OF_QUEUES))
2485 return -EFAULT;
2486 status = STATUS_SUCCESS;
2487 break;
2488
2489 case IOCTL_BCM_SWITCH_TRANSFER_MODE:
2490 status = bcm_char_ioctl_switch_transfer_mode(argp, ad);
2491 return status;
2492
2493 case IOCTL_BCM_GET_DRIVER_VERSION:
2494 status = bcm_char_ioctl_get_driver_version(argp);
2495 return status;
2496
2497 case IOCTL_BCM_GET_CURRENT_STATUS:
2498 status = bcm_char_ioctl_get_current_status(argp, ad);
2499 return status;
2500
2501 case IOCTL_BCM_SET_MAC_TRACING:
2502 status = bcm_char_ioctl_set_mac_tracing(argp, ad);
2503 return status;
2504
2505 case IOCTL_BCM_GET_DSX_INDICATION:
2506 status = bcm_char_ioctl_get_dsx_indication(argp, ad);
2507 return status;
2508
2509 case IOCTL_BCM_GET_HOST_MIBS:
2510 status = bcm_char_ioctl_get_host_mibs(argp, ad, tarang);
2511 return status;
2512
2513 case IOCTL_BCM_WAKE_UP_DEVICE_FROM_IDLE:
2514 if ((false == ad->bTriedToWakeUpFromlowPowerMode) &&
2515 (TRUE == ad->IdleMode)) {
2516 ad->usIdleModePattern = ABORT_IDLE_MODE;
2517 ad->bWakeUpDevice = TRUE;
2518 wake_up(&ad->process_rx_cntrlpkt);
2519 }
2520
2521 status = STATUS_SUCCESS;
2522 break;
2523
2524 case IOCTL_BCM_BULK_WRM:
2525 status = bcm_char_ioctl_bulk_wrm(argp, ad, cmd);
2526 return status;
2527
2528 case IOCTL_BCM_GET_NVM_SIZE:
2529 status = bcm_char_ioctl_get_nvm_size(argp, ad);
2530 return status;
2531
2532 case IOCTL_BCM_CAL_INIT:
2533 status = bcm_char_ioctl_cal_init(argp, ad);
2534 return status;
2535
2536 case IOCTL_BCM_SET_DEBUG:
2537 status = bcm_char_ioctl_set_debug(argp, ad);
2538 return status;
2539
2540 case IOCTL_BCM_NVM_READ:
2541 case IOCTL_BCM_NVM_WRITE:
2542 status = bcm_char_ioctl_nvm_rw(argp, ad, cmd);
2543 return status;
2544
2545 case IOCTL_BCM_FLASH2X_SECTION_READ:
2546 status = bcm_char_ioctl_flash2x_section_read(argp, ad);
2547 return status;
2548
2549 case IOCTL_BCM_FLASH2X_SECTION_WRITE:
2550 status = bcm_char_ioctl_flash2x_section_write(argp, ad);
2551 return status;
2552
2553 case IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP:
2554 status = bcm_char_ioctl_flash2x_section_bitmap(argp, ad);
2555 return status;
2556
2557 case IOCTL_BCM_SET_ACTIVE_SECTION:
2558 status = bcm_char_ioctl_set_active_section(argp, ad);
2559 return status;
2560
2561 case IOCTL_BCM_IDENTIFY_ACTIVE_SECTION:
2562 /* Right Now we are taking care of only DSD */
2563 ad->bAllDSDWriteAllow = false;
2564 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
2565 "IOCTL_BCM_IDENTIFY_ACTIVE_SECTION called");
2566 status = STATUS_SUCCESS;
2567 break;
2568
2569 case IOCTL_BCM_COPY_SECTION:
2570 status = bcm_char_ioctl_copy_section(argp, ad);
2571 return status;
2572
2573 case IOCTL_BCM_GET_FLASH_CS_INFO:
2574 status = bcm_char_ioctl_get_flash_cs_info(argp, ad);
2575 return status;
2576
2577 case IOCTL_BCM_SELECT_DSD:
2578 status = bcm_char_ioctl_select_dsd(argp, ad);
2579 return status;
2580
2581 case IOCTL_BCM_NVM_RAW_READ:
2582 status = bcm_char_ioctl_nvm_raw_read(argp, ad);
2583 return status;
2584
2585 case IOCTL_BCM_CNTRLMSG_MASK:
2586 status = bcm_char_ioctl_cntrlmsg_mask(argp, ad, tarang);
2587 return status;
2588
2589 case IOCTL_BCM_GET_DEVICE_DRIVER_INFO:
2590 status = bcm_char_ioctl_get_device_driver_info(argp, ad);
2591 return status;
2592
2593 case IOCTL_BCM_TIME_SINCE_NET_ENTRY:
2594 status = bcm_char_ioctl_time_since_net_entry(argp, ad);
2595 return status;
2596
2597 case IOCTL_CLOSE_NOTIFICATION:
2598 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, OSAL_DBG, DBG_LVL_ALL,
2599 "IOCTL_CLOSE_NOTIFICATION");
2600 break;
2601
2602 default:
2603 pr_info(DRV_NAME ": unknown ioctl cmd=%#x\n", cmd);
2604 status = STATUS_FAILURE;
2605 break;
2606 }
2607 return status;
2608}
2609
2610
2611static const struct file_operations bcm_fops = {
2612 .owner = THIS_MODULE,
2613 .open = bcm_char_open,
2614 .release = bcm_char_release,
2615 .read = bcm_char_read,
2616 .unlocked_ioctl = bcm_char_ioctl,
2617 .llseek = no_llseek,
2618};
2619
2620int register_control_device_interface(struct bcm_mini_adapter *ad)
2621{
2622
2623 if (ad->major > 0)
2624 return ad->major;
2625
2626 ad->major = register_chrdev(0, DEV_NAME, &bcm_fops);
2627 if (ad->major < 0) {
2628 pr_err(DRV_NAME ": could not created character device\n");
2629 return ad->major;
2630 }
2631
2632 ad->pstCreatedClassDevice = device_create(bcm_class, NULL,
2633 MKDEV(ad->major, 0),
2634 ad, DEV_NAME);
2635
2636 if (IS_ERR(ad->pstCreatedClassDevice)) {
2637 pr_err(DRV_NAME ": class device create failed\n");
2638 unregister_chrdev(ad->major, DEV_NAME);
2639 return PTR_ERR(ad->pstCreatedClassDevice);
2640 }
2641
2642 return 0;
2643}
2644
2645void unregister_control_device_interface(struct bcm_mini_adapter *ad)
2646{
2647 if (ad->major > 0) {
2648 device_destroy(bcm_class, MKDEV(ad->major, 0));
2649 unregister_chrdev(ad->major, DEV_NAME);
2650 }
2651}
2652
diff --git a/drivers/staging/bcm/Bcmnet.c b/drivers/staging/bcm/Bcmnet.c
deleted file mode 100644
index e57767684cee..000000000000
--- a/drivers/staging/bcm/Bcmnet.c
+++ /dev/null
@@ -1,240 +0,0 @@
1#include "headers.h"
2
3struct net_device *gblpnetdev;
4
5static INT bcm_open(struct net_device *dev)
6{
7 struct bcm_mini_adapter *ad = GET_BCM_ADAPTER(dev);
8
9 if (ad->fw_download_done == false) {
10 pr_notice(PFX "%s: link up failed (download in progress)\n",
11 dev->name);
12 return -EBUSY;
13 }
14
15 if (netif_msg_ifup(ad))
16 pr_info(PFX "%s: enabling interface\n", dev->name);
17
18 if (ad->LinkUpStatus) {
19 if (netif_msg_link(ad))
20 pr_info(PFX "%s: link up\n", dev->name);
21
22 netif_carrier_on(ad->dev);
23 netif_start_queue(ad->dev);
24 }
25
26 return 0;
27}
28
29static INT bcm_close(struct net_device *dev)
30{
31 struct bcm_mini_adapter *ad = GET_BCM_ADAPTER(dev);
32
33 if (netif_msg_ifdown(ad))
34 pr_info(PFX "%s: disabling interface\n", dev->name);
35
36 netif_carrier_off(dev);
37 netif_stop_queue(dev);
38
39 return 0;
40}
41
42static u16 bcm_select_queue(struct net_device *dev, struct sk_buff *skb,
43 void *accel_priv, select_queue_fallback_t fallback)
44{
45 return ClassifyPacket(netdev_priv(dev), skb);
46}
47
48/*******************************************************************
49* Function - bcm_transmit()
50*
51* Description - This is the main transmit function for our virtual
52* interface(eth0). It handles the ARP packets. It
53* clones this packet and then Queue it to a suitable
54* Queue. Then calls the transmit_packet().
55*
56* Parameter - skb - Pointer to the socket buffer structure
57* dev - Pointer to the virtual net device structure
58*
59*********************************************************************/
60
61static netdev_tx_t bcm_transmit(struct sk_buff *skb, struct net_device *dev)
62{
63 struct bcm_mini_adapter *ad = GET_BCM_ADAPTER(dev);
64 u16 qindex = skb_get_queue_mapping(skb);
65
66
67 if (ad->device_removed || !ad->LinkUpStatus)
68 goto drop;
69
70 if (ad->TransferMode != IP_PACKET_ONLY_MODE)
71 goto drop;
72
73 if (INVALID_QUEUE_INDEX == qindex)
74 goto drop;
75
76 if (ad->PackInfo[qindex].uiCurrentPacketsOnHost >=
77 SF_MAX_ALLOWED_PACKETS_TO_BACKUP)
78 return NETDEV_TX_BUSY;
79
80 /* Now Enqueue the packet */
81 if (netif_msg_tx_queued(ad))
82 pr_info(PFX "%s: enqueueing packet to queue %d\n",
83 dev->name, qindex);
84
85 spin_lock(&ad->PackInfo[qindex].SFQueueLock);
86 ad->PackInfo[qindex].uiCurrentBytesOnHost += skb->len;
87 ad->PackInfo[qindex].uiCurrentPacketsOnHost++;
88
89 *((B_UINT32 *) skb->cb + SKB_CB_LATENCY_OFFSET) = jiffies;
90 ENQUEUEPACKET(ad->PackInfo[qindex].FirstTxQueue,
91 ad->PackInfo[qindex].LastTxQueue, skb);
92 atomic_inc(&ad->TotalPacketCount);
93 spin_unlock(&ad->PackInfo[qindex].SFQueueLock);
94
95 /* FIXME - this is racy and incorrect, replace with work queue */
96 if (!atomic_read(&ad->TxPktAvail)) {
97 atomic_set(&ad->TxPktAvail, 1);
98 wake_up(&ad->tx_packet_wait_queue);
99 }
100 return NETDEV_TX_OK;
101
102 drop:
103 dev_kfree_skb(skb);
104 return NETDEV_TX_OK;
105}
106
107
108
109/**
110@ingroup init_functions
111Register other driver entry points with the kernel
112*/
113static const struct net_device_ops bcmNetDevOps = {
114 .ndo_open = bcm_open,
115 .ndo_stop = bcm_close,
116 .ndo_start_xmit = bcm_transmit,
117 .ndo_change_mtu = eth_change_mtu,
118 .ndo_set_mac_address = eth_mac_addr,
119 .ndo_validate_addr = eth_validate_addr,
120 .ndo_select_queue = bcm_select_queue,
121};
122
123static struct device_type wimax_type = {
124 .name = "wimax",
125};
126
127static int bcm_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
128{
129 cmd->supported = 0;
130 cmd->advertising = 0;
131 cmd->speed = SPEED_10000;
132 cmd->duplex = DUPLEX_FULL;
133 cmd->port = PORT_TP;
134 cmd->phy_address = 0;
135 cmd->transceiver = XCVR_INTERNAL;
136 cmd->autoneg = AUTONEG_DISABLE;
137 cmd->maxtxpkt = 0;
138 cmd->maxrxpkt = 0;
139 return 0;
140}
141
142static void bcm_get_drvinfo(struct net_device *dev,
143 struct ethtool_drvinfo *info)
144{
145 struct bcm_mini_adapter *ad = GET_BCM_ADAPTER(dev);
146 struct bcm_interface_adapter *intf_ad = ad->pvInterfaceAdapter;
147 struct usb_device *udev = interface_to_usbdev(intf_ad->interface);
148
149 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
150 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
151 snprintf(info->fw_version, sizeof(info->fw_version), "%u.%u",
152 ad->uiFlashLayoutMajorVersion,
153 ad->uiFlashLayoutMinorVersion);
154
155 usb_make_path(udev, info->bus_info, sizeof(info->bus_info));
156}
157
158static u32 bcm_get_link(struct net_device *dev)
159{
160 struct bcm_mini_adapter *ad = GET_BCM_ADAPTER(dev);
161
162 return ad->LinkUpStatus;
163}
164
165static u32 bcm_get_msglevel(struct net_device *dev)
166{
167 struct bcm_mini_adapter *ad = GET_BCM_ADAPTER(dev);
168
169 return ad->msg_enable;
170}
171
172static void bcm_set_msglevel(struct net_device *dev, u32 level)
173{
174 struct bcm_mini_adapter *ad = GET_BCM_ADAPTER(dev);
175
176 ad->msg_enable = level;
177}
178
179static const struct ethtool_ops bcm_ethtool_ops = {
180 .get_settings = bcm_get_settings,
181 .get_drvinfo = bcm_get_drvinfo,
182 .get_link = bcm_get_link,
183 .get_msglevel = bcm_get_msglevel,
184 .set_msglevel = bcm_set_msglevel,
185};
186
187int register_networkdev(struct bcm_mini_adapter *ad)
188{
189 struct net_device *net = ad->dev;
190 struct bcm_interface_adapter *intf_ad = ad->pvInterfaceAdapter;
191 struct usb_interface *udev = intf_ad->interface;
192 struct usb_device *xdev = intf_ad->udev;
193
194 int result;
195
196 net->netdev_ops = &bcmNetDevOps;
197 net->ethtool_ops = &bcm_ethtool_ops;
198 net->mtu = MTU_SIZE; /* 1400 Bytes */
199 net->tx_queue_len = TX_QLEN;
200 net->flags |= IFF_NOARP;
201
202 netif_carrier_off(net);
203
204 SET_NETDEV_DEVTYPE(net, &wimax_type);
205
206 /* Read the MAC Address from EEPROM */
207 result = ReadMacAddressFromNVM(ad);
208 if (result != STATUS_SUCCESS) {
209 dev_err(&udev->dev,
210 PFX "Error in Reading the mac Address: %d", result);
211 return -EIO;
212 }
213
214 result = register_netdev(net);
215 if (result)
216 return result;
217
218 gblpnetdev = ad->dev;
219
220 if (netif_msg_probe(ad))
221 dev_info(&udev->dev, PFX "%s: register usb-%s-%s %pM\n",
222 net->name, xdev->bus->bus_name, xdev->devpath,
223 net->dev_addr);
224
225 return 0;
226}
227
228void unregister_networkdev(struct bcm_mini_adapter *ad)
229{
230 struct net_device *net = ad->dev;
231 struct bcm_interface_adapter *intf_ad = ad->pvInterfaceAdapter;
232 struct usb_interface *udev = intf_ad->interface;
233 struct usb_device *xdev = intf_ad->udev;
234
235 if (netif_msg_probe(ad))
236 dev_info(&udev->dev, PFX "%s: unregister usb-%s%s\n",
237 net->name, xdev->bus->bus_name, xdev->devpath);
238
239 unregister_netdev(ad->dev);
240}
diff --git a/drivers/staging/bcm/CmHost.c b/drivers/staging/bcm/CmHost.c
deleted file mode 100644
index adca0ce4d05f..000000000000
--- a/drivers/staging/bcm/CmHost.c
+++ /dev/null
@@ -1,2254 +0,0 @@
1/************************************************************
2 * CMHOST.C
3 * This file contains the routines for handling Connection
4 * Management.
5 ************************************************************/
6
7#include "headers.h"
8
9enum E_CLASSIFIER_ACTION {
10 eInvalidClassifierAction,
11 eAddClassifier,
12 eReplaceClassifier,
13 eDeleteClassifier
14};
15
16static ULONG GetNextTargetBufferLocation(struct bcm_mini_adapter *Adapter,
17 B_UINT16 tid);
18static void restore_endianess_of_pstClassifierEntry(
19 struct bcm_classifier_rule *pstClassifierEntry,
20 enum bcm_ipaddr_context eIpAddrContext);
21
22static void apply_phs_rule_to_all_classifiers(
23 register struct bcm_mini_adapter *Adapter,
24 register UINT uiSearchRuleIndex,
25 USHORT uVCID,
26 struct bcm_phs_rule *sPhsRule,
27 struct bcm_phs_rules *cPhsRule,
28 struct bcm_add_indication_alt *pstAddIndication);
29
30/************************************************************
31 * Function - SearchSfid
32 *
33 * Description - This routinue would search QOS queues having
34 * specified SFID as input parameter.
35 *
36 * Parameters - Adapter: Pointer to the Adapter structure
37 * uiSfid : Given SFID for matching
38 *
39 * Returns - Queue index for this SFID(If matched)
40 * Else Invalid Queue Index(If Not matched)
41 ************************************************************/
42int SearchSfid(struct bcm_mini_adapter *Adapter, UINT uiSfid)
43{
44 int i;
45
46 for (i = (NO_OF_QUEUES-1); i >= 0; i--)
47 if (Adapter->PackInfo[i].ulSFID == uiSfid)
48 return i;
49
50 return NO_OF_QUEUES+1;
51}
52
53/***************************************************************
54 * Function -SearchFreeSfid
55 *
56 * Description - This routinue would search Free available SFID.
57 *
58 * Parameter - Adapter: Pointer to the Adapter structure
59 *
60 * Returns - Queue index for the free SFID
61 * Else returns Invalid Index.
62 ****************************************************************/
63static int SearchFreeSfid(struct bcm_mini_adapter *Adapter)
64{
65 int i;
66
67 for (i = 0; i < (NO_OF_QUEUES-1); i++)
68 if (Adapter->PackInfo[i].ulSFID == 0)
69 return i;
70
71 return NO_OF_QUEUES+1;
72}
73
74/*
75 * Function: SearchClsid
76 * Description: This routinue would search Classifier having specified ClassifierID as input parameter
77 * Input parameters: struct bcm_mini_adapter *Adapter - Adapter Context
78 * unsigned int uiSfid - The SF in which the classifier is to searched
79 * B_UINT16 uiClassifierID - The classifier ID to be searched
80 * Return: int :Classifier table index of matching entry
81 */
82static int SearchClsid(struct bcm_mini_adapter *Adapter,
83 ULONG ulSFID,
84 B_UINT16 uiClassifierID)
85{
86 int i;
87
88 for (i = 0; i < MAX_CLASSIFIERS; i++) {
89 if ((Adapter->astClassifierTable[i].bUsed) &&
90 (Adapter->astClassifierTable[i].uiClassifierRuleIndex
91 == uiClassifierID) &&
92 (Adapter->astClassifierTable[i].ulSFID == ulSFID))
93 return i;
94 }
95
96 return MAX_CLASSIFIERS+1;
97}
98
99/*
100 * @ingroup ctrl_pkt_functions
101 * This routinue would search Free available Classifier entry in classifier table.
102 * @return free Classifier Entry index in classifier table for specified SF
103 */
104static int SearchFreeClsid(struct bcm_mini_adapter *Adapter /**Adapter Context*/)
105{
106 int i;
107
108 for (i = 0; i < MAX_CLASSIFIERS; i++) {
109 if (!Adapter->astClassifierTable[i].bUsed)
110 return i;
111 }
112
113 return MAX_CLASSIFIERS+1;
114}
115
116static VOID deleteSFBySfid(struct bcm_mini_adapter *Adapter,
117 UINT uiSearchRuleIndex)
118{
119 /* deleting all the packet held in the SF */
120 flush_queue(Adapter, uiSearchRuleIndex);
121
122 /* Deleting the all classifiers for this SF */
123 DeleteAllClassifiersForSF(Adapter, uiSearchRuleIndex);
124
125 /* Resetting only MIBS related entries in the SF */
126 memset((PVOID)&Adapter->PackInfo[uiSearchRuleIndex], 0,
127 sizeof(struct bcm_mibs_table));
128}
129
130static inline VOID
131CopyIpAddrToClassifier(struct bcm_classifier_rule *pstClassifierEntry,
132 B_UINT8 u8IpAddressLen, B_UINT8 *pu8IpAddressMaskSrc,
133 bool bIpVersion6, enum bcm_ipaddr_context eIpAddrContext)
134{
135 int i = 0;
136 UINT nSizeOfIPAddressInBytes = IP_LENGTH_OF_ADDRESS;
137 UCHAR *ptrClassifierIpAddress = NULL;
138 UCHAR *ptrClassifierIpMask = NULL;
139 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
140
141 if (bIpVersion6)
142 nSizeOfIPAddressInBytes = IPV6_ADDRESS_SIZEINBYTES;
143
144 /* Destination Ip Address */
145 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
146 "Ip Address Range Length:0x%X ", u8IpAddressLen);
147 if ((bIpVersion6 ? (IPV6_ADDRESS_SIZEINBYTES * MAX_IP_RANGE_LENGTH * 2) :
148 (TOTAL_MASKED_ADDRESS_IN_BYTES)) >= u8IpAddressLen) {
149
150 union u_ip_address *st_dest_ip =
151 &pstClassifierEntry->stDestIpAddress;
152
153 union u_ip_address *st_src_ip =
154 &pstClassifierEntry->stSrcIpAddress;
155
156 /*
157 * checking both the mask and address togethor in Classification.
158 * So length will be : TotalLengthInBytes/nSizeOfIPAddressInBytes * 2
159 * (nSizeOfIPAddressInBytes for address and nSizeOfIPAddressInBytes for mask)
160 */
161 if (eIpAddrContext == eDestIpAddress) {
162 pstClassifierEntry->ucIPDestinationAddressLength =
163 u8IpAddressLen/(nSizeOfIPAddressInBytes * 2);
164 if (bIpVersion6) {
165 ptrClassifierIpAddress =
166 st_dest_ip->ucIpv6Address;
167 ptrClassifierIpMask =
168 st_dest_ip->ucIpv6Mask;
169 } else {
170 ptrClassifierIpAddress =
171 st_dest_ip->ucIpv4Address;
172 ptrClassifierIpMask =
173 st_dest_ip->ucIpv4Mask;
174 }
175 } else if (eIpAddrContext == eSrcIpAddress) {
176 pstClassifierEntry->ucIPSourceAddressLength =
177 u8IpAddressLen/(nSizeOfIPAddressInBytes * 2);
178 if (bIpVersion6) {
179 ptrClassifierIpAddress =
180 st_src_ip->ucIpv6Address;
181 ptrClassifierIpMask = st_src_ip->ucIpv6Mask;
182 } else {
183 ptrClassifierIpAddress =
184 st_src_ip->ucIpv4Address;
185 ptrClassifierIpMask = st_src_ip->ucIpv4Mask;
186 }
187 }
188 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
189 "Address Length:0x%X\n",
190 pstClassifierEntry->ucIPDestinationAddressLength);
191 while ((u8IpAddressLen >= nSizeOfIPAddressInBytes)
192 && (i < MAX_IP_RANGE_LENGTH)) {
193 memcpy(ptrClassifierIpAddress +
194 (i * nSizeOfIPAddressInBytes),
195 (pu8IpAddressMaskSrc
196 + (i * nSizeOfIPAddressInBytes * 2)),
197 nSizeOfIPAddressInBytes);
198
199 if (!bIpVersion6) {
200 if (eIpAddrContext == eSrcIpAddress) {
201 st_src_ip->ulIpv4Addr[i] =
202 ntohl(st_src_ip->ulIpv4Addr[i]);
203 BCM_DEBUG_PRINT(Adapter,
204 DBG_TYPE_OTHERS,
205 CONN_MSG,
206 DBG_LVL_ALL,
207 "Src Ip Address:0x%luX ",
208 st_src_ip->ulIpv4Addr[i]);
209 } else if (eIpAddrContext == eDestIpAddress) {
210 st_dest_ip->ulIpv4Addr[i] =
211 ntohl(st_dest_ip->ulIpv4Addr[i]);
212 BCM_DEBUG_PRINT(Adapter,
213 DBG_TYPE_OTHERS,
214 CONN_MSG,
215 DBG_LVL_ALL,
216 "Dest Ip Address:0x%luX ",
217 st_dest_ip->ulIpv4Addr[i]);
218 }
219 }
220 u8IpAddressLen -= nSizeOfIPAddressInBytes;
221 if (u8IpAddressLen >= nSizeOfIPAddressInBytes) {
222 memcpy(ptrClassifierIpMask +
223 (i * nSizeOfIPAddressInBytes),
224 (pu8IpAddressMaskSrc
225 + nSizeOfIPAddressInBytes
226 + (i * nSizeOfIPAddressInBytes * 2)),
227 nSizeOfIPAddressInBytes);
228
229 if (!bIpVersion6) {
230 if (eIpAddrContext == eSrcIpAddress) {
231 st_src_ip->ulIpv4Mask[i] =
232 ntohl(st_src_ip->ulIpv4Mask[i]);
233 BCM_DEBUG_PRINT(Adapter,
234 DBG_TYPE_OTHERS,
235 CONN_MSG,
236 DBG_LVL_ALL,
237 "Src Ip Mask Address:0x%luX ",
238 st_src_ip->ulIpv4Mask[i]);
239 } else if (eIpAddrContext == eDestIpAddress) {
240 st_dest_ip->ulIpv4Mask[i] =
241 ntohl(st_dest_ip->ulIpv4Mask[i]);
242 BCM_DEBUG_PRINT(Adapter,
243 DBG_TYPE_OTHERS,
244 CONN_MSG,
245 DBG_LVL_ALL,
246 "Dest Ip Mask Address:0x%luX ",
247 st_dest_ip->ulIpv4Mask[i]);
248 }
249 }
250 u8IpAddressLen -= nSizeOfIPAddressInBytes;
251 }
252 if (u8IpAddressLen == 0)
253 pstClassifierEntry->bDestIpValid = TRUE;
254
255 i++;
256 }
257 if (bIpVersion6) {
258 /* Restore EndianNess of Struct */
259 restore_endianess_of_pstClassifierEntry(
260 pstClassifierEntry,
261 eIpAddrContext
262 );
263 }
264 }
265}
266
267void ClearTargetDSXBuffer(struct bcm_mini_adapter *Adapter, B_UINT16 TID, bool bFreeAll)
268{
269 int i;
270 struct bcm_targetdsx_buffer *curr_buf;
271
272 for (i = 0; i < Adapter->ulTotalTargetBuffersAvailable; i++) {
273 curr_buf = &Adapter->astTargetDsxBuffer[i];
274
275 if (curr_buf->valid)
276 continue;
277
278 if ((bFreeAll) || (curr_buf->tid == TID)) {
279 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
280 "ClearTargetDSXBuffer: found tid %d buffer cleared %lx\n",
281 TID, curr_buf->ulTargetDsxBuffer);
282 curr_buf->valid = 1;
283 curr_buf->tid = 0;
284 Adapter->ulFreeTargetBufferCnt++;
285 }
286 }
287}
288
289/*
290 * @ingroup ctrl_pkt_functions
291 * copy classifier rule into the specified SF index
292 */
293static inline VOID CopyClassifierRuleToSF(struct bcm_mini_adapter *Adapter,
294 struct bcm_convergence_types *psfCSType,
295 UINT uiSearchRuleIndex,
296 UINT nClassifierIndex)
297{
298 struct bcm_classifier_rule *pstClassifierEntry = NULL;
299 /* VOID *pvPhsContext = NULL; */
300 int i;
301 /* UCHAR ucProtocolLength=0; */
302 /* ULONG ulPhsStatus; */
303
304 struct bcm_packet_class_rules *pack_class_rule =
305 &psfCSType->cCPacketClassificationRule;
306
307 if (Adapter->PackInfo[uiSearchRuleIndex].usVCID_Value == 0 ||
308 nClassifierIndex > (MAX_CLASSIFIERS-1))
309 return;
310
311 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
312 "Storing Classifier Rule Index : %X",
313 ntohs(pack_class_rule->u16PacketClassificationRuleIndex));
314
315 if (nClassifierIndex > MAX_CLASSIFIERS-1)
316 return;
317
318 pstClassifierEntry = &Adapter->astClassifierTable[nClassifierIndex];
319 if (pstClassifierEntry) {
320 /* Store if Ipv6 */
321 pstClassifierEntry->bIpv6Protocol =
322 (Adapter->PackInfo[uiSearchRuleIndex].ucIpVersion == IPV6) ? TRUE : false;
323
324 /* Destinaiton Port */
325 pstClassifierEntry->ucDestPortRangeLength =
326 pack_class_rule->u8ProtocolDestPortRangeLength / 4;
327 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
328 "Destination Port Range Length:0x%X ",
329 pstClassifierEntry->ucDestPortRangeLength);
330
331 if (pack_class_rule->u8ProtocolDestPortRangeLength <= MAX_PORT_RANGE) {
332 for (i = 0; i < (pstClassifierEntry->ucDestPortRangeLength); i++) {
333 pstClassifierEntry->usDestPortRangeLo[i] =
334 *((PUSHORT)(pack_class_rule->u8ProtocolDestPortRange+i));
335 pstClassifierEntry->usDestPortRangeHi[i] =
336 *((PUSHORT)(pack_class_rule->u8ProtocolDestPortRange+2+i));
337 pstClassifierEntry->usDestPortRangeLo[i] =
338 ntohs(pstClassifierEntry->usDestPortRangeLo[i]);
339 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
340 CONN_MSG, DBG_LVL_ALL,
341 "Destination Port Range Lo:0x%X ",
342 pstClassifierEntry->usDestPortRangeLo[i]);
343 pstClassifierEntry->usDestPortRangeHi[i] =
344 ntohs(pstClassifierEntry->usDestPortRangeHi[i]);
345 }
346 } else {
347 pstClassifierEntry->ucDestPortRangeLength = 0;
348 }
349
350 /* Source Port */
351 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
352 "Source Port Range Length:0x%X ",
353 pack_class_rule->u8ProtocolSourcePortRangeLength);
354 if (pack_class_rule->u8ProtocolSourcePortRangeLength <= MAX_PORT_RANGE) {
355 pstClassifierEntry->ucSrcPortRangeLength =
356 pack_class_rule->u8ProtocolSourcePortRangeLength/4;
357 for (i = 0; i < (pstClassifierEntry->ucSrcPortRangeLength); i++) {
358 pstClassifierEntry->usSrcPortRangeLo[i] =
359 *((PUSHORT)(pack_class_rule->
360 u8ProtocolSourcePortRange+i));
361 pstClassifierEntry->usSrcPortRangeHi[i] =
362 *((PUSHORT)(pack_class_rule->
363 u8ProtocolSourcePortRange+2+i));
364 pstClassifierEntry->usSrcPortRangeLo[i] =
365 ntohs(pstClassifierEntry->usSrcPortRangeLo[i]);
366 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
367 CONN_MSG, DBG_LVL_ALL,
368 "Source Port Range Lo:0x%X ",
369 pstClassifierEntry->usSrcPortRangeLo[i]);
370 pstClassifierEntry->usSrcPortRangeHi[i] =
371 ntohs(pstClassifierEntry->usSrcPortRangeHi[i]);
372 }
373 }
374 /* Destination Ip Address and Mask */
375 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
376 "Ip Destination Parameters : ");
377 CopyIpAddrToClassifier(pstClassifierEntry,
378 pack_class_rule->u8IPDestinationAddressLength,
379 pack_class_rule->u8IPDestinationAddress,
380 (Adapter->PackInfo[uiSearchRuleIndex].ucIpVersion == IPV6) ?
381 TRUE : false, eDestIpAddress);
382
383 /* Source Ip Address and Mask */
384 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
385 "Ip Source Parameters : ");
386
387 CopyIpAddrToClassifier(pstClassifierEntry,
388 pack_class_rule->u8IPMaskedSourceAddressLength,
389 pack_class_rule->u8IPMaskedSourceAddress,
390 (Adapter->PackInfo[uiSearchRuleIndex].ucIpVersion == IPV6) ? TRUE : false,
391 eSrcIpAddress);
392
393 /* TOS */
394 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
395 "TOS Length:0x%X ",
396 pack_class_rule->u8IPTypeOfServiceLength);
397 if (pack_class_rule->u8IPTypeOfServiceLength == 3) {
398 pstClassifierEntry->ucIPTypeOfServiceLength =
399 pack_class_rule->u8IPTypeOfServiceLength;
400 pstClassifierEntry->ucTosLow =
401 pack_class_rule->u8IPTypeOfService[0];
402 pstClassifierEntry->ucTosHigh =
403 pack_class_rule->u8IPTypeOfService[1];
404 pstClassifierEntry->ucTosMask =
405 pack_class_rule->u8IPTypeOfService[2];
406 pstClassifierEntry->bTOSValid = TRUE;
407 }
408 if (pack_class_rule->u8Protocol == 0) {
409 /* we didn't get protocol field filled in by the BS */
410 pstClassifierEntry->ucProtocolLength = 0;
411 } else {
412 pstClassifierEntry->ucProtocolLength = 1; /* 1 valid protocol */
413 }
414
415 pstClassifierEntry->ucProtocol[0] = pack_class_rule->u8Protocol;
416 pstClassifierEntry->u8ClassifierRulePriority =
417 pack_class_rule->u8ClassifierRulePriority;
418
419 /* store the classifier rule ID and set this classifier entry as valid */
420 pstClassifierEntry->ucDirection =
421 Adapter->PackInfo[uiSearchRuleIndex].ucDirection;
422 pstClassifierEntry->uiClassifierRuleIndex =
423 ntohs(pack_class_rule->u16PacketClassificationRuleIndex);
424 pstClassifierEntry->usVCID_Value =
425 Adapter->PackInfo[uiSearchRuleIndex].usVCID_Value;
426 pstClassifierEntry->ulSFID =
427 Adapter->PackInfo[uiSearchRuleIndex].ulSFID;
428 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
429 "Search Index %d Dir: %d, Index: %d, Vcid: %d\n",
430 uiSearchRuleIndex,
431 pstClassifierEntry->ucDirection,
432 pstClassifierEntry->uiClassifierRuleIndex,
433 pstClassifierEntry->usVCID_Value);
434
435 if (pack_class_rule->u8AssociatedPHSI)
436 pstClassifierEntry->u8AssociatedPHSI =
437 pack_class_rule->u8AssociatedPHSI;
438
439 /* Copy ETH CS Parameters */
440 pstClassifierEntry->ucEthCSSrcMACLen =
441 (pack_class_rule->u8EthernetSourceMACAddressLength);
442 memcpy(pstClassifierEntry->au8EThCSSrcMAC,
443 pack_class_rule->u8EthernetSourceMACAddress,
444 MAC_ADDRESS_SIZE);
445 memcpy(pstClassifierEntry->au8EThCSSrcMACMask,
446 pack_class_rule->u8EthernetSourceMACAddress
447 + MAC_ADDRESS_SIZE, MAC_ADDRESS_SIZE);
448 pstClassifierEntry->ucEthCSDestMACLen =
449 (pack_class_rule->u8EthernetDestMacAddressLength);
450 memcpy(pstClassifierEntry->au8EThCSDestMAC,
451 pack_class_rule->u8EthernetDestMacAddress,
452 MAC_ADDRESS_SIZE);
453 memcpy(pstClassifierEntry->au8EThCSDestMACMask,
454 pack_class_rule->u8EthernetDestMacAddress
455 + MAC_ADDRESS_SIZE, MAC_ADDRESS_SIZE);
456 pstClassifierEntry->ucEtherTypeLen =
457 (pack_class_rule->u8EthertypeLength);
458 memcpy(pstClassifierEntry->au8EthCSEtherType,
459 pack_class_rule->u8Ethertype,
460 NUM_ETHERTYPE_BYTES);
461 memcpy(pstClassifierEntry->usUserPriority,
462 &pack_class_rule->u16UserPriority, 2);
463 pstClassifierEntry->usVLANID =
464 ntohs(pack_class_rule->u16VLANID);
465 pstClassifierEntry->usValidityBitMap =
466 ntohs(pack_class_rule->u16ValidityBitMap);
467
468 pstClassifierEntry->bUsed = TRUE;
469 }
470}
471
472/*
473 * @ingroup ctrl_pkt_functions
474 */
475static inline VOID DeleteClassifierRuleFromSF(struct bcm_mini_adapter *Adapter,
476 UINT uiSearchRuleIndex, UINT nClassifierIndex)
477{
478 struct bcm_classifier_rule *pstClassifierEntry = NULL;
479 B_UINT16 u16PacketClassificationRuleIndex;
480 USHORT usVCID;
481 /* VOID *pvPhsContext = NULL; */
482 /*ULONG ulPhsStatus; */
483
484 usVCID = Adapter->PackInfo[uiSearchRuleIndex].usVCID_Value;
485
486 if (nClassifierIndex > MAX_CLASSIFIERS-1)
487 return;
488
489 if (usVCID == 0)
490 return;
491
492 u16PacketClassificationRuleIndex =
493 Adapter->astClassifierTable[nClassifierIndex].uiClassifierRuleIndex;
494 pstClassifierEntry = &Adapter->astClassifierTable[nClassifierIndex];
495 if (pstClassifierEntry) {
496 pstClassifierEntry->bUsed = false;
497 pstClassifierEntry->uiClassifierRuleIndex = 0;
498 memset(pstClassifierEntry, 0,
499 sizeof(struct bcm_classifier_rule));
500
501 /* Delete the PHS Rule for this classifier */
502 PhsDeleteClassifierRule(&Adapter->stBCMPhsContext, usVCID,
503 u16PacketClassificationRuleIndex);
504 }
505}
506
507/*
508 * @ingroup ctrl_pkt_functions
509 */
510VOID DeleteAllClassifiersForSF(struct bcm_mini_adapter *Adapter,
511 UINT uiSearchRuleIndex)
512{
513 struct bcm_classifier_rule *pstClassifierEntry = NULL;
514 int i;
515 /* B_UINT16 u16PacketClassificationRuleIndex; */
516 USHORT ulVCID;
517 /* VOID *pvPhsContext = NULL; */
518 /* ULONG ulPhsStatus; */
519
520 ulVCID = Adapter->PackInfo[uiSearchRuleIndex].usVCID_Value;
521
522 if (ulVCID == 0)
523 return;
524
525 for (i = 0; i < MAX_CLASSIFIERS; i++) {
526 if (Adapter->astClassifierTable[i].usVCID_Value == ulVCID) {
527 pstClassifierEntry = &Adapter->astClassifierTable[i];
528
529 if (pstClassifierEntry->bUsed)
530 DeleteClassifierRuleFromSF(Adapter,
531 uiSearchRuleIndex, i);
532 }
533 }
534
535 /* Delete All Phs Rules Associated with this SF */
536 PhsDeleteSFRules(&Adapter->stBCMPhsContext, ulVCID);
537}
538
539/*
540 * This routinue copies the Connection Management
541 * related data into the Adapter structure.
542 * @ingroup ctrl_pkt_functions
543 */
544static VOID CopyToAdapter(register struct bcm_mini_adapter *Adapter, /* <Pointer to the Adapter structure */
545 register struct bcm_connect_mgr_params *psfLocalSet, /* Pointer to the connection manager parameters structure */
546 register UINT uiSearchRuleIndex, /* <Index of Queue, to which this data belongs */
547 register UCHAR ucDsxType,
548 struct bcm_add_indication_alt *pstAddIndication) {
549
550 /* UCHAR ucProtocolLength = 0; */
551 ULONG ulSFID;
552 UINT nClassifierIndex = 0;
553 enum E_CLASSIFIER_ACTION eClassifierAction = eInvalidClassifierAction;
554 B_UINT16 u16PacketClassificationRuleIndex = 0;
555 int i;
556 struct bcm_convergence_types *psfCSType = NULL;
557 struct bcm_phs_rule sPhsRule;
558 struct bcm_packet_info *curr_packinfo =
559 &Adapter->PackInfo[uiSearchRuleIndex];
560 USHORT uVCID = curr_packinfo->usVCID_Value;
561 UINT UGIValue = 0;
562
563 curr_packinfo->bValid = TRUE;
564 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
565 "Search Rule Index = %d\n", uiSearchRuleIndex);
566 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
567 "%s: SFID= %x ", __func__, ntohl(psfLocalSet->u32SFID));
568 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
569 "Updating Queue %d", uiSearchRuleIndex);
570
571 ulSFID = ntohl(psfLocalSet->u32SFID);
572 /* Store IP Version used */
573 /* Get The Version Of IP used (IPv6 or IPv4) from CSSpecification field of SF */
574
575 curr_packinfo->bIPCSSupport = 0;
576 curr_packinfo->bEthCSSupport = 0;
577
578 /* Enable IP/ETh CS Support As Required */
579 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
580 "CopyToAdapter : u8CSSpecification : %X\n",
581 psfLocalSet->u8CSSpecification);
582 switch (psfLocalSet->u8CSSpecification) {
583 case eCSPacketIPV4:
584 curr_packinfo->bIPCSSupport = IPV4_CS;
585 break;
586 case eCSPacketIPV6:
587 curr_packinfo->bIPCSSupport = IPV6_CS;
588 break;
589 case eCS802_3PacketEthernet:
590 case eCS802_1QPacketVLAN:
591 curr_packinfo->bEthCSSupport = ETH_CS_802_3;
592 break;
593 case eCSPacketIPV4Over802_1QVLAN:
594 case eCSPacketIPV4Over802_3Ethernet:
595 curr_packinfo->bIPCSSupport = IPV4_CS;
596 curr_packinfo->bEthCSSupport = ETH_CS_802_3;
597 break;
598 case eCSPacketIPV6Over802_1QVLAN:
599 case eCSPacketIPV6Over802_3Ethernet:
600 curr_packinfo->bIPCSSupport = IPV6_CS;
601 curr_packinfo->bEthCSSupport = ETH_CS_802_3;
602 break;
603 default:
604 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
605 "Error in value of CS Classification.. setting default to IP CS\n");
606 curr_packinfo->bIPCSSupport = IPV4_CS;
607 break;
608 }
609
610 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
611 "CopyToAdapter : Queue No : %X ETH CS Support : %X , IP CS Support : %X\n",
612 uiSearchRuleIndex,
613 curr_packinfo->bEthCSSupport,
614 curr_packinfo->bIPCSSupport);
615
616 /* Store IP Version used */
617 /* Get The Version Of IP used (IPv6 or IPv4) from CSSpecification field of SF */
618 if (curr_packinfo->bIPCSSupport == IPV6_CS)
619 curr_packinfo->ucIpVersion = IPV6;
620 else
621 curr_packinfo->ucIpVersion = IPV4;
622
623 /* To ensure that the ETH CS code doesn't gets executed if the BS doesn't supports ETH CS */
624 if (!Adapter->bETHCSEnabled)
625 curr_packinfo->bEthCSSupport = 0;
626
627 if (psfLocalSet->u8ServiceClassNameLength > 0 && psfLocalSet->u8ServiceClassNameLength < 32)
628 memcpy(curr_packinfo->ucServiceClassName,
629 psfLocalSet->u8ServiceClassName,
630 psfLocalSet->u8ServiceClassNameLength);
631
632 curr_packinfo->u8QueueType = psfLocalSet->u8ServiceFlowSchedulingType;
633
634 if (curr_packinfo->u8QueueType == BE && curr_packinfo->ucDirection)
635 Adapter->usBestEffortQueueIndex = uiSearchRuleIndex;
636
637 curr_packinfo->ulSFID = ntohl(psfLocalSet->u32SFID);
638
639 curr_packinfo->u8TrafficPriority = psfLocalSet->u8TrafficPriority;
640
641 /* copy all the classifier in the Service Flow param structure */
642 for (i = 0; i < psfLocalSet->u8TotalClassifiers; i++) {
643 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
644 "Classifier index =%d", i);
645 psfCSType = &psfLocalSet->cConvergenceSLTypes[i];
646 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
647 "Classifier index =%d", i);
648
649 if (psfCSType->cCPacketClassificationRule.u8ClassifierRulePriority)
650 curr_packinfo->bClassifierPriority = TRUE;
651
652 if (psfCSType->cCPacketClassificationRule.u8ClassifierRulePriority)
653 curr_packinfo->bClassifierPriority = TRUE;
654
655 if (ucDsxType == DSA_ACK) {
656 eClassifierAction = eAddClassifier;
657 } else if (ucDsxType == DSC_ACK) {
658 switch (psfCSType->u8ClassfierDSCAction) {
659 case 0: /* DSC Add Classifier */
660 eClassifierAction = eAddClassifier;
661 break;
662 case 1: /* DSC Replace Classifier */
663 eClassifierAction = eReplaceClassifier;
664 break;
665 case 2: /* DSC Delete Classifier */
666 eClassifierAction = eDeleteClassifier;
667 break;
668 default:
669 eClassifierAction = eInvalidClassifierAction;
670 }
671 }
672
673 u16PacketClassificationRuleIndex = ntohs(psfCSType->cCPacketClassificationRule.u16PacketClassificationRuleIndex);
674
675 switch (eClassifierAction) {
676 case eAddClassifier:
677 /* Get a Free Classifier Index From Classifier table for this SF to add the Classifier */
678 /* Contained in this message */
679 nClassifierIndex = SearchClsid(Adapter,
680 ulSFID,
681 u16PacketClassificationRuleIndex);
682
683 if (nClassifierIndex > MAX_CLASSIFIERS) {
684 nClassifierIndex = SearchFreeClsid(Adapter);
685 if (nClassifierIndex > MAX_CLASSIFIERS) {
686 /* Failed To get a free Entry */
687 BCM_DEBUG_PRINT(Adapter,
688 DBG_TYPE_OTHERS,
689 CONN_MSG,
690 DBG_LVL_ALL,
691 "Error Failed To get a free Classifier Entry");
692 break;
693 }
694 /* Copy the Classifier Rule for this service flow into our Classifier table maintained per SF. */
695 CopyClassifierRuleToSF(Adapter, psfCSType,
696 uiSearchRuleIndex,
697 nClassifierIndex);
698 } else {
699 /* This Classifier Already Exists and it is invalid to Add Classifier with existing PCRI */
700 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
701 CONN_MSG,
702 DBG_LVL_ALL,
703 "CopyToAdapter: Error The Specified Classifier Already Exists and attempted To Add Classifier with Same PCRI : 0x%x\n",
704 u16PacketClassificationRuleIndex);
705 }
706 break;
707 case eReplaceClassifier:
708 /* Get the Classifier Index From Classifier table for this SF and replace existing Classifier */
709 /* with the new classifier Contained in this message */
710 nClassifierIndex = SearchClsid(Adapter, ulSFID,
711 u16PacketClassificationRuleIndex);
712 if (nClassifierIndex > MAX_CLASSIFIERS) {
713 /* Failed To search the classifier */
714 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
715 CONN_MSG, DBG_LVL_ALL,
716 "Error Search for Classifier To be replaced failed");
717 break;
718 }
719 /* Copy the Classifier Rule for this service flow into our Classifier table maintained per SF. */
720 CopyClassifierRuleToSF(Adapter, psfCSType,
721 uiSearchRuleIndex, nClassifierIndex);
722 break;
723 case eDeleteClassifier:
724 /* Get the Classifier Index From Classifier table for this SF and replace existing Classifier */
725 /* with the new classifier Contained in this message */
726 nClassifierIndex = SearchClsid(Adapter, ulSFID,
727 u16PacketClassificationRuleIndex);
728 if (nClassifierIndex > MAX_CLASSIFIERS) {
729 /* Failed To search the classifier */
730 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
731 CONN_MSG, DBG_LVL_ALL,
732 "Error Search for Classifier To be deleted failed");
733 break;
734 }
735
736 /* Delete This classifier */
737 DeleteClassifierRuleFromSF(Adapter, uiSearchRuleIndex,
738 nClassifierIndex);
739 break;
740 default:
741 /* Invalid Action for classifier */
742 break;
743 }
744 }
745
746 /* Repeat parsing Classification Entries to process PHS Rules */
747 for (i = 0; i < psfLocalSet->u8TotalClassifiers; i++) {
748 psfCSType = &psfLocalSet->cConvergenceSLTypes[i];
749 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
750 "psfCSType->u8PhsDSCAction : 0x%x\n",
751 psfCSType->u8PhsDSCAction);
752
753 switch (psfCSType->u8PhsDSCAction) {
754 case eDeleteAllPHSRules:
755 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG,
756 DBG_LVL_ALL,
757 "Deleting All PHS Rules For VCID: 0x%X\n",
758 uVCID);
759
760 /* Delete All the PHS rules for this Service flow */
761 PhsDeleteSFRules(&Adapter->stBCMPhsContext, uVCID);
762 break;
763 case eDeletePHSRule:
764 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG,
765 DBG_LVL_ALL,
766 "PHS DSC Action = Delete PHS Rule\n");
767
768 if (psfCSType->cPhsRule.u8PHSI)
769 PhsDeletePHSRule(&Adapter->stBCMPhsContext,
770 uVCID,
771 psfCSType->cCPacketClassificationRule.u8AssociatedPHSI);
772
773 break;
774 default:
775 if (ucDsxType == DSC_ACK) {
776 /* BCM_DEBUG_PRINT(CONN_MSG,("Invalid PHS DSC Action For DSC\n",psfCSType->cPhsRule.u8PHSI)); */
777 break; /* FOr DSC ACK Case PHS DSC Action must be in valid set */
778 }
779 /* Proceed To Add PHS rule for DSA_ACK case even if PHS DSC action is unspecified */
780 /* No Break Here . Intentionally! */
781
782 case eAddPHSRule:
783 case eSetPHSRule:
784 if (psfCSType->cPhsRule.u8PHSI) {
785 /* Apply This PHS Rule to all classifiers whose Associated PHSI Match */
786 apply_phs_rule_to_all_classifiers(Adapter,
787 uiSearchRuleIndex,
788 uVCID,
789 &sPhsRule,
790 &psfCSType->cPhsRule,
791 pstAddIndication);
792 }
793 break;
794 }
795 }
796
797 if (psfLocalSet->u32MaxSustainedTrafficRate == 0) {
798 /* No Rate Limit . Set Max Sustained Traffic Rate to Maximum */
799 curr_packinfo->uiMaxAllowedRate = WIMAX_MAX_ALLOWED_RATE;
800 } else if (ntohl(psfLocalSet->u32MaxSustainedTrafficRate) > WIMAX_MAX_ALLOWED_RATE) {
801 /* Too large Allowed Rate specified. Limiting to Wi Max Allowed rate */
802 curr_packinfo->uiMaxAllowedRate = WIMAX_MAX_ALLOWED_RATE;
803 } else {
804 curr_packinfo->uiMaxAllowedRate =
805 ntohl(psfLocalSet->u32MaxSustainedTrafficRate);
806 }
807
808 curr_packinfo->uiMaxLatency = ntohl(psfLocalSet->u32MaximumLatency);
809 if (curr_packinfo->uiMaxLatency == 0) /* 0 should be treated as infinite */
810 curr_packinfo->uiMaxLatency = MAX_LATENCY_ALLOWED;
811
812 if ((curr_packinfo->u8QueueType == ERTPS ||
813 curr_packinfo->u8QueueType == UGS))
814 UGIValue = ntohs(psfLocalSet->u16UnsolicitedGrantInterval);
815
816 if (UGIValue == 0)
817 UGIValue = DEFAULT_UG_INTERVAL;
818
819 /*
820 * For UGI based connections...
821 * DEFAULT_UGI_FACTOR*UGIInterval worth of data is the max token count at host...
822 * The extra amount of token is to ensure that a large amount of jitter won't have loss in throughput...
823 * In case of non-UGI based connection, 200 frames worth of data is the max token count at host...
824 */
825 curr_packinfo->uiMaxBucketSize =
826 (DEFAULT_UGI_FACTOR*curr_packinfo->uiMaxAllowedRate*UGIValue)/1000;
827
828 if (curr_packinfo->uiMaxBucketSize < WIMAX_MAX_MTU*8) {
829 UINT UGIFactor = 0;
830 /* Special Handling to ensure the biggest size of packet can go out from host to FW as follows:
831 * 1. Any packet from Host to FW can go out in different packet size.
832 * 2. So in case the Bucket count is smaller than MTU, the packets of size (Size > TokenCount), will get dropped.
833 * 3. We can allow packets of MaxSize from Host->FW that can go out from FW in multiple SDUs by fragmentation at Wimax Layer
834 */
835 UGIFactor = (curr_packinfo->uiMaxLatency/UGIValue + 1);
836
837 if (UGIFactor > DEFAULT_UGI_FACTOR)
838 curr_packinfo->uiMaxBucketSize =
839 (UGIFactor*curr_packinfo->uiMaxAllowedRate*UGIValue)/1000;
840
841 if (curr_packinfo->uiMaxBucketSize > WIMAX_MAX_MTU*8)
842 curr_packinfo->uiMaxBucketSize = WIMAX_MAX_MTU*8;
843 }
844
845 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
846 "LAT: %d, UGI: %d\n", curr_packinfo->uiMaxLatency,
847 UGIValue);
848 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
849 "uiMaxAllowedRate: 0x%x, u32MaxSustainedTrafficRate: 0x%x ,uiMaxBucketSize: 0x%x",
850 curr_packinfo->uiMaxAllowedRate,
851 ntohl(psfLocalSet->u32MaxSustainedTrafficRate),
852 curr_packinfo->uiMaxBucketSize);
853
854 /* copy the extended SF Parameters to Support MIBS */
855 CopyMIBSExtendedSFParameters(Adapter, psfLocalSet, uiSearchRuleIndex);
856
857 /* store header suppression enabled flag per SF */
858 curr_packinfo->bHeaderSuppressionEnabled =
859 !(psfLocalSet->u8RequesttransmissionPolicy &
860 MASK_DISABLE_HEADER_SUPPRESSION);
861
862 kfree(curr_packinfo->pstSFIndication);
863 curr_packinfo->pstSFIndication = pstAddIndication;
864
865 /* Re Sort the SF list in PackInfo according to Traffic Priority */
866 SortPackInfo(Adapter);
867
868 /* Re Sort the Classifier Rules table and re - arrange
869 * according to Classifier Rule Priority
870 */
871 SortClassifiers(Adapter);
872 DumpPhsRules(&Adapter->stBCMPhsContext);
873 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
874 "%s <=====", __func__);
875}
876
877/***********************************************************************
878 * Function - DumpCmControlPacket
879 *
880 * Description - This routinue Dumps the Contents of the AddIndication
881 * Structure in the Connection Management Control Packet
882 *
883 * Parameter - pvBuffer: Pointer to the buffer containing the
884 * AddIndication data.
885 *
886 * Returns - None
887 *************************************************************************/
888static VOID DumpCmControlPacket(PVOID pvBuffer)
889{
890 int uiLoopIndex;
891 int nIndex;
892 struct bcm_add_indication_alt *pstAddIndication;
893 UINT nCurClassifierCnt;
894 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
895
896 pstAddIndication = pvBuffer;
897 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "======>");
898 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8Type: 0x%X", pstAddIndication->u8Type);
899 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8Direction: 0x%X", pstAddIndication->u8Direction);
900 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16TID: 0x%X", ntohs(pstAddIndication->u16TID));
901 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16CID: 0x%X", ntohs(pstAddIndication->u16CID));
902 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16VCID: 0x%X", ntohs(pstAddIndication->u16VCID));
903 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " AuthorizedSet--->");
904 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32SFID: 0x%X", htonl(pstAddIndication->sfAuthorizedSet.u32SFID));
905 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16CID: 0x%X", htons(pstAddIndication->sfAuthorizedSet.u16CID));
906 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8ServiceClassNameLength: 0x%X",
907 pstAddIndication->sfAuthorizedSet.u8ServiceClassNameLength);
908
909 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8ServiceClassName: 0x%X ,0x%X , 0x%X, 0x%X, 0x%X, 0x%X",
910 pstAddIndication->sfAuthorizedSet.u8ServiceClassName[0],
911 pstAddIndication->sfAuthorizedSet.u8ServiceClassName[1],
912 pstAddIndication->sfAuthorizedSet.u8ServiceClassName[2],
913 pstAddIndication->sfAuthorizedSet.u8ServiceClassName[3],
914 pstAddIndication->sfAuthorizedSet.u8ServiceClassName[4],
915 pstAddIndication->sfAuthorizedSet.u8ServiceClassName[5]);
916
917 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8MBSService: 0x%X", pstAddIndication->sfAuthorizedSet.u8MBSService);
918 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8QosParamSet: 0x%X", pstAddIndication->sfAuthorizedSet.u8QosParamSet);
919 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8TrafficPriority: 0x%X, %p",
920 pstAddIndication->sfAuthorizedSet.u8TrafficPriority, &pstAddIndication->sfAuthorizedSet.u8TrafficPriority);
921 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32MaxSustainedTrafficRate: 0x%X 0x%p",
922 pstAddIndication->sfAuthorizedSet.u32MaxSustainedTrafficRate,
923 &pstAddIndication->sfAuthorizedSet.u32MaxSustainedTrafficRate);
924 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32MaxTrafficBurst: 0x%X", pstAddIndication->sfAuthorizedSet.u32MaxTrafficBurst);
925 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32MinReservedTrafficRate : 0x%X",
926 pstAddIndication->sfAuthorizedSet.u32MinReservedTrafficRate);
927 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8VendorSpecificQoSParamLength: 0x%X",
928 pstAddIndication->sfAuthorizedSet.u8VendorSpecificQoSParamLength);
929 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8VendorSpecificQoSParam: 0x%X",
930 pstAddIndication->sfAuthorizedSet.u8VendorSpecificQoSParam[0]);
931 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8ServiceFlowSchedulingType: 0x%X",
932 pstAddIndication->sfAuthorizedSet.u8ServiceFlowSchedulingType);
933 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32ToleratedJitter: 0x%X", pstAddIndication->sfAuthorizedSet.u32ToleratedJitter);
934 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32MaximumLatency: 0x%X", pstAddIndication->sfAuthorizedSet.u32MaximumLatency);
935 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8FixedLengthVSVariableLengthSDUIndicator: 0x%X",
936 pstAddIndication->sfAuthorizedSet.u8FixedLengthVSVariableLengthSDUIndicator);
937 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8SDUSize: 0x%X", pstAddIndication->sfAuthorizedSet.u8SDUSize);
938 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16TargetSAID: 0x%X", pstAddIndication->sfAuthorizedSet.u16TargetSAID);
939 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8ARQEnable: 0x%X", pstAddIndication->sfAuthorizedSet.u8ARQEnable);
940 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16ARQWindowSize: 0x%X", pstAddIndication->sfAuthorizedSet.u16ARQWindowSize);
941 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16ARQRetryTxTimeOut: 0x%X", pstAddIndication->sfAuthorizedSet.u16ARQRetryTxTimeOut);
942 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16ARQRetryRxTimeOut: 0x%X", pstAddIndication->sfAuthorizedSet.u16ARQRetryRxTimeOut);
943 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16ARQBlockLifeTime: 0x%X", pstAddIndication->sfAuthorizedSet.u16ARQBlockLifeTime);
944 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16ARQSyncLossTimeOut: 0x%X", pstAddIndication->sfAuthorizedSet.u16ARQSyncLossTimeOut);
945 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8ARQDeliverInOrder: 0x%X", pstAddIndication->sfAuthorizedSet.u8ARQDeliverInOrder);
946 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16ARQRxPurgeTimeOut: 0x%X", pstAddIndication->sfAuthorizedSet.u16ARQRxPurgeTimeOut);
947 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16ARQBlockSize: 0x%X", pstAddIndication->sfAuthorizedSet.u16ARQBlockSize);
948 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8CSSpecification: 0x%X", pstAddIndication->sfAuthorizedSet.u8CSSpecification);
949 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8TypeOfDataDeliveryService: 0x%X",
950 pstAddIndication->sfAuthorizedSet.u8TypeOfDataDeliveryService);
951 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16SDUInterArrivalTime: 0x%X", pstAddIndication->sfAuthorizedSet.u16SDUInterArrivalTime);
952 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16TimeBase: 0x%X", pstAddIndication->sfAuthorizedSet.u16TimeBase);
953 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8PagingPreference: 0x%X", pstAddIndication->sfAuthorizedSet.u8PagingPreference);
954 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16UnsolicitedPollingInterval: 0x%X",
955 pstAddIndication->sfAuthorizedSet.u16UnsolicitedPollingInterval);
956
957 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "sfAuthorizedSet.u8HARQChannelMapping %x %x %x ",
958 *(unsigned int *)pstAddIndication->sfAuthorizedSet.u8HARQChannelMapping,
959 *(unsigned int *)&pstAddIndication->sfAuthorizedSet.u8HARQChannelMapping[4],
960 *(USHORT *)&pstAddIndication->sfAuthorizedSet.u8HARQChannelMapping[8]);
961 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8TrafficIndicationPreference: 0x%X",
962 pstAddIndication->sfAuthorizedSet.u8TrafficIndicationPreference);
963 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " Total Classifiers Received: 0x%X", pstAddIndication->sfAuthorizedSet.u8TotalClassifiers);
964
965 nCurClassifierCnt = pstAddIndication->sfAuthorizedSet.u8TotalClassifiers;
966 if (nCurClassifierCnt > MAX_CLASSIFIERS_IN_SF)
967 nCurClassifierCnt = MAX_CLASSIFIERS_IN_SF;
968
969 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "pstAddIndication->sfAuthorizedSet.bValid %d", pstAddIndication->sfAuthorizedSet.bValid);
970 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "pstAddIndication->sfAuthorizedSet.u16MacOverhead %x", pstAddIndication->sfAuthorizedSet.u16MacOverhead);
971 if (!pstAddIndication->sfAuthorizedSet.bValid)
972 pstAddIndication->sfAuthorizedSet.bValid = 1;
973 for (nIndex = 0; nIndex < nCurClassifierCnt; nIndex++) {
974 struct bcm_convergence_types *psfCSType = NULL;
975
976 psfCSType = &pstAddIndication->sfAuthorizedSet.cConvergenceSLTypes[nIndex];
977
978 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "psfCSType = %p", psfCSType);
979 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "CCPacketClassificationRuleSI====>");
980 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8ClassifierRulePriority: 0x%X ",
981 psfCSType->cCPacketClassificationRule.u8ClassifierRulePriority);
982 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8IPTypeOfServiceLength: 0x%X ",
983 psfCSType->cCPacketClassificationRule.u8IPTypeOfServiceLength);
984 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8IPTypeOfService[3]: 0x%X ,0x%X ,0x%X ",
985 psfCSType->cCPacketClassificationRule.u8IPTypeOfService[0],
986 psfCSType->cCPacketClassificationRule.u8IPTypeOfService[1],
987 psfCSType->cCPacketClassificationRule.u8IPTypeOfService[2]);
988
989 for (uiLoopIndex = 0; uiLoopIndex < 1; uiLoopIndex++)
990 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8Protocol: 0x%02X ",
991 psfCSType->cCPacketClassificationRule.u8Protocol);
992
993 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8IPMaskedSourceAddressLength: 0x%X ",
994 psfCSType->cCPacketClassificationRule.u8IPMaskedSourceAddressLength);
995
996 for (uiLoopIndex = 0; uiLoopIndex < 32; uiLoopIndex++)
997 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8IPMaskedSourceAddress[32]: 0x%02X ",
998 psfCSType->cCPacketClassificationRule.u8IPMaskedSourceAddress[uiLoopIndex]);
999
1000 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8IPDestinationAddressLength: 0x%X ",
1001 psfCSType->cCPacketClassificationRule.u8IPDestinationAddressLength);
1002
1003 for (uiLoopIndex = 0; uiLoopIndex < 32; uiLoopIndex++)
1004 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8IPDestinationAddress[32]: 0x%02X ",
1005 psfCSType->cCPacketClassificationRule.u8IPDestinationAddress[uiLoopIndex]);
1006
1007 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8ProtocolSourcePortRangeLength:0x%X ",
1008 psfCSType->cCPacketClassificationRule.u8ProtocolSourcePortRangeLength);
1009 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8ProtocolSourcePortRange[4]: 0x%02X ,0x%02X ,0x%02X ,0x%02X ",
1010 psfCSType->cCPacketClassificationRule.u8ProtocolSourcePortRange[0],
1011 psfCSType->cCPacketClassificationRule.u8ProtocolSourcePortRange[1],
1012 psfCSType->cCPacketClassificationRule.u8ProtocolSourcePortRange[2],
1013 psfCSType->cCPacketClassificationRule.u8ProtocolSourcePortRange[3]);
1014
1015 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8ProtocolDestPortRangeLength: 0x%02X ",
1016 psfCSType->cCPacketClassificationRule.u8ProtocolDestPortRangeLength);
1017 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8ProtocolDestPortRange[4]: 0x%02X ,0x%02X ,0x%02X ,0x%02X ",
1018 psfCSType->cCPacketClassificationRule.u8ProtocolDestPortRange[0],
1019 psfCSType->cCPacketClassificationRule.u8ProtocolDestPortRange[1],
1020 psfCSType->cCPacketClassificationRule.u8ProtocolDestPortRange[2],
1021 psfCSType->cCPacketClassificationRule.u8ProtocolDestPortRange[3]);
1022
1023 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8EthernetDestMacAddressLength: 0x%02X ",
1024 psfCSType->cCPacketClassificationRule.u8EthernetDestMacAddressLength);
1025
1026 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1027 DBG_LVL_ALL, "u8EthernetDestMacAddress[6]: %pM",
1028 psfCSType->cCPacketClassificationRule.
1029 u8EthernetDestMacAddress);
1030
1031 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8EthernetSourceMACAddressLength: 0x%02X ",
1032 psfCSType->cCPacketClassificationRule.u8EthernetDestMacAddressLength);
1033
1034 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1035 DBG_LVL_ALL, "u8EthernetSourceMACAddress[6]: %pM",
1036 psfCSType->cCPacketClassificationRule.
1037 u8EthernetSourceMACAddress);
1038
1039 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8EthertypeLength: 0x%02X ",
1040 psfCSType->cCPacketClassificationRule.u8EthertypeLength);
1041 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8Ethertype[3]: 0x%02X ,0x%02X ,0x%02X ",
1042 psfCSType->cCPacketClassificationRule.u8Ethertype[0],
1043 psfCSType->cCPacketClassificationRule.u8Ethertype[1],
1044 psfCSType->cCPacketClassificationRule.u8Ethertype[2]);
1045
1046 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16UserPriority: 0x%X ", psfCSType->cCPacketClassificationRule.u16UserPriority);
1047 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16VLANID: 0x%X ", psfCSType->cCPacketClassificationRule.u16VLANID);
1048 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8AssociatedPHSI: 0x%02X ", psfCSType->cCPacketClassificationRule.u8AssociatedPHSI);
1049 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16PacketClassificationRuleIndex: 0x%X ",
1050 psfCSType->cCPacketClassificationRule.u16PacketClassificationRuleIndex);
1051
1052 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8VendorSpecificClassifierParamLength: 0x%X ",
1053 psfCSType->cCPacketClassificationRule.u8VendorSpecificClassifierParamLength);
1054 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8VendorSpecificClassifierParam[1]: 0x%X ",
1055 psfCSType->cCPacketClassificationRule.u8VendorSpecificClassifierParam[0]);
1056#ifdef VERSION_D5
1057 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8IPv6FlowLableLength: 0x%X ",
1058 psfCSType->cCPacketClassificationRule.u8IPv6FlowLableLength);
1059 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1060 DBG_LVL_ALL, "u8IPv6FlowLable[6]: 0x%*ph ",
1061 6, psfCSType->cCPacketClassificationRule.
1062 u8IPv6FlowLable);
1063#endif
1064 }
1065
1066 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "bValid: 0x%02X", pstAddIndication->sfAuthorizedSet.bValid);
1067 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "AdmittedSet--->");
1068 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32SFID: 0x%X", pstAddIndication->sfAdmittedSet.u32SFID);
1069 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16CID: 0x%X", pstAddIndication->sfAdmittedSet.u16CID);
1070 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8ServiceClassNameLength: 0x%X",
1071 pstAddIndication->sfAdmittedSet.u8ServiceClassNameLength);
1072 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL,
1073 "u8ServiceClassName: 0x%*ph",
1074 6, pstAddIndication->sfAdmittedSet.u8ServiceClassName);
1075
1076 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8MBSService: 0x%02X", pstAddIndication->sfAdmittedSet.u8MBSService);
1077 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8QosParamSet: 0x%02X", pstAddIndication->sfAdmittedSet.u8QosParamSet);
1078 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8TrafficPriority: 0x%02X", pstAddIndication->sfAdmittedSet.u8TrafficPriority);
1079 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32MaxTrafficBurst: 0x%X", pstAddIndication->sfAdmittedSet.u32MaxTrafficBurst);
1080 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32MinReservedTrafficRate: 0x%X",
1081 pstAddIndication->sfAdmittedSet.u32MinReservedTrafficRate);
1082
1083 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8VendorSpecificQoSParamLength: 0x%02X",
1084 pstAddIndication->sfAdmittedSet.u8VendorSpecificQoSParamLength);
1085 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8VendorSpecificQoSParam: 0x%02X",
1086 pstAddIndication->sfAdmittedSet.u8VendorSpecificQoSParam[0]);
1087 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8ServiceFlowSchedulingType: 0x%02X",
1088 pstAddIndication->sfAdmittedSet.u8ServiceFlowSchedulingType);
1089 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32ToleratedJitter: 0x%X", pstAddIndication->sfAdmittedSet.u32ToleratedJitter);
1090 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32MaximumLatency: 0x%X", pstAddIndication->sfAdmittedSet.u32MaximumLatency);
1091 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8FixedLengthVSVariableLengthSDUIndicator: 0x%02X",
1092 pstAddIndication->sfAdmittedSet.u8FixedLengthVSVariableLengthSDUIndicator);
1093 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8SDUSize: 0x%02X", pstAddIndication->sfAdmittedSet.u8SDUSize);
1094 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16TargetSAID: 0x%02X", pstAddIndication->sfAdmittedSet.u16TargetSAID);
1095 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8ARQEnable: 0x%02X", pstAddIndication->sfAdmittedSet.u8ARQEnable);
1096 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16ARQWindowSize: 0x%X", pstAddIndication->sfAdmittedSet.u16ARQWindowSize);
1097 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16ARQRetryTxTimeOut: 0x%X", pstAddIndication->sfAdmittedSet.u16ARQRetryTxTimeOut);
1098 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16ARQRetryRxTimeOut: 0x%X", pstAddIndication->sfAdmittedSet.u16ARQRetryRxTimeOut);
1099 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16ARQBlockLifeTime: 0x%X", pstAddIndication->sfAdmittedSet.u16ARQBlockLifeTime);
1100 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16ARQSyncLossTimeOut: 0x%X", pstAddIndication->sfAdmittedSet.u16ARQSyncLossTimeOut);
1101 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8ARQDeliverInOrder: 0x%02X", pstAddIndication->sfAdmittedSet.u8ARQDeliverInOrder);
1102 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16ARQRxPurgeTimeOut: 0x%X", pstAddIndication->sfAdmittedSet.u16ARQRxPurgeTimeOut);
1103 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16ARQBlockSize: 0x%X", pstAddIndication->sfAdmittedSet.u16ARQBlockSize);
1104 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8CSSpecification: 0x%02X", pstAddIndication->sfAdmittedSet.u8CSSpecification);
1105 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8TypeOfDataDeliveryService: 0x%02X",
1106 pstAddIndication->sfAdmittedSet.u8TypeOfDataDeliveryService);
1107 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16SDUInterArrivalTime: 0x%X", pstAddIndication->sfAdmittedSet.u16SDUInterArrivalTime);
1108 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16TimeBase: 0x%X", pstAddIndication->sfAdmittedSet.u16TimeBase);
1109 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8PagingPreference: 0x%X", pstAddIndication->sfAdmittedSet.u8PagingPreference);
1110 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8TrafficIndicationPreference: 0x%02X",
1111 pstAddIndication->sfAdmittedSet.u8TrafficIndicationPreference);
1112 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " Total Classifiers Received: 0x%X", pstAddIndication->sfAdmittedSet.u8TotalClassifiers);
1113
1114 nCurClassifierCnt = pstAddIndication->sfAdmittedSet.u8TotalClassifiers;
1115 if (nCurClassifierCnt > MAX_CLASSIFIERS_IN_SF)
1116 nCurClassifierCnt = MAX_CLASSIFIERS_IN_SF;
1117
1118 for (nIndex = 0; nIndex < nCurClassifierCnt; nIndex++) {
1119 struct bcm_convergence_types *psfCSType = NULL;
1120
1121 psfCSType = &pstAddIndication->sfAdmittedSet.cConvergenceSLTypes[nIndex];
1122 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " CCPacketClassificationRuleSI====>");
1123 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8ClassifierRulePriority: 0x%02X ",
1124 psfCSType->cCPacketClassificationRule.u8ClassifierRulePriority);
1125 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8IPTypeOfServiceLength: 0x%02X",
1126 psfCSType->cCPacketClassificationRule.u8IPTypeOfServiceLength);
1127 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1128 DBG_LVL_ALL, "u8IPTypeOfService[3]: 0x%*ph",
1129 3, psfCSType->cCPacketClassificationRule.
1130 u8IPTypeOfService);
1131 for (uiLoopIndex = 0; uiLoopIndex < 1; uiLoopIndex++)
1132 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8Protocol: 0x%02X ", psfCSType->cCPacketClassificationRule.u8Protocol);
1133
1134 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8IPMaskedSourceAddressLength: 0x%02X ",
1135 psfCSType->cCPacketClassificationRule.u8IPMaskedSourceAddressLength);
1136
1137 for (uiLoopIndex = 0; uiLoopIndex < 32; uiLoopIndex++)
1138 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8IPMaskedSourceAddress[32]: 0x%02X ",
1139 psfCSType->cCPacketClassificationRule.u8IPMaskedSourceAddress[uiLoopIndex]);
1140
1141 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8IPDestinationAddressLength: 0x%02X ",
1142 psfCSType->cCPacketClassificationRule.u8IPDestinationAddressLength);
1143
1144 for (uiLoopIndex = 0; uiLoopIndex < 32; uiLoopIndex++)
1145 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8IPDestinationAddress[32]: 0x%02X ",
1146 psfCSType->cCPacketClassificationRule.u8IPDestinationAddress[uiLoopIndex]);
1147
1148 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8ProtocolSourcePortRangeLength: 0x%02X ",
1149 psfCSType->cCPacketClassificationRule.u8ProtocolSourcePortRangeLength);
1150
1151 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1152 DBG_LVL_ALL, "u8ProtocolSourcePortRange[4]: 0x%*ph ",
1153 4, psfCSType->cCPacketClassificationRule.
1154 u8ProtocolSourcePortRange);
1155
1156 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8ProtocolDestPortRangeLength: 0x%02X ",
1157 psfCSType->cCPacketClassificationRule.u8ProtocolDestPortRangeLength);
1158
1159 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1160 DBG_LVL_ALL, "u8ProtocolDestPortRange[4]: 0x%*ph ",
1161 4, psfCSType->cCPacketClassificationRule.
1162 u8ProtocolDestPortRange);
1163
1164 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8EthernetDestMacAddressLength: 0x%02X ",
1165 psfCSType->cCPacketClassificationRule.u8EthernetDestMacAddressLength);
1166
1167 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1168 DBG_LVL_ALL, "u8EthernetDestMacAddress[6]: %pM",
1169 psfCSType->cCPacketClassificationRule.
1170 u8EthernetDestMacAddress);
1171
1172 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8EthernetSourceMACAddressLength: 0x%02X ",
1173 psfCSType->cCPacketClassificationRule.u8EthernetDestMacAddressLength);
1174
1175 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1176 DBG_LVL_ALL, "u8EthernetSourceMACAddress[6]: %pM",
1177 psfCSType->cCPacketClassificationRule.
1178 u8EthernetSourceMACAddress);
1179
1180 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8EthertypeLength: 0x%02X ", psfCSType->cCPacketClassificationRule.u8EthertypeLength);
1181 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1182 DBG_LVL_ALL, "u8Ethertype[3]: 0x%*ph",
1183 3, psfCSType->cCPacketClassificationRule.
1184 u8Ethertype);
1185
1186 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16UserPriority: 0x%X ", psfCSType->cCPacketClassificationRule.u16UserPriority);
1187 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16VLANID: 0x%X ", psfCSType->cCPacketClassificationRule.u16VLANID);
1188 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8AssociatedPHSI: 0x%02X ", psfCSType->cCPacketClassificationRule.u8AssociatedPHSI);
1189 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16PacketClassificationRuleIndex: 0x%X ",
1190 psfCSType->cCPacketClassificationRule.u16PacketClassificationRuleIndex);
1191 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8VendorSpecificClassifierParamLength: 0x%02X",
1192 psfCSType->cCPacketClassificationRule.u8VendorSpecificClassifierParamLength);
1193 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8VendorSpecificClassifierParam[1]: 0x%02X ",
1194 psfCSType->cCPacketClassificationRule.u8VendorSpecificClassifierParam[0]);
1195#ifdef VERSION_D5
1196 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8IPv6FlowLableLength: 0x%X ",
1197 psfCSType->cCPacketClassificationRule.u8IPv6FlowLableLength);
1198 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1199 DBG_LVL_ALL, "u8IPv6FlowLable[6]: 0x%*ph ",
1200 6, psfCSType->cCPacketClassificationRule.
1201 u8IPv6FlowLable);
1202#endif
1203 }
1204
1205 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "bValid: 0x%X", pstAddIndication->sfAdmittedSet.bValid);
1206 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " ActiveSet--->");
1207 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32SFID: 0x%X", pstAddIndication->sfActiveSet.u32SFID);
1208 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u16CID: 0x%X", pstAddIndication->sfActiveSet.u16CID);
1209 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8ServiceClassNameLength: 0x%X", pstAddIndication->sfActiveSet.u8ServiceClassNameLength);
1210 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL,
1211 "u8ServiceClassName: 0x%*ph",
1212 6, pstAddIndication->sfActiveSet.u8ServiceClassName);
1213
1214 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8MBSService: 0x%02X", pstAddIndication->sfActiveSet.u8MBSService);
1215 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8QosParamSet: 0x%02X", pstAddIndication->sfActiveSet.u8QosParamSet);
1216 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8TrafficPriority: 0x%02X", pstAddIndication->sfActiveSet.u8TrafficPriority);
1217 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32MaxTrafficBurst: 0x%X", pstAddIndication->sfActiveSet.u32MaxTrafficBurst);
1218 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32MinReservedTrafficRate: 0x%X",
1219 pstAddIndication->sfActiveSet.u32MinReservedTrafficRate);
1220 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8VendorSpecificQoSParamLength: 0x%02X",
1221 pstAddIndication->sfActiveSet.u8VendorSpecificQoSParamLength);
1222 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8VendorSpecificQoSParam: 0x%02X",
1223 pstAddIndication->sfActiveSet.u8VendorSpecificQoSParam[0]);
1224 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8ServiceFlowSchedulingType: 0x%02X",
1225 pstAddIndication->sfActiveSet.u8ServiceFlowSchedulingType);
1226 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32ToleratedJitter: 0x%X", pstAddIndication->sfActiveSet.u32ToleratedJitter);
1227 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u32MaximumLatency: 0x%X", pstAddIndication->sfActiveSet.u32MaximumLatency);
1228 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8FixedLengthVSVariableLengthSDUIndicator: 0x%02X",
1229 pstAddIndication->sfActiveSet.u8FixedLengthVSVariableLengthSDUIndicator);
1230 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, "u8SDUSize: 0x%X", pstAddIndication->sfActiveSet.u8SDUSize);
1231 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " u16TargetSAID: 0x%X", pstAddIndication->sfActiveSet.u16TargetSAID);
1232 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " u8ARQEnable: 0x%X", pstAddIndication->sfActiveSet.u8ARQEnable);
1233 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " u16ARQWindowSize: 0x%X", pstAddIndication->sfActiveSet.u16ARQWindowSize);
1234 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " u16ARQRetryTxTimeOut: 0x%X", pstAddIndication->sfActiveSet.u16ARQRetryTxTimeOut);
1235 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " u16ARQRetryRxTimeOut: 0x%X", pstAddIndication->sfActiveSet.u16ARQRetryRxTimeOut);
1236 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " u16ARQBlockLifeTime: 0x%X", pstAddIndication->sfActiveSet.u16ARQBlockLifeTime);
1237 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " u16ARQSyncLossTimeOut: 0x%X", pstAddIndication->sfActiveSet.u16ARQSyncLossTimeOut);
1238 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " u8ARQDeliverInOrder: 0x%X", pstAddIndication->sfActiveSet.u8ARQDeliverInOrder);
1239 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " u16ARQRxPurgeTimeOut: 0x%X", pstAddIndication->sfActiveSet.u16ARQRxPurgeTimeOut);
1240 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " u16ARQBlockSize: 0x%X", pstAddIndication->sfActiveSet.u16ARQBlockSize);
1241 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " u8CSSpecification: 0x%X", pstAddIndication->sfActiveSet.u8CSSpecification);
1242 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " u8TypeOfDataDeliveryService: 0x%X",
1243 pstAddIndication->sfActiveSet.u8TypeOfDataDeliveryService);
1244 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " u16SDUInterArrivalTime: 0x%X", pstAddIndication->sfActiveSet.u16SDUInterArrivalTime);
1245 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " u16TimeBase: 0x%X", pstAddIndication->sfActiveSet.u16TimeBase);
1246 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " u8PagingPreference: 0x%X", pstAddIndication->sfActiveSet.u8PagingPreference);
1247 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " u8TrafficIndicationPreference: 0x%X",
1248 pstAddIndication->sfActiveSet.u8TrafficIndicationPreference);
1249 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL, " Total Classifiers Received: 0x%X", pstAddIndication->sfActiveSet.u8TotalClassifiers);
1250
1251 nCurClassifierCnt = pstAddIndication->sfActiveSet.u8TotalClassifiers;
1252 if (nCurClassifierCnt > MAX_CLASSIFIERS_IN_SF)
1253 nCurClassifierCnt = MAX_CLASSIFIERS_IN_SF;
1254
1255 for (nIndex = 0; nIndex < nCurClassifierCnt; nIndex++) {
1256 struct bcm_convergence_types *psfCSType = NULL;
1257 struct bcm_packet_class_rules *clsRule = NULL;
1258
1259 psfCSType = &pstAddIndication->sfActiveSet.cConvergenceSLTypes[nIndex];
1260 clsRule = &psfCSType->cCPacketClassificationRule;
1261
1262 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1263 DBG_LVL_ALL, " CCPacketClassificationRuleSI====>");
1264 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1265 DBG_LVL_ALL, " u8ClassifierRulePriority: 0x%X ",
1266 clsRule->u8ClassifierRulePriority);
1267 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1268 DBG_LVL_ALL, " u8IPTypeOfServiceLength: 0x%X ",
1269 clsRule->u8IPTypeOfServiceLength);
1270 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1271 DBG_LVL_ALL,
1272 " u8IPTypeOfService[3]: 0x%X ,0x%X ,0x%X ",
1273 clsRule->u8IPTypeOfService[0],
1274 clsRule->u8IPTypeOfService[1],
1275 clsRule->u8IPTypeOfService[2]);
1276
1277 for (uiLoopIndex = 0; uiLoopIndex < 1; uiLoopIndex++)
1278 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1279 DBG_LVL_ALL,
1280 " u8Protocol: 0x%X ",
1281 clsRule->u8Protocol);
1282
1283 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1284 DBG_LVL_ALL,
1285 "u8IPMaskedSourceAddressLength: 0x%X ",
1286 clsRule->u8IPMaskedSourceAddressLength);
1287
1288 for (uiLoopIndex = 0; uiLoopIndex < 32; uiLoopIndex++)
1289 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1290 DBG_LVL_ALL,
1291 "u8IPMaskedSourceAddress[32]: 0x%X ",
1292 clsRule->u8IPMaskedSourceAddress[uiLoopIndex]);
1293
1294 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1295 DBG_LVL_ALL,
1296 "u8IPDestinationAddressLength: 0x%02X ",
1297 clsRule->u8IPDestinationAddressLength);
1298
1299 for (uiLoopIndex = 0; uiLoopIndex < 32; uiLoopIndex++)
1300 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1301 DBG_LVL_ALL,
1302 " u8IPDestinationAddress[32]:0x%X ",
1303 clsRule->u8IPDestinationAddress[uiLoopIndex]);
1304
1305 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1306 DBG_LVL_ALL,
1307 " u8ProtocolSourcePortRangeLength: 0x%X ",
1308 clsRule->u8ProtocolSourcePortRangeLength);
1309
1310 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1311 DBG_LVL_ALL,
1312 " u8ProtocolSourcePortRange[4]: 0x%X ,0x%X ,0x%X ,0x%X ",
1313 clsRule->u8ProtocolSourcePortRange[0],
1314 clsRule->u8ProtocolSourcePortRange[1],
1315 clsRule->u8ProtocolSourcePortRange[2],
1316 clsRule->u8ProtocolSourcePortRange[3]);
1317
1318 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1319 DBG_LVL_ALL,
1320 " u8ProtocolDestPortRangeLength: 0x%X ",
1321 clsRule->u8ProtocolDestPortRangeLength);
1322 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1323 DBG_LVL_ALL,
1324 " u8ProtocolDestPortRange[4]: 0x%X ,0x%X ,0x%X ,0x%X ",
1325 clsRule->u8ProtocolDestPortRange[0],
1326 clsRule->u8ProtocolDestPortRange[1],
1327 clsRule->u8ProtocolDestPortRange[2],
1328 clsRule->u8ProtocolDestPortRange[3]);
1329
1330 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1331 DBG_LVL_ALL,
1332 " u8EthernetDestMacAddressLength: 0x%X ",
1333 clsRule->u8EthernetDestMacAddressLength);
1334 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1335 DBG_LVL_ALL,
1336 " u8EthernetDestMacAddress[6]: 0x%X ,0x%X ,0x%X ,0x%X ,0x%X ,0x%X",
1337 clsRule->u8EthernetDestMacAddress[0],
1338 clsRule->u8EthernetDestMacAddress[1],
1339 clsRule->u8EthernetDestMacAddress[2],
1340 clsRule->u8EthernetDestMacAddress[3],
1341 clsRule->u8EthernetDestMacAddress[4],
1342 clsRule->u8EthernetDestMacAddress[5]);
1343
1344 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1345 DBG_LVL_ALL,
1346 " u8EthernetSourceMACAddressLength: 0x%X ",
1347 clsRule->u8EthernetDestMacAddressLength);
1348 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1349 DBG_LVL_ALL,
1350 "u8EthernetSourceMACAddress[6]: 0x%X ,0x%X ,0x%X ,0x%X ,0x%X ,0x%X",
1351 clsRule->u8EthernetSourceMACAddress[0],
1352 clsRule->u8EthernetSourceMACAddress[1],
1353 clsRule->u8EthernetSourceMACAddress[2],
1354 clsRule->u8EthernetSourceMACAddress[3],
1355 clsRule->u8EthernetSourceMACAddress[4],
1356 clsRule->u8EthernetSourceMACAddress[5]);
1357
1358 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1359 DBG_LVL_ALL, " u8EthertypeLength: 0x%X ",
1360 clsRule->u8EthertypeLength);
1361 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1362 DBG_LVL_ALL,
1363 " u8Ethertype[3]: 0x%X ,0x%X ,0x%X ",
1364 clsRule->u8Ethertype[0],
1365 clsRule->u8Ethertype[1],
1366 clsRule->u8Ethertype[2]);
1367 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1368 DBG_LVL_ALL, " u16UserPriority: 0x%X ",
1369 clsRule->u16UserPriority);
1370 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1371 DBG_LVL_ALL, " u16VLANID: 0x%X ",
1372 clsRule->u16VLANID);
1373 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1374 DBG_LVL_ALL, " u8AssociatedPHSI: 0x%X ",
1375 clsRule->u8AssociatedPHSI);
1376 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1377 DBG_LVL_ALL,
1378 " u16PacketClassificationRuleIndex:0x%X ",
1379 clsRule->u16PacketClassificationRuleIndex);
1380
1381 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1382 DBG_LVL_ALL,
1383 " u8VendorSpecificClassifierParamLength:0x%X ",
1384 clsRule->u8VendorSpecificClassifierParamLength);
1385 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1386 DBG_LVL_ALL,
1387 " u8VendorSpecificClassifierParam[1]:0x%X ",
1388 clsRule->u8VendorSpecificClassifierParam[0]);
1389#ifdef VERSION_D5
1390 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1391 DBG_LVL_ALL, " u8IPv6FlowLableLength: 0x%X ",
1392 clsRule->u8IPv6FlowLableLength);
1393 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL,
1394 DBG_LVL_ALL,
1395 " u8IPv6FlowLable[6]: 0x%X ,0x%X ,0x%X ,0x%X ,0x%X ,0x%X ",
1396 clsRule->u8IPv6FlowLable[0],
1397 clsRule->u8IPv6FlowLable[1],
1398 clsRule->u8IPv6FlowLable[2],
1399 clsRule->u8IPv6FlowLable[3],
1400 clsRule->u8IPv6FlowLable[4],
1401 clsRule->u8IPv6FlowLable[5]);
1402#endif
1403 }
1404
1405 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_CONTROL, DBG_LVL_ALL,
1406 " bValid: 0x%X", pstAddIndication->sfActiveSet.bValid);
1407}
1408
1409static inline ULONG RestoreSFParam(struct bcm_mini_adapter *Adapter,
1410 ULONG ulAddrSFParamSet, PUCHAR pucDestBuffer)
1411{
1412 UINT nBytesToRead = sizeof(struct bcm_connect_mgr_params);
1413
1414 if (ulAddrSFParamSet == 0 || NULL == pucDestBuffer) {
1415 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1416 "Got Param address as 0!!");
1417 return 0;
1418 }
1419 ulAddrSFParamSet = ntohl(ulAddrSFParamSet);
1420
1421 /* Read out the SF Param Set At the indicated Location */
1422 if (rdm(Adapter, ulAddrSFParamSet, (PUCHAR)pucDestBuffer, nBytesToRead) < 0)
1423 return STATUS_FAILURE;
1424
1425 return 1;
1426}
1427
1428static ULONG StoreSFParam(struct bcm_mini_adapter *Adapter, PUCHAR pucSrcBuffer,
1429 ULONG ulAddrSFParamSet)
1430{
1431 UINT nBytesToWrite = sizeof(struct bcm_connect_mgr_params);
1432 int ret = 0;
1433
1434 if (ulAddrSFParamSet == 0 || NULL == pucSrcBuffer)
1435 return 0;
1436
1437 ret = wrm(Adapter, ulAddrSFParamSet, (u8 *)pucSrcBuffer, nBytesToWrite);
1438 if (ret < 0) {
1439 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1440 "%s:%d WRM failed", __func__, __LINE__);
1441 return ret;
1442 }
1443 return 1;
1444}
1445
1446ULONG StoreCmControlResponseMessage(struct bcm_mini_adapter *Adapter,
1447 PVOID pvBuffer, UINT *puBufferLength)
1448{
1449 struct bcm_add_indication_alt *pstAddIndicationAlt = NULL;
1450 struct bcm_add_indication *pstAddIndication = NULL;
1451 struct bcm_del_request *pstDeletionRequest;
1452 UINT uiSearchRuleIndex;
1453 ULONG ulSFID;
1454
1455 pstAddIndicationAlt = pvBuffer;
1456
1457 /*
1458 * In case of DSD Req By MS, we should immediately delete this SF so that
1459 * we can stop the further classifying the pkt for this SF.
1460 */
1461 if (pstAddIndicationAlt->u8Type == DSD_REQ) {
1462 pstDeletionRequest = pvBuffer;
1463
1464 ulSFID = ntohl(pstDeletionRequest->u32SFID);
1465 uiSearchRuleIndex = SearchSfid(Adapter, ulSFID);
1466
1467 if (uiSearchRuleIndex < NO_OF_QUEUES) {
1468 deleteSFBySfid(Adapter, uiSearchRuleIndex);
1469 Adapter->u32TotalDSD++;
1470 }
1471 return 1;
1472 }
1473
1474 if ((pstAddIndicationAlt->u8Type == DSD_RSP) ||
1475 (pstAddIndicationAlt->u8Type == DSD_ACK)) {
1476 /* No Special handling send the message as it is */
1477 return 1;
1478 }
1479 /* For DSA_REQ, only up to "psfAuthorizedSet" parameter should be accessed by driver! */
1480
1481 pstAddIndication = kmalloc(sizeof(struct bcm_add_indication),
1482 GFP_KERNEL);
1483 if (pstAddIndication == NULL)
1484 return 0;
1485
1486 /* AUTHORIZED SET */
1487 pstAddIndication->psfAuthorizedSet = (struct bcm_connect_mgr_params *)
1488 GetNextTargetBufferLocation(Adapter,
1489 pstAddIndicationAlt->u16TID);
1490 if (!pstAddIndication->psfAuthorizedSet) {
1491 kfree(pstAddIndication);
1492 return 0;
1493 }
1494
1495 if (StoreSFParam(Adapter, (PUCHAR)&pstAddIndicationAlt->sfAuthorizedSet,
1496 (ULONG)pstAddIndication->psfAuthorizedSet) != 1) {
1497 kfree(pstAddIndication);
1498 return 0;
1499 }
1500
1501 /* this can't possibly be right */
1502 pstAddIndication->psfAuthorizedSet =
1503 (struct bcm_connect_mgr_params *) ntohl(
1504 (ULONG)pstAddIndication->psfAuthorizedSet);
1505
1506 if (pstAddIndicationAlt->u8Type == DSA_REQ) {
1507 struct bcm_add_request AddRequest;
1508
1509 AddRequest.u8Type = pstAddIndicationAlt->u8Type;
1510 AddRequest.eConnectionDir = pstAddIndicationAlt->u8Direction;
1511 AddRequest.u16TID = pstAddIndicationAlt->u16TID;
1512 AddRequest.u16CID = pstAddIndicationAlt->u16CID;
1513 AddRequest.u16VCID = pstAddIndicationAlt->u16VCID;
1514 AddRequest.psfParameterSet = pstAddIndication->psfAuthorizedSet;
1515 (*puBufferLength) = sizeof(struct bcm_add_request);
1516 memcpy(pvBuffer, &AddRequest, sizeof(struct bcm_add_request));
1517 kfree(pstAddIndication);
1518 return 1;
1519 }
1520
1521 /* Since it's not DSA_REQ, we can access all field in pstAddIndicationAlt */
1522 /* We need to extract the structure from the buffer and pack it differently */
1523
1524 pstAddIndication->u8Type = pstAddIndicationAlt->u8Type;
1525 pstAddIndication->eConnectionDir = pstAddIndicationAlt->u8Direction;
1526 pstAddIndication->u16TID = pstAddIndicationAlt->u16TID;
1527 pstAddIndication->u16CID = pstAddIndicationAlt->u16CID;
1528 pstAddIndication->u16VCID = pstAddIndicationAlt->u16VCID;
1529 pstAddIndication->u8CC = pstAddIndicationAlt->u8CC;
1530
1531 /* ADMITTED SET */
1532 pstAddIndication->psfAdmittedSet = (struct bcm_connect_mgr_params *)
1533 GetNextTargetBufferLocation(Adapter,
1534 pstAddIndicationAlt->u16TID);
1535 if (!pstAddIndication->psfAdmittedSet) {
1536 kfree(pstAddIndication);
1537 return 0;
1538 }
1539 if (StoreSFParam(Adapter, (PUCHAR)&pstAddIndicationAlt->sfAdmittedSet,
1540 (ULONG)pstAddIndication->psfAdmittedSet) != 1) {
1541 kfree(pstAddIndication);
1542 return 0;
1543 }
1544
1545 pstAddIndication->psfAdmittedSet =
1546 (struct bcm_connect_mgr_params *) ntohl(
1547 (ULONG) pstAddIndication->psfAdmittedSet);
1548
1549 /* ACTIVE SET */
1550 pstAddIndication->psfActiveSet = (struct bcm_connect_mgr_params *)
1551 GetNextTargetBufferLocation(Adapter,
1552 pstAddIndicationAlt->u16TID);
1553 if (!pstAddIndication->psfActiveSet) {
1554 kfree(pstAddIndication);
1555 return 0;
1556 }
1557 if (StoreSFParam(Adapter, (PUCHAR)&pstAddIndicationAlt->sfActiveSet,
1558 (ULONG)pstAddIndication->psfActiveSet) != 1) {
1559 kfree(pstAddIndication);
1560 return 0;
1561 }
1562
1563 pstAddIndication->psfActiveSet =
1564 (struct bcm_connect_mgr_params *) ntohl(
1565 (ULONG)pstAddIndication->psfActiveSet);
1566
1567 (*puBufferLength) = sizeof(struct bcm_add_indication);
1568 *(struct bcm_add_indication *)pvBuffer = *pstAddIndication;
1569 kfree(pstAddIndication);
1570 return 1;
1571}
1572
1573static inline struct bcm_add_indication_alt
1574*RestoreCmControlResponseMessage(register struct bcm_mini_adapter *Adapter,
1575 register PVOID pvBuffer)
1576{
1577 ULONG ulStatus = 0;
1578 struct bcm_add_indication *pstAddIndication = NULL;
1579 struct bcm_add_indication_alt *pstAddIndicationDest = NULL;
1580
1581 pstAddIndication = pvBuffer;
1582 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1583 "=====>");
1584 if ((pstAddIndication->u8Type == DSD_REQ) ||
1585 (pstAddIndication->u8Type == DSD_RSP) ||
1586 (pstAddIndication->u8Type == DSD_ACK))
1587 return pvBuffer;
1588
1589 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1590 "Inside RestoreCmControlResponseMessage ");
1591 /*
1592 * Need to Allocate memory to contain the SUPER Large structures
1593 * Our driver can't create these structures on Stack :(
1594 */
1595 pstAddIndicationDest = kmalloc(sizeof(struct bcm_add_indication_alt),
1596 GFP_KERNEL);
1597
1598 if (pstAddIndicationDest) {
1599 memset(pstAddIndicationDest, 0,
1600 sizeof(struct bcm_add_indication_alt));
1601 } else {
1602 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG,
1603 DBG_LVL_ALL,
1604 "Failed to allocate memory for SF Add Indication Structure ");
1605 return NULL;
1606 }
1607 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1608 "AddIndication-u8Type : 0x%X",
1609 pstAddIndication->u8Type);
1610 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1611 "AddIndication-u8Direction : 0x%X",
1612 pstAddIndication->eConnectionDir);
1613 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1614 "AddIndication-u8TID : 0x%X",
1615 ntohs(pstAddIndication->u16TID));
1616 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1617 "AddIndication-u8CID : 0x%X",
1618 ntohs(pstAddIndication->u16CID));
1619 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1620 "AddIndication-u16VCID : 0x%X",
1621 ntohs(pstAddIndication->u16VCID));
1622 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1623 "AddIndication-autorized set loc : %p",
1624 pstAddIndication->psfAuthorizedSet);
1625 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1626 "AddIndication-admitted set loc : %p",
1627 pstAddIndication->psfAdmittedSet);
1628 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1629 "AddIndication-Active set loc : %p",
1630 pstAddIndication->psfActiveSet);
1631
1632 pstAddIndicationDest->u8Type = pstAddIndication->u8Type;
1633 pstAddIndicationDest->u8Direction = pstAddIndication->eConnectionDir;
1634 pstAddIndicationDest->u16TID = pstAddIndication->u16TID;
1635 pstAddIndicationDest->u16CID = pstAddIndication->u16CID;
1636 pstAddIndicationDest->u16VCID = pstAddIndication->u16VCID;
1637 pstAddIndicationDest->u8CC = pstAddIndication->u8CC;
1638
1639 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1640 "Restoring Active Set ");
1641 ulStatus = RestoreSFParam(Adapter,
1642 (ULONG)pstAddIndication->psfActiveSet,
1643 (PUCHAR)&pstAddIndicationDest->sfActiveSet);
1644 if (ulStatus != 1)
1645 goto failed_restore_sf_param;
1646
1647 if (pstAddIndicationDest->sfActiveSet.u8TotalClassifiers > MAX_CLASSIFIERS_IN_SF)
1648 pstAddIndicationDest->sfActiveSet.u8TotalClassifiers =
1649 MAX_CLASSIFIERS_IN_SF;
1650
1651 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1652 "Restoring Admitted Set ");
1653 ulStatus = RestoreSFParam(Adapter,
1654 (ULONG)pstAddIndication->psfAdmittedSet,
1655 (PUCHAR)&pstAddIndicationDest->sfAdmittedSet);
1656 if (ulStatus != 1)
1657 goto failed_restore_sf_param;
1658
1659 if (pstAddIndicationDest->sfAdmittedSet.u8TotalClassifiers > MAX_CLASSIFIERS_IN_SF)
1660 pstAddIndicationDest->sfAdmittedSet.u8TotalClassifiers =
1661 MAX_CLASSIFIERS_IN_SF;
1662
1663 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1664 "Restoring Authorized Set ");
1665 ulStatus = RestoreSFParam(Adapter,
1666 (ULONG)pstAddIndication->psfAuthorizedSet,
1667 (PUCHAR)&pstAddIndicationDest->sfAuthorizedSet);
1668 if (ulStatus != 1)
1669 goto failed_restore_sf_param;
1670
1671 if (pstAddIndicationDest->sfAuthorizedSet.u8TotalClassifiers > MAX_CLASSIFIERS_IN_SF)
1672 pstAddIndicationDest->sfAuthorizedSet.u8TotalClassifiers =
1673 MAX_CLASSIFIERS_IN_SF;
1674
1675 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1676 "Dumping the whole raw packet");
1677 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1678 "============================================================");
1679 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1680 " pstAddIndicationDest->sfActiveSet size %zx %p",
1681 sizeof(*pstAddIndicationDest), pstAddIndicationDest);
1682 /* BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_OTHERS, CONN_MSG,
1683 * DBG_LVL_ALL, (unsigned char *)pstAddIndicationDest,
1684 * sizeof(*pstAddIndicationDest));
1685 */
1686 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1687 "============================================================");
1688 return pstAddIndicationDest;
1689failed_restore_sf_param:
1690 kfree(pstAddIndicationDest);
1691 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1692 "<=====");
1693 return NULL;
1694}
1695
1696ULONG SetUpTargetDsxBuffers(struct bcm_mini_adapter *Adapter)
1697{
1698 ULONG ulTargetDsxBuffersBase = 0;
1699 ULONG ulCntTargetBuffers;
1700 ULONG i;
1701 int Status;
1702
1703 if (!Adapter) {
1704 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1705 "Adapter was NULL!!!");
1706 return 0;
1707 }
1708
1709 if (Adapter->astTargetDsxBuffer[0].ulTargetDsxBuffer)
1710 return 1;
1711
1712 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1713 "Size of Each DSX Buffer(Also size of connection manager parameters): %zx ",
1714 sizeof(struct bcm_connect_mgr_params));
1715 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1716 "Reading DSX buffer From Target location %x ",
1717 DSX_MESSAGE_EXCHANGE_BUFFER);
1718
1719 Status = rdmalt(Adapter, DSX_MESSAGE_EXCHANGE_BUFFER,
1720 (PUINT)&ulTargetDsxBuffersBase, sizeof(UINT));
1721 if (Status < 0) {
1722 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1723 "RDM failed!!");
1724 return 0;
1725 }
1726
1727 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1728 "Base Address Of DSX Target Buffer : 0x%lx",
1729 ulTargetDsxBuffersBase);
1730 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1731 "Tgt Buffer is Now %lx :", ulTargetDsxBuffersBase);
1732 ulCntTargetBuffers = DSX_MESSAGE_EXCHANGE_BUFFER_SIZE /
1733 sizeof(struct bcm_connect_mgr_params);
1734
1735 Adapter->ulTotalTargetBuffersAvailable =
1736 ulCntTargetBuffers > MAX_TARGET_DSX_BUFFERS ?
1737 MAX_TARGET_DSX_BUFFERS : ulCntTargetBuffers;
1738
1739 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
1740 " Total Target DSX Buffer setup %lx ",
1741 Adapter->ulTotalTargetBuffersAvailable);
1742
1743 for (i = 0; i < Adapter->ulTotalTargetBuffersAvailable; i++) {
1744 Adapter->astTargetDsxBuffer[i].ulTargetDsxBuffer = ulTargetDsxBuffersBase;
1745 Adapter->astTargetDsxBuffer[i].valid = 1;
1746 Adapter->astTargetDsxBuffer[i].tid = 0;
1747 ulTargetDsxBuffersBase += sizeof(struct bcm_connect_mgr_params);
1748 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, " Target DSX Buffer %lx setup at 0x%lx",
1749 i, Adapter->astTargetDsxBuffer[i].ulTargetDsxBuffer);
1750 }
1751 Adapter->ulCurrentTargetBuffer = 0;
1752 Adapter->ulFreeTargetBufferCnt = Adapter->ulTotalTargetBuffersAvailable;
1753 return 1;
1754}
1755
1756static ULONG GetNextTargetBufferLocation(struct bcm_mini_adapter *Adapter,
1757 B_UINT16 tid)
1758{
1759 ULONG dsx_buf;
1760 ULONG idx, max_try;
1761
1762 if ((Adapter->ulTotalTargetBuffersAvailable == 0)
1763 || (Adapter->ulFreeTargetBufferCnt == 0)) {
1764 ClearTargetDSXBuffer(Adapter, tid, false);
1765 return 0;
1766 }
1767
1768 idx = Adapter->ulCurrentTargetBuffer;
1769 max_try = Adapter->ulTotalTargetBuffersAvailable;
1770 while ((max_try) && (Adapter->astTargetDsxBuffer[idx].valid != 1)) {
1771 idx = (idx+1) % Adapter->ulTotalTargetBuffersAvailable;
1772 max_try--;
1773 }
1774
1775 if (max_try == 0) {
1776 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1777 "\n GetNextTargetBufferLocation : Error No Free Target DSX Buffers FreeCnt : %lx ",
1778 Adapter->ulFreeTargetBufferCnt);
1779 ClearTargetDSXBuffer(Adapter, tid, false);
1780 return 0;
1781 }
1782
1783 dsx_buf = Adapter->astTargetDsxBuffer[idx].ulTargetDsxBuffer;
1784 Adapter->astTargetDsxBuffer[idx].valid = 0;
1785 Adapter->astTargetDsxBuffer[idx].tid = tid;
1786 Adapter->ulFreeTargetBufferCnt--;
1787 idx = (idx+1)%Adapter->ulTotalTargetBuffersAvailable;
1788 Adapter->ulCurrentTargetBuffer = idx;
1789 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1790 "GetNextTargetBufferLocation :Returning address %lx tid %d\n",
1791 dsx_buf, tid);
1792
1793 return dsx_buf;
1794}
1795
1796int AllocAdapterDsxBuffer(struct bcm_mini_adapter *Adapter)
1797{
1798 /*
1799 * Need to Allocate memory to contain the SUPER Large structures
1800 * Our driver can't create these structures on Stack
1801 */
1802 Adapter->caDsxReqResp = kmalloc(sizeof(struct bcm_add_indication_alt)
1803 + LEADER_SIZE, GFP_KERNEL);
1804 if (!Adapter->caDsxReqResp)
1805 return -ENOMEM;
1806
1807 return 0;
1808}
1809
1810int FreeAdapterDsxBuffer(struct bcm_mini_adapter *Adapter)
1811{
1812 kfree(Adapter->caDsxReqResp);
1813 return 0;
1814}
1815
1816/*
1817 * @ingroup ctrl_pkt_functions
1818 * This routinue would process the Control responses
1819 * for the Connection Management.
1820 * @return - Queue index for the free SFID else returns Invalid Index.
1821 */
1822bool CmControlResponseMessage(struct bcm_mini_adapter *Adapter, /* <Pointer to the Adapter structure */
1823 PVOID pvBuffer /* Starting Address of the Buffer, that contains the AddIndication Data */)
1824{
1825 struct bcm_connect_mgr_params *psfLocalSet = NULL;
1826 struct bcm_add_indication_alt *pstAddIndication = NULL;
1827 struct bcm_change_indication *pstChangeIndication = NULL;
1828 struct bcm_leader *pLeader = NULL;
1829 INT uiSearchRuleIndex = 0;
1830 ULONG ulSFID;
1831
1832 /*
1833 * Otherwise the message contains a target address from where we need to
1834 * read out the rest of the service flow param structure
1835 */
1836 pstAddIndication = RestoreCmControlResponseMessage(Adapter, pvBuffer);
1837 if (pstAddIndication == NULL) {
1838 ClearTargetDSXBuffer(Adapter, ((struct bcm_add_indication *)pvBuffer)->u16TID, false);
1839 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Error in restoring Service Flow param structure from DSx message");
1840 return false;
1841 }
1842
1843 DumpCmControlPacket(pstAddIndication);
1844 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "====>");
1845 pLeader = (struct bcm_leader *)Adapter->caDsxReqResp;
1846
1847 pLeader->Status = CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ;
1848 pLeader->Vcid = 0;
1849
1850 ClearTargetDSXBuffer(Adapter, pstAddIndication->u16TID, false);
1851 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "### TID RECEIVED %d\n", pstAddIndication->u16TID);
1852 switch (pstAddIndication->u8Type) {
1853 case DSA_REQ:
1854 pLeader->PLength = sizeof(struct bcm_add_indication_alt);
1855 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "Sending DSA Response....\n");
1856 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "SENDING DSA RESPONSE TO MAC %d", pLeader->PLength);
1857 *((struct bcm_add_indication_alt *)&(Adapter->caDsxReqResp[LEADER_SIZE]))
1858 = *pstAddIndication;
1859 ((struct bcm_add_indication_alt *)&(Adapter->caDsxReqResp[LEADER_SIZE]))->u8Type = DSA_RSP;
1860
1861 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, " VCID = %x", ntohs(pstAddIndication->u16VCID));
1862 CopyBufferToControlPacket(Adapter, (PVOID)Adapter->caDsxReqResp);
1863 kfree(pstAddIndication);
1864 break;
1865 case DSA_RSP:
1866 pLeader->PLength = sizeof(struct bcm_add_indication_alt);
1867 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "SENDING DSA ACK TO MAC %d",
1868 pLeader->PLength);
1869 *((struct bcm_add_indication_alt *)&(Adapter->caDsxReqResp[LEADER_SIZE]))
1870 = *pstAddIndication;
1871 ((struct bcm_add_indication_alt *)&(Adapter->caDsxReqResp[LEADER_SIZE]))->u8Type = DSA_ACK;
1872 /* FALLTHROUGH */
1873 case DSA_ACK:
1874 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "VCID:0x%X",
1875 ntohs(pstAddIndication->u16VCID));
1876 uiSearchRuleIndex = SearchFreeSfid(Adapter);
1877 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "uiSearchRuleIndex:0x%X ",
1878 uiSearchRuleIndex);
1879 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "Direction:0x%X ",
1880 pstAddIndication->u8Direction);
1881 if (uiSearchRuleIndex < NO_OF_QUEUES) {
1882 Adapter->PackInfo[uiSearchRuleIndex].ucDirection =
1883 pstAddIndication->u8Direction;
1884 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "bValid:0x%X ",
1885 pstAddIndication->sfActiveSet.bValid);
1886 if (pstAddIndication->sfActiveSet.bValid == TRUE)
1887 Adapter->PackInfo[uiSearchRuleIndex].bActiveSet = TRUE;
1888
1889 if (pstAddIndication->sfAuthorizedSet.bValid == TRUE)
1890 Adapter->PackInfo[uiSearchRuleIndex].bAuthorizedSet = TRUE;
1891
1892 if (pstAddIndication->sfAdmittedSet.bValid == TRUE)
1893 Adapter->PackInfo[uiSearchRuleIndex].bAdmittedSet = TRUE;
1894
1895 if (pstAddIndication->sfActiveSet.bValid == false) {
1896 Adapter->PackInfo[uiSearchRuleIndex].bActive = false;
1897 Adapter->PackInfo[uiSearchRuleIndex].bActivateRequestSent = false;
1898 if (pstAddIndication->sfAdmittedSet.bValid)
1899 psfLocalSet = &pstAddIndication->sfAdmittedSet;
1900 else if (pstAddIndication->sfAuthorizedSet.bValid)
1901 psfLocalSet = &pstAddIndication->sfAuthorizedSet;
1902 } else {
1903 psfLocalSet = &pstAddIndication->sfActiveSet;
1904 Adapter->PackInfo[uiSearchRuleIndex].bActive = TRUE;
1905 }
1906
1907 if (!psfLocalSet) {
1908 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "No set is valid\n");
1909 Adapter->PackInfo[uiSearchRuleIndex].bActive = false;
1910 Adapter->PackInfo[uiSearchRuleIndex].bValid = false;
1911 Adapter->PackInfo[uiSearchRuleIndex].usVCID_Value = 0;
1912 kfree(pstAddIndication);
1913 } else if (psfLocalSet->bValid && (pstAddIndication->u8CC == 0)) {
1914 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "DSA ACK");
1915 Adapter->PackInfo[uiSearchRuleIndex].usVCID_Value = ntohs(pstAddIndication->u16VCID);
1916 Adapter->PackInfo[uiSearchRuleIndex].usCID = ntohs(pstAddIndication->u16CID);
1917
1918 if (UPLINK_DIR == pstAddIndication->u8Direction)
1919 atomic_set(&Adapter->PackInfo[uiSearchRuleIndex].uiPerSFTxResourceCount, DEFAULT_PERSFCOUNT);
1920
1921 CopyToAdapter(Adapter, psfLocalSet, uiSearchRuleIndex, DSA_ACK, pstAddIndication);
1922 /* don't free pstAddIndication */
1923
1924 /* Inside CopyToAdapter, Sorting of all the SFs take place.
1925 * Hence any access to the newly added SF through uiSearchRuleIndex is invalid.
1926 * SHOULD BE STRICTLY AVOIDED.
1927 */
1928 /* *(PULONG)(((PUCHAR)pvBuffer)+1)=psfLocalSet->u32SFID; */
1929 memcpy((((PUCHAR)pvBuffer)+1), &psfLocalSet->u32SFID, 4);
1930
1931 if (pstAddIndication->sfActiveSet.bValid == TRUE) {
1932 if (UPLINK_DIR == pstAddIndication->u8Direction) {
1933 if (!Adapter->LinkUpStatus) {
1934 netif_carrier_on(Adapter->dev);
1935 netif_start_queue(Adapter->dev);
1936 Adapter->LinkUpStatus = 1;
1937 if (netif_msg_link(Adapter))
1938 pr_info(PFX "%s: link up\n", Adapter->dev->name);
1939 atomic_set(&Adapter->TxPktAvail, 1);
1940 wake_up(&Adapter->tx_packet_wait_queue);
1941 Adapter->liTimeSinceLastNetEntry = get_seconds();
1942 }
1943 }
1944 }
1945 } else {
1946 Adapter->PackInfo[uiSearchRuleIndex].bActive = false;
1947 Adapter->PackInfo[uiSearchRuleIndex].bValid = false;
1948 Adapter->PackInfo[uiSearchRuleIndex].usVCID_Value = 0;
1949 kfree(pstAddIndication);
1950 }
1951 } else {
1952 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "DSA ACK did not get valid SFID");
1953 kfree(pstAddIndication);
1954 return false;
1955 }
1956 break;
1957 case DSC_REQ:
1958 pLeader->PLength = sizeof(struct bcm_change_indication);
1959 pstChangeIndication = (struct bcm_change_indication *)pstAddIndication;
1960 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "SENDING DSC RESPONSE TO MAC %d", pLeader->PLength);
1961
1962 *((struct bcm_change_indication *)&(Adapter->caDsxReqResp[LEADER_SIZE])) = *pstChangeIndication;
1963 ((struct bcm_change_indication *)&(Adapter->caDsxReqResp[LEADER_SIZE]))->u8Type = DSC_RSP;
1964
1965 CopyBufferToControlPacket(Adapter, (PVOID)Adapter->caDsxReqResp);
1966 kfree(pstAddIndication);
1967 break;
1968 case DSC_RSP:
1969 pLeader->PLength = sizeof(struct bcm_change_indication);
1970 pstChangeIndication = (struct bcm_change_indication *)pstAddIndication;
1971 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "SENDING DSC ACK TO MAC %d", pLeader->PLength);
1972 *((struct bcm_change_indication *)&(Adapter->caDsxReqResp[LEADER_SIZE])) = *pstChangeIndication;
1973 ((struct bcm_change_indication *)&(Adapter->caDsxReqResp[LEADER_SIZE]))->u8Type = DSC_ACK;
1974 /* FALLTHROUGH */
1975 case DSC_ACK:
1976 pstChangeIndication = (struct bcm_change_indication *)pstAddIndication;
1977 uiSearchRuleIndex = SearchSfid(Adapter, ntohl(pstChangeIndication->sfActiveSet.u32SFID));
1978 if (uiSearchRuleIndex > NO_OF_QUEUES-1)
1979 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "SF doesn't exist for which DSC_ACK is received");
1980
1981 if (uiSearchRuleIndex < NO_OF_QUEUES) {
1982 Adapter->PackInfo[uiSearchRuleIndex].ucDirection = pstChangeIndication->u8Direction;
1983 if (pstChangeIndication->sfActiveSet.bValid == TRUE)
1984 Adapter->PackInfo[uiSearchRuleIndex].bActiveSet = TRUE;
1985
1986 if (pstChangeIndication->sfAuthorizedSet.bValid == TRUE)
1987 Adapter->PackInfo[uiSearchRuleIndex].bAuthorizedSet = TRUE;
1988
1989 if (pstChangeIndication->sfAdmittedSet.bValid == TRUE)
1990 Adapter->PackInfo[uiSearchRuleIndex].bAdmittedSet = TRUE;
1991
1992 if (pstChangeIndication->sfActiveSet.bValid == false) {
1993 Adapter->PackInfo[uiSearchRuleIndex].bActive = false;
1994 Adapter->PackInfo[uiSearchRuleIndex].bActivateRequestSent = false;
1995
1996 if (pstChangeIndication->sfAdmittedSet.bValid)
1997 psfLocalSet = &pstChangeIndication->sfAdmittedSet;
1998 else if (pstChangeIndication->sfAuthorizedSet.bValid)
1999 psfLocalSet = &pstChangeIndication->sfAuthorizedSet;
2000 } else {
2001 psfLocalSet = &pstChangeIndication->sfActiveSet;
2002 Adapter->PackInfo[uiSearchRuleIndex].bActive = TRUE;
2003 }
2004
2005 if (!psfLocalSet) {
2006 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "No set is valid\n");
2007 Adapter->PackInfo[uiSearchRuleIndex].bActive = false;
2008 Adapter->PackInfo[uiSearchRuleIndex].bValid = false;
2009 Adapter->PackInfo[uiSearchRuleIndex].usVCID_Value = 0;
2010 kfree(pstAddIndication);
2011 } else if (psfLocalSet->bValid && (pstChangeIndication->u8CC == 0)) {
2012 Adapter->PackInfo[uiSearchRuleIndex].usVCID_Value = ntohs(pstChangeIndication->u16VCID);
2013 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "CC field is %d bvalid = %d\n",
2014 pstChangeIndication->u8CC, psfLocalSet->bValid);
2015 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "VCID= %d\n", ntohs(pstChangeIndication->u16VCID));
2016 Adapter->PackInfo[uiSearchRuleIndex].usCID = ntohs(pstChangeIndication->u16CID);
2017 CopyToAdapter(Adapter, psfLocalSet, uiSearchRuleIndex, DSC_ACK, pstAddIndication);
2018
2019 *(PULONG)(((PUCHAR)pvBuffer)+1) = psfLocalSet->u32SFID;
2020 } else if (pstChangeIndication->u8CC == 6) {
2021 deleteSFBySfid(Adapter, uiSearchRuleIndex);
2022 kfree(pstAddIndication);
2023 }
2024 } else {
2025 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "DSC ACK did not get valid SFID");
2026 kfree(pstAddIndication);
2027 return false;
2028 }
2029 break;
2030 case DSD_REQ:
2031 pLeader->PLength = sizeof(struct bcm_del_indication);
2032 *((struct bcm_del_indication *)&(Adapter->caDsxReqResp[LEADER_SIZE])) = *((struct bcm_del_indication *)pstAddIndication);
2033
2034 ulSFID = ntohl(((struct bcm_del_indication *)pstAddIndication)->u32SFID);
2035 uiSearchRuleIndex = SearchSfid(Adapter, ulSFID);
2036 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "DSD - Removing connection %x", uiSearchRuleIndex);
2037
2038 if (uiSearchRuleIndex < NO_OF_QUEUES) {
2039 /* Delete All Classifiers Associated with this SFID */
2040 deleteSFBySfid(Adapter, uiSearchRuleIndex);
2041 Adapter->u32TotalDSD++;
2042 }
2043
2044 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "SENDING DSD RESPONSE TO MAC");
2045 ((struct bcm_del_indication *)&(Adapter->caDsxReqResp[LEADER_SIZE]))->u8Type = DSD_RSP;
2046 CopyBufferToControlPacket(Adapter, (PVOID)Adapter->caDsxReqResp);
2047 /* FALLTHROUGH */
2048 case DSD_RSP:
2049 /* Do nothing as SF has already got Deleted */
2050 break;
2051 case DSD_ACK:
2052 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL, "DSD ACK Rcd, let App handle it\n");
2053 break;
2054 default:
2055 kfree(pstAddIndication);
2056 return false;
2057 }
2058 return TRUE;
2059}
2060
2061int get_dsx_sf_data_to_application(struct bcm_mini_adapter *Adapter,
2062 UINT uiSFId, void __user *user_buffer)
2063{
2064 int status = 0;
2065 struct bcm_packet_info *psSfInfo = NULL;
2066
2067 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
2068 "status =%d", status);
2069 status = SearchSfid(Adapter, uiSFId);
2070 if (status >= NO_OF_QUEUES) {
2071 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
2072 "SFID %d not present in queue !!!", uiSFId);
2073 return -EINVAL;
2074 }
2075 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
2076 "status =%d", status);
2077 psSfInfo = &Adapter->PackInfo[status];
2078 if (psSfInfo->pstSFIndication
2079 && copy_to_user(user_buffer, psSfInfo->pstSFIndication,
2080 sizeof(struct bcm_add_indication_alt))) {
2081 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
2082 "copy to user failed SFID %d, present in queue !!!",
2083 uiSFId);
2084 status = -EFAULT;
2085 return status;
2086 }
2087 return STATUS_SUCCESS;
2088}
2089
2090VOID OverrideServiceFlowParams(struct bcm_mini_adapter *Adapter,
2091 PUINT puiBuffer)
2092{
2093 B_UINT32 u32NumofSFsinMsg = ntohl(*(puiBuffer + 1));
2094 struct bcm_stim_sfhostnotify *pHostInfo = NULL;
2095 UINT uiSearchRuleIndex = 0;
2096 ULONG ulSFID = 0;
2097
2098 puiBuffer += 2;
2099 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
2100 "u32NumofSFsinMsg: 0x%x\n", u32NumofSFsinMsg);
2101
2102 while (u32NumofSFsinMsg != 0 && u32NumofSFsinMsg < NO_OF_QUEUES) {
2103 u32NumofSFsinMsg--;
2104 pHostInfo = (struct bcm_stim_sfhostnotify *)puiBuffer;
2105 puiBuffer = (PUINT)(pHostInfo + 1);
2106
2107 ulSFID = ntohl(pHostInfo->SFID);
2108 uiSearchRuleIndex = SearchSfid(Adapter, ulSFID);
2109 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
2110 "SFID: 0x%lx\n", ulSFID);
2111
2112 if (uiSearchRuleIndex >= NO_OF_QUEUES
2113 || uiSearchRuleIndex == HiPriority) {
2114 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG,
2115 DBG_LVL_ALL,
2116 "The SFID <%lx> doesn't exist in host entry or is Invalid\n",
2117 ulSFID);
2118 continue;
2119 }
2120
2121 if (pHostInfo->RetainSF == false) {
2122 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG,
2123 DBG_LVL_ALL, "Going to Delete SF");
2124 deleteSFBySfid(Adapter, uiSearchRuleIndex);
2125 } else {
2126 struct bcm_packet_info *packinfo =
2127 &Adapter->PackInfo[uiSearchRuleIndex];
2128
2129 packinfo->usVCID_Value = ntohs(pHostInfo->VCID);
2130 packinfo->usCID = ntohs(pHostInfo->newCID);
2131 packinfo->bActive = false;
2132
2133 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG,
2134 DBG_LVL_ALL,
2135 "pHostInfo->QoSParamSet: 0x%x\n",
2136 pHostInfo->QoSParamSet);
2137
2138 if (pHostInfo->QoSParamSet & 0x1)
2139 packinfo->bAuthorizedSet = TRUE;
2140 if (pHostInfo->QoSParamSet & 0x2)
2141 packinfo->bAdmittedSet = TRUE;
2142 if (pHostInfo->QoSParamSet & 0x4) {
2143 packinfo->bActiveSet = TRUE;
2144 packinfo->bActive = TRUE;
2145 }
2146 }
2147 }
2148}
2149
2150static void restore_endianess_of_pstClassifierEntry(
2151 struct bcm_classifier_rule *pstClassifierEntry,
2152 enum bcm_ipaddr_context eIpAddrContext)
2153{
2154 int i;
2155 union u_ip_address *stSrc = &pstClassifierEntry->stSrcIpAddress;
2156 union u_ip_address *stDest = &pstClassifierEntry->stDestIpAddress;
2157
2158 for (i = 0; i < MAX_IP_RANGE_LENGTH * 4; i++) {
2159 if (eIpAddrContext == eSrcIpAddress) {
2160 stSrc->ulIpv6Addr[i] = ntohl(stSrc->ulIpv6Addr[i]);
2161 stSrc->ulIpv6Mask[i] = ntohl(stSrc->ulIpv6Mask[i]);
2162 } else if (eIpAddrContext == eDestIpAddress) {
2163 stDest->ulIpv6Addr[i] = ntohl(stDest->ulIpv6Addr[i]);
2164 stDest->ulIpv6Mask[i] = ntohl(stDest->ulIpv6Mask[i]);
2165 }
2166 }
2167}
2168
2169static void apply_phs_rule_to_all_classifiers(
2170 register struct bcm_mini_adapter *Adapter, /* <Pointer to the Adapter structure */
2171 register UINT uiSearchRuleIndex, /* <Index of Queue, to which this data belongs */
2172 USHORT uVCID,
2173 struct bcm_phs_rule *sPhsRule,
2174 struct bcm_phs_rules *cPhsRule,
2175 struct bcm_add_indication_alt *pstAddIndication)
2176{
2177 unsigned int uiClassifierIndex = 0;
2178 struct bcm_classifier_rule *curr_classifier = NULL;
2179
2180 if (pstAddIndication->u8Direction == UPLINK_DIR) {
2181 for (uiClassifierIndex = 0; uiClassifierIndex < MAX_CLASSIFIERS; uiClassifierIndex++) {
2182 curr_classifier =
2183 &Adapter->astClassifierTable[uiClassifierIndex];
2184 if ((curr_classifier->bUsed) &&
2185 (curr_classifier->ulSFID == Adapter->PackInfo[uiSearchRuleIndex].ulSFID) &&
2186 (curr_classifier->u8AssociatedPHSI == cPhsRule->u8PHSI)) {
2187 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG, DBG_LVL_ALL,
2188 "Adding PHS Rule For Classifier: 0x%x cPhsRule.u8PHSI: 0x%x\n",
2189 curr_classifier->uiClassifierRuleIndex,
2190 cPhsRule->u8PHSI);
2191 /* Update The PHS Rule for this classifier as Associated PHSI id defined */
2192
2193 /* Copy the PHS Rule */
2194 sPhsRule->u8PHSI = cPhsRule->u8PHSI;
2195 sPhsRule->u8PHSFLength = cPhsRule->u8PHSFLength;
2196 sPhsRule->u8PHSMLength = cPhsRule->u8PHSMLength;
2197 sPhsRule->u8PHSS = cPhsRule->u8PHSS;
2198 sPhsRule->u8PHSV = cPhsRule->u8PHSV;
2199 memcpy(sPhsRule->u8PHSF, cPhsRule->u8PHSF, MAX_PHS_LENGTHS);
2200 memcpy(sPhsRule->u8PHSM, cPhsRule->u8PHSM, MAX_PHS_LENGTHS);
2201 sPhsRule->u8RefCnt = 0;
2202 sPhsRule->bUnclassifiedPHSRule = false;
2203 sPhsRule->PHSModifiedBytes = 0;
2204 sPhsRule->PHSModifiedNumPackets = 0;
2205 sPhsRule->PHSErrorNumPackets = 0;
2206
2207 /* bPHSRuleAssociated = TRUE; */
2208 /* Store The PHS Rule for this classifier */
2209
2210 PhsUpdateClassifierRule(
2211 &Adapter->stBCMPhsContext,
2212 uVCID,
2213 curr_classifier->uiClassifierRuleIndex,
2214 sPhsRule,
2215 curr_classifier->u8AssociatedPHSI);
2216
2217 /* Update PHS Rule For the Classifier */
2218 if (sPhsRule->u8PHSI) {
2219 curr_classifier->u32PHSRuleID = sPhsRule->u8PHSI;
2220 memcpy(&curr_classifier->sPhsRule, sPhsRule, sizeof(struct bcm_phs_rule));
2221 }
2222 }
2223 }
2224 } else {
2225 /* Error PHS Rule specified in signaling could not be applied to any classifier */
2226
2227 /* Copy the PHS Rule */
2228 sPhsRule->u8PHSI = cPhsRule->u8PHSI;
2229 sPhsRule->u8PHSFLength = cPhsRule->u8PHSFLength;
2230 sPhsRule->u8PHSMLength = cPhsRule->u8PHSMLength;
2231 sPhsRule->u8PHSS = cPhsRule->u8PHSS;
2232 sPhsRule->u8PHSV = cPhsRule->u8PHSV;
2233 memcpy(sPhsRule->u8PHSF, cPhsRule->u8PHSF, MAX_PHS_LENGTHS);
2234 memcpy(sPhsRule->u8PHSM, cPhsRule->u8PHSM, MAX_PHS_LENGTHS);
2235 sPhsRule->u8RefCnt = 0;
2236 sPhsRule->bUnclassifiedPHSRule = TRUE;
2237 sPhsRule->PHSModifiedBytes = 0;
2238 sPhsRule->PHSModifiedNumPackets = 0;
2239 sPhsRule->PHSErrorNumPackets = 0;
2240 /* Store The PHS Rule for this classifier */
2241
2242 /*
2243 * Passing the argument u8PHSI instead of clsid. Because for DL with no classifier rule,
2244 * clsid will be zero hence we can't have multiple PHS rules for the same SF.
2245 * To support multiple PHS rule, passing u8PHSI.
2246 */
2247 PhsUpdateClassifierRule(
2248 &Adapter->stBCMPhsContext,
2249 uVCID,
2250 sPhsRule->u8PHSI,
2251 sPhsRule,
2252 sPhsRule->u8PHSI);
2253 }
2254}
diff --git a/drivers/staging/bcm/CmHost.h b/drivers/staging/bcm/CmHost.h
deleted file mode 100644
index 0887d3f49e2f..000000000000
--- a/drivers/staging/bcm/CmHost.h
+++ /dev/null
@@ -1,62 +0,0 @@
1/***************************************************************************
2 * (c) Beceem Communications Inc.
3 * All Rights Reserved
4 *
5 * file : CmHost.h
6 * author: Rajeev Tirumala
7 * date : September 8 , 2006
8 * brief : Definitions for Connection Management Requests structure
9 * which we will use to setup our connection structures.Its high
10 * time we had a header file for CmHost.cpp to isolate the way
11 * f/w sends DSx messages and the way we interpret them in code.
12 * Revision History
13 *
14 * Date Author Version Description
15 * 08-Sep-06 Rajeev 0.1 Created
16 ***************************************************************************/
17#ifndef _CM_HOST_H
18#define _CM_HOST_H
19
20#pragma once
21#pragma pack(push, 4)
22
23#define DSX_MESSAGE_EXCHANGE_BUFFER 0xBF60AC84 /* This contains the pointer */
24#define DSX_MESSAGE_EXCHANGE_BUFFER_SIZE 72000 /* 24 K Bytes */
25
26struct bcm_add_indication_alt {
27 u8 u8Type;
28 u8 u8Direction;
29 u16 u16TID;
30 u16 u16CID;
31 u16 u16VCID;
32 struct bcm_connect_mgr_params sfAuthorizedSet;
33 struct bcm_connect_mgr_params sfAdmittedSet;
34 struct bcm_connect_mgr_params sfActiveSet;
35 u8 u8CC; /* < Confirmation Code */
36 u8 u8Padd;
37 u16 u16Padd;
38};
39
40struct bcm_change_indication {
41 u8 u8Type;
42 u8 u8Direction;
43 u16 u16TID;
44 u16 u16CID;
45 u16 u16VCID;
46 struct bcm_connect_mgr_params sfAuthorizedSet;
47 struct bcm_connect_mgr_params sfAdmittedSet;
48 struct bcm_connect_mgr_params sfActiveSet;
49 u8 u8CC; /* < Confirmation Code */
50 u8 u8Padd;
51 u16 u16Padd;
52};
53
54unsigned long StoreCmControlResponseMessage(struct bcm_mini_adapter *Adapter, void *pvBuffer, unsigned int *puBufferLength);
55int AllocAdapterDsxBuffer(struct bcm_mini_adapter *Adapter);
56int FreeAdapterDsxBuffer(struct bcm_mini_adapter *Adapter);
57unsigned long SetUpTargetDsxBuffers(struct bcm_mini_adapter *Adapter);
58bool CmControlResponseMessage(struct bcm_mini_adapter *Adapter, void *pvBuffer);
59
60#pragma pack(pop)
61
62#endif
diff --git a/drivers/staging/bcm/DDRInit.c b/drivers/staging/bcm/DDRInit.c
deleted file mode 100644
index 4226c931cd45..000000000000
--- a/drivers/staging/bcm/DDRInit.c
+++ /dev/null
@@ -1,1355 +0,0 @@
1#include "headers.h"
2
3
4
5#define DDR_DUMP_INTERNAL_DEVICE_MEMORY 0xBFC02B00
6#define MIPS_CLOCK_REG 0x0f000820
7
8/* DDR INIT-133Mhz */
9#define T3_SKIP_CLOCK_PROGRAM_DUMP_133MHZ 12 /* index for 0x0F007000 */
10static struct bcm_ddr_setting asT3_DDRSetting133MHz[] = {
11 /* DPLL Clock Setting */
12 {0x0F000800, 0x00007212},
13 {0x0f000820, 0x07F13FFF},
14 {0x0f000810, 0x00000F95},
15 {0x0f000860, 0x00000000},
16 {0x0f000880, 0x000003DD},
17 /* Changed source for X-bar and MIPS clock to APLL */
18 {0x0f000840, 0x0FFF1B00},
19 {0x0f000870, 0x00000002},
20 {0x0F00a044, 0x1fffffff},
21 {0x0F00a040, 0x1f000000},
22 {0x0F00a084, 0x1Cffffff},
23 {0x0F00a080, 0x1C000000},
24 {0x0F00a04C, 0x0000000C},
25 /* Memcontroller Default values */
26 {0x0F007000, 0x00010001},
27 {0x0F007004, 0x01010100},
28 {0x0F007008, 0x01000001},
29 {0x0F00700c, 0x00000000},
30 {0x0F007010, 0x01000000},
31 {0x0F007014, 0x01000100},
32 {0x0F007018, 0x01000000},
33 {0x0F00701c, 0x01020001},
34 {0x0F007020, 0x04030107},
35 {0x0F007024, 0x02000007},
36 {0x0F007028, 0x02020202},
37 {0x0F00702c, 0x0206060a},
38 {0x0F007030, 0x05000000},
39 {0x0F007034, 0x00000003},
40 {0x0F007038, 0x110a0200},
41 {0x0F00703C, 0x02101010},
42 {0x0F007040, 0x45751200},
43 {0x0F007044, 0x110a0d00},
44 {0x0F007048, 0x081b0306},
45 {0x0F00704c, 0x00000000},
46 {0x0F007050, 0x0000001c},
47 {0x0F007054, 0x00000000},
48 {0x0F007058, 0x00000000},
49 {0x0F00705c, 0x00000000},
50 {0x0F007060, 0x0010246c},
51 {0x0F007064, 0x00000010},
52 {0x0F007068, 0x00000000},
53 {0x0F00706c, 0x00000001},
54 {0x0F007070, 0x00007000},
55 {0x0F007074, 0x00000000},
56 {0x0F007078, 0x00000000},
57 {0x0F00707C, 0x00000000},
58 {0x0F007080, 0x00000000},
59 {0x0F007084, 0x00000000},
60 /* Enable BW improvement within memory controller */
61 {0x0F007094, 0x00000104},
62 /* Enable 2 ports within X-bar */
63 {0x0F00A000, 0x00000016},
64 /* Enable start bit within memory controller */
65 {0x0F007018, 0x01010000}
66};
67/* 80Mhz */
68#define T3_SKIP_CLOCK_PROGRAM_DUMP_80MHZ 10 /* index for 0x0F007000 */
69static struct bcm_ddr_setting asT3_DDRSetting80MHz[] = {
70 /* DPLL Clock Setting */
71 {0x0f000810, 0x00000F95},
72 {0x0f000820, 0x07f1ffff},
73 {0x0f000860, 0x00000000},
74 {0x0f000880, 0x000003DD},
75 {0x0F00a044, 0x1fffffff},
76 {0x0F00a040, 0x1f000000},
77 {0x0F00a084, 0x1Cffffff},
78 {0x0F00a080, 0x1C000000},
79 {0x0F00a000, 0x00000016},
80 {0x0F00a04C, 0x0000000C},
81 /* Memcontroller Default values */
82 {0x0F007000, 0x00010001},
83 {0x0F007004, 0x01000000},
84 {0x0F007008, 0x01000001},
85 {0x0F00700c, 0x00000000},
86 {0x0F007010, 0x01000000},
87 {0x0F007014, 0x01000100},
88 {0x0F007018, 0x01000000},
89 {0x0F00701c, 0x01020000},
90 {0x0F007020, 0x04020107},
91 {0x0F007024, 0x00000007},
92 {0x0F007028, 0x02020201},
93 {0x0F00702c, 0x0204040a},
94 {0x0F007030, 0x04000000},
95 {0x0F007034, 0x00000002},
96 {0x0F007038, 0x1F060200},
97 {0x0F00703C, 0x1C22221F},
98 {0x0F007040, 0x8A006600},
99 {0x0F007044, 0x221a0800},
100 {0x0F007048, 0x02690204},
101 {0x0F00704c, 0x00000000},
102 {0x0F007050, 0x0000001c},
103 {0x0F007054, 0x00000000},
104 {0x0F007058, 0x00000000},
105 {0x0F00705c, 0x00000000},
106 {0x0F007060, 0x000A15D6},
107 {0x0F007064, 0x0000000A},
108 {0x0F007068, 0x00000000},
109 {0x0F00706c, 0x00000001},
110 {0x0F007070, 0x00004000},
111 {0x0F007074, 0x00000000},
112 {0x0F007078, 0x00000000},
113 {0x0F00707C, 0x00000000},
114 {0x0F007080, 0x00000000},
115 {0x0F007084, 0x00000000},
116 {0x0F007094, 0x00000104},
117 /* Enable start bit within memory controller */
118 {0x0F007018, 0x01010000}
119};
120/* 100Mhz */
121#define T3_SKIP_CLOCK_PROGRAM_DUMP_100MHZ 13 /* index for 0x0F007000 */
122static struct bcm_ddr_setting asT3_DDRSetting100MHz[] = {
123 /* DPLL Clock Setting */
124 {0x0F000800, 0x00007008},
125 {0x0f000810, 0x00000F95},
126 {0x0f000820, 0x07F13E3F},
127 {0x0f000860, 0x00000000},
128 {0x0f000880, 0x000003DD},
129 /* Changed source for X-bar and MIPS clock to APLL */
130 {0x0f000840, 0x0FFF1B00},
131 {0x0f000870, 0x00000002},
132 {0x0F00a044, 0x1fffffff},
133 {0x0F00a040, 0x1f000000},
134 {0x0F00a084, 0x1Cffffff},
135 {0x0F00a080, 0x1C000000},
136 {0x0F00a04C, 0x0000000C},
137 /* Enable 2 ports within X-bar */
138 {0x0F00A000, 0x00000016},
139 /* Memcontroller Default values */
140 {0x0F007000, 0x00010001},
141 {0x0F007004, 0x01010100},
142 {0x0F007008, 0x01000001},
143 {0x0F00700c, 0x00000000},
144 {0x0F007010, 0x01000000},
145 {0x0F007014, 0x01000100},
146 {0x0F007018, 0x01000000},
147 {0x0F00701c, 0x01020001},
148 {0x0F007020, 0x04020107},
149 {0x0F007024, 0x00000007},
150 {0x0F007028, 0x01020201},
151 {0x0F00702c, 0x0204040A},
152 {0x0F007030, 0x06000000},
153 {0x0F007034, 0x00000004},
154 {0x0F007038, 0x20080200},
155 {0x0F00703C, 0x02030320},
156 {0x0F007040, 0x6E7F1200},
157 {0x0F007044, 0x01190A00},
158 {0x0F007048, 0x06120305},
159 {0x0F00704c, 0x00000000},
160 {0x0F007050, 0x0000001C},
161 {0x0F007054, 0x00000000},
162 {0x0F007058, 0x00000000},
163 {0x0F00705c, 0x00000000},
164 {0x0F007060, 0x00082ED6},
165 {0x0F007064, 0x0000000A},
166 {0x0F007068, 0x00000000},
167 {0x0F00706c, 0x00000001},
168 {0x0F007070, 0x00005000},
169 {0x0F007074, 0x00000000},
170 {0x0F007078, 0x00000000},
171 {0x0F00707C, 0x00000000},
172 {0x0F007080, 0x00000000},
173 {0x0F007084, 0x00000000},
174 /* Enable BW improvement within memory controller */
175 {0x0F007094, 0x00000104},
176 /* Enable start bit within memory controller */
177 {0x0F007018, 0x01010000}
178};
179
180/* Net T3B DDR Settings
181 * DDR INIT-133Mhz
182 */
183static struct bcm_ddr_setting asDPLL_266MHZ[] = {
184 {0x0F000800, 0x00007212},
185 {0x0f000820, 0x07F13FFF},
186 {0x0f000810, 0x00000F95},
187 {0x0f000860, 0x00000000},
188 {0x0f000880, 0x000003DD},
189 /* Changed source for X-bar and MIPS clock to APLL */
190 {0x0f000840, 0x0FFF1B00},
191 {0x0f000870, 0x00000002}
192};
193
194#define T3B_SKIP_CLOCK_PROGRAM_DUMP_133MHZ 11 /* index for 0x0F007000 */
195static struct bcm_ddr_setting asT3B_DDRSetting133MHz[] = {
196 /* DPLL Clock Setting */
197 {0x0f000810, 0x00000F95},
198 {0x0f000810, 0x00000F95},
199 {0x0f000810, 0x00000F95},
200 {0x0f000820, 0x07F13652},
201 {0x0f000840, 0x0FFF0800},
202 /* Changed source for X-bar and MIPS clock to APLL */
203 {0x0f000880, 0x000003DD},
204 {0x0f000860, 0x00000000},
205 /* Changed source for X-bar and MIPS clock to APLL */
206 {0x0F00a044, 0x1fffffff},
207 {0x0F00a040, 0x1f000000},
208 {0x0F00a084, 0x1Cffffff},
209 {0x0F00a080, 0x1C000000},
210 /* Enable 2 ports within X-bar */
211 {0x0F00A000, 0x00000016},
212 /* Memcontroller Default values */
213 {0x0F007000, 0x00010001},
214 {0x0F007004, 0x01010100},
215 {0x0F007008, 0x01000001},
216 {0x0F00700c, 0x00000000},
217 {0x0F007010, 0x01000000},
218 {0x0F007014, 0x01000100},
219 {0x0F007018, 0x01000000},
220 {0x0F00701c, 0x01020001},
221 {0x0F007020, 0x04030107},
222 {0x0F007024, 0x02000007},
223 {0x0F007028, 0x02020202},
224 {0x0F00702c, 0x0206060a},
225 {0x0F007030, 0x05000000},
226 {0x0F007034, 0x00000003},
227 {0x0F007038, 0x130a0200},
228 {0x0F00703C, 0x02101012},
229 {0x0F007040, 0x457D1200},
230 {0x0F007044, 0x11130d00},
231 {0x0F007048, 0x040D0306},
232 {0x0F00704c, 0x00000000},
233 {0x0F007050, 0x0000001c},
234 {0x0F007054, 0x00000000},
235 {0x0F007058, 0x00000000},
236 {0x0F00705c, 0x00000000},
237 {0x0F007060, 0x0010246c},
238 {0x0F007064, 0x00000012},
239 {0x0F007068, 0x00000000},
240 {0x0F00706c, 0x00000001},
241 {0x0F007070, 0x00007000},
242 {0x0F007074, 0x00000000},
243 {0x0F007078, 0x00000000},
244 {0x0F00707C, 0x00000000},
245 {0x0F007080, 0x00000000},
246 {0x0F007084, 0x00000000},
247 /* Enable BW improvement within memory controller */
248 {0x0F007094, 0x00000104},
249 /* Enable start bit within memory controller */
250 {0x0F007018, 0x01010000},
251 };
252
253#define T3B_SKIP_CLOCK_PROGRAM_DUMP_80MHZ 9 /* index for 0x0F007000 */
254static struct bcm_ddr_setting asT3B_DDRSetting80MHz[] = {
255 /* DPLL Clock Setting */
256 {0x0f000810, 0x00000F95},
257 {0x0f000820, 0x07F13FFF},
258 {0x0f000840, 0x0FFF1F00},
259 {0x0f000880, 0x000003DD},
260 {0x0f000860, 0x00000000},
261
262 {0x0F00a044, 0x1fffffff},
263 {0x0F00a040, 0x1f000000},
264 {0x0F00a084, 0x1Cffffff},
265 {0x0F00a080, 0x1C000000},
266 {0x0F00a000, 0x00000016},
267 /* Memcontroller Default values */
268 {0x0F007000, 0x00010001},
269 {0x0F007004, 0x01000000},
270 {0x0F007008, 0x01000001},
271 {0x0F00700c, 0x00000000},
272 {0x0F007010, 0x01000000},
273 {0x0F007014, 0x01000100},
274 {0x0F007018, 0x01000000},
275 {0x0F00701c, 0x01020000},
276 {0x0F007020, 0x04020107},
277 {0x0F007024, 0x00000007},
278 {0x0F007028, 0x02020201},
279 {0x0F00702c, 0x0204040a},
280 {0x0F007030, 0x04000000},
281 {0x0F007034, 0x02000002},
282 {0x0F007038, 0x1F060202},
283 {0x0F00703C, 0x1C22221F},
284 {0x0F007040, 0x8A006600},
285 {0x0F007044, 0x221a0800},
286 {0x0F007048, 0x02690204},
287 {0x0F00704c, 0x00000000},
288 {0x0F007050, 0x0100001c},
289 {0x0F007054, 0x00000000},
290 {0x0F007058, 0x00000000},
291 {0x0F00705c, 0x00000000},
292 {0x0F007060, 0x000A15D6},
293 {0x0F007064, 0x0000000A},
294 {0x0F007068, 0x00000000},
295 {0x0F00706c, 0x00000001},
296 {0x0F007070, 0x00004000},
297 {0x0F007074, 0x00000000},
298 {0x0F007078, 0x00000000},
299 {0x0F00707C, 0x00000000},
300 {0x0F007080, 0x00000000},
301 {0x0F007084, 0x00000000},
302 {0x0F007094, 0x00000104},
303 /* Enable start bit within memory controller */
304 {0x0F007018, 0x01010000}
305};
306
307/* 100Mhz */
308#define T3B_SKIP_CLOCK_PROGRAM_DUMP_100MHZ 9 /* index for 0x0F007000 */
309static struct bcm_ddr_setting asT3B_DDRSetting100MHz[] = {
310 /* DPLL Clock Setting */
311 {0x0f000810, 0x00000F95},
312 {0x0f000820, 0x07F1369B},
313 {0x0f000840, 0x0FFF0800},
314 {0x0f000880, 0x000003DD},
315 {0x0f000860, 0x00000000},
316 {0x0F00a044, 0x1fffffff},
317 {0x0F00a040, 0x1f000000},
318 {0x0F00a084, 0x1Cffffff},
319 {0x0F00a080, 0x1C000000},
320 /* Enable 2 ports within X-bar */
321 {0x0F00A000, 0x00000016},
322 /* Memcontroller Default values */
323 {0x0F007000, 0x00010001},
324 {0x0F007004, 0x01010100},
325 {0x0F007008, 0x01000001},
326 {0x0F00700c, 0x00000000},
327 {0x0F007010, 0x01000000},
328 {0x0F007014, 0x01000100},
329 {0x0F007018, 0x01000000},
330 {0x0F00701c, 0x01020000},
331 {0x0F007020, 0x04020107},
332 {0x0F007024, 0x00000007},
333 {0x0F007028, 0x01020201},
334 {0x0F00702c, 0x0204040A},
335 {0x0F007030, 0x06000000},
336 {0x0F007034, 0x02000004},
337 {0x0F007038, 0x20080200},
338 {0x0F00703C, 0x02030320},
339 {0x0F007040, 0x6E7F1200},
340 {0x0F007044, 0x01190A00},
341 {0x0F007048, 0x06120305},
342 {0x0F00704c, 0x00000000},
343 {0x0F007050, 0x0100001C},
344 {0x0F007054, 0x00000000},
345 {0x0F007058, 0x00000000},
346 {0x0F00705c, 0x00000000},
347 {0x0F007060, 0x00082ED6},
348 {0x0F007064, 0x0000000A},
349 {0x0F007068, 0x00000000},
350 {0x0F00706c, 0x00000001},
351 {0x0F007070, 0x00005000},
352 {0x0F007074, 0x00000000},
353 {0x0F007078, 0x00000000},
354 {0x0F00707C, 0x00000000},
355 {0x0F007080, 0x00000000},
356 {0x0F007084, 0x00000000},
357 /* Enable BW improvement within memory controller */
358 {0x0F007094, 0x00000104},
359 /* Enable start bit within memory controller */
360 {0x0F007018, 0x01010000}
361};
362
363
364#define T3LP_SKIP_CLOCK_PROGRAM_DUMP_133MHZ 9 /* index for 0x0F007000 */
365static struct bcm_ddr_setting asT3LP_DDRSetting133MHz[] = {
366 /* DPLL Clock Setting */
367 {0x0f000820, 0x03F1365B},
368 {0x0f000810, 0x00002F95},
369 {0x0f000880, 0x000003DD},
370 /* Changed source for X-bar and MIPS clock to APLL */
371 {0x0f000840, 0x0FFF0000},
372 {0x0f000860, 0x00000000},
373 {0x0F00a044, 0x1fffffff},
374 {0x0F00a040, 0x1f000000},
375 {0x0F00a084, 0x1Cffffff},
376 {0x0F00a080, 0x1C000000},
377 {0x0F00A000, 0x00000016},
378 /* Memcontroller Default values */
379 {0x0F007000, 0x00010001},
380 {0x0F007004, 0x01010100},
381 {0x0F007008, 0x01000001},
382 {0x0F00700c, 0x00000000},
383 {0x0F007010, 0x01000000},
384 {0x0F007014, 0x01000100},
385 {0x0F007018, 0x01000000},
386 {0x0F00701c, 0x01020001},
387 {0x0F007020, 0x04030107},
388 {0x0F007024, 0x02000007},
389 {0x0F007028, 0x02020200},
390 {0x0F00702c, 0x0206060a},
391 {0x0F007030, 0x05000000},
392 {0x0F007034, 0x00000003},
393 {0x0F007038, 0x200a0200},
394 {0x0F00703C, 0x02101020},
395 {0x0F007040, 0x45711200},
396 {0x0F007044, 0x110D0D00},
397 {0x0F007048, 0x04080306},
398 {0x0F00704c, 0x00000000},
399 {0x0F007050, 0x0100001c},
400 {0x0F007054, 0x00000000},
401 {0x0F007058, 0x00000000},
402 {0x0F00705c, 0x00000000},
403 {0x0F007060, 0x0010245F},
404 {0x0F007064, 0x00000010},
405 {0x0F007068, 0x00000000},
406 {0x0F00706c, 0x00000001},
407 {0x0F007070, 0x00007000},
408 {0x0F007074, 0x00000000},
409 {0x0F007078, 0x00000000},
410 {0x0F00707C, 0x00000000},
411 {0x0F007080, 0x00000000},
412 {0x0F007084, 0x00000000},
413 {0x0F007088, 0x01000001},
414 {0x0F00708c, 0x00000101},
415 {0x0F007090, 0x00000000},
416 /* Enable BW improvement within memory controller */
417 {0x0F007094, 0x00040000},
418 {0x0F007098, 0x00000000},
419 {0x0F0070c8, 0x00000104},
420 /* Enable 2 ports within X-bar */
421 /* Enable start bit within memory controller */
422 {0x0F007018, 0x01010000}
423};
424
425#define T3LP_SKIP_CLOCK_PROGRAM_DUMP_100MHZ 11 /* index for 0x0F007000 */
426static struct bcm_ddr_setting asT3LP_DDRSetting100MHz[] = {
427 /* DPLL Clock Setting */
428 {0x0f000810, 0x00002F95},
429 {0x0f000820, 0x03F1369B},
430 {0x0f000840, 0x0fff0000},
431 {0x0f000860, 0x00000000},
432 {0x0f000880, 0x000003DD},
433 /* Changed source for X-bar and MIPS clock to APLL */
434 {0x0f000840, 0x0FFF0000},
435 {0x0F00a044, 0x1fffffff},
436 {0x0F00a040, 0x1f000000},
437 {0x0F00a084, 0x1Cffffff},
438 {0x0F00a080, 0x1C000000},
439 /* Memcontroller Default values */
440 {0x0F007000, 0x00010001},
441 {0x0F007004, 0x01010100},
442 {0x0F007008, 0x01000001},
443 {0x0F00700c, 0x00000000},
444 {0x0F007010, 0x01000000},
445 {0x0F007014, 0x01000100},
446 {0x0F007018, 0x01000000},
447 {0x0F00701c, 0x01020000},
448 {0x0F007020, 0x04020107},
449 {0x0F007024, 0x00000007},
450 {0x0F007028, 0x01020200},
451 {0x0F00702c, 0x0204040a},
452 {0x0F007030, 0x06000000},
453 {0x0F007034, 0x00000004},
454 {0x0F007038, 0x1F080200},
455 {0x0F00703C, 0x0203031F},
456 {0x0F007040, 0x6e001200},
457 {0x0F007044, 0x011a0a00},
458 {0x0F007048, 0x03000305},
459 {0x0F00704c, 0x00000000},
460 {0x0F007050, 0x0100001c},
461 {0x0F007054, 0x00000000},
462 {0x0F007058, 0x00000000},
463 {0x0F00705c, 0x00000000},
464 {0x0F007060, 0x00082ED6},
465 {0x0F007064, 0x0000000A},
466 {0x0F007068, 0x00000000},
467 {0x0F00706c, 0x00000001},
468 {0x0F007070, 0x00005000},
469 {0x0F007074, 0x00000000},
470 {0x0F007078, 0x00000000},
471 {0x0F00707C, 0x00000000},
472 {0x0F007080, 0x00000000},
473 {0x0F007084, 0x00000000},
474 {0x0F007088, 0x01000001},
475 {0x0F00708c, 0x00000101},
476 {0x0F007090, 0x00000000},
477 {0x0F007094, 0x00010000},
478 {0x0F007098, 0x00000000},
479 {0x0F0070C8, 0x00000104},
480 /* Enable 2 ports within X-bar */
481 {0x0F00A000, 0x00000016},
482 /* Enable start bit within memory controller */
483 {0x0F007018, 0x01010000}
484};
485
486#define T3LP_SKIP_CLOCK_PROGRAM_DUMP_80MHZ 9 /* index for 0x0F007000 */
487static struct bcm_ddr_setting asT3LP_DDRSetting80MHz[] = {
488 /* DPLL Clock Setting */
489 {0x0f000820, 0x07F13FFF},
490 {0x0f000810, 0x00002F95},
491 {0x0f000860, 0x00000000},
492 {0x0f000880, 0x000003DD},
493 {0x0f000840, 0x0FFF1F00},
494 {0x0F00a044, 0x1fffffff},
495 {0x0F00a040, 0x1f000000},
496 {0x0F00a084, 0x1Cffffff},
497 {0x0F00a080, 0x1C000000},
498 {0x0F00A000, 0x00000016},
499 {0x0f007000, 0x00010001},
500 {0x0f007004, 0x01000000},
501 {0x0f007008, 0x01000001},
502 {0x0f00700c, 0x00000000},
503 {0x0f007010, 0x01000000},
504 {0x0f007014, 0x01000100},
505 {0x0f007018, 0x01000000},
506 {0x0f00701c, 0x01020000},
507 {0x0f007020, 0x04020107},
508 {0x0f007024, 0x00000007},
509 {0x0f007028, 0x02020200},
510 {0x0f00702c, 0x0204040a},
511 {0x0f007030, 0x04000000},
512 {0x0f007034, 0x00000002},
513 {0x0f007038, 0x1d060200},
514 {0x0f00703c, 0x1c22221d},
515 {0x0f007040, 0x8A116600},
516 {0x0f007044, 0x222d0800},
517 {0x0f007048, 0x02690204},
518 {0x0f00704c, 0x00000000},
519 {0x0f007050, 0x0100001c},
520 {0x0f007054, 0x00000000},
521 {0x0f007058, 0x00000000},
522 {0x0f00705c, 0x00000000},
523 {0x0f007060, 0x000A15D6},
524 {0x0f007064, 0x0000000A},
525 {0x0f007068, 0x00000000},
526 {0x0f00706c, 0x00000001},
527 {0x0f007070, 0x00004000},
528 {0x0f007074, 0x00000000},
529 {0x0f007078, 0x00000000},
530 {0x0f00707c, 0x00000000},
531 {0x0f007080, 0x00000000},
532 {0x0f007084, 0x00000000},
533 {0x0f007088, 0x01000001},
534 {0x0f00708c, 0x00000101},
535 {0x0f007090, 0x00000000},
536 {0x0f007094, 0x00010000},
537 {0x0f007098, 0x00000000},
538 {0x0F0070C8, 0x00000104},
539 {0x0F007018, 0x01010000}
540};
541
542
543
544
545/* T3 LP-B (UMA-B) */
546
547#define T3LPB_SKIP_CLOCK_PROGRAM_DUMP_160MHZ 7 /* index for 0x0F007000 */
548static struct bcm_ddr_setting asT3LPB_DDRSetting160MHz[] = {
549 /* DPLL Clock Setting */
550 {0x0f000820, 0x03F137DB},
551 {0x0f000810, 0x01842795},
552 {0x0f000860, 0x00000000},
553 {0x0f000880, 0x000003DD},
554 {0x0f000840, 0x0FFF0400},
555 {0x0F00a044, 0x1fffffff},
556 {0x0F00a040, 0x1f000000},
557 {0x0f003050, 0x00000021}, /* this is flash/eeprom clock divisor which
558 * set the flash clock to 20 MHz */
559 {0x0F00a084, 0x1Cffffff}, /* Now dump from her in internal memory */
560 {0x0F00a080, 0x1C000000},
561 {0x0F00A000, 0x00000016},
562 {0x0f007000, 0x00010001},
563 {0x0f007004, 0x01000001},
564 {0x0f007008, 0x01000101},
565 {0x0f00700c, 0x00000000},
566 {0x0f007010, 0x01000100},
567 {0x0f007014, 0x01000100},
568 {0x0f007018, 0x01000000},
569 {0x0f00701c, 0x01020000},
570 {0x0f007020, 0x04030107},
571 {0x0f007024, 0x02000007},
572 {0x0f007028, 0x02020200},
573 {0x0f00702c, 0x0206060a},
574 {0x0f007030, 0x050d0d00},
575 {0x0f007034, 0x00000003},
576 {0x0f007038, 0x170a0200},
577 {0x0f00703c, 0x02101012},
578 {0x0f007040, 0x45161200},
579 {0x0f007044, 0x11250c00},
580 {0x0f007048, 0x04da0307},
581 {0x0f00704c, 0x00000000},
582 {0x0f007050, 0x0000001c},
583 {0x0f007054, 0x00000000},
584 {0x0f007058, 0x00000000},
585 {0x0f00705c, 0x00000000},
586 {0x0f007060, 0x00142bb6},
587 {0x0f007064, 0x20430014},
588 {0x0f007068, 0x00000000},
589 {0x0f00706c, 0x00000001},
590 {0x0f007070, 0x00009000},
591 {0x0f007074, 0x00000000},
592 {0x0f007078, 0x00000000},
593 {0x0f00707c, 0x00000000},
594 {0x0f007080, 0x00000000},
595 {0x0f007084, 0x00000000},
596 {0x0f007088, 0x01000001},
597 {0x0f00708c, 0x00000101},
598 {0x0f007090, 0x00000000},
599 {0x0f007094, 0x00040000},
600 {0x0f007098, 0x00000000},
601 {0x0F0070C8, 0x00000104},
602 {0x0F007018, 0x01010000}
603};
604
605
606#define T3LPB_SKIP_CLOCK_PROGRAM_DUMP_133MHZ 7 /* index for 0x0F007000 */
607static struct bcm_ddr_setting asT3LPB_DDRSetting133MHz[] = {
608 /* DPLL Clock Setting */
609 {0x0f000820, 0x03F1365B},
610 {0x0f000810, 0x00002F95},
611 {0x0f000880, 0x000003DD},
612 /* Changed source for X-bar and MIPS clock to APLL */
613 {0x0f000840, 0x0FFF0000},
614 {0x0f000860, 0x00000000},
615 {0x0F00a044, 0x1fffffff},
616 {0x0F00a040, 0x1f000000},
617 {0x0f003050, 0x00000021}, /* flash/eeprom clock divisor which
618 * set the flash clock to 20 MHz */
619 {0x0F00a084, 0x1Cffffff}, /* dump from here in internal memory */
620 {0x0F00a080, 0x1C000000},
621 {0x0F00A000, 0x00000016},
622 /* Memcontroller Default values */
623 {0x0F007000, 0x00010001},
624 {0x0F007004, 0x01010100},
625 {0x0F007008, 0x01000001},
626 {0x0F00700c, 0x00000000},
627 {0x0F007010, 0x01000000},
628 {0x0F007014, 0x01000100},
629 {0x0F007018, 0x01000000},
630 {0x0F00701c, 0x01020001},
631 {0x0F007020, 0x04030107},
632 {0x0F007024, 0x02000007},
633 {0x0F007028, 0x02020200},
634 {0x0F00702c, 0x0206060a},
635 {0x0F007030, 0x05000000},
636 {0x0F007034, 0x00000003},
637 {0x0F007038, 0x190a0200},
638 {0x0F00703C, 0x02101017},
639 {0x0F007040, 0x45171200},
640 {0x0F007044, 0x11290D00},
641 {0x0F007048, 0x04080306},
642 {0x0F00704c, 0x00000000},
643 {0x0F007050, 0x0100001c},
644 {0x0F007054, 0x00000000},
645 {0x0F007058, 0x00000000},
646 {0x0F00705c, 0x00000000},
647 {0x0F007060, 0x0010245F},
648 {0x0F007064, 0x00000010},
649 {0x0F007068, 0x00000000},
650 {0x0F00706c, 0x00000001},
651 {0x0F007070, 0x00007000},
652 {0x0F007074, 0x00000000},
653 {0x0F007078, 0x00000000},
654 {0x0F00707C, 0x00000000},
655 {0x0F007080, 0x00000000},
656 {0x0F007084, 0x00000000},
657 {0x0F007088, 0x01000001},
658 {0x0F00708c, 0x00000101},
659 {0x0F007090, 0x00000000},
660 /* Enable BW improvement within memory controller */
661 {0x0F007094, 0x00040000},
662 {0x0F007098, 0x00000000},
663 {0x0F0070c8, 0x00000104},
664 /* Enable 2 ports within X-bar */
665 /* Enable start bit within memory controller */
666 {0x0F007018, 0x01010000}
667};
668
669#define T3LPB_SKIP_CLOCK_PROGRAM_DUMP_100MHZ 8 /* index for 0x0F007000 */
670static struct bcm_ddr_setting asT3LPB_DDRSetting100MHz[] = {
671 /* DPLL Clock Setting */
672 {0x0f000810, 0x00002F95},
673 {0x0f000820, 0x03F1369B},
674 {0x0f000840, 0x0fff0000},
675 {0x0f000860, 0x00000000},
676 {0x0f000880, 0x000003DD},
677 /* Changed source for X-bar and MIPS clock to APLL */
678 {0x0f000840, 0x0FFF0000},
679 {0x0F00a044, 0x1fffffff},
680 {0x0F00a040, 0x1f000000},
681 {0x0f003050, 0x00000021}, /* flash/eeprom clock divisor which
682 * set the flash clock to 20 MHz */
683 {0x0F00a084, 0x1Cffffff}, /* dump from here in internal memory */
684 {0x0F00a080, 0x1C000000},
685 /* Memcontroller Default values */
686 {0x0F007000, 0x00010001},
687 {0x0F007004, 0x01010100},
688 {0x0F007008, 0x01000001},
689 {0x0F00700c, 0x00000000},
690 {0x0F007010, 0x01000000},
691 {0x0F007014, 0x01000100},
692 {0x0F007018, 0x01000000},
693 {0x0F00701c, 0x01020000},
694 {0x0F007020, 0x04020107},
695 {0x0F007024, 0x00000007},
696 {0x0F007028, 0x01020200},
697 {0x0F00702c, 0x0204040a},
698 {0x0F007030, 0x06000000},
699 {0x0F007034, 0x00000004},
700 {0x0F007038, 0x1F080200},
701 {0x0F00703C, 0x0203031F},
702 {0x0F007040, 0x6e001200},
703 {0x0F007044, 0x011a0a00},
704 {0x0F007048, 0x03000305},
705 {0x0F00704c, 0x00000000},
706 {0x0F007050, 0x0100001c},
707 {0x0F007054, 0x00000000},
708 {0x0F007058, 0x00000000},
709 {0x0F00705c, 0x00000000},
710 {0x0F007060, 0x00082ED6},
711 {0x0F007064, 0x0000000A},
712 {0x0F007068, 0x00000000},
713 {0x0F00706c, 0x00000001},
714 {0x0F007070, 0x00005000},
715 {0x0F007074, 0x00000000},
716 {0x0F007078, 0x00000000},
717 {0x0F00707C, 0x00000000},
718 {0x0F007080, 0x00000000},
719 {0x0F007084, 0x00000000},
720 {0x0F007088, 0x01000001},
721 {0x0F00708c, 0x00000101},
722 {0x0F007090, 0x00000000},
723 {0x0F007094, 0x00010000},
724 {0x0F007098, 0x00000000},
725 {0x0F0070C8, 0x00000104},
726 /* Enable 2 ports within X-bar */
727 {0x0F00A000, 0x00000016},
728 /* Enable start bit within memory controller */
729 {0x0F007018, 0x01010000}
730};
731
732#define T3LPB_SKIP_CLOCK_PROGRAM_DUMP_80MHZ 7 /* index for 0x0F007000 */
733static struct bcm_ddr_setting asT3LPB_DDRSetting80MHz[] = {
734 /* DPLL Clock Setting */
735 {0x0f000820, 0x07F13FFF},
736 {0x0f000810, 0x00002F95},
737 {0x0f000860, 0x00000000},
738 {0x0f000880, 0x000003DD},
739 {0x0f000840, 0x0FFF1F00},
740 {0x0F00a044, 0x1fffffff},
741 {0x0F00a040, 0x1f000000},
742 {0x0f003050, 0x00000021}, /* flash/eeprom clock divisor
743 * which set the flash clock to 20 MHz */
744 {0x0F00a084, 0x1Cffffff}, /* dump from here in internal memory */
745 {0x0F00a080, 0x1C000000},
746 {0x0F00A000, 0x00000016},
747 {0x0f007000, 0x00010001},
748 {0x0f007004, 0x01000000},
749 {0x0f007008, 0x01000001},
750 {0x0f00700c, 0x00000000},
751 {0x0f007010, 0x01000000},
752 {0x0f007014, 0x01000100},
753 {0x0f007018, 0x01000000},
754 {0x0f00701c, 0x01020000},
755 {0x0f007020, 0x04020107},
756 {0x0f007024, 0x00000007},
757 {0x0f007028, 0x02020200},
758 {0x0f00702c, 0x0204040a},
759 {0x0f007030, 0x04000000},
760 {0x0f007034, 0x00000002},
761 {0x0f007038, 0x1d060200},
762 {0x0f00703c, 0x1c22221d},
763 {0x0f007040, 0x8A116600},
764 {0x0f007044, 0x222d0800},
765 {0x0f007048, 0x02690204},
766 {0x0f00704c, 0x00000000},
767 {0x0f007050, 0x0100001c},
768 {0x0f007054, 0x00000000},
769 {0x0f007058, 0x00000000},
770 {0x0f00705c, 0x00000000},
771 {0x0f007060, 0x000A15D6},
772 {0x0f007064, 0x0000000A},
773 {0x0f007068, 0x00000000},
774 {0x0f00706c, 0x00000001},
775 {0x0f007070, 0x00004000},
776 {0x0f007074, 0x00000000},
777 {0x0f007078, 0x00000000},
778 {0x0f00707c, 0x00000000},
779 {0x0f007080, 0x00000000},
780 {0x0f007084, 0x00000000},
781 {0x0f007088, 0x01000001},
782 {0x0f00708c, 0x00000101},
783 {0x0f007090, 0x00000000},
784 {0x0f007094, 0x00010000},
785 {0x0f007098, 0x00000000},
786 {0x0F0070C8, 0x00000104},
787 {0x0F007018, 0x01010000}
788};
789
790
791int ddr_init(struct bcm_mini_adapter *Adapter)
792{
793 struct bcm_ddr_setting *psDDRSetting = NULL;
794 ULONG RegCount = 0;
795 UINT value = 0;
796 UINT uiResetValue = 0;
797 UINT uiClockSetting = 0;
798 int retval = STATUS_SUCCESS;
799
800 switch (Adapter->chip_id) {
801 case 0xbece3200:
802 switch (Adapter->DDRSetting) {
803 case DDR_80_MHZ:
804 psDDRSetting = asT3LP_DDRSetting80MHz;
805 RegCount = (sizeof(asT3LP_DDRSetting80MHz) /
806 sizeof(struct bcm_ddr_setting));
807 break;
808 case DDR_100_MHZ:
809 psDDRSetting = asT3LP_DDRSetting100MHz;
810 RegCount = (sizeof(asT3LP_DDRSetting100MHz) /
811 sizeof(struct bcm_ddr_setting));
812 break;
813 case DDR_133_MHZ:
814 psDDRSetting = asT3LP_DDRSetting133MHz;
815 RegCount = (sizeof(asT3LP_DDRSetting133MHz) /
816 sizeof(struct bcm_ddr_setting));
817 if (Adapter->bMipsConfig == MIPS_200_MHZ)
818 uiClockSetting = 0x03F13652;
819 else
820 uiClockSetting = 0x03F1365B;
821 break;
822 default:
823 return -EINVAL;
824 }
825
826 break;
827 case T3LPB:
828 case BCS220_2:
829 case BCS220_2BC:
830 case BCS250_BC:
831 case BCS220_3:
832 /* Set bit 2 and bit 6 to 1 for BBIC 2mA drive
833 * (please check current value and additionally set these bits)
834 */
835 if ((Adapter->chip_id != BCS220_2) &&
836 (Adapter->chip_id != BCS220_2BC) &&
837 (Adapter->chip_id != BCS220_3)) {
838 retval = rdmalt(Adapter, (UINT)0x0f000830, &uiResetValue,
839 sizeof(uiResetValue));
840 if (retval < 0) {
841 BCM_DEBUG_PRINT(Adapter, CMHOST, RDM, DBG_LVL_ALL,
842 "%s:%d RDM failed\n",
843 __func__, __LINE__);
844 return retval;
845 }
846 uiResetValue |= 0x44;
847 retval = wrmalt(Adapter, (UINT)0x0f000830, &uiResetValue,
848 sizeof(uiResetValue));
849 if (retval < 0) {
850 BCM_DEBUG_PRINT(Adapter, CMHOST, RDM, DBG_LVL_ALL,
851 "%s:%d RDM failed\n",
852 __func__, __LINE__);
853 return retval;
854 }
855 }
856 switch (Adapter->DDRSetting) {
857
858
859
860 case DDR_80_MHZ:
861 psDDRSetting = asT3LPB_DDRSetting80MHz;
862 RegCount = (sizeof(asT3B_DDRSetting80MHz) /
863 sizeof(struct bcm_ddr_setting));
864 break;
865 case DDR_100_MHZ:
866 psDDRSetting = asT3LPB_DDRSetting100MHz;
867 RegCount = (sizeof(asT3B_DDRSetting100MHz) /
868 sizeof(struct bcm_ddr_setting));
869 break;
870 case DDR_133_MHZ:
871 psDDRSetting = asT3LPB_DDRSetting133MHz;
872 RegCount = (sizeof(asT3B_DDRSetting133MHz) /
873 sizeof(struct bcm_ddr_setting));
874
875 if (Adapter->bMipsConfig == MIPS_200_MHZ)
876 uiClockSetting = 0x03F13652;
877 else
878 uiClockSetting = 0x03F1365B;
879 break;
880
881 case DDR_160_MHZ:
882 psDDRSetting = asT3LPB_DDRSetting160MHz;
883 RegCount = sizeof(asT3LPB_DDRSetting160MHz) /
884 sizeof(struct bcm_ddr_setting);
885
886 if (Adapter->bMipsConfig == MIPS_200_MHZ)
887 uiClockSetting = 0x03F137D2;
888 else
889 uiClockSetting = 0x03F137DB;
890 }
891 break;
892
893 case 0xbece0110:
894 case 0xbece0120:
895 case 0xbece0121:
896 case 0xbece0130:
897 case 0xbece0300:
898 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
899 "DDR Setting: %x\n", Adapter->DDRSetting);
900 switch (Adapter->DDRSetting) {
901 case DDR_80_MHZ:
902 psDDRSetting = asT3_DDRSetting80MHz;
903 RegCount = (sizeof(asT3_DDRSetting80MHz) /
904 sizeof(struct bcm_ddr_setting));
905 break;
906 case DDR_100_MHZ:
907 psDDRSetting = asT3_DDRSetting100MHz;
908 RegCount = (sizeof(asT3_DDRSetting100MHz) /
909 sizeof(struct bcm_ddr_setting));
910 break;
911 case DDR_133_MHZ:
912 psDDRSetting = asT3_DDRSetting133MHz;
913 RegCount = (sizeof(asT3_DDRSetting133MHz) /
914 sizeof(struct bcm_ddr_setting));
915 break;
916 default:
917 return -EINVAL;
918 }
919 case 0xbece0310:
920 {
921 switch (Adapter->DDRSetting) {
922 case DDR_80_MHZ:
923 psDDRSetting = asT3B_DDRSetting80MHz;
924 RegCount = (sizeof(asT3B_DDRSetting80MHz) /
925 sizeof(struct bcm_ddr_setting));
926 break;
927 case DDR_100_MHZ:
928 psDDRSetting = asT3B_DDRSetting100MHz;
929 RegCount = (sizeof(asT3B_DDRSetting100MHz) /
930 sizeof(struct bcm_ddr_setting));
931 break;
932 case DDR_133_MHZ:
933
934 /* 266Mhz PLL selected. */
935 if (Adapter->bDPLLConfig == PLL_266_MHZ) {
936 memcpy(asT3B_DDRSetting133MHz, asDPLL_266MHZ,
937 sizeof(asDPLL_266MHZ));
938 psDDRSetting = asT3B_DDRSetting133MHz;
939 RegCount = (sizeof(asT3B_DDRSetting133MHz) /
940 sizeof(struct bcm_ddr_setting));
941 } else {
942 psDDRSetting = asT3B_DDRSetting133MHz;
943 RegCount = (sizeof(asT3B_DDRSetting133MHz) /
944 sizeof(struct bcm_ddr_setting));
945 if (Adapter->bMipsConfig == MIPS_200_MHZ)
946 uiClockSetting = 0x07F13652;
947 else
948 uiClockSetting = 0x07F1365B;
949 }
950 break;
951 default:
952 return -EINVAL;
953 }
954 break;
955
956 }
957 default:
958 return -EINVAL;
959 }
960
961 value = 0;
962 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
963 "Register Count is =%lu\n", RegCount);
964 while (RegCount && !retval) {
965 if (uiClockSetting
966 && psDDRSetting->ulRegAddress == MIPS_CLOCK_REG)
967 value = uiClockSetting;
968 else
969 value = psDDRSetting->ulRegValue;
970 retval = wrmalt(Adapter, psDDRSetting->ulRegAddress, &value,
971 sizeof(value));
972 if (STATUS_SUCCESS != retval) {
973 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
974 "%s:%d\n", __func__, __LINE__);
975 break;
976 }
977
978 RegCount--;
979 psDDRSetting++;
980 }
981
982 if (Adapter->chip_id >= 0xbece3300) {
983
984 mdelay(3);
985 if ((Adapter->chip_id != BCS220_2) &&
986 (Adapter->chip_id != BCS220_2BC) &&
987 (Adapter->chip_id != BCS220_3)) {
988 /* drive MDDR to half in case of UMA-B: */
989 uiResetValue = 0x01010001;
990 retval = wrmalt(Adapter, (UINT)0x0F007018,
991 &uiResetValue, sizeof(uiResetValue));
992 if (retval < 0) {
993 BCM_DEBUG_PRINT(Adapter, CMHOST, RDM,
994 DBG_LVL_ALL,
995 "%s:%d RDM failed\n",
996 __func__,
997 __LINE__);
998 return retval;
999 }
1000 uiResetValue = 0x00040020;
1001 retval = wrmalt(Adapter, (UINT)0x0F007094,
1002 &uiResetValue, sizeof(uiResetValue));
1003 if (retval < 0) {
1004 BCM_DEBUG_PRINT(Adapter, CMHOST, RDM,
1005 DBG_LVL_ALL,
1006 "%s:%d RDM failed\n",
1007 __func__,
1008 __LINE__);
1009 return retval;
1010 }
1011 uiResetValue = 0x01020101;
1012 retval = wrmalt(Adapter, (UINT)0x0F00701c,
1013 &uiResetValue, sizeof(uiResetValue));
1014 if (retval < 0) {
1015 BCM_DEBUG_PRINT(Adapter, CMHOST, RDM,
1016 DBG_LVL_ALL,
1017 "%s:%d RDM failed\n",
1018 __func__,
1019 __LINE__);
1020 return retval;
1021 }
1022 uiResetValue = 0x01010000;
1023 retval = wrmalt(Adapter, (UINT)0x0F007018,
1024 &uiResetValue, sizeof(uiResetValue));
1025 if (retval < 0) {
1026 BCM_DEBUG_PRINT(Adapter, CMHOST, RDM,
1027 DBG_LVL_ALL,
1028 "%s:%d RDM failed\n",
1029 __func__,
1030 __LINE__);
1031 return retval;
1032 }
1033 }
1034 mdelay(3);
1035
1036 /* DC/DC standby change...
1037 * This is to be done only for Hybrid PMU mode.
1038 * with the current h/w there is no way to detect this.
1039 * and since we dont have internal PMU lets do it under
1040 * UMA-B chip id. we will change this when we will have
1041 * internal PMU.
1042 */
1043 if (Adapter->PmuMode == HYBRID_MODE_7C) {
1044 retval = rdmalt(Adapter, (UINT)0x0f000c00,
1045 &uiResetValue, sizeof(uiResetValue));
1046 if (retval < 0) {
1047 BCM_DEBUG_PRINT(Adapter, CMHOST, RDM,
1048 DBG_LVL_ALL,
1049 "%s:%d RDM failed\n",
1050 __func__,
1051 __LINE__);
1052 return retval;
1053 }
1054 retval = rdmalt(Adapter, (UINT)0x0f000c00,
1055 &uiResetValue, sizeof(uiResetValue));
1056 if (retval < 0) {
1057 BCM_DEBUG_PRINT(Adapter, CMHOST, RDM,
1058 DBG_LVL_ALL,
1059 "%s:%d RDM failed\n",
1060 __func__,
1061 __LINE__);
1062 return retval;
1063 }
1064 uiResetValue = 0x1322a8;
1065 retval = wrmalt(Adapter, (UINT)0x0f000d1c,
1066 &uiResetValue, sizeof(uiResetValue));
1067 if (retval < 0) {
1068 BCM_DEBUG_PRINT(Adapter, CMHOST, RDM,
1069 DBG_LVL_ALL,
1070 "%s:%d RDM failed\n",
1071 __func__,
1072 __LINE__);
1073 return retval;
1074 }
1075 retval = rdmalt(Adapter, (UINT)0x0f000c00,
1076 &uiResetValue, sizeof(uiResetValue));
1077 if (retval < 0) {
1078 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, RDM,
1079 DBG_LVL_ALL,
1080 "%s:%d RDM failed\n",
1081 __func__,
1082 __LINE__);
1083 return retval;
1084 }
1085 retval = rdmalt(Adapter, (UINT)0x0f000c00,
1086 &uiResetValue, sizeof(uiResetValue));
1087 if (retval < 0) {
1088 BCM_DEBUG_PRINT(Adapter, CMHOST, RDM,
1089 DBG_LVL_ALL,
1090 "%s:%d RDM failed\n",
1091 __func__,
1092 __LINE__);
1093 return retval;
1094 }
1095 uiResetValue = 0x132296;
1096 retval = wrmalt(Adapter, (UINT)0x0f000d14,
1097 &uiResetValue, sizeof(uiResetValue));
1098 if (retval < 0) {
1099 BCM_DEBUG_PRINT(Adapter, CMHOST, RDM,
1100 DBG_LVL_ALL,
1101 "%s:%d RDM failed\n",
1102 __func__,
1103 __LINE__);
1104 return retval;
1105 }
1106 } else if (Adapter->PmuMode == HYBRID_MODE_6) {
1107
1108 retval = rdmalt(Adapter, (UINT)0x0f000c00,
1109 &uiResetValue, sizeof(uiResetValue));
1110 if (retval < 0) {
1111 BCM_DEBUG_PRINT(Adapter, CMHOST, RDM,
1112 DBG_LVL_ALL,
1113 "%s:%d RDM failed\n",
1114 __func__,
1115 __LINE__);
1116 return retval;
1117 }
1118 retval = rdmalt(Adapter, (UINT)0x0f000c00,
1119 &uiResetValue, sizeof(uiResetValue));
1120 if (retval < 0) {
1121 BCM_DEBUG_PRINT(Adapter, CMHOST, RDM,
1122 DBG_LVL_ALL,
1123 "%s:%d RDM failed\n",
1124 __func__,
1125 __LINE__);
1126 return retval;
1127 }
1128 uiResetValue = 0x6003229a;
1129 retval = wrmalt(Adapter, (UINT)0x0f000d14,
1130 &uiResetValue, sizeof(uiResetValue));
1131 if (retval < 0) {
1132 BCM_DEBUG_PRINT(Adapter, CMHOST, RDM,
1133 DBG_LVL_ALL,
1134 "%s:%d RDM failed\n",
1135 __func__,
1136 __LINE__);
1137 return retval;
1138 }
1139 retval = rdmalt(Adapter, (UINT)0x0f000c00,
1140 &uiResetValue, sizeof(uiResetValue));
1141 if (retval < 0) {
1142 BCM_DEBUG_PRINT(Adapter, CMHOST, RDM,
1143 DBG_LVL_ALL,
1144 "%s:%d RDM failed\n",
1145 __func__,
1146 __LINE__);
1147 return retval;
1148 }
1149 retval = rdmalt(Adapter, (UINT)0x0f000c00,
1150 &uiResetValue, sizeof(uiResetValue));
1151 if (retval < 0) {
1152 BCM_DEBUG_PRINT(Adapter, CMHOST, RDM,
1153 DBG_LVL_ALL,
1154 "%s:%d RDM failed\n",
1155 __func__,
1156 __LINE__);
1157 return retval;
1158 }
1159 uiResetValue = 0x1322a8;
1160 retval = wrmalt(Adapter, (UINT)0x0f000d1c,
1161 &uiResetValue, sizeof(uiResetValue));
1162 if (retval < 0) {
1163 BCM_DEBUG_PRINT(Adapter, CMHOST, RDM,
1164 DBG_LVL_ALL,
1165 "%s:%d RDM failed\n",
1166 __func__,
1167 __LINE__);
1168 return retval;
1169 }
1170 }
1171
1172 }
1173 Adapter->bDDRInitDone = TRUE;
1174 return retval;
1175}
1176
1177int download_ddr_settings(struct bcm_mini_adapter *Adapter)
1178{
1179 struct bcm_ddr_setting *psDDRSetting = NULL;
1180 ULONG RegCount = 0;
1181 unsigned long ul_ddr_setting_load_addr =
1182 DDR_DUMP_INTERNAL_DEVICE_MEMORY;
1183 UINT value = 0;
1184 int retval = STATUS_SUCCESS;
1185 bool bOverrideSelfRefresh = false;
1186
1187 switch (Adapter->chip_id) {
1188 case 0xbece3200:
1189 switch (Adapter->DDRSetting) {
1190 case DDR_80_MHZ:
1191 psDDRSetting = asT3LP_DDRSetting80MHz;
1192 RegCount = ARRAY_SIZE(asT3LP_DDRSetting80MHz);
1193 RegCount -= T3LP_SKIP_CLOCK_PROGRAM_DUMP_80MHZ;
1194 psDDRSetting += T3LP_SKIP_CLOCK_PROGRAM_DUMP_80MHZ;
1195 break;
1196 case DDR_100_MHZ:
1197 psDDRSetting = asT3LP_DDRSetting100MHz;
1198 RegCount = ARRAY_SIZE(asT3LP_DDRSetting100MHz);
1199 RegCount -= T3LP_SKIP_CLOCK_PROGRAM_DUMP_100MHZ;
1200 psDDRSetting += T3LP_SKIP_CLOCK_PROGRAM_DUMP_100MHZ;
1201 break;
1202 case DDR_133_MHZ:
1203 bOverrideSelfRefresh = TRUE;
1204 psDDRSetting = asT3LP_DDRSetting133MHz;
1205 RegCount = ARRAY_SIZE(asT3LP_DDRSetting133MHz);
1206 RegCount -= T3LP_SKIP_CLOCK_PROGRAM_DUMP_133MHZ;
1207 psDDRSetting += T3LP_SKIP_CLOCK_PROGRAM_DUMP_133MHZ;
1208 break;
1209 default:
1210 return -EINVAL;
1211 }
1212 break;
1213
1214 case T3LPB:
1215 case BCS220_2:
1216 case BCS220_2BC:
1217 case BCS250_BC:
1218 case BCS220_3:
1219 switch (Adapter->DDRSetting) {
1220 case DDR_80_MHZ:
1221 psDDRSetting = asT3LPB_DDRSetting80MHz;
1222 RegCount = ARRAY_SIZE(asT3LPB_DDRSetting80MHz);
1223 RegCount -= T3LPB_SKIP_CLOCK_PROGRAM_DUMP_80MHZ;
1224 psDDRSetting += T3LPB_SKIP_CLOCK_PROGRAM_DUMP_80MHZ;
1225 break;
1226 case DDR_100_MHZ:
1227 psDDRSetting = asT3LPB_DDRSetting100MHz;
1228 RegCount = ARRAY_SIZE(asT3LPB_DDRSetting100MHz);
1229 RegCount -= T3LPB_SKIP_CLOCK_PROGRAM_DUMP_100MHZ;
1230 psDDRSetting += T3LPB_SKIP_CLOCK_PROGRAM_DUMP_100MHZ;
1231 break;
1232 case DDR_133_MHZ:
1233 bOverrideSelfRefresh = TRUE;
1234 psDDRSetting = asT3LPB_DDRSetting133MHz;
1235 RegCount = ARRAY_SIZE(asT3LPB_DDRSetting133MHz);
1236 RegCount -= T3LPB_SKIP_CLOCK_PROGRAM_DUMP_133MHZ;
1237 psDDRSetting += T3LPB_SKIP_CLOCK_PROGRAM_DUMP_133MHZ;
1238 break;
1239
1240 case DDR_160_MHZ:
1241 bOverrideSelfRefresh = TRUE;
1242 psDDRSetting = asT3LPB_DDRSetting160MHz;
1243 RegCount = ARRAY_SIZE(asT3LPB_DDRSetting160MHz);
1244 RegCount -= T3LPB_SKIP_CLOCK_PROGRAM_DUMP_160MHZ;
1245 psDDRSetting += T3LPB_SKIP_CLOCK_PROGRAM_DUMP_160MHZ;
1246
1247 break;
1248 default:
1249 return -EINVAL;
1250 }
1251 break;
1252 case 0xbece0300:
1253 switch (Adapter->DDRSetting) {
1254 case DDR_80_MHZ:
1255 psDDRSetting = asT3_DDRSetting80MHz;
1256 RegCount = ARRAY_SIZE(asT3_DDRSetting80MHz);
1257 RegCount -= T3_SKIP_CLOCK_PROGRAM_DUMP_80MHZ;
1258 psDDRSetting += T3_SKIP_CLOCK_PROGRAM_DUMP_80MHZ;
1259 break;
1260 case DDR_100_MHZ:
1261 psDDRSetting = asT3_DDRSetting100MHz;
1262 RegCount = ARRAY_SIZE(asT3_DDRSetting100MHz);
1263 RegCount -= T3_SKIP_CLOCK_PROGRAM_DUMP_100MHZ;
1264 psDDRSetting += T3_SKIP_CLOCK_PROGRAM_DUMP_100MHZ;
1265 break;
1266 case DDR_133_MHZ:
1267 psDDRSetting = asT3_DDRSetting133MHz;
1268 RegCount = ARRAY_SIZE(asT3_DDRSetting133MHz);
1269 RegCount -= T3_SKIP_CLOCK_PROGRAM_DUMP_133MHZ;
1270 psDDRSetting += T3_SKIP_CLOCK_PROGRAM_DUMP_133MHZ;
1271 break;
1272 default:
1273 return -EINVAL;
1274 }
1275 break;
1276 case 0xbece0310:
1277 {
1278 switch (Adapter->DDRSetting) {
1279 case DDR_80_MHZ:
1280 psDDRSetting = asT3B_DDRSetting80MHz;
1281 RegCount = ARRAY_SIZE(asT3B_DDRSetting80MHz);
1282 RegCount -= T3B_SKIP_CLOCK_PROGRAM_DUMP_80MHZ;
1283 psDDRSetting += T3B_SKIP_CLOCK_PROGRAM_DUMP_80MHZ;
1284 break;
1285 case DDR_100_MHZ:
1286 psDDRSetting = asT3B_DDRSetting100MHz;
1287 RegCount = ARRAY_SIZE(asT3B_DDRSetting100MHz);
1288 RegCount -= T3B_SKIP_CLOCK_PROGRAM_DUMP_100MHZ;
1289 psDDRSetting += T3B_SKIP_CLOCK_PROGRAM_DUMP_100MHZ;
1290 break;
1291 case DDR_133_MHZ:
1292 bOverrideSelfRefresh = TRUE;
1293 psDDRSetting = asT3B_DDRSetting133MHz;
1294 RegCount = ARRAY_SIZE(asT3B_DDRSetting133MHz);
1295 RegCount -= T3B_SKIP_CLOCK_PROGRAM_DUMP_133MHZ;
1296 psDDRSetting += T3B_SKIP_CLOCK_PROGRAM_DUMP_133MHZ;
1297 break;
1298 }
1299 break;
1300 }
1301 default:
1302 return -EINVAL;
1303 }
1304 /* total number of Register that has to be dumped */
1305 value = RegCount;
1306 retval = wrmalt(Adapter, ul_ddr_setting_load_addr, &value,
1307 sizeof(value));
1308 if (retval) {
1309 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1310 "%s:%d\n", __func__, __LINE__);
1311
1312 return retval;
1313 }
1314 ul_ddr_setting_load_addr += sizeof(ULONG);
1315 /* signature */
1316 value = (0x1d1e0dd0);
1317 retval = wrmalt(Adapter, ul_ddr_setting_load_addr, &value,
1318 sizeof(value));
1319 if (retval) {
1320 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1321 "%s:%d\n", __func__, __LINE__);
1322 return retval;
1323 }
1324
1325 ul_ddr_setting_load_addr += sizeof(ULONG);
1326 RegCount *= (sizeof(struct bcm_ddr_setting)/sizeof(ULONG));
1327
1328 while (RegCount && !retval) {
1329 value = psDDRSetting->ulRegAddress;
1330 retval = wrmalt(Adapter, ul_ddr_setting_load_addr, &value,
1331 sizeof(value));
1332 ul_ddr_setting_load_addr += sizeof(ULONG);
1333 if (!retval) {
1334 if (bOverrideSelfRefresh
1335 && (psDDRSetting->ulRegAddress
1336 == 0x0F007018))
1337 value = (psDDRSetting->ulRegValue | (1<<8));
1338 else
1339 value = psDDRSetting->ulRegValue;
1340
1341 if (STATUS_SUCCESS != wrmalt(Adapter,
1342 ul_ddr_setting_load_addr,
1343 &value,
1344 sizeof(value))) {
1345 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
1346 "%s:%d\n", __func__, __LINE__);
1347 break;
1348 }
1349 }
1350 ul_ddr_setting_load_addr += sizeof(ULONG);
1351 RegCount--;
1352 psDDRSetting++;
1353 }
1354 return retval;
1355}
diff --git a/drivers/staging/bcm/DDRInit.h b/drivers/staging/bcm/DDRInit.h
deleted file mode 100644
index b0196fce9255..000000000000
--- a/drivers/staging/bcm/DDRInit.h
+++ /dev/null
@@ -1,9 +0,0 @@
1#ifndef _DDR_INIT_H_
2#define _DDR_INIT_H_
3
4
5
6int ddr_init(struct bcm_mini_adapter *psAdapter);
7int download_ddr_settings(struct bcm_mini_adapter *psAdapter);
8
9#endif
diff --git a/drivers/staging/bcm/Debug.h b/drivers/staging/bcm/Debug.h
deleted file mode 100644
index 7b331215c1ac..000000000000
--- a/drivers/staging/bcm/Debug.h
+++ /dev/null
@@ -1,242 +0,0 @@
1/*
2 * Debug.h
3 *
4 * Dynamic (runtime) debug framework implementation.
5 * -kaiwan.
6 */
7#ifndef _DEBUG_H
8#define _DEBUG_H
9#include <linux/string.h>
10#define NONE 0xFFFF
11
12/* TYPE and SUBTYPE
13 * Define valid TYPE (or category or code-path, however you like to think of it)
14 * and SUBTYPE s.
15 * Type and SubType are treated as bitmasks.
16 */
17#define DBG_TYPE_INITEXIT (1 << 0) /* 1 */
18#define DBG_TYPE_TX (1 << 1) /* 2 */
19#define DBG_TYPE_RX (1 << 2) /* 4 */
20#define DBG_TYPE_OTHERS (1 << 3) /* 8 */
21#define NUMTYPES 4
22
23/* -SUBTYPEs for TX : TYPE is DBG_TYPE_TX -----//
24 * Transmit.c ,Arp.c, LeakyBucket.c, And Qos.c
25 * total 17 macros
26 */
27/* Transmit.c */
28#define TX 1
29#define MP_SEND (TX << 0)
30#define NEXT_SEND (TX << 1)
31#define TX_FIFO (TX << 2)
32#define TX_CONTROL (TX << 3)
33
34/* Arp.c */
35#define IP_ADDR (TX << 4)
36#define ARP_REQ (TX << 5)
37#define ARP_RESP (TX << 6)
38
39/* Leakybucket.c */
40#define TOKEN_COUNTS (TX << 8)
41#define CHECK_TOKENS (TX << 9)
42#define TX_PACKETS (TX << 10)
43#define TIMER (TX << 11)
44
45/* Qos.c */
46#define QOS TX
47#define QUEUE_INDEX (QOS << 12)
48#define IPV4_DBG (QOS << 13)
49#define IPV6_DBG (QOS << 14)
50#define PRUNE_QUEUE (QOS << 15)
51#define SEND_QUEUE (QOS << 16)
52
53/* TX_Misc */
54#define TX_OSAL_DBG (TX << 17)
55
56/* --SUBTYPEs for ------INIT & EXIT---------------------
57 * ------------ TYPE is DBG_TYPE_INITEXIT -----//
58 * DriverEntry.c, bcmfwup.c, ChipDetectTask.c, HaltnReset.c, InterfaceDDR.c
59 */
60#define MP 1
61#define DRV_ENTRY (MP << 0)
62#define MP_INIT (MP << 1)
63#define READ_REG (MP << 3)
64#define DISPATCH (MP << 2)
65#define CLAIM_ADAP (MP << 4)
66#define REG_IO_PORT (MP << 5)
67#define INIT_DISP (MP << 6)
68#define RX_INIT (MP << 7)
69
70/* -SUBTYPEs for --RX----------------------------------
71 * ------------RX : TYPE is DBG_TYPE_RX -----//
72 * Receive.c
73 */
74#define RX 1
75#define RX_DPC (RX << 0)
76#define RX_CTRL (RX << 3)
77#define RX_DATA (RX << 4)
78#define MP_RETURN (RX << 1)
79#define LINK_MSG (RX << 2)
80
81/* -SUBTYPEs for ----OTHER ROUTINES------------------
82 * ------------OTHERS : TYPE is DBG_TYPE_OTHER -----//
83 * HaltnReset,CheckForHang,PnP,Misc,CmHost
84 * total 12 macros
85 */
86#define OTHERS 1
87#define ISR OTHERS
88#define MP_DPC (ISR << 0)
89
90/* HaltnReset.c */
91#define HALT OTHERS
92#define MP_HALT (HALT << 1)
93#define CHECK_HANG (HALT << 2)
94#define MP_RESET (HALT << 3)
95#define MP_SHUTDOWN (HALT << 4)
96
97/* pnp.c */
98#define PNP OTHERS
99#define MP_PNP (PNP << 5)
100
101/* Misc.c */
102#define MISC OTHERS
103#define DUMP_INFO (MISC << 6)
104#define CLASSIFY (MISC << 7)
105#define LINK_UP_MSG (MISC << 8)
106#define CP_CTRL_PKT (MISC << 9)
107#define DUMP_CONTROL (MISC << 10)
108#define LED_DUMP_INFO (MISC << 11)
109
110/* CmHost.c */
111#define CMHOST OTHERS
112#define SERIAL (OTHERS << 12)
113#define IDLE_MODE (OTHERS << 13)
114#define WRM (OTHERS << 14)
115#define RDM (OTHERS << 15)
116
117/* TODO - put PHS_SEND in Tx PHS_RECEIVE in Rx path ? */
118#define PHS_SEND (OTHERS << 16)
119#define PHS_RECEIVE (OTHERS << 17)
120#define PHS_MODULE (OTHERS << 18)
121
122#define INTF_INIT (OTHERS << 19)
123#define INTF_ERR (OTHERS << 20)
124#define INTF_WARN (OTHERS << 21)
125#define INTF_NORM (OTHERS << 22)
126
127#define IRP_COMPLETION (OTHERS << 23)
128#define SF_DESCRIPTOR_CNTS (OTHERS << 24)
129#define PHS_DISPATCH (OTHERS << 25)
130#define OSAL_DBG (OTHERS << 26)
131#define NVM_RW (OTHERS << 27)
132
133#define HOST_MIBS (OTHERS << 28)
134#define CONN_MSG (CMHOST << 29)
135
136/* Debug level
137 * We have 8 debug levels, in (numerical) increasing order of verbosity.
138 * IMP: Currently implementing ONLY DBG_LVL_ALL , i.e. , all debug prints will
139 * appear (of course, iff global debug flag is ON and we match the Type and SubType).
140 * Finer granularity debug levels are currently not in use, although the feature exists.
141 *
142 * Another way to say this:
143 * All the debug prints currently have 'debug_level' set to DBG_LVL_ALL .
144 * You can compile-time change that to any of the below, if you wish to. However, as of now, there's
145 * no dynamic facility to have the userspace 'TestApp' set debug_level. Slated for future expansion.
146 */
147#define BCM_ALL 7
148#define BCM_LOW 6
149#define BCM_PRINT 5
150#define BCM_NORMAL 4
151#define BCM_MEDIUM 3
152#define BCM_SCREAM 2
153#define BCM_ERR 1
154/* Not meant for developer in debug prints.
155 * To be used to disable all prints by setting the DBG_LVL_CURR to this value
156 */
157#define BCM_NONE 0
158
159/* The current driver logging level.
160 * Everything at this level and (numerically) lower (meaning higher prio)
161 * is logged.
162 * Replace 'BCM_ALL' in the DBG_LVL_CURR macro with the logging level desired.
163 * For eg. to set the logging level to 'errors only' use:
164 * #define DBG_LVL_CURR (BCM_ERR)
165 */
166
167#define DBG_LVL_CURR (BCM_ALL)
168#define DBG_LVL_ALL BCM_ALL
169
170/* ---Userspace mapping of Debug State.
171 * Delibrately matches that of the Windows driver..
172 * The TestApp's ioctl passes this struct to us.
173 */
174struct bcm_user_debug_state {
175 unsigned int Subtype, Type;
176 unsigned int OnOff;
177/* unsigned int debug_level; future expansion */
178} __packed;
179
180/* ---Kernel-space mapping of Debug State */
181struct bcm_debug_state {
182 unsigned int type;
183 /* A bitmap of 32 bits for Subtype per Type.
184 * Valid indexes in 'subtype' array are *only* 1,2,4 and 8,
185 * corresponding to valid Type values. Hence we use the 'Type' field
186 * as the index value, ignoring the array entries 0,3,5,6,7 !
187 */
188 unsigned int subtype[(NUMTYPES*2)+1];
189 unsigned int debug_level;
190};
191/* Instantiated in the Adapter structure
192 * We'll reuse the debug level parameter to include a bit (the MSB) to indicate whether or not
193 * we want the function's name printed.
194 */
195#define DBG_NO_FUNC_PRINT (1 << 31)
196#define DBG_LVL_BITMASK 0xFF
197
198/* --- Only for direct printk's; "hidden" to API. */
199#define DBG_TYPE_PRINTK 3
200
201#define BCM_DEBUG_PRINT(Adapter, Type, SubType, dbg_level, string, args...) \
202 do { \
203 if (DBG_TYPE_PRINTK == Type) \
204 pr_info("%s:" string, __func__, ##args); \
205 else if (Adapter && \
206 (dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level && \
207 (Type & Adapter->stDebugState.type) && \
208 (SubType & Adapter->stDebugState.subtype[Type])) { \
209 if (dbg_level & DBG_NO_FUNC_PRINT) \
210 pr_debug("%s:\n", string); \
211 else \
212 pr_debug("%s:\n" string, __func__, ##args); \
213 } \
214 } while (0)
215
216#define BCM_DEBUG_PRINT_BUFFER(Adapter, Type, SubType, dbg_level, buffer, bufferlen) \
217 do { \
218 if (DBG_TYPE_PRINTK == Type || \
219 (Adapter && \
220 (dbg_level & DBG_LVL_BITMASK) <= Adapter->stDebugState.debug_level && \
221 (Type & Adapter->stDebugState.type) && \
222 (SubType & Adapter->stDebugState.subtype[Type]))) { \
223 pr_debug("%s:\n", __func__); \
224 print_hex_dump(KERN_DEBUG, " ", DUMP_PREFIX_OFFSET, \
225 16, 1, buffer, bufferlen, false); \
226 } \
227 } while (0)
228
229#define BCM_SHOW_DEBUG_BITMAP(Adapter) do { \
230 int i; \
231 for (i = 0; i < (NUMTYPES * 2) + 1; i++) { \
232 if ((i == 1) || (i == 2) || (i == 4) || (i == 8)) { \
233 /* CAUTION! Forcefully turn on ALL debug paths and subpaths! \
234 * Adapter->stDebugState.subtype[i] = 0xffffffff; \
235 */ \
236 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "subtype[%d] = 0x%08x\n", \
237 i, Adapter->stDebugState.subtype[i]); \
238 } \
239 } \
240} while (0)
241
242#endif
diff --git a/drivers/staging/bcm/HandleControlPacket.c b/drivers/staging/bcm/HandleControlPacket.c
deleted file mode 100644
index dd5d138a6528..000000000000
--- a/drivers/staging/bcm/HandleControlPacket.c
+++ /dev/null
@@ -1,241 +0,0 @@
1/**
2 * @file HandleControlPacket.c
3 * This file contains the routines to deal with
4 * sending and receiving of control packets.
5 */
6#include "headers.h"
7
8/**
9 * When a control packet is received, analyze the
10 * "status" and call appropriate response function.
11 * Enqueue the control packet for Application.
12 * @return None
13 */
14static VOID handle_rx_control_packet(struct bcm_mini_adapter *Adapter,
15 struct sk_buff *skb)
16{
17 struct bcm_tarang_data *pTarang = NULL;
18 bool HighPriorityMessage = false;
19 struct sk_buff *newPacket = NULL;
20 CHAR cntrl_msg_mask_bit = 0;
21 bool drop_pkt_flag = TRUE;
22 USHORT usStatus = *(PUSHORT)(skb->data);
23
24 if (netif_msg_pktdata(Adapter))
25 print_hex_dump(KERN_DEBUG, PFX "rx control: ", DUMP_PREFIX_NONE,
26 16, 1, skb->data, skb->len, 0);
27
28 switch (usStatus) {
29 case CM_RESPONSES: /* 0xA0 */
30 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CP_CTRL_PKT,
31 DBG_LVL_ALL,
32 "MAC Version Seems to be Non Multi-Classifier, rejected by Driver");
33 HighPriorityMessage = TRUE;
34 break;
35 case CM_CONTROL_NEWDSX_MULTICLASSIFIER_RESP:
36 HighPriorityMessage = TRUE;
37 if (Adapter->LinkStatus == LINKUP_DONE)
38 CmControlResponseMessage(Adapter,
39 (skb->data + sizeof(USHORT)));
40 break;
41 case LINK_CONTROL_RESP: /* 0xA2 */
42 case STATUS_RSP: /* 0xA1 */
43 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CP_CTRL_PKT,
44 DBG_LVL_ALL, "LINK_CONTROL_RESP");
45 HighPriorityMessage = TRUE;
46 LinkControlResponseMessage(Adapter,
47 (skb->data + sizeof(USHORT)));
48 break;
49 case STATS_POINTER_RESP: /* 0xA6 */
50 HighPriorityMessage = TRUE;
51 StatisticsResponse(Adapter, (skb->data + sizeof(USHORT)));
52 break;
53 case IDLE_MODE_STATUS: /* 0xA3 */
54 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CP_CTRL_PKT,
55 DBG_LVL_ALL,
56 "IDLE_MODE_STATUS Type Message Got from F/W");
57 InterfaceIdleModeRespond(Adapter, (PUINT)(skb->data +
58 sizeof(USHORT)));
59 HighPriorityMessage = TRUE;
60 break;
61
62 case AUTH_SS_HOST_MSG:
63 HighPriorityMessage = TRUE;
64 break;
65
66 default:
67 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CP_CTRL_PKT,
68 DBG_LVL_ALL, "Got Default Response");
69 /* Let the Application Deal with This Packet */
70 break;
71 }
72
73 /* Queue The Control Packet to The Application Queues */
74 down(&Adapter->RxAppControlQueuelock);
75
76 for (pTarang = Adapter->pTarangs; pTarang; pTarang = pTarang->next) {
77 if (Adapter->device_removed)
78 break;
79
80 drop_pkt_flag = TRUE;
81 /*
82 * There are cntrl msg from A0 to AC. It has been mapped to 0 to
83 * C bit in the cntrl mask.
84 * Also, by default AD to BF has been masked to the rest of the
85 * bits... which wil be ON by default.
86 * if mask bit is enable to particular pkt status, send it out
87 * to app else stop it.
88 */
89 cntrl_msg_mask_bit = (usStatus & 0x1F);
90 /*
91 * printk("\ninew msg mask bit which is disable in mask:%X",
92 * cntrl_msg_mask_bit);
93 */
94 if (pTarang->RxCntrlMsgBitMask & (1 << cntrl_msg_mask_bit))
95 drop_pkt_flag = false;
96
97 if ((drop_pkt_flag == TRUE) ||
98 (pTarang->AppCtrlQueueLen > MAX_APP_QUEUE_LEN)
99 || ((pTarang->AppCtrlQueueLen >
100 MAX_APP_QUEUE_LEN / 2) &&
101 (HighPriorityMessage == false))) {
102 /*
103 * Assumption:-
104 * 1. every tarang manages it own dropped pkt
105 * statitistics
106 * 2. Total packet dropped per tarang will be equal to
107 * the sum of all types of dropped pkt by that
108 * tarang only.
109 */
110 struct bcm_mibs_dropped_cntrl_msg *msg =
111 &pTarang->stDroppedAppCntrlMsgs;
112 switch (*(PUSHORT)skb->data) {
113 case CM_RESPONSES:
114 msg->cm_responses++;
115 break;
116 case CM_CONTROL_NEWDSX_MULTICLASSIFIER_RESP:
117 msg->cm_control_newdsx_multiclassifier_resp++;
118 break;
119 case LINK_CONTROL_RESP:
120 msg->link_control_resp++;
121 break;
122 case STATUS_RSP:
123 msg->status_rsp++;
124 break;
125 case STATS_POINTER_RESP:
126 msg->stats_pointer_resp++;
127 break;
128 case IDLE_MODE_STATUS:
129 msg->idle_mode_status++;
130 break;
131 case AUTH_SS_HOST_MSG:
132 msg->auth_ss_host_msg++;
133 break;
134 default:
135 msg->low_priority_message++;
136 break;
137 }
138
139 continue;
140 }
141
142 newPacket = skb_clone(skb, GFP_KERNEL);
143 if (!newPacket)
144 break;
145 ENQUEUEPACKET(pTarang->RxAppControlHead,
146 pTarang->RxAppControlTail, newPacket);
147 pTarang->AppCtrlQueueLen++;
148 }
149 up(&Adapter->RxAppControlQueuelock);
150 wake_up(&Adapter->process_read_wait_queue);
151 dev_kfree_skb(skb);
152 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CP_CTRL_PKT, DBG_LVL_ALL,
153 "After wake_up_interruptible");
154}
155
156/**
157 * @ingroup ctrl_pkt_functions
158 * Thread to handle control pkt reception
159 */
160
161/* pointer to adapter object*/
162int control_packet_handler(struct bcm_mini_adapter *Adapter)
163{
164 struct sk_buff *ctrl_packet = NULL;
165 unsigned long flags = 0;
166 /* struct timeval tv; */
167 /* int *puiBuffer = NULL; */
168 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CP_CTRL_PKT, DBG_LVL_ALL,
169 "Entering to make thread wait on control packet event!");
170 while (1) {
171 wait_event_interruptible(Adapter->process_rx_cntrlpkt,
172 atomic_read(&Adapter->cntrlpktCnt) ||
173 Adapter->bWakeUpDevice ||
174 kthread_should_stop());
175
176
177 if (kthread_should_stop()) {
178 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CP_CTRL_PKT,
179 DBG_LVL_ALL, "Exiting\n");
180 return 0;
181 }
182 if (TRUE == Adapter->bWakeUpDevice) {
183 Adapter->bWakeUpDevice = false;
184 if ((false == Adapter->bTriedToWakeUpFromlowPowerMode)
185 && ((TRUE == Adapter->IdleMode) ||
186 (TRUE == Adapter->bShutStatus))) {
187 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
188 CP_CTRL_PKT, DBG_LVL_ALL,
189 "Calling InterfaceAbortIdlemode\n");
190 /*
191 * Adapter->bTriedToWakeUpFromlowPowerMode
192 * = TRUE;
193 */
194 InterfaceIdleModeWakeup(Adapter);
195 }
196 continue;
197 }
198
199 while (atomic_read(&Adapter->cntrlpktCnt)) {
200 spin_lock_irqsave(&Adapter->control_queue_lock, flags);
201 ctrl_packet = Adapter->RxControlHead;
202 if (ctrl_packet) {
203 DEQUEUEPACKET(Adapter->RxControlHead,
204 Adapter->RxControlTail);
205 /* Adapter->RxControlHead=ctrl_packet->next; */
206 }
207
208 spin_unlock_irqrestore(&Adapter->control_queue_lock,
209 flags);
210 handle_rx_control_packet(Adapter, ctrl_packet);
211 atomic_dec(&Adapter->cntrlpktCnt);
212 }
213
214 SetUpTargetDsxBuffers(Adapter);
215 }
216 return STATUS_SUCCESS;
217}
218
219INT flushAllAppQ(void)
220{
221 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
222 struct bcm_tarang_data *pTarang = NULL;
223 struct sk_buff *PacketToDrop = NULL;
224
225 for (pTarang = Adapter->pTarangs; pTarang; pTarang = pTarang->next) {
226 while (pTarang->RxAppControlHead != NULL) {
227 PacketToDrop = pTarang->RxAppControlHead;
228 DEQUEUEPACKET(pTarang->RxAppControlHead,
229 pTarang->RxAppControlTail);
230 dev_kfree_skb(PacketToDrop);
231 }
232 pTarang->AppCtrlQueueLen = 0;
233 /* dropped contrl packet statistics also should be reset. */
234 memset((PVOID)&pTarang->stDroppedAppCntrlMsgs, 0,
235 sizeof(struct bcm_mibs_dropped_cntrl_msg));
236
237 }
238 return STATUS_SUCCESS;
239}
240
241
diff --git a/drivers/staging/bcm/HostMIBSInterface.h b/drivers/staging/bcm/HostMIBSInterface.h
deleted file mode 100644
index f922ac49b70e..000000000000
--- a/drivers/staging/bcm/HostMIBSInterface.h
+++ /dev/null
@@ -1,192 +0,0 @@
1#ifndef _HOST_MIBSINTERFACE_H
2#define _HOST_MIBSINTERFACE_H
3
4/*
5 * Copyright (c) 2007 Beceem Communications Pvt. Ltd
6 * File Name: HostMIBSInterface.h
7 * Abstract: This file contains DS used by the Host to update the Host
8 * statistics used for the MIBS.
9 */
10
11#define MIBS_MAX_CLASSIFIERS 100
12#define MIBS_MAX_PHSRULES 100
13#define MIBS_MAX_SERVICEFLOWS 17
14#define MIBS_MAX_IP_RANGE_LENGTH 4
15#define MIBS_MAX_PORT_RANGE 4
16#define MIBS_MAX_PROTOCOL_LENGTH 32
17#define MIBS_MAX_PHS_LENGTHS 255
18#define MIBS_IPV6_ADDRESS_SIZEINBYTES 0x10
19#define MIBS_IP_LENGTH_OF_ADDRESS 4
20#define MIBS_MAX_HIST_ENTRIES 12
21#define MIBS_PKTSIZEHIST_RANGE 128
22
23union bcm_mibs_ip_addr {
24 struct {
25 /* Source Ip Address Range */
26 unsigned long ulIpv4Addr[MIBS_MAX_IP_RANGE_LENGTH];
27 /* Source Ip Mask Address Range */
28 unsigned long ulIpv4Mask[MIBS_MAX_IP_RANGE_LENGTH];
29 };
30 struct {
31 /* Source Ip Address Range */
32 unsigned long ulIpv6Addr[MIBS_MAX_IP_RANGE_LENGTH * 4];
33 /* Source Ip Mask Address Range */
34 unsigned long ulIpv6Mask[MIBS_MAX_IP_RANGE_LENGTH * 4];
35 };
36 struct {
37 unsigned char ucIpv4Address[MIBS_MAX_IP_RANGE_LENGTH * MIBS_IP_LENGTH_OF_ADDRESS];
38 unsigned char ucIpv4Mask[MIBS_MAX_IP_RANGE_LENGTH * MIBS_IP_LENGTH_OF_ADDRESS];
39 };
40 struct {
41 unsigned char ucIpv6Address[MIBS_MAX_IP_RANGE_LENGTH * MIBS_IPV6_ADDRESS_SIZEINBYTES];
42 unsigned char ucIpv6Mask[MIBS_MAX_IP_RANGE_LENGTH * MIBS_IPV6_ADDRESS_SIZEINBYTES];
43 };
44};
45
46struct bcm_mibs_host_info {
47 u64 GoodTransmits;
48 u64 GoodReceives;
49 /* this to keep track of the Tx and Rx MailBox Registers. */
50 unsigned long NumDesUsed;
51 unsigned long CurrNumFreeDesc;
52 unsigned long PrevNumFreeDesc;
53 /* to keep track the no of byte received */
54 unsigned long PrevNumRcevBytes;
55 unsigned long CurrNumRcevBytes;
56 /* QOS Related */
57 unsigned long BEBucketSize;
58 unsigned long rtPSBucketSize;
59 unsigned long LastTxQueueIndex;
60 bool TxOutofDescriptors;
61 bool TimerActive;
62 u32 u32TotalDSD;
63 u32 aTxPktSizeHist[MIBS_MAX_HIST_ENTRIES];
64 u32 aRxPktSizeHist[MIBS_MAX_HIST_ENTRIES];
65};
66
67struct bcm_mibs_classifier_rule {
68 unsigned long ulSFID;
69 unsigned char ucReserved[2];
70 u16 uiClassifierRuleIndex;
71 bool bUsed;
72 unsigned short usVCID_Value;
73 u8 u8ClassifierRulePriority;
74 union bcm_mibs_ip_addr stSrcIpAddress;
75 /* IP Source Address Length */
76 unsigned char ucIPSourceAddressLength;
77 union bcm_mibs_ip_addr stDestIpAddress;
78 /* IP Destination Address Length */
79 unsigned char ucIPDestinationAddressLength;
80 unsigned char ucIPTypeOfServiceLength;
81 unsigned char ucTosLow;
82 unsigned char ucTosHigh;
83 unsigned char ucTosMask;
84 unsigned char ucProtocolLength;
85 unsigned char ucProtocol[MIBS_MAX_PROTOCOL_LENGTH];
86 unsigned short usSrcPortRangeLo[MIBS_MAX_PORT_RANGE];
87 unsigned short usSrcPortRangeHi[MIBS_MAX_PORT_RANGE];
88 unsigned char ucSrcPortRangeLength;
89 unsigned short usDestPortRangeLo[MIBS_MAX_PORT_RANGE];
90 unsigned short usDestPortRangeHi[MIBS_MAX_PORT_RANGE];
91 unsigned char ucDestPortRangeLength;
92 bool bProtocolValid;
93 bool bTOSValid;
94 bool bDestIpValid;
95 bool bSrcIpValid;
96 unsigned char ucDirection;
97 bool bIpv6Protocol;
98 u32 u32PHSRuleID;
99};
100
101struct bcm_mibs_phs_rule {
102 unsigned long ulSFID;
103 u8 u8PHSI;
104 u8 u8PHSFLength;
105 u8 u8PHSF[MIBS_MAX_PHS_LENGTHS];
106 u8 u8PHSMLength;
107 u8 u8PHSM[MIBS_MAX_PHS_LENGTHS];
108 u8 u8PHSS;
109 u8 u8PHSV;
110 u8 reserved[5];
111 long PHSModifiedBytes;
112 unsigned long PHSModifiedNumPackets;
113 unsigned long PHSErrorNumPackets;
114};
115
116struct bcm_mibs_parameters {
117 u32 wmanIfSfid;
118 u32 wmanIfCmnCpsSfState;
119 u32 wmanIfCmnCpsMaxSustainedRate;
120 u32 wmanIfCmnCpsMaxTrafficBurst;
121 u32 wmanIfCmnCpsMinReservedRate;
122 u32 wmanIfCmnCpsToleratedJitter;
123 u32 wmanIfCmnCpsMaxLatency;
124 u32 wmanIfCmnCpsFixedVsVariableSduInd;
125 u32 wmanIfCmnCpsSduSize;
126 u32 wmanIfCmnCpsSfSchedulingType;
127 u32 wmanIfCmnCpsArqEnable;
128 u32 wmanIfCmnCpsArqWindowSize;
129 u32 wmanIfCmnCpsArqBlockLifetime;
130 u32 wmanIfCmnCpsArqSyncLossTimeout;
131 u32 wmanIfCmnCpsArqDeliverInOrder;
132 u32 wmanIfCmnCpsArqRxPurgeTimeout;
133 u32 wmanIfCmnCpsArqBlockSize;
134 u32 wmanIfCmnCpsMinRsvdTolerableRate;
135 u32 wmanIfCmnCpsReqTxPolicy;
136 u32 wmanIfCmnSfCsSpecification;
137 u32 wmanIfCmnCpsTargetSaid;
138};
139
140struct bcm_mibs_table {
141 unsigned long ulSFID;
142 unsigned short usVCID_Value;
143 unsigned int uiThreshold;
144 u8 u8TrafficPriority;
145 bool bValid;
146 bool bActive;
147 bool bActivateRequestSent;
148 u8 u8QueueType;
149 unsigned int uiMaxBucketSize;
150 unsigned int uiCurrentQueueDepthOnTarget;
151 unsigned int uiCurrentBytesOnHost;
152 unsigned int uiCurrentPacketsOnHost;
153 unsigned int uiDroppedCountBytes;
154 unsigned int uiDroppedCountPackets;
155 unsigned int uiSentBytes;
156 unsigned int uiSentPackets;
157 unsigned int uiCurrentDrainRate;
158 unsigned int uiThisPeriodSentBytes;
159 u64 liDrainCalculated;
160 unsigned int uiCurrentTokenCount;
161 u64 liLastUpdateTokenAt;
162 unsigned int uiMaxAllowedRate;
163 unsigned int NumOfPacketsSent;
164 unsigned char ucDirection;
165 unsigned short usCID;
166 struct bcm_mibs_parameters stMibsExtServiceFlowTable;
167 unsigned int uiCurrentRxRate;
168 unsigned int uiThisPeriodRxBytes;
169 unsigned int uiTotalRxBytes;
170 unsigned int uiTotalTxBytes;
171};
172
173struct bcm_mibs_dropped_cntrl_msg {
174 unsigned long cm_responses;
175 unsigned long cm_control_newdsx_multiclassifier_resp;
176 unsigned long link_control_resp;
177 unsigned long status_rsp;
178 unsigned long stats_pointer_resp;
179 unsigned long idle_mode_status;
180 unsigned long auth_ss_host_msg;
181 unsigned long low_priority_message;
182};
183
184struct bcm_host_stats_mibs {
185 struct bcm_mibs_host_info stHostInfo;
186 struct bcm_mibs_classifier_rule astClassifierTable[MIBS_MAX_CLASSIFIERS];
187 struct bcm_mibs_table astSFtable[MIBS_MAX_SERVICEFLOWS];
188 struct bcm_mibs_phs_rule astPhsRulesTable[MIBS_MAX_PHSRULES];
189 struct bcm_mibs_dropped_cntrl_msg stDroppedAppCntrlMsgs;
190};
191
192#endif
diff --git a/drivers/staging/bcm/IPv6Protocol.c b/drivers/staging/bcm/IPv6Protocol.c
deleted file mode 100644
index 27f3f416f184..000000000000
--- a/drivers/staging/bcm/IPv6Protocol.c
+++ /dev/null
@@ -1,476 +0,0 @@
1#include "headers.h"
2
3static bool MatchSrcIpv6Address(struct bcm_classifier_rule *pstClassifierRule,
4 struct bcm_ipv6_hdr *pstIpv6Header);
5static bool MatchDestIpv6Address(struct bcm_classifier_rule *pstClassifierRule,
6 struct bcm_ipv6_hdr *pstIpv6Header);
7static VOID DumpIpv6Header(struct bcm_ipv6_hdr *pstIpv6Header);
8
9static UCHAR *GetNextIPV6ChainedHeader(UCHAR **ppucPayload,
10 UCHAR *pucNextHeader, bool *bParseDone, USHORT *pusPayloadLength)
11{
12 UCHAR *pucRetHeaderPtr = NULL;
13 UCHAR *pucPayloadPtr = NULL;
14 USHORT usNextHeaderOffset = 0;
15 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
16
17 if ((ppucPayload == NULL) || (*pusPayloadLength == 0) ||
18 (*bParseDone)) {
19 *bParseDone = TRUE;
20 return NULL;
21 }
22
23 pucRetHeaderPtr = *ppucPayload;
24 pucPayloadPtr = *ppucPayload;
25
26 if (!pucRetHeaderPtr || !pucPayloadPtr) {
27 *bParseDone = TRUE;
28 return NULL;
29 }
30
31 /* Get the Nextt Header Type */
32 *bParseDone = false;
33
34
35 switch (*pucNextHeader) {
36 case IPV6HDR_TYPE_HOPBYHOP:
37 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
38 DBG_LVL_ALL, "\nIPv6 HopByHop Header");
39 usNextHeaderOffset += sizeof(struct bcm_ipv6_options_hdr);
40 break;
41
42 case IPV6HDR_TYPE_ROUTING:
43 {
44 struct bcm_ipv6_routing_hdr *pstIpv6RoutingHeader;
45
46 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
47 DBG_LVL_ALL, "\nIPv6 Routing Header");
48 pstIpv6RoutingHeader =
49 (struct bcm_ipv6_routing_hdr *)pucPayloadPtr;
50 usNextHeaderOffset += sizeof(struct bcm_ipv6_routing_hdr);
51 usNextHeaderOffset += pstIpv6RoutingHeader->ucNumAddresses *
52 IPV6_ADDRESS_SIZEINBYTES;
53 }
54 break;
55
56 case IPV6HDR_TYPE_FRAGMENTATION:
57 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
58 DBG_LVL_ALL,
59 "\nIPv6 Fragmentation Header");
60 usNextHeaderOffset += sizeof(struct bcm_ipv6_fragment_hdr);
61 break;
62
63 case IPV6HDR_TYPE_DESTOPTS:
64 {
65 struct bcm_ipv6_dest_options_hdr *pstIpv6DestOptsHdr =
66 (struct bcm_ipv6_dest_options_hdr *)pucPayloadPtr;
67 int nTotalOptions = pstIpv6DestOptsHdr->ucHdrExtLen;
68
69 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
70 DBG_LVL_ALL,
71 "\nIPv6 DestOpts Header Header");
72 usNextHeaderOffset += sizeof(struct bcm_ipv6_dest_options_hdr);
73 usNextHeaderOffset += nTotalOptions *
74 IPV6_DESTOPTS_HDR_OPTIONSIZE;
75 }
76 break;
77
78
79 case IPV6HDR_TYPE_AUTHENTICATION:
80 {
81 struct bcm_ipv6_authentication_hdr *pstIpv6AuthHdr =
82 (struct bcm_ipv6_authentication_hdr *)pucPayloadPtr;
83 int nHdrLen = pstIpv6AuthHdr->ucLength;
84
85 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
86 DBG_LVL_ALL,
87 "\nIPv6 Authentication Header");
88 usNextHeaderOffset += nHdrLen * 4;
89 }
90 break;
91
92 case IPV6HDR_TYPE_ENCRYPTEDSECURITYPAYLOAD:
93 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
94 DBG_LVL_ALL,
95 "\nIPv6 Encrypted Security Payload Header");
96 *bParseDone = TRUE;
97 break;
98
99 case IPV6_ICMP_HDR_TYPE:
100 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
101 DBG_LVL_ALL, "\nICMP Header");
102 *bParseDone = TRUE;
103 break;
104
105 case TCP_HEADER_TYPE:
106 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
107 DBG_LVL_ALL, "\nTCP Header");
108 *bParseDone = TRUE;
109 break;
110
111 case UDP_HEADER_TYPE:
112 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
113 DBG_LVL_ALL, "\nUDP Header");
114 *bParseDone = TRUE;
115 break;
116
117 default:
118 *bParseDone = TRUE;
119 break;
120 }
121
122 if (*bParseDone == false) {
123 if (*pusPayloadLength <= usNextHeaderOffset) {
124 *bParseDone = TRUE;
125 } else {
126 *pucNextHeader = *pucPayloadPtr;
127 pucPayloadPtr += usNextHeaderOffset;
128 (*pusPayloadLength) -= usNextHeaderOffset;
129 }
130
131 }
132
133 *ppucPayload = pucPayloadPtr;
134 return pucRetHeaderPtr;
135}
136
137
138static UCHAR GetIpv6ProtocolPorts(UCHAR *pucPayload, USHORT *pusSrcPort,
139 USHORT *pusDestPort, USHORT usPayloadLength, UCHAR ucNextHeader)
140{
141 UCHAR *pIpv6HdrScanContext = pucPayload;
142 bool bDone = false;
143 UCHAR ucHeaderType = 0;
144 UCHAR *pucNextHeader = NULL;
145 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
146
147 if (!pucPayload || (usPayloadLength == 0))
148 return 0;
149
150 *pusSrcPort = *pusDestPort = 0;
151 ucHeaderType = ucNextHeader;
152 while (!bDone) {
153 pucNextHeader = GetNextIPV6ChainedHeader(&pIpv6HdrScanContext,
154 &ucHeaderType,
155 &bDone,
156 &usPayloadLength);
157 if (bDone) {
158 if ((ucHeaderType == TCP_HEADER_TYPE) ||
159 (ucHeaderType == UDP_HEADER_TYPE)) {
160 *pusSrcPort = *((PUSHORT)(pucNextHeader));
161 *pusDestPort = *((PUSHORT)(pucNextHeader+2));
162 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
163 DBG_LVL_ALL,
164 "\nProtocol Ports - Src Port :0x%x Dest Port : 0x%x",
165 ntohs(*pusSrcPort),
166 ntohs(*pusDestPort));
167 }
168 break;
169
170 }
171 }
172 return ucHeaderType;
173}
174
175
176/*
177 * Arg 1 struct bcm_mini_adapter *Adapter is a pointer ot the driver control
178 * structure
179 * Arg 2 PVOID pcIpHeader is a pointer to the IP header of the packet
180 */
181USHORT IpVersion6(struct bcm_mini_adapter *Adapter, PVOID pcIpHeader,
182 struct bcm_classifier_rule *pstClassifierRule)
183{
184 USHORT ushDestPort = 0;
185 USHORT ushSrcPort = 0;
186 UCHAR ucNextProtocolAboveIP = 0;
187 struct bcm_ipv6_hdr *pstIpv6Header = NULL;
188 bool bClassificationSucceed = false;
189
190 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
191 DBG_LVL_ALL, "IpVersion6 ==========>\n");
192
193 pstIpv6Header = pcIpHeader;
194
195 DumpIpv6Header(pstIpv6Header);
196
197 /*
198 * Try to get the next higher layer protocol
199 * and the Ports Nos if TCP or UDP
200 */
201 ucNextProtocolAboveIP = GetIpv6ProtocolPorts((UCHAR *)(pcIpHeader +
202 sizeof(struct bcm_ipv6_hdr)),
203 &ushSrcPort,
204 &ushDestPort,
205 pstIpv6Header->usPayloadLength,
206 pstIpv6Header->ucNextHeader);
207
208 do {
209 if (pstClassifierRule->ucDirection == 0) {
210 /*
211 * cannot be processed for classification.
212 * it is a down link connection
213 */
214 break;
215 }
216
217 if (!pstClassifierRule->bIpv6Protocol) {
218 /*
219 * We are looking for Ipv6 Classifiers
220 * Lets ignore this classifier and try the next one
221 */
222 break;
223 }
224
225 bClassificationSucceed = MatchSrcIpv6Address(pstClassifierRule,
226 pstIpv6Header);
227 if (!bClassificationSucceed)
228 break;
229
230 bClassificationSucceed = MatchDestIpv6Address(pstClassifierRule,
231 pstIpv6Header);
232 if (!bClassificationSucceed)
233 break;
234
235 /*
236 * Match the protocol type.
237 * For IPv6 the next protocol at end of
238 * Chain of IPv6 prot headers
239 */
240 bClassificationSucceed = MatchProtocol(pstClassifierRule,
241 ucNextProtocolAboveIP);
242 if (!bClassificationSucceed)
243 break;
244
245 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
246 DBG_LVL_ALL, "\nIPv6 Protocol Matched");
247
248 if ((ucNextProtocolAboveIP == TCP_HEADER_TYPE) ||
249 (ucNextProtocolAboveIP == UDP_HEADER_TYPE)) {
250 /* Match Src Port */
251 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
252 DBG_LVL_ALL, "\nIPv6 Source Port:%x\n",
253 ntohs(ushSrcPort));
254 bClassificationSucceed = MatchSrcPort(pstClassifierRule,
255 ntohs(ushSrcPort));
256 if (!bClassificationSucceed)
257 break;
258
259 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
260 DBG_LVL_ALL, "\nIPv6 Src Port Matched");
261
262 /* Match Dest Port */
263 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
264 DBG_LVL_ALL,
265 "\nIPv6 Destination Port:%x\n",
266 ntohs(ushDestPort));
267 bClassificationSucceed = MatchDestPort(pstClassifierRule,
268 ntohs(ushDestPort));
269 if (!bClassificationSucceed)
270 break;
271 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
272 DBG_LVL_ALL,
273 "\nIPv6 Dest Port Matched");
274 }
275 } while (0);
276
277 if (bClassificationSucceed == TRUE) {
278 INT iMatchedSFQueueIndex = 0;
279
280 iMatchedSFQueueIndex = SearchSfid(Adapter,
281 pstClassifierRule->ulSFID);
282 if ((iMatchedSFQueueIndex >= NO_OF_QUEUES) ||
283 (Adapter->PackInfo[iMatchedSFQueueIndex].bActive == false))
284 bClassificationSucceed = false;
285 }
286
287 return bClassificationSucceed;
288}
289
290
291static bool MatchSrcIpv6Address(struct bcm_classifier_rule *pstClassifierRule,
292 struct bcm_ipv6_hdr *pstIpv6Header)
293{
294 UINT uiLoopIndex = 0;
295 UINT uiIpv6AddIndex = 0;
296 UINT uiIpv6AddrNoLongWords = 4;
297 ULONG aulSrcIP[4];
298 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
299 union u_ip_address *src_addr = &pstClassifierRule->stSrcIpAddress;
300
301 /*
302 * This is the no. of Src Addresses ie Range of IP Addresses contained
303 * in the classifier rule for which we need to match
304 */
305 UINT uiCountIPSrcAddresses =
306 (UINT)pstClassifierRule->ucIPSourceAddressLength;
307
308
309 if (uiCountIPSrcAddresses == 0)
310 return TRUE;
311
312
313 /* First Convert the Ip Address in the packet to Host Endian order */
314 for (uiIpv6AddIndex = 0;
315 uiIpv6AddIndex < uiIpv6AddrNoLongWords;
316 uiIpv6AddIndex++)
317 aulSrcIP[uiIpv6AddIndex] =
318 ntohl(pstIpv6Header->ulSrcIpAddress[uiIpv6AddIndex]);
319
320 for (uiLoopIndex = 0;
321 uiLoopIndex < uiCountIPSrcAddresses;
322 uiLoopIndex += uiIpv6AddrNoLongWords) {
323 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
324 "\n Src Ipv6 Address In Received Packet :\n ");
325 DumpIpv6Address(aulSrcIP);
326 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
327 "\n Src Ipv6 Mask In Classifier Rule:\n");
328 DumpIpv6Address(&src_addr->ulIpv6Mask[uiLoopIndex]);
329 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
330 "\n Src Ipv6 Address In Classifier Rule :\n");
331 DumpIpv6Address(&src_addr->ulIpv6Addr[uiLoopIndex]);
332
333 for (uiIpv6AddIndex = 0;
334 uiIpv6AddIndex < uiIpv6AddrNoLongWords;
335 uiIpv6AddIndex++) {
336 if ((src_addr->ulIpv6Mask[uiLoopIndex+uiIpv6AddIndex] &
337 aulSrcIP[uiIpv6AddIndex]) !=
338 src_addr->ulIpv6Addr[uiLoopIndex+uiIpv6AddIndex]) {
339 /*
340 * Match failed for current Ipv6 Address
341 * Try next Ipv6 Address
342 */
343 break;
344 }
345
346 if (uiIpv6AddIndex == uiIpv6AddrNoLongWords-1) {
347 /* Match Found */
348 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
349 DBG_LVL_ALL,
350 "Ipv6 Src Ip Address Matched\n");
351 return TRUE;
352 }
353 }
354 }
355 return false;
356}
357
358static bool MatchDestIpv6Address(struct bcm_classifier_rule *pstClassifierRule,
359 struct bcm_ipv6_hdr *pstIpv6Header)
360{
361 UINT uiLoopIndex = 0;
362 UINT uiIpv6AddIndex = 0;
363 UINT uiIpv6AddrNoLongWords = 4;
364 ULONG aulDestIP[4];
365 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
366 union u_ip_address *dest_addr = &pstClassifierRule->stDestIpAddress;
367
368 /*
369 * This is the no. of Destination Addresses
370 * ie Range of IP Addresses contained in the classifier rule
371 * for which we need to match
372 */
373 UINT uiCountIPDestinationAddresses =
374 (UINT)pstClassifierRule->ucIPDestinationAddressLength;
375
376 if (uiCountIPDestinationAddresses == 0)
377 return TRUE;
378
379
380 /* First Convert the Ip Address in the packet to Host Endian order */
381 for (uiIpv6AddIndex = 0;
382 uiIpv6AddIndex < uiIpv6AddrNoLongWords;
383 uiIpv6AddIndex++)
384 aulDestIP[uiIpv6AddIndex] =
385 ntohl(pstIpv6Header->ulDestIpAddress[uiIpv6AddIndex]);
386
387 for (uiLoopIndex = 0;
388 uiLoopIndex < uiCountIPDestinationAddresses;
389 uiLoopIndex += uiIpv6AddrNoLongWords) {
390 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
391 "\n Destination Ipv6 Address In Received Packet :\n ");
392 DumpIpv6Address(aulDestIP);
393 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
394 "\n Destination Ipv6 Mask In Classifier Rule :\n");
395 DumpIpv6Address(&dest_addr->ulIpv6Mask[uiLoopIndex]);
396 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
397 "\n Destination Ipv6 Address In Classifier Rule :\n");
398 DumpIpv6Address(&dest_addr->ulIpv6Addr[uiLoopIndex]);
399
400 for (uiIpv6AddIndex = 0;
401 uiIpv6AddIndex < uiIpv6AddrNoLongWords;
402 uiIpv6AddIndex++) {
403 if ((dest_addr->ulIpv6Mask[uiLoopIndex+uiIpv6AddIndex] &
404 aulDestIP[uiIpv6AddIndex]) !=
405 dest_addr->ulIpv6Addr[uiLoopIndex+uiIpv6AddIndex]) {
406 /*
407 * Match failed for current Ipv6 Address.
408 * Try next Ipv6 Address
409 */
410 break;
411 }
412
413 if (uiIpv6AddIndex == uiIpv6AddrNoLongWords-1) {
414 /* Match Found */
415 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG,
416 DBG_LVL_ALL,
417 "Ipv6 Destination Ip Address Matched\n");
418 return TRUE;
419 }
420 }
421 }
422 return false;
423
424}
425
426VOID DumpIpv6Address(ULONG *puIpv6Address)
427{
428 UINT uiIpv6AddrNoLongWords = 4;
429 UINT uiIpv6AddIndex = 0;
430 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
431
432 for (uiIpv6AddIndex = 0;
433 uiIpv6AddIndex < uiIpv6AddrNoLongWords;
434 uiIpv6AddIndex++) {
435 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
436 ":%lx", puIpv6Address[uiIpv6AddIndex]);
437 }
438
439}
440
441static VOID DumpIpv6Header(struct bcm_ipv6_hdr *pstIpv6Header)
442{
443 UCHAR ucVersion;
444 UCHAR ucPrio;
445 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
446
447 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
448 "----Ipv6 Header---");
449 ucVersion = pstIpv6Header->ucVersionPrio & 0xf0;
450 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
451 "Version : %x\n", ucVersion);
452 ucPrio = pstIpv6Header->ucVersionPrio & 0x0f;
453 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
454 "Priority : %x\n", ucPrio);
455 /*
456 * BCM_DEBUG_PRINT( Adapter,DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
457 * "Flow Label : %x\n",(pstIpv6Header->ucVersionPrio &0xf0);
458 */
459 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
460 "Payload Length : %x\n",
461 ntohs(pstIpv6Header->usPayloadLength));
462 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
463 "Next Header : %x\n", pstIpv6Header->ucNextHeader);
464 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
465 "Hop Limit : %x\n", pstIpv6Header->ucHopLimit);
466 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
467 "Src Address :\n");
468 DumpIpv6Address(pstIpv6Header->ulSrcIpAddress);
469 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
470 "Dest Address :\n");
471 DumpIpv6Address(pstIpv6Header->ulDestIpAddress);
472 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV6_DBG, DBG_LVL_ALL,
473 "----Ipv6 Header End---");
474
475
476}
diff --git a/drivers/staging/bcm/IPv6ProtocolHdr.h b/drivers/staging/bcm/IPv6ProtocolHdr.h
deleted file mode 100644
index 96b36a579af2..000000000000
--- a/drivers/staging/bcm/IPv6ProtocolHdr.h
+++ /dev/null
@@ -1,85 +0,0 @@
1#ifndef _IPV6_PROTOCOL_DEFINES_
2#define _IPV6_PROTOCOL_DEFINES_
3
4#define IPV6HDR_TYPE_HOPBYHOP 0x0
5#define IPV6HDR_TYPE_ROUTING 0x2B
6#define IPV6HDR_TYPE_FRAGMENTATION 0x2C
7#define IPV6HDR_TYPE_DESTOPTS 0x3c
8#define IPV6HDR_TYPE_AUTHENTICATION 0x33
9#define IPV6HDR_TYPE_ENCRYPTEDSECURITYPAYLOAD 0x34
10#define MASK_IPV6_CS_SPEC 0x2
11
12#define TCP_HEADER_TYPE 0x6
13#define UDP_HEADER_TYPE 0x11
14#define IPV6_ICMP_HDR_TYPE 0x2
15#define IPV6_FLOWLABEL_BITOFFSET 9
16
17#define IPV6_MAX_CHAINEDHDR_BUFFBYTES 0x64
18/*
19 * Size of Dest Options field of Destinations Options Header
20 * in bytes.
21 */
22#define IPV6_DESTOPTS_HDR_OPTIONSIZE 0x8
23
24struct bcm_ipv6_hdr {
25 unsigned char ucVersionPrio;
26 unsigned char aucFlowLabel[3];
27 unsigned short usPayloadLength;
28 unsigned char ucNextHeader;
29 unsigned char ucHopLimit;
30 unsigned long ulSrcIpAddress[4];
31 unsigned long ulDestIpAddress[4];
32};
33
34struct bcm_ipv6_routing_hdr {
35 unsigned char ucNextHeader;
36 unsigned char ucRoutingType;
37 unsigned char ucNumAddresses;
38 unsigned char ucNextAddress;
39 unsigned long ulReserved;
40};
41
42struct bcm_ipv6_fragment_hdr {
43 unsigned char ucNextHeader;
44 unsigned char ucReserved;
45 unsigned short usFragmentOffset;
46 unsigned long ulIdentification;
47};
48
49struct bcm_ipv6_dest_options_hdr {
50 unsigned char ucNextHeader;
51 unsigned char ucHdrExtLen;
52 unsigned char ucDestOptions[6];
53};
54
55struct bcm_ipv6_options_hdr {
56 unsigned char ucNextHeader;
57 unsigned char ucMisc[3];
58 unsigned long ulJumboPayloadLen;
59};
60
61struct bcm_ipv6_authentication_hdr {
62 unsigned char ucNextHeader;
63 unsigned char ucLength;
64 unsigned short usReserved;
65 unsigned long ulSecurityParametersIndex;
66};
67
68enum bcm_ipaddr_context {
69 eSrcIpAddress,
70 eDestIpAddress
71};
72
73/* Function Prototypes */
74
75unsigned short IpVersion6(struct bcm_mini_adapter *Adapter, /* < Pointer to the driver control structure */
76 void *pcIpHeader, /* <Pointer to the IP Hdr of the packet */
77 struct bcm_classifier_rule *pstClassifierRule);
78
79void DumpIpv6Address(unsigned long *puIpv6Address);
80
81extern bool MatchSrcPort(struct bcm_classifier_rule *pstClassifierRule, unsigned short ushSrcPort);
82extern bool MatchDestPort(struct bcm_classifier_rule *pstClassifierRule, unsigned short ushSrcPort);
83extern bool MatchProtocol(struct bcm_classifier_rule *pstClassifierRule, unsigned char ucProtocol);
84
85#endif
diff --git a/drivers/staging/bcm/InterfaceAdapter.h b/drivers/staging/bcm/InterfaceAdapter.h
deleted file mode 100644
index 06a6b18bca48..000000000000
--- a/drivers/staging/bcm/InterfaceAdapter.h
+++ /dev/null
@@ -1,79 +0,0 @@
1#ifndef _INTERFACE_ADAPTER_H
2#define _INTERFACE_ADAPTER_H
3
4struct bcm_bulk_endpoint_in {
5 char *bulk_in_buffer;
6 size_t bulk_in_size;
7 unsigned char bulk_in_endpointAddr;
8 unsigned int bulk_in_pipe;
9};
10
11struct bcm_bulk_endpoint_out {
12 unsigned char bulk_out_buffer;
13 size_t bulk_out_size;
14 unsigned char bulk_out_endpointAddr;
15 unsigned int bulk_out_pipe;
16 /* this is used when int out endpoint is used as bulk out end point */
17 unsigned char int_out_interval;
18};
19
20struct bcm_intr_endpoint_in {
21 char *int_in_buffer;
22 size_t int_in_size;
23 unsigned char int_in_endpointAddr;
24 unsigned char int_in_interval;
25 unsigned int int_in_pipe;
26};
27
28struct bcm_intr_endpoint_out {
29 char *int_out_buffer;
30 size_t int_out_size;
31 unsigned char int_out_endpointAddr;
32 unsigned char int_out_interval;
33 unsigned int int_out_pipe;
34};
35
36struct bcm_usb_tcb {
37 struct urb *urb;
38 void *psIntfAdapter;
39 bool bUsed;
40};
41
42struct bcm_usb_rcb {
43 struct urb *urb;
44 void *psIntfAdapter;
45 bool bUsed;
46};
47
48/*
49 * This is the interface specific Sub-Adapter
50 * Structure.
51 */
52struct bcm_interface_adapter {
53 struct usb_device *udev;
54 struct usb_interface *interface;
55 /* Bulk endpoint in info */
56 struct bcm_bulk_endpoint_in sBulkIn;
57 /* Bulk endpoint out info */
58 struct bcm_bulk_endpoint_out sBulkOut;
59 /* Interrupt endpoint in info */
60 struct bcm_intr_endpoint_in sIntrIn;
61 /* Interrupt endpoint out info */
62 struct bcm_intr_endpoint_out sIntrOut;
63 unsigned long ulInterruptData[2];
64 struct urb *psInterruptUrb;
65 struct bcm_usb_tcb asUsbTcb[MAXIMUM_USB_TCB];
66 struct bcm_usb_rcb asUsbRcb[MAXIMUM_USB_RCB];
67 atomic_t uNumTcbUsed;
68 atomic_t uCurrTcb;
69 atomic_t uNumRcbUsed;
70 atomic_t uCurrRcb;
71 struct bcm_mini_adapter *psAdapter;
72 bool bFlashBoot;
73 bool bHighSpeedDevice;
74 bool bSuspended;
75 bool bPreparingForBusSuspend;
76 struct work_struct usbSuspendWork;
77};
78
79#endif
diff --git a/drivers/staging/bcm/InterfaceDld.c b/drivers/staging/bcm/InterfaceDld.c
deleted file mode 100644
index abc7a7ab782a..000000000000
--- a/drivers/staging/bcm/InterfaceDld.c
+++ /dev/null
@@ -1,317 +0,0 @@
1#include "headers.h"
2
3int InterfaceFileDownload(PVOID arg, struct file *flp, unsigned int on_chip_loc)
4{
5 /* unsigned int reg = 0; */
6 mm_segment_t oldfs = {0};
7 int errno = 0, len = 0; /* ,is_config_file = 0 */
8 loff_t pos = 0;
9 struct bcm_interface_adapter *psIntfAdapter = arg;
10 /* struct bcm_mini_adapter *Adapter = psIntfAdapter->psAdapter; */
11 char *buff = kmalloc(MAX_TRANSFER_CTRL_BYTE_USB, GFP_KERNEL);
12
13 if (!buff)
14 return -ENOMEM;
15
16 while (1) {
17 oldfs = get_fs();
18 set_fs(get_ds());
19 len = vfs_read(flp, (void __force __user *)buff,
20 MAX_TRANSFER_CTRL_BYTE_USB, &pos);
21 set_fs(oldfs);
22 if (len <= 0) {
23 if (len < 0)
24 errno = len;
25 else
26 errno = 0;
27 break;
28 }
29 /* BCM_DEBUG_PRINT_BUFFER(Adapter,DBG_TYPE_INITEXIT, MP_INIT,
30 * DBG_LVL_ALL, buff,
31 * MAX_TRANSFER_CTRL_BYTE_USB);
32 */
33 errno = InterfaceWRM(psIntfAdapter, on_chip_loc, buff, len);
34 if (errno)
35 break;
36 on_chip_loc += MAX_TRANSFER_CTRL_BYTE_USB;
37 }
38
39 kfree(buff);
40 return errno;
41}
42
43int InterfaceFileReadbackFromChip(PVOID arg, struct file *flp,
44 unsigned int on_chip_loc)
45{
46 char *buff, *buff_readback;
47 unsigned int reg = 0;
48 mm_segment_t oldfs = {0};
49 int errno = 0, len = 0, is_config_file = 0;
50 loff_t pos = 0;
51 static int fw_down;
52 INT Status = STATUS_SUCCESS;
53 struct bcm_interface_adapter *psIntfAdapter = arg;
54 int bytes;
55
56 buff = kzalloc(MAX_TRANSFER_CTRL_BYTE_USB, GFP_DMA);
57 buff_readback = kzalloc(MAX_TRANSFER_CTRL_BYTE_USB , GFP_DMA);
58 if (!buff || !buff_readback) {
59 kfree(buff);
60 kfree(buff_readback);
61
62 return -ENOMEM;
63 }
64
65 is_config_file = (on_chip_loc == CONFIG_BEGIN_ADDR) ? 1 : 0;
66
67 while (1) {
68 oldfs = get_fs();
69 set_fs(get_ds());
70 len = vfs_read(flp, (void __force __user *)buff,
71 MAX_TRANSFER_CTRL_BYTE_USB, &pos);
72 set_fs(oldfs);
73 fw_down++;
74
75 if (len <= 0) {
76 if (len < 0)
77 errno = len;
78 else
79 errno = 0;
80 break;
81 }
82
83 bytes = InterfaceRDM(psIntfAdapter, on_chip_loc,
84 buff_readback, len);
85 if (bytes < 0) {
86 Status = bytes;
87 goto exit;
88 }
89 reg++;
90 if ((len-sizeof(unsigned int)) < 4) {
91 if (memcmp(buff_readback, buff, len)) {
92 Status = -EIO;
93 goto exit;
94 }
95 } else {
96 len -= 4;
97
98 while (len) {
99 if (*(unsigned int *)&buff_readback[len] !=
100 *(unsigned int *)&buff[len]) {
101 Status = -EIO;
102 goto exit;
103 }
104 len -= 4;
105 }
106 }
107 on_chip_loc += MAX_TRANSFER_CTRL_BYTE_USB;
108 } /* End of while(1) */
109
110exit:
111 kfree(buff);
112 kfree(buff_readback);
113 return Status;
114}
115
116static int bcm_download_config_file(struct bcm_mini_adapter *Adapter,
117 struct bcm_firmware_info *psFwInfo)
118{
119 int retval = STATUS_SUCCESS;
120 B_UINT32 value = 0;
121
122 if (Adapter->pstargetparams == NULL) {
123 Adapter->pstargetparams =
124 kmalloc(sizeof(struct bcm_target_params), GFP_KERNEL);
125 if (Adapter->pstargetparams == NULL)
126 return -ENOMEM;
127 }
128
129 if (psFwInfo->u32FirmwareLength != sizeof(struct bcm_target_params))
130 return -EIO;
131
132 retval = copy_from_user(Adapter->pstargetparams,
133 psFwInfo->pvMappedFirmwareAddress,
134 psFwInfo->u32FirmwareLength);
135 if (retval) {
136 kfree(Adapter->pstargetparams);
137 Adapter->pstargetparams = NULL;
138 return -EFAULT;
139 }
140
141 /* Parse the structure and then Download the Firmware */
142 beceem_parse_target_struct(Adapter);
143
144 /* Initializing the NVM. */
145 BcmInitNVM(Adapter);
146 retval = InitLedSettings(Adapter);
147
148 if (retval)
149 return retval;
150
151 if (Adapter->LEDInfo.led_thread_running &
152 BCM_LED_THREAD_RUNNING_ACTIVELY) {
153 Adapter->LEDInfo.bLedInitDone = false;
154 Adapter->DriverState = DRIVER_INIT;
155 wake_up(&Adapter->LEDInfo.notify_led_event);
156 }
157
158 if (Adapter->LEDInfo.led_thread_running &
159 BCM_LED_THREAD_RUNNING_ACTIVELY) {
160 Adapter->DriverState = FW_DOWNLOAD;
161 wake_up(&Adapter->LEDInfo.notify_led_event);
162 }
163
164 /* Initialize the DDR Controller */
165 retval = ddr_init(Adapter);
166 if (retval)
167 return retval;
168
169 value = 0;
170 wrmalt(Adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 4,
171 &value, sizeof(value));
172 wrmalt(Adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 8,
173 &value, sizeof(value));
174
175 if (Adapter->eNVMType == NVM_FLASH) {
176 retval = PropagateCalParamsFromFlashToMemory(Adapter);
177 if (retval)
178 return retval;
179 }
180
181 retval = buffDnldVerify(Adapter, (PUCHAR)Adapter->pstargetparams,
182 sizeof(struct bcm_target_params), CONFIG_BEGIN_ADDR);
183
184 if (retval)
185 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT,
186 MP_INIT, DBG_LVL_ALL,
187 "configuration file not downloaded properly");
188 else
189 Adapter->bCfgDownloaded = TRUE;
190
191 return retval;
192}
193
194int bcm_ioctl_fw_download(struct bcm_mini_adapter *Adapter,
195 struct bcm_firmware_info *psFwInfo)
196{
197 int retval = STATUS_SUCCESS;
198 PUCHAR buff = NULL;
199
200 /* Config File is needed for the Driver to download the Config file and
201 * Firmware. Check for the Config file to be first to be sent from the
202 * Application
203 */
204 atomic_set(&Adapter->uiMBupdate, false);
205 if (!Adapter->bCfgDownloaded &&
206 psFwInfo->u32StartingAddress != CONFIG_BEGIN_ADDR) {
207 /* Can't Download Firmware. */
208 return -EINVAL;
209 }
210
211 /* If Config File, Finish the DDR Settings and then Download CFG File */
212 if (psFwInfo->u32StartingAddress == CONFIG_BEGIN_ADDR) {
213 retval = bcm_download_config_file(Adapter, psFwInfo);
214 } else {
215 buff = kzalloc(psFwInfo->u32FirmwareLength, GFP_KERNEL);
216 if (buff == NULL)
217 return -ENOMEM;
218
219 retval = copy_from_user(buff,
220 psFwInfo->pvMappedFirmwareAddress,
221 psFwInfo->u32FirmwareLength);
222 if (retval != STATUS_SUCCESS) {
223 retval = -EFAULT;
224 goto error;
225 }
226
227 retval = buffDnldVerify(Adapter,
228 buff,
229 psFwInfo->u32FirmwareLength,
230 psFwInfo->u32StartingAddress);
231
232 if (retval != STATUS_SUCCESS)
233 goto error;
234 }
235
236error:
237 kfree(buff);
238 return retval;
239}
240
241static INT buffDnld(struct bcm_mini_adapter *Adapter,
242 PUCHAR mappedbuffer, UINT u32FirmwareLength,
243 ULONG u32StartingAddress)
244{
245 unsigned int len = 0;
246 int retval = STATUS_SUCCESS;
247
248 len = u32FirmwareLength;
249
250 while (u32FirmwareLength) {
251 len = MIN_VAL(u32FirmwareLength, MAX_TRANSFER_CTRL_BYTE_USB);
252 retval = wrm(Adapter, u32StartingAddress, mappedbuffer, len);
253
254 if (retval)
255 break;
256 u32StartingAddress += len;
257 u32FirmwareLength -= len;
258 mappedbuffer += len;
259 }
260 return retval;
261}
262
263static INT buffRdbkVerify(struct bcm_mini_adapter *Adapter,
264 PUCHAR mappedbuffer, UINT u32FirmwareLength,
265 ULONG u32StartingAddress)
266{
267 UINT len = u32FirmwareLength;
268 INT retval = STATUS_SUCCESS;
269 PUCHAR readbackbuff = kzalloc(MAX_TRANSFER_CTRL_BYTE_USB, GFP_KERNEL);
270 int bytes;
271
272 if (NULL == readbackbuff)
273 return -ENOMEM;
274
275 while (u32FirmwareLength && !retval) {
276 len = MIN_VAL(u32FirmwareLength, MAX_TRANSFER_CTRL_BYTE_USB);
277 bytes = rdm(Adapter, u32StartingAddress, readbackbuff, len);
278
279 if (bytes < 0) {
280 retval = bytes;
281 break;
282 }
283
284 if (memcmp(readbackbuff, mappedbuffer, len) != 0) {
285 pr_err("%s() failed. The firmware doesn't match what was written",
286 __func__);
287 retval = -EIO;
288 }
289
290 u32StartingAddress += len;
291 u32FirmwareLength -= len;
292 mappedbuffer += len;
293
294 } /* end of while (u32FirmwareLength && !retval) */
295 kfree(readbackbuff);
296 return retval;
297}
298
299INT buffDnldVerify(struct bcm_mini_adapter *Adapter,
300 unsigned char *mappedbuffer,
301 unsigned int u32FirmwareLength,
302 unsigned long u32StartingAddress)
303{
304 INT status = STATUS_SUCCESS;
305
306 status = buffDnld(Adapter, mappedbuffer,
307 u32FirmwareLength, u32StartingAddress);
308 if (status != STATUS_SUCCESS)
309 goto error;
310
311 status = buffRdbkVerify(Adapter, mappedbuffer,
312 u32FirmwareLength, u32StartingAddress);
313 if (status != STATUS_SUCCESS)
314 goto error;
315error:
316 return status;
317}
diff --git a/drivers/staging/bcm/InterfaceIdleMode.c b/drivers/staging/bcm/InterfaceIdleMode.c
deleted file mode 100644
index 612c89fba341..000000000000
--- a/drivers/staging/bcm/InterfaceIdleMode.c
+++ /dev/null
@@ -1,274 +0,0 @@
1#include "headers.h"
2
3/*
4Function: InterfaceIdleModeWakeup
5
6Description: This is the hardware specific Function for
7 waking up HW device from Idle mode.
8 A software abort pattern is written to the
9 device to wake it and necessary power state
10 transitions from host are performed here.
11
12Input parameters: IN struct bcm_mini_adapter *Adapter
13 - Miniport Adapter Context
14
15Return: BCM_STATUS_SUCCESS - If Wakeup of the HW Interface
16 was successful.
17 Other - If an error occurred.
18*/
19
20/*
21Function: InterfaceIdleModeRespond
22
23Description: This is the hardware specific Function for
24 responding to Idle mode request from target.
25 Necessary power state transitions from host for
26 idle mode or other device specific initializations
27 are performed here.
28
29Input parameters: IN struct bcm_mini_adapter * Adapter
30 - Miniport Adapter Context
31
32Return: BCM_STATUS_SUCCESS - If Idle mode response related
33 HW configuration was successful.
34 Other - If an error occurred.
35*/
36
37/*
38"dmem bfc02f00 100" tells how many time device went in Idle mode.
39this value will be at address bfc02fa4.just before value d0ea1dle.
40
41Set time value by writing at bfc02f98 7d0
42
43checking the Ack timer expire on kannon by running command
44d qcslog .. if it shows e means host has not send response
45to f/w with in 200 ms. Response should be
46send to f/w with in 200 ms after the Idle/Shutdown req issued
47
48*/
49
50
51int InterfaceIdleModeRespond(struct bcm_mini_adapter *Adapter,
52 unsigned int *puiBuffer)
53{
54 int status = STATUS_SUCCESS;
55 unsigned int uiRegRead = 0;
56 int bytes;
57
58 if (ntohl(*puiBuffer) == GO_TO_IDLE_MODE_PAYLOAD) {
59 if (ntohl(*(puiBuffer+1)) == 0) {
60
61 status = wrmalt(Adapter, SW_ABORT_IDLEMODE_LOC,
62 &uiRegRead, sizeof(uiRegRead));
63 if (status)
64 return status;
65
66 if (Adapter->ulPowerSaveMode ==
67 DEVICE_POWERSAVE_MODE_AS_MANUAL_CLOCK_GATING) {
68 uiRegRead = 0x00000000;
69 status = wrmalt(Adapter,
70 DEBUG_INTERRUPT_GENERATOR_REGISTOR,
71 &uiRegRead, sizeof(uiRegRead));
72 if (status)
73 return status;
74 }
75 /* Below Register should not br read in case of
76 * Manual and Protocol Idle mode */
77 else if (Adapter->ulPowerSaveMode !=
78 DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE) {
79 /* clear on read Register */
80 bytes = rdmalt(Adapter, DEVICE_INT_OUT_EP_REG0,
81 &uiRegRead, sizeof(uiRegRead));
82 if (bytes < 0) {
83 status = bytes;
84 return status;
85 }
86 /* clear on read Register */
87 bytes = rdmalt(Adapter, DEVICE_INT_OUT_EP_REG1,
88 &uiRegRead, sizeof(uiRegRead));
89 if (bytes < 0) {
90 status = bytes;
91 return status;
92 }
93 }
94
95 /* Set Idle Mode Flag to False and
96 * Clear IdleMode reg. */
97 Adapter->IdleMode = false;
98 Adapter->bTriedToWakeUpFromlowPowerMode = false;
99
100 wake_up(&Adapter->lowpower_mode_wait_queue);
101
102 } else {
103 if (TRUE == Adapter->IdleMode)
104 return status;
105
106 uiRegRead = 0;
107
108 if (Adapter->chip_id == BCS220_2 ||
109 Adapter->chip_id == BCS220_2BC ||
110 Adapter->chip_id == BCS250_BC ||
111 Adapter->chip_id == BCS220_3) {
112
113 bytes = rdmalt(Adapter, HPM_CONFIG_MSW,
114 &uiRegRead, sizeof(uiRegRead));
115 if (bytes < 0) {
116 status = bytes;
117 return status;
118 }
119
120
121 uiRegRead |= (1<<17);
122
123 status = wrmalt(Adapter, HPM_CONFIG_MSW,
124 &uiRegRead, sizeof(uiRegRead));
125 if (status)
126 return status;
127 }
128 SendIdleModeResponse(Adapter);
129 }
130 } else if (ntohl(*puiBuffer) == IDLE_MODE_SF_UPDATE_MSG) {
131 OverrideServiceFlowParams(Adapter, puiBuffer);
132 }
133 return status;
134}
135
136static int InterfaceAbortIdlemode(struct bcm_mini_adapter *Adapter,
137 unsigned int Pattern)
138{
139 int status = STATUS_SUCCESS;
140 unsigned int value;
141 unsigned int chip_id;
142 unsigned long timeout = 0, itr = 0;
143
144 int lenwritten = 0;
145 unsigned char aucAbortPattern[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
146 0xFF, 0xFF, 0xFF};
147 struct bcm_interface_adapter *psInterfaceAdapter =
148 Adapter->pvInterfaceAdapter;
149
150 /* Abort Bus suspend if its already suspended */
151 if ((TRUE == psInterfaceAdapter->bSuspended) &&
152 (TRUE == Adapter->bDoSuspend))
153 status = usb_autopm_get_interface(
154 psInterfaceAdapter->interface);
155
156 if ((Adapter->ulPowerSaveMode ==
157 DEVICE_POWERSAVE_MODE_AS_MANUAL_CLOCK_GATING) ||
158 (Adapter->ulPowerSaveMode ==
159 DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)) {
160 /* write the SW abort pattern. */
161 status = wrmalt(Adapter, SW_ABORT_IDLEMODE_LOC,
162 &Pattern, sizeof(Pattern));
163 if (status)
164 return status;
165 }
166
167 if (Adapter->ulPowerSaveMode ==
168 DEVICE_POWERSAVE_MODE_AS_MANUAL_CLOCK_GATING) {
169 value = 0x80000000;
170 status = wrmalt(Adapter,
171 DEBUG_INTERRUPT_GENERATOR_REGISTOR,
172 &value, sizeof(value));
173 if (status)
174 return status;
175 } else if (Adapter->ulPowerSaveMode !=
176 DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE) {
177 /*
178 * Get a Interrupt Out URB and send 8 Bytes Down
179 * To be Done in Thread Context.
180 * Not using Asynchronous Mechanism.
181 */
182 status = usb_interrupt_msg(psInterfaceAdapter->udev,
183 usb_sndintpipe(psInterfaceAdapter->udev,
184 psInterfaceAdapter->sIntrOut.int_out_endpointAddr),
185 aucAbortPattern,
186 8,
187 &lenwritten,
188 5000);
189 if (status)
190 return status;
191
192 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
193 IDLE_MODE, DBG_LVL_ALL,
194 "NOB Sent down :%d", lenwritten);
195
196 /* mdelay(25); */
197
198 timeout = jiffies + msecs_to_jiffies(50);
199 while (time_after(timeout, jiffies)) {
200 itr++;
201 rdmalt(Adapter, CHIP_ID_REG, &chip_id, sizeof(UINT));
202 if (0xbece3200 == (chip_id&~(0xF0)))
203 chip_id = chip_id&~(0xF0);
204 if (chip_id == Adapter->chip_id)
205 break;
206 }
207 if (time_before(timeout, jiffies))
208 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
209 IDLE_MODE, DBG_LVL_ALL,
210 "Not able to read chip-id even after 25 msec");
211 else
212 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
213 IDLE_MODE, DBG_LVL_ALL,
214 "Number of completed iteration to read chip-id :%lu", itr);
215
216 status = wrmalt(Adapter, SW_ABORT_IDLEMODE_LOC,
217 &Pattern, sizeof(status));
218 if (status)
219 return status;
220 }
221 return status;
222}
223int InterfaceIdleModeWakeup(struct bcm_mini_adapter *Adapter)
224{
225 if (Adapter->bTriedToWakeUpFromlowPowerMode) {
226 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
227 IDLE_MODE, DBG_LVL_ALL,
228 "Wake up already attempted.. ignoring\n");
229 } else {
230 Adapter->bTriedToWakeUpFromlowPowerMode = TRUE;
231 InterfaceAbortIdlemode(Adapter, Adapter->usIdleModePattern);
232
233 }
234 return 0;
235}
236
237void InterfaceHandleShutdownModeWakeup(struct bcm_mini_adapter *Adapter)
238{
239 unsigned int uiRegVal = 0;
240 INT Status = 0;
241 int bytes;
242
243 if (Adapter->ulPowerSaveMode ==
244 DEVICE_POWERSAVE_MODE_AS_MANUAL_CLOCK_GATING) {
245 /* clear idlemode interrupt. */
246 uiRegVal = 0;
247 Status = wrmalt(Adapter,
248 DEBUG_INTERRUPT_GENERATOR_REGISTOR,
249 &uiRegVal, sizeof(uiRegVal));
250 if (Status)
251 return;
252 }
253
254 else {
255
256/* clear Interrupt EP registers. */
257 bytes = rdmalt(Adapter,
258 DEVICE_INT_OUT_EP_REG0,
259 &uiRegVal, sizeof(uiRegVal));
260 if (bytes < 0) {
261 Status = bytes;
262 return;
263 }
264
265 bytes = rdmalt(Adapter,
266 DEVICE_INT_OUT_EP_REG1,
267 &uiRegVal, sizeof(uiRegVal));
268 if (bytes < 0) {
269 Status = bytes;
270 return;
271 }
272 }
273}
274
diff --git a/drivers/staging/bcm/InterfaceIdleMode.h b/drivers/staging/bcm/InterfaceIdleMode.h
deleted file mode 100644
index 2ef64003aa89..000000000000
--- a/drivers/staging/bcm/InterfaceIdleMode.h
+++ /dev/null
@@ -1,15 +0,0 @@
1#ifndef _INTERFACE_IDLEMODE_H
2#define _INTERFACE_IDLEMODE_H
3
4INT InterfaceIdleModeWakeup(struct bcm_mini_adapter *Adapter);
5
6INT InterfaceIdleModeRespond(struct bcm_mini_adapter *Adapter,
7 unsigned int *puiBuffer);
8
9VOID InterfaceWriteIdleModeWakePattern(struct bcm_mini_adapter *Adapter);
10
11INT InterfaceWakeUp(struct bcm_mini_adapter *Adapter);
12
13VOID InterfaceHandleShutdownModeWakeup(struct bcm_mini_adapter *Adapter);
14#endif
15
diff --git a/drivers/staging/bcm/InterfaceInit.c b/drivers/staging/bcm/InterfaceInit.c
deleted file mode 100644
index bb61d34886b3..000000000000
--- a/drivers/staging/bcm/InterfaceInit.c
+++ /dev/null
@@ -1,729 +0,0 @@
1#include "headers.h"
2#include <linux/usb/ch9.h>
3static struct usb_device_id InterfaceUsbtable[] = {
4 { USB_DEVICE(BCM_USB_VENDOR_ID_T3, BCM_USB_PRODUCT_ID_T3) },
5 { USB_DEVICE(BCM_USB_VENDOR_ID_T3, BCM_USB_PRODUCT_ID_T3B) },
6 { USB_DEVICE(BCM_USB_VENDOR_ID_T3, BCM_USB_PRODUCT_ID_T3L) },
7 { USB_DEVICE(BCM_USB_VENDOR_ID_T3, BCM_USB_PRODUCT_ID_SYM) },
8 { USB_DEVICE(BCM_USB_VENDOR_ID_ZTE, BCM_USB_PRODUCT_ID_226) },
9 { USB_DEVICE(BCM_USB_VENDOR_ID_FOXCONN, BCM_USB_PRODUCT_ID_1901) },
10 { USB_DEVICE(BCM_USB_VENDOR_ID_ZTE, BCM_USB_PRODUCT_ID_ZTE_TU25) },
11 { USB_DEVICE(BCM_USB_VENDOR_ID_ZTE, BCM_USB_PRODUCT_ID_ZTE_226) },
12 { USB_DEVICE(BCM_USB_VENDOR_ID_ZTE, BCM_USB_PRODUCT_ID_ZTE_326) },
13 { }
14};
15MODULE_DEVICE_TABLE(usb, InterfaceUsbtable);
16
17static int debug = -1;
18module_param(debug, uint, 0600);
19MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
20
21static const u32 default_msg =
22 NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK
23 | NETIF_MSG_TIMER | NETIF_MSG_TX_ERR | NETIF_MSG_RX_ERR
24 | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN;
25
26static int InterfaceAdapterInit(struct bcm_interface_adapter *Adapter);
27
28static void InterfaceAdapterFree(struct bcm_interface_adapter *psIntfAdapter)
29{
30 int i = 0;
31 struct bcm_mini_adapter *ps_ad = psIntfAdapter->psAdapter;
32
33 /* Wake up the wait_queue... */
34 if (ps_ad->LEDInfo.led_thread_running &
35 BCM_LED_THREAD_RUNNING_ACTIVELY) {
36 ps_ad->DriverState = DRIVER_HALT;
37 wake_up(&ps_ad->LEDInfo.notify_led_event);
38 }
39 reset_card_proc(ps_ad);
40
41 /*
42 * worst case time taken by the RDM/WRM will be 5 sec. will check after
43 * every 100 ms to accertain the device is not being accessed. After
44 * this No RDM/WRM should be made.
45 */
46 while (ps_ad->DeviceAccess) {
47 BCM_DEBUG_PRINT(ps_ad, DBG_TYPE_INITEXIT, DRV_ENTRY,
48 DBG_LVL_ALL, "Device is being accessed.\n");
49 msleep(100);
50 }
51 /* Free interrupt URB */
52 /* ps_ad->device_removed = TRUE; */
53 usb_free_urb(psIntfAdapter->psInterruptUrb);
54
55 /* Free transmit URBs */
56 for (i = 0; i < MAXIMUM_USB_TCB; i++) {
57 if (psIntfAdapter->asUsbTcb[i].urb != NULL) {
58 usb_free_urb(psIntfAdapter->asUsbTcb[i].urb);
59 psIntfAdapter->asUsbTcb[i].urb = NULL;
60 }
61 }
62 /* Free receive URB and buffers */
63 for (i = 0; i < MAXIMUM_USB_RCB; i++) {
64 if (psIntfAdapter->asUsbRcb[i].urb != NULL) {
65 kfree(psIntfAdapter->asUsbRcb[i].urb->transfer_buffer);
66 usb_free_urb(psIntfAdapter->asUsbRcb[i].urb);
67 psIntfAdapter->asUsbRcb[i].urb = NULL;
68 }
69 }
70 AdapterFree(ps_ad);
71}
72
73static void ConfigureEndPointTypesThroughEEPROM(
74 struct bcm_mini_adapter *Adapter)
75{
76 u32 ulReg;
77 int bytes;
78 struct bcm_interface_adapter *interfaceAdapter;
79
80 /* Program EP2 MAX_PKT_SIZE */
81 ulReg = ntohl(EP2_MPS_REG);
82 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x128, 4, TRUE);
83 ulReg = ntohl(EP2_MPS);
84 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x12C, 4, TRUE);
85
86 ulReg = ntohl(EP2_CFG_REG);
87 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x132, 4, TRUE);
88 interfaceAdapter =
89 (struct bcm_interface_adapter *)(Adapter->pvInterfaceAdapter);
90 if (interfaceAdapter->bHighSpeedDevice) {
91 ulReg = ntohl(EP2_CFG_INT);
92 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x136, 4, TRUE);
93 } else {
94 /* USE BULK EP as TX in FS mode. */
95 ulReg = ntohl(EP2_CFG_BULK);
96 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x136, 4, TRUE);
97 }
98
99 /* Program EP4 MAX_PKT_SIZE. */
100 ulReg = ntohl(EP4_MPS_REG);
101 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x13C, 4, TRUE);
102 ulReg = ntohl(EP4_MPS);
103 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x140, 4, TRUE);
104
105 /* Program TX EP as interrupt(Alternate Setting) */
106 bytes = rdmalt(Adapter, 0x0F0110F8, &ulReg, sizeof(u32));
107 if (bytes < 0) {
108 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, DRV_ENTRY,
109 DBG_LVL_ALL, "reading of Tx EP failed\n");
110 return;
111 }
112 ulReg |= 0x6;
113
114 ulReg = ntohl(ulReg);
115 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1CC, 4, TRUE);
116
117 ulReg = ntohl(EP4_CFG_REG);
118 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1C8, 4, TRUE);
119 /* Program ISOCHRONOUS EP size to zero. */
120 ulReg = ntohl(ISO_MPS_REG);
121 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1D2, 4, TRUE);
122 ulReg = ntohl(ISO_MPS);
123 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1D6, 4, TRUE);
124
125 /*
126 * Update EEPROM Version.
127 * Read 4 bytes from 508 and modify 511 and 510.
128 */
129 ReadBeceemEEPROM(Adapter, 0x1FC, &ulReg);
130 ulReg &= 0x0101FFFF;
131 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1FC, 4, TRUE);
132
133 /*
134 * Update length field if required.
135 * Also make the string NULL terminated.
136 */
137
138 ReadBeceemEEPROM(Adapter, 0xA8, &ulReg);
139 if ((ulReg&0x00FF0000)>>16 > 0x30) {
140 ulReg = (ulReg&0xFF00FFFF)|(0x30<<16);
141 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0xA8, 4, TRUE);
142 }
143 ReadBeceemEEPROM(Adapter, 0x148, &ulReg);
144 if ((ulReg&0x00FF0000)>>16 > 0x30) {
145 ulReg = (ulReg&0xFF00FFFF)|(0x30<<16);
146 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x148, 4, TRUE);
147 }
148 ulReg = 0;
149 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x122, 4, TRUE);
150 ulReg = 0;
151 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&ulReg, 0x1C2, 4, TRUE);
152}
153
154static int usbbcm_device_probe(struct usb_interface *intf,
155 const struct usb_device_id *id)
156{
157 struct usb_device *udev = interface_to_usbdev(intf);
158 int retval;
159 struct bcm_mini_adapter *psAdapter;
160 struct bcm_interface_adapter *psIntfAdapter;
161 struct net_device *ndev;
162
163 /* Reserve one extra queue for the bit-bucket */
164 ndev = alloc_etherdev_mq(sizeof(struct bcm_mini_adapter),
165 NO_OF_QUEUES + 1);
166 if (ndev == NULL) {
167 dev_err(&udev->dev, DRV_NAME ": no memory for device\n");
168 return -ENOMEM;
169 }
170
171 SET_NETDEV_DEV(ndev, &intf->dev);
172
173 psAdapter = netdev_priv(ndev);
174 psAdapter->dev = ndev;
175 psAdapter->msg_enable = netif_msg_init(debug, default_msg);
176
177 /* Init default driver debug state */
178
179 psAdapter->stDebugState.debug_level = DBG_LVL_CURR;
180 psAdapter->stDebugState.type = DBG_TYPE_INITEXIT;
181
182 /*
183 * Technically, one can start using BCM_DEBUG_PRINT after this point.
184 * However, realize that by default the Type/Subtype bitmaps are all
185 * zero now; so no prints will actually appear until the TestApp turns
186 * on debug paths via the ioctl(); so practically speaking, in early
187 * init, no logging happens.
188 *
189 * A solution (used below): we explicitly set the bitmaps to 1 for
190 * Type=DBG_TYPE_INITEXIT and ALL subtype's of the same. Now all bcm
191 * debug statements get logged, enabling debug during early init.
192 * Further, we turn this OFF once init_module() completes.
193 */
194
195 psAdapter->stDebugState.subtype[DBG_TYPE_INITEXIT] = 0xff;
196 BCM_SHOW_DEBUG_BITMAP(psAdapter);
197
198 retval = InitAdapter(psAdapter);
199 if (retval) {
200 dev_err(&udev->dev, DRV_NAME ": InitAdapter Failed\n");
201 AdapterFree(psAdapter);
202 return retval;
203 }
204
205 /* Allocate interface adapter structure */
206 psIntfAdapter = kzalloc(sizeof(struct bcm_interface_adapter),
207 GFP_KERNEL);
208 if (psIntfAdapter == NULL) {
209 AdapterFree(psAdapter);
210 return -ENOMEM;
211 }
212
213 psAdapter->pvInterfaceAdapter = psIntfAdapter;
214 psIntfAdapter->psAdapter = psAdapter;
215
216 /* Store usb interface in Interface Adapter */
217 psIntfAdapter->interface = intf;
218 usb_set_intfdata(intf, psIntfAdapter);
219
220 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
221 "psIntfAdapter 0x%p\n", psIntfAdapter);
222 retval = InterfaceAdapterInit(psIntfAdapter);
223 if (retval) {
224 /* If the Firmware/Cfg File is not present
225 * then return success, let the application
226 * download the files.
227 */
228 if (-ENOENT == retval) {
229 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY,
230 DBG_LVL_ALL,
231 "File Not Found. Use app to download.\n");
232 return STATUS_SUCCESS;
233 }
234 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY,
235 DBG_LVL_ALL, "InterfaceAdapterInit failed.\n");
236 usb_set_intfdata(intf, NULL);
237 udev = interface_to_usbdev(intf);
238 usb_put_dev(udev);
239 InterfaceAdapterFree(psIntfAdapter);
240 return retval;
241 }
242 if (psAdapter->chip_id > T3) {
243 uint32_t uiNackZeroLengthInt = 4;
244
245 retval =
246 wrmalt(psAdapter, DISABLE_USB_ZERO_LEN_INT,
247 &uiNackZeroLengthInt,
248 sizeof(uiNackZeroLengthInt));
249 if (retval)
250 return retval;
251 }
252
253 /* Check whether the USB-Device Supports remote Wake-Up */
254 if (USB_CONFIG_ATT_WAKEUP & udev->actconfig->desc.bmAttributes) {
255 /* If Suspend then only support dynamic suspend */
256 if (psAdapter->bDoSuspend) {
257#ifdef CONFIG_PM
258 pm_runtime_set_autosuspend_delay(&udev->dev, 0);
259 intf->needs_remote_wakeup = 1;
260 usb_enable_autosuspend(udev);
261 device_init_wakeup(&intf->dev, 1);
262 INIT_WORK(&psIntfAdapter->usbSuspendWork,
263 putUsbSuspend);
264 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, DRV_ENTRY,
265 DBG_LVL_ALL,
266 "Enabling USB Auto-Suspend\n");
267#endif
268 } else {
269 intf->needs_remote_wakeup = 0;
270 usb_disable_autosuspend(udev);
271 }
272 }
273
274 psAdapter->stDebugState.subtype[DBG_TYPE_INITEXIT] = 0x0;
275 return retval;
276}
277
278static void usbbcm_disconnect(struct usb_interface *intf)
279{
280 struct bcm_interface_adapter *psIntfAdapter = usb_get_intfdata(intf);
281 struct bcm_mini_adapter *psAdapter;
282 struct usb_device *udev = interface_to_usbdev(intf);
283
284 if (psIntfAdapter == NULL)
285 return;
286
287 psAdapter = psIntfAdapter->psAdapter;
288 netif_device_detach(psAdapter->dev);
289
290 if (psAdapter->bDoSuspend)
291 intf->needs_remote_wakeup = 0;
292
293 psAdapter->device_removed = TRUE;
294 usb_set_intfdata(intf, NULL);
295 InterfaceAdapterFree(psIntfAdapter);
296 usb_put_dev(udev);
297}
298
299static int AllocUsbCb(struct bcm_interface_adapter *psIntfAdapter)
300{
301 int i = 0;
302
303 for (i = 0; i < MAXIMUM_USB_TCB; i++) {
304 psIntfAdapter->asUsbTcb[i].urb = usb_alloc_urb(0, GFP_KERNEL);
305
306 if (psIntfAdapter->asUsbTcb[i].urb == NULL) {
307 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,
308 DBG_TYPE_PRINTK, 0, 0,
309 "Can't allocate Tx urb for index %d\n",
310 i);
311 return -ENOMEM;
312 }
313 }
314
315 for (i = 0; i < MAXIMUM_USB_RCB; i++) {
316 psIntfAdapter->asUsbRcb[i].urb = usb_alloc_urb(0, GFP_KERNEL);
317
318 if (psIntfAdapter->asUsbRcb[i].urb == NULL) {
319 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,
320 DBG_TYPE_PRINTK, 0, 0,
321 "Can't allocate Rx urb for index %d\n",
322 i);
323 return -ENOMEM;
324 }
325
326 psIntfAdapter->asUsbRcb[i].urb->transfer_buffer =
327 kmalloc(MAX_DATA_BUFFER_SIZE, GFP_KERNEL);
328
329 if (psIntfAdapter->asUsbRcb[i].urb->transfer_buffer == NULL) {
330 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,
331 DBG_TYPE_PRINTK, 0, 0,
332 "Can't allocate Rx buffer for index %d\n",
333 i);
334 return -ENOMEM;
335 }
336 psIntfAdapter->asUsbRcb[i].urb->transfer_buffer_length =
337 MAX_DATA_BUFFER_SIZE;
338 }
339 return 0;
340}
341
342static int device_run(struct bcm_interface_adapter *psIntfAdapter)
343{
344 int value = 0;
345 UINT status = STATUS_SUCCESS;
346 struct bcm_mini_adapter *psAd = psIntfAdapter->psAdapter;
347
348 status = InitCardAndDownloadFirmware(psAd);
349 if (status != STATUS_SUCCESS) {
350 pr_err(DRV_NAME "InitCardAndDownloadFirmware failed.\n");
351 return status;
352 }
353 if (psAd->fw_download_done) {
354 if (StartInterruptUrb(psIntfAdapter)) {
355 BCM_DEBUG_PRINT(psAd, DBG_TYPE_INITEXIT, DRV_ENTRY,
356 DBG_LVL_ALL,
357 "Cannot send interrupt in URB\n");
358 }
359
360 /*
361 * now register the cntrl interface. after downloading the f/w
362 * waiting for 5 sec to get the mailbox interrupt.
363 */
364 psAd->waiting_to_fw_download_done = false;
365 value = wait_event_timeout(psAd->ioctl_fw_dnld_wait_queue,
366 psAd->waiting_to_fw_download_done,
367 5 * HZ);
368
369 if (value == 0)
370 pr_err(DRV_NAME ": Timeout waiting for mailbox interrupt.\n");
371
372 if (register_control_device_interface(psAd) < 0) {
373 pr_err(DRV_NAME ": Register Control Device failed.\n");
374 return -EIO;
375 }
376 }
377 return 0;
378}
379
380static int select_alternate_setting_for_highspeed_modem(
381 struct bcm_interface_adapter *psIntfAdapter,
382 struct usb_endpoint_descriptor **endpoint,
383 const struct usb_host_interface *iface_desc,
384 int *usedIntOutForBulkTransfer)
385{
386 int retval = 0;
387 struct bcm_mini_adapter *psAd = psIntfAdapter->psAdapter;
388
389 /* selecting alternate setting one as a default setting
390 * for High Speed modem. */
391 if (psIntfAdapter->bHighSpeedDevice)
392 retval = usb_set_interface(psIntfAdapter->udev,
393 DEFAULT_SETTING_0,
394 ALTERNATE_SETTING_1);
395 BCM_DEBUG_PRINT(psAd, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
396 "BCM16 is applicable on this dongle\n");
397 if (retval || !psIntfAdapter->bHighSpeedDevice) {
398 *usedIntOutForBulkTransfer = EP2;
399 *endpoint = &iface_desc->endpoint[EP2].desc;
400 BCM_DEBUG_PRINT(psAd, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
401 "Interface altsetting failed or modem is configured to Full Speed, hence will work on default setting 0\n");
402 /*
403 * If Modem is high speed device EP2 should be
404 * INT OUT End point
405 *
406 * If Mode is FS then EP2 should be bulk end
407 * point
408 */
409 if ((psIntfAdapter->bHighSpeedDevice &&
410 !usb_endpoint_is_int_out(*endpoint)) ||
411 (!psIntfAdapter->bHighSpeedDevice &&
412 !usb_endpoint_is_bulk_out(*endpoint))) {
413 BCM_DEBUG_PRINT(psAd, DBG_TYPE_INITEXIT, DRV_ENTRY,
414 DBG_LVL_ALL,
415 "Configuring the EEPROM\n");
416 /* change the EP2, EP4 to INT OUT end point */
417 ConfigureEndPointTypesThroughEEPROM(
418 psAd);
419
420 /*
421 * It resets the device and if any thing
422 * gets changed in USB descriptor it
423 * will show fail and re-enumerate the
424 * device
425 */
426 retval = usb_reset_device(psIntfAdapter->udev);
427 if (retval) {
428 BCM_DEBUG_PRINT(psAd, DBG_TYPE_INITEXIT,
429 DRV_ENTRY, DBG_LVL_ALL,
430 "reset failed. Re-enumerating the device.\n");
431 return retval;
432 }
433
434 }
435 if (!psIntfAdapter->bHighSpeedDevice &&
436 usb_endpoint_is_bulk_out(*endpoint)) {
437 /*
438 * Once BULK is selected in FS mode.
439 * Revert it back to INT.
440 * Else USB_IF will fail.
441 */
442 UINT _uiData = ntohl(EP2_CFG_INT);
443
444 BCM_DEBUG_PRINT(psAd, DBG_TYPE_INITEXIT, DRV_ENTRY,
445 DBG_LVL_ALL,
446 "Reverting Bulk to INT as it is in Full Speed mode.\n");
447 BeceemEEPROMBulkWrite(psAd, (PUCHAR) & _uiData, 0x136,
448 4, TRUE);
449 }
450 } else {
451 *usedIntOutForBulkTransfer = EP4;
452 *endpoint = &iface_desc->endpoint[EP4].desc;
453 BCM_DEBUG_PRINT(psAd, DBG_TYPE_INITEXIT, DRV_ENTRY, DBG_LVL_ALL,
454 "Choosing AltSetting as a default setting.\n");
455 if (!usb_endpoint_is_int_out(*endpoint)) {
456 BCM_DEBUG_PRINT(psAd, DBG_TYPE_INITEXIT, DRV_ENTRY,
457 DBG_LVL_ALL,
458 "Dongle does not have BCM16 Fix.\n");
459 /*
460 * change the EP2, EP4 to INT OUT end point and use EP4
461 * in altsetting
462 */
463 ConfigureEndPointTypesThroughEEPROM(psAd);
464
465 /*
466 * It resets the device and if any thing
467 * gets changed in USB descriptor it
468 * will show fail and re-enumerate the
469 * device
470 */
471 retval = usb_reset_device(psIntfAdapter->udev);
472 if (retval) {
473 BCM_DEBUG_PRINT(psAd, DBG_TYPE_INITEXIT,
474 DRV_ENTRY, DBG_LVL_ALL,
475 "reset failed. Re-enumerating the device.\n");
476 return retval;
477 }
478 }
479 }
480
481 return 0;
482}
483
484static int InterfaceAdapterInit(struct bcm_interface_adapter *psIntfAdapter)
485{
486 struct usb_host_interface *iface_desc;
487 struct usb_endpoint_descriptor *endpoint;
488 size_t buffer_size;
489 unsigned long value;
490 int retval = 0;
491 int usedIntOutForBulkTransfer = 0;
492 bool bBcm16 = false;
493 UINT uiData = 0;
494 int bytes;
495 struct bcm_mini_adapter *psAd = psIntfAdapter->psAdapter;
496
497 /* Store the usb dev into interface adapter */
498 psIntfAdapter->udev =
499 usb_get_dev(interface_to_usbdev(psIntfAdapter->interface));
500
501 psIntfAdapter->bHighSpeedDevice =
502 (psIntfAdapter->udev->speed == USB_SPEED_HIGH);
503 psAd->interface_rdm = BcmRDM;
504 psAd->interface_wrm = BcmWRM;
505
506 bytes = rdmalt(psAd, CHIP_ID_REG, (u32 *) &(psAd->chip_id),
507 sizeof(u32));
508 if (bytes < 0) {
509 retval = bytes;
510 BCM_DEBUG_PRINT(psAd, DBG_TYPE_PRINTK, 0, 0,
511 "CHIP ID Read Failed\n");
512 return retval;
513 }
514
515 if (0xbece3200 == (psAd->chip_id & ~(0xF0)))
516 psAd->chip_id &= ~0xF0;
517
518 dev_info(&psIntfAdapter->udev->dev, "RDM Chip ID 0x%lx\n",
519 psAd->chip_id);
520
521 iface_desc = psIntfAdapter->interface->cur_altsetting;
522
523 if (psAd->chip_id == T3B) {
524 /* T3B device will have EEPROM, check if EEPROM is proper and
525 * BCM16 can be done or not. */
526 BeceemEEPROMBulkRead(psAd, &uiData, 0x0, 4);
527 if (uiData == BECM)
528 bBcm16 = TRUE;
529
530 dev_info(&psIntfAdapter->udev->dev,
531 "number of alternate setting %d\n",
532 psIntfAdapter->interface->num_altsetting);
533
534 if (bBcm16 == TRUE) {
535 retval = select_alternate_setting_for_highspeed_modem(
536 psIntfAdapter, &endpoint, iface_desc,
537 &usedIntOutForBulkTransfer);
538 if (retval)
539 return retval;
540 }
541 }
542
543 iface_desc = psIntfAdapter->interface->cur_altsetting;
544
545 for (value = 0; value < iface_desc->desc.bNumEndpoints; ++value) {
546 endpoint = &iface_desc->endpoint[value].desc;
547
548 if (!psIntfAdapter->sBulkIn.bulk_in_endpointAddr &&
549 usb_endpoint_is_bulk_in(endpoint)) {
550 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
551 psIntfAdapter->sBulkIn.bulk_in_size = buffer_size;
552 psIntfAdapter->sBulkIn.bulk_in_endpointAddr =
553 endpoint->bEndpointAddress;
554 psIntfAdapter->sBulkIn.bulk_in_pipe = usb_rcvbulkpipe(
555 psIntfAdapter->udev,
556 psIntfAdapter->sBulkIn.bulk_in_endpointAddr);
557 }
558
559 if (!psIntfAdapter->sBulkOut.bulk_out_endpointAddr &&
560 usb_endpoint_is_bulk_out(endpoint)) {
561 psIntfAdapter->sBulkOut.bulk_out_endpointAddr =
562 endpoint->bEndpointAddress;
563 psIntfAdapter->sBulkOut.bulk_out_pipe = usb_sndbulkpipe(
564 psIntfAdapter->udev,
565 psIntfAdapter->sBulkOut.bulk_out_endpointAddr);
566 }
567
568 if (!psIntfAdapter->sIntrIn.int_in_endpointAddr &&
569 usb_endpoint_is_int_in(endpoint)) {
570 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
571 psIntfAdapter->sIntrIn.int_in_size = buffer_size;
572 psIntfAdapter->sIntrIn.int_in_endpointAddr =
573 endpoint->bEndpointAddress;
574 psIntfAdapter->sIntrIn.int_in_interval =
575 endpoint->bInterval;
576 psIntfAdapter->sIntrIn.int_in_buffer =
577 kmalloc(buffer_size, GFP_KERNEL);
578 if (!psIntfAdapter->sIntrIn.int_in_buffer)
579 return -EINVAL;
580 }
581
582 if (!psIntfAdapter->sIntrOut.int_out_endpointAddr &&
583 usb_endpoint_is_int_out(endpoint)) {
584 if (!psIntfAdapter->sBulkOut.bulk_out_endpointAddr &&
585 (psAd->chip_id == T3B) &&
586 (value == usedIntOutForBulkTransfer)) {
587 /*
588 * use first intout end point as a bulk out end
589 * point
590 */
591 buffer_size =
592 le16_to_cpu(endpoint->wMaxPacketSize);
593 psIntfAdapter->sBulkOut.bulk_out_size =
594 buffer_size;
595 psIntfAdapter->sBulkOut.bulk_out_endpointAddr =
596 endpoint->bEndpointAddress;
597 psIntfAdapter->sBulkOut.bulk_out_pipe =
598 usb_sndintpipe(psIntfAdapter->udev,
599 psIntfAdapter->sBulkOut
600 .bulk_out_endpointAddr);
601 psIntfAdapter->sBulkOut.int_out_interval =
602 endpoint->bInterval;
603 } else if (value == EP6) {
604 buffer_size =
605 le16_to_cpu(endpoint->wMaxPacketSize);
606 psIntfAdapter->sIntrOut.int_out_size =
607 buffer_size;
608 psIntfAdapter->sIntrOut.int_out_endpointAddr =
609 endpoint->bEndpointAddress;
610 psIntfAdapter->sIntrOut.int_out_interval =
611 endpoint->bInterval;
612 psIntfAdapter->sIntrOut.int_out_buffer =
613 kmalloc(buffer_size, GFP_KERNEL);
614 if (!psIntfAdapter->sIntrOut.int_out_buffer)
615 return -EINVAL;
616 }
617 }
618 }
619
620 usb_set_intfdata(psIntfAdapter->interface, psIntfAdapter);
621
622 psAd->bcm_file_download = InterfaceFileDownload;
623 psAd->bcm_file_readback_from_chip = InterfaceFileReadbackFromChip;
624 psAd->interface_transmit = InterfaceTransmitPacket;
625
626 retval = CreateInterruptUrb(psIntfAdapter);
627
628 if (retval) {
629 BCM_DEBUG_PRINT(psAd, DBG_TYPE_PRINTK, 0, 0,
630 "Cannot create interrupt urb\n");
631 return retval;
632 }
633
634 retval = AllocUsbCb(psIntfAdapter);
635 if (retval)
636 return retval;
637
638 return device_run(psIntfAdapter);
639}
640
641static int InterfaceSuspend(struct usb_interface *intf, pm_message_t message)
642{
643 struct bcm_interface_adapter *psIntfAdapter = usb_get_intfdata(intf);
644
645 psIntfAdapter->bSuspended = TRUE;
646
647 if (psIntfAdapter->bPreparingForBusSuspend) {
648 psIntfAdapter->bPreparingForBusSuspend = false;
649
650 if (psIntfAdapter->psAdapter->LinkStatus == LINKUP_DONE) {
651 psIntfAdapter->psAdapter->IdleMode = TRUE;
652 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,
653 DBG_TYPE_INITEXIT, DRV_ENTRY,
654 DBG_LVL_ALL,
655 "Host Entered in PMU Idle Mode.\n");
656 } else {
657 psIntfAdapter->psAdapter->bShutStatus = TRUE;
658 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,
659 DBG_TYPE_INITEXIT, DRV_ENTRY,
660 DBG_LVL_ALL,
661 "Host Entered in PMU Shutdown Mode.\n");
662 }
663 }
664 psIntfAdapter->psAdapter->bPreparingForLowPowerMode = false;
665
666 /* Signaling the control pkt path */
667 wake_up(&psIntfAdapter->psAdapter->lowpower_mode_wait_queue);
668
669 return 0;
670}
671
672static int InterfaceResume(struct usb_interface *intf)
673{
674 struct bcm_interface_adapter *psIntfAdapter = usb_get_intfdata(intf);
675
676 mdelay(100);
677 psIntfAdapter->bSuspended = false;
678
679 StartInterruptUrb(psIntfAdapter);
680 InterfaceRx(psIntfAdapter);
681 return 0;
682}
683
684static struct usb_driver usbbcm_driver = {
685 .name = "usbbcm",
686 .probe = usbbcm_device_probe,
687 .disconnect = usbbcm_disconnect,
688 .suspend = InterfaceSuspend,
689 .resume = InterfaceResume,
690 .id_table = InterfaceUsbtable,
691 .supports_autosuspend = 1,
692};
693
694struct class *bcm_class;
695
696static __init int bcm_init(void)
697{
698 int retval;
699
700 pr_info("%s: %s, %s\n", DRV_NAME, DRV_DESCRIPTION, DRV_VERSION);
701 pr_info("%s\n", DRV_COPYRIGHT);
702
703 bcm_class = class_create(THIS_MODULE, DRV_NAME);
704 if (IS_ERR(bcm_class)) {
705 pr_err(DRV_NAME ": could not create class\n");
706 return PTR_ERR(bcm_class);
707 }
708
709 retval = usb_register(&usbbcm_driver);
710 if (retval < 0) {
711 pr_err(DRV_NAME ": could not register usb driver\n");
712 class_destroy(bcm_class);
713 return retval;
714 }
715 return 0;
716}
717
718static __exit void bcm_exit(void)
719{
720 usb_deregister(&usbbcm_driver);
721 class_destroy(bcm_class);
722}
723
724module_init(bcm_init);
725module_exit(bcm_exit);
726
727MODULE_DESCRIPTION(DRV_DESCRIPTION);
728MODULE_VERSION(DRV_VERSION);
729MODULE_LICENSE("GPL");
diff --git a/drivers/staging/bcm/InterfaceInit.h b/drivers/staging/bcm/InterfaceInit.h
deleted file mode 100644
index ffa6e9667ec4..000000000000
--- a/drivers/staging/bcm/InterfaceInit.h
+++ /dev/null
@@ -1,26 +0,0 @@
1#ifndef _INTERFACE_INIT_H
2#define _INTERFACE_INIT_H
3
4#define BCM_USB_VENDOR_ID_T3 0x198f
5#define BCM_USB_VENDOR_ID_FOXCONN 0x0489
6#define BCM_USB_VENDOR_ID_ZTE 0x19d2
7
8#define BCM_USB_PRODUCT_ID_T3 0x0300
9#define BCM_USB_PRODUCT_ID_T3B 0x0210
10#define BCM_USB_PRODUCT_ID_T3L 0x0220
11#define BCM_USB_PRODUCT_ID_SYM 0x15E
12#define BCM_USB_PRODUCT_ID_1901 0xe017
13#define BCM_USB_PRODUCT_ID_226 0x0132 /* not sure if this is valid */
14#define BCM_USB_PRODUCT_ID_ZTE_226 0x172
15#define BCM_USB_PRODUCT_ID_ZTE_326 0x173 /* ZTE AX326 */
16#define BCM_USB_PRODUCT_ID_ZTE_TU25 0x0007
17
18#define BCM_USB_MINOR_BASE 192
19
20int InterfaceInitialize(void);
21
22int InterfaceExit(void);
23
24int usbbcm_worker_thread(struct bcm_interface_adapter *psIntfAdapter);
25
26#endif
diff --git a/drivers/staging/bcm/InterfaceIsr.c b/drivers/staging/bcm/InterfaceIsr.c
deleted file mode 100644
index b9f8a7aa24fe..000000000000
--- a/drivers/staging/bcm/InterfaceIsr.c
+++ /dev/null
@@ -1,190 +0,0 @@
1#include "headers.h"
2
3
4static void read_int_callback(struct urb *urb/*, struct pt_regs *regs*/)
5{
6 int status = urb->status;
7 struct bcm_interface_adapter *psIntfAdapter =
8 (struct bcm_interface_adapter *)urb->context;
9 struct bcm_mini_adapter *Adapter = psIntfAdapter->psAdapter;
10
11 if (netif_msg_intr(Adapter))
12 pr_info(PFX "%s: interrupt status %d\n",
13 Adapter->dev->name, status);
14
15 if (Adapter->device_removed) {
16 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, INTF_INIT,
17 DBG_LVL_ALL, "Device has Got Removed.");
18 return;
19 }
20
21 if ((Adapter->bPreparingForLowPowerMode && Adapter->bDoSuspend) ||
22 psIntfAdapter->bSuspended ||
23 psIntfAdapter->bPreparingForBusSuspend) {
24 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, INTF_INIT,
25 DBG_LVL_ALL,
26 "Interrupt call back is called while suspending the device");
27 return;
28 }
29
30 switch (status) {
31 /* success */
32 case STATUS_SUCCESS:
33 if (urb->actual_length) {
34
35 if (psIntfAdapter->ulInterruptData[1] & 0xFF) {
36 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
37 INTF_INIT, DBG_LVL_ALL,
38 "Got USIM interrupt");
39 }
40
41 if (psIntfAdapter->ulInterruptData[1] & 0xFF00) {
42 atomic_set(&Adapter->CurrNumFreeTxDesc,
43 (psIntfAdapter->ulInterruptData[1] &
44 0xFF00) >> 8);
45 atomic_set(&Adapter->uiMBupdate, TRUE);
46 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
47 INTF_INIT, DBG_LVL_ALL,
48 "TX mailbox contains %d",
49 atomic_read(&Adapter->CurrNumFreeTxDesc));
50 }
51 if (psIntfAdapter->ulInterruptData[1] >> 16) {
52 Adapter->CurrNumRecvDescs =
53 (psIntfAdapter->ulInterruptData[1] >> 16);
54 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
55 INTF_INIT, DBG_LVL_ALL,
56 "RX mailbox contains %d",
57 Adapter->CurrNumRecvDescs);
58 InterfaceRx(psIntfAdapter);
59 }
60 if (Adapter->fw_download_done &&
61 !Adapter->downloadDDR &&
62 atomic_read(&Adapter->CurrNumFreeTxDesc)) {
63
64 psIntfAdapter->psAdapter->downloadDDR += 1;
65 wake_up(&Adapter->tx_packet_wait_queue);
66 }
67 if (!Adapter->waiting_to_fw_download_done) {
68 Adapter->waiting_to_fw_download_done = TRUE;
69 wake_up(&Adapter->ioctl_fw_dnld_wait_queue);
70 }
71 if (!atomic_read(&Adapter->TxPktAvail)) {
72 atomic_set(&Adapter->TxPktAvail, 1);
73 wake_up(&Adapter->tx_packet_wait_queue);
74 }
75 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, INTF_INIT,
76 DBG_LVL_ALL, "Firing interrupt in URB");
77 }
78 break;
79 case -ENOENT:
80 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, INTF_INIT,
81 DBG_LVL_ALL, "URB has got disconnected....");
82 return;
83 case -EINPROGRESS:
84 /*
85 * This situation may happened when URBunlink is used. for
86 * detail check usb_unlink_urb documentation.
87 */
88 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, INTF_INIT,
89 DBG_LVL_ALL,
90 "Impossibe condition has occurred... something very bad is going on");
91 break;
92 /* return; */
93 case -EPIPE:
94 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, INTF_INIT,
95 DBG_LVL_ALL,
96 "Interrupt IN endPoint has got halted/stalled...need to clear this");
97 Adapter->bEndPointHalted = TRUE;
98 wake_up(&Adapter->tx_packet_wait_queue);
99 urb->status = STATUS_SUCCESS;
100 return;
101 /* software-driven interface shutdown */
102 case -ECONNRESET: /* URB got unlinked */
103 case -ESHUTDOWN: /* hardware gone. this is the serious problem */
104 /*
105 * Occurs only when something happens with the
106 * host controller device
107 */
108 case -ENODEV: /* Device got removed */
109 case -EINVAL:
110 /*
111 * Some thing very bad happened with the URB. No
112 * description is available.
113 */
114 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, INTF_INIT,
115 DBG_LVL_ALL, "interrupt urb error %d", status);
116 urb->status = STATUS_SUCCESS;
117 break;
118 /* return; */
119 default:
120 /*
121 * This is required to check what is the defaults conditions
122 * when it occurs..
123 */
124 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, NEXT_SEND, DBG_LVL_ALL,
125 "GOT DEFAULT INTERRUPT URB STATUS :%d..Please Analyze it...",
126 status);
127 break;
128 }
129
130 StartInterruptUrb(psIntfAdapter);
131
132
133}
134
135int CreateInterruptUrb(struct bcm_interface_adapter *psIntfAdapter)
136{
137 psIntfAdapter->psInterruptUrb = usb_alloc_urb(0, GFP_KERNEL);
138 if (!psIntfAdapter->psInterruptUrb) {
139 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_OTHERS,
140 INTF_INIT, DBG_LVL_ALL,
141 "Cannot allocate interrupt urb");
142 return -ENOMEM;
143 }
144 psIntfAdapter->psInterruptUrb->transfer_buffer =
145 psIntfAdapter->ulInterruptData;
146 psIntfAdapter->psInterruptUrb->transfer_buffer_length =
147 sizeof(psIntfAdapter->ulInterruptData);
148
149 psIntfAdapter->sIntrIn.int_in_pipe = usb_rcvintpipe(psIntfAdapter->udev,
150 psIntfAdapter->sIntrIn.int_in_endpointAddr);
151
152 usb_fill_int_urb(psIntfAdapter->psInterruptUrb, psIntfAdapter->udev,
153 psIntfAdapter->sIntrIn.int_in_pipe,
154 psIntfAdapter->psInterruptUrb->transfer_buffer,
155 psIntfAdapter->psInterruptUrb->transfer_buffer_length,
156 read_int_callback, psIntfAdapter,
157 psIntfAdapter->sIntrIn.int_in_interval);
158
159 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_OTHERS, INTF_INIT,
160 DBG_LVL_ALL, "Interrupt Interval: %d\n",
161 psIntfAdapter->sIntrIn.int_in_interval);
162 return 0;
163}
164
165
166INT StartInterruptUrb(struct bcm_interface_adapter *psIntfAdapter)
167{
168 INT status = 0;
169
170 if (!(psIntfAdapter->psAdapter->device_removed ||
171 psIntfAdapter->psAdapter->bEndPointHalted ||
172 psIntfAdapter->bSuspended ||
173 psIntfAdapter->bPreparingForBusSuspend ||
174 psIntfAdapter->psAdapter->StopAllXaction)) {
175 status =
176 usb_submit_urb(psIntfAdapter->psInterruptUrb, GFP_ATOMIC);
177 if (status) {
178 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,
179 DBG_TYPE_OTHERS, INTF_INIT, DBG_LVL_ALL,
180 "Cannot send inturb %d\n", status);
181 if (status == -EPIPE) {
182 psIntfAdapter->psAdapter->bEndPointHalted =
183 TRUE;
184 wake_up(&psIntfAdapter->psAdapter->tx_packet_wait_queue);
185 }
186 }
187 }
188 return status;
189}
190
diff --git a/drivers/staging/bcm/InterfaceIsr.h b/drivers/staging/bcm/InterfaceIsr.h
deleted file mode 100644
index 3073bd71cfeb..000000000000
--- a/drivers/staging/bcm/InterfaceIsr.h
+++ /dev/null
@@ -1,15 +0,0 @@
1#ifndef _INTERFACE_ISR_H
2#define _INTERFACE_ISR_H
3
4int CreateInterruptUrb(struct bcm_interface_adapter *psIntfAdapter);
5
6
7INT StartInterruptUrb(struct bcm_interface_adapter *psIntfAdapter);
8
9
10VOID InterfaceEnableInterrupt(struct bcm_mini_adapter *Adapter);
11
12VOID InterfaceDisableInterrupt(struct bcm_mini_adapter *Adapter);
13
14#endif
15
diff --git a/drivers/staging/bcm/InterfaceMacros.h b/drivers/staging/bcm/InterfaceMacros.h
deleted file mode 100644
index fedb79437f33..000000000000
--- a/drivers/staging/bcm/InterfaceMacros.h
+++ /dev/null
@@ -1,18 +0,0 @@
1#ifndef _INTERFACE_MACROS_H
2#define _INTERFACE_MACROS_H
3
4#define BCM_USB_MAX_READ_LENGTH 2048
5
6#define MAXIMUM_USB_TCB 128
7#define MAXIMUM_USB_RCB 128
8
9#define MAX_BUFFERS_PER_QUEUE 256
10
11#define MAX_DATA_BUFFER_SIZE 2048
12
13/* Num of Asynchronous reads pending */
14#define NUM_RX_DESC 64
15
16#define SYS_CFG 0x0F000C00
17
18#endif
diff --git a/drivers/staging/bcm/InterfaceMisc.c b/drivers/staging/bcm/InterfaceMisc.c
deleted file mode 100644
index e5bcfec2a6cf..000000000000
--- a/drivers/staging/bcm/InterfaceMisc.c
+++ /dev/null
@@ -1,247 +0,0 @@
1#include "headers.h"
2
3static int adapter_err_occurred(const struct bcm_interface_adapter *ad)
4{
5 if (ad->psAdapter->device_removed == TRUE) {
6 BCM_DEBUG_PRINT(ad->psAdapter, DBG_TYPE_PRINTK, 0, 0,
7 "Device got removed");
8 return -ENODEV;
9 }
10
11 if ((ad->psAdapter->StopAllXaction == TRUE) &&
12 (ad->psAdapter->chip_id >= T3LPB)) {
13 BCM_DEBUG_PRINT(ad->psAdapter, DBG_TYPE_OTHERS, RDM,
14 DBG_LVL_ALL,
15 "Currently Xaction is not allowed on the bus");
16 return -EACCES;
17 }
18
19 if (ad->bSuspended == TRUE || ad->bPreparingForBusSuspend == TRUE) {
20 BCM_DEBUG_PRINT(ad->psAdapter, DBG_TYPE_OTHERS, RDM,
21 DBG_LVL_ALL,
22 "Bus is in suspended states hence RDM not allowed..");
23 return -EACCES;
24 }
25
26 return 0;
27}
28
29int InterfaceRDM(struct bcm_interface_adapter *psIntfAdapter,
30 unsigned int addr,
31 void *buff,
32 int len)
33{
34 int bytes;
35 int err = 0;
36
37 if (!psIntfAdapter)
38 return -EINVAL;
39
40 err = adapter_err_occurred(psIntfAdapter);
41 if (err)
42 return err;
43
44 psIntfAdapter->psAdapter->DeviceAccess = TRUE;
45
46 bytes = usb_control_msg(psIntfAdapter->udev,
47 usb_rcvctrlpipe(psIntfAdapter->udev, 0),
48 0x02,
49 0xC2,
50 (addr & 0xFFFF),
51 ((addr >> 16) & 0xFFFF),
52 buff,
53 len,
54 5000);
55
56 if (-ENODEV == bytes)
57 psIntfAdapter->psAdapter->device_removed = TRUE;
58
59 if (bytes < 0)
60 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_OTHERS, RDM,
61 DBG_LVL_ALL, "RDM failed status :%d", bytes);
62 else
63 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_OTHERS, RDM,
64 DBG_LVL_ALL, "RDM sent %d", bytes);
65
66 psIntfAdapter->psAdapter->DeviceAccess = false;
67 return bytes;
68}
69
70int InterfaceWRM(struct bcm_interface_adapter *psIntfAdapter,
71 unsigned int addr,
72 void *buff,
73 int len)
74{
75 int retval = 0;
76 int err = 0;
77
78 if (!psIntfAdapter)
79 return -EINVAL;
80
81 err = adapter_err_occurred(psIntfAdapter);
82 if (err)
83 return err;
84
85 psIntfAdapter->psAdapter->DeviceAccess = TRUE;
86
87 retval = usb_control_msg(psIntfAdapter->udev,
88 usb_sndctrlpipe(psIntfAdapter->udev, 0),
89 0x01,
90 0x42,
91 (addr & 0xFFFF),
92 ((addr >> 16) & 0xFFFF),
93 buff,
94 len,
95 5000);
96
97 if (-ENODEV == retval)
98 psIntfAdapter->psAdapter->device_removed = TRUE;
99
100 if (retval < 0) {
101 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_OTHERS, WRM,
102 DBG_LVL_ALL, "WRM failed status :%d", retval);
103 psIntfAdapter->psAdapter->DeviceAccess = false;
104 return retval;
105 } else {
106 psIntfAdapter->psAdapter->DeviceAccess = false;
107 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_OTHERS, WRM,
108 DBG_LVL_ALL, "WRM sent %d", retval);
109 return STATUS_SUCCESS;
110 }
111}
112
113int BcmRDM(void *arg,
114 unsigned int addr,
115 void *buff,
116 int len)
117{
118 return InterfaceRDM((struct bcm_interface_adapter *)arg, addr, buff,
119 len);
120}
121
122int BcmWRM(void *arg,
123 unsigned int addr,
124 void *buff,
125 int len)
126{
127 return InterfaceWRM((struct bcm_interface_adapter *)arg, addr, buff,
128 len);
129}
130
131int Bcm_clear_halt_of_endpoints(struct bcm_mini_adapter *Adapter)
132{
133 struct bcm_interface_adapter *psIntfAdapter =
134 (struct bcm_interface_adapter *)(Adapter->pvInterfaceAdapter);
135 int status = STATUS_SUCCESS;
136
137 /*
138 * usb_clear_halt - tells device to clear endpoint halt/stall condition
139 * @dev: device whose endpoint is halted
140 * @pipe: endpoint "pipe" being cleared
141 * @ Context: !in_interrupt ()
142 *
143 * usb_clear_halt is the synchrnous call and returns 0 on success else
144 * returns with error code.
145 * This is used to clear halt conditions for bulk and interrupt
146 * endpoints only.
147 * Control and isochronous endpoints never halts.
148 *
149 * Any URBs queued for such an endpoint should normally be unlinked by
150 * the driver before clearing the halt condition.
151 *
152 */
153
154 /* Killing all the submitted urbs to different end points. */
155 Bcm_kill_all_URBs(psIntfAdapter);
156
157 /* clear the halted/stalled state for every end point */
158 status = usb_clear_halt(psIntfAdapter->udev,
159 psIntfAdapter->sIntrIn.int_in_pipe);
160 if (status != STATUS_SUCCESS)
161 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, INTF_INIT,
162 DBG_LVL_ALL,
163 "Unable to Clear Halt of Interrupt IN end point. :%d ",
164 status);
165
166 status = usb_clear_halt(psIntfAdapter->udev,
167 psIntfAdapter->sBulkIn.bulk_in_pipe);
168 if (status != STATUS_SUCCESS)
169 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, INTF_INIT,
170 DBG_LVL_ALL,
171 "Unable to Clear Halt of Bulk IN end point. :%d ",
172 status);
173
174 status = usb_clear_halt(psIntfAdapter->udev,
175 psIntfAdapter->sBulkOut.bulk_out_pipe);
176 if (status != STATUS_SUCCESS)
177 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, INTF_INIT,
178 DBG_LVL_ALL,
179 "Unable to Clear Halt of Bulk OUT end point. :%d ",
180 status);
181
182 return status;
183}
184
185void Bcm_kill_all_URBs(struct bcm_interface_adapter *psIntfAdapter)
186{
187 struct urb *tempUrb = NULL;
188 unsigned int i;
189
190 /*
191 * usb_kill_urb - cancel a transfer request and wait for it to finish
192 * @urb: pointer to URB describing a previously submitted request,
193 * returns nothing as it is void returned API.
194 *
195 * This routine cancels an in-progress request. It is guaranteed that
196 * upon return all completion handlers will have finished and the URB
197 * will be totally idle and available for reuse
198 *
199 * This routine may not be used in an interrupt context (such as a
200 * bottom half or a completion handler), or when holding a spinlock, or
201 * in other situations where the caller can't schedule().
202 *
203 */
204
205 /* Cancel submitted Interrupt-URB's */
206 if (psIntfAdapter->psInterruptUrb) {
207 if (psIntfAdapter->psInterruptUrb->status == -EINPROGRESS)
208 usb_kill_urb(psIntfAdapter->psInterruptUrb);
209 }
210
211 /* Cancel All submitted TX URB's */
212 for (i = 0; i < MAXIMUM_USB_TCB; i++) {
213 tempUrb = psIntfAdapter->asUsbTcb[i].urb;
214 if (tempUrb) {
215 if (tempUrb->status == -EINPROGRESS)
216 usb_kill_urb(tempUrb);
217 }
218 }
219
220 for (i = 0; i < MAXIMUM_USB_RCB; i++) {
221 tempUrb = psIntfAdapter->asUsbRcb[i].urb;
222 if (tempUrb) {
223 if (tempUrb->status == -EINPROGRESS)
224 usb_kill_urb(tempUrb);
225 }
226 }
227
228 atomic_set(&psIntfAdapter->uNumTcbUsed, 0);
229 atomic_set(&psIntfAdapter->uCurrTcb, 0);
230
231 atomic_set(&psIntfAdapter->uNumRcbUsed, 0);
232 atomic_set(&psIntfAdapter->uCurrRcb, 0);
233}
234
235void putUsbSuspend(struct work_struct *work)
236{
237 struct bcm_interface_adapter *psIntfAdapter = NULL;
238 struct usb_interface *intf = NULL;
239
240 psIntfAdapter = container_of(work, struct bcm_interface_adapter,
241 usbSuspendWork);
242 intf = psIntfAdapter->interface;
243
244 if (psIntfAdapter->bSuspended == false)
245 usb_autopm_put_interface(intf);
246}
247
diff --git a/drivers/staging/bcm/InterfaceMisc.h b/drivers/staging/bcm/InterfaceMisc.h
deleted file mode 100644
index 0e5e38b26329..000000000000
--- a/drivers/staging/bcm/InterfaceMisc.h
+++ /dev/null
@@ -1,42 +0,0 @@
1#ifndef __INTERFACE_MISC_H
2#define __INTERFACE_MISC_H
3
4INT
5InterfaceRDM(struct bcm_interface_adapter *psIntfAdapter,
6 UINT addr,
7 PVOID buff,
8 INT len);
9
10INT
11InterfaceWRM(struct bcm_interface_adapter *psIntfAdapter,
12 UINT addr,
13 PVOID buff,
14 INT len);
15
16
17int InterfaceFileDownload(PVOID psIntfAdapter,
18 struct file *flp,
19 unsigned int on_chip_loc);
20
21int InterfaceFileReadbackFromChip(PVOID psIntfAdapter,
22 struct file *flp,
23 unsigned int on_chip_loc);
24
25
26int BcmRDM(PVOID arg,
27 UINT addr,
28 PVOID buff,
29 INT len);
30
31int BcmWRM(PVOID arg,
32 UINT addr,
33 PVOID buff,
34 INT len);
35
36INT Bcm_clear_halt_of_endpoints(struct bcm_mini_adapter *Adapter);
37
38VOID Bcm_kill_all_URBs(struct bcm_interface_adapter *psIntfAdapter);
39
40#define DISABLE_USB_ZERO_LEN_INT 0x0F011878
41
42#endif /* __INTERFACE_MISC_H */
diff --git a/drivers/staging/bcm/InterfaceRx.c b/drivers/staging/bcm/InterfaceRx.c
deleted file mode 100644
index 0f179b9382d3..000000000000
--- a/drivers/staging/bcm/InterfaceRx.c
+++ /dev/null
@@ -1,289 +0,0 @@
1#include "headers.h"
2
3static void handle_control_packet(struct bcm_interface_adapter *interface,
4 struct bcm_mini_adapter *ad,
5 struct bcm_leader *leader,
6 struct sk_buff *skb,
7 struct urb *urb)
8{
9 BCM_DEBUG_PRINT(interface->psAdapter, DBG_TYPE_RX, RX_CTRL, DBG_LVL_ALL,
10 "Received control pkt...");
11 *(PUSHORT)skb->data = leader->Status;
12 memcpy(skb->data+sizeof(USHORT), urb->transfer_buffer +
13 (sizeof(struct bcm_leader)), leader->PLength);
14 skb->len = leader->PLength + sizeof(USHORT);
15
16 spin_lock(&ad->control_queue_lock);
17 ENQUEUEPACKET(ad->RxControlHead, ad->RxControlTail, skb);
18 spin_unlock(&ad->control_queue_lock);
19
20 atomic_inc(&ad->cntrlpktCnt);
21 wake_up(&ad->process_rx_cntrlpkt);
22}
23
24static void format_eth_hdr_to_stack(struct bcm_interface_adapter *interface,
25 struct bcm_mini_adapter *ad,
26 struct bcm_leader *p_leader,
27 struct sk_buff *skb,
28 struct urb *urb,
29 UINT ui_index,
30 int queue_index,
31 bool b_header_supression_endabled)
32{
33 /*
34 * Data Packet, Format a proper Ethernet Header
35 * and give it to the stack
36 */
37 BCM_DEBUG_PRINT(interface->psAdapter, DBG_TYPE_RX, RX_DATA,
38 DBG_LVL_ALL, "Received Data pkt...");
39 skb_reserve(skb, 2 + SKB_RESERVE_PHS_BYTES);
40 memcpy(skb->data+ETH_HLEN, (PUCHAR)urb->transfer_buffer +
41 sizeof(struct bcm_leader), p_leader->PLength);
42 skb->dev = ad->dev;
43
44 /* currently skb->len has extra ETH_HLEN bytes in the beginning */
45 skb_put(skb, p_leader->PLength + ETH_HLEN);
46 ad->PackInfo[queue_index].uiTotalRxBytes += p_leader->PLength;
47 ad->PackInfo[queue_index].uiThisPeriodRxBytes += p_leader->PLength;
48 BCM_DEBUG_PRINT(interface->psAdapter, DBG_TYPE_RX, RX_DATA,
49 DBG_LVL_ALL, "Received Data pkt of len :0x%X",
50 p_leader->PLength);
51
52 if (netif_running(ad->dev)) {
53 /* Moving ahead by ETH_HLEN to the data ptr as received from FW */
54 skb_pull(skb, ETH_HLEN);
55 PHSReceive(ad, p_leader->Vcid, skb, &skb->len,
56 NULL, b_header_supression_endabled);
57
58 if (!ad->PackInfo[queue_index].bEthCSSupport) {
59 skb_push(skb, ETH_HLEN);
60
61 memcpy(skb->data, skb->dev->dev_addr, 6);
62 memcpy(skb->data+6, skb->dev->dev_addr, 6);
63 (*(skb->data+11))++;
64 *(skb->data+12) = 0x08;
65 *(skb->data+13) = 0x00;
66 p_leader->PLength += ETH_HLEN;
67 }
68
69 skb->protocol = eth_type_trans(skb, ad->dev);
70 netif_rx(skb);
71 } else {
72 BCM_DEBUG_PRINT(interface->psAdapter, DBG_TYPE_RX,
73 RX_DATA, DBG_LVL_ALL,
74 "i/f not up hance freeing SKB...");
75 dev_kfree_skb(skb);
76 }
77
78 ++ad->dev->stats.rx_packets;
79 ad->dev->stats.rx_bytes += p_leader->PLength;
80
81 for (ui_index = 0; ui_index < MIBS_MAX_HIST_ENTRIES; ui_index++) {
82 if ((p_leader->PLength <=
83 MIBS_PKTSIZEHIST_RANGE*(ui_index+1)) &&
84 (p_leader->PLength > MIBS_PKTSIZEHIST_RANGE*(ui_index)))
85
86 ad->aRxPktSizeHist[ui_index]++;
87 }
88}
89
90static int SearchVcid(struct bcm_mini_adapter *Adapter, unsigned short usVcid)
91{
92 int iIndex = 0;
93
94 for (iIndex = (NO_OF_QUEUES-1); iIndex >= 0; iIndex--)
95 if (Adapter->PackInfo[iIndex].usVCID_Value == usVcid)
96 return iIndex;
97 return NO_OF_QUEUES+1;
98
99}
100
101
102static struct bcm_usb_rcb *
103GetBulkInRcb(struct bcm_interface_adapter *psIntfAdapter)
104{
105 struct bcm_usb_rcb *pRcb = NULL;
106 UINT index = 0;
107
108 if ((atomic_read(&psIntfAdapter->uNumRcbUsed) < MAXIMUM_USB_RCB) &&
109 (psIntfAdapter->psAdapter->StopAllXaction == false)) {
110 index = atomic_read(&psIntfAdapter->uCurrRcb);
111 pRcb = &psIntfAdapter->asUsbRcb[index];
112 pRcb->bUsed = TRUE;
113 pRcb->psIntfAdapter = psIntfAdapter;
114 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_RX, RX_DPC,
115 DBG_LVL_ALL, "Got Rx desc %d used %d", index,
116 atomic_read(&psIntfAdapter->uNumRcbUsed));
117 index = (index + 1) % MAXIMUM_USB_RCB;
118 atomic_set(&psIntfAdapter->uCurrRcb, index);
119 atomic_inc(&psIntfAdapter->uNumRcbUsed);
120 }
121 return pRcb;
122}
123
124/*this is receive call back - when pkt available for receive (BULK IN- end point)*/
125static void read_bulk_callback(struct urb *urb)
126{
127 struct sk_buff *skb = NULL;
128 bool bHeaderSupressionEnabled = false;
129 int QueueIndex = NO_OF_QUEUES + 1;
130 UINT uiIndex = 0;
131 struct bcm_usb_rcb *pRcb = (struct bcm_usb_rcb *)urb->context;
132 struct bcm_interface_adapter *psIntfAdapter = pRcb->psIntfAdapter;
133 struct bcm_mini_adapter *Adapter = psIntfAdapter->psAdapter;
134 struct bcm_leader *pLeader = urb->transfer_buffer;
135
136 if (unlikely(netif_msg_rx_status(Adapter)))
137 pr_info(PFX "%s: rx urb status %d length %d\n",
138 Adapter->dev->name, urb->status, urb->actual_length);
139
140 if ((Adapter->device_removed == TRUE) ||
141 (TRUE == Adapter->bEndPointHalted) ||
142 (0 == urb->actual_length)) {
143 pRcb->bUsed = false;
144 atomic_dec(&psIntfAdapter->uNumRcbUsed);
145 return;
146 }
147
148 if (urb->status != STATUS_SUCCESS) {
149 if (urb->status == -EPIPE) {
150 Adapter->bEndPointHalted = TRUE;
151 wake_up(&Adapter->tx_packet_wait_queue);
152 } else {
153 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC,
154 DBG_LVL_ALL,
155 "Rx URB has got cancelled. status :%d",
156 urb->status);
157 }
158 pRcb->bUsed = false;
159 atomic_dec(&psIntfAdapter->uNumRcbUsed);
160 urb->status = STATUS_SUCCESS;
161 return;
162 }
163
164 if (Adapter->bDoSuspend && (Adapter->bPreparingForLowPowerMode)) {
165 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL,
166 "device is going in low power mode while PMU option selected..hence rx packet should not be process");
167 return;
168 }
169
170 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL,
171 "Read back done len %d\n", pLeader->PLength);
172 if (!pLeader->PLength) {
173 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL,
174 "Leader Length 0");
175 atomic_dec(&psIntfAdapter->uNumRcbUsed);
176 return;
177 }
178 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL,
179 "Leader Status:0x%hX, Length:0x%hX, VCID:0x%hX",
180 pLeader->Status, pLeader->PLength, pLeader->Vcid);
181 if (MAX_CNTL_PKT_SIZE < pLeader->PLength) {
182 if (netif_msg_rx_err(Adapter))
183 pr_info(PFX "%s: corrupted leader length...%d\n",
184 Adapter->dev->name, pLeader->PLength);
185 ++Adapter->dev->stats.rx_dropped;
186 atomic_dec(&psIntfAdapter->uNumRcbUsed);
187 return;
188 }
189
190 QueueIndex = SearchVcid(Adapter, pLeader->Vcid);
191 if (QueueIndex < NO_OF_QUEUES) {
192 bHeaderSupressionEnabled =
193 Adapter->PackInfo[QueueIndex].bHeaderSuppressionEnabled;
194 bHeaderSupressionEnabled =
195 bHeaderSupressionEnabled & Adapter->bPHSEnabled;
196 }
197
198 skb = dev_alloc_skb(pLeader->PLength + SKB_RESERVE_PHS_BYTES +
199 SKB_RESERVE_ETHERNET_HEADER);
200 if (!skb) {
201 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0,
202 "NO SKBUFF!!! Dropping the Packet");
203 atomic_dec(&psIntfAdapter->uNumRcbUsed);
204 return;
205 }
206 /* If it is a control Packet, then call handle_bcm_packet ()*/
207 if ((ntohs(pLeader->Vcid) == VCID_CONTROL_PACKET) ||
208 (!(pLeader->Status >= 0x20 && pLeader->Status <= 0x3F))) {
209 handle_control_packet(psIntfAdapter, Adapter, pLeader, skb,
210 urb);
211 } else {
212 format_eth_hdr_to_stack(psIntfAdapter, Adapter, pLeader, skb,
213 urb, uiIndex, QueueIndex,
214 bHeaderSupressionEnabled);
215 }
216 Adapter->PrevNumRecvDescs++;
217 pRcb->bUsed = false;
218 atomic_dec(&psIntfAdapter->uNumRcbUsed);
219}
220
221static int ReceiveRcb(struct bcm_interface_adapter *psIntfAdapter,
222 struct bcm_usb_rcb *pRcb)
223{
224 struct urb *urb = pRcb->urb;
225 int retval = 0;
226
227 usb_fill_bulk_urb(urb, psIntfAdapter->udev,
228 usb_rcvbulkpipe(psIntfAdapter->udev,
229 psIntfAdapter->sBulkIn.bulk_in_endpointAddr),
230 urb->transfer_buffer,
231 BCM_USB_MAX_READ_LENGTH,
232 read_bulk_callback, pRcb);
233
234 if (false == psIntfAdapter->psAdapter->device_removed &&
235 false == psIntfAdapter->psAdapter->bEndPointHalted &&
236 false == psIntfAdapter->bSuspended &&
237 false == psIntfAdapter->bPreparingForBusSuspend) {
238 retval = usb_submit_urb(urb, GFP_ATOMIC);
239 if (retval) {
240 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_RX,
241 RX_DPC, DBG_LVL_ALL,
242 "failed submitting read urb, error %d",
243 retval);
244 /* if this return value is because of pipe halt. need to clear this. */
245 if (retval == -EPIPE) {
246 psIntfAdapter->psAdapter->bEndPointHalted = TRUE;
247 wake_up(&psIntfAdapter->psAdapter->tx_packet_wait_queue);
248 }
249
250 }
251 }
252 return retval;
253}
254
255/*
256Function: InterfaceRx
257
258Description: This is the hardware specific Function for Receiving
259 data packet/control packets from the device.
260
261Input parameters: IN struct bcm_mini_adapter *Adapter - Miniport Adapter Context
262
263
264
265Return: TRUE - If Rx was successful.
266 Other - If an error occurred.
267*/
268
269bool InterfaceRx(struct bcm_interface_adapter *psIntfAdapter)
270{
271 USHORT RxDescCount = NUM_RX_DESC -
272 atomic_read(&psIntfAdapter->uNumRcbUsed);
273
274 struct bcm_usb_rcb *pRcb = NULL;
275
276 while (RxDescCount) {
277 pRcb = GetBulkInRcb(psIntfAdapter);
278 if (pRcb == NULL) {
279 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,
280 DBG_TYPE_PRINTK, 0, 0,
281 "Unable to get Rcb pointer");
282 return false;
283 }
284 ReceiveRcb(psIntfAdapter, pRcb);
285 RxDescCount--;
286 }
287 return TRUE;
288}
289
diff --git a/drivers/staging/bcm/InterfaceRx.h b/drivers/staging/bcm/InterfaceRx.h
deleted file mode 100644
index b4e858bcda34..000000000000
--- a/drivers/staging/bcm/InterfaceRx.h
+++ /dev/null
@@ -1,7 +0,0 @@
1#ifndef _INTERFACE_RX_H
2#define _INTERFACE_RX_H
3
4bool InterfaceRx(struct bcm_interface_adapter *Adapter);
5
6#endif
7
diff --git a/drivers/staging/bcm/InterfaceTx.c b/drivers/staging/bcm/InterfaceTx.c
deleted file mode 100644
index 9b3f64b821ed..000000000000
--- a/drivers/staging/bcm/InterfaceTx.c
+++ /dev/null
@@ -1,213 +0,0 @@
1#include "headers.h"
2
3static void prepare_low_power_mode(struct urb *urb,
4 struct bcm_interface_adapter *interface,
5 struct bcm_mini_adapter *ps_adapter,
6 struct bcm_mini_adapter *ad,
7 struct bcm_link_request *p_control_msg,
8 bool *b_power_down_msg)
9{
10 if (((p_control_msg->szData[0] == GO_TO_IDLE_MODE_PAYLOAD) &&
11 (p_control_msg->szData[1] == TARGET_CAN_GO_TO_IDLE_MODE))) {
12
13 *b_power_down_msg = TRUE;
14 /*
15 * This covers the bus err while Idle Request msg
16 * sent down.
17 */
18 if (urb->status != STATUS_SUCCESS) {
19 ps_adapter->bPreparingForLowPowerMode = false;
20 BCM_DEBUG_PRINT(ad, DBG_TYPE_TX, NEXT_SEND,
21 DBG_LVL_ALL,
22 "Idle Mode Request msg failed to reach to Modem");
23 /* Signalling the cntrl pkt path in Ioctl */
24 wake_up(&ps_adapter->lowpower_mode_wait_queue);
25 StartInterruptUrb(interface);
26 return;
27 }
28
29 if (ps_adapter->bDoSuspend == false) {
30 ps_adapter->IdleMode = TRUE;
31 /* since going in Idle mode completed hence making this var false */
32 ps_adapter->bPreparingForLowPowerMode = false;
33
34 BCM_DEBUG_PRINT(ad, DBG_TYPE_TX, NEXT_SEND,
35 DBG_LVL_ALL,
36 "Host Entered in Idle Mode State...");
37 /* Signalling the cntrl pkt path in Ioctl*/
38 wake_up(&ps_adapter->lowpower_mode_wait_queue);
39 }
40
41 } else if ((p_control_msg->Leader.Status == LINK_UP_CONTROL_REQ) &&
42 (p_control_msg->szData[0] == LINK_UP_ACK) &&
43 (p_control_msg->szData[1] == LINK_SHUTDOWN_REQ_FROM_FIRMWARE) &&
44 (p_control_msg->szData[2] == SHUTDOWN_ACK_FROM_DRIVER)) {
45 /*
46 * This covers the bus err while shutdown Request
47 * msg sent down.
48 */
49 if (urb->status != STATUS_SUCCESS) {
50 ps_adapter->bPreparingForLowPowerMode = false;
51 BCM_DEBUG_PRINT(ad, DBG_TYPE_TX, NEXT_SEND,
52 DBG_LVL_ALL,
53 "Shutdown Request Msg failed to reach to Modem");
54 /* Signalling the cntrl pkt path in Ioctl */
55 wake_up(&ps_adapter->lowpower_mode_wait_queue);
56 StartInterruptUrb(interface);
57 return;
58 }
59
60 *b_power_down_msg = TRUE;
61 if (ps_adapter->bDoSuspend == false) {
62 ps_adapter->bShutStatus = TRUE;
63 /*
64 * since going in shutdown mode completed hence
65 * making this var false
66 */
67 ps_adapter->bPreparingForLowPowerMode = false;
68 BCM_DEBUG_PRINT(ad, DBG_TYPE_TX, NEXT_SEND,
69 DBG_LVL_ALL,
70 "Host Entered in shutdown Mode State...");
71 /* Signalling the cntrl pkt path in Ioctl */
72 wake_up(&ps_adapter->lowpower_mode_wait_queue);
73 }
74 }
75
76 if (ps_adapter->bDoSuspend && *b_power_down_msg) {
77 /* issuing bus suspend request */
78 BCM_DEBUG_PRINT(ad, DBG_TYPE_TX, NEXT_SEND, DBG_LVL_ALL,
79 "Issuing the Bus suspend request to USB stack");
80 interface->bPreparingForBusSuspend = TRUE;
81 schedule_work(&interface->usbSuspendWork);
82 }
83}
84
85/*this is transmit call-back(BULK OUT)*/
86static void write_bulk_callback(struct urb *urb/*, struct pt_regs *regs*/)
87{
88 struct bcm_usb_tcb *pTcb = (struct bcm_usb_tcb *)urb->context;
89 struct bcm_interface_adapter *psIntfAdapter = pTcb->psIntfAdapter;
90 struct bcm_link_request *pControlMsg =
91 (struct bcm_link_request *)urb->transfer_buffer;
92 struct bcm_mini_adapter *psAdapter = psIntfAdapter->psAdapter;
93 bool bpowerDownMsg = false;
94 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
95
96 if (unlikely(netif_msg_tx_done(Adapter)))
97 pr_info(PFX "%s: transmit status %d\n", Adapter->dev->name,
98 urb->status);
99
100 if (urb->status != STATUS_SUCCESS) {
101 if (urb->status == -EPIPE) {
102 psIntfAdapter->psAdapter->bEndPointHalted = TRUE;
103 wake_up(&psIntfAdapter->psAdapter->tx_packet_wait_queue);
104 } else {
105 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, NEXT_SEND,
106 DBG_LVL_ALL,
107 "Tx URB has got cancelled. status :%d",
108 urb->status);
109 }
110 }
111
112 pTcb->bUsed = false;
113 atomic_dec(&psIntfAdapter->uNumTcbUsed);
114
115 if (TRUE == psAdapter->bPreparingForLowPowerMode) {
116 prepare_low_power_mode(urb, psIntfAdapter, psAdapter, Adapter,
117 pControlMsg, &bpowerDownMsg);
118 }
119
120 usb_free_coherent(urb->dev, urb->transfer_buffer_length,
121 urb->transfer_buffer, urb->transfer_dma);
122}
123
124
125static struct bcm_usb_tcb *GetBulkOutTcb(struct bcm_interface_adapter *psIntfAdapter)
126{
127 struct bcm_usb_tcb *pTcb = NULL;
128 UINT index = 0;
129
130 if ((atomic_read(&psIntfAdapter->uNumTcbUsed) < MAXIMUM_USB_TCB) &&
131 (psIntfAdapter->psAdapter->StopAllXaction == false)) {
132 index = atomic_read(&psIntfAdapter->uCurrTcb);
133 pTcb = &psIntfAdapter->asUsbTcb[index];
134 pTcb->bUsed = TRUE;
135 pTcb->psIntfAdapter = psIntfAdapter;
136 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_TX,
137 NEXT_SEND, DBG_LVL_ALL,
138 "Got Tx desc %d used %d",
139 index,
140 atomic_read(&psIntfAdapter->uNumTcbUsed));
141 index = (index + 1) % MAXIMUM_USB_TCB;
142 atomic_set(&psIntfAdapter->uCurrTcb, index);
143 atomic_inc(&psIntfAdapter->uNumTcbUsed);
144 }
145 return pTcb;
146}
147
148static int TransmitTcb(struct bcm_interface_adapter *psIntfAdapter,
149 struct bcm_usb_tcb *pTcb, PVOID data, int len)
150{
151
152 struct urb *urb = pTcb->urb;
153 int retval = 0;
154
155 urb->transfer_buffer = usb_alloc_coherent(psIntfAdapter->udev, len,
156 GFP_ATOMIC, &urb->transfer_dma);
157 if (!urb->transfer_buffer) {
158 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0,
159 "Error allocating memory\n");
160 return -ENOMEM;
161 }
162 memcpy(urb->transfer_buffer, data, len);
163 urb->transfer_buffer_length = len;
164
165 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_TX, NEXT_SEND,
166 DBG_LVL_ALL, "Sending Bulk out packet\n");
167 /* For T3B,INT OUT end point will be used as bulk out end point */
168 if ((psIntfAdapter->psAdapter->chip_id == T3B) &&
169 (psIntfAdapter->bHighSpeedDevice == TRUE)) {
170 usb_fill_int_urb(urb, psIntfAdapter->udev,
171 psIntfAdapter->sBulkOut.bulk_out_pipe,
172 urb->transfer_buffer, len, write_bulk_callback, pTcb,
173 psIntfAdapter->sBulkOut.int_out_interval);
174 } else {
175 usb_fill_bulk_urb(urb, psIntfAdapter->udev,
176 psIntfAdapter->sBulkOut.bulk_out_pipe,
177 urb->transfer_buffer, len, write_bulk_callback, pTcb);
178 }
179 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; /* For DMA transfer */
180
181 if (false == psIntfAdapter->psAdapter->device_removed &&
182 false == psIntfAdapter->psAdapter->bEndPointHalted &&
183 false == psIntfAdapter->bSuspended &&
184 false == psIntfAdapter->bPreparingForBusSuspend) {
185 retval = usb_submit_urb(urb, GFP_ATOMIC);
186 if (retval) {
187 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_TX,
188 NEXT_SEND, DBG_LVL_ALL,
189 "failed submitting write urb, error %d",
190 retval);
191 if (retval == -EPIPE) {
192 psIntfAdapter->psAdapter->bEndPointHalted = TRUE;
193 wake_up(&psIntfAdapter->psAdapter->tx_packet_wait_queue);
194 }
195 }
196 }
197 return retval;
198}
199
200int InterfaceTransmitPacket(PVOID arg, PVOID data, UINT len)
201{
202 struct bcm_usb_tcb *pTcb = NULL;
203 struct bcm_interface_adapter *psIntfAdapter = arg;
204
205 pTcb = GetBulkOutTcb(psIntfAdapter);
206 if (pTcb == NULL) {
207 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_PRINTK, 0, 0,
208 "No URB to transmit packet, dropping packet");
209 return -EFAULT;
210 }
211 return TransmitTcb(psIntfAdapter, pTcb, data, len);
212}
213
diff --git a/drivers/staging/bcm/InterfaceTx.h b/drivers/staging/bcm/InterfaceTx.h
deleted file mode 100644
index 273147577c17..000000000000
--- a/drivers/staging/bcm/InterfaceTx.h
+++ /dev/null
@@ -1,7 +0,0 @@
1#ifndef _INTERFACE_TX_H
2#define _INTERFACE_TX_H
3
4INT InterfaceTransmitPacket(PVOID arg, PVOID data, UINT len);
5
6#endif
7
diff --git a/drivers/staging/bcm/Ioctl.h b/drivers/staging/bcm/Ioctl.h
deleted file mode 100644
index fa5f8671612e..000000000000
--- a/drivers/staging/bcm/Ioctl.h
+++ /dev/null
@@ -1,226 +0,0 @@
1#ifndef _IOCTL_H_
2#define _IOCTL_H_
3
4struct bcm_rdm_buffer {
5 unsigned long Register;
6 unsigned long Length;
7} __packed;
8
9struct bcm_wrm_buffer {
10 unsigned long Register;
11 unsigned long Length;
12 unsigned char Data[4];
13} __packed;
14
15struct bcm_ioctl_buffer {
16 void __user *InputBuffer;
17 unsigned long InputLength;
18 void __user *OutputBuffer;
19 unsigned long OutputLength;
20} __packed;
21
22struct bcm_gpio_info {
23 unsigned int uiGpioNumber; /* valid numbers 0-15 */
24 unsigned int uiGpioValue; /* 1 set ; 0 not set */
25} __packed;
26
27struct bcm_user_thread_req {
28 /* 0->Inactivate LED thread. */
29 /* 1->Activate the LED thread */
30 unsigned int ThreadState;
31} __packed;
32
33#define LED_THREAD_ACTIVATION_REQ 1
34#define BCM_IOCTL 'k'
35#define IOCTL_SEND_CONTROL_MESSAGE _IOW(BCM_IOCTL, 0x801, int)
36#define IOCTL_BCM_REGISTER_WRITE _IOW(BCM_IOCTL, 0x802, int)
37#define IOCTL_BCM_REGISTER_READ _IOR(BCM_IOCTL, 0x803, int)
38#define IOCTL_BCM_COMMON_MEMORY_WRITE _IOW(BCM_IOCTL, 0x804, int)
39#define IOCTL_BCM_COMMON_MEMORY_READ _IOR(BCM_IOCTL, 0x805, int)
40#define IOCTL_GET_CONTROL_MESSAGE _IOR(BCM_IOCTL, 0x806, int)
41#define IOCTL_BCM_FIRMWARE_DOWNLOAD _IOW(BCM_IOCTL, 0x807, int)
42#define IOCTL_BCM_SET_SEND_VCID _IOW(BCM_IOCTL, 0x808, int)
43#define IOCTL_BCM_SWITCH_TRANSFER_MODE _IOW(BCM_IOCTL, 0x809, int)
44#define IOCTL_LINK_REQ _IOW(BCM_IOCTL, 0x80A, int)
45#define IOCTL_RSSI_LEVEL_REQ _IOW(BCM_IOCTL, 0x80B, int)
46#define IOCTL_IDLE_REQ _IOW(BCM_IOCTL, 0x80C, int)
47#define IOCTL_SS_INFO_REQ _IOW(BCM_IOCTL, 0x80D, int)
48#define IOCTL_GET_STATISTICS_POINTER _IOW(BCM_IOCTL, 0x80E, int)
49#define IOCTL_CM_REQUEST _IOW(BCM_IOCTL, 0x80F, int)
50#define IOCTL_INIT_PARAM_REQ _IOW(BCM_IOCTL, 0x810, int)
51#define IOCTL_MAC_ADDR_REQ _IOW(BCM_IOCTL, 0x811, int)
52#define IOCTL_MAC_ADDR_RESP _IOWR(BCM_IOCTL, 0x812, int)
53#define IOCTL_CLASSIFICATION_RULE _IOW(BCM_IOCTL, 0x813, char)
54#define IOCTL_CLOSE_NOTIFICATION _IO(BCM_IOCTL, 0x814)
55#define IOCTL_LINK_UP _IO(BCM_IOCTL, 0x815)
56#define IOCTL_LINK_DOWN _IO(BCM_IOCTL, 0x816, struct bcm_ioctl_buffer)
57#define IOCTL_CHIP_RESET _IO(BCM_IOCTL, 0x816)
58#define IOCTL_CINR_LEVEL_REQ _IOW(BCM_IOCTL, 0x817, char)
59#define IOCTL_WTM_CONTROL_REQ _IOW(BCM_IOCTL, 0x817, char)
60#define IOCTL_BE_BUCKET_SIZE _IOW(BCM_IOCTL, 0x818, unsigned long)
61#define IOCTL_RTPS_BUCKET_SIZE _IOW(BCM_IOCTL, 0x819, unsigned long)
62#define IOCTL_QOS_THRESHOLD _IOW(BCM_IOCTL, 0x820, unsigned long)
63#define IOCTL_DUMP_PACKET_INFO _IO(BCM_IOCTL, 0x821)
64#define IOCTL_GET_PACK_INFO _IOR(BCM_IOCTL, 0x823, int)
65#define IOCTL_BCM_GET_DRIVER_VERSION _IOR(BCM_IOCTL, 0x829, int)
66#define IOCTL_BCM_GET_CURRENT_STATUS _IOW(BCM_IOCTL, 0x828, int)
67#define IOCTL_BCM_GPIO_SET_REQUEST _IOW(BCM_IOCTL, 0x82A, int)
68#define IOCTL_BCM_GPIO_STATUS_REQUEST _IOW(BCM_IOCTL, 0x82b, int)
69#define IOCTL_BCM_GET_DSX_INDICATION _IOR(BCM_IOCTL, 0x854, int)
70#define IOCTL_BCM_BUFFER_DOWNLOAD_START _IOW(BCM_IOCTL, 0x855, int)
71#define IOCTL_BCM_BUFFER_DOWNLOAD _IOW(BCM_IOCTL, 0x856, int)
72#define IOCTL_BCM_BUFFER_DOWNLOAD_STOP _IOW(BCM_IOCTL, 0x857, int)
73#define IOCTL_BCM_REGISTER_WRITE_PRIVATE _IOW(BCM_IOCTL, 0x826, char)
74#define IOCTL_BCM_REGISTER_READ_PRIVATE _IOW(BCM_IOCTL, 0x827, char)
75#define IOCTL_BCM_SET_DEBUG _IOW(BCM_IOCTL, 0x824, struct bcm_ioctl_buffer)
76#define IOCTL_BCM_EEPROM_REGISTER_WRITE _IOW(BCM_IOCTL, 0x858, int)
77#define IOCTL_BCM_EEPROM_REGISTER_READ _IOR(BCM_IOCTL, 0x859, int)
78#define IOCTL_BCM_WAKE_UP_DEVICE_FROM_IDLE _IOR(BCM_IOCTL, 0x860, int)
79#define IOCTL_BCM_SET_MAC_TRACING _IOW(BCM_IOCTL, 0x82c, int)
80#define IOCTL_BCM_GET_HOST_MIBS _IOW(BCM_IOCTL, 0x853, int)
81#define IOCTL_BCM_NVM_READ _IOR(BCM_IOCTL, 0x861, int)
82#define IOCTL_BCM_NVM_WRITE _IOW(BCM_IOCTL, 0x862, int)
83#define IOCTL_BCM_GET_NVM_SIZE _IOR(BCM_IOCTL, 0x863, int)
84#define IOCTL_BCM_CAL_INIT _IOR(BCM_IOCTL, 0x864, int)
85#define IOCTL_BCM_BULK_WRM _IOW(BCM_IOCTL, 0x90B, int)
86#define IOCTL_BCM_FLASH2X_SECTION_READ _IOR(BCM_IOCTL, 0x865, int)
87#define IOCTL_BCM_FLASH2X_SECTION_WRITE _IOW(BCM_IOCTL, 0x866, int)
88#define IOCTL_BCM_GET_FLASH2X_SECTION_BITMAP _IOR(BCM_IOCTL, 0x867, int)
89#define IOCTL_BCM_SET_ACTIVE_SECTION _IOW(BCM_IOCTL, 0x868, int)
90#define IOCTL_BCM_IDENTIFY_ACTIVE_SECTION _IO(BCM_IOCTL, 0x869)
91#define IOCTL_BCM_COPY_SECTION _IOW(BCM_IOCTL, 0x870, int)
92#define IOCTL_BCM_GET_FLASH_CS_INFO _IOR(BCM_IOCTL, 0x871, int)
93#define IOCTL_BCM_SELECT_DSD _IOW(BCM_IOCTL, 0x872, int)
94#define IOCTL_BCM_NVM_RAW_READ _IOR(BCM_IOCTL, 0x875, int)
95#define IOCTL_BCM_CNTRLMSG_MASK _IOW(BCM_IOCTL, 0x874, int)
96#define IOCTL_BCM_GET_DEVICE_DRIVER_INFO _IOR(BCM_IOCTL, 0x877, int)
97#define IOCTL_BCM_TIME_SINCE_NET_ENTRY _IOR(BCM_IOCTL, 0x876, int)
98#define BCM_LED_THREAD_STATE_CHANGE_REQ _IOW(BCM_IOCTL, 0x878, int)
99#define IOCTL_BCM_GPIO_MULTI_REQUEST _IOW(BCM_IOCTL, 0x82D, struct bcm_ioctl_buffer)
100#define IOCTL_BCM_GPIO_MODE_REQUEST _IOW(BCM_IOCTL, 0x82E, struct bcm_ioctl_buffer)
101
102enum bcm_interface_type {
103 BCM_MII,
104 BCM_CARDBUS,
105 BCM_USB,
106 BCM_SDIO,
107 BCM_PCMCIA
108};
109
110struct bcm_driver_info {
111 enum bcm_nvm_type u32NVMType;
112 unsigned int MaxRDMBufferSize;
113 enum bcm_interface_type u32InterfaceType;
114 unsigned int u32DSDStartOffset;
115 unsigned int u32RxAlignmentCorrection;
116 unsigned int u32Reserved[10];
117};
118
119struct bcm_nvm_readwrite {
120 void __user *pBuffer;
121 uint32_t uiOffset;
122 uint32_t uiNumBytes;
123 bool bVerify;
124};
125
126struct bcm_bulk_wrm_buffer {
127 unsigned long Register;
128 unsigned long SwapEndian;
129 unsigned long Values[1];
130};
131
132enum bcm_flash2x_section_val {
133 NO_SECTION_VAL = 0, /* no section chosen when absolute offset is given for RD/WR */
134 ISO_IMAGE1,
135 ISO_IMAGE2,
136 DSD0,
137 DSD1,
138 DSD2,
139 VSA0,
140 VSA1,
141 VSA2,
142 SCSI,
143 CONTROL_SECTION,
144 ISO_IMAGE1_PART2,
145 ISO_IMAGE1_PART3,
146 ISO_IMAGE2_PART2,
147 ISO_IMAGE2_PART3,
148 TOTAL_SECTIONS
149};
150
151/*
152 * Structure used for READ/WRITE Flash Map2.x
153 */
154struct bcm_flash2x_readwrite {
155 enum bcm_flash2x_section_val Section; /* section to be read/written */
156 u32 offset; /* offset within section. */
157 u32 numOfBytes; /* number of bytes from the offset */
158 u32 bVerify;
159 void __user *pDataBuff; /* buffer for reading/writing */
160};
161
162/*
163 * This structure is used for coping one section to other.
164 * there are two ways to copy one section to other.
165 * it NOB =0, complete section will be copied on to other.
166 * if NOB !=0, only NOB will be copied from the given offset.
167 */
168
169struct bcm_flash2x_copy_section {
170 enum bcm_flash2x_section_val SrcSection;
171 enum bcm_flash2x_section_val DstSection;
172 u32 offset;
173 u32 numOfBytes;
174};
175
176/*
177 * This section provide the complete bitmap of the Flash.
178 * using this map lib/APP will issue read/write command.
179 * Fields are defined as :
180 * Bit [0] = section is present //1:present, 0: Not present
181 * Bit [1] = section is valid //1: valid, 0: not valid
182 * Bit [2] = Section is R/W //0: RW, 1: RO
183 * Bit [3] = Section is Active or not 1 means Active, 0->inactive
184 * Bit [7...3] = Reserved
185 */
186
187struct bcm_flash2x_bitmap {
188 unsigned char ISO_IMAGE1;
189 unsigned char ISO_IMAGE2;
190 unsigned char DSD0;
191 unsigned char DSD1;
192 unsigned char DSD2;
193 unsigned char VSA0;
194 unsigned char VSA1;
195 unsigned char VSA2;
196 unsigned char SCSI;
197 unsigned char CONTROL_SECTION;
198 /* Reserved for future use */
199 unsigned char Reserved0;
200 unsigned char Reserved1;
201 unsigned char Reserved2;
202};
203
204struct bcm_time_elapsed {
205 u64 ul64TimeElapsedSinceNetEntry;
206 u32 uiReserved[4];
207};
208
209enum {
210 WIMAX_IDX = 0, /* To access WiMAX chip GPIO's for GPIO_MULTI_INFO or GPIO_MULTI_MODE */
211 HOST_IDX, /* To access Host chip GPIO's for GPIO_MULTI_INFO or GPIO_MULTI_MODE */
212 MAX_IDX
213};
214
215struct bcm_gpio_multi_info {
216 unsigned int uiGPIOCommand; /* 1 for set and 0 for get */
217 unsigned int uiGPIOMask; /* set the corresponding bit to 1 to access GPIO */
218 unsigned int uiGPIOValue; /* 0 or 1; value to be set when command is 1. */
219} __packed;
220
221struct bcm_gpio_multi_mode {
222 unsigned int uiGPIOMode; /* 1 for OUT mode, 0 for IN mode */
223 unsigned int uiGPIOMask; /* GPIO mask to set mode */
224} __packed;
225
226#endif
diff --git a/drivers/staging/bcm/Kconfig b/drivers/staging/bcm/Kconfig
deleted file mode 100644
index 8acf4b24a7c9..000000000000
--- a/drivers/staging/bcm/Kconfig
+++ /dev/null
@@ -1,6 +0,0 @@
1config BCM_WIMAX
2 tristate "Beceem BCS200/BCS220-3 and BCSM250 wimax support"
3 depends on USB && NET
4 help
5 This is an experimental driver for the Beceem WIMAX chipset used
6 by Sprint 4G.
diff --git a/drivers/staging/bcm/LeakyBucket.c b/drivers/staging/bcm/LeakyBucket.c
deleted file mode 100644
index d6b55f993b57..000000000000
--- a/drivers/staging/bcm/LeakyBucket.c
+++ /dev/null
@@ -1,364 +0,0 @@
1/**********************************************************************
2* LEAKYBUCKET.C
3* This file contains the routines related to Leaky Bucket Algorithm.
4***********************************************************************/
5#include "headers.h"
6
7/**
8 * UpdateTokenCount() - Calculates the token count for each channel
9 * and updates the same in Adapter structure
10 * @Adapter: Pointer to the Adapter structure.
11 *
12 * Return: None
13 */
14static VOID UpdateTokenCount(register struct bcm_mini_adapter *Adapter)
15{
16 ULONG liCurrentTime;
17 INT i = 0;
18 struct timeval tv;
19 struct bcm_packet_info *curr_pi;
20
21 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TOKEN_COUNTS, DBG_LVL_ALL,
22 "=====>\n");
23 if (NULL == Adapter) {
24 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TOKEN_COUNTS,
25 DBG_LVL_ALL, "Adapter found NULL!\n");
26 return;
27 }
28
29 do_gettimeofday(&tv);
30 for (i = 0; i < NO_OF_QUEUES; i++) {
31 curr_pi = &Adapter->PackInfo[i];
32
33 if (TRUE == curr_pi->bValid && (1 == curr_pi->ucDirection)) {
34 liCurrentTime = ((tv.tv_sec -
35 curr_pi->stLastUpdateTokenAt.tv_sec)*1000 +
36 (tv.tv_usec - curr_pi->stLastUpdateTokenAt.tv_usec) /
37 1000);
38 if (0 != liCurrentTime) {
39 curr_pi->uiCurrentTokenCount += (ULONG)
40 ((curr_pi->uiMaxAllowedRate) *
41 ((ULONG)((liCurrentTime)))/1000);
42 memcpy(&curr_pi->stLastUpdateTokenAt, &tv,
43 sizeof(struct timeval));
44 curr_pi->liLastUpdateTokenAt = liCurrentTime;
45 if (curr_pi->uiCurrentTokenCount >=
46 curr_pi->uiMaxBucketSize) {
47 curr_pi->uiCurrentTokenCount =
48 curr_pi->uiMaxBucketSize;
49 }
50 }
51 }
52 }
53 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TOKEN_COUNTS, DBG_LVL_ALL,
54 "<=====\n");
55}
56
57
58/**
59 * IsPacketAllowedForFlow() - This function checks whether the given
60 * packet from the specified queue can be allowed for transmission by
61 * checking the token count.
62 * @Adapter: Pointer to the Adpater structure.
63 * @iQIndex: The queue Identifier.
64 * @ulPacketLength: Number of bytes to be transmitted.
65 *
66 * Returns: The number of bytes allowed for transmission.
67 */
68static ULONG GetSFTokenCount(struct bcm_mini_adapter *Adapter, struct bcm_packet_info *psSF)
69{
70 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TOKEN_COUNTS, DBG_LVL_ALL,
71 "IsPacketAllowedForFlow ===>");
72
73 /* Validate the parameters */
74 if (NULL == Adapter || (psSF < Adapter->PackInfo &&
75 (uintptr_t)psSF > (uintptr_t) &Adapter->PackInfo[HiPriority])) {
76 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TOKEN_COUNTS, DBG_LVL_ALL,
77 "IPAFF: Got wrong Parameters:Adapter: %p, QIndex: %zd\n",
78 Adapter, (psSF-Adapter->PackInfo));
79 return 0;
80 }
81
82 if (false != psSF->bValid && psSF->ucDirection) {
83 if (0 != psSF->uiCurrentTokenCount) {
84 return psSF->uiCurrentTokenCount;
85 } else {
86 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TOKEN_COUNTS,
87 DBG_LVL_ALL,
88 "Not enough tokens in queue %zd Available %u\n",
89 psSF-Adapter->PackInfo, psSF->uiCurrentTokenCount);
90 psSF->uiPendedLast = 1;
91 }
92 } else {
93 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TOKEN_COUNTS, DBG_LVL_ALL,
94 "IPAFF: Queue %zd not valid\n",
95 psSF-Adapter->PackInfo);
96 }
97 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TOKEN_COUNTS, DBG_LVL_ALL,
98 "IsPacketAllowedForFlow <===");
99 return 0;
100}
101
102/**
103@ingroup tx_functions
104This function despatches packet from the specified queue.
105@return Zero(success) or Negative value(failure)
106*/
107static INT SendPacketFromQueue(struct bcm_mini_adapter *Adapter,/**<Logical Adapter*/
108 struct bcm_packet_info *psSF, /**<Queue identifier*/
109 struct sk_buff *Packet) /**<Pointer to the packet to be sent*/
110{
111 INT Status = STATUS_FAILURE;
112 UINT uiIndex = 0, PktLen = 0;
113
114 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, SEND_QUEUE, DBG_LVL_ALL,
115 "=====>");
116 if (!Adapter || !Packet || !psSF) {
117 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, SEND_QUEUE, DBG_LVL_ALL,
118 "Got NULL Adapter or Packet");
119 return -EINVAL;
120 }
121
122 if (psSF->liDrainCalculated == 0)
123 psSF->liDrainCalculated = jiffies;
124 /* send the packet to the fifo.. */
125 PktLen = Packet->len;
126 Status = SetupNextSend(Adapter, Packet, psSF->usVCID_Value);
127 if (Status == 0) {
128 for (uiIndex = 0; uiIndex < MIBS_MAX_HIST_ENTRIES; uiIndex++) {
129 if ((PktLen <= MIBS_PKTSIZEHIST_RANGE*(uiIndex+1)) &&
130 (PktLen > MIBS_PKTSIZEHIST_RANGE*(uiIndex)))
131 Adapter->aTxPktSizeHist[uiIndex]++;
132 }
133 }
134 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, SEND_QUEUE, DBG_LVL_ALL,
135 "<=====");
136 return Status;
137}
138
139static void get_data_packet(struct bcm_mini_adapter *ad,
140 struct bcm_packet_info *ps_sf)
141{
142 int packet_len;
143 struct sk_buff *qpacket;
144
145 if (!ps_sf->ucDirection)
146 return;
147
148 BCM_DEBUG_PRINT(ad, DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL,
149 "UpdateTokenCount ");
150 if (ad->IdleMode || ad->bPreparingForLowPowerMode)
151 return; /* in idle mode */
152
153 /* Check for Free Descriptors */
154 if (atomic_read(&ad->CurrNumFreeTxDesc) <=
155 MINIMUM_PENDING_DESCRIPTORS) {
156 BCM_DEBUG_PRINT(ad, DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL,
157 " No Free Tx Descriptor(%d) is available for Data pkt..",
158 atomic_read(&ad->CurrNumFreeTxDesc));
159 return;
160 }
161
162 spin_lock_bh(&ps_sf->SFQueueLock);
163 qpacket = ps_sf->FirstTxQueue;
164
165 if (qpacket) {
166 BCM_DEBUG_PRINT(ad, DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL,
167 "Dequeuing Data Packet");
168
169 if (ps_sf->bEthCSSupport)
170 packet_len = qpacket->len;
171 else
172 packet_len = qpacket->len - ETH_HLEN;
173
174 packet_len <<= 3;
175 if (packet_len <= GetSFTokenCount(ad, ps_sf)) {
176 BCM_DEBUG_PRINT(ad, DBG_TYPE_TX, TX_PACKETS,
177 DBG_LVL_ALL, "Allowed bytes %d",
178 (packet_len >> 3));
179
180 DEQUEUEPACKET(ps_sf->FirstTxQueue, ps_sf->LastTxQueue);
181 ps_sf->uiCurrentBytesOnHost -= (qpacket->len);
182 ps_sf->uiCurrentPacketsOnHost--;
183 atomic_dec(&ad->TotalPacketCount);
184 spin_unlock_bh(&ps_sf->SFQueueLock);
185
186 SendPacketFromQueue(ad, ps_sf, qpacket);
187 ps_sf->uiPendedLast = false;
188 } else {
189 BCM_DEBUG_PRINT(ad, DBG_TYPE_TX, TX_PACKETS,
190 DBG_LVL_ALL, "For Queue: %zd\n",
191 ps_sf - ad->PackInfo);
192 BCM_DEBUG_PRINT(ad, DBG_TYPE_TX, TX_PACKETS,
193 DBG_LVL_ALL,
194 "\nAvailable Tokens = %d required = %d\n",
195 ps_sf->uiCurrentTokenCount,
196 packet_len);
197 /*
198 this part indicates that because of
199 non-availability of the tokens
200 pkt has not been send out hence setting the
201 pending flag indicating the host to send it out
202 first next iteration.
203 */
204 ps_sf->uiPendedLast = TRUE;
205 spin_unlock_bh(&ps_sf->SFQueueLock);
206 }
207 } else {
208 spin_unlock_bh(&ps_sf->SFQueueLock);
209 }
210}
211
212static void send_control_packet(struct bcm_mini_adapter *ad,
213 struct bcm_packet_info *ps_sf)
214{
215 char *ctrl_packet = NULL;
216 INT status = 0;
217
218 if ((atomic_read(&ad->CurrNumFreeTxDesc) > 0) &&
219 (atomic_read(&ad->index_rd_txcntrlpkt) !=
220 atomic_read(&ad->index_wr_txcntrlpkt))) {
221 ctrl_packet = ad->txctlpacket
222 [(atomic_read(&ad->index_rd_txcntrlpkt)%MAX_CNTRL_PKTS)];
223 if (ctrl_packet) {
224 BCM_DEBUG_PRINT(ad, DBG_TYPE_TX, TX_PACKETS,
225 DBG_LVL_ALL,
226 "Sending Control packet");
227 status = SendControlPacket(ad, ctrl_packet);
228 if (STATUS_SUCCESS == status) {
229 spin_lock_bh(&ps_sf->SFQueueLock);
230 ps_sf->NumOfPacketsSent++;
231 ps_sf->uiSentBytes += ((struct bcm_leader *)ctrl_packet)->PLength;
232 ps_sf->uiSentPackets++;
233 atomic_dec(&ad->TotalPacketCount);
234 ps_sf->uiCurrentBytesOnHost -= ((struct bcm_leader *)ctrl_packet)->PLength;
235 ps_sf->uiCurrentPacketsOnHost--;
236 atomic_inc(&ad->index_rd_txcntrlpkt);
237 spin_unlock_bh(&ps_sf->SFQueueLock);
238 } else {
239 BCM_DEBUG_PRINT(ad, DBG_TYPE_TX, TX_PACKETS,
240 DBG_LVL_ALL,
241 "SendControlPacket Failed\n");
242 }
243 } else {
244 BCM_DEBUG_PRINT(ad, DBG_TYPE_TX, TX_PACKETS,
245 DBG_LVL_ALL,
246 " Control Pkt is not available, Indexing is wrong....");
247 }
248 }
249}
250
251/**
252 * CheckAndSendPacketFromIndex() - This function dequeues the
253 * data/control packet from the specified queue for transmission.
254 * @Adapter: Pointer to the driver control structure.
255 * @iQIndex: The queue Identifier.
256 *
257 * Returns: None.
258 */
259static VOID CheckAndSendPacketFromIndex(struct bcm_mini_adapter *Adapter,
260 struct bcm_packet_info *psSF)
261{
262 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL,
263 "%zd ====>", (psSF-Adapter->PackInfo));
264 if ((psSF != &Adapter->PackInfo[HiPriority]) &&
265 Adapter->LinkUpStatus &&
266 atomic_read(&psSF->uiPerSFTxResourceCount)) { /* Get data packet */
267
268 get_data_packet(Adapter, psSF);
269 } else {
270 send_control_packet(Adapter, psSF);
271 }
272}
273
274
275/**
276 * transmit_packets() - This function transmits the packets from
277 * different queues, if free descriptors are available on target.
278 * @Adapter: Pointer to the Adapter structure.
279 *
280 * Returns: None.
281 */
282VOID transmit_packets(struct bcm_mini_adapter *Adapter)
283{
284 UINT uiPrevTotalCount = 0;
285 int iIndex = 0;
286
287 bool exit_flag = TRUE;
288
289 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL,
290 "=====>");
291
292 if (NULL == Adapter) {
293 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL,
294 "Got NULL Adapter");
295 return;
296 }
297 if (Adapter->device_removed == TRUE) {
298 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL,
299 "Device removed");
300 return;
301 }
302
303 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL,
304 "\nUpdateTokenCount ====>\n");
305
306 UpdateTokenCount(Adapter);
307
308 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL,
309 "\nPruneQueueAllSF ====>\n");
310
311 PruneQueueAllSF(Adapter);
312
313 uiPrevTotalCount = atomic_read(&Adapter->TotalPacketCount);
314
315 for (iIndex = HiPriority; iIndex >= 0; iIndex--) {
316 if (!uiPrevTotalCount || (TRUE == Adapter->device_removed))
317 break;
318
319 if (Adapter->PackInfo[iIndex].bValid &&
320 Adapter->PackInfo[iIndex].uiPendedLast &&
321 Adapter->PackInfo[iIndex].uiCurrentBytesOnHost) {
322 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_PACKETS,
323 DBG_LVL_ALL,
324 "Calling CheckAndSendPacketFromIndex..");
325 CheckAndSendPacketFromIndex(Adapter,
326 &Adapter->PackInfo[iIndex]);
327 uiPrevTotalCount--;
328 }
329 }
330
331 while (uiPrevTotalCount > 0 && !Adapter->device_removed) {
332 exit_flag = TRUE;
333 /* second iteration to parse non-pending queues */
334 for (iIndex = HiPriority; iIndex >= 0; iIndex--) {
335 if (!uiPrevTotalCount ||
336 (TRUE == Adapter->device_removed))
337 break;
338
339 if (Adapter->PackInfo[iIndex].bValid &&
340 Adapter->PackInfo[iIndex].uiCurrentBytesOnHost &&
341 !Adapter->PackInfo[iIndex].uiPendedLast) {
342 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX,
343 TX_PACKETS, DBG_LVL_ALL,
344 "Calling CheckAndSendPacketFromIndex..");
345 CheckAndSendPacketFromIndex(Adapter, &Adapter->PackInfo[iIndex]);
346 uiPrevTotalCount--;
347 exit_flag = false;
348 }
349 }
350
351 if (Adapter->IdleMode || Adapter->bPreparingForLowPowerMode) {
352 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_PACKETS,
353 DBG_LVL_ALL, "In Idle Mode\n");
354 break;
355 }
356 if (exit_flag == TRUE)
357 break;
358 } /* end of inner while loop */
359
360 update_per_cid_rx(Adapter);
361 Adapter->txtransmit_running = 0;
362 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL,
363 "<======");
364}
diff --git a/drivers/staging/bcm/Macros.h b/drivers/staging/bcm/Macros.h
deleted file mode 100644
index dc01e3016d4f..000000000000
--- a/drivers/staging/bcm/Macros.h
+++ /dev/null
@@ -1,352 +0,0 @@
1/*************************************
2* Macros.h
3**************************************/
4#ifndef __MACROS_H__
5#define __MACROS_H__
6
7#define TX_TIMER_PERIOD 10 /*10 msec*/
8#define MAX_CLASSIFIERS 100
9#define MAX_TARGET_DSX_BUFFERS 24
10
11#define MAX_CNTRL_PKTS 100
12#define MAX_DATA_PKTS 200
13#define MAX_ETH_SIZE 1536
14#define MAX_CNTL_PKT_SIZE 2048
15
16#define MTU_SIZE 1400
17#define TX_QLEN 5
18
19#define MAC_ADDR_REGISTER 0xbf60d000
20
21
22/* Quality of Service */
23#define NO_OF_QUEUES 17
24#define HiPriority (NO_OF_QUEUES-1)
25#define LowPriority 0
26#define BE 2
27#define rtPS 4
28#define ERTPS 5
29#define UGS 6
30
31#define BE_BUCKET_SIZE (1024*1024*100) /* 32kb */
32#define rtPS_BUCKET_SIZE (1024*1024*100) /* 8kb */
33#define MAX_ALLOWED_RATE (1024*1024*100)
34#define TX_PACKET_THRESHOLD 10
35#define XSECONDS (1*HZ)
36#define DSC_ACTIVATE_REQUEST 248
37#define QUEUE_DEPTH_OFFSET 0x1fc01000
38#define MAX_DEVICE_DESC_SIZE 2040
39#define MAX_CTRL_QUEUE_LEN 100
40#define MAX_APP_QUEUE_LEN 200
41#define MAX_LATENCY_ALLOWED 0xFFFFFFFF
42#define DEFAULT_UG_INTERVAL 250
43#define DEFAULT_UGI_FACTOR 4
44
45#define DEFAULT_PERSFCOUNT 60
46#define MAX_CONNECTIONS 10
47#define MAX_CLASS_NAME_LENGTH 32
48
49#define ETH_LENGTH_OF_ADDRESS 6
50#define MAX_MULTICAST_ADDRESSES 32
51#define IP_LENGTH_OF_ADDRESS 4
52
53#define IP_PACKET_ONLY_MODE 0
54#define ETH_PACKET_TUNNELING_MODE 1
55
56/* Link Request */
57#define SET_MAC_ADDRESS_REQUEST 0
58#define SYNC_UP_REQUEST 1
59#define SYNCED_UP 2
60#define LINK_UP_REQUEST 3
61#define LINK_CONNECTED 4
62#define SYNC_UP_NOTIFICATION 2
63#define LINK_UP_NOTIFICATION 4
64
65
66#define LINK_NET_ENTRY 0x0002
67#define HMC_STATUS 0x0004
68#define LINK_UP_CONTROL_REQ 0x83
69
70#define STATS_POINTER_REQ_STATUS 0x86
71#define NETWORK_ENTRY_REQ_PAYLOAD 198
72#define LINK_DOWN_REQ_PAYLOAD 226
73#define SYNC_UP_REQ_PAYLOAD 228
74#define STATISTICS_POINTER_REQ 237
75#define LINK_UP_REQ_PAYLOAD 245
76#define LINK_UP_ACK 246
77
78#define STATS_MSG_SIZE 4
79#define INDEX_TO_DATA 4
80
81#define GO_TO_IDLE_MODE_PAYLOAD 210
82#define COME_UP_FROM_IDLE_MODE_PAYLOAD 211
83#define IDLE_MODE_SF_UPDATE_MSG 187
84
85#define SKB_RESERVE_ETHERNET_HEADER 16
86#define SKB_RESERVE_PHS_BYTES 32
87
88#define IP_PACKET_ONLY_MODE 0
89#define ETH_PACKET_TUNNELING_MODE 1
90
91#define ETH_CS_802_3 1
92#define ETH_CS_802_1Q_VLAN 3
93#define IPV4_CS 1
94#define IPV6_CS 2
95#define ETH_CS_MASK 0x3f
96
97/** \brief Validity bit maps for TLVs in packet classification rule */
98
99#define PKT_CLASSIFICATION_USER_PRIORITY_VALID 0
100#define PKT_CLASSIFICATION_VLANID_VALID 1
101
102#ifndef MIN
103#define MIN(_a, _b) ((_a) < (_b) ? (_a) : (_b))
104#endif
105
106
107/*Leader related terms */
108#define LEADER_STATUS 0x00
109#define LEADER_STATUS_TCP_ACK 0x1
110#define LEADER_SIZE sizeof(struct bcm_leader)
111#define MAC_ADDR_REQ_SIZE sizeof(struct bcm_packettosend)
112#define SS_INFO_REQ_SIZE sizeof(struct bcm_packettosend)
113#define CM_REQUEST_SIZE (LEADER_SIZE + sizeof(stLocalSFChangeRequest))
114#define IDLE_REQ_SIZE sizeof(struct bcm_packettosend)
115
116
117#define MAX_TRANSFER_CTRL_BYTE_USB (2*1024)
118
119#define GET_MAILBOX1_REG_REQUEST 0x87
120#define GET_MAILBOX1_REG_RESPONSE 0x67
121#define VCID_CONTROL_PACKET 0x00
122
123#define TRANSMIT_NETWORK_DATA 0x00
124#define RECEIVED_NETWORK_DATA 0x20
125
126#define CM_RESPONSES 0xA0
127#define STATUS_RSP 0xA1
128#define LINK_CONTROL_RESP 0xA2
129#define IDLE_MODE_STATUS 0xA3
130#define STATS_POINTER_RESP 0xA6
131#define MGMT_MSG_INFO_SW_STATUS 0xA7
132#define AUTH_SS_HOST_MSG 0xA8
133
134#define CM_DSA_ACK_PAYLOAD 247
135#define CM_DSC_ACK_PAYLOAD 248
136#define CM_DSD_ACK_PAYLOAD 249
137#define CM_DSDEACTVATE 250
138#define TOTAL_MASKED_ADDRESS_IN_BYTES 32
139
140#define MAC_REQ 0
141#define LINK_RESP 1
142#define RSSI_INDICATION 2
143
144#define SS_INFO 4
145#define STATISTICS_INFO 5
146#define CM_INDICATION 6
147#define PARAM_RESP 7
148#define BUFFER_1K 1024
149#define BUFFER_2K (BUFFER_1K*2)
150#define BUFFER_4K (BUFFER_2K*2)
151#define BUFFER_8K (BUFFER_4K*2)
152#define BUFFER_16K (BUFFER_8K*2)
153#define DOWNLINK_DIR 0
154#define UPLINK_DIR 1
155
156#define BCM_SIGNATURE "BECEEM"
157
158
159#define GPIO_OUTPUT_REGISTER 0x0F00003C
160#define BCM_GPIO_OUTPUT_SET_REG 0x0F000040
161#define BCM_GPIO_OUTPUT_CLR_REG 0x0F000044
162#define GPIO_MODE_REGISTER 0x0F000034
163#define GPIO_PIN_STATE_REGISTER 0x0F000038
164
165struct bcm_link_state {
166 unsigned char ucLinkStatus;
167 unsigned char bIdleMode;
168 unsigned char bShutdownMode;
169};
170
171enum enLinkStatus {
172 WAIT_FOR_SYNC = 1,
173 PHY_SYNC_ACHIVED = 2,
174 LINKUP_IN_PROGRESS = 3,
175 LINKUP_DONE = 4,
176 DREG_RECEIVED = 5,
177 LINK_STATUS_RESET_RECEIVED = 6,
178 PERIODIC_WAKE_UP_NOTIFICATION_FRM_FW = 7,
179 LINK_SHUTDOWN_REQ_FROM_FIRMWARE = 8,
180 COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW = 9
181};
182
183enum bcm_phs_dsc_action {
184 eAddPHSRule = 0,
185 eSetPHSRule,
186 eDeletePHSRule,
187 eDeleteAllPHSRules
188};
189
190#define CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ 0x89 /* Host to Mac */
191#define CM_CONTROL_NEWDSX_MULTICLASSIFIER_RESP 0xA9 /* Mac to Host */
192#define MASK_DISABLE_HEADER_SUPPRESSION 0x10 /* 0b000010000 */
193#define MINIMUM_PENDING_DESCRIPTORS 5
194
195#define SHUTDOWN_HOSTINITIATED_REQUESTPAYLOAD 0xCC
196#define SHUTDOWN_ACK_FROM_DRIVER 0x1
197#define SHUTDOWN_NACK_FROM_DRIVER 0x2
198
199#define LINK_SYNC_UP_SUBTYPE 0x0001
200#define LINK_SYNC_DOWN_SUBTYPE 0x0001
201
202
203
204#define CONT_MODE 1
205#define SINGLE_DESCRIPTOR 1
206
207
208#define DESCRIPTOR_LENGTH 0x30
209#define FIRMWARE_DESCS_ADDRESS 0x1F100000
210
211
212#define CLOCK_RESET_CNTRL_REG_1 0x0F00000C
213#define CLOCK_RESET_CNTRL_REG_2 0x0F000840
214
215
216
217#define TX_DESCRIPTOR_HEAD_REGISTER 0x0F010034
218#define RX_DESCRIPTOR_HEAD_REGISTER 0x0F010094
219
220#define STATISTICS_BEGIN_ADDR 0xbf60f02c
221
222#define MAX_PENDING_CTRL_PACKET (MAX_CTRL_QUEUE_LEN-10)
223
224#define WIMAX_MAX_MTU (MTU_SIZE + ETH_HLEN)
225#define AUTO_LINKUP_ENABLE 0x2
226#define AUTO_SYNC_DISABLE 0x1
227#define AUTO_FIRM_DOWNLOAD 0x1
228#define SETTLE_DOWN_TIME 50
229
230#define HOST_BUS_SUSPEND_BIT 16
231
232#define IDLE_MESSAGE 0x81
233
234#define MIPS_CLOCK_133MHz 1
235
236#define TARGET_CAN_GO_TO_IDLE_MODE 2
237#define TARGET_CAN_NOT_GO_TO_IDLE_MODE 3
238#define IDLE_MODE_PAYLOAD_LENGTH 8
239
240#define IP_HEADER(Buffer) ((IPHeaderFormat *)(Buffer))
241#define IPV4 4
242#define IP_VERSION(byte) (((byte&0xF0)>>4))
243
244#define SET_MAC_ADDRESS 193
245#define SET_MAC_ADDRESS_RESPONSE 236
246
247#define IDLE_MODE_WAKEUP_PATTERN 0xd0ea1d1e
248#define IDLE_MODE_WAKEUP_NOTIFIER_ADDRESS 0x1FC02FA8
249#define IDLE_MODE_MAX_RETRY_COUNT 1000
250
251#define CONFIG_BEGIN_ADDR 0xBF60B000
252
253#define FIRMWARE_BEGIN_ADDR 0xBFC00000
254
255#define INVALID_QUEUE_INDEX NO_OF_QUEUES
256
257#define INVALID_PID ((pid_t)-1)
258#define DDR_80_MHZ 0
259#define DDR_100_MHZ 1
260#define DDR_120_MHZ 2 /* Additional Frequency for T3LP */
261#define DDR_133_MHZ 3
262#define DDR_140_MHZ 4 /* Not Used (Reserved for future) */
263#define DDR_160_MHZ 5 /* Additional Frequency for T3LP */
264#define DDR_180_MHZ 6 /* Not Used (Reserved for future) */
265#define DDR_200_MHZ 7 /* Not Used (Reserved for future) */
266
267#define MIPS_200_MHZ 0
268#define MIPS_160_MHZ 1
269
270#define PLL_800_MHZ 0
271#define PLL_266_MHZ 1
272
273#define DEVICE_POWERSAVE_MODE_AS_MANUAL_CLOCK_GATING 0
274#define DEVICE_POWERSAVE_MODE_AS_PMU_CLOCK_GATING 1
275#define DEVICE_POWERSAVE_MODE_AS_PMU_SHUTDOWN 2
276#define DEVICE_POWERSAVE_MODE_AS_RESERVED 3
277#define DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE 4
278
279
280#define EEPROM_REJECT_REG_1 0x0f003018
281#define EEPROM_REJECT_REG_2 0x0f00301c
282#define EEPROM_REJECT_REG_3 0x0f003008
283#define EEPROM_REJECT_REG_4 0x0f003020
284#define EEPROM_REJECT_MASK 0x0fffffff
285#define VSG_MODE 0x3
286
287/* Idle Mode Related Registers */
288#define DEBUG_INTERRUPT_GENERATOR_REGISTOR 0x0F00007C
289#define SW_ABORT_IDLEMODE_LOC 0x0FF01FFC
290
291#define SW_ABORT_IDLEMODE_PATTERN 0xd0ea1d1e
292#define DEVICE_INT_OUT_EP_REG0 0x0F011870
293#define DEVICE_INT_OUT_EP_REG1 0x0F011874
294
295#define BIN_FILE "/lib/firmware/macxvi200.bin"
296#define CFG_FILE "/lib/firmware/macxvi.cfg"
297#define SF_MAX_ALLOWED_PACKETS_TO_BACKUP 128
298#define MIN_VAL(x, y) ((x) < (y) ? (x) : (y))
299#define MAC_ADDRESS_SIZE 6
300#define EEPROM_COMMAND_Q_REG 0x0F003018
301#define EEPROM_READ_DATA_Q_REG 0x0F003020
302#define CHIP_ID_REG 0x0F000000
303#define GPIO_MODE_REG 0x0F000034
304#define GPIO_OUTPUT_REG 0x0F00003C
305#define WIMAX_MAX_ALLOWED_RATE (1024*1024*50)
306
307#define T3 0xbece0300
308#define TARGET_SFID_TXDESC_MAP_LOC 0xBFFFF400
309
310#define RWM_READ 0
311#define RWM_WRITE 1
312
313#define T3LPB 0xbece3300
314#define BCS220_2 0xbece3311
315#define BCS220_2BC 0xBECE3310
316#define BCS250_BC 0xbece3301
317#define BCS220_3 0xbece3321
318
319
320#define HPM_CONFIG_LDO145 0x0F000D54
321#define HPM_CONFIG_MSW 0x0F000D58
322
323#define T3B 0xbece0310
324enum bcm_nvm_type {
325 NVM_AUTODETECT = 0,
326 NVM_EEPROM,
327 NVM_FLASH,
328 NVM_UNKNOWN
329};
330
331enum bcm_pmu_modes {
332 HYBRID_MODE_7C = 0,
333 INTERNAL_MODE_6 = 1,
334 HYBRID_MODE_6 = 2
335};
336
337#define MAX_RDM_WRM_RETIRES 1
338
339enum eAbortPattern {
340 ABORT_SHUTDOWN_MODE = 1,
341 ABORT_IDLE_REG = 1,
342 ABORT_IDLE_MODE = 2,
343 ABORT_IDLE_SYNCDOWN = 3
344};
345
346
347/* Offsets used by driver in skb cb variable */
348#define SKB_CB_CLASSIFICATION_OFFSET 0
349#define SKB_CB_LATENCY_OFFSET 1
350#define SKB_CB_TCPACK_OFFSET 2
351
352#endif /* __MACROS_H__ */
diff --git a/drivers/staging/bcm/Makefile b/drivers/staging/bcm/Makefile
deleted file mode 100644
index 652b7f87737c..000000000000
--- a/drivers/staging/bcm/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
1#
2# Makefile for Beceem USB Wimax card
3#
4
5obj-$(CONFIG_BCM_WIMAX) += bcm_wimax.o
6
7bcm_wimax-y := InterfaceDld.o InterfaceIdleMode.o InterfaceInit.o InterfaceRx.o \
8 InterfaceIsr.o InterfaceMisc.o InterfaceTx.o \
9 CmHost.o IPv6Protocol.o Qos.o Transmit.o\
10 Bcmnet.o DDRInit.o HandleControlPacket.o\
11 LeakyBucket.o Misc.o sort.o Bcmchar.o hostmibs.o PHSModule.o\
12 led_control.o nvm.o vendorspecificextn.o
diff --git a/drivers/staging/bcm/Misc.c b/drivers/staging/bcm/Misc.c
deleted file mode 100644
index 883f7394dee6..000000000000
--- a/drivers/staging/bcm/Misc.c
+++ /dev/null
@@ -1,1587 +0,0 @@
1#include "headers.h"
2
3static int BcmFileDownload(struct bcm_mini_adapter *Adapter, const char *path, unsigned int loc);
4static void doPowerAutoCorrection(struct bcm_mini_adapter *psAdapter);
5static void HandleShutDownModeRequest(struct bcm_mini_adapter *Adapter, PUCHAR pucBuffer);
6static int bcm_parse_target_params(struct bcm_mini_adapter *Adapter);
7static void beceem_protocol_reset(struct bcm_mini_adapter *Adapter);
8
9static void default_wimax_protocol_initialize(struct bcm_mini_adapter *Adapter)
10{
11 unsigned int uiLoopIndex;
12
13 for (uiLoopIndex = 0; uiLoopIndex < NO_OF_QUEUES-1; uiLoopIndex++) {
14 Adapter->PackInfo[uiLoopIndex].uiThreshold = TX_PACKET_THRESHOLD;
15 Adapter->PackInfo[uiLoopIndex].uiMaxAllowedRate = MAX_ALLOWED_RATE;
16 Adapter->PackInfo[uiLoopIndex].uiMaxBucketSize = 20*1024*1024;
17 }
18
19 Adapter->BEBucketSize = BE_BUCKET_SIZE;
20 Adapter->rtPSBucketSize = rtPS_BUCKET_SIZE;
21 Adapter->LinkStatus = SYNC_UP_REQUEST;
22 Adapter->TransferMode = IP_PACKET_ONLY_MODE;
23 Adapter->usBestEffortQueueIndex = -1;
24}
25
26int InitAdapter(struct bcm_mini_adapter *psAdapter)
27{
28 int i = 0;
29 int Status = STATUS_SUCCESS;
30
31 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Initialising Adapter = %p", psAdapter);
32
33 if (psAdapter == NULL) {
34 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Adapter is NULL");
35 return -EINVAL;
36 }
37
38 sema_init(&psAdapter->NVMRdmWrmLock, 1);
39 sema_init(&psAdapter->rdmwrmsync, 1);
40 spin_lock_init(&psAdapter->control_queue_lock);
41 spin_lock_init(&psAdapter->txtransmitlock);
42 sema_init(&psAdapter->RxAppControlQueuelock, 1);
43 sema_init(&psAdapter->fw_download_sema, 1);
44 sema_init(&psAdapter->LowPowerModeSync, 1);
45
46 for (i = 0; i < NO_OF_QUEUES; i++)
47 spin_lock_init(&psAdapter->PackInfo[i].SFQueueLock);
48 i = 0;
49
50 init_waitqueue_head(&psAdapter->process_rx_cntrlpkt);
51 init_waitqueue_head(&psAdapter->tx_packet_wait_queue);
52 init_waitqueue_head(&psAdapter->process_read_wait_queue);
53 init_waitqueue_head(&psAdapter->ioctl_fw_dnld_wait_queue);
54 init_waitqueue_head(&psAdapter->lowpower_mode_wait_queue);
55 psAdapter->waiting_to_fw_download_done = TRUE;
56 psAdapter->fw_download_done = false;
57
58 default_wimax_protocol_initialize(psAdapter);
59 for (i = 0; i < MAX_CNTRL_PKTS; i++) {
60 psAdapter->txctlpacket[i] = kmalloc(MAX_CNTL_PKT_SIZE, GFP_KERNEL);
61 if (!psAdapter->txctlpacket[i]) {
62 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "No More Cntl pkts got, max got is %d", i);
63 return -ENOMEM;
64 }
65 }
66
67 if (AllocAdapterDsxBuffer(psAdapter)) {
68 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to allocate DSX buffers");
69 return -EINVAL;
70 }
71
72 /* Initialize PHS interface */
73 if (phs_init(&psAdapter->stBCMPhsContext, psAdapter) != 0) {
74 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "%s:%s:%d:Error PHS Init Failed=====>\n", __FILE__, __func__, __LINE__);
75 return -ENOMEM;
76 }
77
78 Status = BcmAllocFlashCSStructure(psAdapter);
79 if (Status) {
80 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Memory Allocation for Flash structure failed");
81 return Status;
82 }
83
84 Status = vendorextnInit(psAdapter);
85
86 if (STATUS_SUCCESS != Status) {
87 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Vendor Init Failed");
88 return Status;
89 }
90
91 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Adapter initialised");
92
93 return STATUS_SUCCESS;
94}
95
96void AdapterFree(struct bcm_mini_adapter *Adapter)
97{
98 int count;
99
100 beceem_protocol_reset(Adapter);
101 vendorextnExit(Adapter);
102
103 if (Adapter->control_packet_handler && !IS_ERR(Adapter->control_packet_handler))
104 kthread_stop(Adapter->control_packet_handler);
105
106 if (Adapter->transmit_packet_thread && !IS_ERR(Adapter->transmit_packet_thread))
107 kthread_stop(Adapter->transmit_packet_thread);
108
109 wake_up(&Adapter->process_read_wait_queue);
110
111 if (Adapter->LEDInfo.led_thread_running & (BCM_LED_THREAD_RUNNING_ACTIVELY | BCM_LED_THREAD_RUNNING_INACTIVELY))
112 kthread_stop(Adapter->LEDInfo.led_cntrl_threadid);
113
114 unregister_networkdev(Adapter);
115
116 /* FIXME: use proper wait_event and refcounting */
117 while (atomic_read(&Adapter->ApplicationRunning)) {
118 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Waiting for Application to close.. %d\n", atomic_read(&Adapter->ApplicationRunning));
119 msleep(100);
120 }
121 unregister_control_device_interface(Adapter);
122 kfree(Adapter->pstargetparams);
123
124 for (count = 0; count < MAX_CNTRL_PKTS; count++)
125 kfree(Adapter->txctlpacket[count]);
126
127 FreeAdapterDsxBuffer(Adapter);
128 kfree(Adapter->pvInterfaceAdapter);
129
130 /* Free the PHS Interface */
131 PhsCleanup(&Adapter->stBCMPhsContext);
132
133 BcmDeAllocFlashCSStructure(Adapter);
134
135 free_netdev(Adapter->dev);
136}
137
138static int create_worker_threads(struct bcm_mini_adapter *psAdapter)
139{
140 /* Rx Control Packets Processing */
141 psAdapter->control_packet_handler = kthread_run((int (*)(void *))
142 control_packet_handler, psAdapter, "%s-rx", DRV_NAME);
143 if (IS_ERR(psAdapter->control_packet_handler)) {
144 pr_notice(DRV_NAME ": could not create control thread\n");
145 return PTR_ERR(psAdapter->control_packet_handler);
146 }
147
148 /* Tx Thread */
149 psAdapter->transmit_packet_thread = kthread_run((int (*)(void *))
150 tx_pkt_handler, psAdapter, "%s-tx", DRV_NAME);
151 if (IS_ERR(psAdapter->transmit_packet_thread)) {
152 pr_notice(DRV_NAME ": could not creat transmit thread\n");
153 kthread_stop(psAdapter->control_packet_handler);
154 return PTR_ERR(psAdapter->transmit_packet_thread);
155 }
156 return 0;
157}
158
159static struct file *open_firmware_file(struct bcm_mini_adapter *Adapter, const char *path)
160{
161 struct file *flp = filp_open(path, O_RDONLY, S_IRWXU);
162
163 if (IS_ERR(flp)) {
164 pr_err(DRV_NAME "Unable To Open File %s, err %ld", path, PTR_ERR(flp));
165 flp = NULL;
166 }
167
168 if (Adapter->device_removed)
169 flp = NULL;
170
171 return flp;
172}
173
174/* Arguments:
175 * Logical Adapter
176 * Path to image file
177 * Download Address on the chip
178 */
179static int BcmFileDownload(struct bcm_mini_adapter *Adapter, const char *path, unsigned int loc)
180{
181 int errorno = 0;
182 struct file *flp = NULL;
183 struct timeval tv = {0};
184
185 flp = open_firmware_file(Adapter, path);
186 if (!flp) {
187 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Unable to Open %s\n", path);
188 return -ENOENT;
189 }
190 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Opened file is = %s and length =0x%lx to be downloaded at =0x%x", path, (unsigned long)file_inode(flp)->i_size, loc);
191 do_gettimeofday(&tv);
192
193 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "download start %lx", ((tv.tv_sec * 1000) + (tv.tv_usec / 1000)));
194 if (Adapter->bcm_file_download(Adapter->pvInterfaceAdapter, flp, loc)) {
195 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to download the firmware with error %x!!!", -EIO);
196 errorno = -EIO;
197 goto exit_download;
198 }
199 vfs_llseek(flp, 0, 0);
200 if (Adapter->bcm_file_readback_from_chip(Adapter->pvInterfaceAdapter, flp, loc)) {
201 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Failed to read back firmware!");
202 errorno = -EIO;
203 goto exit_download;
204 }
205
206exit_download:
207 filp_close(flp, NULL);
208 return errorno;
209}
210
211/**
212 * @ingroup ctrl_pkt_functions
213 * This function copies the contents of given buffer
214 * to the control packet and queues it for transmission.
215 * @note Do not acquire the spinlock, as it it already acquired.
216 * @return SUCCESS/FAILURE.
217 * Arguments:
218 * Logical Adapter
219 * Control Packet Buffer
220 */
221int CopyBufferToControlPacket(struct bcm_mini_adapter *Adapter, void *ioBuffer)
222{
223 struct bcm_leader *pLeader = NULL;
224 int Status = 0;
225 unsigned char *ctrl_buff;
226 unsigned int pktlen = 0;
227 struct bcm_link_request *pLinkReq = NULL;
228 PUCHAR pucAddIndication = NULL;
229
230 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "======>");
231 if (!ioBuffer) {
232 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Got Null Buffer\n");
233 return -EINVAL;
234 }
235
236 pLinkReq = (struct bcm_link_request *)ioBuffer;
237 pLeader = (struct bcm_leader *)ioBuffer; /* ioBuffer Contains sw_Status and Payload */
238
239 if (Adapter->bShutStatus == TRUE &&
240 pLinkReq->szData[0] == LINK_DOWN_REQ_PAYLOAD &&
241 pLinkReq->szData[1] == LINK_SYNC_UP_SUBTYPE) {
242
243 /* Got sync down in SHUTDOWN..we could not process this. */
244 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "SYNC DOWN Request in Shut Down Mode..\n");
245 return STATUS_FAILURE;
246 }
247
248 if ((pLeader->Status == LINK_UP_CONTROL_REQ) &&
249 ((pLinkReq->szData[0] == LINK_UP_REQ_PAYLOAD &&
250 (pLinkReq->szData[1] == LINK_SYNC_UP_SUBTYPE)) || /* Sync Up Command */
251 pLinkReq->szData[0] == NETWORK_ENTRY_REQ_PAYLOAD)) /* Net Entry Command */ {
252
253 if (Adapter->LinkStatus > PHY_SYNC_ACHIVED) {
254 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "LinkStatus is Greater than PHY_SYN_ACHIEVED");
255 return STATUS_FAILURE;
256 }
257
258 if (Adapter->bShutStatus == TRUE) {
259 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "SYNC UP IN SHUTDOWN..Device WakeUp\n");
260 if (Adapter->bTriedToWakeUpFromlowPowerMode == false) {
261 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Waking up for the First Time..\n");
262 Adapter->usIdleModePattern = ABORT_SHUTDOWN_MODE; /* change it to 1 for current support. */
263 Adapter->bWakeUpDevice = TRUE;
264 wake_up(&Adapter->process_rx_cntrlpkt);
265 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue, !Adapter->bShutStatus, (5 * HZ));
266
267 if (Status == -ERESTARTSYS)
268 return Status;
269
270 if (Adapter->bShutStatus) {
271 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Shutdown Mode Wake up Failed - No Wake Up Received\n");
272 return STATUS_FAILURE;
273 }
274 } else {
275 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Wakeup has been tried already...\n");
276 }
277 }
278 }
279
280 if (Adapter->IdleMode == TRUE) {
281 /* BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0,"Device is in Idle mode ... hence\n"); */
282 if (pLeader->Status == LINK_UP_CONTROL_REQ || pLeader->Status == 0x80 ||
283 pLeader->Status == CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ) {
284
285 if ((pLeader->Status == LINK_UP_CONTROL_REQ) && (pLinkReq->szData[0] == LINK_DOWN_REQ_PAYLOAD)) {
286 if (pLinkReq->szData[1] == LINK_SYNC_DOWN_SUBTYPE) {
287 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Link Down Sent in Idle Mode\n");
288 Adapter->usIdleModePattern = ABORT_IDLE_SYNCDOWN; /* LINK DOWN sent in Idle Mode */
289 } else {
290 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "ABORT_IDLE_MODE pattern is being written\n");
291 Adapter->usIdleModePattern = ABORT_IDLE_REG;
292 }
293 } else {
294 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "ABORT_IDLE_MODE pattern is being written\n");
295 Adapter->usIdleModePattern = ABORT_IDLE_MODE;
296 }
297
298 /*Setting bIdleMode_tx_from_host to TRUE to indicate LED control thread to represent
299 * the wake up from idlemode is from host
300 */
301 /* Adapter->LEDInfo.bIdleMode_tx_from_host = TRUE; */
302 Adapter->bWakeUpDevice = TRUE;
303 wake_up(&Adapter->process_rx_cntrlpkt);
304
305 /* We should not send DREG message down while in idlemode. */
306 if (LINK_DOWN_REQ_PAYLOAD == pLinkReq->szData[0])
307 return STATUS_SUCCESS;
308
309 Status = wait_event_interruptible_timeout(Adapter->lowpower_mode_wait_queue, !Adapter->IdleMode, (5 * HZ));
310
311 if (Status == -ERESTARTSYS)
312 return Status;
313
314 if (Adapter->IdleMode) {
315 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Idle Mode Wake up Failed - No Wake Up Received\n");
316 return STATUS_FAILURE;
317 }
318 } else {
319 return STATUS_SUCCESS;
320 }
321 }
322
323 /* The Driver has to send control messages with a particular VCID */
324 pLeader->Vcid = VCID_CONTROL_PACKET; /* VCID for control packet. */
325
326 /* Allocate skb for Control Packet */
327 pktlen = pLeader->PLength;
328 ctrl_buff = (char *)Adapter->txctlpacket[atomic_read(&Adapter->index_wr_txcntrlpkt)%MAX_CNTRL_PKTS];
329
330 if (!ctrl_buff) {
331 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "mem allocation Failed");
332 return -ENOMEM;
333 }
334
335 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Control packet to be taken =%d and address is =%pincoming address is =%p and packet len=%x",
336 atomic_read(&Adapter->index_wr_txcntrlpkt), ctrl_buff, ioBuffer, pktlen);
337
338 if (pLeader) {
339 if ((pLeader->Status == 0x80) ||
340 (pLeader->Status == CM_CONTROL_NEWDSX_MULTICLASSIFIER_REQ)) {
341 /*
342 * Restructure the DSX message to handle Multiple classifier Support
343 * Write the Service Flow param Structures directly to the target
344 * and embed the pointers in the DSX messages sent to target.
345 */
346 /* Lets store the current length of the control packet we are transmitting */
347 pucAddIndication = (PUCHAR)ioBuffer + LEADER_SIZE;
348 pktlen = pLeader->PLength;
349 Status = StoreCmControlResponseMessage(Adapter, pucAddIndication, &pktlen);
350 if (Status != 1) {
351 ClearTargetDSXBuffer(Adapter, ((struct bcm_add_indication_alt *)pucAddIndication)->u16TID, false);
352 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, " Error Restoring The DSX Control Packet. Dsx Buffers on Target may not be Setup Properly ");
353 return STATUS_FAILURE;
354 }
355 /*
356 * update the leader to use the new length
357 * The length of the control packet is length of message being sent + Leader length
358 */
359 pLeader->PLength = pktlen;
360 }
361 }
362
363 if (pktlen + LEADER_SIZE > MAX_CNTL_PKT_SIZE)
364 return -EINVAL;
365
366 memset(ctrl_buff, 0, pktlen+LEADER_SIZE);
367 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Copying the Control Packet Buffer with length=%d\n", pLeader->PLength);
368 *(struct bcm_leader *)ctrl_buff = *pLeader;
369 memcpy(ctrl_buff + LEADER_SIZE, ((PUCHAR)ioBuffer + LEADER_SIZE), pLeader->PLength);
370 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Enqueuing the Control Packet");
371
372 /* Update the statistics counters */
373 spin_lock_bh(&Adapter->PackInfo[HiPriority].SFQueueLock);
374 Adapter->PackInfo[HiPriority].uiCurrentBytesOnHost += pLeader->PLength;
375 Adapter->PackInfo[HiPriority].uiCurrentPacketsOnHost++;
376 atomic_inc(&Adapter->TotalPacketCount);
377 spin_unlock_bh(&Adapter->PackInfo[HiPriority].SFQueueLock);
378 Adapter->PackInfo[HiPriority].bValid = TRUE;
379
380 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "CurrBytesOnHost: %x bValid: %x",
381 Adapter->PackInfo[HiPriority].uiCurrentBytesOnHost,
382 Adapter->PackInfo[HiPriority].bValid);
383 Status = STATUS_SUCCESS;
384 /*Queue the packet for transmission */
385 atomic_inc(&Adapter->index_wr_txcntrlpkt);
386 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Calling transmit_packets");
387 atomic_set(&Adapter->TxPktAvail, 1);
388 wake_up(&Adapter->tx_packet_wait_queue);
389
390 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "<====");
391 return Status;
392}
393
394/******************************************************************
395* Function - LinkMessage()
396*
397* Description - This function builds the Sync-up and Link-up request
398* packet messages depending on the device Link status.
399*
400* Parameters - Adapter: Pointer to the Adapter structure.
401*
402* Returns - None.
403*******************************************************************/
404void LinkMessage(struct bcm_mini_adapter *Adapter)
405{
406 struct bcm_link_request *pstLinkRequest = NULL;
407
408 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "=====>");
409 if (Adapter->LinkStatus == SYNC_UP_REQUEST && Adapter->AutoSyncup) {
410 pstLinkRequest = kzalloc(sizeof(struct bcm_link_request), GFP_ATOMIC);
411 if (!pstLinkRequest) {
412 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Can not allocate memory for Link request!");
413 return;
414 }
415 /* sync up request... */
416 Adapter->LinkStatus = WAIT_FOR_SYNC; /* current link status */
417 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Requesting For SyncUp...");
418 pstLinkRequest->szData[0] = LINK_UP_REQ_PAYLOAD;
419 pstLinkRequest->szData[1] = LINK_SYNC_UP_SUBTYPE;
420 pstLinkRequest->Leader.Status = LINK_UP_CONTROL_REQ;
421 pstLinkRequest->Leader.PLength = sizeof(ULONG);
422 Adapter->bSyncUpRequestSent = TRUE;
423
424 } else if (Adapter->LinkStatus == PHY_SYNC_ACHIVED && Adapter->AutoLinkUp) {
425 pstLinkRequest = kzalloc(sizeof(struct bcm_link_request), GFP_ATOMIC);
426 if (!pstLinkRequest) {
427 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Can not allocate memory for Link request!");
428 return;
429 }
430 /* LINK_UP_REQUEST */
431 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Requesting For LinkUp...");
432 pstLinkRequest->szData[0] = LINK_UP_REQ_PAYLOAD;
433 pstLinkRequest->szData[1] = LINK_NET_ENTRY;
434 pstLinkRequest->Leader.Status = LINK_UP_CONTROL_REQ;
435 pstLinkRequest->Leader.PLength = sizeof(ULONG);
436 }
437 if (pstLinkRequest) {
438 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "Calling CopyBufferToControlPacket");
439 CopyBufferToControlPacket(Adapter, pstLinkRequest);
440 kfree(pstLinkRequest);
441 }
442 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LINK_UP_MSG, DBG_LVL_ALL, "LinkMessage <=====");
443 return;
444}
445
446/**********************************************************************
447* Function - StatisticsResponse()
448*
449* Description - This function handles the Statistics response packet.
450*
451* Parameters - Adapter : Pointer to the Adapter structure.
452* - pvBuffer: Starting address of Statistic response data.
453*
454* Returns - None.
455************************************************************************/
456void StatisticsResponse(struct bcm_mini_adapter *Adapter, void *pvBuffer)
457{
458 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s====>", __func__);
459 Adapter->StatisticsPointer = ntohl(*(__be32 *)pvBuffer);
460 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Stats at %x", (unsigned int)Adapter->StatisticsPointer);
461 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "%s <====", __func__);
462}
463
464/**********************************************************************
465* Function - LinkControlResponseMessage()
466*
467* Description - This function handles the Link response packets.
468*
469* Parameters - Adapter : Pointer to the Adapter structure.
470* - pucBuffer: Starting address of Link response data.
471*
472* Returns - None.
473***********************************************************************/
474void LinkControlResponseMessage(struct bcm_mini_adapter *Adapter, PUCHAR pucBuffer)
475{
476 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "=====>");
477
478 if (*pucBuffer == LINK_UP_ACK) {
479 switch (*(pucBuffer+1)) {
480 case PHY_SYNC_ACHIVED: /* SYNCed UP */
481 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "PHY_SYNC_ACHIVED");
482
483 if (Adapter->LinkStatus == LINKUP_DONE)
484 beceem_protocol_reset(Adapter);
485
486 Adapter->usBestEffortQueueIndex = INVALID_QUEUE_INDEX;
487 Adapter->LinkStatus = PHY_SYNC_ACHIVED;
488
489 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
490 Adapter->DriverState = NO_NETWORK_ENTRY;
491 wake_up(&Adapter->LEDInfo.notify_led_event);
492 }
493
494 LinkMessage(Adapter);
495 break;
496
497 case LINKUP_DONE:
498 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "LINKUP_DONE");
499 Adapter->LinkStatus = LINKUP_DONE;
500 Adapter->bPHSEnabled = *(pucBuffer+3);
501 Adapter->bETHCSEnabled = *(pucBuffer+4) & ETH_CS_MASK;
502 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "PHS Support Status Received In LinkUp Ack : %x\n", Adapter->bPHSEnabled);
503
504 if ((false == Adapter->bShutStatus) && (false == Adapter->IdleMode)) {
505 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
506 Adapter->DriverState = NORMAL_OPERATION;
507 wake_up(&Adapter->LEDInfo.notify_led_event);
508 }
509 }
510 LinkMessage(Adapter);
511 break;
512
513 case WAIT_FOR_SYNC:
514 /*
515 * Driver to ignore the DREG_RECEIVED
516 * WiMAX Application should handle this Message
517 */
518 /* Adapter->liTimeSinceLastNetEntry = 0; */
519 Adapter->LinkUpStatus = 0;
520 Adapter->LinkStatus = 0;
521 Adapter->usBestEffortQueueIndex = INVALID_QUEUE_INDEX;
522 Adapter->bTriedToWakeUpFromlowPowerMode = false;
523 Adapter->IdleMode = false;
524 beceem_protocol_reset(Adapter);
525
526 break;
527 case LINK_SHUTDOWN_REQ_FROM_FIRMWARE:
528 case COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW:
529 {
530 HandleShutDownModeRequest(Adapter, pucBuffer);
531 }
532 break;
533 default:
534 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "default case:LinkResponse %x", *(pucBuffer + 1));
535 break;
536 }
537 } else if (SET_MAC_ADDRESS_RESPONSE == *pucBuffer) {
538 PUCHAR puMacAddr = (pucBuffer + 1);
539
540 Adapter->LinkStatus = SYNC_UP_REQUEST;
541 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "MAC address response, sending SYNC_UP");
542 LinkMessage(Adapter);
543 memcpy(Adapter->dev->dev_addr, puMacAddr, MAC_ADDRESS_SIZE);
544 }
545 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "%s <=====", __func__);
546}
547
548void SendIdleModeResponse(struct bcm_mini_adapter *Adapter)
549{
550 int status = 0, NVMAccess = 0, lowPwrAbortMsg = 0;
551 struct timeval tv;
552 struct bcm_link_request stIdleResponse = {{0} };
553
554 memset(&tv, 0, sizeof(tv));
555 stIdleResponse.Leader.Status = IDLE_MESSAGE;
556 stIdleResponse.Leader.PLength = IDLE_MODE_PAYLOAD_LENGTH;
557 stIdleResponse.szData[0] = GO_TO_IDLE_MODE_PAYLOAD;
558 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, " ============>");
559
560 /*********************************
561 *down_trylock -
562 * if [ semaphore is available ]
563 * acquire semaphone and return value 0 ;
564 * else
565 * return non-zero value ;
566 *
567 ***********************************/
568
569 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
570 lowPwrAbortMsg = down_trylock(&Adapter->LowPowerModeSync);
571
572
573 if ((NVMAccess || lowPwrAbortMsg || atomic_read(&Adapter->TotalPacketCount)) &&
574 (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)) {
575
576 if (!NVMAccess)
577 up(&Adapter->NVMRdmWrmLock);
578
579 if (!lowPwrAbortMsg)
580 up(&Adapter->LowPowerModeSync);
581
582 stIdleResponse.szData[1] = TARGET_CAN_NOT_GO_TO_IDLE_MODE; /* NACK- device access is going on. */
583 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "HOST IS NACKING Idle mode To F/W!!!!!!!!");
584 Adapter->bPreparingForLowPowerMode = false;
585 } else {
586 stIdleResponse.szData[1] = TARGET_CAN_GO_TO_IDLE_MODE; /* 2; Idle ACK */
587 Adapter->StatisticsPointer = 0;
588
589 /* Wait for the LED to TURN OFF before sending ACK response */
590 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
591 int iRetVal = 0;
592
593 /* Wake the LED Thread with IDLEMODE_ENTER State */
594 Adapter->DriverState = LOWPOWER_MODE_ENTER;
595 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "LED Thread is Running..Hence Setting LED Event as IDLEMODE_ENTER jiffies:%ld", jiffies);
596 wake_up(&Adapter->LEDInfo.notify_led_event);
597
598 /* Wait for 1 SEC for LED to OFF */
599 iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent, Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
600
601 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
602 if (iRetVal <= 0) {
603 stIdleResponse.szData[1] = TARGET_CAN_NOT_GO_TO_IDLE_MODE; /* NACK- device access is going on. */
604 Adapter->DriverState = NORMAL_OPERATION;
605 wake_up(&Adapter->LEDInfo.notify_led_event);
606 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "NACKING Idle mode as time out happen from LED side!!!!!!!!");
607 }
608 }
609
610 if (stIdleResponse.szData[1] == TARGET_CAN_GO_TO_IDLE_MODE) {
611 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "ACKING IDLE MODE !!!!!!!!!");
612 down(&Adapter->rdmwrmsync);
613 Adapter->bPreparingForLowPowerMode = TRUE;
614 up(&Adapter->rdmwrmsync);
615 /* Killing all URBS. */
616 if (Adapter->bDoSuspend == TRUE)
617 Bcm_kill_all_URBs((struct bcm_interface_adapter *)(Adapter->pvInterfaceAdapter));
618 } else {
619 Adapter->bPreparingForLowPowerMode = false;
620 }
621
622 if (!NVMAccess)
623 up(&Adapter->NVMRdmWrmLock);
624
625 if (!lowPwrAbortMsg)
626 up(&Adapter->LowPowerModeSync);
627 }
628
629 status = CopyBufferToControlPacket(Adapter, &stIdleResponse);
630 if (status != STATUS_SUCCESS) {
631 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "fail to send the Idle mode Request\n");
632 Adapter->bPreparingForLowPowerMode = false;
633 StartInterruptUrb((struct bcm_interface_adapter *)(Adapter->pvInterfaceAdapter));
634 }
635 do_gettimeofday(&tv);
636 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_RX, RX_DPC, DBG_LVL_ALL, "IdleMode Msg submitter to Q :%ld ms", tv.tv_sec * 1000 + tv.tv_usec / 1000);
637}
638
639/******************************************************************
640* Function - DumpPackInfo()
641*
642* Description - This function dumps the all Queue(PackInfo[]) details.
643*
644* Parameters - Adapter: Pointer to the Adapter structure.
645*
646* Returns - None.
647*******************************************************************/
648void DumpPackInfo(struct bcm_mini_adapter *Adapter)
649{
650 unsigned int uiLoopIndex = 0;
651 unsigned int uiIndex = 0;
652 unsigned int uiClsfrIndex = 0;
653 struct bcm_classifier_rule *pstClassifierEntry = NULL;
654
655 for (uiLoopIndex = 0; uiLoopIndex < NO_OF_QUEUES; uiLoopIndex++) {
656 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "*********** Showing Details Of Queue %d***** ******", uiLoopIndex);
657 if (false == Adapter->PackInfo[uiLoopIndex].bValid) {
658 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bValid is false for %X index\n", uiLoopIndex);
659 continue;
660 }
661
662 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, " Dumping SF Rule Entry For SFID %lX\n", Adapter->PackInfo[uiLoopIndex].ulSFID);
663 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, " ucDirection %X\n", Adapter->PackInfo[uiLoopIndex].ucDirection);
664
665 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6)
666 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Ipv6 Service Flow\n");
667 else
668 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Ipv4 Service Flow\n");
669
670 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "SF Traffic Priority %X\n", Adapter->PackInfo[uiLoopIndex].u8TrafficPriority);
671
672 for (uiClsfrIndex = 0; uiClsfrIndex < MAX_CLASSIFIERS; uiClsfrIndex++) {
673 pstClassifierEntry = &Adapter->astClassifierTable[uiClsfrIndex];
674 if (!pstClassifierEntry->bUsed)
675 continue;
676
677 if (pstClassifierEntry->ulSFID != Adapter->PackInfo[uiLoopIndex].ulSFID)
678 continue;
679
680 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X Classifier Rule ID : %X\n", uiClsfrIndex, pstClassifierEntry->uiClassifierRuleIndex);
681 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X usVCID_Value : %X\n", uiClsfrIndex, pstClassifierEntry->usVCID_Value);
682 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X bProtocolValid : %X\n", uiClsfrIndex, pstClassifierEntry->bProtocolValid);
683 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X bTOSValid : %X\n", uiClsfrIndex, pstClassifierEntry->bTOSValid);
684 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X bDestIpValid : %X\n", uiClsfrIndex, pstClassifierEntry->bDestIpValid);
685 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tDumping Classifier Rule Entry For Index: %X bSrcIpValid : %X\n", uiClsfrIndex, pstClassifierEntry->bSrcIpValid);
686
687 for (uiIndex = 0; uiIndex < MAX_PORT_RANGE; uiIndex++) {
688 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusSrcPortRangeLo:%X\n", pstClassifierEntry->usSrcPortRangeLo[uiIndex]);
689 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusSrcPortRangeHi:%X\n", pstClassifierEntry->usSrcPortRangeHi[uiIndex]);
690 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusDestPortRangeLo:%X\n", pstClassifierEntry->usDestPortRangeLo[uiIndex]);
691 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tusDestPortRangeHi:%X\n", pstClassifierEntry->usDestPortRangeHi[uiIndex]);
692 }
693
694 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucIPSourceAddressLength : 0x%x\n", pstClassifierEntry->ucIPSourceAddressLength);
695 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucIPDestinationAddressLength : 0x%x\n", pstClassifierEntry->ucIPDestinationAddressLength);
696 for (uiIndex = 0; uiIndex < pstClassifierEntry->ucIPSourceAddressLength; uiIndex++) {
697 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6) {
698 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulSrcIpAddr :\n");
699 DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Addr);
700 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulSrcIpMask :\n");
701 DumpIpv6Address(pstClassifierEntry->stSrcIpAddress.ulIpv6Mask);
702 } else {
703 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulSrcIpAddr:%lX\n", pstClassifierEntry->stSrcIpAddress.ulIpv4Addr[uiIndex]);
704 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulSrcIpMask:%lX\n", pstClassifierEntry->stSrcIpAddress.ulIpv4Mask[uiIndex]);
705 }
706 }
707
708 for (uiIndex = 0; uiIndex < pstClassifierEntry->ucIPDestinationAddressLength; uiIndex++) {
709 if (Adapter->PackInfo[uiLoopIndex].ucIpVersion == IPV6) {
710 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulDestIpAddr :\n");
711 DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Addr);
712 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tIpv6 ulDestIpMask :\n");
713 DumpIpv6Address(pstClassifierEntry->stDestIpAddress.ulIpv6Mask);
714 } else {
715 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulDestIpAddr:%lX\n", pstClassifierEntry->stDestIpAddress.ulIpv4Addr[uiIndex]);
716 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tulDestIpMask:%lX\n", pstClassifierEntry->stDestIpAddress.ulIpv4Mask[uiIndex]);
717 }
718 }
719 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tucProtocol:0x%X\n", pstClassifierEntry->ucProtocol[0]);
720 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\tu8ClassifierRulePriority:%X\n", pstClassifierEntry->u8ClassifierRulePriority);
721 }
722 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ulSFID:%lX\n", Adapter->PackInfo[uiLoopIndex].ulSFID);
723 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "usVCID_Value:%X\n", Adapter->PackInfo[uiLoopIndex].usVCID_Value);
724 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "PhsEnabled: 0x%X\n", Adapter->PackInfo[uiLoopIndex].bHeaderSuppressionEnabled);
725 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiThreshold:%X\n", Adapter->PackInfo[uiLoopIndex].uiThreshold);
726
727 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bValid:%X\n", Adapter->PackInfo[uiLoopIndex].bValid);
728 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bActive:%X\n", Adapter->PackInfo[uiLoopIndex].bActive);
729 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ActivateReqSent: %x", Adapter->PackInfo[uiLoopIndex].bActivateRequestSent);
730 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "u8QueueType:%X\n", Adapter->PackInfo[uiLoopIndex].u8QueueType);
731 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxBucketSize:%X\n", Adapter->PackInfo[uiLoopIndex].uiMaxBucketSize);
732 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiPerSFTxResourceCount:%X\n", atomic_read(&Adapter->PackInfo[uiLoopIndex].uiPerSFTxResourceCount));
733 /* DumpDebug(DUMP_INFO,("bCSSupport:%X\n",Adapter->PackInfo[uiLoopIndex].bCSSupport)); */
734 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "CurrQueueDepthOnTarget: %x\n", Adapter->PackInfo[uiLoopIndex].uiCurrentQueueDepthOnTarget);
735 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentBytesOnHost:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentBytesOnHost);
736 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentPacketsOnHost:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentPacketsOnHost);
737 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiDroppedCountBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiDroppedCountBytes);
738 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiDroppedCountPackets:%X\n", Adapter->PackInfo[uiLoopIndex].uiDroppedCountPackets);
739 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiSentBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiSentBytes);
740 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiSentPackets:%X\n", Adapter->PackInfo[uiLoopIndex].uiSentPackets);
741 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentDrainRate:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentDrainRate);
742 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiThisPeriodSentBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiThisPeriodSentBytes);
743 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "liDrainCalculated:%llX\n", Adapter->PackInfo[uiLoopIndex].liDrainCalculated);
744 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiCurrentTokenCount:%X\n", Adapter->PackInfo[uiLoopIndex].uiCurrentTokenCount);
745 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "liLastUpdateTokenAt:%llX\n", Adapter->PackInfo[uiLoopIndex].liLastUpdateTokenAt);
746 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxAllowedRate:%X\n", Adapter->PackInfo[uiLoopIndex].uiMaxAllowedRate);
747 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiPendedLast:%X\n", Adapter->PackInfo[uiLoopIndex].uiPendedLast);
748 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "NumOfPacketsSent:%X\n", Adapter->PackInfo[uiLoopIndex].NumOfPacketsSent);
749 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Direction: %x\n", Adapter->PackInfo[uiLoopIndex].ucDirection);
750 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "CID: %x\n", Adapter->PackInfo[uiLoopIndex].usCID);
751 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ProtocolValid: %x\n", Adapter->PackInfo[uiLoopIndex].bProtocolValid);
752 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "TOSValid: %x\n", Adapter->PackInfo[uiLoopIndex].bTOSValid);
753 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "DestIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bDestIpValid);
754 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "SrcIpValid: %x\n", Adapter->PackInfo[uiLoopIndex].bSrcIpValid);
755 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ActiveSet: %x\n", Adapter->PackInfo[uiLoopIndex].bActiveSet);
756 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AdmittedSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAdmittedSet);
757 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "AuthzSet: %x\n", Adapter->PackInfo[uiLoopIndex].bAuthorizedSet);
758 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "ClassifyPrority: %x\n", Adapter->PackInfo[uiLoopIndex].bClassifierPriority);
759 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiMaxLatency: %x\n", Adapter->PackInfo[uiLoopIndex].uiMaxLatency);
760 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO,
761 DBG_LVL_ALL, "ServiceClassName: %*ph\n",
762 4, Adapter->PackInfo[uiLoopIndex].
763 ucServiceClassName);
764/* BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "bHeaderSuppressionEnabled :%X\n", Adapter->PackInfo[uiLoopIndex].bHeaderSuppressionEnabled);
765 * BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalTxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalTxBytes);
766 * BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "uiTotalRxBytes:%X\n", Adapter->PackInfo[uiLoopIndex].uiTotalRxBytes);
767 * DumpDebug(DUMP_INFO,(" uiRanOutOfResCount:%X\n",Adapter->PackInfo[uiLoopIndex].uiRanOutOfResCount));
768 */
769 }
770
771 for (uiLoopIndex = 0; uiLoopIndex < MIBS_MAX_HIST_ENTRIES; uiLoopIndex++)
772 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Adapter->aRxPktSizeHist[%x] = %x\n", uiLoopIndex, Adapter->aRxPktSizeHist[uiLoopIndex]);
773
774 for (uiLoopIndex = 0; uiLoopIndex < MIBS_MAX_HIST_ENTRIES; uiLoopIndex++)
775 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "Adapter->aTxPktSizeHist[%x] = %x\n", uiLoopIndex, Adapter->aTxPktSizeHist[uiLoopIndex]);
776}
777
778int reset_card_proc(struct bcm_mini_adapter *ps_adapter)
779{
780 int retval = STATUS_SUCCESS;
781 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
782 struct bcm_interface_adapter *psIntfAdapter = NULL;
783 unsigned int value = 0, uiResetValue = 0;
784 int bytes;
785
786 psIntfAdapter = ((struct bcm_interface_adapter *)(ps_adapter->pvInterfaceAdapter));
787 ps_adapter->bDDRInitDone = false;
788
789 if (ps_adapter->chip_id >= T3LPB) {
790 /* SYS_CFG register is write protected hence for modifying this reg value, it should be read twice before */
791 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
792 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
793
794 /* making bit[6...5] same as was before f/w download. this setting force the h/w to */
795 /* re-populated the SP RAM area with the string descriptor. */
796 value = value | (ps_adapter->syscfgBefFwDld & 0x00000060);
797 wrmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
798 }
799
800 /* killing all submitted URBs. */
801 psIntfAdapter->psAdapter->StopAllXaction = TRUE;
802 Bcm_kill_all_URBs(psIntfAdapter);
803 /* Reset the UMA-B Device */
804 if (ps_adapter->chip_id >= T3LPB) {
805 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Resetting UMA-B\n");
806 retval = usb_reset_device(psIntfAdapter->udev);
807 psIntfAdapter->psAdapter->StopAllXaction = false;
808
809 if (retval != STATUS_SUCCESS) {
810 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Reset failed with ret value :%d", retval);
811 goto err_exit;
812 }
813
814 if (ps_adapter->chip_id == BCS220_2 ||
815 ps_adapter->chip_id == BCS220_2BC ||
816 ps_adapter->chip_id == BCS250_BC ||
817 ps_adapter->chip_id == BCS220_3) {
818
819 bytes = rdmalt(ps_adapter, HPM_CONFIG_LDO145, &value, sizeof(value));
820 if (bytes < 0) {
821 retval = bytes;
822 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "read failed with status :%d", retval);
823 goto err_exit;
824 }
825 /* setting 0th bit */
826 value |= (1<<0);
827 retval = wrmalt(ps_adapter, HPM_CONFIG_LDO145, &value, sizeof(value));
828 if (retval < 0) {
829 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
830 goto err_exit;
831 }
832 }
833 } else {
834 bytes = rdmalt(ps_adapter, 0x0f007018, &value, sizeof(value));
835 if (bytes < 0) {
836 retval = bytes;
837 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "read failed with status :%d", retval);
838 goto err_exit;
839 }
840 value &= (~(1<<16));
841 retval = wrmalt(ps_adapter, 0x0f007018, &value, sizeof(value));
842 if (retval < 0) {
843 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
844 goto err_exit;
845 }
846
847 /* Toggling the GPIO 8, 9 */
848 value = 0;
849 retval = wrmalt(ps_adapter, GPIO_OUTPUT_REGISTER, &value, sizeof(value));
850 if (retval < 0) {
851 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
852 goto err_exit;
853 }
854 value = 0x300;
855 retval = wrmalt(ps_adapter, GPIO_MODE_REGISTER, &value, sizeof(value));
856 if (retval < 0) {
857 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "write failed with status :%d", retval);
858 goto err_exit;
859 }
860 mdelay(50);
861 }
862
863 /* ps_adapter->downloadDDR = false; */
864 if (ps_adapter->bFlashBoot) {
865 /* In flash boot mode MIPS state register has reverse polarity.
866 * So just or with setting bit 30.
867 * Make the MIPS in Reset state.
868 */
869 rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
870 uiResetValue |= (1<<30);
871 wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &uiResetValue, sizeof(uiResetValue));
872 }
873
874 if (ps_adapter->chip_id >= T3LPB) {
875 uiResetValue = 0;
876 /*
877 * WA for SYSConfig Issue.
878 * Read SYSCFG Twice to make it writable.
879 */
880 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));
881 if (uiResetValue & (1<<4)) {
882 uiResetValue = 0;
883 rdmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue)); /* 2nd read to make it writable. */
884 uiResetValue &= (~(1<<4));
885 wrmalt(ps_adapter, SYS_CFG, &uiResetValue, sizeof(uiResetValue));
886 }
887 }
888 uiResetValue = 0;
889 wrmalt(ps_adapter, 0x0f01186c, &uiResetValue, sizeof(uiResetValue));
890
891err_exit:
892 psIntfAdapter->psAdapter->StopAllXaction = false;
893 return retval;
894}
895
896int run_card_proc(struct bcm_mini_adapter *ps_adapter)
897{
898 int status = STATUS_SUCCESS;
899 int bytes;
900
901 unsigned int value = 0;
902 {
903 bytes = rdmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value));
904 if (bytes < 0) {
905 status = bytes;
906 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "%s:%d\n", __func__, __LINE__);
907 return status;
908 }
909
910 if (ps_adapter->bFlashBoot)
911 value &= (~(1<<30));
912 else
913 value |= (1<<30);
914
915 if (wrmalt(ps_adapter, CLOCK_RESET_CNTRL_REG_1, &value, sizeof(value)) < 0) {
916 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "%s:%d\n", __func__, __LINE__);
917 return STATUS_FAILURE;
918 }
919 }
920 return status;
921}
922
923int InitCardAndDownloadFirmware(struct bcm_mini_adapter *ps_adapter)
924{
925 int status;
926 unsigned int value = 0;
927 /*
928 * Create the threads first and then download the
929 * Firm/DDR Settings..
930 */
931 status = create_worker_threads(ps_adapter);
932 if (status < 0)
933 return status;
934
935 status = bcm_parse_target_params(ps_adapter);
936 if (status)
937 return status;
938
939 if (ps_adapter->chip_id >= T3LPB) {
940 rdmalt(ps_adapter, SYS_CFG, &value, sizeof(value));
941 ps_adapter->syscfgBefFwDld = value;
942
943 if ((value & 0x60) == 0)
944 ps_adapter->bFlashBoot = TRUE;
945 }
946
947 reset_card_proc(ps_adapter);
948
949 /* Initializing the NVM. */
950 BcmInitNVM(ps_adapter);
951 status = ddr_init(ps_adapter);
952 if (status) {
953 pr_err(DRV_NAME "ddr_init Failed\n");
954 return status;
955 }
956
957 /* Download cfg file */
958 status = buffDnldVerify(ps_adapter,
959 (PUCHAR)ps_adapter->pstargetparams,
960 sizeof(struct bcm_target_params),
961 CONFIG_BEGIN_ADDR);
962 if (status) {
963 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Error downloading CFG file");
964 goto OUT;
965 }
966
967 if (register_networkdev(ps_adapter)) {
968 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Netdevice failed. Cleanup needs to be performed.");
969 return -EIO;
970 }
971
972 if (false == ps_adapter->AutoFirmDld) {
973 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "AutoFirmDld Disabled in CFG File..\n");
974 /* If Auto f/w download is disable, register the control interface, */
975 /* register the control interface after the mailbox. */
976 if (register_control_device_interface(ps_adapter) < 0) {
977 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Register Control Device failed. Cleanup needs to be performed.");
978 return -EIO;
979 }
980 return STATUS_SUCCESS;
981 }
982
983 /*
984 * Do the LED Settings here. It will be used by the Firmware Download
985 * Thread.
986 */
987
988 /*
989 * 1. If the LED Settings fails, do not stop and do the Firmware download.
990 * 2. This init would happened only if the cfg file is present, else
991 * call from the ioctl context.
992 */
993
994 status = InitLedSettings(ps_adapter);
995 if (status) {
996 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_PRINTK, 0, 0, "INIT LED FAILED\n");
997 return status;
998 }
999
1000 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1001 ps_adapter->DriverState = DRIVER_INIT;
1002 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1003 }
1004
1005 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1006 ps_adapter->DriverState = FW_DOWNLOAD;
1007 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1008 }
1009
1010 value = 0;
1011 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 4, &value, sizeof(value));
1012 wrmalt(ps_adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 8, &value, sizeof(value));
1013
1014 if (ps_adapter->eNVMType == NVM_FLASH) {
1015 status = PropagateCalParamsFromFlashToMemory(ps_adapter);
1016 if (status) {
1017 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Propagation of Cal param failed ..");
1018 goto OUT;
1019 }
1020 }
1021
1022 /* Download Firmare */
1023 status = BcmFileDownload(ps_adapter, BIN_FILE, FIRMWARE_BEGIN_ADDR);
1024 if (status != 0) {
1025 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "No Firmware File is present...\n");
1026 goto OUT;
1027 }
1028
1029 status = run_card_proc(ps_adapter);
1030 if (status) {
1031 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "run_card_proc Failed\n");
1032 goto OUT;
1033 }
1034
1035 ps_adapter->fw_download_done = TRUE;
1036 mdelay(10);
1037
1038OUT:
1039 if (ps_adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1040 ps_adapter->DriverState = FW_DOWNLOAD_DONE;
1041 wake_up(&ps_adapter->LEDInfo.notify_led_event);
1042 }
1043
1044 return status;
1045}
1046
1047static int bcm_parse_target_params(struct bcm_mini_adapter *Adapter)
1048{
1049 struct file *flp = NULL;
1050 char *buff;
1051 int len = 0;
1052
1053 buff = kmalloc(BUFFER_1K, GFP_KERNEL);
1054 if (!buff)
1055 return -ENOMEM;
1056
1057 Adapter->pstargetparams = kmalloc(sizeof(struct bcm_target_params), GFP_KERNEL);
1058 if (Adapter->pstargetparams == NULL) {
1059 kfree(buff);
1060 return -ENOMEM;
1061 }
1062
1063 flp = open_firmware_file(Adapter, CFG_FILE);
1064 if (!flp) {
1065 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "NOT ABLE TO OPEN THE %s FILE\n", CFG_FILE);
1066 kfree(buff);
1067 kfree(Adapter->pstargetparams);
1068 Adapter->pstargetparams = NULL;
1069 return -ENOENT;
1070 }
1071 len = kernel_read(flp, 0, buff, BUFFER_1K);
1072 filp_close(flp, NULL);
1073
1074 if (len != sizeof(struct bcm_target_params)) {
1075 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Mismatch in Target Param Structure!\n");
1076 kfree(buff);
1077 kfree(Adapter->pstargetparams);
1078 Adapter->pstargetparams = NULL;
1079 return -ENOENT;
1080 }
1081
1082 /* Check for autolink in config params */
1083 /*
1084 * Values in Adapter->pstargetparams are in network byte order
1085 */
1086 memcpy(Adapter->pstargetparams, buff, sizeof(struct bcm_target_params));
1087 kfree(buff);
1088 beceem_parse_target_struct(Adapter);
1089 return STATUS_SUCCESS;
1090}
1091
1092void beceem_parse_target_struct(struct bcm_mini_adapter *Adapter)
1093{
1094 unsigned int uiHostDrvrCfg6 = 0, uiEEPROMFlag = 0;
1095
1096 if (ntohl(Adapter->pstargetparams->m_u32PhyParameter2) & AUTO_SYNC_DISABLE) {
1097 pr_info(DRV_NAME ": AutoSyncup is Disabled\n");
1098 Adapter->AutoSyncup = false;
1099 } else {
1100 pr_info(DRV_NAME ": AutoSyncup is Enabled\n");
1101 Adapter->AutoSyncup = TRUE;
1102 }
1103
1104 if (ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_LINKUP_ENABLE) {
1105 pr_info(DRV_NAME ": Enabling autolink up");
1106 Adapter->AutoLinkUp = TRUE;
1107 } else {
1108 pr_info(DRV_NAME ": Disabling autolink up");
1109 Adapter->AutoLinkUp = false;
1110 }
1111 /* Setting the DDR Setting.. */
1112 Adapter->DDRSetting = (ntohl(Adapter->pstargetparams->HostDrvrConfig6) >> 8)&0x0F;
1113 Adapter->ulPowerSaveMode = (ntohl(Adapter->pstargetparams->HostDrvrConfig6)>>12)&0x0F;
1114 pr_info(DRV_NAME ": DDR Setting: %x\n", Adapter->DDRSetting);
1115 pr_info(DRV_NAME ": Power Save Mode: %lx\n", Adapter->ulPowerSaveMode);
1116 if (ntohl(Adapter->pstargetparams->HostDrvrConfig6) & AUTO_FIRM_DOWNLOAD) {
1117 pr_info(DRV_NAME ": Enabling Auto Firmware Download\n");
1118 Adapter->AutoFirmDld = TRUE;
1119 } else {
1120 pr_info(DRV_NAME ": Disabling Auto Firmware Download\n");
1121 Adapter->AutoFirmDld = false;
1122 }
1123 uiHostDrvrCfg6 = ntohl(Adapter->pstargetparams->HostDrvrConfig6);
1124 Adapter->bMipsConfig = (uiHostDrvrCfg6>>20)&0x01;
1125 pr_info(DRV_NAME ": MIPSConfig : 0x%X\n", Adapter->bMipsConfig);
1126 /* used for backward compatibility. */
1127 Adapter->bDPLLConfig = (uiHostDrvrCfg6>>19)&0x01;
1128 Adapter->PmuMode = (uiHostDrvrCfg6 >> 24) & 0x03;
1129 pr_info(DRV_NAME ": PMU MODE: %x", Adapter->PmuMode);
1130
1131 if ((uiHostDrvrCfg6 >> HOST_BUS_SUSPEND_BIT) & (0x01)) {
1132 Adapter->bDoSuspend = TRUE;
1133 pr_info(DRV_NAME ": Making DoSuspend TRUE as per configFile");
1134 }
1135
1136 uiEEPROMFlag = ntohl(Adapter->pstargetparams->m_u32EEPROMFlag);
1137 pr_info(DRV_NAME ": uiEEPROMFlag : 0x%X\n", uiEEPROMFlag);
1138 Adapter->eNVMType = (enum bcm_nvm_type)((uiEEPROMFlag>>4)&0x3);
1139 Adapter->bStatusWrite = (uiEEPROMFlag>>6)&0x1;
1140 Adapter->uiSectorSizeInCFG = 1024*(0xFFFF & ntohl(Adapter->pstargetparams->HostDrvrConfig4));
1141 Adapter->bSectorSizeOverride = (bool) ((ntohl(Adapter->pstargetparams->HostDrvrConfig4))>>16)&0x1;
1142
1143 if (ntohl(Adapter->pstargetparams->m_u32PowerSavingModeOptions) & 0x01)
1144 Adapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE;
1145
1146 if (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE)
1147 doPowerAutoCorrection(Adapter);
1148}
1149
1150static void doPowerAutoCorrection(struct bcm_mini_adapter *psAdapter)
1151{
1152 unsigned int reporting_mode;
1153
1154 reporting_mode = ntohl(psAdapter->pstargetparams->m_u32PowerSavingModeOptions) & 0x02;
1155 psAdapter->bIsAutoCorrectEnabled = !((char)(psAdapter->ulPowerSaveMode >> 3) & 0x1);
1156
1157 if (reporting_mode) {
1158 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "can't do suspen/resume as reporting mode is enable");
1159 psAdapter->bDoSuspend = false;
1160 }
1161
1162 if (psAdapter->bIsAutoCorrectEnabled && (psAdapter->chip_id >= T3LPB)) {
1163 /* If reporting mode is enable, switch PMU to PMC */
1164 {
1165 psAdapter->ulPowerSaveMode = DEVICE_POWERSAVE_MODE_AS_PMU_CLOCK_GATING;
1166 psAdapter->bDoSuspend = false;
1167 }
1168
1169 /* clearing space bit[15..12] */
1170 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl((0xF << 12)));
1171 /* placing the power save mode option */
1172 psAdapter->pstargetparams->HostDrvrConfig6 |= htonl((psAdapter->ulPowerSaveMode << 12));
1173 } else if (psAdapter->bIsAutoCorrectEnabled == false) {
1174 /* remove the autocorrect disable bit set before dumping. */
1175 psAdapter->ulPowerSaveMode &= ~(1 << 3);
1176 psAdapter->pstargetparams->HostDrvrConfig6 &= ~(htonl(1 << 15));
1177 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_INITEXIT, MP_INIT, DBG_LVL_ALL, "Using Forced User Choice: %lx\n", psAdapter->ulPowerSaveMode);
1178 }
1179}
1180
1181static void convertEndian(unsigned char rwFlag, unsigned int *puiBuffer, unsigned int uiByteCount)
1182{
1183 unsigned int uiIndex = 0;
1184
1185 if (RWM_WRITE == rwFlag) {
1186 for (uiIndex = 0; uiIndex < (uiByteCount/sizeof(unsigned int)); uiIndex++)
1187 puiBuffer[uiIndex] = htonl(puiBuffer[uiIndex]);
1188 } else {
1189 for (uiIndex = 0; uiIndex < (uiByteCount/sizeof(unsigned int)); uiIndex++)
1190 puiBuffer[uiIndex] = ntohl(puiBuffer[uiIndex]);
1191 }
1192}
1193
1194int rdm(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, PCHAR pucBuff, size_t sSize)
1195{
1196 return Adapter->interface_rdm(Adapter->pvInterfaceAdapter,
1197 uiAddress, pucBuff, sSize);
1198}
1199
1200int wrm(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, PCHAR pucBuff, size_t sSize)
1201{
1202 int iRetVal;
1203
1204 iRetVal = Adapter->interface_wrm(Adapter->pvInterfaceAdapter,
1205 uiAddress, pucBuff, sSize);
1206 return iRetVal;
1207}
1208
1209int wrmalt(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, unsigned int *pucBuff, size_t size)
1210{
1211 convertEndian(RWM_WRITE, pucBuff, size);
1212 return wrm(Adapter, uiAddress, (PUCHAR)pucBuff, size);
1213}
1214
1215int rdmalt(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, unsigned int *pucBuff, size_t size)
1216{
1217 int uiRetVal = 0;
1218
1219 uiRetVal = rdm(Adapter, uiAddress, (PUCHAR)pucBuff, size);
1220 convertEndian(RWM_READ, (unsigned int *)pucBuff, size);
1221
1222 return uiRetVal;
1223}
1224
1225int wrmWithLock(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, PCHAR pucBuff, size_t sSize)
1226{
1227 int status = STATUS_SUCCESS;
1228
1229 down(&Adapter->rdmwrmsync);
1230
1231 if ((Adapter->IdleMode == TRUE) ||
1232 (Adapter->bShutStatus == TRUE) ||
1233 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1234
1235 status = -EACCES;
1236 goto exit;
1237 }
1238
1239 status = wrm(Adapter, uiAddress, pucBuff, sSize);
1240exit:
1241 up(&Adapter->rdmwrmsync);
1242 return status;
1243}
1244
1245int wrmaltWithLock(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, unsigned int *pucBuff, size_t size)
1246{
1247 int iRetVal = STATUS_SUCCESS;
1248
1249 down(&Adapter->rdmwrmsync);
1250
1251 if ((Adapter->IdleMode == TRUE) ||
1252 (Adapter->bShutStatus == TRUE) ||
1253 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1254
1255 iRetVal = -EACCES;
1256 goto exit;
1257 }
1258
1259 iRetVal = wrmalt(Adapter, uiAddress, pucBuff, size);
1260exit:
1261 up(&Adapter->rdmwrmsync);
1262 return iRetVal;
1263}
1264
1265int rdmaltWithLock(struct bcm_mini_adapter *Adapter, unsigned int uiAddress, unsigned int *pucBuff, size_t size)
1266{
1267 int uiRetVal = STATUS_SUCCESS;
1268
1269 down(&Adapter->rdmwrmsync);
1270 if ((Adapter->IdleMode == TRUE) ||
1271 (Adapter->bShutStatus == TRUE) ||
1272 (Adapter->bPreparingForLowPowerMode == TRUE)) {
1273
1274 uiRetVal = -EACCES;
1275 goto exit;
1276 }
1277
1278 uiRetVal = rdmalt(Adapter, uiAddress, pucBuff, size);
1279exit:
1280 up(&Adapter->rdmwrmsync);
1281 return uiRetVal;
1282}
1283
1284static void HandleShutDownModeWakeup(struct bcm_mini_adapter *Adapter)
1285{
1286 int clear_abort_pattern = 0, Status = 0;
1287
1288 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
1289 /* target has woken up From Shut Down */
1290 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Clearing Shut Down Software abort pattern\n");
1291 Status = wrmalt(Adapter, SW_ABORT_IDLEMODE_LOC, (unsigned int *)&clear_abort_pattern, sizeof(clear_abort_pattern));
1292 if (Status) {
1293 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "WRM to SW_ABORT_IDLEMODE_LOC failed with err:%d", Status);
1294 return;
1295 }
1296
1297 if (Adapter->ulPowerSaveMode != DEVICE_POWERSAVE_MODE_AS_PROTOCOL_IDLE_MODE) {
1298 msleep(100);
1299 InterfaceHandleShutdownModeWakeup(Adapter);
1300 msleep(100);
1301 }
1302
1303 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1304 Adapter->DriverState = NO_NETWORK_ENTRY;
1305 wake_up(&Adapter->LEDInfo.notify_led_event);
1306 }
1307
1308 Adapter->bTriedToWakeUpFromlowPowerMode = false;
1309 Adapter->bShutStatus = false;
1310 wake_up(&Adapter->lowpower_mode_wait_queue);
1311 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
1312}
1313
1314static void SendShutModeResponse(struct bcm_mini_adapter *Adapter)
1315{
1316 struct bcm_link_request stShutdownResponse;
1317 unsigned int NVMAccess = 0, lowPwrAbortMsg = 0;
1318 unsigned int Status = 0;
1319
1320 memset(&stShutdownResponse, 0, sizeof(struct bcm_link_request));
1321 stShutdownResponse.Leader.Status = LINK_UP_CONTROL_REQ;
1322 stShutdownResponse.Leader.PLength = 8; /* 8 bytes; */
1323 stShutdownResponse.szData[0] = LINK_UP_ACK;
1324 stShutdownResponse.szData[1] = LINK_SHUTDOWN_REQ_FROM_FIRMWARE;
1325
1326 /*********************************
1327 * down_trylock -
1328 * if [ semaphore is available ]
1329 * acquire semaphone and return value 0 ;
1330 * else
1331 * return non-zero value ;
1332 *
1333 ***********************************/
1334
1335 NVMAccess = down_trylock(&Adapter->NVMRdmWrmLock);
1336 lowPwrAbortMsg = down_trylock(&Adapter->LowPowerModeSync);
1337
1338 if (NVMAccess || lowPwrAbortMsg || atomic_read(&Adapter->TotalPacketCount)) {
1339 if (!NVMAccess)
1340 up(&Adapter->NVMRdmWrmLock);
1341
1342 if (!lowPwrAbortMsg)
1343 up(&Adapter->LowPowerModeSync);
1344
1345 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Device Access is going on NACK the Shut Down MODE\n");
1346 stShutdownResponse.szData[2] = SHUTDOWN_NACK_FROM_DRIVER; /* NACK- device access is going on. */
1347 Adapter->bPreparingForLowPowerMode = false;
1348 } else {
1349 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "Sending SHUTDOWN MODE ACK\n");
1350 stShutdownResponse.szData[2] = SHUTDOWN_ACK_FROM_DRIVER; /* ShutDown ACK */
1351
1352 /* Wait for the LED to TURN OFF before sending ACK response */
1353 if (Adapter->LEDInfo.led_thread_running & BCM_LED_THREAD_RUNNING_ACTIVELY) {
1354 int iRetVal = 0;
1355
1356 /* Wake the LED Thread with LOWPOWER_MODE_ENTER State */
1357 Adapter->DriverState = LOWPOWER_MODE_ENTER;
1358 wake_up(&Adapter->LEDInfo.notify_led_event);
1359
1360 /* Wait for 1 SEC for LED to OFF */
1361 iRetVal = wait_event_timeout(Adapter->LEDInfo.idleModeSyncEvent, Adapter->LEDInfo.bIdle_led_off, msecs_to_jiffies(1000));
1362
1363 /* If Timed Out to Sync IDLE MODE Enter, do IDLE mode Exit and Send NACK to device */
1364 if (iRetVal <= 0) {
1365 stShutdownResponse.szData[1] = SHUTDOWN_NACK_FROM_DRIVER; /* NACK- device access is going on. */
1366 Adapter->DriverState = NO_NETWORK_ENTRY;
1367 wake_up(&Adapter->LEDInfo.notify_led_event);
1368 }
1369 }
1370
1371 if (stShutdownResponse.szData[2] == SHUTDOWN_ACK_FROM_DRIVER) {
1372 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "ACKING SHUTDOWN MODE !!!!!!!!!");
1373 down(&Adapter->rdmwrmsync);
1374 Adapter->bPreparingForLowPowerMode = TRUE;
1375 up(&Adapter->rdmwrmsync);
1376 /* Killing all URBS. */
1377 if (Adapter->bDoSuspend == TRUE)
1378 Bcm_kill_all_URBs((struct bcm_interface_adapter *)(Adapter->pvInterfaceAdapter));
1379 } else {
1380 Adapter->bPreparingForLowPowerMode = false;
1381 }
1382
1383 if (!NVMAccess)
1384 up(&Adapter->NVMRdmWrmLock);
1385
1386 if (!lowPwrAbortMsg)
1387 up(&Adapter->LowPowerModeSync);
1388 }
1389
1390 Status = CopyBufferToControlPacket(Adapter, &stShutdownResponse);
1391 if (Status != STATUS_SUCCESS) {
1392 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "fail to send the Idle mode Request\n");
1393 Adapter->bPreparingForLowPowerMode = false;
1394 StartInterruptUrb((struct bcm_interface_adapter *)(Adapter->pvInterfaceAdapter));
1395 }
1396}
1397
1398static void HandleShutDownModeRequest(struct bcm_mini_adapter *Adapter, PUCHAR pucBuffer)
1399{
1400 unsigned int uiResetValue = 0;
1401
1402 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "====>\n");
1403
1404 if (*(pucBuffer+1) == COMPLETE_WAKE_UP_NOTIFICATION_FRM_FW) {
1405 HandleShutDownModeWakeup(Adapter);
1406 } else if (*(pucBuffer+1) == LINK_SHUTDOWN_REQ_FROM_FIRMWARE) {
1407 /* Target wants to go to Shut Down Mode */
1408 /* InterfacePrepareForShutdown(Adapter); */
1409 if (Adapter->chip_id == BCS220_2 ||
1410 Adapter->chip_id == BCS220_2BC ||
1411 Adapter->chip_id == BCS250_BC ||
1412 Adapter->chip_id == BCS220_3) {
1413
1414 rdmalt(Adapter, HPM_CONFIG_MSW, &uiResetValue, 4);
1415 uiResetValue |= (1<<17);
1416 wrmalt(Adapter, HPM_CONFIG_MSW, &uiResetValue, 4);
1417 }
1418
1419 SendShutModeResponse(Adapter);
1420 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "ShutDownModeResponse:Notification received: Sending the response(Ack/Nack)\n");
1421 }
1422
1423 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, MP_SHUTDOWN, DBG_LVL_ALL, "<====\n");
1424}
1425
1426void ResetCounters(struct bcm_mini_adapter *Adapter)
1427{
1428 beceem_protocol_reset(Adapter);
1429 Adapter->CurrNumRecvDescs = 0;
1430 Adapter->PrevNumRecvDescs = 0;
1431 Adapter->LinkUpStatus = 0;
1432 Adapter->LinkStatus = 0;
1433 atomic_set(&Adapter->cntrlpktCnt, 0);
1434 atomic_set(&Adapter->TotalPacketCount, 0);
1435 Adapter->fw_download_done = false;
1436 Adapter->LinkStatus = 0;
1437 Adapter->AutoLinkUp = false;
1438 Adapter->IdleMode = false;
1439 Adapter->bShutStatus = false;
1440}
1441
1442struct bcm_classifier_rule *GetFragIPClsEntry(struct bcm_mini_adapter *Adapter, USHORT usIpIdentification, ULONG SrcIP)
1443{
1444 unsigned int uiIndex = 0;
1445
1446 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1447 if ((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) &&
1448 (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification) &&
1449 (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress == SrcIP) &&
1450 !Adapter->astFragmentedPktClassifierTable[uiIndex].bOutOfOrderFragment)
1451
1452 return Adapter->astFragmentedPktClassifierTable[uiIndex].pstMatchedClassifierEntry;
1453 }
1454 return NULL;
1455}
1456
1457void AddFragIPClsEntry(struct bcm_mini_adapter *Adapter, struct bcm_fragmented_packet_info *psFragPktInfo)
1458{
1459 unsigned int uiIndex = 0;
1460
1461 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1462 if (!Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) {
1463 memcpy(&Adapter->astFragmentedPktClassifierTable[uiIndex], psFragPktInfo, sizeof(struct bcm_fragmented_packet_info));
1464 break;
1465 }
1466 }
1467}
1468
1469void DelFragIPClsEntry(struct bcm_mini_adapter *Adapter, USHORT usIpIdentification, ULONG SrcIp)
1470{
1471 unsigned int uiIndex = 0;
1472
1473 for (uiIndex = 0; uiIndex < MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES; uiIndex++) {
1474 if ((Adapter->astFragmentedPktClassifierTable[uiIndex].bUsed) &&
1475 (Adapter->astFragmentedPktClassifierTable[uiIndex].usIpIdentification == usIpIdentification) &&
1476 (Adapter->astFragmentedPktClassifierTable[uiIndex].ulSrcIpAddress == SrcIp))
1477
1478 memset(&Adapter->astFragmentedPktClassifierTable[uiIndex], 0, sizeof(struct bcm_fragmented_packet_info));
1479 }
1480}
1481
1482void update_per_cid_rx(struct bcm_mini_adapter *Adapter)
1483{
1484 unsigned int qindex = 0;
1485
1486 if ((jiffies - Adapter->liDrainCalculated) < XSECONDS)
1487 return;
1488
1489 for (qindex = 0; qindex < HiPriority; qindex++) {
1490 if (Adapter->PackInfo[qindex].ucDirection == 0) {
1491 Adapter->PackInfo[qindex].uiCurrentRxRate =
1492 (Adapter->PackInfo[qindex].uiCurrentRxRate +
1493 Adapter->PackInfo[qindex].uiThisPeriodRxBytes) / 2;
1494
1495 Adapter->PackInfo[qindex].uiThisPeriodRxBytes = 0;
1496 } else {
1497 Adapter->PackInfo[qindex].uiCurrentDrainRate =
1498 (Adapter->PackInfo[qindex].uiCurrentDrainRate +
1499 Adapter->PackInfo[qindex].uiThisPeriodSentBytes) / 2;
1500 Adapter->PackInfo[qindex].uiThisPeriodSentBytes = 0;
1501 }
1502 }
1503 Adapter->liDrainCalculated = jiffies;
1504}
1505
1506void update_per_sf_desc_cnts(struct bcm_mini_adapter *Adapter)
1507{
1508 int iIndex = 0;
1509 u32 uibuff[MAX_TARGET_DSX_BUFFERS];
1510 int bytes;
1511
1512 if (!atomic_read(&Adapter->uiMBupdate))
1513 return;
1514
1515 bytes = rdmaltWithLock(Adapter, TARGET_SFID_TXDESC_MAP_LOC, (unsigned int *)uibuff, sizeof(unsigned int) * MAX_TARGET_DSX_BUFFERS);
1516 if (bytes < 0) {
1517 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "rdm failed\n");
1518 return;
1519 }
1520
1521 for (iIndex = 0; iIndex < HiPriority; iIndex++) {
1522 if (Adapter->PackInfo[iIndex].bValid && Adapter->PackInfo[iIndex].ucDirection) {
1523 if (Adapter->PackInfo[iIndex].usVCID_Value < MAX_TARGET_DSX_BUFFERS)
1524 atomic_set(&Adapter->PackInfo[iIndex].uiPerSFTxResourceCount, uibuff[Adapter->PackInfo[iIndex].usVCID_Value]);
1525 else
1526 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Invalid VCID : %x\n", Adapter->PackInfo[iIndex].usVCID_Value);
1527 }
1528 }
1529 atomic_set(&Adapter->uiMBupdate, false);
1530}
1531
1532void flush_queue(struct bcm_mini_adapter *Adapter, unsigned int iQIndex)
1533{
1534 struct sk_buff *PacketToDrop = NULL;
1535 struct net_device_stats *netstats = &Adapter->dev->stats;
1536
1537 spin_lock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
1538
1539 while (Adapter->PackInfo[iQIndex].FirstTxQueue && atomic_read(&Adapter->TotalPacketCount)) {
1540 PacketToDrop = Adapter->PackInfo[iQIndex].FirstTxQueue;
1541 if (PacketToDrop && PacketToDrop->len) {
1542 netstats->tx_dropped++;
1543 DEQUEUEPACKET(Adapter->PackInfo[iQIndex].FirstTxQueue, Adapter->PackInfo[iQIndex].LastTxQueue);
1544 Adapter->PackInfo[iQIndex].uiCurrentPacketsOnHost--;
1545 Adapter->PackInfo[iQIndex].uiCurrentBytesOnHost -= PacketToDrop->len;
1546
1547 /* Adding dropped statistics */
1548 Adapter->PackInfo[iQIndex].uiDroppedCountBytes += PacketToDrop->len;
1549 Adapter->PackInfo[iQIndex].uiDroppedCountPackets++;
1550 dev_kfree_skb(PacketToDrop);
1551 atomic_dec(&Adapter->TotalPacketCount);
1552 }
1553 }
1554 spin_unlock_bh(&Adapter->PackInfo[iQIndex].SFQueueLock);
1555}
1556
1557static void beceem_protocol_reset(struct bcm_mini_adapter *Adapter)
1558{
1559 int i;
1560
1561 if (netif_msg_link(Adapter))
1562 pr_notice(PFX "%s: protocol reset\n", Adapter->dev->name);
1563
1564 netif_carrier_off(Adapter->dev);
1565 netif_stop_queue(Adapter->dev);
1566
1567 Adapter->IdleMode = false;
1568 Adapter->LinkUpStatus = false;
1569 ClearTargetDSXBuffer(Adapter, 0, TRUE);
1570 /* Delete All Classifier Rules */
1571
1572 for (i = 0; i < HiPriority; i++)
1573 DeleteAllClassifiersForSF(Adapter, i);
1574
1575 flush_all_queues(Adapter);
1576
1577 if (Adapter->TimerActive == TRUE)
1578 Adapter->TimerActive = false;
1579
1580 memset(Adapter->astFragmentedPktClassifierTable, 0, sizeof(struct bcm_fragmented_packet_info) * MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES);
1581
1582 for (i = 0; i < HiPriority; i++) {
1583 /* resetting only the first size (S_MIBS_SERVICEFLOW_TABLE) for the SF. */
1584 /* It is same between MIBs and SF. */
1585 memset(&Adapter->PackInfo[i].stMibsExtServiceFlowTable, 0, sizeof(struct bcm_mibs_parameters));
1586 }
1587}
diff --git a/drivers/staging/bcm/PHSDefines.h b/drivers/staging/bcm/PHSDefines.h
deleted file mode 100644
index cd78ee4ffa22..000000000000
--- a/drivers/staging/bcm/PHSDefines.h
+++ /dev/null
@@ -1,94 +0,0 @@
1#ifndef BCM_PHS_DEFINES_H
2#define BCM_PHS_DEFINES_H
3
4#define PHS_INVALID_TABLE_INDEX 0xffffffff
5#define PHS_MEM_TAG "_SHP"
6
7/* PHS Defines */
8#define STATUS_PHS_COMPRESSED 0xa1
9#define STATUS_PHS_NOCOMPRESSION 0xa2
10#define APPLY_PHS 1
11#define MAX_NO_BIT 7
12#define ZERO_PHSI 0
13#define VERIFY 0
14#define SIZE_MULTIPLE_32 4
15#define UNCOMPRESSED_PACKET 0
16#define DYNAMIC 0
17#define SUPPRESS 0x80
18#define NO_CLASSIFIER_MATCH 0
19#define SEND_PACKET_UNCOMPRESSED 0
20#define PHSI_IS_ZERO 0
21#define PHSI_LEN 1
22#define ERROR_LEN 0
23#define PHS_BUFFER_SIZE 1532
24#define MAX_PHSRULE_PER_SF 20
25#define MAX_SERVICEFLOWS 17
26
27/* PHS Error Defines */
28#define PHS_SUCCESS 0
29#define ERR_PHS_INVALID_DEVICE_EXETENSION 0x800
30#define ERR_PHS_INVALID_PHS_RULE 0x801
31#define ERR_PHS_RULE_ALREADY_EXISTS 0x802
32#define ERR_SF_MATCH_FAIL 0x803
33#define ERR_INVALID_CLASSIFIERTABLE_FOR_SF 0x804
34#define ERR_SFTABLE_FULL 0x805
35#define ERR_CLSASSIFIER_TABLE_FULL 0x806
36#define ERR_PHSRULE_MEMALLOC_FAIL 0x807
37#define ERR_CLSID_MATCH_FAIL 0x808
38#define ERR_PHSRULE_MATCH_FAIL 0x809
39
40struct bcm_phs_rule {
41 u8 u8PHSI;
42 u8 u8PHSFLength;
43 u8 u8PHSF[MAX_PHS_LENGTHS];
44 u8 u8PHSMLength;
45 u8 u8PHSM[MAX_PHS_LENGTHS];
46 u8 u8PHSS;
47 u8 u8PHSV;
48 u8 u8RefCnt;
49 u8 bUnclassifiedPHSRule;
50 u8 u8Reserved[3];
51 long PHSModifiedBytes;
52 unsigned long PHSModifiedNumPackets;
53 unsigned long PHSErrorNumPackets;
54};
55
56enum bcm_phs_classifier_context {
57 eActiveClassifierRuleContext,
58 eOldClassifierRuleContext
59};
60
61struct bcm_phs_classifier_entry {
62 u8 bUsed;
63 u16 uiClassifierRuleId;
64 u8 u8PHSI;
65 struct bcm_phs_rule *pstPhsRule;
66 u8 bUnclassifiedPHSRule;
67};
68
69struct bcm_phs_classifier_table {
70 u16 uiTotalClassifiers;
71 struct bcm_phs_classifier_entry stActivePhsRulesList[MAX_PHSRULE_PER_SF];
72 struct bcm_phs_classifier_entry stOldPhsRulesList[MAX_PHSRULE_PER_SF];
73 u16 uiOldestPhsRuleIndex;
74};
75
76struct bcm_phs_entry {
77 u8 bUsed;
78 u16 uiVcid;
79 struct bcm_phs_classifier_table *pstClassifierTable;
80};
81
82struct bcm_phs_table {
83 u16 uiTotalServiceFlows;
84 struct bcm_phs_entry stSFList[MAX_SERVICEFLOWS];
85};
86
87struct bcm_phs_extension {
88 /* PHS Specific data */
89 struct bcm_phs_table *pstServiceFlowPhsRulesTable;
90 void *CompressedTxBuffer;
91 void *UnCompressedRxBuffer;
92};
93
94#endif
diff --git a/drivers/staging/bcm/PHSModule.c b/drivers/staging/bcm/PHSModule.c
deleted file mode 100644
index 5f4e503d54ec..000000000000
--- a/drivers/staging/bcm/PHSModule.c
+++ /dev/null
@@ -1,1703 +0,0 @@
1#include "headers.h"
2
3static UINT CreateSFToClassifierRuleMapping(B_UINT16 uiVcid,
4 B_UINT16 uiClsId,
5 struct bcm_phs_table *psServiceFlowTable,
6 struct bcm_phs_rule *psPhsRule,
7 B_UINT8 u8AssociatedPHSI);
8
9static UINT CreateClassiferToPHSRuleMapping(B_UINT16 uiVcid,
10 B_UINT16 uiClsId,
11 struct bcm_phs_entry *pstServiceFlowEntry,
12 struct bcm_phs_rule *psPhsRule,
13 B_UINT8 u8AssociatedPHSI);
14
15static UINT CreateClassifierPHSRule(B_UINT16 uiClsId,
16 struct bcm_phs_classifier_table *psaClassifiertable,
17 struct bcm_phs_rule *psPhsRule,
18 enum bcm_phs_classifier_context eClsContext,
19 B_UINT8 u8AssociatedPHSI);
20
21static UINT UpdateClassifierPHSRule(B_UINT16 uiClsId,
22 struct bcm_phs_classifier_entry *pstClassifierEntry,
23 struct bcm_phs_classifier_table *psaClassifiertable,
24 struct bcm_phs_rule *psPhsRule,
25 B_UINT8 u8AssociatedPHSI);
26
27static bool ValidatePHSRuleComplete(const struct bcm_phs_rule *psPhsRule);
28
29static bool DerefPhsRule(B_UINT16 uiClsId,
30 struct bcm_phs_classifier_table *psaClassifiertable,
31 struct bcm_phs_rule *pstPhsRule);
32
33static UINT GetClassifierEntry(struct bcm_phs_classifier_table *pstClassifierTable,
34 B_UINT32 uiClsid,
35 enum bcm_phs_classifier_context eClsContext,
36 struct bcm_phs_classifier_entry **ppstClassifierEntry);
37
38static UINT GetPhsRuleEntry(struct bcm_phs_classifier_table *pstClassifierTable,
39 B_UINT32 uiPHSI,
40 enum bcm_phs_classifier_context eClsContext,
41 struct bcm_phs_rule **ppstPhsRule);
42
43static void free_phs_serviceflow_rules(struct bcm_phs_table *psServiceFlowRulesTable);
44
45static int phs_compress(struct bcm_phs_rule *phs_members,
46 unsigned char *in_buf,
47 unsigned char *out_buf,
48 unsigned int *header_size,
49 UINT *new_header_size);
50
51static int verify_suppress_phsf(unsigned char *in_buffer,
52 unsigned char *out_buffer,
53 unsigned char *phsf,
54 unsigned char *phsm,
55 unsigned int phss,
56 unsigned int phsv,
57 UINT *new_header_size);
58
59static int phs_decompress(unsigned char *in_buf,
60 unsigned char *out_buf,
61 struct bcm_phs_rule *phs_rules,
62 UINT *header_size);
63
64static ULONG PhsCompress(void *pvContext,
65 B_UINT16 uiVcid,
66 B_UINT16 uiClsId,
67 void *pvInputBuffer,
68 void *pvOutputBuffer,
69 UINT *pOldHeaderSize,
70 UINT *pNewHeaderSize);
71
72static ULONG PhsDeCompress(void *pvContext,
73 B_UINT16 uiVcid,
74 void *pvInputBuffer,
75 void *pvOutputBuffer,
76 UINT *pInHeaderSize,
77 UINT *pOutHeaderSize);
78
79#define IN
80#define OUT
81
82/*
83 * Function: PHSTransmit
84 * Description: This routine handle PHS(Payload Header Suppression for Tx path.
85 * It extracts a fragment of the NDIS_PACKET containing the header
86 * to be suppressed. It then suppresses the header by invoking PHS exported compress routine.
87 * The header data after suppression is copied back to the NDIS_PACKET.
88 *
89 * Input parameters: IN struct bcm_mini_adapter *Adapter - Miniport Adapter Context
90 * IN Packet - NDIS packet containing data to be transmitted
91 * IN USHORT Vcid - vcid pertaining to connection on which the packet is being sent.Used to
92 * identify PHS rule to be applied.
93 * B_UINT16 uiClassifierRuleID - Classifier Rule ID
94 * BOOLEAN bHeaderSuppressionEnabled - indicates if header suprression is enabled for SF.
95 *
96 * Return: STATUS_SUCCESS - If the send was successful.
97 * Other - If an error occurred.
98 */
99
100int PHSTransmit(struct bcm_mini_adapter *Adapter,
101 struct sk_buff **pPacket,
102 USHORT Vcid,
103 B_UINT16 uiClassifierRuleID,
104 bool bHeaderSuppressionEnabled,
105 UINT *PacketLen,
106 UCHAR bEthCSSupport)
107{
108 /* PHS Sepcific */
109 UINT unPHSPktHdrBytesCopied = 0;
110 UINT unPhsOldHdrSize = 0;
111 UINT unPHSNewPktHeaderLen = 0;
112 /* Pointer to PHS IN Hdr Buffer */
113 PUCHAR pucPHSPktHdrInBuf =
114 Adapter->stPhsTxContextInfo.ucaHdrSuppressionInBuf;
115 /* Pointer to PHS OUT Hdr Buffer */
116 PUCHAR pucPHSPktHdrOutBuf =
117 Adapter->stPhsTxContextInfo.ucaHdrSuppressionOutBuf;
118 UINT usPacketType;
119 UINT BytesToRemove = 0;
120 bool bPHSI = 0;
121 LONG ulPhsStatus = 0;
122 UINT numBytesCompressed = 0;
123 struct sk_buff *newPacket = NULL;
124 struct sk_buff *Packet = *pPacket;
125
126 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,
127 "In PHSTransmit");
128
129 if (!bEthCSSupport)
130 BytesToRemove = ETH_HLEN;
131 /*
132 * Accumulate the header upto the size we support suppression
133 * from NDIS packet
134 */
135
136 usPacketType = ((struct ethhdr *)(Packet->data))->h_proto;
137
138 pucPHSPktHdrInBuf = Packet->data + BytesToRemove;
139 /* considering data after ethernet header */
140 if ((*PacketLen - BytesToRemove) < MAX_PHS_LENGTHS)
141 unPHSPktHdrBytesCopied = (*PacketLen - BytesToRemove);
142 else
143 unPHSPktHdrBytesCopied = MAX_PHS_LENGTHS;
144
145 if ((unPHSPktHdrBytesCopied > 0) &&
146 (unPHSPktHdrBytesCopied <= MAX_PHS_LENGTHS)) {
147
148 /*
149 * Step 2 Suppress Header using PHS and fill into intermediate
150 * ucaPHSPktHdrOutBuf.
151 * Suppress only if IP Header and PHS Enabled For the
152 * Service Flow
153 */
154 if (((usPacketType == ETHERNET_FRAMETYPE_IPV4) ||
155 (usPacketType == ETHERNET_FRAMETYPE_IPV6)) &&
156 (bHeaderSuppressionEnabled)) {
157
158 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND,
159 DBG_LVL_ALL,
160 "\nTrying to PHS Compress Using Classifier rule 0x%X",
161 uiClassifierRuleID);
162 unPHSNewPktHeaderLen = unPHSPktHdrBytesCopied;
163 ulPhsStatus = PhsCompress(&Adapter->stBCMPhsContext,
164 Vcid,
165 uiClassifierRuleID,
166 pucPHSPktHdrInBuf,
167 pucPHSPktHdrOutBuf,
168 &unPhsOldHdrSize,
169 &unPHSNewPktHeaderLen);
170 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND,
171 DBG_LVL_ALL,
172 "\nPHS Old header Size : %d New Header Size %d\n",
173 unPhsOldHdrSize, unPHSNewPktHeaderLen);
174
175 if (unPHSNewPktHeaderLen == unPhsOldHdrSize) {
176
177 if (ulPhsStatus == STATUS_PHS_COMPRESSED)
178 bPHSI = *pucPHSPktHdrOutBuf;
179
180 ulPhsStatus = STATUS_PHS_NOCOMPRESSION;
181 }
182
183 if (ulPhsStatus == STATUS_PHS_COMPRESSED) {
184
185 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
186 PHS_SEND, DBG_LVL_ALL,
187 "PHS Sending packet Compressed");
188
189 if (skb_cloned(Packet)) {
190 newPacket =
191 skb_copy(Packet, GFP_ATOMIC);
192
193 if (newPacket == NULL)
194 return STATUS_FAILURE;
195
196 dev_kfree_skb(Packet);
197 *pPacket = Packet = newPacket;
198 pucPHSPktHdrInBuf =
199 Packet->data + BytesToRemove;
200 }
201
202 numBytesCompressed = unPhsOldHdrSize -
203 (unPHSNewPktHeaderLen + PHSI_LEN);
204
205 memcpy(pucPHSPktHdrInBuf + numBytesCompressed,
206 pucPHSPktHdrOutBuf,
207 unPHSNewPktHeaderLen + PHSI_LEN);
208 memcpy(Packet->data + numBytesCompressed,
209 Packet->data, BytesToRemove);
210 skb_pull(Packet, numBytesCompressed);
211
212 return STATUS_SUCCESS;
213 } else {
214 /* if one byte headroom is not available,
215 * increase it through skb_cow
216 */
217 if (!(skb_headroom(Packet) > 0)) {
218
219 if (skb_cow(Packet, 1)) {
220 BCM_DEBUG_PRINT(Adapter,
221 DBG_TYPE_PRINTK,
222 0, 0,
223 "SKB Cow Failed\n");
224 return STATUS_FAILURE;
225 }
226 }
227 skb_push(Packet, 1);
228
229 /*
230 * CAUTION: The MAC Header is getting corrupted
231 * here for IP CS - can be saved by copying 14
232 * Bytes. not needed .... hence corrupting it.
233 */
234 *(Packet->data + BytesToRemove) = bPHSI;
235 return STATUS_SUCCESS;
236 }
237 } else {
238
239 if (!bHeaderSuppressionEnabled)
240 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
241 PHS_SEND, DBG_LVL_ALL,
242 "\nHeader Suppression Disabled For SF: No PHS\n");
243
244 return STATUS_SUCCESS;
245 }
246 }
247
248 /* BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,
249 * "PHSTransmit : Dumping data packet After PHS"); */
250 return STATUS_SUCCESS;
251}
252
253int PHSReceive(struct bcm_mini_adapter *Adapter,
254 USHORT usVcid,
255 struct sk_buff *packet,
256 UINT *punPacketLen,
257 UCHAR *pucEthernetHdr,
258 UINT bHeaderSuppressionEnabled)
259{
260 u32 nStandardPktHdrLen = 0;
261 u32 nTotalsuppressedPktHdrBytes = 0;
262 int ulPhsStatus = 0;
263 PUCHAR pucInBuff = NULL;
264 UINT TotalBytesAdded = 0;
265
266 if (!bHeaderSuppressionEnabled) {
267 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE,
268 DBG_LVL_ALL,
269 "\nPhs Disabled for incoming packet");
270 return ulPhsStatus;
271 }
272
273 pucInBuff = packet->data;
274
275 /* Restore PHS suppressed header */
276 nStandardPktHdrLen = packet->len;
277 ulPhsStatus = PhsDeCompress(&Adapter->stBCMPhsContext,
278 usVcid,
279 pucInBuff,
280 Adapter->ucaPHSPktRestoreBuf,
281 &nTotalsuppressedPktHdrBytes,
282 &nStandardPktHdrLen);
283
284 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL,
285 "\nSuppressed PktHdrLen : 0x%x Restored PktHdrLen : 0x%x",
286 nTotalsuppressedPktHdrBytes, nStandardPktHdrLen);
287
288 if (ulPhsStatus != STATUS_PHS_COMPRESSED) {
289 skb_pull(packet, 1);
290 return STATUS_SUCCESS;
291 } else {
292 TotalBytesAdded = nStandardPktHdrLen -
293 nTotalsuppressedPktHdrBytes - PHSI_LEN;
294
295 if (TotalBytesAdded) {
296 if (skb_headroom(packet) >= (SKB_RESERVE_ETHERNET_HEADER + TotalBytesAdded))
297 skb_push(packet, TotalBytesAdded);
298 else {
299 if (skb_cow(packet, skb_headroom(packet) + TotalBytesAdded)) {
300 BCM_DEBUG_PRINT(Adapter,
301 DBG_TYPE_PRINTK, 0, 0,
302 "cow failed in receive\n");
303 return STATUS_FAILURE;
304 }
305
306 skb_push(packet, TotalBytesAdded);
307 }
308 }
309
310 memcpy(packet->data, Adapter->ucaPHSPktRestoreBuf,
311 nStandardPktHdrLen);
312 }
313
314 return STATUS_SUCCESS;
315}
316
317void DumpFullPacket(UCHAR *pBuf, UINT nPktLen)
318{
319 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
320
321 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL,
322 "Dumping Data Packet");
323 BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_TX, IPV4_DBG, DBG_LVL_ALL,
324 pBuf, nPktLen);
325}
326
327/*
328 * Procedure: phs_init
329 *
330 * Description: This routine is responsible for allocating memory for classifier
331 * and PHS rules.
332 *
333 * Arguments:
334 * pPhsdeviceExtension - ptr to Device extension containing PHS Classifier rules
335 * and PHS Rules , RX, TX buffer etc
336 *
337 * Returns:
338 * TRUE(1) -If allocation of memory was successful.
339 * FALSE -If allocation of memory fails.
340 */
341int phs_init(struct bcm_phs_extension *pPhsdeviceExtension,
342 struct bcm_mini_adapter *Adapter)
343{
344 int i;
345 struct bcm_phs_table *pstServiceFlowTable;
346
347 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL,
348 "\nPHS:phs_init function");
349
350 if (pPhsdeviceExtension->pstServiceFlowPhsRulesTable)
351 return -EINVAL;
352
353 pPhsdeviceExtension->pstServiceFlowPhsRulesTable =
354 kzalloc(sizeof(struct bcm_phs_table), GFP_KERNEL);
355
356 if (!pPhsdeviceExtension->pstServiceFlowPhsRulesTable) {
357 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH,
358 DBG_LVL_ALL,
359 "\nAllocation ServiceFlowPhsRulesTable failed");
360 return -ENOMEM;
361 }
362
363 pstServiceFlowTable = pPhsdeviceExtension->pstServiceFlowPhsRulesTable;
364 for (i = 0; i < MAX_SERVICEFLOWS; i++) {
365 struct bcm_phs_entry sServiceFlow =
366 pstServiceFlowTable->stSFList[i];
367 sServiceFlow.pstClassifierTable =
368 kzalloc(sizeof(struct bcm_phs_classifier_table),
369 GFP_KERNEL);
370 if (!sServiceFlow.pstClassifierTable) {
371 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH,
372 DBG_LVL_ALL, "\nAllocation failed");
373 free_phs_serviceflow_rules(pPhsdeviceExtension->pstServiceFlowPhsRulesTable);
374 pPhsdeviceExtension->pstServiceFlowPhsRulesTable = NULL;
375 return -ENOMEM;
376 }
377 }
378
379 pPhsdeviceExtension->CompressedTxBuffer = kmalloc(PHS_BUFFER_SIZE, GFP_KERNEL);
380 if (pPhsdeviceExtension->CompressedTxBuffer == NULL) {
381 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH,
382 DBG_LVL_ALL, "\nAllocation failed");
383 free_phs_serviceflow_rules(pPhsdeviceExtension->pstServiceFlowPhsRulesTable);
384 pPhsdeviceExtension->pstServiceFlowPhsRulesTable = NULL;
385 return -ENOMEM;
386 }
387
388 pPhsdeviceExtension->UnCompressedRxBuffer =
389 kmalloc(PHS_BUFFER_SIZE, GFP_KERNEL);
390 if (pPhsdeviceExtension->UnCompressedRxBuffer == NULL) {
391 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH,
392 DBG_LVL_ALL, "\nAllocation failed");
393 kfree(pPhsdeviceExtension->CompressedTxBuffer);
394 free_phs_serviceflow_rules(pPhsdeviceExtension->pstServiceFlowPhsRulesTable);
395 pPhsdeviceExtension->pstServiceFlowPhsRulesTable = NULL;
396 return -ENOMEM;
397 }
398
399 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL,
400 "\n phs_init Successful");
401 return STATUS_SUCCESS;
402}
403
404int PhsCleanup(IN struct bcm_phs_extension *pPHSDeviceExt)
405{
406 if (pPHSDeviceExt->pstServiceFlowPhsRulesTable) {
407 free_phs_serviceflow_rules(pPHSDeviceExt->pstServiceFlowPhsRulesTable);
408 pPHSDeviceExt->pstServiceFlowPhsRulesTable = NULL;
409 }
410
411 kfree(pPHSDeviceExt->CompressedTxBuffer);
412 pPHSDeviceExt->CompressedTxBuffer = NULL;
413
414 kfree(pPHSDeviceExt->UnCompressedRxBuffer);
415 pPHSDeviceExt->UnCompressedRxBuffer = NULL;
416
417 return 0;
418}
419
420/*
421 * PHS functions
422 * PhsUpdateClassifierRule
423 *
424 * Routine Description:
425 * Exported function to add or modify a PHS Rule.
426 *
427 * Arguments:
428 * IN void* pvContext - PHS Driver Specific Context
429 * IN B_UINT16 uiVcid - The Service Flow ID for which the PHS rule applies
430 * IN B_UINT16 uiClsId - The Classifier ID within the Service Flow for which the PHS rule applies.
431 * IN struct bcm_phs_rule *psPhsRule - The PHS Rule strcuture to be added to the PHS Rule table.
432 *
433 * Return Value:
434 *
435 * 0 if successful,
436 * >0 Error.
437 */
438ULONG PhsUpdateClassifierRule(IN void *pvContext,
439 IN B_UINT16 uiVcid ,
440 IN B_UINT16 uiClsId ,
441 IN struct bcm_phs_rule *psPhsRule,
442 IN B_UINT8 u8AssociatedPHSI)
443{
444 ULONG lStatus = 0;
445 UINT nSFIndex = 0;
446 struct bcm_phs_entry *pstServiceFlowEntry = NULL;
447 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
448 struct bcm_phs_extension *pDeviceExtension =
449 (struct bcm_phs_extension *)pvContext;
450
451 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL,
452 "PHS With Corr2 Changes\n");
453
454 if (pDeviceExtension == NULL) {
455 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH,
456 DBG_LVL_ALL, "Invalid Device Extension\n");
457 return ERR_PHS_INVALID_DEVICE_EXETENSION;
458 }
459
460 if (u8AssociatedPHSI == 0)
461 return ERR_PHS_INVALID_PHS_RULE;
462
463 /* Retrieve the SFID Entry Index for requested Service Flow */
464 nSFIndex = GetServiceFlowEntry(pDeviceExtension->pstServiceFlowPhsRulesTable,
465 uiVcid, &pstServiceFlowEntry);
466
467 if (nSFIndex == PHS_INVALID_TABLE_INDEX) {
468 /* This is a new SF. Create a mapping entry for this */
469 lStatus = CreateSFToClassifierRuleMapping(uiVcid, uiClsId,
470 pDeviceExtension->pstServiceFlowPhsRulesTable,
471 psPhsRule,
472 u8AssociatedPHSI);
473 return lStatus;
474 }
475
476 /* SF already Exists Add PHS Rule to existing SF */
477 lStatus = CreateClassiferToPHSRuleMapping(uiVcid, uiClsId,
478 pstServiceFlowEntry,
479 psPhsRule,
480 u8AssociatedPHSI);
481
482 return lStatus;
483}
484
485/*
486 * PhsDeletePHSRule
487 *
488 * Routine Description:
489 * Deletes the specified phs Rule within Vcid
490 *
491 * Arguments:
492 * IN void* pvContext - PHS Driver Specific Context
493 * IN B_UINT16 uiVcid - The Service Flow ID for which the PHS rule applies
494 * IN B_UINT8 u8PHSI - the PHS Index identifying PHS rule to be deleted.
495 *
496 * Return Value:
497 *
498 * 0 if successful,
499 * >0 Error.
500 */
501ULONG PhsDeletePHSRule(IN void *pvContext,
502 IN B_UINT16 uiVcid,
503 IN B_UINT8 u8PHSI)
504{
505 UINT nSFIndex = 0, nClsidIndex = 0;
506 struct bcm_phs_entry *pstServiceFlowEntry = NULL;
507 struct bcm_phs_classifier_table *pstClassifierRulesTable = NULL;
508 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
509 struct bcm_phs_extension *pDeviceExtension = (struct bcm_phs_extension *)pvContext;
510 struct bcm_phs_classifier_entry *curr_entry;
511
512 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL,
513 "======>\n");
514
515 if (pDeviceExtension) {
516 /* Retrieve the SFID Entry Index for requested Service Flow */
517 nSFIndex = GetServiceFlowEntry(pDeviceExtension->pstServiceFlowPhsRulesTable,
518 uiVcid, &pstServiceFlowEntry);
519
520 if (nSFIndex == PHS_INVALID_TABLE_INDEX) {
521 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH,
522 DBG_LVL_ALL, "SFID Match Failed\n");
523 return ERR_SF_MATCH_FAIL;
524 }
525
526 pstClassifierRulesTable = pstServiceFlowEntry->pstClassifierTable;
527 if (pstClassifierRulesTable) {
528 for (nClsidIndex = 0; nClsidIndex < MAX_PHSRULE_PER_SF; nClsidIndex++) {
529 curr_entry = &pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex];
530 if (curr_entry->bUsed &&
531 curr_entry->pstPhsRule &&
532 (curr_entry->pstPhsRule->u8PHSI == u8PHSI)) {
533
534 if (curr_entry->pstPhsRule->u8RefCnt)
535 curr_entry->pstPhsRule->u8RefCnt--;
536
537 if (0 == curr_entry->pstPhsRule->u8RefCnt)
538 kfree(curr_entry->pstPhsRule);
539
540 memset(curr_entry,
541 0,
542 sizeof(struct bcm_phs_classifier_entry));
543 }
544 }
545 }
546 }
547 return 0;
548}
549
550/*
551 * PhsDeleteClassifierRule
552 *
553 * Routine Description:
554 * Exported function to Delete a PHS Rule for the SFID,CLSID Pair.
555 *
556 * Arguments:
557 * IN void* pvContext - PHS Driver Specific Context
558 * IN B_UINT16 uiVcid - The Service Flow ID for which the PHS rule applies
559 * IN B_UINT16 uiClsId - The Classifier ID within the Service Flow for which the PHS rule applies.
560 *
561 * Return Value:
562 *
563 * 0 if successful,
564 * >0 Error.
565 */
566ULONG PhsDeleteClassifierRule(IN void *pvContext,
567 IN B_UINT16 uiVcid,
568 IN B_UINT16 uiClsId)
569{
570 UINT nSFIndex = 0, nClsidIndex = 0;
571 struct bcm_phs_entry *pstServiceFlowEntry = NULL;
572 struct bcm_phs_classifier_entry *pstClassifierEntry = NULL;
573 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
574 struct bcm_phs_extension *pDeviceExtension =
575 (struct bcm_phs_extension *)pvContext;
576
577 if (!pDeviceExtension)
578 goto out;
579
580 /* Retrieve the SFID Entry Index for requested Service Flow */
581 nSFIndex = GetServiceFlowEntry(pDeviceExtension->pstServiceFlowPhsRulesTable,
582 uiVcid, &pstServiceFlowEntry);
583 if (nSFIndex == PHS_INVALID_TABLE_INDEX) {
584 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH,
585 DBG_LVL_ALL, "SFID Match Failed\n");
586 return ERR_SF_MATCH_FAIL;
587 }
588
589 nClsidIndex =
590 GetClassifierEntry(pstServiceFlowEntry->pstClassifierTable,
591 uiClsId,
592 eActiveClassifierRuleContext,
593 &pstClassifierEntry);
594
595 if ((nClsidIndex != PHS_INVALID_TABLE_INDEX) &&
596 (!pstClassifierEntry->bUnclassifiedPHSRule)) {
597 if (pstClassifierEntry->pstPhsRule) {
598 if (pstClassifierEntry->pstPhsRule->u8RefCnt)
599 pstClassifierEntry->pstPhsRule->u8RefCnt--;
600
601 if (0 == pstClassifierEntry->pstPhsRule->u8RefCnt)
602 kfree(pstClassifierEntry->pstPhsRule);
603 }
604 memset(pstClassifierEntry, 0,
605 sizeof(struct bcm_phs_classifier_entry));
606 }
607
608 nClsidIndex =
609 GetClassifierEntry(pstServiceFlowEntry->pstClassifierTable,
610 uiClsId,
611 eOldClassifierRuleContext,
612 &pstClassifierEntry);
613
614 if ((nClsidIndex != PHS_INVALID_TABLE_INDEX) &&
615 (!pstClassifierEntry->bUnclassifiedPHSRule)) {
616 kfree(pstClassifierEntry->pstPhsRule);
617 memset(pstClassifierEntry, 0,
618 sizeof(struct bcm_phs_classifier_entry));
619 }
620
621out:
622 return 0;
623}
624
625/*
626 * PhsDeleteSFRules
627 *
628 * Routine Description:
629 * Exported function to Delete a all PHS Rules for the SFID.
630 *
631 * Arguments:
632 * IN void* pvContext - PHS Driver Specific Context
633 * IN B_UINT16 uiVcid - The Service Flow ID for which the PHS rules need to be deleted
634 *
635 * Return Value:
636 *
637 * 0 if successful,
638 * >0 Error.
639 */
640ULONG PhsDeleteSFRules(IN void *pvContext, IN B_UINT16 uiVcid)
641{
642 UINT nSFIndex = 0, nClsidIndex = 0;
643 struct bcm_phs_entry *pstServiceFlowEntry = NULL;
644 struct bcm_phs_classifier_table *pstClassifierRulesTable = NULL;
645 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
646 struct bcm_phs_extension *pDeviceExtension =
647 (struct bcm_phs_extension *)pvContext;
648 struct bcm_phs_classifier_entry *curr_clsf_entry;
649 struct bcm_phs_classifier_entry *curr_rules_list;
650
651 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL,
652 "====>\n");
653
654 if (!pDeviceExtension)
655 goto out;
656
657 /* Retrieve the SFID Entry Index for requested Service Flow */
658 nSFIndex = GetServiceFlowEntry(pDeviceExtension->pstServiceFlowPhsRulesTable,
659 uiVcid, &pstServiceFlowEntry);
660 if (nSFIndex == PHS_INVALID_TABLE_INDEX) {
661 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH,
662 DBG_LVL_ALL, "SFID Match Failed\n");
663 return ERR_SF_MATCH_FAIL;
664 }
665
666 pstClassifierRulesTable = pstServiceFlowEntry->pstClassifierTable;
667 if (pstClassifierRulesTable) {
668 for (nClsidIndex = 0; nClsidIndex < MAX_PHSRULE_PER_SF; nClsidIndex++) {
669 curr_clsf_entry =
670 &pstClassifierRulesTable->stActivePhsRulesList[nClsidIndex];
671
672 curr_rules_list =
673 &pstClassifierRulesTable->stOldPhsRulesList[nClsidIndex];
674
675 if (curr_clsf_entry->pstPhsRule) {
676
677 if (curr_clsf_entry->pstPhsRule->u8RefCnt)
678 curr_clsf_entry->pstPhsRule->u8RefCnt--;
679
680 if (0 == curr_clsf_entry->pstPhsRule->u8RefCnt)
681 kfree(curr_clsf_entry->pstPhsRule);
682
683 curr_clsf_entry->pstPhsRule = NULL;
684 }
685 memset(curr_clsf_entry, 0,
686 sizeof(struct bcm_phs_classifier_entry));
687 if (curr_rules_list->pstPhsRule) {
688
689 if (curr_rules_list->pstPhsRule->u8RefCnt)
690 curr_rules_list->pstPhsRule->u8RefCnt--;
691
692 if (0 == curr_rules_list->pstPhsRule->u8RefCnt)
693 kfree(curr_rules_list->pstPhsRule);
694
695 curr_rules_list->pstPhsRule = NULL;
696 }
697 memset(curr_rules_list, 0,
698 sizeof(struct bcm_phs_classifier_entry));
699 }
700 }
701 pstServiceFlowEntry->bUsed = false;
702 pstServiceFlowEntry->uiVcid = 0;
703
704out:
705 return 0;
706}
707
708/*
709 * PhsCompress
710 *
711 * Routine Description:
712 * Exported function to compress the data using PHS.
713 *
714 * Arguments:
715 * IN void* pvContext - PHS Driver Specific Context.
716 * IN B_UINT16 uiVcid - The Service Flow ID to which current
717 * packet header compression applies.
718 * IN UINT uiClsId - The Classifier ID to which current packet
719 * header compression applies.
720 * IN void *pvInputBuffer - The Input buffer containg packet header
721 * data
722 * IN void *pvOutputBuffer - The output buffer returned by this
723 * function after PHS
724 * IN UINT *pOldHeaderSize - The actual size of the header before PHS
725 * IN UINT *pNewHeaderSize - The new size of the header after applying
726 * PHS
727 *
728 * Return Value:
729 *
730 * 0 if successful,
731 * >0 Error.
732 */
733static ULONG PhsCompress(IN void *pvContext,
734 IN B_UINT16 uiVcid,
735 IN B_UINT16 uiClsId,
736 IN void *pvInputBuffer,
737 OUT void *pvOutputBuffer,
738 OUT UINT *pOldHeaderSize,
739 OUT UINT *pNewHeaderSize)
740{
741 UINT nSFIndex = 0, nClsidIndex = 0;
742 struct bcm_phs_entry *pstServiceFlowEntry = NULL;
743 struct bcm_phs_classifier_entry *pstClassifierEntry = NULL;
744 struct bcm_phs_rule *pstPhsRule = NULL;
745 ULONG lStatus = 0;
746 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
747 struct bcm_phs_extension *pDeviceExtension =
748 (struct bcm_phs_extension *)pvContext;
749
750 if (pDeviceExtension == NULL) {
751 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,
752 "Invalid Device Extension\n");
753 lStatus = STATUS_PHS_NOCOMPRESSION;
754 return lStatus;
755 }
756
757 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,
758 "Suppressing header\n");
759
760 /* Retrieve the SFID Entry Index for requested Service Flow */
761 nSFIndex = GetServiceFlowEntry(pDeviceExtension->pstServiceFlowPhsRulesTable,
762 uiVcid, &pstServiceFlowEntry);
763 if (nSFIndex == PHS_INVALID_TABLE_INDEX) {
764 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,
765 "SFID Match Failed\n");
766 lStatus = STATUS_PHS_NOCOMPRESSION;
767 return lStatus;
768 }
769
770 nClsidIndex = GetClassifierEntry(pstServiceFlowEntry->pstClassifierTable,
771 uiClsId, eActiveClassifierRuleContext,
772 &pstClassifierEntry);
773
774 if (nClsidIndex == PHS_INVALID_TABLE_INDEX) {
775 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,
776 "No PHS Rule Defined For Classifier\n");
777 lStatus = STATUS_PHS_NOCOMPRESSION;
778 return lStatus;
779 }
780
781 /* get rule from SF id,Cls ID pair and proceed */
782 pstPhsRule = pstClassifierEntry->pstPhsRule;
783 if (!ValidatePHSRuleComplete(pstPhsRule)) {
784 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL,
785 "PHS Rule Defined For Classifier But Not Complete\n");
786 lStatus = STATUS_PHS_NOCOMPRESSION;
787 return lStatus;
788 }
789
790 /* Compress Packet */
791 lStatus = phs_compress(pstPhsRule,
792 (PUCHAR)pvInputBuffer,
793 (PUCHAR)pvOutputBuffer,
794 pOldHeaderSize,
795 pNewHeaderSize);
796
797 if (lStatus == STATUS_PHS_COMPRESSED) {
798 pstPhsRule->PHSModifiedBytes +=
799 *pOldHeaderSize - *pNewHeaderSize - 1;
800 pstPhsRule->PHSModifiedNumPackets++;
801 } else {
802 pstPhsRule->PHSErrorNumPackets++;
803 }
804
805 return lStatus;
806}
807
808/*
809 * PhsDeCompress
810 *
811 * Routine Description:
812 * Exported function to restore the packet header in Rx path.
813 *
814 * Arguments:
815 * IN void* pvContext - PHS Driver Specific Context.
816 * IN B_UINT16 uiVcid - The Service Flow ID to which current
817 * packet header restoration applies.
818 * IN void *pvInputBuffer - The Input buffer containg suppressed
819 * packet header data
820 * OUT void *pvOutputBuffer - The output buffer returned by this
821 * function after restoration
822 * OUT UINT *pHeaderSize - The packet header size after restoration
823 * is returned in this parameter.
824 *
825 * Return Value:
826 *
827 * 0 if successful,
828 * >0 Error.
829 */
830static ULONG PhsDeCompress(IN void *pvContext,
831 IN B_UINT16 uiVcid,
832 IN void *pvInputBuffer,
833 OUT void *pvOutputBuffer,
834 OUT UINT *pInHeaderSize,
835 OUT UINT *pOutHeaderSize)
836{
837 UINT nSFIndex = 0, nPhsRuleIndex = 0;
838 struct bcm_phs_entry *pstServiceFlowEntry = NULL;
839 struct bcm_phs_rule *pstPhsRule = NULL;
840 UINT phsi;
841 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
842 struct bcm_phs_extension *pDeviceExtension =
843 (struct bcm_phs_extension *)pvContext;
844
845 *pInHeaderSize = 0;
846 if (pDeviceExtension == NULL) {
847 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE,
848 DBG_LVL_ALL, "Invalid Device Extension\n");
849 return ERR_PHS_INVALID_DEVICE_EXETENSION;
850 }
851
852 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL,
853 "Restoring header\n");
854
855 phsi = *((unsigned char *)(pvInputBuffer));
856 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL,
857 "PHSI To Be Used For restore : %x\n", phsi);
858 if (phsi == UNCOMPRESSED_PACKET)
859 return STATUS_PHS_NOCOMPRESSION;
860
861 /* Retrieve the SFID Entry Index for requested Service Flow */
862 nSFIndex = GetServiceFlowEntry(pDeviceExtension->pstServiceFlowPhsRulesTable,
863 uiVcid, &pstServiceFlowEntry);
864 if (nSFIndex == PHS_INVALID_TABLE_INDEX) {
865 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE,
866 DBG_LVL_ALL,
867 "SFID Match Failed During Lookup\n");
868 return ERR_SF_MATCH_FAIL;
869 }
870
871 nPhsRuleIndex = GetPhsRuleEntry(pstServiceFlowEntry->pstClassifierTable,
872 phsi,
873 eActiveClassifierRuleContext,
874 &pstPhsRule);
875 if (nPhsRuleIndex == PHS_INVALID_TABLE_INDEX) {
876 /* Phs Rule does not exist in active rules table. Lets try
877 * in the old rules table. */
878 nPhsRuleIndex = GetPhsRuleEntry(pstServiceFlowEntry->pstClassifierTable,
879 phsi,
880 eOldClassifierRuleContext,
881 &pstPhsRule);
882 if (nPhsRuleIndex == PHS_INVALID_TABLE_INDEX)
883 return ERR_PHSRULE_MATCH_FAIL;
884 }
885
886 *pInHeaderSize = phs_decompress((PUCHAR)pvInputBuffer,
887 (PUCHAR)pvOutputBuffer,
888 pstPhsRule,
889 pOutHeaderSize);
890
891 pstPhsRule->PHSModifiedBytes += *pOutHeaderSize - *pInHeaderSize - 1;
892
893 pstPhsRule->PHSModifiedNumPackets++;
894 return STATUS_PHS_COMPRESSED;
895}
896
897/*
898 * Procedure: free_phs_serviceflow_rules
899 *
900 * Description: This routine is responsible for freeing memory allocated for
901 * PHS rules.
902 *
903 * Arguments:
904 * rules - ptr to S_SERVICEFLOW_TABLE structure.
905 *
906 * Returns:
907 * Does not return any value.
908 */
909static void free_phs_serviceflow_rules(struct bcm_phs_table *psServiceFlowRulesTable)
910{
911 int i, j;
912 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
913 struct bcm_phs_classifier_entry *curr_act_rules_list;
914 struct bcm_phs_classifier_entry *curr_old_rules_list;
915
916 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL,
917 "=======>\n");
918
919 if (!psServiceFlowRulesTable)
920 goto out;
921
922 for (i = 0; i < MAX_SERVICEFLOWS; i++) {
923 struct bcm_phs_entry stServiceFlowEntry =
924 psServiceFlowRulesTable->stSFList[i];
925 struct bcm_phs_classifier_table *pstClassifierRulesTable =
926 stServiceFlowEntry.pstClassifierTable;
927
928 if (pstClassifierRulesTable) {
929 for (j = 0; j < MAX_PHSRULE_PER_SF; j++) {
930 curr_act_rules_list =
931 &pstClassifierRulesTable->stActivePhsRulesList[j];
932
933 curr_old_rules_list =
934 &pstClassifierRulesTable->stOldPhsRulesList[j];
935
936 if (curr_act_rules_list->pstPhsRule) {
937
938 if (curr_act_rules_list->pstPhsRule->u8RefCnt)
939 curr_act_rules_list->pstPhsRule->u8RefCnt--;
940
941 if (0 == curr_act_rules_list->pstPhsRule->u8RefCnt)
942 kfree(curr_act_rules_list->pstPhsRule);
943
944 curr_act_rules_list->pstPhsRule = NULL;
945 }
946
947 if (curr_old_rules_list->pstPhsRule) {
948
949 if (curr_old_rules_list->pstPhsRule->u8RefCnt)
950 curr_old_rules_list->pstPhsRule->u8RefCnt--;
951
952 if (0 == curr_old_rules_list->pstPhsRule->u8RefCnt)
953 kfree(curr_old_rules_list->pstPhsRule);
954
955 curr_old_rules_list->pstPhsRule = NULL;
956 }
957 }
958 kfree(pstClassifierRulesTable);
959 stServiceFlowEntry.pstClassifierTable =
960 pstClassifierRulesTable = NULL;
961 }
962 }
963
964out:
965
966 kfree(psServiceFlowRulesTable);
967 psServiceFlowRulesTable = NULL;
968}
969
970static bool ValidatePHSRuleComplete(IN const struct bcm_phs_rule *psPhsRule)
971{
972 return (psPhsRule &&
973 psPhsRule->u8PHSI &&
974 psPhsRule->u8PHSS &&
975 psPhsRule->u8PHSFLength);
976}
977
978UINT GetServiceFlowEntry(IN struct bcm_phs_table *psServiceFlowTable,
979 IN B_UINT16 uiVcid,
980 struct bcm_phs_entry **ppstServiceFlowEntry)
981{
982 int i;
983 struct bcm_phs_entry *curr_sf_list;
984
985 for (i = 0; i < MAX_SERVICEFLOWS; i++) {
986 curr_sf_list = &psServiceFlowTable->stSFList[i];
987 if (curr_sf_list->bUsed && (curr_sf_list->uiVcid == uiVcid)) {
988 *ppstServiceFlowEntry = curr_sf_list;
989 return i;
990 }
991 }
992
993 *ppstServiceFlowEntry = NULL;
994 return PHS_INVALID_TABLE_INDEX;
995}
996
997static UINT GetClassifierEntry(IN struct bcm_phs_classifier_table *pstClassifierTable,
998 IN B_UINT32 uiClsid,
999 enum bcm_phs_classifier_context eClsContext,
1000 OUT struct bcm_phs_classifier_entry **ppstClassifierEntry)
1001{
1002 int i;
1003 struct bcm_phs_classifier_entry *psClassifierRules = NULL;
1004
1005 for (i = 0; i < MAX_PHSRULE_PER_SF; i++) {
1006
1007 if (eClsContext == eActiveClassifierRuleContext)
1008 psClassifierRules =
1009 &pstClassifierTable->stActivePhsRulesList[i];
1010 else
1011 psClassifierRules =
1012 &pstClassifierTable->stOldPhsRulesList[i];
1013
1014 if (psClassifierRules->bUsed &&
1015 (psClassifierRules->uiClassifierRuleId == uiClsid)) {
1016 *ppstClassifierEntry = psClassifierRules;
1017 return i;
1018 }
1019 }
1020
1021 *ppstClassifierEntry = NULL;
1022 return PHS_INVALID_TABLE_INDEX;
1023}
1024
1025static UINT GetPhsRuleEntry(IN struct bcm_phs_classifier_table *pstClassifierTable,
1026 IN B_UINT32 uiPHSI,
1027 enum bcm_phs_classifier_context eClsContext,
1028 OUT struct bcm_phs_rule **ppstPhsRule)
1029{
1030 int i;
1031 struct bcm_phs_classifier_entry *pstClassifierRule = NULL;
1032
1033 for (i = 0; i < MAX_PHSRULE_PER_SF; i++) {
1034 if (eClsContext == eActiveClassifierRuleContext)
1035 pstClassifierRule =
1036 &pstClassifierTable->stActivePhsRulesList[i];
1037 else
1038 pstClassifierRule =
1039 &pstClassifierTable->stOldPhsRulesList[i];
1040
1041 if (pstClassifierRule->bUsed &&
1042 (pstClassifierRule->u8PHSI == uiPHSI)) {
1043 *ppstPhsRule = pstClassifierRule->pstPhsRule;
1044 return i;
1045 }
1046 }
1047
1048 *ppstPhsRule = NULL;
1049 return PHS_INVALID_TABLE_INDEX;
1050}
1051
1052static UINT CreateSFToClassifierRuleMapping(IN B_UINT16 uiVcid,
1053 IN B_UINT16 uiClsId,
1054 IN struct bcm_phs_table *psServiceFlowTable,
1055 struct bcm_phs_rule *psPhsRule,
1056 B_UINT8 u8AssociatedPHSI)
1057{
1058 struct bcm_phs_classifier_table *psaClassifiertable = NULL;
1059 UINT uiStatus = 0;
1060 int iSfIndex;
1061 bool bFreeEntryFound = false;
1062 struct bcm_phs_entry *curr_list;
1063
1064 /* Check for a free entry in SFID table */
1065 for (iSfIndex = 0; iSfIndex < MAX_SERVICEFLOWS; iSfIndex++) {
1066 curr_list = &psServiceFlowTable->stSFList[iSfIndex];
1067 if (!curr_list->bUsed) {
1068 bFreeEntryFound = TRUE;
1069 break;
1070 }
1071 }
1072
1073 if (!bFreeEntryFound)
1074 return ERR_SFTABLE_FULL;
1075
1076 psaClassifiertable = curr_list->pstClassifierTable;
1077 uiStatus = CreateClassifierPHSRule(uiClsId,
1078 psaClassifiertable,
1079 psPhsRule,
1080 eActiveClassifierRuleContext,
1081 u8AssociatedPHSI);
1082 if (uiStatus == PHS_SUCCESS) {
1083 /* Add entry at free index to the SF */
1084 curr_list->bUsed = TRUE;
1085 curr_list->uiVcid = uiVcid;
1086 }
1087
1088 return uiStatus;
1089}
1090
1091static UINT CreateClassiferToPHSRuleMapping(IN B_UINT16 uiVcid,
1092 IN B_UINT16 uiClsId,
1093 IN struct bcm_phs_entry *pstServiceFlowEntry,
1094 struct bcm_phs_rule *psPhsRule,
1095 B_UINT8 u8AssociatedPHSI)
1096{
1097 struct bcm_phs_classifier_entry *pstClassifierEntry = NULL;
1098 UINT uiStatus = PHS_SUCCESS;
1099 UINT nClassifierIndex = 0;
1100 struct bcm_phs_classifier_table *psaClassifiertable = NULL;
1101 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
1102
1103 psaClassifiertable = pstServiceFlowEntry->pstClassifierTable;
1104
1105 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL,
1106 "==>");
1107
1108 /* Check if the supplied Classifier already exists */
1109 nClassifierIndex = GetClassifierEntry(
1110 pstServiceFlowEntry->pstClassifierTable,
1111 uiClsId,
1112 eActiveClassifierRuleContext,
1113 &pstClassifierEntry);
1114
1115 if (nClassifierIndex == PHS_INVALID_TABLE_INDEX) {
1116 /*
1117 * The Classifier doesn't exist. So its a new classifier being
1118 * added.
1119 * Add new entry to associate PHS Rule to the Classifier
1120 */
1121
1122 uiStatus = CreateClassifierPHSRule(uiClsId, psaClassifiertable,
1123 psPhsRule,
1124 eActiveClassifierRuleContext,
1125 u8AssociatedPHSI);
1126 return uiStatus;
1127 }
1128
1129 /*
1130 * The Classifier exists.The PHS Rule for this classifier
1131 * is being modified
1132 */
1133
1134 if (pstClassifierEntry->u8PHSI == psPhsRule->u8PHSI) {
1135 if (pstClassifierEntry->pstPhsRule == NULL)
1136 return ERR_PHS_INVALID_PHS_RULE;
1137
1138 /*
1139 * This rule already exists if any fields are changed for this
1140 * PHS rule update them.
1141 */
1142 /* If any part of PHSF is valid then we update PHSF */
1143 if (psPhsRule->u8PHSFLength) {
1144 /* update PHSF */
1145 memcpy(pstClassifierEntry->pstPhsRule->u8PHSF,
1146 psPhsRule->u8PHSF,
1147 MAX_PHS_LENGTHS);
1148 }
1149
1150 if (psPhsRule->u8PHSFLength) {
1151 /* update PHSFLen */
1152 pstClassifierEntry->pstPhsRule->u8PHSFLength =
1153 psPhsRule->u8PHSFLength;
1154 }
1155
1156 if (psPhsRule->u8PHSMLength) {
1157 /* update PHSM */
1158 memcpy(pstClassifierEntry->pstPhsRule->u8PHSM,
1159 psPhsRule->u8PHSM,
1160 MAX_PHS_LENGTHS);
1161 }
1162
1163 if (psPhsRule->u8PHSMLength) {
1164 /* update PHSM Len */
1165 pstClassifierEntry->pstPhsRule->u8PHSMLength =
1166 psPhsRule->u8PHSMLength;
1167 }
1168
1169 if (psPhsRule->u8PHSS) {
1170 /* update PHSS */
1171 pstClassifierEntry->pstPhsRule->u8PHSS =
1172 psPhsRule->u8PHSS;
1173 }
1174
1175 /* update PHSV */
1176 pstClassifierEntry->pstPhsRule->u8PHSV = psPhsRule->u8PHSV;
1177 } else {
1178 /* A new rule is being set for this classifier. */
1179 uiStatus = UpdateClassifierPHSRule(uiClsId,
1180 pstClassifierEntry,
1181 psaClassifiertable,
1182 psPhsRule,
1183 u8AssociatedPHSI);
1184 }
1185
1186 return uiStatus;
1187}
1188
1189static UINT CreateClassifierPHSRule(IN B_UINT16 uiClsId,
1190 struct bcm_phs_classifier_table *psaClassifiertable,
1191 struct bcm_phs_rule *psPhsRule,
1192 enum bcm_phs_classifier_context eClsContext,
1193 B_UINT8 u8AssociatedPHSI)
1194{
1195 UINT iClassifierIndex = 0;
1196 bool bFreeEntryFound = false;
1197 struct bcm_phs_classifier_entry *psClassifierRules = NULL;
1198 UINT nStatus = PHS_SUCCESS;
1199 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
1200
1201 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH, DBG_LVL_ALL,
1202 "Inside CreateClassifierPHSRule");
1203
1204 if (psaClassifiertable == NULL)
1205 return ERR_INVALID_CLASSIFIERTABLE_FOR_SF;
1206
1207 if (eClsContext == eOldClassifierRuleContext) {
1208 /*
1209 * If An Old Entry for this classifier ID already exists in the
1210 * old rules table replace it.
1211 */
1212
1213 iClassifierIndex = GetClassifierEntry(psaClassifiertable,
1214 uiClsId,
1215 eClsContext,
1216 &psClassifierRules);
1217
1218 if (iClassifierIndex != PHS_INVALID_TABLE_INDEX) {
1219 /*
1220 * The Classifier already exists in the old rules table
1221 * Lets replace the old classifier with the new one.
1222 */
1223 bFreeEntryFound = TRUE;
1224 }
1225 }
1226
1227 if (!bFreeEntryFound) {
1228 /* Continue to search for a free location to add the rule */
1229 for (iClassifierIndex = 0; iClassifierIndex <
1230 MAX_PHSRULE_PER_SF; iClassifierIndex++) {
1231 if (eClsContext == eActiveClassifierRuleContext)
1232 psClassifierRules = &psaClassifiertable->stActivePhsRulesList[iClassifierIndex];
1233 else
1234 psClassifierRules = &psaClassifiertable->stOldPhsRulesList[iClassifierIndex];
1235
1236 if (!psClassifierRules->bUsed) {
1237 bFreeEntryFound = TRUE;
1238 break;
1239 }
1240 }
1241 }
1242
1243 if (!bFreeEntryFound) {
1244
1245 if (eClsContext == eActiveClassifierRuleContext)
1246 return ERR_CLSASSIFIER_TABLE_FULL;
1247 else {
1248 /* Lets replace the oldest rule if we are looking in
1249 * old Rule table */
1250 if (psaClassifiertable->uiOldestPhsRuleIndex >= MAX_PHSRULE_PER_SF)
1251 psaClassifiertable->uiOldestPhsRuleIndex = 0;
1252
1253 iClassifierIndex =
1254 psaClassifiertable->uiOldestPhsRuleIndex;
1255 psClassifierRules =
1256 &psaClassifiertable->stOldPhsRulesList[iClassifierIndex];
1257
1258 (psaClassifiertable->uiOldestPhsRuleIndex)++;
1259 }
1260 }
1261
1262 if (eClsContext == eOldClassifierRuleContext) {
1263
1264 if (psClassifierRules->pstPhsRule == NULL) {
1265
1266 psClassifierRules->pstPhsRule =
1267 kmalloc(sizeof(struct bcm_phs_rule),
1268 GFP_KERNEL);
1269
1270 if (NULL == psClassifierRules->pstPhsRule)
1271 return ERR_PHSRULE_MEMALLOC_FAIL;
1272 }
1273
1274 psClassifierRules->bUsed = TRUE;
1275 psClassifierRules->uiClassifierRuleId = uiClsId;
1276 psClassifierRules->u8PHSI = psPhsRule->u8PHSI;
1277 psClassifierRules->bUnclassifiedPHSRule =
1278 psPhsRule->bUnclassifiedPHSRule;
1279
1280 /* Update The PHS rule */
1281 memcpy(psClassifierRules->pstPhsRule, psPhsRule,
1282 sizeof(struct bcm_phs_rule));
1283 } else
1284 nStatus = UpdateClassifierPHSRule(uiClsId,
1285 psClassifierRules,
1286 psaClassifiertable,
1287 psPhsRule,
1288 u8AssociatedPHSI);
1289
1290 return nStatus;
1291}
1292
1293static UINT UpdateClassifierPHSRule(IN B_UINT16 uiClsId,
1294 IN struct bcm_phs_classifier_entry *pstClassifierEntry,
1295 struct bcm_phs_classifier_table *psaClassifiertable,
1296 struct bcm_phs_rule *psPhsRule,
1297 B_UINT8 u8AssociatedPHSI)
1298{
1299 struct bcm_phs_rule *pstAddPhsRule = NULL;
1300 UINT nPhsRuleIndex = 0;
1301 bool bPHSRuleOrphaned = false;
1302 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
1303
1304 psPhsRule->u8RefCnt = 0;
1305
1306 /* Step 1 Deref Any Exisiting PHS Rule in this classifier Entry */
1307 bPHSRuleOrphaned = DerefPhsRule(uiClsId, psaClassifiertable,
1308 pstClassifierEntry->pstPhsRule);
1309
1310 /* Step 2 Search if there is a PHS Rule with u8AssociatedPHSI in
1311 * Classifier table for this SF */
1312 nPhsRuleIndex = GetPhsRuleEntry(psaClassifiertable, u8AssociatedPHSI,
1313 eActiveClassifierRuleContext,
1314 &pstAddPhsRule);
1315 if (PHS_INVALID_TABLE_INDEX == nPhsRuleIndex) {
1316
1317 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH,
1318 DBG_LVL_ALL,
1319 "\nAdding New PHSRuleEntry For Classifier");
1320
1321 if (psPhsRule->u8PHSI == 0) {
1322 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH,
1323 DBG_LVL_ALL, "\nError PHSI is Zero\n");
1324 return ERR_PHS_INVALID_PHS_RULE;
1325 }
1326
1327 /* Step 2.a PHS Rule Does Not Exist .Create New PHS Rule for
1328 * uiClsId */
1329 if (false == bPHSRuleOrphaned) {
1330
1331 pstClassifierEntry->pstPhsRule =
1332 kmalloc(sizeof(struct bcm_phs_rule),
1333 GFP_KERNEL);
1334 if (NULL == pstClassifierEntry->pstPhsRule)
1335 return ERR_PHSRULE_MEMALLOC_FAIL;
1336 }
1337 memcpy(pstClassifierEntry->pstPhsRule, psPhsRule,
1338 sizeof(struct bcm_phs_rule));
1339 } else {
1340 /* Step 2.b PHS Rule Exists Tie uiClsId with the existing
1341 * PHS Rule */
1342 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_DISPATCH,
1343 DBG_LVL_ALL,
1344 "\nTying Classifier to Existing PHS Rule");
1345 if (bPHSRuleOrphaned) {
1346 kfree(pstClassifierEntry->pstPhsRule);
1347 pstClassifierEntry->pstPhsRule = NULL;
1348 }
1349 pstClassifierEntry->pstPhsRule = pstAddPhsRule;
1350 }
1351
1352 pstClassifierEntry->bUsed = TRUE;
1353 pstClassifierEntry->u8PHSI = pstClassifierEntry->pstPhsRule->u8PHSI;
1354 pstClassifierEntry->uiClassifierRuleId = uiClsId;
1355 pstClassifierEntry->pstPhsRule->u8RefCnt++;
1356 pstClassifierEntry->bUnclassifiedPHSRule =
1357 pstClassifierEntry->pstPhsRule->bUnclassifiedPHSRule;
1358
1359 return PHS_SUCCESS;
1360}
1361
1362static bool DerefPhsRule(IN B_UINT16 uiClsId,
1363 struct bcm_phs_classifier_table *psaClassifiertable,
1364 struct bcm_phs_rule *pstPhsRule)
1365{
1366 if (pstPhsRule == NULL)
1367 return false;
1368
1369 if (pstPhsRule->u8RefCnt)
1370 pstPhsRule->u8RefCnt--;
1371
1372 return (0 == pstPhsRule->u8RefCnt);
1373}
1374
1375static void dbg_print_st_cls_entry(struct bcm_mini_adapter *ad,
1376 struct bcm_phs_entry *st_serv_flow_entry,
1377 struct bcm_phs_classifier_entry *st_cls_entry)
1378{
1379 int k;
1380
1381 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\n VCID : %#X", st_serv_flow_entry->uiVcid);
1382 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n ClassifierID : %#X", st_cls_entry->uiClassifierRuleId);
1383 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSRuleID : %#X", st_cls_entry->u8PHSI);
1384 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n****************PHS Rule********************\n");
1385 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSI : %#X", st_cls_entry->pstPhsRule->u8PHSI);
1386 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSFLength : %#X ", st_cls_entry->pstPhsRule->u8PHSFLength);
1387 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSF : ");
1388
1389 for (k = 0 ; k < st_cls_entry->pstPhsRule->u8PHSFLength; k++)
1390 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "%#X ", st_cls_entry->pstPhsRule->u8PHSF[k]);
1391 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSMLength : %#X", st_cls_entry->pstPhsRule->u8PHSMLength);
1392 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSM :");
1393
1394 for (k = 0; k < st_cls_entry->pstPhsRule->u8PHSMLength; k++)
1395 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "%#X ", st_cls_entry->pstPhsRule->u8PHSM[k]);
1396 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSS : %#X ", st_cls_entry->pstPhsRule->u8PHSS);
1397 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, DUMP_INFO, (DBG_LVL_ALL|DBG_NO_FUNC_PRINT), "\n PHSV : %#X", st_cls_entry->pstPhsRule->u8PHSV);
1398 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL, "\n********************************************\n");
1399}
1400
1401static void phsrules_per_sf_dbg_print(struct bcm_mini_adapter *ad,
1402 struct bcm_phs_entry *st_serv_flow_entry)
1403{
1404 int j, l;
1405 struct bcm_phs_classifier_entry st_cls_entry;
1406
1407 for (j = 0; j < MAX_PHSRULE_PER_SF; j++) {
1408
1409 for (l = 0; l < 2; l++) {
1410
1411 if (l == 0) {
1412 st_cls_entry = st_serv_flow_entry->pstClassifierTable->stActivePhsRulesList[j];
1413 if (st_cls_entry.bUsed)
1414 BCM_DEBUG_PRINT(ad,
1415 DBG_TYPE_OTHERS,
1416 DUMP_INFO,
1417 (DBG_LVL_ALL | DBG_NO_FUNC_PRINT),
1418 "\n Active PHS Rule :\n");
1419 } else {
1420 st_cls_entry = st_serv_flow_entry->pstClassifierTable->stOldPhsRulesList[j];
1421 if (st_cls_entry.bUsed)
1422 BCM_DEBUG_PRINT(ad,
1423 DBG_TYPE_OTHERS,
1424 DUMP_INFO,
1425 (DBG_LVL_ALL | DBG_NO_FUNC_PRINT),
1426 "\n Old PHS Rule :\n");
1427 }
1428
1429 if (st_cls_entry.bUsed) {
1430 dbg_print_st_cls_entry(ad,
1431 st_serv_flow_entry,
1432 &st_cls_entry);
1433 }
1434 }
1435 }
1436}
1437
1438void DumpPhsRules(struct bcm_phs_extension *pDeviceExtension)
1439{
1440 int i;
1441 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
1442
1443 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, DUMP_INFO, DBG_LVL_ALL,
1444 "\n Dumping PHS Rules :\n");
1445
1446 for (i = 0; i < MAX_SERVICEFLOWS; i++) {
1447
1448 struct bcm_phs_entry stServFlowEntry =
1449 pDeviceExtension->pstServiceFlowPhsRulesTable->stSFList[i];
1450
1451 if (!stServFlowEntry.bUsed)
1452 continue;
1453
1454 phsrules_per_sf_dbg_print(Adapter, &stServFlowEntry);
1455 }
1456}
1457
1458/*
1459 * Procedure: phs_decompress
1460 *
1461 * Description: This routine restores the static fields within the packet.
1462 *
1463 * Arguments:
1464 * in_buf - ptr to incoming packet buffer.
1465 * out_buf - ptr to output buffer where the suppressed
1466 * header is copied.
1467 * decomp_phs_rules - ptr to PHS rule.
1468 * header_size - ptr to field which holds the phss or
1469 * phsf_length.
1470 *
1471 * Returns:
1472 * size - The number of bytes of dynamic fields present with in the
1473 * incoming packet header.
1474 * 0 - If PHS rule is NULL.If PHSI is 0 indicateing packet as
1475 * uncompressed.
1476 */
1477static int phs_decompress(unsigned char *in_buf,
1478 unsigned char *out_buf,
1479 struct bcm_phs_rule *decomp_phs_rules,
1480 UINT *header_size)
1481{
1482 int phss, size = 0;
1483 struct bcm_phs_rule *tmp_memb;
1484 int bit, i = 0;
1485 unsigned char *phsf, *phsm;
1486 int in_buf_len = *header_size - 1;
1487 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
1488
1489 in_buf++;
1490
1491 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE, DBG_LVL_ALL,
1492 "====>\n");
1493 *header_size = 0;
1494
1495 if (decomp_phs_rules == NULL)
1496 return 0;
1497
1498 tmp_memb = decomp_phs_rules;
1499 /*
1500 * BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_RECEIVE,DBG_LVL_ALL,
1501 * "\nDECOMP:In phs_decompress PHSI 1 %d",phsi));
1502 * header_size = tmp_memb->u8PHSFLength;
1503 */
1504 phss = tmp_memb->u8PHSS;
1505 phsf = tmp_memb->u8PHSF;
1506 phsm = tmp_memb->u8PHSM;
1507
1508 if (phss > MAX_PHS_LENGTHS)
1509 phss = MAX_PHS_LENGTHS;
1510
1511 /*
1512 * BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, PHS_RECEIVE,DBG_LVL_ALL,
1513 * "\nDECOMP:
1514 * In phs_decompress PHSI %d phss %d index %d",phsi,phss,index));
1515 */
1516 while ((phss > 0) && (size < in_buf_len)) {
1517 bit = ((*phsm << i) & SUPPRESS);
1518
1519 if (bit == SUPPRESS) {
1520 *out_buf = *phsf;
1521 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE,
1522 DBG_LVL_ALL,
1523 "\nDECOMP:In phss %d phsf %d output %d",
1524 phss, *phsf, *out_buf);
1525 } else {
1526 *out_buf = *in_buf;
1527 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_RECEIVE,
1528 DBG_LVL_ALL,
1529 "\nDECOMP:In phss %d input %d output %d",
1530 phss, *in_buf, *out_buf);
1531 in_buf++;
1532 size++;
1533 }
1534 out_buf++;
1535 phsf++;
1536 phss--;
1537 i++;
1538 *header_size = *header_size + 1;
1539
1540 if (i > MAX_NO_BIT) {
1541 i = 0;
1542 phsm++;
1543 }
1544 }
1545
1546 return size;
1547}
1548
1549/*
1550 * Procedure: phs_compress
1551 *
1552 * Description: This routine suppresses the static fields within the packet.
1553 * Before that it will verify the fields to be suppressed with the corresponding
1554 * fields in the phsf. For verification it checks the phsv field of PHS rule.
1555 * If set and verification succeeds it suppresses the field.If any one static
1556 * field is found different none of the static fields are suppressed then the
1557 * packet is sent as uncompressed packet with phsi=0.
1558 *
1559 * Arguments:
1560 * phs_rule - ptr to PHS rule.
1561 * in_buf - ptr to incoming packet buffer.
1562 * out_buf - ptr to output buffer where the suppressed header is
1563 * copied.
1564 * header_size - ptr to field which holds the phss.
1565 *
1566 * Returns:
1567 * size - The number of bytes copied into the output buffer i.e
1568 * dynamic fields
1569 * 0 - If PHS rule is NULL.If PHSV field is not set. If the
1570 * verification fails.
1571 */
1572static int phs_compress(struct bcm_phs_rule *phs_rule,
1573 unsigned char *in_buf,
1574 unsigned char *out_buf,
1575 UINT *header_size,
1576 UINT *new_header_size)
1577{
1578 unsigned char *old_addr = out_buf;
1579 int suppress = 0;
1580 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
1581
1582 if (phs_rule == NULL) {
1583 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,
1584 "\nphs_compress(): phs_rule null!");
1585 *out_buf = ZERO_PHSI;
1586 return STATUS_PHS_NOCOMPRESSION;
1587 }
1588
1589 if (phs_rule->u8PHSS <= *new_header_size)
1590 *header_size = phs_rule->u8PHSS;
1591 else
1592 *header_size = *new_header_size;
1593
1594 /* To copy PHSI */
1595 out_buf++;
1596 suppress = verify_suppress_phsf(in_buf, out_buf, phs_rule->u8PHSF,
1597 phs_rule->u8PHSM, phs_rule->u8PHSS,
1598 phs_rule->u8PHSV, new_header_size);
1599
1600 if (suppress == STATUS_PHS_COMPRESSED) {
1601 *old_addr = (unsigned char)phs_rule->u8PHSI;
1602 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,
1603 "\nCOMP:In phs_compress phsi %d",
1604 phs_rule->u8PHSI);
1605 } else {
1606 *old_addr = ZERO_PHSI;
1607 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,
1608 "\nCOMP:In phs_compress PHSV Verification failed");
1609 }
1610
1611 return suppress;
1612}
1613
1614/*
1615 * Procedure: verify_suppress_phsf
1616 *
1617 * Description: This routine verifies the fields of the packet and if all the
1618 * static fields are equal it adds the phsi of that PHS rule.If any static
1619 * field differs it woun't suppress any field.
1620 *
1621 * Arguments:
1622 * rules_set - ptr to classifier_rules.
1623 * in_buffer - ptr to incoming packet buffer.
1624 * out_buffer - ptr to output buffer where the suppressed header is copied.
1625 * phsf - ptr to phsf.
1626 * phsm - ptr to phsm.
1627 * phss - variable holding phss.
1628 *
1629 * Returns:
1630 * size - The number of bytes copied into the output buffer i.e dynamic
1631 * fields.
1632 * 0 - Packet has failed the verification.
1633 */
1634static int verify_suppress_phsf(unsigned char *in_buffer,
1635 unsigned char *out_buffer,
1636 unsigned char *phsf,
1637 unsigned char *phsm,
1638 unsigned int phss,
1639 unsigned int phsv,
1640 UINT *new_header_size)
1641{
1642 unsigned int size = 0;
1643 int bit, i = 0;
1644 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
1645
1646 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,
1647 "\nCOMP:In verify_phsf PHSM - 0x%X", *phsm);
1648
1649 if (phss > (*new_header_size))
1650 phss = *new_header_size;
1651
1652 while (phss > 0) {
1653 bit = ((*phsm << i) & SUPPRESS);
1654 if (bit == SUPPRESS) {
1655 if (*in_buffer != *phsf) {
1656 if (phsv == VERIFY) {
1657 BCM_DEBUG_PRINT(Adapter,
1658 DBG_TYPE_OTHERS,
1659 PHS_SEND,
1660 DBG_LVL_ALL,
1661 "\nCOMP:In verify_phsf failed for field %d buf %d phsf %d",
1662 phss,
1663 *in_buffer,
1664 *phsf);
1665 return STATUS_PHS_NOCOMPRESSION;
1666 }
1667 } else
1668 BCM_DEBUG_PRINT(Adapter,
1669 DBG_TYPE_OTHERS,
1670 PHS_SEND,
1671 DBG_LVL_ALL,
1672 "\nCOMP:In verify_phsf success for field %d buf %d phsf %d",
1673 phss,
1674 *in_buffer,
1675 *phsf);
1676 } else {
1677 *out_buffer = *in_buffer;
1678 BCM_DEBUG_PRINT(Adapter,
1679 DBG_TYPE_OTHERS,
1680 PHS_SEND,
1681 DBG_LVL_ALL,
1682 "\nCOMP:In copying_header input %d out %d",
1683 *in_buffer,
1684 *out_buffer);
1685 out_buffer++;
1686 size++;
1687 }
1688
1689 in_buffer++;
1690 phsf++;
1691 phss--;
1692 i++;
1693
1694 if (i > MAX_NO_BIT) {
1695 i = 0;
1696 phsm++;
1697 }
1698 }
1699 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, PHS_SEND, DBG_LVL_ALL,
1700 "\nCOMP:In verify_phsf success");
1701 *new_header_size = size;
1702 return STATUS_PHS_COMPRESSED;
1703}
diff --git a/drivers/staging/bcm/PHSModule.h b/drivers/staging/bcm/PHSModule.h
deleted file mode 100644
index d84d60ba48f9..000000000000
--- a/drivers/staging/bcm/PHSModule.h
+++ /dev/null
@@ -1,59 +0,0 @@
1#ifndef BCM_MINIPORT_PHSMODULE_H
2#define BCM_MINIPORT_PHSMODULE_H
3
4int PHSTransmit(struct bcm_mini_adapter *Adapter,
5 struct sk_buff **pPacket,
6 USHORT Vcid,
7 B_UINT16 uiClassifierRuleID,
8 bool bHeaderSuppressionEnabled,
9 PUINT PacketLen,
10 UCHAR bEthCSSupport);
11
12int PHSReceive(struct bcm_mini_adapter *Adapter,
13 USHORT usVcid,
14 struct sk_buff *packet,
15 UINT *punPacketLen,
16 UCHAR *pucEthernetHdr,
17 UINT
18 );
19
20
21void DumpDataPacketHeader(PUCHAR pPkt);
22
23void DumpFullPacket(UCHAR *pBuf, UINT nPktLen);
24
25void DumpPhsRules(struct bcm_phs_extension *pDeviceExtension);
26
27
28int phs_init(struct bcm_phs_extension *pPhsdeviceExtension,
29 struct bcm_mini_adapter *Adapter);
30
31int PhsCleanup(struct bcm_phs_extension *pPHSDeviceExt);
32
33/* Utility Functions */
34ULONG PhsUpdateClassifierRule(void *pvContext,
35 B_UINT16 uiVcid,
36 B_UINT16 uiClsId,
37 struct bcm_phs_rule *psPhsRule,
38 B_UINT8 u8AssociatedPHSI);
39
40ULONG PhsDeletePHSRule(void *pvContext, B_UINT16 uiVcid, B_UINT8 u8PHSI);
41
42ULONG PhsDeleteClassifierRule(void *pvContext,
43 B_UINT16 uiVcid,
44 B_UINT16 uiClsId);
45
46ULONG PhsDeleteSFRules(void *pvContext, B_UINT16 uiVcid);
47
48
49bool ValidatePHSRule(struct bcm_phs_rule *psPhsRule);
50
51UINT GetServiceFlowEntry(struct bcm_phs_table *psServiceFlowTable,
52 B_UINT16 uiVcid,
53 struct bcm_phs_entry **ppstServiceFlowEntry);
54
55
56void DumpPhsRules(struct bcm_phs_extension *pDeviceExtension);
57
58
59#endif
diff --git a/drivers/staging/bcm/Protocol.h b/drivers/staging/bcm/Protocol.h
deleted file mode 100644
index 9818128d9320..000000000000
--- a/drivers/staging/bcm/Protocol.h
+++ /dev/null
@@ -1,128 +0,0 @@
1/************************************
2* Protocol.h
3*************************************/
4#ifndef __PROTOCOL_H__
5#define __PROTOCOL_H__
6
7#define IPV4 4
8#define IPV6 6
9
10struct ArpHeader {
11 struct arphdr arp;
12 unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */
13 unsigned char ar_sip[4]; /* sender IP address */
14 unsigned char ar_tha[ETH_ALEN]; /* target hardware address */
15 unsigned char ar_tip[4]; /* target IP address */
16};
17
18struct bcm_transport_header {
19 union {
20 struct udphdr uhdr;
21 struct tcphdr thdr;
22 };
23} __packed;
24
25enum bcm_ip_frame_type {
26 eNonIPPacket,
27 eIPv4Packet,
28 eIPv6Packet
29};
30
31enum bcm_eth_frame_type {
32 eEthUnsupportedFrame,
33 eEth802LLCFrame,
34 eEth802LLCSNAPFrame,
35 eEth802QVLANFrame,
36 eEthOtherFrame
37};
38
39struct bcm_eth_packet_info {
40 enum bcm_ip_frame_type eNwpktIPFrameType;
41 enum bcm_eth_frame_type eNwpktEthFrameType;
42 unsigned short usEtherType;
43 unsigned char ucDSAP;
44};
45
46struct bcm_eth_q_frame {
47 struct bcm_eth_header EThHdr;
48 unsigned short UserPriority:3;
49 unsigned short CFI:1;
50 unsigned short VLANID:12;
51 unsigned short EthType;
52} __packed;
53
54struct bcm_eth_llc_frame {
55 struct bcm_eth_header EThHdr;
56 unsigned char DSAP;
57 unsigned char SSAP;
58 unsigned char Control;
59} __packed;
60
61struct bcm_eth_llc_snap_frame {
62 struct bcm_eth_header EThHdr;
63 unsigned char DSAP;
64 unsigned char SSAP;
65 unsigned char Control;
66 unsigned char OUI[3];
67 unsigned short usEtherType;
68} __packed;
69
70struct bcm_ethernet2_frame {
71 struct bcm_eth_header EThHdr;
72} __packed;
73
74#define ETHERNET_FRAMETYPE_IPV4 ntohs(0x0800)
75#define ETHERNET_FRAMETYPE_IPV6 ntohs(0x86dd)
76#define ETHERNET_FRAMETYPE_802QVLAN ntohs(0x8100)
77
78/* Per SF CS Specification Encodings */
79enum bcm_spec_encoding {
80 eCSSpecUnspecified = 0,
81 eCSPacketIPV4,
82 eCSPacketIPV6,
83 eCS802_3PacketEthernet,
84 eCS802_1QPacketVLAN,
85 eCSPacketIPV4Over802_3Ethernet,
86 eCSPacketIPV6Over802_3Ethernet,
87 eCSPacketIPV4Over802_1QVLAN,
88 eCSPacketIPV6Over802_1QVLAN,
89 eCSPacketUnsupported
90};
91
92#define IP6_HEADER_LEN 40
93#define IP_VERSION(byte) (((byte&0xF0)>>4))
94
95#define MAC_ADDRESS_SIZE 6
96#define ETH_AND_IP_HEADER_LEN (14 + 20)
97#define L4_SRC_PORT_LEN 2
98#define L4_DEST_PORT_LEN 2
99#define CTRL_PKT_LEN (8 + ETH_AND_IP_HEADER_LEN)
100
101#define ETH_ARP_FRAME 0x806
102#define ETH_IPV4_FRAME 0x800
103#define ETH_IPV6_FRAME 0x86DD
104#define UDP 0x11
105#define TCP 0x06
106
107#define ARP_OP_REQUEST 0x01
108#define ARP_OP_REPLY 0x02
109#define ARP_PKT_SIZE 60
110
111/* This is the format for the TCP packet header */
112struct bcm_tcp_header {
113 unsigned short usSrcPort;
114 unsigned short usDestPort;
115 unsigned long ulSeqNumber;
116 unsigned long ulAckNumber;
117 unsigned char HeaderLength;
118 unsigned char ucFlags;
119 unsigned short usWindowsSize;
120 unsigned short usChkSum;
121 unsigned short usUrgetPtr;
122};
123
124#define TCP_HEADER_LEN sizeof(struct bcm_tcp_header)
125#define TCP_ACK 0x10 /* Bit 4 in tcpflags field. */
126#define GET_TCP_HEADER_LEN(byte) ((byte&0xF0)>>4)
127
128#endif /* __PROTOCOL_H__ */
diff --git a/drivers/staging/bcm/Prototypes.h b/drivers/staging/bcm/Prototypes.h
deleted file mode 100644
index 1ddc8b2539f6..000000000000
--- a/drivers/staging/bcm/Prototypes.h
+++ /dev/null
@@ -1,217 +0,0 @@
1#ifndef _PROTOTYPES_H_
2#define _PROTOTYPES_H_
3
4VOID LinkControlResponseMessage(struct bcm_mini_adapter *Adapter, PUCHAR pucBuffer);
5
6VOID StatisticsResponse(struct bcm_mini_adapter *Adapter, PVOID pvBuffer);
7
8VOID IdleModeResponse(struct bcm_mini_adapter *Adapter, PUINT puiBuffer);
9
10int control_packet_handler(struct bcm_mini_adapter *Adapter);
11
12VOID DeleteAllClassifiersForSF(struct bcm_mini_adapter *Adapter, UINT uiSearchRuleIndex);
13
14VOID flush_all_queues(struct bcm_mini_adapter *Adapter);
15
16int register_control_device_interface(struct bcm_mini_adapter *ps_adapter);
17
18void unregister_control_device_interface(struct bcm_mini_adapter *Adapter);
19
20INT CopyBufferToControlPacket(struct bcm_mini_adapter *Adapter,/**<Logical Adapter*/
21 PVOID ioBuffer/**<Control Packet Buffer*/
22 );
23
24VOID SortPackInfo(struct bcm_mini_adapter *Adapter);
25
26VOID SortClassifiers(struct bcm_mini_adapter *Adapter);
27
28VOID flush_all_queues(struct bcm_mini_adapter *Adapter);
29
30VOID PruneQueueAllSF(struct bcm_mini_adapter *Adapter);
31
32INT SearchSfid(struct bcm_mini_adapter *Adapter, UINT uiSfid);
33
34USHORT ClassifyPacket(struct bcm_mini_adapter *Adapter, struct sk_buff *skb);
35
36bool MatchSrcPort(struct bcm_classifier_rule *pstClassifierRule, USHORT ushSrcPort);
37
38bool MatchDestPort(struct bcm_classifier_rule *pstClassifierRule, USHORT ushSrcPort);
39
40bool MatchProtocol(struct bcm_classifier_rule *pstClassifierRule, UCHAR ucProtocol);
41
42INT SetupNextSend(struct bcm_mini_adapter *Adapter, /**<Logical Adapter*/
43 struct sk_buff *Packet, /**<data buffer*/
44 USHORT Vcid);
45
46VOID LinkMessage(struct bcm_mini_adapter *Adapter);
47
48VOID transmit_packets(struct bcm_mini_adapter *Adapter);
49
50INT SendControlPacket(struct bcm_mini_adapter *Adapter, /**<Logical Adapter*/
51 char *pControlPacket/**<Control Packet*/
52 );
53
54int register_networkdev(struct bcm_mini_adapter *Adapter);
55
56void unregister_networkdev(struct bcm_mini_adapter *Adapter);
57
58INT AllocAdapterDsxBuffer(struct bcm_mini_adapter *Adapter);
59
60VOID AdapterFree(struct bcm_mini_adapter *Adapter);
61
62INT FreeAdapterDsxBuffer(struct bcm_mini_adapter *Adapter);
63
64int tx_pkt_handler(struct bcm_mini_adapter *Adapter);
65
66int reset_card_proc(struct bcm_mini_adapter *Adapter);
67
68int run_card_proc(struct bcm_mini_adapter *Adapter);
69
70int InitCardAndDownloadFirmware(struct bcm_mini_adapter *ps_adapter);
71
72INT ReadMacAddressFromNVM(struct bcm_mini_adapter *Adapter);
73
74int register_control_device_interface(struct bcm_mini_adapter *ps_adapter);
75
76void DumpPackInfo(struct bcm_mini_adapter *Adapter);
77
78int rdm(struct bcm_mini_adapter *Adapter, UINT uiAddress, PCHAR pucBuff, size_t size);
79
80int wrm(struct bcm_mini_adapter *Adapter, UINT uiAddress, PCHAR pucBuff, size_t size);
81
82int wrmalt(struct bcm_mini_adapter *Adapter, UINT uiAddress, unsigned int *pucBuff, size_t sSize);
83
84int rdmalt(struct bcm_mini_adapter *Adapter, UINT uiAddress, unsigned int *pucBuff, size_t sSize);
85
86int get_dsx_sf_data_to_application(struct bcm_mini_adapter *Adapter, UINT uiSFId, void __user *user_buffer);
87
88void SendIdleModeResponse(struct bcm_mini_adapter *Adapter);
89
90int ProcessGetHostMibs(struct bcm_mini_adapter *Adapter, struct bcm_host_stats_mibs *buf);
91
92void GetDroppedAppCntrlPktMibs(struct bcm_host_stats_mibs *ioBuffer, struct bcm_tarang_data *pTarang);
93
94void beceem_parse_target_struct(struct bcm_mini_adapter *Adapter);
95
96int bcm_ioctl_fw_download(struct bcm_mini_adapter *Adapter, struct bcm_firmware_info *psFwInfo);
97
98void CopyMIBSExtendedSFParameters(struct bcm_mini_adapter *Adapter,
99 struct bcm_connect_mgr_params *psfLocalSet, UINT uiSearchRuleIndex);
100
101VOID ResetCounters(struct bcm_mini_adapter *Adapter);
102
103int InitLedSettings(struct bcm_mini_adapter *Adapter);
104
105struct bcm_classifier_rule *GetFragIPClsEntry(struct bcm_mini_adapter *Adapter, USHORT usIpIdentification, ULONG SrcIP);
106
107void AddFragIPClsEntry(struct bcm_mini_adapter *Adapter, struct bcm_fragmented_packet_info *psFragPktInfo);
108
109void DelFragIPClsEntry(struct bcm_mini_adapter *Adapter, USHORT usIpIdentification, ULONG SrcIp);
110
111void update_per_cid_rx(struct bcm_mini_adapter *Adapter);
112
113void update_per_sf_desc_cnts(struct bcm_mini_adapter *Adapter);
114
115void ClearTargetDSXBuffer(struct bcm_mini_adapter *Adapter, B_UINT16 TID, bool bFreeAll);
116
117void flush_queue(struct bcm_mini_adapter *Adapter, UINT iQIndex);
118
119INT flushAllAppQ(VOID);
120
121INT BeceemEEPROMBulkRead(
122 struct bcm_mini_adapter *Adapter,
123 PUINT pBuffer,
124 UINT uiOffset,
125 UINT uiNumBytes);
126
127INT WriteBeceemEEPROM(struct bcm_mini_adapter *Adapter, UINT uiEEPROMOffset, UINT uiData);
128
129INT PropagateCalParamsFromFlashToMemory(struct bcm_mini_adapter *Adapter);
130
131INT BeceemEEPROMBulkWrite(
132 struct bcm_mini_adapter *Adapter,
133 PUCHAR pBuffer,
134 UINT uiOffset,
135 UINT uiNumBytes,
136 bool bVerify);
137
138INT ReadBeceemEEPROM(struct bcm_mini_adapter *Adapter, UINT dwAddress, UINT *pdwData);
139
140INT BeceemNVMRead(
141 struct bcm_mini_adapter *Adapter,
142 PUINT pBuffer,
143 UINT uiOffset,
144 UINT uiNumBytes);
145
146INT BeceemNVMWrite(
147 struct bcm_mini_adapter *Adapter,
148 PUINT pBuffer,
149 UINT uiOffset,
150 UINT uiNumBytes,
151 bool bVerify);
152
153INT BcmInitNVM(struct bcm_mini_adapter *Adapter);
154
155INT BcmUpdateSectorSize(struct bcm_mini_adapter *Adapter, UINT uiSectorSize);
156
157bool IsSectionExistInFlash(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val section);
158
159INT BcmGetFlash2xSectionalBitMap(struct bcm_mini_adapter *Adapter, struct bcm_flash2x_bitmap *psFlash2xBitMap);
160
161INT BcmFlash2xBulkWrite(
162 struct bcm_mini_adapter *Adapter,
163 PUINT pBuffer,
164 enum bcm_flash2x_section_val eFlashSectionVal,
165 UINT uiOffset,
166 UINT uiNumBytes,
167 UINT bVerify);
168
169INT BcmFlash2xBulkRead(
170 struct bcm_mini_adapter *Adapter,
171 PUINT pBuffer,
172 enum bcm_flash2x_section_val eFlashSectionVal,
173 UINT uiOffsetWithinSectionVal,
174 UINT uiNumBytes);
175
176INT BcmGetSectionValStartOffset(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val eFlashSectionVal);
177
178INT BcmSetActiveSection(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val eFlash2xSectVal);
179
180INT BcmAllocFlashCSStructure(struct bcm_mini_adapter *psAdapter);
181
182INT BcmDeAllocFlashCSStructure(struct bcm_mini_adapter *psAdapter);
183
184INT BcmCopyISO(struct bcm_mini_adapter *Adapter, struct bcm_flash2x_copy_section sCopySectStrut);
185
186INT BcmFlash2xCorruptSig(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val eFlash2xSectionVal);
187
188INT BcmFlash2xWriteSig(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val eFlashSectionVal);
189
190INT validateFlash2xReadWrite(struct bcm_mini_adapter *Adapter, struct bcm_flash2x_readwrite *psFlash2xReadWrite);
191
192INT IsFlash2x(struct bcm_mini_adapter *Adapter);
193
194INT BcmCopySection(struct bcm_mini_adapter *Adapter,
195 enum bcm_flash2x_section_val SrcSection,
196 enum bcm_flash2x_section_val DstSection,
197 UINT offset,
198 UINT numOfBytes);
199
200bool IsNonCDLessDevice(struct bcm_mini_adapter *Adapter);
201
202VOID OverrideServiceFlowParams(struct bcm_mini_adapter *Adapter, PUINT puiBuffer);
203
204int wrmaltWithLock(struct bcm_mini_adapter *Adapter, UINT uiAddress, unsigned int *pucBuff, size_t sSize);
205
206int rdmaltWithLock(struct bcm_mini_adapter *Adapter, UINT uiAddress, unsigned int *pucBuff, size_t sSize);
207
208int wrmWithLock(struct bcm_mini_adapter *Adapter, UINT uiAddress, PCHAR pucBuff, size_t size);
209
210INT buffDnldVerify(struct bcm_mini_adapter *Adapter, unsigned char *mappedbuffer, unsigned int u32FirmwareLength,
211 unsigned long u32StartingAddress);
212
213VOID putUsbSuspend(struct work_struct *work);
214
215bool IsReqGpioIsLedInNVM(struct bcm_mini_adapter *Adapter, UINT gpios);
216
217#endif
diff --git a/drivers/staging/bcm/Qos.c b/drivers/staging/bcm/Qos.c
deleted file mode 100644
index b3ac614cd35f..000000000000
--- a/drivers/staging/bcm/Qos.c
+++ /dev/null
@@ -1,1200 +0,0 @@
1/**
2 * @file Qos.C
3 * This file contains the routines related to Quality of Service.
4*/
5#include "headers.h"
6
7static void EThCSGetPktInfo(struct bcm_mini_adapter *Adapter,
8 PVOID pvEthPayload,
9 struct bcm_eth_packet_info *pstEthCsPktInfo);
10
11static bool EThCSClassifyPkt(struct bcm_mini_adapter *Adapter,
12 struct sk_buff *skb,
13 struct bcm_eth_packet_info *pstEthCsPktInfo,
14 struct bcm_classifier_rule *pstClassifierRule,
15 B_UINT8 EthCSCupport);
16
17static USHORT IpVersion4(struct bcm_mini_adapter *Adapter, struct iphdr *iphd,
18 struct bcm_classifier_rule *pstClassifierRule);
19
20static VOID PruneQueue(struct bcm_mini_adapter *Adapter, INT iIndex);
21
22
23/*******************************************************************
24* Function - MatchSrcIpAddress()
25*
26* Description - Checks whether the Source IP address from the packet
27* matches with that of Queue.
28*
29* Parameters - pstClassifierRule: Pointer to the packet info structure.
30* - ulSrcIP : Source IP address from the packet.
31*
32* Returns - TRUE(If address matches) else FAIL .
33*********************************************************************/
34static bool MatchSrcIpAddress(struct bcm_classifier_rule *pstClassifierRule,
35 ULONG ulSrcIP)
36{
37 UCHAR ucLoopIndex = 0;
38
39 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
40 union u_ip_address *src_addr;
41
42 ulSrcIP = ntohl(ulSrcIP);
43 if (0 == pstClassifierRule->ucIPSourceAddressLength)
44 return TRUE;
45 for (ucLoopIndex = 0;
46 ucLoopIndex < (pstClassifierRule->ucIPSourceAddressLength);
47 ucLoopIndex++) {
48 src_addr = &pstClassifierRule->stSrcIpAddress;
49 BCM_DEBUG_PRINT(Adapter,
50 DBG_TYPE_TX,
51 IPV4_DBG,
52 DBG_LVL_ALL,
53 "Src Ip Address Mask:0x%x PacketIp:0x%x and Classification:0x%x",
54 (UINT)src_addr->ulIpv4Mask[ucLoopIndex],
55 (UINT)ulSrcIP,
56 (UINT)src_addr->ulIpv6Addr[ucLoopIndex]);
57
58 if ((src_addr->ulIpv4Mask[ucLoopIndex] & ulSrcIP) ==
59 (src_addr->ulIpv4Addr[ucLoopIndex] &
60 src_addr->ulIpv4Mask[ucLoopIndex]))
61 return TRUE;
62 }
63 BCM_DEBUG_PRINT(Adapter,
64 DBG_TYPE_TX,
65 IPV4_DBG,
66 DBG_LVL_ALL,
67 "Src Ip Address Not Matched");
68 return false;
69}
70
71
72/*******************************************************************
73* Function - MatchDestIpAddress()
74*
75* Description - Checks whether the Destination IP address from the packet
76* matches with that of Queue.
77*
78* Parameters - pstClassifierRule: Pointer to the packet info structure.
79* - ulDestIP : Destination IP address from the packet.
80*
81* Returns - TRUE(If address matches) else FAIL .
82*********************************************************************/
83static bool MatchDestIpAddress(struct bcm_classifier_rule *pstClassifierRule, ULONG ulDestIP)
84{
85 UCHAR ucLoopIndex = 0;
86 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
87 union u_ip_address *dest_addr = &pstClassifierRule->stDestIpAddress;
88
89 ulDestIP = ntohl(ulDestIP);
90 if (0 == pstClassifierRule->ucIPDestinationAddressLength)
91 return TRUE;
92 BCM_DEBUG_PRINT(Adapter,
93 DBG_TYPE_TX,
94 IPV4_DBG,
95 DBG_LVL_ALL,
96 "Destination Ip Address 0x%x 0x%x 0x%x ",
97 (UINT)ulDestIP,
98 (UINT)dest_addr->ulIpv4Mask[ucLoopIndex],
99 (UINT)dest_addr->ulIpv4Addr[ucLoopIndex]);
100
101 for (ucLoopIndex = 0;
102 ucLoopIndex < (pstClassifierRule->ucIPDestinationAddressLength);
103 ucLoopIndex++) {
104 if ((dest_addr->ulIpv4Mask[ucLoopIndex] & ulDestIP) ==
105 (dest_addr->ulIpv4Addr[ucLoopIndex] &
106 dest_addr->ulIpv4Mask[ucLoopIndex]))
107 return TRUE;
108 }
109 BCM_DEBUG_PRINT(Adapter,
110 DBG_TYPE_TX,
111 IPV4_DBG,
112 DBG_LVL_ALL,
113 "Destination Ip Address Not Matched");
114 return false;
115}
116
117
118/************************************************************************
119* Function - MatchTos()
120*
121* Description - Checks the TOS from the packet matches with that of queue.
122*
123* Parameters - pstClassifierRule : Pointer to the packet info structure.
124* - ucTypeOfService: TOS from the packet.
125*
126* Returns - TRUE(If address matches) else FAIL.
127**************************************************************************/
128static bool MatchTos(struct bcm_classifier_rule *pstClassifierRule,
129 UCHAR ucTypeOfService)
130{
131 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
132
133 if (3 != pstClassifierRule->ucIPTypeOfServiceLength)
134 return TRUE;
135
136 if (((pstClassifierRule->ucTosMask & ucTypeOfService) <=
137 pstClassifierRule->ucTosHigh) &&
138 ((pstClassifierRule->ucTosMask & ucTypeOfService) >=
139 pstClassifierRule->ucTosLow))
140 return TRUE;
141
142 BCM_DEBUG_PRINT(Adapter,
143 DBG_TYPE_TX,
144 IPV4_DBG,
145 DBG_LVL_ALL,
146 "Type Of Service Not Matched");
147 return false;
148}
149
150
151/***************************************************************************
152* Function - MatchProtocol()
153*
154* Description - Checks the protocol from the packet matches with that of queue.
155*
156* Parameters - pstClassifierRule: Pointer to the packet info structure.
157* - ucProtocol : Protocol from the packet.
158*
159* Returns - TRUE(If address matches) else FAIL.
160****************************************************************************/
161bool MatchProtocol(struct bcm_classifier_rule *pstClassifierRule,
162 UCHAR ucProtocol)
163{
164 UCHAR ucLoopIndex = 0;
165 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
166
167 if (0 == pstClassifierRule->ucProtocolLength)
168 return TRUE;
169 for (ucLoopIndex = 0;
170 ucLoopIndex < pstClassifierRule->ucProtocolLength;
171 ucLoopIndex++) {
172 BCM_DEBUG_PRINT(Adapter,
173 DBG_TYPE_TX,
174 IPV4_DBG,
175 DBG_LVL_ALL,
176 "Protocol:0x%X Classification Protocol:0x%X",
177 ucProtocol,
178 pstClassifierRule->ucProtocol[ucLoopIndex]);
179 if (pstClassifierRule->ucProtocol[ucLoopIndex] == ucProtocol)
180 return TRUE;
181 }
182 BCM_DEBUG_PRINT(Adapter,
183 DBG_TYPE_TX,
184 IPV4_DBG,
185 DBG_LVL_ALL,
186 "Protocol Not Matched");
187 return false;
188}
189
190
191/***********************************************************************
192* Function - MatchSrcPort()
193*
194* Description - Checks, Source port from the packet matches with that of queue.
195*
196* Parameters - pstClassifierRule: Pointer to the packet info structure.
197* - ushSrcPort : Source port from the packet.
198*
199* Returns - TRUE(If address matches) else FAIL.
200***************************************************************************/
201bool MatchSrcPort(struct bcm_classifier_rule *pstClassifierRule,
202 USHORT ushSrcPort)
203{
204 UCHAR ucLoopIndex = 0;
205
206 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
207
208
209 if (0 == pstClassifierRule->ucSrcPortRangeLength)
210 return TRUE;
211 for (ucLoopIndex = 0;
212 ucLoopIndex < pstClassifierRule->ucSrcPortRangeLength;
213 ucLoopIndex++) {
214 if (ushSrcPort <= pstClassifierRule->usSrcPortRangeHi[ucLoopIndex] &&
215 ushSrcPort >= pstClassifierRule->usSrcPortRangeLo[ucLoopIndex])
216 return TRUE;
217 }
218 BCM_DEBUG_PRINT(Adapter,
219 DBG_TYPE_TX,
220 IPV4_DBG,
221 DBG_LVL_ALL,
222 "Src Port: %x Not Matched ",
223 ushSrcPort);
224 return false;
225}
226
227
228/***********************************************************************
229* Function - MatchDestPort()
230*
231* Description - Checks, Destination port from packet matches with that of queue.
232*
233* Parameters - pstClassifierRule: Pointer to the packet info structure.
234* - ushDestPort : Destination port from the packet.
235*
236* Returns - TRUE(If address matches) else FAIL.
237***************************************************************************/
238bool MatchDestPort(struct bcm_classifier_rule *pstClassifierRule,
239 USHORT ushDestPort)
240{
241 UCHAR ucLoopIndex = 0;
242 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
243
244 if (0 == pstClassifierRule->ucDestPortRangeLength)
245 return TRUE;
246
247 for (ucLoopIndex = 0;
248 ucLoopIndex < pstClassifierRule->ucDestPortRangeLength;
249 ucLoopIndex++) {
250 BCM_DEBUG_PRINT(Adapter,
251 DBG_TYPE_TX,
252 IPV4_DBG,
253 DBG_LVL_ALL,
254 "Matching Port:0x%X 0x%X 0x%X",
255 ushDestPort,
256 pstClassifierRule->usDestPortRangeLo[ucLoopIndex],
257 pstClassifierRule->usDestPortRangeHi[ucLoopIndex]);
258
259 if (ushDestPort <= pstClassifierRule->usDestPortRangeHi[ucLoopIndex] &&
260 ushDestPort >= pstClassifierRule->usDestPortRangeLo[ucLoopIndex])
261 return TRUE;
262 }
263 BCM_DEBUG_PRINT(Adapter,
264 DBG_TYPE_TX,
265 IPV4_DBG,
266 DBG_LVL_ALL,
267 "Dest Port: %x Not Matched",
268 ushDestPort);
269 return false;
270}
271/**
272 * @ingroup tx_functions
273 * Compares IPV4 Ip address and port number
274 * @return Queue Index.
275*/
276static USHORT IpVersion4(struct bcm_mini_adapter *Adapter,
277 struct iphdr *iphd,
278 struct bcm_classifier_rule *pstClassifierRule)
279{
280 struct bcm_transport_header *xprt_hdr = NULL;
281 bool bClassificationSucceed = false;
282
283 BCM_DEBUG_PRINT(Adapter,
284 DBG_TYPE_TX,
285 IPV4_DBG,
286 DBG_LVL_ALL,
287 "========>");
288
289 xprt_hdr = (struct bcm_transport_header *)((PUCHAR)iphd + sizeof(struct iphdr));
290
291 BCM_DEBUG_PRINT(Adapter,
292 DBG_TYPE_TX,
293 IPV4_DBG,
294 DBG_LVL_ALL,
295 "Trying to see Direction = %d %d",
296 pstClassifierRule->ucDirection,
297 pstClassifierRule->usVCID_Value);
298
299 /* Checking classifier validity */
300 if (!pstClassifierRule->bUsed ||
301 pstClassifierRule->ucDirection == DOWNLINK_DIR)
302 goto out;
303
304 BCM_DEBUG_PRINT(Adapter,
305 DBG_TYPE_TX,
306 IPV4_DBG,
307 DBG_LVL_ALL,
308 "is IPv6 check!");
309 if (pstClassifierRule->bIpv6Protocol)
310 goto out;
311
312 /* Checking IP header parameter */
313 BCM_DEBUG_PRINT(Adapter,
314 DBG_TYPE_TX,
315 IPV4_DBG,
316 DBG_LVL_ALL,
317 "Trying to match Source IP Address");
318 if (!MatchSrcIpAddress(pstClassifierRule, iphd->saddr))
319 goto out;
320 BCM_DEBUG_PRINT(Adapter,
321 DBG_TYPE_TX,
322 IPV4_DBG,
323 DBG_LVL_ALL,
324 "Source IP Address Matched");
325
326 if (!MatchDestIpAddress(pstClassifierRule, iphd->daddr))
327 goto out;
328 BCM_DEBUG_PRINT(Adapter,
329 DBG_TYPE_TX,
330 IPV4_DBG,
331 DBG_LVL_ALL,
332 "Destination IP Address Matched");
333
334 if (!MatchTos(pstClassifierRule, iphd->tos)) {
335 BCM_DEBUG_PRINT(Adapter,
336 DBG_TYPE_TX,
337 IPV4_DBG,
338 DBG_LVL_ALL,
339 "TOS Match failed\n");
340 goto out;
341 }
342 BCM_DEBUG_PRINT(Adapter,
343 DBG_TYPE_TX,
344 IPV4_DBG,
345 DBG_LVL_ALL,
346 "TOS Matched");
347
348 if (!MatchProtocol(pstClassifierRule, iphd->protocol))
349 goto out;
350 BCM_DEBUG_PRINT(Adapter,
351 DBG_TYPE_TX,
352 IPV4_DBG,
353 DBG_LVL_ALL,
354 "Protocol Matched");
355
356 /*
357 * if protocol is not TCP or UDP then no
358 * need of comparing source port and destination port
359 */
360 if (iphd->protocol != TCP && iphd->protocol != UDP) {
361 bClassificationSucceed = TRUE;
362 goto out;
363 }
364 /* Checking Transport Layer Header field if present */
365 BCM_DEBUG_PRINT(Adapter,
366 DBG_TYPE_TX,
367 IPV4_DBG,
368 DBG_LVL_ALL,
369 "Source Port %04x",
370 (iphd->protocol == UDP) ? xprt_hdr->uhdr.source : xprt_hdr->thdr.source);
371
372 if (!MatchSrcPort(pstClassifierRule,
373 ntohs((iphd->protocol == UDP) ?
374 xprt_hdr->uhdr.source : xprt_hdr->thdr.source)))
375 goto out;
376 BCM_DEBUG_PRINT(Adapter,
377 DBG_TYPE_TX,
378 IPV4_DBG,
379 DBG_LVL_ALL,
380 "Src Port Matched");
381
382 BCM_DEBUG_PRINT(Adapter,
383 DBG_TYPE_TX,
384 IPV4_DBG,
385 DBG_LVL_ALL,
386 "Destination Port %04x",
387 (iphd->protocol == UDP) ? xprt_hdr->uhdr.dest :
388 xprt_hdr->thdr.dest);
389
390 if (!MatchDestPort(pstClassifierRule,
391 ntohs((iphd->protocol == UDP) ?
392 xprt_hdr->uhdr.dest : xprt_hdr->thdr.dest)))
393 goto out;
394 bClassificationSucceed = TRUE;
395
396out:
397 if (TRUE == bClassificationSucceed) {
398 INT iMatchedSFQueueIndex = 0;
399
400 iMatchedSFQueueIndex =
401 SearchSfid(Adapter, pstClassifierRule->ulSFID);
402 if (iMatchedSFQueueIndex >= NO_OF_QUEUES)
403 bClassificationSucceed = false;
404 else if (false == Adapter->PackInfo[iMatchedSFQueueIndex].bActive)
405 bClassificationSucceed = false;
406 }
407
408 BCM_DEBUG_PRINT(Adapter,
409 DBG_TYPE_TX,
410 IPV4_DBG,
411 DBG_LVL_ALL,
412 "IpVersion4 <==========");
413
414 return bClassificationSucceed;
415}
416
417VOID PruneQueueAllSF(struct bcm_mini_adapter *Adapter)
418{
419 UINT iIndex = 0;
420
421 for (iIndex = 0; iIndex < HiPriority; iIndex++) {
422 if (!Adapter->PackInfo[iIndex].bValid)
423 continue;
424
425 PruneQueue(Adapter, iIndex);
426 }
427}
428
429
430/**
431 * @ingroup tx_functions
432 * This function checks if the max queue size for a queue
433 * is less than number of bytes in the queue. If so -
434 * drops packets from the Head till the number of bytes is
435 * less than or equal to max queue size for the queue.
436 */
437static VOID PruneQueue(struct bcm_mini_adapter *Adapter, INT iIndex)
438{
439 struct sk_buff *PacketToDrop = NULL;
440 struct net_device_stats *netstats;
441 struct bcm_packet_info *curr_pack_info = &Adapter->PackInfo[iIndex];
442
443 BCM_DEBUG_PRINT(Adapter,
444 DBG_TYPE_TX,
445 PRUNE_QUEUE,
446 DBG_LVL_ALL,
447 "=====> Index %d",
448 iIndex);
449
450 if (iIndex == HiPriority)
451 return;
452
453 if (!Adapter || (iIndex < 0) || (iIndex > HiPriority))
454 return;
455
456 /* To Store the netdevice statistic */
457 netstats = &Adapter->dev->stats;
458
459 spin_lock_bh(&curr_pack_info->SFQueueLock);
460
461 while (1) {
462/* while((UINT)curr_pack_info->uiCurrentPacketsOnHost >
463 SF_MAX_ALLOWED_PACKETS_TO_BACKUP) { */
464
465 BCM_DEBUG_PRINT(Adapter,
466 DBG_TYPE_TX,
467 PRUNE_QUEUE,
468 DBG_LVL_ALL,
469 "uiCurrentBytesOnHost:%x uiMaxBucketSize :%x",
470 curr_pack_info->uiCurrentBytesOnHost,
471 curr_pack_info->uiMaxBucketSize);
472
473 PacketToDrop = curr_pack_info->FirstTxQueue;
474
475 if (PacketToDrop == NULL)
476 break;
477 if ((curr_pack_info->uiCurrentPacketsOnHost <
478 SF_MAX_ALLOWED_PACKETS_TO_BACKUP) &&
479 ((1000*(jiffies - *((B_UINT32 *)(PacketToDrop->cb) +
480 SKB_CB_LATENCY_OFFSET))/HZ) <=
481 curr_pack_info->uiMaxLatency))
482 break;
483
484 if (PacketToDrop) {
485 if (netif_msg_tx_err(Adapter))
486 pr_info(PFX "%s: tx queue %d overlimit\n",
487 Adapter->dev->name, iIndex);
488
489 netstats->tx_dropped++;
490
491 DEQUEUEPACKET(curr_pack_info->FirstTxQueue,
492 curr_pack_info->LastTxQueue);
493 /* update current bytes and packets count */
494 curr_pack_info->uiCurrentBytesOnHost -=
495 PacketToDrop->len;
496 curr_pack_info->uiCurrentPacketsOnHost--;
497 /* update dropped bytes and packets counts */
498 curr_pack_info->uiDroppedCountBytes += PacketToDrop->len;
499 curr_pack_info->uiDroppedCountPackets++;
500 dev_kfree_skb(PacketToDrop);
501
502 }
503
504 BCM_DEBUG_PRINT(Adapter,
505 DBG_TYPE_TX,
506 PRUNE_QUEUE,
507 DBG_LVL_ALL,
508 "Dropped Bytes:%x Dropped Packets:%x",
509 curr_pack_info->uiDroppedCountBytes,
510 curr_pack_info->uiDroppedCountPackets);
511
512 atomic_dec(&Adapter->TotalPacketCount);
513 }
514
515 spin_unlock_bh(&curr_pack_info->SFQueueLock);
516
517 BCM_DEBUG_PRINT(Adapter,
518 DBG_TYPE_TX,
519 PRUNE_QUEUE,
520 DBG_LVL_ALL,
521 "TotalPacketCount:%x",
522 atomic_read(&Adapter->TotalPacketCount));
523 BCM_DEBUG_PRINT(Adapter,
524 DBG_TYPE_TX,
525 PRUNE_QUEUE,
526 DBG_LVL_ALL,
527 "<=====");
528}
529
530VOID flush_all_queues(struct bcm_mini_adapter *Adapter)
531{
532 INT iQIndex;
533 UINT uiTotalPacketLength;
534 struct sk_buff *PacketToDrop = NULL;
535 struct bcm_packet_info *curr_packet_info;
536
537 BCM_DEBUG_PRINT(Adapter,
538 DBG_TYPE_OTHERS,
539 DUMP_INFO,
540 DBG_LVL_ALL,
541 "=====>");
542
543 /* down(&Adapter->data_packet_queue_lock); */
544 for (iQIndex = LowPriority; iQIndex < HiPriority; iQIndex++) {
545 struct net_device_stats *netstats = &Adapter->dev->stats;
546
547 curr_packet_info = &Adapter->PackInfo[iQIndex];
548
549 spin_lock_bh(&curr_packet_info->SFQueueLock);
550 while (curr_packet_info->FirstTxQueue) {
551 PacketToDrop = curr_packet_info->FirstTxQueue;
552 if (PacketToDrop) {
553 uiTotalPacketLength = PacketToDrop->len;
554 netstats->tx_dropped++;
555 } else
556 uiTotalPacketLength = 0;
557
558 DEQUEUEPACKET(curr_packet_info->FirstTxQueue,
559 curr_packet_info->LastTxQueue);
560
561 /* Free the skb */
562 dev_kfree_skb(PacketToDrop);
563
564 /* update current bytes and packets count */
565 curr_packet_info->uiCurrentBytesOnHost -= uiTotalPacketLength;
566 curr_packet_info->uiCurrentPacketsOnHost--;
567
568 /* update dropped bytes and packets counts */
569 curr_packet_info->uiDroppedCountBytes += uiTotalPacketLength;
570 curr_packet_info->uiDroppedCountPackets++;
571
572 BCM_DEBUG_PRINT(Adapter,
573 DBG_TYPE_OTHERS,
574 DUMP_INFO,
575 DBG_LVL_ALL,
576 "Dropped Bytes:%x Dropped Packets:%x",
577 curr_packet_info->uiDroppedCountBytes,
578 curr_packet_info->uiDroppedCountPackets);
579 atomic_dec(&Adapter->TotalPacketCount);
580 }
581 spin_unlock_bh(&curr_packet_info->SFQueueLock);
582 }
583 /* up(&Adapter->data_packet_queue_lock); */
584 BCM_DEBUG_PRINT(Adapter,
585 DBG_TYPE_OTHERS,
586 DUMP_INFO,
587 DBG_LVL_ALL,
588 "<=====");
589}
590
591USHORT ClassifyPacket(struct bcm_mini_adapter *Adapter, struct sk_buff *skb)
592{
593 INT uiLoopIndex = 0;
594 struct bcm_classifier_rule *pstClassifierRule = NULL;
595 struct bcm_eth_packet_info stEthCsPktInfo;
596 PVOID pvEThPayload = NULL;
597 struct iphdr *pIpHeader = NULL;
598 INT uiSfIndex = 0;
599 USHORT usIndex = Adapter->usBestEffortQueueIndex;
600 bool bFragmentedPkt = false, bClassificationSucceed = false;
601 USHORT usCurrFragment = 0;
602
603 struct bcm_tcp_header *pTcpHeader;
604 UCHAR IpHeaderLength;
605 UCHAR TcpHeaderLength;
606
607 pvEThPayload = skb->data;
608 *((UINT32 *) (skb->cb) + SKB_CB_TCPACK_OFFSET) = 0;
609 EThCSGetPktInfo(Adapter, pvEThPayload, &stEthCsPktInfo);
610
611 switch (stEthCsPktInfo.eNwpktEthFrameType) {
612 case eEth802LLCFrame:
613 BCM_DEBUG_PRINT(Adapter,
614 DBG_TYPE_TX,
615 IPV4_DBG,
616 DBG_LVL_ALL,
617 "ClassifyPacket : 802LLCFrame\n");
618 pIpHeader = pvEThPayload + sizeof(struct bcm_eth_llc_frame);
619 break;
620 case eEth802LLCSNAPFrame:
621 BCM_DEBUG_PRINT(Adapter,
622 DBG_TYPE_TX,
623 IPV4_DBG,
624 DBG_LVL_ALL,
625 "ClassifyPacket : 802LLC SNAP Frame\n");
626 pIpHeader = pvEThPayload +
627 sizeof(struct bcm_eth_llc_snap_frame);
628 break;
629 case eEth802QVLANFrame:
630 BCM_DEBUG_PRINT(Adapter,
631 DBG_TYPE_TX,
632 IPV4_DBG,
633 DBG_LVL_ALL,
634 "ClassifyPacket : 802.1Q VLANFrame\n");
635 pIpHeader = pvEThPayload + sizeof(struct bcm_eth_q_frame);
636 break;
637 case eEthOtherFrame:
638 BCM_DEBUG_PRINT(Adapter,
639 DBG_TYPE_TX,
640 IPV4_DBG,
641 DBG_LVL_ALL,
642 "ClassifyPacket : ETH Other Frame\n");
643 pIpHeader = pvEThPayload + sizeof(struct bcm_ethernet2_frame);
644 break;
645 default:
646 BCM_DEBUG_PRINT(Adapter,
647 DBG_TYPE_TX,
648 IPV4_DBG,
649 DBG_LVL_ALL,
650 "ClassifyPacket : Unrecognized ETH Frame\n");
651 pIpHeader = pvEThPayload + sizeof(struct bcm_ethernet2_frame);
652 break;
653 }
654
655 if (stEthCsPktInfo.eNwpktIPFrameType == eIPv4Packet) {
656 usCurrFragment = (ntohs(pIpHeader->frag_off) & IP_OFFSET);
657 if ((ntohs(pIpHeader->frag_off) & IP_MF) || usCurrFragment)
658 bFragmentedPkt = TRUE;
659
660 if (bFragmentedPkt) {
661 /* Fragmented Packet. Get Frag Classifier Entry. */
662 pstClassifierRule = GetFragIPClsEntry(Adapter,
663 pIpHeader->id,
664 pIpHeader->saddr);
665 if (pstClassifierRule) {
666 BCM_DEBUG_PRINT(Adapter,
667 DBG_TYPE_TX,
668 IPV4_DBG,
669 DBG_LVL_ALL,
670 "It is next Fragmented pkt");
671 bClassificationSucceed = TRUE;
672 }
673 if (!(ntohs(pIpHeader->frag_off) & IP_MF)) {
674 /* Fragmented Last packet . Remove Frag Classifier Entry */
675 BCM_DEBUG_PRINT(Adapter,
676 DBG_TYPE_TX,
677 IPV4_DBG,
678 DBG_LVL_ALL,
679 "This is the last fragmented Pkt");
680 DelFragIPClsEntry(Adapter,
681 pIpHeader->id,
682 pIpHeader->saddr);
683 }
684 }
685 }
686
687 for (uiLoopIndex = MAX_CLASSIFIERS - 1; uiLoopIndex >= 0; uiLoopIndex--) {
688 if (bClassificationSucceed)
689 break;
690 /*
691 * Iterate through all classifiers which are already in order of priority
692 * to classify the packet until match found
693 */
694 if (false == Adapter->astClassifierTable[uiLoopIndex].bUsed) {
695 bClassificationSucceed = false;
696 continue;
697 }
698 BCM_DEBUG_PRINT(Adapter,
699 DBG_TYPE_TX,
700 IPV4_DBG,
701 DBG_LVL_ALL,
702 "Adapter->PackInfo[%d].bvalid=True\n",
703 uiLoopIndex);
704
705 if (0 == Adapter->astClassifierTable[uiLoopIndex].ucDirection) {
706 bClassificationSucceed = false; /* cannot be processed for classification. */
707 continue; /* it is a down link connection */
708 }
709
710 pstClassifierRule = &Adapter->astClassifierTable[uiLoopIndex];
711
712 uiSfIndex = SearchSfid(Adapter, pstClassifierRule->ulSFID);
713 if (uiSfIndex >= NO_OF_QUEUES) {
714 BCM_DEBUG_PRINT(Adapter,
715 DBG_TYPE_TX,
716 IPV4_DBG,
717 DBG_LVL_ALL,
718 "Queue Not Valid. SearchSfid for this classifier Failed\n");
719 continue;
720 }
721
722 if (Adapter->PackInfo[uiSfIndex].bEthCSSupport) {
723
724 if (eEthUnsupportedFrame == stEthCsPktInfo.eNwpktEthFrameType) {
725 BCM_DEBUG_PRINT(Adapter,
726 DBG_TYPE_TX,
727 IPV4_DBG,
728 DBG_LVL_ALL,
729 " ClassifyPacket : Packet Not a Valid Supported Ethernet Frame\n");
730 bClassificationSucceed = false;
731 continue;
732 }
733
734
735
736 BCM_DEBUG_PRINT(Adapter,
737 DBG_TYPE_TX,
738 IPV4_DBG,
739 DBG_LVL_ALL,
740 "Performing ETH CS Classification on Classifier Rule ID : %x Service Flow ID : %lx\n",
741 pstClassifierRule->uiClassifierRuleIndex,
742 Adapter->PackInfo[uiSfIndex].ulSFID);
743 bClassificationSucceed = EThCSClassifyPkt(Adapter,
744 skb,
745 &stEthCsPktInfo,
746 pstClassifierRule,
747 Adapter->PackInfo[uiSfIndex].bEthCSSupport);
748
749 if (!bClassificationSucceed) {
750 BCM_DEBUG_PRINT(Adapter,
751 DBG_TYPE_TX,
752 IPV4_DBG,
753 DBG_LVL_ALL,
754 "ClassifyPacket : Ethernet CS Classification Failed\n");
755 continue;
756 }
757 } else { /* No ETH Supported on this SF */
758 if (eEthOtherFrame != stEthCsPktInfo.eNwpktEthFrameType) {
759 BCM_DEBUG_PRINT(Adapter,
760 DBG_TYPE_TX,
761 IPV4_DBG,
762 DBG_LVL_ALL,
763 " ClassifyPacket : Packet Not a 802.3 Ethernet Frame... hence not allowed over non-ETH CS SF\n");
764 bClassificationSucceed = false;
765 continue;
766 }
767 }
768
769 BCM_DEBUG_PRINT(Adapter,
770 DBG_TYPE_TX,
771 IPV4_DBG,
772 DBG_LVL_ALL,
773 "Proceeding to IP CS Clasification");
774
775 if (Adapter->PackInfo[uiSfIndex].bIPCSSupport) {
776
777 if (stEthCsPktInfo.eNwpktIPFrameType == eNonIPPacket) {
778 BCM_DEBUG_PRINT(Adapter,
779 DBG_TYPE_TX,
780 IPV4_DBG,
781 DBG_LVL_ALL,
782 " ClassifyPacket : Packet is Not an IP Packet\n");
783 bClassificationSucceed = false;
784 continue;
785 }
786 BCM_DEBUG_PRINT(Adapter,
787 DBG_TYPE_TX,
788 IPV4_DBG,
789 DBG_LVL_ALL,
790 "Dump IP Header :\n");
791 DumpFullPacket((PUCHAR)pIpHeader, 20);
792
793 if (stEthCsPktInfo.eNwpktIPFrameType == eIPv4Packet)
794 bClassificationSucceed = IpVersion4(Adapter,
795 pIpHeader,
796 pstClassifierRule);
797 else if (stEthCsPktInfo.eNwpktIPFrameType == eIPv6Packet)
798 bClassificationSucceed = IpVersion6(Adapter,
799 pIpHeader,
800 pstClassifierRule);
801 }
802 }
803
804 if (bClassificationSucceed == TRUE) {
805 BCM_DEBUG_PRINT(Adapter,
806 DBG_TYPE_TX,
807 IPV4_DBG,
808 DBG_LVL_ALL,
809 "CF id : %d, SF ID is =%lu",
810 pstClassifierRule->uiClassifierRuleIndex,
811 pstClassifierRule->ulSFID);
812
813 /* Store The matched Classifier in SKB */
814 *((UINT32 *)(skb->cb)+SKB_CB_CLASSIFICATION_OFFSET) =
815 pstClassifierRule->uiClassifierRuleIndex;
816 if ((TCP == pIpHeader->protocol) && !bFragmentedPkt &&
817 (ETH_AND_IP_HEADER_LEN + TCP_HEADER_LEN <=
818 skb->len)) {
819 IpHeaderLength = pIpHeader->ihl;
820 pTcpHeader =
821 (struct bcm_tcp_header *)(((PUCHAR)pIpHeader) +
822 (IpHeaderLength*4));
823 TcpHeaderLength = GET_TCP_HEADER_LEN(pTcpHeader->HeaderLength);
824
825 if ((pTcpHeader->ucFlags & TCP_ACK) &&
826 (ntohs(pIpHeader->tot_len) ==
827 (IpHeaderLength*4)+(TcpHeaderLength*4)))
828 *((UINT32 *) (skb->cb) + SKB_CB_TCPACK_OFFSET) =
829 TCP_ACK;
830 }
831
832 usIndex = SearchSfid(Adapter, pstClassifierRule->ulSFID);
833 BCM_DEBUG_PRINT(Adapter,
834 DBG_TYPE_TX,
835 IPV4_DBG,
836 DBG_LVL_ALL,
837 "index is =%d",
838 usIndex);
839
840 /*
841 * If this is the first fragment of a Fragmented pkt,
842 * add this CF. Only This CF should be used for all other
843 * fragment of this Pkt.
844 */
845 if (bFragmentedPkt && (usCurrFragment == 0)) {
846 /*
847 * First Fragment of Fragmented Packet.
848 * Create Frag CLS Entry
849 */
850 struct bcm_fragmented_packet_info stFragPktInfo;
851
852 stFragPktInfo.bUsed = TRUE;
853 stFragPktInfo.ulSrcIpAddress = pIpHeader->saddr;
854 stFragPktInfo.usIpIdentification = pIpHeader->id;
855 stFragPktInfo.pstMatchedClassifierEntry =
856 pstClassifierRule;
857 stFragPktInfo.bOutOfOrderFragment = false;
858 AddFragIPClsEntry(Adapter, &stFragPktInfo);
859 }
860
861
862 }
863
864 return bClassificationSucceed ? usIndex : INVALID_QUEUE_INDEX;
865}
866
867static bool EthCSMatchSrcMACAddress(struct bcm_classifier_rule *pstClassifierRule,
868 PUCHAR Mac)
869{
870 UINT i = 0;
871 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
872
873 if (pstClassifierRule->ucEthCSSrcMACLen == 0)
874 return TRUE;
875 BCM_DEBUG_PRINT(Adapter,
876 DBG_TYPE_TX,
877 IPV4_DBG,
878 DBG_LVL_ALL,
879 "%s\n", __func__);
880 for (i = 0; i < MAC_ADDRESS_SIZE; i++) {
881 BCM_DEBUG_PRINT(Adapter,
882 DBG_TYPE_TX,
883 IPV4_DBG,
884 DBG_LVL_ALL,
885 "SRC MAC[%x] = %x ClassifierRuleSrcMAC = %x Mask : %x\n",
886 i,
887 Mac[i],
888 pstClassifierRule->au8EThCSSrcMAC[i],
889 pstClassifierRule->au8EThCSSrcMACMask[i]);
890 if ((pstClassifierRule->au8EThCSSrcMAC[i] &
891 pstClassifierRule->au8EThCSSrcMACMask[i]) !=
892 (Mac[i] & pstClassifierRule->au8EThCSSrcMACMask[i]))
893 return false;
894 }
895 return TRUE;
896}
897
898static bool EthCSMatchDestMACAddress(struct bcm_classifier_rule *pstClassifierRule,
899 PUCHAR Mac)
900{
901 UINT i = 0;
902 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
903
904 if (pstClassifierRule->ucEthCSDestMACLen == 0)
905 return TRUE;
906 BCM_DEBUG_PRINT(Adapter,
907 DBG_TYPE_TX,
908 IPV4_DBG,
909 DBG_LVL_ALL,
910 "%s\n",
911 __func__);
912 for (i = 0; i < MAC_ADDRESS_SIZE; i++) {
913 BCM_DEBUG_PRINT(Adapter,
914 DBG_TYPE_TX,
915 IPV4_DBG,
916 DBG_LVL_ALL,
917 "SRC MAC[%x] = %x ClassifierRuleSrcMAC = %x Mask : %x\n",
918 i,
919 Mac[i],
920 pstClassifierRule->au8EThCSDestMAC[i],
921 pstClassifierRule->au8EThCSDestMACMask[i]);
922 if ((pstClassifierRule->au8EThCSDestMAC[i] &
923 pstClassifierRule->au8EThCSDestMACMask[i]) !=
924 (Mac[i] & pstClassifierRule->au8EThCSDestMACMask[i]))
925 return false;
926 }
927 return TRUE;
928}
929
930static bool EthCSMatchEThTypeSAP(struct bcm_classifier_rule *pstClassifierRule,
931 struct sk_buff *skb,
932 struct bcm_eth_packet_info *pstEthCsPktInfo)
933{
934 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
935
936 if ((pstClassifierRule->ucEtherTypeLen == 0) ||
937 (pstClassifierRule->au8EthCSEtherType[0] == 0))
938 return TRUE;
939
940 BCM_DEBUG_PRINT(Adapter,
941 DBG_TYPE_TX,
942 IPV4_DBG,
943 DBG_LVL_ALL,
944 "%s SrcEtherType:%x CLS EtherType[0]:%x\n",
945 __func__,
946 pstEthCsPktInfo->usEtherType,
947 pstClassifierRule->au8EthCSEtherType[0]);
948 if (pstClassifierRule->au8EthCSEtherType[0] == 1) {
949 BCM_DEBUG_PRINT(Adapter,
950 DBG_TYPE_TX,
951 IPV4_DBG,
952 DBG_LVL_ALL,
953 "%s CLS EtherType[1]:%x EtherType[2]:%x\n",
954 __func__,
955 pstClassifierRule->au8EthCSEtherType[1],
956 pstClassifierRule->au8EthCSEtherType[2]);
957
958 if (memcmp(&pstEthCsPktInfo->usEtherType,
959 &pstClassifierRule->au8EthCSEtherType[1],
960 2) == 0)
961 return TRUE;
962 else
963 return false;
964 }
965
966 if (pstClassifierRule->au8EthCSEtherType[0] == 2) {
967 if (eEth802LLCFrame != pstEthCsPktInfo->eNwpktEthFrameType)
968 return false;
969
970 BCM_DEBUG_PRINT(Adapter,
971 DBG_TYPE_TX,
972 IPV4_DBG,
973 DBG_LVL_ALL,
974 "%s EthCS DSAP:%x EtherType[2]:%x\n",
975 __func__,
976 pstEthCsPktInfo->ucDSAP,
977 pstClassifierRule->au8EthCSEtherType[2]);
978 if (pstEthCsPktInfo->ucDSAP ==
979 pstClassifierRule->au8EthCSEtherType[2])
980 return TRUE;
981 else
982 return false;
983
984 }
985
986 return false;
987
988}
989
990static bool EthCSMatchVLANRules(struct bcm_classifier_rule *pstClassifierRule,
991 struct sk_buff *skb,
992 struct bcm_eth_packet_info *pstEthCsPktInfo)
993{
994 bool bClassificationSucceed = false;
995 USHORT usVLANID;
996 B_UINT8 uPriority = 0;
997 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
998
999 BCM_DEBUG_PRINT(Adapter,
1000 DBG_TYPE_TX,
1001 IPV4_DBG,
1002 DBG_LVL_ALL,
1003 "%s CLS UserPrio:%x CLS VLANID:%x\n",
1004 __func__,
1005 ntohs(*((USHORT *)pstClassifierRule->usUserPriority)),
1006 pstClassifierRule->usVLANID);
1007
1008 /*
1009 * In case FW didn't receive the TLV,
1010 * the priority field should be ignored
1011 */
1012 if (pstClassifierRule->usValidityBitMap &
1013 (1<<PKT_CLASSIFICATION_USER_PRIORITY_VALID)) {
1014 if (pstEthCsPktInfo->eNwpktEthFrameType != eEth802QVLANFrame)
1015 return false;
1016
1017 uPriority = (ntohs(*(USHORT *)(skb->data +
1018 sizeof(struct bcm_eth_header))) &
1019 0xF000) >> 13;
1020
1021 if ((uPriority >= pstClassifierRule->usUserPriority[0]) &&
1022 (uPriority <=
1023 pstClassifierRule->usUserPriority[1]))
1024 bClassificationSucceed = TRUE;
1025
1026 if (!bClassificationSucceed)
1027 return false;
1028 }
1029
1030 BCM_DEBUG_PRINT(Adapter,
1031 DBG_TYPE_TX,
1032 IPV4_DBG,
1033 DBG_LVL_ALL,
1034 "ETH CS 802.1 D User Priority Rule Matched\n");
1035
1036 bClassificationSucceed = false;
1037
1038 if (pstClassifierRule->usValidityBitMap &
1039 (1<<PKT_CLASSIFICATION_VLANID_VALID)) {
1040 if (pstEthCsPktInfo->eNwpktEthFrameType != eEth802QVLANFrame)
1041 return false;
1042
1043 usVLANID = ntohs(*(USHORT *)(skb->data +
1044 sizeof(struct bcm_eth_header))) & 0xFFF;
1045
1046 BCM_DEBUG_PRINT(Adapter,
1047 DBG_TYPE_TX,
1048 IPV4_DBG,
1049 DBG_LVL_ALL,
1050 "%s Pkt VLANID %x Priority: %d\n",
1051 __func__,
1052 usVLANID,
1053 uPriority);
1054
1055 if (usVLANID == ((pstClassifierRule->usVLANID & 0xFFF0) >> 4))
1056 bClassificationSucceed = TRUE;
1057
1058 if (!bClassificationSucceed)
1059 return false;
1060 }
1061
1062 BCM_DEBUG_PRINT(Adapter,
1063 DBG_TYPE_TX,
1064 IPV4_DBG,
1065 DBG_LVL_ALL,
1066 "ETH CS 802.1 Q VLAN ID Rule Matched\n");
1067
1068 return TRUE;
1069}
1070
1071
1072static bool EThCSClassifyPkt(struct bcm_mini_adapter *Adapter,
1073 struct sk_buff *skb,
1074 struct bcm_eth_packet_info *pstEthCsPktInfo,
1075 struct bcm_classifier_rule *pstClassifierRule,
1076 B_UINT8 EthCSCupport)
1077{
1078 bool bClassificationSucceed = false;
1079
1080 bClassificationSucceed = EthCSMatchSrcMACAddress(pstClassifierRule,
1081 ((struct bcm_eth_header *)(skb->data))->au8SourceAddress);
1082 if (!bClassificationSucceed)
1083 return false;
1084 BCM_DEBUG_PRINT(Adapter,
1085 DBG_TYPE_TX,
1086 IPV4_DBG,
1087 DBG_LVL_ALL,
1088 "ETH CS SrcMAC Matched\n");
1089
1090 bClassificationSucceed = EthCSMatchDestMACAddress(pstClassifierRule,
1091 ((struct bcm_eth_header *)(skb->data))->au8DestinationAddress);
1092 if (!bClassificationSucceed)
1093 return false;
1094 BCM_DEBUG_PRINT(Adapter,
1095 DBG_TYPE_TX,
1096 IPV4_DBG,
1097 DBG_LVL_ALL,
1098 "ETH CS DestMAC Matched\n");
1099
1100 /* classify on ETHType/802.2SAP TLV */
1101 bClassificationSucceed = EthCSMatchEThTypeSAP(pstClassifierRule,
1102 skb,
1103 pstEthCsPktInfo);
1104 if (!bClassificationSucceed)
1105 return false;
1106
1107 BCM_DEBUG_PRINT(Adapter,
1108 DBG_TYPE_TX,
1109 IPV4_DBG,
1110 DBG_LVL_ALL,
1111 "ETH CS EthType/802.2SAP Matched\n");
1112
1113 /* classify on 802.1VLAN Header Parameters */
1114 bClassificationSucceed = EthCSMatchVLANRules(pstClassifierRule,
1115 skb,
1116 pstEthCsPktInfo);
1117 if (!bClassificationSucceed)
1118 return false;
1119 BCM_DEBUG_PRINT(Adapter,
1120 DBG_TYPE_TX,
1121 IPV4_DBG,
1122 DBG_LVL_ALL,
1123 "ETH CS 802.1 VLAN Rules Matched\n");
1124
1125 return bClassificationSucceed;
1126}
1127
1128static void EThCSGetPktInfo(struct bcm_mini_adapter *Adapter,
1129 PVOID pvEthPayload,
1130 struct bcm_eth_packet_info *pstEthCsPktInfo)
1131{
1132 USHORT u16Etype = ntohs(
1133 ((struct bcm_eth_header *)pvEthPayload)->u16Etype);
1134
1135 BCM_DEBUG_PRINT(Adapter,
1136 DBG_TYPE_TX,
1137 IPV4_DBG,
1138 DBG_LVL_ALL,
1139 "EthCSGetPktInfo : Eth Hdr Type : %X\n",
1140 u16Etype);
1141 if (u16Etype > 0x5dc) {
1142 BCM_DEBUG_PRINT(Adapter,
1143 DBG_TYPE_TX,
1144 IPV4_DBG,
1145 DBG_LVL_ALL,
1146 "EthCSGetPktInfo : ETH2 Frame\n");
1147 /* ETH2 Frame */
1148 if (u16Etype == ETHERNET_FRAMETYPE_802QVLAN) {
1149 /* 802.1Q VLAN Header */
1150 pstEthCsPktInfo->eNwpktEthFrameType = eEth802QVLANFrame;
1151 u16Etype = ((struct bcm_eth_q_frame *)pvEthPayload)->EthType;
1152 /* ((ETH_CS_802_Q_FRAME*)pvEthPayload)->UserPriority */
1153 } else {
1154 pstEthCsPktInfo->eNwpktEthFrameType = eEthOtherFrame;
1155 u16Etype = ntohs(u16Etype);
1156 }
1157 } else {
1158 /* 802.2 LLC */
1159 BCM_DEBUG_PRINT(Adapter,
1160 DBG_TYPE_TX,
1161 IPV4_DBG,
1162 DBG_LVL_ALL,
1163 "802.2 LLC Frame\n");
1164 pstEthCsPktInfo->eNwpktEthFrameType = eEth802LLCFrame;
1165 pstEthCsPktInfo->ucDSAP =
1166 ((struct bcm_eth_llc_frame *)pvEthPayload)->DSAP;
1167 if (pstEthCsPktInfo->ucDSAP == 0xAA && ((struct bcm_eth_llc_frame *)pvEthPayload)->SSAP == 0xAA) {
1168 /* SNAP Frame */
1169 pstEthCsPktInfo->eNwpktEthFrameType = eEth802LLCSNAPFrame;
1170 u16Etype = ((struct bcm_eth_llc_snap_frame *)pvEthPayload)->usEtherType;
1171 }
1172 }
1173 if (u16Etype == ETHERNET_FRAMETYPE_IPV4)
1174 pstEthCsPktInfo->eNwpktIPFrameType = eIPv4Packet;
1175 else if (u16Etype == ETHERNET_FRAMETYPE_IPV6)
1176 pstEthCsPktInfo->eNwpktIPFrameType = eIPv6Packet;
1177 else
1178 pstEthCsPktInfo->eNwpktIPFrameType = eNonIPPacket;
1179
1180 pstEthCsPktInfo->usEtherType = ((struct bcm_eth_header *)pvEthPayload)->u16Etype;
1181 BCM_DEBUG_PRINT(Adapter,
1182 DBG_TYPE_TX,
1183 IPV4_DBG,
1184 DBG_LVL_ALL,
1185 "EthCsPktInfo->eNwpktIPFrameType : %x\n",
1186 pstEthCsPktInfo->eNwpktIPFrameType);
1187 BCM_DEBUG_PRINT(Adapter,
1188 DBG_TYPE_TX,
1189 IPV4_DBG,
1190 DBG_LVL_ALL,
1191 "EthCsPktInfo->eNwpktEthFrameType : %x\n",
1192 pstEthCsPktInfo->eNwpktEthFrameType);
1193 BCM_DEBUG_PRINT(Adapter,
1194 DBG_TYPE_TX,
1195 IPV4_DBG,
1196 DBG_LVL_ALL,
1197 "EthCsPktInfo->usEtherType : %x\n",
1198 pstEthCsPktInfo->usEtherType);
1199}
1200
diff --git a/drivers/staging/bcm/Queue.h b/drivers/staging/bcm/Queue.h
deleted file mode 100644
index 460c0aee67f6..000000000000
--- a/drivers/staging/bcm/Queue.h
+++ /dev/null
@@ -1,29 +0,0 @@
1/*************************************
2* Queue.h
3**************************************/
4#ifndef __QUEUE_H__
5#define __QUEUE_H__
6
7
8
9#define ENQUEUEPACKET(_Head, _Tail, _Packet) \
10do { \
11 if (!_Head) { \
12 _Head = _Packet; \
13 } \
14 else { \
15 (_Tail)->next = _Packet; \
16 } \
17 (_Packet)->next = NULL; \
18 _Tail = _Packet; \
19} while (0)
20#define DEQUEUEPACKET(Head, Tail) \
21do { \
22 if (Head) { \
23 if (!Head->next) { \
24 Tail = NULL; \
25 } \
26 Head = Head->next; \
27 } \
28} while (0)
29#endif /* __QUEUE_H__ */
diff --git a/drivers/staging/bcm/TODO b/drivers/staging/bcm/TODO
deleted file mode 100644
index 8467f45d08a6..000000000000
--- a/drivers/staging/bcm/TODO
+++ /dev/null
@@ -1,26 +0,0 @@
1This driver is barely functional in its current state.
2
3Kevin McKinney(klmckinney1@gmail.com) and Matthias Beyer(mail@beyermatthias.de)
4are currently maintaining/cleaning up this driver. Please copy us on all
5patches. More maintainers are aways welcomed.
6
7BIG:
8 - existing API is (/dev/tarang) should be replaced
9 Is it possible to use same API as Intel Wimax stack and
10 have same user level components.
11 - Qos and queue model is non-standard and inflexible.
12 Use existing TC Qos?
13
14TODO:
15 - support more than one board - eliminate global variables
16 - remove developer debug BCM_DEBUG() macros
17 add a limited number of messages through netif_msg()
18 - fix non-standard kernel style
19 - checkpatch warnings
20 - use request firmware
21 - fix use of file I/O to load config with better API
22 - merge some files together?
23 - cleanup/eliminate debug messages
24
25
26
diff --git a/drivers/staging/bcm/Transmit.c b/drivers/staging/bcm/Transmit.c
deleted file mode 100644
index 622a482e9826..000000000000
--- a/drivers/staging/bcm/Transmit.c
+++ /dev/null
@@ -1,271 +0,0 @@
1/**
2 * @file Transmit.c
3 * @defgroup tx_functions Transmission
4 * @section Queueing
5 * @dot
6 * digraph transmit1 {
7 * node[shape=box]
8 * edge[weight=5;color=red]
9 *
10 * bcm_transmit->GetPacketQueueIndex[label="IP Packet"]
11 * GetPacketQueueIndex->IpVersion4[label="IPV4"]
12 * GetPacketQueueIndex->IpVersion6[label="IPV6"]
13 * }
14 *
15 * @enddot
16 *
17 * @section De-Queueing
18 * @dot
19 * digraph transmit2 {
20 * node[shape=box]
21 * edge[weight=5;color=red]
22 * interrupt_service_thread->transmit_packets
23 * tx_pkt_hdler->transmit_packets
24 * transmit_packets->CheckAndSendPacketFromIndex
25 * transmit_packets->UpdateTokenCount
26 * CheckAndSendPacketFromIndex->PruneQueue
27 * CheckAndSendPacketFromIndex->IsPacketAllowedForFlow
28 * CheckAndSendPacketFromIndex->SendControlPacket[label="control pkt"]
29 * SendControlPacket->bcm_cmd53
30 * CheckAndSendPacketFromIndex->SendPacketFromQueue[label="data pkt"]
31 * SendPacketFromQueue->SetupNextSend->bcm_cmd53
32 * }
33 * @enddot
34 */
35
36#include "headers.h"
37
38/**
39 * @ingroup ctrl_pkt_functions
40 * This function dispatches control packet to the h/w interface
41 * @return zero(success) or -ve value(failure)
42 */
43int SendControlPacket(struct bcm_mini_adapter *Adapter, char *pControlPacket)
44{
45 struct bcm_leader *PLeader = (struct bcm_leader *)pControlPacket;
46
47 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL, "Tx");
48 if (!pControlPacket || !Adapter) {
49 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL,
50 "Got NULL Control Packet or Adapter");
51 return STATUS_FAILURE;
52 }
53 if ((atomic_read(&Adapter->CurrNumFreeTxDesc) <
54 ((PLeader->PLength-1)/MAX_DEVICE_DESC_SIZE)+1)) {
55 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL,
56 "NO FREE DESCRIPTORS TO SEND CONTROL PACKET");
57 return STATUS_FAILURE;
58 }
59
60 /* Update the netdevice statistics */
61 /* Dump Packet */
62 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL,
63 "Leader Status: %x", PLeader->Status);
64 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL,
65 "Leader VCID: %x", PLeader->Vcid);
66 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL,
67 "Leader Length: %x", PLeader->PLength);
68 if (Adapter->device_removed)
69 return 0;
70
71 if (netif_msg_pktdata(Adapter))
72 print_hex_dump(KERN_DEBUG, PFX "tx control: ", DUMP_PREFIX_NONE,
73 16, 1, pControlPacket,
74 PLeader->PLength + LEADER_SIZE, 0);
75
76 Adapter->interface_transmit(Adapter->pvInterfaceAdapter,
77 pControlPacket,
78 (PLeader->PLength + LEADER_SIZE));
79
80 atomic_dec(&Adapter->CurrNumFreeTxDesc);
81 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_CONTROL, DBG_LVL_ALL,
82 "<=========");
83 return STATUS_SUCCESS;
84}
85
86/**
87 * @ingroup tx_functions
88 * This function despatches the IP packets with the given vcid
89 * to the target via the host h/w interface.
90 * @return zero(success) or -ve value(failure)
91 */
92int SetupNextSend(struct bcm_mini_adapter *Adapter,
93 struct sk_buff *Packet, USHORT Vcid)
94{
95 int status = 0;
96 bool bHeaderSupressionEnabled = false;
97 B_UINT16 uiClassifierRuleID;
98 u16 QueueIndex = skb_get_queue_mapping(Packet);
99 struct bcm_packet_info *curr_packet_info =
100 &Adapter->PackInfo[QueueIndex];
101 struct bcm_leader Leader = {0};
102
103 if (Packet->len > MAX_DEVICE_DESC_SIZE) {
104 status = STATUS_FAILURE;
105 goto errExit;
106 }
107
108 /* Get the Classifier Rule ID */
109 uiClassifierRuleID = *((UINT32 *) (Packet->cb) +
110 SKB_CB_CLASSIFICATION_OFFSET);
111
112 bHeaderSupressionEnabled = curr_packet_info->bHeaderSuppressionEnabled &
113 Adapter->bPHSEnabled;
114
115 if (Adapter->device_removed) {
116 status = STATUS_FAILURE;
117 goto errExit;
118 }
119
120 status = PHSTransmit(Adapter, &Packet, Vcid, uiClassifierRuleID,
121 bHeaderSupressionEnabled,
122 (UINT *)&Packet->len,
123 curr_packet_info->bEthCSSupport);
124
125 if (status != STATUS_SUCCESS) {
126 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, NEXT_SEND, DBG_LVL_ALL,
127 "PHS Transmit failed..\n");
128 goto errExit;
129 }
130
131 Leader.Vcid = Vcid;
132
133 if (TCP_ACK == *((UINT32 *) (Packet->cb) + SKB_CB_TCPACK_OFFSET))
134 Leader.Status = LEADER_STATUS_TCP_ACK;
135 else
136 Leader.Status = LEADER_STATUS;
137
138 if (curr_packet_info->bEthCSSupport) {
139 Leader.PLength = Packet->len;
140 if (skb_headroom(Packet) < LEADER_SIZE) {
141 status = skb_cow(Packet, LEADER_SIZE);
142 if (status) {
143 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, NEXT_SEND,
144 DBG_LVL_ALL,
145 "bcm_transmit : Failed To Increase headRoom\n");
146 goto errExit;
147 }
148 }
149 skb_push(Packet, LEADER_SIZE);
150 memcpy(Packet->data, &Leader, LEADER_SIZE);
151 } else {
152 Leader.PLength = Packet->len - ETH_HLEN;
153 memcpy((struct bcm_leader *)skb_pull(Packet,
154 (ETH_HLEN - LEADER_SIZE)),
155 &Leader,
156 LEADER_SIZE);
157 }
158
159 status = Adapter->interface_transmit(Adapter->pvInterfaceAdapter,
160 Packet->data,
161 (Leader.PLength + LEADER_SIZE));
162 if (status) {
163 ++Adapter->dev->stats.tx_errors;
164 if (netif_msg_tx_err(Adapter))
165 pr_info(PFX "%s: transmit error %d\n",
166 Adapter->dev->name,
167 status);
168 } else {
169 struct net_device_stats *netstats = &Adapter->dev->stats;
170
171 curr_packet_info->uiTotalTxBytes += Leader.PLength;
172
173 netstats->tx_bytes += Leader.PLength;
174 ++netstats->tx_packets;
175
176 curr_packet_info->uiCurrentTokenCount -= Leader.PLength << 3;
177 curr_packet_info->uiSentBytes += (Packet->len);
178 curr_packet_info->uiSentPackets++;
179 curr_packet_info->NumOfPacketsSent++;
180
181 atomic_dec(&curr_packet_info->uiPerSFTxResourceCount);
182 curr_packet_info->uiThisPeriodSentBytes += Leader.PLength;
183 }
184
185 atomic_dec(&Adapter->CurrNumFreeTxDesc);
186
187errExit:
188 dev_kfree_skb(Packet);
189 return status;
190}
191
192static int tx_pending(struct bcm_mini_adapter *Adapter)
193{
194 return (atomic_read(&Adapter->TxPktAvail)
195 && MINIMUM_PENDING_DESCRIPTORS <
196 atomic_read(&Adapter->CurrNumFreeTxDesc))
197 || Adapter->device_removed || (1 == Adapter->downloadDDR);
198}
199
200/**
201 * @ingroup tx_functions
202 * Transmit thread
203 */
204int tx_pkt_handler(struct bcm_mini_adapter *Adapter)
205{
206 int status = 0;
207
208 while (!kthread_should_stop()) {
209 /* FIXME - the timeout looks like workaround
210 * for racey usage of TxPktAvail
211 */
212 if (Adapter->LinkUpStatus)
213 wait_event_timeout(Adapter->tx_packet_wait_queue,
214 tx_pending(Adapter),
215 msecs_to_jiffies(10));
216 else
217 wait_event_interruptible(Adapter->tx_packet_wait_queue,
218 tx_pending(Adapter));
219
220 if (Adapter->device_removed)
221 break;
222
223 if (Adapter->downloadDDR == 1) {
224 Adapter->downloadDDR += 1;
225 status = download_ddr_settings(Adapter);
226 if (status)
227 pr_err(PFX "DDR DOWNLOAD FAILED! %d\n", status);
228 continue;
229 }
230
231 /* Check end point for halt/stall. */
232 if (Adapter->bEndPointHalted == TRUE) {
233 Bcm_clear_halt_of_endpoints(Adapter);
234 Adapter->bEndPointHalted = false;
235 StartInterruptUrb((struct bcm_interface_adapter *)
236 (Adapter->pvInterfaceAdapter));
237 }
238
239 if (Adapter->LinkUpStatus && !Adapter->IdleMode) {
240 if (atomic_read(&Adapter->TotalPacketCount))
241 update_per_sf_desc_cnts(Adapter);
242 }
243
244 if (atomic_read(&Adapter->CurrNumFreeTxDesc) &&
245 Adapter->LinkStatus == SYNC_UP_REQUEST &&
246 !Adapter->bSyncUpRequestSent) {
247
248 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_PACKETS,
249 DBG_LVL_ALL, "Calling LinkMessage");
250 LinkMessage(Adapter);
251 }
252
253 if ((Adapter->IdleMode || Adapter->bShutStatus) &&
254 atomic_read(&Adapter->TotalPacketCount)) {
255 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX,
256 TX_PACKETS, DBG_LVL_ALL,
257 "Device in Low Power mode...waking up");
258 Adapter->usIdleModePattern = ABORT_IDLE_MODE;
259 Adapter->bWakeUpDevice = TRUE;
260 wake_up(&Adapter->process_rx_cntrlpkt);
261 }
262
263 transmit_packets(Adapter);
264 atomic_set(&Adapter->TxPktAvail, 0);
265 }
266
267 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_TX, TX_PACKETS, DBG_LVL_ALL,
268 "Exiting the tx thread..\n");
269 Adapter->transmit_packet_thread = NULL;
270 return 0;
271}
diff --git a/drivers/staging/bcm/Typedefs.h b/drivers/staging/bcm/Typedefs.h
deleted file mode 100644
index 90b3b25dd606..000000000000
--- a/drivers/staging/bcm/Typedefs.h
+++ /dev/null
@@ -1,47 +0,0 @@
1/****************************
2* Typedefs.h
3****************************/
4#ifndef __TYPEDEFS_H__
5#define __TYPEDEFS_H__
6#define STATUS_SUCCESS 0
7#define STATUS_FAILURE -1
8
9
10#define TRUE 1
11
12
13typedef char CHAR;
14typedef int INT;
15typedef short SHORT;
16typedef long LONG;
17typedef void VOID;
18
19typedef unsigned char UCHAR;
20typedef unsigned char B_UINT8;
21typedef unsigned short USHORT;
22typedef unsigned short B_UINT16;
23typedef unsigned int UINT;
24typedef unsigned int B_UINT32;
25typedef unsigned long ULONG;
26typedef unsigned long DWORD;
27
28typedef char *PCHAR;
29typedef short *PSHORT;
30typedef int *PINT;
31typedef long *PLONG;
32typedef void *PVOID;
33
34typedef unsigned char *PUCHAR;
35typedef unsigned short *PUSHORT;
36typedef unsigned int *PUINT;
37typedef unsigned long *PULONG;
38typedef unsigned long long ULONG64;
39typedef unsigned long long LARGE_INTEGER;
40typedef unsigned int UINT32;
41#ifndef NULL
42#define NULL 0
43#endif
44
45
46#endif /* __TYPEDEFS_H__ */
47
diff --git a/drivers/staging/bcm/cntrl_SignalingInterface.h b/drivers/staging/bcm/cntrl_SignalingInterface.h
deleted file mode 100644
index 8683c2d4276e..000000000000
--- a/drivers/staging/bcm/cntrl_SignalingInterface.h
+++ /dev/null
@@ -1,311 +0,0 @@
1#ifndef CNTRL_SIGNALING_INTERFACE_
2#define CNTRL_SIGNALING_INTERFACE_
3
4#define DSA_REQ 11
5#define DSA_RSP 12
6#define DSA_ACK 13
7#define DSC_REQ 14
8#define DSC_RSP 15
9#define DSC_ACK 16
10#define DSD_REQ 17
11#define DSD_RSP 18
12#define DSD_ACK 19
13#define MAX_CLASSIFIERS_IN_SF 4
14
15#define MAX_STRING_LEN 20
16#define MAX_PHS_LENGTHS 255
17#define VENDOR_PHS_PARAM_LENGTH 10
18#define MAX_NUM_ACTIVE_BS 10
19#define AUTH_TOKEN_LENGTH 10
20#define NUM_HARQ_CHANNELS 16 /* Changed from 10 to 16 to accommodate all HARQ channels */
21#define VENDOR_CLASSIFIER_PARAM_LENGTH 1 /* Changed the size to 1 byte since we dnt use it */
22#define VENDOR_SPECIF_QOS_PARAM 1
23#define VENDOR_PHS_PARAM_LENGTH 10
24#define MBS_CONTENTS_ID_LENGTH 10
25#define GLOBAL_SF_CLASSNAME_LENGTH 6
26
27#define TYPE_OF_SERVICE_LENGTH 3
28#define IP_MASKED_SRC_ADDRESS_LENGTH 32
29#define IP_MASKED_DEST_ADDRESS_LENGTH 32
30#define PROTOCOL_SRC_PORT_RANGE_LENGTH 4
31#define PROTOCOL_DEST_PORT_RANGE_LENGTH 4
32#define ETHERNET_DEST_MAC_ADDR_LENGTH 12
33#define ETHERNET_SRC_MAC_ADDR_LENGTH 12
34#define NUM_ETHERTYPE_BYTES 3
35#define NUM_IPV6_FLOWLABLE_BYTES 3
36
37struct bcm_packet_class_rules {
38 /* 16bit UserPriority Of The Service Flow */
39 u16 u16UserPriority;
40 /* 16bit VLANID Of The Service Flow */
41 u16 u16VLANID;
42 /* 16bit Packet Classification RuleIndex Of The Service Flow */
43 u16 u16PacketClassificationRuleIndex;
44 /* 8bit Classifier Rule Priority Of The Service Flow */
45 u8 u8ClassifierRulePriority;
46 /* Length of IP TypeOfService field */
47 u8 u8IPTypeOfServiceLength;
48 /* 3bytes IP TypeOfService */
49 u8 u8IPTypeOfService[TYPE_OF_SERVICE_LENGTH];
50 /* Protocol used in classification of Service Flow */
51 u8 u8Protocol;
52 /* Length of IP Masked Source Address */
53 u8 u8IPMaskedSourceAddressLength;
54 /* IP Masked Source Address used in classification for the Service Flow */
55 u8 u8IPMaskedSourceAddress[IP_MASKED_SRC_ADDRESS_LENGTH];
56 /* Length of IP Destination Address */
57 u8 u8IPDestinationAddressLength;
58 /* IP Destination Address used in classification for the Service Flow */
59 u8 u8IPDestinationAddress[IP_MASKED_DEST_ADDRESS_LENGTH];
60 /* Length of Protocol Source Port Range */
61 u8 u8ProtocolSourcePortRangeLength;
62 /* Protocol Source Port Range used in the Service Flow */
63 u8 u8ProtocolSourcePortRange[PROTOCOL_SRC_PORT_RANGE_LENGTH];
64 /* Length of Protocol Dest Port Range */
65 u8 u8ProtocolDestPortRangeLength;
66 /* Protocol Dest Port Range used in the Service Flow */
67 u8 u8ProtocolDestPortRange[PROTOCOL_DEST_PORT_RANGE_LENGTH];
68 /* Length of Ethernet Destination MAC Address */
69 u8 u8EthernetDestMacAddressLength;
70 /* Ethernet Destination MAC Address used in classification of the Service Flow */
71 u8 u8EthernetDestMacAddress[ETHERNET_DEST_MAC_ADDR_LENGTH];
72 /* Length of Ethernet Source MAC Address */
73 u8 u8EthernetSourceMACAddressLength;
74 /* Ethernet Source MAC Address used in classification of the Service Flow */
75 u8 u8EthernetSourceMACAddress[ETHERNET_SRC_MAC_ADDR_LENGTH];
76 /* Length of Ethertype */
77 u8 u8EthertypeLength;
78 /* 3bytes Ethertype Of The Service Flow */
79 u8 u8Ethertype[NUM_ETHERTYPE_BYTES];
80 /* 8bit Associated PHSI Of The Service Flow */
81 u8 u8AssociatedPHSI;
82 /* Length of Vendor Specific Classifier Param length Of The Service Flow */
83 u8 u8VendorSpecificClassifierParamLength;
84 /* Vendor Specific Classifier Param Of The Service Flow */
85 u8 u8VendorSpecificClassifierParam[VENDOR_CLASSIFIER_PARAM_LENGTH];
86 /* Length Of IPv6 Flow Lable of the Service Flow */
87 u8 u8IPv6FlowLableLength;
88 /* IPv6 Flow Lable Of The Service Flow */
89 u8 u8IPv6FlowLable[NUM_IPV6_FLOWLABLE_BYTES];
90 /* Action associated with the classifier rule */
91 u8 u8ClassifierActionRule;
92 u16 u16ValidityBitMap;
93};
94
95struct bcm_phs_rules {
96 /* 8bit PHS Index Of The Service Flow */
97 u8 u8PHSI;
98 /* PHSF Length Of The Service Flow */
99 u8 u8PHSFLength;
100 /* String of bytes containing header information to be suppressed by the sending CS and reconstructed by the receiving CS */
101 u8 u8PHSF[MAX_PHS_LENGTHS];
102 /* PHSM Length Of The Service Flow */
103 u8 u8PHSMLength;
104 /* PHS Mask for the SF */
105 u8 u8PHSM[MAX_PHS_LENGTHS];
106 /* 8bit Total number of bytes to be suppressed for the Service Flow */
107 u8 u8PHSS;
108 /* 8bit Indicates whether or not Packet Header contents need to be verified prior to suppression */
109 u8 u8PHSV;
110 /* Vendor Specific PHS param Length Of The Service Flow */
111 u8 u8VendorSpecificPHSParamsLength;
112 /* Vendor Specific PHS param Of The Service Flow */
113 u8 u8VendorSpecificPHSParams[VENDOR_PHS_PARAM_LENGTH];
114 u8 u8Padding[2];
115};
116
117struct bcm_convergence_types {
118 /* 8bit Phs Classfier Action Of The Service Flow */
119 u8 u8ClassfierDSCAction;
120 /* 8bit Phs DSC Action Of The Service Flow */
121 u8 u8PhsDSCAction;
122 /* 16bit Padding */
123 u8 u8Padding[2];
124 /* Packet classification rules structure */
125 struct bcm_packet_class_rules cCPacketClassificationRule;
126 /* Payload header suppression rules structure */
127 struct bcm_phs_rules cPhsRule;
128};
129
130struct bcm_connect_mgr_params {
131 /* 32bitSFID Of The Service Flow */
132 u32 u32SFID;
133 /* 32bit Maximum Sustained Traffic Rate of the Service Flow */
134 u32 u32MaxSustainedTrafficRate;
135 /* 32bit Maximum Traffic Burst allowed for the Service Flow */
136 u32 u32MaxTrafficBurst;
137 /* 32bit Minimum Reserved Traffic Rate of the Service Flow */
138 u32 u32MinReservedTrafficRate;
139 /* 32bit Tolerated Jitter of the Service Flow */
140 u32 u32ToleratedJitter;
141 /* 32bit Maximum Latency of the Service Flow */
142 u32 u32MaximumLatency;
143 /* 16bitCID Of The Service Flow */
144 u16 u16CID;
145 /* 16bit SAID on which the service flow being set up shall be mapped */
146 u16 u16TargetSAID;
147 /* 16bit ARQ window size negotiated */
148 u16 u16ARQWindowSize;
149 /* 16bit Total Tx delay incl sending, receiving & processing delays */
150 u16 u16ARQRetryTxTimeOut;
151 /* 16bit Total Rx delay incl sending, receiving & processing delays */
152 u16 u16ARQRetryRxTimeOut;
153 /* 16bit ARQ block lifetime */
154 u16 u16ARQBlockLifeTime;
155 /* 16bit ARQ Sync loss timeout */
156 u16 u16ARQSyncLossTimeOut;
157 /* 16bit ARQ Purge timeout */
158 u16 u16ARQRxPurgeTimeOut;
159 /* TODO::Remove this once we move to a new CORR2 driver
160 * brief Size of an ARQ block
161 */
162 u16 u16ARQBlockSize;
163 /* #endif */
164 /* 16bit Nominal interval b/w consecutive SDU arrivals at MAC SAP */
165 u16 u16SDUInterArrivalTime;
166 /* 16bit Specifies the time base for rate measurement */
167 u16 u16TimeBase;
168 /* 16bit Interval b/w Successive Grant oppurtunities */
169 u16 u16UnsolicitedGrantInterval;
170 /* 16bit Interval b/w Successive Polling grant oppurtunities */
171 u16 u16UnsolicitedPollingInterval;
172 /* internal var to get the overhead */
173 u16 u16MacOverhead;
174 /* MBS contents Identifier */
175 u16 u16MBSContentsID[MBS_CONTENTS_ID_LENGTH];
176 /* MBS contents Identifier length */
177 u8 u8MBSContentsIDLength;
178 /* ServiceClassName Length Of The Service Flow */
179 u8 u8ServiceClassNameLength;
180 /* 32bytes ServiceClassName Of The Service Flow */
181 u8 u8ServiceClassName[32];
182 /* 8bit Indicates whether or not MBS service is requested for this Serivce Flow */
183 u8 u8MBSService;
184 /* 8bit QOS Parameter Set specifies proper application of QoS parameters to Provisioned, Admitted and Active sets */
185 u8 u8QosParamSet;
186 /* 8bit Traffic Priority Of the Service Flow */
187 u8 u8TrafficPriority;
188 /* 8bit Uplink Grant Scheduling Type of The Service Flow */
189 u8 u8ServiceFlowSchedulingType;
190 /* 8bit Request transmission Policy of the Service Flow */
191 u8 u8RequesttransmissionPolicy;
192 /* 8bit Specifies whether SDUs for this Service flow are of FixedLength or Variable length */
193 u8 u8FixedLengthVSVariableLengthSDUIndicator;
194 /* 8bit Length of the SDU for a fixed length SDU service flow */
195 u8 u8SDUSize;
196 /* 8bit Indicates whether or not ARQ is requested for this connection */
197 u8 u8ARQEnable;
198 /* < 8bit Indicates whether or not data has tobe delivered in order to higher layer */
199 u8 u8ARQDeliverInOrder;
200 /* 8bit Receiver ARQ ACK processing time */
201 u8 u8RxARQAckProcessingTime;
202 /* 8bit Convergence Sublayer Specification Of The Service Flow */
203 u8 u8CSSpecification;
204 /* 8 bit Type of data delivery service */
205 u8 u8TypeOfDataDeliveryService;
206 /* 8bit Specifies whether a service flow may generate Paging */
207 u8 u8PagingPreference;
208 /* 8bit Indicates the MBS Zone through which the connection or virtual connection is valid */
209 u8 u8MBSZoneIdentifierassignment;
210 /* 8bit Specifies whether traffic on SF should generate MOB_TRF_IND to MS in sleep mode */
211 u8 u8TrafficIndicationPreference;
212 /* 8bit Speciifes the length of predefined Global QoS parameter set encoding for this SF */
213 u8 u8GlobalServicesClassNameLength;
214 /* 6 byte Speciifes the predefined Global QoS parameter set encoding for this SF */
215 u8 u8GlobalServicesClassName[GLOBAL_SF_CLASSNAME_LENGTH];
216 /* 8bit Indicates whether or not SN feedback is enabled for the conn */
217 u8 u8SNFeedbackEnabled;
218 /* Indicates the size of the Fragment Sequence Number for the connection */
219 u8 u8FSNSize;
220 /* 8bit Number of CIDs in active BS list */
221 u8 u8CIDAllocation4activeBSsLength;
222 /* CIDs of BS in the active list */
223 u8 u8CIDAllocation4activeBSs[MAX_NUM_ACTIVE_BS];
224 /* Specifies if PDU extended subheader should be applied on every PDU on this conn */
225 u8 u8PDUSNExtendedSubheader4HarqReordering;
226 /* 8bit Specifies whether the connection uses HARQ or not */
227 u8 u8HARQServiceFlows;
228 /* Specifies the length of Authorization token */
229 u8 u8AuthTokenLength;
230 /* Specifies the Authorization token */
231 u8 u8AuthToken[AUTH_TOKEN_LENGTH];
232 /* specifes Number of HARQ channels used to carry data length */
233 u8 u8HarqChannelMappingLength;
234 /* specifes HARQ channels used to carry data */
235 u8 u8HARQChannelMapping[NUM_HARQ_CHANNELS];
236 /* 8bit Length of Vendor Specific QoS Params */
237 u8 u8VendorSpecificQoSParamLength;
238 /* 1byte Vendor Specific QoS Param Of The Service Flow */
239 u8 u8VendorSpecificQoSParam[VENDOR_SPECIF_QOS_PARAM];
240 /* indicates total classifiers in the SF */
241 u8 u8TotalClassifiers; /* < Total number of valid classifiers */
242 u8 bValid; /* < Validity flag */
243 u8 u8Padding; /* < Padding byte */
244 /*
245 * Structure for Convergence SubLayer Types with a maximum of 4 classifiers
246 */
247 struct bcm_convergence_types cConvergenceSLTypes[MAX_CLASSIFIERS_IN_SF];
248};
249
250struct bcm_add_request {
251 u8 u8Type; /* < Type */
252 u8 eConnectionDir; /* < Connection direction */
253 /* brief 16 bit TID */
254 u16 u16TID; /* < 16bit TID */
255 /* brief 16bitCID */
256 u16 u16CID; /* < 16bit CID */
257 /* brief 16bitVCID */
258 u16 u16VCID; /* < 16bit VCID */
259 struct bcm_connect_mgr_params *psfParameterSet; /* < connection manager parameters */
260};
261
262struct bcm_add_indication {
263 u8 u8Type; /* < Type */
264 u8 eConnectionDir; /* < Connection Direction */
265 /* brief 16 bit TID */
266 u16 u16TID; /* < TID */
267 /* brief 16bitCID */
268 u16 u16CID; /* < 16bitCID */
269 /* brief 16bitVCID */
270 u16 u16VCID; /* < 16bitVCID */
271 struct bcm_connect_mgr_params *psfAuthorizedSet; /* Authorized set of connection manager parameters */
272 struct bcm_connect_mgr_params *psfAdmittedSet; /* Admitted set of connection manager parameters */
273 struct bcm_connect_mgr_params *psfActiveSet; /* Activeset of connection manager parameters */
274 u8 u8CC; /* <Confirmation Code */
275 u8 u8Padd; /* < 8-bit Padding */
276 u16 u16Padd; /* < 16 bit Padding */
277};
278
279struct bcm_del_request {
280 u8 u8Type; /* < Type */
281 u8 u8Padding; /* < Padding byte */
282 u16 u16TID; /* < TID */
283 /* brief 32bitSFID */
284 u32 u32SFID; /* < SFID */
285};
286
287struct bcm_del_indication {
288 u8 u8Type; /* < Type */
289 u8 u8Padding; /* < Padding */
290 u16 u16TID; /* < TID */
291 /* brief 16bitCID */
292 u16 u16CID; /* < CID */
293 /* brief 16bitVCID */
294 u16 u16VCID; /* < VCID */
295 /* brief 32bitSFID */
296 u32 u32SFID; /* < SFID */
297 /* brief 8bit Confirmation code */
298 u8 u8ConfirmationCode; /* < Confirmation code */
299 u8 u8Padding1[3]; /* < 3 byte Padding */
300};
301
302struct bcm_stim_sfhostnotify {
303 u32 SFID; /* SFID of the service flow */
304 u16 newCID; /* the new/changed CID */
305 u16 VCID; /* Get new Vcid if the flow has been made active in CID update TLV, but was inactive earlier or the orig vcid */
306 u8 RetainSF; /* Indication to Host if the SF is to be retained or deleted; if TRUE-retain else delete */
307 u8 QoSParamSet; /* QoS paramset of the retained SF */
308 u16 u16reserved; /* For byte alignment */
309};
310
311#endif
diff --git a/drivers/staging/bcm/headers.h b/drivers/staging/bcm/headers.h
deleted file mode 100644
index a7d4af5ea9a7..000000000000
--- a/drivers/staging/bcm/headers.h
+++ /dev/null
@@ -1,78 +0,0 @@
1
2/*******************************************************************
3* Headers.h
4*******************************************************************/
5#ifndef __HEADERS_H__
6#define __HEADERS_H__
7
8#include <linux/kernel.h>
9#include <linux/module.h>
10#include <linux/types.h>
11#include <linux/netdevice.h>
12#include <linux/skbuff.h>
13#include <linux/socket.h>
14#include <linux/netfilter.h>
15#include <linux/netfilter_ipv4.h>
16#include <linux/if_arp.h>
17#include <linux/delay.h>
18#include <linux/spinlock.h>
19#include <linux/fs.h>
20#include <linux/file.h>
21#include <linux/string.h>
22#include <linux/etherdevice.h>
23#include <linux/wait.h>
24#include <linux/proc_fs.h>
25#include <linux/interrupt.h>
26#include <linux/stddef.h>
27#include <linux/stat.h>
28#include <linux/fcntl.h>
29#include <linux/unistd.h>
30#include <linux/sched.h>
31#include <linux/mm.h>
32#include <linux/pagemap.h>
33#include <linux/kthread.h>
34#include <linux/tcp.h>
35#include <linux/udp.h>
36#include <linux/usb.h>
37#include <linux/uaccess.h>
38#include <net/ip.h>
39
40#include "Typedefs.h"
41#include "Macros.h"
42#include "HostMIBSInterface.h"
43#include "cntrl_SignalingInterface.h"
44#include "PHSDefines.h"
45#include "led_control.h"
46#include "Ioctl.h"
47#include "nvm.h"
48#include "target_params.h"
49#include "Adapter.h"
50#include "CmHost.h"
51#include "DDRInit.h"
52#include "Debug.h"
53#include "IPv6ProtocolHdr.h"
54#include "PHSModule.h"
55#include "Protocol.h"
56#include "Prototypes.h"
57#include "Queue.h"
58#include "vendorspecificextn.h"
59
60#include "InterfaceMacros.h"
61#include "InterfaceAdapter.h"
62#include "InterfaceIsr.h"
63#include "InterfaceMisc.h"
64#include "InterfaceRx.h"
65#include "InterfaceTx.h"
66#include "InterfaceIdleMode.h"
67#include "InterfaceInit.h"
68
69#define DRV_NAME "beceem"
70#define DEV_NAME "tarang"
71#define DRV_DESCRIPTION "Beceem Communications Inc. WiMAX driver"
72#define DRV_COPYRIGHT "Copyright 2010. Beceem Communications Inc"
73#define DRV_VERSION "5.2.45"
74#define PFX DRV_NAME " "
75
76extern struct class *bcm_class;
77
78#endif
diff --git a/drivers/staging/bcm/hostmibs.c b/drivers/staging/bcm/hostmibs.c
deleted file mode 100644
index f9b08a5d8ce8..000000000000
--- a/drivers/staging/bcm/hostmibs.c
+++ /dev/null
@@ -1,164 +0,0 @@
1/*
2 * File Name: hostmibs.c
3 *
4 * Author: Beceem Communications Pvt. Ltd
5 *
6 * Abstract: This file contains the routines to copy the statistics used by
7 * the driver to the Host MIBS structure and giving the same to Application.
8 */
9
10#include "headers.h"
11
12INT ProcessGetHostMibs(struct bcm_mini_adapter *Adapter,
13 struct bcm_host_stats_mibs *pstHostMibs)
14{
15 struct bcm_phs_entry *pstServiceFlowEntry = NULL;
16 struct bcm_phs_rule *pstPhsRule = NULL;
17 struct bcm_phs_classifier_table *pstClassifierTable = NULL;
18 struct bcm_phs_classifier_entry *pstClassifierRule = NULL;
19 struct bcm_phs_extension *pDeviceExtension = &Adapter->stBCMPhsContext;
20 struct bcm_mibs_host_info *host_info;
21 UINT nClassifierIndex = 0;
22 UINT nPhsTableIndex = 0;
23 UINT nSfIndex = 0;
24 UINT uiIndex = 0;
25
26 if (pDeviceExtension == NULL) {
27 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, HOST_MIBS,
28 DBG_LVL_ALL, "Invalid Device Extension\n");
29 return STATUS_FAILURE;
30 }
31
32 /* Copy the classifier Table */
33 for (nClassifierIndex = 0; nClassifierIndex < MAX_CLASSIFIERS;
34 nClassifierIndex++) {
35 if (Adapter->astClassifierTable[nClassifierIndex].bUsed == TRUE)
36 memcpy(&pstHostMibs->astClassifierTable[nClassifierIndex],
37 &Adapter->astClassifierTable[nClassifierIndex],
38 sizeof(struct bcm_mibs_classifier_rule));
39 }
40
41 /* Copy the SF Table */
42 for (nSfIndex = 0; nSfIndex < NO_OF_QUEUES; nSfIndex++) {
43 if (Adapter->PackInfo[nSfIndex].bValid) {
44 memcpy(&pstHostMibs->astSFtable[nSfIndex],
45 &Adapter->PackInfo[nSfIndex],
46 sizeof(struct bcm_mibs_table));
47 } else {
48 /* If index in not valid,
49 * don't process this for the PHS table.
50 * Go For the next entry.
51 */
52 continue;
53 }
54
55 /* Retrieve the SFID Entry Index for requested Service Flow */
56 if (PHS_INVALID_TABLE_INDEX ==
57 GetServiceFlowEntry(pDeviceExtension->
58 pstServiceFlowPhsRulesTable,
59 Adapter->PackInfo[nSfIndex].
60 usVCID_Value, &pstServiceFlowEntry))
61
62 continue;
63
64 pstClassifierTable = pstServiceFlowEntry->pstClassifierTable;
65
66 for (uiIndex = 0; uiIndex < MAX_PHSRULE_PER_SF; uiIndex++) {
67 pstClassifierRule = &pstClassifierTable->stActivePhsRulesList[uiIndex];
68
69 if (pstClassifierRule->bUsed) {
70 pstPhsRule = pstClassifierRule->pstPhsRule;
71
72 pstHostMibs->astPhsRulesTable[nPhsTableIndex].
73 ulSFID = Adapter->PackInfo[nSfIndex].ulSFID;
74
75 memcpy(&pstHostMibs->astPhsRulesTable[nPhsTableIndex].u8PHSI,
76 &pstPhsRule->u8PHSI,
77 sizeof(struct bcm_phs_rule));
78 nPhsTableIndex++;
79
80 }
81
82 }
83
84 }
85
86 /* Copy other Host Statistics parameters */
87 host_info = &pstHostMibs->stHostInfo;
88 host_info->GoodTransmits = Adapter->dev->stats.tx_packets;
89 host_info->GoodReceives = Adapter->dev->stats.rx_packets;
90 host_info->CurrNumFreeDesc = atomic_read(&Adapter->CurrNumFreeTxDesc);
91 host_info->BEBucketSize = Adapter->BEBucketSize;
92 host_info->rtPSBucketSize = Adapter->rtPSBucketSize;
93 host_info->TimerActive = Adapter->TimerActive;
94 host_info->u32TotalDSD = Adapter->u32TotalDSD;
95
96 memcpy(host_info->aTxPktSizeHist, Adapter->aTxPktSizeHist,
97 sizeof(UINT32) * MIBS_MAX_HIST_ENTRIES);
98 memcpy(host_info->aRxPktSizeHist, Adapter->aRxPktSizeHist,
99 sizeof(UINT32) * MIBS_MAX_HIST_ENTRIES);
100
101 return STATUS_SUCCESS;
102}
103
104VOID GetDroppedAppCntrlPktMibs(struct bcm_host_stats_mibs *pstHostMibs,
105 struct bcm_tarang_data *pTarang)
106{
107 memcpy(&(pstHostMibs->stDroppedAppCntrlMsgs),
108 &(pTarang->stDroppedAppCntrlMsgs),
109 sizeof(struct bcm_mibs_dropped_cntrl_msg));
110}
111
112VOID CopyMIBSExtendedSFParameters(struct bcm_mini_adapter *Adapter,
113 struct bcm_connect_mgr_params *psfLocalSet,
114 UINT uiSearchRuleIndex)
115{
116 struct bcm_mibs_parameters *t =
117 &Adapter->PackInfo[uiSearchRuleIndex].stMibsExtServiceFlowTable;
118
119 t->wmanIfSfid = psfLocalSet->u32SFID;
120 t->wmanIfCmnCpsMaxSustainedRate =
121 psfLocalSet->u32MaxSustainedTrafficRate;
122 t->wmanIfCmnCpsMaxTrafficBurst = psfLocalSet->u32MaxTrafficBurst;
123 t->wmanIfCmnCpsMinReservedRate = psfLocalSet->u32MinReservedTrafficRate;
124 t->wmanIfCmnCpsToleratedJitter = psfLocalSet->u32ToleratedJitter;
125 t->wmanIfCmnCpsMaxLatency = psfLocalSet->u32MaximumLatency;
126 t->wmanIfCmnCpsFixedVsVariableSduInd =
127 psfLocalSet->u8FixedLengthVSVariableLengthSDUIndicator;
128 t->wmanIfCmnCpsFixedVsVariableSduInd =
129 ntohl(t->wmanIfCmnCpsFixedVsVariableSduInd);
130 t->wmanIfCmnCpsSduSize = psfLocalSet->u8SDUSize;
131 t->wmanIfCmnCpsSduSize = ntohl(t->wmanIfCmnCpsSduSize);
132 t->wmanIfCmnCpsSfSchedulingType =
133 psfLocalSet->u8ServiceFlowSchedulingType;
134 t->wmanIfCmnCpsSfSchedulingType =
135 ntohl(t->wmanIfCmnCpsSfSchedulingType);
136 t->wmanIfCmnCpsArqEnable = psfLocalSet->u8ARQEnable;
137 t->wmanIfCmnCpsArqEnable = ntohl(t->wmanIfCmnCpsArqEnable);
138 t->wmanIfCmnCpsArqWindowSize = ntohs(psfLocalSet->u16ARQWindowSize);
139 t->wmanIfCmnCpsArqWindowSize = ntohl(t->wmanIfCmnCpsArqWindowSize);
140 t->wmanIfCmnCpsArqBlockLifetime =
141 ntohs(psfLocalSet->u16ARQBlockLifeTime);
142 t->wmanIfCmnCpsArqBlockLifetime =
143 ntohl(t->wmanIfCmnCpsArqBlockLifetime);
144 t->wmanIfCmnCpsArqSyncLossTimeout =
145 ntohs(psfLocalSet->u16ARQSyncLossTimeOut);
146 t->wmanIfCmnCpsArqSyncLossTimeout =
147 ntohl(t->wmanIfCmnCpsArqSyncLossTimeout);
148 t->wmanIfCmnCpsArqDeliverInOrder = psfLocalSet->u8ARQDeliverInOrder;
149 t->wmanIfCmnCpsArqDeliverInOrder =
150 ntohl(t->wmanIfCmnCpsArqDeliverInOrder);
151 t->wmanIfCmnCpsArqRxPurgeTimeout =
152 ntohs(psfLocalSet->u16ARQRxPurgeTimeOut);
153 t->wmanIfCmnCpsArqRxPurgeTimeout =
154 ntohl(t->wmanIfCmnCpsArqRxPurgeTimeout);
155 t->wmanIfCmnCpsArqBlockSize = ntohs(psfLocalSet->u16ARQBlockSize);
156 t->wmanIfCmnCpsArqBlockSize = ntohl(t->wmanIfCmnCpsArqBlockSize);
157 t->wmanIfCmnCpsReqTxPolicy = psfLocalSet->u8RequesttransmissionPolicy;
158 t->wmanIfCmnCpsReqTxPolicy = ntohl(t->wmanIfCmnCpsReqTxPolicy);
159 t->wmanIfCmnSfCsSpecification = psfLocalSet->u8CSSpecification;
160 t->wmanIfCmnSfCsSpecification = ntohl(t->wmanIfCmnSfCsSpecification);
161 t->wmanIfCmnCpsTargetSaid = ntohs(psfLocalSet->u16TargetSAID);
162 t->wmanIfCmnCpsTargetSaid = ntohl(t->wmanIfCmnCpsTargetSaid);
163
164}
diff --git a/drivers/staging/bcm/led_control.c b/drivers/staging/bcm/led_control.c
deleted file mode 100644
index 074fc39ed678..000000000000
--- a/drivers/staging/bcm/led_control.c
+++ /dev/null
@@ -1,952 +0,0 @@
1#include "headers.h"
2
3#define STATUS_IMAGE_CHECKSUM_MISMATCH -199
4#define EVENT_SIGNALED 1
5
6static B_UINT16 CFG_CalculateChecksum(B_UINT8 *pu8Buffer, B_UINT32 u32Size)
7{
8 B_UINT16 u16CheckSum = 0;
9
10 while (u32Size--) {
11 u16CheckSum += (B_UINT8)~(*pu8Buffer);
12 pu8Buffer++;
13 }
14 return u16CheckSum;
15}
16
17bool IsReqGpioIsLedInNVM(struct bcm_mini_adapter *Adapter, UINT gpios)
18{
19 INT Status;
20
21 Status = (Adapter->gpioBitMap & gpios) ^ gpios;
22 if (Status)
23 return false;
24 else
25 return TRUE;
26}
27
28static INT LED_Blink(struct bcm_mini_adapter *Adapter,
29 UINT GPIO_Num,
30 UCHAR uiLedIndex,
31 ULONG timeout,
32 INT num_of_time,
33 enum bcm_led_events currdriverstate)
34{
35 int Status = STATUS_SUCCESS;
36 bool bInfinite = false;
37
38 /* Check if num_of_time is -ve. If yes, blink led in infinite loop */
39 if (num_of_time < 0) {
40 bInfinite = TRUE;
41 num_of_time = 1;
42 }
43 while (num_of_time) {
44 if (currdriverstate == Adapter->DriverState)
45 TURN_ON_LED(Adapter, GPIO_Num, uiLedIndex);
46
47 /* Wait for timeout after setting on the LED */
48 Status = wait_event_interruptible_timeout(
49 Adapter->LEDInfo.notify_led_event,
50 currdriverstate != Adapter->DriverState ||
51 kthread_should_stop(),
52 msecs_to_jiffies(timeout));
53
54 if (kthread_should_stop()) {
55 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LED_DUMP_INFO,
56 DBG_LVL_ALL,
57 "Led thread got signal to exit..hence exiting");
58 Adapter->LEDInfo.led_thread_running =
59 BCM_LED_THREAD_DISABLED;
60 TURN_OFF_LED(Adapter, GPIO_Num, uiLedIndex);
61 Status = EVENT_SIGNALED;
62 break;
63 }
64 if (Status) {
65 TURN_OFF_LED(Adapter, GPIO_Num, uiLedIndex);
66 Status = EVENT_SIGNALED;
67 break;
68 }
69
70 TURN_OFF_LED(Adapter, GPIO_Num, uiLedIndex);
71 Status = wait_event_interruptible_timeout(
72 Adapter->LEDInfo.notify_led_event,
73 currdriverstate != Adapter->DriverState ||
74 kthread_should_stop(),
75 msecs_to_jiffies(timeout));
76 if (bInfinite == false)
77 num_of_time--;
78 }
79 return Status;
80}
81
82static INT ScaleRateofTransfer(ULONG rate)
83{
84 if (rate <= 3)
85 return rate;
86 else if ((rate > 3) && (rate <= 100))
87 return 5;
88 else if ((rate > 100) && (rate <= 200))
89 return 6;
90 else if ((rate > 200) && (rate <= 300))
91 return 7;
92 else if ((rate > 300) && (rate <= 400))
93 return 8;
94 else if ((rate > 400) && (rate <= 500))
95 return 9;
96 else if ((rate > 500) && (rate <= 600))
97 return 10;
98 else
99 return MAX_NUM_OF_BLINKS;
100}
101
102static INT blink_in_normal_bandwidth(struct bcm_mini_adapter *ad,
103 INT *time,
104 INT *time_tx,
105 INT *time_rx,
106 UCHAR GPIO_Num_tx,
107 UCHAR uiTxLedIndex,
108 UCHAR GPIO_Num_rx,
109 UCHAR uiRxLedIndex,
110 enum bcm_led_events currdriverstate,
111 ulong *timeout)
112{
113 /*
114 * Assign minimum number of blinks of
115 * either Tx or Rx.
116 */
117 *time = (*time_tx > *time_rx ? *time_rx : *time_tx);
118
119 if (*time > 0) {
120 /* Blink both Tx and Rx LEDs */
121 if ((LED_Blink(ad, 1 << GPIO_Num_tx, uiTxLedIndex, *timeout,
122 *time, currdriverstate) == EVENT_SIGNALED) ||
123 (LED_Blink(ad, 1 << GPIO_Num_rx, uiRxLedIndex, *timeout,
124 *time, currdriverstate) == EVENT_SIGNALED))
125 return EVENT_SIGNALED;
126 }
127
128 if (*time == *time_tx) {
129 /* Blink pending rate of Rx */
130 if (LED_Blink(ad, (1 << GPIO_Num_rx), uiRxLedIndex, *timeout,
131 *time_rx - *time,
132 currdriverstate) == EVENT_SIGNALED)
133 return EVENT_SIGNALED;
134
135 *time = *time_rx;
136 } else {
137 /* Blink pending rate of Tx */
138 if (LED_Blink(ad, 1 << GPIO_Num_tx, uiTxLedIndex, *timeout,
139 *time_tx - *time,
140 currdriverstate) == EVENT_SIGNALED)
141 return EVENT_SIGNALED;
142
143 *time = *time_tx;
144 }
145
146 return 0;
147}
148
149static INT LED_Proportional_Blink(struct bcm_mini_adapter *Adapter,
150 UCHAR GPIO_Num_tx,
151 UCHAR uiTxLedIndex,
152 UCHAR GPIO_Num_rx,
153 UCHAR uiRxLedIndex,
154 enum bcm_led_events currdriverstate)
155{
156 /* Initial values of TX and RX packets */
157 ULONG64 Initial_num_of_packts_tx = 0, Initial_num_of_packts_rx = 0;
158 /* values of TX and RX packets after 1 sec */
159 ULONG64 Final_num_of_packts_tx = 0, Final_num_of_packts_rx = 0;
160 /* Rate of transfer of Tx and Rx in 1 sec */
161 ULONG64 rate_of_transfer_tx = 0, rate_of_transfer_rx = 0;
162 int Status = STATUS_SUCCESS;
163 INT num_of_time = 0, num_of_time_tx = 0, num_of_time_rx = 0;
164 UINT remDelay = 0;
165 /* UINT GPIO_num = DISABLE_GPIO_NUM; */
166 ulong timeout = 0;
167
168 /* Read initial value of packets sent/received */
169 Initial_num_of_packts_tx = Adapter->dev->stats.tx_packets;
170 Initial_num_of_packts_rx = Adapter->dev->stats.rx_packets;
171
172 /* Scale the rate of transfer to no of blinks. */
173 num_of_time_tx = ScaleRateofTransfer((ULONG)rate_of_transfer_tx);
174 num_of_time_rx = ScaleRateofTransfer((ULONG)rate_of_transfer_rx);
175
176 while ((Adapter->device_removed == false)) {
177 timeout = 50;
178
179 if (EVENT_SIGNALED == blink_in_normal_bandwidth(Adapter,
180 &num_of_time,
181 &num_of_time_tx,
182 &num_of_time_rx,
183 GPIO_Num_tx,
184 uiTxLedIndex,
185 GPIO_Num_rx,
186 uiRxLedIndex,
187 currdriverstate,
188 &timeout))
189 return EVENT_SIGNALED;
190
191
192 /*
193 * If Tx/Rx rate is less than maximum blinks per second,
194 * wait till delay completes to 1 second
195 */
196 remDelay = MAX_NUM_OF_BLINKS - num_of_time;
197 if (remDelay > 0) {
198 timeout = 100 * remDelay;
199 Status = wait_event_interruptible_timeout(
200 Adapter->LEDInfo.notify_led_event,
201 currdriverstate != Adapter->DriverState
202 || kthread_should_stop(),
203 msecs_to_jiffies(timeout));
204
205 if (kthread_should_stop()) {
206 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
207 LED_DUMP_INFO, DBG_LVL_ALL,
208 "Led thread got signal to exit..hence exiting");
209 Adapter->LEDInfo.led_thread_running =
210 BCM_LED_THREAD_DISABLED;
211 return EVENT_SIGNALED;
212 }
213 if (Status)
214 return EVENT_SIGNALED;
215 }
216
217 /* Turn off both Tx and Rx LEDs before next second */
218 TURN_OFF_LED(Adapter, 1 << GPIO_Num_tx, uiTxLedIndex);
219 TURN_OFF_LED(Adapter, 1 << GPIO_Num_rx, uiTxLedIndex);
220
221 /*
222 * Read the Tx & Rx packets transmission after 1 second and
223 * calculate rate of transfer
224 */
225 Final_num_of_packts_tx = Adapter->dev->stats.tx_packets;
226 Final_num_of_packts_rx = Adapter->dev->stats.rx_packets;
227
228 rate_of_transfer_tx = Final_num_of_packts_tx -
229 Initial_num_of_packts_tx;
230 rate_of_transfer_rx = Final_num_of_packts_rx -
231 Initial_num_of_packts_rx;
232
233 /* Read initial value of packets sent/received */
234 Initial_num_of_packts_tx = Final_num_of_packts_tx;
235 Initial_num_of_packts_rx = Final_num_of_packts_rx;
236
237 /* Scale the rate of transfer to no of blinks. */
238 num_of_time_tx =
239 ScaleRateofTransfer((ULONG)rate_of_transfer_tx);
240 num_of_time_rx =
241 ScaleRateofTransfer((ULONG)rate_of_transfer_rx);
242
243 }
244 return Status;
245}
246
247/*
248 * -----------------------------------------------------------------------------
249 * Procedure: ValidateDSDParamsChecksum
250 *
251 * Description: Reads DSD Params and validates checkusm.
252 *
253 * Arguments:
254 * Adapter - Pointer to Adapter structure.
255 * ulParamOffset - Start offset of the DSD parameter to be read and
256 * validated.
257 * usParamLen - Length of the DSD Parameter.
258 *
259 * Returns:
260 * <OSAL_STATUS_CODE>
261 * -----------------------------------------------------------------------------
262 */
263static INT ValidateDSDParamsChecksum(struct bcm_mini_adapter *Adapter,
264 ULONG ulParamOffset,
265 USHORT usParamLen)
266{
267 INT Status = STATUS_SUCCESS;
268 PUCHAR puBuffer = NULL;
269 USHORT usChksmOrg = 0;
270 USHORT usChecksumCalculated = 0;
271
272 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,
273 "LED Thread:ValidateDSDParamsChecksum: 0x%lx 0x%X",
274 ulParamOffset, usParamLen);
275
276 puBuffer = kmalloc(usParamLen, GFP_KERNEL);
277 if (!puBuffer) {
278 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LED_DUMP_INFO,
279 DBG_LVL_ALL,
280 "LED Thread: ValidateDSDParamsChecksum Allocation failed");
281 return -ENOMEM;
282
283 }
284
285 /* Read the DSD data from the parameter offset. */
286 if (STATUS_SUCCESS != BeceemNVMRead(Adapter, (PUINT)puBuffer,
287 ulParamOffset, usParamLen)) {
288 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LED_DUMP_INFO,
289 DBG_LVL_ALL,
290 "LED Thread: ValidateDSDParamsChecksum BeceemNVMRead failed");
291 Status = STATUS_IMAGE_CHECKSUM_MISMATCH;
292 goto exit;
293 }
294
295 /* Calculate the checksum of the data read from the DSD parameter. */
296 usChecksumCalculated = CFG_CalculateChecksum(puBuffer, usParamLen);
297 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,
298 "LED Thread: usCheckSumCalculated = 0x%x\n",
299 usChecksumCalculated);
300
301 /*
302 * End of the DSD parameter will have a TWO bytes checksum stored in it.
303 * Read it and compare with the calculated Checksum.
304 */
305 if (STATUS_SUCCESS != BeceemNVMRead(Adapter, (PUINT)&usChksmOrg,
306 ulParamOffset+usParamLen, 2)) {
307 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LED_DUMP_INFO,
308 DBG_LVL_ALL,
309 "LED Thread: ValidateDSDParamsChecksum BeceemNVMRead failed");
310 Status = STATUS_IMAGE_CHECKSUM_MISMATCH;
311 goto exit;
312 }
313 usChksmOrg = ntohs(usChksmOrg);
314 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,
315 "LED Thread: usChksmOrg = 0x%x", usChksmOrg);
316
317 /*
318 * Compare the checksum calculated with the checksum read
319 * from DSD section
320 */
321 if (usChecksumCalculated ^ usChksmOrg) {
322 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LED_DUMP_INFO,
323 DBG_LVL_ALL,
324 "LED Thread: ValidateDSDParamsChecksum: Checksums don't match");
325 Status = STATUS_IMAGE_CHECKSUM_MISMATCH;
326 goto exit;
327 }
328
329exit:
330 kfree(puBuffer);
331 return Status;
332}
333
334
335/*
336 * -----------------------------------------------------------------------------
337 * Procedure: ValidateHWParmStructure
338 *
339 * Description: Validates HW Parameters.
340 *
341 * Arguments:
342 * Adapter - Pointer to Adapter structure.
343 * ulHwParamOffset - Start offset of the HW parameter Section to be read
344 * and validated.
345 *
346 * Returns:
347 * <OSAL_STATUS_CODE>
348 * -----------------------------------------------------------------------------
349 */
350static INT ValidateHWParmStructure(struct bcm_mini_adapter *Adapter,
351 ULONG ulHwParamOffset)
352{
353
354 INT Status = STATUS_SUCCESS;
355 USHORT HwParamLen = 0;
356 /*
357 * Add DSD start offset to the hwParamOffset to get
358 * the actual address.
359 */
360 ulHwParamOffset += DSD_START_OFFSET;
361
362 /* Read the Length of HW_PARAM structure */
363 BeceemNVMRead(Adapter, (PUINT)&HwParamLen, ulHwParamOffset, 2);
364 HwParamLen = ntohs(HwParamLen);
365 if (0 == HwParamLen || HwParamLen > Adapter->uiNVMDSDSize)
366 return STATUS_IMAGE_CHECKSUM_MISMATCH;
367
368 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,
369 "LED Thread:HwParamLen = 0x%x", HwParamLen);
370 Status = ValidateDSDParamsChecksum(Adapter, ulHwParamOffset,
371 HwParamLen);
372 return Status;
373} /* ValidateHWParmStructure() */
374
375static int ReadLEDInformationFromEEPROM(struct bcm_mini_adapter *Adapter,
376 UCHAR GPIO_Array[])
377{
378 int Status = STATUS_SUCCESS;
379
380 ULONG dwReadValue = 0;
381 USHORT usHwParamData = 0;
382 USHORT usEEPROMVersion = 0;
383 UCHAR ucIndex = 0;
384 UCHAR ucGPIOInfo[32] = {0};
385
386 BeceemNVMRead(Adapter, (PUINT)&usEEPROMVersion,
387 EEPROM_VERSION_OFFSET, 2);
388
389 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,
390 "usEEPROMVersion: Minor:0x%X Major:0x%x",
391 usEEPROMVersion & 0xFF,
392 ((usEEPROMVersion >> 8) & 0xFF));
393
394
395 if (((usEEPROMVersion>>8)&0xFF) < EEPROM_MAP5_MAJORVERSION) {
396 BeceemNVMRead(Adapter, (PUINT)&usHwParamData,
397 EEPROM_HW_PARAM_POINTER_ADDRESS, 2);
398 usHwParamData = ntohs(usHwParamData);
399 dwReadValue = usHwParamData;
400 } else {
401 /*
402 * Validate Compatibility section and then read HW param
403 * if compatibility section is valid.
404 */
405 Status = ValidateDSDParamsChecksum(Adapter,
406 DSD_START_OFFSET,
407 COMPATIBILITY_SECTION_LENGTH_MAP5);
408
409 if (Status != STATUS_SUCCESS)
410 return Status;
411
412 BeceemNVMRead(Adapter, (PUINT)&dwReadValue,
413 EEPROM_HW_PARAM_POINTER_ADDRRES_MAP5, 4);
414 dwReadValue = ntohl(dwReadValue);
415 }
416
417
418 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,
419 "LED Thread: Start address of HW_PARAM structure = 0x%lx",
420 dwReadValue);
421
422 /*
423 * Validate if the address read out is within the DSD.
424 * Adapter->uiNVMDSDSize gives whole DSD size inclusive of Autoinit.
425 * lower limit should be above DSD_START_OFFSET and
426 * upper limit should be below (Adapter->uiNVMDSDSize-DSD_START_OFFSET)
427 */
428 if (dwReadValue < DSD_START_OFFSET ||
429 dwReadValue > (Adapter->uiNVMDSDSize-DSD_START_OFFSET))
430 return STATUS_IMAGE_CHECKSUM_MISMATCH;
431
432 Status = ValidateHWParmStructure(Adapter, dwReadValue);
433 if (Status)
434 return Status;
435
436 /*
437 * Add DSD_START_OFFSET to the offset read from the EEPROM.
438 * This will give the actual start HW Parameters start address.
439 * To read GPIO section, add GPIO offset further.
440 */
441
442 dwReadValue += DSD_START_OFFSET;
443 /* = start address of hw param section. */
444 dwReadValue += GPIO_SECTION_START_OFFSET;
445 /* = GPIO start offset within HW Param section. */
446
447 /*
448 * Read the GPIO values for 32 GPIOs from EEPROM and map the function
449 * number to GPIO pin number to GPIO_Array
450 */
451 BeceemNVMRead(Adapter, (UINT *)ucGPIOInfo, dwReadValue, 32);
452 for (ucIndex = 0; ucIndex < 32; ucIndex++) {
453
454 switch (ucGPIOInfo[ucIndex]) {
455 case RED_LED:
456 GPIO_Array[RED_LED] = ucIndex;
457 Adapter->gpioBitMap |= (1 << ucIndex);
458 break;
459 case BLUE_LED:
460 GPIO_Array[BLUE_LED] = ucIndex;
461 Adapter->gpioBitMap |= (1 << ucIndex);
462 break;
463 case YELLOW_LED:
464 GPIO_Array[YELLOW_LED] = ucIndex;
465 Adapter->gpioBitMap |= (1 << ucIndex);
466 break;
467 case GREEN_LED:
468 GPIO_Array[GREEN_LED] = ucIndex;
469 Adapter->gpioBitMap |= (1 << ucIndex);
470 break;
471 default:
472 break;
473 }
474
475 }
476 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,
477 "GPIO's bit map correspond to LED :0x%X",
478 Adapter->gpioBitMap);
479 return Status;
480}
481
482
483static int ReadConfigFileStructure(struct bcm_mini_adapter *Adapter,
484 bool *bEnableThread)
485{
486 int Status = STATUS_SUCCESS;
487 /* Array to store GPIO numbers from EEPROM */
488 UCHAR GPIO_Array[NUM_OF_LEDS+1];
489 UINT uiIndex = 0;
490 UINT uiNum_of_LED_Type = 0;
491 PUCHAR puCFGData = NULL;
492 UCHAR bData = 0;
493 struct bcm_led_state_info *curr_led_state;
494
495 memset(GPIO_Array, DISABLE_GPIO_NUM, NUM_OF_LEDS+1);
496
497 if (!Adapter->pstargetparams || IS_ERR(Adapter->pstargetparams)) {
498 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LED_DUMP_INFO,
499 DBG_LVL_ALL, "Target Params not Avail.\n");
500 return -ENOENT;
501 }
502
503 /* Populate GPIO_Array with GPIO numbers for LED functions */
504 /* Read the GPIO numbers from EEPROM */
505 Status = ReadLEDInformationFromEEPROM(Adapter, GPIO_Array);
506 if (Status == STATUS_IMAGE_CHECKSUM_MISMATCH) {
507 *bEnableThread = false;
508 return STATUS_SUCCESS;
509 } else if (Status) {
510 *bEnableThread = false;
511 return Status;
512 }
513
514 /*
515 * CONFIG file read successfully. Deallocate the memory of
516 * uiFileNameBufferSize
517 */
518 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,
519 "LED Thread: Config file read successfully\n");
520 puCFGData = (PUCHAR) &Adapter->pstargetparams->HostDrvrConfig1;
521
522 /*
523 * Offset for HostDrvConfig1, HostDrvConfig2, HostDrvConfig3 which
524 * will have the information of LED type, LED on state for different
525 * driver state and LED blink state.
526 */
527
528 for (uiIndex = 0; uiIndex < NUM_OF_LEDS; uiIndex++) {
529 bData = *puCFGData;
530 curr_led_state = &Adapter->LEDInfo.LEDState[uiIndex];
531
532 /*
533 * Check Bit 8 for polarity. If it is set,
534 * polarity is reverse polarity
535 */
536 if (bData & 0x80) {
537 curr_led_state->BitPolarity = 0;
538 /* unset the bit 8 */
539 bData = bData & 0x7f;
540 }
541
542 curr_led_state->LED_Type = bData;
543 if (bData <= NUM_OF_LEDS)
544 curr_led_state->GPIO_Num = GPIO_Array[bData];
545 else
546 curr_led_state->GPIO_Num = DISABLE_GPIO_NUM;
547
548 puCFGData++;
549 bData = *puCFGData;
550 curr_led_state->LED_On_State = bData;
551 puCFGData++;
552 bData = *puCFGData;
553 curr_led_state->LED_Blink_State = bData;
554 puCFGData++;
555 }
556
557 /*
558 * Check if all the LED settings are disabled. If it is disabled,
559 * dont launch the LED control thread.
560 */
561 for (uiIndex = 0; uiIndex < NUM_OF_LEDS; uiIndex++) {
562 curr_led_state = &Adapter->LEDInfo.LEDState[uiIndex];
563
564 if ((curr_led_state->LED_Type == DISABLE_GPIO_NUM) ||
565 (curr_led_state->LED_Type == 0x7f) ||
566 (curr_led_state->LED_Type == 0))
567 uiNum_of_LED_Type++;
568 }
569 if (uiNum_of_LED_Type >= NUM_OF_LEDS)
570 *bEnableThread = false;
571
572 return Status;
573}
574
575/*
576 * -----------------------------------------------------------------------------
577 * Procedure: LedGpioInit
578 *
579 * Description: Initializes LED GPIOs. Makes the LED GPIOs to OUTPUT mode
580 * and make the initial state to be OFF.
581 *
582 * Arguments:
583 * Adapter - Pointer to MINI_ADAPTER structure.
584 *
585 * Returns: VOID
586 *
587 * -----------------------------------------------------------------------------
588 */
589static VOID LedGpioInit(struct bcm_mini_adapter *Adapter)
590{
591 UINT uiResetValue = 0;
592 UINT uiIndex = 0;
593 struct bcm_led_state_info *curr_led_state;
594
595 /* Set all LED GPIO Mode to output mode */
596 if (rdmalt(Adapter, GPIO_MODE_REGISTER, &uiResetValue,
597 sizeof(uiResetValue)) < 0)
598 BCM_DEBUG_PRINT (Adapter, DBG_TYPE_OTHERS, LED_DUMP_INFO,
599 DBG_LVL_ALL, "LED Thread: RDM Failed\n");
600 for (uiIndex = 0; uiIndex < NUM_OF_LEDS; uiIndex++) {
601 curr_led_state = &Adapter->LEDInfo.LEDState[uiIndex];
602
603 if (curr_led_state->GPIO_Num != DISABLE_GPIO_NUM)
604 uiResetValue |= (1 << curr_led_state->GPIO_Num);
605
606 TURN_OFF_LED(Adapter, 1 << curr_led_state->GPIO_Num, uiIndex);
607
608 }
609 if (wrmalt(Adapter, GPIO_MODE_REGISTER, &uiResetValue,
610 sizeof(uiResetValue)) < 0)
611 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LED_DUMP_INFO,
612 DBG_LVL_ALL, "LED Thread: WRM Failed\n");
613
614 Adapter->LEDInfo.bIdle_led_off = false;
615}
616
617static INT BcmGetGPIOPinInfo(struct bcm_mini_adapter *Adapter,
618 UCHAR *GPIO_num_tx,
619 UCHAR *GPIO_num_rx,
620 UCHAR *uiLedTxIndex,
621 UCHAR *uiLedRxIndex,
622 enum bcm_led_events currdriverstate)
623{
624 UINT uiIndex = 0;
625 struct bcm_led_state_info *led_state_info;
626
627 *GPIO_num_tx = DISABLE_GPIO_NUM;
628 *GPIO_num_rx = DISABLE_GPIO_NUM;
629
630 for (uiIndex = 0; uiIndex < NUM_OF_LEDS; uiIndex++) {
631 led_state_info = &Adapter->LEDInfo.LEDState[uiIndex];
632
633 if (((currdriverstate == NORMAL_OPERATION) ||
634 (currdriverstate == IDLEMODE_EXIT) ||
635 (currdriverstate == FW_DOWNLOAD)) &&
636 (led_state_info->LED_Blink_State & currdriverstate) &&
637 (led_state_info->GPIO_Num != DISABLE_GPIO_NUM)) {
638 if (*GPIO_num_tx == DISABLE_GPIO_NUM) {
639 *GPIO_num_tx = led_state_info->GPIO_Num;
640 *uiLedTxIndex = uiIndex;
641 } else {
642 *GPIO_num_rx = led_state_info->GPIO_Num;
643 *uiLedRxIndex = uiIndex;
644 }
645 } else {
646 if ((led_state_info->LED_On_State & currdriverstate) &&
647 (led_state_info->GPIO_Num != DISABLE_GPIO_NUM)) {
648 *GPIO_num_tx = led_state_info->GPIO_Num;
649 *uiLedTxIndex = uiIndex;
650 }
651 }
652 }
653 return STATUS_SUCCESS;
654}
655
656static void handle_adapter_driver_state(struct bcm_mini_adapter *ad,
657 enum bcm_led_events currdriverstate,
658 UCHAR GPIO_num,
659 UCHAR dummyGPIONum,
660 UCHAR uiLedIndex,
661 UCHAR dummyIndex,
662 ulong timeout,
663 UINT uiResetValue,
664 UINT uiIndex)
665{
666 switch (ad->DriverState) {
667 case DRIVER_INIT:
668 currdriverstate = DRIVER_INIT;
669 /* ad->DriverState; */
670 BcmGetGPIOPinInfo(ad, &GPIO_num, &dummyGPIONum,
671 &uiLedIndex, &dummyIndex,
672 currdriverstate);
673
674 if (GPIO_num != DISABLE_GPIO_NUM)
675 TURN_ON_LED(ad, 1 << GPIO_num, uiLedIndex);
676
677 break;
678 case FW_DOWNLOAD:
679 /*
680 * BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS,
681 * LED_DUMP_INFO, DBG_LVL_ALL,
682 * "LED Thread: FW_DN_DONE called\n");
683 */
684 currdriverstate = FW_DOWNLOAD;
685 BcmGetGPIOPinInfo(ad, &GPIO_num, &dummyGPIONum,
686 &uiLedIndex, &dummyIndex,
687 currdriverstate);
688
689 if (GPIO_num != DISABLE_GPIO_NUM) {
690 timeout = 50;
691 LED_Blink(ad, 1 << GPIO_num, uiLedIndex, timeout,
692 -1, currdriverstate);
693 }
694 break;
695 case FW_DOWNLOAD_DONE:
696 currdriverstate = FW_DOWNLOAD_DONE;
697 BcmGetGPIOPinInfo(ad, &GPIO_num, &dummyGPIONum,
698 &uiLedIndex, &dummyIndex, currdriverstate);
699 if (GPIO_num != DISABLE_GPIO_NUM)
700 TURN_ON_LED(ad, 1 << GPIO_num, uiLedIndex);
701 break;
702
703 case SHUTDOWN_EXIT:
704 /*
705 * no break, continue to NO_NETWORK_ENTRY
706 * state as well.
707 */
708 case NO_NETWORK_ENTRY:
709 currdriverstate = NO_NETWORK_ENTRY;
710 BcmGetGPIOPinInfo(ad, &GPIO_num, &dummyGPIONum,
711 &uiLedIndex, &dummyGPIONum, currdriverstate);
712 if (GPIO_num != DISABLE_GPIO_NUM)
713 TURN_ON_LED(ad, 1 << GPIO_num, uiLedIndex);
714 break;
715 case NORMAL_OPERATION:
716 {
717 UCHAR GPIO_num_tx = DISABLE_GPIO_NUM;
718 UCHAR GPIO_num_rx = DISABLE_GPIO_NUM;
719 UCHAR uiLEDTx = 0;
720 UCHAR uiLEDRx = 0;
721
722 currdriverstate = NORMAL_OPERATION;
723 ad->LEDInfo.bIdle_led_off = false;
724
725 BcmGetGPIOPinInfo(ad, &GPIO_num_tx, &GPIO_num_rx,
726 &uiLEDTx, &uiLEDRx, currdriverstate);
727 if ((GPIO_num_tx == DISABLE_GPIO_NUM) &&
728 (GPIO_num_rx == DISABLE_GPIO_NUM)) {
729 GPIO_num = DISABLE_GPIO_NUM;
730 } else {
731 /*
732 * If single LED is selected, use same
733 * for both Tx and Rx
734 */
735 if (GPIO_num_tx == DISABLE_GPIO_NUM) {
736 GPIO_num_tx = GPIO_num_rx;
737 uiLEDTx = uiLEDRx;
738 } else if (GPIO_num_rx == DISABLE_GPIO_NUM) {
739 GPIO_num_rx = GPIO_num_tx;
740 uiLEDRx = uiLEDTx;
741 }
742 /*
743 * Blink the LED in proportionate
744 * to Tx and Rx transmissions.
745 */
746 LED_Proportional_Blink(ad,
747 GPIO_num_tx, uiLEDTx,
748 GPIO_num_rx, uiLEDRx,
749 currdriverstate);
750 }
751 }
752 break;
753 case LOWPOWER_MODE_ENTER:
754 currdriverstate = LOWPOWER_MODE_ENTER;
755 if (DEVICE_POWERSAVE_MODE_AS_MANUAL_CLOCK_GATING ==
756 ad->ulPowerSaveMode) {
757 /* Turn OFF all the LED */
758 uiResetValue = 0;
759 for (uiIndex = 0; uiIndex < NUM_OF_LEDS; uiIndex++) {
760 if (ad->LEDInfo.LEDState[uiIndex].GPIO_Num != DISABLE_GPIO_NUM)
761 TURN_OFF_LED(ad,
762 (1 << ad->LEDInfo.LEDState[uiIndex].GPIO_Num),
763 uiIndex);
764 }
765
766 }
767 /* Turn off LED And WAKE-UP for Sendinf IDLE mode ACK */
768 ad->LEDInfo.bLedInitDone = false;
769 ad->LEDInfo.bIdle_led_off = TRUE;
770 wake_up(&ad->LEDInfo.idleModeSyncEvent);
771 GPIO_num = DISABLE_GPIO_NUM;
772 break;
773 case IDLEMODE_CONTINUE:
774 currdriverstate = IDLEMODE_CONTINUE;
775 GPIO_num = DISABLE_GPIO_NUM;
776 break;
777 case IDLEMODE_EXIT:
778 break;
779 case DRIVER_HALT:
780 currdriverstate = DRIVER_HALT;
781 GPIO_num = DISABLE_GPIO_NUM;
782 for (uiIndex = 0; uiIndex < NUM_OF_LEDS; uiIndex++) {
783 if (ad->LEDInfo.LEDState[uiIndex].GPIO_Num !=
784 DISABLE_GPIO_NUM)
785 TURN_OFF_LED(ad,
786 (1 << ad->LEDInfo.LEDState[uiIndex].GPIO_Num),
787 uiIndex);
788 }
789 /* ad->DriverState = DRIVER_INIT; */
790 break;
791 case LED_THREAD_INACTIVE:
792 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, LED_DUMP_INFO,
793 DBG_LVL_ALL, "InActivating LED thread...");
794 currdriverstate = LED_THREAD_INACTIVE;
795 ad->LEDInfo.led_thread_running =
796 BCM_LED_THREAD_RUNNING_INACTIVELY;
797 ad->LEDInfo.bLedInitDone = false;
798 /* disable ALL LED */
799 for (uiIndex = 0; uiIndex < NUM_OF_LEDS; uiIndex++) {
800 if (ad->LEDInfo.LEDState[uiIndex].GPIO_Num !=
801 DISABLE_GPIO_NUM)
802 TURN_OFF_LED(ad,
803 (1 << ad->LEDInfo.LEDState[uiIndex].GPIO_Num),
804 uiIndex);
805 }
806 break;
807 case LED_THREAD_ACTIVE:
808 BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, LED_DUMP_INFO,
809 DBG_LVL_ALL, "Activating LED thread again...");
810 if (ad->LinkUpStatus == false)
811 ad->DriverState = NO_NETWORK_ENTRY;
812 else
813 ad->DriverState = NORMAL_OPERATION;
814
815 ad->LEDInfo.led_thread_running =
816 BCM_LED_THREAD_RUNNING_ACTIVELY;
817 break;
818 /* return; */
819 default:
820 break;
821 }
822}
823
824static VOID LEDControlThread(struct bcm_mini_adapter *Adapter)
825{
826 UINT uiIndex = 0;
827 UCHAR GPIO_num = 0;
828 UCHAR uiLedIndex = 0;
829 UINT uiResetValue = 0;
830 enum bcm_led_events currdriverstate = 0;
831 ulong timeout = 0;
832
833 INT Status = 0;
834
835 UCHAR dummyGPIONum = 0;
836 UCHAR dummyIndex = 0;
837
838 /* currdriverstate = Adapter->DriverState; */
839 Adapter->LEDInfo.bIdleMode_tx_from_host = false;
840
841 /*
842 * Wait till event is triggered
843 *
844 * wait_event(Adapter->LEDInfo.notify_led_event,
845 * currdriverstate!= Adapter->DriverState);
846 */
847
848 GPIO_num = DISABLE_GPIO_NUM;
849
850 while (TRUE) {
851 /* Wait till event is triggered */
852 if ((GPIO_num == DISABLE_GPIO_NUM)
853 ||
854 ((currdriverstate != FW_DOWNLOAD) &&
855 (currdriverstate != NORMAL_OPERATION) &&
856 (currdriverstate != LOWPOWER_MODE_ENTER))
857 ||
858 (currdriverstate == LED_THREAD_INACTIVE))
859 Status = wait_event_interruptible(
860 Adapter->LEDInfo.notify_led_event,
861 currdriverstate != Adapter->DriverState
862 || kthread_should_stop());
863
864 if (kthread_should_stop() || Adapter->device_removed) {
865 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LED_DUMP_INFO,
866 DBG_LVL_ALL,
867 "Led thread got signal to exit..hence exiting");
868 Adapter->LEDInfo.led_thread_running =
869 BCM_LED_THREAD_DISABLED;
870 TURN_OFF_LED(Adapter, 1 << GPIO_num, uiLedIndex);
871 return; /* STATUS_FAILURE; */
872 }
873
874 if (GPIO_num != DISABLE_GPIO_NUM)
875 TURN_OFF_LED(Adapter, 1 << GPIO_num, uiLedIndex);
876
877 if (Adapter->LEDInfo.bLedInitDone == false) {
878 LedGpioInit(Adapter);
879 Adapter->LEDInfo.bLedInitDone = TRUE;
880 }
881
882 handle_adapter_driver_state(Adapter,
883 currdriverstate,
884 GPIO_num,
885 dummyGPIONum,
886 uiLedIndex,
887 dummyIndex,
888 timeout,
889 uiResetValue,
890 uiIndex
891 );
892 }
893 Adapter->LEDInfo.led_thread_running = BCM_LED_THREAD_DISABLED;
894}
895
896int InitLedSettings(struct bcm_mini_adapter *Adapter)
897{
898 int Status = STATUS_SUCCESS;
899 bool bEnableThread = TRUE;
900 UCHAR uiIndex = 0;
901
902 /*
903 * Initially set BitPolarity to normal polarity. The bit 8 of LED type
904 * is used to change the polarity of the LED.
905 */
906
907 for (uiIndex = 0; uiIndex < NUM_OF_LEDS; uiIndex++)
908 Adapter->LEDInfo.LEDState[uiIndex].BitPolarity = 1;
909
910 /*
911 * Read the LED settings of CONFIG file and map it
912 * to GPIO numbers in EEPROM
913 */
914 Status = ReadConfigFileStructure(Adapter, &bEnableThread);
915 if (STATUS_SUCCESS != Status) {
916 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LED_DUMP_INFO,
917 DBG_LVL_ALL,
918 "LED Thread: FAILED in ReadConfigFileStructure\n");
919 return Status;
920 }
921
922 if (Adapter->LEDInfo.led_thread_running) {
923 if (bEnableThread) {
924 ;
925 } else {
926 Adapter->DriverState = DRIVER_HALT;
927 wake_up(&Adapter->LEDInfo.notify_led_event);
928 Adapter->LEDInfo.led_thread_running =
929 BCM_LED_THREAD_DISABLED;
930 }
931
932 } else if (bEnableThread) {
933 /* Create secondary thread to handle the LEDs */
934 init_waitqueue_head(&Adapter->LEDInfo.notify_led_event);
935 init_waitqueue_head(&Adapter->LEDInfo.idleModeSyncEvent);
936 Adapter->LEDInfo.led_thread_running =
937 BCM_LED_THREAD_RUNNING_ACTIVELY;
938 Adapter->LEDInfo.bIdle_led_off = false;
939 Adapter->LEDInfo.led_cntrl_threadid =
940 kthread_run((int (*)(void *)) LEDControlThread,
941 Adapter, "led_control_thread");
942 if (IS_ERR(Adapter->LEDInfo.led_cntrl_threadid)) {
943 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LED_DUMP_INFO,
944 DBG_LVL_ALL,
945 "Not able to spawn Kernel Thread\n");
946 Adapter->LEDInfo.led_thread_running =
947 BCM_LED_THREAD_DISABLED;
948 return PTR_ERR(Adapter->LEDInfo.led_cntrl_threadid);
949 }
950 }
951 return Status;
952}
diff --git a/drivers/staging/bcm/led_control.h b/drivers/staging/bcm/led_control.h
deleted file mode 100644
index 1b24bf4658af..000000000000
--- a/drivers/staging/bcm/led_control.h
+++ /dev/null
@@ -1,84 +0,0 @@
1#ifndef _LED_CONTROL_H
2#define _LED_CONTROL_H
3
4#define NUM_OF_LEDS 4
5#define DSD_START_OFFSET 0x0200
6#define EEPROM_VERSION_OFFSET 0x020E
7#define EEPROM_HW_PARAM_POINTER_ADDRESS 0x0218
8#define EEPROM_HW_PARAM_POINTER_ADDRRES_MAP5 0x0220
9#define GPIO_SECTION_START_OFFSET 0x03
10#define COMPATIBILITY_SECTION_LENGTH 42
11#define COMPATIBILITY_SECTION_LENGTH_MAP5 84
12#define EEPROM_MAP5_MAJORVERSION 5
13#define EEPROM_MAP5_MINORVERSION 0
14#define MAX_NUM_OF_BLINKS 10
15#define NUM_OF_GPIO_PINS 16
16#define DISABLE_GPIO_NUM 0xFF
17#define EVENT_SIGNALED 1
18#define MAX_FILE_NAME_BUFFER_SIZE 100
19
20#define TURN_ON_LED(ad, GPIO, index) do { \
21 unsigned int gpio_val = GPIO; \
22 (ad->LEDInfo.LEDState[index].BitPolarity == 1) ? \
23 wrmaltWithLock(ad, BCM_GPIO_OUTPUT_SET_REG, &gpio_val, sizeof(gpio_val)) : \
24 wrmaltWithLock(ad, BCM_GPIO_OUTPUT_CLR_REG, &gpio_val, sizeof(gpio_val)); \
25 } while (0)
26
27#define TURN_OFF_LED(ad, GPIO, index) do { \
28 unsigned int gpio_val = GPIO; \
29 (ad->LEDInfo.LEDState[index].BitPolarity == 1) ? \
30 wrmaltWithLock(ad, BCM_GPIO_OUTPUT_CLR_REG, &gpio_val, sizeof(gpio_val)) : \
31 wrmaltWithLock(ad, BCM_GPIO_OUTPUT_SET_REG, &gpio_val, sizeof(gpio_val)); \
32 } while (0)
33
34enum bcm_led_colors {
35 RED_LED = 1,
36 BLUE_LED = 2,
37 YELLOW_LED = 3,
38 GREEN_LED = 4
39};
40
41enum bcm_led_events {
42 SHUTDOWN_EXIT = 0x00,
43 DRIVER_INIT = 0x1,
44 FW_DOWNLOAD = 0x2,
45 FW_DOWNLOAD_DONE = 0x4,
46 NO_NETWORK_ENTRY = 0x8,
47 NORMAL_OPERATION = 0x10,
48 LOWPOWER_MODE_ENTER = 0x20,
49 IDLEMODE_CONTINUE = 0x40,
50 IDLEMODE_EXIT = 0x80,
51 LED_THREAD_INACTIVE = 0x100, /* Makes the LED thread Inactivce. It wil be equivallent to putting the thread on hold. */
52 LED_THREAD_ACTIVE = 0x200, /* Makes the LED Thread Active back. */
53 DRIVER_HALT = 0xff
54}; /* Enumerated values of different driver states */
55
56/*
57 * Structure which stores the information of different LED types
58 * and corresponding LED state information of driver states
59 */
60struct bcm_led_state_info {
61 unsigned char LED_Type; /* specify GPIO number - use 0xFF if not used */
62 unsigned char LED_On_State; /* Bits set or reset for different states */
63 unsigned char LED_Blink_State; /* Bits set or reset for blinking LEDs for different states */
64 unsigned char GPIO_Num;
65 unsigned char BitPolarity; /* To represent whether H/W is normal polarity or reverse polarity */
66};
67
68struct bcm_led_info {
69 struct bcm_led_state_info LEDState[NUM_OF_LEDS];
70 bool bIdleMode_tx_from_host; /* Variable to notify whether driver came out from idlemode due to Host or target */
71 bool bIdle_led_off;
72 wait_queue_head_t notify_led_event;
73 wait_queue_head_t idleModeSyncEvent;
74 struct task_struct *led_cntrl_threadid;
75 int led_thread_running;
76 bool bLedInitDone;
77};
78
79/* LED Thread state. */
80#define BCM_LED_THREAD_DISABLED 0 /* LED Thread is not running. */
81#define BCM_LED_THREAD_RUNNING_ACTIVELY 1 /* LED thread is running. */
82#define BCM_LED_THREAD_RUNNING_INACTIVELY 2 /* LED thread has been put on hold */
83
84#endif
diff --git a/drivers/staging/bcm/nvm.c b/drivers/staging/bcm/nvm.c
deleted file mode 100644
index ce09473fbb1f..000000000000
--- a/drivers/staging/bcm/nvm.c
+++ /dev/null
@@ -1,4661 +0,0 @@
1#include "headers.h"
2
3#define DWORD unsigned int
4
5static int BcmDoChipSelect(struct bcm_mini_adapter *Adapter,
6 unsigned int offset);
7static int BcmGetActiveDSD(struct bcm_mini_adapter *Adapter);
8static int BcmGetActiveISO(struct bcm_mini_adapter *Adapter);
9static unsigned int BcmGetEEPROMSize(struct bcm_mini_adapter *Adapter);
10static int BcmGetFlashCSInfo(struct bcm_mini_adapter *Adapter);
11static unsigned int BcmGetFlashSectorSize(struct bcm_mini_adapter *Adapter,
12 unsigned int FlashSectorSizeSig,
13 unsigned int FlashSectorSize);
14
15static VOID BcmValidateNvmType(struct bcm_mini_adapter *Adapter);
16static int BcmGetNvmSize(struct bcm_mini_adapter *Adapter);
17static unsigned int BcmGetFlashSize(struct bcm_mini_adapter *Adapter);
18static enum bcm_nvm_type BcmGetNvmType(struct bcm_mini_adapter *Adapter);
19
20static int BcmGetSectionValEndOffset(struct bcm_mini_adapter *Adapter,
21 enum bcm_flash2x_section_val eFlash2xSectionVal);
22
23static B_UINT8 IsOffsetWritable(struct bcm_mini_adapter *Adapter,
24 unsigned int uiOffset);
25static int IsSectionWritable(struct bcm_mini_adapter *Adapter,
26 enum bcm_flash2x_section_val Section);
27static int IsSectionExistInVendorInfo(struct bcm_mini_adapter *Adapter,
28 enum bcm_flash2x_section_val section);
29
30static int ReadDSDPriority(struct bcm_mini_adapter *Adapter,
31 enum bcm_flash2x_section_val dsd);
32static int ReadDSDSignature(struct bcm_mini_adapter *Adapter,
33 enum bcm_flash2x_section_val dsd);
34static int ReadISOPriority(struct bcm_mini_adapter *Adapter,
35 enum bcm_flash2x_section_val iso);
36static int ReadISOSignature(struct bcm_mini_adapter *Adapter,
37 enum bcm_flash2x_section_val iso);
38
39static int CorruptDSDSig(struct bcm_mini_adapter *Adapter,
40 enum bcm_flash2x_section_val eFlash2xSectionVal);
41static int CorruptISOSig(struct bcm_mini_adapter *Adapter,
42 enum bcm_flash2x_section_val eFlash2xSectionVal);
43static int SaveHeaderIfPresent(struct bcm_mini_adapter *Adapter,
44 PUCHAR pBuff,
45 unsigned int uiSectAlignAddr);
46static int WriteToFlashWithoutSectorErase(struct bcm_mini_adapter *Adapter,
47 PUINT pBuff,
48 enum bcm_flash2x_section_val eFlash2xSectionVal,
49 unsigned int uiOffset,
50 unsigned int uiNumBytes);
51static enum bcm_flash2x_section_val getHighestPriDSD(struct bcm_mini_adapter *Adapter);
52static enum bcm_flash2x_section_val getHighestPriISO(struct bcm_mini_adapter *Adapter);
53
54static int BeceemFlashBulkRead(
55 struct bcm_mini_adapter *Adapter,
56 PUINT pBuffer,
57 unsigned int uiOffset,
58 unsigned int uiNumBytes);
59
60static int BeceemFlashBulkWrite(
61 struct bcm_mini_adapter *Adapter,
62 PUINT pBuffer,
63 unsigned int uiOffset,
64 unsigned int uiNumBytes,
65 bool bVerify);
66
67static int GetFlashBaseAddr(struct bcm_mini_adapter *Adapter);
68
69static int ReadBeceemEEPROMBulk(struct bcm_mini_adapter *Adapter, unsigned int dwAddress, unsigned int *pdwData, unsigned int dwNumData);
70
71/* Procedure: ReadEEPROMStatusRegister
72 *
73 * Description: Reads the standard EEPROM Status Register.
74 *
75 * Arguments:
76 * Adapter - ptr to Adapter object instance
77 * Returns:
78 * OSAL_STATUS_CODE
79 */
80static UCHAR ReadEEPROMStatusRegister(struct bcm_mini_adapter *Adapter)
81{
82 UCHAR uiData = 0;
83 DWORD dwRetries = MAX_EEPROM_RETRIES * RETRIES_PER_DELAY;
84 unsigned int uiStatus = 0;
85 unsigned int value = 0;
86 unsigned int value1 = 0;
87
88 /* Read the EEPROM status register */
89 value = EEPROM_READ_STATUS_REGISTER;
90 wrmalt(Adapter, EEPROM_CMDQ_SPI_REG, &value, sizeof(value));
91
92 while (dwRetries != 0) {
93 value = 0;
94 uiStatus = 0;
95 rdmalt(Adapter, EEPROM_SPI_Q_STATUS1_REG, &uiStatus, sizeof(uiStatus));
96 if (Adapter->device_removed == TRUE) {
97 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Modem has got removed hence exiting....");
98 break;
99 }
100
101 /* Wait for Avail bit to be set. */
102 if ((uiStatus & EEPROM_READ_DATA_AVAIL) != 0) {
103 /* Clear the Avail/Full bits - which ever is set. */
104 value = uiStatus & (EEPROM_READ_DATA_AVAIL | EEPROM_READ_DATA_FULL);
105 wrmalt(Adapter, EEPROM_SPI_Q_STATUS1_REG, &value, sizeof(value));
106
107 value = 0;
108 rdmalt(Adapter, EEPROM_READ_DATAQ_REG, &value, sizeof(value));
109 uiData = (UCHAR)value;
110
111 break;
112 }
113
114 dwRetries--;
115 if (dwRetries == 0) {
116 rdmalt(Adapter, EEPROM_SPI_Q_STATUS1_REG, &value, sizeof(value));
117 rdmalt(Adapter, EEPROM_SPI_Q_STATUS_REG, &value1, sizeof(value1));
118 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "0x3004 = %x 0x3008 = %x, retries = %d failed.\n", value, value1, MAX_EEPROM_RETRIES * RETRIES_PER_DELAY);
119 return uiData;
120 }
121 if (!(dwRetries%RETRIES_PER_DELAY))
122 udelay(1000);
123 uiStatus = 0;
124 }
125 return uiData;
126} /* ReadEEPROMStatusRegister */
127
128/*
129 * Procedure: ReadBeceemEEPROMBulk
130 *
131 * Description: This routine reads 16Byte data from EEPROM
132 *
133 * Arguments:
134 * Adapter - ptr to Adapter object instance
135 * dwAddress - EEPROM Offset to read the data from.
136 * pdwData - Pointer to double word where data needs to be stored in. // dwNumWords - Number of words. Valid values are 4 ONLY.
137 *
138 * Returns:
139 * OSAL_STATUS_CODE:
140 */
141
142static int ReadBeceemEEPROMBulk(struct bcm_mini_adapter *Adapter,
143 DWORD dwAddress,
144 DWORD *pdwData,
145 DWORD dwNumWords)
146{
147 DWORD dwIndex = 0;
148 DWORD dwRetries = MAX_EEPROM_RETRIES * RETRIES_PER_DELAY;
149 unsigned int uiStatus = 0;
150 unsigned int value = 0;
151 unsigned int value1 = 0;
152 UCHAR *pvalue;
153
154 /* Flush the read and cmd queue. */
155 value = (EEPROM_READ_QUEUE_FLUSH | EEPROM_CMD_QUEUE_FLUSH);
156 wrmalt(Adapter, SPI_FLUSH_REG, &value, sizeof(value));
157 value = 0;
158 wrmalt(Adapter, SPI_FLUSH_REG, &value, sizeof(value));
159
160 /* Clear the Avail/Full bits. */
161 value = (EEPROM_READ_DATA_AVAIL | EEPROM_READ_DATA_FULL);
162 wrmalt(Adapter, EEPROM_SPI_Q_STATUS1_REG, &value, sizeof(value));
163
164 value = dwAddress | ((dwNumWords == 4) ? EEPROM_16_BYTE_PAGE_READ : EEPROM_4_BYTE_PAGE_READ);
165 wrmalt(Adapter, EEPROM_CMDQ_SPI_REG, &value, sizeof(value));
166
167 while (dwRetries != 0) {
168 uiStatus = 0;
169 rdmalt(Adapter, EEPROM_SPI_Q_STATUS1_REG, &uiStatus, sizeof(uiStatus));
170 if (Adapter->device_removed == TRUE) {
171 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Modem has got Removed.hence exiting from loop...");
172 return -ENODEV;
173 }
174
175 /* If we are reading 16 bytes we want to be sure that the queue
176 * is full before we read. In the other cases we are ok if the
177 * queue has data available
178 */
179 if (dwNumWords == 4) {
180 if ((uiStatus & EEPROM_READ_DATA_FULL) != 0) {
181 /* Clear the Avail/Full bits - which ever is set. */
182 value = (uiStatus & (EEPROM_READ_DATA_AVAIL | EEPROM_READ_DATA_FULL));
183 wrmalt(Adapter, EEPROM_SPI_Q_STATUS1_REG, &value, sizeof(value));
184 break;
185 }
186 } else if (dwNumWords == 1) {
187 if ((uiStatus & EEPROM_READ_DATA_AVAIL) != 0) {
188 /* We just got Avail and we have to read 32bits so we
189 * need this sleep for Cardbus kind of devices.
190 */
191 if (Adapter->chip_id == 0xBECE0210)
192 udelay(800);
193
194 /* Clear the Avail/Full bits - which ever is set. */
195 value = (uiStatus & (EEPROM_READ_DATA_AVAIL | EEPROM_READ_DATA_FULL));
196 wrmalt(Adapter, EEPROM_SPI_Q_STATUS1_REG, &value, sizeof(value));
197 break;
198 }
199 }
200
201 uiStatus = 0;
202
203 dwRetries--;
204 if (dwRetries == 0) {
205 value = 0;
206 value1 = 0;
207 rdmalt(Adapter, EEPROM_SPI_Q_STATUS1_REG, &value, sizeof(value));
208 rdmalt(Adapter, EEPROM_SPI_Q_STATUS_REG, &value1, sizeof(value1));
209 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "dwNumWords %d 0x3004 = %x 0x3008 = %x retries = %d failed.\n",
210 dwNumWords, value, value1, MAX_EEPROM_RETRIES * RETRIES_PER_DELAY);
211 return STATUS_FAILURE;
212 }
213
214 if (!(dwRetries%RETRIES_PER_DELAY))
215 udelay(1000);
216 }
217
218 for (dwIndex = 0; dwIndex < dwNumWords; dwIndex++) {
219 /* We get only a byte at a time - from LSB to MSB. We shift it into an integer. */
220 pvalue = (PUCHAR)(pdwData + dwIndex);
221
222 value = 0;
223 rdmalt(Adapter, EEPROM_READ_DATAQ_REG, &value, sizeof(value));
224
225 pvalue[0] = value;
226
227 value = 0;
228 rdmalt(Adapter, EEPROM_READ_DATAQ_REG, &value, sizeof(value));
229
230 pvalue[1] = value;
231
232 value = 0;
233 rdmalt(Adapter, EEPROM_READ_DATAQ_REG, &value, sizeof(value));
234
235 pvalue[2] = value;
236
237 value = 0;
238 rdmalt(Adapter, EEPROM_READ_DATAQ_REG, &value, sizeof(value));
239
240 pvalue[3] = value;
241 }
242
243 return STATUS_SUCCESS;
244} /* ReadBeceemEEPROMBulk() */
245
246/*
247 * Procedure: ReadBeceemEEPROM
248 *
249 * Description: This routine reads 4 data from EEPROM. It uses 1 or 2 page
250 * reads to do this operation.
251 *
252 * Arguments:
253 * Adapter - ptr to Adapter object instance
254 * uiOffset - EEPROM Offset to read the data from.
255 * pBuffer - Pointer to word where data needs to be stored in.
256 *
257 * Returns:
258 * OSAL_STATUS_CODE:
259 */
260
261int ReadBeceemEEPROM(struct bcm_mini_adapter *Adapter,
262 DWORD uiOffset,
263 DWORD *pBuffer)
264{
265 unsigned int uiData[8] = {0};
266 unsigned int uiByteOffset = 0;
267 unsigned int uiTempOffset = 0;
268
269 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, " ====> ");
270
271 uiTempOffset = uiOffset - (uiOffset % MAX_RW_SIZE);
272 uiByteOffset = uiOffset - uiTempOffset;
273
274 ReadBeceemEEPROMBulk(Adapter, uiTempOffset, (PUINT)&uiData[0], 4);
275
276 /* A word can overlap at most over 2 pages. In that case we read the
277 * next page too.
278 */
279 if (uiByteOffset > 12)
280 ReadBeceemEEPROMBulk(Adapter, uiTempOffset + MAX_RW_SIZE, (PUINT)&uiData[4], 4);
281
282 memcpy((PUCHAR)pBuffer, (((PUCHAR)&uiData[0]) + uiByteOffset), 4);
283
284 return STATUS_SUCCESS;
285} /* ReadBeceemEEPROM() */
286
287int ReadMacAddressFromNVM(struct bcm_mini_adapter *Adapter)
288{
289 int Status;
290 unsigned char puMacAddr[6];
291
292 Status = BeceemNVMRead(Adapter,
293 (PUINT)&puMacAddr[0],
294 INIT_PARAMS_1_MACADDRESS_ADDRESS,
295 MAC_ADDRESS_SIZE);
296
297 if (Status == STATUS_SUCCESS)
298 memcpy(Adapter->dev->dev_addr, puMacAddr, MAC_ADDRESS_SIZE);
299
300 return Status;
301}
302
303/*
304 * Procedure: BeceemEEPROMBulkRead
305 *
306 * Description: Reads the EEPROM and returns the Data.
307 *
308 * Arguments:
309 * Adapter - ptr to Adapter object instance
310 * pBuffer - Buffer to store the data read from EEPROM
311 * uiOffset - Offset of EEPROM from where data should be read
312 * uiNumBytes - Number of bytes to be read from the EEPROM.
313 *
314 * Returns:
315 * OSAL_STATUS_SUCCESS - if EEPROM read is successful.
316 * <FAILURE> - if failed.
317 */
318
319int BeceemEEPROMBulkRead(struct bcm_mini_adapter *Adapter,
320 PUINT pBuffer,
321 unsigned int uiOffset,
322 unsigned int uiNumBytes)
323{
324 unsigned int uiData[4] = {0};
325 /* unsigned int uiAddress = 0; */
326 unsigned int uiBytesRemaining = uiNumBytes;
327 unsigned int uiIndex = 0;
328 unsigned int uiTempOffset = 0;
329 unsigned int uiExtraBytes = 0;
330 unsigned int uiFailureRetries = 0;
331 PUCHAR pcBuff = (PUCHAR)pBuffer;
332
333 if (uiOffset % MAX_RW_SIZE && uiBytesRemaining) {
334 uiTempOffset = uiOffset - (uiOffset % MAX_RW_SIZE);
335 uiExtraBytes = uiOffset - uiTempOffset;
336 ReadBeceemEEPROMBulk(Adapter, uiTempOffset, (PUINT)&uiData[0], 4);
337 if (uiBytesRemaining >= (MAX_RW_SIZE - uiExtraBytes)) {
338 memcpy(pBuffer, (((PUCHAR)&uiData[0]) + uiExtraBytes), MAX_RW_SIZE - uiExtraBytes);
339 uiBytesRemaining -= (MAX_RW_SIZE - uiExtraBytes);
340 uiIndex += (MAX_RW_SIZE - uiExtraBytes);
341 uiOffset += (MAX_RW_SIZE - uiExtraBytes);
342 } else {
343 memcpy(pBuffer, (((PUCHAR)&uiData[0]) + uiExtraBytes), uiBytesRemaining);
344 uiIndex += uiBytesRemaining;
345 uiOffset += uiBytesRemaining;
346 uiBytesRemaining = 0;
347 }
348 }
349
350 while (uiBytesRemaining && uiFailureRetries != 128) {
351 if (Adapter->device_removed)
352 return -1;
353
354 if (uiBytesRemaining >= MAX_RW_SIZE) {
355 /* For the requests more than or equal to 16 bytes, use bulk
356 * read function to make the access faster.
357 * We read 4 Dwords of data
358 */
359 if (ReadBeceemEEPROMBulk(Adapter, uiOffset, &uiData[0], 4) == 0) {
360 memcpy(pcBuff + uiIndex, &uiData[0], MAX_RW_SIZE);
361 uiOffset += MAX_RW_SIZE;
362 uiBytesRemaining -= MAX_RW_SIZE;
363 uiIndex += MAX_RW_SIZE;
364 } else {
365 uiFailureRetries++;
366 mdelay(3); /* sleep for a while before retry... */
367 }
368 } else if (uiBytesRemaining >= 4) {
369 if (ReadBeceemEEPROM(Adapter, uiOffset, &uiData[0]) == 0) {
370 memcpy(pcBuff + uiIndex, &uiData[0], 4);
371 uiOffset += 4;
372 uiBytesRemaining -= 4;
373 uiIndex += 4;
374 } else {
375 uiFailureRetries++;
376 mdelay(3); /* sleep for a while before retry... */
377 }
378 } else {
379 /* Handle the reads less than 4 bytes... */
380 PUCHAR pCharBuff = (PUCHAR)pBuffer;
381
382 pCharBuff += uiIndex;
383 if (ReadBeceemEEPROM(Adapter, uiOffset, &uiData[0]) == 0) {
384 memcpy(pCharBuff, &uiData[0], uiBytesRemaining); /* copy only bytes requested. */
385 uiBytesRemaining = 0;
386 } else {
387 uiFailureRetries++;
388 mdelay(3); /* sleep for a while before retry... */
389 }
390 }
391 }
392
393 return 0;
394}
395
396/*
397 * Procedure: BeceemFlashBulkRead
398 *
399 * Description: Reads the FLASH and returns the Data.
400 *
401 * Arguments:
402 * Adapter - ptr to Adapter object instance
403 * pBuffer - Buffer to store the data read from FLASH
404 * uiOffset - Offset of FLASH from where data should be read
405 * uiNumBytes - Number of bytes to be read from the FLASH.
406 *
407 * Returns:
408 * OSAL_STATUS_SUCCESS - if FLASH read is successful.
409 * <FAILURE> - if failed.
410 */
411
412static int BeceemFlashBulkRead(struct bcm_mini_adapter *Adapter,
413 PUINT pBuffer,
414 unsigned int uiOffset,
415 unsigned int uiNumBytes)
416{
417 unsigned int uiIndex = 0;
418 unsigned int uiBytesToRead = uiNumBytes;
419 int Status = 0;
420 unsigned int uiPartOffset = 0;
421 int bytes;
422
423 if (Adapter->device_removed) {
424 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Device Got Removed");
425 return -ENODEV;
426 }
427
428 /* Adding flash Base address
429 * uiOffset = uiOffset + GetFlashBaseAddr(Adapter);
430 */
431 #if defined(BCM_SHM_INTERFACE) && !defined(FLASH_DIRECT_ACCESS)
432 Status = bcmflash_raw_read((uiOffset/FLASH_PART_SIZE), (uiOffset % FLASH_PART_SIZE), (unsigned char *)pBuffer, uiNumBytes);
433 return Status;
434 #endif
435
436 Adapter->SelectedChip = RESET_CHIP_SELECT;
437
438 if (uiOffset % MAX_RW_SIZE) {
439 BcmDoChipSelect(Adapter, uiOffset);
440 uiPartOffset = (uiOffset & (FLASH_PART_SIZE - 1)) + GetFlashBaseAddr(Adapter);
441
442 uiBytesToRead = MAX_RW_SIZE - (uiOffset % MAX_RW_SIZE);
443 uiBytesToRead = MIN(uiNumBytes, uiBytesToRead);
444
445 bytes = rdm(Adapter, uiPartOffset, (PCHAR)pBuffer + uiIndex, uiBytesToRead);
446 if (bytes < 0) {
447 Status = bytes;
448 Adapter->SelectedChip = RESET_CHIP_SELECT;
449 return Status;
450 }
451
452 uiIndex += uiBytesToRead;
453 uiOffset += uiBytesToRead;
454 uiNumBytes -= uiBytesToRead;
455 }
456
457 while (uiNumBytes) {
458 BcmDoChipSelect(Adapter, uiOffset);
459 uiPartOffset = (uiOffset & (FLASH_PART_SIZE - 1)) + GetFlashBaseAddr(Adapter);
460
461 uiBytesToRead = MIN(uiNumBytes, MAX_RW_SIZE);
462
463 bytes = rdm(Adapter, uiPartOffset, (PCHAR)pBuffer + uiIndex, uiBytesToRead);
464 if (bytes < 0) {
465 Status = bytes;
466 break;
467 }
468
469 uiIndex += uiBytesToRead;
470 uiOffset += uiBytesToRead;
471 uiNumBytes -= uiBytesToRead;
472 }
473 Adapter->SelectedChip = RESET_CHIP_SELECT;
474 return Status;
475}
476
477/*
478 * Procedure: BcmGetFlashSize
479 *
480 * Description: Finds the size of FLASH.
481 *
482 * Arguments:
483 * Adapter - ptr to Adapter object instance
484 *
485 * Returns:
486 * unsigned int - size of the FLASH Storage.
487 *
488 */
489
490static unsigned int BcmGetFlashSize(struct bcm_mini_adapter *Adapter)
491{
492 if (IsFlash2x(Adapter))
493 return Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(struct bcm_dsd_header);
494 else
495 return 32 * 1024;
496}
497
498/*
499 * Procedure: BcmGetEEPROMSize
500 *
501 * Description: Finds the size of EEPROM.
502 *
503 * Arguments:
504 * Adapter - ptr to Adapter object instance
505 *
506 * Returns:
507 * unsigned int - size of the EEPROM Storage.
508 *
509 */
510
511static unsigned int BcmGetEEPROMSize(struct bcm_mini_adapter *Adapter)
512{
513 unsigned int uiData = 0;
514 unsigned int uiIndex = 0;
515
516 /*
517 * if EEPROM is present and already Calibrated,it will have
518 * 'BECM' string at 0th offset.
519 * To find the EEPROM size read the possible boundaries of the
520 * EEPROM like 4K,8K etc..accessing the EEPROM beyond its size will
521 * result in wrap around. So when we get the End of the EEPROM we will
522 * get 'BECM' string which is indeed at offset 0.
523 */
524 BeceemEEPROMBulkRead(Adapter, &uiData, 0x0, 4);
525 if (uiData == BECM) {
526 for (uiIndex = 2; uiIndex <= 256; uiIndex *= 2) {
527 BeceemEEPROMBulkRead(Adapter, &uiData, uiIndex * 1024, 4);
528 if (uiData == BECM)
529 return uiIndex * 1024;
530 }
531 } else {
532 /*
533 * EEPROM may not be present or not programmed
534 */
535 uiData = 0xBABEFACE;
536 if (BeceemEEPROMBulkWrite(Adapter, (PUCHAR)&uiData, 0, 4, TRUE) == 0) {
537 uiData = 0;
538 for (uiIndex = 2; uiIndex <= 256; uiIndex *= 2) {
539 BeceemEEPROMBulkRead(Adapter, &uiData, uiIndex * 1024, 4);
540 if (uiData == 0xBABEFACE)
541 return uiIndex * 1024;
542 }
543 }
544 }
545 return 0;
546}
547
548/*
549 * Procedure: FlashSectorErase
550 *
551 * Description: Finds the sector size of the FLASH.
552 *
553 * Arguments:
554 * Adapter - ptr to Adapter object instance
555 * addr - sector start address
556 * numOfSectors - number of sectors to be erased.
557 *
558 * Returns:
559 * OSAL_STATUS_CODE
560 *
561 */
562
563static int FlashSectorErase(struct bcm_mini_adapter *Adapter,
564 unsigned int addr,
565 unsigned int numOfSectors)
566{
567 unsigned int iIndex = 0, iRetries = 0;
568 unsigned int uiStatus = 0;
569 unsigned int value;
570 int bytes;
571
572 for (iIndex = 0; iIndex < numOfSectors; iIndex++) {
573 value = 0x06000000;
574 wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value));
575
576 value = (0xd8000000 | (addr & 0xFFFFFF));
577 wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value));
578 iRetries = 0;
579
580 do {
581 value = (FLASH_CMD_STATUS_REG_READ << 24);
582 if (wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value)) < 0) {
583 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Programing of FLASH_SPI_CMDQ_REG fails");
584 return STATUS_FAILURE;
585 }
586
587 bytes = rdmalt(Adapter, FLASH_SPI_READQ_REG, &uiStatus, sizeof(uiStatus));
588 if (bytes < 0) {
589 uiStatus = bytes;
590 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Reading status of FLASH_SPI_READQ_REG fails");
591 return uiStatus;
592 }
593 iRetries++;
594 /* After every try lets make the CPU free for 10 ms. generally time taken by the
595 * the sector erase cycle is 500 ms to 40000 msec. hence sleeping 10 ms
596 * won't hamper performance in any case.
597 */
598 mdelay(10);
599 } while ((uiStatus & 0x1) && (iRetries < 400));
600
601 if (uiStatus & 0x1) {
602 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "iRetries crossing the limit of 80000\n");
603 return STATUS_FAILURE;
604 }
605
606 addr += Adapter->uiSectorSize;
607 }
608 return 0;
609}
610/*
611 * Procedure: flashByteWrite
612 *
613 * Description: Performs Byte by Byte write to flash
614 *
615 * Arguments:
616 * Adapter - ptr to Adapter object instance
617 * uiOffset - Offset of the flash where data needs to be written to.
618 * pData - Address of Data to be written.
619 * Returns:
620 * OSAL_STATUS_CODE
621 *
622 */
623
624static int flashByteWrite(struct bcm_mini_adapter *Adapter,
625 unsigned int uiOffset,
626 PVOID pData)
627{
628 unsigned int uiStatus = 0;
629 int iRetries = MAX_FLASH_RETRIES * FLASH_PER_RETRIES_DELAY; /* 3 */
630 unsigned int value;
631 ULONG ulData = *(PUCHAR)pData;
632 int bytes;
633 /*
634 * need not write 0xFF because write requires an erase and erase will
635 * make whole sector 0xFF.
636 */
637
638 if (0xFF == ulData)
639 return STATUS_SUCCESS;
640
641 /* DumpDebug(NVM_RW,("flashWrite ====>\n")); */
642 value = (FLASH_CMD_WRITE_ENABLE << 24);
643 if (wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value)) < 0) {
644 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Write enable in FLASH_SPI_CMDQ_REG register fails");
645 return STATUS_FAILURE;
646 }
647
648 if (wrm(Adapter, FLASH_SPI_WRITEQ_REG, (PCHAR)&ulData, 4) < 0) {
649 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "DATA Write on FLASH_SPI_WRITEQ_REG fails");
650 return STATUS_FAILURE;
651 }
652 value = (0x02000000 | (uiOffset & 0xFFFFFF));
653 if (wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value)) < 0) {
654 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Programming of FLASH_SPI_CMDQ_REG fails");
655 return STATUS_FAILURE;
656 }
657
658 /* __udelay(950); */
659
660 do {
661 value = (FLASH_CMD_STATUS_REG_READ << 24);
662 if (wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value)) < 0) {
663 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Programing of FLASH_SPI_CMDQ_REG fails");
664 return STATUS_FAILURE;
665 }
666 /* __udelay(1); */
667 bytes = rdmalt(Adapter, FLASH_SPI_READQ_REG, &uiStatus, sizeof(uiStatus));
668 if (bytes < 0) {
669 uiStatus = bytes;
670 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Reading status of FLASH_SPI_READQ_REG fails");
671 return uiStatus;
672 }
673 iRetries--;
674 if (iRetries && ((iRetries % FLASH_PER_RETRIES_DELAY) == 0))
675 udelay(1000);
676
677 } while ((uiStatus & 0x1) && (iRetries > 0));
678
679 if (uiStatus & 0x1) {
680 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Write fails even after checking status for 200 times.");
681 return STATUS_FAILURE;
682 }
683
684 return STATUS_SUCCESS;
685}
686
687/*
688 * Procedure: flashWrite
689 *
690 * Description: Performs write to flash
691 *
692 * Arguments:
693 * Adapter - ptr to Adapter object instance
694 * uiOffset - Offset of the flash where data needs to be written to.
695 * pData - Address of Data to be written.
696 * Returns:
697 * OSAL_STATUS_CODE
698 *
699 */
700
701static int flashWrite(struct bcm_mini_adapter *Adapter,
702 unsigned int uiOffset,
703 PVOID pData)
704{
705 /* unsigned int uiStatus = 0;
706 * int iRetries = 0;
707 * unsigned int uiReadBack = 0;
708 */
709 unsigned int uiStatus = 0;
710 int iRetries = MAX_FLASH_RETRIES * FLASH_PER_RETRIES_DELAY; /* 3 */
711 unsigned int value;
712 unsigned int uiErasePattern[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
713 int bytes;
714 /*
715 * need not write 0xFFFFFFFF because write requires an erase and erase will
716 * make whole sector 0xFFFFFFFF.
717 */
718 if (!memcmp(pData, uiErasePattern, MAX_RW_SIZE))
719 return 0;
720
721 value = (FLASH_CMD_WRITE_ENABLE << 24);
722
723 if (wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value)) < 0) {
724 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Write Enable of FLASH_SPI_CMDQ_REG fails");
725 return STATUS_FAILURE;
726 }
727
728 if (wrm(Adapter, uiOffset, (PCHAR)pData, MAX_RW_SIZE) < 0) {
729 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Data write fails...");
730 return STATUS_FAILURE;
731 }
732
733 /* __udelay(950); */
734 do {
735 value = (FLASH_CMD_STATUS_REG_READ << 24);
736 if (wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value)) < 0) {
737 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Programing of FLASH_SPI_CMDQ_REG fails");
738 return STATUS_FAILURE;
739 }
740 /* __udelay(1); */
741 bytes = rdmalt(Adapter, FLASH_SPI_READQ_REG, &uiStatus, sizeof(uiStatus));
742 if (bytes < 0) {
743 uiStatus = bytes;
744 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Reading status of FLASH_SPI_READQ_REG fails");
745 return uiStatus;
746 }
747
748 iRetries--;
749 /* this will ensure that in there will be no changes in the current path.
750 * currently one rdm/wrm takes 125 us.
751 * Hence 125 *2 * FLASH_PER_RETRIES_DELAY > 3 ms(worst case delay)
752 * Hence current implementation cycle will intoduce no delay in current path
753 */
754 if (iRetries && ((iRetries % FLASH_PER_RETRIES_DELAY) == 0))
755 udelay(1000);
756 } while ((uiStatus & 0x1) && (iRetries > 0));
757
758 if (uiStatus & 0x1) {
759 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Write fails even after checking status for 200 times.");
760 return STATUS_FAILURE;
761 }
762
763 return STATUS_SUCCESS;
764}
765
766/*-----------------------------------------------------------------------------
767 * Procedure: flashByteWriteStatus
768 *
769 * Description: Performs byte by byte write to flash with write done status check
770 *
771 * Arguments:
772 * Adapter - ptr to Adapter object instance
773 * uiOffset - Offset of the flash where data needs to be written to.
774 * pData - Address of the Data to be written.
775 * Returns:
776 * OSAL_STATUS_CODE
777 *
778 */
779static int flashByteWriteStatus(struct bcm_mini_adapter *Adapter,
780 unsigned int uiOffset,
781 PVOID pData)
782{
783 unsigned int uiStatus = 0;
784 int iRetries = MAX_FLASH_RETRIES * FLASH_PER_RETRIES_DELAY; /* 3 */
785 ULONG ulData = *(PUCHAR)pData;
786 unsigned int value;
787 int bytes;
788
789 /*
790 * need not write 0xFFFFFFFF because write requires an erase and erase will
791 * make whole sector 0xFFFFFFFF.
792 */
793
794 if (0xFF == ulData)
795 return STATUS_SUCCESS;
796
797 /* DumpDebug(NVM_RW,("flashWrite ====>\n")); */
798
799 value = (FLASH_CMD_WRITE_ENABLE << 24);
800 if (wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value)) < 0) {
801 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Write enable in FLASH_SPI_CMDQ_REG register fails");
802 return STATUS_SUCCESS;
803 }
804 if (wrm(Adapter, FLASH_SPI_WRITEQ_REG, (PCHAR)&ulData, 4) < 0) {
805 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "DATA Write on FLASH_SPI_WRITEQ_REG fails");
806 return STATUS_FAILURE;
807 }
808 value = (0x02000000 | (uiOffset & 0xFFFFFF));
809 if (wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value)) < 0) {
810 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Programming of FLASH_SPI_CMDQ_REG fails");
811 return STATUS_FAILURE;
812 }
813
814 /* msleep(1); */
815
816 do {
817 value = (FLASH_CMD_STATUS_REG_READ << 24);
818 if (wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value)) < 0) {
819 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Programing of FLASH_SPI_CMDQ_REG fails");
820 return STATUS_FAILURE;
821 }
822 /* __udelay(1); */
823 bytes = rdmalt(Adapter, FLASH_SPI_READQ_REG, &uiStatus, sizeof(uiStatus));
824 if (bytes < 0) {
825 uiStatus = bytes;
826 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Reading status of FLASH_SPI_READQ_REG fails");
827 return uiStatus;
828 }
829
830 iRetries--;
831 if (iRetries && ((iRetries % FLASH_PER_RETRIES_DELAY) == 0))
832 udelay(1000);
833
834 } while ((uiStatus & 0x1) && (iRetries > 0));
835
836 if (uiStatus & 0x1) {
837 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Write fails even after checking status for 200 times.");
838 return STATUS_FAILURE;
839 }
840
841 return STATUS_SUCCESS;
842}
843/*
844 * Procedure: flashWriteStatus
845 *
846 * Description: Performs write to flash with write done status check
847 *
848 * Arguments:
849 * Adapter - ptr to Adapter object instance
850 * uiOffset - Offset of the flash where data needs to be written to.
851 * pData - Address of the Data to be written.
852 * Returns:
853 * OSAL_STATUS_CODE
854 *
855 */
856
857static int flashWriteStatus(struct bcm_mini_adapter *Adapter,
858 unsigned int uiOffset,
859 PVOID pData)
860{
861 unsigned int uiStatus = 0;
862 int iRetries = MAX_FLASH_RETRIES * FLASH_PER_RETRIES_DELAY; /* 3 */
863 /* unsigned int uiReadBack = 0; */
864 unsigned int value;
865 unsigned int uiErasePattern[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
866 int bytes;
867
868 /*
869 * need not write 0xFFFFFFFF because write requires an erase and erase will
870 * make whole sector 0xFFFFFFFF.
871 */
872 if (!memcmp(pData, uiErasePattern, MAX_RW_SIZE))
873 return 0;
874
875 value = (FLASH_CMD_WRITE_ENABLE << 24);
876 if (wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value)) < 0) {
877 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Write Enable of FLASH_SPI_CMDQ_REG fails");
878 return STATUS_FAILURE;
879 }
880
881 if (wrm(Adapter, uiOffset, (PCHAR)pData, MAX_RW_SIZE) < 0) {
882 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Data write fails...");
883 return STATUS_FAILURE;
884 }
885 /* __udelay(1); */
886
887 do {
888 value = (FLASH_CMD_STATUS_REG_READ << 24);
889 if (wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value)) < 0) {
890 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Programing of FLASH_SPI_CMDQ_REG fails");
891 return STATUS_FAILURE;
892 }
893 /* __udelay(1); */
894 bytes = rdmalt(Adapter, FLASH_SPI_READQ_REG, &uiStatus, sizeof(uiStatus));
895 if (bytes < 0) {
896 uiStatus = bytes;
897 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Reading status of FLASH_SPI_READQ_REG fails");
898 return uiStatus;
899 }
900 iRetries--;
901 /* this will ensure that in there will be no changes in the current path.
902 * currently one rdm/wrm takes 125 us.
903 * Hence 125 *2 * FLASH_PER_RETRIES_DELAY >3 ms(worst case delay)
904 * Hence current implementation cycle will intoduce no delay in current path
905 */
906 if (iRetries && ((iRetries % FLASH_PER_RETRIES_DELAY) == 0))
907 udelay(1000);
908
909 } while ((uiStatus & 0x1) && (iRetries > 0));
910
911 if (uiStatus & 0x1) {
912 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Write fails even after checking status for 200 times.");
913 return STATUS_FAILURE;
914 }
915
916 return STATUS_SUCCESS;
917}
918
919/*
920 * Procedure: BcmRestoreBlockProtectStatus
921 *
922 * Description: Restores the original block protection status.
923 *
924 * Arguments:
925 * Adapter - ptr to Adapter object instance
926 * ulWriteStatus -Original status
927 * Returns:
928 * <VOID>
929 *
930 */
931
932static VOID BcmRestoreBlockProtectStatus(struct bcm_mini_adapter *Adapter, ULONG ulWriteStatus)
933{
934 unsigned int value;
935
936 value = (FLASH_CMD_WRITE_ENABLE << 24);
937 wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value));
938
939 udelay(20);
940 value = (FLASH_CMD_STATUS_REG_WRITE << 24) | (ulWriteStatus << 16);
941 wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value));
942 udelay(20);
943}
944
945/*
946 * Procedure: BcmFlashUnProtectBlock
947 *
948 * Description: UnProtects appropriate blocks for writing.
949 *
950 * Arguments:
951 * Adapter - ptr to Adapter object instance
952 * uiOffset - Offset of the flash where data needs to be written to. This should be Sector aligned.
953 * Returns:
954 * ULONG - Status value before UnProtect.
955 *
956 */
957
958static ULONG BcmFlashUnProtectBlock(struct bcm_mini_adapter *Adapter, unsigned int uiOffset, unsigned int uiLength)
959{
960 ULONG ulStatus = 0;
961 ULONG ulWriteStatus = 0;
962 unsigned int value;
963
964 uiOffset = uiOffset&0x000FFFFF;
965 /*
966 * Implemented only for 1MB Flash parts.
967 */
968 if (FLASH_PART_SST25VF080B == Adapter->ulFlashID) {
969 /*
970 * Get Current BP status.
971 */
972 value = (FLASH_CMD_STATUS_REG_READ << 24);
973 wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value));
974 udelay(10);
975 /*
976 * Read status will be WWXXYYZZ. We have to take only WW.
977 */
978 rdmalt(Adapter, FLASH_SPI_READQ_REG, (PUINT)&ulStatus, sizeof(ulStatus));
979 ulStatus >>= 24;
980 ulWriteStatus = ulStatus;
981 /*
982 * Bits [5-2] give current block level protection status.
983 * Bit5: BP3 - DONT CARE
984 * BP2-BP0: 0 - NO PROTECTION, 1 - UPPER 1/16, 2 - UPPER 1/8, 3 - UPPER 1/4
985 * 4 - UPPER 1/2. 5 to 7 - ALL BLOCKS
986 */
987
988 if (ulStatus) {
989 if ((uiOffset+uiLength) <= 0x80000) {
990 /*
991 * Offset comes in lower half of 1MB. Protect the upper half.
992 * Clear BP1 and BP0 and set BP2.
993 */
994 ulWriteStatus |= (0x4<<2);
995 ulWriteStatus &= ~(0x3<<2);
996 } else if ((uiOffset + uiLength) <= 0xC0000) {
997 /*
998 * Offset comes below Upper 1/4. Upper 1/4 can be protected.
999 * Clear BP2 and set BP1 and BP0.
1000 */
1001 ulWriteStatus |= (0x3<<2);
1002 ulWriteStatus &= ~(0x1<<4);
1003 } else if ((uiOffset + uiLength) <= 0xE0000) {
1004 /*
1005 * Offset comes below Upper 1/8. Upper 1/8 can be protected.
1006 * Clear BP2 and BP0 and set BP1
1007 */
1008 ulWriteStatus |= (0x1<<3);
1009 ulWriteStatus &= ~(0x5<<2);
1010 } else if ((uiOffset + uiLength) <= 0xF0000) {
1011 /*
1012 * Offset comes below Upper 1/16. Only upper 1/16 can be protected.
1013 * Set BP0 and Clear BP2,BP1.
1014 */
1015 ulWriteStatus |= (0x1<<2);
1016 ulWriteStatus &= ~(0x3<<3);
1017 } else {
1018 /*
1019 * Unblock all.
1020 * Clear BP2,BP1 and BP0.
1021 */
1022 ulWriteStatus &= ~(0x7<<2);
1023 }
1024
1025 value = (FLASH_CMD_WRITE_ENABLE << 24);
1026 wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value));
1027 udelay(20);
1028 value = (FLASH_CMD_STATUS_REG_WRITE << 24) | (ulWriteStatus << 16);
1029 wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value));
1030 udelay(20);
1031 }
1032 }
1033 return ulStatus;
1034}
1035
1036static int bulk_read_complete_sector(struct bcm_mini_adapter *ad,
1037 UCHAR read_bk[],
1038 PCHAR tmpbuff,
1039 unsigned int offset,
1040 unsigned int partoff)
1041{
1042 unsigned int i;
1043 int j;
1044 int bulk_read_stat;
1045 FP_FLASH_WRITE_STATUS writef =
1046 ad->fpFlashWriteWithStatusCheck;
1047
1048 for (i = 0; i < ad->uiSectorSize; i += MAX_RW_SIZE) {
1049 bulk_read_stat = BeceemFlashBulkRead(ad,
1050 (PUINT)read_bk,
1051 offset + i,
1052 MAX_RW_SIZE);
1053
1054 if (bulk_read_stat != STATUS_SUCCESS)
1055 continue;
1056
1057 if (ad->ulFlashWriteSize == 1) {
1058 for (j = 0; j < 16; j++) {
1059 if ((read_bk[j] != tmpbuff[i + j]) &&
1060 (STATUS_SUCCESS != (*writef)(ad, partoff + i + j, &tmpbuff[i + j]))) {
1061 return STATUS_FAILURE;
1062 }
1063 }
1064 } else {
1065 if ((memcmp(read_bk, &tmpbuff[i], MAX_RW_SIZE)) &&
1066 (STATUS_SUCCESS != (*writef)(ad, partoff + i, &tmpbuff[i]))) {
1067 return STATUS_FAILURE;
1068 }
1069 }
1070 }
1071
1072 return STATUS_SUCCESS;
1073}
1074
1075/*
1076 * Procedure: BeceemFlashBulkWrite
1077 *
1078 * Description: Performs write to the flash
1079 *
1080 * Arguments:
1081 * Adapter - ptr to Adapter object instance
1082 * pBuffer - Data to be written.
1083 * uiOffset - Offset of the flash where data needs to be written to.
1084 * uiNumBytes - Number of bytes to be written.
1085 * bVerify - read verify flag.
1086 * Returns:
1087 * OSAL_STATUS_CODE
1088 *
1089 */
1090
1091static int BeceemFlashBulkWrite(struct bcm_mini_adapter *Adapter,
1092 PUINT pBuffer,
1093 unsigned int uiOffset,
1094 unsigned int uiNumBytes,
1095 bool bVerify)
1096{
1097 PCHAR pTempBuff = NULL;
1098 PUCHAR pcBuffer = (PUCHAR)pBuffer;
1099 unsigned int uiIndex = 0;
1100 unsigned int uiOffsetFromSectStart = 0;
1101 unsigned int uiSectAlignAddr = 0;
1102 unsigned int uiCurrSectOffsetAddr = 0;
1103 unsigned int uiSectBoundary = 0;
1104 unsigned int uiNumSectTobeRead = 0;
1105 UCHAR ucReadBk[16] = {0};
1106 ULONG ulStatus = 0;
1107 int Status = STATUS_SUCCESS;
1108 unsigned int uiTemp = 0;
1109 unsigned int index = 0;
1110 unsigned int uiPartOffset = 0;
1111
1112 #if defined(BCM_SHM_INTERFACE) && !defined(FLASH_DIRECT_ACCESS)
1113 Status = bcmflash_raw_write((uiOffset / FLASH_PART_SIZE), (uiOffset % FLASH_PART_SIZE), (unsigned char *)pBuffer, uiNumBytes);
1114 return Status;
1115 #endif
1116
1117 uiOffsetFromSectStart = uiOffset & ~(Adapter->uiSectorSize - 1);
1118
1119 /* Adding flash Base address
1120 * uiOffset = uiOffset + GetFlashBaseAddr(Adapter);
1121 */
1122
1123 uiSectAlignAddr = uiOffset & ~(Adapter->uiSectorSize - 1);
1124 uiCurrSectOffsetAddr = uiOffset & (Adapter->uiSectorSize - 1);
1125 uiSectBoundary = uiSectAlignAddr + Adapter->uiSectorSize;
1126
1127 pTempBuff = kmalloc(Adapter->uiSectorSize, GFP_KERNEL);
1128 if (!pTempBuff)
1129 goto BeceemFlashBulkWrite_EXIT;
1130 /*
1131 * check if the data to be written is overlapped across sectors
1132 */
1133 if (uiOffset+uiNumBytes < uiSectBoundary) {
1134 uiNumSectTobeRead = 1;
1135 } else {
1136 /* Number of sectors = Last sector start address/First sector start address */
1137 uiNumSectTobeRead = (uiCurrSectOffsetAddr + uiNumBytes) / Adapter->uiSectorSize;
1138 if ((uiCurrSectOffsetAddr + uiNumBytes)%Adapter->uiSectorSize)
1139 uiNumSectTobeRead++;
1140 }
1141 /* Check whether Requested sector is writable or not in case of flash2x write. But if write call is
1142 * for DSD calibration, allow it without checking of sector permission
1143 */
1144
1145 if (IsFlash2x(Adapter) && (Adapter->bAllDSDWriteAllow == false)) {
1146 index = 0;
1147 uiTemp = uiNumSectTobeRead;
1148 while (uiTemp) {
1149 if (IsOffsetWritable(Adapter, uiOffsetFromSectStart + index * Adapter->uiSectorSize) == false) {
1150 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Sector Starting at offset <0X%X> is not writable",
1151 (uiOffsetFromSectStart + index * Adapter->uiSectorSize));
1152 Status = SECTOR_IS_NOT_WRITABLE;
1153 goto BeceemFlashBulkWrite_EXIT;
1154 }
1155 uiTemp = uiTemp - 1;
1156 index = index + 1;
1157 }
1158 }
1159 Adapter->SelectedChip = RESET_CHIP_SELECT;
1160 while (uiNumSectTobeRead) {
1161 /* do_gettimeofday(&tv1);
1162 * BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "\nTime In start of write :%ld ms\n",(tv1.tv_sec *1000 + tv1.tv_usec /1000));
1163 */
1164 uiPartOffset = (uiSectAlignAddr & (FLASH_PART_SIZE - 1)) + GetFlashBaseAddr(Adapter);
1165
1166 BcmDoChipSelect(Adapter, uiSectAlignAddr);
1167
1168 if (0 != BeceemFlashBulkRead(Adapter,
1169 (PUINT)pTempBuff,
1170 uiOffsetFromSectStart,
1171 Adapter->uiSectorSize)) {
1172 Status = -1;
1173 goto BeceemFlashBulkWrite_EXIT;
1174 }
1175
1176 /* do_gettimeofday(&tr);
1177 * BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Total time taken by Read :%ld ms\n", (tr.tv_sec *1000 + tr.tv_usec/1000) - (tv1.tv_sec *1000 + tv1.tv_usec/1000));
1178 */
1179 ulStatus = BcmFlashUnProtectBlock(Adapter, uiSectAlignAddr, Adapter->uiSectorSize);
1180
1181 if (uiNumSectTobeRead > 1) {
1182 memcpy(&pTempBuff[uiCurrSectOffsetAddr], pcBuffer, uiSectBoundary - (uiSectAlignAddr + uiCurrSectOffsetAddr));
1183 pcBuffer += ((uiSectBoundary - (uiSectAlignAddr + uiCurrSectOffsetAddr)));
1184 uiNumBytes -= (uiSectBoundary - (uiSectAlignAddr + uiCurrSectOffsetAddr));
1185 } else {
1186 memcpy(&pTempBuff[uiCurrSectOffsetAddr], pcBuffer, uiNumBytes);
1187 }
1188
1189 if (IsFlash2x(Adapter))
1190 SaveHeaderIfPresent(Adapter, (PUCHAR)pTempBuff, uiOffsetFromSectStart);
1191
1192 FlashSectorErase(Adapter, uiPartOffset, 1);
1193 /* do_gettimeofday(&te);
1194 * BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Total time taken by Erase :%ld ms\n", (te.tv_sec *1000 + te.tv_usec/1000) - (tr.tv_sec *1000 + tr.tv_usec/1000));
1195 */
1196 for (uiIndex = 0; uiIndex < Adapter->uiSectorSize; uiIndex += Adapter->ulFlashWriteSize) {
1197 if (Adapter->device_removed) {
1198 Status = -1;
1199 goto BeceemFlashBulkWrite_EXIT;
1200 }
1201
1202 if (STATUS_SUCCESS != (*Adapter->fpFlashWrite)(Adapter, uiPartOffset + uiIndex, (&pTempBuff[uiIndex]))) {
1203 Status = -1;
1204 goto BeceemFlashBulkWrite_EXIT;
1205 }
1206 }
1207
1208 /* do_gettimeofday(&tw);
1209 * BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Total time taken in Write to Flash :%ld ms\n", (tw.tv_sec *1000 + tw.tv_usec/1000) - (te.tv_sec *1000 + te.tv_usec/1000));
1210 */
1211
1212 if (STATUS_FAILURE == bulk_read_complete_sector(Adapter,
1213 ucReadBk,
1214 pTempBuff,
1215 uiOffsetFromSectStart,
1216 uiPartOffset)) {
1217 Status = STATUS_FAILURE;
1218 goto BeceemFlashBulkWrite_EXIT;
1219 }
1220
1221 /* do_gettimeofday(&twv);
1222 * BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Total time taken in Write to Flash verification :%ld ms\n", (twv.tv_sec *1000 + twv.tv_usec/1000) - (tw.tv_sec *1000 + tw.tv_usec/1000));
1223 */
1224 if (ulStatus) {
1225 BcmRestoreBlockProtectStatus(Adapter, ulStatus);
1226 ulStatus = 0;
1227 }
1228
1229 uiCurrSectOffsetAddr = 0;
1230 uiSectAlignAddr = uiSectBoundary;
1231 uiSectBoundary += Adapter->uiSectorSize;
1232 uiOffsetFromSectStart += Adapter->uiSectorSize;
1233 uiNumSectTobeRead--;
1234 }
1235 /* do_gettimeofday(&tv2);
1236 * BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Time after Write :%ld ms\n",(tv2.tv_sec *1000 + tv2.tv_usec/1000));
1237 * BCM_DEBUG_PRINT(Adapter,DBG_TYPE_PRINTK, 0, 0, "Total time taken by in Write is :%ld ms\n", (tv2.tv_sec *1000 + tv2.tv_usec/1000) - (tv1.tv_sec *1000 + tv1.tv_usec/1000));
1238 *
1239 * Cleanup.
1240 */
1241BeceemFlashBulkWrite_EXIT:
1242 if (ulStatus)
1243 BcmRestoreBlockProtectStatus(Adapter, ulStatus);
1244
1245 kfree(pTempBuff);
1246
1247 Adapter->SelectedChip = RESET_CHIP_SELECT;
1248 return Status;
1249}
1250
1251/*
1252 * Procedure: BeceemFlashBulkWriteStatus
1253 *
1254 * Description: Writes to Flash. Checks the SPI status after each write.
1255 *
1256 * Arguments:
1257 * Adapter - ptr to Adapter object instance
1258 * pBuffer - Data to be written.
1259 * uiOffset - Offset of the flash where data needs to be written to.
1260 * uiNumBytes - Number of bytes to be written.
1261 * bVerify - read verify flag.
1262 * Returns:
1263 * OSAL_STATUS_CODE
1264 *
1265 */
1266
1267static int BeceemFlashBulkWriteStatus(struct bcm_mini_adapter *Adapter,
1268 PUINT pBuffer,
1269 unsigned int uiOffset,
1270 unsigned int uiNumBytes,
1271 bool bVerify)
1272{
1273 PCHAR pTempBuff = NULL;
1274 PUCHAR pcBuffer = (PUCHAR)pBuffer;
1275 unsigned int uiIndex = 0;
1276 unsigned int uiOffsetFromSectStart = 0;
1277 unsigned int uiSectAlignAddr = 0;
1278 unsigned int uiCurrSectOffsetAddr = 0;
1279 unsigned int uiSectBoundary = 0;
1280 unsigned int uiNumSectTobeRead = 0;
1281 UCHAR ucReadBk[16] = {0};
1282 ULONG ulStatus = 0;
1283 unsigned int Status = STATUS_SUCCESS;
1284 unsigned int uiTemp = 0;
1285 unsigned int index = 0;
1286 unsigned int uiPartOffset = 0;
1287
1288 uiOffsetFromSectStart = uiOffset & ~(Adapter->uiSectorSize - 1);
1289
1290 /* uiOffset += Adapter->ulFlashCalStart;
1291 * Adding flash Base address
1292 * uiOffset = uiOffset + GetFlashBaseAddr(Adapter);
1293 */
1294 uiSectAlignAddr = uiOffset & ~(Adapter->uiSectorSize - 1);
1295 uiCurrSectOffsetAddr = uiOffset & (Adapter->uiSectorSize - 1);
1296 uiSectBoundary = uiSectAlignAddr + Adapter->uiSectorSize;
1297
1298 pTempBuff = kmalloc(Adapter->uiSectorSize, GFP_KERNEL);
1299 if (!pTempBuff)
1300 goto BeceemFlashBulkWriteStatus_EXIT;
1301
1302 /*
1303 * check if the data to be written is overlapped across sectors
1304 */
1305 if (uiOffset+uiNumBytes < uiSectBoundary) {
1306 uiNumSectTobeRead = 1;
1307 } else {
1308 /* Number of sectors = Last sector start address/First sector start address */
1309 uiNumSectTobeRead = (uiCurrSectOffsetAddr + uiNumBytes) / Adapter->uiSectorSize;
1310 if ((uiCurrSectOffsetAddr + uiNumBytes)%Adapter->uiSectorSize)
1311 uiNumSectTobeRead++;
1312 }
1313
1314 if (IsFlash2x(Adapter) && (Adapter->bAllDSDWriteAllow == false)) {
1315 index = 0;
1316 uiTemp = uiNumSectTobeRead;
1317 while (uiTemp) {
1318 if (IsOffsetWritable(Adapter, uiOffsetFromSectStart + index * Adapter->uiSectorSize) == false) {
1319 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Sector Starting at offset <0X%x> is not writable",
1320 (uiOffsetFromSectStart + index * Adapter->uiSectorSize));
1321 Status = SECTOR_IS_NOT_WRITABLE;
1322 goto BeceemFlashBulkWriteStatus_EXIT;
1323 }
1324 uiTemp = uiTemp - 1;
1325 index = index + 1;
1326 }
1327 }
1328
1329 Adapter->SelectedChip = RESET_CHIP_SELECT;
1330 while (uiNumSectTobeRead) {
1331 uiPartOffset = (uiSectAlignAddr & (FLASH_PART_SIZE - 1)) + GetFlashBaseAddr(Adapter);
1332
1333 BcmDoChipSelect(Adapter, uiSectAlignAddr);
1334 if (0 != BeceemFlashBulkRead(Adapter,
1335 (PUINT)pTempBuff,
1336 uiOffsetFromSectStart,
1337 Adapter->uiSectorSize)) {
1338 Status = -1;
1339 goto BeceemFlashBulkWriteStatus_EXIT;
1340 }
1341
1342 ulStatus = BcmFlashUnProtectBlock(Adapter, uiOffsetFromSectStart, Adapter->uiSectorSize);
1343
1344 if (uiNumSectTobeRead > 1) {
1345 memcpy(&pTempBuff[uiCurrSectOffsetAddr], pcBuffer, uiSectBoundary - (uiSectAlignAddr + uiCurrSectOffsetAddr));
1346 pcBuffer += ((uiSectBoundary - (uiSectAlignAddr + uiCurrSectOffsetAddr)));
1347 uiNumBytes -= (uiSectBoundary - (uiSectAlignAddr + uiCurrSectOffsetAddr));
1348 } else {
1349 memcpy(&pTempBuff[uiCurrSectOffsetAddr], pcBuffer, uiNumBytes);
1350 }
1351
1352 if (IsFlash2x(Adapter))
1353 SaveHeaderIfPresent(Adapter, (PUCHAR)pTempBuff, uiOffsetFromSectStart);
1354
1355 FlashSectorErase(Adapter, uiPartOffset, 1);
1356
1357 for (uiIndex = 0; uiIndex < Adapter->uiSectorSize; uiIndex += Adapter->ulFlashWriteSize) {
1358 if (Adapter->device_removed) {
1359 Status = -1;
1360 goto BeceemFlashBulkWriteStatus_EXIT;
1361 }
1362
1363 if (STATUS_SUCCESS != (*Adapter->fpFlashWriteWithStatusCheck)(Adapter, uiPartOffset+uiIndex, &pTempBuff[uiIndex])) {
1364 Status = -1;
1365 goto BeceemFlashBulkWriteStatus_EXIT;
1366 }
1367 }
1368
1369 if (bVerify) {
1370 for (uiIndex = 0; uiIndex < Adapter->uiSectorSize; uiIndex += MAX_RW_SIZE) {
1371 if (STATUS_SUCCESS == BeceemFlashBulkRead(Adapter, (PUINT)ucReadBk, uiOffsetFromSectStart + uiIndex, MAX_RW_SIZE)) {
1372 if (memcmp(ucReadBk, &pTempBuff[uiIndex], MAX_RW_SIZE)) {
1373 Status = STATUS_FAILURE;
1374 goto BeceemFlashBulkWriteStatus_EXIT;
1375 }
1376 }
1377 }
1378 }
1379
1380 if (ulStatus) {
1381 BcmRestoreBlockProtectStatus(Adapter, ulStatus);
1382 ulStatus = 0;
1383 }
1384
1385 uiCurrSectOffsetAddr = 0;
1386 uiSectAlignAddr = uiSectBoundary;
1387 uiSectBoundary += Adapter->uiSectorSize;
1388 uiOffsetFromSectStart += Adapter->uiSectorSize;
1389 uiNumSectTobeRead--;
1390 }
1391/*
1392 * Cleanup.
1393 */
1394BeceemFlashBulkWriteStatus_EXIT:
1395 if (ulStatus)
1396 BcmRestoreBlockProtectStatus(Adapter, ulStatus);
1397
1398 kfree(pTempBuff);
1399 Adapter->SelectedChip = RESET_CHIP_SELECT;
1400 return Status;
1401}
1402
1403/*
1404 * Procedure: PropagateCalParamsFromFlashToMemory
1405 *
1406 * Description: Dumps the calibration section of EEPROM to DDR.
1407 *
1408 * Arguments:
1409 * Adapter - ptr to Adapter object instance
1410 * Returns:
1411 * OSAL_STATUS_CODE
1412 *
1413 */
1414
1415int PropagateCalParamsFromFlashToMemory(struct bcm_mini_adapter *Adapter)
1416{
1417 PCHAR pBuff, pPtr;
1418 unsigned int uiEepromSize = 0;
1419 unsigned int uiBytesToCopy = 0;
1420 /* unsigned int uiIndex = 0; */
1421 unsigned int uiCalStartAddr = EEPROM_CALPARAM_START;
1422 unsigned int uiMemoryLoc = EEPROM_CAL_DATA_INTERNAL_LOC;
1423 unsigned int value;
1424 int Status = 0;
1425
1426 /*
1427 * Write the signature first. This will ensure firmware does not access EEPROM.
1428 */
1429 value = 0xbeadbead;
1430 wrmalt(Adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 4, &value, sizeof(value));
1431 value = 0xbeadbead;
1432 wrmalt(Adapter, EEPROM_CAL_DATA_INTERNAL_LOC - 8, &value, sizeof(value));
1433
1434 if (0 != BeceemNVMRead(Adapter, &uiEepromSize, EEPROM_SIZE_OFFSET, 4))
1435 return -1;
1436
1437 uiEepromSize = ntohl(uiEepromSize);
1438 uiEepromSize >>= 16;
1439
1440 /*
1441 * subtract the auto init section size
1442 */
1443 uiEepromSize -= EEPROM_CALPARAM_START;
1444
1445 if (uiEepromSize > 1024 * 1024)
1446 return -1;
1447
1448 pBuff = kmalloc(uiEepromSize, GFP_KERNEL);
1449 if (pBuff == NULL)
1450 return -ENOMEM;
1451
1452 if (0 != BeceemNVMRead(Adapter, (PUINT)pBuff, uiCalStartAddr, uiEepromSize)) {
1453 kfree(pBuff);
1454 return -1;
1455 }
1456
1457 pPtr = pBuff;
1458
1459 uiBytesToCopy = MIN(BUFFER_4K, uiEepromSize);
1460
1461 while (uiBytesToCopy) {
1462 Status = wrm(Adapter, uiMemoryLoc, (PCHAR)pPtr, uiBytesToCopy);
1463 if (Status) {
1464 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "wrm failed with status :%d", Status);
1465 break;
1466 }
1467
1468 pPtr += uiBytesToCopy;
1469 uiEepromSize -= uiBytesToCopy;
1470 uiMemoryLoc += uiBytesToCopy;
1471 uiBytesToCopy = MIN(BUFFER_4K, uiEepromSize);
1472 }
1473
1474 kfree(pBuff);
1475 return Status;
1476}
1477
1478/*
1479 * Procedure: BeceemEEPROMReadBackandVerify
1480 *
1481 * Description: Read back the data written and verifies.
1482 *
1483 * Arguments:
1484 * Adapter - ptr to Adapter object instance
1485 * pBuffer - Data to be written.
1486 * uiOffset - Offset of the flash where data needs to be written to.
1487 * uiNumBytes - Number of bytes to be written.
1488 * Returns:
1489 * OSAL_STATUS_CODE
1490 *
1491 */
1492
1493static int BeceemEEPROMReadBackandVerify(struct bcm_mini_adapter *Adapter,
1494 PUINT pBuffer,
1495 unsigned int uiOffset,
1496 unsigned int uiNumBytes)
1497{
1498 unsigned int uiRdbk = 0;
1499 unsigned int uiIndex = 0;
1500 unsigned int uiData = 0;
1501 unsigned int auiData[4] = {0};
1502
1503 while (uiNumBytes) {
1504 if (Adapter->device_removed)
1505 return -1;
1506
1507 if (uiNumBytes >= MAX_RW_SIZE) {
1508 /* for the requests more than or equal to MAX_RW_SIZE bytes, use bulk read function to make the access faster. */
1509 BeceemEEPROMBulkRead(Adapter, &auiData[0], uiOffset, MAX_RW_SIZE);
1510
1511 if (memcmp(&pBuffer[uiIndex], &auiData[0], MAX_RW_SIZE)) {
1512 /* re-write */
1513 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)(pBuffer + uiIndex), uiOffset, MAX_RW_SIZE, false);
1514 mdelay(3);
1515 BeceemEEPROMBulkRead(Adapter, &auiData[0], uiOffset, MAX_RW_SIZE);
1516
1517 if (memcmp(&pBuffer[uiIndex], &auiData[0], MAX_RW_SIZE))
1518 return -1;
1519 }
1520 uiOffset += MAX_RW_SIZE;
1521 uiNumBytes -= MAX_RW_SIZE;
1522 uiIndex += 4;
1523 } else if (uiNumBytes >= 4) {
1524 BeceemEEPROMBulkRead(Adapter, &uiData, uiOffset, 4);
1525 if (uiData != pBuffer[uiIndex]) {
1526 /* re-write */
1527 BeceemEEPROMBulkWrite(Adapter, (PUCHAR)(pBuffer + uiIndex), uiOffset, 4, false);
1528 mdelay(3);
1529 BeceemEEPROMBulkRead(Adapter, &uiData, uiOffset, 4);
1530 if (uiData != pBuffer[uiIndex])
1531 return -1;
1532 }
1533 uiOffset += 4;
1534 uiNumBytes -= 4;
1535 uiIndex++;
1536 } else {
1537 /* Handle the reads less than 4 bytes... */
1538 uiData = 0;
1539 memcpy(&uiData, ((PUCHAR)pBuffer) + (uiIndex * sizeof(unsigned int)), uiNumBytes);
1540 BeceemEEPROMBulkRead(Adapter, &uiRdbk, uiOffset, 4);
1541
1542 if (memcmp(&uiData, &uiRdbk, uiNumBytes))
1543 return -1;
1544
1545 uiNumBytes = 0;
1546 }
1547 }
1548
1549 return 0;
1550}
1551
1552static VOID BcmSwapWord(unsigned int *ptr1)
1553{
1554 unsigned int tempval = (unsigned int)*ptr1;
1555 char *ptr2 = (char *)&tempval;
1556 char *ptr = (char *)ptr1;
1557
1558 ptr[0] = ptr2[3];
1559 ptr[1] = ptr2[2];
1560 ptr[2] = ptr2[1];
1561 ptr[3] = ptr2[0];
1562}
1563
1564/*
1565 * Procedure: BeceemEEPROMWritePage
1566 *
1567 * Description: Performs page write (16bytes) to the EEPROM
1568 *
1569 * Arguments:
1570 * Adapter - ptr to Adapter object instance
1571 * uiData - Data to be written.
1572 * uiOffset - Offset of the EEPROM where data needs to be written to.
1573 * Returns:
1574 * OSAL_STATUS_CODE
1575 *
1576 */
1577
1578static int BeceemEEPROMWritePage(struct bcm_mini_adapter *Adapter, unsigned int uiData[], unsigned int uiOffset)
1579{
1580 unsigned int uiRetries = MAX_EEPROM_RETRIES * RETRIES_PER_DELAY;
1581 unsigned int uiStatus = 0;
1582 UCHAR uiEpromStatus = 0;
1583 unsigned int value = 0;
1584
1585 /* Flush the Write/Read/Cmd queues. */
1586 value = (EEPROM_WRITE_QUEUE_FLUSH | EEPROM_CMD_QUEUE_FLUSH | EEPROM_READ_QUEUE_FLUSH);
1587 wrmalt(Adapter, SPI_FLUSH_REG, &value, sizeof(value));
1588 value = 0;
1589 wrmalt(Adapter, SPI_FLUSH_REG, &value, sizeof(value));
1590
1591 /* Clear the Empty/Avail/Full bits. After this it has been confirmed
1592 * that the bit was cleared by reading back the register. See NOTE below.
1593 * We also clear the Read queues as we do a EEPROM status register read
1594 * later.
1595 */
1596 value = (EEPROM_WRITE_QUEUE_EMPTY | EEPROM_WRITE_QUEUE_AVAIL | EEPROM_WRITE_QUEUE_FULL | EEPROM_READ_DATA_AVAIL | EEPROM_READ_DATA_FULL);
1597 wrmalt(Adapter, EEPROM_SPI_Q_STATUS1_REG, &value, sizeof(value));
1598
1599 /* Enable write */
1600 value = EEPROM_WRITE_ENABLE;
1601 wrmalt(Adapter, EEPROM_CMDQ_SPI_REG, &value, sizeof(value));
1602
1603 /* We can write back to back 8bits * 16 into the queue and as we have
1604 * checked for the queue to be empty we can write in a burst.
1605 */
1606
1607 value = uiData[0];
1608 BcmSwapWord(&value);
1609 wrm(Adapter, EEPROM_WRITE_DATAQ_REG, (PUCHAR)&value, 4);
1610
1611 value = uiData[1];
1612 BcmSwapWord(&value);
1613 wrm(Adapter, EEPROM_WRITE_DATAQ_REG, (PUCHAR)&value, 4);
1614
1615 value = uiData[2];
1616 BcmSwapWord(&value);
1617 wrm(Adapter, EEPROM_WRITE_DATAQ_REG, (PUCHAR)&value, 4);
1618
1619 value = uiData[3];
1620 BcmSwapWord(&value);
1621 wrm(Adapter, EEPROM_WRITE_DATAQ_REG, (PUCHAR)&value, 4);
1622
1623 /* NOTE : After this write, on readback of EEPROM_SPI_Q_STATUS1_REG
1624 * shows that we see 7 for the EEPROM data write. Which means that
1625 * queue got full, also space is available as well as the queue is empty.
1626 * This may happen in sequence.
1627 */
1628 value = EEPROM_16_BYTE_PAGE_WRITE | uiOffset;
1629 wrmalt(Adapter, EEPROM_CMDQ_SPI_REG, &value, sizeof(value));
1630
1631 /* Ideally we should loop here without tries and eventually succeed.
1632 * What we are checking if the previous write has completed, and this
1633 * may take time. We should wait till the Empty bit is set.
1634 */
1635 uiStatus = 0;
1636 rdmalt(Adapter, EEPROM_SPI_Q_STATUS1_REG, &uiStatus, sizeof(uiStatus));
1637 while ((uiStatus & EEPROM_WRITE_QUEUE_EMPTY) == 0) {
1638 uiRetries--;
1639 if (uiRetries == 0) {
1640 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "0x0f003004 = %x, %d retries failed.\n", uiStatus, MAX_EEPROM_RETRIES * RETRIES_PER_DELAY);
1641 return STATUS_FAILURE;
1642 }
1643
1644 if (!(uiRetries%RETRIES_PER_DELAY))
1645 udelay(1000);
1646
1647 uiStatus = 0;
1648 rdmalt(Adapter, EEPROM_SPI_Q_STATUS1_REG, &uiStatus, sizeof(uiStatus));
1649 if (Adapter->device_removed == TRUE) {
1650 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Modem got removed hence exiting from loop....");
1651 return -ENODEV;
1652 }
1653 }
1654
1655 if (uiRetries != 0) {
1656 /* Clear the ones that are set - either, Empty/Full/Avail bits */
1657 value = (uiStatus & (EEPROM_WRITE_QUEUE_EMPTY | EEPROM_WRITE_QUEUE_AVAIL | EEPROM_WRITE_QUEUE_FULL));
1658 wrmalt(Adapter, EEPROM_SPI_Q_STATUS1_REG, &value, sizeof(value));
1659 }
1660
1661 /* Here we should check if the EEPROM status register is correct before
1662 * proceeding. Bit 0 in the EEPROM Status register should be 0 before
1663 * we proceed further. A 1 at Bit 0 indicates that the EEPROM is busy
1664 * with the previous write. Note also that issuing this read finally
1665 * means the previous write to the EEPROM has completed.
1666 */
1667 uiRetries = MAX_EEPROM_RETRIES * RETRIES_PER_DELAY;
1668 uiEpromStatus = 0;
1669 while (uiRetries != 0) {
1670 uiEpromStatus = ReadEEPROMStatusRegister(Adapter);
1671 if (Adapter->device_removed == TRUE) {
1672 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Modem has got removed hence exiting from loop...");
1673 return -ENODEV;
1674 }
1675 if ((EEPROM_STATUS_REG_WRITE_BUSY & uiEpromStatus) == 0) {
1676 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "EEPROM status register = %x tries = %d\n", uiEpromStatus, (MAX_EEPROM_RETRIES * RETRIES_PER_DELAY - uiRetries));
1677 return STATUS_SUCCESS;
1678 }
1679 uiRetries--;
1680 if (uiRetries == 0) {
1681 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "0x0f003004 = %x, for EEPROM status read %d retries failed.\n", uiEpromStatus, MAX_EEPROM_RETRIES * RETRIES_PER_DELAY);
1682 return STATUS_FAILURE;
1683 }
1684 uiEpromStatus = 0;
1685 if (!(uiRetries%RETRIES_PER_DELAY))
1686 udelay(1000);
1687 }
1688
1689 return STATUS_SUCCESS;
1690} /* BeceemEEPROMWritePage */
1691
1692/*
1693 * Procedure: BeceemEEPROMBulkWrite
1694 *
1695 * Description: Performs write to the EEPROM
1696 *
1697 * Arguments:
1698 * Adapter - ptr to Adapter object instance
1699 * pBuffer - Data to be written.
1700 * uiOffset - Offset of the EEPROM where data needs to be written to.
1701 * uiNumBytes - Number of bytes to be written.
1702 * bVerify - read verify flag.
1703 * Returns:
1704 * OSAL_STATUS_CODE
1705 *
1706 */
1707
1708int BeceemEEPROMBulkWrite(struct bcm_mini_adapter *Adapter,
1709 PUCHAR pBuffer,
1710 unsigned int uiOffset,
1711 unsigned int uiNumBytes,
1712 bool bVerify)
1713{
1714 unsigned int uiBytesToCopy = uiNumBytes;
1715 /* unsigned int uiRdbk = 0; */
1716 unsigned int uiData[4] = {0};
1717 unsigned int uiIndex = 0;
1718 unsigned int uiTempOffset = 0;
1719 unsigned int uiExtraBytes = 0;
1720 /* PUINT puiBuffer = (PUINT)pBuffer;
1721 * int value;
1722 */
1723
1724 if (uiOffset % MAX_RW_SIZE && uiBytesToCopy) {
1725 uiTempOffset = uiOffset - (uiOffset % MAX_RW_SIZE);
1726 uiExtraBytes = uiOffset - uiTempOffset;
1727
1728 BeceemEEPROMBulkRead(Adapter, &uiData[0], uiTempOffset, MAX_RW_SIZE);
1729
1730 if (uiBytesToCopy >= (16 - uiExtraBytes)) {
1731 memcpy((((PUCHAR)&uiData[0]) + uiExtraBytes), pBuffer, MAX_RW_SIZE - uiExtraBytes);
1732
1733 if (STATUS_FAILURE == BeceemEEPROMWritePage(Adapter, uiData, uiTempOffset))
1734 return STATUS_FAILURE;
1735
1736 uiBytesToCopy -= (MAX_RW_SIZE - uiExtraBytes);
1737 uiIndex += (MAX_RW_SIZE - uiExtraBytes);
1738 uiOffset += (MAX_RW_SIZE - uiExtraBytes);
1739 } else {
1740 memcpy((((PUCHAR)&uiData[0]) + uiExtraBytes), pBuffer, uiBytesToCopy);
1741
1742 if (STATUS_FAILURE == BeceemEEPROMWritePage(Adapter, uiData, uiTempOffset))
1743 return STATUS_FAILURE;
1744
1745 uiIndex += uiBytesToCopy;
1746 uiOffset += uiBytesToCopy;
1747 uiBytesToCopy = 0;
1748 }
1749 }
1750
1751 while (uiBytesToCopy) {
1752 if (Adapter->device_removed)
1753 return -1;
1754
1755 if (uiBytesToCopy >= MAX_RW_SIZE) {
1756 if (STATUS_FAILURE == BeceemEEPROMWritePage(Adapter, (PUINT) &pBuffer[uiIndex], uiOffset))
1757 return STATUS_FAILURE;
1758
1759 uiIndex += MAX_RW_SIZE;
1760 uiOffset += MAX_RW_SIZE;
1761 uiBytesToCopy -= MAX_RW_SIZE;
1762 } else {
1763 /*
1764 * To program non 16byte aligned data, read 16byte and then update.
1765 */
1766 BeceemEEPROMBulkRead(Adapter, &uiData[0], uiOffset, 16);
1767 memcpy(&uiData[0], pBuffer + uiIndex, uiBytesToCopy);
1768
1769 if (STATUS_FAILURE == BeceemEEPROMWritePage(Adapter, uiData, uiOffset))
1770 return STATUS_FAILURE;
1771
1772 uiBytesToCopy = 0;
1773 }
1774 }
1775
1776 return 0;
1777}
1778
1779/*
1780 * Procedure: BeceemNVMRead
1781 *
1782 * Description: Reads n number of bytes from NVM.
1783 *
1784 * Arguments:
1785 * Adapter - ptr to Adapter object instance
1786 * pBuffer - Buffer to store the data read from NVM
1787 * uiOffset - Offset of NVM from where data should be read
1788 * uiNumBytes - Number of bytes to be read from the NVM.
1789 *
1790 * Returns:
1791 * OSAL_STATUS_SUCCESS - if NVM read is successful.
1792 * <FAILURE> - if failed.
1793 */
1794
1795int BeceemNVMRead(struct bcm_mini_adapter *Adapter,
1796 PUINT pBuffer,
1797 unsigned int uiOffset,
1798 unsigned int uiNumBytes)
1799{
1800 int Status = 0;
1801
1802 #if !defined(BCM_SHM_INTERFACE) || defined(FLASH_DIRECT_ACCESS)
1803 unsigned int uiTemp = 0, value;
1804 #endif
1805
1806 if (Adapter->eNVMType == NVM_FLASH) {
1807 if (Adapter->bFlashRawRead == false) {
1808 if (IsSectionExistInVendorInfo(Adapter, Adapter->eActiveDSD))
1809 return vendorextnReadSection(Adapter, (PUCHAR)pBuffer, Adapter->eActiveDSD, uiOffset, uiNumBytes);
1810
1811 uiOffset = uiOffset + Adapter->ulFlashCalStart;
1812 }
1813
1814 #if defined(BCM_SHM_INTERFACE) && !defined(FLASH_DIRECT_ACCESS)
1815 Status = bcmflash_raw_read((uiOffset / FLASH_PART_SIZE), (uiOffset % FLASH_PART_SIZE), (unsigned char *)pBuffer, uiNumBytes);
1816 #else
1817 rdmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
1818 value = 0;
1819 wrmalt(Adapter, 0x0f000C80, &value, sizeof(value));
1820 Status = BeceemFlashBulkRead(Adapter,
1821 pBuffer,
1822 uiOffset,
1823 uiNumBytes);
1824 wrmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
1825 #endif
1826 } else if (Adapter->eNVMType == NVM_EEPROM) {
1827 Status = BeceemEEPROMBulkRead(Adapter,
1828 pBuffer,
1829 uiOffset,
1830 uiNumBytes);
1831 } else {
1832 Status = -1;
1833 }
1834
1835 return Status;
1836}
1837
1838/*
1839 * Procedure: BeceemNVMWrite
1840 *
1841 * Description: Writes n number of bytes to NVM.
1842 *
1843 * Arguments:
1844 * Adapter - ptr to Adapter object instance
1845 * pBuffer - Buffer contains the data to be written.
1846 * uiOffset - Offset of NVM where data to be written to.
1847 * uiNumBytes - Number of bytes to be written..
1848 *
1849 * Returns:
1850 * OSAL_STATUS_SUCCESS - if NVM write is successful.
1851 * <FAILURE> - if failed.
1852 */
1853
1854int BeceemNVMWrite(struct bcm_mini_adapter *Adapter,
1855 PUINT pBuffer,
1856 unsigned int uiOffset,
1857 unsigned int uiNumBytes,
1858 bool bVerify)
1859{
1860 int Status = 0;
1861 unsigned int uiTemp = 0;
1862 unsigned int uiMemoryLoc = EEPROM_CAL_DATA_INTERNAL_LOC;
1863 unsigned int uiIndex = 0;
1864
1865 #if !defined(BCM_SHM_INTERFACE) || defined(FLASH_DIRECT_ACCESS)
1866 unsigned int value;
1867 #endif
1868
1869 unsigned int uiFlashOffset = 0;
1870
1871 if (Adapter->eNVMType == NVM_FLASH) {
1872 if (IsSectionExistInVendorInfo(Adapter, Adapter->eActiveDSD))
1873 Status = vendorextnWriteSection(Adapter, (PUCHAR)pBuffer, Adapter->eActiveDSD, uiOffset, uiNumBytes, bVerify);
1874 else {
1875 uiFlashOffset = uiOffset + Adapter->ulFlashCalStart;
1876
1877 #if defined(BCM_SHM_INTERFACE) && !defined(FLASH_DIRECT_ACCESS)
1878 Status = bcmflash_raw_write((uiFlashOffset / FLASH_PART_SIZE), (uiFlashOffset % FLASH_PART_SIZE), (unsigned char *)pBuffer, uiNumBytes);
1879 #else
1880 rdmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
1881 value = 0;
1882 wrmalt(Adapter, 0x0f000C80, &value, sizeof(value));
1883
1884 if (Adapter->bStatusWrite == TRUE)
1885 Status = BeceemFlashBulkWriteStatus(Adapter,
1886 pBuffer,
1887 uiFlashOffset,
1888 uiNumBytes ,
1889 bVerify);
1890 else
1891
1892 Status = BeceemFlashBulkWrite(Adapter,
1893 pBuffer,
1894 uiFlashOffset,
1895 uiNumBytes,
1896 bVerify);
1897 #endif
1898 }
1899
1900 if (uiOffset >= EEPROM_CALPARAM_START) {
1901 uiMemoryLoc += (uiOffset - EEPROM_CALPARAM_START);
1902 while (uiNumBytes) {
1903 if (uiNumBytes > BUFFER_4K) {
1904 wrm(Adapter, (uiMemoryLoc+uiIndex), (PCHAR)(pBuffer + (uiIndex / 4)), BUFFER_4K);
1905 uiNumBytes -= BUFFER_4K;
1906 uiIndex += BUFFER_4K;
1907 } else {
1908 wrm(Adapter, uiMemoryLoc+uiIndex, (PCHAR)(pBuffer + (uiIndex / 4)), uiNumBytes);
1909 uiNumBytes = 0;
1910 break;
1911 }
1912 }
1913 } else {
1914 if ((uiOffset + uiNumBytes) > EEPROM_CALPARAM_START) {
1915 ULONG ulBytesTobeSkipped = 0;
1916 PUCHAR pcBuffer = (PUCHAR)pBuffer; /* char pointer to take care of odd byte cases. */
1917
1918 uiNumBytes -= (EEPROM_CALPARAM_START - uiOffset);
1919 ulBytesTobeSkipped += (EEPROM_CALPARAM_START - uiOffset);
1920 uiOffset += (EEPROM_CALPARAM_START - uiOffset);
1921 while (uiNumBytes) {
1922 if (uiNumBytes > BUFFER_4K) {
1923 wrm(Adapter, uiMemoryLoc + uiIndex, (PCHAR)&pcBuffer[ulBytesTobeSkipped + uiIndex], BUFFER_4K);
1924 uiNumBytes -= BUFFER_4K;
1925 uiIndex += BUFFER_4K;
1926 } else {
1927 wrm(Adapter, uiMemoryLoc + uiIndex, (PCHAR)&pcBuffer[ulBytesTobeSkipped + uiIndex], uiNumBytes);
1928 uiNumBytes = 0;
1929 break;
1930 }
1931 }
1932 }
1933 }
1934 /* restore the values. */
1935 wrmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
1936 } else if (Adapter->eNVMType == NVM_EEPROM) {
1937 Status = BeceemEEPROMBulkWrite(Adapter,
1938 (PUCHAR)pBuffer,
1939 uiOffset,
1940 uiNumBytes,
1941 bVerify);
1942 if (bVerify)
1943 Status = BeceemEEPROMReadBackandVerify(Adapter, (PUINT)pBuffer, uiOffset, uiNumBytes);
1944 } else {
1945 Status = -1;
1946 }
1947 return Status;
1948}
1949
1950/*
1951 * Procedure: BcmUpdateSectorSize
1952 *
1953 * Description: Updates the sector size to FLASH.
1954 *
1955 * Arguments:
1956 * Adapter - ptr to Adapter object instance
1957 * uiSectorSize - sector size
1958 *
1959 * Returns:
1960 * OSAL_STATUS_SUCCESS - if NVM write is successful.
1961 * <FAILURE> - if failed.
1962 */
1963
1964int BcmUpdateSectorSize(struct bcm_mini_adapter *Adapter, unsigned int uiSectorSize)
1965{
1966 int Status = -1;
1967 struct bcm_flash_cs_info sFlashCsInfo = {0};
1968 unsigned int uiTemp = 0;
1969 unsigned int uiSectorSig = 0;
1970 unsigned int uiCurrentSectorSize = 0;
1971 unsigned int value;
1972
1973 rdmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
1974 value = 0;
1975 wrmalt(Adapter, 0x0f000C80, &value, sizeof(value));
1976
1977 /*
1978 * Before updating the sector size in the reserved area, check if already present.
1979 */
1980 BeceemFlashBulkRead(Adapter, (PUINT)&sFlashCsInfo, Adapter->ulFlashControlSectionStart, sizeof(sFlashCsInfo));
1981 uiSectorSig = ntohl(sFlashCsInfo.FlashSectorSizeSig);
1982 uiCurrentSectorSize = ntohl(sFlashCsInfo.FlashSectorSize);
1983
1984 if (uiSectorSig == FLASH_SECTOR_SIZE_SIG) {
1985 if ((uiCurrentSectorSize <= MAX_SECTOR_SIZE) && (uiCurrentSectorSize >= MIN_SECTOR_SIZE)) {
1986 if (uiSectorSize == uiCurrentSectorSize) {
1987 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Provided sector size is same as programmed in Flash");
1988 Status = STATUS_SUCCESS;
1989 goto Restore;
1990 }
1991 }
1992 }
1993
1994 if ((uiSectorSize <= MAX_SECTOR_SIZE) && (uiSectorSize >= MIN_SECTOR_SIZE)) {
1995 sFlashCsInfo.FlashSectorSize = htonl(uiSectorSize);
1996 sFlashCsInfo.FlashSectorSizeSig = htonl(FLASH_SECTOR_SIZE_SIG);
1997
1998 Status = BeceemFlashBulkWrite(Adapter,
1999 (PUINT)&sFlashCsInfo,
2000 Adapter->ulFlashControlSectionStart,
2001 sizeof(sFlashCsInfo),
2002 TRUE);
2003 }
2004
2005Restore:
2006 /* restore the values. */
2007 wrmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
2008
2009 return Status;
2010}
2011
2012/*
2013 * Procedure: BcmGetFlashSectorSize
2014 *
2015 * Description: Finds the sector size of the FLASH.
2016 *
2017 * Arguments:
2018 * Adapter - ptr to Adapter object instance
2019 *
2020 * Returns:
2021 * unsigned int - sector size.
2022 *
2023 */
2024
2025static unsigned int BcmGetFlashSectorSize(struct bcm_mini_adapter *Adapter, unsigned int FlashSectorSizeSig, unsigned int FlashSectorSize)
2026{
2027 unsigned int uiSectorSize = 0;
2028 unsigned int uiSectorSig = 0;
2029
2030 if (Adapter->bSectorSizeOverride &&
2031 (Adapter->uiSectorSizeInCFG <= MAX_SECTOR_SIZE &&
2032 Adapter->uiSectorSizeInCFG >= MIN_SECTOR_SIZE)) {
2033 Adapter->uiSectorSize = Adapter->uiSectorSizeInCFG;
2034 } else {
2035 uiSectorSig = FlashSectorSizeSig;
2036
2037 if (uiSectorSig == FLASH_SECTOR_SIZE_SIG) {
2038 uiSectorSize = FlashSectorSize;
2039 /*
2040 * If the sector size stored in the FLASH makes sense then use it.
2041 */
2042 if (uiSectorSize <= MAX_SECTOR_SIZE && uiSectorSize >= MIN_SECTOR_SIZE) {
2043 Adapter->uiSectorSize = uiSectorSize;
2044 } else if (Adapter->uiSectorSizeInCFG <= MAX_SECTOR_SIZE &&
2045 Adapter->uiSectorSizeInCFG >= MIN_SECTOR_SIZE) {
2046 /* No valid size in FLASH, check if Config file has it. */
2047 Adapter->uiSectorSize = Adapter->uiSectorSizeInCFG;
2048 } else {
2049 /* Init to Default, if none of the above works. */
2050 Adapter->uiSectorSize = DEFAULT_SECTOR_SIZE;
2051 }
2052 } else {
2053 if (Adapter->uiSectorSizeInCFG <= MAX_SECTOR_SIZE &&
2054 Adapter->uiSectorSizeInCFG >= MIN_SECTOR_SIZE)
2055 Adapter->uiSectorSize = Adapter->uiSectorSizeInCFG;
2056 else
2057 Adapter->uiSectorSize = DEFAULT_SECTOR_SIZE;
2058 }
2059 }
2060
2061 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Sector size :%x\n", Adapter->uiSectorSize);
2062
2063 return Adapter->uiSectorSize;
2064}
2065
2066/*
2067 * Procedure: BcmInitEEPROMQueues
2068 *
2069 * Description: Initialization of EEPROM queues.
2070 *
2071 * Arguments:
2072 * Adapter - ptr to Adapter object instance
2073 *
2074 * Returns:
2075 * <OSAL_STATUS_CODE>
2076 */
2077
2078static int BcmInitEEPROMQueues(struct bcm_mini_adapter *Adapter)
2079{
2080 unsigned int value = 0;
2081 /* CHIP Bug : Clear the Avail bits on the Read queue. The default
2082 * value on this register is supposed to be 0x00001102.
2083 * But we get 0x00001122.
2084 */
2085 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Fixing reset value on 0x0f003004 register\n");
2086 value = EEPROM_READ_DATA_AVAIL;
2087 wrmalt(Adapter, EEPROM_SPI_Q_STATUS1_REG, &value, sizeof(value));
2088
2089 /* Flush the all the EEPROM queues. */
2090 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, " Flushing the queues\n");
2091 value = EEPROM_ALL_QUEUE_FLUSH;
2092 wrmalt(Adapter, SPI_FLUSH_REG, &value, sizeof(value));
2093
2094 value = 0;
2095 wrmalt(Adapter, SPI_FLUSH_REG, &value, sizeof(value));
2096
2097 /* Read the EEPROM Status Register. Just to see, no real purpose. */
2098 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "EEPROM Status register value = %x\n", ReadEEPROMStatusRegister(Adapter));
2099
2100 return STATUS_SUCCESS;
2101} /* BcmInitEEPROMQueues() */
2102
2103/*
2104 * Procedure: BcmInitNVM
2105 *
2106 * Description: Initialization of NVM, EEPROM size,FLASH size, sector size etc.
2107 *
2108 * Arguments:
2109 * Adapter - ptr to Adapter object instance
2110 *
2111 * Returns:
2112 * <OSAL_STATUS_CODE>
2113 */
2114
2115int BcmInitNVM(struct bcm_mini_adapter *ps_adapter)
2116{
2117 BcmValidateNvmType(ps_adapter);
2118 BcmInitEEPROMQueues(ps_adapter);
2119
2120 if (ps_adapter->eNVMType == NVM_AUTODETECT) {
2121 ps_adapter->eNVMType = BcmGetNvmType(ps_adapter);
2122 if (ps_adapter->eNVMType == NVM_UNKNOWN)
2123 BCM_DEBUG_PRINT(ps_adapter, DBG_TYPE_PRINTK, 0, 0, "NVM Type is unknown!!\n");
2124 } else if (ps_adapter->eNVMType == NVM_FLASH) {
2125 BcmGetFlashCSInfo(ps_adapter);
2126 }
2127
2128 BcmGetNvmSize(ps_adapter);
2129
2130 return STATUS_SUCCESS;
2131}
2132
2133/* BcmGetNvmSize : set the EEPROM or flash size in Adapter.
2134 *
2135 * Input Parameter:
2136 * Adapter data structure
2137 * Return Value :
2138 * 0. means success;
2139 */
2140
2141static int BcmGetNvmSize(struct bcm_mini_adapter *Adapter)
2142{
2143 if (Adapter->eNVMType == NVM_EEPROM)
2144 Adapter->uiNVMDSDSize = BcmGetEEPROMSize(Adapter);
2145 else if (Adapter->eNVMType == NVM_FLASH)
2146 Adapter->uiNVMDSDSize = BcmGetFlashSize(Adapter);
2147
2148 return 0;
2149}
2150
2151/*
2152 * Procedure: BcmValidateNvm
2153 *
2154 * Description: Validates the NVM Type option selected against the device
2155 *
2156 * Arguments:
2157 * Adapter - ptr to Adapter object instance
2158 *
2159 * Returns:
2160 * <VOID>
2161 */
2162
2163static VOID BcmValidateNvmType(struct bcm_mini_adapter *Adapter)
2164{
2165 /*
2166 * if forcing the FLASH through CFG file, we should ensure device really has a FLASH.
2167 * Accessing the FLASH address without the FLASH being present can cause hang/freeze etc.
2168 * So if NVM_FLASH is selected for older chipsets, change it to AUTODETECT where EEPROM is 1st choice.
2169 */
2170
2171 if (Adapter->eNVMType == NVM_FLASH &&
2172 Adapter->chip_id < 0xBECE3300)
2173 Adapter->eNVMType = NVM_AUTODETECT;
2174}
2175
2176/*
2177 * Procedure: BcmReadFlashRDID
2178 *
2179 * Description: Reads ID from Serial Flash
2180 *
2181 * Arguments:
2182 * Adapter - ptr to Adapter object instance
2183 *
2184 * Returns:
2185 * Flash ID
2186 */
2187
2188static ULONG BcmReadFlashRDID(struct bcm_mini_adapter *Adapter)
2189{
2190 ULONG ulRDID = 0;
2191 unsigned int value;
2192
2193 /*
2194 * Read ID Instruction.
2195 */
2196 value = (FLASH_CMD_READ_ID << 24);
2197 wrmalt(Adapter, FLASH_SPI_CMDQ_REG, &value, sizeof(value));
2198
2199 /* Delay */
2200 udelay(10);
2201
2202 /*
2203 * Read SPI READQ REG. The output will be WWXXYYZZ.
2204 * The ID is 3Bytes long and is WWXXYY. ZZ needs to be Ignored.
2205 */
2206 rdmalt(Adapter, FLASH_SPI_READQ_REG, (PUINT)&ulRDID, sizeof(ulRDID));
2207
2208 return ulRDID >> 8;
2209}
2210
2211int BcmAllocFlashCSStructure(struct bcm_mini_adapter *psAdapter)
2212{
2213 if (!psAdapter) {
2214 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_PRINTK, 0, 0, "Adapter structure point is NULL");
2215 return -EINVAL;
2216 }
2217 psAdapter->psFlashCSInfo = kzalloc(sizeof(struct bcm_flash_cs_info), GFP_KERNEL);
2218 if (psAdapter->psFlashCSInfo == NULL) {
2219 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_PRINTK, 0, 0, "Can't Allocate memory for Flash 1.x");
2220 return -ENOMEM;
2221 }
2222
2223 psAdapter->psFlash2xCSInfo = kzalloc(sizeof(struct bcm_flash2x_cs_info), GFP_KERNEL);
2224 if (!psAdapter->psFlash2xCSInfo) {
2225 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_PRINTK, 0, 0, "Can't Allocate memory for Flash 2.x");
2226 kfree(psAdapter->psFlashCSInfo);
2227 return -ENOMEM;
2228 }
2229
2230 psAdapter->psFlash2xVendorInfo = kzalloc(sizeof(struct bcm_flash2x_vendor_info), GFP_KERNEL);
2231 if (!psAdapter->psFlash2xVendorInfo) {
2232 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_PRINTK, 0, 0, "Can't Allocate Vendor Info Memory for Flash 2.x");
2233 kfree(psAdapter->psFlashCSInfo);
2234 kfree(psAdapter->psFlash2xCSInfo);
2235 return -ENOMEM;
2236 }
2237
2238 return STATUS_SUCCESS;
2239}
2240
2241int BcmDeAllocFlashCSStructure(struct bcm_mini_adapter *psAdapter)
2242{
2243 if (!psAdapter) {
2244 BCM_DEBUG_PRINT(psAdapter, DBG_TYPE_PRINTK, 0, 0, "Adapter structure point is NULL");
2245 return -EINVAL;
2246 }
2247 kfree(psAdapter->psFlashCSInfo);
2248 kfree(psAdapter->psFlash2xCSInfo);
2249 kfree(psAdapter->psFlash2xVendorInfo);
2250 return STATUS_SUCCESS;
2251}
2252
2253static int BcmDumpFlash2XCSStructure(struct bcm_flash2x_cs_info *psFlash2xCSInfo, struct bcm_mini_adapter *Adapter)
2254{
2255 unsigned int Index = 0;
2256
2257 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "**********************FLASH2X CS Structure *******************");
2258 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Signature is :%x", (psFlash2xCSInfo->MagicNumber));
2259 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Flash Major Version :%d", MAJOR_VERSION(psFlash2xCSInfo->FlashLayoutVersion));
2260 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Flash Minor Version :%d", MINOR_VERSION(psFlash2xCSInfo->FlashLayoutVersion));
2261 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, " ISOImageMajorVersion:0x%x", (psFlash2xCSInfo->ISOImageVersion));
2262 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "SCSIFirmwareMajorVersion :0x%x", (psFlash2xCSInfo->SCSIFirmwareVersion));
2263 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForPart1ISOImage :0x%x", (psFlash2xCSInfo->OffsetFromZeroForPart1ISOImage));
2264 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForScsiFirmware :0x%x", (psFlash2xCSInfo->OffsetFromZeroForScsiFirmware));
2265 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "SizeOfScsiFirmware :0x%x", (psFlash2xCSInfo->SizeOfScsiFirmware));
2266 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForPart2ISOImage :0x%x", (psFlash2xCSInfo->OffsetFromZeroForPart2ISOImage));
2267 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForDSDStart :0x%x", (psFlash2xCSInfo->OffsetFromZeroForDSDStart));
2268 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForDSDEnd :0x%x", (psFlash2xCSInfo->OffsetFromZeroForDSDEnd));
2269 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForVSAStart :0x%x", (psFlash2xCSInfo->OffsetFromZeroForVSAStart));
2270 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForVSAEnd :0x%x", (psFlash2xCSInfo->OffsetFromZeroForVSAEnd));
2271 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForControlSectionStart :0x%x", (psFlash2xCSInfo->OffsetFromZeroForControlSectionStart));
2272 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForControlSectionData :0x%x", (psFlash2xCSInfo->OffsetFromZeroForControlSectionData));
2273 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "CDLessInactivityTimeout :0x%x", (psFlash2xCSInfo->CDLessInactivityTimeout));
2274 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "NewImageSignature :0x%x", (psFlash2xCSInfo->NewImageSignature));
2275 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "FlashSectorSizeSig :0x%x", (psFlash2xCSInfo->FlashSectorSizeSig));
2276 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "FlashSectorSize :0x%x", (psFlash2xCSInfo->FlashSectorSize));
2277 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "FlashWriteSupportSize :0x%x", (psFlash2xCSInfo->FlashWriteSupportSize));
2278 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "TotalFlashSize :0x%X", (psFlash2xCSInfo->TotalFlashSize));
2279 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "FlashBaseAddr :0x%x", (psFlash2xCSInfo->FlashBaseAddr));
2280 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "FlashPartMaxSize :0x%x", (psFlash2xCSInfo->FlashPartMaxSize));
2281 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "IsCDLessDeviceBootSig :0x%x", (psFlash2xCSInfo->IsCDLessDeviceBootSig));
2282 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "MassStorageTimeout :0x%x", (psFlash2xCSInfo->MassStorageTimeout));
2283 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage1Part1Start :0x%x", (psFlash2xCSInfo->OffsetISOImage1Part1Start));
2284 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage1Part1End :0x%x", (psFlash2xCSInfo->OffsetISOImage1Part1End));
2285 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage1Part2Start :0x%x", (psFlash2xCSInfo->OffsetISOImage1Part2Start));
2286 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage1Part2End :0x%x", (psFlash2xCSInfo->OffsetISOImage1Part2End));
2287 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage1Part3Start :0x%x", (psFlash2xCSInfo->OffsetISOImage1Part3Start));
2288 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage1Part3End :0x%x", (psFlash2xCSInfo->OffsetISOImage1Part3End));
2289 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage2Part1Start :0x%x", (psFlash2xCSInfo->OffsetISOImage2Part1Start));
2290 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage2Part1End :0x%x", (psFlash2xCSInfo->OffsetISOImage2Part1End));
2291 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage2Part2Start :0x%x", (psFlash2xCSInfo->OffsetISOImage2Part2Start));
2292 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage2Part2End :0x%x", (psFlash2xCSInfo->OffsetISOImage2Part2End));
2293 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage2Part3Start :0x%x", (psFlash2xCSInfo->OffsetISOImage2Part3Start));
2294 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetISOImage2Part3End :0x%x", (psFlash2xCSInfo->OffsetISOImage2Part3End));
2295 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromDSDStartForDSDHeader :0x%x", (psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader));
2296 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForDSD1Start :0x%x", (psFlash2xCSInfo->OffsetFromZeroForDSD1Start));
2297 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForDSD1End :0x%x", (psFlash2xCSInfo->OffsetFromZeroForDSD1End));
2298 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForDSD2Start :0x%x", (psFlash2xCSInfo->OffsetFromZeroForDSD2Start));
2299 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForDSD2End :0x%x", (psFlash2xCSInfo->OffsetFromZeroForDSD2End));
2300 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForVSA1Start :0x%x", (psFlash2xCSInfo->OffsetFromZeroForVSA1Start));
2301 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForVSA1End :0x%x", (psFlash2xCSInfo->OffsetFromZeroForVSA1End));
2302 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForVSA2Start :0x%x", (psFlash2xCSInfo->OffsetFromZeroForVSA2Start));
2303 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "OffsetFromZeroForVSA2End :0x%x", (psFlash2xCSInfo->OffsetFromZeroForVSA2End));
2304 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Sector Access Bit Map is Defined as :");
2305
2306 for (Index = 0; Index < (FLASH2X_TOTAL_SIZE / (DEFAULT_SECTOR_SIZE * 16)); Index++)
2307 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "SectorAccessBitMap[%d] :0x%x", Index,
2308 (psFlash2xCSInfo->SectorAccessBitMap[Index]));
2309
2310 return STATUS_SUCCESS;
2311}
2312
2313static int ConvertEndianOf2XCSStructure(struct bcm_flash2x_cs_info *psFlash2xCSInfo)
2314{
2315 unsigned int Index = 0;
2316
2317 psFlash2xCSInfo->MagicNumber = ntohl(psFlash2xCSInfo->MagicNumber);
2318 psFlash2xCSInfo->FlashLayoutVersion = ntohl(psFlash2xCSInfo->FlashLayoutVersion);
2319 /* psFlash2xCSInfo->FlashLayoutMinorVersion = ntohs(psFlash2xCSInfo->FlashLayoutMinorVersion); */
2320 psFlash2xCSInfo->ISOImageVersion = ntohl(psFlash2xCSInfo->ISOImageVersion);
2321 psFlash2xCSInfo->SCSIFirmwareVersion = ntohl(psFlash2xCSInfo->SCSIFirmwareVersion);
2322 psFlash2xCSInfo->OffsetFromZeroForPart1ISOImage = ntohl(psFlash2xCSInfo->OffsetFromZeroForPart1ISOImage);
2323 psFlash2xCSInfo->OffsetFromZeroForScsiFirmware = ntohl(psFlash2xCSInfo->OffsetFromZeroForScsiFirmware);
2324 psFlash2xCSInfo->SizeOfScsiFirmware = ntohl(psFlash2xCSInfo->SizeOfScsiFirmware);
2325 psFlash2xCSInfo->OffsetFromZeroForPart2ISOImage = ntohl(psFlash2xCSInfo->OffsetFromZeroForPart2ISOImage);
2326 psFlash2xCSInfo->OffsetFromZeroForDSDStart = ntohl(psFlash2xCSInfo->OffsetFromZeroForDSDStart);
2327 psFlash2xCSInfo->OffsetFromZeroForDSDEnd = ntohl(psFlash2xCSInfo->OffsetFromZeroForDSDEnd);
2328 psFlash2xCSInfo->OffsetFromZeroForVSAStart = ntohl(psFlash2xCSInfo->OffsetFromZeroForVSAStart);
2329 psFlash2xCSInfo->OffsetFromZeroForVSAEnd = ntohl(psFlash2xCSInfo->OffsetFromZeroForVSAEnd);
2330 psFlash2xCSInfo->OffsetFromZeroForControlSectionStart = ntohl(psFlash2xCSInfo->OffsetFromZeroForControlSectionStart);
2331 psFlash2xCSInfo->OffsetFromZeroForControlSectionData = ntohl(psFlash2xCSInfo->OffsetFromZeroForControlSectionData);
2332 psFlash2xCSInfo->CDLessInactivityTimeout = ntohl(psFlash2xCSInfo->CDLessInactivityTimeout);
2333 psFlash2xCSInfo->NewImageSignature = ntohl(psFlash2xCSInfo->NewImageSignature);
2334 psFlash2xCSInfo->FlashSectorSizeSig = ntohl(psFlash2xCSInfo->FlashSectorSizeSig);
2335 psFlash2xCSInfo->FlashSectorSize = ntohl(psFlash2xCSInfo->FlashSectorSize);
2336 psFlash2xCSInfo->FlashWriteSupportSize = ntohl(psFlash2xCSInfo->FlashWriteSupportSize);
2337 psFlash2xCSInfo->TotalFlashSize = ntohl(psFlash2xCSInfo->TotalFlashSize);
2338 psFlash2xCSInfo->FlashBaseAddr = ntohl(psFlash2xCSInfo->FlashBaseAddr);
2339 psFlash2xCSInfo->FlashPartMaxSize = ntohl(psFlash2xCSInfo->FlashPartMaxSize);
2340 psFlash2xCSInfo->IsCDLessDeviceBootSig = ntohl(psFlash2xCSInfo->IsCDLessDeviceBootSig);
2341 psFlash2xCSInfo->MassStorageTimeout = ntohl(psFlash2xCSInfo->MassStorageTimeout);
2342 psFlash2xCSInfo->OffsetISOImage1Part1Start = ntohl(psFlash2xCSInfo->OffsetISOImage1Part1Start);
2343 psFlash2xCSInfo->OffsetISOImage1Part1End = ntohl(psFlash2xCSInfo->OffsetISOImage1Part1End);
2344 psFlash2xCSInfo->OffsetISOImage1Part2Start = ntohl(psFlash2xCSInfo->OffsetISOImage1Part2Start);
2345 psFlash2xCSInfo->OffsetISOImage1Part2End = ntohl(psFlash2xCSInfo->OffsetISOImage1Part2End);
2346 psFlash2xCSInfo->OffsetISOImage1Part3Start = ntohl(psFlash2xCSInfo->OffsetISOImage1Part3Start);
2347 psFlash2xCSInfo->OffsetISOImage1Part3End = ntohl(psFlash2xCSInfo->OffsetISOImage1Part3End);
2348 psFlash2xCSInfo->OffsetISOImage2Part1Start = ntohl(psFlash2xCSInfo->OffsetISOImage2Part1Start);
2349 psFlash2xCSInfo->OffsetISOImage2Part1End = ntohl(psFlash2xCSInfo->OffsetISOImage2Part1End);
2350 psFlash2xCSInfo->OffsetISOImage2Part2Start = ntohl(psFlash2xCSInfo->OffsetISOImage2Part2Start);
2351 psFlash2xCSInfo->OffsetISOImage2Part2End = ntohl(psFlash2xCSInfo->OffsetISOImage2Part2End);
2352 psFlash2xCSInfo->OffsetISOImage2Part3Start = ntohl(psFlash2xCSInfo->OffsetISOImage2Part3Start);
2353 psFlash2xCSInfo->OffsetISOImage2Part3End = ntohl(psFlash2xCSInfo->OffsetISOImage2Part3End);
2354 psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader = ntohl(psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader);
2355 psFlash2xCSInfo->OffsetFromZeroForDSD1Start = ntohl(psFlash2xCSInfo->OffsetFromZeroForDSD1Start);
2356 psFlash2xCSInfo->OffsetFromZeroForDSD1End = ntohl(psFlash2xCSInfo->OffsetFromZeroForDSD1End);
2357 psFlash2xCSInfo->OffsetFromZeroForDSD2Start = ntohl(psFlash2xCSInfo->OffsetFromZeroForDSD2Start);
2358 psFlash2xCSInfo->OffsetFromZeroForDSD2End = ntohl(psFlash2xCSInfo->OffsetFromZeroForDSD2End);
2359 psFlash2xCSInfo->OffsetFromZeroForVSA1Start = ntohl(psFlash2xCSInfo->OffsetFromZeroForVSA1Start);
2360 psFlash2xCSInfo->OffsetFromZeroForVSA1End = ntohl(psFlash2xCSInfo->OffsetFromZeroForVSA1End);
2361 psFlash2xCSInfo->OffsetFromZeroForVSA2Start = ntohl(psFlash2xCSInfo->OffsetFromZeroForVSA2Start);
2362 psFlash2xCSInfo->OffsetFromZeroForVSA2End = ntohl(psFlash2xCSInfo->OffsetFromZeroForVSA2End);
2363
2364 for (Index = 0; Index < (FLASH2X_TOTAL_SIZE / (DEFAULT_SECTOR_SIZE * 16)); Index++)
2365 psFlash2xCSInfo->SectorAccessBitMap[Index] = ntohl(psFlash2xCSInfo->SectorAccessBitMap[Index]);
2366
2367 return STATUS_SUCCESS;
2368}
2369
2370static int ConvertEndianOfCSStructure(struct bcm_flash_cs_info *psFlashCSInfo)
2371{
2372 /* unsigned int Index = 0; */
2373 psFlashCSInfo->MagicNumber = ntohl(psFlashCSInfo->MagicNumber);
2374 psFlashCSInfo->FlashLayoutVersion = ntohl(psFlashCSInfo->FlashLayoutVersion);
2375 psFlashCSInfo->ISOImageVersion = ntohl(psFlashCSInfo->ISOImageVersion);
2376 /* won't convert according to old assumption */
2377 psFlashCSInfo->SCSIFirmwareVersion = (psFlashCSInfo->SCSIFirmwareVersion);
2378 psFlashCSInfo->OffsetFromZeroForPart1ISOImage = ntohl(psFlashCSInfo->OffsetFromZeroForPart1ISOImage);
2379 psFlashCSInfo->OffsetFromZeroForScsiFirmware = ntohl(psFlashCSInfo->OffsetFromZeroForScsiFirmware);
2380 psFlashCSInfo->SizeOfScsiFirmware = ntohl(psFlashCSInfo->SizeOfScsiFirmware);
2381 psFlashCSInfo->OffsetFromZeroForPart2ISOImage = ntohl(psFlashCSInfo->OffsetFromZeroForPart2ISOImage);
2382 psFlashCSInfo->OffsetFromZeroForCalibrationStart = ntohl(psFlashCSInfo->OffsetFromZeroForCalibrationStart);
2383 psFlashCSInfo->OffsetFromZeroForCalibrationEnd = ntohl(psFlashCSInfo->OffsetFromZeroForCalibrationEnd);
2384 psFlashCSInfo->OffsetFromZeroForVSAStart = ntohl(psFlashCSInfo->OffsetFromZeroForVSAStart);
2385 psFlashCSInfo->OffsetFromZeroForVSAEnd = ntohl(psFlashCSInfo->OffsetFromZeroForVSAEnd);
2386 psFlashCSInfo->OffsetFromZeroForControlSectionStart = ntohl(psFlashCSInfo->OffsetFromZeroForControlSectionStart);
2387 psFlashCSInfo->OffsetFromZeroForControlSectionData = ntohl(psFlashCSInfo->OffsetFromZeroForControlSectionData);
2388 psFlashCSInfo->CDLessInactivityTimeout = ntohl(psFlashCSInfo->CDLessInactivityTimeout);
2389 psFlashCSInfo->NewImageSignature = ntohl(psFlashCSInfo->NewImageSignature);
2390 psFlashCSInfo->FlashSectorSizeSig = ntohl(psFlashCSInfo->FlashSectorSizeSig);
2391 psFlashCSInfo->FlashSectorSize = ntohl(psFlashCSInfo->FlashSectorSize);
2392 psFlashCSInfo->FlashWriteSupportSize = ntohl(psFlashCSInfo->FlashWriteSupportSize);
2393 psFlashCSInfo->TotalFlashSize = ntohl(psFlashCSInfo->TotalFlashSize);
2394 psFlashCSInfo->FlashBaseAddr = ntohl(psFlashCSInfo->FlashBaseAddr);
2395 psFlashCSInfo->FlashPartMaxSize = ntohl(psFlashCSInfo->FlashPartMaxSize);
2396 psFlashCSInfo->IsCDLessDeviceBootSig = ntohl(psFlashCSInfo->IsCDLessDeviceBootSig);
2397 psFlashCSInfo->MassStorageTimeout = ntohl(psFlashCSInfo->MassStorageTimeout);
2398
2399 return STATUS_SUCCESS;
2400}
2401
2402static int IsSectionExistInVendorInfo(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val section)
2403{
2404 return (Adapter->uiVendorExtnFlag &&
2405 (Adapter->psFlash2xVendorInfo->VendorSection[section].AccessFlags & FLASH2X_SECTION_PRESENT) &&
2406 (Adapter->psFlash2xVendorInfo->VendorSection[section].OffsetFromZeroForSectionStart != UNINIT_PTR_IN_CS));
2407}
2408
2409static VOID UpdateVendorInfo(struct bcm_mini_adapter *Adapter)
2410{
2411 B_UINT32 i = 0;
2412 unsigned int uiSizeSection = 0;
2413
2414 Adapter->uiVendorExtnFlag = false;
2415
2416 for (i = 0; i < TOTAL_SECTIONS; i++)
2417 Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart = UNINIT_PTR_IN_CS;
2418
2419 if (STATUS_SUCCESS != vendorextnGetSectionInfo(Adapter, Adapter->psFlash2xVendorInfo))
2420 return;
2421
2422 i = 0;
2423 while (i < TOTAL_SECTIONS) {
2424 if (!(Adapter->psFlash2xVendorInfo->VendorSection[i].AccessFlags & FLASH2X_SECTION_PRESENT)) {
2425 i++;
2426 continue;
2427 }
2428
2429 Adapter->uiVendorExtnFlag = TRUE;
2430 uiSizeSection = (Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionEnd -
2431 Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart);
2432
2433 switch (i) {
2434 case DSD0:
2435 if ((uiSizeSection >= (Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(struct bcm_dsd_header))) &&
2436 (UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart))
2437 Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDEnd = VENDOR_PTR_IN_CS;
2438 else
2439 Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDEnd = UNINIT_PTR_IN_CS;
2440 break;
2441
2442 case DSD1:
2443 if ((uiSizeSection >= (Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(struct bcm_dsd_header))) &&
2444 (UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart))
2445 Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1End = VENDOR_PTR_IN_CS;
2446 else
2447 Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1End = UNINIT_PTR_IN_CS;
2448 break;
2449
2450 case DSD2:
2451 if ((uiSizeSection >= (Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(struct bcm_dsd_header))) &&
2452 (UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart))
2453 Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2End = VENDOR_PTR_IN_CS;
2454 else
2455 Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2End = UNINIT_PTR_IN_CS;
2456 break;
2457 case VSA0:
2458 if (UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart)
2459 Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAEnd = VENDOR_PTR_IN_CS;
2460 else
2461 Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAEnd = UNINIT_PTR_IN_CS;
2462 break;
2463
2464 case VSA1:
2465 if (UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart)
2466 Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1End = VENDOR_PTR_IN_CS;
2467 else
2468 Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1End = UNINIT_PTR_IN_CS;
2469 break;
2470 case VSA2:
2471 if (UNINIT_PTR_IN_CS != Adapter->psFlash2xVendorInfo->VendorSection[i].OffsetFromZeroForSectionStart)
2472 Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2End = VENDOR_PTR_IN_CS;
2473 else
2474 Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2Start = Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2End = UNINIT_PTR_IN_CS;
2475 break;
2476
2477 default:
2478 break;
2479 }
2480 i++;
2481 }
2482}
2483
2484/*
2485 * Procedure: BcmGetFlashCSInfo
2486 *
2487 * Description: Reads control structure and gets Cal section addresses.
2488 *
2489 * Arguments:
2490 * Adapter - ptr to Adapter object instance
2491 *
2492 * Returns:
2493 * <VOID>
2494 */
2495
2496static int BcmGetFlashCSInfo(struct bcm_mini_adapter *Adapter)
2497{
2498 /* struct bcm_flash_cs_info sFlashCsInfo = {0}; */
2499
2500 #if !defined(BCM_SHM_INTERFACE) || defined(FLASH_DIRECT_ACCESS)
2501 unsigned int value;
2502 #endif
2503
2504 unsigned int uiFlashLayoutMajorVersion;
2505
2506 Adapter->uiFlashLayoutMinorVersion = 0;
2507 Adapter->uiFlashLayoutMajorVersion = 0;
2508 Adapter->ulFlashControlSectionStart = FLASH_CS_INFO_START_ADDR;
2509
2510 Adapter->uiFlashBaseAdd = 0;
2511 Adapter->ulFlashCalStart = 0;
2512 memset(Adapter->psFlashCSInfo, 0 , sizeof(struct bcm_flash_cs_info));
2513 memset(Adapter->psFlash2xCSInfo, 0 , sizeof(struct bcm_flash2x_cs_info));
2514
2515 if (!Adapter->bDDRInitDone) {
2516 value = FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT;
2517 wrmalt(Adapter, 0xAF00A080, &value, sizeof(value));
2518 }
2519
2520 /* Reading first 8 Bytes to get the Flash Layout
2521 * MagicNumber(4 bytes) +FlashLayoutMinorVersion(2 Bytes) +FlashLayoutMajorVersion(2 Bytes)
2522 */
2523 BeceemFlashBulkRead(Adapter, (PUINT)Adapter->psFlashCSInfo, Adapter->ulFlashControlSectionStart, 8);
2524
2525 Adapter->psFlashCSInfo->FlashLayoutVersion = ntohl(Adapter->psFlashCSInfo->FlashLayoutVersion);
2526 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Flash Layout Version :%X", (Adapter->psFlashCSInfo->FlashLayoutVersion));
2527 /* BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Flash Layout Minor Version :%d\n", ntohs(sFlashCsInfo.FlashLayoutMinorVersion)); */
2528 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Signature is :%x\n", ntohl(Adapter->psFlashCSInfo->MagicNumber));
2529
2530 if (FLASH_CONTROL_STRUCT_SIGNATURE == ntohl(Adapter->psFlashCSInfo->MagicNumber)) {
2531 uiFlashLayoutMajorVersion = MAJOR_VERSION((Adapter->psFlashCSInfo->FlashLayoutVersion));
2532 Adapter->uiFlashLayoutMinorVersion = MINOR_VERSION((Adapter->psFlashCSInfo->FlashLayoutVersion));
2533 } else {
2534 Adapter->uiFlashLayoutMinorVersion = 0;
2535 uiFlashLayoutMajorVersion = 0;
2536 }
2537
2538 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "FLASH LAYOUT MAJOR VERSION :%X", uiFlashLayoutMajorVersion);
2539
2540 if (uiFlashLayoutMajorVersion < FLASH_2X_MAJOR_NUMBER) {
2541 BeceemFlashBulkRead(Adapter, (PUINT)Adapter->psFlashCSInfo, Adapter->ulFlashControlSectionStart, sizeof(struct bcm_flash_cs_info));
2542 ConvertEndianOfCSStructure(Adapter->psFlashCSInfo);
2543 Adapter->ulFlashCalStart = (Adapter->psFlashCSInfo->OffsetFromZeroForCalibrationStart);
2544
2545 if (!((Adapter->uiFlashLayoutMajorVersion == 1) && (Adapter->uiFlashLayoutMinorVersion == 1)))
2546 Adapter->ulFlashControlSectionStart = Adapter->psFlashCSInfo->OffsetFromZeroForControlSectionStart;
2547
2548 if ((FLASH_CONTROL_STRUCT_SIGNATURE == (Adapter->psFlashCSInfo->MagicNumber)) &&
2549 (SCSI_FIRMWARE_MINOR_VERSION <= MINOR_VERSION(Adapter->psFlashCSInfo->SCSIFirmwareVersion)) &&
2550 (FLASH_SECTOR_SIZE_SIG == (Adapter->psFlashCSInfo->FlashSectorSizeSig)) &&
2551 (BYTE_WRITE_SUPPORT == (Adapter->psFlashCSInfo->FlashWriteSupportSize))) {
2552 Adapter->ulFlashWriteSize = (Adapter->psFlashCSInfo->FlashWriteSupportSize);
2553 Adapter->fpFlashWrite = flashByteWrite;
2554 Adapter->fpFlashWriteWithStatusCheck = flashByteWriteStatus;
2555 } else {
2556 Adapter->ulFlashWriteSize = MAX_RW_SIZE;
2557 Adapter->fpFlashWrite = flashWrite;
2558 Adapter->fpFlashWriteWithStatusCheck = flashWriteStatus;
2559 }
2560
2561 BcmGetFlashSectorSize(Adapter, (Adapter->psFlashCSInfo->FlashSectorSizeSig),
2562 (Adapter->psFlashCSInfo->FlashSectorSize));
2563 Adapter->uiFlashBaseAdd = Adapter->psFlashCSInfo->FlashBaseAddr & 0xFCFFFFFF;
2564 } else {
2565 if (BcmFlash2xBulkRead(Adapter, (PUINT)Adapter->psFlash2xCSInfo, NO_SECTION_VAL,
2566 Adapter->ulFlashControlSectionStart, sizeof(struct bcm_flash2x_cs_info))) {
2567 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Unable to read CS structure\n");
2568 return STATUS_FAILURE;
2569 }
2570
2571 ConvertEndianOf2XCSStructure(Adapter->psFlash2xCSInfo);
2572 BcmDumpFlash2XCSStructure(Adapter->psFlash2xCSInfo, Adapter);
2573 if ((FLASH_CONTROL_STRUCT_SIGNATURE == Adapter->psFlash2xCSInfo->MagicNumber) &&
2574 (SCSI_FIRMWARE_MINOR_VERSION <= MINOR_VERSION(Adapter->psFlash2xCSInfo->SCSIFirmwareVersion)) &&
2575 (FLASH_SECTOR_SIZE_SIG == Adapter->psFlash2xCSInfo->FlashSectorSizeSig) &&
2576 (BYTE_WRITE_SUPPORT == Adapter->psFlash2xCSInfo->FlashWriteSupportSize)) {
2577 Adapter->ulFlashWriteSize = Adapter->psFlash2xCSInfo->FlashWriteSupportSize;
2578 Adapter->fpFlashWrite = flashByteWrite;
2579 Adapter->fpFlashWriteWithStatusCheck = flashByteWriteStatus;
2580 } else {
2581 Adapter->ulFlashWriteSize = MAX_RW_SIZE;
2582 Adapter->fpFlashWrite = flashWrite;
2583 Adapter->fpFlashWriteWithStatusCheck = flashWriteStatus;
2584 }
2585
2586 BcmGetFlashSectorSize(Adapter, Adapter->psFlash2xCSInfo->FlashSectorSizeSig,
2587 Adapter->psFlash2xCSInfo->FlashSectorSize);
2588
2589 UpdateVendorInfo(Adapter);
2590
2591 BcmGetActiveDSD(Adapter);
2592 BcmGetActiveISO(Adapter);
2593 Adapter->uiFlashBaseAdd = Adapter->psFlash2xCSInfo->FlashBaseAddr & 0xFCFFFFFF;
2594 Adapter->ulFlashControlSectionStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForControlSectionStart;
2595 }
2596 /*
2597 * Concerns: what if CS sector size does not match with this sector size ???
2598 * what is the indication of AccessBitMap in CS in flash 2.x ????
2599 */
2600 Adapter->ulFlashID = BcmReadFlashRDID(Adapter);
2601 Adapter->uiFlashLayoutMajorVersion = uiFlashLayoutMajorVersion;
2602
2603 return STATUS_SUCCESS;
2604}
2605
2606/*
2607 * Procedure: BcmGetNvmType
2608 *
2609 * Description: Finds the type of NVM used.
2610 *
2611 * Arguments:
2612 * Adapter - ptr to Adapter object instance
2613 *
2614 * Returns:
2615 * NVM_TYPE
2616 *
2617 */
2618
2619static enum bcm_nvm_type BcmGetNvmType(struct bcm_mini_adapter *Adapter)
2620{
2621 unsigned int uiData = 0;
2622
2623 BeceemEEPROMBulkRead(Adapter, &uiData, 0x0, 4);
2624 if (uiData == BECM)
2625 return NVM_EEPROM;
2626
2627 /*
2628 * Read control struct and get cal addresses before accessing the flash
2629 */
2630 BcmGetFlashCSInfo(Adapter);
2631
2632 BeceemFlashBulkRead(Adapter, &uiData, 0x0 + Adapter->ulFlashCalStart, 4);
2633 if (uiData == BECM)
2634 return NVM_FLASH;
2635
2636 /*
2637 * even if there is no valid signature on EEPROM/FLASH find out if they really exist.
2638 * if exist select it.
2639 */
2640 if (BcmGetEEPROMSize(Adapter))
2641 return NVM_EEPROM;
2642
2643 /* TBD for Flash. */
2644 return NVM_UNKNOWN;
2645}
2646
2647/*
2648 * BcmGetSectionValStartOffset - this will calculate the section's starting offset if section val is given
2649 * @Adapter : Drivers Private Data structure
2650 * @eFlashSectionVal : Flash secion value defined in enum bcm_flash2x_section_val
2651 *
2652 * Return value:-
2653 * On success it return the start offset of the provided section val
2654 * On Failure -returns STATUS_FAILURE
2655 */
2656
2657int BcmGetSectionValStartOffset(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val eFlashSectionVal)
2658{
2659 /*
2660 * Considering all the section for which end offset can be calculated or directly given
2661 * in CS Structure. if matching case does not exist, return STATUS_FAILURE indicating section
2662 * endoffset can't be calculated or given in CS Structure.
2663 */
2664
2665 int SectStartOffset = 0;
2666
2667 SectStartOffset = INVALID_OFFSET;
2668
2669 if (IsSectionExistInVendorInfo(Adapter, eFlashSectionVal))
2670 return Adapter->psFlash2xVendorInfo->VendorSection[eFlashSectionVal].OffsetFromZeroForSectionStart;
2671
2672 switch (eFlashSectionVal) {
2673 case ISO_IMAGE1:
2674 if ((Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start != UNINIT_PTR_IN_CS) &&
2675 (IsNonCDLessDevice(Adapter) == false))
2676 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start);
2677 break;
2678 case ISO_IMAGE2:
2679 if ((Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start != UNINIT_PTR_IN_CS) &&
2680 (IsNonCDLessDevice(Adapter) == false))
2681 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start);
2682 break;
2683 case DSD0:
2684 if (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDStart != UNINIT_PTR_IN_CS)
2685 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDStart);
2686 break;
2687 case DSD1:
2688 if (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1Start != UNINIT_PTR_IN_CS)
2689 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1Start);
2690 break;
2691 case DSD2:
2692 if (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2Start != UNINIT_PTR_IN_CS)
2693 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2Start);
2694 break;
2695 case VSA0:
2696 if (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAStart != UNINIT_PTR_IN_CS)
2697 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAStart);
2698 break;
2699 case VSA1:
2700 if (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1Start != UNINIT_PTR_IN_CS)
2701 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1Start);
2702 break;
2703 case VSA2:
2704 if (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2Start != UNINIT_PTR_IN_CS)
2705 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2Start);
2706 break;
2707 case SCSI:
2708 if (Adapter->psFlash2xCSInfo->OffsetFromZeroForScsiFirmware != UNINIT_PTR_IN_CS)
2709 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForScsiFirmware);
2710 break;
2711 case CONTROL_SECTION:
2712 if (Adapter->psFlash2xCSInfo->OffsetFromZeroForControlSectionStart != UNINIT_PTR_IN_CS)
2713 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForControlSectionStart);
2714 break;
2715 case ISO_IMAGE1_PART2:
2716 if (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2Start != UNINIT_PTR_IN_CS)
2717 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2Start);
2718 break;
2719 case ISO_IMAGE1_PART3:
2720 if (Adapter->psFlash2xCSInfo->OffsetISOImage1Part3Start != UNINIT_PTR_IN_CS)
2721 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part3Start);
2722 break;
2723 case ISO_IMAGE2_PART2:
2724 if (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2Start != UNINIT_PTR_IN_CS)
2725 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2Start);
2726 break;
2727 case ISO_IMAGE2_PART3:
2728 if (Adapter->psFlash2xCSInfo->OffsetISOImage2Part3Start != UNINIT_PTR_IN_CS)
2729 SectStartOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage2Part3Start);
2730 break;
2731 default:
2732 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Section Does not exist in Flash 2.x");
2733 SectStartOffset = INVALID_OFFSET;
2734 }
2735
2736 return SectStartOffset;
2737}
2738
2739/*
2740 * BcmGetSectionValEndOffset - this will calculate the section's Ending offset if section val is given
2741 * @Adapter : Drivers Private Data structure
2742 * @eFlashSectionVal : Flash secion value defined in enum bcm_flash2x_section_val
2743 *
2744 * Return value:-
2745 * On success it return the end offset of the provided section val
2746 * On Failure -returns STATUS_FAILURE
2747 */
2748
2749static int BcmGetSectionValEndOffset(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val eFlash2xSectionVal)
2750{
2751 int SectEndOffset = 0;
2752
2753 SectEndOffset = INVALID_OFFSET;
2754 if (IsSectionExistInVendorInfo(Adapter, eFlash2xSectionVal))
2755 return Adapter->psFlash2xVendorInfo->VendorSection[eFlash2xSectionVal].OffsetFromZeroForSectionEnd;
2756
2757 switch (eFlash2xSectionVal) {
2758 case ISO_IMAGE1:
2759 if ((Adapter->psFlash2xCSInfo->OffsetISOImage1Part1End != UNINIT_PTR_IN_CS) &&
2760 (IsNonCDLessDevice(Adapter) == false))
2761 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part1End);
2762 break;
2763 case ISO_IMAGE2:
2764 if ((Adapter->psFlash2xCSInfo->OffsetISOImage2Part1End != UNINIT_PTR_IN_CS) &&
2765 (IsNonCDLessDevice(Adapter) == false))
2766 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage2Part1End);
2767 break;
2768 case DSD0:
2769 if (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDEnd != UNINIT_PTR_IN_CS)
2770 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDEnd);
2771 break;
2772 case DSD1:
2773 if (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1End != UNINIT_PTR_IN_CS)
2774 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1End);
2775 break;
2776 case DSD2:
2777 if (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2End != UNINIT_PTR_IN_CS)
2778 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2End);
2779 break;
2780 case VSA0:
2781 if (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAEnd != UNINIT_PTR_IN_CS)
2782 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAEnd);
2783 break;
2784 case VSA1:
2785 if (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1End != UNINIT_PTR_IN_CS)
2786 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1End);
2787 break;
2788 case VSA2:
2789 if (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2End != UNINIT_PTR_IN_CS)
2790 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2End);
2791 break;
2792 case SCSI:
2793 if (Adapter->psFlash2xCSInfo->OffsetFromZeroForScsiFirmware != UNINIT_PTR_IN_CS)
2794 SectEndOffset = ((Adapter->psFlash2xCSInfo->OffsetFromZeroForScsiFirmware) +
2795 (Adapter->psFlash2xCSInfo->SizeOfScsiFirmware));
2796 break;
2797 case CONTROL_SECTION:
2798 /* Not Clear So Putting failure. confirm and fix it. */
2799 SectEndOffset = STATUS_FAILURE;
2800 break;
2801 case ISO_IMAGE1_PART2:
2802 if (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2End != UNINIT_PTR_IN_CS)
2803 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2End);
2804 break;
2805 case ISO_IMAGE1_PART3:
2806 if (Adapter->psFlash2xCSInfo->OffsetISOImage1Part3End != UNINIT_PTR_IN_CS)
2807 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part3End);
2808 break;
2809 case ISO_IMAGE2_PART2:
2810 if (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2End != UNINIT_PTR_IN_CS)
2811 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2End);
2812 break;
2813 case ISO_IMAGE2_PART3:
2814 if (Adapter->psFlash2xCSInfo->OffsetISOImage2Part3End != UNINIT_PTR_IN_CS)
2815 SectEndOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage2Part3End);
2816 break;
2817 default:
2818 SectEndOffset = INVALID_OFFSET;
2819 }
2820
2821 return SectEndOffset;
2822}
2823
2824/*
2825 * BcmFlash2xBulkRead:- Read API for Flash Map 2.x .
2826 * @Adapter :Driver Private Data Structure
2827 * @pBuffer : Buffer where data has to be put after reading
2828 * @eFlashSectionVal :Flash Section Val defined in enum bcm_flash2x_section_val
2829 * @uiOffsetWithinSectionVal :- Offset with in provided section
2830 * @uiNumBytes : Number of Bytes for Read
2831 *
2832 * Return value:-
2833 * return true on success and STATUS_FAILURE on fail.
2834 */
2835
2836int BcmFlash2xBulkRead(struct bcm_mini_adapter *Adapter,
2837 PUINT pBuffer,
2838 enum bcm_flash2x_section_val eFlash2xSectionVal,
2839 unsigned int uiOffsetWithinSectionVal,
2840 unsigned int uiNumBytes)
2841{
2842 int Status = STATUS_SUCCESS;
2843 int SectionStartOffset = 0;
2844 unsigned int uiAbsoluteOffset = 0;
2845 unsigned int uiTemp = 0, value = 0;
2846
2847 if (!Adapter) {
2848 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Adapter structure is NULL");
2849 return -EINVAL;
2850 }
2851 if (Adapter->device_removed) {
2852 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Device has been removed");
2853 return -ENODEV;
2854 }
2855
2856 /* NO_SECTION_VAL means absolute offset is given. */
2857 if (eFlash2xSectionVal == NO_SECTION_VAL)
2858 SectionStartOffset = 0;
2859 else
2860 SectionStartOffset = BcmGetSectionValStartOffset(Adapter, eFlash2xSectionVal);
2861
2862 if (SectionStartOffset == STATUS_FAILURE) {
2863 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "This Section<%d> does not exist in Flash 2.x Map ", eFlash2xSectionVal);
2864 return -EINVAL;
2865 }
2866
2867 if (IsSectionExistInVendorInfo(Adapter, eFlash2xSectionVal))
2868 return vendorextnReadSection(Adapter, (PUCHAR)pBuffer, eFlash2xSectionVal, uiOffsetWithinSectionVal, uiNumBytes);
2869
2870 /* calculating the absolute offset from FLASH; */
2871 uiAbsoluteOffset = uiOffsetWithinSectionVal + SectionStartOffset;
2872 rdmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
2873 value = 0;
2874 wrmalt(Adapter, 0x0f000C80, &value, sizeof(value));
2875 Status = BeceemFlashBulkRead(Adapter, pBuffer, uiAbsoluteOffset, uiNumBytes);
2876 wrmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
2877 if (Status) {
2878 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Read Failed with Status :%d", Status);
2879 return Status;
2880 }
2881
2882 return Status;
2883}
2884
2885/*
2886 * BcmFlash2xBulkWrite :-API for Writing on the Flash Map 2.x.
2887 * @Adapter :Driver Private Data Structure
2888 * @pBuffer : Buffer From where data has to taken for writing
2889 * @eFlashSectionVal :Flash Section Val defined in enum bcm_flash2x_section_val
2890 * @uiOffsetWithinSectionVal :- Offset with in provided section
2891 * @uiNumBytes : Number of Bytes for Write
2892 *
2893 * Return value:-
2894 * return true on success and STATUS_FAILURE on fail.
2895 *
2896 */
2897
2898int BcmFlash2xBulkWrite(struct bcm_mini_adapter *Adapter,
2899 PUINT pBuffer,
2900 enum bcm_flash2x_section_val eFlash2xSectVal,
2901 unsigned int uiOffset,
2902 unsigned int uiNumBytes,
2903 unsigned int bVerify)
2904{
2905 int Status = STATUS_SUCCESS;
2906 unsigned int FlashSectValStartOffset = 0;
2907 unsigned int uiTemp = 0, value = 0;
2908
2909 if (!Adapter) {
2910 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Adapter structure is NULL");
2911 return -EINVAL;
2912 }
2913
2914 if (Adapter->device_removed) {
2915 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Device has been removed");
2916 return -ENODEV;
2917 }
2918
2919 /* NO_SECTION_VAL means absolute offset is given. */
2920 if (eFlash2xSectVal == NO_SECTION_VAL)
2921 FlashSectValStartOffset = 0;
2922 else
2923 FlashSectValStartOffset = BcmGetSectionValStartOffset(Adapter, eFlash2xSectVal);
2924
2925 if (FlashSectValStartOffset == STATUS_FAILURE) {
2926 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "This Section<%d> does not exist in Flash Map 2.x", eFlash2xSectVal);
2927 return -EINVAL;
2928 }
2929
2930 if (IsSectionExistInVendorInfo(Adapter, eFlash2xSectVal))
2931 return vendorextnWriteSection(Adapter, (PUCHAR)pBuffer, eFlash2xSectVal, uiOffset, uiNumBytes, bVerify);
2932
2933 /* calculating the absolute offset from FLASH; */
2934 uiOffset = uiOffset + FlashSectValStartOffset;
2935
2936 rdmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
2937 value = 0;
2938 wrmalt(Adapter, 0x0f000C80, &value, sizeof(value));
2939
2940 Status = BeceemFlashBulkWrite(Adapter, pBuffer, uiOffset, uiNumBytes, bVerify);
2941
2942 wrmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
2943 if (Status) {
2944 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Flash Write failed with Status :%d", Status);
2945 return Status;
2946 }
2947
2948 return Status;
2949}
2950
2951/*
2952 * BcmGetActiveDSD : Set the Active DSD in Adapter Structure which has to be dumped in DDR
2953 * @Adapter :-Drivers private Data Structure
2954 *
2955 * Return Value:-
2956 * Return STATUS_SUCESS if get success in setting the right DSD else negative error code
2957 *
2958 */
2959
2960static int BcmGetActiveDSD(struct bcm_mini_adapter *Adapter)
2961{
2962 enum bcm_flash2x_section_val uiHighestPriDSD = 0;
2963
2964 uiHighestPriDSD = getHighestPriDSD(Adapter);
2965 Adapter->eActiveDSD = uiHighestPriDSD;
2966
2967 if (DSD0 == uiHighestPriDSD)
2968 Adapter->ulFlashCalStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDStart;
2969 if (DSD1 == uiHighestPriDSD)
2970 Adapter->ulFlashCalStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1Start;
2971 if (DSD2 == uiHighestPriDSD)
2972 Adapter->ulFlashCalStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2Start;
2973 if (Adapter->eActiveDSD)
2974 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Active DSD :%d", Adapter->eActiveDSD);
2975 if (Adapter->eActiveDSD == 0) {
2976 /* if No DSD gets Active, Make Active the DSD with WR permission */
2977 if (IsSectionWritable(Adapter, DSD2)) {
2978 Adapter->eActiveDSD = DSD2;
2979 Adapter->ulFlashCalStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2Start;
2980 } else if (IsSectionWritable(Adapter, DSD1)) {
2981 Adapter->eActiveDSD = DSD1;
2982 Adapter->ulFlashCalStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1Start;
2983 } else if (IsSectionWritable(Adapter, DSD0)) {
2984 Adapter->eActiveDSD = DSD0;
2985 Adapter->ulFlashCalStart = Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDStart;
2986 }
2987 }
2988
2989 return STATUS_SUCCESS;
2990}
2991
2992/*
2993 * BcmGetActiveISO :- Set the Active ISO in Adapter Data Structue
2994 * @Adapter : Driver private Data Structure
2995 *
2996 * Return Value:-
2997 * Sucsess:- STATUS_SUCESS
2998 * Failure- : negative erro code
2999 *
3000 */
3001
3002static int BcmGetActiveISO(struct bcm_mini_adapter *Adapter)
3003{
3004 int HighestPriISO = 0;
3005
3006 HighestPriISO = getHighestPriISO(Adapter);
3007
3008 Adapter->eActiveISO = HighestPriISO;
3009 if (Adapter->eActiveISO == ISO_IMAGE2)
3010 Adapter->uiActiveISOOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start);
3011 else if (Adapter->eActiveISO == ISO_IMAGE1)
3012 Adapter->uiActiveISOOffset = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start);
3013
3014 if (Adapter->eActiveISO)
3015 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Active ISO :%x", Adapter->eActiveISO);
3016
3017 return STATUS_SUCCESS;
3018}
3019
3020/*
3021 * IsOffsetWritable :- it will tell the access permission of the sector having passed offset
3022 * @Adapter : Drivers Private Data Structure
3023 * @uiOffset : Offset provided in the Flash
3024 *
3025 * Return Value:-
3026 * Success:-TRUE , offset is writable
3027 * Failure:-false, offset is RO
3028 *
3029 */
3030
3031static B_UINT8 IsOffsetWritable(struct bcm_mini_adapter *Adapter, unsigned int uiOffset)
3032{
3033 unsigned int uiSectorNum = 0;
3034 unsigned int uiWordOfSectorPermission = 0;
3035 unsigned int uiBitofSectorePermission = 0;
3036 B_UINT32 permissionBits = 0;
3037
3038 uiSectorNum = uiOffset/Adapter->uiSectorSize;
3039
3040 /* calculating the word having this Sector Access permission from SectorAccessBitMap Array */
3041 uiWordOfSectorPermission = Adapter->psFlash2xCSInfo->SectorAccessBitMap[uiSectorNum / 16];
3042
3043 /* calculating the bit index inside the word for this sector */
3044 uiBitofSectorePermission = 2 * (15 - uiSectorNum % 16);
3045
3046 /* Setting Access permission */
3047 permissionBits = uiWordOfSectorPermission & (0x3 << uiBitofSectorePermission);
3048 permissionBits = (permissionBits >> uiBitofSectorePermission) & 0x3;
3049 if (permissionBits == SECTOR_READWRITE_PERMISSION)
3050 return TRUE;
3051 else
3052 return false;
3053}
3054
3055static int BcmDumpFlash2xSectionBitMap(struct bcm_flash2x_bitmap *psFlash2xBitMap)
3056{
3057 struct bcm_mini_adapter *Adapter = GET_BCM_ADAPTER(gblpnetdev);
3058
3059 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "***************Flash 2.x Section Bitmap***************");
3060 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "ISO_IMAGE1 :0X%x", psFlash2xBitMap->ISO_IMAGE1);
3061 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "ISO_IMAGE2 :0X%x", psFlash2xBitMap->ISO_IMAGE2);
3062 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "DSD0 :0X%x", psFlash2xBitMap->DSD0);
3063 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "DSD1 :0X%x", psFlash2xBitMap->DSD1);
3064 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "DSD2 :0X%x", psFlash2xBitMap->DSD2);
3065 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "VSA0 :0X%x", psFlash2xBitMap->VSA0);
3066 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "VSA1 :0X%x", psFlash2xBitMap->VSA1);
3067 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "VSA2 :0X%x", psFlash2xBitMap->VSA2);
3068 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "SCSI :0X%x", psFlash2xBitMap->SCSI);
3069 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "CONTROL_SECTION :0X%x", psFlash2xBitMap->CONTROL_SECTION);
3070
3071 return STATUS_SUCCESS;
3072}
3073
3074/*
3075 * BcmGetFlash2xSectionalBitMap :- It will provide the bit map of all the section present in Flash
3076 * 8bit has been assigned to every section.
3077 * bit[0] :Section present or not
3078 * bit[1] :section is valid or not
3079 * bit[2] : Secton is read only or has write permission too.
3080 * bit[3] : Active Section -
3081 * bit[7...4] = Reserved .
3082 *
3083 * @Adapter:-Driver private Data Structure
3084 *
3085 * Return value:-
3086 * Success:- STATUS_SUCESS
3087 * Failure:- negative error code
3088 */
3089
3090int BcmGetFlash2xSectionalBitMap(struct bcm_mini_adapter *Adapter, struct bcm_flash2x_bitmap *psFlash2xBitMap)
3091{
3092 struct bcm_flash2x_cs_info *psFlash2xCSInfo = Adapter->psFlash2xCSInfo;
3093 enum bcm_flash2x_section_val uiHighestPriDSD = 0;
3094 enum bcm_flash2x_section_val uiHighestPriISO = 0;
3095 bool SetActiveDSDDone = false;
3096 bool SetActiveISODone = false;
3097
3098 /* For 1.x map all the section except DSD0 will be shown as not present
3099 * This part will be used by calibration tool to detect the number of DSD present in Flash.
3100 */
3101 if (IsFlash2x(Adapter) == false) {
3102 psFlash2xBitMap->ISO_IMAGE2 = 0;
3103 psFlash2xBitMap->ISO_IMAGE1 = 0;
3104 psFlash2xBitMap->DSD0 = FLASH2X_SECTION_VALID | FLASH2X_SECTION_ACT | FLASH2X_SECTION_PRESENT; /* 0xF; 0000(Reseved)1(Active)0(RW)1(valid)1(present) */
3105 psFlash2xBitMap->DSD1 = 0;
3106 psFlash2xBitMap->DSD2 = 0;
3107 psFlash2xBitMap->VSA0 = 0;
3108 psFlash2xBitMap->VSA1 = 0;
3109 psFlash2xBitMap->VSA2 = 0;
3110 psFlash2xBitMap->CONTROL_SECTION = 0;
3111 psFlash2xBitMap->SCSI = 0;
3112 psFlash2xBitMap->Reserved0 = 0;
3113 psFlash2xBitMap->Reserved1 = 0;
3114 psFlash2xBitMap->Reserved2 = 0;
3115
3116 return STATUS_SUCCESS;
3117 }
3118
3119 uiHighestPriDSD = getHighestPriDSD(Adapter);
3120 uiHighestPriISO = getHighestPriISO(Adapter);
3121
3122 /*
3123 * IS0 IMAGE 2
3124 */
3125 if ((psFlash2xCSInfo->OffsetISOImage2Part1Start) != UNINIT_PTR_IN_CS) {
3126 /* Setting the 0th Bit representing the Section is present or not. */
3127 psFlash2xBitMap->ISO_IMAGE2 = psFlash2xBitMap->ISO_IMAGE2 | FLASH2X_SECTION_PRESENT;
3128
3129 if (ReadISOSignature(Adapter, ISO_IMAGE2) == ISO_IMAGE_MAGIC_NUMBER)
3130 psFlash2xBitMap->ISO_IMAGE2 |= FLASH2X_SECTION_VALID;
3131
3132 /* Calculation for extrating the Access permission */
3133 if (IsSectionWritable(Adapter, ISO_IMAGE2) == false)
3134 psFlash2xBitMap->ISO_IMAGE2 |= FLASH2X_SECTION_RO;
3135
3136 if (SetActiveISODone == false && uiHighestPriISO == ISO_IMAGE2) {
3137 psFlash2xBitMap->ISO_IMAGE2 |= FLASH2X_SECTION_ACT;
3138 SetActiveISODone = TRUE;
3139 }
3140 }
3141
3142 /*
3143 * IS0 IMAGE 1
3144 */
3145 if ((psFlash2xCSInfo->OffsetISOImage1Part1Start) != UNINIT_PTR_IN_CS) {
3146 /* Setting the 0th Bit representing the Section is present or not. */
3147 psFlash2xBitMap->ISO_IMAGE1 = psFlash2xBitMap->ISO_IMAGE1 | FLASH2X_SECTION_PRESENT;
3148
3149 if (ReadISOSignature(Adapter, ISO_IMAGE1) == ISO_IMAGE_MAGIC_NUMBER)
3150 psFlash2xBitMap->ISO_IMAGE1 |= FLASH2X_SECTION_VALID;
3151
3152 /* Calculation for extrating the Access permission */
3153 if (IsSectionWritable(Adapter, ISO_IMAGE1) == false)
3154 psFlash2xBitMap->ISO_IMAGE1 |= FLASH2X_SECTION_RO;
3155
3156 if (SetActiveISODone == false && uiHighestPriISO == ISO_IMAGE1) {
3157 psFlash2xBitMap->ISO_IMAGE1 |= FLASH2X_SECTION_ACT;
3158 SetActiveISODone = TRUE;
3159 }
3160 }
3161
3162 /*
3163 * DSD2
3164 */
3165 if ((psFlash2xCSInfo->OffsetFromZeroForDSD2Start) != UNINIT_PTR_IN_CS) {
3166 /* Setting the 0th Bit representing the Section is present or not. */
3167 psFlash2xBitMap->DSD2 = psFlash2xBitMap->DSD2 | FLASH2X_SECTION_PRESENT;
3168
3169 if (ReadDSDSignature(Adapter, DSD2) == DSD_IMAGE_MAGIC_NUMBER)
3170 psFlash2xBitMap->DSD2 |= FLASH2X_SECTION_VALID;
3171
3172 /* Calculation for extrating the Access permission */
3173 if (IsSectionWritable(Adapter, DSD2) == false) {
3174 psFlash2xBitMap->DSD2 |= FLASH2X_SECTION_RO;
3175 } else {
3176 /* Means section is writable */
3177 if ((SetActiveDSDDone == false) && (uiHighestPriDSD == DSD2)) {
3178 psFlash2xBitMap->DSD2 |= FLASH2X_SECTION_ACT;
3179 SetActiveDSDDone = TRUE;
3180 }
3181 }
3182 }
3183
3184 /*
3185 * DSD 1
3186 */
3187 if ((psFlash2xCSInfo->OffsetFromZeroForDSD1Start) != UNINIT_PTR_IN_CS) {
3188 /* Setting the 0th Bit representing the Section is present or not. */
3189 psFlash2xBitMap->DSD1 = psFlash2xBitMap->DSD1 | FLASH2X_SECTION_PRESENT;
3190
3191 if (ReadDSDSignature(Adapter, DSD1) == DSD_IMAGE_MAGIC_NUMBER)
3192 psFlash2xBitMap->DSD1 |= FLASH2X_SECTION_VALID;
3193
3194 /* Calculation for extrating the Access permission */
3195 if (IsSectionWritable(Adapter, DSD1) == false) {
3196 psFlash2xBitMap->DSD1 |= FLASH2X_SECTION_RO;
3197 } else {
3198 /* Means section is writable */
3199 if ((SetActiveDSDDone == false) && (uiHighestPriDSD == DSD1)) {
3200 psFlash2xBitMap->DSD1 |= FLASH2X_SECTION_ACT;
3201 SetActiveDSDDone = TRUE;
3202 }
3203 }
3204 }
3205
3206 /*
3207 * For DSD 0
3208 */
3209 if ((psFlash2xCSInfo->OffsetFromZeroForDSDStart) != UNINIT_PTR_IN_CS) {
3210 /* Setting the 0th Bit representing the Section is present or not. */
3211 psFlash2xBitMap->DSD0 = psFlash2xBitMap->DSD0 | FLASH2X_SECTION_PRESENT;
3212
3213 if (ReadDSDSignature(Adapter, DSD0) == DSD_IMAGE_MAGIC_NUMBER)
3214 psFlash2xBitMap->DSD0 |= FLASH2X_SECTION_VALID;
3215
3216 /* Setting Access permission */
3217 if (IsSectionWritable(Adapter, DSD0) == false) {
3218 psFlash2xBitMap->DSD0 |= FLASH2X_SECTION_RO;
3219 } else {
3220 /* Means section is writable */
3221 if ((SetActiveDSDDone == false) && (uiHighestPriDSD == DSD0)) {
3222 psFlash2xBitMap->DSD0 |= FLASH2X_SECTION_ACT;
3223 SetActiveDSDDone = TRUE;
3224 }
3225 }
3226 }
3227
3228 /*
3229 * VSA 0
3230 */
3231 if ((psFlash2xCSInfo->OffsetFromZeroForVSAStart) != UNINIT_PTR_IN_CS) {
3232 /* Setting the 0th Bit representing the Section is present or not. */
3233 psFlash2xBitMap->VSA0 = psFlash2xBitMap->VSA0 | FLASH2X_SECTION_PRESENT;
3234
3235 /* Setting the Access Bit. Map is not defined hece setting it always valid */
3236 psFlash2xBitMap->VSA0 |= FLASH2X_SECTION_VALID;
3237
3238 /* Calculation for extrating the Access permission */
3239 if (IsSectionWritable(Adapter, VSA0) == false)
3240 psFlash2xBitMap->VSA0 |= FLASH2X_SECTION_RO;
3241
3242 /* By Default section is Active */
3243 psFlash2xBitMap->VSA0 |= FLASH2X_SECTION_ACT;
3244 }
3245
3246 /*
3247 * VSA 1
3248 */
3249 if ((psFlash2xCSInfo->OffsetFromZeroForVSA1Start) != UNINIT_PTR_IN_CS) {
3250 /* Setting the 0th Bit representing the Section is present or not. */
3251 psFlash2xBitMap->VSA1 = psFlash2xBitMap->VSA1 | FLASH2X_SECTION_PRESENT;
3252
3253 /* Setting the Access Bit. Map is not defined hece setting it always valid */
3254 psFlash2xBitMap->VSA1 |= FLASH2X_SECTION_VALID;
3255
3256 /* Checking For Access permission */
3257 if (IsSectionWritable(Adapter, VSA1) == false)
3258 psFlash2xBitMap->VSA1 |= FLASH2X_SECTION_RO;
3259
3260 /* By Default section is Active */
3261 psFlash2xBitMap->VSA1 |= FLASH2X_SECTION_ACT;
3262 }
3263
3264 /*
3265 * VSA 2
3266 */
3267 if ((psFlash2xCSInfo->OffsetFromZeroForVSA2Start) != UNINIT_PTR_IN_CS) {
3268 /* Setting the 0th Bit representing the Section is present or not. */
3269 psFlash2xBitMap->VSA2 = psFlash2xBitMap->VSA2 | FLASH2X_SECTION_PRESENT;
3270
3271 /* Setting the Access Bit. Map is not defined hece setting it always valid */
3272 psFlash2xBitMap->VSA2 |= FLASH2X_SECTION_VALID;
3273
3274 /* Checking For Access permission */
3275 if (IsSectionWritable(Adapter, VSA2) == false)
3276 psFlash2xBitMap->VSA2 |= FLASH2X_SECTION_RO;
3277
3278 /* By Default section is Active */
3279 psFlash2xBitMap->VSA2 |= FLASH2X_SECTION_ACT;
3280 }
3281
3282 /*
3283 * SCSI Section
3284 */
3285 if ((psFlash2xCSInfo->OffsetFromZeroForScsiFirmware) != UNINIT_PTR_IN_CS) {
3286 /* Setting the 0th Bit representing the Section is present or not. */
3287 psFlash2xBitMap->SCSI = psFlash2xBitMap->SCSI | FLASH2X_SECTION_PRESENT;
3288
3289 /* Setting the Access Bit. Map is not defined hece setting it always valid */
3290 psFlash2xBitMap->SCSI |= FLASH2X_SECTION_VALID;
3291
3292 /* Checking For Access permission */
3293 if (IsSectionWritable(Adapter, SCSI) == false)
3294 psFlash2xBitMap->SCSI |= FLASH2X_SECTION_RO;
3295
3296 /* By Default section is Active */
3297 psFlash2xBitMap->SCSI |= FLASH2X_SECTION_ACT;
3298 }
3299
3300 /*
3301 * Control Section
3302 */
3303 if ((psFlash2xCSInfo->OffsetFromZeroForControlSectionStart) != UNINIT_PTR_IN_CS) {
3304 /* Setting the 0th Bit representing the Section is present or not. */
3305 psFlash2xBitMap->CONTROL_SECTION = psFlash2xBitMap->CONTROL_SECTION | (FLASH2X_SECTION_PRESENT);
3306
3307 /* Setting the Access Bit. Map is not defined hece setting it always valid */
3308 psFlash2xBitMap->CONTROL_SECTION |= FLASH2X_SECTION_VALID;
3309
3310 /* Checking For Access permission */
3311 if (IsSectionWritable(Adapter, CONTROL_SECTION) == false)
3312 psFlash2xBitMap->CONTROL_SECTION |= FLASH2X_SECTION_RO;
3313
3314 /* By Default section is Active */
3315 psFlash2xBitMap->CONTROL_SECTION |= FLASH2X_SECTION_ACT;
3316 }
3317
3318 /*
3319 * For Reserved Sections
3320 */
3321 psFlash2xBitMap->Reserved0 = 0;
3322 psFlash2xBitMap->Reserved0 = 0;
3323 psFlash2xBitMap->Reserved0 = 0;
3324 BcmDumpFlash2xSectionBitMap(psFlash2xBitMap);
3325
3326 return STATUS_SUCCESS;
3327}
3328
3329/*
3330 * BcmSetActiveSection :- Set Active section is used to make priority field highest over other
3331 * section of same type.
3332 *
3333 * @Adapater :- Bcm Driver Private Data Structure
3334 * @eFlash2xSectionVal :- Flash section val whose priority has to be made highest.
3335 *
3336 * Return Value:- Make the priorit highest else return erorr code
3337 *
3338 */
3339
3340int BcmSetActiveSection(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val eFlash2xSectVal)
3341{
3342 unsigned int SectImagePriority = 0;
3343 int Status = STATUS_SUCCESS;
3344
3345 /* struct bcm_dsd_header sDSD = {0};
3346 * struct bcm_iso_header sISO = {0};
3347 */
3348 int HighestPriDSD = 0;
3349 int HighestPriISO = 0;
3350
3351 Status = IsSectionWritable(Adapter, eFlash2xSectVal);
3352 if (Status != TRUE) {
3353 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Provided Section <%d> is not writable", eFlash2xSectVal);
3354 return STATUS_FAILURE;
3355 }
3356
3357 Adapter->bHeaderChangeAllowed = TRUE;
3358 switch (eFlash2xSectVal) {
3359 case ISO_IMAGE1:
3360 case ISO_IMAGE2:
3361 if (ReadISOSignature(Adapter, eFlash2xSectVal) == ISO_IMAGE_MAGIC_NUMBER) {
3362 HighestPriISO = getHighestPriISO(Adapter);
3363
3364 if (HighestPriISO == eFlash2xSectVal) {
3365 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Given ISO<%x> already has highest priority", eFlash2xSectVal);
3366 Status = STATUS_SUCCESS;
3367 break;
3368 }
3369
3370 SectImagePriority = ReadISOPriority(Adapter, HighestPriISO) + 1;
3371
3372 if ((SectImagePriority == 0) && IsSectionWritable(Adapter, HighestPriISO)) {
3373 /* This is a SPECIAL Case which will only happen if the current highest priority ISO has priority value = 0x7FFFFFFF.
3374 * We will write 1 to the current Highest priority ISO And then shall increase the priority of the requested ISO
3375 * by user
3376 */
3377 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "SectImagePriority wraparound happened, eFlash2xSectVal: 0x%x\n", eFlash2xSectVal);
3378 SectImagePriority = htonl(0x1);
3379 Status = BcmFlash2xBulkWrite(Adapter,
3380 &SectImagePriority,
3381 HighestPriISO,
3382 0 + FIELD_OFFSET_IN_HEADER(struct bcm_iso_header *, ISOImagePriority),
3383 SIGNATURE_SIZE,
3384 TRUE);
3385 if (Status) {
3386 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Priority has not been written properly");
3387 Status = STATUS_FAILURE;
3388 break;
3389 }
3390
3391 HighestPriISO = getHighestPriISO(Adapter);
3392
3393 if (HighestPriISO == eFlash2xSectVal) {
3394 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Given ISO<%x> already has highest priority", eFlash2xSectVal);
3395 Status = STATUS_SUCCESS;
3396 break;
3397 }
3398
3399 SectImagePriority = 2;
3400 }
3401
3402 SectImagePriority = htonl(SectImagePriority);
3403
3404 Status = BcmFlash2xBulkWrite(Adapter,
3405 &SectImagePriority,
3406 eFlash2xSectVal,
3407 0 + FIELD_OFFSET_IN_HEADER(struct bcm_iso_header *, ISOImagePriority),
3408 SIGNATURE_SIZE,
3409 TRUE);
3410 if (Status) {
3411 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Priority has not been written properly");
3412 break;
3413 }
3414 } else {
3415 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Signature is currupted. Hence can't increase the priority");
3416 Status = STATUS_FAILURE;
3417 break;
3418 }
3419 break;
3420 case DSD0:
3421 case DSD1:
3422 case DSD2:
3423 if (ReadDSDSignature(Adapter, eFlash2xSectVal) == DSD_IMAGE_MAGIC_NUMBER) {
3424 HighestPriDSD = getHighestPriDSD(Adapter);
3425 if (HighestPriDSD == eFlash2xSectVal) {
3426 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Given DSD<%x> already has highest priority", eFlash2xSectVal);
3427 Status = STATUS_SUCCESS;
3428 break;
3429 }
3430
3431 SectImagePriority = ReadDSDPriority(Adapter, HighestPriDSD) + 1;
3432 if (SectImagePriority == 0) {
3433 /* This is a SPECIAL Case which will only happen if the current highest priority DSD has priority value = 0x7FFFFFFF.
3434 * We will write 1 to the current Highest priority DSD And then shall increase the priority of the requested DSD
3435 * by user
3436 */
3437 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, NVM_RW, DBG_LVL_ALL, "SectImagePriority wraparound happened, eFlash2xSectVal: 0x%x\n", eFlash2xSectVal);
3438 SectImagePriority = htonl(0x1);
3439
3440 Status = BcmFlash2xBulkWrite(Adapter,
3441 &SectImagePriority,
3442 HighestPriDSD,
3443 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(struct bcm_dsd_header *, DSDImagePriority),
3444 SIGNATURE_SIZE,
3445 TRUE);
3446 if (Status) {
3447 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Priority has not been written properly");
3448 break;
3449 }
3450
3451 HighestPriDSD = getHighestPriDSD(Adapter);
3452
3453 if (HighestPriDSD == eFlash2xSectVal) {
3454 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Made the DSD: %x highest by reducing priority of other\n", eFlash2xSectVal);
3455 Status = STATUS_SUCCESS;
3456 break;
3457 }
3458
3459 SectImagePriority = htonl(0x2);
3460 Status = BcmFlash2xBulkWrite(Adapter,
3461 &SectImagePriority,
3462 HighestPriDSD,
3463 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(struct bcm_dsd_header *, DSDImagePriority),
3464 SIGNATURE_SIZE,
3465 TRUE);
3466 if (Status) {
3467 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Priority has not been written properly");
3468 break;
3469 }
3470
3471 HighestPriDSD = getHighestPriDSD(Adapter);
3472 if (HighestPriDSD == eFlash2xSectVal) {
3473 Status = STATUS_SUCCESS;
3474 break;
3475 }
3476
3477 SectImagePriority = 3;
3478 }
3479 SectImagePriority = htonl(SectImagePriority);
3480 Status = BcmFlash2xBulkWrite(Adapter,
3481 &SectImagePriority,
3482 eFlash2xSectVal,
3483 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(struct bcm_dsd_header *, DSDImagePriority),
3484 SIGNATURE_SIZE,
3485 TRUE);
3486 if (Status) {
3487 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Priority has not been written properly");
3488 Status = STATUS_FAILURE;
3489 break;
3490 }
3491 } else {
3492 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Signature is currupted. Hence can't increase the priority");
3493 Status = STATUS_FAILURE;
3494 break;
3495 }
3496 break;
3497 case VSA0:
3498 case VSA1:
3499 case VSA2:
3500 /* Has to be decided */
3501 break;
3502 default:
3503 Status = STATUS_FAILURE;
3504 break;
3505 }
3506
3507 Adapter->bHeaderChangeAllowed = false;
3508 return Status;
3509}
3510
3511/*
3512 * BcmCopyISO - Used only for copying the ISO section
3513 * @Adapater :- Bcm Driver Private Data Structure
3514 * @sCopySectStrut :- Section copy structure
3515 *
3516 * Return value:- SUCCESS if copies successfully else negative error code
3517 *
3518 */
3519
3520int BcmCopyISO(struct bcm_mini_adapter *Adapter, struct bcm_flash2x_copy_section sCopySectStrut)
3521{
3522 PCHAR Buff = NULL;
3523 enum bcm_flash2x_section_val eISOReadPart = 0, eISOWritePart = 0;
3524 unsigned int uiReadOffsetWithinPart = 0, uiWriteOffsetWithinPart = 0;
3525 unsigned int uiTotalDataToCopy = 0;
3526 bool IsThisHeaderSector = false;
3527 unsigned int sigOffset = 0;
3528 unsigned int ISOLength = 0;
3529 unsigned int Status = STATUS_SUCCESS;
3530 unsigned int SigBuff[MAX_RW_SIZE];
3531 unsigned int i = 0;
3532
3533 if (ReadISOSignature(Adapter, sCopySectStrut.SrcSection) != ISO_IMAGE_MAGIC_NUMBER) {
3534 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "error as Source ISO Section does not have valid signature");
3535 return STATUS_FAILURE;
3536 }
3537
3538 Status = BcmFlash2xBulkRead(Adapter, &ISOLength,
3539 sCopySectStrut.SrcSection,
3540 0 + FIELD_OFFSET_IN_HEADER(struct bcm_iso_header *, ISOImageSize),
3541 4);
3542 if (Status) {
3543 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Read failed while copying ISO\n");
3544 return Status;
3545 }
3546
3547 ISOLength = htonl(ISOLength);
3548 if (ISOLength % Adapter->uiSectorSize)
3549 ISOLength = Adapter->uiSectorSize * (1 + ISOLength/Adapter->uiSectorSize);
3550
3551 sigOffset = FIELD_OFFSET_IN_HEADER(struct bcm_iso_header *, ISOImageMagicNumber);
3552
3553 Buff = kzalloc(Adapter->uiSectorSize, GFP_KERNEL);
3554
3555 if (!Buff) {
3556 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Memory allocation failed for section size");
3557 return -ENOMEM;
3558 }
3559
3560 if (sCopySectStrut.SrcSection == ISO_IMAGE1 && sCopySectStrut.DstSection == ISO_IMAGE2) {
3561 eISOReadPart = ISO_IMAGE1;
3562 eISOWritePart = ISO_IMAGE2;
3563 uiReadOffsetWithinPart = 0;
3564 uiWriteOffsetWithinPart = 0;
3565
3566 uiTotalDataToCopy = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part1End) -
3567 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start) +
3568 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2End) -
3569 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2Start) +
3570 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part3End) -
3571 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part3Start);
3572
3573 if (uiTotalDataToCopy < ISOLength) {
3574 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "error as Source ISO Section does not have valid signature");
3575 Status = STATUS_FAILURE;
3576 goto out;
3577 }
3578
3579 uiTotalDataToCopy = (Adapter->psFlash2xCSInfo->OffsetISOImage2Part1End) -
3580 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start) +
3581 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2End) -
3582 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2Start) +
3583 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part3End) -
3584 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part3Start);
3585
3586 if (uiTotalDataToCopy < ISOLength) {
3587 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "error as Dest ISO Section does not have enough section size");
3588 Status = STATUS_FAILURE;
3589 goto out;
3590 }
3591
3592 uiTotalDataToCopy = ISOLength;
3593
3594 CorruptISOSig(Adapter, ISO_IMAGE2);
3595 while (uiTotalDataToCopy) {
3596 if (uiTotalDataToCopy == Adapter->uiSectorSize) {
3597 /* Setting for write of first sector. First sector is assumed to be written in last */
3598 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Writing the signature sector");
3599 eISOReadPart = ISO_IMAGE1;
3600 uiReadOffsetWithinPart = 0;
3601 eISOWritePart = ISO_IMAGE2;
3602 uiWriteOffsetWithinPart = 0;
3603 IsThisHeaderSector = TRUE;
3604 } else {
3605 uiReadOffsetWithinPart = uiReadOffsetWithinPart + Adapter->uiSectorSize;
3606 uiWriteOffsetWithinPart = uiWriteOffsetWithinPart + Adapter->uiSectorSize;
3607
3608 if ((eISOReadPart == ISO_IMAGE1) && (uiReadOffsetWithinPart == (Adapter->psFlash2xCSInfo->OffsetISOImage1Part1End - Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start))) {
3609 eISOReadPart = ISO_IMAGE1_PART2;
3610 uiReadOffsetWithinPart = 0;
3611 }
3612
3613 if ((eISOReadPart == ISO_IMAGE1_PART2) && (uiReadOffsetWithinPart == (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2End - Adapter->psFlash2xCSInfo->OffsetISOImage1Part2Start))) {
3614 eISOReadPart = ISO_IMAGE1_PART3;
3615 uiReadOffsetWithinPart = 0;
3616 }
3617
3618 if ((eISOWritePart == ISO_IMAGE2) && (uiWriteOffsetWithinPart == (Adapter->psFlash2xCSInfo->OffsetISOImage2Part1End - Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start))) {
3619 eISOWritePart = ISO_IMAGE2_PART2;
3620 uiWriteOffsetWithinPart = 0;
3621 }
3622
3623 if ((eISOWritePart == ISO_IMAGE2_PART2) && (uiWriteOffsetWithinPart == (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2End - Adapter->psFlash2xCSInfo->OffsetISOImage2Part2Start))) {
3624 eISOWritePart = ISO_IMAGE2_PART3;
3625 uiWriteOffsetWithinPart = 0;
3626 }
3627 }
3628
3629 Status = BcmFlash2xBulkRead(Adapter,
3630 (PUINT)Buff,
3631 eISOReadPart,
3632 uiReadOffsetWithinPart,
3633 Adapter->uiSectorSize);
3634 if (Status) {
3635 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Read failed while copying ISO: Part: %x, OffsetWithinPart: %x\n", eISOReadPart, uiReadOffsetWithinPart);
3636 break;
3637 }
3638
3639 if (IsThisHeaderSector == TRUE) {
3640 /* If this is header sector write 0xFFFFFFFF at the sig time and in last write sig */
3641 memcpy(SigBuff, Buff + sigOffset, sizeof(SigBuff));
3642
3643 for (i = 0; i < MAX_RW_SIZE; i++)
3644 *(Buff + sigOffset + i) = 0xFF;
3645 }
3646 Adapter->bHeaderChangeAllowed = TRUE;
3647 Status = BcmFlash2xBulkWrite(Adapter,
3648 (PUINT)Buff,
3649 eISOWritePart,
3650 uiWriteOffsetWithinPart,
3651 Adapter->uiSectorSize,
3652 TRUE);
3653 if (Status) {
3654 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Write failed while copying ISO: Part: %x, OffsetWithinPart: %x\n", eISOWritePart, uiWriteOffsetWithinPart);
3655 break;
3656 }
3657
3658 Adapter->bHeaderChangeAllowed = false;
3659 if (IsThisHeaderSector == TRUE) {
3660 WriteToFlashWithoutSectorErase(Adapter,
3661 SigBuff,
3662 eISOWritePart,
3663 sigOffset,
3664 MAX_RW_SIZE);
3665 IsThisHeaderSector = false;
3666 }
3667 /* subtracting the written Data */
3668 uiTotalDataToCopy = uiTotalDataToCopy - Adapter->uiSectorSize;
3669 }
3670 }
3671
3672 if (sCopySectStrut.SrcSection == ISO_IMAGE2 && sCopySectStrut.DstSection == ISO_IMAGE1) {
3673 eISOReadPart = ISO_IMAGE2;
3674 eISOWritePart = ISO_IMAGE1;
3675 uiReadOffsetWithinPart = 0;
3676 uiWriteOffsetWithinPart = 0;
3677
3678 uiTotalDataToCopy = (Adapter->psFlash2xCSInfo->OffsetISOImage2Part1End) -
3679 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start) +
3680 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2End) -
3681 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2Start) +
3682 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part3End) -
3683 (Adapter->psFlash2xCSInfo->OffsetISOImage2Part3Start);
3684
3685 if (uiTotalDataToCopy < ISOLength) {
3686 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "error as Source ISO Section does not have valid signature");
3687 Status = STATUS_FAILURE;
3688 goto out;
3689 }
3690
3691 uiTotalDataToCopy = (Adapter->psFlash2xCSInfo->OffsetISOImage1Part1End) -
3692 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start) +
3693 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2End) -
3694 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2Start) +
3695 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part3End) -
3696 (Adapter->psFlash2xCSInfo->OffsetISOImage1Part3Start);
3697
3698 if (uiTotalDataToCopy < ISOLength) {
3699 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "error as Dest ISO Section does not have enough section size");
3700 Status = STATUS_FAILURE;
3701 goto out;
3702 }
3703
3704 uiTotalDataToCopy = ISOLength;
3705
3706 CorruptISOSig(Adapter, ISO_IMAGE1);
3707
3708 while (uiTotalDataToCopy) {
3709 if (uiTotalDataToCopy == Adapter->uiSectorSize) {
3710 /* Setting for write of first sector. First sector is assumed to be written in last */
3711 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Writing the signature sector");
3712 eISOReadPart = ISO_IMAGE2;
3713 uiReadOffsetWithinPart = 0;
3714 eISOWritePart = ISO_IMAGE1;
3715 uiWriteOffsetWithinPart = 0;
3716 IsThisHeaderSector = TRUE;
3717 } else {
3718 uiReadOffsetWithinPart = uiReadOffsetWithinPart + Adapter->uiSectorSize;
3719 uiWriteOffsetWithinPart = uiWriteOffsetWithinPart + Adapter->uiSectorSize;
3720
3721 if ((eISOReadPart == ISO_IMAGE2) && (uiReadOffsetWithinPart == (Adapter->psFlash2xCSInfo->OffsetISOImage2Part1End - Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start))) {
3722 eISOReadPart = ISO_IMAGE2_PART2;
3723 uiReadOffsetWithinPart = 0;
3724 }
3725
3726 if ((eISOReadPart == ISO_IMAGE2_PART2) && (uiReadOffsetWithinPart == (Adapter->psFlash2xCSInfo->OffsetISOImage2Part2End - Adapter->psFlash2xCSInfo->OffsetISOImage2Part2Start))) {
3727 eISOReadPart = ISO_IMAGE2_PART3;
3728 uiReadOffsetWithinPart = 0;
3729 }
3730
3731 if ((eISOWritePart == ISO_IMAGE1) && (uiWriteOffsetWithinPart == (Adapter->psFlash2xCSInfo->OffsetISOImage1Part1End - Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start))) {
3732 eISOWritePart = ISO_IMAGE1_PART2;
3733 uiWriteOffsetWithinPart = 0;
3734 }
3735
3736 if ((eISOWritePart == ISO_IMAGE1_PART2) && (uiWriteOffsetWithinPart == (Adapter->psFlash2xCSInfo->OffsetISOImage1Part2End - Adapter->psFlash2xCSInfo->OffsetISOImage1Part2Start))) {
3737 eISOWritePart = ISO_IMAGE1_PART3;
3738 uiWriteOffsetWithinPart = 0;
3739 }
3740 }
3741
3742 Status = BcmFlash2xBulkRead(Adapter,
3743 (PUINT)Buff,
3744 eISOReadPart,
3745 uiReadOffsetWithinPart,
3746 Adapter->uiSectorSize);
3747 if (Status) {
3748 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Read failed while copying ISO: Part: %x, OffsetWithinPart: %x\n", eISOReadPart, uiReadOffsetWithinPart);
3749 break;
3750 }
3751
3752 if (IsThisHeaderSector == TRUE) {
3753 /* If this is header sector write 0xFFFFFFFF at the sig time and in last write sig */
3754 memcpy(SigBuff, Buff + sigOffset, sizeof(SigBuff));
3755
3756 for (i = 0; i < MAX_RW_SIZE; i++)
3757 *(Buff + sigOffset + i) = 0xFF;
3758 }
3759 Adapter->bHeaderChangeAllowed = TRUE;
3760 Status = BcmFlash2xBulkWrite(Adapter,
3761 (PUINT)Buff,
3762 eISOWritePart,
3763 uiWriteOffsetWithinPart,
3764 Adapter->uiSectorSize,
3765 TRUE);
3766 if (Status) {
3767 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Write failed while copying ISO: Part: %x, OffsetWithinPart: %x\n", eISOWritePart, uiWriteOffsetWithinPart);
3768 break;
3769 }
3770
3771 Adapter->bHeaderChangeAllowed = false;
3772 if (IsThisHeaderSector == TRUE) {
3773 WriteToFlashWithoutSectorErase(Adapter,
3774 SigBuff,
3775 eISOWritePart,
3776 sigOffset,
3777 MAX_RW_SIZE);
3778
3779 IsThisHeaderSector = false;
3780 }
3781
3782 /* subtracting the written Data */
3783 uiTotalDataToCopy = uiTotalDataToCopy - Adapter->uiSectorSize;
3784 }
3785 }
3786out:
3787 kfree(Buff);
3788
3789 return Status;
3790}
3791
3792/*
3793 * BcmFlash2xCorruptSig : this API is used to corrupt the written sig in Bcm Header present in flash section.
3794 * It will corrupt the sig, if Section is writable, by making first bytes as zero.
3795 * @Adapater :- Bcm Driver Private Data Structure
3796 * @eFlash2xSectionVal :- Flash section val which has header
3797 *
3798 * Return Value :-
3799 * Success :- If Section is present and writable, corrupt the sig and return STATUS_SUCCESS
3800 * Failure :-Return negative error code
3801 */
3802
3803int BcmFlash2xCorruptSig(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val eFlash2xSectionVal)
3804{
3805 int Status = STATUS_SUCCESS;
3806
3807 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Section Value :%x\n", eFlash2xSectionVal);
3808
3809 if ((eFlash2xSectionVal == DSD0) || (eFlash2xSectionVal == DSD1) || (eFlash2xSectionVal == DSD2)) {
3810 Status = CorruptDSDSig(Adapter, eFlash2xSectionVal);
3811 } else if (eFlash2xSectionVal == ISO_IMAGE1 || eFlash2xSectionVal == ISO_IMAGE2) {
3812 Status = CorruptISOSig(Adapter, eFlash2xSectionVal);
3813 } else {
3814 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Given Section <%d>does not have Header", eFlash2xSectionVal);
3815 return STATUS_SUCCESS;
3816 }
3817 return Status;
3818}
3819
3820/*
3821 *BcmFlash2xWriteSig :-this API is used to Write the sig if requested Section has
3822 * header and Write Permission.
3823 * @Adapater :- Bcm Driver Private Data Structure
3824 * @eFlashSectionVal :- Flash section val which has header
3825 *
3826 * Return Value :-
3827 * Success :- If Section is present and writable write the sig and return STATUS_SUCCESS
3828 * Failure :-Return negative error code
3829 */
3830
3831int BcmFlash2xWriteSig(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val eFlashSectionVal)
3832{
3833 unsigned int uiSignature = 0;
3834 unsigned int uiOffset = 0;
3835
3836 /* struct bcm_dsd_header dsdHeader = {0}; */
3837 if (Adapter->bSigCorrupted == false) {
3838 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Signature is not corrupted by driver, hence not restoring\n");
3839 return STATUS_SUCCESS;
3840 }
3841
3842 if (Adapter->bAllDSDWriteAllow == false) {
3843 if (IsSectionWritable(Adapter, eFlashSectionVal) == false) {
3844 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Section is not Writable...Hence can't Write signature");
3845 return SECTOR_IS_NOT_WRITABLE;
3846 }
3847 }
3848
3849 if ((eFlashSectionVal == DSD0) || (eFlashSectionVal == DSD1) || (eFlashSectionVal == DSD2)) {
3850 uiSignature = htonl(DSD_IMAGE_MAGIC_NUMBER);
3851 uiOffset = Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader;
3852
3853 uiOffset += FIELD_OFFSET_IN_HEADER(struct bcm_dsd_header *, DSDImageMagicNumber);
3854
3855 if ((ReadDSDSignature(Adapter, eFlashSectionVal) & 0xFF000000) != CORRUPTED_PATTERN) {
3856 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Corrupted Pattern is not there. Hence won't write sig");
3857 return STATUS_FAILURE;
3858 }
3859 } else if ((eFlashSectionVal == ISO_IMAGE1) || (eFlashSectionVal == ISO_IMAGE2)) {
3860 uiSignature = htonl(ISO_IMAGE_MAGIC_NUMBER);
3861 /* uiOffset = 0; */
3862 uiOffset = FIELD_OFFSET_IN_HEADER(struct bcm_iso_header *, ISOImageMagicNumber);
3863 if ((ReadISOSignature(Adapter, eFlashSectionVal) & 0xFF000000) != CORRUPTED_PATTERN) {
3864 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Currupted Pattern is not there. Hence won't write sig");
3865 return STATUS_FAILURE;
3866 }
3867 } else {
3868 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "GIVEN SECTION< %d > IS NOT VALID FOR SIG WRITE...", eFlashSectionVal);
3869 return STATUS_FAILURE;
3870 }
3871
3872 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Restoring the signature");
3873
3874 Adapter->bHeaderChangeAllowed = TRUE;
3875 Adapter->bSigCorrupted = false;
3876 BcmFlash2xBulkWrite(Adapter, &uiSignature, eFlashSectionVal, uiOffset, SIGNATURE_SIZE, TRUE);
3877 Adapter->bHeaderChangeAllowed = false;
3878
3879 return STATUS_SUCCESS;
3880}
3881
3882/*
3883 * validateFlash2xReadWrite :- This API is used to validate the user request for Read/Write.
3884 * if requested Bytes goes beyond the Requested section, it reports error.
3885 * @Adapater :- Bcm Driver Private Data Structure
3886 * @psFlash2xReadWrite :-Flash2x Read/write structure pointer
3887 *
3888 * Return values:-Return TRUE is request is valid else false.
3889 */
3890
3891int validateFlash2xReadWrite(struct bcm_mini_adapter *Adapter, struct bcm_flash2x_readwrite *psFlash2xReadWrite)
3892{
3893 unsigned int uiNumOfBytes = 0;
3894 unsigned int uiSectStartOffset = 0;
3895 unsigned int uiSectEndOffset = 0;
3896
3897 uiNumOfBytes = psFlash2xReadWrite->numOfBytes;
3898
3899 if (IsSectionExistInFlash(Adapter, psFlash2xReadWrite->Section) != TRUE) {
3900 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Section<%x> does not exist in Flash", psFlash2xReadWrite->Section);
3901 return false;
3902 }
3903 uiSectStartOffset = BcmGetSectionValStartOffset(Adapter, psFlash2xReadWrite->Section);
3904 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Start offset :%x ,section :%d\n", uiSectStartOffset, psFlash2xReadWrite->Section);
3905 if ((psFlash2xReadWrite->Section == ISO_IMAGE1) || (psFlash2xReadWrite->Section == ISO_IMAGE2)) {
3906 if (psFlash2xReadWrite->Section == ISO_IMAGE1) {
3907 uiSectEndOffset = BcmGetSectionValEndOffset(Adapter, ISO_IMAGE1) -
3908 BcmGetSectionValStartOffset(Adapter, ISO_IMAGE1) +
3909 BcmGetSectionValEndOffset(Adapter, ISO_IMAGE1_PART2) -
3910 BcmGetSectionValStartOffset(Adapter, ISO_IMAGE1_PART2) +
3911 BcmGetSectionValEndOffset(Adapter, ISO_IMAGE1_PART3) -
3912 BcmGetSectionValStartOffset(Adapter, ISO_IMAGE1_PART3);
3913 } else if (psFlash2xReadWrite->Section == ISO_IMAGE2) {
3914 uiSectEndOffset = BcmGetSectionValEndOffset(Adapter, ISO_IMAGE2) -
3915 BcmGetSectionValStartOffset(Adapter, ISO_IMAGE2) +
3916 BcmGetSectionValEndOffset(Adapter, ISO_IMAGE2_PART2) -
3917 BcmGetSectionValStartOffset(Adapter, ISO_IMAGE2_PART2) +
3918 BcmGetSectionValEndOffset(Adapter, ISO_IMAGE2_PART3) -
3919 BcmGetSectionValStartOffset(Adapter, ISO_IMAGE2_PART3);
3920 }
3921
3922 /* since this uiSectEndoffset is the size of iso Image. hence for calculating the virtual endoffset
3923 * it should be added in startoffset. so that check done in last of this function can be valued.
3924 */
3925 uiSectEndOffset = uiSectStartOffset + uiSectEndOffset;
3926
3927 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Total size of the ISO Image :%x", uiSectEndOffset);
3928 } else
3929 uiSectEndOffset = BcmGetSectionValEndOffset(Adapter, psFlash2xReadWrite->Section);
3930
3931 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "End offset :%x\n", uiSectEndOffset);
3932
3933 /* psFlash2xReadWrite->offset and uiNumOfBytes are user controlled and can lead to integer overflows */
3934 if (psFlash2xReadWrite->offset > uiSectEndOffset) {
3935 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Invalid Request....");
3936 return false;
3937 }
3938 if (uiNumOfBytes > uiSectEndOffset) {
3939 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Invalid Request....");
3940 return false;
3941 }
3942 /* Checking the boundary condition */
3943 if ((uiSectStartOffset + psFlash2xReadWrite->offset + uiNumOfBytes) <= uiSectEndOffset)
3944 return TRUE;
3945 else {
3946 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Invalid Request....");
3947 return false;
3948 }
3949}
3950
3951/*
3952 * IsFlash2x :- check for Flash 2.x
3953 * Adapater :- Bcm Driver Private Data Structure
3954 *
3955 * Return value:-
3956 * return TRUE if flah2.x of hgher version else return false.
3957 */
3958
3959int IsFlash2x(struct bcm_mini_adapter *Adapter)
3960{
3961 if (Adapter->uiFlashLayoutMajorVersion >= FLASH_2X_MAJOR_NUMBER)
3962 return TRUE;
3963 else
3964 return false;
3965}
3966
3967/*
3968 * GetFlashBaseAddr :- Calculate the Flash Base address
3969 * @Adapater :- Bcm Driver Private Data Structure
3970 *
3971 * Return Value:-
3972 * Success :- Base Address of the Flash
3973 */
3974
3975static int GetFlashBaseAddr(struct bcm_mini_adapter *Adapter)
3976{
3977 unsigned int uiBaseAddr = 0;
3978
3979 if (Adapter->bDDRInitDone) {
3980 /*
3981 * For All Valid Flash Versions... except 1.1, take the value from FlashBaseAddr
3982 * In case of Raw Read... use the default value
3983 */
3984 if (Adapter->uiFlashLayoutMajorVersion && (Adapter->bFlashRawRead == false) &&
3985 !((Adapter->uiFlashLayoutMajorVersion == 1) && (Adapter->uiFlashLayoutMinorVersion == 1)))
3986 uiBaseAddr = Adapter->uiFlashBaseAdd;
3987 else
3988 uiBaseAddr = FLASH_CONTIGIOUS_START_ADDR_AFTER_INIT;
3989 } else {
3990 /*
3991 * For All Valid Flash Versions... except 1.1, take the value from FlashBaseAddr
3992 * In case of Raw Read... use the default value
3993 */
3994 if (Adapter->uiFlashLayoutMajorVersion && (Adapter->bFlashRawRead == false) &&
3995 !((Adapter->uiFlashLayoutMajorVersion == 1) && (Adapter->uiFlashLayoutMinorVersion == 1)))
3996 uiBaseAddr = Adapter->uiFlashBaseAdd | FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT;
3997 else
3998 uiBaseAddr = FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT;
3999 }
4000
4001 return uiBaseAddr;
4002}
4003
4004/*
4005 * BcmCopySection :- This API is used to copy the One section in another. Both section should
4006 * be contiuous and of same size. Hence this Will not be applicabe to copy ISO.
4007 *
4008 * @Adapater :- Bcm Driver Private Data Structure
4009 * @SrcSection :- Source section From where data has to be copied
4010 * @DstSection :- Destination section to which data has to be copied
4011 * @offset :- Offset from/to where data has to be copied from one section to another.
4012 * @numOfBytes :- number of byes that has to be copyed from one section to another at given offset.
4013 * in case of numofBytes equal zero complete section will be copied.
4014 * Return Values-
4015 * Success : Return STATUS_SUCCESS
4016 * Faillure :- return negative error code
4017 */
4018
4019int BcmCopySection(struct bcm_mini_adapter *Adapter,
4020 enum bcm_flash2x_section_val SrcSection,
4021 enum bcm_flash2x_section_val DstSection,
4022 unsigned int offset,
4023 unsigned int numOfBytes)
4024{
4025 unsigned int BuffSize = 0;
4026 unsigned int BytesToBeCopied = 0;
4027 PUCHAR pBuff = NULL;
4028 int Status = STATUS_SUCCESS;
4029
4030 if (SrcSection == DstSection) {
4031 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Source and Destination should be different ...try again");
4032 return -EINVAL;
4033 }
4034
4035 if ((SrcSection != DSD0) && (SrcSection != DSD1) && (SrcSection != DSD2)) {
4036 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Source should be DSD subsection");
4037 return -EINVAL;
4038 }
4039
4040 if ((DstSection != DSD0) && (DstSection != DSD1) && (DstSection != DSD2)) {
4041 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Destination should be DSD subsection");
4042 return -EINVAL;
4043 }
4044
4045 /* if offset zero means have to copy complete secton */
4046 if (numOfBytes == 0) {
4047 numOfBytes = BcmGetSectionValEndOffset(Adapter, SrcSection)
4048 - BcmGetSectionValStartOffset(Adapter, SrcSection);
4049
4050 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Section Size :0x%x", numOfBytes);
4051 }
4052
4053 if ((offset + numOfBytes) > BcmGetSectionValEndOffset(Adapter, SrcSection)
4054 - BcmGetSectionValStartOffset(Adapter, SrcSection)) {
4055 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, " Input parameters going beyond the section offS: %x numB: %x of Source Section\n",
4056 offset, numOfBytes);
4057 return -EINVAL;
4058 }
4059
4060 if ((offset + numOfBytes) > BcmGetSectionValEndOffset(Adapter, DstSection)
4061 - BcmGetSectionValStartOffset(Adapter, DstSection)) {
4062 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Input parameters going beyond the section offS: %x numB: %x of Destination Section\n",
4063 offset, numOfBytes);
4064 return -EINVAL;
4065 }
4066
4067 if (numOfBytes > Adapter->uiSectorSize)
4068 BuffSize = Adapter->uiSectorSize;
4069 else
4070 BuffSize = numOfBytes;
4071
4072 pBuff = kzalloc(BuffSize, GFP_KERNEL);
4073 if (!pBuff) {
4074 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Memory allocation failed.. ");
4075 return -ENOMEM;
4076 }
4077
4078 BytesToBeCopied = Adapter->uiSectorSize;
4079 if (offset % Adapter->uiSectorSize)
4080 BytesToBeCopied = Adapter->uiSectorSize - (offset % Adapter->uiSectorSize);
4081 if (BytesToBeCopied > numOfBytes)
4082 BytesToBeCopied = numOfBytes;
4083
4084 Adapter->bHeaderChangeAllowed = TRUE;
4085
4086 do {
4087 Status = BcmFlash2xBulkRead(Adapter, (PUINT)pBuff, SrcSection , offset, BytesToBeCopied);
4088 if (Status) {
4089 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Read failed at offset :%d for NOB :%d", SrcSection, BytesToBeCopied);
4090 break;
4091 }
4092 Status = BcmFlash2xBulkWrite(Adapter, (PUINT)pBuff, DstSection, offset, BytesToBeCopied, false);
4093 if (Status) {
4094 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Write failed at offset :%d for NOB :%d", DstSection, BytesToBeCopied);
4095 break;
4096 }
4097 offset = offset + BytesToBeCopied;
4098 numOfBytes = numOfBytes - BytesToBeCopied;
4099 if (numOfBytes) {
4100 if (numOfBytes > Adapter->uiSectorSize)
4101 BytesToBeCopied = Adapter->uiSectorSize;
4102 else
4103 BytesToBeCopied = numOfBytes;
4104 }
4105 } while (numOfBytes > 0);
4106
4107 kfree(pBuff);
4108 Adapter->bHeaderChangeAllowed = false;
4109
4110 return Status;
4111}
4112
4113/*
4114 * SaveHeaderIfPresent :- This API is use to Protect the Header in case of Header Sector write
4115 * @Adapater :- Bcm Driver Private Data Structure
4116 * @pBuff :- Data buffer that has to be written in sector having the header map.
4117 * @uiOffset :- Flash offset that has to be written.
4118 *
4119 * Return value :-
4120 * Success :- On success return STATUS_SUCCESS
4121 * Faillure :- Return negative error code
4122 */
4123
4124static int SaveHeaderIfPresent(struct bcm_mini_adapter *Adapter, PUCHAR pBuff, unsigned int uiOffset)
4125{
4126 unsigned int offsetToProtect = 0, HeaderSizeToProtect = 0;
4127 bool bHasHeader = false;
4128 PUCHAR pTempBuff = NULL;
4129 unsigned int uiSectAlignAddr = 0;
4130 unsigned int sig = 0;
4131
4132 /* making the offset sector aligned */
4133 uiSectAlignAddr = uiOffset & ~(Adapter->uiSectorSize - 1);
4134
4135 if ((uiSectAlignAddr == BcmGetSectionValEndOffset(Adapter, DSD2) - Adapter->uiSectorSize) ||
4136 (uiSectAlignAddr == BcmGetSectionValEndOffset(Adapter, DSD1) - Adapter->uiSectorSize) ||
4137 (uiSectAlignAddr == BcmGetSectionValEndOffset(Adapter, DSD0) - Adapter->uiSectorSize)) {
4138 /* offset from the sector boundary having the header map */
4139 offsetToProtect = Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader % Adapter->uiSectorSize;
4140 HeaderSizeToProtect = sizeof(struct bcm_dsd_header);
4141 bHasHeader = TRUE;
4142 }
4143
4144 if (uiSectAlignAddr == BcmGetSectionValStartOffset(Adapter, ISO_IMAGE1) ||
4145 uiSectAlignAddr == BcmGetSectionValStartOffset(Adapter, ISO_IMAGE2)) {
4146 offsetToProtect = 0;
4147 HeaderSizeToProtect = sizeof(struct bcm_iso_header);
4148 bHasHeader = TRUE;
4149 }
4150 /* If Header is present overwrite passed buffer with this */
4151 if (bHasHeader && (Adapter->bHeaderChangeAllowed == false)) {
4152 pTempBuff = kzalloc(HeaderSizeToProtect, GFP_KERNEL);
4153 if (!pTempBuff) {
4154 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Memory allocation failed");
4155 return -ENOMEM;
4156 }
4157 /* Read header */
4158 BeceemFlashBulkRead(Adapter, (PUINT)pTempBuff, (uiSectAlignAddr + offsetToProtect), HeaderSizeToProtect);
4159 BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, pTempBuff, HeaderSizeToProtect);
4160 /* Replace Buffer content with Header */
4161 memcpy(pBuff + offsetToProtect, pTempBuff, HeaderSizeToProtect);
4162
4163 kfree(pTempBuff);
4164 }
4165 if (bHasHeader && Adapter->bSigCorrupted) {
4166 sig = *((PUINT)(pBuff + offsetToProtect + FIELD_OFFSET_IN_HEADER(struct bcm_dsd_header *, DSDImageMagicNumber)));
4167 sig = ntohl(sig);
4168 if ((sig & 0xFF000000) != CORRUPTED_PATTERN) {
4169 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Desired pattern is not at sig offset. Hence won't restore");
4170 Adapter->bSigCorrupted = false;
4171 return STATUS_SUCCESS;
4172 }
4173 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, " Corrupted sig is :%X", sig);
4174 *((PUINT)(pBuff + offsetToProtect + FIELD_OFFSET_IN_HEADER(struct bcm_dsd_header *, DSDImageMagicNumber))) = htonl(DSD_IMAGE_MAGIC_NUMBER);
4175 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Restoring the signature in Header Write only");
4176 Adapter->bSigCorrupted = false;
4177 }
4178
4179 return STATUS_SUCCESS;
4180}
4181
4182/*
4183 * BcmDoChipSelect : This will selcet the appropriate chip for writing.
4184 * @Adapater :- Bcm Driver Private Data Structure
4185 *
4186 * OutPut:-
4187 * Select the Appropriate chip and retrn status Success
4188 */
4189static int BcmDoChipSelect(struct bcm_mini_adapter *Adapter, unsigned int offset)
4190{
4191 unsigned int FlashConfig = 0;
4192 int ChipNum = 0;
4193 unsigned int GPIOConfig = 0;
4194 unsigned int PartNum = 0;
4195
4196 ChipNum = offset / FLASH_PART_SIZE;
4197
4198 /*
4199 * Chip Select mapping to enable flash0.
4200 * To select flash 0, we have to OR with (0<<12).
4201 * ORing 0 will have no impact so not doing that part.
4202 * In future if Chip select value changes from 0 to non zero,
4203 * That needs be taken care with backward comaptibility. No worries for now.
4204 */
4205
4206 /*
4207 * SelectedChip Variable is the selection that the host is 100% Sure the same as what the register will hold. This can be ONLY ensured
4208 * if the Chip doesn't goes to low power mode while the flash operation is in progress (NVMRdmWrmLock is taken)
4209 * Before every new Flash Write operation, we reset the variable. This is to ensure that after any wake-up from
4210 * power down modes (Idle mode/shutdown mode), the values in the register will be different.
4211 */
4212
4213 if (Adapter->SelectedChip == ChipNum)
4214 return STATUS_SUCCESS;
4215
4216 /* BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Selected Chip :%x", ChipNum); */
4217 Adapter->SelectedChip = ChipNum;
4218
4219 /* bit[13..12] will select the appropriate chip */
4220 rdmalt(Adapter, FLASH_CONFIG_REG, &FlashConfig, 4);
4221 rdmalt(Adapter, FLASH_GPIO_CONFIG_REG, &GPIOConfig, 4);
4222 {
4223 switch (ChipNum) {
4224 case 0:
4225 PartNum = 0;
4226 break;
4227 case 1:
4228 PartNum = 3;
4229 GPIOConfig |= (0x4 << CHIP_SELECT_BIT12);
4230 break;
4231 case 2:
4232 PartNum = 1;
4233 GPIOConfig |= (0x1 << CHIP_SELECT_BIT12);
4234 break;
4235 case 3:
4236 PartNum = 2;
4237 GPIOConfig |= (0x2 << CHIP_SELECT_BIT12);
4238 break;
4239 }
4240 }
4241 /* In case the bits already written in the FLASH_CONFIG_REG is same as what the user desired,
4242 * nothing to do... can return immediately.
4243 * ASSUMPTION: FLASH_GPIO_CONFIG_REG will be in sync with FLASH_CONFIG_REG.
4244 * Even if the chip goes to low power mode, it should wake with values in each register in sync with each other.
4245 * These values are not written by host other than during CHIP_SELECT.
4246 */
4247 if (PartNum == ((FlashConfig >> CHIP_SELECT_BIT12) & 0x3))
4248 return STATUS_SUCCESS;
4249
4250 /* clearing the bit[13..12] */
4251 FlashConfig &= 0xFFFFCFFF;
4252 FlashConfig = (FlashConfig | (PartNum<<CHIP_SELECT_BIT12)); /* 00 */
4253
4254 wrmalt(Adapter, FLASH_GPIO_CONFIG_REG, &GPIOConfig, 4);
4255 udelay(100);
4256
4257 wrmalt(Adapter, FLASH_CONFIG_REG, &FlashConfig, 4);
4258 udelay(100);
4259
4260 return STATUS_SUCCESS;
4261}
4262
4263static int ReadDSDSignature(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val dsd)
4264{
4265 unsigned int uiDSDsig = 0;
4266 /* unsigned int sigoffsetInMap = 0;
4267 * struct bcm_dsd_header dsdHeader = {0};
4268 */
4269
4270 /* sigoffsetInMap =(PUCHAR)&(dsdHeader.DSDImageMagicNumber) -(PUCHAR)&dsdHeader; */
4271
4272 if (dsd != DSD0 && dsd != DSD1 && dsd != DSD2) {
4273 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "passed section value is not for DSDs");
4274 return STATUS_FAILURE;
4275 }
4276 BcmFlash2xBulkRead(Adapter,
4277 &uiDSDsig,
4278 dsd,
4279 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(struct bcm_dsd_header *, DSDImageMagicNumber),
4280 SIGNATURE_SIZE);
4281
4282 uiDSDsig = ntohl(uiDSDsig);
4283 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "DSD SIG :%x", uiDSDsig);
4284
4285 return uiDSDsig;
4286}
4287
4288static int ReadDSDPriority(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val dsd)
4289{
4290 /* unsigned int priOffsetInMap = 0 ; */
4291 unsigned int uiDSDPri = STATUS_FAILURE;
4292 /* struct bcm_dsd_header dsdHeader = {0};
4293 * priOffsetInMap = (PUCHAR)&(dsdHeader.DSDImagePriority) -(PUCHAR)&dsdHeader;
4294 */
4295 if (IsSectionWritable(Adapter, dsd)) {
4296 if (ReadDSDSignature(Adapter, dsd) == DSD_IMAGE_MAGIC_NUMBER) {
4297 BcmFlash2xBulkRead(Adapter,
4298 &uiDSDPri,
4299 dsd,
4300 Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + FIELD_OFFSET_IN_HEADER(struct bcm_dsd_header *, DSDImagePriority),
4301 4);
4302
4303 uiDSDPri = ntohl(uiDSDPri);
4304 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "DSD<%x> Priority :%x", dsd, uiDSDPri);
4305 }
4306 }
4307
4308 return uiDSDPri;
4309}
4310
4311static enum bcm_flash2x_section_val getHighestPriDSD(struct bcm_mini_adapter *Adapter)
4312{
4313 int DSDHighestPri = STATUS_FAILURE;
4314 int DsdPri = 0;
4315 enum bcm_flash2x_section_val HighestPriDSD = 0;
4316
4317 if (IsSectionWritable(Adapter, DSD2)) {
4318 DSDHighestPri = ReadDSDPriority(Adapter, DSD2);
4319 HighestPriDSD = DSD2;
4320 }
4321
4322 if (IsSectionWritable(Adapter, DSD1)) {
4323 DsdPri = ReadDSDPriority(Adapter, DSD1);
4324 if (DSDHighestPri < DsdPri) {
4325 DSDHighestPri = DsdPri;
4326 HighestPriDSD = DSD1;
4327 }
4328 }
4329
4330 if (IsSectionWritable(Adapter, DSD0)) {
4331 DsdPri = ReadDSDPriority(Adapter, DSD0);
4332 if (DSDHighestPri < DsdPri) {
4333 DSDHighestPri = DsdPri;
4334 HighestPriDSD = DSD0;
4335 }
4336 }
4337 if (HighestPriDSD)
4338 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Highest DSD :%x , and its Pri :%x", HighestPriDSD, DSDHighestPri);
4339
4340 return HighestPriDSD;
4341}
4342
4343static int ReadISOSignature(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val iso)
4344{
4345 unsigned int uiISOsig = 0;
4346 /* unsigned int sigoffsetInMap = 0;
4347 * struct bcm_iso_header ISOHeader = {0};
4348 * sigoffsetInMap =(PUCHAR)&(ISOHeader.ISOImageMagicNumber) -(PUCHAR)&ISOHeader;
4349 */
4350 if (iso != ISO_IMAGE1 && iso != ISO_IMAGE2) {
4351 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "passed section value is not for ISOs");
4352 return STATUS_FAILURE;
4353 }
4354 BcmFlash2xBulkRead(Adapter,
4355 &uiISOsig,
4356 iso,
4357 0 + FIELD_OFFSET_IN_HEADER(struct bcm_iso_header *, ISOImageMagicNumber),
4358 SIGNATURE_SIZE);
4359
4360 uiISOsig = ntohl(uiISOsig);
4361 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "ISO SIG :%x", uiISOsig);
4362
4363 return uiISOsig;
4364}
4365
4366static int ReadISOPriority(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val iso)
4367{
4368 unsigned int ISOPri = STATUS_FAILURE;
4369
4370 if (IsSectionWritable(Adapter, iso)) {
4371 if (ReadISOSignature(Adapter, iso) == ISO_IMAGE_MAGIC_NUMBER) {
4372 BcmFlash2xBulkRead(Adapter,
4373 &ISOPri,
4374 iso,
4375 0 + FIELD_OFFSET_IN_HEADER(struct bcm_iso_header *, ISOImagePriority),
4376 4);
4377
4378 ISOPri = ntohl(ISOPri);
4379 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "ISO<%x> Priority :%x", iso, ISOPri);
4380 }
4381 }
4382
4383 return ISOPri;
4384}
4385
4386static enum bcm_flash2x_section_val getHighestPriISO(struct bcm_mini_adapter *Adapter)
4387{
4388 int ISOHighestPri = STATUS_FAILURE;
4389 int ISOPri = 0;
4390 enum bcm_flash2x_section_val HighestPriISO = NO_SECTION_VAL;
4391
4392 if (IsSectionWritable(Adapter, ISO_IMAGE2)) {
4393 ISOHighestPri = ReadISOPriority(Adapter, ISO_IMAGE2);
4394 HighestPriISO = ISO_IMAGE2;
4395 }
4396
4397 if (IsSectionWritable(Adapter, ISO_IMAGE1)) {
4398 ISOPri = ReadISOPriority(Adapter, ISO_IMAGE1);
4399 if (ISOHighestPri < ISOPri) {
4400 ISOHighestPri = ISOPri;
4401 HighestPriISO = ISO_IMAGE1;
4402 }
4403 }
4404 if (HighestPriISO)
4405 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Highest ISO :%x and its Pri :%x", HighestPriISO, ISOHighestPri);
4406
4407 return HighestPriISO;
4408}
4409
4410static int WriteToFlashWithoutSectorErase(struct bcm_mini_adapter *Adapter,
4411 PUINT pBuff,
4412 enum bcm_flash2x_section_val eFlash2xSectionVal,
4413 unsigned int uiOffset,
4414 unsigned int uiNumBytes)
4415{
4416 #if !defined(BCM_SHM_INTERFACE) || defined(FLASH_DIRECT_ACCESS)
4417 unsigned int uiTemp = 0, value = 0;
4418 unsigned int i = 0;
4419 unsigned int uiPartOffset = 0;
4420 #endif
4421 unsigned int uiStartOffset = 0;
4422 /* Adding section start address */
4423 int Status = STATUS_SUCCESS;
4424 PUCHAR pcBuff = (PUCHAR)pBuff;
4425
4426 if (uiNumBytes % Adapter->ulFlashWriteSize) {
4427 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Writing without Sector Erase for non-FlashWriteSize number of bytes 0x%x\n", uiNumBytes);
4428 return STATUS_FAILURE;
4429 }
4430
4431 uiStartOffset = BcmGetSectionValStartOffset(Adapter, eFlash2xSectionVal);
4432
4433 if (IsSectionExistInVendorInfo(Adapter, eFlash2xSectionVal))
4434 return vendorextnWriteSectionWithoutErase(Adapter, pcBuff, eFlash2xSectionVal, uiOffset, uiNumBytes);
4435
4436 uiOffset = uiOffset + uiStartOffset;
4437
4438 #if defined(BCM_SHM_INTERFACE) && !defined(FLASH_DIRECT_ACCESS)
4439 Status = bcmflash_raw_writenoerase((uiOffset / FLASH_PART_SIZE), (uiOffset % FLASH_PART_SIZE), pcBuff, uiNumBytes);
4440 #else
4441 rdmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
4442 value = 0;
4443 wrmalt(Adapter, 0x0f000C80, &value, sizeof(value));
4444
4445 Adapter->SelectedChip = RESET_CHIP_SELECT;
4446 BcmDoChipSelect(Adapter, uiOffset);
4447 uiPartOffset = (uiOffset & (FLASH_PART_SIZE - 1)) + GetFlashBaseAddr(Adapter);
4448
4449 for (i = 0; i < uiNumBytes; i += Adapter->ulFlashWriteSize) {
4450 if (Adapter->ulFlashWriteSize == BYTE_WRITE_SUPPORT)
4451 Status = flashByteWrite(Adapter, uiPartOffset, pcBuff);
4452 else
4453 Status = flashWrite(Adapter, uiPartOffset, pcBuff);
4454
4455 if (Status != STATUS_SUCCESS)
4456 break;
4457
4458 pcBuff = pcBuff + Adapter->ulFlashWriteSize;
4459 uiPartOffset = uiPartOffset + Adapter->ulFlashWriteSize;
4460 }
4461 wrmalt(Adapter, 0x0f000C80, &uiTemp, sizeof(uiTemp));
4462 Adapter->SelectedChip = RESET_CHIP_SELECT;
4463 #endif
4464
4465 return Status;
4466}
4467
4468bool IsSectionExistInFlash(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val section)
4469{
4470 bool SectionPresent = false;
4471
4472 switch (section) {
4473 case ISO_IMAGE1:
4474 if ((Adapter->psFlash2xCSInfo->OffsetISOImage1Part1Start != UNINIT_PTR_IN_CS) &&
4475 (IsNonCDLessDevice(Adapter) == false))
4476 SectionPresent = TRUE;
4477 break;
4478 case ISO_IMAGE2:
4479 if ((Adapter->psFlash2xCSInfo->OffsetISOImage2Part1Start != UNINIT_PTR_IN_CS) &&
4480 (IsNonCDLessDevice(Adapter) == false))
4481 SectionPresent = TRUE;
4482 break;
4483 case DSD0:
4484 if (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSDStart != UNINIT_PTR_IN_CS)
4485 SectionPresent = TRUE;
4486 break;
4487 case DSD1:
4488 if (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD1Start != UNINIT_PTR_IN_CS)
4489 SectionPresent = TRUE;
4490 break;
4491 case DSD2:
4492 if (Adapter->psFlash2xCSInfo->OffsetFromZeroForDSD2Start != UNINIT_PTR_IN_CS)
4493 SectionPresent = TRUE;
4494 break;
4495 case VSA0:
4496 if (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSAStart != UNINIT_PTR_IN_CS)
4497 SectionPresent = TRUE;
4498 break;
4499 case VSA1:
4500 if (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA1Start != UNINIT_PTR_IN_CS)
4501 SectionPresent = TRUE;
4502 break;
4503 case VSA2:
4504 if (Adapter->psFlash2xCSInfo->OffsetFromZeroForVSA2Start != UNINIT_PTR_IN_CS)
4505 SectionPresent = TRUE;
4506 break;
4507 case SCSI:
4508 if (Adapter->psFlash2xCSInfo->OffsetFromZeroForScsiFirmware != UNINIT_PTR_IN_CS)
4509 SectionPresent = TRUE;
4510 break;
4511 case CONTROL_SECTION:
4512 if (Adapter->psFlash2xCSInfo->OffsetFromZeroForControlSectionStart != UNINIT_PTR_IN_CS)
4513 SectionPresent = TRUE;
4514 break;
4515 default:
4516 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Section Does not exist in Flash 2.x");
4517 SectionPresent = false;
4518 }
4519
4520 return SectionPresent;
4521}
4522
4523static int IsSectionWritable(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val Section)
4524{
4525 int offset = STATUS_FAILURE;
4526 int Status = false;
4527
4528 if (IsSectionExistInFlash(Adapter, Section) == false) {
4529 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Section <%d> does not exist", Section);
4530 return false;
4531 }
4532
4533 offset = BcmGetSectionValStartOffset(Adapter, Section);
4534 if (offset == INVALID_OFFSET) {
4535 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Section<%d> does not exist", Section);
4536 return false;
4537 }
4538
4539 if (IsSectionExistInVendorInfo(Adapter, Section))
4540 return !(Adapter->psFlash2xVendorInfo->VendorSection[Section].AccessFlags & FLASH2X_SECTION_RO);
4541
4542 Status = IsOffsetWritable(Adapter, offset);
4543 return Status;
4544}
4545
4546static int CorruptDSDSig(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val eFlash2xSectionVal)
4547{
4548 PUCHAR pBuff = NULL;
4549 unsigned int sig = 0;
4550 unsigned int uiOffset = 0;
4551 unsigned int BlockStatus = 0;
4552 unsigned int uiSectAlignAddr = 0;
4553
4554 Adapter->bSigCorrupted = false;
4555 if (Adapter->bAllDSDWriteAllow == false) {
4556 if (IsSectionWritable(Adapter, eFlash2xSectionVal) != TRUE) {
4557 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Section is not Writable...Hence can't Corrupt signature");
4558 return SECTOR_IS_NOT_WRITABLE;
4559 }
4560 }
4561
4562 pBuff = kzalloc(MAX_RW_SIZE, GFP_KERNEL);
4563 if (!pBuff) {
4564 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Can't allocate memorey");
4565 return -ENOMEM;
4566 }
4567
4568 uiOffset = Adapter->psFlash2xCSInfo->OffsetFromDSDStartForDSDHeader + sizeof(struct bcm_dsd_header);
4569 uiOffset -= MAX_RW_SIZE;
4570
4571 BcmFlash2xBulkRead(Adapter, (PUINT)pBuff, eFlash2xSectionVal, uiOffset, MAX_RW_SIZE);
4572
4573 sig = *((PUINT)(pBuff + 12));
4574 sig = ntohl(sig);
4575 BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, pBuff, MAX_RW_SIZE);
4576 /* Now corrupting the sig by corrupting 4th last Byte. */
4577 *(pBuff + 12) = 0;
4578
4579 if (sig == DSD_IMAGE_MAGIC_NUMBER) {
4580 Adapter->bSigCorrupted = TRUE;
4581 if (Adapter->ulFlashWriteSize == BYTE_WRITE_SUPPORT) {
4582 uiSectAlignAddr = uiOffset & ~(Adapter->uiSectorSize - 1);
4583 BlockStatus = BcmFlashUnProtectBlock(Adapter, uiSectAlignAddr, Adapter->uiSectorSize);
4584
4585 WriteToFlashWithoutSectorErase(Adapter, (PUINT)(pBuff + 12), eFlash2xSectionVal,
4586 (uiOffset + 12), BYTE_WRITE_SUPPORT);
4587 if (BlockStatus) {
4588 BcmRestoreBlockProtectStatus(Adapter, BlockStatus);
4589 BlockStatus = 0;
4590 }
4591 } else {
4592 WriteToFlashWithoutSectorErase(Adapter, (PUINT)pBuff, eFlash2xSectionVal,
4593 uiOffset, MAX_RW_SIZE);
4594 }
4595 } else {
4596 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "BCM Signature is not present in header");
4597 kfree(pBuff);
4598
4599 return STATUS_FAILURE;
4600 }
4601
4602 kfree(pBuff);
4603 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Corrupted the signature");
4604
4605 return STATUS_SUCCESS;
4606}
4607
4608static int CorruptISOSig(struct bcm_mini_adapter *Adapter, enum bcm_flash2x_section_val eFlash2xSectionVal)
4609{
4610 PUCHAR pBuff = NULL;
4611 unsigned int sig = 0;
4612 unsigned int uiOffset = 0;
4613
4614 Adapter->bSigCorrupted = false;
4615
4616 if (IsSectionWritable(Adapter, eFlash2xSectionVal) != TRUE) {
4617 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Section is not Writable...Hence can't Corrupt signature");
4618 return SECTOR_IS_NOT_WRITABLE;
4619 }
4620
4621 pBuff = kzalloc(MAX_RW_SIZE, GFP_KERNEL);
4622 if (!pBuff) {
4623 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "Can't allocate memorey");
4624 return -ENOMEM;
4625 }
4626
4627 uiOffset = 0;
4628
4629 BcmFlash2xBulkRead(Adapter, (PUINT)pBuff, eFlash2xSectionVal, uiOffset, MAX_RW_SIZE);
4630
4631 sig = *((PUINT)pBuff);
4632 sig = ntohl(sig);
4633
4634 /* corrupt signature */
4635 *pBuff = 0;
4636
4637 if (sig == ISO_IMAGE_MAGIC_NUMBER) {
4638 Adapter->bSigCorrupted = TRUE;
4639 WriteToFlashWithoutSectorErase(Adapter, (PUINT)pBuff, eFlash2xSectionVal,
4640 uiOffset, Adapter->ulFlashWriteSize);
4641 } else {
4642 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_PRINTK, 0, 0, "BCM Signature is not present in header");
4643 kfree(pBuff);
4644
4645 return STATUS_FAILURE;
4646 }
4647
4648 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, "Corrupted the signature");
4649 BCM_DEBUG_PRINT_BUFFER(Adapter, DBG_TYPE_OTHERS, NVM_RW, DBG_LVL_ALL, pBuff, MAX_RW_SIZE);
4650
4651 kfree(pBuff);
4652 return STATUS_SUCCESS;
4653}
4654
4655bool IsNonCDLessDevice(struct bcm_mini_adapter *Adapter)
4656{
4657 if (Adapter->psFlash2xCSInfo->IsCDLessDeviceBootSig == NON_CDLESS_DEVICE_BOOT_SIG)
4658 return TRUE;
4659 else
4660 return false;
4661}
diff --git a/drivers/staging/bcm/nvm.h b/drivers/staging/bcm/nvm.h
deleted file mode 100644
index e765cca5d966..000000000000
--- a/drivers/staging/bcm/nvm.h
+++ /dev/null
@@ -1,286 +0,0 @@
1/***************************************************************************************
2 *
3 * Copyright (c) Beceem Communications Inc.
4 *
5 * Module Name:
6 * NVM.h
7 *
8 * Abstract:
9 * This file has the prototypes,preprocessors and definitions various NVM libraries.
10 *
11 *
12 * Revision History:
13 * Who When What
14 * -------- -------- ----------------------------------------------
15 * Name Date Created/reviewed/modified
16 *
17 * Notes:
18 *
19 ****************************************************************************************/
20
21#ifndef _NVM_H_
22#define _NVM_H_
23
24struct bcm_flash_cs_info {
25 u32 MagicNumber;
26 /* let the magic number be 0xBECE-F1A5 - F1A5 for "flas-h" */
27 u32 FlashLayoutVersion;
28 u32 ISOImageVersion;
29 u32 SCSIFirmwareVersion;
30 u32 OffsetFromZeroForPart1ISOImage;
31 u32 OffsetFromZeroForScsiFirmware;
32 u32 SizeOfScsiFirmware;
33 u32 OffsetFromZeroForPart2ISOImage;
34 u32 OffsetFromZeroForCalibrationStart;
35 u32 OffsetFromZeroForCalibrationEnd;
36 u32 OffsetFromZeroForVSAStart;
37 u32 OffsetFromZeroForVSAEnd;
38 u32 OffsetFromZeroForControlSectionStart;
39 u32 OffsetFromZeroForControlSectionData;
40 u32 CDLessInactivityTimeout;
41 u32 NewImageSignature;
42 u32 FlashSectorSizeSig;
43 u32 FlashSectorSize;
44 u32 FlashWriteSupportSize;
45 u32 TotalFlashSize;
46 u32 FlashBaseAddr;
47 u32 FlashPartMaxSize;
48 u32 IsCDLessDeviceBootSig;
49 /* MSC Timeout after reset to switch from MSC to NW Mode */
50 u32 MassStorageTimeout;
51};
52
53#define FLASH2X_TOTAL_SIZE (64 * 1024 * 1024)
54#define DEFAULT_SECTOR_SIZE (64 * 1024)
55
56struct bcm_flash2x_cs_info {
57 /* magic number as 0xBECE-F1A5 - F1A5 for "flas-h" */
58 u32 MagicNumber;
59 u32 FlashLayoutVersion;
60 u32 ISOImageVersion;
61 u32 SCSIFirmwareVersion;
62 u32 OffsetFromZeroForPart1ISOImage;
63 u32 OffsetFromZeroForScsiFirmware;
64 u32 SizeOfScsiFirmware;
65 u32 OffsetFromZeroForPart2ISOImage;
66 u32 OffsetFromZeroForDSDStart;
67 u32 OffsetFromZeroForDSDEnd;
68 u32 OffsetFromZeroForVSAStart;
69 u32 OffsetFromZeroForVSAEnd;
70 u32 OffsetFromZeroForControlSectionStart;
71 u32 OffsetFromZeroForControlSectionData;
72 /* NO Data Activity timeout to switch from MSC to NW Mode */
73 u32 CDLessInactivityTimeout;
74 u32 NewImageSignature;
75 u32 FlashSectorSizeSig;
76 u32 FlashSectorSize;
77 u32 FlashWriteSupportSize;
78 u32 TotalFlashSize;
79 u32 FlashBaseAddr;
80 u32 FlashPartMaxSize;
81 u32 IsCDLessDeviceBootSig;
82 /* MSC Timeout after reset to switch from MSC to NW Mode */
83 u32 MassStorageTimeout;
84 /* Flash Map 2.0 Field */
85 u32 OffsetISOImage1Part1Start;
86 u32 OffsetISOImage1Part1End;
87 u32 OffsetISOImage1Part2Start;
88 u32 OffsetISOImage1Part2End;
89 u32 OffsetISOImage1Part3Start;
90 u32 OffsetISOImage1Part3End;
91 u32 OffsetISOImage2Part1Start;
92 u32 OffsetISOImage2Part1End;
93 u32 OffsetISOImage2Part2Start;
94 u32 OffsetISOImage2Part2End;
95 u32 OffsetISOImage2Part3Start;
96 u32 OffsetISOImage2Part3End;
97 /* DSD Header offset from start of DSD */
98 u32 OffsetFromDSDStartForDSDHeader;
99 u32 OffsetFromZeroForDSD1Start;
100 u32 OffsetFromZeroForDSD1End;
101 u32 OffsetFromZeroForDSD2Start;
102 u32 OffsetFromZeroForDSD2End;
103 u32 OffsetFromZeroForVSA1Start;
104 u32 OffsetFromZeroForVSA1End;
105 u32 OffsetFromZeroForVSA2Start;
106 u32 OffsetFromZeroForVSA2End;
107 /*
108 * ACCESS_BITS_PER_SECTOR 2
109 * ACCESS_RW 0
110 * ACCESS_RO 1
111 * ACCESS_RESVD 2
112 * ACCESS_RESVD 3
113 */
114 u32 SectorAccessBitMap[FLASH2X_TOTAL_SIZE / (DEFAULT_SECTOR_SIZE * 16)];
115 /* All expansions to the control data structure should add here */
116};
117
118struct bcm_vendor_section_info {
119 u32 OffsetFromZeroForSectionStart;
120 u32 OffsetFromZeroForSectionEnd;
121 u32 AccessFlags;
122 u32 Reserved[16];
123};
124
125struct bcm_flash2x_vendor_info {
126 struct bcm_vendor_section_info VendorSection[TOTAL_SECTIONS];
127 u32 Reserved[16];
128};
129
130struct bcm_dsd_header {
131 u32 DSDImageSize;
132 u32 DSDImageCRC;
133 u32 DSDImagePriority;
134 /* We should not consider right now. Reading reserve is worthless. */
135 u32 Reserved[252]; /* Resvd for DSD Header */
136 u32 DSDImageMagicNumber;
137};
138
139struct bcm_iso_header {
140 u32 ISOImageMagicNumber;
141 u32 ISOImageSize;
142 u32 ISOImageCRC;
143 u32 ISOImagePriority;
144 /* We should not consider right now. Reading reserve is worthless. */
145 u32 Reserved[60]; /* Resvd for ISO Header extension */
146};
147
148#define EEPROM_BEGIN_CIS (0)
149#define EEPROM_BEGIN_NON_CIS (0x200)
150#define EEPROM_END (0x2000)
151#define INIT_PARAMS_SIGNATURE (0x95a7a597)
152#define MAX_INIT_PARAMS_LENGTH (2048)
153#define MAC_ADDRESS_OFFSET 0x200
154
155#define INIT_PARAMS_1_SIGNATURE_ADDRESS EEPROM_BEGIN_NON_CIS
156#define INIT_PARAMS_1_DATA_ADDRESS (INIT_PARAMS_1_SIGNATURE_ADDRESS+16)
157#define INIT_PARAMS_1_MACADDRESS_ADDRESS (MAC_ADDRESS_OFFSET)
158#define INIT_PARAMS_1_LENGTH_ADDRESS (INIT_PARAMS_1_SIGNATURE_ADDRESS+4)
159
160#define INIT_PARAMS_2_SIGNATURE_ADDRESS (EEPROM_BEGIN_NON_CIS + 2048 + 16)
161#define INIT_PARAMS_2_DATA_ADDRESS (INIT_PARAMS_2_SIGNATURE_ADDRESS + 16)
162#define INIT_PARAMS_2_MACADDRESS_ADDRESS (INIT_PARAMS_2_SIGNATURE_ADDRESS + 8)
163#define INIT_PARAMS_2_LENGTH_ADDRESS (INIT_PARAMS_2_SIGNATURE_ADDRESS + 4)
164
165#define EEPROM_SPI_DEV_CONFIG_REG 0x0F003000
166#define EEPROM_SPI_Q_STATUS1_REG 0x0F003004
167#define EEPROM_SPI_Q_STATUS1_MASK_REG 0x0F00300C
168
169#define EEPROM_SPI_Q_STATUS_REG 0x0F003008
170#define EEPROM_CMDQ_SPI_REG 0x0F003018
171#define EEPROM_WRITE_DATAQ_REG 0x0F00301C
172#define EEPROM_READ_DATAQ_REG 0x0F003020
173#define SPI_FLUSH_REG 0x0F00304C
174
175#define EEPROM_WRITE_ENABLE 0x06000000
176#define EEPROM_READ_STATUS_REGISTER 0x05000000
177#define EEPROM_16_BYTE_PAGE_WRITE 0xFA000000
178#define EEPROM_WRITE_QUEUE_EMPTY 0x00001000
179#define EEPROM_WRITE_QUEUE_AVAIL 0x00002000
180#define EEPROM_WRITE_QUEUE_FULL 0x00004000
181#define EEPROM_16_BYTE_PAGE_READ 0xFB000000
182#define EEPROM_4_BYTE_PAGE_READ 0x3B000000
183
184#define EEPROM_CMD_QUEUE_FLUSH 0x00000001
185#define EEPROM_WRITE_QUEUE_FLUSH 0x00000002
186#define EEPROM_READ_QUEUE_FLUSH 0x00000004
187#define EEPROM_ETH_QUEUE_FLUSH 0x00000008
188#define EEPROM_ALL_QUEUE_FLUSH 0x0000000f
189#define EEPROM_READ_ENABLE 0x06000000
190#define EEPROM_16_BYTE_PAGE_WRITE 0xFA000000
191#define EEPROM_READ_DATA_FULL 0x00000010
192#define EEPROM_READ_DATA_AVAIL 0x00000020
193#define EEPROM_READ_QUEUE_EMPTY 0x00000002
194#define EEPROM_CMD_QUEUE_EMPTY 0x00000100
195#define EEPROM_CMD_QUEUE_AVAIL 0x00000200
196#define EEPROM_CMD_QUEUE_FULL 0x00000400
197
198/* Most EEPROM status register bit 0 indicates if the EEPROM is busy
199 * with a write if set 1. See the details of the EEPROM Status Register
200 * in the EEPROM data sheet.
201 */
202#define EEPROM_STATUS_REG_WRITE_BUSY 0x00000001
203
204/* We will have 1 mSec for every RETRIES_PER_DELAY count and have a max attempts of MAX_EEPROM_RETRIES
205 * This will give us 80 mSec minimum of delay = 80mSecs
206 */
207#define MAX_EEPROM_RETRIES 80
208#define RETRIES_PER_DELAY 64
209#define MAX_RW_SIZE 0x10
210#define MAX_READ_SIZE 0x10
211#define MAX_SECTOR_SIZE (512 * 1024)
212#define MIN_SECTOR_SIZE (1024)
213#define FLASH_SECTOR_SIZE_OFFSET 0xEFFFC
214#define FLASH_SECTOR_SIZE_SIG_OFFSET 0xEFFF8
215#define FLASH_SECTOR_SIZE_SIG 0xCAFEBABE
216#define FLASH_CS_INFO_START_ADDR 0xFF0000
217#define FLASH_CONTROL_STRUCT_SIGNATURE 0xBECEF1A5
218#define SCSI_FIRMWARE_MAJOR_VERSION 0x1
219#define SCSI_FIRMWARE_MINOR_VERSION 0x5
220#define BYTE_WRITE_SUPPORT 0x1
221#define FLASH_AUTO_INIT_BASE_ADDR 0xF00000
222#define FLASH_CONTIGIOUS_START_ADDR_AFTER_INIT 0x1C000000
223#define FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT 0x1F000000
224#define FLASH_CONTIGIOUS_START_ADDR_BCS350 0x08000000
225#define FLASH_CONTIGIOUS_END_ADDR_BCS350 0x08FFFFFF
226#define FLASH_SIZE_ADDR 0xFFFFEC
227#define FLASH_SPI_CMDQ_REG 0xAF003040
228#define FLASH_SPI_WRITEQ_REG 0xAF003044
229#define FLASH_SPI_READQ_REG 0xAF003048
230#define FLASH_CONFIG_REG 0xAF003050
231#define FLASH_GPIO_CONFIG_REG 0xAF000030
232#define FLASH_CMD_WRITE_ENABLE 0x06
233#define FLASH_CMD_READ_ENABLE 0x03
234#define FLASH_CMD_RESET_WRITE_ENABLE 0x04
235#define FLASH_CMD_STATUS_REG_READ 0x05
236#define FLASH_CMD_STATUS_REG_WRITE 0x01
237#define FLASH_CMD_READ_ID 0x9F
238#define PAD_SELECT_REGISTER 0xAF000410
239#define FLASH_PART_SST25VF080B 0xBF258E
240#define EEPROM_CAL_DATA_INTERNAL_LOC 0xbFB00008
241#define EEPROM_CALPARAM_START 0x200
242#define EEPROM_SIZE_OFFSET 524
243
244/* As Read/Write time vaires from 1.5 to 3.0 ms.
245 * so After Ignoring the rdm/wrm time(that is dependent on many factor like interface etc.),
246 * here time calculated meets the worst case delay, 3.0 ms
247 */
248#define MAX_FLASH_RETRIES 4
249#define FLASH_PER_RETRIES_DELAY 16
250#define EEPROM_MAX_CAL_AREA_SIZE 0xF0000
251#define BECM ntohl(0x4245434d)
252#define FLASH_2X_MAJOR_NUMBER 0x2
253#define DSD_IMAGE_MAGIC_NUMBER 0xBECE0D5D
254#define ISO_IMAGE_MAGIC_NUMBER 0xBECE0150
255#define NON_CDLESS_DEVICE_BOOT_SIG 0xBECEB007
256
257#define MINOR_VERSION(x) ((x >> 16) & 0xFFFF)
258#define MAJOR_VERSION(x) (x & 0xFFFF)
259
260#define CORRUPTED_PATTERN 0x0
261#define UNINIT_PTR_IN_CS 0xBBBBDDDD
262#define VENDOR_PTR_IN_CS 0xAAAACCCC
263#define FLASH2X_SECTION_PRESENT (1 << 0)
264#define FLASH2X_SECTION_VALID (1 << 1)
265#define FLASH2X_SECTION_RO (1 << 2)
266#define FLASH2X_SECTION_ACT (1 << 3)
267#define SECTOR_IS_NOT_WRITABLE STATUS_FAILURE
268#define INVALID_OFFSET STATUS_FAILURE
269#define INVALID_SECTION STATUS_FAILURE
270#define SECTOR_1K 1024
271#define SECTOR_64K (64 * SECTOR_1K)
272#define SECTOR_128K (2 * SECTOR_64K)
273#define SECTOR_256k (2 * SECTOR_128K)
274#define SECTOR_512K (2 * SECTOR_256k)
275#define FLASH_PART_SIZE (16 * 1024 * 1024)
276#define RESET_CHIP_SELECT -1
277#define CHIP_SELECT_BIT12 12
278#define SECTOR_READWRITE_PERMISSION 0
279#define SECTOR_READONLY 1
280#define SIGNATURE_SIZE 4
281#define DEFAULT_BUFF_SIZE 0x10000
282
283#define FIELD_OFFSET_IN_HEADER(HeaderPointer, Field) ((u8 *)&((HeaderPointer)(NULL))->Field - (u8 *)(NULL))
284
285#endif
286
diff --git a/drivers/staging/bcm/sort.c b/drivers/staging/bcm/sort.c
deleted file mode 100644
index ca0b17991512..000000000000
--- a/drivers/staging/bcm/sort.c
+++ /dev/null
@@ -1,52 +0,0 @@
1#include "headers.h"
2#include <linux/sort.h>
3
4/*
5 * File Name: sort.c
6 *
7 * Author: Beceem Communications Pvt. Ltd
8 *
9 * Abstract: This file contains the routines sorting the classification rules.
10 *
11 * Copyright (c) 2007 Beceem Communications Pvt. Ltd
12 */
13
14static int compare_packet_info(void const *a, void const *b)
15{
16 struct bcm_packet_info const *pa = a;
17 struct bcm_packet_info const *pb = b;
18
19 if (!pa->bValid || !pb->bValid)
20 return 0;
21
22 return pa->u8TrafficPriority - pb->u8TrafficPriority;
23}
24
25VOID SortPackInfo(struct bcm_mini_adapter *Adapter)
26{
27 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG,
28 DBG_LVL_ALL, "<=======");
29
30 sort(Adapter->PackInfo, NO_OF_QUEUES, sizeof(struct bcm_packet_info),
31 compare_packet_info, NULL);
32}
33
34static int compare_classifiers(void const *a, void const *b)
35{
36 struct bcm_classifier_rule const *pa = a;
37 struct bcm_classifier_rule const *pb = b;
38
39 if (!pa->bUsed || !pb->bUsed)
40 return 0;
41
42 return pa->u8ClassifierRulePriority - pb->u8ClassifierRulePriority;
43}
44
45VOID SortClassifiers(struct bcm_mini_adapter *Adapter)
46{
47 BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, CONN_MSG,
48 DBG_LVL_ALL, "<=======");
49
50 sort(Adapter->astClassifierTable, MAX_CLASSIFIERS,
51 sizeof(struct bcm_classifier_rule), compare_classifiers, NULL);
52}
diff --git a/drivers/staging/bcm/target_params.h b/drivers/staging/bcm/target_params.h
deleted file mode 100644
index dc45f9ab854d..000000000000
--- a/drivers/staging/bcm/target_params.h
+++ /dev/null
@@ -1,57 +0,0 @@
1#ifndef TARGET_PARAMS_H
2#define TARGET_PARAMS_H
3
4struct bcm_target_params {
5 u32 m_u32CfgVersion;
6 u32 m_u32CenterFrequency;
7 u32 m_u32BandAScan;
8 u32 m_u32BandBScan;
9 u32 m_u32BandCScan;
10 u32 m_u32ErtpsOptions;
11 u32 m_u32PHSEnable;
12 u32 m_u32HoEnable;
13 u32 m_u32HoReserved1;
14 u32 m_u32HoReserved2;
15 u32 m_u32MimoEnable;
16 u32 m_u32SecurityEnable;
17 u32 m_u32PowerSavingModesEnable; /* bit 1: 1 Idlemode enable; bit2: 1 Sleepmode Enable */
18 /* PowerSaving Mode Options:
19 * bit 0 = 1: CPE mode - to keep pcmcia if alive;
20 * bit 1 = 1: CINR reporting in Idlemode Msg
21 * bit 2 = 1: Default PSC Enable in sleepmode
22 */
23 u32 m_u32PowerSavingModeOptions;
24 u32 m_u32ArqEnable;
25 /* From Version #3, the HARQ section renamed as general */
26 u32 m_u32HarqEnable;
27 u32 m_u32EEPROMFlag;
28 /* BINARY TYPE - 4th MSByte: Interface Type - 3rd MSByte: Vendor Type - 2nd MSByte
29 * Unused - LSByte
30 */
31 u32 m_u32Customize;
32 u32 m_u32ConfigBW; /* In Hz */
33 u32 m_u32ShutDownInitThresholdTimer;
34 u32 m_u32RadioParameter;
35 u32 m_u32PhyParameter1;
36 u32 m_u32PhyParameter2;
37 u32 m_u32PhyParameter3;
38 u32 m_u32TestOptions; /* in eval mode only; lower 16bits = basic cid for testing; then bit 16 is test cqich,bit 17 test init rang; bit 18 test periodic rang and bit 19 is test harq ack/nack */
39 u32 m_u32MaxMACDataperDLFrame;
40 u32 m_u32MaxMACDataperULFrame;
41 u32 m_u32Corr2MacFlags;
42 u32 HostDrvrConfig1;
43 u32 HostDrvrConfig2;
44 u32 HostDrvrConfig3;
45 u32 HostDrvrConfig4;
46 u32 HostDrvrConfig5;
47 u32 HostDrvrConfig6;
48 u32 m_u32SegmentedPUSCenable;
49 /* removed SHUT down related 'unused' params from here to sync 4.x and 5.x CFG files..
50 * BAMC Related Parameters
51 * Bit 0-15 Band AMC signaling configuration: Bit 1 = 1 – Enable Band AMC signaling.
52 * bit 16-31 Band AMC Data configuration: Bit 16 = 1 – Band AMC 2x3 support.
53 */
54 u32 m_u32BandAMCEnable;
55};
56
57#endif
diff --git a/drivers/staging/bcm/vendorspecificextn.c b/drivers/staging/bcm/vendorspecificextn.c
deleted file mode 100644
index 1d9bef6e4273..000000000000
--- a/drivers/staging/bcm/vendorspecificextn.c
+++ /dev/null
@@ -1,145 +0,0 @@
1#include "headers.h"
2/*
3 * Procedure: vendorextnGetSectionInfo
4 *
5 * Description: Finds the type of NVM used.
6 *
7 * Arguments:
8 * Adapter - ptr to Adapter object instance
9 * pNVMType - ptr to NVM type.
10 * Returns:
11 * STATUS_SUCCESS/STATUS_FAILURE
12 *
13 */
14INT vendorextnGetSectionInfo(PVOID pContext,
15 struct bcm_flash2x_vendor_info *pVendorInfo)
16{
17 return STATUS_FAILURE;
18}
19
20/*
21 * Procedure: vendorextnInit
22 *
23 * Description: Initializing the vendor extension NVM interface
24 *
25 * Arguments:
26 * Adapter - Pointer to MINI Adapter Structure
27 * Returns:
28 * STATUS_SUCCESS/STATUS_FAILURE
29 *
30 *
31 */
32INT vendorextnInit(struct bcm_mini_adapter *Adapter)
33{
34 return STATUS_SUCCESS;
35}
36
37/*
38 * Procedure: vendorextnExit
39 *
40 * Description: Free the resource associated with vendor extension NVM interface
41 *
42 * Arguments:
43 *
44 * Returns:
45 * STATUS_SUCCESS/STATUS_FAILURE
46 *
47 *
48 */
49INT vendorextnExit(struct bcm_mini_adapter *Adapter)
50{
51 return STATUS_SUCCESS;
52}
53
54/*
55 * Procedure: vendorextnIoctl
56 *
57 * Description: execute the vendor extension specific ioctl
58 *
59 * Arguments:
60 * Adapter -Beceem private Adapter Structure
61 * cmd -vendor extension specific Ioctl commad
62 * arg -input parameter sent by vendor
63 *
64 * Returns:
65 * CONTINUE_COMMON_PATH in case it is not meant to be processed
66 * by vendor ioctls
67 * STATUS_SUCCESS/STATUS_FAILURE as per the IOCTL return value
68 */
69
70INT vendorextnIoctl(struct bcm_mini_adapter *Adapter, UINT cmd, ULONG arg)
71{
72 return CONTINUE_COMMON_PATH;
73}
74
75
76
77/*
78 * Procedure: vendorextnReadSection
79 *
80 * Description: Reads from a section of NVM
81 *
82 * Arguments:
83 * pContext - ptr to Adapter object instance
84 * pBuffer - Read the data from Vendor Area to this buffer
85 * SectionVal - Value of type of Section
86 * Offset - Read from the Offset of the Vendor Section.
87 * numOfBytes - Read numOfBytes from the Vendor section to Buffer
88 *
89 * Returns:
90 * STATUS_SUCCESS/STATUS_FAILURE
91 */
92
93INT vendorextnReadSection(PVOID pContext, PUCHAR pBuffer,
94 enum bcm_flash2x_section_val SectionVal, UINT offset, UINT numOfBytes)
95{
96 return STATUS_FAILURE;
97}
98
99
100
101/*
102 * Procedure: vendorextnWriteSection
103 *
104 * Description: Write to a Section of NVM
105 *
106 * Arguments:
107 * pContext - ptr to Adapter object instance
108 * pBuffer - Write the data provided in the buffer
109 * SectionVal - Value of type of Section
110 * Offset - Writes to the Offset of the Vendor Section.
111 * numOfBytes - Write num Bytes after reading from pBuffer.
112 * bVerify - the Buffer Written should be verified.
113 *
114 * Returns:
115 * STATUS_SUCCESS/STATUS_FAILURE
116 */
117INT vendorextnWriteSection(PVOID pContext, PUCHAR pBuffer,
118 enum bcm_flash2x_section_val SectionVal, UINT offset,
119 UINT numOfBytes, bool bVerify)
120{
121 return STATUS_FAILURE;
122}
123
124
125
126/*
127 * Procedure: vendorextnWriteSectionWithoutErase
128 *
129 * Description: Write to a Section of NVM without erasing the sector
130 *
131 * Arguments:
132 * pContext - ptr to Adapter object instance
133 * pBuffer - Write the data provided in the buffer
134 * SectionVal - Value of type of Section
135 * Offset - Writes to the Offset of the Vendor Section.
136 * numOfBytes - Write num Bytes after reading from pBuffer.
137 *
138 * Returns:
139 * STATUS_SUCCESS/STATUS_FAILURE
140 */
141INT vendorextnWriteSectionWithoutErase(PVOID pContext, PUCHAR pBuffer,
142 enum bcm_flash2x_section_val SectionVal, UINT offset, UINT numOfBytes)
143{
144 return STATUS_FAILURE;
145}
diff --git a/drivers/staging/bcm/vendorspecificextn.h b/drivers/staging/bcm/vendorspecificextn.h
deleted file mode 100644
index ff57f0570451..000000000000
--- a/drivers/staging/bcm/vendorspecificextn.h
+++ /dev/null
@@ -1,18 +0,0 @@
1
2#ifndef __VENDOR_EXTN_NVM_H__
3#define __VENDOR_EXTN_NVM_H__
4
5#define CONTINUE_COMMON_PATH 0xFFFF
6
7INT vendorextnGetSectionInfo(PVOID pContext, struct bcm_flash2x_vendor_info *pVendorInfo);
8INT vendorextnExit(struct bcm_mini_adapter *Adapter);
9INT vendorextnInit(struct bcm_mini_adapter *Adapter);
10INT vendorextnIoctl(struct bcm_mini_adapter *Adapter, UINT cmd, ULONG arg);
11INT vendorextnReadSection(PVOID pContext, PUCHAR pBuffer, enum bcm_flash2x_section_val SectionVal,
12 UINT offset, UINT numOfBytes);
13INT vendorextnWriteSection(PVOID pContext, PUCHAR pBuffer, enum bcm_flash2x_section_val SectionVal,
14 UINT offset, UINT numOfBytes, bool bVerify);
15INT vendorextnWriteSectionWithoutErase(PVOID pContext, PUCHAR pBuffer, enum bcm_flash2x_section_val SectionVal,
16 UINT offset, UINT numOfBytes);
17
18#endif /* */
diff --git a/drivers/staging/clocking-wizard/Kconfig b/drivers/staging/clocking-wizard/Kconfig
new file mode 100644
index 000000000000..357af02c562c
--- /dev/null
+++ b/drivers/staging/clocking-wizard/Kconfig
@@ -0,0 +1,9 @@
1#
2# Xilinx Clocking Wizard Driver
3#
4
5config COMMON_CLK_XLNX_CLKWZRD
6 tristate "Xilinx Clocking Wizard"
7 depends on COMMON_CLK && OF
8 ---help---
9 Support for the Xilinx Clocking Wizard IP core clock generator.
diff --git a/drivers/staging/clocking-wizard/Makefile b/drivers/staging/clocking-wizard/Makefile
new file mode 100644
index 000000000000..5ad352f521fe
--- /dev/null
+++ b/drivers/staging/clocking-wizard/Makefile
@@ -0,0 +1 @@
obj-$(CONFIG_COMMON_CLK_XLNX_CLKWZRD) += clk-xlnx-clock-wizard.o
diff --git a/drivers/staging/clocking-wizard/TODO b/drivers/staging/clocking-wizard/TODO
new file mode 100644
index 000000000000..ebe99db7d153
--- /dev/null
+++ b/drivers/staging/clocking-wizard/TODO
@@ -0,0 +1,12 @@
1TODO:
2 - support for fractional multiplier
3 - support for fractional divider (output 0 only)
4 - support for set_rate() operations (may benefit from Stephen Boyd's
5 refactoring of the clk primitives: https://lkml.org/lkml/2014/9/5/766)
6 - review arithmetic
7 - overflow after multiplication?
8 - maximize accuracy before divisions
9
10Patches to:
11 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
12 Sören Brinkmann <soren.brinkmann@xilinx.com>
diff --git a/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c b/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c
new file mode 100644
index 000000000000..471d0877f382
--- /dev/null
+++ b/drivers/staging/clocking-wizard/clk-xlnx-clock-wizard.c
@@ -0,0 +1,341 @@
1/*
2 * Xilinx 'Clocking Wizard' driver
3 *
4 * Copyright (C) 2013 - 2014 Xilinx
5 *
6 * Sören Brinkmann <soren.brinkmann@xilinx.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 v2 as published by
10 * the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include <linux/platform_device.h>
22#include <linux/clk-provider.h>
23#include <linux/slab.h>
24#include <linux/io.h>
25#include <linux/of.h>
26#include <linux/module.h>
27#include <linux/err.h>
28
29#define WZRD_NUM_OUTPUTS 7
30#define WZRD_ACLK_MAX_FREQ 250000000UL
31
32#define WZRD_CLK_CFG_REG(n) (0x200 + 4 * (n))
33
34#define WZRD_CLkOUT0_FRAC_EN BIT(18)
35#define WZRD_CLkFBOUT_FRAC_EN BIT(26)
36
37#define WZRD_CLKFBOUT_MULT_SHIFT 8
38#define WZRD_CLKFBOUT_MULT_MASK (0xff << WZRD_CLKFBOUT_MULT_SHIFT)
39#define WZRD_DIVCLK_DIVIDE_SHIFT 0
40#define WZRD_DIVCLK_DIVIDE_MASK (0xff << WZRD_DIVCLK_DIVIDE_SHIFT)
41#define WZRD_CLKOUT_DIVIDE_SHIFT 0
42#define WZRD_CLKOUT_DIVIDE_MASK (0xff << WZRD_DIVCLK_DIVIDE_SHIFT)
43
44enum clk_wzrd_int_clks {
45 wzrd_clk_mul,
46 wzrd_clk_mul_div,
47 wzrd_clk_int_max
48};
49
50/**
51 * struct clk_wzrd:
52 * @clk_data: Clock data
53 * @nb: Notifier block
54 * @base: Memory base
55 * @clk_in1: Handle to input clock 'clk_in1'
56 * @axi_clk: Handle to input clock 's_axi_aclk'
57 * @clks_internal: Internal clocks
58 * @clkout: Output clocks
59 * @speed_grade: Speed grade of the device
60 * @suspended: Flag indicating power state of the device
61 */
62struct clk_wzrd {
63 struct clk_onecell_data clk_data;
64 struct notifier_block nb;
65 void __iomem *base;
66 struct clk *clk_in1;
67 struct clk *axi_clk;
68 struct clk *clks_internal[wzrd_clk_int_max];
69 struct clk *clkout[WZRD_NUM_OUTPUTS];
70 int speed_grade;
71 bool suspended;
72};
73#define to_clk_wzrd(_nb) container_of(_nb, struct clk_wzrd, nb)
74
75/* maximum frequencies for input/output clocks per speed grade */
76static const unsigned long clk_wzrd_max_freq[] = {
77 800000000UL,
78 933000000UL,
79 1066000000UL
80};
81
82static int clk_wzrd_clk_notifier(struct notifier_block *nb, unsigned long event,
83 void *data)
84{
85 unsigned long max;
86 struct clk_notifier_data *ndata = data;
87 struct clk_wzrd *clk_wzrd = to_clk_wzrd(nb);
88
89 if (clk_wzrd->suspended)
90 return NOTIFY_OK;
91
92 if (ndata->clk == clk_wzrd->clk_in1)
93 max = clk_wzrd_max_freq[clk_wzrd->speed_grade - 1];
94 if (ndata->clk == clk_wzrd->axi_clk)
95 max = WZRD_ACLK_MAX_FREQ;
96
97 switch (event) {
98 case PRE_RATE_CHANGE:
99 if (ndata->new_rate > max)
100 return NOTIFY_BAD;
101 return NOTIFY_OK;
102 case POST_RATE_CHANGE:
103 case ABORT_RATE_CHANGE:
104 default:
105 return NOTIFY_DONE;
106 }
107}
108
109static int __maybe_unused clk_wzrd_suspend(struct device *dev)
110{
111 struct clk_wzrd *clk_wzrd = dev_get_drvdata(dev);
112
113 clk_disable_unprepare(clk_wzrd->axi_clk);
114 clk_wzrd->suspended = true;
115
116 return 0;
117}
118
119static int __maybe_unused clk_wzrd_resume(struct device *dev)
120{
121 int ret;
122 struct clk_wzrd *clk_wzrd = dev_get_drvdata(dev);
123
124 ret = clk_prepare_enable(clk_wzrd->axi_clk);
125 if (ret) {
126 dev_err(dev, "unable to enable s_axi_aclk\n");
127 return ret;
128 }
129
130 clk_wzrd->suspended = false;
131
132 return 0;
133}
134
135static SIMPLE_DEV_PM_OPS(clk_wzrd_dev_pm_ops, clk_wzrd_suspend,
136 clk_wzrd_resume);
137
138static int clk_wzrd_probe(struct platform_device *pdev)
139{
140 int i, ret;
141 u32 reg;
142 unsigned long rate;
143 const char *clk_name;
144 struct clk_wzrd *clk_wzrd;
145 struct resource *mem;
146 struct device_node *np = pdev->dev.of_node;
147
148 clk_wzrd = devm_kzalloc(&pdev->dev, sizeof(*clk_wzrd), GFP_KERNEL);
149 if (!clk_wzrd)
150 return -ENOMEM;
151 platform_set_drvdata(pdev, clk_wzrd);
152
153 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
154 clk_wzrd->base = devm_ioremap_resource(&pdev->dev, mem);
155 if (IS_ERR(clk_wzrd->base))
156 return PTR_ERR(clk_wzrd->base);
157
158 ret = of_property_read_u32(np, "speed-grade", &clk_wzrd->speed_grade);
159 if (!ret) {
160 if (clk_wzrd->speed_grade < 1 || clk_wzrd->speed_grade > 3) {
161 dev_warn(&pdev->dev, "invalid speed grade '%d'\n",
162 clk_wzrd->speed_grade);
163 clk_wzrd->speed_grade = 0;
164 }
165 }
166
167 clk_wzrd->clk_in1 = devm_clk_get(&pdev->dev, "clk_in1");
168 if (IS_ERR(clk_wzrd->clk_in1)) {
169 if (clk_wzrd->clk_in1 != ERR_PTR(-EPROBE_DEFER))
170 dev_err(&pdev->dev, "clk_in1 not found\n");
171 return PTR_ERR(clk_wzrd->clk_in1);
172 }
173
174 clk_wzrd->axi_clk = devm_clk_get(&pdev->dev, "s_axi_aclk");
175 if (IS_ERR(clk_wzrd->axi_clk)) {
176 if (clk_wzrd->axi_clk != ERR_PTR(-EPROBE_DEFER))
177 dev_err(&pdev->dev, "s_axi_aclk not found\n");
178 return PTR_ERR(clk_wzrd->axi_clk);
179 }
180 ret = clk_prepare_enable(clk_wzrd->axi_clk);
181 if (ret) {
182 dev_err(&pdev->dev, "enabling s_axi_aclk failed\n");
183 return ret;
184 }
185 rate = clk_get_rate(clk_wzrd->axi_clk);
186 if (rate > WZRD_ACLK_MAX_FREQ) {
187 dev_err(&pdev->dev, "s_axi_aclk frequency (%lu) too high\n",
188 rate);
189 ret = -EINVAL;
190 goto err_disable_clk;
191 }
192
193 /* we don't support fractional div/mul yet */
194 reg = readl(clk_wzrd->base + WZRD_CLK_CFG_REG(0)) &
195 WZRD_CLkFBOUT_FRAC_EN;
196 reg |= readl(clk_wzrd->base + WZRD_CLK_CFG_REG(2)) &
197 WZRD_CLkOUT0_FRAC_EN;
198 if (reg)
199 dev_warn(&pdev->dev, "fractional div/mul not supported\n");
200
201 /* register multiplier */
202 reg = (readl(clk_wzrd->base + WZRD_CLK_CFG_REG(0)) &
203 WZRD_CLKFBOUT_MULT_MASK) >> WZRD_CLKFBOUT_MULT_SHIFT;
204 clk_name = kasprintf(GFP_KERNEL, "%s_mul", dev_name(&pdev->dev));
205 if (!clk_name) {
206 ret = -ENOMEM;
207 goto err_disable_clk;
208 }
209 clk_wzrd->clks_internal[wzrd_clk_mul] = clk_register_fixed_factor(
210 &pdev->dev, clk_name,
211 __clk_get_name(clk_wzrd->clk_in1),
212 0, reg, 1);
213 kfree(clk_name);
214 if (IS_ERR(clk_wzrd->clks_internal[wzrd_clk_mul])) {
215 dev_err(&pdev->dev, "unable to register fixed-factor clock\n");
216 ret = PTR_ERR(clk_wzrd->clks_internal[wzrd_clk_mul]);
217 goto err_disable_clk;
218 }
219
220 /* register div */
221 reg = (readl(clk_wzrd->base + WZRD_CLK_CFG_REG(0)) &
222 WZRD_DIVCLK_DIVIDE_MASK) >> WZRD_DIVCLK_DIVIDE_SHIFT;
223 clk_name = kasprintf(GFP_KERNEL, "%s_mul_div", dev_name(&pdev->dev));
224 if (!clk_name) {
225 ret = -ENOMEM;
226 goto err_rm_int_clk;
227 }
228
229 clk_wzrd->clks_internal[wzrd_clk_mul_div] = clk_register_fixed_factor(
230 &pdev->dev, clk_name,
231 __clk_get_name(clk_wzrd->clks_internal[wzrd_clk_mul]),
232 0, 1, reg);
233 if (IS_ERR(clk_wzrd->clks_internal[wzrd_clk_mul_div])) {
234 dev_err(&pdev->dev, "unable to register divider clock\n");
235 ret = PTR_ERR(clk_wzrd->clks_internal[wzrd_clk_mul_div]);
236 goto err_rm_int_clk;
237 }
238
239 /* register div per output */
240 for (i = WZRD_NUM_OUTPUTS - 1; i >= 0 ; i--) {
241 const char *clkout_name;
242 if (of_property_read_string_index(np, "clock-output-names", i,
243 &clkout_name)) {
244 dev_err(&pdev->dev,
245 "clock output name not specified\n");
246 ret = -EINVAL;
247 goto err_rm_int_clks;
248 }
249 reg = readl(clk_wzrd->base + WZRD_CLK_CFG_REG(2) + i * 12);
250 reg &= WZRD_CLKOUT_DIVIDE_MASK;
251 reg >>= WZRD_CLKOUT_DIVIDE_SHIFT;
252 clk_wzrd->clkout[i] = clk_register_fixed_factor(&pdev->dev,
253 clkout_name, clk_name, 0, 1, reg);
254 if (IS_ERR(clk_wzrd->clkout[i])) {
255 int j;
256
257 for (j = i + 1; j < WZRD_NUM_OUTPUTS; j++)
258 clk_unregister(clk_wzrd->clkout[j]);
259 dev_err(&pdev->dev,
260 "unable to register divider clock\n");
261 ret = PTR_ERR(clk_wzrd->clkout[i]);
262 goto err_rm_int_clks;
263 }
264 }
265
266 kfree(clk_name);
267
268 clk_wzrd->clk_data.clks = clk_wzrd->clkout;
269 clk_wzrd->clk_data.clk_num = ARRAY_SIZE(clk_wzrd->clkout);
270 of_clk_add_provider(np, of_clk_src_onecell_get, &clk_wzrd->clk_data);
271
272 if (clk_wzrd->speed_grade) {
273 clk_wzrd->nb.notifier_call = clk_wzrd_clk_notifier;
274
275 ret = clk_notifier_register(clk_wzrd->clk_in1,
276 &clk_wzrd->nb);
277 if (ret)
278 dev_warn(&pdev->dev,
279 "unable to register clock notifier\n");
280
281 ret = clk_notifier_register(clk_wzrd->axi_clk, &clk_wzrd->nb);
282 if (ret)
283 dev_warn(&pdev->dev,
284 "unable to register clock notifier\n");
285 }
286
287 return 0;
288
289err_rm_int_clks:
290 clk_unregister(clk_wzrd->clks_internal[1]);
291err_rm_int_clk:
292 kfree(clk_name);
293 clk_unregister(clk_wzrd->clks_internal[0]);
294err_disable_clk:
295 clk_disable_unprepare(clk_wzrd->axi_clk);
296
297 return ret;
298}
299
300static int clk_wzrd_remove(struct platform_device *pdev)
301{
302 int i;
303 struct clk_wzrd *clk_wzrd = platform_get_drvdata(pdev);
304
305 of_clk_del_provider(pdev->dev.of_node);
306
307 for (i = 0; i < WZRD_NUM_OUTPUTS; i++)
308 clk_unregister(clk_wzrd->clkout[i]);
309 for (i = 0; i < wzrd_clk_int_max; i++)
310 clk_unregister(clk_wzrd->clks_internal[i]);
311
312 if (clk_wzrd->speed_grade) {
313 clk_notifier_unregister(clk_wzrd->axi_clk, &clk_wzrd->nb);
314 clk_notifier_unregister(clk_wzrd->clk_in1, &clk_wzrd->nb);
315 }
316
317 clk_disable_unprepare(clk_wzrd->axi_clk);
318
319 return 0;
320}
321
322static const struct of_device_id clk_wzrd_ids[] = {
323 { .compatible = "xlnx,clocking-wizard" },
324 { },
325};
326MODULE_DEVICE_TABLE(of, clk_wzrd_ids);
327
328static struct platform_driver clk_wzrd_driver = {
329 .driver = {
330 .name = "clk-wizard",
331 .of_match_table = clk_wzrd_ids,
332 .pm = &clk_wzrd_dev_pm_ops,
333 },
334 .probe = clk_wzrd_probe,
335 .remove = clk_wzrd_remove,
336};
337module_platform_driver(clk_wzrd_driver);
338
339MODULE_LICENSE("GPL");
340MODULE_AUTHOR("Soeren Brinkmann <soren.brinkmann@xilinx.com");
341MODULE_DESCRIPTION("Driver for the Xilinx Clocking Wizard IP core");
diff --git a/drivers/staging/clocking-wizard/dt-binding.txt b/drivers/staging/clocking-wizard/dt-binding.txt
new file mode 100644
index 000000000000..723271e93316
--- /dev/null
+++ b/drivers/staging/clocking-wizard/dt-binding.txt
@@ -0,0 +1,30 @@
1Binding for Xilinx Clocking Wizard IP Core
2
3This binding uses the common clock binding[1]. Details about the devices can be
4found in the product guide[2].
5
6[1] Documentation/devicetree/bindings/clock/clock-bindings.txt
7[2] Clocking Wizard Product Guide
8http://www.xilinx.com/support/documentation/ip_documentation/clk_wiz/v5_1/pg065-clk-wiz.pdf
9
10Required properties:
11 - compatible: Must be 'xlnx,clocking-wizard'
12 - reg: Base and size of the cores register space
13 - clocks: Handle to input clock
14 - clock-names: Tuple containing 'clk_in1' and 's_axi_aclk'
15 - clock-output-names: Names for the output clocks
16
17Optional properties:
18 - speed-grade: Speed grade of the device (valid values are 1..3)
19
20Example:
21 clock-generator@40040000 {
22 reg = <0x40040000 0x1000>;
23 compatible = "xlnx,clocking-wizard";
24 speed-grade = <1>;
25 clock-names = "clk_in1", "s_axi_aclk";
26 clocks = <&clkc 15>, <&clkc 15>;
27 clock-output-names = "clk_out0", "clk_out1", "clk_out2",
28 "clk_out3", "clk_out4", "clk_out5",
29 "clk_out6", "clk_out7";
30 };
diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig
index 152f4c12ea43..a8201fe87512 100644
--- a/drivers/staging/comedi/Kconfig
+++ b/drivers/staging/comedi/Kconfig
@@ -384,6 +384,7 @@ config COMEDI_DT282X
384 384
385config COMEDI_DMM32AT 385config COMEDI_DMM32AT
386 tristate "Diamond Systems MM-32-AT PC/104 board support" 386 tristate "Diamond Systems MM-32-AT PC/104 board support"
387 select COMEDI_8255
387 ---help--- 388 ---help---
388 Enable support for Diamond Systems MM-32-AT PC/104 boards 389 Enable support for Diamond Systems MM-32-AT PC/104 boards
389 390
@@ -564,11 +565,14 @@ config COMEDI_S526
564endif # COMEDI_ISA_DRIVERS 565endif # COMEDI_ISA_DRIVERS
565 566
566menuconfig COMEDI_PCI_DRIVERS 567menuconfig COMEDI_PCI_DRIVERS
567 bool "Comedi PCI drivers" 568 tristate "Comedi PCI drivers"
568 depends on PCI 569 depends on PCI
569 ---help--- 570 ---help---
570 Enable support for comedi PCI drivers. 571 Enable support for comedi PCI drivers.
571 572
573 To compile this support as a module, choose M here: the module will
574 be called comedi_pci.
575
572if COMEDI_PCI_DRIVERS 576if COMEDI_PCI_DRIVERS
573 577
574config COMEDI_8255_PCI 578config COMEDI_8255_PCI
@@ -595,14 +599,6 @@ config COMEDI_ADDI_WATCHDOG
595 boards. This module will be automatically selected when needed. The 599 boards. This module will be automatically selected when needed. The
596 module will be called addi_watchdog. 600 module will be called addi_watchdog.
597 601
598config COMEDI_ADDI_APCI_035
599 tristate "ADDI-DATA APCI_035 support"
600 ---help---
601 Enable support for ADDI-DATA APCI_035 cards
602
603 To compile this driver as a module, choose M here: the module will be
604 called addi_apci_035.
605
606config COMEDI_ADDI_APCI_1032 602config COMEDI_ADDI_APCI_1032
607 tristate "ADDI-DATA APCI_1032 support" 603 tristate "ADDI-DATA APCI_1032 support"
608 ---help--- 604 ---help---
@@ -939,11 +935,11 @@ config COMEDI_CB_PCIDDA
939 called cb_pcidda. 935 called cb_pcidda.
940 936
941config COMEDI_CB_PCIMDAS 937config COMEDI_CB_PCIMDAS
942 tristate "MeasurementComputing PCIM-DAS1602/16 support" 938 tristate "MeasurementComputing PCIM-DAS1602/16, PCIe-DAS1602/16 support"
943 select COMEDI_8255 939 select COMEDI_8255
944 ---help--- 940 ---help---
945 Enable support for ComputerBoards/MeasurementComputing PCI Migration 941 Enable support for ComputerBoards/MeasurementComputing PCI Migration
946 series PCIM-DAS1602/16 942 series PCIM-DAS1602/16 and PCIe-DAS1602/16.
947 943
948 To compile this driver as a module, choose M here: the module will be 944 To compile this driver as a module, choose M here: the module will be
949 called cb_pcimdas. 945 called cb_pcimdas.
@@ -1084,11 +1080,14 @@ config COMEDI_NI_TIOCMD
1084endif # COMEDI_PCI_DRIVERS 1080endif # COMEDI_PCI_DRIVERS
1085 1081
1086menuconfig COMEDI_PCMCIA_DRIVERS 1082menuconfig COMEDI_PCMCIA_DRIVERS
1087 bool "Comedi PCMCIA drivers" 1083 tristate "Comedi PCMCIA drivers"
1088 depends on PCMCIA 1084 depends on PCMCIA
1089 ---help--- 1085 ---help---
1090 Enable support for comedi PCMCIA drivers. 1086 Enable support for comedi PCMCIA drivers.
1091 1087
1088 To compile this support as a module, choose M here: the module will
1089 be called comedi_pcmcia.
1090
1092if COMEDI_PCMCIA_DRIVERS 1091if COMEDI_PCMCIA_DRIVERS
1093 1092
1094config COMEDI_CB_DAS16_CS 1093config COMEDI_CB_DAS16_CS
@@ -1160,11 +1159,14 @@ config COMEDI_QUATECH_DAQP_CS
1160endif # COMEDI_PCMCIA_DRIVERS 1159endif # COMEDI_PCMCIA_DRIVERS
1161 1160
1162menuconfig COMEDI_USB_DRIVERS 1161menuconfig COMEDI_USB_DRIVERS
1163 bool "Comedi USB drivers" 1162 tristate "Comedi USB drivers"
1164 depends on USB 1163 depends on USB
1165 ---help--- 1164 ---help---
1166 Enable support for comedi USB drivers. 1165 Enable support for comedi USB drivers.
1167 1166
1167 To compile this support as a module, choose M here: the module will
1168 be called comedi_usb.
1169
1168if COMEDI_USB_DRIVERS 1170if COMEDI_USB_DRIVERS
1169 1171
1170config COMEDI_DT9812 1172config COMEDI_DT9812
diff --git a/drivers/staging/comedi/Makefile b/drivers/staging/comedi/Makefile
index fae2d9090006..7f9dfb3923ab 100644
--- a/drivers/staging/comedi/Makefile
+++ b/drivers/staging/comedi/Makefile
@@ -2,12 +2,13 @@ ccflags-$(CONFIG_COMEDI_DEBUG) := -DDEBUG
2 2
3comedi-y := comedi_fops.o range.o drivers.o \ 3comedi-y := comedi_fops.o range.o drivers.o \
4 comedi_buf.o 4 comedi_buf.o
5comedi-$(CONFIG_COMEDI_PCI_DRIVERS) += comedi_pci.o
6comedi-$(CONFIG_COMEDI_PCMCIA_DRIVERS) += comedi_pcmcia.o
7comedi-$(CONFIG_COMEDI_USB_DRIVERS) += comedi_usb.o
8comedi-$(CONFIG_PROC_FS) += proc.o 5comedi-$(CONFIG_PROC_FS) += proc.o
9comedi-$(CONFIG_COMPAT) += comedi_compat32.o 6comedi-$(CONFIG_COMPAT) += comedi_compat32.o
10 7
8obj-$(CONFIG_COMEDI_PCI_DRIVERS) += comedi_pci.o
9obj-$(CONFIG_COMEDI_PCMCIA_DRIVERS) += comedi_pcmcia.o
10obj-$(CONFIG_COMEDI_USB_DRIVERS) += comedi_usb.o
11
11obj-$(CONFIG_COMEDI) += comedi.o 12obj-$(CONFIG_COMEDI) += comedi.o
12 13
13obj-$(CONFIG_COMEDI) += kcomedilib/ 14obj-$(CONFIG_COMEDI) += kcomedilib/
diff --git a/drivers/staging/comedi/comedi.h b/drivers/staging/comedi/comedi.h
index c8c99e65423b..745574077352 100644
--- a/drivers/staging/comedi/comedi.h
+++ b/drivers/staging/comedi/comedi.h
@@ -367,6 +367,8 @@ enum comedi_support_level {
367#define COMEDI_BUFCONFIG _IOR(CIO, 13, struct comedi_bufconfig) 367#define COMEDI_BUFCONFIG _IOR(CIO, 13, struct comedi_bufconfig)
368#define COMEDI_BUFINFO _IOWR(CIO, 14, struct comedi_bufinfo) 368#define COMEDI_BUFINFO _IOWR(CIO, 14, struct comedi_bufinfo)
369#define COMEDI_POLL _IO(CIO, 15) 369#define COMEDI_POLL _IO(CIO, 15)
370#define COMEDI_SETRSUBD _IO(CIO, 16)
371#define COMEDI_SETWSUBD _IO(CIO, 17)
370 372
371/* structures */ 373/* structures */
372 374
@@ -514,17 +516,6 @@ struct comedi_bufinfo {
514 516
515#define COMEDI_MIN_SPEED ((unsigned int)0xffffffff) 517#define COMEDI_MIN_SPEED ((unsigned int)0xffffffff)
516 518
517/* callback stuff */
518/* only relevant to kernel modules. */
519
520#define COMEDI_CB_EOS 1 /* end of scan */
521#define COMEDI_CB_EOA 2 /* end of acquisition/output */
522#define COMEDI_CB_BLOCK 4 /* data has arrived:
523 * wakes up read() / write() */
524#define COMEDI_CB_EOBUF 8 /* DEPRECATED: end of buffer */
525#define COMEDI_CB_ERROR 16 /* card error during acquisition */
526#define COMEDI_CB_OVERFLOW 32 /* buffer overflow/underflow */
527
528/**********************************************************/ 519/**********************************************************/
529/* everything after this line is ALPHA */ 520/* everything after this line is ALPHA */
530/**********************************************************/ 521/**********************************************************/
diff --git a/drivers/staging/comedi/comedi_buf.c b/drivers/staging/comedi/comedi_buf.c
index c60a45ad12b9..19e7b229d15e 100644
--- a/drivers/staging/comedi/comedi_buf.c
+++ b/drivers/staging/comedi/comedi_buf.c
@@ -236,6 +236,7 @@ void comedi_buf_reset(struct comedi_subdevice *s)
236 async->buf_read_ptr = 0; 236 async->buf_read_ptr = 0;
237 237
238 async->cur_chan = 0; 238 async->cur_chan = 0;
239 async->scans_done = 0;
239 async->scan_progress = 0; 240 async->scan_progress = 0;
240 async->munge_chan = 0; 241 async->munge_chan = 0;
241 async->munge_count = 0; 242 async->munge_count = 0;
@@ -252,15 +253,15 @@ static unsigned int comedi_buf_write_n_available(struct comedi_subdevice *s)
252 return free_end - async->buf_write_alloc_count; 253 return free_end - async->buf_write_alloc_count;
253} 254}
254 255
255static unsigned int __comedi_buf_write_alloc(struct comedi_subdevice *s, 256/* allocates chunk for the writer from free buffer space */
256 unsigned int nbytes, 257unsigned int comedi_buf_write_alloc(struct comedi_subdevice *s,
257 int strict) 258 unsigned int nbytes)
258{ 259{
259 struct comedi_async *async = s->async; 260 struct comedi_async *async = s->async;
260 unsigned int available = comedi_buf_write_n_available(s); 261 unsigned int available = comedi_buf_write_n_available(s);
261 262
262 if (nbytes > available) 263 if (nbytes > available)
263 nbytes = strict ? 0 : available; 264 nbytes = available;
264 265
265 async->buf_write_alloc_count += nbytes; 266 async->buf_write_alloc_count += nbytes;
266 267
@@ -272,13 +273,6 @@ static unsigned int __comedi_buf_write_alloc(struct comedi_subdevice *s,
272 273
273 return nbytes; 274 return nbytes;
274} 275}
275
276/* allocates chunk for the writer from free buffer space */
277unsigned int comedi_buf_write_alloc(struct comedi_subdevice *s,
278 unsigned int nbytes)
279{
280 return __comedi_buf_write_alloc(s, nbytes, 0);
281}
282EXPORT_SYMBOL_GPL(comedi_buf_write_alloc); 276EXPORT_SYMBOL_GPL(comedi_buf_write_alloc);
283 277
284/* 278/*
@@ -290,7 +284,7 @@ static unsigned int comedi_buf_munge(struct comedi_subdevice *s,
290{ 284{
291 struct comedi_async *async = s->async; 285 struct comedi_async *async = s->async;
292 unsigned int count = 0; 286 unsigned int count = 0;
293 const unsigned num_sample_bytes = bytes_per_sample(s); 287 const unsigned num_sample_bytes = comedi_bytes_per_sample(s);
294 288
295 if (!s->munge || (async->cmd.flags & CMDF_RAWDATA)) { 289 if (!s->munge || (async->cmd.flags & CMDF_RAWDATA)) {
296 async->munge_count += num_bytes; 290 async->munge_count += num_bytes;
@@ -427,43 +421,11 @@ unsigned int comedi_buf_read_free(struct comedi_subdevice *s,
427} 421}
428EXPORT_SYMBOL_GPL(comedi_buf_read_free); 422EXPORT_SYMBOL_GPL(comedi_buf_read_free);
429 423
430int comedi_buf_put(struct comedi_subdevice *s, unsigned short x) 424static void comedi_buf_memcpy_to(struct comedi_subdevice *s,
431{ 425 const void *data, unsigned int num_bytes)
432 struct comedi_async *async = s->async;
433 unsigned int n = __comedi_buf_write_alloc(s, sizeof(short), 1);
434
435 if (n < sizeof(short)) {
436 async->events |= COMEDI_CB_ERROR;
437 return 0;
438 }
439 *(unsigned short *)(async->prealloc_buf + async->buf_write_ptr) = x;
440 comedi_buf_write_free(s, sizeof(short));
441 return 1;
442}
443EXPORT_SYMBOL_GPL(comedi_buf_put);
444
445int comedi_buf_get(struct comedi_subdevice *s, unsigned short *x)
446{ 426{
447 struct comedi_async *async = s->async; 427 struct comedi_async *async = s->async;
448 unsigned int n = comedi_buf_read_n_available(s); 428 unsigned int write_ptr = async->buf_write_ptr;
449
450 if (n < sizeof(short))
451 return 0;
452 comedi_buf_read_alloc(s, sizeof(short));
453 *x = *(unsigned short *)(async->prealloc_buf + async->buf_read_ptr);
454 comedi_buf_read_free(s, sizeof(short));
455 return 1;
456}
457EXPORT_SYMBOL_GPL(comedi_buf_get);
458
459void comedi_buf_memcpy_to(struct comedi_subdevice *s, unsigned int offset,
460 const void *data, unsigned int num_bytes)
461{
462 struct comedi_async *async = s->async;
463 unsigned int write_ptr = async->buf_write_ptr + offset;
464
465 if (write_ptr >= async->prealloc_bufsz)
466 write_ptr %= async->prealloc_bufsz;
467 429
468 while (num_bytes) { 430 while (num_bytes) {
469 unsigned int block_size; 431 unsigned int block_size;
@@ -481,17 +443,13 @@ void comedi_buf_memcpy_to(struct comedi_subdevice *s, unsigned int offset,
481 write_ptr = 0; 443 write_ptr = 0;
482 } 444 }
483} 445}
484EXPORT_SYMBOL_GPL(comedi_buf_memcpy_to);
485 446
486void comedi_buf_memcpy_from(struct comedi_subdevice *s, unsigned int offset, 447static void comedi_buf_memcpy_from(struct comedi_subdevice *s,
487 void *dest, unsigned int nbytes) 448 void *dest, unsigned int nbytes)
488{ 449{
489 void *src; 450 void *src;
490 struct comedi_async *async = s->async; 451 struct comedi_async *async = s->async;
491 unsigned int read_ptr = async->buf_read_ptr + offset; 452 unsigned int read_ptr = async->buf_read_ptr;
492
493 if (read_ptr >= async->prealloc_bufsz)
494 read_ptr %= async->prealloc_bufsz;
495 453
496 while (nbytes) { 454 while (nbytes) {
497 unsigned int block_size; 455 unsigned int block_size;
@@ -509,69 +467,84 @@ void comedi_buf_memcpy_from(struct comedi_subdevice *s, unsigned int offset,
509 read_ptr = 0; 467 read_ptr = 0;
510 } 468 }
511} 469}
512EXPORT_SYMBOL_GPL(comedi_buf_memcpy_from);
513 470
514/** 471/**
515 * comedi_write_array_to_buffer - write data to comedi buffer 472 * comedi_buf_write_samples - write sample data to comedi buffer
516 * @s: comedi_subdevice struct 473 * @s: comedi_subdevice struct
517 * @data: destination 474 * @data: samples
518 * @num_bytes: number of bytes to write 475 * @nsamples: number of samples
519 * 476 *
520 * Writes up to num_bytes bytes of data to the comedi buffer associated with 477 * Writes nsamples to the comedi buffer associated with the subdevice, marks
521 * the subdevice, marks it as written and updates the acquisition scan 478 * it as written and updates the acquisition scan progress.
522 * progress.
523 * 479 *
524 * Returns the amount of data written in bytes. 480 * Returns the amount of data written in bytes.
525 */ 481 */
526unsigned int comedi_write_array_to_buffer(struct comedi_subdevice *s, 482unsigned int comedi_buf_write_samples(struct comedi_subdevice *s,
527 const void *data, 483 const void *data, unsigned int nsamples)
528 unsigned int num_bytes)
529{ 484{
530 struct comedi_async *async = s->async; 485 unsigned int max_samples;
531 unsigned int retval; 486 unsigned int nbytes;
532
533 if (num_bytes == 0)
534 return 0;
535 487
536 retval = comedi_buf_write_alloc(s, num_bytes); 488 /*
537 if (retval != num_bytes) { 489 * Make sure there is enough room in the buffer for all the samples.
490 * If not, clamp the nsamples to the number that will fit, flag the
491 * buffer overrun and add the samples that fit.
492 */
493 max_samples = comedi_bytes_to_samples(s,
494 comedi_buf_write_n_available(s));
495 if (nsamples > max_samples) {
538 dev_warn(s->device->class_dev, "buffer overrun\n"); 496 dev_warn(s->device->class_dev, "buffer overrun\n");
539 async->events |= COMEDI_CB_OVERFLOW; 497 s->async->events |= COMEDI_CB_OVERFLOW;
540 return 0; 498 nsamples = max_samples;
541 } 499 }
542 500
543 comedi_buf_memcpy_to(s, 0, data, num_bytes); 501 if (nsamples == 0)
544 comedi_buf_write_free(s, num_bytes); 502 return 0;
545 comedi_inc_scan_progress(s, num_bytes);
546 async->events |= COMEDI_CB_BLOCK;
547 503
548 return num_bytes; 504 nbytes = comedi_buf_write_alloc(s,
505 comedi_samples_to_bytes(s, nsamples));
506 comedi_buf_memcpy_to(s, data, nbytes);
507 comedi_buf_write_free(s, nbytes);
508 comedi_inc_scan_progress(s, nbytes);
509 s->async->events |= COMEDI_CB_BLOCK;
510
511 return nbytes;
549} 512}
550EXPORT_SYMBOL_GPL(comedi_write_array_to_buffer); 513EXPORT_SYMBOL_GPL(comedi_buf_write_samples);
551 514
552/** 515/**
553 * comedi_read_array_from_buffer - read data from comedi buffer 516 * comedi_buf_read_samples - read sample data from comedi buffer
554 * @s: comedi_subdevice struct 517 * @s: comedi_subdevice struct
555 * @data: destination 518 * @data: destination
556 * @num_bytes: number of bytes to read 519 * @nsamples: maximum number of samples to read
557 * 520 *
558 * Reads up to num_bytes bytes of data from the comedi buffer associated with 521 * Reads up to nsamples from the comedi buffer associated with the subdevice,
559 * the subdevice, marks it as read and updates the acquisition scan progress. 522 * marks it as read and updates the acquisition scan progress.
560 * 523 *
561 * Returns the amount of data read in bytes. 524 * Returns the amount of data read in bytes.
562 */ 525 */
563unsigned int comedi_read_array_from_buffer(struct comedi_subdevice *s, 526unsigned int comedi_buf_read_samples(struct comedi_subdevice *s,
564 void *data, unsigned int num_bytes) 527 void *data, unsigned int nsamples)
565{ 528{
566 if (num_bytes == 0) 529 unsigned int max_samples;
530 unsigned int nbytes;
531
532 /* clamp nsamples to the number of full samples available */
533 max_samples = comedi_bytes_to_samples(s,
534 comedi_buf_read_n_available(s));
535 if (nsamples > max_samples)
536 nsamples = max_samples;
537
538 if (nsamples == 0)
567 return 0; 539 return 0;
568 540
569 num_bytes = comedi_buf_read_alloc(s, num_bytes); 541 nbytes = comedi_buf_read_alloc(s,
570 comedi_buf_memcpy_from(s, 0, data, num_bytes); 542 comedi_samples_to_bytes(s, nsamples));
571 comedi_buf_read_free(s, num_bytes); 543 comedi_buf_memcpy_from(s, data, nbytes);
572 comedi_inc_scan_progress(s, num_bytes); 544 comedi_buf_read_free(s, nbytes);
545 comedi_inc_scan_progress(s, nbytes);
573 s->async->events |= COMEDI_CB_BLOCK; 546 s->async->events |= COMEDI_CB_BLOCK;
574 547
575 return num_bytes; 548 return nbytes;
576} 549}
577EXPORT_SYMBOL_GPL(comedi_read_array_from_buffer); 550EXPORT_SYMBOL_GPL(comedi_buf_read_samples);
diff --git a/drivers/staging/comedi/comedi_compat32.c b/drivers/staging/comedi/comedi_compat32.c
index 9b6f96f1591c..5a4c74f703b3 100644
--- a/drivers/staging/comedi/comedi_compat32.c
+++ b/drivers/staging/comedi/comedi_compat32.c
@@ -416,6 +416,8 @@ static inline int raw_ioctl(struct file *file, unsigned int cmd,
416 case COMEDI_UNLOCK: 416 case COMEDI_UNLOCK:
417 case COMEDI_CANCEL: 417 case COMEDI_CANCEL:
418 case COMEDI_POLL: 418 case COMEDI_POLL:
419 case COMEDI_SETRSUBD:
420 case COMEDI_SETWSUBD:
419 /* No translation needed. */ 421 /* No translation needed. */
420 rc = translated_ioctl(file, cmd, arg); 422 rc = translated_ioctl(file, cmd, arg);
421 break; 423 break;
diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index 9c32f0276009..f143cb64d69e 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -43,6 +43,22 @@
43 43
44#include "comedi_internal.h" 44#include "comedi_internal.h"
45 45
46/**
47 * struct comedi_file - per-file private data for comedi device
48 * @dev: comedi_device struct
49 * @read_subdev: current "read" subdevice
50 * @write_subdev: current "write" subdevice
51 * @last_detach_count: last known detach count
52 * @last_attached: last known attached/detached state
53 */
54struct comedi_file {
55 struct comedi_device *dev;
56 struct comedi_subdevice *read_subdev;
57 struct comedi_subdevice *write_subdev;
58 unsigned int last_detach_count;
59 bool last_attached:1;
60};
61
46#define COMEDI_NUM_MINORS 0x100 62#define COMEDI_NUM_MINORS 0x100
47#define COMEDI_NUM_SUBDEVICE_MINORS \ 63#define COMEDI_NUM_SUBDEVICE_MINORS \
48 (COMEDI_NUM_MINORS - COMEDI_NUM_BOARD_MINORS) 64 (COMEDI_NUM_MINORS - COMEDI_NUM_BOARD_MINORS)
@@ -239,6 +255,54 @@ comedi_write_subdevice(const struct comedi_device *dev, unsigned int minor)
239 return dev->write_subdev; 255 return dev->write_subdev;
240} 256}
241 257
258static void comedi_file_reset(struct file *file)
259{
260 struct comedi_file *cfp = file->private_data;
261 struct comedi_device *dev = cfp->dev;
262 struct comedi_subdevice *s, *read_s, *write_s;
263 unsigned int minor = iminor(file_inode(file));
264
265 read_s = dev->read_subdev;
266 write_s = dev->write_subdev;
267 if (minor >= COMEDI_NUM_BOARD_MINORS) {
268 s = comedi_subdevice_from_minor(dev, minor);
269 if (s == NULL || s->subdev_flags & SDF_CMD_READ)
270 read_s = s;
271 if (s == NULL || s->subdev_flags & SDF_CMD_WRITE)
272 write_s = s;
273 }
274 cfp->last_attached = dev->attached;
275 cfp->last_detach_count = dev->detach_count;
276 ACCESS_ONCE(cfp->read_subdev) = read_s;
277 ACCESS_ONCE(cfp->write_subdev) = write_s;
278}
279
280static void comedi_file_check(struct file *file)
281{
282 struct comedi_file *cfp = file->private_data;
283 struct comedi_device *dev = cfp->dev;
284
285 if (cfp->last_attached != dev->attached ||
286 cfp->last_detach_count != dev->detach_count)
287 comedi_file_reset(file);
288}
289
290static struct comedi_subdevice *comedi_file_read_subdevice(struct file *file)
291{
292 struct comedi_file *cfp = file->private_data;
293
294 comedi_file_check(file);
295 return ACCESS_ONCE(cfp->read_subdev);
296}
297
298static struct comedi_subdevice *comedi_file_write_subdevice(struct file *file)
299{
300 struct comedi_file *cfp = file->private_data;
301
302 comedi_file_check(file);
303 return ACCESS_ONCE(cfp->write_subdev);
304}
305
242static int resize_async_buffer(struct comedi_device *dev, 306static int resize_async_buffer(struct comedi_device *dev,
243 struct comedi_subdevice *s, unsigned new_size) 307 struct comedi_subdevice *s, unsigned new_size)
244{ 308{
@@ -776,7 +840,6 @@ static int do_devinfo_ioctl(struct comedi_device *dev,
776 struct comedi_devinfo __user *arg, 840 struct comedi_devinfo __user *arg,
777 struct file *file) 841 struct file *file)
778{ 842{
779 const unsigned minor = iminor(file_inode(file));
780 struct comedi_subdevice *s; 843 struct comedi_subdevice *s;
781 struct comedi_devinfo devinfo; 844 struct comedi_devinfo devinfo;
782 845
@@ -788,13 +851,13 @@ static int do_devinfo_ioctl(struct comedi_device *dev,
788 strlcpy(devinfo.driver_name, dev->driver->driver_name, COMEDI_NAMELEN); 851 strlcpy(devinfo.driver_name, dev->driver->driver_name, COMEDI_NAMELEN);
789 strlcpy(devinfo.board_name, dev->board_name, COMEDI_NAMELEN); 852 strlcpy(devinfo.board_name, dev->board_name, COMEDI_NAMELEN);
790 853
791 s = comedi_read_subdevice(dev, minor); 854 s = comedi_file_read_subdevice(file);
792 if (s) 855 if (s)
793 devinfo.read_subdevice = s->index; 856 devinfo.read_subdevice = s->index;
794 else 857 else
795 devinfo.read_subdevice = -1; 858 devinfo.read_subdevice = -1;
796 859
797 s = comedi_write_subdevice(dev, minor); 860 s = comedi_file_write_subdevice(file);
798 if (s) 861 if (s)
799 devinfo.write_subdevice = s->index; 862 devinfo.write_subdevice = s->index;
800 else 863 else
@@ -991,7 +1054,7 @@ static int do_bufinfo_ioctl(struct comedi_device *dev,
991 if (s->busy != file) 1054 if (s->busy != file)
992 return -EACCES; 1055 return -EACCES;
993 1056
994 if (bi.bytes_read && (s->subdev_flags & SDF_CMD_READ)) { 1057 if (bi.bytes_read && !(async->cmd.flags & CMDF_WRITE)) {
995 bi.bytes_read = comedi_buf_read_alloc(s, bi.bytes_read); 1058 bi.bytes_read = comedi_buf_read_alloc(s, bi.bytes_read);
996 comedi_buf_read_free(s, bi.bytes_read); 1059 comedi_buf_read_free(s, bi.bytes_read);
997 1060
@@ -1001,7 +1064,7 @@ static int do_bufinfo_ioctl(struct comedi_device *dev,
1001 } 1064 }
1002 } 1065 }
1003 1066
1004 if (bi.bytes_written && (s->subdev_flags & SDF_CMD_WRITE)) { 1067 if (bi.bytes_written && (async->cmd.flags & CMDF_WRITE)) {
1005 bi.bytes_written = 1068 bi.bytes_written =
1006 comedi_buf_write_alloc(s, bi.bytes_written); 1069 comedi_buf_write_alloc(s, bi.bytes_written);
1007 comedi_buf_write_free(s, bi.bytes_written); 1070 comedi_buf_write_free(s, bi.bytes_written);
@@ -1451,6 +1514,21 @@ static int __comedi_get_user_cmd(struct comedi_device *dev,
1451 return -EINVAL; 1514 return -EINVAL;
1452 } 1515 }
1453 1516
1517 /*
1518 * Set the CMDF_WRITE flag to the correct state if the subdevice
1519 * supports only "read" commands or only "write" commands.
1520 */
1521 switch (s->subdev_flags & (SDF_CMD_READ | SDF_CMD_WRITE)) {
1522 case SDF_CMD_READ:
1523 cmd->flags &= ~CMDF_WRITE;
1524 break;
1525 case SDF_CMD_WRITE:
1526 cmd->flags |= CMDF_WRITE;
1527 break;
1528 default:
1529 break;
1530 }
1531
1454 return 0; 1532 return 0;
1455} 1533}
1456 1534
@@ -1552,9 +1630,7 @@ static int do_cmd_ioctl(struct comedi_device *dev,
1552 1630
1553 comedi_buf_reset(s); 1631 comedi_buf_reset(s);
1554 1632
1555 async->cb_mask = 1633 async->cb_mask = COMEDI_CB_BLOCK | COMEDI_CB_CANCEL_MASK;
1556 COMEDI_CB_EOA | COMEDI_CB_BLOCK | COMEDI_CB_ERROR |
1557 COMEDI_CB_OVERFLOW;
1558 if (async->cmd.flags & CMDF_WAKE_EOS) 1634 if (async->cmd.flags & CMDF_WAKE_EOS)
1559 async->cb_mask |= COMEDI_CB_EOS; 1635 async->cb_mask |= COMEDI_CB_EOS;
1560 1636
@@ -1720,7 +1796,6 @@ static int do_cancel_ioctl(struct comedi_device *dev, unsigned long arg,
1720 void *file) 1796 void *file)
1721{ 1797{
1722 struct comedi_subdevice *s; 1798 struct comedi_subdevice *s;
1723 int ret;
1724 1799
1725 if (arg >= dev->n_subdevices) 1800 if (arg >= dev->n_subdevices)
1726 return -EINVAL; 1801 return -EINVAL;
@@ -1734,9 +1809,7 @@ static int do_cancel_ioctl(struct comedi_device *dev, unsigned long arg,
1734 if (s->busy != file) 1809 if (s->busy != file)
1735 return -EBUSY; 1810 return -EBUSY;
1736 1811
1737 ret = do_cancel(dev, s); 1812 return do_cancel(dev, s);
1738
1739 return ret;
1740} 1813}
1741 1814
1742/* 1815/*
@@ -1774,11 +1847,96 @@ static int do_poll_ioctl(struct comedi_device *dev, unsigned long arg,
1774 return -EINVAL; 1847 return -EINVAL;
1775} 1848}
1776 1849
1850/*
1851 * COMEDI_SETRSUBD ioctl
1852 * sets the current "read" subdevice on a per-file basis
1853 *
1854 * arg:
1855 * subdevice number
1856 *
1857 * reads:
1858 * nothing
1859 *
1860 * writes:
1861 * nothing
1862 */
1863static int do_setrsubd_ioctl(struct comedi_device *dev, unsigned long arg,
1864 struct file *file)
1865{
1866 struct comedi_file *cfp = file->private_data;
1867 struct comedi_subdevice *s_old, *s_new;
1868
1869 if (arg >= dev->n_subdevices)
1870 return -EINVAL;
1871
1872 s_new = &dev->subdevices[arg];
1873 s_old = comedi_file_read_subdevice(file);
1874 if (s_old == s_new)
1875 return 0; /* no change */
1876
1877 if (!(s_new->subdev_flags & SDF_CMD_READ))
1878 return -EINVAL;
1879
1880 /*
1881 * Check the file isn't still busy handling a "read" command on the
1882 * old subdevice (if any).
1883 */
1884 if (s_old && s_old->busy == file && s_old->async &&
1885 !(s_old->async->cmd.flags & CMDF_WRITE))
1886 return -EBUSY;
1887
1888 ACCESS_ONCE(cfp->read_subdev) = s_new;
1889 return 0;
1890}
1891
1892/*
1893 * COMEDI_SETWSUBD ioctl
1894 * sets the current "write" subdevice on a per-file basis
1895 *
1896 * arg:
1897 * subdevice number
1898 *
1899 * reads:
1900 * nothing
1901 *
1902 * writes:
1903 * nothing
1904 */
1905static int do_setwsubd_ioctl(struct comedi_device *dev, unsigned long arg,
1906 struct file *file)
1907{
1908 struct comedi_file *cfp = file->private_data;
1909 struct comedi_subdevice *s_old, *s_new;
1910
1911 if (arg >= dev->n_subdevices)
1912 return -EINVAL;
1913
1914 s_new = &dev->subdevices[arg];
1915 s_old = comedi_file_write_subdevice(file);
1916 if (s_old == s_new)
1917 return 0; /* no change */
1918
1919 if (!(s_new->subdev_flags & SDF_CMD_WRITE))
1920 return -EINVAL;
1921
1922 /*
1923 * Check the file isn't still busy handling a "write" command on the
1924 * old subdevice (if any).
1925 */
1926 if (s_old && s_old->busy == file && s_old->async &&
1927 (s_old->async->cmd.flags & CMDF_WRITE))
1928 return -EBUSY;
1929
1930 ACCESS_ONCE(cfp->write_subdev) = s_new;
1931 return 0;
1932}
1933
1777static long comedi_unlocked_ioctl(struct file *file, unsigned int cmd, 1934static long comedi_unlocked_ioctl(struct file *file, unsigned int cmd,
1778 unsigned long arg) 1935 unsigned long arg)
1779{ 1936{
1780 const unsigned minor = iminor(file_inode(file)); 1937 unsigned minor = iminor(file_inode(file));
1781 struct comedi_device *dev = file->private_data; 1938 struct comedi_file *cfp = file->private_data;
1939 struct comedi_device *dev = cfp->dev;
1782 int rc; 1940 int rc;
1783 1941
1784 mutex_lock(&dev->mutex); 1942 mutex_lock(&dev->mutex);
@@ -1867,6 +2025,12 @@ static long comedi_unlocked_ioctl(struct file *file, unsigned int cmd,
1867 case COMEDI_POLL: 2025 case COMEDI_POLL:
1868 rc = do_poll_ioctl(dev, arg, file); 2026 rc = do_poll_ioctl(dev, arg, file);
1869 break; 2027 break;
2028 case COMEDI_SETRSUBD:
2029 rc = do_setrsubd_ioctl(dev, arg, file);
2030 break;
2031 case COMEDI_SETWSUBD:
2032 rc = do_setwsubd_ioctl(dev, arg, file);
2033 break;
1870 default: 2034 default:
1871 rc = -ENOTTY; 2035 rc = -ENOTTY;
1872 break; 2036 break;
@@ -1900,8 +2064,8 @@ static struct vm_operations_struct comedi_vm_ops = {
1900 2064
1901static int comedi_mmap(struct file *file, struct vm_area_struct *vma) 2065static int comedi_mmap(struct file *file, struct vm_area_struct *vma)
1902{ 2066{
1903 const unsigned minor = iminor(file_inode(file)); 2067 struct comedi_file *cfp = file->private_data;
1904 struct comedi_device *dev = file->private_data; 2068 struct comedi_device *dev = cfp->dev;
1905 struct comedi_subdevice *s; 2069 struct comedi_subdevice *s;
1906 struct comedi_async *async; 2070 struct comedi_async *async;
1907 struct comedi_buf_map *bm = NULL; 2071 struct comedi_buf_map *bm = NULL;
@@ -1927,9 +2091,9 @@ static int comedi_mmap(struct file *file, struct vm_area_struct *vma)
1927 } 2091 }
1928 2092
1929 if (vma->vm_flags & VM_WRITE) 2093 if (vma->vm_flags & VM_WRITE)
1930 s = comedi_write_subdevice(dev, minor); 2094 s = comedi_file_write_subdevice(file);
1931 else 2095 else
1932 s = comedi_read_subdevice(dev, minor); 2096 s = comedi_file_read_subdevice(file);
1933 if (!s) { 2097 if (!s) {
1934 retval = -EINVAL; 2098 retval = -EINVAL;
1935 goto done; 2099 goto done;
@@ -1992,8 +2156,8 @@ done:
1992static unsigned int comedi_poll(struct file *file, poll_table *wait) 2156static unsigned int comedi_poll(struct file *file, poll_table *wait)
1993{ 2157{
1994 unsigned int mask = 0; 2158 unsigned int mask = 0;
1995 const unsigned minor = iminor(file_inode(file)); 2159 struct comedi_file *cfp = file->private_data;
1996 struct comedi_device *dev = file->private_data; 2160 struct comedi_device *dev = cfp->dev;
1997 struct comedi_subdevice *s; 2161 struct comedi_subdevice *s;
1998 2162
1999 mutex_lock(&dev->mutex); 2163 mutex_lock(&dev->mutex);
@@ -2003,21 +2167,23 @@ static unsigned int comedi_poll(struct file *file, poll_table *wait)
2003 goto done; 2167 goto done;
2004 } 2168 }
2005 2169
2006 s = comedi_read_subdevice(dev, minor); 2170 s = comedi_file_read_subdevice(file);
2007 if (s && s->async) { 2171 if (s && s->async) {
2008 poll_wait(file, &s->async->wait_head, wait); 2172 poll_wait(file, &s->async->wait_head, wait);
2009 if (!s->busy || !comedi_is_subdevice_running(s) || 2173 if (!s->busy || !comedi_is_subdevice_running(s) ||
2174 (s->async->cmd.flags & CMDF_WRITE) ||
2010 comedi_buf_read_n_available(s) > 0) 2175 comedi_buf_read_n_available(s) > 0)
2011 mask |= POLLIN | POLLRDNORM; 2176 mask |= POLLIN | POLLRDNORM;
2012 } 2177 }
2013 2178
2014 s = comedi_write_subdevice(dev, minor); 2179 s = comedi_file_write_subdevice(file);
2015 if (s && s->async) { 2180 if (s && s->async) {
2016 unsigned int bps = bytes_per_sample(s); 2181 unsigned int bps = comedi_bytes_per_sample(s);
2017 2182
2018 poll_wait(file, &s->async->wait_head, wait); 2183 poll_wait(file, &s->async->wait_head, wait);
2019 comedi_buf_write_alloc(s, s->async->prealloc_bufsz); 2184 comedi_buf_write_alloc(s, s->async->prealloc_bufsz);
2020 if (!s->busy || !comedi_is_subdevice_running(s) || 2185 if (!s->busy || !comedi_is_subdevice_running(s) ||
2186 !(s->async->cmd.flags & CMDF_WRITE) ||
2021 comedi_buf_write_n_allocated(s) >= bps) 2187 comedi_buf_write_n_allocated(s) >= bps)
2022 mask |= POLLOUT | POLLWRNORM; 2188 mask |= POLLOUT | POLLWRNORM;
2023 } 2189 }
@@ -2034,8 +2200,8 @@ static ssize_t comedi_write(struct file *file, const char __user *buf,
2034 struct comedi_async *async; 2200 struct comedi_async *async;
2035 int n, m, count = 0, retval = 0; 2201 int n, m, count = 0, retval = 0;
2036 DECLARE_WAITQUEUE(wait, current); 2202 DECLARE_WAITQUEUE(wait, current);
2037 const unsigned minor = iminor(file_inode(file)); 2203 struct comedi_file *cfp = file->private_data;
2038 struct comedi_device *dev = file->private_data; 2204 struct comedi_device *dev = cfp->dev;
2039 bool on_wait_queue = false; 2205 bool on_wait_queue = false;
2040 bool attach_locked; 2206 bool attach_locked;
2041 unsigned int old_detach_count; 2207 unsigned int old_detach_count;
@@ -2051,7 +2217,7 @@ static ssize_t comedi_write(struct file *file, const char __user *buf,
2051 goto out; 2217 goto out;
2052 } 2218 }
2053 2219
2054 s = comedi_write_subdevice(dev, minor); 2220 s = comedi_file_write_subdevice(file);
2055 if (!s || !s->async) { 2221 if (!s || !s->async) {
2056 retval = -EIO; 2222 retval = -EIO;
2057 goto out; 2223 goto out;
@@ -2065,6 +2231,10 @@ static ssize_t comedi_write(struct file *file, const char __user *buf,
2065 retval = -EACCES; 2231 retval = -EACCES;
2066 goto out; 2232 goto out;
2067 } 2233 }
2234 if (!(async->cmd.flags & CMDF_WRITE)) {
2235 retval = -EINVAL;
2236 goto out;
2237 }
2068 2238
2069 add_wait_queue(&async->wait_head, &wait); 2239 add_wait_queue(&async->wait_head, &wait);
2070 on_wait_queue = true; 2240 on_wait_queue = true;
@@ -2099,7 +2269,7 @@ static ssize_t comedi_write(struct file *file, const char __user *buf,
2099 * meantime!), but check the subdevice pointer 2269 * meantime!), but check the subdevice pointer
2100 * as well just in case. 2270 * as well just in case.
2101 */ 2271 */
2102 new_s = comedi_write_subdevice(dev, minor); 2272 new_s = comedi_file_write_subdevice(file);
2103 if (dev->attached && 2273 if (dev->attached &&
2104 old_detach_count == dev->detach_count && 2274 old_detach_count == dev->detach_count &&
2105 s == new_s && new_s->async == async) 2275 s == new_s && new_s->async == async)
@@ -2136,6 +2306,10 @@ static ssize_t comedi_write(struct file *file, const char __user *buf,
2136 retval = -EACCES; 2306 retval = -EACCES;
2137 break; 2307 break;
2138 } 2308 }
2309 if (!(async->cmd.flags & CMDF_WRITE)) {
2310 retval = -EINVAL;
2311 break;
2312 }
2139 continue; 2313 continue;
2140 } 2314 }
2141 2315
@@ -2170,8 +2344,8 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
2170 struct comedi_async *async; 2344 struct comedi_async *async;
2171 int n, m, count = 0, retval = 0; 2345 int n, m, count = 0, retval = 0;
2172 DECLARE_WAITQUEUE(wait, current); 2346 DECLARE_WAITQUEUE(wait, current);
2173 const unsigned minor = iminor(file_inode(file)); 2347 struct comedi_file *cfp = file->private_data;
2174 struct comedi_device *dev = file->private_data; 2348 struct comedi_device *dev = cfp->dev;
2175 unsigned int old_detach_count; 2349 unsigned int old_detach_count;
2176 bool become_nonbusy = false; 2350 bool become_nonbusy = false;
2177 bool attach_locked; 2351 bool attach_locked;
@@ -2187,7 +2361,7 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
2187 goto out; 2361 goto out;
2188 } 2362 }
2189 2363
2190 s = comedi_read_subdevice(dev, minor); 2364 s = comedi_file_read_subdevice(file);
2191 if (!s || !s->async) { 2365 if (!s || !s->async) {
2192 retval = -EIO; 2366 retval = -EIO;
2193 goto out; 2367 goto out;
@@ -2200,6 +2374,10 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
2200 retval = -EACCES; 2374 retval = -EACCES;
2201 goto out; 2375 goto out;
2202 } 2376 }
2377 if (async->cmd.flags & CMDF_WRITE) {
2378 retval = -EINVAL;
2379 goto out;
2380 }
2203 2381
2204 add_wait_queue(&async->wait_head, &wait); 2382 add_wait_queue(&async->wait_head, &wait);
2205 while (nbytes > 0 && !retval) { 2383 while (nbytes > 0 && !retval) {
@@ -2239,6 +2417,10 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
2239 retval = -EACCES; 2417 retval = -EACCES;
2240 break; 2418 break;
2241 } 2419 }
2420 if (async->cmd.flags & CMDF_WRITE) {
2421 retval = -EINVAL;
2422 break;
2423 }
2242 continue; 2424 continue;
2243 } 2425 }
2244 m = copy_to_user(buf, async->prealloc_buf + 2426 m = copy_to_user(buf, async->prealloc_buf +
@@ -2276,7 +2458,7 @@ static ssize_t comedi_read(struct file *file, char __user *buf, size_t nbytes,
2276 * meantime!), but check the subdevice pointer as well just in 2458 * meantime!), but check the subdevice pointer as well just in
2277 * case. 2459 * case.
2278 */ 2460 */
2279 new_s = comedi_read_subdevice(dev, minor); 2461 new_s = comedi_file_read_subdevice(file);
2280 if (dev->attached && old_detach_count == dev->detach_count && 2462 if (dev->attached && old_detach_count == dev->detach_count &&
2281 s == new_s && new_s->async == async) { 2463 s == new_s && new_s->async == async) {
2282 if (become_nonbusy || comedi_buf_n_bytes_ready(s) == 0) 2464 if (become_nonbusy || comedi_buf_n_bytes_ready(s) == 0)
@@ -2294,6 +2476,7 @@ out:
2294static int comedi_open(struct inode *inode, struct file *file) 2476static int comedi_open(struct inode *inode, struct file *file)
2295{ 2477{
2296 const unsigned minor = iminor(inode); 2478 const unsigned minor = iminor(inode);
2479 struct comedi_file *cfp;
2297 struct comedi_device *dev = comedi_dev_get_from_minor(minor); 2480 struct comedi_device *dev = comedi_dev_get_from_minor(minor);
2298 int rc; 2481 int rc;
2299 2482
@@ -2302,6 +2485,12 @@ static int comedi_open(struct inode *inode, struct file *file)
2302 return -ENODEV; 2485 return -ENODEV;
2303 } 2486 }
2304 2487
2488 cfp = kzalloc(sizeof(*cfp), GFP_KERNEL);
2489 if (!cfp)
2490 return -ENOMEM;
2491
2492 cfp->dev = dev;
2493
2305 mutex_lock(&dev->mutex); 2494 mutex_lock(&dev->mutex);
2306 if (!dev->attached && !capable(CAP_NET_ADMIN)) { 2495 if (!dev->attached && !capable(CAP_NET_ADMIN)) {
2307 dev_dbg(dev->class_dev, "not attached and not CAP_NET_ADMIN\n"); 2496 dev_dbg(dev->class_dev, "not attached and not CAP_NET_ADMIN\n");
@@ -2323,26 +2512,31 @@ static int comedi_open(struct inode *inode, struct file *file)
2323 } 2512 }
2324 2513
2325 dev->use_count++; 2514 dev->use_count++;
2326 file->private_data = dev; 2515 file->private_data = cfp;
2516 comedi_file_reset(file);
2327 rc = 0; 2517 rc = 0;
2328 2518
2329out: 2519out:
2330 mutex_unlock(&dev->mutex); 2520 mutex_unlock(&dev->mutex);
2331 if (rc) 2521 if (rc) {
2332 comedi_dev_put(dev); 2522 comedi_dev_put(dev);
2523 kfree(cfp);
2524 }
2333 return rc; 2525 return rc;
2334} 2526}
2335 2527
2336static int comedi_fasync(int fd, struct file *file, int on) 2528static int comedi_fasync(int fd, struct file *file, int on)
2337{ 2529{
2338 struct comedi_device *dev = file->private_data; 2530 struct comedi_file *cfp = file->private_data;
2531 struct comedi_device *dev = cfp->dev;
2339 2532
2340 return fasync_helper(fd, file, on, &dev->async_queue); 2533 return fasync_helper(fd, file, on, &dev->async_queue);
2341} 2534}
2342 2535
2343static int comedi_close(struct inode *inode, struct file *file) 2536static int comedi_close(struct inode *inode, struct file *file)
2344{ 2537{
2345 struct comedi_device *dev = file->private_data; 2538 struct comedi_file *cfp = file->private_data;
2539 struct comedi_device *dev = cfp->dev;
2346 struct comedi_subdevice *s = NULL; 2540 struct comedi_subdevice *s = NULL;
2347 int i; 2541 int i;
2348 2542
@@ -2368,6 +2562,7 @@ static int comedi_close(struct inode *inode, struct file *file)
2368 2562
2369 mutex_unlock(&dev->mutex); 2563 mutex_unlock(&dev->mutex);
2370 comedi_dev_put(dev); 2564 comedi_dev_put(dev);
2565 kfree(cfp);
2371 2566
2372 return 0; 2567 return 0;
2373} 2568}
@@ -2395,14 +2590,14 @@ void comedi_event(struct comedi_device *dev, struct comedi_subdevice *s)
2395 if (!comedi_is_subdevice_running(s)) 2590 if (!comedi_is_subdevice_running(s))
2396 return; 2591 return;
2397 2592
2398 if (s-> 2593 if (s->async->events & COMEDI_CB_CANCEL_MASK)
2399 async->events & (COMEDI_CB_EOA | COMEDI_CB_ERROR |
2400 COMEDI_CB_OVERFLOW)) {
2401 runflags_mask |= SRF_RUNNING; 2594 runflags_mask |= SRF_RUNNING;
2402 } 2595
2403 /* remember if an error event has occurred, so an error 2596 /*
2404 * can be returned the next time the user does a read() */ 2597 * Remember if an error event has occurred, so an error
2405 if (s->async->events & (COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW)) { 2598 * can be returned the next time the user does a read().
2599 */
2600 if (s->async->events & COMEDI_CB_ERROR_MASK) {
2406 runflags_mask |= SRF_ERROR; 2601 runflags_mask |= SRF_ERROR;
2407 runflags |= SRF_ERROR; 2602 runflags |= SRF_ERROR;
2408 } 2603 }
diff --git a/drivers/staging/comedi/comedi_pci.c b/drivers/staging/comedi/comedi_pci.c
index aa0795a2660e..6ba59c977006 100644
--- a/drivers/staging/comedi/comedi_pci.c
+++ b/drivers/staging/comedi/comedi_pci.c
@@ -16,6 +16,7 @@
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 */ 17 */
18 18
19#include <linux/module.h>
19#include <linux/pci.h> 20#include <linux/pci.h>
20#include <linux/interrupt.h> 21#include <linux/interrupt.h>
21 22
@@ -168,3 +169,18 @@ void comedi_pci_driver_unregister(struct comedi_driver *comedi_driver,
168 comedi_driver_unregister(comedi_driver); 169 comedi_driver_unregister(comedi_driver);
169} 170}
170EXPORT_SYMBOL_GPL(comedi_pci_driver_unregister); 171EXPORT_SYMBOL_GPL(comedi_pci_driver_unregister);
172
173static int __init comedi_pci_init(void)
174{
175 return 0;
176}
177module_init(comedi_pci_init);
178
179static void __exit comedi_pci_exit(void)
180{
181}
182module_exit(comedi_pci_exit);
183
184MODULE_AUTHOR("http://www.comedi.org");
185MODULE_DESCRIPTION("Comedi PCI interface module");
186MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/comedi_pcmcia.c b/drivers/staging/comedi/comedi_pcmcia.c
index 9d49d5d01ad9..0529bae8e5ac 100644
--- a/drivers/staging/comedi/comedi_pcmcia.c
+++ b/drivers/staging/comedi/comedi_pcmcia.c
@@ -16,6 +16,7 @@
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 */ 17 */
18 18
19#include <linux/module.h>
19#include <linux/kernel.h> 20#include <linux/kernel.h>
20 21
21#include <pcmcia/cistpl.h> 22#include <pcmcia/cistpl.h>
@@ -154,3 +155,18 @@ void comedi_pcmcia_driver_unregister(struct comedi_driver *comedi_driver,
154 comedi_driver_unregister(comedi_driver); 155 comedi_driver_unregister(comedi_driver);
155} 156}
156EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_unregister); 157EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_unregister);
158
159static int __init comedi_pcmcia_init(void)
160{
161 return 0;
162}
163module_init(comedi_pcmcia_init);
164
165static void __exit comedi_pcmcia_exit(void)
166{
167}
168module_exit(comedi_pcmcia_exit);
169
170MODULE_AUTHOR("http://www.comedi.org");
171MODULE_DESCRIPTION("Comedi PCMCIA interface module");
172MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/comedi_usb.c b/drivers/staging/comedi/comedi_usb.c
index 13f18bef6091..0b862a64c049 100644
--- a/drivers/staging/comedi/comedi_usb.c
+++ b/drivers/staging/comedi/comedi_usb.c
@@ -16,6 +16,7 @@
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 */ 17 */
18 18
19#include <linux/module.h>
19#include <linux/usb.h> 20#include <linux/usb.h>
20 21
21#include "comedidev.h" 22#include "comedidev.h"
@@ -114,3 +115,18 @@ void comedi_usb_driver_unregister(struct comedi_driver *comedi_driver,
114 comedi_driver_unregister(comedi_driver); 115 comedi_driver_unregister(comedi_driver);
115} 116}
116EXPORT_SYMBOL_GPL(comedi_usb_driver_unregister); 117EXPORT_SYMBOL_GPL(comedi_usb_driver_unregister);
118
119static int __init comedi_usb_init(void)
120{
121 return 0;
122}
123module_init(comedi_usb_init);
124
125static void __exit comedi_usb_exit(void)
126{
127}
128module_exit(comedi_usb_exit);
129
130MODULE_AUTHOR("http://www.comedi.org");
131MODULE_DESCRIPTION("Comedi USB interface module");
132MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h
index 1b2bbd56f6ef..77be191988ca 100644
--- a/drivers/staging/comedi/comedidev.h
+++ b/drivers/staging/comedi/comedidev.h
@@ -121,6 +121,7 @@ struct comedi_buf_map {
121 * @buf_read_ptr: buffer position for reader 121 * @buf_read_ptr: buffer position for reader
122 * @cur_chan: current position in chanlist for scan (for those 122 * @cur_chan: current position in chanlist for scan (for those
123 * drivers that use it) 123 * drivers that use it)
124 * @scans_done: the number of scans completed (COMEDI_CB_EOS)
124 * @scan_progress: amount received or sent for current scan (in bytes) 125 * @scan_progress: amount received or sent for current scan (in bytes)
125 * @munge_chan: current position in chanlist for "munging" 126 * @munge_chan: current position in chanlist for "munging"
126 * @munge_count: "munge" count (in bytes, modulo 2**32) 127 * @munge_count: "munge" count (in bytes, modulo 2**32)
@@ -201,6 +202,7 @@ struct comedi_async {
201 unsigned int buf_write_ptr; 202 unsigned int buf_write_ptr;
202 unsigned int buf_read_ptr; 203 unsigned int buf_read_ptr;
203 unsigned int cur_chan; 204 unsigned int cur_chan;
205 unsigned int scans_done;
204 unsigned int scan_progress; 206 unsigned int scan_progress;
205 unsigned int munge_chan; 207 unsigned int munge_chan;
206 unsigned int munge_count; 208 unsigned int munge_count;
@@ -213,6 +215,28 @@ struct comedi_async {
213 unsigned int x); 215 unsigned int x);
214}; 216};
215 217
218/**
219 * comedi_async callback "events"
220 * @COMEDI_CB_EOS: end-of-scan
221 * @COMEDI_CB_EOA: end-of-acquisition/output
222 * @COMEDI_CB_BLOCK: data has arrived, wakes up read() / write()
223 * @COMEDI_CB_EOBUF: DEPRECATED: end of buffer
224 * @COMEDI_CB_ERROR: card error during acquisition
225 * @COMEDI_CB_OVERFLOW: buffer overflow/underflow
226 *
227 * @COMEDI_CB_ERROR_MASK: events that indicate an error has occurred
228 * @COMEDI_CB_CANCEL_MASK: events that will cancel an async command
229 */
230#define COMEDI_CB_EOS (1 << 0)
231#define COMEDI_CB_EOA (1 << 1)
232#define COMEDI_CB_BLOCK (1 << 2)
233#define COMEDI_CB_EOBUF (1 << 3)
234#define COMEDI_CB_ERROR (1 << 4)
235#define COMEDI_CB_OVERFLOW (1 << 5)
236
237#define COMEDI_CB_ERROR_MASK (COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW)
238#define COMEDI_CB_CANCEL_MASK (COMEDI_CB_EOA | COMEDI_CB_ERROR_MASK)
239
216struct comedi_driver { 240struct comedi_driver {
217 struct comedi_driver *next; 241 struct comedi_driver *next;
218 242
@@ -391,12 +415,61 @@ static inline unsigned int comedi_offset_munge(struct comedi_subdevice *s,
391 return val ^ s->maxdata ^ (s->maxdata >> 1); 415 return val ^ s->maxdata ^ (s->maxdata >> 1);
392} 416}
393 417
394static inline unsigned int bytes_per_sample(const struct comedi_subdevice *subd) 418/**
419 * comedi_bytes_per_sample - determine subdevice sample size
420 * @s: comedi_subdevice struct
421 *
422 * The sample size will be 4 (sizeof int) or 2 (sizeof short) depending on
423 * whether the SDF_LSAMPL subdevice flag is set or not.
424 *
425 * Returns the subdevice sample size.
426 */
427static inline unsigned int comedi_bytes_per_sample(struct comedi_subdevice *s)
428{
429 return s->subdev_flags & SDF_LSAMPL ? sizeof(int) : sizeof(short);
430}
431
432/**
433 * comedi_sample_shift - determine log2 of subdevice sample size
434 * @s: comedi_subdevice struct
435 *
436 * The sample size will be 4 (sizeof int) or 2 (sizeof short) depending on
437 * whether the SDF_LSAMPL subdevice flag is set or not. The log2 of the
438 * sample size will be 2 or 1 and can be used as the right operand of a
439 * bit-shift operator to multiply or divide something by the sample size.
440 *
441 * Returns log2 of the subdevice sample size.
442 */
443static inline unsigned int comedi_sample_shift(struct comedi_subdevice *s)
395{ 444{
396 if (subd->subdev_flags & SDF_LSAMPL) 445 return s->subdev_flags & SDF_LSAMPL ? 2 : 1;
397 return sizeof(unsigned int); 446}
398 447
399 return sizeof(short); 448/**
449 * comedi_bytes_to_samples - converts a number of bytes to a number of samples
450 * @s: comedi_subdevice struct
451 * @nbytes: number of bytes
452 *
453 * Returns the number of bytes divided by the subdevice sample size.
454 */
455static inline unsigned int comedi_bytes_to_samples(struct comedi_subdevice *s,
456 unsigned int nbytes)
457{
458 return nbytes >> comedi_sample_shift(s);
459}
460
461/**
462 * comedi_samples_to_bytes - converts a number of samples to a number of bytes
463 * @s: comedi_subdevice struct
464 * @nsamples: number of samples
465 *
466 * Returns the number of samples multiplied by the subdevice sample size.
467 * Does not check for arithmetic overflow.
468 */
469static inline unsigned int comedi_samples_to_bytes(struct comedi_subdevice *s,
470 unsigned int nsamples)
471{
472 return nsamples << comedi_sample_shift(s);
400} 473}
401 474
402/* 475/*
@@ -419,18 +492,10 @@ unsigned int comedi_buf_read_n_available(struct comedi_subdevice *s);
419unsigned int comedi_buf_read_alloc(struct comedi_subdevice *s, unsigned int n); 492unsigned int comedi_buf_read_alloc(struct comedi_subdevice *s, unsigned int n);
420unsigned int comedi_buf_read_free(struct comedi_subdevice *s, unsigned int n); 493unsigned int comedi_buf_read_free(struct comedi_subdevice *s, unsigned int n);
421 494
422int comedi_buf_put(struct comedi_subdevice *s, unsigned short x); 495unsigned int comedi_buf_write_samples(struct comedi_subdevice *s,
423int comedi_buf_get(struct comedi_subdevice *s, unsigned short *x); 496 const void *data, unsigned int nsamples);
424 497unsigned int comedi_buf_read_samples(struct comedi_subdevice *s,
425void comedi_buf_memcpy_to(struct comedi_subdevice *s, unsigned int offset, 498 void *data, unsigned int nsamples);
426 const void *source, unsigned int num_bytes);
427void comedi_buf_memcpy_from(struct comedi_subdevice *s, unsigned int offset,
428 void *destination, unsigned int num_bytes);
429unsigned int comedi_write_array_to_buffer(struct comedi_subdevice *s,
430 const void *data,
431 unsigned int num_bytes);
432unsigned int comedi_read_array_from_buffer(struct comedi_subdevice *s,
433 void *data, unsigned int num_bytes);
434 499
435/* drivers.c - general comedi driver functions */ 500/* drivers.c - general comedi driver functions */
436 501
@@ -451,6 +516,10 @@ int comedi_dio_insn_config(struct comedi_device *, struct comedi_subdevice *,
451unsigned int comedi_dio_update_state(struct comedi_subdevice *, 516unsigned int comedi_dio_update_state(struct comedi_subdevice *,
452 unsigned int *data); 517 unsigned int *data);
453unsigned int comedi_bytes_per_scan(struct comedi_subdevice *s); 518unsigned int comedi_bytes_per_scan(struct comedi_subdevice *s);
519unsigned int comedi_nscans_left(struct comedi_subdevice *s,
520 unsigned int nscans);
521unsigned int comedi_nsamples_left(struct comedi_subdevice *s,
522 unsigned int nsamples);
454void comedi_inc_scan_progress(struct comedi_subdevice *s, 523void comedi_inc_scan_progress(struct comedi_subdevice *s,
455 unsigned int num_bytes); 524 unsigned int num_bytes);
456 525
@@ -493,8 +562,6 @@ void comedi_driver_unregister(struct comedi_driver *);
493 module_driver(__comedi_driver, comedi_driver_register, \ 562 module_driver(__comedi_driver, comedi_driver_register, \
494 comedi_driver_unregister) 563 comedi_driver_unregister)
495 564
496#ifdef CONFIG_COMEDI_PCI_DRIVERS
497
498/* comedi_pci.c - comedi PCI driver specific functions */ 565/* comedi_pci.c - comedi PCI driver specific functions */
499 566
500/* 567/*
@@ -538,36 +605,6 @@ void comedi_pci_driver_unregister(struct comedi_driver *, struct pci_driver *);
538 module_driver(__comedi_driver, comedi_pci_driver_register, \ 605 module_driver(__comedi_driver, comedi_pci_driver_register, \
539 comedi_pci_driver_unregister, &(__pci_driver)) 606 comedi_pci_driver_unregister, &(__pci_driver))
540 607
541#else
542
543/*
544 * Some of the comedi mixed ISA/PCI drivers call the PCI specific
545 * functions. Provide some dummy functions if CONFIG_COMEDI_PCI_DRIVERS
546 * is not enabled.
547 */
548
549static inline struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev)
550{
551 return NULL;
552}
553
554static inline int comedi_pci_enable(struct comedi_device *dev)
555{
556 return -ENOSYS;
557}
558
559static inline void comedi_pci_disable(struct comedi_device *dev)
560{
561}
562
563static inline void comedi_pci_detach(struct comedi_device *dev)
564{
565}
566
567#endif /* CONFIG_COMEDI_PCI_DRIVERS */
568
569#ifdef CONFIG_COMEDI_PCMCIA_DRIVERS
570
571/* comedi_pcmcia.c - comedi PCMCIA driver specific functions */ 608/* comedi_pcmcia.c - comedi PCMCIA driver specific functions */
572 609
573struct pcmcia_driver; 610struct pcmcia_driver;
@@ -601,10 +638,6 @@ void comedi_pcmcia_driver_unregister(struct comedi_driver *,
601 module_driver(__comedi_driver, comedi_pcmcia_driver_register, \ 638 module_driver(__comedi_driver, comedi_pcmcia_driver_register, \
602 comedi_pcmcia_driver_unregister, &(__pcmcia_driver)) 639 comedi_pcmcia_driver_unregister, &(__pcmcia_driver))
603 640
604#endif /* CONFIG_COMEDI_PCMCIA_DRIVERS */
605
606#ifdef CONFIG_COMEDI_USB_DRIVERS
607
608/* comedi_usb.c - comedi USB driver specific functions */ 641/* comedi_usb.c - comedi USB driver specific functions */
609 642
610struct usb_driver; 643struct usb_driver;
@@ -634,6 +667,4 @@ void comedi_usb_driver_unregister(struct comedi_driver *, struct usb_driver *);
634 module_driver(__comedi_driver, comedi_usb_driver_register, \ 667 module_driver(__comedi_driver, comedi_usb_driver_register, \
635 comedi_usb_driver_unregister, &(__usb_driver)) 668 comedi_usb_driver_unregister, &(__usb_driver))
636 669
637#endif /* CONFIG_COMEDI_USB_DRIVERS */
638
639#endif /* _COMEDIDEV_H */ 670#endif /* _COMEDIDEV_H */
diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
index 3e5bccbc9c39..61802d7947ae 100644
--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -109,6 +109,10 @@ int comedi_alloc_subdev_readback(struct comedi_subdevice *s)
109 s->readback = kcalloc(s->n_chan, sizeof(*s->readback), GFP_KERNEL); 109 s->readback = kcalloc(s->n_chan, sizeof(*s->readback), GFP_KERNEL);
110 if (!s->readback) 110 if (!s->readback)
111 return -ENOMEM; 111 return -ENOMEM;
112
113 if (!s->insn_read)
114 s->insn_read = comedi_readback_insn_read;
115
112 return 0; 116 return 0;
113} 117}
114EXPORT_SYMBOL_GPL(comedi_alloc_subdev_readback); 118EXPORT_SYMBOL_GPL(comedi_alloc_subdev_readback);
@@ -316,19 +320,91 @@ unsigned int comedi_bytes_per_scan(struct comedi_subdevice *s)
316 case COMEDI_SUBD_DI: 320 case COMEDI_SUBD_DI:
317 case COMEDI_SUBD_DO: 321 case COMEDI_SUBD_DO:
318 case COMEDI_SUBD_DIO: 322 case COMEDI_SUBD_DIO:
319 bits_per_sample = 8 * bytes_per_sample(s); 323 bits_per_sample = 8 * comedi_bytes_per_sample(s);
320 num_samples = (cmd->chanlist_len + bits_per_sample - 1) / 324 num_samples = DIV_ROUND_UP(cmd->scan_end_arg, bits_per_sample);
321 bits_per_sample;
322 break; 325 break;
323 default: 326 default:
324 num_samples = cmd->chanlist_len; 327 num_samples = cmd->scan_end_arg;
325 break; 328 break;
326 } 329 }
327 return num_samples * bytes_per_sample(s); 330 return comedi_samples_to_bytes(s, num_samples);
328} 331}
329EXPORT_SYMBOL_GPL(comedi_bytes_per_scan); 332EXPORT_SYMBOL_GPL(comedi_bytes_per_scan);
330 333
331/** 334/**
335 * comedi_nscans_left - return the number of scans left in the command
336 * @s: comedi_subdevice struct
337 * @nscans: the expected number of scans
338 *
339 * If nscans is 0, the number of scans available in the async buffer will be
340 * used. Otherwise the expected number of scans will be used.
341 *
342 * If the async command has a stop_src of TRIG_COUNT, the nscans will be
343 * checked against the number of scans left in the command.
344 *
345 * The return value will then be either the expected number of scans or the
346 * number of scans remaining in the command.
347 */
348unsigned int comedi_nscans_left(struct comedi_subdevice *s,
349 unsigned int nscans)
350{
351 struct comedi_async *async = s->async;
352 struct comedi_cmd *cmd = &async->cmd;
353
354 if (nscans == 0) {
355 unsigned int nbytes = comedi_buf_read_n_available(s);
356
357 nscans = nbytes / comedi_bytes_per_scan(s);
358 }
359
360 if (cmd->stop_src == TRIG_COUNT) {
361 unsigned int scans_left = 0;
362
363 if (async->scans_done < cmd->stop_arg)
364 scans_left = cmd->stop_arg - async->scans_done;
365
366 if (nscans > scans_left)
367 nscans = scans_left;
368 }
369 return nscans;
370}
371EXPORT_SYMBOL_GPL(comedi_nscans_left);
372
373/**
374 * comedi_nsamples_left - return the number of samples left in the command
375 * @s: comedi_subdevice struct
376 * @nsamples: the expected number of samples
377 *
378 * Returns the expected number of samples of the number of samples remaining
379 * in the command.
380 */
381unsigned int comedi_nsamples_left(struct comedi_subdevice *s,
382 unsigned int nsamples)
383{
384 struct comedi_async *async = s->async;
385 struct comedi_cmd *cmd = &async->cmd;
386
387 if (cmd->stop_src == TRIG_COUNT) {
388 /* +1 to force comedi_nscans_left() to return the scans left */
389 unsigned int nscans = (nsamples / cmd->scan_end_arg) + 1;
390 unsigned int scans_left = comedi_nscans_left(s, nscans);
391 unsigned int scan_pos =
392 comedi_bytes_to_samples(s, async->scan_progress);
393 unsigned long long samples_left = 0;
394
395 if (scans_left) {
396 samples_left = ((unsigned long long)scans_left *
397 cmd->scan_end_arg) - scan_pos;
398 }
399
400 if (samples_left < nsamples)
401 nsamples = samples_left;
402 }
403 return nsamples;
404}
405EXPORT_SYMBOL_GPL(comedi_nsamples_left);
406
407/**
332 * comedi_inc_scan_progress - update scan progress in asynchronous command 408 * comedi_inc_scan_progress - update scan progress in asynchronous command
333 * @s: comedi_subdevice struct 409 * @s: comedi_subdevice struct
334 * @num_bytes: amount of data in bytes to increment scan progress 410 * @num_bytes: amount of data in bytes to increment scan progress
@@ -342,10 +418,24 @@ void comedi_inc_scan_progress(struct comedi_subdevice *s,
342 unsigned int num_bytes) 418 unsigned int num_bytes)
343{ 419{
344 struct comedi_async *async = s->async; 420 struct comedi_async *async = s->async;
421 struct comedi_cmd *cmd = &async->cmd;
345 unsigned int scan_length = comedi_bytes_per_scan(s); 422 unsigned int scan_length = comedi_bytes_per_scan(s);
346 423
424 /* track the 'cur_chan' for non-SDF_PACKED subdevices */
425 if (!(s->subdev_flags & SDF_PACKED)) {
426 async->cur_chan += comedi_bytes_to_samples(s, num_bytes);
427 async->cur_chan %= cmd->chanlist_len;
428 }
429
347 async->scan_progress += num_bytes; 430 async->scan_progress += num_bytes;
348 if (async->scan_progress >= scan_length) { 431 if (async->scan_progress >= scan_length) {
432 unsigned int nscans = async->scan_progress / scan_length;
433
434 if (async->scans_done < (UINT_MAX - nscans))
435 async->scans_done += nscans;
436 else
437 async->scans_done = UINT_MAX;
438
349 async->scan_progress %= scan_length; 439 async->scan_progress %= scan_length;
350 async->events |= COMEDI_CB_EOS; 440 async->events |= COMEDI_CB_EOS;
351 } 441 }
@@ -376,7 +466,7 @@ unsigned int comedi_handle_events(struct comedi_device *dev,
376 if (events == 0) 466 if (events == 0)
377 return events; 467 return events;
378 468
379 if (events & (COMEDI_CB_EOA | COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW)) 469 if (events & COMEDI_CB_CANCEL_MASK)
380 s->cancel(dev, s); 470 s->cancel(dev, s);
381 471
382 comedi_event(dev, s); 472 comedi_event(dev, s);
diff --git a/drivers/staging/comedi/drivers/Makefile b/drivers/staging/comedi/drivers/Makefile
index 6bc9ef3b25b3..84fdf20ca986 100644
--- a/drivers/staging/comedi/drivers/Makefile
+++ b/drivers/staging/comedi/drivers/Makefile
@@ -60,7 +60,6 @@ obj-$(CONFIG_COMEDI_S526) += s526.o
60# Comedi PCI drivers 60# Comedi PCI drivers
61obj-$(CONFIG_COMEDI_8255_PCI) += 8255_pci.o 61obj-$(CONFIG_COMEDI_8255_PCI) += 8255_pci.o
62obj-$(CONFIG_COMEDI_ADDI_WATCHDOG) += addi_watchdog.o 62obj-$(CONFIG_COMEDI_ADDI_WATCHDOG) += addi_watchdog.o
63obj-$(CONFIG_COMEDI_ADDI_APCI_035) += addi_apci_035.o
64obj-$(CONFIG_COMEDI_ADDI_APCI_1032) += addi_apci_1032.o 63obj-$(CONFIG_COMEDI_ADDI_APCI_1032) += addi_apci_1032.o
65obj-$(CONFIG_COMEDI_ADDI_APCI_1500) += addi_apci_1500.o 64obj-$(CONFIG_COMEDI_ADDI_APCI_1500) += addi_apci_1500.o
66obj-$(CONFIG_COMEDI_ADDI_APCI_1516) += addi_apci_1516.o 65obj-$(CONFIG_COMEDI_ADDI_APCI_1516) += addi_apci_1516.o
diff --git a/drivers/staging/comedi/drivers/addi-data/addi_common.c b/drivers/staging/comedi/drivers/addi-data/addi_common.c
deleted file mode 100644
index 2e7fb218340f..000000000000
--- a/drivers/staging/comedi/drivers/addi-data/addi_common.c
+++ /dev/null
@@ -1,274 +0,0 @@
1/**
2@verbatim
3
4Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
5
6 ADDI-DATA GmbH
7 Dieselstrasse 3
8 D-77833 Ottersweier
9 Tel: +19(0)7223/9493-0
10 Fax: +49(0)7223/9493-92
11 http://www.addi-data.com
12 info@addi-data.com
13
14This program is free software; you can redistribute it and/or modify it under
15the terms of the GNU General Public License as published by the Free Software
16Foundation; either version 2 of the License, or (at your option) any later
17version.
18
19This program is distributed in the hope that it will be useful, but WITHOUT ANY
20WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21PARTICULAR PURPOSE. See the GNU General Public License for more details.
22
23@endverbatim
24*/
25/*
26
27 +-----------------------------------------------------------------------+
28 | (C) ADDI-DATA GmbH Dieselstrasse 3 D-77833 Ottersweier |
29 +-----------------------------------------------------------------------+
30 | Tel : +49 (0) 7223/9493-0 | email : info@addi-data.com |
31 | Fax : +49 (0) 7223/9493-92 | Internet : http://www.addi-data.com |
32 +-----------------------------------------------------------------------+
33 | Project : ADDI DATA | Compiler : GCC |
34 | Modulname : addi_common.c | Version : 2.96 |
35 +-------------------------------+---------------------------------------+
36 | Author : | Date : |
37 +-----------------------------------------------------------------------+
38 | Description : ADDI COMMON Main Module |
39 +-----------------------------------------------------------------------+
40*/
41
42static int i_ADDIDATA_InsnReadEeprom(struct comedi_device *dev,
43 struct comedi_subdevice *s,
44 struct comedi_insn *insn,
45 unsigned int *data)
46{
47 const struct addi_board *this_board = dev->board_ptr;
48 struct addi_private *devpriv = dev->private;
49 unsigned short w_Address = CR_CHAN(insn->chanspec);
50 unsigned short w_Data;
51
52 w_Data = addi_eeprom_readw(devpriv->i_IobaseAmcc,
53 this_board->pc_EepromChip, 2 * w_Address);
54 data[0] = w_Data;
55
56 return insn->n;
57}
58
59static irqreturn_t v_ADDI_Interrupt(int irq, void *d)
60{
61 struct comedi_device *dev = d;
62 const struct addi_board *this_board = dev->board_ptr;
63
64 this_board->interrupt(irq, d);
65 return IRQ_RETVAL(1);
66}
67
68static int i_ADDI_Reset(struct comedi_device *dev)
69{
70 const struct addi_board *this_board = dev->board_ptr;
71
72 this_board->reset(dev);
73 return 0;
74}
75
76static int addi_auto_attach(struct comedi_device *dev,
77 unsigned long context_unused)
78{
79 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
80 const struct addi_board *this_board = dev->board_ptr;
81 struct addi_private *devpriv;
82 struct comedi_subdevice *s;
83 int ret, n_subdevices;
84 unsigned int dw_Dummy;
85
86 dev->board_name = this_board->pc_DriverName;
87
88 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
89 if (!devpriv)
90 return -ENOMEM;
91
92 ret = comedi_pci_enable(dev);
93 if (ret)
94 return ret;
95
96 if (this_board->i_IorangeBase1)
97 dev->iobase = pci_resource_start(pcidev, 1);
98 else
99 dev->iobase = pci_resource_start(pcidev, 0);
100
101 devpriv->iobase = dev->iobase;
102 devpriv->i_IobaseAmcc = pci_resource_start(pcidev, 0);
103 devpriv->i_IobaseAddon = pci_resource_start(pcidev, 2);
104 devpriv->i_IobaseReserved = pci_resource_start(pcidev, 3);
105
106 /* Initialize parameters that can be overridden in EEPROM */
107 devpriv->s_EeParameters.i_NbrAiChannel = this_board->i_NbrAiChannel;
108 devpriv->s_EeParameters.i_NbrAoChannel = this_board->i_NbrAoChannel;
109 devpriv->s_EeParameters.i_AiMaxdata = this_board->i_AiMaxdata;
110 devpriv->s_EeParameters.i_AoMaxdata = this_board->i_AoMaxdata;
111 devpriv->s_EeParameters.i_NbrDiChannel = this_board->i_NbrDiChannel;
112 devpriv->s_EeParameters.i_NbrDoChannel = this_board->i_NbrDoChannel;
113 devpriv->s_EeParameters.i_DoMaxdata = this_board->i_DoMaxdata;
114 devpriv->s_EeParameters.i_Timer = this_board->i_Timer;
115 devpriv->s_EeParameters.ui_MinAcquisitiontimeNs =
116 this_board->ui_MinAcquisitiontimeNs;
117 devpriv->s_EeParameters.ui_MinDelaytimeNs =
118 this_board->ui_MinDelaytimeNs;
119
120 /* ## */
121
122 if (pcidev->irq > 0) {
123 ret = request_irq(pcidev->irq, v_ADDI_Interrupt, IRQF_SHARED,
124 dev->board_name, dev);
125 if (ret == 0)
126 dev->irq = pcidev->irq;
127 }
128
129 /* Read eepeom and fill addi_board Structure */
130
131 if (this_board->i_PCIEeprom) {
132 if (!(strcmp(this_board->pc_EepromChip, "S5920"))) {
133 /* Set 3 wait stait */
134 if (!(strcmp(dev->board_name, "apci035")))
135 outl(0x80808082, devpriv->i_IobaseAmcc + 0x60);
136 else
137 outl(0x83838383, devpriv->i_IobaseAmcc + 0x60);
138
139 /* Enable the interrupt for the controller */
140 dw_Dummy = inl(devpriv->i_IobaseAmcc + 0x38);
141 outl(dw_Dummy | 0x2000, devpriv->i_IobaseAmcc + 0x38);
142 }
143 addi_eeprom_read_info(dev, pci_resource_start(pcidev, 0));
144 }
145
146 n_subdevices = 7;
147 ret = comedi_alloc_subdevices(dev, n_subdevices);
148 if (ret)
149 return ret;
150
151 /* Allocate and Initialise AI Subdevice Structures */
152 s = &dev->subdevices[0];
153 if ((devpriv->s_EeParameters.i_NbrAiChannel)
154 || (this_board->i_NbrAiChannelDiff)) {
155 dev->read_subdev = s;
156 s->type = COMEDI_SUBD_AI;
157 s->subdev_flags =
158 SDF_READABLE | SDF_COMMON | SDF_GROUND
159 | SDF_DIFF;
160 if (devpriv->s_EeParameters.i_NbrAiChannel)
161 s->n_chan = devpriv->s_EeParameters.i_NbrAiChannel;
162 else
163 s->n_chan = this_board->i_NbrAiChannelDiff;
164 s->maxdata = devpriv->s_EeParameters.i_AiMaxdata;
165 s->len_chanlist = this_board->i_AiChannelList;
166 s->range_table = this_board->pr_AiRangelist;
167
168 s->insn_config = this_board->ai_config;
169 s->insn_read = this_board->ai_read;
170 s->insn_write = this_board->ai_write;
171 s->insn_bits = this_board->ai_bits;
172 s->do_cmdtest = this_board->ai_cmdtest;
173 s->do_cmd = this_board->ai_cmd;
174 s->cancel = this_board->ai_cancel;
175
176 } else {
177 s->type = COMEDI_SUBD_UNUSED;
178 }
179
180 /* Allocate and Initialise AO Subdevice Structures */
181 s = &dev->subdevices[1];
182 if (devpriv->s_EeParameters.i_NbrAoChannel) {
183 s->type = COMEDI_SUBD_AO;
184 s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON;
185 s->n_chan = devpriv->s_EeParameters.i_NbrAoChannel;
186 s->maxdata = devpriv->s_EeParameters.i_AoMaxdata;
187 s->len_chanlist =
188 devpriv->s_EeParameters.i_NbrAoChannel;
189 s->insn_write = this_board->ao_write;
190 } else {
191 s->type = COMEDI_SUBD_UNUSED;
192 }
193 /* Allocate and Initialise DI Subdevice Structures */
194 s = &dev->subdevices[2];
195 if (devpriv->s_EeParameters.i_NbrDiChannel) {
196 s->type = COMEDI_SUBD_DI;
197 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON;
198 s->n_chan = devpriv->s_EeParameters.i_NbrDiChannel;
199 s->maxdata = 1;
200 s->len_chanlist =
201 devpriv->s_EeParameters.i_NbrDiChannel;
202 s->range_table = &range_digital;
203 s->insn_config = this_board->di_config;
204 s->insn_read = this_board->di_read;
205 s->insn_write = this_board->di_write;
206 s->insn_bits = this_board->di_bits;
207 } else {
208 s->type = COMEDI_SUBD_UNUSED;
209 }
210 /* Allocate and Initialise DO Subdevice Structures */
211 s = &dev->subdevices[3];
212 if (devpriv->s_EeParameters.i_NbrDoChannel) {
213 s->type = COMEDI_SUBD_DO;
214 s->subdev_flags =
215 SDF_READABLE | SDF_WRITEABLE | SDF_GROUND | SDF_COMMON;
216 s->n_chan = devpriv->s_EeParameters.i_NbrDoChannel;
217 s->maxdata = devpriv->s_EeParameters.i_DoMaxdata;
218 s->len_chanlist =
219 devpriv->s_EeParameters.i_NbrDoChannel;
220 s->range_table = &range_digital;
221
222 /* insn_config - for digital output memory */
223 s->insn_config = this_board->do_config;
224 s->insn_write = this_board->do_write;
225 s->insn_bits = this_board->do_bits;
226 s->insn_read = this_board->do_read;
227 } else {
228 s->type = COMEDI_SUBD_UNUSED;
229 }
230
231 /* Allocate and Initialise Timer Subdevice Structures */
232 s = &dev->subdevices[4];
233 if (devpriv->s_EeParameters.i_Timer) {
234 s->type = COMEDI_SUBD_TIMER;
235 s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON;
236 s->n_chan = 1;
237 s->maxdata = 0;
238 s->len_chanlist = 1;
239 s->range_table = &range_digital;
240
241 s->insn_write = this_board->timer_write;
242 s->insn_read = this_board->timer_read;
243 s->insn_config = this_board->timer_config;
244 s->insn_bits = this_board->timer_bits;
245 } else {
246 s->type = COMEDI_SUBD_UNUSED;
247 }
248
249 /* Allocate and Initialise TTL */
250 s = &dev->subdevices[5];
251 s->type = COMEDI_SUBD_UNUSED;
252
253 /* EEPROM */
254 s = &dev->subdevices[6];
255 if (this_board->i_PCIEeprom) {
256 s->type = COMEDI_SUBD_MEMORY;
257 s->subdev_flags = SDF_READABLE | SDF_INTERNAL;
258 s->n_chan = 256;
259 s->maxdata = 0xffff;
260 s->insn_read = i_ADDIDATA_InsnReadEeprom;
261 } else {
262 s->type = COMEDI_SUBD_UNUSED;
263 }
264
265 i_ADDI_Reset(dev);
266 return 0;
267}
268
269static void i_ADDI_Detach(struct comedi_device *dev)
270{
271 if (dev->iobase)
272 i_ADDI_Reset(dev);
273 comedi_pci_detach(dev);
274}
diff --git a/drivers/staging/comedi/drivers/addi-data/addi_common.h b/drivers/staging/comedi/drivers/addi-data/addi_common.h
deleted file mode 100644
index e2a3ffeee5cf..000000000000
--- a/drivers/staging/comedi/drivers/addi-data/addi_common.h
+++ /dev/null
@@ -1,144 +0,0 @@
1/*
2 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
3 *
4 * ADDI-DATA GmbH
5 * Dieselstrasse 3
6 * D-77833 Ottersweier
7 * Tel: +19(0)7223/9493-0
8 * Fax: +49(0)7223/9493-92
9 * http://www.addi-data.com
10 * info@addi-data.com
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the Free
14 * Software Foundation; either version 2 of the License, or (at your option)
15 * any later version.
16 */
17
18#include <linux/sched.h>
19#include <linux/interrupt.h>
20
21struct addi_board {
22 const char *pc_DriverName; /* driver name */
23 int i_IorangeBase1;
24 int i_PCIEeprom; /* eeprom present or not */
25 char *pc_EepromChip; /* type of chip */
26 int i_NbrAiChannel; /* num of A/D chans */
27 int i_NbrAiChannelDiff; /* num of A/D chans in diff mode */
28 int i_AiChannelList; /* len of chanlist */
29 int i_NbrAoChannel; /* num of D/A chans */
30 int i_AiMaxdata; /* resolution of A/D */
31 int i_AoMaxdata; /* resolution of D/A */
32 const struct comedi_lrange *pr_AiRangelist; /* rangelist for A/D */
33
34 int i_NbrDiChannel; /* Number of DI channels */
35 int i_NbrDoChannel; /* Number of DO channels */
36 int i_DoMaxdata; /* data to set all channels high */
37
38 int i_Timer; /* timer subdevice present or not */
39 unsigned int ui_MinAcquisitiontimeNs; /* Minimum Acquisition in Nano secs */
40 unsigned int ui_MinDelaytimeNs; /* Minimum Delay in Nano secs */
41
42 /* interrupt and reset */
43 void (*interrupt)(int irq, void *d);
44 int (*reset)(struct comedi_device *);
45
46 /* Subdevice functions */
47
48 /* ANALOG INPUT */
49 int (*ai_config)(struct comedi_device *, struct comedi_subdevice *,
50 struct comedi_insn *, unsigned int *);
51 int (*ai_read)(struct comedi_device *, struct comedi_subdevice *,
52 struct comedi_insn *, unsigned int *);
53 int (*ai_write)(struct comedi_device *, struct comedi_subdevice *,
54 struct comedi_insn *, unsigned int *);
55 int (*ai_bits)(struct comedi_device *, struct comedi_subdevice *,
56 struct comedi_insn *, unsigned int *);
57 int (*ai_cmdtest)(struct comedi_device *, struct comedi_subdevice *,
58 struct comedi_cmd *);
59 int (*ai_cmd)(struct comedi_device *, struct comedi_subdevice *);
60 int (*ai_cancel)(struct comedi_device *, struct comedi_subdevice *);
61
62 /* Analog Output */
63 int (*ao_write)(struct comedi_device *, struct comedi_subdevice *,
64 struct comedi_insn *, unsigned int *);
65
66 /* Digital Input */
67 int (*di_config)(struct comedi_device *, struct comedi_subdevice *,
68 struct comedi_insn *, unsigned int *);
69 int (*di_read)(struct comedi_device *, struct comedi_subdevice *,
70 struct comedi_insn *, unsigned int *);
71 int (*di_write)(struct comedi_device *, struct comedi_subdevice *,
72 struct comedi_insn *, unsigned int *);
73 int (*di_bits)(struct comedi_device *, struct comedi_subdevice *,
74 struct comedi_insn *, unsigned int *);
75
76 /* Digital Output */
77 int (*do_config)(struct comedi_device *, struct comedi_subdevice *,
78 struct comedi_insn *, unsigned int *);
79 int (*do_write)(struct comedi_device *, struct comedi_subdevice *,
80 struct comedi_insn *, unsigned int *);
81 int (*do_bits)(struct comedi_device *, struct comedi_subdevice *,
82 struct comedi_insn *, unsigned int *);
83 int (*do_read)(struct comedi_device *, struct comedi_subdevice *,
84 struct comedi_insn *, unsigned int *);
85
86 /* TIMER */
87 int (*timer_config)(struct comedi_device *, struct comedi_subdevice *,
88 struct comedi_insn *, unsigned int *);
89 int (*timer_write)(struct comedi_device *, struct comedi_subdevice *,
90 struct comedi_insn *, unsigned int *);
91 int (*timer_read)(struct comedi_device *, struct comedi_subdevice *,
92 struct comedi_insn *, unsigned int *);
93 int (*timer_bits)(struct comedi_device *, struct comedi_subdevice *,
94 struct comedi_insn *, unsigned int *);
95};
96
97struct addi_private {
98 int iobase;
99 int i_IobaseAmcc; /* base+size for AMCC chip */
100 int i_IobaseAddon; /* addon base address */
101 int i_IobaseReserved;
102 unsigned int ui_AiActualScan; /* how many scans we finished */
103 unsigned int ui_AiNbrofChannels; /* how many channels is measured */
104 unsigned int ui_AiChannelList[32]; /* actual chanlist */
105 unsigned int ui_AiReadData[32];
106 unsigned short us_UseDma; /* To use Dma or not */
107 unsigned char b_DmaDoubleBuffer; /* we can use double buffering */
108 unsigned int ui_DmaActualBuffer; /* which buffer is used now */
109 unsigned short *ul_DmaBufferVirtual[2]; /* pointers to DMA buffer */
110 dma_addr_t ul_DmaBufferHw[2]; /* hw address of DMA buff */
111 unsigned int ui_DmaBufferSize[2]; /* size of dma buffer in bytes */
112 unsigned int ui_DmaBufferUsesize[2]; /* which size we may now used for transfer */
113 unsigned char b_DigitalOutputRegister; /* Digital Output Register */
114 unsigned char b_OutputMemoryStatus;
115 unsigned char b_TimerSelectMode; /* Contain data written at iobase + 0C */
116 unsigned char b_ModeSelectRegister; /* Contain data written at iobase + 0E */
117 unsigned short us_OutputRegister; /* Contain data written at iobase + 0 */
118 unsigned char b_Timer2Mode; /* Specify the timer 2 mode */
119 unsigned char b_Timer2Interrupt; /* Timer2 interrupt enable or disable */
120 unsigned int ai_running:1;
121 unsigned char b_InterruptMode; /* eoc eos or dma */
122 unsigned char b_EocEosInterrupt; /* Enable disable eoc eos interrupt */
123 unsigned int ui_EocEosConversionTime;
124 unsigned char b_ExttrigEnable; /* To enable or disable external trigger */
125
126 /* Pointer to the current process */
127 struct task_struct *tsk_Current;
128
129 /* Parameters read from EEPROM overriding static board info */
130 struct {
131 int i_NbrAiChannel; /* num of A/D chans */
132 int i_NbrAoChannel; /* num of D/A chans */
133 int i_AiMaxdata; /* resolution of A/D */
134 int i_AoMaxdata; /* resolution of D/A */
135 int i_NbrDiChannel; /* Number of DI channels */
136 int i_NbrDoChannel; /* Number of DO channels */
137 int i_DoMaxdata; /* data to set all channels high */
138 int i_Timer; /* timer subdevice present or not */
139 unsigned int ui_MinAcquisitiontimeNs;
140 /* Minimum Acquisition in Nano secs */
141 unsigned int ui_MinDelaytimeNs;
142 /* Minimum Delay in Nano secs */
143 } s_EeParameters;
144};
diff --git a/drivers/staging/comedi/drivers/addi-data/addi_eeprom.c b/drivers/staging/comedi/drivers/addi-data/addi_eeprom.c
deleted file mode 100644
index b731856c27da..000000000000
--- a/drivers/staging/comedi/drivers/addi-data/addi_eeprom.c
+++ /dev/null
@@ -1,360 +0,0 @@
1/*
2 * addi_eeprom.c - ADDI EEPROM Module
3 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
4 * Project manager: Eric Stolz
5 *
6 * ADDI-DATA GmbH
7 * Dieselstrasse 3
8 * D-77833 Ottersweier
9 * Tel: +19(0)7223/9493-0
10 * Fax: +49(0)7223/9493-92
11 * http://www.addi-data.com
12 * info@addi-data.com
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
23 */
24
25#include <linux/delay.h>
26
27#define NVRAM_USER_DATA_START 0x100
28
29#define NVCMD_BEGIN_READ (0x7 << 5) /* nvRam begin read command */
30#define NVCMD_LOAD_LOW (0x4 << 5) /* nvRam load low command */
31#define NVCMD_LOAD_HIGH (0x5 << 5) /* nvRam load high command */
32
33#define EE93C76_CLK_BIT (1 << 0)
34#define EE93C76_CS_BIT (1 << 1)
35#define EE93C76_DOUT_BIT (1 << 2)
36#define EE93C76_DIN_BIT (1 << 3)
37#define EE93C76_READ_CMD (0x0180 << 4)
38#define EE93C76_CMD_LEN 13
39
40#define EEPROM_DIGITALINPUT 0
41#define EEPROM_DIGITALOUTPUT 1
42#define EEPROM_ANALOGINPUT 2
43#define EEPROM_ANALOGOUTPUT 3
44#define EEPROM_TIMER 4
45#define EEPROM_WATCHDOG 5
46#define EEPROM_TIMER_WATCHDOG_COUNTER 10
47
48static void addi_eeprom_clk_93c76(unsigned long iobase, unsigned int val)
49{
50 outl(val & ~EE93C76_CLK_BIT, iobase);
51 udelay(100);
52
53 outl(val | EE93C76_CLK_BIT, iobase);
54 udelay(100);
55}
56
57static unsigned int addi_eeprom_cmd_93c76(unsigned long iobase,
58 unsigned int cmd,
59 unsigned char len)
60{
61 unsigned int val = EE93C76_CS_BIT;
62 int i;
63
64 /* Toggle EEPROM's Chip select to get it out of Shift Register Mode */
65 outl(val, iobase);
66 udelay(100);
67
68 /* Send EEPROM command - one bit at a time */
69 for (i = (len - 1); i >= 0; i--) {
70 if (cmd & (1 << i))
71 val |= EE93C76_DOUT_BIT;
72 else
73 val &= ~EE93C76_DOUT_BIT;
74
75 /* Write the command */
76 outl(val, iobase);
77 udelay(100);
78
79 addi_eeprom_clk_93c76(iobase, val);
80 }
81 return val;
82}
83
84static unsigned short addi_eeprom_readw_93c76(unsigned long iobase,
85 unsigned short addr)
86{
87 unsigned short val = 0;
88 unsigned int cmd;
89 unsigned int tmp;
90 int i;
91
92 /* Send EEPROM read command and offset to EEPROM */
93 cmd = EE93C76_READ_CMD | (addr / 2);
94 cmd = addi_eeprom_cmd_93c76(iobase, cmd, EE93C76_CMD_LEN);
95
96 /* Get the 16-bit value */
97 for (i = 0; i < 16; i++) {
98 addi_eeprom_clk_93c76(iobase, cmd);
99
100 tmp = inl(iobase);
101 udelay(100);
102
103 val <<= 1;
104 if (tmp & EE93C76_DIN_BIT)
105 val |= 0x1;
106 }
107
108 /* Toggle EEPROM's Chip select to get it out of Shift Register Mode */
109 outl(0, iobase);
110 udelay(100);
111
112 return val;
113}
114
115static void addi_eeprom_nvram_wait(unsigned long iobase)
116{
117 unsigned char val;
118
119 do {
120 val = inb(iobase + AMCC_OP_REG_MCSR_NVCMD);
121 } while (val & 0x80);
122}
123
124static unsigned short addi_eeprom_readw_nvram(unsigned long iobase,
125 unsigned short addr)
126{
127 unsigned short val = 0;
128 unsigned char tmp;
129 unsigned char i;
130
131 for (i = 0; i < 2; i++) {
132 /* Load the low 8 bit address */
133 outb(NVCMD_LOAD_LOW, iobase + AMCC_OP_REG_MCSR_NVCMD);
134 addi_eeprom_nvram_wait(iobase);
135 outb((addr + i) & 0xff, iobase + AMCC_OP_REG_MCSR_NVDATA);
136 addi_eeprom_nvram_wait(iobase);
137
138 /* Load the high 8 bit address */
139 outb(NVCMD_LOAD_HIGH, iobase + AMCC_OP_REG_MCSR_NVCMD);
140 addi_eeprom_nvram_wait(iobase);
141 outb(((addr + i) >> 8) & 0xff,
142 iobase + AMCC_OP_REG_MCSR_NVDATA);
143 addi_eeprom_nvram_wait(iobase);
144
145 /* Read the eeprom data byte */
146 outb(NVCMD_BEGIN_READ, iobase + AMCC_OP_REG_MCSR_NVCMD);
147 addi_eeprom_nvram_wait(iobase);
148 tmp = inb(iobase + AMCC_OP_REG_MCSR_NVDATA);
149 addi_eeprom_nvram_wait(iobase);
150
151 if (i == 0)
152 val |= tmp;
153 else
154 val |= (tmp << 8);
155 }
156
157 return val;
158}
159
160static unsigned short addi_eeprom_readw(unsigned long iobase,
161 char *type,
162 unsigned short addr)
163{
164 unsigned short val = 0;
165
166 /* Add the offset to the start of the user data */
167 addr += NVRAM_USER_DATA_START;
168
169 if (!strcmp(type, "S5920") || !strcmp(type, "S5933"))
170 val = addi_eeprom_readw_nvram(iobase, addr);
171
172 if (!strcmp(type, "93C76"))
173 val = addi_eeprom_readw_93c76(iobase, addr);
174
175 return val;
176}
177
178static void addi_eeprom_read_di_info(struct comedi_device *dev,
179 unsigned long iobase,
180 unsigned short addr)
181{
182 const struct addi_board *this_board = dev->board_ptr;
183 struct addi_private *devpriv = dev->private;
184 char *type = this_board->pc_EepromChip;
185 unsigned short tmp;
186
187 /* Number of channels */
188 tmp = addi_eeprom_readw(iobase, type, addr + 6);
189 devpriv->s_EeParameters.i_NbrDiChannel = tmp;
190
191 /* Interruptible or not */
192 tmp = addi_eeprom_readw(iobase, type, addr + 8);
193 tmp = (tmp >> 7) & 0x01;
194
195 /* How many interruptible logic */
196 tmp = addi_eeprom_readw(iobase, type, addr + 10);
197}
198
199static void addi_eeprom_read_do_info(struct comedi_device *dev,
200 unsigned long iobase,
201 unsigned short addr)
202{
203 const struct addi_board *this_board = dev->board_ptr;
204 struct addi_private *devpriv = dev->private;
205 char *type = this_board->pc_EepromChip;
206 unsigned short tmp;
207
208 /* Number of channels */
209 tmp = addi_eeprom_readw(iobase, type, addr + 6);
210 devpriv->s_EeParameters.i_NbrDoChannel = tmp;
211
212 devpriv->s_EeParameters.i_DoMaxdata = 0xffffffff >> (32 - tmp);
213}
214
215static void addi_eeprom_read_timer_info(struct comedi_device *dev,
216 unsigned long iobase,
217 unsigned short addr)
218{
219 struct addi_private *devpriv = dev->private;
220#if 0
221 const struct addi_board *this_board = dev->board_ptr;
222 char *type = this_board->pc_EepromChip;
223 unsigned short offset = 0;
224 unsigned short ntimers;
225 unsigned short tmp;
226 int i;
227
228 /* Number of Timers */
229 ntimers = addi_eeprom_readw(iobase, type, addr + 6);
230
231 /* Read header size */
232 for (i = 0; i < ntimers; i++) {
233 unsigned short size;
234 unsigned short res;
235 unsigned short mode;
236 unsigned short min_timing;
237 unsigned short timebase;
238
239 size = addi_eeprom_readw(iobase, type, addr + 8 + offset + 0);
240
241 /* Resolution / Mode */
242 tmp = addi_eeprom_readw(iobase, type, addr + 8 + offset + 2);
243 res = (tmp >> 10) & 0x3f;
244 mode = (tmp >> 4) & 0x3f;
245
246 /* MinTiming / Timebase */
247 tmp = addi_eeprom_readw(iobase, type, addr + 8 + offset + 4);
248 min_timing = (tmp >> 6) & 0x3ff;
249 Timebase = tmp & 0x3f;
250
251 offset += size;
252 }
253#endif
254 /* Timer subdevice present */
255 devpriv->s_EeParameters.i_Timer = 1;
256}
257
258static void addi_eeprom_read_ao_info(struct comedi_device *dev,
259 unsigned long iobase,
260 unsigned short addr)
261{
262 const struct addi_board *this_board = dev->board_ptr;
263 struct addi_private *devpriv = dev->private;
264 char *type = this_board->pc_EepromChip;
265 unsigned short tmp;
266
267 /* No of channels for 1st hard component */
268 tmp = addi_eeprom_readw(iobase, type, addr + 10);
269 devpriv->s_EeParameters.i_NbrAoChannel = (tmp >> 4) & 0x3ff;
270
271 /* Resolution for 1st hard component */
272 tmp = addi_eeprom_readw(iobase, type, addr + 16);
273 tmp = (tmp >> 8) & 0xff;
274 devpriv->s_EeParameters.i_AoMaxdata = 0xfff >> (16 - tmp);
275}
276
277static void addi_eeprom_read_ai_info(struct comedi_device *dev,
278 unsigned long iobase,
279 unsigned short addr)
280{
281 const struct addi_board *this_board = dev->board_ptr;
282 struct addi_private *devpriv = dev->private;
283 char *type = this_board->pc_EepromChip;
284 unsigned short offset;
285 unsigned short tmp;
286
287 /* No of channels for 1st hard component */
288 tmp = addi_eeprom_readw(iobase, type, addr + 10);
289 devpriv->s_EeParameters.i_NbrAiChannel = (tmp >> 4) & 0x3ff;
290 if (!strcmp(this_board->pc_DriverName, "apci3200"))
291 devpriv->s_EeParameters.i_NbrAiChannel *= 4;
292
293 tmp = addi_eeprom_readw(iobase, type, addr + 16);
294 devpriv->s_EeParameters.ui_MinAcquisitiontimeNs = tmp * 1000;
295
296 tmp = addi_eeprom_readw(iobase, type, addr + 30);
297 devpriv->s_EeParameters.ui_MinDelaytimeNs = tmp * 1000;
298
299 tmp = addi_eeprom_readw(iobase, type, addr + 20);
300 /* dma = (tmp >> 13) & 0x01; */
301
302 tmp = addi_eeprom_readw(iobase, type, addr + 72) & 0xff;
303 if (tmp) { /* > 0 */
304 /* offset of first analog input single header */
305 offset = 74 + (2 * tmp) + (10 * (1 + (tmp / 16)));
306 } else { /* = 0 */
307 offset = 74;
308 }
309
310 /* Resolution */
311 tmp = addi_eeprom_readw(iobase, type, addr + offset + 2) & 0x1f;
312 devpriv->s_EeParameters.i_AiMaxdata = 0xffff >> (16 - tmp);
313}
314
315static void addi_eeprom_read_info(struct comedi_device *dev,
316 unsigned long iobase)
317{
318 const struct addi_board *this_board = dev->board_ptr;
319 char *type = this_board->pc_EepromChip;
320 unsigned short size;
321 unsigned char nfuncs;
322 int i;
323
324 size = addi_eeprom_readw(iobase, type, 8);
325 nfuncs = addi_eeprom_readw(iobase, type, 10) & 0xff;
326
327 /* Read functionality details */
328 for (i = 0; i < nfuncs; i++) {
329 unsigned short offset = i * 4;
330 unsigned short addr;
331 unsigned char func;
332
333 func = addi_eeprom_readw(iobase, type, 12 + offset) & 0x3f;
334 addr = addi_eeprom_readw(iobase, type, 14 + offset);
335
336 switch (func) {
337 case EEPROM_DIGITALINPUT:
338 addi_eeprom_read_di_info(dev, iobase, addr);
339 break;
340
341 case EEPROM_DIGITALOUTPUT:
342 addi_eeprom_read_do_info(dev, iobase, addr);
343 break;
344
345 case EEPROM_ANALOGINPUT:
346 addi_eeprom_read_ai_info(dev, iobase, addr);
347 break;
348
349 case EEPROM_ANALOGOUTPUT:
350 addi_eeprom_read_ao_info(dev, iobase, addr);
351 break;
352
353 case EEPROM_TIMER:
354 case EEPROM_WATCHDOG:
355 case EEPROM_TIMER_WATCHDOG_COUNTER:
356 addi_eeprom_read_timer_info(dev, iobase, addr);
357 break;
358 }
359 }
360}
diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci035.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci035.c
deleted file mode 100644
index 53bb51bd77b5..000000000000
--- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci035.c
+++ /dev/null
@@ -1,480 +0,0 @@
1/*
2 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
3 *
4 * ADDI-DATA GmbH
5 * Dieselstrasse 3
6 * D-77833 Ottersweier
7 * Tel: +19(0)7223/9493-0
8 * Fax: +49(0)7223/9493-92
9 * http://www.addi-data.com
10 * info@addi-data.com
11 *
12 * This program is free software; you can redistribute it and/or modify it under
13 * the terms of the GNU General Public License as published by the Free Software
14 * Foundation; either version 2 of the License, or (at your option) any later
15 * version.
16 *
17 * This program is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20 * details.
21 */
22
23/* Card Specific information */
24#define APCI035_ADDRESS_RANGE 255
25
26/* Timer / Watchdog Related Defines */
27#define APCI035_TCW_SYNC_ENABLEDISABLE 0
28#define APCI035_TCW_RELOAD_VALUE 4
29#define APCI035_TCW_TIMEBASE 8
30#define APCI035_TCW_PROG 12
31#define APCI035_TCW_TRIG_STATUS 16
32#define APCI035_TCW_IRQ 20
33#define APCI035_TCW_WARN_TIMEVAL 24
34#define APCI035_TCW_WARN_TIMEBASE 28
35
36#define ADDIDATA_TIMER 0
37/* #define ADDIDATA_WATCHDOG 1 */
38
39#define APCI035_TW1 0
40#define APCI035_TW2 32
41#define APCI035_TW3 64
42#define APCI035_TW4 96
43
44#define APCI035_AI_OFFSET 0
45#define APCI035_TEMP 128
46#define APCI035_ALR_SEQ 4
47#define APCI035_START_STOP_INDEX 8
48#define APCI035_ALR_START_STOP 12
49#define APCI035_ALR_IRQ 16
50#define APCI035_EOS 20
51#define APCI035_CHAN_NO 24
52#define APCI035_CHAN_VAL 28
53#define APCI035_CONV_TIME_TIME_BASE 36
54#define APCI035_RELOAD_CONV_TIME_VAL 32
55#define APCI035_DELAY_TIME_TIME_BASE 44
56#define APCI035_RELOAD_DELAY_TIME_VAL 40
57#define ENABLE_EXT_TRIG 1
58#define ENABLE_EXT_GATE 2
59#define ENABLE_EXT_TRIG_GATE 3
60
61#define ANALOG_INPUT 0
62#define TEMPERATURE 1
63#define RESISTANCE 2
64
65#define ADDIDATA_GREATER_THAN_TEST 0
66#define ADDIDATA_LESS_THAN_TEST 1
67
68#define APCI035_MAXVOLT 2.5
69
70#define ADDIDATA_UNIPOLAR 1
71#define ADDIDATA_BIPOLAR 2
72
73/* ANALOG INPUT RANGE */
74static struct comedi_lrange range_apci035_ai = {
75 8, {
76 BIP_RANGE(10),
77 BIP_RANGE(5),
78 BIP_RANGE(2),
79 BIP_RANGE(1),
80 UNI_RANGE(10),
81 UNI_RANGE(5),
82 UNI_RANGE(2),
83 UNI_RANGE(1)
84 }
85};
86
87static int i_WatchdogNbr;
88static int i_Temp;
89static int i_Flag = 1;
90
91/*
92 * Configures The Timer , Counter or Watchdog
93 *
94 * data[0] 0 = Configure As Timer, 1 = Configure As Watchdog
95 * data[1] Watchdog number
96 * data[2] Time base Unit
97 * data[3] Reload Value
98 * data[4] External Trigger, 1 = Enable, 0 = Disable
99 * data[5] External Trigger Level
100 * 00 = Trigger Disabled
101 * 01 = Trigger Enabled (Low level)
102 * 10 = Trigger Enabled (High Level)
103 * 11 = Trigger Enabled (High/Low level)
104 * data[6] External Gate, 1 = Enable, 0 = Disable
105 * data[7] External Gate level
106 * 00 = Gate Disabled
107 * 01 = Gate Enabled (Low level)
108 * 10 = Gate Enabled (High Level)
109 * data[8] Warning Relay, 1 = Enable, 0 = Disable
110 * data[9] Warning Delay available
111 * data[10] Warning Relay Time unit
112 * data[11] Warning Relay Time Reload value
113 * data[12] Reset Relay, 1 = Enable, 0 = Disable
114 * data[13] Interrupt, 1 = Enable, 0 = Disable
115 */
116static int apci035_timer_config(struct comedi_device *dev,
117 struct comedi_subdevice *s,
118 struct comedi_insn *insn,
119 unsigned int *data)
120{
121 struct addi_private *devpriv = dev->private;
122 unsigned int ui_Status;
123 unsigned int ui_Command;
124 unsigned int ui_Mode;
125
126 i_Temp = 0;
127 devpriv->tsk_Current = current;
128 devpriv->b_TimerSelectMode = data[0];
129 i_WatchdogNbr = data[1];
130 if (data[0] == 0)
131 ui_Mode = 2;
132 else
133 ui_Mode = 0;
134
135 ui_Command = 0;
136 outl(ui_Command, devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12);
137
138 ui_Command = inl(devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12);
139
140 /* Set the reload value */
141 outl(data[3], devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 4);
142
143 /* Set the time unit */
144 outl(data[2], devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 8);
145 if (data[0] == ADDIDATA_TIMER) {
146
147 /* Set the mode : */
148 /* - Disable the hardware */
149 /* - Disable the counter mode */
150 /* - Disable the warning */
151 /* - Disable the reset */
152 /* - Enable the timer mode */
153 /* - Set the timer mode */
154
155 ui_Command =
156 (ui_Command & 0xFFF719E2UL) | ui_Mode << 13UL | 0x10UL;
157
158 } else if (data[0] == ADDIDATA_WATCHDOG) {
159
160 /* Set the mode : */
161 /* - Disable the hardware */
162 /* - Disable the counter mode */
163 /* - Disable the warning */
164 /* - Disable the reset */
165 /* - Disable the timer mode */
166
167 ui_Command = ui_Command & 0xFFF819E2UL;
168
169 } else {
170 dev_err(dev->class_dev, "The parameter for Timer/watchdog selection is in error\n");
171 return -EINVAL;
172 }
173
174 outl(ui_Command, devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12);
175
176 ui_Command = inl(devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12);
177
178 /* Disable the hardware trigger */
179 ui_Command = ui_Command & 0xFFFFF89FUL;
180 if (data[4] == 1) {
181 /* Set the hardware trigger level */
182 ui_Command = ui_Command | (data[5] << 5);
183 }
184 outl(ui_Command, devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12);
185
186 ui_Command = inl(devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12);
187
188 /* Disable the hardware gate */
189 ui_Command = ui_Command & 0xFFFFF87FUL;
190 if (data[6] == 1) {
191 /* Set the hardware gate level */
192 ui_Command = ui_Command | (data[7] << 7);
193 }
194 outl(ui_Command, devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12);
195
196 ui_Command = inl(devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12);
197
198 /* Disable the hardware output */
199 ui_Command = ui_Command & 0xFFFFF9FBUL;
200
201 /* Set the hardware output level */
202 ui_Command = ui_Command | (data[8] << 2);
203 outl(ui_Command, devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12);
204 if (data[9] == 1) {
205 /* Set the reload value */
206 outl(data[11],
207 devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 24);
208
209 /* Set the time unite */
210 outl(data[10],
211 devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 28);
212 }
213
214 ui_Command = inl(devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12);
215
216 /* Disable the hardware output */
217 ui_Command = ui_Command & 0xFFFFF9F7UL;
218
219 /* Set the hardware output level */
220 ui_Command = ui_Command | (data[12] << 3);
221 outl(ui_Command, devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12);
222
223 /* Enable the watchdog interrupt */
224 ui_Command = inl(devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12);
225
226 /* Set the interrupt selection */
227 ui_Status = inl(devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 16);
228
229 ui_Command = (ui_Command & 0xFFFFF9FDUL) | (data[13] << 1);
230 outl(ui_Command, devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12);
231
232 return insn->n;
233}
234
235/*
236 * Start / Stop The Selected Timer , or Watchdog
237 *
238 * data[0]
239 * 0 - Stop Selected Timer/Watchdog
240 * 1 - Start Selected Timer/Watch*dog
241 * 2 - Trigger Selected Timer/Watchdog
242 * 3 - Stop All Timer/Watchdog
243 * 4 - Start All Timer/Watchdog
244 * 5 - Trigger All Timer/Watchdog
245 */
246static int apci035_timer_write(struct comedi_device *dev,
247 struct comedi_subdevice *s,
248 struct comedi_insn *insn,
249 unsigned int *data)
250{
251 struct addi_private *devpriv = dev->private;
252 unsigned int ui_Command;
253 int i_Count;
254
255 if (data[0] == 1) {
256 ui_Command =
257 inl(devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12);
258
259 /* Start the hardware */
260 ui_Command = (ui_Command & 0xFFFFF9FFUL) | 0x1UL;
261 outl(ui_Command,
262 devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12);
263 }
264 if (data[0] == 2) {
265 ui_Command =
266 inl(devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12);
267
268 /* Set the trigger command */
269 ui_Command = (ui_Command & 0xFFFFF9FFUL) | 0x200UL;
270 outl(ui_Command,
271 devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12);
272 }
273
274 if (data[0] == 0) {
275 /* Stop The Watchdog */
276 ui_Command = 0;
277 /*
278 * ui_Command = inl(devpriv->iobase+((i_WatchdogNbr-1)*32)+12);
279 * ui_Command = ui_Command & 0xFFFFF9FEUL;
280 */
281 outl(ui_Command,
282 devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 12);
283 }
284 if (data[0] == 3) {
285 /* stop all Watchdogs */
286 ui_Command = 0;
287 for (i_Count = 1; i_Count <= 4; i_Count++) {
288 if (devpriv->b_TimerSelectMode == ADDIDATA_WATCHDOG)
289 ui_Command = 0x2UL;
290 else
291 ui_Command = 0x10UL;
292
293 i_WatchdogNbr = i_Count;
294 outl(ui_Command,
295 devpriv->iobase + ((i_WatchdogNbr - 1) * 32) +
296 0);
297 }
298
299 }
300 if (data[0] == 4) {
301 /* start all Watchdogs */
302 ui_Command = 0;
303 for (i_Count = 1; i_Count <= 4; i_Count++) {
304 if (devpriv->b_TimerSelectMode == ADDIDATA_WATCHDOG)
305 ui_Command = 0x1UL;
306 else
307 ui_Command = 0x8UL;
308
309 i_WatchdogNbr = i_Count;
310 outl(ui_Command,
311 devpriv->iobase + ((i_WatchdogNbr - 1) * 32) +
312 0);
313 }
314 }
315 if (data[0] == 5) {
316 /* trigger all Watchdogs */
317 ui_Command = 0;
318 for (i_Count = 1; i_Count <= 4; i_Count++) {
319 if (devpriv->b_TimerSelectMode == ADDIDATA_WATCHDOG)
320 ui_Command = 0x4UL;
321 else
322 ui_Command = 0x20UL;
323
324 i_WatchdogNbr = i_Count;
325 outl(ui_Command,
326 devpriv->iobase + ((i_WatchdogNbr - 1) * 32) +
327 0);
328 }
329 i_Temp = 1;
330 }
331 return insn->n;
332}
333
334/*
335 * Read The Selected Timer , Counter or Watchdog
336 *
337 * data[0] software trigger status
338 * data[1] hardware trigger status
339 * data[2] Software clear status
340 * data[3] Overflow status
341 * data[4] Timer actual value
342 */
343static int apci035_timer_read(struct comedi_device *dev,
344 struct comedi_subdevice *s,
345 struct comedi_insn *insn,
346 unsigned int *data)
347{
348 struct addi_private *devpriv = dev->private;
349 unsigned int ui_Status; /* Status register */
350
351 i_WatchdogNbr = insn->unused[0];
352
353 /* Get the status */
354 ui_Status = inl(devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 16);
355
356 /* Get the software trigger status */
357 data[0] = ((ui_Status >> 1) & 1);
358
359 /* Get the hardware trigger status */
360 data[1] = ((ui_Status >> 2) & 1);
361
362 /* Get the software clear status */
363 data[2] = ((ui_Status >> 3) & 1);
364
365 /* Get the overflow status */
366 data[3] = ((ui_Status >> 0) & 1);
367 if (devpriv->b_TimerSelectMode == ADDIDATA_TIMER)
368 data[4] = inl(devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 0);
369
370 return insn->n;
371}
372
373/*
374 * Configures The Analog Input Subdevice
375 *
376 * data[0] Warning delay value
377 */
378static int apci035_ai_config(struct comedi_device *dev,
379 struct comedi_subdevice *s,
380 struct comedi_insn *insn,
381 unsigned int *data)
382{
383 struct addi_private *devpriv = dev->private;
384
385 devpriv->tsk_Current = current;
386 outl(0x200 | 0, devpriv->iobase + 128 + 0x4);
387 outl(0, devpriv->iobase + 128 + 0);
388
389 /* Initialise the warning value */
390 outl(0x300 | 0, devpriv->iobase + 128 + 0x4);
391 outl((data[0] << 8), devpriv->iobase + 128 + 0);
392 outl(0x200000UL, devpriv->iobase + 128 + 12);
393
394 return insn->n;
395}
396
397/*
398 * Read value of the selected channel
399 *
400 * data[0] Digital Value Of Input
401 */
402static int apci035_ai_read(struct comedi_device *dev,
403 struct comedi_subdevice *s,
404 struct comedi_insn *insn,
405 unsigned int *data)
406{
407 struct addi_private *devpriv = dev->private;
408 unsigned int ui_CommandRegister;
409
410 /* Set the start */
411 ui_CommandRegister = 0x80000;
412
413 /* Write the command register */
414 outl(ui_CommandRegister, devpriv->iobase + 128 + 8);
415
416 /* Read the digital value of the input */
417 data[0] = inl(devpriv->iobase + 128 + 28);
418 return insn->n;
419}
420
421static int apci035_reset(struct comedi_device *dev)
422{
423 struct addi_private *devpriv = dev->private;
424 int i_Count;
425
426 for (i_Count = 1; i_Count <= 4; i_Count++) {
427 i_WatchdogNbr = i_Count;
428
429 /* stop all timers */
430 outl(0x0, devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 0);
431 }
432 outl(0x0, devpriv->iobase + 128 + 12); /* Disable the warning delay */
433
434 return 0;
435}
436
437static void apci035_interrupt(int irq, void *d)
438{
439 struct comedi_device *dev = d;
440 struct addi_private *devpriv = dev->private;
441 unsigned int ui_StatusRegister1;
442 unsigned int ui_StatusRegister2;
443 unsigned int ui_ReadCommand;
444 unsigned int ui_ChannelNumber;
445 unsigned int ui_DigitalTemperature;
446
447 if (i_Temp == 1) {
448 i_WatchdogNbr = i_Flag;
449 i_Flag = i_Flag + 1;
450 }
451
452 /* Read the interrupt status register of temperature Warning */
453 ui_StatusRegister1 = inl(devpriv->iobase + 128 + 16);
454
455 /* Read the interrupt status register for Watchdog/timer */
456 ui_StatusRegister2 =
457 inl(devpriv->iobase + ((i_WatchdogNbr - 1) * 32) + 20);
458
459 /* Test if warning relay interrupt */
460 if ((((ui_StatusRegister1) & 0x8) == 0x8)) {
461
462 /* Disable the temperature warning */
463 ui_ReadCommand = inl(devpriv->iobase + 128 + 12);
464 ui_ReadCommand = ui_ReadCommand & 0xFFDF0000UL;
465 outl(ui_ReadCommand, devpriv->iobase + 128 + 12);
466
467 /* Read the channel number */
468 ui_ChannelNumber = inl(devpriv->iobase + 128 + 60);
469
470 /* Read the digital temperature value */
471 ui_DigitalTemperature = inl(devpriv->iobase + 128 + 60);
472
473 /* send signal to the sample */
474 send_sig(SIGIO, devpriv->tsk_Current, 0);
475
476 } else if ((ui_StatusRegister2 & 0x1) == 0x1) {
477 /* send signal to the sample */
478 send_sig(SIGIO, devpriv->tsk_Current, 0);
479 }
480}
diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1500.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1500.c
index 0ea081e1e119..bfa9228c833f 100644
--- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1500.c
+++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1500.c
@@ -158,7 +158,7 @@ static int apci1500_di_config(struct comedi_device *dev,
158 struct comedi_insn *insn, 158 struct comedi_insn *insn,
159 unsigned int *data) 159 unsigned int *data)
160{ 160{
161 struct addi_private *devpriv = dev->private; 161 struct apci1500_private *devpriv = dev->private;
162 int i_PatternPolarity = 0, i_PatternTransition = 0, i_PatternMask = 0; 162 int i_PatternPolarity = 0, i_PatternTransition = 0, i_PatternMask = 0;
163 int i_MaxChannel = 0, i_Count = 0, i_EventMask = 0; 163 int i_MaxChannel = 0, i_Count = 0, i_EventMask = 0;
164 int i_PatternTransitionCount = 0, i_RegValue; 164 int i_PatternTransitionCount = 0, i_RegValue;
@@ -466,7 +466,7 @@ static int apci1500_di_write(struct comedi_device *dev,
466 struct comedi_insn *insn, 466 struct comedi_insn *insn,
467 unsigned int *data) 467 unsigned int *data)
468{ 468{
469 struct addi_private *devpriv = dev->private; 469 struct apci1500_private *devpriv = dev->private;
470 int i_Event1InterruptStatus = 0, i_Event2InterruptStatus = 470 int i_Event1InterruptStatus = 0, i_Event2InterruptStatus =
471 0, i_RegValue; 471 0, i_RegValue;
472 472
@@ -653,7 +653,7 @@ static int apci1500_di_read(struct comedi_device *dev,
653 struct comedi_insn *insn, 653 struct comedi_insn *insn,
654 unsigned int *data) 654 unsigned int *data)
655{ 655{
656 struct addi_private *devpriv = dev->private; 656 struct apci1500_private *devpriv = dev->private;
657 int i_DummyRead = 0; 657 int i_DummyRead = 0;
658 658
659 /* Software reset */ 659 /* Software reset */
@@ -789,7 +789,7 @@ static int apci1500_di_insn_bits(struct comedi_device *dev,
789 struct comedi_insn *insn, 789 struct comedi_insn *insn,
790 unsigned int *data) 790 unsigned int *data)
791{ 791{
792 struct addi_private *devpriv = dev->private; 792 struct apci1500_private *devpriv = dev->private;
793 793
794 data[1] = inw(devpriv->i_IobaseAddon + APCI1500_DIGITAL_IP); 794 data[1] = inw(devpriv->i_IobaseAddon + APCI1500_DIGITAL_IP);
795 795
@@ -807,7 +807,7 @@ static int apci1500_do_config(struct comedi_device *dev,
807 struct comedi_insn *insn, 807 struct comedi_insn *insn,
808 unsigned int *data) 808 unsigned int *data)
809{ 809{
810 struct addi_private *devpriv = dev->private; 810 struct apci1500_private *devpriv = dev->private;
811 811
812 devpriv->b_OutputMemoryStatus = data[0]; 812 devpriv->b_OutputMemoryStatus = data[0];
813 return insn->n; 813 return insn->n;
@@ -821,7 +821,7 @@ static int apci1500_do_write(struct comedi_device *dev,
821 struct comedi_insn *insn, 821 struct comedi_insn *insn,
822 unsigned int *data) 822 unsigned int *data)
823{ 823{
824 struct addi_private *devpriv = dev->private; 824 struct apci1500_private *devpriv = dev->private;
825 static unsigned int ui_Temp; 825 static unsigned int ui_Temp;
826 unsigned int ui_Temp1; 826 unsigned int ui_Temp1;
827 unsigned int ui_NoOfChannel = CR_CHAN(insn->chanspec); /* get the channel */ 827 unsigned int ui_NoOfChannel = CR_CHAN(insn->chanspec); /* get the channel */
@@ -981,7 +981,7 @@ static int apci1500_timer_config(struct comedi_device *dev,
981 struct comedi_insn *insn, 981 struct comedi_insn *insn,
982 unsigned int *data) 982 unsigned int *data)
983{ 983{
984 struct addi_private *devpriv = dev->private; 984 struct apci1500_private *devpriv = dev->private;
985 int i_TimerCounterMode, i_MasterConfiguration; 985 int i_TimerCounterMode, i_MasterConfiguration;
986 986
987 devpriv->tsk_Current = current; 987 devpriv->tsk_Current = current;
@@ -1471,7 +1471,7 @@ static int apci1500_timer_write(struct comedi_device *dev,
1471 struct comedi_insn *insn, 1471 struct comedi_insn *insn,
1472 unsigned int *data) 1472 unsigned int *data)
1473{ 1473{
1474 struct addi_private *devpriv = dev->private; 1474 struct apci1500_private *devpriv = dev->private;
1475 int i_CommandAndStatusValue; 1475 int i_CommandAndStatusValue;
1476 1476
1477 switch (data[0]) { 1477 switch (data[0]) {
@@ -1731,7 +1731,7 @@ static int apci1500_timer_bits(struct comedi_device *dev,
1731 struct comedi_insn *insn, 1731 struct comedi_insn *insn,
1732 unsigned int *data) 1732 unsigned int *data)
1733{ 1733{
1734 struct addi_private *devpriv = dev->private; 1734 struct apci1500_private *devpriv = dev->private;
1735 int i_CommandAndStatusValue; 1735 int i_CommandAndStatusValue;
1736 1736
1737 switch (data[0]) { 1737 switch (data[0]) {
@@ -1895,7 +1895,7 @@ static int apci1500_do_bits(struct comedi_device *dev,
1895 struct comedi_insn *insn, 1895 struct comedi_insn *insn,
1896 unsigned int *data) 1896 unsigned int *data)
1897{ 1897{
1898 struct addi_private *devpriv = dev->private; 1898 struct apci1500_private *devpriv = dev->private;
1899 unsigned int ui_Status; 1899 unsigned int ui_Status;
1900 int i_RegValue; 1900 int i_RegValue;
1901 int i_Constant; 1901 int i_Constant;
@@ -2011,11 +2011,11 @@ static int apci1500_do_bits(struct comedi_device *dev,
2011 return insn->n; 2011 return insn->n;
2012} 2012}
2013 2013
2014static void apci1500_interrupt(int irq, void *d) 2014static irqreturn_t apci1500_interrupt(int irq, void *d)
2015{ 2015{
2016 2016
2017 struct comedi_device *dev = d; 2017 struct comedi_device *dev = d;
2018 struct addi_private *devpriv = dev->private; 2018 struct apci1500_private *devpriv = dev->private;
2019 unsigned int ui_InterruptStatus = 0; 2019 unsigned int ui_InterruptStatus = 0;
2020 int i_RegValue = 0; 2020 int i_RegValue = 0;
2021 2021
@@ -2180,11 +2180,13 @@ static void apci1500_interrupt(int irq, void *d)
2180 "Interrupt from unknown source\n"); 2180 "Interrupt from unknown source\n");
2181 2181
2182 } 2182 }
2183
2184 return IRQ_HANDLED;
2183} 2185}
2184 2186
2185static int apci1500_reset(struct comedi_device *dev) 2187static int apci1500_reset(struct comedi_device *dev)
2186{ 2188{
2187 struct addi_private *devpriv = dev->private; 2189 struct apci1500_private *devpriv = dev->private;
2188 int i_DummyRead = 0; 2190 int i_DummyRead = 0;
2189 2191
2190 i_TimerCounter1Init = 0; 2192 i_TimerCounter1Init = 0;
diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1564.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1564.c
index 98de96953a29..fa99c8ca4f95 100644
--- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1564.c
+++ b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci1564.c
@@ -16,244 +16,189 @@
16#define ADDIDATA_TIMER 0 16#define ADDIDATA_TIMER 0
17#define ADDIDATA_COUNTER 1 17#define ADDIDATA_COUNTER 1
18#define ADDIDATA_WATCHDOG 2 18#define ADDIDATA_WATCHDOG 2
19#define APCI1564_COUNTER1 0 19
20#define APCI1564_COUNTER2 1 20static int apci1564_timer_insn_config(struct comedi_device *dev,
21#define APCI1564_COUNTER3 2 21 struct comedi_subdevice *s,
22#define APCI1564_COUNTER4 3 22 struct comedi_insn *insn,
23 23 unsigned int *data)
24/*
25 * devpriv->amcc_iobase Register Map
26 */
27#define APCI1564_DI_REG 0x04
28#define APCI1564_DI_INT_MODE1_REG 0x08
29#define APCI1564_DI_INT_MODE2_REG 0x0c
30#define APCI1564_DI_INT_STATUS_REG 0x10
31#define APCI1564_DI_IRQ_REG 0x14
32#define APCI1564_DO_REG 0x18
33#define APCI1564_DO_INT_CTRL_REG 0x1c
34#define APCI1564_DO_INT_STATUS_REG 0x20
35#define APCI1564_DO_IRQ_REG 0x24
36#define APCI1564_WDOG_REG 0x28
37#define APCI1564_WDOG_RELOAD_REG 0x2c
38#define APCI1564_WDOG_TIMEBASE_REG 0x30
39#define APCI1564_WDOG_CTRL_REG 0x34
40#define APCI1564_WDOG_STATUS_REG 0x38
41#define APCI1564_WDOG_IRQ_REG 0x3c
42#define APCI1564_WDOG_WARN_TIMEVAL_REG 0x40
43#define APCI1564_WDOG_WARN_TIMEBASE_REG 0x44
44#define APCI1564_TIMER_REG 0x48
45#define APCI1564_TIMER_RELOAD_REG 0x4c
46#define APCI1564_TIMER_TIMEBASE_REG 0x50
47#define APCI1564_TIMER_CTRL_REG 0x54
48#define APCI1564_TIMER_STATUS_REG 0x58
49#define APCI1564_TIMER_IRQ_REG 0x5c
50#define APCI1564_TIMER_WARN_TIMEVAL_REG 0x60
51#define APCI1564_TIMER_WARN_TIMEBASE_REG 0x64
52
53/*
54 * dev->iobase Register Map
55 */
56#define APCI1564_COUNTER_REG(x) (0x00 + ((x) * 0x20))
57#define APCI1564_COUNTER_RELOAD_REG(x) (0x04 + ((x) * 0x20))
58#define APCI1564_COUNTER_TIMEBASE_REG(x) (0x08 + ((x) * 0x20))
59#define APCI1564_COUNTER_CTRL_REG(x) (0x0c + ((x) * 0x20))
60#define APCI1564_COUNTER_STATUS_REG(x) (0x10 + ((x) * 0x20))
61#define APCI1564_COUNTER_IRQ_REG(x) (0x14 + ((x) * 0x20))
62#define APCI1564_COUNTER_WARN_TIMEVAL_REG(x) (0x18 + ((x) * 0x20))
63#define APCI1564_COUNTER_WARN_TIMEBASE_REG(x) (0x1c + ((x) * 0x20))
64
65/*
66 * Configures The Timer or Counter
67 *
68 * data[0] Configure as: 0 = Timer, 1 = Counter
69 * data[1] 1 = Enable Interrupt, 0 = Disable Interrupt
70 * data[2] Time Unit
71 * data[3] Reload Value
72 * data[4] Timer Mode
73 * data[5] Timer Counter Watchdog Number
74 * data[6] Counter Direction
75 */
76static int apci1564_timer_config(struct comedi_device *dev,
77 struct comedi_subdevice *s,
78 struct comedi_insn *insn,
79 unsigned int *data)
80{ 24{
81 struct apci1564_private *devpriv = dev->private; 25 struct apci1564_private *devpriv = dev->private;
82 unsigned int ul_Command1 = 0; 26 unsigned int ctrl;
83 27
84 devpriv->tsk_current = current; 28 devpriv->tsk_current = current;
85 if (data[0] == ADDIDATA_TIMER) {
86 /* First Stop The Timer */
87 ul_Command1 = inl(devpriv->amcc_iobase + APCI1564_TIMER_CTRL_REG);
88 ul_Command1 = ul_Command1 & 0xFFFFF9FEUL;
89 /* Stop The Timer */
90 outl(ul_Command1, devpriv->amcc_iobase + APCI1564_TIMER_CTRL_REG);
91
92 devpriv->timer_select_mode = ADDIDATA_TIMER;
93 if (data[1] == 1) {
94 /* Enable TIMER int & DISABLE ALL THE OTHER int SOURCES */
95 outl(0x02, devpriv->amcc_iobase + APCI1564_TIMER_CTRL_REG);
96 outl(0x0, devpriv->amcc_iobase + APCI1564_DI_IRQ_REG);
97 outl(0x0, devpriv->amcc_iobase + APCI1564_DO_IRQ_REG);
98 outl(0x0, devpriv->amcc_iobase + APCI1564_WDOG_IRQ_REG);
99 outl(0x0, dev->iobase +
100 APCI1564_COUNTER_IRQ_REG(APCI1564_COUNTER1));
101 outl(0x0, dev->iobase +
102 APCI1564_COUNTER_IRQ_REG(APCI1564_COUNTER2));
103 outl(0x0, dev->iobase +
104 APCI1564_COUNTER_IRQ_REG(APCI1564_COUNTER3));
105 outl(0x0, dev->iobase +
106 APCI1564_COUNTER_IRQ_REG(APCI1564_COUNTER4));
107 } else {
108 /* disable Timer interrupt */
109 outl(0x0, devpriv->amcc_iobase + APCI1564_TIMER_CTRL_REG);
110 }
111 29
112 /* Loading Timebase */ 30 /* First Stop The Timer */
113 outl(data[2], devpriv->amcc_iobase + APCI1564_TIMER_TIMEBASE_REG); 31 ctrl = inl(devpriv->timer + ADDI_TCW_CTRL_REG);
114 32 ctrl &= 0xfffff9fe;
115 /* Loading the Reload value */ 33 /* Stop The Timer */
116 outl(data[3], devpriv->amcc_iobase + APCI1564_TIMER_RELOAD_REG); 34 outl(ctrl, devpriv->timer + ADDI_TCW_CTRL_REG);
117 35
118 ul_Command1 = inl(devpriv->amcc_iobase + APCI1564_TIMER_CTRL_REG); 36 if (data[1] == 1) {
119 ul_Command1 = (ul_Command1 & 0xFFF719E2UL) | 2UL << 13UL | 0x10UL; 37 /* Enable timer int & disable all the other int sources */
120 /* mode 2 */ 38 outl(0x02, devpriv->timer + ADDI_TCW_CTRL_REG);
121 outl(ul_Command1, devpriv->amcc_iobase + APCI1564_TIMER_CTRL_REG); 39 outl(0x0, dev->iobase + APCI1564_DI_IRQ_REG);
122 } else if (data[0] == ADDIDATA_COUNTER) { 40 outl(0x0, dev->iobase + APCI1564_DO_IRQ_REG);
123 devpriv->timer_select_mode = ADDIDATA_COUNTER; 41 outl(0x0, dev->iobase + APCI1564_WDOG_IRQ_REG);
124 devpriv->mode_select_register = data[5]; 42 if (devpriv->counters) {
125 43 unsigned long iobase;
126 /* First Stop The Counter */ 44
127 ul_Command1 = inl(dev->iobase + 45 iobase = devpriv->counters + ADDI_TCW_IRQ_REG;
128 APCI1564_COUNTER_CTRL_REG(data[5] - 1)); 46 outl(0x0, iobase + APCI1564_COUNTER(0));
129 ul_Command1 = ul_Command1 & 0xFFFFF9FEUL; 47 outl(0x0, iobase + APCI1564_COUNTER(1));
130 /* Stop The Timer */ 48 outl(0x0, iobase + APCI1564_COUNTER(2));
131 outl(ul_Command1, dev->iobase + 49 }
132 APCI1564_COUNTER_CTRL_REG(data[5] - 1));
133
134 /* Set the reload value */
135 outl(data[3], dev->iobase +
136 APCI1564_COUNTER_RELOAD_REG(data[5] - 1));
137
138 /* Set the mode : */
139 /* - Disable the hardware */
140 /* - Disable the counter mode */
141 /* - Disable the warning */
142 /* - Disable the reset */
143 /* - Disable the timer mode */
144 /* - Enable the counter mode */
145
146 ul_Command1 =
147 (ul_Command1 & 0xFFFC19E2UL) | 0x80000UL |
148 (unsigned int) ((unsigned int) data[4] << 16UL);
149 outl(ul_Command1, dev->iobase +
150 APCI1564_COUNTER_CTRL_REG(data[5] - 1));
151
152 /* Enable or Disable Interrupt */
153 ul_Command1 = (ul_Command1 & 0xFFFFF9FD) | (data[1] << 1);
154 outl(ul_Command1, dev->iobase +
155 APCI1564_COUNTER_CTRL_REG(data[5] - 1));
156
157 /* Set the Up/Down selection */
158 ul_Command1 = (ul_Command1 & 0xFFFBF9FFUL) | (data[6] << 18);
159 outl(ul_Command1, dev->iobase +
160 APCI1564_COUNTER_CTRL_REG(data[5] - 1));
161 } else { 50 } else {
162 dev_err(dev->class_dev, "Invalid subdevice.\n"); 51 /* disable Timer interrupt */
52 outl(0x0, devpriv->timer + ADDI_TCW_CTRL_REG);
163 } 53 }
54
55 /* Loading Timebase */
56 outl(data[2], devpriv->timer + ADDI_TCW_TIMEBASE_REG);
57
58 /* Loading the Reload value */
59 outl(data[3], devpriv->timer + ADDI_TCW_RELOAD_REG);
60
61 ctrl = inl(devpriv->timer + ADDI_TCW_CTRL_REG);
62 ctrl &= 0xfff719e2;
63 ctrl |= (2 << 13) | 0x10;
64 /* mode 2 */
65 outl(ctrl, devpriv->timer + ADDI_TCW_CTRL_REG);
66
164 return insn->n; 67 return insn->n;
165} 68}
166 69
167/* 70static int apci1564_timer_insn_write(struct comedi_device *dev,
168 * Start / Stop The Selected Timer or Counter 71 struct comedi_subdevice *s,
169 * 72 struct comedi_insn *insn,
170 * data[0] Configure as: 0 = Timer, 1 = Counter 73 unsigned int *data)
171 * data[1] 0 = Stop, 1 = Start, 2 = Trigger Clear (Only Counter)
172 */
173static int apci1564_timer_write(struct comedi_device *dev,
174 struct comedi_subdevice *s,
175 struct comedi_insn *insn,
176 unsigned int *data)
177{ 74{
178 struct apci1564_private *devpriv = dev->private; 75 struct apci1564_private *devpriv = dev->private;
179 unsigned int ul_Command1 = 0; 76 unsigned int ctrl;
77
78 ctrl = inl(devpriv->timer + ADDI_TCW_CTRL_REG);
79 switch (data[1]) {
80 case 0: /* Stop The Timer */
81 ctrl &= 0xfffff9fe;
82 break;
83 case 1: /* Enable the Timer */
84 ctrl &= 0xfffff9ff;
85 ctrl |= 0x1;
86 break;
87 }
88 outl(ctrl, devpriv->timer + ADDI_TCW_CTRL_REG);
180 89
181 if (devpriv->timer_select_mode == ADDIDATA_TIMER) { 90 return insn->n;
182 if (data[1] == 1) { 91}
183 ul_Command1 = inl(devpriv->amcc_iobase + APCI1564_TIMER_CTRL_REG);
184 ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x1UL;
185 92
186 /* Enable the Timer */ 93static int apci1564_timer_insn_read(struct comedi_device *dev,
187 outl(ul_Command1, devpriv->amcc_iobase + APCI1564_TIMER_CTRL_REG); 94 struct comedi_subdevice *s,
188 } else if (data[1] == 0) { 95 struct comedi_insn *insn,
189 /* Stop The Timer */ 96 unsigned int *data)
97{
98 struct apci1564_private *devpriv = dev->private;
99
100 /* Stores the status of the Timer */
101 data[0] = inl(devpriv->timer + ADDI_TCW_STATUS_REG) & 0x1;
102
103 /* Stores the Actual value of the Timer */
104 data[1] = inl(devpriv->timer + ADDI_TCW_VAL_REG);
190 105
191 ul_Command1 = inl(devpriv->amcc_iobase + APCI1564_TIMER_CTRL_REG);
192 ul_Command1 = ul_Command1 & 0xFFFFF9FEUL;
193 outl(ul_Command1, devpriv->amcc_iobase + APCI1564_TIMER_CTRL_REG);
194 }
195 } else if (devpriv->timer_select_mode == ADDIDATA_COUNTER) {
196 ul_Command1 =
197 inl(dev->iobase +
198 APCI1564_COUNTER_CTRL_REG(devpriv->mode_select_register - 1));
199 if (data[1] == 1) {
200 /* Start the Counter subdevice */
201 ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x1UL;
202 } else if (data[1] == 0) {
203 /* Stops the Counter subdevice */
204 ul_Command1 = 0;
205
206 } else if (data[1] == 2) {
207 /* Clears the Counter subdevice */
208 ul_Command1 = (ul_Command1 & 0xFFFFF9FFUL) | 0x400;
209 }
210 outl(ul_Command1, dev->iobase +
211 APCI1564_COUNTER_CTRL_REG(devpriv->mode_select_register - 1));
212 } else {
213 dev_err(dev->class_dev, "Invalid subdevice.\n");
214 }
215 return insn->n; 106 return insn->n;
216} 107}
217 108
218/* 109static int apci1564_counter_insn_config(struct comedi_device *dev,
219 * Read The Selected Timer or Counter 110 struct comedi_subdevice *s,
220 */ 111 struct comedi_insn *insn,
221static int apci1564_timer_read(struct comedi_device *dev, 112 unsigned int *data)
222 struct comedi_subdevice *s,
223 struct comedi_insn *insn,
224 unsigned int *data)
225{ 113{
226 struct apci1564_private *devpriv = dev->private; 114 struct apci1564_private *devpriv = dev->private;
227 unsigned int ul_Command1 = 0; 115 unsigned int chan = CR_CHAN(insn->chanspec);
228 116 unsigned long iobase = devpriv->counters + APCI1564_COUNTER(chan);
229 if (devpriv->timer_select_mode == ADDIDATA_TIMER) { 117 unsigned int ctrl;
230 /* Stores the status of the Timer */ 118
231 data[0] = inl(devpriv->amcc_iobase + APCI1564_TIMER_STATUS_REG) & 0x1; 119 devpriv->tsk_current = current;
232 120
233 /* Stores the Actual value of the Timer */ 121 /* First Stop The Counter */
234 data[1] = inl(devpriv->amcc_iobase + APCI1564_TIMER_REG); 122 ctrl = inl(iobase + ADDI_TCW_CTRL_REG);
235 } else if (devpriv->timer_select_mode == ADDIDATA_COUNTER) { 123 ctrl &= 0xfffff9fe;
236 /* Read the Counter Actual Value. */ 124 /* Stop The Timer */
237 data[0] = 125 outl(ctrl, iobase + ADDI_TCW_CTRL_REG);
238 inl(dev->iobase + 126
239 APCI1564_COUNTER_REG(devpriv->mode_select_register - 1)); 127 /* Set the reload value */
240 ul_Command1 = 128 outl(data[3], iobase + ADDI_TCW_RELOAD_REG);
241 inl(dev->iobase + 129
242 APCI1564_COUNTER_STATUS_REG(devpriv->mode_select_register - 1)); 130 /* Set the mode : */
243 131 /* - Disable the hardware */
244 /* Get the software trigger status */ 132 /* - Disable the counter mode */
245 data[1] = (unsigned char) ((ul_Command1 >> 1) & 1); 133 /* - Disable the warning */
246 134 /* - Disable the reset */
247 /* Get the hardware trigger status */ 135 /* - Disable the timer mode */
248 data[2] = (unsigned char) ((ul_Command1 >> 2) & 1); 136 /* - Enable the counter mode */
249 137
250 /* Get the software clear status */ 138 ctrl &= 0xfffc19e2;
251 data[3] = (unsigned char) ((ul_Command1 >> 3) & 1); 139 ctrl |= 0x80000 | (data[4] << 16);
252 140 outl(ctrl, iobase + ADDI_TCW_CTRL_REG);
253 /* Get the overflow status */ 141
254 data[4] = (unsigned char) ((ul_Command1 >> 0) & 1); 142 /* Enable or Disable Interrupt */
255 } else { 143 ctrl &= 0xfffff9fd;
256 dev_err(dev->class_dev, "Invalid subdevice.\n"); 144 ctrl |= (data[1] << 1);
145 outl(ctrl, iobase + ADDI_TCW_CTRL_REG);
146
147 /* Set the Up/Down selection */
148 ctrl &= 0xfffbf9ff;
149 ctrl |= (data[6] << 18);
150 outl(ctrl, iobase + ADDI_TCW_CTRL_REG);
151
152 return insn->n;
153}
154
155static int apci1564_counter_insn_write(struct comedi_device *dev,
156 struct comedi_subdevice *s,
157 struct comedi_insn *insn,
158 unsigned int *data)
159{
160 struct apci1564_private *devpriv = dev->private;
161 unsigned int chan = CR_CHAN(insn->chanspec);
162 unsigned long iobase = devpriv->counters + APCI1564_COUNTER(chan);
163 unsigned int ctrl;
164
165 ctrl = inl(iobase + ADDI_TCW_CTRL_REG);
166 switch (data[1]) {
167 case 0: /* Stops the Counter subdevice */
168 ctrl = 0;
169 break;
170 case 1: /* Start the Counter subdevice */
171 ctrl &= 0xfffff9ff;
172 ctrl |= 0x1;
173 break;
174 case 2: /* Clears the Counter subdevice */
175 ctrl &= 0xfffff9ff;
176 ctrl |= 0x400;
177 break;
257 } 178 }
179 outl(ctrl, iobase + ADDI_TCW_CTRL_REG);
180
181 return insn->n;
182}
183
184static int apci1564_counter_insn_read(struct comedi_device *dev,
185 struct comedi_subdevice *s,
186 struct comedi_insn *insn,
187 unsigned int *data)
188{
189 struct apci1564_private *devpriv = dev->private;
190 unsigned int chan = CR_CHAN(insn->chanspec);
191 unsigned long iobase = devpriv->counters + APCI1564_COUNTER(chan);
192 unsigned int status;
193
194 /* Read the Counter Actual Value. */
195 data[0] = inl(iobase + ADDI_TCW_VAL_REG);
196
197 status = inl(iobase + ADDI_TCW_STATUS_REG);
198 data[1] = (status >> 1) & 1; /* software trigger status */
199 data[2] = (status >> 2) & 1; /* hardware trigger status */
200 data[3] = (status >> 3) & 1; /* software clear status */
201 data[4] = (status >> 0) & 1; /* overflow status */
202
258 return insn->n; 203 return insn->n;
259} 204}
diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c
deleted file mode 100644
index 2950815b65f4..000000000000
--- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3120.c
+++ /dev/null
@@ -1,2050 +0,0 @@
1/**
2@verbatim
3
4Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
5
6 ADDI-DATA GmbH
7 Dieselstrasse 3
8 D-77833 Ottersweier
9 Tel: +19(0)7223/9493-0
10 Fax: +49(0)7223/9493-92
11 http://www.addi-data.com
12 info@addi-data.com
13
14This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
15
16This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17
18@endverbatim
19*/
20/*
21 +-----------------------------------------------------------------------+
22 | (C) ADDI-DATA GmbH Dieselstrasse 3 D-77833 Ottersweier |
23 +-----------------------------------------------------------------------+
24 | Tel : +49 (0) 7223/9493-0 | email : info@addi-data.com |
25 | Fax : +49 (0) 7223/9493-92 | Internet : http://www.addi-data.com |
26 +-----------------------------------------------------------------------+
27 | Project : APCI-3120 | Compiler : GCC |
28 | Module name : hwdrv_apci3120.c| Version : 2.96 |
29 +-------------------------------+---------------------------------------+
30 | Project manager: Eric Stolz | Date : 02/12/2002 |
31 +-----------------------------------------------------------------------+
32 | Description :APCI3120 Module. Hardware abstraction Layer for APCI3120|
33 +-----------------------------------------------------------------------+
34 | UPDATE'S |
35 +-----------------------------------------------------------------------+
36 | Date | Author | Description of updates |
37 +----------+-----------+------------------------------------------------+
38 | | | |
39 | | | |
40 +----------+-----------+------------------------------------------------+
41*/
42
43#include <linux/delay.h>
44
45/*
46 * ADDON RELATED ADDITIONS
47 */
48/* Constant */
49#define APCI3120_ENABLE_TRANSFER_ADD_ON_LOW 0x00
50#define APCI3120_ENABLE_TRANSFER_ADD_ON_HIGH 0x1200
51#define APCI3120_A2P_FIFO_MANAGEMENT 0x04000400L
52#define APCI3120_AMWEN_ENABLE 0x02
53#define APCI3120_A2P_FIFO_WRITE_ENABLE 0x01
54#define APCI3120_FIFO_ADVANCE_ON_BYTE_2 0x20000000L
55#define APCI3120_ENABLE_WRITE_TC_INT 0x00004000L
56#define APCI3120_CLEAR_WRITE_TC_INT 0x00040000L
57#define APCI3120_DISABLE_AMWEN_AND_A2P_FIFO_WRITE 0x0
58#define APCI3120_DISABLE_BUS_MASTER_ADD_ON 0x0
59#define APCI3120_DISABLE_BUS_MASTER_PCI 0x0
60
61/* ADD_ON ::: this needed since apci supports 16 bit interface to add on */
62#define APCI3120_ADD_ON_AGCSTS_LOW 0x3C
63#define APCI3120_ADD_ON_AGCSTS_HIGH (APCI3120_ADD_ON_AGCSTS_LOW + 2)
64#define APCI3120_ADD_ON_MWAR_LOW 0x24
65#define APCI3120_ADD_ON_MWAR_HIGH (APCI3120_ADD_ON_MWAR_LOW + 2)
66#define APCI3120_ADD_ON_MWTC_LOW 0x058
67#define APCI3120_ADD_ON_MWTC_HIGH (APCI3120_ADD_ON_MWTC_LOW + 2)
68
69/* AMCC */
70#define APCI3120_AMCC_OP_MCSR 0x3C
71#define APCI3120_AMCC_OP_REG_INTCSR 0x38
72
73/* for transfer count enable bit */
74#define AGCSTS_TC_ENABLE 0x10000000
75
76/* used for test on mixture of BIP/UNI ranges */
77#define APCI3120_BIPOLAR_RANGES 4
78
79#define APCI3120_ADDRESS_RANGE 16
80
81#define APCI3120_DISABLE 0
82#define APCI3120_ENABLE 1
83
84#define APCI3120_START 1
85#define APCI3120_STOP 0
86
87#define APCI3120_EOC_MODE 1
88#define APCI3120_EOS_MODE 2
89#define APCI3120_DMA_MODE 3
90
91/* DIGITAL INPUT-OUTPUT DEFINE */
92
93#define APCI3120_DIGITAL_OUTPUT 0x0d
94#define APCI3120_RD_STATUS 0x02
95#define APCI3120_RD_FIFO 0x00
96
97/* digital output insn_write ON /OFF selection */
98#define APCI3120_SET4DIGITALOUTPUTON 1
99#define APCI3120_SET4DIGITALOUTPUTOFF 0
100
101/* analog output SELECT BIT */
102#define APCI3120_ANALOG_OP_CHANNEL_1 0x0000
103#define APCI3120_ANALOG_OP_CHANNEL_2 0x4000
104#define APCI3120_ANALOG_OP_CHANNEL_3 0x8000
105#define APCI3120_ANALOG_OP_CHANNEL_4 0xc000
106#define APCI3120_ANALOG_OP_CHANNEL_5 0x0000
107#define APCI3120_ANALOG_OP_CHANNEL_6 0x4000
108#define APCI3120_ANALOG_OP_CHANNEL_7 0x8000
109#define APCI3120_ANALOG_OP_CHANNEL_8 0xc000
110
111/* Enable external trigger bit in nWrAddress */
112#define APCI3120_ENABLE_EXT_TRIGGER 0x8000
113
114/* ANALOG OUTPUT AND INPUT DEFINE */
115#define APCI3120_UNIPOLAR 0x80
116#define APCI3120_BIPOLAR 0x00
117#define APCI3120_ANALOG_OUTPUT_1 0x08
118#define APCI3120_ANALOG_OUTPUT_2 0x0a
119#define APCI3120_1_GAIN 0x00
120#define APCI3120_2_GAIN 0x10
121#define APCI3120_5_GAIN 0x20
122#define APCI3120_10_GAIN 0x30
123#define APCI3120_SEQ_RAM_ADDRESS 0x06
124#define APCI3120_RESET_FIFO 0x0c
125#define APCI3120_TIMER_0_MODE_2 0x01
126#define APCI3120_TIMER_0_MODE_4 0x2
127#define APCI3120_SELECT_TIMER_0_WORD 0x00
128#define APCI3120_ENABLE_TIMER0 0x1000
129#define APCI3120_CLEAR_PR 0xf0ff
130#define APCI3120_CLEAR_PA 0xfff0
131#define APCI3120_CLEAR_PA_PR (APCI3120_CLEAR_PR & APCI3120_CLEAR_PA)
132
133/* nWrMode_Select */
134#define APCI3120_ENABLE_SCAN 0x8
135#define APCI3120_DISABLE_SCAN (~APCI3120_ENABLE_SCAN)
136#define APCI3120_ENABLE_EOS_INT 0x2
137
138#define APCI3120_DISABLE_EOS_INT (~APCI3120_ENABLE_EOS_INT)
139#define APCI3120_ENABLE_EOC_INT 0x1
140#define APCI3120_DISABLE_EOC_INT (~APCI3120_ENABLE_EOC_INT)
141#define APCI3120_DISABLE_ALL_INTERRUPT_WITHOUT_TIMER \
142 (APCI3120_DISABLE_EOS_INT & APCI3120_DISABLE_EOC_INT)
143#define APCI3120_DISABLE_ALL_INTERRUPT \
144 (APCI3120_DISABLE_TIMER_INT & APCI3120_DISABLE_EOS_INT & APCI3120_DISABLE_EOC_INT)
145
146/* status register bits */
147#define APCI3120_EOC 0x8000
148#define APCI3120_EOS 0x2000
149
150/* software trigger dummy register */
151#define APCI3120_START_CONVERSION 0x02
152
153/* TIMER DEFINE */
154#define APCI3120_QUARTZ_A 70
155#define APCI3120_QUARTZ_B 50
156#define APCI3120_TIMER 1
157#define APCI3120_WATCHDOG 2
158#define APCI3120_TIMER_DISABLE 0
159#define APCI3120_TIMER_ENABLE 1
160#define APCI3120_ENABLE_TIMER2 0x4000
161#define APCI3120_DISABLE_TIMER2 (~APCI3120_ENABLE_TIMER2)
162#define APCI3120_ENABLE_TIMER_INT 0x04
163#define APCI3120_DISABLE_TIMER_INT (~APCI3120_ENABLE_TIMER_INT)
164#define APCI3120_WRITE_MODE_SELECT 0x0e
165#define APCI3120_SELECT_TIMER_0_WORD 0x00
166#define APCI3120_SELECT_TIMER_1_WORD 0x01
167#define APCI3120_TIMER_1_MODE_2 0x4
168
169/* $$ BIT FOR MODE IN nCsTimerCtr1 */
170#define APCI3120_TIMER_2_MODE_0 0x0
171#define APCI3120_TIMER_2_MODE_2 0x10
172#define APCI3120_TIMER_2_MODE_5 0x30
173
174/* $$ BIT FOR MODE IN nCsTimerCtr0 */
175#define APCI3120_SELECT_TIMER_2_LOW_WORD 0x02
176#define APCI3120_SELECT_TIMER_2_HIGH_WORD 0x03
177
178#define APCI3120_TIMER_CRT0 0x0d
179#define APCI3120_TIMER_CRT1 0x0c
180
181#define APCI3120_TIMER_VALUE 0x04
182#define APCI3120_TIMER_STATUS_REGISTER 0x0d
183#define APCI3120_RD_STATUS 0x02
184#define APCI3120_WR_ADDRESS 0x00
185#define APCI3120_ENABLE_WATCHDOG 0x20
186#define APCI3120_DISABLE_WATCHDOG (~APCI3120_ENABLE_WATCHDOG)
187#define APCI3120_ENABLE_TIMER_COUNTER 0x10
188#define APCI3120_DISABLE_TIMER_COUNTER (~APCI3120_ENABLE_TIMER_COUNTER)
189#define APCI3120_FC_TIMER 0x1000
190#define APCI3120_ENABLE_TIMER0 0x1000
191#define APCI3120_ENABLE_TIMER1 0x2000
192#define APCI3120_ENABLE_TIMER2 0x4000
193#define APCI3120_DISABLE_TIMER0 (~APCI3120_ENABLE_TIMER0)
194#define APCI3120_DISABLE_TIMER1 (~APCI3120_ENABLE_TIMER1)
195#define APCI3120_DISABLE_TIMER2 (~APCI3120_ENABLE_TIMER2)
196
197#define APCI3120_TIMER2_SELECT_EOS 0xc0
198#define APCI3120_COUNTER 3
199#define APCI3120_DISABLE_ALL_TIMER (APCI3120_DISABLE_TIMER0 & \
200 APCI3120_DISABLE_TIMER1 & \
201 APCI3120_DISABLE_TIMER2)
202
203#define MAX_ANALOGINPUT_CHANNELS 32
204
205struct str_AnalogReadInformation {
206 /* EOC or EOS */
207 unsigned char b_Type;
208 /* Interrupt use or not */
209 unsigned char b_InterruptFlag;
210 /* Selection of the conversion time */
211 unsigned int ui_ConvertTiming;
212 /* Number of channel to read */
213 unsigned char b_NbrOfChannel;
214 /* Number of the channel to be read */
215 unsigned int ui_ChannelList[MAX_ANALOGINPUT_CHANNELS];
216 /* Gain of each channel */
217 unsigned int ui_RangeList[MAX_ANALOGINPUT_CHANNELS];
218};
219
220/* ANALOG INPUT RANGE */
221static const struct comedi_lrange range_apci3120_ai = {
222 8, {
223 BIP_RANGE(10),
224 BIP_RANGE(5),
225 BIP_RANGE(2),
226 BIP_RANGE(1),
227 UNI_RANGE(10),
228 UNI_RANGE(5),
229 UNI_RANGE(2),
230 UNI_RANGE(1)
231 }
232};
233
234/* ANALOG OUTPUT RANGE */
235static const struct comedi_lrange range_apci3120_ao = {
236 2, {
237 BIP_RANGE(10),
238 UNI_RANGE(10)
239 }
240};
241
242
243/* FUNCTION DEFINITIONS */
244static int apci3120_ai_insn_config(struct comedi_device *dev,
245 struct comedi_subdevice *s,
246 struct comedi_insn *insn,
247 unsigned int *data)
248{
249 const struct addi_board *this_board = dev->board_ptr;
250 struct addi_private *devpriv = dev->private;
251 unsigned int i;
252
253 if ((data[0] != APCI3120_EOC_MODE) && (data[0] != APCI3120_EOS_MODE))
254 return -1;
255
256 /* Check for Conversion time to be added */
257 devpriv->ui_EocEosConversionTime = data[2];
258
259 if (data[0] == APCI3120_EOS_MODE) {
260
261 /* Test the number of the channel */
262 for (i = 0; i < data[3]; i++) {
263
264 if (CR_CHAN(data[4 + i]) >=
265 this_board->i_NbrAiChannel) {
266 dev_err(dev->class_dev, "bad channel list\n");
267 return -2;
268 }
269 }
270
271 devpriv->b_InterruptMode = APCI3120_EOS_MODE;
272
273 if (data[1])
274 devpriv->b_EocEosInterrupt = APCI3120_ENABLE;
275 else
276 devpriv->b_EocEosInterrupt = APCI3120_DISABLE;
277 /* Copy channel list and Range List to devpriv */
278 devpriv->ui_AiNbrofChannels = data[3];
279 for (i = 0; i < devpriv->ui_AiNbrofChannels; i++)
280 devpriv->ui_AiChannelList[i] = data[4 + i];
281
282 } else { /* EOC */
283 devpriv->b_InterruptMode = APCI3120_EOC_MODE;
284 if (data[1])
285 devpriv->b_EocEosInterrupt = APCI3120_ENABLE;
286 else
287 devpriv->b_EocEosInterrupt = APCI3120_DISABLE;
288 }
289
290 return insn->n;
291}
292
293/*
294 * This function will first check channel list is ok or not and then
295 * initialize the sequence RAM with the polarity, Gain,Channel number.
296 * If the last argument of function "check"is 1 then it only checks
297 * the channel list is ok or not.
298 */
299static int apci3120_setup_chan_list(struct comedi_device *dev,
300 struct comedi_subdevice *s,
301 int n_chan,
302 unsigned int *chanlist,
303 char check)
304{
305 struct addi_private *devpriv = dev->private;
306 unsigned int i;
307 unsigned int gain;
308 unsigned short us_TmpValue;
309
310 /* correct channel and range number check itself comedi/range.c */
311 if (n_chan < 1) {
312 if (!check)
313 dev_err(dev->class_dev,
314 "range/channel list is empty!\n");
315 return 0;
316 }
317 /* All is ok, so we can setup channel/range list */
318 if (check)
319 return 1;
320
321 /* Code to set the PA and PR...Here it set PA to 0 */
322 devpriv->us_OutputRegister =
323 devpriv->us_OutputRegister & APCI3120_CLEAR_PA_PR;
324 devpriv->us_OutputRegister = ((n_chan - 1) & 0xf) << 8;
325 outw(devpriv->us_OutputRegister, dev->iobase + APCI3120_WR_ADDRESS);
326
327 for (i = 0; i < n_chan; i++) {
328 /* store range list to card */
329 us_TmpValue = CR_CHAN(chanlist[i]); /* get channel number */
330
331 if (CR_RANGE(chanlist[i]) < APCI3120_BIPOLAR_RANGES)
332 us_TmpValue &= ((~APCI3120_UNIPOLAR) & 0xff); /* set bipolar */
333 else
334 us_TmpValue |= APCI3120_UNIPOLAR; /* enable unipolar */
335
336 gain = CR_RANGE(chanlist[i]); /* get gain number */
337 us_TmpValue |= ((gain & 0x03) << 4); /* <<4 for G0 and G1 bit in RAM */
338 us_TmpValue |= i << 8; /* To select the RAM LOCATION */
339 outw(us_TmpValue, dev->iobase + APCI3120_SEQ_RAM_ADDRESS);
340 }
341 return 1; /* we can serve this with scan logic */
342}
343
344/*
345 * Reads analog input in synchronous mode EOC and EOS is selected
346 * as per configured if no conversion time is set uses default
347 * conversion time 10 microsec.
348 */
349static int apci3120_ai_insn_read(struct comedi_device *dev,
350 struct comedi_subdevice *s,
351 struct comedi_insn *insn,
352 unsigned int *data)
353{
354 const struct addi_board *this_board = dev->board_ptr;
355 struct addi_private *devpriv = dev->private;
356 unsigned short us_ConvertTiming, us_TmpValue, i;
357 unsigned char b_Tmp;
358
359 /* fix conversion time to 10 us */
360 if (!devpriv->ui_EocEosConversionTime)
361 us_ConvertTiming = 10;
362 else
363 us_ConvertTiming = (unsigned short) (devpriv->ui_EocEosConversionTime / 1000); /* nano to useconds */
364
365 /* Clear software registers */
366 devpriv->b_TimerSelectMode = 0;
367 devpriv->b_ModeSelectRegister = 0;
368 devpriv->us_OutputRegister = 0;
369
370 if (insn->unused[0] == 222) { /* second insn read */
371 for (i = 0; i < insn->n; i++)
372 data[i] = devpriv->ui_AiReadData[i];
373 } else {
374 devpriv->tsk_Current = current; /* Save the current process task structure */
375
376 /*
377 * Testing if board have the new Quartz and calculate the time value
378 * to set in the timer
379 */
380 us_TmpValue =
381 (unsigned short) inw(devpriv->iobase + APCI3120_RD_STATUS);
382
383 /* EL250804: Testing if board APCI3120 have the new Quartz or if it is an APCI3001 */
384 if ((us_TmpValue & 0x00B0) == 0x00B0
385 || !strcmp(this_board->pc_DriverName, "apci3001")) {
386 us_ConvertTiming = (us_ConvertTiming * 2) - 2;
387 } else {
388 us_ConvertTiming =
389 ((us_ConvertTiming * 12926) / 10000) - 1;
390 }
391
392 us_TmpValue = (unsigned short) devpriv->b_InterruptMode;
393
394 switch (us_TmpValue) {
395
396 case APCI3120_EOC_MODE:
397
398 /*
399 * Testing the interrupt flag and set the EOC bit Clears the FIFO
400 */
401 inw(devpriv->iobase + APCI3120_RESET_FIFO);
402
403 /* Initialize the sequence array */
404 if (!apci3120_setup_chan_list(dev, s, 1,
405 &insn->chanspec, 0))
406 return -EINVAL;
407
408 /* Initialize Timer 0 mode 4 */
409 devpriv->b_TimerSelectMode =
410 (devpriv->
411 b_TimerSelectMode & 0xFC) |
412 APCI3120_TIMER_0_MODE_4;
413 outb(devpriv->b_TimerSelectMode,
414 devpriv->iobase + APCI3120_TIMER_CRT1);
415
416 /* Reset the scan bit and Disables the EOS, DMA, EOC interrupt */
417 devpriv->b_ModeSelectRegister =
418 devpriv->
419 b_ModeSelectRegister & APCI3120_DISABLE_SCAN;
420
421 if (devpriv->b_EocEosInterrupt == APCI3120_ENABLE) {
422
423 /* Disables the EOS,DMA and enables the EOC interrupt */
424 devpriv->b_ModeSelectRegister =
425 (devpriv->
426 b_ModeSelectRegister &
427 APCI3120_DISABLE_EOS_INT) |
428 APCI3120_ENABLE_EOC_INT;
429 inw(devpriv->iobase);
430
431 } else {
432 devpriv->b_ModeSelectRegister =
433 devpriv->
434 b_ModeSelectRegister &
435 APCI3120_DISABLE_ALL_INTERRUPT_WITHOUT_TIMER;
436 }
437
438 outb(devpriv->b_ModeSelectRegister,
439 devpriv->iobase + APCI3120_WRITE_MODE_SELECT);
440
441 /* Sets gate 0 */
442 devpriv->us_OutputRegister =
443 (devpriv->
444 us_OutputRegister & APCI3120_CLEAR_PA_PR) |
445 APCI3120_ENABLE_TIMER0;
446 outw(devpriv->us_OutputRegister,
447 devpriv->iobase + APCI3120_WR_ADDRESS);
448
449 /* Select Timer 0 */
450 b_Tmp = ((devpriv->
451 b_DigitalOutputRegister) & 0xF0) |
452 APCI3120_SELECT_TIMER_0_WORD;
453 outb(b_Tmp, devpriv->iobase + APCI3120_TIMER_CRT0);
454
455 /* Set the conversion time */
456 outw(us_ConvertTiming,
457 devpriv->iobase + APCI3120_TIMER_VALUE);
458
459 us_TmpValue =
460 (unsigned short) inw(dev->iobase + APCI3120_RD_STATUS);
461
462 if (devpriv->b_EocEosInterrupt == APCI3120_DISABLE) {
463
464 do {
465 /* Waiting for the end of conversion */
466 us_TmpValue =
467 inw(devpriv->iobase +
468 APCI3120_RD_STATUS);
469 } while ((us_TmpValue & APCI3120_EOC) ==
470 APCI3120_EOC);
471
472 /* Read the result in FIFO and put it in insn data pointer */
473 us_TmpValue = inw(devpriv->iobase + 0);
474 *data = us_TmpValue;
475
476 inw(devpriv->iobase + APCI3120_RESET_FIFO);
477 }
478
479 break;
480
481 case APCI3120_EOS_MODE:
482
483 inw(devpriv->iobase);
484 /* Clears the FIFO */
485 inw(devpriv->iobase + APCI3120_RESET_FIFO);
486 /* clear PA PR and disable timer 0 */
487
488 devpriv->us_OutputRegister =
489 (devpriv->
490 us_OutputRegister & APCI3120_CLEAR_PA_PR) |
491 APCI3120_DISABLE_TIMER0;
492
493 outw(devpriv->us_OutputRegister,
494 devpriv->iobase + APCI3120_WR_ADDRESS);
495
496 if (!apci3120_setup_chan_list(dev, s,
497 devpriv->ui_AiNbrofChannels,
498 devpriv->ui_AiChannelList, 0))
499 return -EINVAL;
500
501 /* Initialize Timer 0 mode 2 */
502 devpriv->b_TimerSelectMode =
503 (devpriv->
504 b_TimerSelectMode & 0xFC) |
505 APCI3120_TIMER_0_MODE_2;
506 outb(devpriv->b_TimerSelectMode,
507 devpriv->iobase + APCI3120_TIMER_CRT1);
508
509 /* Select Timer 0 */
510 b_Tmp = ((devpriv->
511 b_DigitalOutputRegister) & 0xF0) |
512 APCI3120_SELECT_TIMER_0_WORD;
513 outb(b_Tmp, devpriv->iobase + APCI3120_TIMER_CRT0);
514
515 /* Set the conversion time */
516 outw(us_ConvertTiming,
517 devpriv->iobase + APCI3120_TIMER_VALUE);
518
519 /* Set the scan bit */
520 devpriv->b_ModeSelectRegister =
521 devpriv->
522 b_ModeSelectRegister | APCI3120_ENABLE_SCAN;
523 outb(devpriv->b_ModeSelectRegister,
524 devpriv->iobase + APCI3120_WRITE_MODE_SELECT);
525
526 /* If Interrupt function is loaded */
527 if (devpriv->b_EocEosInterrupt == APCI3120_ENABLE) {
528 /* Disables the EOC,DMA and enables the EOS interrupt */
529 devpriv->b_ModeSelectRegister =
530 (devpriv->
531 b_ModeSelectRegister &
532 APCI3120_DISABLE_EOC_INT) |
533 APCI3120_ENABLE_EOS_INT;
534 inw(devpriv->iobase);
535
536 } else
537 devpriv->b_ModeSelectRegister =
538 devpriv->
539 b_ModeSelectRegister &
540 APCI3120_DISABLE_ALL_INTERRUPT_WITHOUT_TIMER;
541
542 outb(devpriv->b_ModeSelectRegister,
543 devpriv->iobase + APCI3120_WRITE_MODE_SELECT);
544
545 inw(devpriv->iobase + APCI3120_RD_STATUS);
546
547 /* Sets gate 0 */
548 devpriv->us_OutputRegister =
549 devpriv->
550 us_OutputRegister | APCI3120_ENABLE_TIMER0;
551 outw(devpriv->us_OutputRegister,
552 devpriv->iobase + APCI3120_WR_ADDRESS);
553
554 /* Start conversion */
555 outw(0, devpriv->iobase + APCI3120_START_CONVERSION);
556
557 /* Waiting of end of conversion if interrupt is not installed */
558 if (devpriv->b_EocEosInterrupt == APCI3120_DISABLE) {
559 /* Waiting the end of conversion */
560 do {
561 us_TmpValue =
562 inw(devpriv->iobase +
563 APCI3120_RD_STATUS);
564 } while ((us_TmpValue & APCI3120_EOS) !=
565 APCI3120_EOS);
566
567 for (i = 0; i < devpriv->ui_AiNbrofChannels;
568 i++) {
569 /* Read the result in FIFO and write them in shared memory */
570 us_TmpValue = inw(devpriv->iobase);
571 data[i] = (unsigned int) us_TmpValue;
572 }
573
574 devpriv->b_InterruptMode = APCI3120_EOC_MODE; /* Restore defaults */
575 }
576 break;
577
578 default:
579 dev_err(dev->class_dev, "inputs wrong\n");
580
581 }
582 devpriv->ui_EocEosConversionTime = 0; /* re initializing the variable */
583 }
584
585 return insn->n;
586
587}
588
589static int apci3120_reset(struct comedi_device *dev)
590{
591 struct addi_private *devpriv = dev->private;
592 unsigned int i;
593 unsigned short us_TmpValue;
594
595 devpriv->ai_running = 0;
596 devpriv->b_EocEosInterrupt = APCI3120_DISABLE;
597 devpriv->b_InterruptMode = APCI3120_EOC_MODE;
598 devpriv->ui_EocEosConversionTime = 0; /* set eoc eos conv time to 0 */
599
600 /* variables used in timer subdevice */
601 devpriv->b_Timer2Mode = 0;
602 devpriv->b_Timer2Interrupt = 0;
603 devpriv->b_ExttrigEnable = 0; /* Disable ext trigger */
604
605 /* Disable all interrupts, watchdog for the anolog output */
606 devpriv->b_ModeSelectRegister = 0;
607 outb(devpriv->b_ModeSelectRegister,
608 dev->iobase + APCI3120_WRITE_MODE_SELECT);
609
610 /* Disables all counters, ext trigger and clears PA, PR */
611 devpriv->us_OutputRegister = 0;
612 outw(devpriv->us_OutputRegister, dev->iobase + APCI3120_WR_ADDRESS);
613
614 /*
615 * Code to set the all anolog o/p channel to 0v 8191 is decimal
616 * value for zero(0 v)volt in bipolar mode(default)
617 */
618 outw(8191 | APCI3120_ANALOG_OP_CHANNEL_1, dev->iobase + APCI3120_ANALOG_OUTPUT_1); /* channel 1 */
619 outw(8191 | APCI3120_ANALOG_OP_CHANNEL_2, dev->iobase + APCI3120_ANALOG_OUTPUT_1); /* channel 2 */
620 outw(8191 | APCI3120_ANALOG_OP_CHANNEL_3, dev->iobase + APCI3120_ANALOG_OUTPUT_1); /* channel 3 */
621 outw(8191 | APCI3120_ANALOG_OP_CHANNEL_4, dev->iobase + APCI3120_ANALOG_OUTPUT_1); /* channel 4 */
622
623 outw(8191 | APCI3120_ANALOG_OP_CHANNEL_5, dev->iobase + APCI3120_ANALOG_OUTPUT_2); /* channel 5 */
624 outw(8191 | APCI3120_ANALOG_OP_CHANNEL_6, dev->iobase + APCI3120_ANALOG_OUTPUT_2); /* channel 6 */
625 outw(8191 | APCI3120_ANALOG_OP_CHANNEL_7, dev->iobase + APCI3120_ANALOG_OUTPUT_2); /* channel 7 */
626 outw(8191 | APCI3120_ANALOG_OP_CHANNEL_8, dev->iobase + APCI3120_ANALOG_OUTPUT_2); /* channel 8 */
627
628 udelay(10);
629
630 inw(dev->iobase + 0); /* make a dummy read */
631 inb(dev->iobase + APCI3120_RESET_FIFO); /* flush FIFO */
632 inw(dev->iobase + APCI3120_RD_STATUS); /* flush A/D status register */
633
634 /* code to reset the RAM sequence */
635 for (i = 0; i < 16; i++) {
636 us_TmpValue = i << 8; /* select the location */
637 outw(us_TmpValue, dev->iobase + APCI3120_SEQ_RAM_ADDRESS);
638 }
639 return 0;
640}
641
642static int apci3120_exttrig_enable(struct comedi_device *dev)
643{
644 struct addi_private *devpriv = dev->private;
645
646 devpriv->us_OutputRegister |= APCI3120_ENABLE_EXT_TRIGGER;
647 outw(devpriv->us_OutputRegister, dev->iobase + APCI3120_WR_ADDRESS);
648 return 0;
649}
650
651static int apci3120_exttrig_disable(struct comedi_device *dev)
652{
653 struct addi_private *devpriv = dev->private;
654
655 devpriv->us_OutputRegister &= ~APCI3120_ENABLE_EXT_TRIGGER;
656 outw(devpriv->us_OutputRegister, dev->iobase + APCI3120_WR_ADDRESS);
657 return 0;
658}
659
660static int apci3120_cancel(struct comedi_device *dev,
661 struct comedi_subdevice *s)
662{
663 struct addi_private *devpriv = dev->private;
664
665 /* Disable A2P Fifo write and AMWEN signal */
666 outw(0, devpriv->i_IobaseAddon + 4);
667
668 /* Disable Bus Master ADD ON */
669 outw(APCI3120_ADD_ON_AGCSTS_LOW, devpriv->i_IobaseAddon + 0);
670 outw(0, devpriv->i_IobaseAddon + 2);
671 outw(APCI3120_ADD_ON_AGCSTS_HIGH, devpriv->i_IobaseAddon + 0);
672 outw(0, devpriv->i_IobaseAddon + 2);
673
674 /* Disable BUS Master PCI */
675 outl(0, devpriv->i_IobaseAmcc + AMCC_OP_REG_MCSR);
676
677 /* Disable ext trigger */
678 apci3120_exttrig_disable(dev);
679
680 devpriv->us_OutputRegister = 0;
681 /* stop counters */
682 outw(devpriv->
683 us_OutputRegister & APCI3120_DISABLE_TIMER0 &
684 APCI3120_DISABLE_TIMER1, dev->iobase + APCI3120_WR_ADDRESS);
685
686 outw(APCI3120_DISABLE_ALL_TIMER, dev->iobase + APCI3120_WR_ADDRESS);
687
688 /* DISABLE_ALL_INTERRUPT */
689 outb(APCI3120_DISABLE_ALL_INTERRUPT,
690 dev->iobase + APCI3120_WRITE_MODE_SELECT);
691 /* Flush FIFO */
692 inb(dev->iobase + APCI3120_RESET_FIFO);
693 inw(dev->iobase + APCI3120_RD_STATUS);
694 devpriv->ui_AiActualScan = 0;
695 s->async->cur_chan = 0;
696 devpriv->ui_DmaActualBuffer = 0;
697
698 devpriv->ai_running = 0;
699 devpriv->b_InterruptMode = APCI3120_EOC_MODE;
700 devpriv->b_EocEosInterrupt = APCI3120_DISABLE;
701 apci3120_reset(dev);
702 return 0;
703}
704
705static int apci3120_ai_cmdtest(struct comedi_device *dev,
706 struct comedi_subdevice *s,
707 struct comedi_cmd *cmd)
708{
709 int err = 0;
710
711 /* Step 1 : check if triggers are trivially valid */
712
713 err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_EXT);
714 err |= cfc_check_trigger_src(&cmd->scan_begin_src,
715 TRIG_TIMER | TRIG_FOLLOW);
716 err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_TIMER);
717 err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
718 err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
719
720 if (err)
721 return 1;
722
723 /* Step 2a : make sure trigger sources are unique */
724
725 err |= cfc_check_trigger_is_unique(cmd->start_src);
726 err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
727 err |= cfc_check_trigger_is_unique(cmd->stop_src);
728
729 /* Step 2b : and mutually compatible */
730
731 if (err)
732 return 2;
733
734 /* Step 3: check if arguments are trivially valid */
735
736 err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
737
738 if (cmd->scan_begin_src == TRIG_TIMER) /* Test Delay timing */
739 err |= cfc_check_trigger_arg_min(&cmd->scan_begin_arg, 100000);
740
741 if (cmd->scan_begin_src == TRIG_TIMER) {
742 if (cmd->convert_arg)
743 err |= cfc_check_trigger_arg_min(&cmd->convert_arg,
744 10000);
745 } else {
746 err |= cfc_check_trigger_arg_min(&cmd->convert_arg, 10000);
747 }
748
749 err |= cfc_check_trigger_arg_min(&cmd->chanlist_len, 1);
750 err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len);
751
752 if (cmd->stop_src == TRIG_COUNT)
753 err |= cfc_check_trigger_arg_min(&cmd->stop_arg, 1);
754 else /* TRIG_NONE */
755 err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0);
756
757 if (err)
758 return 3;
759
760 /* step 4: fix up any arguments */
761
762 if (cmd->scan_begin_src == TRIG_TIMER &&
763 cmd->scan_begin_arg < cmd->convert_arg * cmd->scan_end_arg) {
764 cmd->scan_begin_arg = cmd->convert_arg * cmd->scan_end_arg;
765 err |= -EINVAL;
766 }
767
768 if (err)
769 return 4;
770
771 return 0;
772}
773
774/*
775 * This is used for analog input cyclic acquisition.
776 * Performs the command operations.
777 * If DMA is configured does DMA initialization otherwise does the
778 * acquisition with EOS interrupt.
779 */
780static int apci3120_cyclic_ai(int mode,
781 struct comedi_device *dev,
782 struct comedi_subdevice *s)
783{
784 const struct addi_board *this_board = dev->board_ptr;
785 struct addi_private *devpriv = dev->private;
786 struct comedi_cmd *cmd = &s->async->cmd;
787 unsigned char b_Tmp;
788 unsigned int ui_Tmp, ui_DelayTiming = 0, ui_TimerValue1 = 0, dmalen0 =
789 0, dmalen1 = 0, ui_TimerValue2 =
790 0, ui_TimerValue0, ui_ConvertTiming;
791 unsigned short us_TmpValue;
792
793 /* Resets the FIFO */
794 inb(dev->iobase + APCI3120_RESET_FIFO);
795
796 devpriv->ai_running = 1;
797
798 /* clear software registers */
799 devpriv->b_TimerSelectMode = 0;
800 devpriv->us_OutputRegister = 0;
801 devpriv->b_ModeSelectRegister = 0;
802
803 /* Clear Timer Write TC int */
804 outl(APCI3120_CLEAR_WRITE_TC_INT,
805 devpriv->i_IobaseAmcc + APCI3120_AMCC_OP_REG_INTCSR);
806
807 /* Disables All Timer */
808 /* Sets PR and PA to 0 */
809 devpriv->us_OutputRegister = devpriv->us_OutputRegister &
810 APCI3120_DISABLE_TIMER0 &
811 APCI3120_DISABLE_TIMER1 & APCI3120_CLEAR_PA_PR;
812
813 outw(devpriv->us_OutputRegister, dev->iobase + APCI3120_WR_ADDRESS);
814
815 /* Resets the FIFO */
816 /* BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver */
817 inb(devpriv->iobase + APCI3120_RESET_FIFO);
818 /* END JK 07.05.04: Comparison between WIN32 and Linux driver */
819
820 devpriv->ui_AiActualScan = 0;
821 s->async->cur_chan = 0;
822 devpriv->ui_DmaActualBuffer = 0;
823
824 /* value for timer2 minus -2 has to be done */
825 ui_TimerValue2 = cmd->stop_arg - 2;
826 ui_ConvertTiming = cmd->convert_arg;
827
828 if (mode == 2)
829 ui_DelayTiming = cmd->scan_begin_arg;
830
831 /* Initializes the sequence array */
832 if (!apci3120_setup_chan_list(dev, s, devpriv->ui_AiNbrofChannels,
833 cmd->chanlist, 0))
834 return -EINVAL;
835
836 us_TmpValue = (unsigned short) inw(dev->iobase + APCI3120_RD_STATUS);
837
838 /* EL241003 Begin: add this section to replace floats calculation by integer calculations */
839 /* EL250804: Testing if board APCI3120 have the new Quartz or if it is an APCI3001 */
840 if ((us_TmpValue & 0x00B0) == 0x00B0
841 || !strcmp(this_board->pc_DriverName, "apci3001")) {
842 ui_TimerValue0 = ui_ConvertTiming * 2 - 2000;
843 ui_TimerValue0 = ui_TimerValue0 / 1000;
844
845 if (mode == 2) {
846 ui_DelayTiming = ui_DelayTiming / 1000;
847 ui_TimerValue1 = ui_DelayTiming * 2 - 200;
848 ui_TimerValue1 = ui_TimerValue1 / 100;
849 }
850 } else {
851 ui_ConvertTiming = ui_ConvertTiming / 1000;
852 ui_TimerValue0 = ui_ConvertTiming * 12926 - 10000;
853 ui_TimerValue0 = ui_TimerValue0 / 10000;
854
855 if (mode == 2) {
856 ui_DelayTiming = ui_DelayTiming / 1000;
857 ui_TimerValue1 = ui_DelayTiming * 12926 - 1;
858 ui_TimerValue1 = ui_TimerValue1 / 1000000;
859 }
860 }
861 /* EL241003 End */
862
863 if (devpriv->b_ExttrigEnable == APCI3120_ENABLE)
864 apci3120_exttrig_enable(dev); /* activate EXT trigger */
865 switch (mode) {
866 case 1:
867 /* init timer0 in mode 2 */
868 devpriv->b_TimerSelectMode =
869 (devpriv->
870 b_TimerSelectMode & 0xFC) | APCI3120_TIMER_0_MODE_2;
871 outb(devpriv->b_TimerSelectMode,
872 dev->iobase + APCI3120_TIMER_CRT1);
873
874 /* Select Timer 0 */
875 b_Tmp = ((devpriv->
876 b_DigitalOutputRegister) & 0xF0) |
877 APCI3120_SELECT_TIMER_0_WORD;
878 outb(b_Tmp, dev->iobase + APCI3120_TIMER_CRT0);
879 /* Set the conversion time */
880 outw(((unsigned short) ui_TimerValue0),
881 dev->iobase + APCI3120_TIMER_VALUE);
882 break;
883
884 case 2:
885 /* init timer1 in mode 2 */
886 devpriv->b_TimerSelectMode =
887 (devpriv->
888 b_TimerSelectMode & 0xF3) | APCI3120_TIMER_1_MODE_2;
889 outb(devpriv->b_TimerSelectMode,
890 dev->iobase + APCI3120_TIMER_CRT1);
891
892 /* Select Timer 1 */
893 b_Tmp = ((devpriv->
894 b_DigitalOutputRegister) & 0xF0) |
895 APCI3120_SELECT_TIMER_1_WORD;
896 outb(b_Tmp, dev->iobase + APCI3120_TIMER_CRT0);
897 /* Set the conversion time */
898 outw(((unsigned short) ui_TimerValue1),
899 dev->iobase + APCI3120_TIMER_VALUE);
900
901 /* init timer0 in mode 2 */
902 devpriv->b_TimerSelectMode =
903 (devpriv->
904 b_TimerSelectMode & 0xFC) | APCI3120_TIMER_0_MODE_2;
905 outb(devpriv->b_TimerSelectMode,
906 dev->iobase + APCI3120_TIMER_CRT1);
907
908 /* Select Timer 0 */
909 b_Tmp = ((devpriv->
910 b_DigitalOutputRegister) & 0xF0) |
911 APCI3120_SELECT_TIMER_0_WORD;
912 outb(b_Tmp, dev->iobase + APCI3120_TIMER_CRT0);
913
914 /* Set the conversion time */
915 outw(((unsigned short) ui_TimerValue0),
916 dev->iobase + APCI3120_TIMER_VALUE);
917 break;
918
919 }
920 /* common for all modes */
921 /* BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver */
922 devpriv->b_ModeSelectRegister = devpriv->b_ModeSelectRegister &
923 APCI3120_DISABLE_SCAN;
924 /* END JK 07.05.04: Comparison between WIN32 and Linux driver */
925
926 outb(devpriv->b_ModeSelectRegister,
927 dev->iobase + APCI3120_WRITE_MODE_SELECT);
928
929 /* If DMA is disabled */
930 if (devpriv->us_UseDma == APCI3120_DISABLE) {
931 /* disable EOC and enable EOS */
932 devpriv->b_InterruptMode = APCI3120_EOS_MODE;
933 devpriv->b_EocEosInterrupt = APCI3120_ENABLE;
934
935 devpriv->b_ModeSelectRegister =
936 (devpriv->
937 b_ModeSelectRegister & APCI3120_DISABLE_EOC_INT) |
938 APCI3120_ENABLE_EOS_INT;
939 outb(devpriv->b_ModeSelectRegister,
940 dev->iobase + APCI3120_WRITE_MODE_SELECT);
941
942 if (cmd->stop_src == TRIG_COUNT) {
943 /*
944 * configure Timer2 For counting EOS Reset gate 2 of Timer 2 to
945 * disable it (Set Bit D14 to 0)
946 */
947 devpriv->us_OutputRegister =
948 devpriv->
949 us_OutputRegister & APCI3120_DISABLE_TIMER2;
950 outw(devpriv->us_OutputRegister,
951 dev->iobase + APCI3120_WR_ADDRESS);
952
953 /* DISABLE TIMER intERRUPT */
954 devpriv->b_ModeSelectRegister =
955 devpriv->
956 b_ModeSelectRegister &
957 APCI3120_DISABLE_TIMER_INT & 0xEF;
958 outb(devpriv->b_ModeSelectRegister,
959 dev->iobase + APCI3120_WRITE_MODE_SELECT);
960
961 /* (1) Init timer 2 in mode 0 and write timer value */
962 devpriv->b_TimerSelectMode =
963 (devpriv->
964 b_TimerSelectMode & 0x0F) |
965 APCI3120_TIMER_2_MODE_0;
966 outb(devpriv->b_TimerSelectMode,
967 dev->iobase + APCI3120_TIMER_CRT1);
968
969 /* Writing LOW unsigned short */
970 b_Tmp = ((devpriv->
971 b_DigitalOutputRegister) & 0xF0) |
972 APCI3120_SELECT_TIMER_2_LOW_WORD;
973 outb(b_Tmp, dev->iobase + APCI3120_TIMER_CRT0);
974 outw(ui_TimerValue2 & 0xffff,
975 dev->iobase + APCI3120_TIMER_VALUE);
976
977 /* Writing HIGH unsigned short */
978 b_Tmp = ((devpriv->
979 b_DigitalOutputRegister) & 0xF0) |
980 APCI3120_SELECT_TIMER_2_HIGH_WORD;
981 outb(b_Tmp, dev->iobase + APCI3120_TIMER_CRT0);
982 outw((ui_TimerValue2 >> 16) & 0xffff,
983 dev->iobase + APCI3120_TIMER_VALUE);
984
985 /* (2) Reset FC_TIMER BIT Clearing timer status register */
986 inb(dev->iobase + APCI3120_TIMER_STATUS_REGISTER);
987 /* enable timer counter and disable watch dog */
988 devpriv->b_ModeSelectRegister =
989 (devpriv->
990 b_ModeSelectRegister |
991 APCI3120_ENABLE_TIMER_COUNTER) &
992 APCI3120_DISABLE_WATCHDOG;
993 /* select EOS clock input for timer 2 */
994 devpriv->b_ModeSelectRegister =
995 devpriv->
996 b_ModeSelectRegister |
997 APCI3120_TIMER2_SELECT_EOS;
998 /* Enable timer2 interrupt */
999 devpriv->b_ModeSelectRegister =
1000 devpriv->
1001 b_ModeSelectRegister |
1002 APCI3120_ENABLE_TIMER_INT;
1003 outb(devpriv->b_ModeSelectRegister,
1004 dev->iobase + APCI3120_WRITE_MODE_SELECT);
1005 devpriv->b_Timer2Mode = APCI3120_COUNTER;
1006 devpriv->b_Timer2Interrupt = APCI3120_ENABLE;
1007 }
1008 } else {
1009 /* If DMA Enabled */
1010 unsigned int scan_bytes = cmd->scan_end_arg * sizeof(short);
1011
1012 devpriv->b_InterruptMode = APCI3120_DMA_MODE;
1013
1014 /* Disables the EOC, EOS interrupt */
1015 devpriv->b_ModeSelectRegister = devpriv->b_ModeSelectRegister &
1016 APCI3120_DISABLE_EOC_INT & APCI3120_DISABLE_EOS_INT;
1017
1018 outb(devpriv->b_ModeSelectRegister,
1019 dev->iobase + APCI3120_WRITE_MODE_SELECT);
1020
1021 dmalen0 = devpriv->ui_DmaBufferSize[0];
1022 dmalen1 = devpriv->ui_DmaBufferSize[1];
1023
1024 if (cmd->stop_src == TRIG_COUNT) {
1025 /*
1026 * Must we fill full first buffer? And must we fill
1027 * full second buffer when first is once filled?
1028 */
1029 if (dmalen0 > (cmd->stop_arg * scan_bytes)) {
1030 dmalen0 = cmd->stop_arg * scan_bytes;
1031 } else if (dmalen1 > (cmd->stop_arg * scan_bytes -
1032 dmalen0))
1033 dmalen1 = cmd->stop_arg * scan_bytes -
1034 dmalen0;
1035 }
1036
1037 if (cmd->flags & CMDF_WAKE_EOS) {
1038 /* don't we want wake up every scan? */
1039 if (dmalen0 > scan_bytes) {
1040 dmalen0 = scan_bytes;
1041 if (cmd->scan_end_arg & 1)
1042 dmalen0 += 2;
1043 }
1044 if (dmalen1 > scan_bytes) {
1045 dmalen1 = scan_bytes;
1046 if (cmd->scan_end_arg & 1)
1047 dmalen1 -= 2;
1048 if (dmalen1 < 4)
1049 dmalen1 = 4;
1050 }
1051 } else { /* isn't output buff smaller that our DMA buff? */
1052 if (dmalen0 > s->async->prealloc_bufsz)
1053 dmalen0 = s->async->prealloc_bufsz;
1054 if (dmalen1 > s->async->prealloc_bufsz)
1055 dmalen1 = s->async->prealloc_bufsz;
1056 }
1057 devpriv->ui_DmaBufferUsesize[0] = dmalen0;
1058 devpriv->ui_DmaBufferUsesize[1] = dmalen1;
1059
1060 /* Initialize DMA */
1061
1062 /*
1063 * Set Transfer count enable bit and A2P_fifo reset bit in AGCSTS
1064 * register 1
1065 */
1066 ui_Tmp = AGCSTS_TC_ENABLE | AGCSTS_RESET_A2P_FIFO;
1067 outl(ui_Tmp, devpriv->i_IobaseAmcc + AMCC_OP_REG_AGCSTS);
1068
1069 /* changed since 16 bit interface for add on */
1070 /* ENABLE BUS MASTER */
1071 outw(APCI3120_ADD_ON_AGCSTS_LOW, devpriv->i_IobaseAddon + 0);
1072 outw(APCI3120_ENABLE_TRANSFER_ADD_ON_LOW,
1073 devpriv->i_IobaseAddon + 2);
1074
1075 outw(APCI3120_ADD_ON_AGCSTS_HIGH, devpriv->i_IobaseAddon + 0);
1076 outw(APCI3120_ENABLE_TRANSFER_ADD_ON_HIGH,
1077 devpriv->i_IobaseAddon + 2);
1078
1079 /*
1080 * TO VERIFIED BEGIN JK 07.05.04: Comparison between WIN32 and Linux
1081 * driver
1082 */
1083 outw(0x1000, devpriv->i_IobaseAddon + 2);
1084 /* END JK 07.05.04: Comparison between WIN32 and Linux driver */
1085
1086 /* 2 No change */
1087 /* A2P FIFO MANAGEMENT */
1088 /* A2P fifo reset & transfer control enable */
1089 outl(APCI3120_A2P_FIFO_MANAGEMENT, devpriv->i_IobaseAmcc +
1090 APCI3120_AMCC_OP_MCSR);
1091
1092 /*
1093 * 3
1094 * beginning address of dma buf The 32 bit address of dma buffer
1095 * is converted into two 16 bit addresses Can done by using _attach
1096 * and put into into an array array used may be for differnet pages
1097 */
1098
1099 /* DMA Start Address Low */
1100 outw(APCI3120_ADD_ON_MWAR_LOW, devpriv->i_IobaseAddon + 0);
1101 outw((devpriv->ul_DmaBufferHw[0] & 0xFFFF),
1102 devpriv->i_IobaseAddon + 2);
1103
1104 /* DMA Start Address High */
1105 outw(APCI3120_ADD_ON_MWAR_HIGH, devpriv->i_IobaseAddon + 0);
1106 outw((devpriv->ul_DmaBufferHw[0] / 65536),
1107 devpriv->i_IobaseAddon + 2);
1108
1109 /*
1110 * 4
1111 * amount of bytes to be transferred set transfer count used ADDON
1112 * MWTC register commented testing
1113 */
1114
1115 /* Nbr of acquisition LOW */
1116 outw(APCI3120_ADD_ON_MWTC_LOW, devpriv->i_IobaseAddon + 0);
1117 outw((devpriv->ui_DmaBufferUsesize[0] & 0xFFFF),
1118 devpriv->i_IobaseAddon + 2);
1119
1120 /* Nbr of acquisition HIGH */
1121 outw(APCI3120_ADD_ON_MWTC_HIGH, devpriv->i_IobaseAddon + 0);
1122 outw((devpriv->ui_DmaBufferUsesize[0] / 65536),
1123 devpriv->i_IobaseAddon + 2);
1124
1125 /*
1126 * 5
1127 * To configure A2P FIFO testing outl(
1128 * FIFO_ADVANCE_ON_BYTE_2,devpriv->i_IobaseAmcc+AMCC_OP_REG_INTCSR);
1129 */
1130
1131 /* A2P FIFO RESET */
1132 /*
1133 * TO VERIFY BEGIN JK 07.05.04: Comparison between WIN32 and Linux
1134 * driver
1135 */
1136 outl(0x04000000UL, devpriv->i_IobaseAmcc + AMCC_OP_REG_MCSR);
1137 /* END JK 07.05.04: Comparison between WIN32 and Linux driver */
1138
1139 /*
1140 * 6
1141 * ENABLE A2P FIFO WRITE AND ENABLE AMWEN AMWEN_ENABLE |
1142 * A2P_FIFO_WRITE_ENABLE (0x01|0x02)=0x03
1143 */
1144
1145 /*
1146 * 7
1147 * initialise end of dma interrupt AINT_WRITE_COMPL =
1148 * ENABLE_WRITE_TC_INT(ADDI)
1149 */
1150 /* A2P FIFO CONFIGURATE, END OF DMA intERRUPT INIT */
1151 outl((APCI3120_FIFO_ADVANCE_ON_BYTE_2 |
1152 APCI3120_ENABLE_WRITE_TC_INT),
1153 devpriv->i_IobaseAmcc + AMCC_OP_REG_INTCSR);
1154
1155 /* BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver */
1156 /* ENABLE A2P FIFO WRITE AND ENABLE AMWEN */
1157 outw(3, devpriv->i_IobaseAddon + 4);
1158 /* END JK 07.05.04: Comparison between WIN32 and Linux driver */
1159
1160 /* A2P FIFO RESET */
1161 /* BEGIN JK 07.05.04: Comparison between WIN32 and Linux driver */
1162 outl(0x04000000UL,
1163 devpriv->i_IobaseAmcc + APCI3120_AMCC_OP_MCSR);
1164 /* END JK 07.05.04: Comparison between WIN32 and Linux driver */
1165 }
1166
1167 if (devpriv->us_UseDma == APCI3120_DISABLE &&
1168 cmd->stop_src == TRIG_COUNT) {
1169 /* set gate 2 to start conversion */
1170 devpriv->us_OutputRegister =
1171 devpriv->us_OutputRegister | APCI3120_ENABLE_TIMER2;
1172 outw(devpriv->us_OutputRegister,
1173 dev->iobase + APCI3120_WR_ADDRESS);
1174 }
1175
1176 switch (mode) {
1177 case 1:
1178 /* set gate 0 to start conversion */
1179 devpriv->us_OutputRegister =
1180 devpriv->us_OutputRegister | APCI3120_ENABLE_TIMER0;
1181 outw(devpriv->us_OutputRegister,
1182 dev->iobase + APCI3120_WR_ADDRESS);
1183 break;
1184 case 2:
1185 /* set gate 0 and gate 1 */
1186 devpriv->us_OutputRegister =
1187 devpriv->us_OutputRegister | APCI3120_ENABLE_TIMER1;
1188 devpriv->us_OutputRegister =
1189 devpriv->us_OutputRegister | APCI3120_ENABLE_TIMER0;
1190 outw(devpriv->us_OutputRegister,
1191 dev->iobase + APCI3120_WR_ADDRESS);
1192 break;
1193
1194 }
1195
1196 return 0;
1197
1198}
1199
1200/*
1201 * Does asynchronous acquisition.
1202 * Determines the mode 1 or 2.
1203 */
1204static int apci3120_ai_cmd(struct comedi_device *dev,
1205 struct comedi_subdevice *s)
1206{
1207 struct addi_private *devpriv = dev->private;
1208 struct comedi_cmd *cmd = &s->async->cmd;
1209
1210 /* loading private structure with cmd structure inputs */
1211 devpriv->ui_AiNbrofChannels = cmd->chanlist_len;
1212
1213 if (cmd->start_src == TRIG_EXT)
1214 devpriv->b_ExttrigEnable = APCI3120_ENABLE;
1215 else
1216 devpriv->b_ExttrigEnable = APCI3120_DISABLE;
1217
1218 if (cmd->scan_begin_src == TRIG_FOLLOW)
1219 return apci3120_cyclic_ai(1, dev, s);
1220 /* TRIG_TIMER */
1221 return apci3120_cyclic_ai(2, dev, s);
1222}
1223
1224/*
1225 * This function copies the data from DMA buffer to the Comedi buffer.
1226 */
1227static void v_APCI3120_InterruptDmaMoveBlock16bit(struct comedi_device *dev,
1228 struct comedi_subdevice *s,
1229 unsigned short *dma_buffer,
1230 unsigned int num_samples)
1231{
1232 struct addi_private *devpriv = dev->private;
1233 struct comedi_cmd *cmd = &s->async->cmd;
1234
1235 devpriv->ui_AiActualScan +=
1236 (s->async->cur_chan + num_samples) / cmd->scan_end_arg;
1237 s->async->cur_chan += num_samples;
1238 s->async->cur_chan %= cmd->scan_end_arg;
1239
1240 cfc_write_array_to_buffer(s, dma_buffer, num_samples * sizeof(short));
1241}
1242
1243/*
1244 * This is a handler for the DMA interrupt.
1245 * This function copies the data to Comedi Buffer.
1246 * For continuous DMA it reinitializes the DMA operation.
1247 * For single mode DMA it stop the acquisition.
1248 */
1249static void apci3120_interrupt_dma(int irq, void *d)
1250{
1251 struct comedi_device *dev = d;
1252 struct addi_private *devpriv = dev->private;
1253 struct comedi_subdevice *s = dev->read_subdev;
1254 struct comedi_cmd *cmd = &s->async->cmd;
1255 unsigned int next_dma_buf, samplesinbuf;
1256 unsigned long low_word, high_word, var;
1257 unsigned int ui_Tmp;
1258
1259 samplesinbuf =
1260 devpriv->ui_DmaBufferUsesize[devpriv->ui_DmaActualBuffer] -
1261 inl(devpriv->i_IobaseAmcc + AMCC_OP_REG_MWTC);
1262
1263 if (samplesinbuf <
1264 devpriv->ui_DmaBufferUsesize[devpriv->ui_DmaActualBuffer]) {
1265 dev_err(dev->class_dev, "Interrupted DMA transfer!\n");
1266 }
1267 if (samplesinbuf & 1) {
1268 dev_err(dev->class_dev, "Odd count of bytes in DMA ring!\n");
1269 apci3120_cancel(dev, s);
1270 return;
1271 }
1272 samplesinbuf = samplesinbuf >> 1; /* number of received samples */
1273 if (devpriv->b_DmaDoubleBuffer) {
1274 /* switch DMA buffers if is used double buffering */
1275 next_dma_buf = 1 - devpriv->ui_DmaActualBuffer;
1276
1277 ui_Tmp = AGCSTS_TC_ENABLE | AGCSTS_RESET_A2P_FIFO;
1278 outl(ui_Tmp, devpriv->i_IobaseAddon + AMCC_OP_REG_AGCSTS);
1279
1280 /* changed since 16 bit interface for add on */
1281 outw(APCI3120_ADD_ON_AGCSTS_LOW, devpriv->i_IobaseAddon + 0);
1282 outw(APCI3120_ENABLE_TRANSFER_ADD_ON_LOW,
1283 devpriv->i_IobaseAddon + 2);
1284 outw(APCI3120_ADD_ON_AGCSTS_HIGH, devpriv->i_IobaseAddon + 0);
1285 outw(APCI3120_ENABLE_TRANSFER_ADD_ON_HIGH, devpriv->i_IobaseAddon + 2); /* 0x1000 is out putted in windows driver */
1286
1287 var = devpriv->ul_DmaBufferHw[next_dma_buf];
1288 low_word = var & 0xffff;
1289 var = devpriv->ul_DmaBufferHw[next_dma_buf];
1290 high_word = var / 65536;
1291
1292 /* DMA Start Address Low */
1293 outw(APCI3120_ADD_ON_MWAR_LOW, devpriv->i_IobaseAddon + 0);
1294 outw(low_word, devpriv->i_IobaseAddon + 2);
1295
1296 /* DMA Start Address High */
1297 outw(APCI3120_ADD_ON_MWAR_HIGH, devpriv->i_IobaseAddon + 0);
1298 outw(high_word, devpriv->i_IobaseAddon + 2);
1299
1300 var = devpriv->ui_DmaBufferUsesize[next_dma_buf];
1301 low_word = var & 0xffff;
1302 var = devpriv->ui_DmaBufferUsesize[next_dma_buf];
1303 high_word = var / 65536;
1304
1305 /* Nbr of acquisition LOW */
1306 outw(APCI3120_ADD_ON_MWTC_LOW, devpriv->i_IobaseAddon + 0);
1307 outw(low_word, devpriv->i_IobaseAddon + 2);
1308
1309 /* Nbr of acquisition HIGH */
1310 outw(APCI3120_ADD_ON_MWTC_HIGH, devpriv->i_IobaseAddon + 0);
1311 outw(high_word, devpriv->i_IobaseAddon + 2);
1312
1313 /*
1314 * To configure A2P FIFO
1315 * ENABLE A2P FIFO WRITE AND ENABLE AMWEN
1316 * AMWEN_ENABLE | A2P_FIFO_WRITE_ENABLE (0x01|0x02)=0x03
1317 */
1318 outw(3, devpriv->i_IobaseAddon + 4);
1319 /* initialise end of dma interrupt AINT_WRITE_COMPL = ENABLE_WRITE_TC_INT(ADDI) */
1320 outl((APCI3120_FIFO_ADVANCE_ON_BYTE_2 |
1321 APCI3120_ENABLE_WRITE_TC_INT),
1322 devpriv->i_IobaseAmcc + AMCC_OP_REG_INTCSR);
1323
1324 }
1325 if (samplesinbuf) {
1326 v_APCI3120_InterruptDmaMoveBlock16bit(dev, s,
1327 devpriv->ul_DmaBufferVirtual[devpriv->
1328 ui_DmaActualBuffer], samplesinbuf);
1329
1330 if (!(cmd->flags & CMDF_WAKE_EOS)) {
1331 s->async->events |= COMEDI_CB_EOS;
1332 comedi_event(dev, s);
1333 }
1334 }
1335 if (cmd->stop_src == TRIG_COUNT)
1336 if (devpriv->ui_AiActualScan >= cmd->stop_arg) {
1337 /* all data sampled */
1338 apci3120_cancel(dev, s);
1339 s->async->events |= COMEDI_CB_EOA;
1340 comedi_event(dev, s);
1341 return;
1342 }
1343
1344 if (devpriv->b_DmaDoubleBuffer) { /* switch dma buffers */
1345 devpriv->ui_DmaActualBuffer = 1 - devpriv->ui_DmaActualBuffer;
1346 } else {
1347 /*
1348 * restart DMA if is not used double buffering
1349 * ADDED REINITIALISE THE DMA
1350 */
1351 ui_Tmp = AGCSTS_TC_ENABLE | AGCSTS_RESET_A2P_FIFO;
1352 outl(ui_Tmp, devpriv->i_IobaseAddon + AMCC_OP_REG_AGCSTS);
1353
1354 /* changed since 16 bit interface for add on */
1355 outw(APCI3120_ADD_ON_AGCSTS_LOW, devpriv->i_IobaseAddon + 0);
1356 outw(APCI3120_ENABLE_TRANSFER_ADD_ON_LOW,
1357 devpriv->i_IobaseAddon + 2);
1358 outw(APCI3120_ADD_ON_AGCSTS_HIGH, devpriv->i_IobaseAddon + 0);
1359 outw(APCI3120_ENABLE_TRANSFER_ADD_ON_HIGH, devpriv->i_IobaseAddon + 2);
1360 /*
1361 * A2P FIFO MANAGEMENT
1362 * A2P fifo reset & transfer control enable
1363 */
1364 outl(APCI3120_A2P_FIFO_MANAGEMENT,
1365 devpriv->i_IobaseAmcc + AMCC_OP_REG_MCSR);
1366
1367 var = devpriv->ul_DmaBufferHw[0];
1368 low_word = var & 0xffff;
1369 var = devpriv->ul_DmaBufferHw[0];
1370 high_word = var / 65536;
1371 outw(APCI3120_ADD_ON_MWAR_LOW, devpriv->i_IobaseAddon + 0);
1372 outw(low_word, devpriv->i_IobaseAddon + 2);
1373 outw(APCI3120_ADD_ON_MWAR_HIGH, devpriv->i_IobaseAddon + 0);
1374 outw(high_word, devpriv->i_IobaseAddon + 2);
1375
1376 var = devpriv->ui_DmaBufferUsesize[0];
1377 low_word = var & 0xffff; /* changed */
1378 var = devpriv->ui_DmaBufferUsesize[0];
1379 high_word = var / 65536;
1380 outw(APCI3120_ADD_ON_MWTC_LOW, devpriv->i_IobaseAddon + 0);
1381 outw(low_word, devpriv->i_IobaseAddon + 2);
1382 outw(APCI3120_ADD_ON_MWTC_HIGH, devpriv->i_IobaseAddon + 0);
1383 outw(high_word, devpriv->i_IobaseAddon + 2);
1384
1385 /*
1386 * To configure A2P FIFO
1387 * ENABLE A2P FIFO WRITE AND ENABLE AMWEN
1388 * AMWEN_ENABLE | A2P_FIFO_WRITE_ENABLE (0x01|0x02)=0x03
1389 */
1390 outw(3, devpriv->i_IobaseAddon + 4);
1391 /* initialise end of dma interrupt AINT_WRITE_COMPL = ENABLE_WRITE_TC_INT(ADDI) */
1392 outl((APCI3120_FIFO_ADVANCE_ON_BYTE_2 |
1393 APCI3120_ENABLE_WRITE_TC_INT),
1394 devpriv->i_IobaseAmcc + AMCC_OP_REG_INTCSR);
1395 }
1396}
1397
1398/*
1399 * This function handles EOS interrupt.
1400 * This function copies the acquired data(from FIFO) to Comedi buffer.
1401 */
1402static int apci3120_interrupt_handle_eos(struct comedi_device *dev)
1403{
1404 struct addi_private *devpriv = dev->private;
1405 struct comedi_subdevice *s = dev->read_subdev;
1406 int n_chan, i;
1407 int err = 1;
1408
1409 n_chan = devpriv->ui_AiNbrofChannels;
1410
1411 for (i = 0; i < n_chan; i++)
1412 err &= comedi_buf_put(s, inw(dev->iobase + 0));
1413
1414 s->async->events |= COMEDI_CB_EOS;
1415
1416 if (err == 0)
1417 s->async->events |= COMEDI_CB_OVERFLOW;
1418
1419 comedi_event(dev, s);
1420
1421 return 0;
1422}
1423
1424static void apci3120_interrupt(int irq, void *d)
1425{
1426 struct comedi_device *dev = d;
1427 struct addi_private *devpriv = dev->private;
1428 struct comedi_subdevice *s = dev->read_subdev;
1429 unsigned short int_daq;
1430 unsigned int int_amcc, ui_Check, i;
1431 unsigned short us_TmpValue;
1432 unsigned char b_DummyRead;
1433
1434 ui_Check = 1;
1435
1436 int_daq = inw(dev->iobase + APCI3120_RD_STATUS) & 0xf000; /* get IRQ reasons */
1437 int_amcc = inl(devpriv->i_IobaseAmcc + AMCC_OP_REG_INTCSR); /* get AMCC int register */
1438
1439 if ((!int_daq) && (!(int_amcc & ANY_S593X_INT))) {
1440 dev_err(dev->class_dev, "IRQ from unknown source\n");
1441 return;
1442 }
1443
1444 outl(int_amcc | 0x00ff0000, devpriv->i_IobaseAmcc + AMCC_OP_REG_INTCSR); /* shutdown IRQ reasons in AMCC */
1445
1446 int_daq = (int_daq >> 12) & 0xF;
1447
1448 if (devpriv->b_ExttrigEnable == APCI3120_ENABLE) {
1449 /* Disable ext trigger */
1450 apci3120_exttrig_disable(dev);
1451 devpriv->b_ExttrigEnable = APCI3120_DISABLE;
1452 }
1453 /* clear the timer 2 interrupt */
1454 inb(devpriv->i_IobaseAmcc + APCI3120_TIMER_STATUS_REGISTER);
1455
1456 if (int_amcc & MASTER_ABORT_INT)
1457 dev_err(dev->class_dev, "AMCC IRQ - MASTER DMA ABORT!\n");
1458 if (int_amcc & TARGET_ABORT_INT)
1459 dev_err(dev->class_dev, "AMCC IRQ - TARGET DMA ABORT!\n");
1460
1461 /* Ckeck if EOC interrupt */
1462 if (((int_daq & 0x8) == 0)
1463 && (devpriv->b_InterruptMode == APCI3120_EOC_MODE)) {
1464 if (devpriv->b_EocEosInterrupt == APCI3120_ENABLE) {
1465
1466 /* Read the AI Value */
1467 devpriv->ui_AiReadData[0] =
1468 (unsigned int) inw(devpriv->iobase + 0);
1469 devpriv->b_EocEosInterrupt = APCI3120_DISABLE;
1470 send_sig(SIGIO, devpriv->tsk_Current, 0); /* send signal to the sample */
1471 } else {
1472 /* Disable EOC Interrupt */
1473 devpriv->b_ModeSelectRegister =
1474 devpriv->
1475 b_ModeSelectRegister & APCI3120_DISABLE_EOC_INT;
1476 outb(devpriv->b_ModeSelectRegister,
1477 devpriv->iobase + APCI3120_WRITE_MODE_SELECT);
1478
1479 }
1480 }
1481
1482 /* Check If EOS interrupt */
1483 if ((int_daq & 0x2) && (devpriv->b_InterruptMode == APCI3120_EOS_MODE)) {
1484
1485 if (devpriv->b_EocEosInterrupt == APCI3120_ENABLE) { /* enable this in without DMA ??? */
1486
1487 if (devpriv->ai_running) {
1488 ui_Check = 0;
1489 apci3120_interrupt_handle_eos(dev);
1490 devpriv->ui_AiActualScan++;
1491 devpriv->b_ModeSelectRegister =
1492 devpriv->
1493 b_ModeSelectRegister |
1494 APCI3120_ENABLE_EOS_INT;
1495 outb(devpriv->b_ModeSelectRegister,
1496 dev->iobase +
1497 APCI3120_WRITE_MODE_SELECT);
1498 } else {
1499 ui_Check = 0;
1500 for (i = 0; i < devpriv->ui_AiNbrofChannels;
1501 i++) {
1502 us_TmpValue = inw(devpriv->iobase + 0);
1503 devpriv->ui_AiReadData[i] =
1504 (unsigned int) us_TmpValue;
1505 }
1506 devpriv->b_EocEosInterrupt = APCI3120_DISABLE;
1507 devpriv->b_InterruptMode = APCI3120_EOC_MODE;
1508
1509 send_sig(SIGIO, devpriv->tsk_Current, 0); /* send signal to the sample */
1510
1511 }
1512
1513 } else {
1514 devpriv->b_ModeSelectRegister =
1515 devpriv->
1516 b_ModeSelectRegister & APCI3120_DISABLE_EOS_INT;
1517 outb(devpriv->b_ModeSelectRegister,
1518 dev->iobase + APCI3120_WRITE_MODE_SELECT);
1519 devpriv->b_EocEosInterrupt = APCI3120_DISABLE; /* Default settings */
1520 devpriv->b_InterruptMode = APCI3120_EOC_MODE;
1521 }
1522
1523 }
1524 /* Timer2 interrupt */
1525 if (int_daq & 0x1) {
1526
1527 switch (devpriv->b_Timer2Mode) {
1528 case APCI3120_COUNTER:
1529 devpriv->b_ModeSelectRegister =
1530 devpriv->
1531 b_ModeSelectRegister & APCI3120_DISABLE_EOS_INT;
1532 outb(devpriv->b_ModeSelectRegister,
1533 dev->iobase + APCI3120_WRITE_MODE_SELECT);
1534
1535 /* stop timer 2 */
1536 devpriv->us_OutputRegister =
1537 devpriv->
1538 us_OutputRegister & APCI3120_DISABLE_ALL_TIMER;
1539 outw(devpriv->us_OutputRegister,
1540 dev->iobase + APCI3120_WR_ADDRESS);
1541
1542 /* stop timer 0 and timer 1 */
1543 apci3120_cancel(dev, s);
1544
1545 /* UPDATE-0.7.57->0.7.68comedi_done(dev,s); */
1546 s->async->events |= COMEDI_CB_EOA;
1547 comedi_event(dev, s);
1548
1549 break;
1550
1551 case APCI3120_TIMER:
1552
1553 /* Send a signal to from kernel to user space */
1554 send_sig(SIGIO, devpriv->tsk_Current, 0);
1555 break;
1556
1557 case APCI3120_WATCHDOG:
1558
1559 /* Send a signal to from kernel to user space */
1560 send_sig(SIGIO, devpriv->tsk_Current, 0);
1561 break;
1562
1563 default:
1564
1565 /* disable Timer Interrupt */
1566 devpriv->b_ModeSelectRegister =
1567 devpriv->
1568 b_ModeSelectRegister &
1569 APCI3120_DISABLE_TIMER_INT;
1570
1571 outb(devpriv->b_ModeSelectRegister,
1572 dev->iobase + APCI3120_WRITE_MODE_SELECT);
1573
1574 }
1575
1576 b_DummyRead = inb(dev->iobase + APCI3120_TIMER_STATUS_REGISTER);
1577
1578 }
1579
1580 if ((int_daq & 0x4) && (devpriv->b_InterruptMode == APCI3120_DMA_MODE)) {
1581 if (devpriv->ai_running) {
1582
1583 /* Clear Timer Write TC int */
1584 outl(APCI3120_CLEAR_WRITE_TC_INT,
1585 devpriv->i_IobaseAmcc +
1586 APCI3120_AMCC_OP_REG_INTCSR);
1587
1588 /* Clears the timer status register */
1589 inw(dev->iobase + APCI3120_TIMER_STATUS_REGISTER);
1590 /* do some data transfer */
1591 apci3120_interrupt_dma(irq, d);
1592 } else {
1593 /* Stops the Timer */
1594 outw(devpriv->
1595 us_OutputRegister & APCI3120_DISABLE_TIMER0 &
1596 APCI3120_DISABLE_TIMER1,
1597 dev->iobase + APCI3120_WR_ADDRESS);
1598 }
1599
1600 }
1601}
1602
1603/*
1604 * Configure Timer 2
1605 *
1606 * data[0] = TIMER configure as timer
1607 * = WATCHDOG configure as watchdog
1608 * data[1] = Timer constant
1609 * data[2] = Timer2 interrupt (1)enable or(0) disable
1610 */
1611static int apci3120_config_insn_timer(struct comedi_device *dev,
1612 struct comedi_subdevice *s,
1613 struct comedi_insn *insn,
1614 unsigned int *data)
1615{
1616 const struct addi_board *this_board = dev->board_ptr;
1617 struct addi_private *devpriv = dev->private;
1618 unsigned int ui_Timervalue2;
1619 unsigned short us_TmpValue;
1620 unsigned char b_Tmp;
1621
1622 if (!data[1])
1623 dev_err(dev->class_dev, "No timer constant!\n");
1624
1625 devpriv->b_Timer2Interrupt = (unsigned char) data[2]; /* save info whether to enable or disable interrupt */
1626
1627 ui_Timervalue2 = data[1] / 1000; /* convert nano seconds to u seconds */
1628
1629 us_TmpValue = (unsigned short) inw(devpriv->iobase + APCI3120_RD_STATUS);
1630
1631 /*
1632 * EL250804: Testing if board APCI3120 have the new Quartz or if it
1633 * is an APCI3001 and calculate the time value to set in the timer
1634 */
1635 if ((us_TmpValue & 0x00B0) == 0x00B0
1636 || !strcmp(this_board->pc_DriverName, "apci3001")) {
1637 /* Calculate the time value to set in the timer */
1638 ui_Timervalue2 = ui_Timervalue2 / 50;
1639 } else {
1640 /* Calculate the time value to set in the timer */
1641 ui_Timervalue2 = ui_Timervalue2 / 70;
1642 }
1643
1644 /* Reset gate 2 of Timer 2 to disable it (Set Bit D14 to 0) */
1645 devpriv->us_OutputRegister =
1646 devpriv->us_OutputRegister & APCI3120_DISABLE_TIMER2;
1647 outw(devpriv->us_OutputRegister, devpriv->iobase + APCI3120_WR_ADDRESS);
1648
1649 /* Disable TIMER Interrupt */
1650 devpriv->b_ModeSelectRegister =
1651 devpriv->
1652 b_ModeSelectRegister & APCI3120_DISABLE_TIMER_INT & 0xEF;
1653
1654 /* Disable Eoc and Eos Interrupts */
1655 devpriv->b_ModeSelectRegister =
1656 devpriv->
1657 b_ModeSelectRegister & APCI3120_DISABLE_EOC_INT &
1658 APCI3120_DISABLE_EOS_INT;
1659 outb(devpriv->b_ModeSelectRegister,
1660 devpriv->iobase + APCI3120_WRITE_MODE_SELECT);
1661 if (data[0] == APCI3120_TIMER) { /* initialize timer */
1662 /* Set the Timer 2 in mode 2(Timer) */
1663 devpriv->b_TimerSelectMode =
1664 (devpriv->
1665 b_TimerSelectMode & 0x0F) | APCI3120_TIMER_2_MODE_2;
1666 outb(devpriv->b_TimerSelectMode,
1667 devpriv->iobase + APCI3120_TIMER_CRT1);
1668
1669 /*
1670 * Configure the timer 2 for writing the LOW unsigned short of timer
1671 * is Delay value You must make a b_tmp variable with
1672 * DigitalOutPutRegister because at Address_1+APCI3120_TIMER_CRT0
1673 * you can set the digital output and configure the timer 2,and if
1674 * you don't make this, digital output are erase (Set to 0)
1675 */
1676
1677 /* Writing LOW unsigned short */
1678 b_Tmp = ((devpriv->
1679 b_DigitalOutputRegister) & 0xF0) |
1680 APCI3120_SELECT_TIMER_2_LOW_WORD;
1681 outb(b_Tmp, devpriv->iobase + APCI3120_TIMER_CRT0);
1682 outw(ui_Timervalue2 & 0xffff,
1683 devpriv->iobase + APCI3120_TIMER_VALUE);
1684
1685 /* Writing HIGH unsigned short */
1686 b_Tmp = ((devpriv->
1687 b_DigitalOutputRegister) & 0xF0) |
1688 APCI3120_SELECT_TIMER_2_HIGH_WORD;
1689 outb(b_Tmp, devpriv->iobase + APCI3120_TIMER_CRT0);
1690 outw((ui_Timervalue2 >> 16) & 0xffff,
1691 devpriv->iobase + APCI3120_TIMER_VALUE);
1692 /* timer2 in Timer mode enabled */
1693 devpriv->b_Timer2Mode = APCI3120_TIMER;
1694
1695 } else { /* Initialize Watch dog */
1696
1697 /* Set the Timer 2 in mode 5(Watchdog) */
1698 devpriv->b_TimerSelectMode =
1699 (devpriv->
1700 b_TimerSelectMode & 0x0F) | APCI3120_TIMER_2_MODE_5;
1701 outb(devpriv->b_TimerSelectMode,
1702 devpriv->iobase + APCI3120_TIMER_CRT1);
1703
1704 /*
1705 * Configure the timer 2 for writing the LOW unsigned short of timer
1706 * is Delay value You must make a b_tmp variable with
1707 * DigitalOutPutRegister because at Address_1+APCI3120_TIMER_CRT0
1708 * you can set the digital output and configure the timer 2,and if
1709 * you don't make this, digital output are erase (Set to 0)
1710 */
1711
1712 /* Writing LOW unsigned short */
1713 b_Tmp = ((devpriv->
1714 b_DigitalOutputRegister) & 0xF0) |
1715 APCI3120_SELECT_TIMER_2_LOW_WORD;
1716 outb(b_Tmp, devpriv->iobase + APCI3120_TIMER_CRT0);
1717 outw(ui_Timervalue2 & 0xffff,
1718 devpriv->iobase + APCI3120_TIMER_VALUE);
1719
1720 /* Writing HIGH unsigned short */
1721 b_Tmp = ((devpriv->
1722 b_DigitalOutputRegister) & 0xF0) |
1723 APCI3120_SELECT_TIMER_2_HIGH_WORD;
1724 outb(b_Tmp, devpriv->iobase + APCI3120_TIMER_CRT0);
1725
1726 outw((ui_Timervalue2 >> 16) & 0xffff,
1727 devpriv->iobase + APCI3120_TIMER_VALUE);
1728 /* watchdog enabled */
1729 devpriv->b_Timer2Mode = APCI3120_WATCHDOG;
1730
1731 }
1732
1733 return insn->n;
1734
1735}
1736
1737/*
1738 * To start and stop the timer
1739 *
1740 * data[0] = 1 (start)
1741 * = 0 (stop)
1742 * = 2 (write new value)
1743 * data[1] = new value
1744 *
1745 * devpriv->b_Timer2Mode = 0 DISABLE
1746 * = 1 Timer
1747 * = 2 Watch dog
1748 */
1749static int apci3120_write_insn_timer(struct comedi_device *dev,
1750 struct comedi_subdevice *s,
1751 struct comedi_insn *insn,
1752 unsigned int *data)
1753{
1754 const struct addi_board *this_board = dev->board_ptr;
1755 struct addi_private *devpriv = dev->private;
1756 unsigned int ui_Timervalue2 = 0;
1757 unsigned short us_TmpValue;
1758 unsigned char b_Tmp;
1759
1760 if ((devpriv->b_Timer2Mode != APCI3120_WATCHDOG)
1761 && (devpriv->b_Timer2Mode != APCI3120_TIMER)) {
1762 dev_err(dev->class_dev, "timer2 not configured\n");
1763 return -EINVAL;
1764 }
1765
1766 if (data[0] == 2) { /* write new value */
1767 if (devpriv->b_Timer2Mode != APCI3120_TIMER) {
1768 dev_err(dev->class_dev,
1769 "timer2 not configured in TIMER MODE\n");
1770 return -EINVAL;
1771 }
1772
1773 if (data[1])
1774 ui_Timervalue2 = data[1];
1775 else
1776 ui_Timervalue2 = 0;
1777 }
1778
1779 switch (data[0]) {
1780 case APCI3120_START:
1781
1782 /* Reset FC_TIMER BIT */
1783 inb(devpriv->iobase + APCI3120_TIMER_STATUS_REGISTER);
1784 if (devpriv->b_Timer2Mode == APCI3120_TIMER) { /* start timer */
1785 /* Enable Timer */
1786 devpriv->b_ModeSelectRegister =
1787 devpriv->b_ModeSelectRegister & 0x0B;
1788 } else { /* start watch dog */
1789 /* Enable WatchDog */
1790 devpriv->b_ModeSelectRegister =
1791 (devpriv->
1792 b_ModeSelectRegister & 0x0B) |
1793 APCI3120_ENABLE_WATCHDOG;
1794 }
1795
1796 /* enable disable interrupt */
1797 if ((devpriv->b_Timer2Interrupt) == APCI3120_ENABLE) {
1798
1799 devpriv->b_ModeSelectRegister =
1800 devpriv->
1801 b_ModeSelectRegister |
1802 APCI3120_ENABLE_TIMER_INT;
1803 /* save the task structure to pass info to user */
1804 devpriv->tsk_Current = current;
1805 } else {
1806
1807 devpriv->b_ModeSelectRegister =
1808 devpriv->
1809 b_ModeSelectRegister &
1810 APCI3120_DISABLE_TIMER_INT;
1811 }
1812 outb(devpriv->b_ModeSelectRegister,
1813 devpriv->iobase + APCI3120_WRITE_MODE_SELECT);
1814
1815 if (devpriv->b_Timer2Mode == APCI3120_TIMER) { /* start timer */
1816 /* For Timer mode is Gate2 must be activated timer started */
1817 devpriv->us_OutputRegister =
1818 devpriv->
1819 us_OutputRegister | APCI3120_ENABLE_TIMER2;
1820 outw(devpriv->us_OutputRegister,
1821 devpriv->iobase + APCI3120_WR_ADDRESS);
1822 }
1823
1824 break;
1825
1826 case APCI3120_STOP:
1827 if (devpriv->b_Timer2Mode == APCI3120_TIMER) {
1828 /* Disable timer */
1829 devpriv->b_ModeSelectRegister =
1830 devpriv->
1831 b_ModeSelectRegister &
1832 APCI3120_DISABLE_TIMER_COUNTER;
1833 } else {
1834 /* Disable WatchDog */
1835 devpriv->b_ModeSelectRegister =
1836 devpriv->
1837 b_ModeSelectRegister &
1838 APCI3120_DISABLE_WATCHDOG;
1839 }
1840 /* Disable timer interrupt */
1841 devpriv->b_ModeSelectRegister =
1842 devpriv->
1843 b_ModeSelectRegister & APCI3120_DISABLE_TIMER_INT;
1844
1845 /* Write above states to register */
1846 outb(devpriv->b_ModeSelectRegister,
1847 devpriv->iobase + APCI3120_WRITE_MODE_SELECT);
1848
1849 /* Reset Gate 2 */
1850 devpriv->us_OutputRegister =
1851 devpriv->us_OutputRegister & APCI3120_DISABLE_TIMER_INT;
1852 outw(devpriv->us_OutputRegister,
1853 devpriv->iobase + APCI3120_WR_ADDRESS);
1854
1855 /* Reset FC_TIMER BIT */
1856 inb(devpriv->iobase + APCI3120_TIMER_STATUS_REGISTER);
1857
1858 break;
1859
1860 case 2: /* write new value to Timer */
1861 if (devpriv->b_Timer2Mode != APCI3120_TIMER) {
1862 dev_err(dev->class_dev,
1863 "timer2 not configured in TIMER MODE\n");
1864 return -EINVAL;
1865 }
1866 us_TmpValue =
1867 (unsigned short) inw(devpriv->iobase + APCI3120_RD_STATUS);
1868
1869 /*
1870 * EL250804: Testing if board APCI3120 have the new Quartz or if it
1871 * is an APCI3001 and calculate the time value to set in the timer
1872 */
1873 if ((us_TmpValue & 0x00B0) == 0x00B0
1874 || !strcmp(this_board->pc_DriverName, "apci3001")) {
1875 /* Calculate the time value to set in the timer */
1876 ui_Timervalue2 = ui_Timervalue2 / 50;
1877 } else {
1878 /* Calculate the time value to set in the timer */
1879 ui_Timervalue2 = ui_Timervalue2 / 70;
1880 }
1881 /* Writing LOW unsigned short */
1882 b_Tmp = ((devpriv->
1883 b_DigitalOutputRegister) & 0xF0) |
1884 APCI3120_SELECT_TIMER_2_LOW_WORD;
1885 outb(b_Tmp, devpriv->iobase + APCI3120_TIMER_CRT0);
1886
1887 outw(ui_Timervalue2 & 0xffff,
1888 devpriv->iobase + APCI3120_TIMER_VALUE);
1889
1890 /* Writing HIGH unsigned short */
1891 b_Tmp = ((devpriv->
1892 b_DigitalOutputRegister) & 0xF0) |
1893 APCI3120_SELECT_TIMER_2_HIGH_WORD;
1894 outb(b_Tmp, devpriv->iobase + APCI3120_TIMER_CRT0);
1895
1896 outw((ui_Timervalue2 >> 16) & 0xffff,
1897 devpriv->iobase + APCI3120_TIMER_VALUE);
1898
1899 break;
1900 default:
1901 return -EINVAL; /* Not a valid input */
1902 }
1903
1904 return insn->n;
1905}
1906
1907/*
1908 * Read the Timer value
1909 *
1910 * for Timer: data[0]= Timer constant
1911 *
1912 * for watchdog: data[0] = 0 (still running)
1913 * = 1 (run down)
1914 */
1915static int apci3120_read_insn_timer(struct comedi_device *dev,
1916 struct comedi_subdevice *s,
1917 struct comedi_insn *insn,
1918 unsigned int *data)
1919{
1920 struct addi_private *devpriv = dev->private;
1921 unsigned char b_Tmp;
1922 unsigned short us_TmpValue, us_TmpValue_2, us_StatusValue;
1923
1924 if ((devpriv->b_Timer2Mode != APCI3120_WATCHDOG)
1925 && (devpriv->b_Timer2Mode != APCI3120_TIMER)) {
1926 dev_err(dev->class_dev, "timer2 not configured\n");
1927 }
1928 if (devpriv->b_Timer2Mode == APCI3120_TIMER) {
1929
1930 /* Read the LOW unsigned short of Timer 2 register */
1931 b_Tmp = ((devpriv->
1932 b_DigitalOutputRegister) & 0xF0) |
1933 APCI3120_SELECT_TIMER_2_LOW_WORD;
1934 outb(b_Tmp, devpriv->iobase + APCI3120_TIMER_CRT0);
1935
1936 us_TmpValue = inw(devpriv->iobase + APCI3120_TIMER_VALUE);
1937
1938 /* Read the HIGH unsigned short of Timer 2 register */
1939 b_Tmp = ((devpriv->
1940 b_DigitalOutputRegister) & 0xF0) |
1941 APCI3120_SELECT_TIMER_2_HIGH_WORD;
1942 outb(b_Tmp, devpriv->iobase + APCI3120_TIMER_CRT0);
1943
1944 us_TmpValue_2 = inw(devpriv->iobase + APCI3120_TIMER_VALUE);
1945
1946 /* combining both words */
1947 data[0] = (unsigned int) ((us_TmpValue) | ((us_TmpValue_2) << 16));
1948
1949 } else { /* Read watch dog status */
1950
1951 us_StatusValue = inw(devpriv->iobase + APCI3120_RD_STATUS);
1952 us_StatusValue =
1953 ((us_StatusValue & APCI3120_FC_TIMER) >> 12) & 1;
1954 if (us_StatusValue == 1) {
1955 /* RESET FC_TIMER BIT */
1956 inb(devpriv->iobase + APCI3120_TIMER_STATUS_REGISTER);
1957 }
1958 data[0] = us_StatusValue; /* when data[0] = 1 then the watch dog has rundown */
1959 }
1960 return insn->n;
1961}
1962
1963static int apci3120_di_insn_bits(struct comedi_device *dev,
1964 struct comedi_subdevice *s,
1965 struct comedi_insn *insn,
1966 unsigned int *data)
1967{
1968 struct addi_private *devpriv = dev->private;
1969 unsigned int val;
1970
1971 /* the input channels are bits 11:8 of the status reg */
1972 val = inw(devpriv->iobase + APCI3120_RD_STATUS);
1973 data[1] = (val >> 8) & 0xf;
1974
1975 return insn->n;
1976}
1977
1978static int apci3120_do_insn_bits(struct comedi_device *dev,
1979 struct comedi_subdevice *s,
1980 struct comedi_insn *insn,
1981 unsigned int *data)
1982{
1983 struct addi_private *devpriv = dev->private;
1984
1985 if (comedi_dio_update_state(s, data)) {
1986 /* The do channels are bits 7:4 of the do register */
1987 devpriv->b_DigitalOutputRegister = s->state << 4;
1988
1989 outb(devpriv->b_DigitalOutputRegister,
1990 devpriv->iobase + APCI3120_DIGITAL_OUTPUT);
1991 }
1992
1993 data[1] = s->state;
1994
1995 return insn->n;
1996}
1997
1998static int apci3120_ao_insn_write(struct comedi_device *dev,
1999 struct comedi_subdevice *s,
2000 struct comedi_insn *insn,
2001 unsigned int *data)
2002{
2003 struct addi_private *devpriv = dev->private;
2004 unsigned int ui_Range, ui_Channel;
2005 unsigned short us_TmpValue;
2006
2007 ui_Range = CR_RANGE(insn->chanspec);
2008 ui_Channel = CR_CHAN(insn->chanspec);
2009
2010 if (ui_Range) { /* if 1 then unipolar */
2011
2012 if (data[0] != 0)
2013 data[0] =
2014 ((((ui_Channel & 0x03) << 14) & 0xC000) | (1 <<
2015 13) | (data[0] + 8191));
2016 else
2017 data[0] =
2018 ((((ui_Channel & 0x03) << 14) & 0xC000) | (1 <<
2019 13) | 8192);
2020
2021 } else { /* if 0 then bipolar */
2022 data[0] =
2023 ((((ui_Channel & 0x03) << 14) & 0xC000) | (0 << 13) |
2024 data[0]);
2025
2026 }
2027
2028 do { /* Waiting of DA_READY BIT */
2029 us_TmpValue =
2030 ((unsigned short) inw(devpriv->iobase +
2031 APCI3120_RD_STATUS)) & 0x0001;
2032 } while (us_TmpValue != 0x0001);
2033
2034 if (ui_Channel <= 3)
2035 /*
2036 * for channel 0-3 out at the register 1 (wrDac1-8) data[i]
2037 * typecasted to ushort since word write is to be done
2038 */
2039 outw((unsigned short) data[0],
2040 devpriv->iobase + APCI3120_ANALOG_OUTPUT_1);
2041 else
2042 /*
2043 * for channel 4-7 out at the register 2 (wrDac5-8) data[i]
2044 * typecasted to ushort since word write is to be done
2045 */
2046 outw((unsigned short) data[0],
2047 devpriv->iobase + APCI3120_ANALOG_OUTPUT_2);
2048
2049 return insn->n;
2050}
diff --git a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c b/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c
deleted file mode 100644
index 5e321f91172f..000000000000
--- a/drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c
+++ /dev/null
@@ -1,3003 +0,0 @@
1/**
2@verbatim
3
4Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
5
6 ADDI-DATA GmbH
7 Dieselstrasse 3
8 D-77833 Ottersweier
9 Tel: +19(0)7223/9493-0
10 Fax: +49(0)7223/9493-92
11 http://www.addi-data.com
12 info@addi-data.com
13
14This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
15
16This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17
18@endverbatim
19*/
20/*
21
22 +-----------------------------------------------------------------------+
23 | (C) ADDI-DATA GmbH Dieselstraße 3 D-77833 Ottersweier |
24 +-----------------------------------------------------------------------+
25 | Tel : +49 (0) 7223/9493-0 | email : info@addi-data.com |
26 | Fax : +49 (0) 7223/9493-92 | Internet : http://www.addi-data.com |
27 +-------------------------------+---------------------------------------+
28 | Project : APCI-3200 | Compiler : GCC |
29 | Module name : hwdrv_apci3200.c| Version : 2.96 |
30 +-------------------------------+---------------------------------------+
31 | Project manager: Eric Stolz | Date : 02/12/2002 |
32 +-------------------------------+---------------------------------------+
33 | Description : Hardware Layer Access For APCI-3200 |
34 +-----------------------------------------------------------------------+
35 | UPDATES |
36 +----------+-----------+------------------------------------------------+
37 | Date | Author | Description of updates |
38 +----------+-----------+------------------------------------------------+
39 | 02.07.04 | J. Krauth | Modification from the driver in order to |
40 | | | correct some errors when using several boards. |
41 | | | |
42 | | | |
43 +----------+-----------+------------------------------------------------+
44 | 26.10.04 | J. Krauth | - Update for COMEDI 0.7.68 |
45 | | | - Read eeprom value |
46 | | | - Append APCI-3300 |
47 +----------+-----------+------------------------------------------------+
48*/
49
50/* Card Specific information */
51/* #define APCI3200_ADDRESS_RANGE 264 */
52
53/* Analog Input related Defines */
54#define APCI3200_AI_OFFSET_GAIN 0
55#define APCI3200_AI_SC_TEST 4
56#define APCI3200_AI_IRQ 8
57#define APCI3200_AI_AUTOCAL 12
58#define APCI3200_RELOAD_CONV_TIME_VAL 32
59#define APCI3200_CONV_TIME_TIME_BASE 36
60#define APCI3200_RELOAD_DELAY_TIME_VAL 40
61#define APCI3200_DELAY_TIME_TIME_BASE 44
62#define APCI3200_AI_MODULE1 0
63#define APCI3200_AI_MODULE2 64
64#define APCI3200_AI_MODULE3 128
65#define APCI3200_AI_MODULE4 192
66#define TRUE 1
67#define FALSE 0
68#define APCI3200_AI_EOSIRQ 16
69#define APCI3200_AI_EOS 20
70#define APCI3200_AI_CHAN_ID 24
71#define APCI3200_AI_CHAN_VAL 28
72#define ANALOG_INPUT 0
73#define TEMPERATURE 1
74#define RESISTANCE 2
75
76#define ENABLE_EXT_TRIG 1
77#define ENABLE_EXT_GATE 2
78#define ENABLE_EXT_TRIG_GATE 3
79
80#define APCI3200_MAXVOLT 2.5
81#define ADDIDATA_GREATER_THAN_TEST 0
82#define ADDIDATA_LESS_THAN_TEST 1
83
84#define ADDIDATA_UNIPOLAR 1
85#define ADDIDATA_BIPOLAR 2
86
87#define MAX_MODULE 4
88
89/* ANALOG INPUT RANGE */
90static const struct comedi_lrange range_apci3200_ai = {
91 8, {
92 BIP_RANGE(10),
93 BIP_RANGE(5),
94 BIP_RANGE(2),
95 BIP_RANGE(1),
96 UNI_RANGE(10),
97 UNI_RANGE(5),
98 UNI_RANGE(2),
99 UNI_RANGE(1)
100 }
101};
102
103static const struct comedi_lrange range_apci3300_ai = {
104 4, {
105 UNI_RANGE(10),
106 UNI_RANGE(5),
107 UNI_RANGE(2),
108 UNI_RANGE(1)
109 }
110};
111
112int MODULE_NO;
113struct {
114 int i_Gain;
115 int i_Polarity;
116 int i_OffsetRange;
117 int i_Coupling;
118 int i_SingleDiff;
119 int i_AutoCalibration;
120 unsigned int ui_ReloadValue;
121 unsigned int ui_TimeUnitReloadVal;
122 int i_Interrupt;
123 int i_ModuleSelection;
124} Config_Parameters_Module1, Config_Parameters_Module2,
125 Config_Parameters_Module3, Config_Parameters_Module4;
126
127
128struct str_ADDIDATA_RTDStruct {
129 unsigned int ul_NumberOfValue;
130 unsigned int *pul_ResistanceValue;
131 unsigned int *pul_TemperatureValue;
132};
133
134struct str_Module {
135 unsigned long ul_CurrentSourceCJC;
136 unsigned long ul_CurrentSource[5];
137 unsigned long ul_GainFactor[8]; /* Gain Factor */
138 unsigned int w_GainValue[10];
139};
140
141struct str_BoardInfos {
142
143 int i_CJCAvailable;
144 int i_CJCPolarity;
145 int i_CJCGain;
146 int i_InterruptFlag;
147 int i_ADDIDATAPolarity;
148 int i_ADDIDATAGain;
149 int i_AutoCalibration;
150 int i_ADDIDATAConversionTime;
151 int i_ADDIDATAConversionTimeUnit;
152 int i_ADDIDATAType;
153 int i_ChannelNo;
154 int i_ChannelCount;
155 int i_ScanType;
156 int i_FirstChannel;
157 int i_LastChannel;
158 int i_Sum;
159 int i_Offset;
160 unsigned int ui_Channel_num;
161 int i_Count;
162 int i_Initialised;
163 unsigned int ui_InterruptChannelValue[144]; /* Buffer */
164 unsigned char b_StructInitialized;
165 /* 7 is the maximal number of channels */
166 unsigned int ui_ScanValueArray[7 + 12];
167
168 int i_ConnectionType;
169 int i_NbrOfModule;
170 struct str_Module s_Module[MAX_MODULE];
171};
172
173/* BEGIN JK 06.07.04: Management of sevrals boards */
174/*
175 int i_CJCAvailable=1;
176 int i_CJCPolarity=0;
177 int i_CJCGain=2;/* changed from 0 to 2 */
178 int i_InterruptFlag=0;
179 int i_ADDIDATAPolarity;
180 int i_ADDIDATAGain;
181 int i_AutoCalibration=0; /* : auto calibration */
182 int i_ADDIDATAConversionTime;
183 int i_ADDIDATAConversionTimeUnit;
184 int i_ADDIDATAType;
185 int i_ChannelNo;
186 int i_ChannelCount=0;
187 int i_ScanType;
188 int i_FirstChannel;
189 int i_LastChannel;
190 int i_Sum=0;
191 int i_Offset;
192 unsigned int ui_Channel_num=0;
193 static int i_Count=0;
194 int i_Initialised=0;
195 unsigned int ui_InterruptChannelValue[96]; /* Buffer */
196*/
197struct str_BoardInfos s_BoardInfos[100]; /* 100 will be the max number of boards to be used */
198/* END JK 06.07.04: Management of sevrals boards */
199
200#define AMCC_OP_REG_MCSR 0x3c
201#define EEPROM_BUSY 0x80000000
202#define NVCMD_LOAD_LOW (0x4 << 5) /* nvRam load low command */
203#define NVCMD_LOAD_HIGH (0x5 << 5) /* nvRam load high command */
204#define NVCMD_BEGIN_READ (0x7 << 5) /* nvRam begin read command */
205#define NVCMD_BEGIN_WRITE (0x6 << 5) /* EEPROM begin write command */
206
207static int i_AddiHeaderRW_ReadEeprom(int i_NbOfWordsToRead,
208 unsigned int dw_PCIBoardEepromAddress,
209 unsigned short w_EepromStartAddress,
210 unsigned short *pw_DataRead)
211{
212 unsigned int dw_eeprom_busy = 0;
213 int i_Counter = 0;
214 int i_WordCounter;
215 int i;
216 unsigned char pb_ReadByte[1];
217 unsigned char b_ReadLowByte = 0;
218 unsigned char b_ReadHighByte = 0;
219 unsigned char b_SelectedAddressLow = 0;
220 unsigned char b_SelectedAddressHigh = 0;
221 unsigned short w_ReadWord = 0;
222
223 for (i_WordCounter = 0; i_WordCounter < i_NbOfWordsToRead;
224 i_WordCounter++) {
225 do {
226 dw_eeprom_busy =
227 inl(dw_PCIBoardEepromAddress +
228 AMCC_OP_REG_MCSR);
229 dw_eeprom_busy = dw_eeprom_busy & EEPROM_BUSY;
230 } while (dw_eeprom_busy == EEPROM_BUSY);
231
232 for (i_Counter = 0; i_Counter < 2; i_Counter++) {
233 b_SelectedAddressLow = (w_EepromStartAddress + i_Counter) % 256; /* Read the low 8 bit part */
234 b_SelectedAddressHigh = (w_EepromStartAddress + i_Counter) / 256; /* Read the high 8 bit part */
235
236 /* Select the load low address mode */
237 outb(NVCMD_LOAD_LOW,
238 dw_PCIBoardEepromAddress + AMCC_OP_REG_MCSR +
239 3);
240
241 /* Wait on busy */
242 do {
243 dw_eeprom_busy =
244 inl(dw_PCIBoardEepromAddress +
245 AMCC_OP_REG_MCSR);
246 dw_eeprom_busy = dw_eeprom_busy & EEPROM_BUSY;
247 } while (dw_eeprom_busy == EEPROM_BUSY);
248
249 /* Load the low address */
250 outb(b_SelectedAddressLow,
251 dw_PCIBoardEepromAddress + AMCC_OP_REG_MCSR +
252 2);
253
254 /* Wait on busy */
255 do {
256 dw_eeprom_busy =
257 inl(dw_PCIBoardEepromAddress +
258 AMCC_OP_REG_MCSR);
259 dw_eeprom_busy = dw_eeprom_busy & EEPROM_BUSY;
260 } while (dw_eeprom_busy == EEPROM_BUSY);
261
262 /* Select the load high address mode */
263 outb(NVCMD_LOAD_HIGH,
264 dw_PCIBoardEepromAddress + AMCC_OP_REG_MCSR +
265 3);
266
267 /* Wait on busy */
268 do {
269 dw_eeprom_busy =
270 inl(dw_PCIBoardEepromAddress +
271 AMCC_OP_REG_MCSR);
272 dw_eeprom_busy = dw_eeprom_busy & EEPROM_BUSY;
273 } while (dw_eeprom_busy == EEPROM_BUSY);
274
275 /* Load the high address */
276 outb(b_SelectedAddressHigh,
277 dw_PCIBoardEepromAddress + AMCC_OP_REG_MCSR +
278 2);
279
280 /* Wait on busy */
281 do {
282 dw_eeprom_busy =
283 inl(dw_PCIBoardEepromAddress +
284 AMCC_OP_REG_MCSR);
285 dw_eeprom_busy = dw_eeprom_busy & EEPROM_BUSY;
286 } while (dw_eeprom_busy == EEPROM_BUSY);
287
288 /* Select the READ mode */
289 outb(NVCMD_BEGIN_READ,
290 dw_PCIBoardEepromAddress + AMCC_OP_REG_MCSR +
291 3);
292
293 /* Wait on busy */
294 do {
295 dw_eeprom_busy =
296 inl(dw_PCIBoardEepromAddress +
297 AMCC_OP_REG_MCSR);
298 dw_eeprom_busy = dw_eeprom_busy & EEPROM_BUSY;
299 } while (dw_eeprom_busy == EEPROM_BUSY);
300
301 /* Read data into the EEPROM */
302 *pb_ReadByte =
303 inb(dw_PCIBoardEepromAddress +
304 AMCC_OP_REG_MCSR + 2);
305
306 /* Wait on busy */
307 do {
308 dw_eeprom_busy =
309 inl(dw_PCIBoardEepromAddress +
310 AMCC_OP_REG_MCSR);
311 dw_eeprom_busy = dw_eeprom_busy & EEPROM_BUSY;
312 } while (dw_eeprom_busy == EEPROM_BUSY);
313
314 /* Select the upper address part */
315 if (i_Counter == 0)
316 b_ReadLowByte = pb_ReadByte[0];
317 else
318 b_ReadHighByte = pb_ReadByte[0];
319
320
321 /* Sleep */
322 msleep(1);
323
324 }
325 w_ReadWord =
326 (b_ReadLowByte | (((unsigned short)b_ReadHighByte) *
327 256));
328
329 pw_DataRead[i_WordCounter] = w_ReadWord;
330
331 w_EepromStartAddress += 2; /* to read the next word */
332
333 } /* for (...) i_NbOfWordsToRead */
334 return 0;
335}
336
337static void v_GetAPCI3200EepromCalibrationValue(unsigned int dw_PCIBoardEepromAddress,
338 struct str_BoardInfos *BoardInformations)
339{
340 unsigned short w_AnalogInputMainHeaderAddress;
341 unsigned short w_AnalogInputComponentAddress;
342 unsigned short w_NumberOfModuls = 0;
343 unsigned short w_CurrentSources[2];
344 unsigned short w_ModulCounter = 0;
345 unsigned short w_FirstHeaderSize = 0;
346 unsigned short w_NumberOfInputs = 0;
347 unsigned short w_CJCFlag = 0;
348 unsigned short w_NumberOfGainValue = 0;
349 unsigned short w_SingleHeaderAddress = 0;
350 unsigned short w_SingleHeaderSize = 0;
351 unsigned short w_Input = 0;
352 unsigned short w_GainFactorAddress = 0;
353 unsigned short w_GainFactorValue[2];
354 unsigned short w_GainIndex = 0;
355 unsigned short w_GainValue = 0;
356
357 /*****************************************/
358 /** Get the Analog input header address **/
359 /*****************************************/
360 i_AddiHeaderRW_ReadEeprom(1, /* i_NbOfWordsToRead */
361 dw_PCIBoardEepromAddress, 0x116, /* w_EepromStartAddress: Analog input header address */
362 &w_AnalogInputMainHeaderAddress);
363
364 /*******************************************/
365 /** Compute the real analog input address **/
366 /*******************************************/
367 w_AnalogInputMainHeaderAddress = w_AnalogInputMainHeaderAddress + 0x100;
368
369 /******************************/
370 /** Get the number of moduls **/
371 /******************************/
372 i_AddiHeaderRW_ReadEeprom(1, /* i_NbOfWordsToRead */
373 dw_PCIBoardEepromAddress, w_AnalogInputMainHeaderAddress + 0x02, /* w_EepromStartAddress: Number of conponment */
374 &w_NumberOfModuls);
375
376 for (w_ModulCounter = 0; w_ModulCounter < w_NumberOfModuls;
377 w_ModulCounter++) {
378 /***********************************/
379 /** Compute the component address **/
380 /***********************************/
381 w_AnalogInputComponentAddress =
382 w_AnalogInputMainHeaderAddress +
383 (w_FirstHeaderSize * w_ModulCounter) + 0x04;
384
385 /****************************/
386 /** Read first header size **/
387 /****************************/
388 i_AddiHeaderRW_ReadEeprom(1, /* i_NbOfWordsToRead */
389 dw_PCIBoardEepromAddress, w_AnalogInputComponentAddress, /* Address of the first header */
390 &w_FirstHeaderSize);
391
392 w_FirstHeaderSize = w_FirstHeaderSize >> 4;
393
394 /***************************/
395 /** Read number of inputs **/
396 /***************************/
397 i_AddiHeaderRW_ReadEeprom(1, /* i_NbOfWordsToRead */
398 dw_PCIBoardEepromAddress, w_AnalogInputComponentAddress + 0x06, /* Number of inputs for the first modul */
399 &w_NumberOfInputs);
400
401 w_NumberOfInputs = w_NumberOfInputs >> 4;
402
403 /***********************/
404 /** Read the CJC flag **/
405 /***********************/
406 i_AddiHeaderRW_ReadEeprom(1, /* i_NbOfWordsToRead */
407 dw_PCIBoardEepromAddress, w_AnalogInputComponentAddress + 0x08, /* CJC flag */
408 &w_CJCFlag);
409
410 w_CJCFlag = (w_CJCFlag >> 3) & 0x1; /* Get only the CJC flag */
411
412 /*******************************/
413 /** Read number of gain value **/
414 /*******************************/
415 i_AddiHeaderRW_ReadEeprom(1, /* i_NbOfWordsToRead */
416 dw_PCIBoardEepromAddress, w_AnalogInputComponentAddress + 0x44, /* Number of gain value */
417 &w_NumberOfGainValue);
418
419 w_NumberOfGainValue = w_NumberOfGainValue & 0xFF;
420
421 /***********************************/
422 /** Compute single header address **/
423 /***********************************/
424 w_SingleHeaderAddress =
425 w_AnalogInputComponentAddress + 0x46 +
426 (((w_NumberOfGainValue / 16) + 1) * 2) +
427 (6 * w_NumberOfGainValue) +
428 (4 * (((w_NumberOfGainValue / 16) + 1) * 2));
429
430 /********************************************/
431 /** Read current sources value for input 1 **/
432 /********************************************/
433 i_AddiHeaderRW_ReadEeprom(1, /* i_NbOfWordsToRead */
434 dw_PCIBoardEepromAddress, w_SingleHeaderAddress, /* w_EepromStartAddress: Single header address */
435 &w_SingleHeaderSize);
436
437 w_SingleHeaderSize = w_SingleHeaderSize >> 4;
438
439 /*************************************/
440 /** Read gain factor for the module **/
441 /*************************************/
442 w_GainFactorAddress = w_AnalogInputComponentAddress;
443
444 for (w_GainIndex = 0; w_GainIndex < w_NumberOfGainValue;
445 w_GainIndex++) {
446 /************************************/
447 /** Read gain value for the module **/
448 /************************************/
449 i_AddiHeaderRW_ReadEeprom(1, /* i_NbOfWordsToRead */
450 dw_PCIBoardEepromAddress, w_AnalogInputComponentAddress + 70 + (2 * (1 + (w_NumberOfGainValue / 16))) + (0x02 * w_GainIndex), /* Gain value */
451 &w_GainValue);
452
453 BoardInformations->s_Module[w_ModulCounter].
454 w_GainValue[w_GainIndex] = w_GainValue;
455
456 /*************************************/
457 /** Read gain factor for the module **/
458 /*************************************/
459 i_AddiHeaderRW_ReadEeprom(2, /* i_NbOfWordsToRead */
460 dw_PCIBoardEepromAddress, w_AnalogInputComponentAddress + 70 + ((2 * w_NumberOfGainValue) + (2 * (1 + (w_NumberOfGainValue / 16)))) + (0x04 * w_GainIndex), /* Gain factor */
461 w_GainFactorValue);
462
463 BoardInformations->s_Module[w_ModulCounter].
464 ul_GainFactor[w_GainIndex] =
465 (w_GainFactorValue[1] << 16) +
466 w_GainFactorValue[0];
467 }
468
469 /***************************************************************/
470 /** Read current source value for each channels of the module **/
471 /***************************************************************/
472 for (w_Input = 0; w_Input < w_NumberOfInputs; w_Input++) {
473 /********************************************/
474 /** Read current sources value for input 1 **/
475 /********************************************/
476 i_AddiHeaderRW_ReadEeprom(2, /* i_NbOfWordsToRead */
477 dw_PCIBoardEepromAddress,
478 (w_Input * w_SingleHeaderSize) +
479 w_SingleHeaderAddress + 0x0C, w_CurrentSources);
480
481 /************************************/
482 /** Save the current sources value **/
483 /************************************/
484 BoardInformations->s_Module[w_ModulCounter].
485 ul_CurrentSource[w_Input] =
486 (w_CurrentSources[0] +
487 ((w_CurrentSources[1] & 0xFFF) << 16));
488 }
489
490 /***************************************/
491 /** Read the CJC current source value **/
492 /***************************************/
493 i_AddiHeaderRW_ReadEeprom(2, /* i_NbOfWordsToRead */
494 dw_PCIBoardEepromAddress,
495 (w_Input * w_SingleHeaderSize) + w_SingleHeaderAddress +
496 0x0C, w_CurrentSources);
497
498 /************************************/
499 /** Save the current sources value **/
500 /************************************/
501 BoardInformations->s_Module[w_ModulCounter].
502 ul_CurrentSourceCJC =
503 (w_CurrentSources[0] +
504 ((w_CurrentSources[1] & 0xFFF) << 16));
505 }
506}
507
508static int i_APCI3200_GetChannelCalibrationValue(struct comedi_device *dev,
509 unsigned int ui_Channel_num,
510 unsigned int *CJCCurrentSource,
511 unsigned int *ChannelCurrentSource,
512 unsigned int *ChannelGainFactor)
513{
514 int i_DiffChannel = 0;
515 int i_Module = 0;
516
517 /* Test if single or differential mode */
518 if (s_BoardInfos[dev->minor].i_ConnectionType == 1) {
519 /* if diff */
520
521 if (ui_Channel_num <= 1)
522 i_DiffChannel = ui_Channel_num, i_Module = 0;
523 else if ((ui_Channel_num >= 2) && (ui_Channel_num <= 3))
524 i_DiffChannel = ui_Channel_num - 2, i_Module = 1;
525 else if ((ui_Channel_num >= 4) && (ui_Channel_num <= 5))
526 i_DiffChannel = ui_Channel_num - 4, i_Module = 2;
527 else if ((ui_Channel_num >= 6) && (ui_Channel_num <= 7))
528 i_DiffChannel = ui_Channel_num - 6, i_Module = 3;
529
530 } else {
531 /* if single */
532 if ((ui_Channel_num == 0) || (ui_Channel_num == 1))
533 i_DiffChannel = 0, i_Module = 0;
534 else if ((ui_Channel_num == 2) || (ui_Channel_num == 3))
535 i_DiffChannel = 1, i_Module = 0;
536 else if ((ui_Channel_num == 4) || (ui_Channel_num == 5))
537 i_DiffChannel = 0, i_Module = 1;
538 else if ((ui_Channel_num == 6) || (ui_Channel_num == 7))
539 i_DiffChannel = 1, i_Module = 1;
540 else if ((ui_Channel_num == 8) || (ui_Channel_num == 9))
541 i_DiffChannel = 0, i_Module = 2;
542 else if ((ui_Channel_num == 10) || (ui_Channel_num == 11))
543 i_DiffChannel = 1, i_Module = 2;
544 else if ((ui_Channel_num == 12) || (ui_Channel_num == 13))
545 i_DiffChannel = 0, i_Module = 3;
546 else if ((ui_Channel_num == 14) || (ui_Channel_num == 15))
547 i_DiffChannel = 1, i_Module = 3;
548 }
549
550 /* Test if thermocouple or RTD mode */
551 *CJCCurrentSource =
552 s_BoardInfos[dev->minor].s_Module[i_Module].ul_CurrentSourceCJC;
553
554 *ChannelCurrentSource =
555 s_BoardInfos[dev->minor].s_Module[i_Module].
556 ul_CurrentSource[i_DiffChannel];
557 /* } */
558 /* } */
559
560 /* Channle gain factor */
561 *ChannelGainFactor =
562 s_BoardInfos[dev->minor].s_Module[i_Module].
563 ul_GainFactor[s_BoardInfos[dev->minor].i_ADDIDATAGain];
564 /* End JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values */
565
566 return 0;
567}
568
569static int apci3200_di_insn_bits(struct comedi_device *dev,
570 struct comedi_subdevice *s,
571 struct comedi_insn *insn,
572 unsigned int *data)
573{
574 struct addi_private *devpriv = dev->private;
575
576 data[1] = inl(devpriv->i_IobaseReserved) & 0xf;
577
578 return insn->n;
579}
580
581static int apci3200_do_insn_bits(struct comedi_device *dev,
582 struct comedi_subdevice *s,
583 struct comedi_insn *insn,
584 unsigned int *data)
585{
586 struct addi_private *devpriv = dev->private;
587
588 s->state = inl(devpriv->i_IobaseAddon) & 0xf;
589
590 if (comedi_dio_update_state(s, data))
591 outl(s->state, devpriv->i_IobaseAddon);
592
593 data[1] = s->state;
594
595 return insn->n;
596}
597
598static int i_APCI3200_Read1AnalogInputChannel(struct comedi_device *dev,
599 struct comedi_subdevice *s,
600 struct comedi_insn *insn,
601 unsigned int *data)
602{
603 struct addi_private *devpriv = dev->private;
604 unsigned int ui_EOC = 0;
605 unsigned int ui_ChannelNo = 0;
606 unsigned int ui_CommandRegister = 0;
607
608 /* BEGIN JK 06.07.04: Management of sevrals boards */
609 /* ui_ChannelNo=i_ChannelNo; */
610 ui_ChannelNo = s_BoardInfos[dev->minor].i_ChannelNo;
611
612 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
613 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
614 12) >> 19) & 1) != 1) ;
615 /*********************************/
616 /* Write the channel to configure */
617 /*********************************/
618 /* Begin JK 20.10.2004: Bad channel value is used when using differential mode */
619 /* outl(0 | ui_Channel_num , devpriv->iobase+i_Offset + 0x4); */
620 /* outl(0 | s_BoardInfos [dev->minor].ui_Channel_num , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 0x4); */
621 outl(0 | s_BoardInfos[dev->minor].i_ChannelNo,
622 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 0x4);
623 /* End JK 20.10.2004: Bad channel value is used when using differential mode */
624
625 /*******************************/
626 /* Set the convert timing unit */
627 /*******************************/
628 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
629 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
630 12) >> 19) & 1) != 1) ;
631
632 /* outl(i_ADDIDATAConversionTimeUnit , devpriv->iobase+i_Offset + 36); */
633 outl(s_BoardInfos[dev->minor].i_ADDIDATAConversionTimeUnit,
634 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 36);
635
636 /**************************/
637 /* Set the convert timing */
638 /**************************/
639 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
640 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
641 12) >> 19) & 1) != 1) ;
642
643 /* outl(i_ADDIDATAConversionTime , devpriv->iobase+i_Offset + 32); */
644 outl(s_BoardInfos[dev->minor].i_ADDIDATAConversionTime,
645 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 32);
646
647 /**************************************************************************/
648 /* Set the start end stop index to the selected channel and set the start */
649 /**************************************************************************/
650
651 ui_CommandRegister = ui_ChannelNo | (ui_ChannelNo << 8) | 0x80000;
652
653 /*Test if the interrupt is enable */
654 if (s_BoardInfos[dev->minor].i_InterruptFlag == 1) {
655 /* Enable the interrupt */
656 ui_CommandRegister = ui_CommandRegister | 0x00100000;
657 }
658
659 /******************************/
660 /* Write the command register */
661 /******************************/
662 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
663 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
664 12) >> 19) & 1) != 1) ;
665
666 /* outl(ui_CommandRegister, devpriv->iobase+i_Offset + 8); */
667 outl(ui_CommandRegister,
668 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 8);
669
670 /*Test if interrupt is enable */
671 if (s_BoardInfos[dev->minor].i_InterruptFlag == 0) {
672 do {
673 /*************************/
674 /*Read the EOC Status bit */
675 /*************************/
676
677 /* ui_EOC = inl(devpriv->iobase+i_Offset + 20) & 1; */
678 ui_EOC = inl(devpriv->iobase +
679 s_BoardInfos[dev->minor].i_Offset + 20) & 1;
680
681 } while (ui_EOC != 1);
682
683 /***************************************/
684 /* Read the digital value of the input */
685 /***************************************/
686
687 /* data[0] = inl (devpriv->iobase+i_Offset + 28); */
688 data[0] =
689 inl(devpriv->iobase +
690 s_BoardInfos[dev->minor].i_Offset + 28);
691 /* END JK 06.07.04: Management of sevrals boards */
692
693 }
694 return 0;
695}
696
697static int i_APCI3200_ReadCalibrationOffsetValue(struct comedi_device *dev,
698 unsigned int *data)
699{
700 struct addi_private *devpriv = dev->private;
701 unsigned int ui_Temp = 0, ui_EOC = 0;
702 unsigned int ui_CommandRegister = 0;
703
704 /* BEGIN JK 06.07.04: Management of sevrals boards */
705 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
706 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
707 12) >> 19) & 1) != 1) ;
708 /*********************************/
709 /* Write the channel to configure */
710 /*********************************/
711 /* Begin JK 20.10.2004: This seems not necessary ! */
712 /* outl(0 | ui_Channel_num , devpriv->iobase+i_Offset + 0x4); */
713 /* outl(0 | s_BoardInfos [dev->minor].ui_Channel_num , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 0x4); */
714 /* End JK 20.10.2004: This seems not necessary ! */
715
716 /*******************************/
717 /* Set the convert timing unit */
718 /*******************************/
719 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
720 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
721 12) >> 19) & 1) != 1) ;
722 /* outl(i_ADDIDATAConversionTimeUnit , devpriv->iobase+i_Offset + 36); */
723 outl(s_BoardInfos[dev->minor].i_ADDIDATAConversionTimeUnit,
724 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 36);
725 /**************************/
726 /* Set the convert timing */
727 /**************************/
728 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
729 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
730 12) >> 19) & 1) != 1) ;
731 /* outl(i_ADDIDATAConversionTime , devpriv->iobase+i_Offset + 32); */
732 outl(s_BoardInfos[dev->minor].i_ADDIDATAConversionTime,
733 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 32);
734 /*****************************/
735 /*Read the calibration offset */
736 /*****************************/
737 /* ui_Temp = inl(devpriv->iobase+i_Offset + 12); */
738 ui_Temp = inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 12);
739
740 /*********************************/
741 /*Configure the Offset Conversion */
742 /*********************************/
743 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
744 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
745 12) >> 19) & 1) != 1) ;
746 /* outl((ui_Temp | 0x00020000), devpriv->iobase+i_Offset + 12); */
747 outl((ui_Temp | 0x00020000),
748 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 12);
749 /*******************************/
750 /*Initialise ui_CommandRegister */
751 /*******************************/
752
753 ui_CommandRegister = 0;
754
755 /*Test if the interrupt is enable */
756 if (s_BoardInfos[dev->minor].i_InterruptFlag == 1) {
757 /*Enable the interrupt */
758 ui_CommandRegister = ui_CommandRegister | 0x00100000;
759 }
760
761 /**********************/
762 /*Start the conversion */
763 /**********************/
764 ui_CommandRegister = ui_CommandRegister | 0x00080000;
765
766 /***************************/
767 /*Write the command regiter */
768 /***************************/
769 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
770 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
771 12) >> 19) & 1) != 1) ;
772 /* outl(ui_CommandRegister, devpriv->iobase+i_Offset + 8); */
773 outl(ui_CommandRegister,
774 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 8);
775
776 /*Test if interrupt is enable */
777 if (s_BoardInfos[dev->minor].i_InterruptFlag == 0) {
778 do {
779 /*******************/
780 /*Read the EOC flag */
781 /*******************/
782
783 /* ui_EOC = inl (devpriv->iobase+i_Offset + 20) & 1; */
784 ui_EOC = inl(devpriv->iobase +
785 s_BoardInfos[dev->minor].i_Offset + 20) & 1;
786
787 } while (ui_EOC != 1);
788
789 /**************************************************/
790 /*Read the digital value of the calibration Offset */
791 /**************************************************/
792
793 /* data[0] = inl(devpriv->iobase+i_Offset+ 28); */
794 data[0] =
795 inl(devpriv->iobase +
796 s_BoardInfos[dev->minor].i_Offset + 28);
797 }
798 return 0;
799}
800
801static int i_APCI3200_ReadCalibrationGainValue(struct comedi_device *dev,
802 unsigned int *data)
803{
804 struct addi_private *devpriv = dev->private;
805 unsigned int ui_EOC = 0;
806 int ui_CommandRegister = 0;
807
808 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
809 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
810 12) >> 19) & 1) != 1) ;
811 /*********************************/
812 /* Write the channel to configure */
813 /*********************************/
814 /* Begin JK 20.10.2004: This seems not necessary ! */
815 /* outl(0 | ui_Channel_num , devpriv->iobase+i_Offset + 0x4); */
816 /* outl(0 | s_BoardInfos [dev->minor].ui_Channel_num , devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 0x4); */
817 /* End JK 20.10.2004: This seems not necessary ! */
818
819 /***************************/
820 /*Read the calibration gain */
821 /***************************/
822 /*******************************/
823 /* Set the convert timing unit */
824 /*******************************/
825 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
826 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
827 12) >> 19) & 1) != 1) ;
828 /* outl(i_ADDIDATAConversionTimeUnit , devpriv->iobase+i_Offset + 36); */
829 outl(s_BoardInfos[dev->minor].i_ADDIDATAConversionTimeUnit,
830 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 36);
831 /**************************/
832 /* Set the convert timing */
833 /**************************/
834 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
835 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
836 12) >> 19) & 1) != 1) ;
837 /* outl(i_ADDIDATAConversionTime , devpriv->iobase+i_Offset + 32); */
838 outl(s_BoardInfos[dev->minor].i_ADDIDATAConversionTime,
839 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 32);
840 /*******************************/
841 /*Configure the Gain Conversion */
842 /*******************************/
843 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
844 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
845 12) >> 19) & 1) != 1) ;
846 /* outl(0x00040000 , devpriv->iobase+i_Offset + 12); */
847 outl(0x00040000,
848 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 12);
849
850 /*******************************/
851 /*Initialise ui_CommandRegister */
852 /*******************************/
853
854 ui_CommandRegister = 0;
855
856 /*Test if the interrupt is enable */
857 if (s_BoardInfos[dev->minor].i_InterruptFlag == 1) {
858 /*Enable the interrupt */
859 ui_CommandRegister = ui_CommandRegister | 0x00100000;
860 }
861
862 /**********************/
863 /*Start the conversion */
864 /**********************/
865
866 ui_CommandRegister = ui_CommandRegister | 0x00080000;
867 /***************************/
868 /*Write the command regiter */
869 /***************************/
870 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
871 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
872 12) >> 19) & 1) != 1) ;
873 /* outl(ui_CommandRegister , devpriv->iobase+i_Offset + 8); */
874 outl(ui_CommandRegister,
875 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 8);
876
877 /*Test if interrupt is enable */
878 if (s_BoardInfos[dev->minor].i_InterruptFlag == 0) {
879 do {
880
881 /*******************/
882 /*Read the EOC flag */
883 /*******************/
884
885 /* ui_EOC = inl(devpriv->iobase+i_Offset + 20) & 1; */
886 ui_EOC = inl(devpriv->iobase +
887 s_BoardInfos[dev->minor].i_Offset + 20) & 1;
888
889 } while (ui_EOC != 1);
890
891 /************************************************/
892 /*Read the digital value of the calibration Gain */
893 /************************************************/
894
895 /* data[0] = inl(devpriv->iobase+i_Offset + 28); */
896 data[0] =
897 inl(devpriv->iobase +
898 s_BoardInfos[dev->minor].i_Offset + 28);
899
900 }
901 return 0;
902}
903
904static int i_APCI3200_ReadCJCValue(struct comedi_device *dev,
905 unsigned int *data)
906{
907 struct addi_private *devpriv = dev->private;
908 unsigned int ui_EOC = 0;
909 int ui_CommandRegister = 0;
910
911 /******************************/
912 /*Set the converting time unit */
913 /******************************/
914
915 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
916 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
917 12) >> 19) & 1) != 1) ;
918
919 /* outl(i_ADDIDATAConversionTimeUnit , devpriv->iobase+i_Offset + 36); */
920 outl(s_BoardInfos[dev->minor].i_ADDIDATAConversionTimeUnit,
921 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 36);
922 /**************************/
923 /* Set the convert timing */
924 /**************************/
925 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
926 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
927 12) >> 19) & 1) != 1) ;
928
929 /* outl(i_ADDIDATAConversionTime , devpriv->iobase+i_Offset + 32); */
930 outl(s_BoardInfos[dev->minor].i_ADDIDATAConversionTime,
931 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 32);
932
933 /******************************/
934 /*Configure the CJC Conversion */
935 /******************************/
936 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
937 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
938 12) >> 19) & 1) != 1) ;
939
940 /* outl( 0x00000400 , devpriv->iobase+i_Offset + 4); */
941 outl(0x00000400,
942 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 4);
943 /*******************************/
944 /*Initialise dw_CommandRegister */
945 /*******************************/
946 ui_CommandRegister = 0;
947 /*Test if the interrupt is enable */
948 if (s_BoardInfos[dev->minor].i_InterruptFlag == 1) {
949 /*Enable the interrupt */
950 ui_CommandRegister = ui_CommandRegister | 0x00100000;
951 }
952
953 /**********************/
954 /*Start the conversion */
955 /**********************/
956
957 ui_CommandRegister = ui_CommandRegister | 0x00080000;
958
959 /***************************/
960 /*Write the command regiter */
961 /***************************/
962 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
963 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
964 12) >> 19) & 1) != 1) ;
965 /* outl(ui_CommandRegister , devpriv->iobase+i_Offset + 8); */
966 outl(ui_CommandRegister,
967 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 8);
968
969 /*Test if interrupt is enable */
970 if (s_BoardInfos[dev->minor].i_InterruptFlag == 0) {
971 do {
972
973 /*******************/
974 /*Read the EOC flag */
975 /*******************/
976
977 /* ui_EOC = inl(devpriv->iobase+i_Offset + 20) & 1; */
978 ui_EOC = inl(devpriv->iobase +
979 s_BoardInfos[dev->minor].i_Offset + 20) & 1;
980
981 } while (ui_EOC != 1);
982
983 /***********************************/
984 /*Read the digital value of the CJC */
985 /***********************************/
986
987 /* data[0] = inl(devpriv->iobase+i_Offset + 28); */
988 data[0] =
989 inl(devpriv->iobase +
990 s_BoardInfos[dev->minor].i_Offset + 28);
991 }
992 return 0;
993}
994
995static int i_APCI3200_ReadCJCCalOffset(struct comedi_device *dev,
996 unsigned int *data)
997{
998 struct addi_private *devpriv = dev->private;
999 unsigned int ui_EOC = 0;
1000 int ui_CommandRegister = 0;
1001
1002 /*******************************************/
1003 /*Read calibration offset value for the CJC */
1004 /*******************************************/
1005 /*******************************/
1006 /* Set the convert timing unit */
1007 /*******************************/
1008 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
1009 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
1010 12) >> 19) & 1) != 1) ;
1011 /* outl(i_ADDIDATAConversionTimeUnit , devpriv->iobase+i_Offset + 36); */
1012 outl(s_BoardInfos[dev->minor].i_ADDIDATAConversionTimeUnit,
1013 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 36);
1014 /**************************/
1015 /* Set the convert timing */
1016 /**************************/
1017 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
1018 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
1019 12) >> 19) & 1) != 1) ;
1020 /* outl(i_ADDIDATAConversionTime , devpriv->iobase+i_Offset + 32); */
1021 outl(s_BoardInfos[dev->minor].i_ADDIDATAConversionTime,
1022 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 32);
1023 /******************************/
1024 /*Configure the CJC Conversion */
1025 /******************************/
1026 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
1027 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
1028 12) >> 19) & 1) != 1) ;
1029 /* outl(0x00000400 , devpriv->iobase+i_Offset + 4); */
1030 outl(0x00000400,
1031 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 4);
1032 /*********************************/
1033 /*Configure the Offset Conversion */
1034 /*********************************/
1035 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
1036 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
1037 12) >> 19) & 1) != 1) ;
1038 /* outl(0x00020000, devpriv->iobase+i_Offset + 12); */
1039 outl(0x00020000,
1040 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 12);
1041 /*******************************/
1042 /*Initialise ui_CommandRegister */
1043 /*******************************/
1044 ui_CommandRegister = 0;
1045 /*Test if the interrupt is enable */
1046 if (s_BoardInfos[dev->minor].i_InterruptFlag == 1) {
1047 /*Enable the interrupt */
1048 ui_CommandRegister = ui_CommandRegister | 0x00100000;
1049 }
1050
1051 /**********************/
1052 /*Start the conversion */
1053 /**********************/
1054 ui_CommandRegister = ui_CommandRegister | 0x00080000;
1055 /***************************/
1056 /*Write the command regiter */
1057 /***************************/
1058 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
1059 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
1060 12) >> 19) & 1) != 1) ;
1061 /* outl(ui_CommandRegister,devpriv->iobase+i_Offset + 8); */
1062 outl(ui_CommandRegister,
1063 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 8);
1064 if (s_BoardInfos[dev->minor].i_InterruptFlag == 0) {
1065 do {
1066 /*******************/
1067 /*Read the EOC flag */
1068 /*******************/
1069 /* ui_EOC = inl(devpriv->iobase+i_Offset + 20) & 1; */
1070 ui_EOC = inl(devpriv->iobase +
1071 s_BoardInfos[dev->minor].i_Offset + 20) & 1;
1072 } while (ui_EOC != 1);
1073
1074 /**************************************************/
1075 /*Read the digital value of the calibration Offset */
1076 /**************************************************/
1077 /* data[0] = inl(devpriv->iobase+i_Offset + 28); */
1078 data[0] =
1079 inl(devpriv->iobase +
1080 s_BoardInfos[dev->minor].i_Offset + 28);
1081 }
1082 return 0;
1083}
1084
1085static int i_APCI3200_ReadCJCCalGain(struct comedi_device *dev,
1086 unsigned int *data)
1087{
1088 struct addi_private *devpriv = dev->private;
1089 unsigned int ui_EOC = 0;
1090 int ui_CommandRegister = 0;
1091
1092 /*******************************/
1093 /* Set the convert timing unit */
1094 /*******************************/
1095 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
1096 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
1097 12) >> 19) & 1) != 1) ;
1098 /* outl(i_ADDIDATAConversionTimeUnit , devpriv->iobase+i_Offset + 36); */
1099 outl(s_BoardInfos[dev->minor].i_ADDIDATAConversionTimeUnit,
1100 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 36);
1101 /**************************/
1102 /* Set the convert timing */
1103 /**************************/
1104 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
1105 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
1106 12) >> 19) & 1) != 1) ;
1107 /* outl(i_ADDIDATAConversionTime , devpriv->iobase+i_Offset + 32); */
1108 outl(s_BoardInfos[dev->minor].i_ADDIDATAConversionTime,
1109 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 32);
1110 /******************************/
1111 /*Configure the CJC Conversion */
1112 /******************************/
1113 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
1114 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
1115 12) >> 19) & 1) != 1) ;
1116 /* outl(0x00000400,devpriv->iobase+i_Offset + 4); */
1117 outl(0x00000400,
1118 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 4);
1119 /*******************************/
1120 /*Configure the Gain Conversion */
1121 /*******************************/
1122 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
1123 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
1124 12) >> 19) & 1) != 1) ;
1125 /* outl(0x00040000,devpriv->iobase+i_Offset + 12); */
1126 outl(0x00040000,
1127 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 12);
1128
1129 /*******************************/
1130 /*Initialise dw_CommandRegister */
1131 /*******************************/
1132 ui_CommandRegister = 0;
1133 /*Test if the interrupt is enable */
1134 if (s_BoardInfos[dev->minor].i_InterruptFlag == 1) {
1135 /*Enable the interrupt */
1136 ui_CommandRegister = ui_CommandRegister | 0x00100000;
1137 }
1138 /**********************/
1139 /*Start the conversion */
1140 /**********************/
1141 ui_CommandRegister = ui_CommandRegister | 0x00080000;
1142 /***************************/
1143 /*Write the command regiter */
1144 /***************************/
1145 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
1146 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
1147 12) >> 19) & 1) != 1) ;
1148 /* outl(ui_CommandRegister ,devpriv->iobase+i_Offset + 8); */
1149 outl(ui_CommandRegister,
1150 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 8);
1151 if (s_BoardInfos[dev->minor].i_InterruptFlag == 0) {
1152 do {
1153 /*******************/
1154 /*Read the EOC flag */
1155 /*******************/
1156 /* ui_EOC = inl(devpriv->iobase+i_Offset + 20) & 1; */
1157 ui_EOC = inl(devpriv->iobase +
1158 s_BoardInfos[dev->minor].i_Offset + 20) & 1;
1159 } while (ui_EOC != 1);
1160 /************************************************/
1161 /*Read the digital value of the calibration Gain */
1162 /************************************************/
1163 /* data[0] = inl (devpriv->iobase+i_Offset + 28); */
1164 data[0] =
1165 inl(devpriv->iobase +
1166 s_BoardInfos[dev->minor].i_Offset + 28);
1167 }
1168 return 0;
1169}
1170
1171static int apci3200_reset(struct comedi_device *dev)
1172{
1173 struct addi_private *devpriv = dev->private;
1174 int i_Temp;
1175 unsigned int dw_Dummy;
1176
1177 /* i_InterruptFlag=0; */
1178 /* i_Initialised==0; */
1179 /* i_Count=0; */
1180 /* i_Sum=0; */
1181
1182 s_BoardInfos[dev->minor].i_InterruptFlag = 0;
1183 s_BoardInfos[dev->minor].i_Initialised = 0;
1184 s_BoardInfos[dev->minor].i_Count = 0;
1185 s_BoardInfos[dev->minor].i_Sum = 0;
1186 s_BoardInfos[dev->minor].b_StructInitialized = 0;
1187
1188 outl(0x83838383, devpriv->i_IobaseAmcc + 0x60);
1189
1190 /* Enable the interrupt for the controller */
1191 dw_Dummy = inl(devpriv->i_IobaseAmcc + 0x38);
1192 outl(dw_Dummy | 0x2000, devpriv->i_IobaseAmcc + 0x38);
1193 outl(0, devpriv->i_IobaseAddon); /* Resets the output */
1194 /***************/
1195 /*Empty the buffer */
1196 /**************/
1197 for (i_Temp = 0; i_Temp <= 95; i_Temp++) {
1198 /* ui_InterruptChannelValue[i_Temp]=0; */
1199 s_BoardInfos[dev->minor].ui_InterruptChannelValue[i_Temp] = 0;
1200 } /* for(i_Temp=0;i_Temp<=95;i_Temp++) */
1201 /*****************************/
1202 /*Reset the START and IRQ bit */
1203 /*****************************/
1204 for (i_Temp = 0; i_Temp <= 192;) {
1205 while (((inl(devpriv->iobase + i_Temp + 12) >> 19) & 1) != 1) ;
1206 outl(0, devpriv->iobase + i_Temp + 8);
1207 i_Temp = i_Temp + 64;
1208 } /* for(i_Temp=0;i_Temp<=192;i_Temp+64) */
1209 return 0;
1210}
1211
1212/*
1213 * Read value of the selected channel
1214 *
1215 * data[0] : Digital Value Of Input
1216 * data[1] : Calibration Offset Value
1217 * data[2] : Calibration Gain Value
1218 * data[3] : CJC value
1219 * data[4] : CJC offset value
1220 * data[5] : CJC gain value
1221 * data[6] : CJC current source from eeprom
1222 * data[7] : Channel current source from eeprom
1223 * data[8] : Channle gain factor from eeprom
1224 */
1225static int apci3200_ai_read(struct comedi_device *dev,
1226 struct comedi_subdevice *s,
1227 struct comedi_insn *insn,
1228 unsigned int *data)
1229{
1230 unsigned int ui_DummyValue = 0;
1231 int i_ConvertCJCCalibration;
1232 int i = 0;
1233
1234 /* BEGIN JK 06.07.04: Management of sevrals boards */
1235 /* if(i_Initialised==0) */
1236 if (s_BoardInfos[dev->minor].i_Initialised == 0)
1237 /* END JK 06.07.04: Management of sevrals boards */
1238 {
1239 apci3200_reset(dev);
1240 return -EINVAL;
1241 } /* if(i_Initialised==0); */
1242
1243 switch (insn->unused[0]) {
1244 case 0:
1245
1246 i_APCI3200_Read1AnalogInputChannel(dev, s, insn,
1247 &ui_DummyValue);
1248 /* BEGIN JK 06.07.04: Management of sevrals boards */
1249 /* ui_InterruptChannelValue[i_Count+0]=ui_DummyValue; */
1250 s_BoardInfos[dev->minor].
1251 ui_InterruptChannelValue[s_BoardInfos[dev->minor].
1252 i_Count + 0] = ui_DummyValue;
1253 /* END JK 06.07.04: Management of sevrals boards */
1254
1255 /* Begin JK 25.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values */
1256 i_APCI3200_GetChannelCalibrationValue(dev,
1257 s_BoardInfos[dev->minor].ui_Channel_num,
1258 &s_BoardInfos[dev->minor].
1259 ui_InterruptChannelValue[s_BoardInfos[dev->minor].
1260 i_Count + 6],
1261 &s_BoardInfos[dev->minor].
1262 ui_InterruptChannelValue[s_BoardInfos[dev->minor].
1263 i_Count + 7],
1264 &s_BoardInfos[dev->minor].
1265 ui_InterruptChannelValue[s_BoardInfos[dev->minor].
1266 i_Count + 8]);
1267 /* End JK 25.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values */
1268
1269 /* BEGIN JK 06.07.04: Management of sevrals boards */
1270 /* if((i_ADDIDATAType==2) && (i_InterruptFlag == FALSE) && (i_CJCAvailable==1)) */
1271 if ((s_BoardInfos[dev->minor].i_ADDIDATAType == 2)
1272 && (s_BoardInfos[dev->minor].i_InterruptFlag == FALSE)
1273 && (s_BoardInfos[dev->minor].i_CJCAvailable == 1))
1274 /* END JK 06.07.04: Management of sevrals boards */
1275 {
1276 i_APCI3200_ReadCJCValue(dev, &ui_DummyValue);
1277 /* BEGIN JK 06.07.04: Management of sevrals boards */
1278 /* ui_InterruptChannelValue[i_Count + 3]=ui_DummyValue; */
1279 s_BoardInfos[dev->minor].
1280 ui_InterruptChannelValue[s_BoardInfos[dev->
1281 minor].i_Count + 3] = ui_DummyValue;
1282 /* END JK 06.07.04: Management of sevrals boards */
1283 } /* if((i_ADDIDATAType==2) && (i_InterruptFlag == FALSE)) */
1284 else {
1285 /* BEGIN JK 06.07.04: Management of sevrals boards */
1286 /* ui_InterruptChannelValue[i_Count + 3]=0; */
1287 s_BoardInfos[dev->minor].
1288 ui_InterruptChannelValue[s_BoardInfos[dev->
1289 minor].i_Count + 3] = 0;
1290 /* END JK 06.07.04: Management of sevrals boards */
1291 } /* elseif((i_ADDIDATAType==2) && (i_InterruptFlag == FALSE) && (i_CJCAvailable==1)) */
1292
1293 /* BEGIN JK 06.07.04: Management of sevrals boards */
1294 /* if (( i_AutoCalibration == FALSE) && (i_InterruptFlag == FALSE)) */
1295 if ((s_BoardInfos[dev->minor].i_AutoCalibration == FALSE)
1296 && (s_BoardInfos[dev->minor].i_InterruptFlag == FALSE))
1297 /* END JK 06.07.04: Management of sevrals boards */
1298 {
1299 i_APCI3200_ReadCalibrationOffsetValue(dev,
1300 &ui_DummyValue);
1301 /* BEGIN JK 06.07.04: Management of sevrals boards */
1302 /* ui_InterruptChannelValue[i_Count + 1]=ui_DummyValue; */
1303 s_BoardInfos[dev->minor].
1304 ui_InterruptChannelValue[s_BoardInfos[dev->
1305 minor].i_Count + 1] = ui_DummyValue;
1306 /* END JK 06.07.04: Management of sevrals boards */
1307 i_APCI3200_ReadCalibrationGainValue(dev,
1308 &ui_DummyValue);
1309 /* BEGIN JK 06.07.04: Management of sevrals boards */
1310 /* ui_InterruptChannelValue[i_Count + 2]=ui_DummyValue; */
1311 s_BoardInfos[dev->minor].
1312 ui_InterruptChannelValue[s_BoardInfos[dev->
1313 minor].i_Count + 2] = ui_DummyValue;
1314 /* END JK 06.07.04: Management of sevrals boards */
1315 } /* if (( i_AutoCalibration == FALSE) && (i_InterruptFlag == FALSE)) */
1316
1317 /* BEGIN JK 06.07.04: Management of sevrals boards */
1318 /* if((i_ADDIDATAType==2) && (i_InterruptFlag == FALSE)&& (i_CJCAvailable==1)) */
1319 if ((s_BoardInfos[dev->minor].i_ADDIDATAType == 2)
1320 && (s_BoardInfos[dev->minor].i_InterruptFlag == FALSE)
1321 && (s_BoardInfos[dev->minor].i_CJCAvailable == 1))
1322 /* END JK 06.07.04: Management of sevrals boards */
1323 {
1324 /**********************************************************/
1325 /*Test if the Calibration channel must be read for the CJC */
1326 /**********************************************************/
1327 /**********************************/
1328 /*Test if the polarity is the same */
1329 /**********************************/
1330 /* BEGIN JK 06.07.04: Management of sevrals boards */
1331 /* if(i_CJCPolarity!=i_ADDIDATAPolarity) */
1332 if (s_BoardInfos[dev->minor].i_CJCPolarity !=
1333 s_BoardInfos[dev->minor].i_ADDIDATAPolarity)
1334 /* END JK 06.07.04: Management of sevrals boards */
1335 {
1336 i_ConvertCJCCalibration = 1;
1337 } /* if(i_CJCPolarity!=i_ADDIDATAPolarity) */
1338 else {
1339 /* BEGIN JK 06.07.04: Management of sevrals boards */
1340 /* if(i_CJCGain==i_ADDIDATAGain) */
1341 if (s_BoardInfos[dev->minor].i_CJCGain ==
1342 s_BoardInfos[dev->minor].i_ADDIDATAGain)
1343 /* END JK 06.07.04: Management of sevrals boards */
1344 {
1345 i_ConvertCJCCalibration = 0;
1346 } /* if(i_CJCGain==i_ADDIDATAGain) */
1347 else {
1348 i_ConvertCJCCalibration = 1;
1349 } /* elseif(i_CJCGain==i_ADDIDATAGain) */
1350 } /* elseif(i_CJCPolarity!=i_ADDIDATAPolarity) */
1351 if (i_ConvertCJCCalibration == 1) {
1352 i_APCI3200_ReadCJCCalOffset(dev,
1353 &ui_DummyValue);
1354 /* BEGIN JK 06.07.04: Management of sevrals boards */
1355 /* ui_InterruptChannelValue[i_Count+4]=ui_DummyValue; */
1356 s_BoardInfos[dev->minor].
1357 ui_InterruptChannelValue[s_BoardInfos
1358 [dev->minor].i_Count + 4] =
1359 ui_DummyValue;
1360 /* END JK 06.07.04: Management of sevrals boards */
1361
1362 i_APCI3200_ReadCJCCalGain(dev, &ui_DummyValue);
1363
1364 /* BEGIN JK 06.07.04: Management of sevrals boards */
1365 /* ui_InterruptChannelValue[i_Count+5]=ui_DummyValue; */
1366 s_BoardInfos[dev->minor].
1367 ui_InterruptChannelValue[s_BoardInfos
1368 [dev->minor].i_Count + 5] =
1369 ui_DummyValue;
1370 /* END JK 06.07.04: Management of sevrals boards */
1371 } /* if(i_ConvertCJCCalibration==1) */
1372 else {
1373 /* BEGIN JK 06.07.04: Management of sevrals boards */
1374 /* ui_InterruptChannelValue[i_Count+4]=0; */
1375 /* ui_InterruptChannelValue[i_Count+5]=0; */
1376
1377 s_BoardInfos[dev->minor].
1378 ui_InterruptChannelValue[s_BoardInfos
1379 [dev->minor].i_Count + 4] = 0;
1380 s_BoardInfos[dev->minor].
1381 ui_InterruptChannelValue[s_BoardInfos
1382 [dev->minor].i_Count + 5] = 0;
1383 /* END JK 06.07.04: Management of sevrals boards */
1384 } /* elseif(i_ConvertCJCCalibration==1) */
1385 } /* if((i_ADDIDATAType==2) && (i_InterruptFlag == FALSE)) */
1386
1387 /* BEGIN JK 06.07.04: Management of sevrals boards */
1388 /* if(i_ScanType!=1) */
1389 if (s_BoardInfos[dev->minor].i_ScanType != 1) {
1390 /* i_Count=0; */
1391 s_BoardInfos[dev->minor].i_Count = 0;
1392 } /* if(i_ScanType!=1) */
1393 else {
1394 /* i_Count=i_Count +6; */
1395 /* Begin JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values */
1396 /* s_BoardInfos [dev->minor].i_Count=s_BoardInfos [dev->minor].i_Count +6; */
1397 s_BoardInfos[dev->minor].i_Count =
1398 s_BoardInfos[dev->minor].i_Count + 9;
1399 /* End JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values */
1400 } /* else if(i_ScanType!=1) */
1401
1402 /* if((i_ScanType==1) &&(i_InterruptFlag==1)) */
1403 if ((s_BoardInfos[dev->minor].i_ScanType == 1)
1404 && (s_BoardInfos[dev->minor].i_InterruptFlag == 1)) {
1405 /* i_Count=i_Count-6; */
1406 /* Begin JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values */
1407 /* s_BoardInfos [dev->minor].i_Count=s_BoardInfos [dev->minor].i_Count-6; */
1408 s_BoardInfos[dev->minor].i_Count =
1409 s_BoardInfos[dev->minor].i_Count - 9;
1410 /* End JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values */
1411 }
1412 /* if(i_ScanType==0) */
1413 if (s_BoardInfos[dev->minor].i_ScanType == 0) {
1414 /*
1415 data[0]= ui_InterruptChannelValue[0];
1416 data[1]= ui_InterruptChannelValue[1];
1417 data[2]= ui_InterruptChannelValue[2];
1418 data[3]= ui_InterruptChannelValue[3];
1419 data[4]= ui_InterruptChannelValue[4];
1420 data[5]= ui_InterruptChannelValue[5];
1421 */
1422 data[0] =
1423 s_BoardInfos[dev->minor].
1424 ui_InterruptChannelValue[0];
1425 data[1] =
1426 s_BoardInfos[dev->minor].
1427 ui_InterruptChannelValue[1];
1428 data[2] =
1429 s_BoardInfos[dev->minor].
1430 ui_InterruptChannelValue[2];
1431 data[3] =
1432 s_BoardInfos[dev->minor].
1433 ui_InterruptChannelValue[3];
1434 data[4] =
1435 s_BoardInfos[dev->minor].
1436 ui_InterruptChannelValue[4];
1437 data[5] =
1438 s_BoardInfos[dev->minor].
1439 ui_InterruptChannelValue[5];
1440
1441 /* Begin JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values */
1442 i_APCI3200_GetChannelCalibrationValue(dev,
1443 s_BoardInfos[dev->minor].ui_Channel_num,
1444 &data[6], &data[7], &data[8]);
1445 /* End JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values */
1446 }
1447 break;
1448 case 1:
1449
1450 for (i = 0; i < insn->n; i++) {
1451 /* data[i]=ui_InterruptChannelValue[i]; */
1452 data[i] =
1453 s_BoardInfos[dev->minor].
1454 ui_InterruptChannelValue[i];
1455 }
1456
1457 /* i_Count=0; */
1458 /* i_Sum=0; */
1459 /* if(i_ScanType==1) */
1460 s_BoardInfos[dev->minor].i_Count = 0;
1461 s_BoardInfos[dev->minor].i_Sum = 0;
1462 if (s_BoardInfos[dev->minor].i_ScanType == 1) {
1463 /* i_Initialised=0; */
1464 /* i_InterruptFlag=0; */
1465 s_BoardInfos[dev->minor].i_Initialised = 0;
1466 s_BoardInfos[dev->minor].i_InterruptFlag = 0;
1467 /* END JK 06.07.04: Management of sevrals boards */
1468 }
1469 break;
1470 default:
1471 printk("\nThe parameters passed are in error\n");
1472 apci3200_reset(dev);
1473 return -EINVAL;
1474 } /* switch(insn->unused[0]) */
1475
1476 return insn->n;
1477}
1478
1479/*
1480 * Configures The Analog Input Subdevice
1481 *
1482 * data[0] = 0 Normal AI
1483 * = 1 RTD
1484 * = 2 THERMOCOUPLE
1485 * data[1] = Gain To Use
1486 * data[2] = 0 Bipolar
1487 * = 1 Unipolar
1488 * data[3] = Offset Range
1489 * data[4] = 0 DC Coupling
1490 * = 1 AC Coupling
1491 * data[5] = 0 Single
1492 * = 1 Differential
1493 * data[6] = TimerReloadValue
1494 * data[7] = ConvertingTimeUnit
1495 * data[8] = 0 Analog voltage measurement
1496 * = 1 Resistance measurement
1497 * = 2 Temperature measurement
1498 * data[9] = 0 Interrupt Disable
1499 * = 1 INterrupt Enable
1500 * data[10] = Type of Thermocouple
1501 * data[11] = single channel Module Number
1502 * data[12] = 0 Single Read
1503 * = 1 Read more channel
1504 * = 2 Single scan
1505 * = 3 Continuous Scan
1506 * data[13] = Number of channels to read
1507 * data[14] = 0 RTD not used
1508 * = 1 RTD 2 wire connection
1509 * = 2 RTD 3 wire connection
1510 * = 3 RTD 4 wire connection
1511 */
1512static int apci3200_ai_config(struct comedi_device *dev,
1513 struct comedi_subdevice *s,
1514 struct comedi_insn *insn,
1515 unsigned int *data)
1516{
1517 struct addi_private *devpriv = dev->private;
1518 unsigned int ul_Config = 0, ul_Temp = 0;
1519 unsigned int ui_ChannelNo = 0;
1520 unsigned int ui_Dummy = 0;
1521 int i_err = 0;
1522
1523 /* BEGIN JK 06.07.04: Management of sevrals boards */
1524 /* Initialize the structure */
1525 if (s_BoardInfos[dev->minor].b_StructInitialized != 1) {
1526 s_BoardInfos[dev->minor].i_CJCAvailable = 1;
1527 s_BoardInfos[dev->minor].i_CJCPolarity = 0;
1528 s_BoardInfos[dev->minor].i_CJCGain = 2; /* changed from 0 to 2 */
1529 s_BoardInfos[dev->minor].i_InterruptFlag = 0;
1530 s_BoardInfos[dev->minor].i_AutoCalibration = 0; /* : auto calibration */
1531 s_BoardInfos[dev->minor].i_ChannelCount = 0;
1532 s_BoardInfos[dev->minor].i_Sum = 0;
1533 s_BoardInfos[dev->minor].ui_Channel_num = 0;
1534 s_BoardInfos[dev->minor].i_Count = 0;
1535 s_BoardInfos[dev->minor].i_Initialised = 0;
1536 s_BoardInfos[dev->minor].b_StructInitialized = 1;
1537
1538 /* Begin JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values */
1539 s_BoardInfos[dev->minor].i_ConnectionType = 0;
1540 /* End JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values */
1541
1542 /* Begin JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values */
1543 memset(s_BoardInfos[dev->minor].s_Module, 0,
1544 sizeof(s_BoardInfos[dev->minor].s_Module[MAX_MODULE]));
1545
1546 v_GetAPCI3200EepromCalibrationValue(devpriv->i_IobaseAmcc,
1547 &s_BoardInfos[dev->minor]);
1548 /* End JK 21.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values */
1549 }
1550
1551 if (data[0] != 0 && data[0] != 1 && data[0] != 2) {
1552 printk("\nThe selection of acquisition type is in error\n");
1553 i_err++;
1554 } /* if(data[0]!=0 && data[0]!=1 && data[0]!=2) */
1555 if (data[0] == 1) {
1556 if (data[14] != 0 && data[14] != 1 && data[14] != 2
1557 && data[14] != 4) {
1558 printk("\n Error in selection of RTD connection type\n");
1559 i_err++;
1560 } /* if(data[14]!=0 && data[14]!=1 && data[14]!=2 && data[14]!=4) */
1561 } /* if(data[0]==1 ) */
1562 if (data[1] < 0 || data[1] > 7) {
1563 printk("\nThe selection of gain is in error\n");
1564 i_err++;
1565 } /* if(data[1]<0 || data[1]>7) */
1566 if (data[2] != 0 && data[2] != 1) {
1567 printk("\nThe selection of polarity is in error\n");
1568 i_err++;
1569 } /* if(data[2]!=0 && data[2]!=1) */
1570 if (data[3] != 0) {
1571 printk("\nThe selection of offset range is in error\n");
1572 i_err++;
1573 } /* if(data[3]!=0) */
1574 if (data[4] != 0 && data[4] != 1) {
1575 printk("\nThe selection of coupling is in error\n");
1576 i_err++;
1577 } /* if(data[4]!=0 && data[4]!=1) */
1578 if (data[5] != 0 && data[5] != 1) {
1579 printk("\nThe selection of single/differential mode is in error\n");
1580 i_err++;
1581 } /* if(data[5]!=0 && data[5]!=1) */
1582 if (data[8] != 0 && data[8] != 1 && data[2] != 2) {
1583 printk("\nError in selection of functionality\n");
1584 } /* if(data[8]!=0 && data[8]!=1 && data[2]!=2) */
1585 if (data[12] == 0 || data[12] == 1) {
1586 if (data[6] != 20 && data[6] != 40 && data[6] != 80
1587 && data[6] != 160) {
1588 printk("\nThe selection of conversion time reload value is in error\n");
1589 i_err++;
1590 } /* if (data[6]!=20 && data[6]!=40 && data[6]!=80 && data[6]!=160 ) */
1591 if (data[7] != 2) {
1592 printk("\nThe selection of conversion time unit is in error\n");
1593 i_err++;
1594 } /* if(data[7]!=2) */
1595 }
1596 if (data[9] != 0 && data[9] != 1) {
1597 printk("\nThe selection of interrupt enable is in error\n");
1598 i_err++;
1599 } /* if(data[9]!=0 && data[9]!=1) */
1600 if (data[11] < 0 || data[11] > 4) {
1601 printk("\nThe selection of module is in error\n");
1602 i_err++;
1603 } /* if(data[11] <0 || data[11]>1) */
1604 if (data[12] < 0 || data[12] > 3) {
1605 printk("\nThe selection of singlechannel/scan selection is in error\n");
1606 i_err++;
1607 } /* if(data[12] < 0 || data[12]> 3) */
1608 if (data[13] < 0 || data[13] > 16) {
1609 printk("\nThe selection of number of channels is in error\n");
1610 i_err++;
1611 } /* if(data[13] <0 ||data[13] >15) */
1612
1613 /* BEGIN JK 06.07.04: Management of sevrals boards */
1614 /*
1615 i_ChannelCount=data[13];
1616 i_ScanType=data[12];
1617 i_ADDIDATAPolarity = data[2];
1618 i_ADDIDATAGain=data[1];
1619 i_ADDIDATAConversionTime=data[6];
1620 i_ADDIDATAConversionTimeUnit=data[7];
1621 i_ADDIDATAType=data[0];
1622 */
1623
1624 /* Save acquisition configuration for the actual board */
1625 s_BoardInfos[dev->minor].i_ChannelCount = data[13];
1626 s_BoardInfos[dev->minor].i_ScanType = data[12];
1627 s_BoardInfos[dev->minor].i_ADDIDATAPolarity = data[2];
1628 s_BoardInfos[dev->minor].i_ADDIDATAGain = data[1];
1629 s_BoardInfos[dev->minor].i_ADDIDATAConversionTime = data[6];
1630 s_BoardInfos[dev->minor].i_ADDIDATAConversionTimeUnit = data[7];
1631 s_BoardInfos[dev->minor].i_ADDIDATAType = data[0];
1632 /* Begin JK 19.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 */
1633 s_BoardInfos[dev->minor].i_ConnectionType = data[5];
1634 /* End JK 19.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 */
1635 /* END JK 06.07.04: Management of sevrals boards */
1636
1637 /* Begin JK 19.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 */
1638 memset(s_BoardInfos[dev->minor].ui_ScanValueArray, 0, (7 + 12) * sizeof(unsigned int)); /* 7 is the maximal number of channels */
1639 /* End JK 19.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 */
1640
1641 /* BEGIN JK 02.07.04 : This while can't be do, it block the process when using severals boards */
1642 /* while(i_InterruptFlag==1) */
1643 while (s_BoardInfos[dev->minor].i_InterruptFlag == 1) {
1644#ifndef MSXBOX
1645 udelay(1);
1646#else
1647 /* In the case where the driver is compiled for the MSX-Box */
1648 /* we used a printk to have a little delay because udelay */
1649 /* seems to be broken under the MSX-Box. */
1650 /* This solution hat to be studied. */
1651 printk("");
1652#endif
1653 }
1654 /* END JK 02.07.04 : This while can't be do, it block the process when using severals boards */
1655
1656 ui_ChannelNo = CR_CHAN(insn->chanspec); /* get the channel */
1657 /* BEGIN JK 06.07.04: Management of sevrals boards */
1658 /* i_ChannelNo=ui_ChannelNo; */
1659 /* ui_Channel_num =ui_ChannelNo; */
1660
1661 s_BoardInfos[dev->minor].i_ChannelNo = ui_ChannelNo;
1662 s_BoardInfos[dev->minor].ui_Channel_num = ui_ChannelNo;
1663
1664 /* END JK 06.07.04: Management of sevrals boards */
1665
1666 if (data[5] == 0) {
1667 if (ui_ChannelNo > 15) {
1668 printk("\nThe Selection of the channel is in error\n");
1669 i_err++;
1670 } /* if(ui_ChannelNo>15) */
1671 } /* if(data[5]==0) */
1672 else {
1673 if (data[14] == 2) {
1674 if (ui_ChannelNo > 3) {
1675 printk("\nThe Selection of the channel is in error\n");
1676 i_err++;
1677 } /* if(ui_ChannelNo>3) */
1678 } /* if(data[14]==2) */
1679 else {
1680 if (ui_ChannelNo > 7) {
1681 printk("\nThe Selection of the channel is in error\n");
1682 i_err++;
1683 } /* if(ui_ChannelNo>7) */
1684 } /* elseif(data[14]==2) */
1685 } /* elseif(data[5]==0) */
1686 if (data[12] == 0 || data[12] == 1) {
1687 switch (data[5]) {
1688 case 0:
1689 if (ui_ChannelNo <= 3) {
1690 /* BEGIN JK 06.07.04: Management of sevrals boards */
1691 /* i_Offset=0; */
1692 s_BoardInfos[dev->minor].i_Offset = 0;
1693 /* END JK 06.07.04: Management of sevrals boards */
1694 } /* if(ui_ChannelNo <=3) */
1695 if (ui_ChannelNo >= 4 && ui_ChannelNo <= 7) {
1696 /* BEGIN JK 06.07.04: Management of sevrals boards */
1697 /* i_Offset=64; */
1698 s_BoardInfos[dev->minor].i_Offset = 64;
1699 /* END JK 06.07.04: Management of sevrals boards */
1700 } /* if(ui_ChannelNo >=4 && ui_ChannelNo <=7) */
1701 if (ui_ChannelNo >= 8 && ui_ChannelNo <= 11) {
1702 /* BEGIN JK 06.07.04: Management of sevrals boards */
1703 /* i_Offset=128; */
1704 s_BoardInfos[dev->minor].i_Offset = 128;
1705 /* END JK 06.07.04: Management of sevrals boards */
1706 } /* if(ui_ChannelNo >=8 && ui_ChannelNo <=11) */
1707 if (ui_ChannelNo >= 12 && ui_ChannelNo <= 15) {
1708 /* BEGIN JK 06.07.04: Management of sevrals boards */
1709 /* i_Offset=192; */
1710 s_BoardInfos[dev->minor].i_Offset = 192;
1711 /* END JK 06.07.04: Management of sevrals boards */
1712 } /* if(ui_ChannelNo >=12 && ui_ChannelNo <=15) */
1713 break;
1714 case 1:
1715 if (data[14] == 2) {
1716 if (ui_ChannelNo == 0) {
1717 /* BEGIN JK 06.07.04: Management of sevrals boards */
1718 /* i_Offset=0; */
1719 s_BoardInfos[dev->minor].i_Offset = 0;
1720 /* END JK 06.07.04: Management of sevrals boards */
1721 } /* if(ui_ChannelNo ==0 ) */
1722 if (ui_ChannelNo == 1) {
1723 /* BEGIN JK 06.07.04: Management of sevrals boards */
1724 /* i_Offset=0; */
1725 s_BoardInfos[dev->minor].i_Offset = 64;
1726 /* END JK 06.07.04: Management of sevrals boards */
1727 } /* if(ui_ChannelNo ==1) */
1728 if (ui_ChannelNo == 2) {
1729 /* BEGIN JK 06.07.04: Management of sevrals boards */
1730 /* i_Offset=128; */
1731 s_BoardInfos[dev->minor].i_Offset = 128;
1732 /* END JK 06.07.04: Management of sevrals boards */
1733 } /* if(ui_ChannelNo ==2 ) */
1734 if (ui_ChannelNo == 3) {
1735 /* BEGIN JK 06.07.04: Management of sevrals boards */
1736 /* i_Offset=192; */
1737 s_BoardInfos[dev->minor].i_Offset = 192;
1738 /* END JK 06.07.04: Management of sevrals boards */
1739 } /* if(ui_ChannelNo ==3) */
1740
1741 /* BEGIN JK 06.07.04: Management of sevrals boards */
1742 /* i_ChannelNo=0; */
1743 s_BoardInfos[dev->minor].i_ChannelNo = 0;
1744 /* END JK 06.07.04: Management of sevrals boards */
1745 ui_ChannelNo = 0;
1746 break;
1747 } /* if(data[14]==2) */
1748 if (ui_ChannelNo <= 1) {
1749 /* BEGIN JK 06.07.04: Management of sevrals boards */
1750 /* i_Offset=0; */
1751 s_BoardInfos[dev->minor].i_Offset = 0;
1752 /* END JK 06.07.04: Management of sevrals boards */
1753 } /* if(ui_ChannelNo <=1) */
1754 if (ui_ChannelNo >= 2 && ui_ChannelNo <= 3) {
1755 /* BEGIN JK 06.07.04: Management of sevrals boards */
1756 /* i_ChannelNo=i_ChannelNo-2; */
1757 /* i_Offset=64; */
1758 s_BoardInfos[dev->minor].i_ChannelNo =
1759 s_BoardInfos[dev->minor].i_ChannelNo -
1760 2;
1761 s_BoardInfos[dev->minor].i_Offset = 64;
1762 /* END JK 06.07.04: Management of sevrals boards */
1763 ui_ChannelNo = ui_ChannelNo - 2;
1764 } /* if(ui_ChannelNo >=2 && ui_ChannelNo <=3) */
1765 if (ui_ChannelNo >= 4 && ui_ChannelNo <= 5) {
1766 /* BEGIN JK 06.07.04: Management of sevrals boards */
1767 /* i_ChannelNo=i_ChannelNo-4; */
1768 /* i_Offset=128; */
1769 s_BoardInfos[dev->minor].i_ChannelNo =
1770 s_BoardInfos[dev->minor].i_ChannelNo -
1771 4;
1772 s_BoardInfos[dev->minor].i_Offset = 128;
1773 /* END JK 06.07.04: Management of sevrals boards */
1774 ui_ChannelNo = ui_ChannelNo - 4;
1775 } /* if(ui_ChannelNo >=4 && ui_ChannelNo <=5) */
1776 if (ui_ChannelNo >= 6 && ui_ChannelNo <= 7) {
1777 /* BEGIN JK 06.07.04: Management of sevrals boards */
1778 /* i_ChannelNo=i_ChannelNo-6; */
1779 /* i_Offset=192; */
1780 s_BoardInfos[dev->minor].i_ChannelNo =
1781 s_BoardInfos[dev->minor].i_ChannelNo -
1782 6;
1783 s_BoardInfos[dev->minor].i_Offset = 192;
1784 /* END JK 06.07.04: Management of sevrals boards */
1785 ui_ChannelNo = ui_ChannelNo - 6;
1786 } /* if(ui_ChannelNo >=6 && ui_ChannelNo <=7) */
1787 break;
1788
1789 default:
1790 printk("\n This selection of polarity does not exist\n");
1791 i_err++;
1792 } /* switch(data[2]) */
1793 } /* if(data[12]==0 || data[12]==1) */
1794 else {
1795 switch (data[11]) {
1796 case 1:
1797 /* BEGIN JK 06.07.04: Management of sevrals boards */
1798 /* i_Offset=0; */
1799 s_BoardInfos[dev->minor].i_Offset = 0;
1800 /* END JK 06.07.04: Management of sevrals boards */
1801 break;
1802 case 2:
1803 /* BEGIN JK 06.07.04: Management of sevrals boards */
1804 /* i_Offset=64; */
1805 s_BoardInfos[dev->minor].i_Offset = 64;
1806 /* END JK 06.07.04: Management of sevrals boards */
1807 break;
1808 case 3:
1809 /* BEGIN JK 06.07.04: Management of sevrals boards */
1810 /* i_Offset=128; */
1811 s_BoardInfos[dev->minor].i_Offset = 128;
1812 /* END JK 06.07.04: Management of sevrals boards */
1813 break;
1814 case 4:
1815 /* BEGIN JK 06.07.04: Management of sevrals boards */
1816 /* i_Offset=192; */
1817 s_BoardInfos[dev->minor].i_Offset = 192;
1818 /* END JK 06.07.04: Management of sevrals boards */
1819 break;
1820 default:
1821 printk("\nError in module selection\n");
1822 i_err++;
1823 } /* switch(data[11]) */
1824 } /* elseif(data[12]==0 || data[12]==1) */
1825 if (i_err) {
1826 apci3200_reset(dev);
1827 return -EINVAL;
1828 }
1829 /* if(i_ScanType!=1) */
1830 if (s_BoardInfos[dev->minor].i_ScanType != 1) {
1831 /* BEGIN JK 06.07.04: Management of sevrals boards */
1832 /* i_Count=0; */
1833 /* i_Sum=0; */
1834 s_BoardInfos[dev->minor].i_Count = 0;
1835 s_BoardInfos[dev->minor].i_Sum = 0;
1836 /* END JK 06.07.04: Management of sevrals boards */
1837 } /* if(i_ScanType!=1) */
1838
1839 ul_Config =
1840 data[1] | (data[2] << 6) | (data[5] << 7) | (data[3] << 8) |
1841 (data[4] << 9);
1842 /* BEGIN JK 06.07.04: Management of sevrals boards */
1843 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
1844 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
1845 12) >> 19) & 1) != 1) ;
1846 /* END JK 06.07.04: Management of sevrals boards */
1847 /*********************************/
1848 /* Write the channel to configure */
1849 /*********************************/
1850 /* BEGIN JK 06.07.04: Management of sevrals boards */
1851 /* outl(0 | ui_ChannelNo , devpriv->iobase+i_Offset + 0x4); */
1852 outl(0 | ui_ChannelNo,
1853 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 0x4);
1854 /* END JK 06.07.04: Management of sevrals boards */
1855
1856 /* BEGIN JK 06.07.04: Management of sevrals boards */
1857 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
1858 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
1859 12) >> 19) & 1) != 1) ;
1860 /* END JK 06.07.04: Management of sevrals boards */
1861 /**************************/
1862 /* Reset the configuration */
1863 /**************************/
1864 /* BEGIN JK 06.07.04: Management of sevrals boards */
1865 /* outl(0 , devpriv->iobase+i_Offset + 0x0); */
1866 outl(0, devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 0x0);
1867 /* END JK 06.07.04: Management of sevrals boards */
1868
1869 /* BEGIN JK 06.07.04: Management of sevrals boards */
1870 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
1871 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
1872 12) >> 19) & 1) != 1) ;
1873 /* END JK 06.07.04: Management of sevrals boards */
1874
1875 /***************************/
1876 /* Write the configuration */
1877 /***************************/
1878 /* BEGIN JK 06.07.04: Management of sevrals boards */
1879 /* outl(ul_Config , devpriv->iobase+i_Offset + 0x0); */
1880 outl(ul_Config,
1881 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 0x0);
1882 /* END JK 06.07.04: Management of sevrals boards */
1883
1884 /***************************/
1885 /*Reset the calibration bit */
1886 /***************************/
1887 /* BEGIN JK 06.07.04: Management of sevrals boards */
1888 /* ul_Temp = inl(devpriv->iobase+i_Offset + 12); */
1889 ul_Temp = inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 12);
1890 /* END JK 06.07.04: Management of sevrals boards */
1891
1892 /* BEGIN JK 06.07.04: Management of sevrals boards */
1893 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
1894 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
1895 12) >> 19) & 1) != 1) ;
1896 /* END JK 06.07.04: Management of sevrals boards */
1897
1898 /* BEGIN JK 06.07.04: Management of sevrals boards */
1899 /* outl((ul_Temp & 0xFFF9FFFF) , devpriv->iobase+.i_Offset + 12); */
1900 outl((ul_Temp & 0xFFF9FFFF),
1901 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 12);
1902 /* END JK 06.07.04: Management of sevrals boards */
1903
1904 if (data[9] == 1) {
1905 devpriv->tsk_Current = current;
1906 /* BEGIN JK 06.07.04: Management of sevrals boards */
1907 /* i_InterruptFlag=1; */
1908 s_BoardInfos[dev->minor].i_InterruptFlag = 1;
1909 /* END JK 06.07.04: Management of sevrals boards */
1910 } /* if(data[9]==1) */
1911 else {
1912 /* BEGIN JK 06.07.04: Management of sevrals boards */
1913 /* i_InterruptFlag=0; */
1914 s_BoardInfos[dev->minor].i_InterruptFlag = 0;
1915 /* END JK 06.07.04: Management of sevrals boards */
1916 } /* else if(data[9]==1) */
1917
1918 /* BEGIN JK 06.07.04: Management of sevrals boards */
1919 /* i_Initialised=1; */
1920 s_BoardInfos[dev->minor].i_Initialised = 1;
1921 /* END JK 06.07.04: Management of sevrals boards */
1922
1923 /* BEGIN JK 06.07.04: Management of sevrals boards */
1924 /* if(i_ScanType==1) */
1925 if (s_BoardInfos[dev->minor].i_ScanType == 1)
1926 /* END JK 06.07.04: Management of sevrals boards */
1927 {
1928 /* BEGIN JK 06.07.04: Management of sevrals boards */
1929 /* i_Sum=i_Sum+1; */
1930 s_BoardInfos[dev->minor].i_Sum =
1931 s_BoardInfos[dev->minor].i_Sum + 1;
1932 /* END JK 06.07.04: Management of sevrals boards */
1933
1934 insn->unused[0] = 0;
1935 apci3200_ai_read(dev, s, insn, &ui_Dummy);
1936 }
1937
1938 return insn->n;
1939}
1940
1941/*
1942 * Tests the Selected Anlog Input Channel
1943 *
1944 * data[0] = 0 TestAnalogInputShortCircuit
1945 * = 1 TestAnalogInputConnection
1946 *
1947 * data[0] : Digital value obtained
1948 * data[1] : calibration offset
1949 * data[2] : calibration gain
1950 */
1951static int apci3200_ai_bits_test(struct comedi_device *dev,
1952 struct comedi_subdevice *s,
1953 struct comedi_insn *insn,
1954 unsigned int *data)
1955{
1956 struct addi_private *devpriv = dev->private;
1957 unsigned int ui_Configuration = 0;
1958 int i_Temp; /* ,i_TimeUnit; */
1959
1960 /* if(i_Initialised==0) */
1961
1962 if (s_BoardInfos[dev->minor].i_Initialised == 0) {
1963 apci3200_reset(dev);
1964 return -EINVAL;
1965 } /* if(i_Initialised==0); */
1966 if (data[0] != 0 && data[0] != 1) {
1967 printk("\nError in selection of functionality\n");
1968 apci3200_reset(dev);
1969 return -EINVAL;
1970 } /* if(data[0]!=0 && data[0]!=1) */
1971
1972 if (data[0] == 1) /* Perform Short Circuit TEST */
1973 {
1974 /**************************/
1975 /*Set the short-cicuit bit */
1976 /**************************/
1977 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
1978 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].
1979 i_Offset + 12) >> 19) & 1) !=
1980 1) ;
1981 /* outl((0x00001000 |i_ChannelNo) , devpriv->iobase+i_Offset + 4); */
1982 outl((0x00001000 | s_BoardInfos[dev->minor].i_ChannelNo),
1983 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
1984 4);
1985 /*************************/
1986 /*Set the time unit to ns */
1987 /*************************/
1988 /* i_TimeUnit= i_ADDIDATAConversionTimeUnit;
1989 i_ADDIDATAConversionTimeUnit= 1; */
1990 /* i_Temp= i_InterruptFlag ; */
1991 i_Temp = s_BoardInfos[dev->minor].i_InterruptFlag;
1992 s_BoardInfos[dev->minor].i_InterruptFlag = 0;
1993 i_APCI3200_Read1AnalogInputChannel(dev, s, insn, data);
1994 /* if(i_AutoCalibration == FALSE) */
1995 if (s_BoardInfos[dev->minor].i_AutoCalibration == FALSE) {
1996 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
1997 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].
1998 i_Offset +
1999 12) >> 19) & 1) != 1) ;
2000
2001 /* outl((0x00001000 |i_ChannelNo) , devpriv->iobase+i_Offset + 4); */
2002 outl((0x00001000 | s_BoardInfos[dev->minor].
2003 i_ChannelNo),
2004 devpriv->iobase +
2005 s_BoardInfos[dev->minor].i_Offset + 4);
2006 data++;
2007 i_APCI3200_ReadCalibrationOffsetValue(dev, data);
2008 data++;
2009 i_APCI3200_ReadCalibrationGainValue(dev, data);
2010 }
2011 } else {
2012 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
2013 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].
2014 i_Offset + 12) >> 19) & 1) !=
2015 1) ;
2016 /* outl((0x00000800|i_ChannelNo) , devpriv->iobase+i_Offset + 4); */
2017 outl((0x00000800 | s_BoardInfos[dev->minor].i_ChannelNo),
2018 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
2019 4);
2020 /* ui_Configuration = inl(devpriv->iobase+i_Offset + 0); */
2021 ui_Configuration =
2022 inl(devpriv->iobase +
2023 s_BoardInfos[dev->minor].i_Offset + 0);
2024 /*************************/
2025 /*Set the time unit to ns */
2026 /*************************/
2027 /* i_TimeUnit= i_ADDIDATAConversionTimeUnit;
2028 i_ADDIDATAConversionTimeUnit= 1; */
2029 /* i_Temp= i_InterruptFlag ; */
2030 i_Temp = s_BoardInfos[dev->minor].i_InterruptFlag;
2031 s_BoardInfos[dev->minor].i_InterruptFlag = 0;
2032 i_APCI3200_Read1AnalogInputChannel(dev, s, insn, data);
2033 /* if(i_AutoCalibration == FALSE) */
2034 if (s_BoardInfos[dev->minor].i_AutoCalibration == FALSE) {
2035 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
2036 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].
2037 i_Offset +
2038 12) >> 19) & 1) != 1) ;
2039 /* outl((0x00000800|i_ChannelNo) , devpriv->iobase+i_Offset + 4); */
2040 outl((0x00000800 | s_BoardInfos[dev->minor].
2041 i_ChannelNo),
2042 devpriv->iobase +
2043 s_BoardInfos[dev->minor].i_Offset + 4);
2044 data++;
2045 i_APCI3200_ReadCalibrationOffsetValue(dev, data);
2046 data++;
2047 i_APCI3200_ReadCalibrationGainValue(dev, data);
2048 }
2049 }
2050 /* i_InterruptFlag=i_Temp ; */
2051 s_BoardInfos[dev->minor].i_InterruptFlag = i_Temp;
2052 return insn->n;
2053}
2054
2055static int apci3200_ai_write(struct comedi_device *dev,
2056 struct comedi_subdevice *s,
2057 struct comedi_insn *insn,
2058 unsigned int *data)
2059{
2060 apci3200_reset(dev);
2061 return insn->n;
2062}
2063
2064static int apci3200_ai_cmdtest(struct comedi_device *dev,
2065 struct comedi_subdevice *s,
2066 struct comedi_cmd *cmd)
2067{
2068
2069 int err = 0;
2070 unsigned int ui_ConvertTime = 0;
2071 unsigned int ui_ConvertTimeBase = 0;
2072 unsigned int ui_DelayTime = 0;
2073 unsigned int ui_DelayTimeBase = 0;
2074 int i_NbrOfChannel = 0;
2075 int i_Cpt = 0;
2076 double d_ConversionTimeForAllChannels = 0.0;
2077 double d_SCANTimeNewUnit = 0.0;
2078 unsigned int arg;
2079
2080 /* Step 1 : check if triggers are trivially valid */
2081
2082 err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_EXT);
2083 err |= cfc_check_trigger_src(&cmd->scan_begin_src,
2084 TRIG_TIMER | TRIG_FOLLOW);
2085 err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_TIMER);
2086 err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
2087 err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
2088
2089 if (s_BoardInfos[dev->minor].i_InterruptFlag == 0)
2090 err |= -EINVAL;
2091
2092 if (err) {
2093 apci3200_reset(dev);
2094 return 1;
2095 }
2096
2097 /* Step 2a : make sure trigger sources are unique */
2098
2099 err |= cfc_check_trigger_is_unique(&cmd->start_src);
2100 err |= cfc_check_trigger_is_unique(&cmd->scan_begin_src);
2101 err |= cfc_check_trigger_is_unique(&cmd->stop_src);
2102
2103 /* Step 2b : and mutually compatible */
2104
2105 if (err) {
2106 apci3200_reset(dev);
2107 return 2;
2108 }
2109
2110 /* Step 3: check if arguments are trivially valid */
2111
2112 switch (cmd->start_src) {
2113 case TRIG_NOW:
2114 err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
2115 break;
2116 case TRIG_EXT:
2117 /* validate the trigger edge selection */
2118 arg = cmd->start_arg & 0xffff;
2119 if (arg < 1 || arg > 3) {
2120 cmd->start_arg &= ~0xffff;
2121 cmd->start_arg |= 1;
2122 err |= -EINVAL;
2123 }
2124 /* validate the trigger mode selection */
2125 arg = cmd->start_arg >> 16;
2126 if (arg != 2) {
2127 cmd->start_arg &= ~(0xffff << 16);
2128 cmd->start_arg |= (2 << 16);
2129 err |= -EINVAL;
2130 }
2131 break;
2132 }
2133
2134 err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len);
2135
2136 /* i_FirstChannel=cmd->chanlist[0]; */
2137 s_BoardInfos[dev->minor].i_FirstChannel = cmd->chanlist[0];
2138 /* i_LastChannel=cmd->chanlist[1]; */
2139 s_BoardInfos[dev->minor].i_LastChannel = cmd->chanlist[1];
2140
2141 if (cmd->convert_src == TRIG_TIMER) {
2142 ui_ConvertTime = cmd->convert_arg & 0xFFFF;
2143 ui_ConvertTimeBase = cmd->convert_arg >> 16;
2144 if (ui_ConvertTime != 20 && ui_ConvertTime != 40
2145 && ui_ConvertTime != 80 && ui_ConvertTime != 160)
2146 {
2147 printk("\nThe selection of conversion time reload value is in error\n");
2148 err++;
2149 } /* if (ui_ConvertTime!=20 && ui_ConvertTime!=40 && ui_ConvertTime!=80 && ui_ConvertTime!=160 ) */
2150 if (ui_ConvertTimeBase != 2) {
2151 printk("\nThe selection of conversion time unit is in error\n");
2152 err++;
2153 } /* if(ui_ConvertTimeBase!=2) */
2154 } else {
2155 ui_ConvertTime = 0;
2156 ui_ConvertTimeBase = 0;
2157 }
2158 if (cmd->scan_begin_src == TRIG_FOLLOW) {
2159 ui_DelayTime = 0;
2160 ui_DelayTimeBase = 0;
2161 } /* if(cmd->scan_begin_src==TRIG_FOLLOW) */
2162 else {
2163 ui_DelayTime = cmd->scan_begin_arg & 0xFFFF;
2164 ui_DelayTimeBase = cmd->scan_begin_arg >> 16;
2165 if (ui_DelayTimeBase != 2 && ui_DelayTimeBase != 3) {
2166 err++;
2167 printk("\nThe Delay time base selection is in error\n");
2168 }
2169 if (ui_DelayTime < 1 || ui_DelayTime > 1023) {
2170 err++;
2171 printk("\nThe Delay time value is in error\n");
2172 }
2173 if (err) {
2174 apci3200_reset(dev);
2175 return 3;
2176 }
2177 fpu_begin();
2178 d_SCANTimeNewUnit = (double)ui_DelayTime;
2179 /* i_NbrOfChannel= i_LastChannel-i_FirstChannel + 4; */
2180 i_NbrOfChannel =
2181 s_BoardInfos[dev->minor].i_LastChannel -
2182 s_BoardInfos[dev->minor].i_FirstChannel + 4;
2183 /**********************************************************/
2184 /*calculate the total conversion time for all the channels */
2185 /**********************************************************/
2186 d_ConversionTimeForAllChannels =
2187 (double)((double)ui_ConvertTime /
2188 (double)i_NbrOfChannel);
2189
2190 /*******************************/
2191 /*Convert the frequence in time */
2192 /*******************************/
2193 d_ConversionTimeForAllChannels =
2194 (double)1.0 / d_ConversionTimeForAllChannels;
2195 ui_ConvertTimeBase = 3;
2196 /***********************************/
2197 /*Test if the time unit is the same */
2198 /***********************************/
2199
2200 if (ui_DelayTimeBase <= ui_ConvertTimeBase) {
2201
2202 for (i_Cpt = 0;
2203 i_Cpt < (ui_ConvertTimeBase - ui_DelayTimeBase);
2204 i_Cpt++) {
2205
2206 d_ConversionTimeForAllChannels =
2207 d_ConversionTimeForAllChannels * 1000;
2208 d_ConversionTimeForAllChannels =
2209 d_ConversionTimeForAllChannels + 1;
2210 }
2211 } else {
2212 for (i_Cpt = 0;
2213 i_Cpt < (ui_DelayTimeBase - ui_ConvertTimeBase);
2214 i_Cpt++) {
2215 d_SCANTimeNewUnit = d_SCANTimeNewUnit * 1000;
2216
2217 }
2218 }
2219
2220 if (d_ConversionTimeForAllChannels >= d_SCANTimeNewUnit) {
2221
2222 printk("\nSCAN Delay value cannot be used\n");
2223 /*********************************/
2224 /*SCAN Delay value cannot be used */
2225 /*********************************/
2226 err++;
2227 }
2228 fpu_end();
2229 } /* else if(cmd->scan_begin_src==TRIG_FOLLOW) */
2230
2231 if (err) {
2232 apci3200_reset(dev);
2233 return 4;
2234 }
2235
2236 return 0;
2237}
2238
2239static int apci3200_cancel(struct comedi_device *dev,
2240 struct comedi_subdevice *s)
2241{
2242 struct addi_private *devpriv = dev->private;
2243 unsigned int ui_Configuration = 0;
2244
2245 /* i_InterruptFlag=0; */
2246 /* i_Initialised=0; */
2247 /* i_Count=0; */
2248 /* i_Sum=0; */
2249 s_BoardInfos[dev->minor].i_InterruptFlag = 0;
2250 s_BoardInfos[dev->minor].i_Initialised = 0;
2251 s_BoardInfos[dev->minor].i_Count = 0;
2252 s_BoardInfos[dev->minor].i_Sum = 0;
2253
2254 /*******************/
2255 /*Read the register */
2256 /*******************/
2257 /* ui_Configuration = inl(devpriv->iobase+i_Offset + 8); */
2258 ui_Configuration =
2259 inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 8);
2260 /*****************************/
2261 /*Reset the START and IRQ bit */
2262 /*****************************/
2263 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
2264 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
2265 12) >> 19) & 1) != 1) ;
2266 /* outl((ui_Configuration & 0xFFE7FFFF),devpriv->iobase+i_Offset + 8); */
2267 outl((ui_Configuration & 0xFFE7FFFF),
2268 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 8);
2269 return 0;
2270}
2271
2272/*
2273 * Does asynchronous acquisition
2274 * Determines the mode 1 or 2.
2275 */
2276static int apci3200_ai_cmd(struct comedi_device *dev,
2277 struct comedi_subdevice *s)
2278{
2279 struct addi_private *devpriv = dev->private;
2280 struct comedi_cmd *cmd = &s->async->cmd;
2281 unsigned int ui_Configuration = 0;
2282 /* INT i_CurrentSource = 0; */
2283 unsigned int ui_Trigger = 0;
2284 unsigned int ui_TriggerEdge = 0;
2285 unsigned int ui_Triggermode = 0;
2286 unsigned int ui_ScanMode = 0;
2287 unsigned int ui_ConvertTime = 0;
2288 unsigned int ui_ConvertTimeBase = 0;
2289 unsigned int ui_DelayTime = 0;
2290 unsigned int ui_DelayTimeBase = 0;
2291 unsigned int ui_DelayMode = 0;
2292
2293 /* i_FirstChannel=cmd->chanlist[0]; */
2294 /* i_LastChannel=cmd->chanlist[1]; */
2295 s_BoardInfos[dev->minor].i_FirstChannel = cmd->chanlist[0];
2296 s_BoardInfos[dev->minor].i_LastChannel = cmd->chanlist[1];
2297 if (cmd->start_src == TRIG_EXT) {
2298 ui_Trigger = 1;
2299 ui_TriggerEdge = cmd->start_arg & 0xFFFF;
2300 ui_Triggermode = cmd->start_arg >> 16;
2301 } /* if(cmd->start_src==TRIG_EXT) */
2302 else {
2303 ui_Trigger = 0;
2304 } /* elseif(cmd->start_src==TRIG_EXT) */
2305
2306 if (cmd->stop_src == TRIG_COUNT) {
2307 ui_ScanMode = 0;
2308 } /* if (cmd->stop_src==TRIG_COUNT) */
2309 else {
2310 ui_ScanMode = 2;
2311 } /* else if (cmd->stop_src==TRIG_COUNT) */
2312
2313 if (cmd->scan_begin_src == TRIG_FOLLOW) {
2314 ui_DelayTime = 0;
2315 ui_DelayTimeBase = 0;
2316 ui_DelayMode = 0;
2317 } /* if(cmd->scan_begin_src==TRIG_FOLLOW) */
2318 else {
2319 ui_DelayTime = cmd->scan_begin_arg & 0xFFFF;
2320 ui_DelayTimeBase = cmd->scan_begin_arg >> 16;
2321 ui_DelayMode = 1;
2322 } /* else if(cmd->scan_begin_src==TRIG_FOLLOW) */
2323 if (cmd->convert_src == TRIG_TIMER) {
2324 ui_ConvertTime = cmd->convert_arg & 0xFFFF;
2325 ui_ConvertTimeBase = cmd->convert_arg >> 16;
2326 } else {
2327 ui_ConvertTime = 0;
2328 ui_ConvertTimeBase = 0;
2329 }
2330
2331 /* if(i_ADDIDATAType ==1 || ((i_ADDIDATAType==2))) */
2332 /* { */
2333 /**************************************************/
2334 /*Read the old configuration of the current source */
2335 /**************************************************/
2336 /* ui_Configuration = inl(devpriv->iobase+i_Offset + 12); */
2337 ui_Configuration =
2338 inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 12);
2339 /***********************************************/
2340 /*Write the configuration of the current source */
2341 /***********************************************/
2342 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
2343 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
2344 12) >> 19) & 1) != 1) ;
2345 /* outl((ui_Configuration & 0xFFC00000 ), devpriv->iobase+i_Offset +12); */
2346 outl((ui_Configuration & 0xFFC00000),
2347 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 12);
2348 /* } */
2349 ui_Configuration = 0;
2350
2351 /* ui_Configuration = i_FirstChannel |(i_LastChannel << 8)| 0x00100000 | */
2352 ui_Configuration =
2353 s_BoardInfos[dev->minor].i_FirstChannel | (s_BoardInfos[dev->
2354 minor].
2355 i_LastChannel << 8) | 0x00100000 | (ui_Trigger << 24) |
2356 (ui_TriggerEdge << 25) | (ui_Triggermode << 27) | (ui_DelayMode
2357 << 18) | (ui_ScanMode << 16);
2358
2359 /*************************/
2360 /*Write the Configuration */
2361 /*************************/
2362 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
2363 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
2364 12) >> 19) & 1) != 1) ;
2365 /* outl( ui_Configuration, devpriv->iobase+i_Offset + 0x8); */
2366 outl(ui_Configuration,
2367 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 0x8);
2368 /***********************/
2369 /*Write the Delay Value */
2370 /***********************/
2371 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
2372 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
2373 12) >> 19) & 1) != 1) ;
2374 /* outl(ui_DelayTime,devpriv->iobase+i_Offset + 40); */
2375 outl(ui_DelayTime,
2376 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 40);
2377 /***************************/
2378 /*Write the Delay time base */
2379 /***************************/
2380 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
2381 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
2382 12) >> 19) & 1) != 1) ;
2383 /* outl(ui_DelayTimeBase,devpriv->iobase+i_Offset + 44); */
2384 outl(ui_DelayTimeBase,
2385 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 44);
2386 /*********************************/
2387 /*Write the conversion time value */
2388 /*********************************/
2389 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
2390 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
2391 12) >> 19) & 1) != 1) ;
2392 /* outl(ui_ConvertTime,devpriv->iobase+i_Offset + 32); */
2393 outl(ui_ConvertTime,
2394 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 32);
2395
2396 /********************************/
2397 /*Write the conversion time base */
2398 /********************************/
2399 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
2400 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
2401 12) >> 19) & 1) != 1) ;
2402 /* outl(ui_ConvertTimeBase,devpriv->iobase+i_Offset + 36); */
2403 outl(ui_ConvertTimeBase,
2404 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 36);
2405 /*******************/
2406 /*Read the register */
2407 /*******************/
2408 /* ui_Configuration = inl(devpriv->iobase+i_Offset + 4); */
2409 ui_Configuration =
2410 inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 4);
2411 /******************/
2412 /*Set the SCAN bit */
2413 /******************/
2414 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
2415 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
2416 12) >> 19) & 1) != 1) ;
2417
2418 /* outl(((ui_Configuration & 0x1E0FF) | 0x00002000),devpriv->iobase+i_Offset + 4); */
2419 outl(((ui_Configuration & 0x1E0FF) | 0x00002000),
2420 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 4);
2421 /*******************/
2422 /*Read the register */
2423 /*******************/
2424 ui_Configuration = 0;
2425 /* ui_Configuration = inl(devpriv->iobase+i_Offset + 8); */
2426 ui_Configuration =
2427 inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 8);
2428
2429 /*******************/
2430 /*Set the START bit */
2431 /*******************/
2432 /* while (((inl(devpriv->iobase+i_Offset+12)>>19) & 1) != 1); */
2433 while (((inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset +
2434 12) >> 19) & 1) != 1) ;
2435 /* outl((ui_Configuration | 0x00080000),devpriv->iobase+i_Offset + 8); */
2436 outl((ui_Configuration | 0x00080000),
2437 devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 8);
2438 return 0;
2439}
2440
2441/*
2442 * This function copies the acquired data(from FIFO) to Comedi buffer.
2443 */
2444static int i_APCI3200_InterruptHandleEos(struct comedi_device *dev)
2445{
2446 struct addi_private *devpriv = dev->private;
2447 struct comedi_subdevice *s = dev->read_subdev;
2448 unsigned int ui_StatusRegister = 0;
2449
2450 /* BEGIN JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 */
2451 /* comedi_async *async = s->async; */
2452 /* UINT *data; */
2453 /* data=async->data+async->buf_int_ptr;//new samples added from here onwards */
2454 int n = 0, i = 0;
2455 /* END JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 */
2456
2457 /************************************/
2458 /*Read the interrupt status register */
2459 /************************************/
2460 /* ui_StatusRegister = inl(devpriv->iobase+i_Offset + 16); */
2461 ui_StatusRegister =
2462 inl(devpriv->iobase + s_BoardInfos[dev->minor].i_Offset + 16);
2463
2464 /*************************/
2465 /*Test if interrupt occur */
2466 /*************************/
2467
2468 if ((ui_StatusRegister & 0x2) == 0x2) {
2469 /*************************/
2470 /*Read the channel number */
2471 /*************************/
2472 /* ui_ChannelNumber = inl(devpriv->iobase+i_Offset + 24); */
2473 /* BEGIN JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 */
2474 /* This value is not used */
2475 /* ui_ChannelNumber = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 24); */
2476 /* END JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 */
2477
2478 /*************************************/
2479 /*Read the digital Analog Input value */
2480 /*************************************/
2481
2482 /* data[i_Count] = inl(devpriv->iobase+i_Offset + 28); */
2483 /* Begin JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 */
2484 /* data[s_BoardInfos [dev->minor].i_Count] = inl(devpriv->iobase+s_BoardInfos [dev->minor].i_Offset + 28); */
2485 s_BoardInfos[dev->minor].ui_ScanValueArray[s_BoardInfos[dev->
2486 minor].i_Count] =
2487 inl(devpriv->iobase +
2488 s_BoardInfos[dev->minor].i_Offset + 28);
2489 /* End JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 */
2490
2491 /* if((i_Count == (i_LastChannel-i_FirstChannel+3))) */
2492 if ((s_BoardInfos[dev->minor].i_Count ==
2493 (s_BoardInfos[dev->minor].i_LastChannel -
2494 s_BoardInfos[dev->minor].
2495 i_FirstChannel + 3))) {
2496
2497 /* Begin JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values */
2498 s_BoardInfos[dev->minor].i_Count++;
2499
2500 for (i = s_BoardInfos[dev->minor].i_FirstChannel;
2501 i <= s_BoardInfos[dev->minor].i_LastChannel;
2502 i++) {
2503 i_APCI3200_GetChannelCalibrationValue(dev, i,
2504 &s_BoardInfos[dev->minor].
2505 ui_ScanValueArray[s_BoardInfos[dev->
2506 minor].i_Count + ((i -
2507 s_BoardInfos
2508 [dev->minor].
2509 i_FirstChannel)
2510 * 3)],
2511 &s_BoardInfos[dev->minor].
2512 ui_ScanValueArray[s_BoardInfos[dev->
2513 minor].i_Count + ((i -
2514 s_BoardInfos
2515 [dev->minor].
2516 i_FirstChannel)
2517 * 3) + 1],
2518 &s_BoardInfos[dev->minor].
2519 ui_ScanValueArray[s_BoardInfos[dev->
2520 minor].i_Count + ((i -
2521 s_BoardInfos
2522 [dev->minor].
2523 i_FirstChannel)
2524 * 3) + 2]);
2525 }
2526
2527 /* End JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values */
2528
2529 /* i_Count=-1; */
2530
2531 s_BoardInfos[dev->minor].i_Count = -1;
2532
2533 /* async->buf_int_count+=(i_LastChannel-i_FirstChannel+4)*sizeof(unsigned int); */
2534 /* Begin JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 */
2535 /* async->buf_int_count+=(s_BoardInfos [dev->minor].i_LastChannel-s_BoardInfos [dev->minor].i_FirstChannel+4)*sizeof(unsigned int); */
2536 /* End JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 */
2537 /* async->buf_int_ptr+=(i_LastChannel-i_FirstChannel+4)*sizeof(unsigned int); */
2538 /* Begin JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 */
2539 /* async->buf_int_ptr+=(s_BoardInfos [dev->minor].i_LastChannel-s_BoardInfos [dev->minor].i_FirstChannel+4)*sizeof(unsigned int); */
2540 /* comedi_eos(dev,s); */
2541
2542 /* Set the event type (Comedi Buffer End Of Scan) */
2543 s->async->events |= COMEDI_CB_EOS;
2544
2545 /* Test if enougth memory is available and allocate it for 7 values */
2546 n = comedi_buf_write_alloc(s,
2547 (7 + 12) * sizeof(unsigned int));
2548
2549 /* If not enough memory available, event is set to Comedi Buffer Error */
2550 if (n > ((7 + 12) * sizeof(unsigned int))) {
2551 printk("\ncomedi_buf_write_alloc n = %i", n);
2552 s->async->events |= COMEDI_CB_ERROR;
2553 }
2554 /* Write all 7 scan values in the comedi buffer */
2555 comedi_buf_memcpy_to(s, 0,
2556 (unsigned int *) s_BoardInfos[dev->minor].
2557 ui_ScanValueArray, (7 + 12) * sizeof(unsigned int));
2558
2559 /* Update comedi buffer pinters indexes */
2560 comedi_buf_write_free(s,
2561 (7 + 12) * sizeof(unsigned int));
2562
2563 /* Send events */
2564 comedi_event(dev, s);
2565 /* End JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 */
2566
2567 /* BEGIN JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 */
2568 /* */
2569 /* if (s->async->buf_int_ptr>=s->async->data_len) // for buffer rool over */
2570 /* { */
2571 /* /* buffer rollover */ */
2572 /* s->async->buf_int_ptr=0; */
2573 /* comedi_eobuf(dev,s); */
2574 /* } */
2575 /* End JK 18.10.2004: APCI-3200 Driver update 0.7.57 -> 0.7.68 */
2576 }
2577 /* i_Count++; */
2578 s_BoardInfos[dev->minor].i_Count++;
2579 }
2580 /* i_InterruptFlag=0; */
2581 s_BoardInfos[dev->minor].i_InterruptFlag = 0;
2582 return 0;
2583}
2584
2585static void apci3200_interrupt(int irq, void *d)
2586{
2587 struct comedi_device *dev = d;
2588 struct addi_private *devpriv = dev->private;
2589 unsigned int ui_StatusRegister = 0;
2590 unsigned int ui_ChannelNumber = 0;
2591 int i_CalibrationFlag = 0;
2592 int i_CJCFlag = 0;
2593 unsigned int ui_DummyValue = 0;
2594 unsigned int ui_DigitalTemperature = 0;
2595 unsigned int ui_DigitalInput = 0;
2596 int i_ConvertCJCCalibration;
2597 /* BEGIN JK TEST */
2598 int i_ReturnValue = 0;
2599 /* END JK TEST */
2600
2601 /* switch(i_ScanType) */
2602 switch (s_BoardInfos[dev->minor].i_ScanType) {
2603 case 0:
2604 case 1:
2605 /* switch(i_ADDIDATAType) */
2606 switch (s_BoardInfos[dev->minor].i_ADDIDATAType) {
2607 case 0:
2608 case 1:
2609
2610 /************************************/
2611 /*Read the interrupt status register */
2612 /************************************/
2613 /* ui_StatusRegister = inl(devpriv->iobase+i_Offset + 16); */
2614 ui_StatusRegister =
2615 inl(devpriv->iobase +
2616 s_BoardInfos[dev->minor].i_Offset + 16);
2617 if ((ui_StatusRegister & 0x2) == 0x2) {
2618 /* i_CalibrationFlag = ((inl(devpriv->iobase+i_Offset + 12) & 0x00060000) >> 17); */
2619 i_CalibrationFlag =
2620 ((inl(devpriv->iobase +
2621 s_BoardInfos[dev->
2622 minor].
2623 i_Offset +
2624 12) & 0x00060000) >>
2625 17);
2626 /*************************/
2627 /*Read the channel number */
2628 /*************************/
2629 /* ui_ChannelNumber = inl(devpriv->iobase+i_Offset + 24); */
2630
2631 /*************************************/
2632 /*Read the digital analog input value */
2633 /*************************************/
2634 /* ui_DigitalInput = inl(devpriv->iobase+i_Offset + 28); */
2635 ui_DigitalInput =
2636 inl(devpriv->iobase +
2637 s_BoardInfos[dev->minor].i_Offset + 28);
2638
2639 /***********************************************/
2640 /* Test if the value read is the channel value */
2641 /***********************************************/
2642 if (i_CalibrationFlag == 0) {
2643 /* ui_InterruptChannelValue[i_Count + 0] = ui_DigitalInput; */
2644 s_BoardInfos[dev->minor].
2645 ui_InterruptChannelValue
2646 [s_BoardInfos[dev->minor].
2647 i_Count + 0] = ui_DigitalInput;
2648
2649 /* Begin JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values */
2650 /*
2651 i_APCI3200_GetChannelCalibrationValue (dev, s_BoardInfos [dev->minor].ui_Channel_num,
2652 &s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count + 6],
2653 &s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count + 7],
2654 &s_BoardInfos [dev->minor].ui_InterruptChannelValue[s_BoardInfos [dev->minor].i_Count + 8]);
2655 */
2656 /* End JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values */
2657
2658 /******************************************************/
2659 /*Start the conversion of the calibration offset value */
2660 /******************************************************/
2661 i_APCI3200_ReadCalibrationOffsetValue
2662 (dev, &ui_DummyValue);
2663 } /* if (i_CalibrationFlag == 0) */
2664 /**********************************************************/
2665 /* Test if the value read is the calibration offset value */
2666 /**********************************************************/
2667
2668 if (i_CalibrationFlag == 1) {
2669
2670 /******************/
2671 /* Save the value */
2672 /******************/
2673
2674 /* ui_InterruptChannelValue[i_Count + 1] = ui_DigitalInput; */
2675 s_BoardInfos[dev->minor].
2676 ui_InterruptChannelValue
2677 [s_BoardInfos[dev->minor].
2678 i_Count + 1] = ui_DigitalInput;
2679
2680 /******************************************************/
2681 /* Start the conversion of the calibration gain value */
2682 /******************************************************/
2683 i_APCI3200_ReadCalibrationGainValue(dev,
2684 &ui_DummyValue);
2685 } /* if (i_CalibrationFlag == 1) */
2686 /******************************************************/
2687 /*Test if the value read is the calibration gain value */
2688 /******************************************************/
2689
2690 if (i_CalibrationFlag == 2) {
2691
2692 /****************/
2693 /*Save the value */
2694 /****************/
2695 /* ui_InterruptChannelValue[i_Count + 2] = ui_DigitalInput; */
2696 s_BoardInfos[dev->minor].
2697 ui_InterruptChannelValue
2698 [s_BoardInfos[dev->minor].
2699 i_Count + 2] = ui_DigitalInput;
2700 /* if(i_ScanType==1) */
2701 if (s_BoardInfos[dev->minor].
2702 i_ScanType == 1) {
2703
2704 /* i_InterruptFlag=0; */
2705 s_BoardInfos[dev->minor].
2706 i_InterruptFlag = 0;
2707 /* i_Count=i_Count + 6; */
2708 /* Begin JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values */
2709 /* s_BoardInfos [dev->minor].i_Count=s_BoardInfos [dev->minor].i_Count + 6; */
2710 s_BoardInfos[dev->minor].
2711 i_Count =
2712 s_BoardInfos[dev->
2713 minor].i_Count + 9;
2714 /* End JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values */
2715 } /* if(i_ScanType==1) */
2716 else {
2717 /* i_Count=0; */
2718 s_BoardInfos[dev->minor].
2719 i_Count = 0;
2720 } /* elseif(i_ScanType==1) */
2721 /* if(i_ScanType!=1) */
2722 if (s_BoardInfos[dev->minor].
2723 i_ScanType != 1) {
2724 i_ReturnValue = send_sig(SIGIO, devpriv->tsk_Current, 0); /* send signal to the sample */
2725 } /* if(i_ScanType!=1) */
2726 else {
2727 /* if(i_ChannelCount==i_Sum) */
2728 if (s_BoardInfos[dev->minor].
2729 i_ChannelCount ==
2730 s_BoardInfos[dev->
2731 minor].i_Sum) {
2732 send_sig(SIGIO, devpriv->tsk_Current, 0); /* send signal to the sample */
2733 }
2734 } /* if(i_ScanType!=1) */
2735 } /* if (i_CalibrationFlag == 2) */
2736 } /* if ((ui_StatusRegister & 0x2) == 0x2) */
2737
2738 break;
2739
2740 case 2:
2741 /************************************/
2742 /*Read the interrupt status register */
2743 /************************************/
2744
2745 /* ui_StatusRegister = inl(devpriv->iobase+i_Offset + 16); */
2746 ui_StatusRegister =
2747 inl(devpriv->iobase +
2748 s_BoardInfos[dev->minor].i_Offset + 16);
2749 /*************************/
2750 /*Test if interrupt occur */
2751 /*************************/
2752
2753 if ((ui_StatusRegister & 0x2) == 0x2) {
2754
2755 /* i_CJCFlag = ((inl(devpriv->iobase+i_Offset + 4) & 0x00000400) >> 10); */
2756 i_CJCFlag =
2757 ((inl(devpriv->iobase +
2758 s_BoardInfos[dev->
2759 minor].
2760 i_Offset +
2761 4) & 0x00000400) >> 10);
2762
2763 /* i_CalibrationFlag = ((inl(devpriv->iobase+i_Offset + 12) & 0x00060000) >> 17); */
2764 i_CalibrationFlag =
2765 ((inl(devpriv->iobase +
2766 s_BoardInfos[dev->
2767 minor].
2768 i_Offset +
2769 12) & 0x00060000) >>
2770 17);
2771
2772 /*************************/
2773 /*Read the channel number */
2774 /*************************/
2775
2776 /* ui_ChannelNumber = inl(devpriv->iobase+i_Offset + 24); */
2777 ui_ChannelNumber =
2778 inl(devpriv->iobase +
2779 s_BoardInfos[dev->minor].i_Offset + 24);
2780 /* Begin JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values */
2781 s_BoardInfos[dev->minor].ui_Channel_num =
2782 ui_ChannelNumber;
2783 /* End JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values */
2784
2785 /************************************/
2786 /*Read the digital temperature value */
2787 /************************************/
2788 /* ui_DigitalTemperature = inl(devpriv->iobase+i_Offset + 28); */
2789 ui_DigitalTemperature =
2790 inl(devpriv->iobase +
2791 s_BoardInfos[dev->minor].i_Offset + 28);
2792
2793 /*********************************************/
2794 /*Test if the value read is the channel value */
2795 /*********************************************/
2796
2797 if ((i_CalibrationFlag == 0)
2798 && (i_CJCFlag == 0)) {
2799 /* ui_InterruptChannelValue[i_Count + 0]=ui_DigitalTemperature; */
2800 s_BoardInfos[dev->minor].
2801 ui_InterruptChannelValue
2802 [s_BoardInfos[dev->minor].
2803 i_Count + 0] =
2804 ui_DigitalTemperature;
2805
2806 /*********************************/
2807 /*Start the conversion of the CJC */
2808 /*********************************/
2809 i_APCI3200_ReadCJCValue(dev,
2810 &ui_DummyValue);
2811
2812 } /* if ((i_CalibrationFlag == 0) && (i_CJCFlag == 0)) */
2813
2814 /*****************************************/
2815 /*Test if the value read is the CJC value */
2816 /*****************************************/
2817
2818 if ((i_CJCFlag == 1)
2819 && (i_CalibrationFlag == 0)) {
2820 /* ui_InterruptChannelValue[i_Count + 3]=ui_DigitalTemperature; */
2821 s_BoardInfos[dev->minor].
2822 ui_InterruptChannelValue
2823 [s_BoardInfos[dev->minor].
2824 i_Count + 3] =
2825 ui_DigitalTemperature;
2826
2827 /******************************************************/
2828 /*Start the conversion of the calibration offset value */
2829 /******************************************************/
2830 i_APCI3200_ReadCalibrationOffsetValue
2831 (dev, &ui_DummyValue);
2832 } /* if ((i_CJCFlag == 1) && (i_CalibrationFlag == 0)) */
2833
2834 /********************************************************/
2835 /*Test if the value read is the calibration offset value */
2836 /********************************************************/
2837
2838 if ((i_CalibrationFlag == 1)
2839 && (i_CJCFlag == 0)) {
2840 /* ui_InterruptChannelValue[i_Count + 1]=ui_DigitalTemperature; */
2841 s_BoardInfos[dev->minor].
2842 ui_InterruptChannelValue
2843 [s_BoardInfos[dev->minor].
2844 i_Count + 1] =
2845 ui_DigitalTemperature;
2846
2847 /****************************************************/
2848 /*Start the conversion of the calibration gain value */
2849 /****************************************************/
2850 i_APCI3200_ReadCalibrationGainValue(dev,
2851 &ui_DummyValue);
2852
2853 } /* if ((i_CalibrationFlag == 1) && (i_CJCFlag == 0)) */
2854
2855 /******************************************************/
2856 /*Test if the value read is the calibration gain value */
2857 /******************************************************/
2858
2859 if ((i_CalibrationFlag == 2)
2860 && (i_CJCFlag == 0)) {
2861 /* ui_InterruptChannelValue[i_Count + 2]=ui_DigitalTemperature; */
2862 s_BoardInfos[dev->minor].
2863 ui_InterruptChannelValue
2864 [s_BoardInfos[dev->minor].
2865 i_Count + 2] =
2866 ui_DigitalTemperature;
2867
2868 /**********************************************************/
2869 /*Test if the Calibration channel must be read for the CJC */
2870 /**********************************************************/
2871
2872 /*Test if the polarity is the same */
2873 /**********************************/
2874 /* if(i_CJCPolarity!=i_ADDIDATAPolarity) */
2875 if (s_BoardInfos[dev->minor].
2876 i_CJCPolarity !=
2877 s_BoardInfos[dev->minor].
2878 i_ADDIDATAPolarity) {
2879 i_ConvertCJCCalibration = 1;
2880 } /* if(i_CJCPolarity!=i_ADDIDATAPolarity) */
2881 else {
2882 /* if(i_CJCGain==i_ADDIDATAGain) */
2883 if (s_BoardInfos[dev->minor].
2884 i_CJCGain ==
2885 s_BoardInfos[dev->
2886 minor].
2887 i_ADDIDATAGain) {
2888 i_ConvertCJCCalibration
2889 = 0;
2890 } /* if(i_CJCGain==i_ADDIDATAGain) */
2891 else {
2892 i_ConvertCJCCalibration
2893 = 1;
2894 } /* elseif(i_CJCGain==i_ADDIDATAGain) */
2895 } /* elseif(i_CJCPolarity!=i_ADDIDATAPolarity) */
2896 if (i_ConvertCJCCalibration == 1) {
2897 /****************************************************************/
2898 /*Start the conversion of the calibration gain value for the CJC */
2899 /****************************************************************/
2900 i_APCI3200_ReadCJCCalOffset(dev,
2901 &ui_DummyValue);
2902
2903 } /* if(i_ConvertCJCCalibration==1) */
2904 else {
2905 /* ui_InterruptChannelValue[i_Count + 4]=0; */
2906 /* ui_InterruptChannelValue[i_Count + 5]=0; */
2907 s_BoardInfos[dev->minor].
2908 ui_InterruptChannelValue
2909 [s_BoardInfos[dev->
2910 minor].i_Count +
2911 4] = 0;
2912 s_BoardInfos[dev->minor].
2913 ui_InterruptChannelValue
2914 [s_BoardInfos[dev->
2915 minor].i_Count +
2916 5] = 0;
2917 } /* elseif(i_ConvertCJCCalibration==1) */
2918 } /* else if ((i_CalibrationFlag == 2) && (i_CJCFlag == 0)) */
2919
2920 /********************************************************************/
2921 /*Test if the value read is the calibration offset value for the CJC */
2922 /********************************************************************/
2923
2924 if ((i_CalibrationFlag == 1)
2925 && (i_CJCFlag == 1)) {
2926 /* ui_InterruptChannelValue[i_Count + 4]=ui_DigitalTemperature; */
2927 s_BoardInfos[dev->minor].
2928 ui_InterruptChannelValue
2929 [s_BoardInfos[dev->minor].
2930 i_Count + 4] =
2931 ui_DigitalTemperature;
2932
2933 /****************************************************************/
2934 /*Start the conversion of the calibration gain value for the CJC */
2935 /****************************************************************/
2936 i_APCI3200_ReadCJCCalGain(dev,
2937 &ui_DummyValue);
2938
2939 } /* if ((i_CalibrationFlag == 1) && (i_CJCFlag == 1)) */
2940
2941 /******************************************************************/
2942 /*Test if the value read is the calibration gain value for the CJC */
2943 /******************************************************************/
2944
2945 if ((i_CalibrationFlag == 2)
2946 && (i_CJCFlag == 1)) {
2947 /* ui_InterruptChannelValue[i_Count + 5]=ui_DigitalTemperature; */
2948 s_BoardInfos[dev->minor].
2949 ui_InterruptChannelValue
2950 [s_BoardInfos[dev->minor].
2951 i_Count + 5] =
2952 ui_DigitalTemperature;
2953
2954 /* if(i_ScanType==1) */
2955 if (s_BoardInfos[dev->minor].
2956 i_ScanType == 1) {
2957
2958 /* i_InterruptFlag=0; */
2959 s_BoardInfos[dev->minor].
2960 i_InterruptFlag = 0;
2961 /* i_Count=i_Count + 6; */
2962 /* Begin JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values */
2963 /* s_BoardInfos [dev->minor].i_Count=s_BoardInfos [dev->minor].i_Count + 6; */
2964 s_BoardInfos[dev->minor].
2965 i_Count =
2966 s_BoardInfos[dev->
2967 minor].i_Count + 9;
2968 /* End JK 22.10.2004: APCI-3200 / APCI-3300 Reading of EEPROM values */
2969 } /* if(i_ScanType==1) */
2970 else {
2971 /* i_Count=0; */
2972 s_BoardInfos[dev->minor].
2973 i_Count = 0;
2974 } /* elseif(i_ScanType==1) */
2975
2976 /* if(i_ScanType!=1) */
2977 if (s_BoardInfos[dev->minor].
2978 i_ScanType != 1) {
2979 send_sig(SIGIO, devpriv->tsk_Current, 0); /* send signal to the sample */
2980 } /* if(i_ScanType!=1) */
2981 else {
2982 /* if(i_ChannelCount==i_Sum) */
2983 if (s_BoardInfos[dev->minor].
2984 i_ChannelCount ==
2985 s_BoardInfos[dev->
2986 minor].i_Sum) {
2987 send_sig(SIGIO, devpriv->tsk_Current, 0); /* send signal to the sample */
2988
2989 } /* if(i_ChannelCount==i_Sum) */
2990 } /* else if(i_ScanType!=1) */
2991 } /* if ((i_CalibrationFlag == 2) && (i_CJCFlag == 1)) */
2992
2993 } /* else if ((ui_StatusRegister & 0x2) == 0x2) */
2994 break;
2995 } /* switch(i_ADDIDATAType) */
2996 break;
2997 case 2:
2998 case 3:
2999 i_APCI3200_InterruptHandleEos(dev);
3000 break;
3001 } /* switch(i_ScanType) */
3002 return;
3003}
diff --git a/drivers/staging/comedi/drivers/addi_apci_035.c b/drivers/staging/comedi/drivers/addi_apci_035.c
deleted file mode 100644
index af70c8401880..000000000000
--- a/drivers/staging/comedi/drivers/addi_apci_035.c
+++ /dev/null
@@ -1,77 +0,0 @@
1#include <linux/module.h>
2#include <linux/pci.h>
3
4#include "../comedidev.h"
5#include "comedi_fc.h"
6#include "amcc_s5933.h"
7
8#include "addi-data/addi_common.h"
9
10#define ADDIDATA_WATCHDOG 2 /* Or shold it be something else */
11
12#include "addi-data/addi_eeprom.c"
13#include "addi-data/hwdrv_apci035.c"
14#include "addi-data/addi_common.c"
15
16static const struct addi_board apci035_boardtypes[] = {
17 {
18 .pc_DriverName = "apci035",
19 .i_IorangeBase1 = APCI035_ADDRESS_RANGE,
20 .i_PCIEeprom = 1,
21 .pc_EepromChip = "S5920",
22 .i_NbrAiChannel = 16,
23 .i_NbrAiChannelDiff = 8,
24 .i_AiChannelList = 16,
25 .i_AiMaxdata = 0xff,
26 .pr_AiRangelist = &range_apci035_ai,
27 .i_Timer = 1,
28 .ui_MinAcquisitiontimeNs = 10000,
29 .ui_MinDelaytimeNs = 100000,
30 .interrupt = apci035_interrupt,
31 .reset = apci035_reset,
32 .ai_config = apci035_ai_config,
33 .ai_read = apci035_ai_read,
34 .timer_config = apci035_timer_config,
35 .timer_write = apci035_timer_write,
36 .timer_read = apci035_timer_read,
37 },
38};
39
40static int apci035_auto_attach(struct comedi_device *dev,
41 unsigned long context)
42{
43 dev->board_ptr = &apci035_boardtypes[0];
44
45 return addi_auto_attach(dev, context);
46}
47
48static struct comedi_driver apci035_driver = {
49 .driver_name = "addi_apci_035",
50 .module = THIS_MODULE,
51 .auto_attach = apci035_auto_attach,
52 .detach = i_ADDI_Detach,
53};
54
55static int apci035_pci_probe(struct pci_dev *dev,
56 const struct pci_device_id *id)
57{
58 return comedi_pci_auto_config(dev, &apci035_driver, id->driver_data);
59}
60
61static const struct pci_device_id apci035_pci_table[] = {
62 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x0300) },
63 { 0 }
64};
65MODULE_DEVICE_TABLE(pci, apci035_pci_table);
66
67static struct pci_driver apci035_pci_driver = {
68 .name = "addi_apci_035",
69 .id_table = apci035_pci_table,
70 .probe = apci035_pci_probe,
71 .remove = comedi_pci_auto_unconfig,
72};
73module_comedi_pci_driver(apci035_driver, apci035_pci_driver);
74
75MODULE_AUTHOR("Comedi http://www.comedi.org");
76MODULE_DESCRIPTION("Comedi low-level driver");
77MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/addi_apci_1032.c b/drivers/staging/comedi/drivers/addi_apci_1032.c
index 840cb289507a..bf14165297b7 100644
--- a/drivers/staging/comedi/drivers/addi_apci_1032.c
+++ b/drivers/staging/comedi/drivers/addi_apci_1032.c
@@ -258,9 +258,8 @@ static irqreturn_t apci1032_interrupt(int irq, void *d)
258 outl(ctrl & ~APCI1032_CTRL_INT_ENA, dev->iobase + APCI1032_CTRL_REG); 258 outl(ctrl & ~APCI1032_CTRL_INT_ENA, dev->iobase + APCI1032_CTRL_REG);
259 259
260 s->state = inl(dev->iobase + APCI1032_STATUS_REG) & 0xffff; 260 s->state = inl(dev->iobase + APCI1032_STATUS_REG) & 0xffff;
261 comedi_buf_put(s, s->state); 261 comedi_buf_write_samples(s, &s->state, 1);
262 s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOS; 262 comedi_handle_events(dev, s);
263 comedi_event(dev, s);
264 263
265 /* enable the interrupt */ 264 /* enable the interrupt */
266 outl(ctrl, dev->iobase + APCI1032_CTRL_REG); 265 outl(ctrl, dev->iobase + APCI1032_CTRL_REG);
diff --git a/drivers/staging/comedi/drivers/addi_apci_1500.c b/drivers/staging/comedi/drivers/addi_apci_1500.c
index b7a284ac6649..30b132c3d092 100644
--- a/drivers/staging/comedi/drivers/addi_apci_1500.c
+++ b/drivers/staging/comedi/drivers/addi_apci_1500.c
@@ -1,54 +1,109 @@
1#include <linux/module.h> 1#include <linux/module.h>
2#include <linux/pci.h> 2#include <linux/pci.h>
3#include <linux/sched.h>
4#include <linux/interrupt.h>
3 5
4#include "../comedidev.h" 6#include "../comedidev.h"
5#include "comedi_fc.h" 7#include "comedi_fc.h"
6#include "amcc_s5933.h" 8#include "amcc_s5933.h"
7 9
8#include "addi-data/addi_common.h" 10struct apci1500_private {
11 int iobase;
12 int i_IobaseAmcc;
13 int i_IobaseAddon;
14 int i_IobaseReserved;
15 unsigned char b_OutputMemoryStatus;
16 struct task_struct *tsk_Current;
17};
9 18
10#include "addi-data/addi_eeprom.c"
11#include "addi-data/hwdrv_apci1500.c" 19#include "addi-data/hwdrv_apci1500.c"
12#include "addi-data/addi_common.c"
13
14static const struct addi_board apci1500_boardtypes[] = {
15 {
16 .pc_DriverName = "apci1500",
17 .i_IorangeBase1 = APCI1500_ADDRESS_RANGE,
18 .i_PCIEeprom = 0,
19 .i_NbrDiChannel = 16,
20 .i_NbrDoChannel = 16,
21 .i_DoMaxdata = 0xffff,
22 .i_Timer = 1,
23 .interrupt = apci1500_interrupt,
24 .reset = apci1500_reset,
25 .di_config = apci1500_di_config,
26 .di_read = apci1500_di_read,
27 .di_write = apci1500_di_write,
28 .di_bits = apci1500_di_insn_bits,
29 .do_config = apci1500_do_config,
30 .do_write = apci1500_do_write,
31 .do_bits = apci1500_do_bits,
32 .timer_config = apci1500_timer_config,
33 .timer_write = apci1500_timer_write,
34 .timer_read = apci1500_timer_read,
35 .timer_bits = apci1500_timer_bits,
36 },
37};
38 20
39static int apci1500_auto_attach(struct comedi_device *dev, 21static int apci1500_auto_attach(struct comedi_device *dev,
40 unsigned long context) 22 unsigned long context)
41{ 23{
42 dev->board_ptr = &apci1500_boardtypes[0]; 24 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
25 struct apci1500_private *devpriv;
26 struct comedi_subdevice *s;
27 int ret;
28
29 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
30 if (!devpriv)
31 return -ENOMEM;
32
33 ret = comedi_pci_enable(dev);
34 if (ret)
35 return ret;
36
37 dev->iobase = pci_resource_start(pcidev, 1);
38 devpriv->iobase = dev->iobase;
39 devpriv->i_IobaseAmcc = pci_resource_start(pcidev, 0);
40 devpriv->i_IobaseAddon = pci_resource_start(pcidev, 2);
41 devpriv->i_IobaseReserved = pci_resource_start(pcidev, 3);
42
43 if (pcidev->irq > 0) {
44 ret = request_irq(pcidev->irq, apci1500_interrupt, IRQF_SHARED,
45 dev->board_name, dev);
46 if (ret == 0)
47 dev->irq = pcidev->irq;
48 }
49
50 ret = comedi_alloc_subdevices(dev, 3);
51 if (ret)
52 return ret;
43 53
44 return addi_auto_attach(dev, context); 54 /* Allocate and Initialise DI Subdevice Structures */
55 s = &dev->subdevices[0];
56 s->type = COMEDI_SUBD_DI;
57 s->subdev_flags = SDF_READABLE;
58 s->n_chan = 16;
59 s->maxdata = 1;
60 s->range_table = &range_digital;
61 s->insn_config = apci1500_di_config;
62 s->insn_read = apci1500_di_read;
63 s->insn_write = apci1500_di_write;
64 s->insn_bits = apci1500_di_insn_bits;
65
66 /* Allocate and Initialise DO Subdevice Structures */
67 s = &dev->subdevices[1];
68 s->type = COMEDI_SUBD_DO;
69 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
70 s->n_chan = 16;
71 s->maxdata = 1;
72 s->range_table = &range_digital;
73 s->insn_config = apci1500_do_config;
74 s->insn_write = apci1500_do_write;
75 s->insn_bits = apci1500_do_bits;
76
77 /* Allocate and Initialise Timer Subdevice Structures */
78 s = &dev->subdevices[2];
79 s->type = COMEDI_SUBD_TIMER;
80 s->subdev_flags = SDF_WRITABLE;
81 s->n_chan = 1;
82 s->maxdata = 0;
83 s->len_chanlist = 1;
84 s->range_table = &range_digital;
85 s->insn_write = apci1500_timer_write;
86 s->insn_read = apci1500_timer_read;
87 s->insn_config = apci1500_timer_config;
88 s->insn_bits = apci1500_timer_bits;
89
90 apci1500_reset(dev);
91
92 return 0;
93}
94
95static void apci1500_detach(struct comedi_device *dev)
96{
97 if (dev->iobase)
98 apci1500_reset(dev);
99 comedi_pci_detach(dev);
45} 100}
46 101
47static struct comedi_driver apci1500_driver = { 102static struct comedi_driver apci1500_driver = {
48 .driver_name = "addi_apci_1500", 103 .driver_name = "addi_apci_1500",
49 .module = THIS_MODULE, 104 .module = THIS_MODULE,
50 .auto_attach = apci1500_auto_attach, 105 .auto_attach = apci1500_auto_attach,
51 .detach = i_ADDI_Detach, 106 .detach = apci1500_detach,
52}; 107};
53 108
54static int apci1500_pci_probe(struct pci_dev *dev, 109static int apci1500_pci_probe(struct pci_dev *dev,
diff --git a/drivers/staging/comedi/drivers/addi_apci_1516.c b/drivers/staging/comedi/drivers/addi_apci_1516.c
index 55d00fd94c91..d8410415cc90 100644
--- a/drivers/staging/comedi/drivers/addi_apci_1516.c
+++ b/drivers/staging/comedi/drivers/addi_apci_1516.c
@@ -163,7 +163,7 @@ static int apci1516_auto_attach(struct comedi_device *dev,
163 s = &dev->subdevices[1]; 163 s = &dev->subdevices[1];
164 if (this_board->do_nchan) { 164 if (this_board->do_nchan) {
165 s->type = COMEDI_SUBD_DO; 165 s->type = COMEDI_SUBD_DO;
166 s->subdev_flags = SDF_WRITEABLE; 166 s->subdev_flags = SDF_WRITABLE;
167 s->n_chan = this_board->do_nchan; 167 s->n_chan = this_board->do_nchan;
168 s->maxdata = 1; 168 s->maxdata = 1;
169 s->range_table = &range_digital; 169 s->range_table = &range_digital;
diff --git a/drivers/staging/comedi/drivers/addi_apci_1564.c b/drivers/staging/comedi/drivers/addi_apci_1564.c
index 688b015a834e..6872b69da5db 100644
--- a/drivers/staging/comedi/drivers/addi_apci_1564.c
+++ b/drivers/staging/comedi/drivers/addi_apci_1564.c
@@ -28,16 +28,91 @@
28 28
29#include "../comedidev.h" 29#include "../comedidev.h"
30#include "comedi_fc.h" 30#include "comedi_fc.h"
31#include "amcc_s5933.h" 31#include "addi_tcw.h"
32#include "addi_watchdog.h" 32#include "addi_watchdog.h"
33 33
34/*
35 * PCI BAR 0
36 *
37 * PLD Revision 1.0 I/O Mapping
38 * 0x00 93C76 EEPROM
39 * 0x04 - 0x18 Timer 12-Bit
40 *
41 * PLD Revision 2.x I/O Mapping
42 * 0x00 93C76 EEPROM
43 * 0x04 - 0x14 Digital Input
44 * 0x18 - 0x25 Digital Output
45 * 0x28 - 0x44 Watchdog 8-Bit
46 * 0x48 - 0x64 Timer 12-Bit
47 */
48#define APCI1564_EEPROM_REG 0x00
49#define APCI1564_EEPROM_VCC_STATUS (1 << 8)
50#define APCI1564_EEPROM_TO_REV(x) (((x) >> 4) & 0xf)
51#define APCI1564_EEPROM_DI (1 << 3)
52#define APCI1564_EEPROM_DO (1 << 2)
53#define APCI1564_EEPROM_CS (1 << 1)
54#define APCI1564_EEPROM_CLK (1 << 0)
55#define APCI1564_REV1_TIMER_IOBASE 0x04
56#define APCI1564_REV2_MAIN_IOBASE 0x04
57#define APCI1564_REV2_TIMER_IOBASE 0x48
58
59/*
60 * PCI BAR 1
61 *
62 * PLD Revision 1.0 I/O Mapping
63 * 0x00 - 0x10 Digital Input
64 * 0x14 - 0x20 Digital Output
65 * 0x24 - 0x3c Watchdog 8-Bit
66 *
67 * PLD Revision 2.x I/O Mapping
68 * 0x00 Counter_0
69 * 0x20 Counter_1
70 * 0x30 Counter_3
71 */
72#define APCI1564_REV1_MAIN_IOBASE 0x00
73
74/*
75 * dev->iobase Register Map
76 * PLD Revision 1.0 - PCI BAR 1 + 0x00
77 * PLD Revision 2.x - PCI BAR 0 + 0x04
78 */
79#define APCI1564_DI_REG 0x00
80#define APCI1564_DI_INT_MODE1_REG 0x04
81#define APCI1564_DI_INT_MODE2_REG 0x08
82#define APCI1564_DI_INT_STATUS_REG 0x0c
83#define APCI1564_DI_IRQ_REG 0x10
84#define APCI1564_DO_REG 0x14
85#define APCI1564_DO_INT_CTRL_REG 0x18
86#define APCI1564_DO_INT_STATUS_REG 0x1c
87#define APCI1564_DO_IRQ_REG 0x20
88#define APCI1564_WDOG_REG 0x24
89#define APCI1564_WDOG_RELOAD_REG 0x28
90#define APCI1564_WDOG_TIMEBASE_REG 0x2c
91#define APCI1564_WDOG_CTRL_REG 0x30
92#define APCI1564_WDOG_STATUS_REG 0x34
93#define APCI1564_WDOG_IRQ_REG 0x38
94#define APCI1564_WDOG_WARN_TIMEVAL_REG 0x3c
95#define APCI1564_WDOG_WARN_TIMEBASE_REG 0x40
96
97/*
98 * devpriv->timer Register Map (see addi_tcw.h for register/bit defines)
99 * PLD Revision 1.0 - PCI BAR 0 + 0x04
100 * PLD Revision 2.x - PCI BAR 0 + 0x48
101 */
102
103/*
104 * devpriv->counters Register Map (see addi_tcw.h for register/bit defines)
105 * PLD Revision 2.x - PCI BAR 1 + 0x00
106 */
107#define APCI1564_COUNTER(x) ((x) * 0x20)
108
34struct apci1564_private { 109struct apci1564_private {
35 unsigned int amcc_iobase; /* base of AMCC I/O registers */ 110 unsigned long eeprom; /* base address of EEPROM register */
111 unsigned long timer; /* base address of 12-bit timer */
112 unsigned long counters; /* base address of 32-bit counters */
36 unsigned int mode1; /* riding-edge/high level channels */ 113 unsigned int mode1; /* riding-edge/high level channels */
37 unsigned int mode2; /* falling-edge/low level channels */ 114 unsigned int mode2; /* falling-edge/low level channels */
38 unsigned int ctrl; /* interrupt mode OR (edge) . AND (level) */ 115 unsigned int ctrl; /* interrupt mode OR (edge) . AND (level) */
39 unsigned char timer_select_mode;
40 unsigned char mode_select_register;
41 struct task_struct *tsk_current; 116 struct task_struct *tsk_current;
42}; 117};
43 118
@@ -48,27 +123,30 @@ static int apci1564_reset(struct comedi_device *dev)
48 struct apci1564_private *devpriv = dev->private; 123 struct apci1564_private *devpriv = dev->private;
49 124
50 /* Disable the input interrupts and reset status register */ 125 /* Disable the input interrupts and reset status register */
51 outl(0x0, devpriv->amcc_iobase + APCI1564_DI_IRQ_REG); 126 outl(0x0, dev->iobase + APCI1564_DI_IRQ_REG);
52 inl(devpriv->amcc_iobase + APCI1564_DI_INT_STATUS_REG); 127 inl(dev->iobase + APCI1564_DI_INT_STATUS_REG);
53 outl(0x0, devpriv->amcc_iobase + APCI1564_DI_INT_MODE1_REG); 128 outl(0x0, dev->iobase + APCI1564_DI_INT_MODE1_REG);
54 outl(0x0, devpriv->amcc_iobase + APCI1564_DI_INT_MODE2_REG); 129 outl(0x0, dev->iobase + APCI1564_DI_INT_MODE2_REG);
55 130
56 /* Reset the output channels and disable interrupts */ 131 /* Reset the output channels and disable interrupts */
57 outl(0x0, devpriv->amcc_iobase + APCI1564_DO_REG); 132 outl(0x0, dev->iobase + APCI1564_DO_REG);
58 outl(0x0, devpriv->amcc_iobase + APCI1564_DO_INT_CTRL_REG); 133 outl(0x0, dev->iobase + APCI1564_DO_INT_CTRL_REG);
59 134
60 /* Reset the watchdog registers */ 135 /* Reset the watchdog registers */
61 addi_watchdog_reset(devpriv->amcc_iobase + APCI1564_WDOG_REG); 136 addi_watchdog_reset(dev->iobase + APCI1564_WDOG_REG);
62 137
63 /* Reset the timer registers */ 138 /* Reset the timer registers */
64 outl(0x0, devpriv->amcc_iobase + APCI1564_TIMER_CTRL_REG); 139 outl(0x0, devpriv->timer + ADDI_TCW_CTRL_REG);
65 outl(0x0, devpriv->amcc_iobase + APCI1564_TIMER_RELOAD_REG); 140 outl(0x0, devpriv->timer + ADDI_TCW_RELOAD_REG);
141
142 if (devpriv->counters) {
143 unsigned long iobase = devpriv->counters + ADDI_TCW_CTRL_REG;
66 144
67 /* Reset the counter registers */ 145 /* Reset the counter registers */
68 outl(0x0, dev->iobase + APCI1564_COUNTER_CTRL_REG(APCI1564_COUNTER1)); 146 outl(0x0, iobase + APCI1564_COUNTER(0));
69 outl(0x0, dev->iobase + APCI1564_COUNTER_CTRL_REG(APCI1564_COUNTER2)); 147 outl(0x0, iobase + APCI1564_COUNTER(1));
70 outl(0x0, dev->iobase + APCI1564_COUNTER_CTRL_REG(APCI1564_COUNTER3)); 148 outl(0x0, iobase + APCI1564_COUNTER(2));
71 outl(0x0, dev->iobase + APCI1564_COUNTER_CTRL_REG(APCI1564_COUNTER4)); 149 }
72 150
73 return 0; 151 return 0;
74} 152}
@@ -82,55 +160,52 @@ static irqreturn_t apci1564_interrupt(int irq, void *d)
82 unsigned int ctrl; 160 unsigned int ctrl;
83 unsigned int chan; 161 unsigned int chan;
84 162
85 /* check interrupt is from this device */ 163 status = inl(dev->iobase + APCI1564_DI_IRQ_REG);
86 if ((inl(devpriv->amcc_iobase + AMCC_OP_REG_INTCSR) &
87 INTCSR_INTR_ASSERTED) == 0)
88 return IRQ_NONE;
89
90 status = inl(devpriv->amcc_iobase + APCI1564_DI_IRQ_REG);
91 if (status & APCI1564_DI_INT_ENABLE) { 164 if (status & APCI1564_DI_INT_ENABLE) {
92 /* disable the interrupt */ 165 /* disable the interrupt */
93 outl(status & APCI1564_DI_INT_DISABLE, 166 outl(status & APCI1564_DI_INT_DISABLE,
94 devpriv->amcc_iobase + APCI1564_DI_IRQ_REG); 167 dev->iobase + APCI1564_DI_IRQ_REG);
95 168
96 s->state = inl(dev->iobase + APCI1564_DI_INT_STATUS_REG) 169 s->state = inl(dev->iobase + APCI1564_DI_INT_STATUS_REG) &
97 & 0xffff; 170 0xffff;
98 comedi_buf_put(s, s->state); 171 comedi_buf_write_samples(s, &s->state, 1);
99 s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOS; 172 comedi_handle_events(dev, s);
100 comedi_event(dev, s);
101 173
102 /* enable the interrupt */ 174 /* enable the interrupt */
103 outl(status, devpriv->amcc_iobase + APCI1564_DI_IRQ_REG); 175 outl(status, dev->iobase + APCI1564_DI_IRQ_REG);
104 } 176 }
105 177
106 status = inl(devpriv->amcc_iobase + APCI1564_TIMER_IRQ_REG); 178 status = inl(devpriv->timer + ADDI_TCW_IRQ_REG);
107 if (status & 0x01) { 179 if (status & 0x01) {
108 /* Disable Timer Interrupt */ 180 /* Disable Timer Interrupt */
109 ctrl = inl(devpriv->amcc_iobase + APCI1564_TIMER_CTRL_REG); 181 ctrl = inl(devpriv->timer + ADDI_TCW_CTRL_REG);
110 outl(0x0, devpriv->amcc_iobase + APCI1564_TIMER_CTRL_REG); 182 outl(0x0, devpriv->timer + ADDI_TCW_CTRL_REG);
111 183
112 /* Send a signal to from kernel to user space */ 184 /* Send a signal to from kernel to user space */
113 send_sig(SIGIO, devpriv->tsk_current, 0); 185 send_sig(SIGIO, devpriv->tsk_current, 0);
114 186
115 /* Enable Timer Interrupt */ 187 /* Enable Timer Interrupt */
116 outl(ctrl, devpriv->amcc_iobase + APCI1564_TIMER_CTRL_REG); 188 outl(ctrl, devpriv->timer + ADDI_TCW_CTRL_REG);
117 } 189 }
118 190
119 for (chan = 0; chan < 4; chan++) { 191 if (devpriv->counters) {
120 status = inl(dev->iobase + APCI1564_COUNTER_IRQ_REG(chan)); 192 for (chan = 0; chan < 4; chan++) {
121 if (status & 0x01) { 193 unsigned long iobase;
122 /* Disable Counter Interrupt */ 194
123 ctrl = inl(dev->iobase + 195 iobase = devpriv->counters + APCI1564_COUNTER(chan);
124 APCI1564_COUNTER_CTRL_REG(chan)); 196
125 outl(0x0, dev->iobase + 197 status = inl(iobase + ADDI_TCW_IRQ_REG);
126 APCI1564_COUNTER_CTRL_REG(chan)); 198 if (status & 0x01) {
127 199 /* Disable Counter Interrupt */
128 /* Send a signal to from kernel to user space */ 200 ctrl = inl(iobase + ADDI_TCW_CTRL_REG);
129 send_sig(SIGIO, devpriv->tsk_current, 0); 201 outl(0x0, iobase + ADDI_TCW_CTRL_REG);
130 202
131 /* Enable Counter Interrupt */ 203 /* Send a signal to from kernel to user space */
132 outl(ctrl, dev->iobase + 204 send_sig(SIGIO, devpriv->tsk_current, 0);
133 APCI1564_COUNTER_CTRL_REG(chan)); 205
206 /* Enable Counter Interrupt */
207 outl(ctrl, iobase + ADDI_TCW_CTRL_REG);
208 }
134 } 209 }
135 } 210 }
136 211
@@ -142,9 +217,7 @@ static int apci1564_di_insn_bits(struct comedi_device *dev,
142 struct comedi_insn *insn, 217 struct comedi_insn *insn,
143 unsigned int *data) 218 unsigned int *data)
144{ 219{
145 struct apci1564_private *devpriv = dev->private; 220 data[1] = inl(dev->iobase + APCI1564_DI_REG);
146
147 data[1] = inl(devpriv->amcc_iobase + APCI1564_DI_REG);
148 221
149 return insn->n; 222 return insn->n;
150} 223}
@@ -154,12 +227,10 @@ static int apci1564_do_insn_bits(struct comedi_device *dev,
154 struct comedi_insn *insn, 227 struct comedi_insn *insn,
155 unsigned int *data) 228 unsigned int *data)
156{ 229{
157 struct apci1564_private *devpriv = dev->private; 230 s->state = inl(dev->iobase + APCI1564_DO_REG);
158
159 s->state = inl(devpriv->amcc_iobase + APCI1564_DO_REG);
160 231
161 if (comedi_dio_update_state(s, data)) 232 if (comedi_dio_update_state(s, data))
162 outl(s->state, devpriv->amcc_iobase + APCI1564_DO_REG); 233 outl(s->state, dev->iobase + APCI1564_DO_REG);
163 234
164 data[1] = s->state; 235 data[1] = s->state;
165 236
@@ -171,9 +242,7 @@ static int apci1564_diag_insn_bits(struct comedi_device *dev,
171 struct comedi_insn *insn, 242 struct comedi_insn *insn,
172 unsigned int *data) 243 unsigned int *data)
173{ 244{
174 struct apci1564_private *devpriv = dev->private; 245 data[1] = inl(dev->iobase + APCI1564_DO_INT_STATUS_REG) & 3;
175
176 data[1] = inl(devpriv->amcc_iobase + APCI1564_DO_INT_STATUS_REG) & 3;
177 246
178 return insn->n; 247 return insn->n;
179} 248}
@@ -227,10 +296,10 @@ static int apci1564_cos_insn_config(struct comedi_device *dev,
227 devpriv->ctrl = 0; 296 devpriv->ctrl = 0;
228 devpriv->mode1 = 0; 297 devpriv->mode1 = 0;
229 devpriv->mode2 = 0; 298 devpriv->mode2 = 0;
230 outl(0x0, devpriv->amcc_iobase + APCI1564_DI_IRQ_REG); 299 outl(0x0, dev->iobase + APCI1564_DI_IRQ_REG);
231 inl(devpriv->amcc_iobase + APCI1564_DI_INT_STATUS_REG); 300 inl(dev->iobase + APCI1564_DI_INT_STATUS_REG);
232 outl(0x0, devpriv->amcc_iobase + APCI1564_DI_INT_MODE1_REG); 301 outl(0x0, dev->iobase + APCI1564_DI_INT_MODE1_REG);
233 outl(0x0, devpriv->amcc_iobase + APCI1564_DI_INT_MODE2_REG); 302 outl(0x0, dev->iobase + APCI1564_DI_INT_MODE2_REG);
234 break; 303 break;
235 case COMEDI_DIGITAL_TRIG_ENABLE_EDGES: 304 case COMEDI_DIGITAL_TRIG_ENABLE_EDGES:
236 if (devpriv->ctrl != (APCI1564_DI_INT_ENABLE | 305 if (devpriv->ctrl != (APCI1564_DI_INT_ENABLE |
@@ -342,9 +411,9 @@ static int apci1564_cos_cmd(struct comedi_device *dev,
342 return -EINVAL; 411 return -EINVAL;
343 } 412 }
344 413
345 outl(devpriv->mode1, devpriv->amcc_iobase + APCI1564_DI_INT_MODE1_REG); 414 outl(devpriv->mode1, dev->iobase + APCI1564_DI_INT_MODE1_REG);
346 outl(devpriv->mode2, devpriv->amcc_iobase + APCI1564_DI_INT_MODE2_REG); 415 outl(devpriv->mode2, dev->iobase + APCI1564_DI_INT_MODE2_REG);
347 outl(devpriv->ctrl, devpriv->amcc_iobase + APCI1564_DI_IRQ_REG); 416 outl(devpriv->ctrl, dev->iobase + APCI1564_DI_IRQ_REG);
348 417
349 return 0; 418 return 0;
350} 419}
@@ -352,12 +421,10 @@ static int apci1564_cos_cmd(struct comedi_device *dev,
352static int apci1564_cos_cancel(struct comedi_device *dev, 421static int apci1564_cos_cancel(struct comedi_device *dev,
353 struct comedi_subdevice *s) 422 struct comedi_subdevice *s)
354{ 423{
355 struct apci1564_private *devpriv = dev->private; 424 outl(0x0, dev->iobase + APCI1564_DI_IRQ_REG);
356 425 inl(dev->iobase + APCI1564_DI_INT_STATUS_REG);
357 outl(0x0, devpriv->amcc_iobase + APCI1564_DI_IRQ_REG); 426 outl(0x0, dev->iobase + APCI1564_DI_INT_MODE1_REG);
358 inl(devpriv->amcc_iobase + APCI1564_DI_INT_STATUS_REG); 427 outl(0x0, dev->iobase + APCI1564_DI_INT_MODE2_REG);
359 outl(0x0, devpriv->amcc_iobase + APCI1564_DI_INT_MODE1_REG);
360 outl(0x0, devpriv->amcc_iobase + APCI1564_DI_INT_MODE2_REG);
361 428
362 return 0; 429 return 0;
363} 430}
@@ -368,6 +435,7 @@ static int apci1564_auto_attach(struct comedi_device *dev,
368 struct pci_dev *pcidev = comedi_to_pci_dev(dev); 435 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
369 struct apci1564_private *devpriv; 436 struct apci1564_private *devpriv;
370 struct comedi_subdevice *s; 437 struct comedi_subdevice *s;
438 unsigned int val;
371 int ret; 439 int ret;
372 440
373 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv)); 441 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
@@ -378,8 +446,20 @@ static int apci1564_auto_attach(struct comedi_device *dev,
378 if (ret) 446 if (ret)
379 return ret; 447 return ret;
380 448
381 dev->iobase = pci_resource_start(pcidev, 1); 449 /* read the EEPROM register and check the I/O map revision */
382 devpriv->amcc_iobase = pci_resource_start(pcidev, 0); 450 devpriv->eeprom = pci_resource_start(pcidev, 0);
451 val = inl(devpriv->eeprom + APCI1564_EEPROM_REG);
452 if (APCI1564_EEPROM_TO_REV(val) == 0) {
453 /* PLD Revision 1.0 I/O Mapping */
454 dev->iobase = pci_resource_start(pcidev, 1) +
455 APCI1564_REV1_MAIN_IOBASE;
456 devpriv->timer = devpriv->eeprom + APCI1564_REV1_TIMER_IOBASE;
457 } else {
458 /* PLD Revision 2.x I/O Mapping */
459 dev->iobase = devpriv->eeprom + APCI1564_REV2_MAIN_IOBASE;
460 devpriv->timer = devpriv->eeprom + APCI1564_REV2_TIMER_IOBASE;
461 devpriv->counters = pci_resource_start(pcidev, 1);
462 }
383 463
384 apci1564_reset(dev); 464 apci1564_reset(dev);
385 465
@@ -390,7 +470,7 @@ static int apci1564_auto_attach(struct comedi_device *dev,
390 dev->irq = pcidev->irq; 470 dev->irq = pcidev->irq;
391 } 471 }
392 472
393 ret = comedi_alloc_subdevices(dev, 6); 473 ret = comedi_alloc_subdevices(dev, 7);
394 if (ret) 474 if (ret)
395 return ret; 475 return ret;
396 476
@@ -406,7 +486,7 @@ static int apci1564_auto_attach(struct comedi_device *dev,
406 /* Allocate and Initialise DO Subdevice Structures */ 486 /* Allocate and Initialise DO Subdevice Structures */
407 s = &dev->subdevices[1]; 487 s = &dev->subdevices[1];
408 s->type = COMEDI_SUBD_DO; 488 s->type = COMEDI_SUBD_DO;
409 s->subdev_flags = SDF_WRITEABLE; 489 s->subdev_flags = SDF_WRITABLE;
410 s->n_chan = 32; 490 s->n_chan = 32;
411 s->maxdata = 1; 491 s->maxdata = 1;
412 s->range_table = &range_digital; 492 s->range_table = &range_digital;
@@ -431,26 +511,40 @@ static int apci1564_auto_attach(struct comedi_device *dev,
431 s->type = COMEDI_SUBD_UNUSED; 511 s->type = COMEDI_SUBD_UNUSED;
432 } 512 }
433 513
434 /* Allocate and Initialise Timer Subdevice Structures */ 514 /* Timer subdevice */
435 s = &dev->subdevices[3]; 515 s = &dev->subdevices[3];
436 s->type = COMEDI_SUBD_TIMER; 516 s->type = COMEDI_SUBD_TIMER;
437 s->subdev_flags = SDF_WRITEABLE; 517 s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
438 s->n_chan = 1; 518 s->n_chan = 1;
439 s->maxdata = 0; 519 s->maxdata = 0x0fff;
440 s->len_chanlist = 1;
441 s->range_table = &range_digital; 520 s->range_table = &range_digital;
442 s->insn_write = apci1564_timer_write; 521 s->insn_config = apci1564_timer_insn_config;
443 s->insn_read = apci1564_timer_read; 522 s->insn_write = apci1564_timer_insn_write;
444 s->insn_config = apci1564_timer_config; 523 s->insn_read = apci1564_timer_insn_read;
445 524
446 /* Initialize the watchdog subdevice */ 525 /* Counter subdevice */
447 s = &dev->subdevices[4]; 526 s = &dev->subdevices[4];
448 ret = addi_watchdog_init(s, devpriv->amcc_iobase + APCI1564_WDOG_REG); 527 if (devpriv->counters) {
528 s->type = COMEDI_SUBD_COUNTER;
529 s->subdev_flags = SDF_WRITABLE | SDF_READABLE | SDF_LSAMPL;
530 s->n_chan = 3;
531 s->maxdata = 0xffffffff;
532 s->range_table = &range_digital;
533 s->insn_config = apci1564_counter_insn_config;
534 s->insn_write = apci1564_counter_insn_write;
535 s->insn_read = apci1564_counter_insn_read;
536 } else {
537 s->type = COMEDI_SUBD_UNUSED;
538 }
539
540 /* Initialize the watchdog subdevice */
541 s = &dev->subdevices[5];
542 ret = addi_watchdog_init(s, dev->iobase + APCI1564_WDOG_REG);
449 if (ret) 543 if (ret)
450 return ret; 544 return ret;
451 545
452 /* Initialize the diagnostic status subdevice */ 546 /* Initialize the diagnostic status subdevice */
453 s = &dev->subdevices[5]; 547 s = &dev->subdevices[6];
454 s->type = COMEDI_SUBD_DI; 548 s->type = COMEDI_SUBD_DI;
455 s->subdev_flags = SDF_READABLE; 549 s->subdev_flags = SDF_READABLE;
456 s->n_chan = 2; 550 s->n_chan = 2;
diff --git a/drivers/staging/comedi/drivers/addi_apci_16xx.c b/drivers/staging/comedi/drivers/addi_apci_16xx.c
index 4162e2dc2860..a1248dab369f 100644
--- a/drivers/staging/comedi/drivers/addi_apci_16xx.c
+++ b/drivers/staging/comedi/drivers/addi_apci_16xx.c
@@ -140,7 +140,7 @@ static int apci16xx_auto_attach(struct comedi_device *dev,
140 for (i = 0; i < n_subdevs; i++) { 140 for (i = 0; i < n_subdevs; i++) {
141 s = &dev->subdevices[i]; 141 s = &dev->subdevices[i];
142 s->type = COMEDI_SUBD_DIO; 142 s->type = COMEDI_SUBD_DIO;
143 s->subdev_flags = SDF_WRITEABLE | SDF_READABLE; 143 s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
144 s->n_chan = ((i * 32) < board->n_chan) ? 32 : last; 144 s->n_chan = ((i * 32) < board->n_chan) ? 32 : last;
145 s->maxdata = 1; 145 s->maxdata = 1;
146 s->range_table = &range_digital; 146 s->range_table = &range_digital;
diff --git a/drivers/staging/comedi/drivers/addi_apci_2032.c b/drivers/staging/comedi/drivers/addi_apci_2032.c
index aea3da325359..eebf4f151b39 100644
--- a/drivers/staging/comedi/drivers/addi_apci_2032.c
+++ b/drivers/staging/comedi/drivers/addi_apci_2032.c
@@ -47,7 +47,6 @@
47 47
48struct apci2032_int_private { 48struct apci2032_int_private {
49 spinlock_t spinlock; 49 spinlock_t spinlock;
50 unsigned int stop_count;
51 bool active; 50 bool active;
52 unsigned char enabled_isns; 51 unsigned char enabled_isns;
53}; 52};
@@ -148,7 +147,6 @@ static int apci2032_int_cmd(struct comedi_device *dev,
148 spin_lock_irqsave(&subpriv->spinlock, flags); 147 spin_lock_irqsave(&subpriv->spinlock, flags);
149 148
150 subpriv->enabled_isns = enabled_isns; 149 subpriv->enabled_isns = enabled_isns;
151 subpriv->stop_count = cmd->stop_arg;
152 subpriv->active = true; 150 subpriv->active = true;
153 outl(enabled_isns, dev->iobase + APCI2032_INT_CTRL_REG); 151 outl(enabled_isns, dev->iobase + APCI2032_INT_CTRL_REG);
154 152
@@ -178,7 +176,6 @@ static irqreturn_t apci2032_interrupt(int irq, void *d)
178 struct comedi_cmd *cmd = &s->async->cmd; 176 struct comedi_cmd *cmd = &s->async->cmd;
179 struct apci2032_int_private *subpriv; 177 struct apci2032_int_private *subpriv;
180 unsigned int val; 178 unsigned int val;
181 bool do_event = false;
182 179
183 if (!dev->attached) 180 if (!dev->attached)
184 return IRQ_NONE; 181 return IRQ_NONE;
@@ -212,27 +209,16 @@ static irqreturn_t apci2032_interrupt(int irq, void *d)
212 bits |= (1 << i); 209 bits |= (1 << i);
213 } 210 }
214 211
215 if (comedi_buf_put(s, bits)) { 212 comedi_buf_write_samples(s, &bits, 1);
216 s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOS; 213
217 if (cmd->stop_src == TRIG_COUNT && 214 if (cmd->stop_src == TRIG_COUNT &&
218 subpriv->stop_count > 0) { 215 s->async->scans_done >= cmd->stop_arg)
219 subpriv->stop_count--; 216 s->async->events |= COMEDI_CB_EOA;
220 if (subpriv->stop_count == 0) {
221 /* end of acquisition */
222 s->async->events |= COMEDI_CB_EOA;
223 apci2032_int_stop(dev, s);
224 }
225 }
226 } else {
227 apci2032_int_stop(dev, s);
228 s->async->events |= COMEDI_CB_OVERFLOW;
229 }
230 do_event = true;
231 } 217 }
232 218
233 spin_unlock(&subpriv->spinlock); 219 spin_unlock(&subpriv->spinlock);
234 if (do_event) 220
235 comedi_event(dev, s); 221 comedi_handle_events(dev, s);
236 222
237 return IRQ_HANDLED; 223 return IRQ_HANDLED;
238} 224}
@@ -274,7 +260,7 @@ static int apci2032_auto_attach(struct comedi_device *dev,
274 /* Initialize the digital output subdevice */ 260 /* Initialize the digital output subdevice */
275 s = &dev->subdevices[0]; 261 s = &dev->subdevices[0];
276 s->type = COMEDI_SUBD_DO; 262 s->type = COMEDI_SUBD_DO;
277 s->subdev_flags = SDF_WRITEABLE; 263 s->subdev_flags = SDF_WRITABLE;
278 s->n_chan = 32; 264 s->n_chan = 32;
279 s->maxdata = 1; 265 s->maxdata = 1;
280 s->range_table = &range_digital; 266 s->range_table = &range_digital;
@@ -303,7 +289,7 @@ static int apci2032_auto_attach(struct comedi_device *dev,
303 return -ENOMEM; 289 return -ENOMEM;
304 spin_lock_init(&subpriv->spinlock); 290 spin_lock_init(&subpriv->spinlock);
305 s->private = subpriv; 291 s->private = subpriv;
306 s->subdev_flags = SDF_READABLE | SDF_CMD_READ; 292 s->subdev_flags = SDF_READABLE | SDF_CMD_READ | SDF_PACKED;
307 s->len_chanlist = 2; 293 s->len_chanlist = 2;
308 s->do_cmdtest = apci2032_int_cmdtest; 294 s->do_cmdtest = apci2032_int_cmdtest;
309 s->do_cmd = apci2032_int_cmd; 295 s->do_cmd = apci2032_int_cmd;
diff --git a/drivers/staging/comedi/drivers/addi_apci_2200.c b/drivers/staging/comedi/drivers/addi_apci_2200.c
index 51ab1f937bae..1f9d13661ac9 100644
--- a/drivers/staging/comedi/drivers/addi_apci_2200.c
+++ b/drivers/staging/comedi/drivers/addi_apci_2200.c
@@ -98,7 +98,7 @@ static int apci2200_auto_attach(struct comedi_device *dev,
98 /* Initialize the digital output subdevice */ 98 /* Initialize the digital output subdevice */
99 s = &dev->subdevices[1]; 99 s = &dev->subdevices[1];
100 s->type = COMEDI_SUBD_DO; 100 s->type = COMEDI_SUBD_DO;
101 s->subdev_flags = SDF_WRITEABLE; 101 s->subdev_flags = SDF_WRITABLE;
102 s->n_chan = 16; 102 s->n_chan = 16;
103 s->maxdata = 1; 103 s->maxdata = 1;
104 s->range_table = &range_digital; 104 s->range_table = &range_digital;
diff --git a/drivers/staging/comedi/drivers/addi_apci_3120.c b/drivers/staging/comedi/drivers/addi_apci_3120.c
index ba71e24a56fd..c65f9407fd06 100644
--- a/drivers/staging/comedi/drivers/addi_apci_3120.c
+++ b/drivers/staging/comedi/drivers/addi_apci_3120.c
@@ -1,70 +1,993 @@
1/*
2 * addi_apci_3120.c
3 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
4 *
5 * ADDI-DATA GmbH
6 * Dieselstrasse 3
7 * D-77833 Ottersweier
8 * Tel: +19(0)7223/9493-0
9 * Fax: +49(0)7223/9493-92
10 * http://www.addi-data.com
11 * info@addi-data.com
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful, but WITHOUT
19 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21 * more details.
22 */
23
1#include <linux/module.h> 24#include <linux/module.h>
2#include <linux/pci.h> 25#include <linux/pci.h>
26#include <linux/interrupt.h>
3 27
4#include "../comedidev.h" 28#include "../comedidev.h"
5#include "comedi_fc.h" 29#include "comedi_fc.h"
6#include "amcc_s5933.h" 30#include "amcc_s5933.h"
7 31
8#include "addi-data/addi_common.h" 32/*
33 * PCI BAR 0 register map (devpriv->amcc)
34 * see amcc_s5933.h for register and bit defines
35 */
36#define APCI3120_FIFO_ADVANCE_ON_BYTE_2 (1 << 29)
37
38/*
39 * PCI BAR 1 register map (dev->iobase)
40 */
41#define APCI3120_AI_FIFO_REG 0x00
42#define APCI3120_CTRL_REG 0x00
43#define APCI3120_CTRL_EXT_TRIG (1 << 15)
44#define APCI3120_CTRL_GATE(x) (1 << (12 + (x)))
45#define APCI3120_CTRL_PR(x) (((x) & 0xf) << 8)
46#define APCI3120_CTRL_PA(x) (((x) & 0xf) << 0)
47#define APCI3120_AI_SOFTTRIG_REG 0x02
48#define APCI3120_STATUS_REG 0x02
49#define APCI3120_STATUS_EOC_INT (1 << 15)
50#define APCI3120_STATUS_AMCC_INT (1 << 14)
51#define APCI3120_STATUS_EOS_INT (1 << 13)
52#define APCI3120_STATUS_TIMER2_INT (1 << 12)
53#define APCI3120_STATUS_INT_MASK (0xf << 12)
54#define APCI3120_STATUS_TO_DI_BITS(x) (((x) >> 8) & 0xf)
55#define APCI3120_STATUS_TO_VERSION(x) (((x) >> 4) & 0xf)
56#define APCI3120_STATUS_FIFO_FULL (1 << 2)
57#define APCI3120_STATUS_FIFO_EMPTY (1 << 1)
58#define APCI3120_STATUS_DA_READY (1 << 0)
59#define APCI3120_TIMER_REG 0x04
60#define APCI3120_CHANLIST_REG 0x06
61#define APCI3120_CHANLIST_INDEX(x) (((x) & 0xf) << 8)
62#define APCI3120_CHANLIST_UNIPOLAR (1 << 7)
63#define APCI3120_CHANLIST_GAIN(x) (((x) & 0x3) << 4)
64#define APCI3120_CHANLIST_MUX(x) (((x) & 0xf) << 0)
65#define APCI3120_AO_REG(x) (0x08 + (((x) / 4) * 2))
66#define APCI3120_AO_MUX(x) (((x) & 0x3) << 14)
67#define APCI3120_AO_DATA(x) ((x) << 0)
68#define APCI3120_TIMER_MODE_REG 0x0c
69#define APCI3120_TIMER_MODE(_t, _m) ((_m) << ((_t) * 2))
70#define APCI3120_TIMER_MODE0 0 /* I8254_MODE0 */
71#define APCI3120_TIMER_MODE2 1 /* I8254_MODE2 */
72#define APCI3120_TIMER_MODE4 2 /* I8254_MODE4 */
73#define APCI3120_TIMER_MODE5 3 /* I8254_MODE5 */
74#define APCI3120_TIMER_MODE_MASK(_t) (3 << ((_t) * 2))
75#define APCI3120_CTR0_REG 0x0d
76#define APCI3120_CTR0_DO_BITS(x) ((x) << 4)
77#define APCI3120_CTR0_TIMER_SEL(x) ((x) << 0)
78#define APCI3120_MODE_REG 0x0e
79#define APCI3120_MODE_TIMER2_CLK_OSC (0 << 6)
80#define APCI3120_MODE_TIMER2_CLK_OUT1 (1 << 6)
81#define APCI3120_MODE_TIMER2_CLK_EOC (2 << 6)
82#define APCI3120_MODE_TIMER2_CLK_EOS (3 << 6)
83#define APCI3120_MODE_TIMER2_CLK_MASK (3 << 6)
84#define APCI3120_MODE_TIMER2_AS_TIMER (0 << 4)
85#define APCI3120_MODE_TIMER2_AS_COUNTER (1 << 4)
86#define APCI3120_MODE_TIMER2_AS_WDOG (2 << 4)
87#define APCI3120_MODE_TIMER2_AS_MASK (3 << 4) /* sets AS_TIMER */
88#define APCI3120_MODE_SCAN_ENA (1 << 3)
89#define APCI3120_MODE_TIMER2_IRQ_ENA (1 << 2)
90#define APCI3120_MODE_EOS_IRQ_ENA (1 << 1)
91#define APCI3120_MODE_EOC_IRQ_ENA (1 << 0)
92
93/*
94 * PCI BAR 2 register map (devpriv->addon)
95 */
96#define APCI3120_ADDON_ADDR_REG 0x00
97#define APCI3120_ADDON_DATA_REG 0x02
98#define APCI3120_ADDON_CTRL_REG 0x04
99#define APCI3120_ADDON_CTRL_AMWEN_ENA (1 << 1)
100#define APCI3120_ADDON_CTRL_A2P_FIFO_ENA (1 << 0)
9 101
10#include "addi-data/hwdrv_apci3120.c" 102/*
103 * Board revisions
104 */
105#define APCI3120_REVA 0xa
106#define APCI3120_REVB 0xb
107#define APCI3120_REVA_OSC_BASE 70 /* 70ns = 14.29MHz */
108#define APCI3120_REVB_OSC_BASE 50 /* 50ns = 20MHz */
109
110static const struct comedi_lrange apci3120_ai_range = {
111 8, {
112 BIP_RANGE(10),
113 BIP_RANGE(5),
114 BIP_RANGE(2),
115 BIP_RANGE(1),
116 UNI_RANGE(10),
117 UNI_RANGE(5),
118 UNI_RANGE(2),
119 UNI_RANGE(1)
120 }
121};
11 122
12enum apci3120_boardid { 123enum apci3120_boardid {
13 BOARD_APCI3120, 124 BOARD_APCI3120,
14 BOARD_APCI3001, 125 BOARD_APCI3001,
15}; 126};
16 127
17static const struct addi_board apci3120_boardtypes[] = { 128struct apci3120_board {
129 const char *name;
130 unsigned int ai_is_16bit:1;
131 unsigned int has_ao:1;
132};
133
134static const struct apci3120_board apci3120_boardtypes[] = {
18 [BOARD_APCI3120] = { 135 [BOARD_APCI3120] = {
19 .pc_DriverName = "apci3120", 136 .name = "apci3120",
20 .i_NbrAiChannel = 16, 137 .ai_is_16bit = 1,
21 .i_NbrAiChannelDiff = 8, 138 .has_ao = 1,
22 .i_AiChannelList = 16,
23 .i_NbrAoChannel = 8,
24 .i_AiMaxdata = 0xffff,
25 .i_AoMaxdata = 0x3fff,
26 .i_NbrDiChannel = 4,
27 .i_NbrDoChannel = 4,
28 .i_DoMaxdata = 0x0f,
29 .interrupt = apci3120_interrupt,
30 }, 139 },
31 [BOARD_APCI3001] = { 140 [BOARD_APCI3001] = {
32 .pc_DriverName = "apci3001", 141 .name = "apci3001",
33 .i_NbrAiChannel = 16,
34 .i_NbrAiChannelDiff = 8,
35 .i_AiChannelList = 16,
36 .i_AiMaxdata = 0xfff,
37 .i_NbrDiChannel = 4,
38 .i_NbrDoChannel = 4,
39 .i_DoMaxdata = 0x0f,
40 .interrupt = apci3120_interrupt,
41 }, 142 },
42}; 143};
43 144
44static irqreturn_t v_ADDI_Interrupt(int irq, void *d) 145struct apci3120_dmabuf {
146 unsigned short *virt;
147 dma_addr_t hw;
148 unsigned int size;
149 unsigned int use_size;
150};
151
152struct apci3120_private {
153 unsigned long amcc;
154 unsigned long addon;
155 unsigned int osc_base;
156 unsigned int use_dma:1;
157 unsigned int use_double_buffer:1;
158 unsigned int cur_dmabuf:1;
159 struct apci3120_dmabuf dmabuf[2];
160 unsigned char do_bits;
161 unsigned char timer_mode;
162 unsigned char mode;
163 unsigned short ctrl;
164};
165
166static void apci3120_addon_write(struct comedi_device *dev,
167 unsigned int val, unsigned int reg)
168{
169 struct apci3120_private *devpriv = dev->private;
170
171 /* 16-bit interface for AMCC add-on registers */
172
173 outw(reg, devpriv->addon + APCI3120_ADDON_ADDR_REG);
174 outw(val & 0xffff, devpriv->addon + APCI3120_ADDON_DATA_REG);
175
176 outw(reg + 2, devpriv->addon + APCI3120_ADDON_ADDR_REG);
177 outw((val >> 16) & 0xffff, devpriv->addon + APCI3120_ADDON_DATA_REG);
178}
179
180static void apci3120_init_dma(struct comedi_device *dev,
181 struct apci3120_dmabuf *dmabuf)
182{
183 struct apci3120_private *devpriv = dev->private;
184
185 /* AMCC - enable transfer count and reset A2P FIFO */
186 outl(AGCSTS_TC_ENABLE | AGCSTS_RESET_A2P_FIFO,
187 devpriv->amcc + AMCC_OP_REG_AGCSTS);
188
189 /* Add-On - enable transfer count and reset A2P FIFO */
190 apci3120_addon_write(dev, AGCSTS_TC_ENABLE | AGCSTS_RESET_A2P_FIFO,
191 AMCC_OP_REG_AGCSTS);
192
193 /* AMCC - enable transfers and reset A2P flags */
194 outl(RESET_A2P_FLAGS | EN_A2P_TRANSFERS,
195 devpriv->amcc + AMCC_OP_REG_MCSR);
196
197 /* Add-On - DMA start address */
198 apci3120_addon_write(dev, dmabuf->hw, AMCC_OP_REG_AMWAR);
199
200 /* Add-On - Number of acquisitions */
201 apci3120_addon_write(dev, dmabuf->use_size, AMCC_OP_REG_AMWTC);
202
203 /* AMCC - enable write complete (DMA) and set FIFO advance */
204 outl(APCI3120_FIFO_ADVANCE_ON_BYTE_2 | AINT_WRITE_COMPL,
205 devpriv->amcc + AMCC_OP_REG_INTCSR);
206
207 /* Add-On - enable DMA */
208 outw(APCI3120_ADDON_CTRL_AMWEN_ENA | APCI3120_ADDON_CTRL_A2P_FIFO_ENA,
209 devpriv->addon + APCI3120_ADDON_CTRL_REG);
210}
211
212static void apci3120_setup_dma(struct comedi_device *dev,
213 struct comedi_subdevice *s)
214{
215 struct apci3120_private *devpriv = dev->private;
216 struct comedi_cmd *cmd = &s->async->cmd;
217 struct apci3120_dmabuf *dmabuf0 = &devpriv->dmabuf[0];
218 struct apci3120_dmabuf *dmabuf1 = &devpriv->dmabuf[1];
219 unsigned int dmalen0 = dmabuf0->size;
220 unsigned int dmalen1 = dmabuf1->size;
221 unsigned int scan_bytes;
222
223 scan_bytes = comedi_samples_to_bytes(s, cmd->scan_end_arg);
224
225 if (cmd->stop_src == TRIG_COUNT) {
226 /*
227 * Must we fill full first buffer? And must we fill
228 * full second buffer when first is once filled?
229 */
230 if (dmalen0 > (cmd->stop_arg * scan_bytes))
231 dmalen0 = cmd->stop_arg * scan_bytes;
232 else if (dmalen1 > (cmd->stop_arg * scan_bytes - dmalen0))
233 dmalen1 = cmd->stop_arg * scan_bytes - dmalen0;
234 }
235
236 if (cmd->flags & CMDF_WAKE_EOS) {
237 /* don't we want wake up every scan? */
238 if (dmalen0 > scan_bytes) {
239 dmalen0 = scan_bytes;
240 if (cmd->scan_end_arg & 1)
241 dmalen0 += 2;
242 }
243 if (dmalen1 > scan_bytes) {
244 dmalen1 = scan_bytes;
245 if (cmd->scan_end_arg & 1)
246 dmalen1 -= 2;
247 if (dmalen1 < 4)
248 dmalen1 = 4;
249 }
250 } else {
251 /* isn't output buff smaller that our DMA buff? */
252 if (dmalen0 > s->async->prealloc_bufsz)
253 dmalen0 = s->async->prealloc_bufsz;
254 if (dmalen1 > s->async->prealloc_bufsz)
255 dmalen1 = s->async->prealloc_bufsz;
256 }
257 dmabuf0->use_size = dmalen0;
258 dmabuf1->use_size = dmalen1;
259
260 apci3120_init_dma(dev, dmabuf0);
261}
262
263/*
264 * There are three timers on the board. They all use the same base
265 * clock with a fixed prescaler for each timer. The base clock used
266 * depends on the board version and type.
267 *
268 * APCI-3120 Rev A boards OSC = 14.29MHz base clock (~70ns)
269 * APCI-3120 Rev B boards OSC = 20MHz base clock (50ns)
270 * APCI-3001 boards OSC = 20MHz base clock (50ns)
271 *
272 * The prescalers for each timer are:
273 * Timer 0 CLK = OSC/10
274 * Timer 1 CLK = OSC/1000
275 * Timer 2 CLK = OSC/1000
276 */
277static unsigned int apci3120_ns_to_timer(struct comedi_device *dev,
278 unsigned int timer,
279 unsigned int ns,
280 unsigned int flags)
281{
282 struct apci3120_private *devpriv = dev->private;
283 unsigned int prescale = (timer == 0) ? 10 : 1000;
284 unsigned int timer_base = devpriv->osc_base * prescale;
285 unsigned int divisor;
286
287 switch (flags & CMDF_ROUND_MASK) {
288 case CMDF_ROUND_UP:
289 divisor = DIV_ROUND_UP(ns, timer_base);
290 break;
291 case CMDF_ROUND_DOWN:
292 divisor = ns / timer_base;
293 break;
294 case CMDF_ROUND_NEAREST:
295 default:
296 divisor = DIV_ROUND_CLOSEST(ns, timer_base);
297 break;
298 }
299
300 if (timer == 2) {
301 /* timer 2 is 24-bits */
302 if (divisor > 0x00ffffff)
303 divisor = 0x00ffffff;
304 } else {
305 /* timers 0 and 1 are 16-bits */
306 if (divisor > 0xffff)
307 divisor = 0xffff;
308 }
309 /* the timers require a minimum divisor of 2 */
310 if (divisor < 2)
311 divisor = 2;
312
313 return divisor;
314}
315
316static void apci3120_clr_timer2_interrupt(struct comedi_device *dev)
317{
318 /* a dummy read of APCI3120_CTR0_REG clears the timer 2 interrupt */
319 inb(dev->iobase + APCI3120_CTR0_REG);
320}
321
322static void apci3120_timer_write(struct comedi_device *dev,
323 unsigned int timer, unsigned int val)
324{
325 struct apci3120_private *devpriv = dev->private;
326
327 /* write 16-bit value to timer (lower 16-bits of timer 2) */
328 outb(APCI3120_CTR0_DO_BITS(devpriv->do_bits) |
329 APCI3120_CTR0_TIMER_SEL(timer),
330 dev->iobase + APCI3120_CTR0_REG);
331 outw(val & 0xffff, dev->iobase + APCI3120_TIMER_REG);
332
333 if (timer == 2) {
334 /* write upper 16-bits to timer 2 */
335 outb(APCI3120_CTR0_DO_BITS(devpriv->do_bits) |
336 APCI3120_CTR0_TIMER_SEL(timer + 1),
337 dev->iobase + APCI3120_CTR0_REG);
338 outw((val >> 16) & 0xffff, dev->iobase + APCI3120_TIMER_REG);
339 }
340}
341
342static unsigned int apci3120_timer_read(struct comedi_device *dev,
343 unsigned int timer)
344{
345 struct apci3120_private *devpriv = dev->private;
346 unsigned int val;
347
348 /* read 16-bit value from timer (lower 16-bits of timer 2) */
349 outb(APCI3120_CTR0_DO_BITS(devpriv->do_bits) |
350 APCI3120_CTR0_TIMER_SEL(timer),
351 dev->iobase + APCI3120_CTR0_REG);
352 val = inw(dev->iobase + APCI3120_TIMER_REG);
353
354 if (timer == 2) {
355 /* read upper 16-bits from timer 2 */
356 outb(APCI3120_CTR0_DO_BITS(devpriv->do_bits) |
357 APCI3120_CTR0_TIMER_SEL(timer + 1),
358 dev->iobase + APCI3120_CTR0_REG);
359 val |= (inw(dev->iobase + APCI3120_TIMER_REG) << 16);
360 }
361
362 return val;
363}
364
365static void apci3120_timer_set_mode(struct comedi_device *dev,
366 unsigned int timer, unsigned int mode)
367{
368 struct apci3120_private *devpriv = dev->private;
369
370 devpriv->timer_mode &= ~APCI3120_TIMER_MODE_MASK(timer);
371 devpriv->timer_mode |= APCI3120_TIMER_MODE(timer, mode);
372 outb(devpriv->timer_mode, dev->iobase + APCI3120_TIMER_MODE_REG);
373}
374
375static void apci3120_timer_enable(struct comedi_device *dev,
376 unsigned int timer, bool enable)
377{
378 struct apci3120_private *devpriv = dev->private;
379
380 if (enable)
381 devpriv->ctrl |= APCI3120_CTRL_GATE(timer);
382 else
383 devpriv->ctrl &= ~APCI3120_CTRL_GATE(timer);
384 outw(devpriv->ctrl, dev->iobase + APCI3120_CTRL_REG);
385}
386
387static void apci3120_exttrig_enable(struct comedi_device *dev, bool enable)
388{
389 struct apci3120_private *devpriv = dev->private;
390
391 if (enable)
392 devpriv->ctrl |= APCI3120_CTRL_EXT_TRIG;
393 else
394 devpriv->ctrl &= ~APCI3120_CTRL_EXT_TRIG;
395 outw(devpriv->ctrl, dev->iobase + APCI3120_CTRL_REG);
396}
397
398static void apci3120_set_chanlist(struct comedi_device *dev,
399 struct comedi_subdevice *s,
400 int n_chan, unsigned int *chanlist)
401{
402 struct apci3120_private *devpriv = dev->private;
403 int i;
404
405 /* set chanlist for scan */
406 for (i = 0; i < n_chan; i++) {
407 unsigned int chan = CR_CHAN(chanlist[i]);
408 unsigned int range = CR_RANGE(chanlist[i]);
409 unsigned int val;
410
411 val = APCI3120_CHANLIST_MUX(chan) |
412 APCI3120_CHANLIST_GAIN(range) |
413 APCI3120_CHANLIST_INDEX(i);
414
415 if (comedi_range_is_unipolar(s, range))
416 val |= APCI3120_CHANLIST_UNIPOLAR;
417
418 outw(val, dev->iobase + APCI3120_CHANLIST_REG);
419 }
420
421 /* a dummy read of APCI3120_TIMER_MODE_REG resets the ai FIFO */
422 inw(dev->iobase + APCI3120_TIMER_MODE_REG);
423
424 /* set scan length (PR) and scan start (PA) */
425 devpriv->ctrl = APCI3120_CTRL_PR(n_chan - 1) | APCI3120_CTRL_PA(0);
426 outw(devpriv->ctrl, dev->iobase + APCI3120_CTRL_REG);
427
428 /* enable chanlist scanning if necessary */
429 if (n_chan > 1)
430 devpriv->mode |= APCI3120_MODE_SCAN_ENA;
431}
432
433static void apci3120_interrupt_dma(struct comedi_device *dev,
434 struct comedi_subdevice *s)
435{
436 struct apci3120_private *devpriv = dev->private;
437 struct comedi_async *async = s->async;
438 struct comedi_cmd *cmd = &async->cmd;
439 struct apci3120_dmabuf *dmabuf;
440 unsigned int nbytes;
441 unsigned int nsamples;
442
443 dmabuf = &devpriv->dmabuf[devpriv->cur_dmabuf];
444
445 nbytes = dmabuf->use_size - inl(devpriv->amcc + AMCC_OP_REG_MWTC);
446
447 if (nbytes < dmabuf->use_size)
448 dev_err(dev->class_dev, "Interrupted DMA transfer!\n");
449 if (nbytes & 1) {
450 dev_err(dev->class_dev, "Odd count of bytes in DMA ring!\n");
451 async->events |= COMEDI_CB_ERROR;
452 return;
453 }
454
455 nsamples = comedi_bytes_to_samples(s, nbytes);
456 if (nsamples) {
457 comedi_buf_write_samples(s, dmabuf->virt, nsamples);
458
459 if (!(cmd->flags & CMDF_WAKE_EOS))
460 async->events |= COMEDI_CB_EOS;
461 }
462
463 if ((async->events & COMEDI_CB_CANCEL_MASK) ||
464 (cmd->stop_src == TRIG_COUNT && async->scans_done >= cmd->stop_arg))
465 return;
466
467 if (devpriv->use_double_buffer) {
468 /* switch DMA buffers for next interrupt */
469 devpriv->cur_dmabuf = !devpriv->cur_dmabuf;
470 dmabuf = &devpriv->dmabuf[devpriv->cur_dmabuf];
471 apci3120_init_dma(dev, dmabuf);
472 } else {
473 /* restart DMA if not using double buffering */
474 apci3120_init_dma(dev, dmabuf);
475 }
476}
477
478static irqreturn_t apci3120_interrupt(int irq, void *d)
45{ 479{
46 struct comedi_device *dev = d; 480 struct comedi_device *dev = d;
47 const struct addi_board *this_board = dev->board_ptr; 481 struct apci3120_private *devpriv = dev->private;
482 struct comedi_subdevice *s = dev->read_subdev;
483 struct comedi_async *async = s->async;
484 struct comedi_cmd *cmd = &async->cmd;
485 unsigned int status;
486 unsigned int int_amcc;
487
488 status = inw(dev->iobase + APCI3120_STATUS_REG);
489 int_amcc = inl(devpriv->amcc + AMCC_OP_REG_INTCSR);
490
491 if (!(status & APCI3120_STATUS_INT_MASK) &&
492 !(int_amcc & ANY_S593X_INT)) {
493 dev_err(dev->class_dev, "IRQ from unknown source\n");
494 return IRQ_NONE;
495 }
496
497 outl(int_amcc | AINT_INT_MASK, devpriv->amcc + AMCC_OP_REG_INTCSR);
48 498
49 this_board->interrupt(irq, d); 499 if (devpriv->ctrl & APCI3120_CTRL_EXT_TRIG)
50 return IRQ_RETVAL(1); 500 apci3120_exttrig_enable(dev, false);
501
502 if (int_amcc & MASTER_ABORT_INT)
503 dev_err(dev->class_dev, "AMCC IRQ - MASTER DMA ABORT!\n");
504 if (int_amcc & TARGET_ABORT_INT)
505 dev_err(dev->class_dev, "AMCC IRQ - TARGET DMA ABORT!\n");
506
507 if ((status & APCI3120_STATUS_EOC_INT) == 0 &&
508 (devpriv->mode & APCI3120_MODE_EOC_IRQ_ENA)) {
509 /* nothing to do... EOC mode is not currently used */
510 }
511
512 if ((status & APCI3120_STATUS_EOS_INT) &&
513 (devpriv->mode & APCI3120_MODE_EOS_IRQ_ENA)) {
514 unsigned short val;
515 int i;
516
517 for (i = 0; i < cmd->chanlist_len; i++) {
518 val = inw(dev->iobase + APCI3120_AI_FIFO_REG);
519 comedi_buf_write_samples(s, &val, 1);
520 }
521
522 devpriv->mode |= APCI3120_MODE_EOS_IRQ_ENA;
523 outb(devpriv->mode, dev->iobase + APCI3120_MODE_REG);
524 }
525
526 if (status & APCI3120_STATUS_TIMER2_INT) {
527 /*
528 * for safety...
529 * timer2 interrupts are not enabled in the driver
530 */
531 apci3120_clr_timer2_interrupt(dev);
532 }
533
534 if (status & APCI3120_STATUS_AMCC_INT) {
535 /* AMCC- Clear write complete interrupt (DMA) */
536 outl(AINT_WT_COMPLETE, devpriv->amcc + AMCC_OP_REG_INTCSR);
537
538 /* do some data transfer */
539 apci3120_interrupt_dma(dev, s);
540 }
541
542 if (cmd->stop_src == TRIG_COUNT && async->scans_done >= cmd->stop_arg)
543 async->events |= COMEDI_CB_EOA;
544
545 comedi_handle_events(dev, s);
546
547 return IRQ_HANDLED;
548}
549
550static int apci3120_ai_cmd(struct comedi_device *dev,
551 struct comedi_subdevice *s)
552{
553 struct apci3120_private *devpriv = dev->private;
554 struct comedi_cmd *cmd = &s->async->cmd;
555 unsigned int divisor;
556
557 /* set default mode bits */
558 devpriv->mode = APCI3120_MODE_TIMER2_CLK_OSC |
559 APCI3120_MODE_TIMER2_AS_TIMER;
560
561 /* AMCC- Clear write complete interrupt (DMA) */
562 outl(AINT_WT_COMPLETE, devpriv->amcc + AMCC_OP_REG_INTCSR);
563
564 devpriv->cur_dmabuf = 0;
565
566 /* load chanlist for command scan */
567 apci3120_set_chanlist(dev, s, cmd->chanlist_len, cmd->chanlist);
568
569 if (cmd->start_src == TRIG_EXT)
570 apci3120_exttrig_enable(dev, true);
571
572 if (cmd->scan_begin_src == TRIG_TIMER) {
573 /*
574 * Timer 1 is used in MODE2 (rate generator) to set the
575 * start time for each scan.
576 */
577 divisor = apci3120_ns_to_timer(dev, 1, cmd->scan_begin_arg,
578 cmd->flags);
579 apci3120_timer_set_mode(dev, 1, APCI3120_TIMER_MODE2);
580 apci3120_timer_write(dev, 1, divisor);
581 }
582
583 /*
584 * Timer 0 is used in MODE2 (rate generator) to set the conversion
585 * time for each acquisition.
586 */
587 divisor = apci3120_ns_to_timer(dev, 0, cmd->convert_arg, cmd->flags);
588 apci3120_timer_set_mode(dev, 0, APCI3120_TIMER_MODE2);
589 apci3120_timer_write(dev, 0, divisor);
590
591 if (devpriv->use_dma)
592 apci3120_setup_dma(dev, s);
593 else
594 devpriv->mode |= APCI3120_MODE_EOS_IRQ_ENA;
595
596 /* set mode to enable acquisition */
597 outb(devpriv->mode, dev->iobase + APCI3120_MODE_REG);
598
599 if (cmd->scan_begin_src == TRIG_TIMER)
600 apci3120_timer_enable(dev, 1, true);
601 apci3120_timer_enable(dev, 0, true);
602
603 return 0;
604}
605
606static int apci3120_ai_cmdtest(struct comedi_device *dev,
607 struct comedi_subdevice *s,
608 struct comedi_cmd *cmd)
609{
610 unsigned int arg;
611 int err = 0;
612
613 /* Step 1 : check if triggers are trivially valid */
614
615 err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW | TRIG_EXT);
616 err |= cfc_check_trigger_src(&cmd->scan_begin_src,
617 TRIG_TIMER | TRIG_FOLLOW);
618 err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_TIMER);
619 err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
620 err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
621
622 if (err)
623 return 1;
624
625 /* Step 2a : make sure trigger sources are unique */
626
627 err |= cfc_check_trigger_is_unique(cmd->start_src);
628 err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
629 err |= cfc_check_trigger_is_unique(cmd->stop_src);
630
631 /* Step 2b : and mutually compatible */
632
633 if (err)
634 return 2;
635
636 /* Step 3: check if arguments are trivially valid */
637
638 err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
639
640 if (cmd->scan_begin_src == TRIG_TIMER) /* Test Delay timing */
641 err |= cfc_check_trigger_arg_min(&cmd->scan_begin_arg, 100000);
642
643 /* minimum conversion time per sample is 10us */
644 err |= cfc_check_trigger_arg_min(&cmd->convert_arg, 10000);
645
646 err |= cfc_check_trigger_arg_min(&cmd->chanlist_len, 1);
647 err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len);
648
649 if (cmd->stop_src == TRIG_COUNT)
650 err |= cfc_check_trigger_arg_min(&cmd->stop_arg, 1);
651 else /* TRIG_NONE */
652 err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0);
653
654 if (err)
655 return 3;
656
657 /* Step 4: fix up any arguments */
658
659 if (cmd->scan_begin_src == TRIG_TIMER) {
660 /* scan begin must be larger than the scan time */
661 arg = cmd->convert_arg * cmd->scan_end_arg;
662 err |= cfc_check_trigger_arg_min(&cmd->scan_begin_arg, arg);
663 }
664
665 if (err)
666 return 4;
667
668 /* Step 5: check channel list if it exists */
669
670 return 0;
671}
672
673static int apci3120_cancel(struct comedi_device *dev,
674 struct comedi_subdevice *s)
675{
676 struct apci3120_private *devpriv = dev->private;
677
678 /* Add-On - disable DMA */
679 outw(0, devpriv->addon + 4);
680
681 /* Add-On - disable bus master */
682 apci3120_addon_write(dev, 0, AMCC_OP_REG_AGCSTS);
683
684 /* AMCC - disable bus master */
685 outl(0, devpriv->amcc + AMCC_OP_REG_MCSR);
686
687 /* disable all counters, ext trigger, and reset scan */
688 devpriv->ctrl = 0;
689 outw(devpriv->ctrl, dev->iobase + APCI3120_CTRL_REG);
690
691 /* DISABLE_ALL_INTERRUPT */
692 devpriv->mode = 0;
693 outb(devpriv->mode, dev->iobase + APCI3120_MODE_REG);
694
695 inw(dev->iobase + APCI3120_STATUS_REG);
696 devpriv->cur_dmabuf = 0;
697
698 return 0;
699}
700
701static int apci3120_ai_eoc(struct comedi_device *dev,
702 struct comedi_subdevice *s,
703 struct comedi_insn *insn,
704 unsigned long context)
705{
706 unsigned int status;
707
708 status = inw(dev->iobase + APCI3120_STATUS_REG);
709 if ((status & APCI3120_STATUS_EOC_INT) == 0)
710 return 0;
711 return -EBUSY;
712}
713
714static int apci3120_ai_insn_read(struct comedi_device *dev,
715 struct comedi_subdevice *s,
716 struct comedi_insn *insn,
717 unsigned int *data)
718{
719 struct apci3120_private *devpriv = dev->private;
720 unsigned int divisor;
721 int ret;
722 int i;
723
724 /* set mode for A/D conversions by software trigger with timer 0 */
725 devpriv->mode = APCI3120_MODE_TIMER2_CLK_OSC |
726 APCI3120_MODE_TIMER2_AS_TIMER;
727 outb(devpriv->mode, dev->iobase + APCI3120_MODE_REG);
728
729 /* load chanlist for single channel scan */
730 apci3120_set_chanlist(dev, s, 1, &insn->chanspec);
731
732 /*
733 * Timer 0 is used in MODE4 (software triggered strobe) to set the
734 * conversion time for each acquisition. Each conversion is triggered
735 * when the divisor is written to the timer, The conversion is done
736 * when the EOC bit in the status register is '0'.
737 */
738 apci3120_timer_set_mode(dev, 0, APCI3120_TIMER_MODE4);
739 apci3120_timer_enable(dev, 0, true);
740
741 /* fixed conversion time of 10 us */
742 divisor = apci3120_ns_to_timer(dev, 0, 10000, CMDF_ROUND_NEAREST);
743
744 for (i = 0; i < insn->n; i++) {
745 /* trigger conversion */
746 apci3120_timer_write(dev, 0, divisor);
747
748 ret = comedi_timeout(dev, s, insn, apci3120_ai_eoc, 0);
749 if (ret)
750 return ret;
751
752 data[i] = inw(dev->iobase + APCI3120_AI_FIFO_REG);
753 }
754
755 return insn->n;
756}
757
758static int apci3120_ao_ready(struct comedi_device *dev,
759 struct comedi_subdevice *s,
760 struct comedi_insn *insn,
761 unsigned long context)
762{
763 unsigned int status;
764
765 status = inw(dev->iobase + APCI3120_STATUS_REG);
766 if (status & APCI3120_STATUS_DA_READY)
767 return 0;
768 return -EBUSY;
769}
770
771static int apci3120_ao_insn_write(struct comedi_device *dev,
772 struct comedi_subdevice *s,
773 struct comedi_insn *insn,
774 unsigned int *data)
775{
776 unsigned int chan = CR_CHAN(insn->chanspec);
777 int i;
778
779 for (i = 0; i < insn->n; i++) {
780 unsigned int val = data[i];
781 int ret;
782
783 ret = comedi_timeout(dev, s, insn, apci3120_ao_ready, 0);
784 if (ret)
785 return ret;
786
787 outw(APCI3120_AO_MUX(chan) | APCI3120_AO_DATA(val),
788 dev->iobase + APCI3120_AO_REG(chan));
789
790 s->readback[chan] = val;
791 }
792
793 return insn->n;
794}
795
796static int apci3120_di_insn_bits(struct comedi_device *dev,
797 struct comedi_subdevice *s,
798 struct comedi_insn *insn,
799 unsigned int *data)
800{
801 unsigned int status;
802
803 status = inw(dev->iobase + APCI3120_STATUS_REG);
804 data[1] = APCI3120_STATUS_TO_DI_BITS(status);
805
806 return insn->n;
807}
808
809static int apci3120_do_insn_bits(struct comedi_device *dev,
810 struct comedi_subdevice *s,
811 struct comedi_insn *insn,
812 unsigned int *data)
813{
814 struct apci3120_private *devpriv = dev->private;
815
816 if (comedi_dio_update_state(s, data)) {
817 devpriv->do_bits = s->state;
818 outb(APCI3120_CTR0_DO_BITS(devpriv->do_bits),
819 dev->iobase + APCI3120_CTR0_REG);
820 }
821
822 data[1] = s->state;
823
824 return insn->n;
825}
826
827static int apci3120_timer_insn_config(struct comedi_device *dev,
828 struct comedi_subdevice *s,
829 struct comedi_insn *insn,
830 unsigned int *data)
831{
832 struct apci3120_private *devpriv = dev->private;
833 unsigned int divisor;
834 unsigned int status;
835 unsigned int mode;
836 unsigned int timer_mode;
837
838 switch (data[0]) {
839 case INSN_CONFIG_ARM:
840 apci3120_clr_timer2_interrupt(dev);
841 divisor = apci3120_ns_to_timer(dev, 2, data[1],
842 CMDF_ROUND_DOWN);
843 apci3120_timer_write(dev, 2, divisor);
844 apci3120_timer_enable(dev, 2, true);
845 break;
846
847 case INSN_CONFIG_DISARM:
848 apci3120_timer_enable(dev, 2, false);
849 apci3120_clr_timer2_interrupt(dev);
850 break;
851
852 case INSN_CONFIG_GET_COUNTER_STATUS:
853 data[1] = 0;
854 data[2] = COMEDI_COUNTER_ARMED | COMEDI_COUNTER_COUNTING |
855 COMEDI_COUNTER_TERMINAL_COUNT;
856
857 if (devpriv->ctrl & APCI3120_CTRL_GATE(2)) {
858 data[1] |= COMEDI_COUNTER_ARMED;
859 data[1] |= COMEDI_COUNTER_COUNTING;
860 }
861 status = inw(dev->iobase + APCI3120_STATUS_REG);
862 if (status & APCI3120_STATUS_TIMER2_INT) {
863 data[1] &= ~COMEDI_COUNTER_COUNTING;
864 data[1] |= COMEDI_COUNTER_TERMINAL_COUNT;
865 }
866 break;
867
868 case INSN_CONFIG_SET_COUNTER_MODE:
869 switch (data[1]) {
870 case I8254_MODE0:
871 mode = APCI3120_MODE_TIMER2_AS_COUNTER;
872 timer_mode = APCI3120_TIMER_MODE0;
873 break;
874 case I8254_MODE2:
875 mode = APCI3120_MODE_TIMER2_AS_TIMER;
876 timer_mode = APCI3120_TIMER_MODE2;
877 break;
878 case I8254_MODE4:
879 mode = APCI3120_MODE_TIMER2_AS_TIMER;
880 timer_mode = APCI3120_TIMER_MODE4;
881 break;
882 case I8254_MODE5:
883 mode = APCI3120_MODE_TIMER2_AS_WDOG;
884 timer_mode = APCI3120_TIMER_MODE5;
885 break;
886 default:
887 return -EINVAL;
888 }
889 apci3120_timer_enable(dev, 2, false);
890 apci3120_clr_timer2_interrupt(dev);
891 apci3120_timer_set_mode(dev, 2, timer_mode);
892 devpriv->mode &= ~APCI3120_MODE_TIMER2_AS_MASK;
893 devpriv->mode |= mode;
894 outb(devpriv->mode, dev->iobase + APCI3120_MODE_REG);
895 break;
896
897 default:
898 return -EINVAL;
899 }
900
901 return insn->n;
902}
903
904static int apci3120_timer_insn_read(struct comedi_device *dev,
905 struct comedi_subdevice *s,
906 struct comedi_insn *insn,
907 unsigned int *data)
908{
909 int i;
910
911 for (i = 0; i < insn->n; i++)
912 data[i] = apci3120_timer_read(dev, 2);
913
914 return insn->n;
915}
916
917static void apci3120_dma_alloc(struct comedi_device *dev)
918{
919 struct apci3120_private *devpriv = dev->private;
920 struct apci3120_dmabuf *dmabuf;
921 int order;
922 int i;
923
924 for (i = 0; i < 2; i++) {
925 dmabuf = &devpriv->dmabuf[i];
926 for (order = 2; order >= 0; order--) {
927 dmabuf->virt = dma_alloc_coherent(dev->hw_dev,
928 PAGE_SIZE << order,
929 &dmabuf->hw,
930 GFP_KERNEL);
931 if (dmabuf->virt)
932 break;
933 }
934 if (!dmabuf->virt)
935 break;
936 dmabuf->size = PAGE_SIZE << order;
937
938 if (i == 0)
939 devpriv->use_dma = 1;
940 if (i == 1)
941 devpriv->use_double_buffer = 1;
942 }
943}
944
945static void apci3120_dma_free(struct comedi_device *dev)
946{
947 struct apci3120_private *devpriv = dev->private;
948 struct apci3120_dmabuf *dmabuf;
949 int i;
950
951 if (!devpriv)
952 return;
953
954 for (i = 0; i < 2; i++) {
955 dmabuf = &devpriv->dmabuf[i];
956 if (dmabuf->virt) {
957 dma_free_coherent(dev->hw_dev, dmabuf->size,
958 dmabuf->virt, dmabuf->hw);
959 }
960 }
961}
962
963static void apci3120_reset(struct comedi_device *dev)
964{
965 /* disable all interrupt sources */
966 outb(0, dev->iobase + APCI3120_MODE_REG);
967
968 /* disable all counters, ext trigger, and reset scan */
969 outw(0, dev->iobase + APCI3120_CTRL_REG);
970
971 /* clear interrupt status */
972 inw(dev->iobase + APCI3120_STATUS_REG);
51} 973}
52 974
53static int apci3120_auto_attach(struct comedi_device *dev, 975static int apci3120_auto_attach(struct comedi_device *dev,
54 unsigned long context) 976 unsigned long context)
55{ 977{
56 struct pci_dev *pcidev = comedi_to_pci_dev(dev); 978 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
57 const struct addi_board *this_board = NULL; 979 const struct apci3120_board *this_board = NULL;
58 struct addi_private *devpriv; 980 struct apci3120_private *devpriv;
59 struct comedi_subdevice *s; 981 struct comedi_subdevice *s;
60 int ret, order, i; 982 unsigned int status;
983 int ret;
61 984
62 if (context < ARRAY_SIZE(apci3120_boardtypes)) 985 if (context < ARRAY_SIZE(apci3120_boardtypes))
63 this_board = &apci3120_boardtypes[context]; 986 this_board = &apci3120_boardtypes[context];
64 if (!this_board) 987 if (!this_board)
65 return -ENODEV; 988 return -ENODEV;
66 dev->board_ptr = this_board; 989 dev->board_ptr = this_board;
67 dev->board_name = this_board->pc_DriverName; 990 dev->board_name = this_board->name;
68 991
69 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv)); 992 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
70 if (!devpriv) 993 if (!devpriv)
@@ -76,136 +999,100 @@ static int apci3120_auto_attach(struct comedi_device *dev,
76 pci_set_master(pcidev); 999 pci_set_master(pcidev);
77 1000
78 dev->iobase = pci_resource_start(pcidev, 1); 1001 dev->iobase = pci_resource_start(pcidev, 1);
79 devpriv->iobase = dev->iobase; 1002 devpriv->amcc = pci_resource_start(pcidev, 0);
80 devpriv->i_IobaseAmcc = pci_resource_start(pcidev, 0); 1003 devpriv->addon = pci_resource_start(pcidev, 2);
81 devpriv->i_IobaseAddon = pci_resource_start(pcidev, 2); 1004
82 devpriv->i_IobaseReserved = pci_resource_start(pcidev, 3); 1005 apci3120_reset(dev);
83 1006
84 if (pcidev->irq > 0) { 1007 if (pcidev->irq > 0) {
85 ret = request_irq(pcidev->irq, v_ADDI_Interrupt, IRQF_SHARED, 1008 ret = request_irq(pcidev->irq, apci3120_interrupt, IRQF_SHARED,
86 dev->board_name, dev); 1009 dev->board_name, dev);
87 if (ret == 0) 1010 if (ret == 0) {
88 dev->irq = pcidev->irq; 1011 dev->irq = pcidev->irq;
89 }
90 1012
91 /* Allocate DMA buffers */ 1013 apci3120_dma_alloc(dev);
92 for (i = 0; i < 2; i++) {
93 for (order = 2; order >= 0; order--) {
94 devpriv->ul_DmaBufferVirtual[i] =
95 dma_alloc_coherent(dev->hw_dev, PAGE_SIZE << order,
96 &devpriv->ul_DmaBufferHw[i],
97 GFP_KERNEL);
98
99 if (devpriv->ul_DmaBufferVirtual[i])
100 break;
101 } 1014 }
102 if (!devpriv->ul_DmaBufferVirtual[i])
103 break;
104 devpriv->ui_DmaBufferSize[i] = PAGE_SIZE << order;
105 } 1015 }
106 if (devpriv->ul_DmaBufferVirtual[0])
107 devpriv->us_UseDma = 1;
108 1016
109 if (devpriv->ul_DmaBufferVirtual[1]) 1017 status = inw(dev->iobase + APCI3120_STATUS_REG);
110 devpriv->b_DmaDoubleBuffer = 1; 1018 if (APCI3120_STATUS_TO_VERSION(status) == APCI3120_REVB ||
1019 context == BOARD_APCI3001)
1020 devpriv->osc_base = APCI3120_REVB_OSC_BASE;
1021 else
1022 devpriv->osc_base = APCI3120_REVA_OSC_BASE;
111 1023
112 ret = comedi_alloc_subdevices(dev, 5); 1024 ret = comedi_alloc_subdevices(dev, 5);
113 if (ret) 1025 if (ret)
114 return ret; 1026 return ret;
115 1027
116 /* Allocate and Initialise AI Subdevice Structures */ 1028 /* Analog Input subdevice */
117 s = &dev->subdevices[0]; 1029 s = &dev->subdevices[0];
118 dev->read_subdev = s; 1030 s->type = COMEDI_SUBD_AI;
119 s->type = COMEDI_SUBD_AI; 1031 s->subdev_flags = SDF_READABLE | SDF_COMMON | SDF_GROUND | SDF_DIFF;
120 s->subdev_flags = 1032 s->n_chan = 16;
121 SDF_READABLE | SDF_COMMON | SDF_GROUND 1033 s->maxdata = this_board->ai_is_16bit ? 0xffff : 0x0fff;
122 | SDF_DIFF; 1034 s->range_table = &apci3120_ai_range;
123 if (this_board->i_NbrAiChannel) 1035 s->insn_read = apci3120_ai_insn_read;
124 s->n_chan = this_board->i_NbrAiChannel; 1036 if (dev->irq) {
125 else 1037 dev->read_subdev = s;
126 s->n_chan = this_board->i_NbrAiChannelDiff; 1038 s->subdev_flags |= SDF_CMD_READ;
127 s->maxdata = this_board->i_AiMaxdata; 1039 s->len_chanlist = s->n_chan;
128 s->len_chanlist = this_board->i_AiChannelList; 1040 s->do_cmdtest = apci3120_ai_cmdtest;
129 s->range_table = &range_apci3120_ai; 1041 s->do_cmd = apci3120_ai_cmd;
130 1042 s->cancel = apci3120_cancel;
131 s->insn_config = apci3120_ai_insn_config; 1043 }
132 s->insn_read = apci3120_ai_insn_read; 1044
133 s->do_cmdtest = apci3120_ai_cmdtest; 1045 /* Analog Output subdevice */
134 s->do_cmd = apci3120_ai_cmd;
135 s->cancel = apci3120_cancel;
136
137 /* Allocate and Initialise AO Subdevice Structures */
138 s = &dev->subdevices[1]; 1046 s = &dev->subdevices[1];
139 if (this_board->i_NbrAoChannel) { 1047 if (this_board->has_ao) {
140 s->type = COMEDI_SUBD_AO; 1048 s->type = COMEDI_SUBD_AO;
141 s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; 1049 s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON;
142 s->n_chan = this_board->i_NbrAoChannel; 1050 s->n_chan = 8;
143 s->maxdata = this_board->i_AoMaxdata; 1051 s->maxdata = 0x3fff;
144 s->len_chanlist = this_board->i_NbrAoChannel; 1052 s->range_table = &range_bipolar10;
145 s->range_table = &range_apci3120_ao; 1053 s->insn_write = apci3120_ao_insn_write;
146 s->insn_write = apci3120_ao_insn_write; 1054
1055 ret = comedi_alloc_subdev_readback(s);
1056 if (ret)
1057 return ret;
147 } else { 1058 } else {
148 s->type = COMEDI_SUBD_UNUSED; 1059 s->type = COMEDI_SUBD_UNUSED;
149 } 1060 }
150 1061
151 /* Allocate and Initialise DI Subdevice Structures */ 1062 /* Digital Input subdevice */
152 s = &dev->subdevices[2]; 1063 s = &dev->subdevices[2];
153 s->type = COMEDI_SUBD_DI; 1064 s->type = COMEDI_SUBD_DI;
154 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON; 1065 s->subdev_flags = SDF_READABLE;
155 s->n_chan = this_board->i_NbrDiChannel; 1066 s->n_chan = 4;
156 s->maxdata = 1; 1067 s->maxdata = 1;
157 s->len_chanlist = this_board->i_NbrDiChannel; 1068 s->range_table = &range_digital;
158 s->range_table = &range_digital; 1069 s->insn_bits = apci3120_di_insn_bits;
159 s->insn_bits = apci3120_di_insn_bits; 1070
160 1071 /* Digital Output subdevice */
161 /* Allocate and Initialise DO Subdevice Structures */
162 s = &dev->subdevices[3]; 1072 s = &dev->subdevices[3];
163 s->type = COMEDI_SUBD_DO; 1073 s->type = COMEDI_SUBD_DO;
164 s->subdev_flags = 1074 s->subdev_flags = SDF_WRITABLE;
165 SDF_READABLE | SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; 1075 s->n_chan = 4;
166 s->n_chan = this_board->i_NbrDoChannel; 1076 s->maxdata = 1;
167 s->maxdata = this_board->i_DoMaxdata; 1077 s->range_table = &range_digital;
168 s->len_chanlist = this_board->i_NbrDoChannel; 1078 s->insn_bits = apci3120_do_insn_bits;
169 s->range_table = &range_digital;
170 s->insn_bits = apci3120_do_insn_bits;
171
172 /* Allocate and Initialise Timer Subdevice Structures */
173 s = &dev->subdevices[4];
174 s->type = COMEDI_SUBD_TIMER;
175 s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON;
176 s->n_chan = 1;
177 s->maxdata = 0;
178 s->len_chanlist = 1;
179 s->range_table = &range_digital;
180 1079
181 s->insn_write = apci3120_write_insn_timer; 1080 /* Timer subdevice */
182 s->insn_read = apci3120_read_insn_timer; 1081 s = &dev->subdevices[4];
183 s->insn_config = apci3120_config_insn_timer; 1082 s->type = COMEDI_SUBD_TIMER;
1083 s->subdev_flags = SDF_READABLE;
1084 s->n_chan = 1;
1085 s->maxdata = 0x00ffffff;
1086 s->insn_config = apci3120_timer_insn_config;
1087 s->insn_read = apci3120_timer_insn_read;
184 1088
185 apci3120_reset(dev);
186 return 0; 1089 return 0;
187} 1090}
188 1091
189static void apci3120_detach(struct comedi_device *dev) 1092static void apci3120_detach(struct comedi_device *dev)
190{ 1093{
191 struct addi_private *devpriv = dev->private;
192
193 if (dev->iobase)
194 apci3120_reset(dev);
195 comedi_pci_detach(dev); 1094 comedi_pci_detach(dev);
196 if (devpriv) { 1095 apci3120_dma_free(dev);
197 unsigned int i;
198
199 for (i = 0; i < 2; i++) {
200 if (devpriv->ul_DmaBufferVirtual[i]) {
201 dma_free_coherent(dev->hw_dev,
202 devpriv->ui_DmaBufferSize[i],
203 devpriv->
204 ul_DmaBufferVirtual[i],
205 devpriv->ul_DmaBufferHw[i]);
206 }
207 }
208 }
209} 1096}
210 1097
211static struct comedi_driver apci3120_driver = { 1098static struct comedi_driver apci3120_driver = {
diff --git a/drivers/staging/comedi/drivers/addi_apci_3200.c b/drivers/staging/comedi/drivers/addi_apci_3200.c
deleted file mode 100644
index fe6897eff3db..000000000000
--- a/drivers/staging/comedi/drivers/addi_apci_3200.c
+++ /dev/null
@@ -1,125 +0,0 @@
1#include <linux/module.h>
2#include <linux/pci.h>
3
4#include <asm/i387.h>
5
6#include "../comedidev.h"
7#include "comedi_fc.h"
8#include "amcc_s5933.h"
9
10#include "addi-data/addi_common.h"
11
12static void fpu_begin(void)
13{
14 kernel_fpu_begin();
15}
16
17static void fpu_end(void)
18{
19 kernel_fpu_end();
20}
21
22#include "addi-data/addi_eeprom.c"
23#include "addi-data/hwdrv_apci3200.c"
24#include "addi-data/addi_common.c"
25
26enum apci3200_boardid {
27 BOARD_APCI3200,
28 BOARD_APCI3300,
29};
30
31static const struct addi_board apci3200_boardtypes[] = {
32 [BOARD_APCI3200] = {
33 .pc_DriverName = "apci3200",
34 .i_IorangeBase1 = 256,
35 .i_PCIEeprom = 1,
36 .pc_EepromChip = "S5920",
37 .i_NbrAiChannel = 16,
38 .i_NbrAiChannelDiff = 8,
39 .i_AiChannelList = 16,
40 .i_AiMaxdata = 0x3ffff,
41 .pr_AiRangelist = &range_apci3200_ai,
42 .i_NbrDiChannel = 4,
43 .i_NbrDoChannel = 4,
44 .ui_MinAcquisitiontimeNs = 10000,
45 .ui_MinDelaytimeNs = 100000,
46 .interrupt = apci3200_interrupt,
47 .reset = apci3200_reset,
48 .ai_config = apci3200_ai_config,
49 .ai_read = apci3200_ai_read,
50 .ai_write = apci3200_ai_write,
51 .ai_bits = apci3200_ai_bits_test,
52 .ai_cmdtest = apci3200_ai_cmdtest,
53 .ai_cmd = apci3200_ai_cmd,
54 .ai_cancel = apci3200_cancel,
55 .di_bits = apci3200_di_insn_bits,
56 .do_bits = apci3200_do_insn_bits,
57 },
58 [BOARD_APCI3300] = {
59 .pc_DriverName = "apci3300",
60 .i_IorangeBase1 = 256,
61 .i_PCIEeprom = 1,
62 .pc_EepromChip = "S5920",
63 .i_NbrAiChannelDiff = 8,
64 .i_AiChannelList = 8,
65 .i_AiMaxdata = 0x3ffff,
66 .pr_AiRangelist = &range_apci3300_ai,
67 .i_NbrDiChannel = 4,
68 .i_NbrDoChannel = 4,
69 .ui_MinAcquisitiontimeNs = 10000,
70 .ui_MinDelaytimeNs = 100000,
71 .interrupt = apci3200_interrupt,
72 .reset = apci3200_reset,
73 .ai_config = apci3200_ai_config,
74 .ai_read = apci3200_ai_read,
75 .ai_write = apci3200_ai_write,
76 .ai_bits = apci3200_ai_bits_test,
77 .ai_cmdtest = apci3200_ai_cmdtest,
78 .ai_cmd = apci3200_ai_cmd,
79 .ai_cancel = apci3200_cancel,
80 .di_bits = apci3200_di_insn_bits,
81 .do_bits = apci3200_do_insn_bits,
82 },
83};
84
85static int apci3200_auto_attach(struct comedi_device *dev,
86 unsigned long context)
87{
88 const struct addi_board *board = NULL;
89
90 if (context < ARRAY_SIZE(apci3200_boardtypes))
91 board = &apci3200_boardtypes[context];
92 if (!board)
93 return -ENODEV;
94 dev->board_ptr = board;
95
96 return addi_auto_attach(dev, context);
97}
98
99static struct comedi_driver apci3200_driver = {
100 .driver_name = "addi_apci_3200",
101 .module = THIS_MODULE,
102 .auto_attach = apci3200_auto_attach,
103 .detach = i_ADDI_Detach,
104};
105
106static int apci3200_pci_probe(struct pci_dev *dev,
107 const struct pci_device_id *id)
108{
109 return comedi_pci_auto_config(dev, &apci3200_driver, id->driver_data);
110}
111
112static const struct pci_device_id apci3200_pci_table[] = {
113 { PCI_VDEVICE(ADDIDATA, 0x3000), BOARD_APCI3200 },
114 { PCI_VDEVICE(ADDIDATA, 0x3007), BOARD_APCI3300 },
115 { 0 }
116};
117MODULE_DEVICE_TABLE(pci, apci3200_pci_table);
118
119static struct pci_driver apci3200_pci_driver = {
120 .name = "addi_apci_3200",
121 .id_table = apci3200_pci_table,
122 .probe = apci3200_pci_probe,
123 .remove = comedi_pci_auto_unconfig,
124};
125module_comedi_pci_driver(apci3200_driver, apci3200_pci_driver);
diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c
index 010efa3fed6c..a726efcea6a5 100644
--- a/drivers/staging/comedi/drivers/addi_apci_3501.c
+++ b/drivers/staging/comedi/drivers/addi_apci_3501.c
@@ -357,12 +357,11 @@ static int apci3501_auto_attach(struct comedi_device *dev,
357 s = &dev->subdevices[0]; 357 s = &dev->subdevices[0];
358 if (ao_n_chan) { 358 if (ao_n_chan) {
359 s->type = COMEDI_SUBD_AO; 359 s->type = COMEDI_SUBD_AO;
360 s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; 360 s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON;
361 s->n_chan = ao_n_chan; 361 s->n_chan = ao_n_chan;
362 s->maxdata = 0x3fff; 362 s->maxdata = 0x3fff;
363 s->range_table = &apci3501_ao_range; 363 s->range_table = &apci3501_ao_range;
364 s->insn_write = apci3501_ao_insn_write; 364 s->insn_write = apci3501_ao_insn_write;
365 s->insn_read = comedi_readback_insn_read;
366 365
367 ret = comedi_alloc_subdev_readback(s); 366 ret = comedi_alloc_subdev_readback(s);
368 if (ret) 367 if (ret)
@@ -383,7 +382,7 @@ static int apci3501_auto_attach(struct comedi_device *dev,
383 /* Initialize the digital output subdevice */ 382 /* Initialize the digital output subdevice */
384 s = &dev->subdevices[2]; 383 s = &dev->subdevices[2];
385 s->type = COMEDI_SUBD_DO; 384 s->type = COMEDI_SUBD_DO;
386 s->subdev_flags = SDF_WRITEABLE; 385 s->subdev_flags = SDF_WRITABLE;
387 s->n_chan = 2; 386 s->n_chan = 2;
388 s->maxdata = 1; 387 s->maxdata = 1;
389 s->range_table = &range_digital; 388 s->range_table = &range_digital;
@@ -392,7 +391,7 @@ static int apci3501_auto_attach(struct comedi_device *dev,
392 /* Initialize the timer/watchdog subdevice */ 391 /* Initialize the timer/watchdog subdevice */
393 s = &dev->subdevices[3]; 392 s = &dev->subdevices[3];
394 s->type = COMEDI_SUBD_TIMER; 393 s->type = COMEDI_SUBD_TIMER;
395 s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; 394 s->subdev_flags = SDF_WRITABLE;
396 s->n_chan = 1; 395 s->n_chan = 1;
397 s->maxdata = 0; 396 s->maxdata = 0;
398 s->len_chanlist = 1; 397 s->len_chanlist = 1;
diff --git a/drivers/staging/comedi/drivers/addi_apci_3xxx.c b/drivers/staging/comedi/drivers/addi_apci_3xxx.c
index a296bd5b2c0c..c173810a3b5b 100644
--- a/drivers/staging/comedi/drivers/addi_apci_3xxx.c
+++ b/drivers/staging/comedi/drivers/addi_apci_3xxx.c
@@ -371,10 +371,10 @@ static irqreturn_t apci3xxx_irq_handler(int irq, void *d)
371 writel(status, dev->mmio + 16); 371 writel(status, dev->mmio + 16);
372 372
373 val = readl(dev->mmio + 28); 373 val = readl(dev->mmio + 28);
374 comedi_buf_put(s, val); 374 comedi_buf_write_samples(s, &val, 1);
375 375
376 s->async->events |= COMEDI_CB_EOA; 376 s->async->events |= COMEDI_CB_EOA;
377 comedi_event(dev, s); 377 comedi_handle_events(dev, s);
378 378
379 return IRQ_HANDLED; 379 return IRQ_HANDLED;
380 } 380 }
@@ -849,12 +849,11 @@ static int apci3xxx_auto_attach(struct comedi_device *dev,
849 if (board->has_ao) { 849 if (board->has_ao) {
850 s = &dev->subdevices[subdev]; 850 s = &dev->subdevices[subdev];
851 s->type = COMEDI_SUBD_AO; 851 s->type = COMEDI_SUBD_AO;
852 s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; 852 s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON;
853 s->n_chan = 4; 853 s->n_chan = 4;
854 s->maxdata = 0x0fff; 854 s->maxdata = 0x0fff;
855 s->range_table = &apci3xxx_ao_range; 855 s->range_table = &apci3xxx_ao_range;
856 s->insn_write = apci3xxx_ao_insn_write; 856 s->insn_write = apci3xxx_ao_insn_write;
857 s->insn_read = comedi_readback_insn_read;
858 857
859 ret = comedi_alloc_subdev_readback(s); 858 ret = comedi_alloc_subdev_readback(s);
860 if (ret) 859 if (ret)
@@ -880,7 +879,7 @@ static int apci3xxx_auto_attach(struct comedi_device *dev,
880 if (board->has_dig_out) { 879 if (board->has_dig_out) {
881 s = &dev->subdevices[subdev]; 880 s = &dev->subdevices[subdev];
882 s->type = COMEDI_SUBD_DO; 881 s->type = COMEDI_SUBD_DO;
883 s->subdev_flags = SDF_WRITEABLE; 882 s->subdev_flags = SDF_WRITABLE;
884 s->n_chan = 4; 883 s->n_chan = 4;
885 s->maxdata = 1; 884 s->maxdata = 1;
886 s->range_table = &range_digital; 885 s->range_table = &range_digital;
@@ -893,7 +892,7 @@ static int apci3xxx_auto_attach(struct comedi_device *dev,
893 if (board->has_ttl_io) { 892 if (board->has_ttl_io) {
894 s = &dev->subdevices[subdev]; 893 s = &dev->subdevices[subdev];
895 s->type = COMEDI_SUBD_DIO; 894 s->type = COMEDI_SUBD_DIO;
896 s->subdev_flags = SDF_READABLE | SDF_WRITEABLE; 895 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
897 s->n_chan = 24; 896 s->n_chan = 24;
898 s->maxdata = 1; 897 s->maxdata = 1;
899 s->io_bits = 0xff; /* channels 0-7 are always outputs */ 898 s->io_bits = 0xff; /* channels 0-7 are always outputs */
diff --git a/drivers/staging/comedi/drivers/addi_tcw.h b/drivers/staging/comedi/drivers/addi_tcw.h
new file mode 100644
index 000000000000..8794d4cbbfb0
--- /dev/null
+++ b/drivers/staging/comedi/drivers/addi_tcw.h
@@ -0,0 +1,56 @@
1#ifndef _ADDI_TCW_H
2#define _ADDI_TCW_H
3
4/*
5 * Following are the generic definitions for the ADDI-DATA timer/counter/
6 * watchdog (TCW) registers and bits. Some of the registers are not used
7 * depending on the use of the TCW.
8 */
9
10#define ADDI_TCW_VAL_REG 0x00
11
12#define ADDI_TCW_SYNC_REG 0x00
13#define ADDI_TCW_SYNC_CTR_TRIG (1 << 8)
14#define ADDI_TCW_SYNC_CTR_DIS (1 << 7)
15#define ADDI_TCW_SYNC_CTR_ENA (1 << 6)
16#define ADDI_TCW_SYNC_TIMER_TRIG (1 << 5)
17#define ADDI_TCW_SYNC_TIMER_DIS (1 << 4)
18#define ADDI_TCW_SYNC_TIMER_ENA (1 << 3)
19#define ADDI_TCW_SYNC_WDOG_TRIG (1 << 2)
20#define ADDI_TCW_SYNC_WDOG_DIS (1 << 1)
21#define ADDI_TCW_SYNC_WDOG_ENA (1 << 0)
22
23#define ADDI_TCW_RELOAD_REG 0x04
24
25#define ADDI_TCW_TIMEBASE_REG 0x08
26
27#define ADDI_TCW_CTRL_REG 0x0c
28#define ADDI_TCW_CTRL_EXT_CLK_STATUS (1 << 21)
29#define ADDI_TCW_CTRL_CASCADE (1 << 20)
30#define ADDI_TCW_CTRL_CNTR_ENA (1 << 19)
31#define ADDI_TCW_CTRL_CNT_UP (1 << 18)
32#define ADDI_TCW_CTRL_EXT_CLK(x) ((x) << 16)
33#define ADDI_TCW_CTRL_OUT(x) ((x) << 11)
34#define ADDI_TCW_CTRL_GATE (1 << 10)
35#define ADDI_TCW_CTRL_TRIG (1 << 9)
36#define ADDI_TCW_CTRL_EXT_GATE(x) ((x) << 7)
37#define ADDI_TCW_CTRL_EXT_TRIG(x) ((x) << 5)
38#define ADDI_TCW_CTRL_TIMER_ENA (1 << 4)
39#define ADDI_TCW_CTRL_RESET_ENA (1 << 3)
40#define ADDI_TCW_CTRL_WARN_ENA (1 << 2)
41#define ADDI_TCW_CTRL_IRQ_ENA (1 << 1)
42#define ADDI_TCW_CTRL_ENA (1 << 0)
43
44#define ADDI_TCW_STATUS_REG 0x10
45#define ADDI_TCW_STATUS_SOFT_CLR (1 << 3)
46#define ADDI_TCW_STATUS_SOFT_TRIG (1 << 1)
47#define ADDI_TCW_STATUS_OVERFLOW (1 << 0)
48
49#define ADDI_TCW_IRQ_REG 0x14
50#define ADDI_TCW_IRQ (1 << 0)
51
52#define ADDI_TCW_WARN_TIMEVAL_REG 0x18
53
54#define ADDI_TCW_WARN_TIMEBASE_REG 0x1c
55
56#endif
diff --git a/drivers/staging/comedi/drivers/addi_watchdog.c b/drivers/staging/comedi/drivers/addi_watchdog.c
index 23031feaa095..c5b082d4e51e 100644
--- a/drivers/staging/comedi/drivers/addi_watchdog.c
+++ b/drivers/staging/comedi/drivers/addi_watchdog.c
@@ -20,21 +20,9 @@
20 20
21#include <linux/module.h> 21#include <linux/module.h>
22#include "../comedidev.h" 22#include "../comedidev.h"
23#include "addi_tcw.h"
23#include "addi_watchdog.h" 24#include "addi_watchdog.h"
24 25
25/*
26 * Register offsets/defines for the addi-data watchdog
27 */
28#define ADDI_WDOG_REG 0x00
29#define ADDI_WDOG_RELOAD_REG 0x04
30#define ADDI_WDOG_TIMEBASE 0x08
31#define ADDI_WDOG_CTRL_REG 0x0c
32#define ADDI_WDOG_CTRL_ENABLE (1 << 0)
33#define ADDI_WDOG_CTRL_SW_TRIG (1 << 9)
34#define ADDI_WDOG_STATUS_REG 0x10
35#define ADDI_WDOG_STATUS_ENABLED (1 << 0)
36#define ADDI_WDOG_STATUS_SW_TRIG (1 << 1)
37
38struct addi_watchdog_private { 26struct addi_watchdog_private {
39 unsigned long iobase; 27 unsigned long iobase;
40 unsigned int wdog_ctrl; 28 unsigned int wdog_ctrl;
@@ -60,9 +48,9 @@ static int addi_watchdog_insn_config(struct comedi_device *dev,
60 48
61 switch (data[0]) { 49 switch (data[0]) {
62 case INSN_CONFIG_ARM: 50 case INSN_CONFIG_ARM:
63 spriv->wdog_ctrl = ADDI_WDOG_CTRL_ENABLE; 51 spriv->wdog_ctrl = ADDI_TCW_CTRL_ENA;
64 reload = data[1] & s->maxdata; 52 reload = data[1] & s->maxdata;
65 outl(reload, spriv->iobase + ADDI_WDOG_RELOAD_REG); 53 outl(reload, spriv->iobase + ADDI_TCW_RELOAD_REG);
66 54
67 /* Time base is 20ms, let the user know the timeout */ 55 /* Time base is 20ms, let the user know the timeout */
68 dev_info(dev->class_dev, "watchdog enabled, timeout:%dms\n", 56 dev_info(dev->class_dev, "watchdog enabled, timeout:%dms\n",
@@ -75,7 +63,7 @@ static int addi_watchdog_insn_config(struct comedi_device *dev,
75 return -EINVAL; 63 return -EINVAL;
76 } 64 }
77 65
78 outl(spriv->wdog_ctrl, spriv->iobase + ADDI_WDOG_CTRL_REG); 66 outl(spriv->wdog_ctrl, spriv->iobase + ADDI_TCW_CTRL_REG);
79 67
80 return insn->n; 68 return insn->n;
81} 69}
@@ -89,7 +77,7 @@ static int addi_watchdog_insn_read(struct comedi_device *dev,
89 int i; 77 int i;
90 78
91 for (i = 0; i < insn->n; i++) 79 for (i = 0; i < insn->n; i++)
92 data[i] = inl(spriv->iobase + ADDI_WDOG_STATUS_REG); 80 data[i] = inl(spriv->iobase + ADDI_TCW_STATUS_REG);
93 81
94 return insn->n; 82 return insn->n;
95} 83}
@@ -109,8 +97,8 @@ static int addi_watchdog_insn_write(struct comedi_device *dev,
109 97
110 /* "ping" the watchdog */ 98 /* "ping" the watchdog */
111 for (i = 0; i < insn->n; i++) { 99 for (i = 0; i < insn->n; i++) {
112 outl(spriv->wdog_ctrl | ADDI_WDOG_CTRL_SW_TRIG, 100 outl(spriv->wdog_ctrl | ADDI_TCW_CTRL_TRIG,
113 spriv->iobase + ADDI_WDOG_CTRL_REG); 101 spriv->iobase + ADDI_TCW_CTRL_REG);
114 } 102 }
115 103
116 return insn->n; 104 return insn->n;
@@ -118,8 +106,8 @@ static int addi_watchdog_insn_write(struct comedi_device *dev,
118 106
119void addi_watchdog_reset(unsigned long iobase) 107void addi_watchdog_reset(unsigned long iobase)
120{ 108{
121 outl(0x0, iobase + ADDI_WDOG_CTRL_REG); 109 outl(0x0, iobase + ADDI_TCW_CTRL_REG);
122 outl(0x0, iobase + ADDI_WDOG_RELOAD_REG); 110 outl(0x0, iobase + ADDI_TCW_RELOAD_REG);
123} 111}
124EXPORT_SYMBOL_GPL(addi_watchdog_reset); 112EXPORT_SYMBOL_GPL(addi_watchdog_reset);
125 113
@@ -134,7 +122,7 @@ int addi_watchdog_init(struct comedi_subdevice *s, unsigned long iobase)
134 spriv->iobase = iobase; 122 spriv->iobase = iobase;
135 123
136 s->type = COMEDI_SUBD_TIMER; 124 s->type = COMEDI_SUBD_TIMER;
137 s->subdev_flags = SDF_WRITEABLE; 125 s->subdev_flags = SDF_WRITABLE;
138 s->n_chan = 1; 126 s->n_chan = 1;
139 s->maxdata = 0xff; 127 s->maxdata = 0xff;
140 s->insn_config = addi_watchdog_insn_config; 128 s->insn_config = addi_watchdog_insn_config;
diff --git a/drivers/staging/comedi/drivers/adl_pci6208.c b/drivers/staging/comedi/drivers/adl_pci6208.c
index 0ad46fe492c9..528f15c25dae 100644
--- a/drivers/staging/comedi/drivers/adl_pci6208.c
+++ b/drivers/staging/comedi/drivers/adl_pci6208.c
@@ -169,7 +169,6 @@ static int pci6208_auto_attach(struct comedi_device *dev,
169 s->maxdata = 0xffff; 169 s->maxdata = 0xffff;
170 s->range_table = &range_bipolar10; 170 s->range_table = &range_bipolar10;
171 s->insn_write = pci6208_ao_insn_write; 171 s->insn_write = pci6208_ao_insn_write;
172 s->insn_read = comedi_readback_insn_read;
173 172
174 ret = comedi_alloc_subdev_readback(s); 173 ret = comedi_alloc_subdev_readback(s);
175 if (ret) 174 if (ret)
diff --git a/drivers/staging/comedi/drivers/adl_pci9111.c b/drivers/staging/comedi/drivers/adl_pci9111.c
index d18d8f21af23..47f6c0e9f014 100644
--- a/drivers/staging/comedi/drivers/adl_pci9111.c
+++ b/drivers/staging/comedi/drivers/adl_pci9111.c
@@ -133,8 +133,6 @@ static const struct comedi_lrange pci9111_ai_range = {
133struct pci9111_private_data { 133struct pci9111_private_data {
134 unsigned long lcr_io_base; 134 unsigned long lcr_io_base;
135 135
136 int stop_counter;
137
138 unsigned int scan_delay; 136 unsigned int scan_delay;
139 unsigned int chunk_counter; 137 unsigned int chunk_counter;
140 unsigned int chunk_num_samples; 138 unsigned int chunk_num_samples;
@@ -404,12 +402,6 @@ static int pci9111_ai_do_cmd(struct comedi_device *dev,
404 outb(CR_RANGE(cmd->chanlist[0]) & PCI9111_AI_RANGE_MASK, 402 outb(CR_RANGE(cmd->chanlist[0]) & PCI9111_AI_RANGE_MASK,
405 dev->iobase + PCI9111_AI_RANGE_STAT_REG); 403 dev->iobase + PCI9111_AI_RANGE_STAT_REG);
406 404
407 /* Set counter */
408 if (cmd->stop_src == TRIG_COUNT)
409 dev_private->stop_counter = cmd->stop_arg * cmd->chanlist_len;
410 else /* TRIG_NONE */
411 dev_private->stop_counter = 0;
412
413 /* Set timer pacer */ 405 /* Set timer pacer */
414 dev_private->scan_delay = 0; 406 dev_private->scan_delay = 0;
415 if (cmd->convert_src == TRIG_TIMER) { 407 if (cmd->convert_src == TRIG_TIMER) {
@@ -435,7 +427,6 @@ static int pci9111_ai_do_cmd(struct comedi_device *dev,
435 } 427 }
436 outb(trig, dev->iobase + PCI9111_AI_TRIG_CTRL_REG); 428 outb(trig, dev->iobase + PCI9111_AI_TRIG_CTRL_REG);
437 429
438 dev_private->stop_counter *= (1 + dev_private->scan_delay);
439 dev_private->chunk_counter = 0; 430 dev_private->chunk_counter = 0;
440 dev_private->chunk_num_samples = cmd->chanlist_len * 431 dev_private->chunk_num_samples = cmd->chanlist_len *
441 (1 + dev_private->scan_delay); 432 (1 + dev_private->scan_delay);
@@ -452,7 +443,7 @@ static void pci9111_ai_munge(struct comedi_device *dev,
452 unsigned int maxdata = s->maxdata; 443 unsigned int maxdata = s->maxdata;
453 unsigned int invert = (maxdata + 1) >> 1; 444 unsigned int invert = (maxdata + 1) >> 1;
454 unsigned int shift = (maxdata == 0xffff) ? 0 : 4; 445 unsigned int shift = (maxdata == 0xffff) ? 0 : 4;
455 unsigned int num_samples = num_bytes / sizeof(short); 446 unsigned int num_samples = comedi_bytes_to_samples(s, num_bytes);
456 unsigned int i; 447 unsigned int i;
457 448
458 for (i = 0; i < num_samples; i++) 449 for (i = 0; i < num_samples; i++)
@@ -464,22 +455,14 @@ static void pci9111_handle_fifo_half_full(struct comedi_device *dev,
464{ 455{
465 struct pci9111_private_data *devpriv = dev->private; 456 struct pci9111_private_data *devpriv = dev->private;
466 struct comedi_cmd *cmd = &s->async->cmd; 457 struct comedi_cmd *cmd = &s->async->cmd;
467 unsigned int total = 0;
468 unsigned int samples; 458 unsigned int samples;
469 459
470 if (cmd->stop_src == TRIG_COUNT && 460 samples = comedi_nsamples_left(s, PCI9111_FIFO_HALF_SIZE);
471 PCI9111_FIFO_HALF_SIZE > devpriv->stop_counter)
472 samples = devpriv->stop_counter;
473 else
474 samples = PCI9111_FIFO_HALF_SIZE;
475
476 insw(dev->iobase + PCI9111_AI_FIFO_REG, 461 insw(dev->iobase + PCI9111_AI_FIFO_REG,
477 devpriv->ai_bounce_buffer, samples); 462 devpriv->ai_bounce_buffer, samples);
478 463
479 if (devpriv->scan_delay < 1) { 464 if (devpriv->scan_delay < 1) {
480 total = cfc_write_array_to_buffer(s, 465 comedi_buf_write_samples(s, devpriv->ai_bounce_buffer, samples);
481 devpriv->ai_bounce_buffer,
482 samples * sizeof(short));
483 } else { 466 } else {
484 unsigned int pos = 0; 467 unsigned int pos = 0;
485 unsigned int to_read; 468 unsigned int to_read;
@@ -492,17 +475,15 @@ static void pci9111_handle_fifo_half_full(struct comedi_device *dev,
492 if (to_read > samples - pos) 475 if (to_read > samples - pos)
493 to_read = samples - pos; 476 to_read = samples - pos;
494 477
495 total += cfc_write_array_to_buffer(s, 478 comedi_buf_write_samples(s,
496 devpriv->ai_bounce_buffer + pos, 479 devpriv->ai_bounce_buffer + pos,
497 to_read * sizeof(short)); 480 to_read);
498 } else { 481 } else {
499 to_read = devpriv->chunk_num_samples - 482 to_read = devpriv->chunk_num_samples -
500 devpriv->chunk_counter; 483 devpriv->chunk_counter;
501 484
502 if (to_read > samples - pos) 485 if (to_read > samples - pos)
503 to_read = samples - pos; 486 to_read = samples - pos;
504
505 total += to_read * sizeof(short);
506 } 487 }
507 488
508 pos += to_read; 489 pos += to_read;
@@ -513,8 +494,6 @@ static void pci9111_handle_fifo_half_full(struct comedi_device *dev,
513 devpriv->chunk_counter = 0; 494 devpriv->chunk_counter = 0;
514 } 495 }
515 } 496 }
516
517 devpriv->stop_counter -= total / sizeof(short);
518} 497}
519 498
520static irqreturn_t pci9111_interrupt(int irq, void *p_device) 499static irqreturn_t pci9111_interrupt(int irq, void *p_device)
@@ -561,7 +540,7 @@ static irqreturn_t pci9111_interrupt(int irq, void *p_device)
561 dev_dbg(dev->class_dev, "fifo overflow\n"); 540 dev_dbg(dev->class_dev, "fifo overflow\n");
562 outb(0, dev->iobase + PCI9111_INT_CLR_REG); 541 outb(0, dev->iobase + PCI9111_INT_CLR_REG);
563 async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; 542 async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA;
564 cfc_handle_events(dev, s); 543 comedi_handle_events(dev, s);
565 544
566 return IRQ_HANDLED; 545 return IRQ_HANDLED;
567 } 546 }
@@ -571,14 +550,14 @@ static irqreturn_t pci9111_interrupt(int irq, void *p_device)
571 pci9111_handle_fifo_half_full(dev, s); 550 pci9111_handle_fifo_half_full(dev, s);
572 } 551 }
573 552
574 if (cmd->stop_src == TRIG_COUNT && dev_private->stop_counter == 0) 553 if (cmd->stop_src == TRIG_COUNT && async->scans_done >= cmd->stop_arg)
575 async->events |= COMEDI_CB_EOA; 554 async->events |= COMEDI_CB_EOA;
576 555
577 outb(0, dev->iobase + PCI9111_INT_CLR_REG); 556 outb(0, dev->iobase + PCI9111_INT_CLR_REG);
578 557
579 spin_unlock_irqrestore(&dev->spinlock, irq_flags); 558 spin_unlock_irqrestore(&dev->spinlock, irq_flags);
580 559
581 cfc_handle_events(dev, s); 560 comedi_handle_events(dev, s);
582 561
583 return IRQ_HANDLED; 562 return IRQ_HANDLED;
584} 563}
@@ -752,7 +731,6 @@ static int pci9111_auto_attach(struct comedi_device *dev,
752 s->len_chanlist = 1; 731 s->len_chanlist = 1;
753 s->range_table = &range_bipolar10; 732 s->range_table = &range_bipolar10;
754 s->insn_write = pci9111_ao_insn_write; 733 s->insn_write = pci9111_ao_insn_write;
755 s->insn_read = comedi_readback_insn_read;
756 734
757 ret = comedi_alloc_subdev_readback(s); 735 ret = comedi_alloc_subdev_readback(s);
758 if (ret) 736 if (ret)
@@ -768,7 +746,7 @@ static int pci9111_auto_attach(struct comedi_device *dev,
768 746
769 s = &dev->subdevices[3]; 747 s = &dev->subdevices[3];
770 s->type = COMEDI_SUBD_DO; 748 s->type = COMEDI_SUBD_DO;
771 s->subdev_flags = SDF_READABLE | SDF_WRITABLE; 749 s->subdev_flags = SDF_WRITABLE;
772 s->n_chan = 16; 750 s->n_chan = 16;
773 s->maxdata = 1; 751 s->maxdata = 1;
774 s->range_table = &range_digital; 752 s->range_table = &range_digital;
diff --git a/drivers/staging/comedi/drivers/adl_pci9118.c b/drivers/staging/comedi/drivers/adl_pci9118.c
index e18fd9569a2b..26603582e71a 100644
--- a/drivers/staging/comedi/drivers/adl_pci9118.c
+++ b/drivers/staging/comedi/drivers/adl_pci9118.c
@@ -221,7 +221,6 @@ struct pci9118_private {
221 unsigned char int_ctrl; 221 unsigned char int_ctrl;
222 unsigned char ai_cfg; 222 unsigned char ai_cfg;
223 unsigned int ai_do; /* what do AI? 0=nothing, 1 to 4 mode */ 223 unsigned int ai_do; /* what do AI? 0=nothing, 1 to 4 mode */
224 unsigned int ai_act_scan; /* how many scans we finished */
225 unsigned int ai_n_realscanlen; /* 224 unsigned int ai_n_realscanlen; /*
226 * what we must transfer for one 225 * what we must transfer for one
227 * outgoing scan include front/back adds 226 * outgoing scan include front/back adds
@@ -447,51 +446,112 @@ static void interrupt_pci9118_ai_mode4_switch(struct comedi_device *dev,
447 outl(devpriv->ai_cfg, dev->iobase + PCI9118_AI_CFG_REG); 446 outl(devpriv->ai_cfg, dev->iobase + PCI9118_AI_CFG_REG);
448} 447}
449 448
450static unsigned int defragment_dma_buffer(struct comedi_device *dev, 449static unsigned int valid_samples_in_act_dma_buf(struct comedi_device *dev,
451 struct comedi_subdevice *s, 450 struct comedi_subdevice *s,
452 unsigned short *dma_buffer, 451 unsigned int n_raw_samples)
453 unsigned int num_samples)
454{ 452{
455 struct pci9118_private *devpriv = dev->private; 453 struct pci9118_private *devpriv = dev->private;
456 struct comedi_cmd *cmd = &s->async->cmd; 454 struct comedi_cmd *cmd = &s->async->cmd;
457 unsigned int i = 0, j = 0; 455 unsigned int start_pos = devpriv->ai_add_front;
458 unsigned int start_pos = devpriv->ai_add_front, 456 unsigned int stop_pos = start_pos + cmd->chanlist_len;
459 stop_pos = devpriv->ai_add_front + cmd->chanlist_len; 457 unsigned int span_len = stop_pos + devpriv->ai_add_back;
460 unsigned int raw_scanlen = devpriv->ai_add_front + cmd->chanlist_len + 458 unsigned int dma_pos = devpriv->ai_act_dmapos;
461 devpriv->ai_add_back; 459 unsigned int whole_spans, n_samples, x;
462 460
463 for (i = 0; i < num_samples; i++) { 461 if (span_len == cmd->chanlist_len)
464 if (devpriv->ai_act_dmapos >= start_pos && 462 return n_raw_samples; /* use all samples */
465 devpriv->ai_act_dmapos < stop_pos) { 463
466 dma_buffer[j++] = dma_buffer[i]; 464 /*
465 * Not all samples are to be used. Buffer contents consist of a
466 * possibly non-whole number of spans and a region of each span
467 * is to be used.
468 *
469 * Account for samples in whole number of spans.
470 */
471 whole_spans = n_raw_samples / span_len;
472 n_samples = whole_spans * cmd->chanlist_len;
473 n_raw_samples -= whole_spans * span_len;
474
475 /*
476 * Deal with remaining samples which could overlap up to two spans.
477 */
478 while (n_raw_samples) {
479 if (dma_pos < start_pos) {
480 /* Skip samples before start position. */
481 x = start_pos - dma_pos;
482 if (x > n_raw_samples)
483 x = n_raw_samples;
484 dma_pos += x;
485 n_raw_samples -= x;
486 if (!n_raw_samples)
487 break;
467 } 488 }
468 devpriv->ai_act_dmapos++; 489 if (dma_pos < stop_pos) {
469 devpriv->ai_act_dmapos %= raw_scanlen; 490 /* Include samples before stop position. */
491 x = stop_pos - dma_pos;
492 if (x > n_raw_samples)
493 x = n_raw_samples;
494 n_samples += x;
495 dma_pos += x;
496 n_raw_samples -= x;
497 }
498 /* Advance to next span. */
499 start_pos += span_len;
500 stop_pos += span_len;
470 } 501 }
471 502 return n_samples;
472 return j;
473} 503}
474 504
475static int move_block_from_dma(struct comedi_device *dev, 505static void move_block_from_dma(struct comedi_device *dev,
476 struct comedi_subdevice *s, 506 struct comedi_subdevice *s,
477 unsigned short *dma_buffer, 507 unsigned short *dma_buffer,
478 unsigned int num_samples) 508 unsigned int n_raw_samples)
479{ 509{
480 struct pci9118_private *devpriv = dev->private; 510 struct pci9118_private *devpriv = dev->private;
481 struct comedi_cmd *cmd = &s->async->cmd; 511 struct comedi_cmd *cmd = &s->async->cmd;
482 unsigned int num_bytes; 512 unsigned int start_pos = devpriv->ai_add_front;
483 513 unsigned int stop_pos = start_pos + cmd->chanlist_len;
484 num_samples = defragment_dma_buffer(dev, s, dma_buffer, num_samples); 514 unsigned int span_len = stop_pos + devpriv->ai_add_back;
485 devpriv->ai_act_scan += 515 unsigned int dma_pos = devpriv->ai_act_dmapos;
486 (s->async->cur_chan + num_samples) / cmd->scan_end_arg; 516 unsigned int x;
487 s->async->cur_chan += num_samples; 517
488 s->async->cur_chan %= cmd->scan_end_arg; 518 if (span_len == cmd->chanlist_len) {
489 num_bytes = 519 /* All samples are to be copied. */
490 cfc_write_array_to_buffer(s, dma_buffer, 520 comedi_buf_write_samples(s, dma_buffer, n_raw_samples);
491 num_samples * sizeof(short)); 521 dma_pos += n_raw_samples;
492 if (num_bytes < num_samples * sizeof(short)) 522 } else {
493 return -1; 523 /*
494 return 0; 524 * Not all samples are to be copied. Buffer contents consist
525 * of a possibly non-whole number of spans and a region of
526 * each span is to be copied.
527 */
528 while (n_raw_samples) {
529 if (dma_pos < start_pos) {
530 /* Skip samples before start position. */
531 x = start_pos - dma_pos;
532 if (x > n_raw_samples)
533 x = n_raw_samples;
534 dma_pos += x;
535 n_raw_samples -= x;
536 if (!n_raw_samples)
537 break;
538 }
539 if (dma_pos < stop_pos) {
540 /* Copy samples before stop position. */
541 x = stop_pos - dma_pos;
542 if (x > n_raw_samples)
543 x = n_raw_samples;
544 comedi_buf_write_samples(s, dma_buffer, x);
545 dma_pos += x;
546 n_raw_samples -= x;
547 }
548 /* Advance to next span. */
549 start_pos += span_len;
550 stop_pos += span_len;
551 }
552 }
553 /* Update position in span for next time. */
554 devpriv->ai_act_dmapos = dma_pos % span_len;
495} 555}
496 556
497static void pci9118_exttrg_enable(struct comedi_device *dev, bool enable) 557static void pci9118_exttrg_enable(struct comedi_device *dev, bool enable)
@@ -578,9 +638,7 @@ static int pci9118_ai_cancel(struct comedi_device *dev,
578 devpriv->ai_do = 0; 638 devpriv->ai_do = 0;
579 devpriv->usedma = 0; 639 devpriv->usedma = 0;
580 640
581 devpriv->ai_act_scan = 0;
582 devpriv->ai_act_dmapos = 0; 641 devpriv->ai_act_dmapos = 0;
583 s->async->cur_chan = 0;
584 s->async->inttrig = NULL; 642 s->async->inttrig = NULL;
585 devpriv->ai_neverending = 0; 643 devpriv->ai_neverending = 0;
586 devpriv->dma_actbuf = 0; 644 devpriv->dma_actbuf = 0;
@@ -594,8 +652,9 @@ static void pci9118_ai_munge(struct comedi_device *dev,
594 unsigned int start_chan_index) 652 unsigned int start_chan_index)
595{ 653{
596 struct pci9118_private *devpriv = dev->private; 654 struct pci9118_private *devpriv = dev->private;
597 unsigned int i, num_samples = num_bytes / sizeof(short);
598 unsigned short *array = data; 655 unsigned short *array = data;
656 unsigned int num_samples = comedi_bytes_to_samples(s, num_bytes);
657 unsigned int i;
599 658
600 for (i = 0; i < num_samples; i++) { 659 for (i = 0; i < num_samples; i++) {
601 if (devpriv->usedma) 660 if (devpriv->usedma)
@@ -617,17 +676,11 @@ static void interrupt_pci9118_ai_onesample(struct comedi_device *dev,
617 676
618 sampl = inl(dev->iobase + PCI9118_AI_FIFO_REG); 677 sampl = inl(dev->iobase + PCI9118_AI_FIFO_REG);
619 678
620 cfc_write_to_buffer(s, sampl); 679 comedi_buf_write_samples(s, &sampl, 1);
621 s->async->cur_chan++; 680
622 if (s->async->cur_chan >= cmd->scan_end_arg) { 681 if (!devpriv->ai_neverending) {
623 /* one scan done */ 682 if (s->async->scans_done >= cmd->stop_arg)
624 s->async->cur_chan %= cmd->scan_end_arg; 683 s->async->events |= COMEDI_CB_EOA;
625 devpriv->ai_act_scan++;
626 if (!devpriv->ai_neverending) {
627 /* all data sampled? */
628 if (devpriv->ai_act_scan >= cmd->stop_arg)
629 s->async->events |= COMEDI_CB_EOA;
630 }
631 } 684 }
632} 685}
633 686
@@ -637,39 +690,37 @@ static void interrupt_pci9118_ai_dma(struct comedi_device *dev,
637 struct pci9118_private *devpriv = dev->private; 690 struct pci9118_private *devpriv = dev->private;
638 struct comedi_cmd *cmd = &s->async->cmd; 691 struct comedi_cmd *cmd = &s->async->cmd;
639 struct pci9118_dmabuf *dmabuf = &devpriv->dmabuf[devpriv->dma_actbuf]; 692 struct pci9118_dmabuf *dmabuf = &devpriv->dmabuf[devpriv->dma_actbuf];
640 unsigned int next_dma_buf, samplesinbuf, sampls, m; 693 unsigned int n_all = comedi_bytes_to_samples(s, dmabuf->use_size);
694 unsigned int n_valid;
695 bool more_dma;
641 696
642 samplesinbuf = dmabuf->use_size >> 1; /* number of received samples */ 697 /* determine whether more DMA buffers to do after this one */
698 n_valid = valid_samples_in_act_dma_buf(dev, s, n_all);
699 more_dma = n_valid < comedi_nsamples_left(s, n_valid + 1);
643 700
644 if (devpriv->dma_doublebuf) { /* 701 /* switch DMA buffers and restart DMA if double buffering */
645 * switch DMA buffers if is used 702 if (more_dma && devpriv->dma_doublebuf) {
646 * double buffering 703 devpriv->dma_actbuf = 1 - devpriv->dma_actbuf;
647 */ 704 pci9118_amcc_setup_dma(dev, devpriv->dma_actbuf);
648 next_dma_buf = 1 - devpriv->dma_actbuf; 705 if (devpriv->ai_do == 4) {
649 pci9118_amcc_setup_dma(dev, next_dma_buf); 706 interrupt_pci9118_ai_mode4_switch(dev,
650 if (devpriv->ai_do == 4) 707 devpriv->dma_actbuf);
651 interrupt_pci9118_ai_mode4_switch(dev, next_dma_buf); 708 }
652 } 709 }
653 710
654 if (samplesinbuf) { 711 if (n_all)
655 /* how many samples is to end of buffer */ 712 move_block_from_dma(dev, s, dmabuf->virt, n_all);
656 m = s->async->prealloc_bufsz >> 1;
657 sampls = m;
658 move_block_from_dma(dev, s, dmabuf->virt, samplesinbuf);
659 m = m - sampls; /* m=how many samples was transferred */
660 }
661 713
662 if (!devpriv->ai_neverending) { 714 if (!devpriv->ai_neverending) {
663 /* all data sampled? */ 715 if (s->async->scans_done >= cmd->stop_arg)
664 if (devpriv->ai_act_scan >= cmd->stop_arg)
665 s->async->events |= COMEDI_CB_EOA; 716 s->async->events |= COMEDI_CB_EOA;
666 } 717 }
667 718
668 if (devpriv->dma_doublebuf) { 719 if (s->async->events & COMEDI_CB_CANCEL_MASK)
669 /* switch dma buffers */ 720 more_dma = false;
670 devpriv->dma_actbuf = 1 - devpriv->dma_actbuf; 721
671 } else { 722 /* restart DMA if not double buffering */
672 /* restart DMA if is not used double buffering */ 723 if (more_dma && !devpriv->dma_doublebuf) {
673 pci9118_amcc_setup_dma(dev, 0); 724 pci9118_amcc_setup_dma(dev, 0);
674 if (devpriv->ai_do == 4) 725 if (devpriv->ai_do == 4)
675 interrupt_pci9118_ai_mode4_switch(dev, 0); 726 interrupt_pci9118_ai_mode4_switch(dev, 0);
@@ -766,7 +817,7 @@ static irqreturn_t pci9118_interrupt(int irq, void *d)
766 interrupt_pci9118_ai_onesample(dev, s); 817 interrupt_pci9118_ai_onesample(dev, s);
767 818
768interrupt_exit: 819interrupt_exit:
769 cfc_handle_events(dev, s); 820 comedi_handle_events(dev, s);
770 return IRQ_HANDLED; 821 return IRQ_HANDLED;
771} 822}
772 823
@@ -1123,9 +1174,7 @@ static int pci9118_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
1123 inl(dev->iobase + PCI9118_AI_STATUS_REG); 1174 inl(dev->iobase + PCI9118_AI_STATUS_REG);
1124 inl(dev->iobase + PCI9118_INT_CTRL_REG); 1175 inl(dev->iobase + PCI9118_INT_CTRL_REG);
1125 1176
1126 devpriv->ai_act_scan = 0;
1127 devpriv->ai_act_dmapos = 0; 1177 devpriv->ai_act_dmapos = 0;
1128 s->async->cur_chan = 0;
1129 1178
1130 if (devpriv->usedma) { 1179 if (devpriv->usedma) {
1131 Compute_and_setup_dma(dev, s); 1180 Compute_and_setup_dma(dev, s);
@@ -1624,7 +1673,6 @@ static int pci9118_common_attach(struct comedi_device *dev,
1624 s->maxdata = 0x0fff; 1673 s->maxdata = 0x0fff;
1625 s->range_table = &range_bipolar10; 1674 s->range_table = &range_bipolar10;
1626 s->insn_write = pci9118_ao_insn_write; 1675 s->insn_write = pci9118_ao_insn_write;
1627 s->insn_read = comedi_readback_insn_read;
1628 1676
1629 ret = comedi_alloc_subdev_readback(s); 1677 ret = comedi_alloc_subdev_readback(s);
1630 if (ret) 1678 if (ret)
diff --git a/drivers/staging/comedi/drivers/adv_pci1710.c b/drivers/staging/comedi/drivers/adv_pci1710.c
index 5539bd294862..d02df7d0c629 100644
--- a/drivers/staging/comedi/drivers/adv_pci1710.c
+++ b/drivers/staging/comedi/drivers/adv_pci1710.c
@@ -298,7 +298,6 @@ static const struct boardtype boardtypes[] = {
298 298
299struct pci1710_private { 299struct pci1710_private {
300 unsigned int CntrlReg; /* Control register */ 300 unsigned int CntrlReg; /* Control register */
301 unsigned int ai_act_scan; /* how many scans we finished */
302 unsigned char ai_et; 301 unsigned char ai_et;
303 unsigned int ai_et_CntrlReg; 302 unsigned int ai_et_CntrlReg;
304 unsigned int ai_et_MuxVal; 303 unsigned int ai_et_MuxVal;
@@ -730,16 +729,12 @@ static int pci171x_ai_cancel(struct comedi_device *dev,
730 break; 729 break;
731 } 730 }
732 731
733 devpriv->ai_act_scan = 0;
734 s->async->cur_chan = 0;
735
736 return 0; 732 return 0;
737} 733}
738 734
739static void pci1710_handle_every_sample(struct comedi_device *dev, 735static void pci1710_handle_every_sample(struct comedi_device *dev,
740 struct comedi_subdevice *s) 736 struct comedi_subdevice *s)
741{ 737{
742 struct pci1710_private *devpriv = dev->private;
743 struct comedi_cmd *cmd = &s->async->cmd; 738 struct comedi_cmd *cmd = &s->async->cmd;
744 unsigned int status; 739 unsigned int status;
745 unsigned int val; 740 unsigned int val;
@@ -749,14 +744,14 @@ static void pci1710_handle_every_sample(struct comedi_device *dev,
749 if (status & Status_FE) { 744 if (status & Status_FE) {
750 dev_dbg(dev->class_dev, "A/D FIFO empty (%4x)\n", status); 745 dev_dbg(dev->class_dev, "A/D FIFO empty (%4x)\n", status);
751 s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; 746 s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR;
752 cfc_handle_events(dev, s); 747 comedi_handle_events(dev, s);
753 return; 748 return;
754 } 749 }
755 if (status & Status_FF) { 750 if (status & Status_FF) {
756 dev_dbg(dev->class_dev, 751 dev_dbg(dev->class_dev,
757 "A/D FIFO Full status (Fatal Error!) (%4x)\n", status); 752 "A/D FIFO Full status (Fatal Error!) (%4x)\n", status);
758 s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; 753 s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR;
759 cfc_handle_events(dev, s); 754 comedi_handle_events(dev, s);
760 return; 755 return;
761 } 756 }
762 757
@@ -770,27 +765,19 @@ static void pci1710_handle_every_sample(struct comedi_device *dev,
770 break; 765 break;
771 } 766 }
772 767
773 comedi_buf_put(s, val & s->maxdata); 768 val &= s->maxdata;
774 769 comedi_buf_write_samples(s, &val, 1);
775 s->async->cur_chan++;
776 if (s->async->cur_chan >= cmd->chanlist_len)
777 s->async->cur_chan = 0;
778 770
779 771 if (cmd->stop_src == TRIG_COUNT &&
780 if (s->async->cur_chan == 0) { /* one scan done */ 772 s->async->scans_done >= cmd->stop_arg) {
781 devpriv->ai_act_scan++; 773 s->async->events |= COMEDI_CB_EOA;
782 if (cmd->stop_src == TRIG_COUNT && 774 break;
783 devpriv->ai_act_scan >= cmd->stop_arg) {
784 /* all data sampled */
785 s->async->events |= COMEDI_CB_EOA;
786 break;
787 }
788 } 775 }
789 } 776 }
790 777
791 outb(0, dev->iobase + PCI171x_CLRINT); /* clear our INT request */ 778 outb(0, dev->iobase + PCI171x_CLRINT); /* clear our INT request */
792 779
793 cfc_handle_events(dev, s); 780 comedi_handle_events(dev, s);
794} 781}
795 782
796/* 783/*
@@ -799,8 +786,6 @@ static void pci1710_handle_every_sample(struct comedi_device *dev,
799static int move_block_from_fifo(struct comedi_device *dev, 786static int move_block_from_fifo(struct comedi_device *dev,
800 struct comedi_subdevice *s, int n, int turn) 787 struct comedi_subdevice *s, int n, int turn)
801{ 788{
802 struct pci1710_private *devpriv = dev->private;
803 struct comedi_cmd *cmd = &s->async->cmd;
804 unsigned int val; 789 unsigned int val;
805 int ret; 790 int ret;
806 int i; 791 int i;
@@ -814,13 +799,8 @@ static int move_block_from_fifo(struct comedi_device *dev,
814 return ret; 799 return ret;
815 } 800 }
816 801
817 comedi_buf_put(s, val & s->maxdata); 802 val &= s->maxdata;
818 803 comedi_buf_write_samples(s, &val, 1);
819 s->async->cur_chan++;
820 if (s->async->cur_chan >= cmd->chanlist_len) {
821 s->async->cur_chan = 0;
822 devpriv->ai_act_scan++;
823 }
824 } 804 }
825 return 0; 805 return 0;
826} 806}
@@ -829,48 +809,47 @@ static void pci1710_handle_fifo(struct comedi_device *dev,
829 struct comedi_subdevice *s) 809 struct comedi_subdevice *s)
830{ 810{
831 const struct boardtype *this_board = dev->board_ptr; 811 const struct boardtype *this_board = dev->board_ptr;
832 struct pci1710_private *devpriv = dev->private;
833 struct comedi_cmd *cmd = &s->async->cmd; 812 struct comedi_cmd *cmd = &s->async->cmd;
834 int m, samplesinbuf; 813 unsigned int nsamples;
814 unsigned int m;
835 815
836 m = inw(dev->iobase + PCI171x_STATUS); 816 m = inw(dev->iobase + PCI171x_STATUS);
837 if (!(m & Status_FH)) { 817 if (!(m & Status_FH)) {
838 dev_dbg(dev->class_dev, "A/D FIFO not half full! (%4x)\n", m); 818 dev_dbg(dev->class_dev, "A/D FIFO not half full! (%4x)\n", m);
839 s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; 819 s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR;
840 cfc_handle_events(dev, s); 820 comedi_handle_events(dev, s);
841 return; 821 return;
842 } 822 }
843 if (m & Status_FF) { 823 if (m & Status_FF) {
844 dev_dbg(dev->class_dev, 824 dev_dbg(dev->class_dev,
845 "A/D FIFO Full status (Fatal Error!) (%4x)\n", m); 825 "A/D FIFO Full status (Fatal Error!) (%4x)\n", m);
846 s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; 826 s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR;
847 cfc_handle_events(dev, s); 827 comedi_handle_events(dev, s);
848 return; 828 return;
849 } 829 }
850 830
851 samplesinbuf = this_board->fifo_half_size; 831 nsamples = this_board->fifo_half_size;
852 if (samplesinbuf * sizeof(short) >= s->async->prealloc_bufsz) { 832 if (comedi_samples_to_bytes(s, nsamples) >= s->async->prealloc_bufsz) {
853 m = s->async->prealloc_bufsz / sizeof(short); 833 m = comedi_bytes_to_samples(s, s->async->prealloc_bufsz);
854 if (move_block_from_fifo(dev, s, m, 0)) 834 if (move_block_from_fifo(dev, s, m, 0))
855 return; 835 return;
856 samplesinbuf -= m; 836 nsamples -= m;
857 } 837 }
858 838
859 if (samplesinbuf) { 839 if (nsamples) {
860 if (move_block_from_fifo(dev, s, samplesinbuf, 1)) 840 if (move_block_from_fifo(dev, s, nsamples, 1))
861 return; 841 return;
862 } 842 }
863 843
864 if (cmd->stop_src == TRIG_COUNT && 844 if (cmd->stop_src == TRIG_COUNT &&
865 devpriv->ai_act_scan >= cmd->stop_arg) { 845 s->async->scans_done >= cmd->stop_arg) {
866 /* all data sampled */
867 s->async->events |= COMEDI_CB_EOA; 846 s->async->events |= COMEDI_CB_EOA;
868 cfc_handle_events(dev, s); 847 comedi_handle_events(dev, s);
869 return; 848 return;
870 } 849 }
871 outb(0, dev->iobase + PCI171x_CLRINT); /* clear our INT request */ 850 outb(0, dev->iobase + PCI171x_CLRINT); /* clear our INT request */
872 851
873 cfc_handle_events(dev, s); 852 comedi_handle_events(dev, s);
874} 853}
875 854
876/* 855/*
@@ -928,9 +907,6 @@ static int pci171x_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
928 outb(0, dev->iobase + PCI171x_CLRFIFO); 907 outb(0, dev->iobase + PCI171x_CLRFIFO);
929 outb(0, dev->iobase + PCI171x_CLRINT); 908 outb(0, dev->iobase + PCI171x_CLRINT);
930 909
931 devpriv->ai_act_scan = 0;
932 s->async->cur_chan = 0;
933
934 devpriv->CntrlReg &= Control_CNT0; 910 devpriv->CntrlReg &= Control_CNT0;
935 if ((cmd->flags & CMDF_WAKE_EOS) == 0) 911 if ((cmd->flags & CMDF_WAKE_EOS) == 0)
936 devpriv->CntrlReg |= Control_ONEFH; 912 devpriv->CntrlReg |= Control_ONEFH;
@@ -1208,7 +1184,7 @@ static int pci1710_auto_attach(struct comedi_device *dev,
1208 if (this_board->n_dichan) { 1184 if (this_board->n_dichan) {
1209 s = &dev->subdevices[subdev]; 1185 s = &dev->subdevices[subdev];
1210 s->type = COMEDI_SUBD_DI; 1186 s->type = COMEDI_SUBD_DI;
1211 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON; 1187 s->subdev_flags = SDF_READABLE;
1212 s->n_chan = this_board->n_dichan; 1188 s->n_chan = this_board->n_dichan;
1213 s->maxdata = 1; 1189 s->maxdata = 1;
1214 s->len_chanlist = this_board->n_dichan; 1190 s->len_chanlist = this_board->n_dichan;
@@ -1220,7 +1196,7 @@ static int pci1710_auto_attach(struct comedi_device *dev,
1220 if (this_board->n_dochan) { 1196 if (this_board->n_dochan) {
1221 s = &dev->subdevices[subdev]; 1197 s = &dev->subdevices[subdev];
1222 s->type = COMEDI_SUBD_DO; 1198 s->type = COMEDI_SUBD_DO;
1223 s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON; 1199 s->subdev_flags = SDF_WRITABLE;
1224 s->n_chan = this_board->n_dochan; 1200 s->n_chan = this_board->n_dochan;
1225 s->maxdata = 1; 1201 s->maxdata = 1;
1226 s->len_chanlist = this_board->n_dochan; 1202 s->len_chanlist = this_board->n_dochan;
diff --git a/drivers/staging/comedi/drivers/adv_pci1723.c b/drivers/staging/comedi/drivers/adv_pci1723.c
index 1610e2b406f3..65f854e1eb66 100644
--- a/drivers/staging/comedi/drivers/adv_pci1723.c
+++ b/drivers/staging/comedi/drivers/adv_pci1723.c
@@ -1,205 +1,124 @@
1/* 1/*
2 comedi/drivers/pci1723.c 2 * adv_pci1723.c
3 3 * Comedi driver for the Advantech PCI-1723 card.
4 COMEDI - Linux Control and Measurement Device Interface 4 *
5 Copyright (C) 2000 David A. Schleef <ds@schleef.org> 5 * COMEDI - Linux Control and Measurement Device Interface
6 6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 This program is free software; you can redistribute it and/or modify 7 *
8 it under the terms of the GNU General Public License as published by 8 * This program is free software; you can redistribute it and/or modify
9 the Free Software Foundation; either version 2 of the License, or 9 * it under the terms of the GNU General Public License as published by
10 (at your option) any later version. 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 */
11 18
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16*/
17/* 19/*
18Driver: adv_pci1723 20 * Driver: adv_pci1723
19Description: Advantech PCI-1723 21 * Description: Advantech PCI-1723
20Author: yonggang <rsmgnu@gmail.com>, Ian Abbott <abbotti@mev.co.uk> 22 * Author: yonggang <rsmgnu@gmail.com>, Ian Abbott <abbotti@mev.co.uk>
21Devices: [Advantech] PCI-1723 (adv_pci1723) 23 * Devices: (Advantech) PCI-1723 [adv_pci1723]
22Updated: Mon, 14 Apr 2008 15:12:56 +0100 24 * Updated: Mon, 14 Apr 2008 15:12:56 +0100
23Status: works 25 * Status: works
24 26 *
25Configuration Options: 27 * Configuration Options: not applicable, uses comedi PCI auto config
26 [0] - PCI bus of device (optional) 28 *
27 [1] - PCI slot of device (optional) 29 * Subdevice 0 is 8-channel AO, 16-bit, range +/- 10 V.
28 30 *
29 If bus/slot is not specified, the first supported 31 * Subdevice 1 is 16-channel DIO. The channels are configurable as
30 PCI device found will be used. 32 * input or output in 2 groups (0 to 7, 8 to 15). Configuring any
31 33 * channel implicitly configures all channels in the same group.
32Subdevice 0 is 8-channel AO, 16-bit, range +/- 10 V. 34 *
33 35 * TODO:
34Subdevice 1 is 16-channel DIO. The channels are configurable as input or 36 * 1. Add the two milliamp ranges to the AO subdevice (0 to 20 mA,
35output in 2 groups (0 to 7, 8 to 15). Configuring any channel implicitly 37 * 4 to 20 mA).
36configures all channels in the same group. 38 * 2. Read the initial ranges and values of the AO subdevice at
37 39 * start-up instead of reinitializing them.
38TODO: 40 * 3. Implement calibration.
39 41 */
401. Add the two milliamp ranges to the AO subdevice (0 to 20 mA, 4 to 20 mA).
412. Read the initial ranges and values of the AO subdevice at start-up instead
42 of reinitializing them.
433. Implement calibration.
44*/
45 42
46#include <linux/module.h> 43#include <linux/module.h>
47#include <linux/pci.h> 44#include <linux/pci.h>
48 45
49#include "../comedidev.h" 46#include "../comedidev.h"
50 47
51/* all the registers for the pci1723 board */
52#define PCI1723_DA(N) ((N)<<1) /* W: D/A register N (0 to 7) */
53
54#define PCI1723_SYN_SET 0x12 /* synchronized set register */
55#define PCI1723_ALL_CHNNELE_SYN_STROBE 0x12
56 /* synchronized status register */
57
58#define PCI1723_RANGE_CALIBRATION_MODE 0x14
59 /* range and calibration mode */
60#define PCI1723_RANGE_CALIBRATION_STATUS 0x14
61 /* range and calibration status */
62
63#define PCI1723_CONTROL_CMD_CALIBRATION_FUN 0x16
64 /*
65 * SADC control command for
66 * calibration function
67 */
68#define PCI1723_STATUS_CMD_CALIBRATION_FUN 0x16
69 /*
70 * SADC control status for
71 * calibration function
72 */
73
74#define PCI1723_CALIBRATION_PARA_STROBE 0x18
75 /* Calibration parameter strobe */
76
77#define PCI1723_DIGITAL_IO_PORT_SET 0x1A /* Digital I/O port setting */
78#define PCI1723_DIGITAL_IO_PORT_MODE 0x1A /* Digital I/O port mode */
79
80#define PCI1723_WRITE_DIGITAL_OUTPUT_CMD 0x1C
81 /* Write digital output command */
82#define PCI1723_READ_DIGITAL_INPUT_DATA 0x1C /* Read digital input data */
83
84#define PCI1723_WRITE_CAL_CMD 0x1E /* Write calibration command */
85#define PCI1723_READ_CAL_STATUS 0x1E /* Read calibration status */
86
87#define PCI1723_SYN_STROBE 0x20 /* Synchronized strobe */
88
89#define PCI1723_RESET_ALL_CHN_STROBE 0x22
90 /* Reset all D/A channels strobe */
91
92#define PCI1723_RESET_CAL_CONTROL_STROBE 0x24
93 /*
94 * Reset the calibration
95 * controller strobe
96 */
97
98#define PCI1723_CHANGE_CHA_OUTPUT_TYPE_STROBE 0x26
99 /*
100 * Change D/A channels output
101 * type strobe
102 */
103
104#define PCI1723_SELECT_CALIBRATION 0x28 /* Select the calibration Ref_V */
105
106struct pci1723_private {
107 unsigned char da_range[8]; /* D/A output range for each channel */
108 unsigned short ao_data[8]; /* data output buffer */
109};
110
111/* 48/*
112 * The pci1723 card reset; 49 * PCI Bar 2 I/O Register map (dev->iobase)
113 */ 50 */
114static int pci1723_reset(struct comedi_device *dev) 51#define PCI1723_AO_REG(x) (0x00 + ((x) * 2))
52#define PCI1723_BOARD_ID_REG 0x10
53#define PCI1723_BOARD_ID_MASK (0xf << 0)
54#define PCI1723_SYNC_CTRL_REG 0x12
55#define PCI1723_SYNC_CTRL_ASYNC (0 << 0)
56#define PCI1723_SYNC_CTRL_SYNC (1 << 0)
57#define PCI1723_CTRL_REG 0x14
58#define PCI1723_CTRL_BUSY (1 << 15)
59#define PCI1723_CTRL_INIT (1 << 14)
60#define PCI1723_CTRL_SELF (1 << 8)
61#define PCI1723_CTRL_IDX(x) (((x) & 0x3) << 6)
62#define PCI1723_CTRL_RANGE(x) (((x) & 0x3) << 4)
63#define PCI1723_CTRL_GAIN (0 << 3)
64#define PCI1723_CTRL_OFFSET (1 << 3)
65#define PCI1723_CTRL_CHAN(x) (((x) & 0x7) << 0)
66#define PCI1723_CALIB_CTRL_REG 0x16
67#define PCI1723_CALIB_CTRL_CS (1 << 2)
68#define PCI1723_CALIB_CTRL_DAT (1 << 1)
69#define PCI1723_CALIB_CTRL_CLK (1 << 0)
70#define PCI1723_CALIB_STROBE_REG 0x18
71#define PCI1723_DIO_CTRL_REG 0x1a
72#define PCI1723_DIO_CTRL_HDIO (1 << 1)
73#define PCI1723_DIO_CTRL_LDIO (1 << 0)
74#define PCI1723_DIO_DATA_REG 0x1c
75#define PCI1723_CALIB_DATA_REG 0x1e
76#define PCI1723_SYNC_STROBE_REG 0x20
77#define PCI1723_RESET_AO_STROBE_REG 0x22
78#define PCI1723_RESET_CALIB_STROBE_REG 0x24
79#define PCI1723_RANGE_STROBE_REG 0x26
80#define PCI1723_VREF_REG 0x28
81#define PCI1723_VREF_NEG10V (0 << 0)
82#define PCI1723_VREF_0V (1 << 0)
83#define PCI1723_VREF_POS10V (3 << 0)
84
85static int pci1723_ao_insn_write(struct comedi_device *dev,
86 struct comedi_subdevice *s,
87 struct comedi_insn *insn,
88 unsigned int *data)
115{ 89{
116 struct pci1723_private *devpriv = dev->private; 90 unsigned int chan = CR_CHAN(insn->chanspec);
117 int i; 91 int i;
118 92
119 outw(0x01, dev->iobase + PCI1723_SYN_SET); 93 for (i = 0; i < insn->n; i++) {
120 /* set synchronous output mode */ 94 unsigned int val = data[i];
121
122 for (i = 0; i < 8; i++) {
123 /* set all outputs to 0V */
124 devpriv->ao_data[i] = 0x8000;
125 outw(devpriv->ao_data[i], dev->iobase + PCI1723_DA(i));
126 /* set all ranges to +/- 10V */
127 devpriv->da_range[i] = 0;
128 outw(((devpriv->da_range[i] << 4) | i),
129 PCI1723_RANGE_CALIBRATION_MODE);
130 }
131
132 outw(0, dev->iobase + PCI1723_CHANGE_CHA_OUTPUT_TYPE_STROBE);
133 /* update ranges */
134 outw(0, dev->iobase + PCI1723_SYN_STROBE); /* update outputs */
135
136 /* set asynchronous output mode */
137 outw(0, dev->iobase + PCI1723_SYN_SET);
138
139 return 0;
140}
141
142static int pci1723_insn_read_ao(struct comedi_device *dev,
143 struct comedi_subdevice *s,
144 struct comedi_insn *insn, unsigned int *data)
145{
146 struct pci1723_private *devpriv = dev->private;
147 int n, chan;
148
149 chan = CR_CHAN(insn->chanspec);
150 for (n = 0; n < insn->n; n++)
151 data[n] = devpriv->ao_data[chan];
152 95
153 return n; 96 outw(val, dev->iobase + PCI1723_AO_REG(chan));
154} 97 s->readback[chan] = val;
155
156/*
157 analog data output;
158*/
159static int pci1723_ao_write_winsn(struct comedi_device *dev,
160 struct comedi_subdevice *s,
161 struct comedi_insn *insn, unsigned int *data)
162{
163 struct pci1723_private *devpriv = dev->private;
164 unsigned int chan = CR_CHAN(insn->chanspec);
165 int n;
166
167 for (n = 0; n < insn->n; n++) {
168 devpriv->ao_data[chan] = data[n];
169 outw(data[n], dev->iobase + PCI1723_DA(chan));
170 } 98 }
171 99
172 return n; 100 return insn->n;
173} 101}
174 102
175/*
176 digital i/o config/query
177*/
178static int pci1723_dio_insn_config(struct comedi_device *dev, 103static int pci1723_dio_insn_config(struct comedi_device *dev,
179 struct comedi_subdevice *s, 104 struct comedi_subdevice *s,
180 struct comedi_insn *insn, unsigned int *data) 105 struct comedi_insn *insn,
106 unsigned int *data)
181{ 107{
182 unsigned int chan = CR_CHAN(insn->chanspec); 108 unsigned int chan = CR_CHAN(insn->chanspec);
183 unsigned int mask; 109 unsigned int mask = (chan < 8) ? 0x00ff : 0xff00;
184 unsigned short mode; 110 unsigned short mode = 0x0000; /* assume output */
185 int ret; 111 int ret;
186 112
187 if (chan < 8)
188 mask = 0x00ff;
189 else
190 mask = 0xff00;
191
192 ret = comedi_dio_insn_config(dev, s, insn, data, mask); 113 ret = comedi_dio_insn_config(dev, s, insn, data, mask);
193 if (ret) 114 if (ret)
194 return ret; 115 return ret;
195 116
196 /* update hardware DIO mode */
197 mode = 0x0000; /* assume output */
198 if (!(s->io_bits & 0x00ff)) 117 if (!(s->io_bits & 0x00ff))
199 mode |= 0x0001; /* low byte input */ 118 mode |= PCI1723_DIO_CTRL_LDIO; /* low byte input */
200 if (!(s->io_bits & 0xff00)) 119 if (!(s->io_bits & 0xff00))
201 mode |= 0x0002; /* high byte input */ 120 mode |= PCI1723_DIO_CTRL_HDIO; /* high byte input */
202 outw(mode, dev->iobase + PCI1723_DIGITAL_IO_PORT_SET); 121 outw(mode, dev->iobase + PCI1723_DIO_CTRL_REG);
203 122
204 return insn->n; 123 return insn->n;
205} 124}
@@ -210,24 +129,21 @@ static int pci1723_dio_insn_bits(struct comedi_device *dev,
210 unsigned int *data) 129 unsigned int *data)
211{ 130{
212 if (comedi_dio_update_state(s, data)) 131 if (comedi_dio_update_state(s, data))
213 outw(s->state, dev->iobase + PCI1723_WRITE_DIGITAL_OUTPUT_CMD); 132 outw(s->state, dev->iobase + PCI1723_DIO_DATA_REG);
214 133
215 data[1] = inw(dev->iobase + PCI1723_READ_DIGITAL_INPUT_DATA); 134 data[1] = inw(dev->iobase + PCI1723_DIO_DATA_REG);
216 135
217 return insn->n; 136 return insn->n;
218} 137}
219 138
220static int pci1723_auto_attach(struct comedi_device *dev, 139static int pci1723_auto_attach(struct comedi_device *dev,
221 unsigned long context_unused) 140 unsigned long context_unused)
222{ 141{
223 struct pci_dev *pcidev = comedi_to_pci_dev(dev); 142 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
224 struct pci1723_private *devpriv;
225 struct comedi_subdevice *s; 143 struct comedi_subdevice *s;
144 unsigned int val;
226 int ret; 145 int ret;
227 146 int i;
228 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
229 if (!devpriv)
230 return -ENOMEM;
231 147
232 ret = comedi_pci_enable(dev); 148 ret = comedi_pci_enable(dev);
233 if (ret) 149 if (ret)
@@ -239,61 +155,57 @@ static int pci1723_auto_attach(struct comedi_device *dev,
239 return ret; 155 return ret;
240 156
241 s = &dev->subdevices[0]; 157 s = &dev->subdevices[0];
242 dev->write_subdev = s;
243 s->type = COMEDI_SUBD_AO; 158 s->type = COMEDI_SUBD_AO;
244 s->subdev_flags = SDF_WRITEABLE | SDF_GROUND | SDF_COMMON; 159 s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON;
245 s->n_chan = 8; 160 s->n_chan = 8;
246 s->maxdata = 0xffff; 161 s->maxdata = 0xffff;
247 s->len_chanlist = 8;
248 s->range_table = &range_bipolar10; 162 s->range_table = &range_bipolar10;
249 s->insn_write = pci1723_ao_write_winsn; 163 s->insn_write = pci1723_ao_insn_write;
250 s->insn_read = pci1723_insn_read_ao; 164
165 ret = comedi_alloc_subdev_readback(s);
166 if (ret)
167 return ret;
168
169 /* synchronously reset all analog outputs to 0V, +/-10V range */
170 outw(PCI1723_SYNC_CTRL_SYNC, dev->iobase + PCI1723_SYNC_CTRL_REG);
171 for (i = 0; i < s->n_chan; i++) {
172 outw(PCI1723_CTRL_RANGE(0) | PCI1723_CTRL_CHAN(i),
173 PCI1723_CTRL_REG);
174 outw(0, dev->iobase + PCI1723_RANGE_STROBE_REG);
175
176 outw(0x8000, dev->iobase + PCI1723_AO_REG(i));
177 s->readback[i] = 0x8000;
178 }
179 outw(0, dev->iobase + PCI1723_SYNC_STROBE_REG);
180
181 /* disable syncronous control */
182 outw(PCI1723_SYNC_CTRL_ASYNC, dev->iobase + PCI1723_SYNC_CTRL_REG);
251 183
252 s = &dev->subdevices[1]; 184 s = &dev->subdevices[1];
253 s->type = COMEDI_SUBD_DIO; 185 s->type = COMEDI_SUBD_DIO;
254 s->subdev_flags = SDF_READABLE | SDF_WRITABLE; 186 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
255 s->n_chan = 16; 187 s->n_chan = 16;
256 s->maxdata = 1; 188 s->maxdata = 1;
257 s->len_chanlist = 16;
258 s->range_table = &range_digital; 189 s->range_table = &range_digital;
259 s->insn_config = pci1723_dio_insn_config; 190 s->insn_config = pci1723_dio_insn_config;
260 s->insn_bits = pci1723_dio_insn_bits; 191 s->insn_bits = pci1723_dio_insn_bits;
261 192
262 /* read DIO config */ 193 /* get initial DIO direction and state */
263 switch (inw(dev->iobase + PCI1723_DIGITAL_IO_PORT_MODE) & 0x03) { 194 val = inw(dev->iobase + PCI1723_DIO_CTRL_REG);
264 case 0x00: /* low byte output, high byte output */ 195 if (!(val & PCI1723_DIO_CTRL_LDIO))
265 s->io_bits = 0xFFFF; 196 s->io_bits |= 0x00ff; /* low byte output */
266 break; 197 if (!(val & PCI1723_DIO_CTRL_HDIO))
267 case 0x01: /* low byte input, high byte output */ 198 s->io_bits |= 0xff00; /* high byte output */
268 s->io_bits = 0xFF00; 199 s->state = inw(dev->iobase + PCI1723_DIO_DATA_REG);
269 break;
270 case 0x02: /* low byte output, high byte input */
271 s->io_bits = 0x00FF;
272 break;
273 case 0x03: /* low byte input, high byte input */
274 s->io_bits = 0x0000;
275 break;
276 }
277 /* read DIO port state */
278 s->state = inw(dev->iobase + PCI1723_READ_DIGITAL_INPUT_DATA);
279
280 pci1723_reset(dev);
281 200
282 return 0; 201 return 0;
283} 202}
284 203
285static void pci1723_detach(struct comedi_device *dev)
286{
287 if (dev->iobase)
288 pci1723_reset(dev);
289 comedi_pci_detach(dev);
290}
291
292static struct comedi_driver adv_pci1723_driver = { 204static struct comedi_driver adv_pci1723_driver = {
293 .driver_name = "adv_pci1723", 205 .driver_name = "adv_pci1723",
294 .module = THIS_MODULE, 206 .module = THIS_MODULE,
295 .auto_attach = pci1723_auto_attach, 207 .auto_attach = pci1723_auto_attach,
296 .detach = pci1723_detach, 208 .detach = comedi_pci_detach,
297}; 209};
298 210
299static int adv_pci1723_pci_probe(struct pci_dev *dev, 211static int adv_pci1723_pci_probe(struct pci_dev *dev,
@@ -318,5 +230,5 @@ static struct pci_driver adv_pci1723_pci_driver = {
318module_comedi_pci_driver(adv_pci1723_driver, adv_pci1723_pci_driver); 230module_comedi_pci_driver(adv_pci1723_driver, adv_pci1723_pci_driver);
319 231
320MODULE_AUTHOR("Comedi http://www.comedi.org"); 232MODULE_AUTHOR("Comedi http://www.comedi.org");
321MODULE_DESCRIPTION("Comedi low-level driver"); 233MODULE_DESCRIPTION("Advantech PCI-1723 Comedi driver");
322MODULE_LICENSE("GPL"); 234MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/adv_pci1724.c b/drivers/staging/comedi/drivers/adv_pci1724.c
index 2697758b1ed9..a8d28403262e 100644
--- a/drivers/staging/comedi/drivers/adv_pci1724.c
+++ b/drivers/staging/comedi/drivers/adv_pci1724.c
@@ -1,122 +1,76 @@
1/* 1/*
2 comedi/drivers/adv_pci1724.c 2 * adv_pci1724.c
3 This is a driver for the Advantech PCI-1724U card. 3 * Comedi driver for the Advantech PCI-1724U card.
4 4 *
5 Author: Frank Mori Hess <fmh6jj@gmail.com> 5 * Author: Frank Mori Hess <fmh6jj@gmail.com>
6 Copyright (C) 2013 GnuBIO Inc 6 * Copyright (C) 2013 GnuBIO Inc
7 7 *
8 COMEDI - Linux Control and Measurement Device Interface 8 * COMEDI - Linux Control and Measurement Device Interface
9 Copyright (C) 1997-8 David A. Schleef <ds@schleef.org> 9 * Copyright (C) 1997-8 David A. Schleef <ds@schleef.org>
10 10 *
11 This program is free software; you can redistribute it and/or modify 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 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 13 * the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version. 14 * (at your option) any later version.
15 15 *
16 This program is distributed in the hope that it will be useful, 16 * This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details. 19 * GNU General Public License for more details.
20*/ 20 */
21 21
22/* 22/*
23 23 * Driver: adv_pci1724
24Driver: adv_1724 24 * Description: Advantech PCI-1724U
25Description: Advantech PCI-1724U 25 * Devices: (Advantech) PCI-1724U [adv_pci1724]
26Author: Frank Mori Hess <fmh6jj@gmail.com> 26 * Author: Frank Mori Hess <fmh6jj@gmail.com>
27Status: works 27 * Updated: 2013-02-09
28Updated: 2013-02-09 28 * Status: works
29Devices: [Advantech] PCI-1724U (adv_pci1724) 29 *
30 30 * Configuration Options: not applicable, uses comedi PCI auto config
31Subdevice 0 is the analog output. 31 *
32Subdevice 1 is the offset calibration for the analog output. 32 * Subdevice 0 is the analog output.
33Subdevice 2 is the gain calibration for the analog output. 33 * Subdevice 1 is the offset calibration for the analog output.
34 34 * Subdevice 2 is the gain calibration for the analog output.
35The calibration offset and gains have quite a large effect 35 *
36on the analog output, so it is possible to adjust the analog output to 36 * The calibration offset and gains have quite a large effect on the
37have an output range significantly different from the board's 37 * analog output, so it is possible to adjust the analog output to
38nominal output ranges. For a calibrated +/- 10V range, the analog 38 * have an output range significantly different from the board's
39output's offset will be set somewhere near mid-range (0x2000) and its 39 * nominal output ranges. For a calibrated +/-10V range, the analog
40gain will be near maximum (0x3fff). 40 * output's offset will be set somewhere near mid-range (0x2000) and
41 41 * its gain will be near maximum (0x3fff).
42There is really no difference between the board's documented 0-20mA 42 *
43versus 4-20mA output ranges. To pick one or the other is simply a matter 43 * There is really no difference between the board's documented 0-20mA
44of adjusting the offset and gain calibration until the board outputs in 44 * versus 4-20mA output ranges. To pick one or the other is simply a
45the desired range. 45 * matter of adjusting the offset and gain calibration until the board
46 46 * outputs in the desired range.
47Configuration options: 47 */
48 None
49
50Manual configuration of comedi devices is not supported by this driver;
51supported PCI devices are configured as comedi devices automatically.
52
53*/
54 48
55#include <linux/module.h> 49#include <linux/module.h>
56#include <linux/delay.h>
57#include <linux/pci.h> 50#include <linux/pci.h>
58 51
59#include "../comedidev.h" 52#include "../comedidev.h"
60 53
61#define PCI_VENDOR_ID_ADVANTECH 0x13fe 54/*
62 55 * PCI bar 2 Register I/O map (dev->iobase)
63#define NUM_AO_CHANNELS 32 56 */
64 57#define PCI1724_DAC_CTRL_REG 0x00
65/* register offsets */ 58#define PCI1724_DAC_CTRL_GX(x) (1 << (20 + ((x) / 8)))
66enum board_registers { 59#define PCI1724_DAC_CTRL_CX(x) (((x) % 8) << 16)
67 DAC_CONTROL_REG = 0x0, 60#define PCI1724_DAC_CTRL_MODE_GAIN (1 << 14)
68 SYNC_OUTPUT_REG = 0x4, 61#define PCI1724_DAC_CTRL_MODE_OFFSET (2 << 14)
69 EEPROM_CONTROL_REG = 0x8, 62#define PCI1724_DAC_CTRL_MODE_NORMAL (3 << 14)
70 SYNC_OUTPUT_TRIGGER_REG = 0xc, 63#define PCI1724_DAC_CTRL_MODE_MASK (3 << 14)
71 BOARD_ID_REG = 0x10 64#define PCI1724_DAC_CTRL_DATA(x) (((x) & 0x3fff) << 0)
72}; 65#define PCI1724_SYNC_CTRL_REG 0x04
73 66#define PCI1724_SYNC_CTRL_DACSTAT (1 << 1)
74/* bit definitions for registers */ 67#define PCI1724_SYNC_CTRL_SYN (1 << 0)
75enum dac_control_contents { 68#define PCI1724_EEPROM_CTRL_REG 0x08
76 DAC_DATA_MASK = 0x3fff, 69#define PCI1724_SYNC_TRIG_REG 0x0c /* any value works */
77 DAC_DESTINATION_MASK = 0xc000, 70#define PCI1724_BOARD_ID_REG 0x10
78 DAC_NORMAL_MODE = 0xc000, 71#define PCI1724_BOARD_ID_MASK (0xf << 0)
79 DAC_OFFSET_MODE = 0x8000, 72
80 DAC_GAIN_MODE = 0x4000, 73static const struct comedi_lrange adv_pci1724_ao_ranges = {
81 DAC_CHANNEL_SELECT_MASK = 0xf0000,
82 DAC_GROUP_SELECT_MASK = 0xf00000
83};
84
85static uint32_t dac_data_bits(uint16_t dac_data)
86{
87 return dac_data & DAC_DATA_MASK;
88}
89
90static uint32_t dac_channel_select_bits(unsigned channel)
91{
92 return (channel << 16) & DAC_CHANNEL_SELECT_MASK;
93}
94
95static uint32_t dac_group_select_bits(unsigned group)
96{
97 return (1 << (20 + group)) & DAC_GROUP_SELECT_MASK;
98}
99
100static uint32_t dac_channel_and_group_select_bits(unsigned comedi_channel)
101{
102 return dac_channel_select_bits(comedi_channel % 8) |
103 dac_group_select_bits(comedi_channel / 8);
104}
105
106enum sync_output_contents {
107 SYNC_MODE = 0x1,
108 DAC_BUSY = 0x2, /* dac state machine is not ready */
109};
110
111enum sync_output_trigger_contents {
112 SYNC_TRIGGER_BITS = 0x0 /* any value works */
113};
114
115enum board_id_contents {
116 BOARD_ID_MASK = 0xf
117};
118
119static const struct comedi_lrange ao_ranges_1724 = {
120 4, { 74 4, {
121 BIP_RANGE(10), 75 BIP_RANGE(10),
122 RANGE_mA(0, 20), 76 RANGE_mA(0, 20),
@@ -125,254 +79,120 @@ static const struct comedi_lrange ao_ranges_1724 = {
125 } 79 }
126}; 80};
127 81
128/* this structure is for data unique to this hardware driver. */ 82static int adv_pci1724_dac_idle(struct comedi_device *dev,
129struct adv_pci1724_private { 83 struct comedi_subdevice *s,
130 int ao_value[NUM_AO_CHANNELS]; 84 struct comedi_insn *insn,
131 int offset_value[NUM_AO_CHANNELS]; 85 unsigned long context)
132 int gain_value[NUM_AO_CHANNELS];
133};
134
135static int wait_for_dac_idle(struct comedi_device *dev)
136{
137 static const int timeout = 10000;
138 int i;
139
140 for (i = 0; i < timeout; ++i) {
141 if ((inl(dev->iobase + SYNC_OUTPUT_REG) & DAC_BUSY) == 0)
142 break;
143 udelay(1);
144 }
145 if (i == timeout) {
146 dev_err(dev->class_dev,
147 "Timed out waiting for dac to become idle\n");
148 return -EIO;
149 }
150 return 0;
151}
152
153static int set_dac(struct comedi_device *dev, unsigned mode, unsigned channel,
154 unsigned data)
155{
156 int retval;
157 unsigned control_bits;
158
159 retval = wait_for_dac_idle(dev);
160 if (retval < 0)
161 return retval;
162
163 control_bits = mode;
164 control_bits |= dac_channel_and_group_select_bits(channel);
165 control_bits |= dac_data_bits(data);
166 outl(control_bits, dev->iobase + DAC_CONTROL_REG);
167 return 0;
168}
169
170static int ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
171 struct comedi_insn *insn, unsigned int *data)
172{ 86{
173 struct adv_pci1724_private *devpriv = dev->private; 87 unsigned int status;
174 int channel = CR_CHAN(insn->chanspec);
175 int retval;
176 int i;
177 88
178 /* turn off synchronous mode */ 89 status = inl(dev->iobase + PCI1724_SYNC_CTRL_REG);
179 outl(0, dev->iobase + SYNC_OUTPUT_REG); 90 if ((status & PCI1724_SYNC_CTRL_DACSTAT) == 0)
180 91 return 0;
181 for (i = 0; i < insn->n; ++i) { 92 return -EBUSY;
182 retval = set_dac(dev, DAC_NORMAL_MODE, channel, data[i]);
183 if (retval < 0)
184 return retval;
185 devpriv->ao_value[channel] = data[i];
186 }
187 return insn->n;
188} 93}
189 94
190static int ao_readback_insn(struct comedi_device *dev, 95static int adv_pci1724_insn_write(struct comedi_device *dev,
191 struct comedi_subdevice *s, 96 struct comedi_subdevice *s,
192 struct comedi_insn *insn, unsigned int *data) 97 struct comedi_insn *insn,
98 unsigned int *data)
193{ 99{
194 struct adv_pci1724_private *devpriv = dev->private; 100 unsigned long mode = (unsigned long)s->private;
195 int channel = CR_CHAN(insn->chanspec); 101 unsigned int chan = CR_CHAN(insn->chanspec);
196 int i; 102 unsigned int ctrl;
197 103 int ret;
198 if (devpriv->ao_value[channel] < 0) {
199 dev_err(dev->class_dev,
200 "Cannot read back channels which have not yet been written to\n");
201 return -EIO;
202 }
203 for (i = 0; i < insn->n; i++)
204 data[i] = devpriv->ao_value[channel];
205
206 return insn->n;
207}
208
209static int offset_write_insn(struct comedi_device *dev,
210 struct comedi_subdevice *s,
211 struct comedi_insn *insn, unsigned int *data)
212{
213 struct adv_pci1724_private *devpriv = dev->private;
214 int channel = CR_CHAN(insn->chanspec);
215 int retval;
216 int i;
217
218 /* turn off synchronous mode */
219 outl(0, dev->iobase + SYNC_OUTPUT_REG);
220
221 for (i = 0; i < insn->n; ++i) {
222 retval = set_dac(dev, DAC_OFFSET_MODE, channel, data[i]);
223 if (retval < 0)
224 return retval;
225 devpriv->offset_value[channel] = data[i];
226 }
227
228 return insn->n;
229}
230
231static int offset_read_insn(struct comedi_device *dev,
232 struct comedi_subdevice *s,
233 struct comedi_insn *insn, unsigned int *data)
234{
235 struct adv_pci1724_private *devpriv = dev->private;
236 unsigned int channel = CR_CHAN(insn->chanspec);
237 int i; 104 int i;
238 105
239 if (devpriv->offset_value[channel] < 0) { 106 ctrl = PCI1724_DAC_CTRL_GX(chan) | PCI1724_DAC_CTRL_CX(chan) | mode;
240 dev_err(dev->class_dev,
241 "Cannot read back channels which have not yet been written to\n");
242 return -EIO;
243 }
244 for (i = 0; i < insn->n; i++)
245 data[i] = devpriv->offset_value[channel];
246
247 return insn->n;
248}
249
250static int gain_write_insn(struct comedi_device *dev,
251 struct comedi_subdevice *s,
252 struct comedi_insn *insn, unsigned int *data)
253{
254 struct adv_pci1724_private *devpriv = dev->private;
255 int channel = CR_CHAN(insn->chanspec);
256 int retval;
257 int i;
258 107
259 /* turn off synchronous mode */ 108 /* turn off synchronous mode */
260 outl(0, dev->iobase + SYNC_OUTPUT_REG); 109 outl(0, dev->iobase + PCI1724_SYNC_CTRL_REG);
261 110
262 for (i = 0; i < insn->n; ++i) { 111 for (i = 0; i < insn->n; ++i) {
263 retval = set_dac(dev, DAC_GAIN_MODE, channel, data[i]); 112 unsigned int val = data[i];
264 if (retval < 0)
265 return retval;
266 devpriv->gain_value[channel] = data[i];
267 }
268 113
269 return insn->n; 114 ret = comedi_timeout(dev, s, insn, adv_pci1724_dac_idle, 0);
270} 115 if (ret)
116 return ret;
271 117
272static int gain_read_insn(struct comedi_device *dev, 118 outl(ctrl | PCI1724_DAC_CTRL_DATA(val),
273 struct comedi_subdevice *s, struct comedi_insn *insn, 119 dev->iobase + PCI1724_DAC_CTRL_REG);
274 unsigned int *data)
275{
276 struct adv_pci1724_private *devpriv = dev->private;
277 unsigned int channel = CR_CHAN(insn->chanspec);
278 int i;
279 120
280 if (devpriv->gain_value[channel] < 0) { 121 s->readback[chan] = val;
281 dev_err(dev->class_dev,
282 "Cannot read back channels which have not yet been written to\n");
283 return -EIO;
284 } 122 }
285 for (i = 0; i < insn->n; i++)
286 data[i] = devpriv->gain_value[channel];
287 123
288 return insn->n; 124 return insn->n;
289} 125}
290 126
291/* Allocate and initialize the subdevice structures. 127static int adv_pci1724_auto_attach(struct comedi_device *dev,
292 */ 128 unsigned long context_unused)
293static int setup_subdevices(struct comedi_device *dev)
294{ 129{
130 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
295 struct comedi_subdevice *s; 131 struct comedi_subdevice *s;
132 unsigned int board_id;
296 int ret; 133 int ret;
297 134
135 ret = comedi_pci_enable(dev);
136 if (ret)
137 return ret;
138
139 dev->iobase = pci_resource_start(pcidev, 2);
140 board_id = inl(dev->iobase + PCI1724_BOARD_ID_REG);
141 dev_info(dev->class_dev, "board id: %d\n",
142 board_id & PCI1724_BOARD_ID_MASK);
143
298 ret = comedi_alloc_subdevices(dev, 3); 144 ret = comedi_alloc_subdevices(dev, 3);
299 if (ret) 145 if (ret)
300 return ret; 146 return ret;
301 147
302 /* analog output subdevice */ 148 /* Analog Output subdevice */
303 s = &dev->subdevices[0]; 149 s = &dev->subdevices[0];
304 s->type = COMEDI_SUBD_AO; 150 s->type = COMEDI_SUBD_AO;
305 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_GROUND; 151 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_GROUND;
306 s->n_chan = NUM_AO_CHANNELS; 152 s->n_chan = 32;
307 s->maxdata = 0x3fff; 153 s->maxdata = 0x3fff;
308 s->range_table = &ao_ranges_1724; 154 s->range_table = &adv_pci1724_ao_ranges;
309 s->insn_read = ao_readback_insn; 155 s->insn_write = adv_pci1724_insn_write;
310 s->insn_write = ao_winsn; 156 s->private = (void *)PCI1724_DAC_CTRL_MODE_NORMAL;
157
158 ret = comedi_alloc_subdev_readback(s);
159 if (ret)
160 return ret;
311 161
312 /* offset calibration */ 162 /* Offset Calibration subdevice */
313 s = &dev->subdevices[1]; 163 s = &dev->subdevices[1];
314 s->type = COMEDI_SUBD_CALIB; 164 s->type = COMEDI_SUBD_CALIB;
315 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; 165 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
316 s->n_chan = NUM_AO_CHANNELS; 166 s->n_chan = 32;
317 s->insn_read = offset_read_insn; 167 s->maxdata = 0x3fff;
318 s->insn_write = offset_write_insn; 168 s->insn_write = adv_pci1724_insn_write;
319 s->maxdata = 0x3fff; 169 s->private = (void *)PCI1724_DAC_CTRL_MODE_OFFSET;
170
171 ret = comedi_alloc_subdev_readback(s);
172 if (ret)
173 return ret;
320 174
321 /* gain calibration */ 175 /* Gain Calibration subdevice */
322 s = &dev->subdevices[2]; 176 s = &dev->subdevices[2];
323 s->type = COMEDI_SUBD_CALIB; 177 s->type = COMEDI_SUBD_CALIB;
324 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; 178 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
325 s->n_chan = NUM_AO_CHANNELS; 179 s->n_chan = 32;
326 s->insn_read = gain_read_insn; 180 s->maxdata = 0x3fff;
327 s->insn_write = gain_write_insn; 181 s->insn_write = adv_pci1724_insn_write;
328 s->maxdata = 0x3fff; 182 s->private = (void *)PCI1724_DAC_CTRL_MODE_GAIN;
329 183
330 return 0; 184 ret = comedi_alloc_subdev_readback(s);
331} 185 if (ret)
332 186 return ret;
333static int adv_pci1724_auto_attach(struct comedi_device *dev,
334 unsigned long context_unused)
335{
336 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
337 struct adv_pci1724_private *devpriv;
338 int i;
339 int retval;
340 unsigned int board_id;
341
342 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
343 if (!devpriv)
344 return -ENOMEM;
345
346 /* init software copies of output values to indicate we don't know
347 * what the output value is since it has never been written. */
348 for (i = 0; i < NUM_AO_CHANNELS; ++i) {
349 devpriv->ao_value[i] = -1;
350 devpriv->offset_value[i] = -1;
351 devpriv->gain_value[i] = -1;
352 }
353
354 retval = comedi_pci_enable(dev);
355 if (retval)
356 return retval;
357
358 dev->iobase = pci_resource_start(pcidev, 2);
359 board_id = inl(dev->iobase + BOARD_ID_REG) & BOARD_ID_MASK;
360 dev_info(dev->class_dev, "board id: %d\n", board_id);
361
362 retval = setup_subdevices(dev);
363 if (retval < 0)
364 return retval;
365 187
366 dev_info(dev->class_dev, "%s (pci %s) attached, board id: %u\n",
367 dev->board_name, pci_name(pcidev), board_id);
368 return 0; 188 return 0;
369} 189}
370 190
371static struct comedi_driver adv_pci1724_driver = { 191static struct comedi_driver adv_pci1724_driver = {
372 .driver_name = "adv_pci1724", 192 .driver_name = "adv_pci1724",
373 .module = THIS_MODULE, 193 .module = THIS_MODULE,
374 .auto_attach = adv_pci1724_auto_attach, 194 .auto_attach = adv_pci1724_auto_attach,
375 .detach = comedi_pci_detach, 195 .detach = comedi_pci_detach,
376}; 196};
377 197
378static int adv_pci1724_pci_probe(struct pci_dev *dev, 198static int adv_pci1724_pci_probe(struct pci_dev *dev,
@@ -389,12 +209,11 @@ static const struct pci_device_id adv_pci1724_pci_table[] = {
389MODULE_DEVICE_TABLE(pci, adv_pci1724_pci_table); 209MODULE_DEVICE_TABLE(pci, adv_pci1724_pci_table);
390 210
391static struct pci_driver adv_pci1724_pci_driver = { 211static struct pci_driver adv_pci1724_pci_driver = {
392 .name = "adv_pci1724", 212 .name = "adv_pci1724",
393 .id_table = adv_pci1724_pci_table, 213 .id_table = adv_pci1724_pci_table,
394 .probe = adv_pci1724_pci_probe, 214 .probe = adv_pci1724_pci_probe,
395 .remove = comedi_pci_auto_unconfig, 215 .remove = comedi_pci_auto_unconfig,
396}; 216};
397
398module_comedi_pci_driver(adv_pci1724_driver, adv_pci1724_pci_driver); 217module_comedi_pci_driver(adv_pci1724_driver, adv_pci1724_pci_driver);
399 218
400MODULE_AUTHOR("Frank Mori Hess <fmh6jj@gmail.com>"); 219MODULE_AUTHOR("Frank Mori Hess <fmh6jj@gmail.com>");
diff --git a/drivers/staging/comedi/drivers/adv_pci_dio.c b/drivers/staging/comedi/drivers/adv_pci_dio.c
index f2e2d7e163bf..09609d6d02da 100644
--- a/drivers/staging/comedi/drivers/adv_pci_dio.c
+++ b/drivers/staging/comedi/drivers/adv_pci_dio.c
@@ -930,7 +930,7 @@ static int pci1760_attach(struct comedi_device *dev)
930 930
931 s = &dev->subdevices[0]; 931 s = &dev->subdevices[0];
932 s->type = COMEDI_SUBD_DI; 932 s->type = COMEDI_SUBD_DI;
933 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON; 933 s->subdev_flags = SDF_READABLE;
934 s->n_chan = 8; 934 s->n_chan = 8;
935 s->maxdata = 1; 935 s->maxdata = 1;
936 s->len_chanlist = 8; 936 s->len_chanlist = 8;
@@ -939,7 +939,7 @@ static int pci1760_attach(struct comedi_device *dev)
939 939
940 s = &dev->subdevices[1]; 940 s = &dev->subdevices[1];
941 s->type = COMEDI_SUBD_DO; 941 s->type = COMEDI_SUBD_DO;
942 s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON; 942 s->subdev_flags = SDF_WRITABLE;
943 s->n_chan = 8; 943 s->n_chan = 8;
944 s->maxdata = 1; 944 s->maxdata = 1;
945 s->len_chanlist = 8; 945 s->len_chanlist = 8;
@@ -978,7 +978,7 @@ static int pci_dio_add_di(struct comedi_device *dev,
978 const struct dio_boardtype *this_board = dev->board_ptr; 978 const struct dio_boardtype *this_board = dev->board_ptr;
979 979
980 s->type = COMEDI_SUBD_DI; 980 s->type = COMEDI_SUBD_DI;
981 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON | d->specflags; 981 s->subdev_flags = SDF_READABLE | d->specflags;
982 if (d->chans > 16) 982 if (d->chans > 16)
983 s->subdev_flags |= SDF_LSAMPL; 983 s->subdev_flags |= SDF_LSAMPL;
984 s->n_chan = d->chans; 984 s->n_chan = d->chans;
@@ -1008,7 +1008,7 @@ static int pci_dio_add_do(struct comedi_device *dev,
1008 const struct dio_boardtype *this_board = dev->board_ptr; 1008 const struct dio_boardtype *this_board = dev->board_ptr;
1009 1009
1010 s->type = COMEDI_SUBD_DO; 1010 s->type = COMEDI_SUBD_DO;
1011 s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON; 1011 s->subdev_flags = SDF_WRITABLE;
1012 if (d->chans > 16) 1012 if (d->chans > 16)
1013 s->subdev_flags |= SDF_LSAMPL; 1013 s->subdev_flags |= SDF_LSAMPL;
1014 s->n_chan = d->chans; 1014 s->n_chan = d->chans;
diff --git a/drivers/staging/comedi/drivers/aio_aio12_8.c b/drivers/staging/comedi/drivers/aio_aio12_8.c
index 538277a691b2..fbc3e5aa94cb 100644
--- a/drivers/staging/comedi/drivers/aio_aio12_8.c
+++ b/drivers/staging/comedi/drivers/aio_aio12_8.c
@@ -212,7 +212,6 @@ static int aio_aio12_8_attach(struct comedi_device *dev,
212 s->maxdata = 0x0fff; 212 s->maxdata = 0x0fff;
213 s->range_table = &range_aio_aio12_8; 213 s->range_table = &range_aio_aio12_8;
214 s->insn_write = aio_aio12_8_ao_insn_write; 214 s->insn_write = aio_aio12_8_ao_insn_write;
215 s->insn_read = comedi_readback_insn_read;
216 215
217 ret = comedi_alloc_subdev_readback(s); 216 ret = comedi_alloc_subdev_readback(s);
218 if (ret) 217 if (ret)
diff --git a/drivers/staging/comedi/drivers/amcc_s5933.h b/drivers/staging/comedi/drivers/amcc_s5933.h
index cf6a497b092c..d4b8c0195bd3 100644
--- a/drivers/staging/comedi/drivers/amcc_s5933.h
+++ b/drivers/staging/comedi/drivers/amcc_s5933.h
@@ -110,6 +110,8 @@
110#define AGCSTS_TCZERO_MASK 0x000000c0 110#define AGCSTS_TCZERO_MASK 0x000000c0
111#define AGCSTS_FIFO_ST_MASK 0x0000003f 111#define AGCSTS_FIFO_ST_MASK 0x0000003f
112 112
113#define AGCSTS_TC_ENABLE 0x10000000
114
113#define AGCSTS_RESET_MBFLAGS 0x08000000 115#define AGCSTS_RESET_MBFLAGS 0x08000000
114#define AGCSTS_RESET_P2A_FIFO 0x04000000 116#define AGCSTS_RESET_P2A_FIFO 0x04000000
115#define AGCSTS_RESET_A2P_FIFO 0x02000000 117#define AGCSTS_RESET_A2P_FIFO 0x02000000
diff --git a/drivers/staging/comedi/drivers/amplc_dio200_common.c b/drivers/staging/comedi/drivers/amplc_dio200_common.c
index 2c1bfb09601d..26aad705aad3 100644
--- a/drivers/staging/comedi/drivers/amplc_dio200_common.c
+++ b/drivers/staging/comedi/drivers/amplc_dio200_common.c
@@ -120,7 +120,6 @@ struct dio200_subdev_intr {
120 unsigned int ofs; 120 unsigned int ofs;
121 unsigned int valid_isns; 121 unsigned int valid_isns;
122 unsigned int enabled_isns; 122 unsigned int enabled_isns;
123 unsigned int stopcount;
124 bool active:1; 123 bool active:1;
125}; 124};
126 125
@@ -256,7 +255,6 @@ static void dio200_read_scan_intr(struct comedi_device *dev,
256 struct comedi_subdevice *s, 255 struct comedi_subdevice *s,
257 unsigned int triggered) 256 unsigned int triggered)
258{ 257{
259 struct dio200_subdev_intr *subpriv = s->private;
260 struct comedi_cmd *cmd = &s->async->cmd; 258 struct comedi_cmd *cmd = &s->async->cmd;
261 unsigned short val; 259 unsigned short val;
262 unsigned int n, ch; 260 unsigned int n, ch;
@@ -267,26 +265,12 @@ static void dio200_read_scan_intr(struct comedi_device *dev,
267 if (triggered & (1U << ch)) 265 if (triggered & (1U << ch))
268 val |= (1U << n); 266 val |= (1U << n);
269 } 267 }
270 /* Write the scan to the buffer. */
271 if (comedi_buf_put(s, val)) {
272 s->async->events |= (COMEDI_CB_BLOCK | COMEDI_CB_EOS);
273 } else {
274 /* Error! Stop acquisition. */
275 dio200_stop_intr(dev, s);
276 s->async->events |= COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW;
277 dev_err(dev->class_dev, "buffer overflow\n");
278 }
279 268
280 /* Check for end of acquisition. */ 269 comedi_buf_write_samples(s, &val, 1);
281 if (cmd->stop_src == TRIG_COUNT) { 270
282 if (subpriv->stopcount > 0) { 271 if (cmd->stop_src == TRIG_COUNT &&
283 subpriv->stopcount--; 272 s->async->scans_done >= cmd->stop_arg)
284 if (subpriv->stopcount == 0) { 273 s->async->events |= COMEDI_CB_EOA;
285 s->async->events |= COMEDI_CB_EOA;
286 dio200_stop_intr(dev, s);
287 }
288 }
289 }
290} 274}
291 275
292static int dio200_handle_read_intr(struct comedi_device *dev, 276static int dio200_handle_read_intr(struct comedi_device *dev,
@@ -297,13 +281,11 @@ static int dio200_handle_read_intr(struct comedi_device *dev,
297 unsigned triggered; 281 unsigned triggered;
298 unsigned intstat; 282 unsigned intstat;
299 unsigned cur_enabled; 283 unsigned cur_enabled;
300 unsigned int oldevents;
301 unsigned long flags; 284 unsigned long flags;
302 285
303 triggered = 0; 286 triggered = 0;
304 287
305 spin_lock_irqsave(&subpriv->spinlock, flags); 288 spin_lock_irqsave(&subpriv->spinlock, flags);
306 oldevents = s->async->events;
307 if (board->has_int_sce) { 289 if (board->has_int_sce) {
308 /* 290 /*
309 * Collect interrupt sources that have triggered and disable 291 * Collect interrupt sources that have triggered and disable
@@ -356,8 +338,7 @@ static int dio200_handle_read_intr(struct comedi_device *dev,
356 } 338 }
357 spin_unlock_irqrestore(&subpriv->spinlock, flags); 339 spin_unlock_irqrestore(&subpriv->spinlock, flags);
358 340
359 if (oldevents != s->async->events) 341 comedi_handle_events(dev, s);
360 comedi_event(dev, s);
361 342
362 return (triggered != 0); 343 return (triggered != 0);
363} 344}
@@ -436,7 +417,6 @@ static int dio200_subdev_intr_cmd(struct comedi_device *dev,
436 spin_lock_irqsave(&subpriv->spinlock, flags); 417 spin_lock_irqsave(&subpriv->spinlock, flags);
437 418
438 subpriv->active = true; 419 subpriv->active = true;
439 subpriv->stopcount = cmd->stop_arg;
440 420
441 if (cmd->start_src == TRIG_INT) 421 if (cmd->start_src == TRIG_INT)
442 s->async->inttrig = dio200_inttrig_start_intr; 422 s->async->inttrig = dio200_inttrig_start_intr;
@@ -469,7 +449,7 @@ static int dio200_subdev_intr_init(struct comedi_device *dev,
469 dio200_write8(dev, subpriv->ofs, 0); 449 dio200_write8(dev, subpriv->ofs, 0);
470 450
471 s->type = COMEDI_SUBD_DI; 451 s->type = COMEDI_SUBD_DI;
472 s->subdev_flags = SDF_READABLE | SDF_CMD_READ; 452 s->subdev_flags = SDF_READABLE | SDF_CMD_READ | SDF_PACKED;
473 if (board->has_int_sce) { 453 if (board->has_int_sce) {
474 s->n_chan = DIO200_MAX_ISNS; 454 s->n_chan = DIO200_MAX_ISNS;
475 s->len_chanlist = DIO200_MAX_ISNS; 455 s->len_chanlist = DIO200_MAX_ISNS;
diff --git a/drivers/staging/comedi/drivers/amplc_pc236_common.c b/drivers/staging/comedi/drivers/amplc_pc236_common.c
index 963c5d868b81..be87172d1f3f 100644
--- a/drivers/staging/comedi/drivers/amplc_pc236_common.c
+++ b/drivers/staging/comedi/drivers/amplc_pc236_common.c
@@ -135,9 +135,8 @@ static irqreturn_t pc236_interrupt(int irq, void *d)
135 135
136 handled = pc236_intr_check(dev); 136 handled = pc236_intr_check(dev);
137 if (dev->attached && handled) { 137 if (dev->attached && handled) {
138 comedi_buf_put(s, 0); 138 comedi_buf_write_samples(s, &s->state, 1);
139 s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOS; 139 comedi_handle_events(dev, s);
140 comedi_event(dev, s);
141 } 140 }
142 return IRQ_RETVAL(handled); 141 return IRQ_RETVAL(handled);
143} 142}
diff --git a/drivers/staging/comedi/drivers/amplc_pc263.c b/drivers/staging/comedi/drivers/amplc_pc263.c
index f8e551d8fd9e..b1946ce6ecc1 100644
--- a/drivers/staging/comedi/drivers/amplc_pc263.c
+++ b/drivers/staging/comedi/drivers/amplc_pc263.c
@@ -83,7 +83,7 @@ static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it)
83 s = &dev->subdevices[0]; 83 s = &dev->subdevices[0];
84 /* digital output subdevice */ 84 /* digital output subdevice */
85 s->type = COMEDI_SUBD_DO; 85 s->type = COMEDI_SUBD_DO;
86 s->subdev_flags = SDF_READABLE | SDF_WRITABLE; 86 s->subdev_flags = SDF_WRITABLE;
87 s->n_chan = 16; 87 s->n_chan = 16;
88 s->maxdata = 1; 88 s->maxdata = 1;
89 s->range_table = &range_digital; 89 s->range_table = &range_digital;
diff --git a/drivers/staging/comedi/drivers/amplc_pci224.c b/drivers/staging/comedi/drivers/amplc_pci224.c
index 3bbbb57f19d6..924c8298c7a0 100644
--- a/drivers/staging/comedi/drivers/amplc_pci224.c
+++ b/drivers/staging/comedi/drivers/amplc_pci224.c
@@ -381,7 +381,6 @@ struct pci224_private {
381 unsigned short daccon; 381 unsigned short daccon;
382 unsigned int cached_div1; 382 unsigned int cached_div1;
383 unsigned int cached_div2; 383 unsigned int cached_div2;
384 unsigned int ao_stop_count;
385 unsigned short ao_enab; /* max 16 channels so 'short' will do */ 384 unsigned short ao_enab; /* max 16 channels so 'short' will do */
386 unsigned char intsce; 385 unsigned char intsce;
387}; 386};
@@ -514,30 +513,21 @@ static void pci224_ao_handle_fifo(struct comedi_device *dev,
514{ 513{
515 struct pci224_private *devpriv = dev->private; 514 struct pci224_private *devpriv = dev->private;
516 struct comedi_cmd *cmd = &s->async->cmd; 515 struct comedi_cmd *cmd = &s->async->cmd;
517 unsigned int bytes_per_scan = cfc_bytes_per_scan(s); 516 unsigned int num_scans = comedi_nscans_left(s, 0);
518 unsigned int num_scans;
519 unsigned int room; 517 unsigned int room;
520 unsigned short dacstat; 518 unsigned short dacstat;
521 unsigned int i, n; 519 unsigned int i, n;
522 520
523 /* Determine number of scans available in buffer. */
524 num_scans = comedi_buf_read_n_available(s) / bytes_per_scan;
525 if (cmd->stop_src == TRIG_COUNT) {
526 /* Fixed number of scans. */
527 if (num_scans > devpriv->ao_stop_count)
528 num_scans = devpriv->ao_stop_count;
529 }
530
531 /* Determine how much room is in the FIFO (in samples). */ 521 /* Determine how much room is in the FIFO (in samples). */
532 dacstat = inw(dev->iobase + PCI224_DACCON); 522 dacstat = inw(dev->iobase + PCI224_DACCON);
533 switch (dacstat & PCI224_DACCON_FIFOFL_MASK) { 523 switch (dacstat & PCI224_DACCON_FIFOFL_MASK) {
534 case PCI224_DACCON_FIFOFL_EMPTY: 524 case PCI224_DACCON_FIFOFL_EMPTY:
535 room = PCI224_FIFO_ROOM_EMPTY; 525 room = PCI224_FIFO_ROOM_EMPTY;
536 if (cmd->stop_src == TRIG_COUNT && 526 if (cmd->stop_src == TRIG_COUNT &&
537 devpriv->ao_stop_count == 0) { 527 s->async->scans_done >= cmd->stop_arg) {
538 /* FIFO empty at end of counted acquisition. */ 528 /* FIFO empty at end of counted acquisition. */
539 s->async->events |= COMEDI_CB_EOA; 529 s->async->events |= COMEDI_CB_EOA;
540 cfc_handle_events(dev, s); 530 comedi_handle_events(dev, s);
541 return; 531 return;
542 } 532 }
543 break; 533 break;
@@ -568,25 +558,23 @@ static void pci224_ao_handle_fifo(struct comedi_device *dev,
568 558
569 /* Process scans. */ 559 /* Process scans. */
570 for (n = 0; n < num_scans; n++) { 560 for (n = 0; n < num_scans; n++) {
571 cfc_read_array_from_buffer(s, &devpriv->ao_scan_vals[0], 561 comedi_buf_read_samples(s, &devpriv->ao_scan_vals[0],
572 bytes_per_scan); 562 cmd->chanlist_len);
573 for (i = 0; i < cmd->chanlist_len; i++) { 563 for (i = 0; i < cmd->chanlist_len; i++) {
574 outw(devpriv->ao_scan_vals[devpriv->ao_scan_order[i]], 564 outw(devpriv->ao_scan_vals[devpriv->ao_scan_order[i]],
575 dev->iobase + PCI224_DACDATA); 565 dev->iobase + PCI224_DACDATA);
576 } 566 }
577 } 567 }
578 if (cmd->stop_src == TRIG_COUNT) { 568 if (cmd->stop_src == TRIG_COUNT &&
579 devpriv->ao_stop_count -= num_scans; 569 s->async->scans_done >= cmd->stop_arg) {
580 if (devpriv->ao_stop_count == 0) { 570 /*
581 /* 571 * Change FIFO interrupt trigger level to wait
582 * Change FIFO interrupt trigger level to wait 572 * until FIFO is empty.
583 * until FIFO is empty. 573 */
584 */ 574 devpriv->daccon = COMBINE(devpriv->daccon,
585 devpriv->daccon = COMBINE(devpriv->daccon, 575 PCI224_DACCON_FIFOINTR_EMPTY,
586 PCI224_DACCON_FIFOINTR_EMPTY, 576 PCI224_DACCON_FIFOINTR_MASK);
587 PCI224_DACCON_FIFOINTR_MASK); 577 outw(devpriv->daccon, dev->iobase + PCI224_DACCON);
588 outw(devpriv->daccon, dev->iobase + PCI224_DACCON);
589 }
590 } 578 }
591 if ((devpriv->daccon & PCI224_DACCON_TRIG_MASK) == 579 if ((devpriv->daccon & PCI224_DACCON_TRIG_MASK) ==
592 PCI224_DACCON_TRIG_NONE) { 580 PCI224_DACCON_TRIG_NONE) {
@@ -618,7 +606,7 @@ static void pci224_ao_handle_fifo(struct comedi_device *dev,
618 outw(devpriv->daccon, dev->iobase + PCI224_DACCON); 606 outw(devpriv->daccon, dev->iobase + PCI224_DACCON);
619 } 607 }
620 608
621 cfc_handle_events(dev, s); 609 comedi_handle_events(dev, s);
622} 610}
623 611
624static int pci224_ao_inttrig_start(struct comedi_device *dev, 612static int pci224_ao_inttrig_start(struct comedi_device *dev,
@@ -908,14 +896,6 @@ static int pci224_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
908 if (cmd->scan_begin_src == TRIG_TIMER) 896 if (cmd->scan_begin_src == TRIG_TIMER)
909 pci224_ao_start_pacer(dev, s); 897 pci224_ao_start_pacer(dev, s);
910 898
911 /*
912 * Sort out end of acquisition.
913 */
914 if (cmd->stop_src == TRIG_COUNT)
915 devpriv->ao_stop_count = cmd->stop_arg;
916 else /* TRIG_EXT | TRIG_NONE */
917 devpriv->ao_stop_count = 0;
918
919 spin_lock_irqsave(&devpriv->ao_spinlock, flags); 899 spin_lock_irqsave(&devpriv->ao_spinlock, flags);
920 if (cmd->start_src == TRIG_INT) { 900 if (cmd->start_src == TRIG_INT) {
921 s->async->inttrig = pci224_ao_inttrig_start; 901 s->async->inttrig = pci224_ao_inttrig_start;
@@ -1095,7 +1075,6 @@ pci224_auto_attach(struct comedi_device *dev, unsigned long context_model)
1095 s->maxdata = (1 << thisboard->ao_bits) - 1; 1075 s->maxdata = (1 << thisboard->ao_bits) - 1;
1096 s->range_table = thisboard->ao_range; 1076 s->range_table = thisboard->ao_range;
1097 s->insn_write = pci224_ao_insn_write; 1077 s->insn_write = pci224_ao_insn_write;
1098 s->insn_read = comedi_readback_insn_read;
1099 s->len_chanlist = s->n_chan; 1078 s->len_chanlist = s->n_chan;
1100 dev->write_subdev = s; 1079 dev->write_subdev = s;
1101 s->do_cmd = pci224_ao_cmd; 1080 s->do_cmd = pci224_ao_cmd;
diff --git a/drivers/staging/comedi/drivers/amplc_pci230.c b/drivers/staging/comedi/drivers/amplc_pci230.c
index 01796cd28e5b..49806a5e514c 100644
--- a/drivers/staging/comedi/drivers/amplc_pci230.c
+++ b/drivers/staging/comedi/drivers/amplc_pci230.c
@@ -35,7 +35,7 @@
35 * automatically. 35 * automatically.
36 * 36 *
37 * The PCI230+ and PCI260+ have the same PCI device IDs as the PCI230 and 37 * The PCI230+ and PCI260+ have the same PCI device IDs as the PCI230 and
38 * PCI260, but can be distinguished by the the size of the PCI regions. A 38 * PCI260, but can be distinguished by the size of the PCI regions. A
39 * card will be configured as a "+" model if detected as such. 39 * card will be configured as a "+" model if detected as such.
40 * 40 *
41 * Subdevices: 41 * Subdevices:
@@ -490,9 +490,6 @@ struct pci230_private {
490 spinlock_t ai_stop_spinlock; /* Spin lock for stopping AI command */ 490 spinlock_t ai_stop_spinlock; /* Spin lock for stopping AI command */
491 spinlock_t ao_stop_spinlock; /* Spin lock for stopping AO command */ 491 spinlock_t ao_stop_spinlock; /* Spin lock for stopping AO command */
492 unsigned long daqio; /* PCI230's DAQ I/O space */ 492 unsigned long daqio; /* PCI230's DAQ I/O space */
493 unsigned int ai_scan_count; /* Number of AI scans remaining */
494 unsigned int ai_scan_pos; /* Current position within AI scan */
495 unsigned int ao_scan_count; /* Number of AO scans remaining. */
496 int intr_cpuid; /* ID of CPU running ISR */ 493 int intr_cpuid; /* ID of CPU running ISR */
497 unsigned short hwver; /* Hardware version (for '+' models) */ 494 unsigned short hwver; /* Hardware version (for '+' models) */
498 unsigned short adccon; /* ADCCON register value */ 495 unsigned short adccon; /* ADCCON register value */
@@ -1074,37 +1071,27 @@ static void pci230_ao_stop(struct comedi_device *dev,
1074static void pci230_handle_ao_nofifo(struct comedi_device *dev, 1071static void pci230_handle_ao_nofifo(struct comedi_device *dev,
1075 struct comedi_subdevice *s) 1072 struct comedi_subdevice *s)
1076{ 1073{
1077 struct pci230_private *devpriv = dev->private;
1078 unsigned short data;
1079 int i, ret;
1080 struct comedi_async *async = s->async; 1074 struct comedi_async *async = s->async;
1081 struct comedi_cmd *cmd = &async->cmd; 1075 struct comedi_cmd *cmd = &async->cmd;
1076 unsigned short data;
1077 int i;
1082 1078
1083 if (cmd->stop_src == TRIG_COUNT && devpriv->ao_scan_count == 0) 1079 if (cmd->stop_src == TRIG_COUNT && async->scans_done >= cmd->stop_arg)
1084 return; 1080 return;
1081
1085 for (i = 0; i < cmd->chanlist_len; i++) { 1082 for (i = 0; i < cmd->chanlist_len; i++) {
1086 unsigned int chan = CR_CHAN(cmd->chanlist[i]); 1083 unsigned int chan = CR_CHAN(cmd->chanlist[i]);
1087 1084
1088 /* Read sample from Comedi's circular buffer. */ 1085 if (!comedi_buf_read_samples(s, &data, 1)) {
1089 ret = comedi_buf_get(s, &data); 1086 async->events |= COMEDI_CB_OVERFLOW;
1090 if (ret == 0) {
1091 s->async->events |= COMEDI_CB_OVERFLOW;
1092 pci230_ao_stop(dev, s);
1093 dev_err(dev->class_dev, "AO buffer underrun\n");
1094 return; 1087 return;
1095 } 1088 }
1096 pci230_ao_write_nofifo(dev, data, chan); 1089 pci230_ao_write_nofifo(dev, data, chan);
1097 s->readback[chan] = data; 1090 s->readback[chan] = data;
1098 } 1091 }
1099 async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOS; 1092
1100 if (cmd->stop_src == TRIG_COUNT) { 1093 if (cmd->stop_src == TRIG_COUNT && async->scans_done >= cmd->stop_arg)
1101 devpriv->ao_scan_count--; 1094 async->events |= COMEDI_CB_EOA;
1102 if (devpriv->ao_scan_count == 0) {
1103 /* End of acquisition. */
1104 async->events |= COMEDI_CB_EOA;
1105 pci230_ao_stop(dev, s);
1106 }
1107 }
1108} 1095}
1109 1096
1110/* 1097/*
@@ -1117,26 +1104,18 @@ static bool pci230_handle_ao_fifo(struct comedi_device *dev,
1117 struct pci230_private *devpriv = dev->private; 1104 struct pci230_private *devpriv = dev->private;
1118 struct comedi_async *async = s->async; 1105 struct comedi_async *async = s->async;
1119 struct comedi_cmd *cmd = &async->cmd; 1106 struct comedi_cmd *cmd = &async->cmd;
1120 unsigned int num_scans; 1107 unsigned int num_scans = comedi_nscans_left(s, 0);
1121 unsigned int room; 1108 unsigned int room;
1122 unsigned short dacstat; 1109 unsigned short dacstat;
1123 unsigned int i, n; 1110 unsigned int i, n;
1124 unsigned int events = 0; 1111 unsigned int events = 0;
1125 bool running;
1126 1112
1127 /* Get DAC FIFO status. */ 1113 /* Get DAC FIFO status. */
1128 dacstat = inw(devpriv->daqio + PCI230_DACCON); 1114 dacstat = inw(devpriv->daqio + PCI230_DACCON);
1129 /* Determine number of scans available in buffer. */ 1115
1130 num_scans = comedi_buf_read_n_available(s) / cfc_bytes_per_scan(s); 1116 if (cmd->stop_src == TRIG_COUNT && num_scans == 0)
1131 if (cmd->stop_src == TRIG_COUNT) { 1117 events |= COMEDI_CB_EOA;
1132 /* Fixed number of scans. */ 1118
1133 if (num_scans > devpriv->ao_scan_count)
1134 num_scans = devpriv->ao_scan_count;
1135 if (devpriv->ao_scan_count == 0) {
1136 /* End of acquisition. */
1137 events |= COMEDI_CB_EOA;
1138 }
1139 }
1140 if (events == 0) { 1119 if (events == 0) {
1141 /* Check for FIFO underrun. */ 1120 /* Check for FIFO underrun. */
1142 if (dacstat & PCI230P2_DAC_FIFO_UNDERRUN_LATCHED) { 1121 if (dacstat & PCI230P2_DAC_FIFO_UNDERRUN_LATCHED) {
@@ -1175,27 +1154,22 @@ static bool pci230_handle_ao_fifo(struct comedi_device *dev,
1175 unsigned int chan = CR_CHAN(cmd->chanlist[i]); 1154 unsigned int chan = CR_CHAN(cmd->chanlist[i]);
1176 unsigned short datum; 1155 unsigned short datum;
1177 1156
1178 comedi_buf_get(s, &datum); 1157 comedi_buf_read_samples(s, &datum, 1);
1179 pci230_ao_write_fifo(dev, datum, chan); 1158 pci230_ao_write_fifo(dev, datum, chan);
1180 s->readback[chan] = datum; 1159 s->readback[chan] = datum;
1181 } 1160 }
1182 } 1161 }
1183 events |= COMEDI_CB_EOS | COMEDI_CB_BLOCK; 1162
1184 if (cmd->stop_src == TRIG_COUNT) { 1163 if (cmd->stop_src == TRIG_COUNT &&
1185 devpriv->ao_scan_count -= num_scans; 1164 async->scans_done >= cmd->stop_arg) {
1186 if (devpriv->ao_scan_count == 0) { 1165 /*
1187 /* 1166 * All data for the command has been written
1188 * All data for the command has been written 1167 * to FIFO. Set FIFO interrupt trigger level
1189 * to FIFO. Set FIFO interrupt trigger level 1168 * to 'empty'.
1190 * to 'empty'. 1169 */
1191 */ 1170 devpriv->daccon &= ~PCI230P2_DAC_INT_FIFO_MASK;
1192 devpriv->daccon = 1171 devpriv->daccon |= PCI230P2_DAC_INT_FIFO_EMPTY;
1193 (devpriv->daccon & 1172 outw(devpriv->daccon, devpriv->daqio + PCI230_DACCON);
1194 ~PCI230P2_DAC_INT_FIFO_MASK) |
1195 PCI230P2_DAC_INT_FIFO_EMPTY;
1196 outw(devpriv->daccon,
1197 devpriv->daqio + PCI230_DACCON);
1198 }
1199 } 1173 }
1200 /* Check if FIFO underrun occurred while writing to FIFO. */ 1174 /* Check if FIFO underrun occurred while writing to FIFO. */
1201 dacstat = inw(devpriv->daqio + PCI230_DACCON); 1175 dacstat = inw(devpriv->daqio + PCI230_DACCON);
@@ -1204,15 +1178,8 @@ static bool pci230_handle_ao_fifo(struct comedi_device *dev,
1204 events |= COMEDI_CB_OVERFLOW | COMEDI_CB_ERROR; 1178 events |= COMEDI_CB_OVERFLOW | COMEDI_CB_ERROR;
1205 } 1179 }
1206 } 1180 }
1207 if (events & (COMEDI_CB_EOA | COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW)) {
1208 /* Stopping AO due to completion or error. */
1209 pci230_ao_stop(dev, s);
1210 running = false;
1211 } else {
1212 running = true;
1213 }
1214 async->events |= events; 1181 async->events |= events;
1215 return running; 1182 return !(async->events & COMEDI_CB_CANCEL_MASK);
1216} 1183}
1217 1184
1218static int pci230_ao_inttrig_scan_begin(struct comedi_device *dev, 1185static int pci230_ao_inttrig_scan_begin(struct comedi_device *dev,
@@ -1235,7 +1202,7 @@ static int pci230_ao_inttrig_scan_begin(struct comedi_device *dev,
1235 /* Not using DAC FIFO. */ 1202 /* Not using DAC FIFO. */
1236 spin_unlock_irqrestore(&devpriv->ao_stop_spinlock, irqflags); 1203 spin_unlock_irqrestore(&devpriv->ao_stop_spinlock, irqflags);
1237 pci230_handle_ao_nofifo(dev, s); 1204 pci230_handle_ao_nofifo(dev, s);
1238 comedi_event(dev, s); 1205 comedi_handle_events(dev, s);
1239 } else { 1206 } else {
1240 /* Using DAC FIFO. */ 1207 /* Using DAC FIFO. */
1241 /* Read DACSWTRIG register to trigger conversion. */ 1208 /* Read DACSWTRIG register to trigger conversion. */
@@ -1265,7 +1232,7 @@ static void pci230_ao_start(struct comedi_device *dev,
1265 1232
1266 /* Preload FIFO data. */ 1233 /* Preload FIFO data. */
1267 run = pci230_handle_ao_fifo(dev, s); 1234 run = pci230_handle_ao_fifo(dev, s);
1268 comedi_event(dev, s); 1235 comedi_handle_events(dev, s);
1269 if (!run) { 1236 if (!run) {
1270 /* Stopped. */ 1237 /* Stopped. */
1271 return; 1238 return;
@@ -1354,8 +1321,6 @@ static int pci230_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
1354 return -EBUSY; 1321 return -EBUSY;
1355 } 1322 }
1356 1323
1357 devpriv->ao_scan_count = cmd->stop_arg;
1358
1359 /* 1324 /*
1360 * Set range - see analogue output range table; 0 => unipolar 10V, 1325 * Set range - see analogue output range table; 0 => unipolar 10V,
1361 * 1 => bipolar +/-10V range scale 1326 * 1 => bipolar +/-10V range scale
@@ -1754,19 +1719,15 @@ static void pci230_ai_update_fifo_trigger_level(struct comedi_device *dev,
1754{ 1719{
1755 struct pci230_private *devpriv = dev->private; 1720 struct pci230_private *devpriv = dev->private;
1756 struct comedi_cmd *cmd = &s->async->cmd; 1721 struct comedi_cmd *cmd = &s->async->cmd;
1757 unsigned int scanlen = cmd->scan_end_arg;
1758 unsigned int wake; 1722 unsigned int wake;
1759 unsigned short triglev; 1723 unsigned short triglev;
1760 unsigned short adccon; 1724 unsigned short adccon;
1761 1725
1762 if (cmd->flags & CMDF_WAKE_EOS) 1726 if (cmd->flags & CMDF_WAKE_EOS)
1763 wake = scanlen - devpriv->ai_scan_pos; 1727 wake = cmd->scan_end_arg - s->async->cur_chan;
1764 else if (cmd->stop_src != TRIG_COUNT ||
1765 devpriv->ai_scan_count >= PCI230_ADC_FIFOLEVEL_HALFFULL ||
1766 scanlen >= PCI230_ADC_FIFOLEVEL_HALFFULL)
1767 wake = PCI230_ADC_FIFOLEVEL_HALFFULL;
1768 else 1728 else
1769 wake = devpriv->ai_scan_count * scanlen - devpriv->ai_scan_pos; 1729 wake = comedi_nsamples_left(s, PCI230_ADC_FIFOLEVEL_HALFFULL);
1730
1770 if (wake >= PCI230_ADC_FIFOLEVEL_HALFFULL) { 1731 if (wake >= PCI230_ADC_FIFOLEVEL_HALFFULL) {
1771 triglev = PCI230_ADC_INT_FIFO_HALF; 1732 triglev = PCI230_ADC_INT_FIFO_HALF;
1772 } else if (wake > 1 && devpriv->hwver > 0) { 1733 } else if (wake > 1 && devpriv->hwver > 0) {
@@ -2059,28 +2020,17 @@ static void pci230_handle_ai(struct comedi_device *dev,
2059 struct pci230_private *devpriv = dev->private; 2020 struct pci230_private *devpriv = dev->private;
2060 struct comedi_async *async = s->async; 2021 struct comedi_async *async = s->async;
2061 struct comedi_cmd *cmd = &async->cmd; 2022 struct comedi_cmd *cmd = &async->cmd;
2062 unsigned int scanlen = cmd->scan_end_arg;
2063 unsigned int events = 0;
2064 unsigned int status_fifo; 2023 unsigned int status_fifo;
2065 unsigned int i; 2024 unsigned int i;
2066 unsigned int todo; 2025 unsigned int todo;
2067 unsigned int fifoamount; 2026 unsigned int fifoamount;
2027 unsigned short val;
2068 2028
2069 /* Determine number of samples to read. */ 2029 /* Determine number of samples to read. */
2070 if (cmd->stop_src != TRIG_COUNT) { 2030 todo = comedi_nsamples_left(s, PCI230_ADC_FIFOLEVEL_HALFFULL);
2071 todo = PCI230_ADC_FIFOLEVEL_HALFFULL;
2072 } else if (devpriv->ai_scan_count == 0) {
2073 todo = 0;
2074 } else if (devpriv->ai_scan_count > PCI230_ADC_FIFOLEVEL_HALFFULL ||
2075 scanlen > PCI230_ADC_FIFOLEVEL_HALFFULL) {
2076 todo = PCI230_ADC_FIFOLEVEL_HALFFULL;
2077 } else {
2078 todo = devpriv->ai_scan_count * scanlen - devpriv->ai_scan_pos;
2079 if (todo > PCI230_ADC_FIFOLEVEL_HALFFULL)
2080 todo = PCI230_ADC_FIFOLEVEL_HALFFULL;
2081 }
2082 if (todo == 0) 2031 if (todo == 0)
2083 return; 2032 return;
2033
2084 fifoamount = 0; 2034 fifoamount = 0;
2085 for (i = 0; i < todo; i++) { 2035 for (i = 0; i < todo; i++) {
2086 if (fifoamount == 0) { 2036 if (fifoamount == 0) {
@@ -2092,7 +2042,7 @@ static void pci230_handle_ai(struct comedi_device *dev,
2092 * unnoticed by the caller. 2042 * unnoticed by the caller.
2093 */ 2043 */
2094 dev_err(dev->class_dev, "AI FIFO overrun\n"); 2044 dev_err(dev->class_dev, "AI FIFO overrun\n");
2095 events |= COMEDI_CB_OVERFLOW | COMEDI_CB_ERROR; 2045 async->events |= COMEDI_CB_ERROR;
2096 break; 2046 break;
2097 } else if (status_fifo & PCI230_ADC_FIFO_EMPTY) { 2047 } else if (status_fifo & PCI230_ADC_FIFO_EMPTY) {
2098 /* FIFO empty. */ 2048 /* FIFO empty. */
@@ -2111,37 +2061,23 @@ static void pci230_handle_ai(struct comedi_device *dev,
2111 fifoamount = 1; 2061 fifoamount = 1;
2112 } 2062 }
2113 } 2063 }
2114 /* Read sample and store in Comedi's circular buffer. */ 2064
2115 if (comedi_buf_put(s, pci230_ai_read(dev)) == 0) { 2065 val = pci230_ai_read(dev);
2116 events |= COMEDI_CB_ERROR | COMEDI_CB_OVERFLOW; 2066 if (!comedi_buf_write_samples(s, &val, 1))
2117 dev_err(dev->class_dev, "AI buffer overflow\n");
2118 break; 2067 break;
2119 } 2068
2120 fifoamount--; 2069 fifoamount--;
2121 devpriv->ai_scan_pos++; 2070
2122 if (devpriv->ai_scan_pos == scanlen) { 2071 if (cmd->stop_src == TRIG_COUNT &&
2123 /* End of scan. */ 2072 async->scans_done >= cmd->stop_arg) {
2124 devpriv->ai_scan_pos = 0; 2073 async->events |= COMEDI_CB_EOA;
2125 devpriv->ai_scan_count--; 2074 break;
2126 async->events |= COMEDI_CB_EOS;
2127 } 2075 }
2128 } 2076 }
2129 if (cmd->stop_src == TRIG_COUNT && devpriv->ai_scan_count == 0) { 2077
2130 /* End of acquisition. */ 2078 /* update FIFO interrupt trigger level if still running */
2131 events |= COMEDI_CB_EOA; 2079 if (!(async->events & COMEDI_CB_CANCEL_MASK))
2132 } else {
2133 /* More samples required, tell Comedi to block. */
2134 events |= COMEDI_CB_BLOCK;
2135 }
2136 async->events |= events;
2137 if (async->events & (COMEDI_CB_EOA | COMEDI_CB_ERROR |
2138 COMEDI_CB_OVERFLOW)) {
2139 /* disable hardware conversions */
2140 pci230_ai_stop(dev, s);
2141 } else {
2142 /* update FIFO interrupt trigger level */
2143 pci230_ai_update_fifo_trigger_level(dev, s); 2080 pci230_ai_update_fifo_trigger_level(dev, s);
2144 }
2145} 2081}
2146 2082
2147static int pci230_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) 2083static int pci230_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
@@ -2177,9 +2113,6 @@ static int pci230_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
2177 if (!pci230_claim_shared(dev, res_mask, OWNER_AICMD)) 2113 if (!pci230_claim_shared(dev, res_mask, OWNER_AICMD))
2178 return -EBUSY; 2114 return -EBUSY;
2179 2115
2180 devpriv->ai_scan_count = cmd->stop_arg;
2181 devpriv->ai_scan_pos = 0; /* Position within scan. */
2182
2183 /* 2116 /*
2184 * Steps: 2117 * Steps:
2185 * - Set channel scan list. 2118 * - Set channel scan list.
@@ -2355,7 +2288,8 @@ static irqreturn_t pci230_interrupt(int irq, void *d)
2355 unsigned char status_int, valid_status_int, temp_ier; 2288 unsigned char status_int, valid_status_int, temp_ier;
2356 struct comedi_device *dev = (struct comedi_device *)d; 2289 struct comedi_device *dev = (struct comedi_device *)d;
2357 struct pci230_private *devpriv = dev->private; 2290 struct pci230_private *devpriv = dev->private;
2358 struct comedi_subdevice *s; 2291 struct comedi_subdevice *s_ao = dev->write_subdev;
2292 struct comedi_subdevice *s_ai = dev->read_subdev;
2359 unsigned long irqflags; 2293 unsigned long irqflags;
2360 2294
2361 /* Read interrupt status/enable register. */ 2295 /* Read interrupt status/enable register. */
@@ -2385,23 +2319,14 @@ static irqreturn_t pci230_interrupt(int irq, void *d)
2385 * two. 2319 * two.
2386 */ 2320 */
2387 2321
2388 if (valid_status_int & PCI230_INT_ZCLK_CT1) { 2322 if (valid_status_int & PCI230_INT_ZCLK_CT1)
2389 s = dev->write_subdev; 2323 pci230_handle_ao_nofifo(dev, s_ao);
2390 pci230_handle_ao_nofifo(dev, s);
2391 comedi_event(dev, s);
2392 }
2393 2324
2394 if (valid_status_int & PCI230P2_INT_DAC) { 2325 if (valid_status_int & PCI230P2_INT_DAC)
2395 s = dev->write_subdev; 2326 pci230_handle_ao_fifo(dev, s_ao);
2396 pci230_handle_ao_fifo(dev, s);
2397 comedi_event(dev, s);
2398 }
2399 2327
2400 if (valid_status_int & PCI230_INT_ADC) { 2328 if (valid_status_int & PCI230_INT_ADC)
2401 s = dev->read_subdev; 2329 pci230_handle_ai(dev, s_ai);
2402 pci230_handle_ai(dev, s);
2403 comedi_event(dev, s);
2404 }
2405 2330
2406 /* Reenable interrupts. */ 2331 /* Reenable interrupts. */
2407 spin_lock_irqsave(&devpriv->isr_spinlock, irqflags); 2332 spin_lock_irqsave(&devpriv->isr_spinlock, irqflags);
@@ -2410,6 +2335,9 @@ static irqreturn_t pci230_interrupt(int irq, void *d)
2410 devpriv->intr_running = false; 2335 devpriv->intr_running = false;
2411 spin_unlock_irqrestore(&devpriv->isr_spinlock, irqflags); 2336 spin_unlock_irqrestore(&devpriv->isr_spinlock, irqflags);
2412 2337
2338 comedi_handle_events(dev, s_ao);
2339 comedi_handle_events(dev, s_ai);
2340
2413 return IRQ_HANDLED; 2341 return IRQ_HANDLED;
2414} 2342}
2415 2343
@@ -2583,7 +2511,6 @@ static int pci230_auto_attach(struct comedi_device *dev,
2583 s->maxdata = (1 << thisboard->ao_bits) - 1; 2511 s->maxdata = (1 << thisboard->ao_bits) - 1;
2584 s->range_table = &pci230_ao_range; 2512 s->range_table = &pci230_ao_range;
2585 s->insn_write = pci230_ao_insn_write; 2513 s->insn_write = pci230_ao_insn_write;
2586 s->insn_read = comedi_readback_insn_read;
2587 s->len_chanlist = 2; 2514 s->len_chanlist = 2;
2588 if (dev->irq) { 2515 if (dev->irq) {
2589 dev->write_subdev = s; 2516 dev->write_subdev = s;
diff --git a/drivers/staging/comedi/drivers/amplc_pci263.c b/drivers/staging/comedi/drivers/amplc_pci263.c
index 2259bee98d48..0d2224b832ac 100644
--- a/drivers/staging/comedi/drivers/amplc_pci263.c
+++ b/drivers/staging/comedi/drivers/amplc_pci263.c
@@ -71,7 +71,7 @@ static int pci263_auto_attach(struct comedi_device *dev,
71 s = &dev->subdevices[0]; 71 s = &dev->subdevices[0];
72 /* digital output subdevice */ 72 /* digital output subdevice */
73 s->type = COMEDI_SUBD_DO; 73 s->type = COMEDI_SUBD_DO;
74 s->subdev_flags = SDF_READABLE | SDF_WRITABLE; 74 s->subdev_flags = SDF_WRITABLE;
75 s->n_chan = 16; 75 s->n_chan = 16;
76 s->maxdata = 1; 76 s->maxdata = 1;
77 s->range_table = &range_digital; 77 s->range_table = &range_digital;
diff --git a/drivers/staging/comedi/drivers/c6xdigio.c b/drivers/staging/comedi/drivers/c6xdigio.c
index e03dd6e71415..e7cb7032a910 100644
--- a/drivers/staging/comedi/drivers/c6xdigio.c
+++ b/drivers/staging/comedi/drivers/c6xdigio.c
@@ -265,7 +265,7 @@ static int c6xdigio_attach(struct comedi_device *dev,
265 s = &dev->subdevices[0]; 265 s = &dev->subdevices[0];
266 /* pwm output subdevice */ 266 /* pwm output subdevice */
267 s->type = COMEDI_SUBD_PWM; 267 s->type = COMEDI_SUBD_PWM;
268 s->subdev_flags = SDF_WRITEABLE; 268 s->subdev_flags = SDF_WRITABLE;
269 s->n_chan = 2; 269 s->n_chan = 2;
270 s->maxdata = 500; 270 s->maxdata = 500;
271 s->range_table = &range_unknown; 271 s->range_table = &range_unknown;
diff --git a/drivers/staging/comedi/drivers/cb_das16_cs.c b/drivers/staging/comedi/drivers/cb_das16_cs.c
index f88880aea6da..0a48d2a961d5 100644
--- a/drivers/staging/comedi/drivers/cb_das16_cs.c
+++ b/drivers/staging/comedi/drivers/cb_das16_cs.c
@@ -305,7 +305,6 @@ static int das16cs_auto_attach(struct comedi_device *dev,
305 s->maxdata = 0xffff; 305 s->maxdata = 0xffff;
306 s->range_table = &range_bipolar10; 306 s->range_table = &range_bipolar10;
307 s->insn_write = &das16cs_ao_insn_write; 307 s->insn_write = &das16cs_ao_insn_write;
308 s->insn_read = comedi_readback_insn_read;
309 308
310 ret = comedi_alloc_subdev_readback(s); 309 ret = comedi_alloc_subdev_readback(s);
311 if (ret) 310 if (ret)
diff --git a/drivers/staging/comedi/drivers/cb_pcidas.c b/drivers/staging/comedi/drivers/cb_pcidas.c
index 1ec363b7505c..669b1703eb99 100644
--- a/drivers/staging/comedi/drivers/cb_pcidas.c
+++ b/drivers/staging/comedi/drivers/cb_pcidas.c
@@ -346,8 +346,6 @@ struct cb_pcidas_private {
346 /* divisors of master clock for analog input pacing */ 346 /* divisors of master clock for analog input pacing */
347 unsigned int divisor1; 347 unsigned int divisor1;
348 unsigned int divisor2; 348 unsigned int divisor2;
349 /* number of analog input samples remaining */
350 unsigned int count;
351 /* bits to write to registers */ 349 /* bits to write to registers */
352 unsigned int adc_fifo_bits; 350 unsigned int adc_fifo_bits;
353 unsigned int s5933_intcsr_bits; 351 unsigned int s5933_intcsr_bits;
@@ -358,11 +356,6 @@ struct cb_pcidas_private {
358 /* divisors of master clock for analog output pacing */ 356 /* divisors of master clock for analog output pacing */
359 unsigned int ao_divisor1; 357 unsigned int ao_divisor1;
360 unsigned int ao_divisor2; 358 unsigned int ao_divisor2;
361 /* number of analog output samples remaining */
362 unsigned int ao_count;
363 unsigned int caldac_value[NUM_CHANNELS_8800];
364 unsigned int trimpot_value[NUM_CHANNELS_8402];
365 unsigned int dac08_value;
366 unsigned int calibration_source; 359 unsigned int calibration_source;
367}; 360};
368 361
@@ -596,25 +589,14 @@ static void write_calibration_bitstream(struct comedi_device *dev,
596 } 589 }
597} 590}
598 591
599static int caldac_8800_write(struct comedi_device *dev, unsigned int address, 592static void caldac_8800_write(struct comedi_device *dev,
600 uint8_t value) 593 unsigned int chan, uint8_t val)
601{ 594{
602 struct cb_pcidas_private *devpriv = dev->private; 595 struct cb_pcidas_private *devpriv = dev->private;
603 static const int num_caldac_channels = 8;
604 static const int bitstream_length = 11; 596 static const int bitstream_length = 11;
605 unsigned int bitstream = ((address & 0x7) << 8) | value; 597 unsigned int bitstream = ((chan & 0x7) << 8) | val;
606 static const int caldac_8800_udelay = 1; 598 static const int caldac_8800_udelay = 1;
607 599
608 if (address >= num_caldac_channels) {
609 dev_err(dev->class_dev, "illegal caldac channel\n");
610 return -1;
611 }
612
613 if (value == devpriv->caldac_value[address])
614 return 1;
615
616 devpriv->caldac_value[address] = value;
617
618 write_calibration_bitstream(dev, cal_enable_bits(dev), bitstream, 600 write_calibration_bitstream(dev, cal_enable_bits(dev), bitstream,
619 bitstream_length); 601 bitstream_length);
620 602
@@ -623,75 +605,62 @@ static int caldac_8800_write(struct comedi_device *dev, unsigned int address,
623 devpriv->control_status + CALIBRATION_REG); 605 devpriv->control_status + CALIBRATION_REG);
624 udelay(caldac_8800_udelay); 606 udelay(caldac_8800_udelay);
625 outw(cal_enable_bits(dev), devpriv->control_status + CALIBRATION_REG); 607 outw(cal_enable_bits(dev), devpriv->control_status + CALIBRATION_REG);
626
627 return 1;
628} 608}
629 609
630static int caldac_write_insn(struct comedi_device *dev, 610static int cb_pcidas_caldac_insn_write(struct comedi_device *dev,
631 struct comedi_subdevice *s, 611 struct comedi_subdevice *s,
632 struct comedi_insn *insn, unsigned int *data) 612 struct comedi_insn *insn,
613 unsigned int *data)
633{ 614{
634 const unsigned int channel = CR_CHAN(insn->chanspec); 615 unsigned int chan = CR_CHAN(insn->chanspec);
635 616
636 return caldac_8800_write(dev, channel, data[0]); 617 if (insn->n) {
637} 618 unsigned int val = data[insn->n - 1];
638 619
639static int caldac_read_insn(struct comedi_device *dev, 620 if (s->readback[chan] != val) {
640 struct comedi_subdevice *s, 621 caldac_8800_write(dev, chan, val);
641 struct comedi_insn *insn, unsigned int *data) 622 s->readback[chan] = val;
642{ 623 }
643 struct cb_pcidas_private *devpriv = dev->private; 624 }
644
645 data[0] = devpriv->caldac_value[CR_CHAN(insn->chanspec)];
646 625
647 return 1; 626 return insn->n;
648} 627}
649 628
650/* 1602/16 pregain offset */ 629/* 1602/16 pregain offset */
651static void dac08_write(struct comedi_device *dev, unsigned int value) 630static void dac08_write(struct comedi_device *dev, unsigned int value)
652{ 631{
653 struct cb_pcidas_private *devpriv = dev->private; 632 struct cb_pcidas_private *devpriv = dev->private;
654 unsigned long cal_reg;
655
656 if (devpriv->dac08_value != value) {
657 devpriv->dac08_value = value;
658
659 cal_reg = devpriv->control_status + CALIBRATION_REG;
660 633
661 value &= 0xff; 634 value &= 0xff;
662 value |= cal_enable_bits(dev); 635 value |= cal_enable_bits(dev);
663 636
664 /* latch the new value into the caldac */ 637 /* latch the new value into the caldac */
665 outw(value, cal_reg); 638 outw(value, devpriv->control_status + CALIBRATION_REG);
666 udelay(1); 639 udelay(1);
667 outw(value | SELECT_DAC08_BIT, cal_reg); 640 outw(value | SELECT_DAC08_BIT,
668 udelay(1); 641 devpriv->control_status + CALIBRATION_REG);
669 outw(value, cal_reg); 642 udelay(1);
670 udelay(1); 643 outw(value, devpriv->control_status + CALIBRATION_REG);
671 } 644 udelay(1);
672} 645}
673 646
674static int dac08_write_insn(struct comedi_device *dev, 647static int cb_pcidas_dac08_insn_write(struct comedi_device *dev,
675 struct comedi_subdevice *s, 648 struct comedi_subdevice *s,
676 struct comedi_insn *insn, unsigned int *data) 649 struct comedi_insn *insn,
650 unsigned int *data)
677{ 651{
678 int i; 652 unsigned int chan = CR_CHAN(insn->chanspec);
679
680 for (i = 0; i < insn->n; i++)
681 dac08_write(dev, data[i]);
682
683 return insn->n;
684}
685 653
686static int dac08_read_insn(struct comedi_device *dev, 654 if (insn->n) {
687 struct comedi_subdevice *s, struct comedi_insn *insn, 655 unsigned int val = data[insn->n - 1];
688 unsigned int *data)
689{
690 struct cb_pcidas_private *devpriv = dev->private;
691 656
692 data[0] = devpriv->dac08_value; 657 if (s->readback[chan] != val) {
658 dac08_write(dev, val);
659 s->readback[chan] = val;
660 }
661 }
693 662
694 return 1; 663 return insn->n;
695} 664}
696 665
697static int trimpot_7376_write(struct comedi_device *dev, uint8_t value) 666static int trimpot_7376_write(struct comedi_device *dev, uint8_t value)
@@ -740,50 +709,41 @@ static int trimpot_8402_write(struct comedi_device *dev, unsigned int channel,
740 return 0; 709 return 0;
741} 710}
742 711
743static int cb_pcidas_trimpot_write(struct comedi_device *dev, 712static void cb_pcidas_trimpot_write(struct comedi_device *dev,
744 unsigned int channel, unsigned int value) 713 unsigned int chan, unsigned int val)
745{ 714{
746 const struct cb_pcidas_board *thisboard = dev->board_ptr; 715 const struct cb_pcidas_board *thisboard = dev->board_ptr;
747 struct cb_pcidas_private *devpriv = dev->private;
748
749 if (devpriv->trimpot_value[channel] == value)
750 return 1;
751 716
752 devpriv->trimpot_value[channel] = value;
753 switch (thisboard->trimpot) { 717 switch (thisboard->trimpot) {
754 case AD7376: 718 case AD7376:
755 trimpot_7376_write(dev, value); 719 trimpot_7376_write(dev, val);
756 break; 720 break;
757 case AD8402: 721 case AD8402:
758 trimpot_8402_write(dev, channel, value); 722 trimpot_8402_write(dev, chan, val);
759 break; 723 break;
760 default: 724 default:
761 dev_err(dev->class_dev, "driver bug?\n"); 725 dev_err(dev->class_dev, "driver bug?\n");
762 return -1; 726 break;
763 } 727 }
764
765 return 1;
766} 728}
767 729
768static int trimpot_write_insn(struct comedi_device *dev, 730static int cb_pcidas_trimpot_insn_write(struct comedi_device *dev,
769 struct comedi_subdevice *s, 731 struct comedi_subdevice *s,
770 struct comedi_insn *insn, unsigned int *data) 732 struct comedi_insn *insn,
733 unsigned int *data)
771{ 734{
772 unsigned int channel = CR_CHAN(insn->chanspec); 735 unsigned int chan = CR_CHAN(insn->chanspec);
773 736
774 return cb_pcidas_trimpot_write(dev, channel, data[0]); 737 if (insn->n) {
775} 738 unsigned int val = data[insn->n - 1];
776 739
777static int trimpot_read_insn(struct comedi_device *dev, 740 if (s->readback[chan] != val) {
778 struct comedi_subdevice *s, 741 cb_pcidas_trimpot_write(dev, chan, val);
779 struct comedi_insn *insn, unsigned int *data) 742 s->readback[chan] = val;
780{ 743 }
781 struct cb_pcidas_private *devpriv = dev->private; 744 }
782 unsigned int channel = CR_CHAN(insn->chanspec);
783
784 data[0] = devpriv->trimpot_value[channel];
785 745
786 return 1; 746 return insn->n;
787} 747}
788 748
789static int cb_pcidas_ai_check_chanlist(struct comedi_device *dev, 749static int cb_pcidas_ai_check_chanlist(struct comedi_device *dev,
@@ -976,9 +936,6 @@ static int cb_pcidas_ai_cmd(struct comedi_device *dev,
976 if (cmd->scan_begin_src == TRIG_TIMER || cmd->convert_src == TRIG_TIMER) 936 if (cmd->scan_begin_src == TRIG_TIMER || cmd->convert_src == TRIG_TIMER)
977 cb_pcidas_ai_load_counters(dev); 937 cb_pcidas_ai_load_counters(dev);
978 938
979 /* set number of conversions */
980 if (cmd->stop_src == TRIG_COUNT)
981 devpriv->count = cmd->chanlist_len * cmd->stop_arg;
982 /* enable interrupts */ 939 /* enable interrupts */
983 spin_lock_irqsave(&dev->spinlock, flags); 940 spin_lock_irqsave(&dev->spinlock, flags);
984 devpriv->adc_fifo_bits |= INTE; 941 devpriv->adc_fifo_bits |= INTE;
@@ -1134,32 +1091,34 @@ static int cb_pcidas_cancel(struct comedi_device *dev,
1134 return 0; 1091 return 0;
1135} 1092}
1136 1093
1094static void cb_pcidas_ao_load_fifo(struct comedi_device *dev,
1095 struct comedi_subdevice *s,
1096 unsigned int nsamples)
1097{
1098 struct cb_pcidas_private *devpriv = dev->private;
1099 unsigned int nbytes;
1100
1101 nsamples = comedi_nsamples_left(s, nsamples);
1102 nbytes = comedi_buf_read_samples(s, devpriv->ao_buffer, nsamples);
1103
1104 nsamples = comedi_bytes_to_samples(s, nbytes);
1105 outsw(devpriv->ao_registers + DACDATA, devpriv->ao_buffer, nsamples);
1106}
1107
1137static int cb_pcidas_ao_inttrig(struct comedi_device *dev, 1108static int cb_pcidas_ao_inttrig(struct comedi_device *dev,
1138 struct comedi_subdevice *s, 1109 struct comedi_subdevice *s,
1139 unsigned int trig_num) 1110 unsigned int trig_num)
1140{ 1111{
1141 const struct cb_pcidas_board *thisboard = dev->board_ptr; 1112 const struct cb_pcidas_board *thisboard = dev->board_ptr;
1142 struct cb_pcidas_private *devpriv = dev->private; 1113 struct cb_pcidas_private *devpriv = dev->private;
1143 unsigned int num_bytes, num_points = thisboard->fifo_size;
1144 struct comedi_async *async = s->async; 1114 struct comedi_async *async = s->async;
1145 struct comedi_cmd *cmd = &s->async->cmd; 1115 struct comedi_cmd *cmd = &async->cmd;
1146 unsigned long flags; 1116 unsigned long flags;
1147 1117
1148 if (trig_num != cmd->start_arg) 1118 if (trig_num != cmd->start_arg)
1149 return -EINVAL; 1119 return -EINVAL;
1150 1120
1151 /* load up fifo */ 1121 cb_pcidas_ao_load_fifo(dev, s, thisboard->fifo_size);
1152 if (cmd->stop_src == TRIG_COUNT && devpriv->ao_count < num_points)
1153 num_points = devpriv->ao_count;
1154
1155 num_bytes = cfc_read_array_from_buffer(s, devpriv->ao_buffer,
1156 num_points * sizeof(short));
1157 num_points = num_bytes / sizeof(short);
1158
1159 if (cmd->stop_src == TRIG_COUNT)
1160 devpriv->ao_count -= num_points;
1161 /* write data to board's fifo */
1162 outsw(devpriv->ao_registers + DACDATA, devpriv->ao_buffer, num_bytes);
1163 1122
1164 /* enable dac half-full and empty interrupts */ 1123 /* enable dac half-full and empty interrupts */
1165 spin_lock_irqsave(&dev->spinlock, flags); 1124 spin_lock_irqsave(&dev->spinlock, flags);
@@ -1224,9 +1183,6 @@ static int cb_pcidas_ao_cmd(struct comedi_device *dev,
1224 if (cmd->scan_begin_src == TRIG_TIMER) 1183 if (cmd->scan_begin_src == TRIG_TIMER)
1225 cb_pcidas_ao_load_counters(dev); 1184 cb_pcidas_ao_load_counters(dev);
1226 1185
1227 /* set number of conversions */
1228 if (cmd->stop_src == TRIG_COUNT)
1229 devpriv->ao_count = cmd->chanlist_len * cmd->stop_arg;
1230 /* set pacer source */ 1186 /* set pacer source */
1231 spin_lock_irqsave(&dev->spinlock, flags); 1187 spin_lock_irqsave(&dev->spinlock, flags);
1232 switch (cmd->scan_begin_src) { 1188 switch (cmd->scan_begin_src) {
@@ -1275,8 +1231,6 @@ static void handle_ao_interrupt(struct comedi_device *dev, unsigned int status)
1275 struct comedi_subdevice *s = dev->write_subdev; 1231 struct comedi_subdevice *s = dev->write_subdev;
1276 struct comedi_async *async = s->async; 1232 struct comedi_async *async = s->async;
1277 struct comedi_cmd *cmd = &async->cmd; 1233 struct comedi_cmd *cmd = &async->cmd;
1278 unsigned int half_fifo = thisboard->fifo_size / 2;
1279 unsigned int num_points;
1280 unsigned long flags; 1234 unsigned long flags;
1281 1235
1282 if (status & DAEMI) { 1236 if (status & DAEMI) {
@@ -1286,32 +1240,17 @@ static void handle_ao_interrupt(struct comedi_device *dev, unsigned int status)
1286 devpriv->control_status + INT_ADCFIFO); 1240 devpriv->control_status + INT_ADCFIFO);
1287 spin_unlock_irqrestore(&dev->spinlock, flags); 1241 spin_unlock_irqrestore(&dev->spinlock, flags);
1288 if (inw(devpriv->ao_registers + DAC_CSR) & DAC_EMPTY) { 1242 if (inw(devpriv->ao_registers + DAC_CSR) & DAC_EMPTY) {
1289 if (cmd->stop_src == TRIG_NONE || 1243 if (cmd->stop_src == TRIG_COUNT &&
1290 (cmd->stop_src == TRIG_COUNT 1244 async->scans_done >= cmd->stop_arg) {
1291 && devpriv->ao_count)) { 1245 async->events |= COMEDI_CB_EOA;
1246 } else {
1292 dev_err(dev->class_dev, "dac fifo underflow\n"); 1247 dev_err(dev->class_dev, "dac fifo underflow\n");
1293 async->events |= COMEDI_CB_ERROR; 1248 async->events |= COMEDI_CB_ERROR;
1294 } 1249 }
1295 async->events |= COMEDI_CB_EOA;
1296 } 1250 }
1297 } else if (status & DAHFI) { 1251 } else if (status & DAHFI) {
1298 unsigned int num_bytes; 1252 cb_pcidas_ao_load_fifo(dev, s, thisboard->fifo_size / 2);
1299 1253
1300 /* figure out how many points we are writing to fifo */
1301 num_points = half_fifo;
1302 if (cmd->stop_src == TRIG_COUNT &&
1303 devpriv->ao_count < num_points)
1304 num_points = devpriv->ao_count;
1305 num_bytes =
1306 cfc_read_array_from_buffer(s, devpriv->ao_buffer,
1307 num_points * sizeof(short));
1308 num_points = num_bytes / sizeof(short);
1309
1310 if (cmd->stop_src == TRIG_COUNT)
1311 devpriv->ao_count -= num_points;
1312 /* write data to board's fifo */
1313 outsw(devpriv->ao_registers + DACDATA, devpriv->ao_buffer,
1314 num_points);
1315 /* clear half-full interrupt latch */ 1254 /* clear half-full interrupt latch */
1316 spin_lock_irqsave(&dev->spinlock, flags); 1255 spin_lock_irqsave(&dev->spinlock, flags);
1317 outw(devpriv->adc_fifo_bits | DAHFI, 1256 outw(devpriv->adc_fifo_bits | DAHFI,
@@ -1319,7 +1258,7 @@ static void handle_ao_interrupt(struct comedi_device *dev, unsigned int status)
1319 spin_unlock_irqrestore(&dev->spinlock, flags); 1258 spin_unlock_irqrestore(&dev->spinlock, flags);
1320 } 1259 }
1321 1260
1322 cfc_handle_events(dev, s); 1261 comedi_handle_events(dev, s);
1323} 1262}
1324 1263
1325static irqreturn_t cb_pcidas_interrupt(int irq, void *d) 1264static irqreturn_t cb_pcidas_interrupt(int irq, void *d)
@@ -1362,18 +1301,15 @@ static irqreturn_t cb_pcidas_interrupt(int irq, void *d)
1362 /* if fifo half-full */ 1301 /* if fifo half-full */
1363 if (status & ADHFI) { 1302 if (status & ADHFI) {
1364 /* read data */ 1303 /* read data */
1365 num_samples = half_fifo; 1304 num_samples = comedi_nsamples_left(s, half_fifo);
1366 if (cmd->stop_src == TRIG_COUNT &&
1367 num_samples > devpriv->count) {
1368 num_samples = devpriv->count;
1369 }
1370 insw(devpriv->adc_fifo + ADCDATA, devpriv->ai_buffer, 1305 insw(devpriv->adc_fifo + ADCDATA, devpriv->ai_buffer,
1371 num_samples); 1306 num_samples);
1372 cfc_write_array_to_buffer(s, devpriv->ai_buffer, 1307 comedi_buf_write_samples(s, devpriv->ai_buffer, num_samples);
1373 num_samples * sizeof(short)); 1308
1374 devpriv->count -= num_samples; 1309 if (cmd->stop_src == TRIG_COUNT &&
1375 if (cmd->stop_src == TRIG_COUNT && devpriv->count == 0) 1310 async->scans_done >= cmd->stop_arg)
1376 async->events |= COMEDI_CB_EOA; 1311 async->events |= COMEDI_CB_EOA;
1312
1377 /* clear half-full interrupt latch */ 1313 /* clear half-full interrupt latch */
1378 spin_lock_irqsave(&dev->spinlock, flags); 1314 spin_lock_irqsave(&dev->spinlock, flags);
1379 outw(devpriv->adc_fifo_bits | INT, 1315 outw(devpriv->adc_fifo_bits | INT,
@@ -1382,14 +1318,17 @@ static irqreturn_t cb_pcidas_interrupt(int irq, void *d)
1382 /* else if fifo not empty */ 1318 /* else if fifo not empty */
1383 } else if (status & (ADNEI | EOBI)) { 1319 } else if (status & (ADNEI | EOBI)) {
1384 for (i = 0; i < timeout; i++) { 1320 for (i = 0; i < timeout; i++) {
1321 unsigned short val;
1322
1385 /* break if fifo is empty */ 1323 /* break if fifo is empty */
1386 if ((ADNE & inw(devpriv->control_status + 1324 if ((ADNE & inw(devpriv->control_status +
1387 INT_ADCFIFO)) == 0) 1325 INT_ADCFIFO)) == 0)
1388 break; 1326 break;
1389 cfc_write_to_buffer(s, inw(devpriv->adc_fifo)); 1327 val = inw(devpriv->adc_fifo);
1328 comedi_buf_write_samples(s, &val, 1);
1329
1390 if (cmd->stop_src == TRIG_COUNT && 1330 if (cmd->stop_src == TRIG_COUNT &&
1391 --devpriv->count == 0) { 1331 async->scans_done >= cmd->stop_arg) {
1392 /* end of acquisition */
1393 async->events |= COMEDI_CB_EOA; 1332 async->events |= COMEDI_CB_EOA;
1394 break; 1333 break;
1395 } 1334 }
@@ -1419,7 +1358,7 @@ static irqreturn_t cb_pcidas_interrupt(int irq, void *d)
1419 async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; 1358 async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR;
1420 } 1359 }
1421 1360
1422 cfc_handle_events(dev, s); 1361 comedi_handle_events(dev, s);
1423 1362
1424 return IRQ_HANDLED; 1363 return IRQ_HANDLED;
1425} 1364}
@@ -1503,7 +1442,6 @@ static int cb_pcidas_auto_attach(struct comedi_device *dev,
1503 s->range_table = &cb_pcidas_ao_ranges; 1442 s->range_table = &cb_pcidas_ao_ranges;
1504 /* default to no fifo (*insn_write) */ 1443 /* default to no fifo (*insn_write) */
1505 s->insn_write = cb_pcidas_ao_nofifo_winsn; 1444 s->insn_write = cb_pcidas_ao_nofifo_winsn;
1506 s->insn_read = comedi_readback_insn_read;
1507 1445
1508 ret = comedi_alloc_subdev_readback(s); 1446 ret = comedi_alloc_subdev_readback(s);
1509 if (ret) 1447 if (ret)
@@ -1542,10 +1480,16 @@ static int cb_pcidas_auto_attach(struct comedi_device *dev,
1542 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; 1480 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
1543 s->n_chan = NUM_CHANNELS_8800; 1481 s->n_chan = NUM_CHANNELS_8800;
1544 s->maxdata = 0xff; 1482 s->maxdata = 0xff;
1545 s->insn_read = caldac_read_insn; 1483 s->insn_write = cb_pcidas_caldac_insn_write;
1546 s->insn_write = caldac_write_insn; 1484
1547 for (i = 0; i < s->n_chan; i++) 1485 ret = comedi_alloc_subdev_readback(s);
1486 if (ret)
1487 return ret;
1488
1489 for (i = 0; i < s->n_chan; i++) {
1548 caldac_8800_write(dev, i, s->maxdata / 2); 1490 caldac_8800_write(dev, i, s->maxdata / 2);
1491 s->readback[i] = s->maxdata / 2;
1492 }
1549 1493
1550 /* trim potentiometer */ 1494 /* trim potentiometer */
1551 s = &dev->subdevices[5]; 1495 s = &dev->subdevices[5];
@@ -1558,10 +1502,16 @@ static int cb_pcidas_auto_attach(struct comedi_device *dev,
1558 s->n_chan = NUM_CHANNELS_8402; 1502 s->n_chan = NUM_CHANNELS_8402;
1559 s->maxdata = 0xff; 1503 s->maxdata = 0xff;
1560 } 1504 }
1561 s->insn_read = trimpot_read_insn; 1505 s->insn_write = cb_pcidas_trimpot_insn_write;
1562 s->insn_write = trimpot_write_insn; 1506
1563 for (i = 0; i < s->n_chan; i++) 1507 ret = comedi_alloc_subdev_readback(s);
1508 if (ret)
1509 return ret;
1510
1511 for (i = 0; i < s->n_chan; i++) {
1564 cb_pcidas_trimpot_write(dev, i, s->maxdata / 2); 1512 cb_pcidas_trimpot_write(dev, i, s->maxdata / 2);
1513 s->readback[i] = s->maxdata / 2;
1514 }
1565 1515
1566 /* dac08 caldac */ 1516 /* dac08 caldac */
1567 s = &dev->subdevices[6]; 1517 s = &dev->subdevices[6];
@@ -1569,10 +1519,17 @@ static int cb_pcidas_auto_attach(struct comedi_device *dev,
1569 s->type = COMEDI_SUBD_CALIB; 1519 s->type = COMEDI_SUBD_CALIB;
1570 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; 1520 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
1571 s->n_chan = NUM_CHANNELS_DAC08; 1521 s->n_chan = NUM_CHANNELS_DAC08;
1572 s->insn_read = dac08_read_insn;
1573 s->insn_write = dac08_write_insn;
1574 s->maxdata = 0xff; 1522 s->maxdata = 0xff;
1575 dac08_write(dev, s->maxdata / 2); 1523 s->insn_write = cb_pcidas_dac08_insn_write;
1524
1525 ret = comedi_alloc_subdev_readback(s);
1526 if (ret)
1527 return ret;
1528
1529 for (i = 0; i < s->n_chan; i++) {
1530 dac08_write(dev, s->maxdata / 2);
1531 s->readback[i] = s->maxdata / 2;
1532 }
1576 } else 1533 } else
1577 s->type = COMEDI_SUBD_UNUSED; 1534 s->type = COMEDI_SUBD_UNUSED;
1578 1535
diff --git a/drivers/staging/comedi/drivers/cb_pcidas64.c b/drivers/staging/comedi/drivers/cb_pcidas64.c
index 3b6bffc66918..eddb7ace43df 100644
--- a/drivers/staging/comedi/drivers/cb_pcidas64.c
+++ b/drivers/staging/comedi/drivers/cb_pcidas64.c
@@ -1065,8 +1065,6 @@ struct pcidas64_private {
1065 /* local address (used by dma controller) */ 1065 /* local address (used by dma controller) */
1066 uint32_t local0_iobase; 1066 uint32_t local0_iobase;
1067 uint32_t local1_iobase; 1067 uint32_t local1_iobase;
1068 /* number of analog input samples remaining */
1069 unsigned int ai_count;
1070 /* dma buffers for analog input */ 1068 /* dma buffers for analog input */
1071 uint16_t *ai_buffer[MAX_AI_DMA_RING_COUNT]; 1069 uint16_t *ai_buffer[MAX_AI_DMA_RING_COUNT];
1072 /* physical addresses of ai dma buffers */ 1070 /* physical addresses of ai dma buffers */
@@ -1087,8 +1085,6 @@ struct pcidas64_private {
1087 dma_addr_t ao_dma_desc_bus_addr; 1085 dma_addr_t ao_dma_desc_bus_addr;
1088 /* keeps track of buffer where the next ao sample should go */ 1086 /* keeps track of buffer where the next ao sample should go */
1089 unsigned int ao_dma_index; 1087 unsigned int ao_dma_index;
1090 /* number of analog output samples remaining */
1091 unsigned long ao_count;
1092 unsigned int hw_revision; /* stc chip hardware revision number */ 1088 unsigned int hw_revision; /* stc chip hardware revision number */
1093 /* last bits sent to INTR_ENABLE_REG register */ 1089 /* last bits sent to INTR_ENABLE_REG register */
1094 unsigned int intr_enable_bits; 1090 unsigned int intr_enable_bits;
@@ -1109,9 +1105,6 @@ struct pcidas64_private {
1109 uint8_t i2c_cal_range_bits; 1105 uint8_t i2c_cal_range_bits;
1110 /* configure digital triggers to trigger on falling edge */ 1106 /* configure digital triggers to trigger on falling edge */
1111 unsigned int ext_trig_falling; 1107 unsigned int ext_trig_falling;
1112 /* states of various devices stored to enable read-back */
1113 unsigned int ad8402_state[2];
1114 unsigned int caldac_state[8];
1115 short ai_cmd_running; 1108 short ai_cmd_running;
1116 unsigned int ai_fifo_segment_length; 1109 unsigned int ai_fifo_segment_length;
1117 struct ext_clock_info ext_clock; 1110 struct ext_clock_info ext_clock;
@@ -2199,10 +2192,6 @@ static void setup_sample_counters(struct comedi_device *dev,
2199{ 2192{
2200 struct pcidas64_private *devpriv = dev->private; 2193 struct pcidas64_private *devpriv = dev->private;
2201 2194
2202 if (cmd->stop_src == TRIG_COUNT) {
2203 /* set software count */
2204 devpriv->ai_count = cmd->stop_arg * cmd->chanlist_len;
2205 }
2206 /* load hardware conversion counter */ 2195 /* load hardware conversion counter */
2207 if (use_hw_sample_counter(cmd)) { 2196 if (use_hw_sample_counter(cmd)) {
2208 writew(cmd->stop_arg & 0xffff, 2197 writew(cmd->stop_arg & 0xffff,
@@ -2642,8 +2631,6 @@ static void pio_drain_ai_fifo_16(struct comedi_device *dev)
2642{ 2631{
2643 struct pcidas64_private *devpriv = dev->private; 2632 struct pcidas64_private *devpriv = dev->private;
2644 struct comedi_subdevice *s = dev->read_subdev; 2633 struct comedi_subdevice *s = dev->read_subdev;
2645 struct comedi_async *async = s->async;
2646 struct comedi_cmd *cmd = &async->cmd;
2647 unsigned int i; 2634 unsigned int i;
2648 uint16_t prepost_bits; 2635 uint16_t prepost_bits;
2649 int read_segment, read_index, write_segment, write_index; 2636 int read_segment, read_index, write_segment, write_index;
@@ -2672,26 +2659,21 @@ static void pio_drain_ai_fifo_16(struct comedi_device *dev)
2672 devpriv->ai_fifo_segment_length - read_index; 2659 devpriv->ai_fifo_segment_length - read_index;
2673 else 2660 else
2674 num_samples = write_index - read_index; 2661 num_samples = write_index - read_index;
2675
2676 if (cmd->stop_src == TRIG_COUNT) {
2677 if (devpriv->ai_count == 0)
2678 break;
2679 if (num_samples > devpriv->ai_count)
2680 num_samples = devpriv->ai_count;
2681
2682 devpriv->ai_count -= num_samples;
2683 }
2684
2685 if (num_samples < 0) { 2662 if (num_samples < 0) {
2686 dev_err(dev->class_dev, 2663 dev_err(dev->class_dev,
2687 "cb_pcidas64: bug! num_samples < 0\n"); 2664 "cb_pcidas64: bug! num_samples < 0\n");
2688 break; 2665 break;
2689 } 2666 }
2690 2667
2668 num_samples = comedi_nsamples_left(s, num_samples);
2669 if (num_samples == 0)
2670 break;
2671
2691 for (i = 0; i < num_samples; i++) { 2672 for (i = 0; i < num_samples; i++) {
2692 cfc_write_to_buffer(s, 2673 unsigned short val;
2693 readw(devpriv->main_iobase + 2674
2694 ADC_FIFO_REG)); 2675 val = readw(devpriv->main_iobase + ADC_FIFO_REG);
2676 comedi_buf_write_samples(s, &val, 1);
2695 } 2677 }
2696 2678
2697 } while (read_segment != write_segment); 2679 } while (read_segment != write_segment);
@@ -2706,33 +2688,30 @@ static void pio_drain_ai_fifo_32(struct comedi_device *dev)
2706{ 2688{
2707 struct pcidas64_private *devpriv = dev->private; 2689 struct pcidas64_private *devpriv = dev->private;
2708 struct comedi_subdevice *s = dev->read_subdev; 2690 struct comedi_subdevice *s = dev->read_subdev;
2709 struct comedi_async *async = s->async; 2691 unsigned int nsamples;
2710 struct comedi_cmd *cmd = &async->cmd;
2711 unsigned int i; 2692 unsigned int i;
2712 unsigned int max_transfer = 100000;
2713 uint32_t fifo_data; 2693 uint32_t fifo_data;
2714 int write_code = 2694 int write_code =
2715 readw(devpriv->main_iobase + ADC_WRITE_PNTR_REG) & 0x7fff; 2695 readw(devpriv->main_iobase + ADC_WRITE_PNTR_REG) & 0x7fff;
2716 int read_code = 2696 int read_code =
2717 readw(devpriv->main_iobase + ADC_READ_PNTR_REG) & 0x7fff; 2697 readw(devpriv->main_iobase + ADC_READ_PNTR_REG) & 0x7fff;
2718 2698
2719 if (cmd->stop_src == TRIG_COUNT) { 2699 nsamples = comedi_nsamples_left(s, 100000);
2720 if (max_transfer > devpriv->ai_count) 2700 for (i = 0; read_code != write_code && i < nsamples;) {
2721 max_transfer = devpriv->ai_count; 2701 unsigned short val;
2722 2702
2723 }
2724 for (i = 0; read_code != write_code && i < max_transfer;) {
2725 fifo_data = readl(dev->mmio + ADC_FIFO_REG); 2703 fifo_data = readl(dev->mmio + ADC_FIFO_REG);
2726 cfc_write_to_buffer(s, fifo_data & 0xffff); 2704 val = fifo_data & 0xffff;
2705 comedi_buf_write_samples(s, &val, 1);
2727 i++; 2706 i++;
2728 if (i < max_transfer) { 2707 if (i < nsamples) {
2729 cfc_write_to_buffer(s, (fifo_data >> 16) & 0xffff); 2708 val = (fifo_data >> 16) & 0xffff;
2709 comedi_buf_write_samples(s, &val, 1);
2730 i++; 2710 i++;
2731 } 2711 }
2732 read_code = readw(devpriv->main_iobase + ADC_READ_PNTR_REG) & 2712 read_code = readw(devpriv->main_iobase + ADC_READ_PNTR_REG) &
2733 0x7fff; 2713 0x7fff;
2734 } 2714 }
2735 devpriv->ai_count -= i;
2736} 2715}
2737 2716
2738/* empty fifo */ 2717/* empty fifo */
@@ -2750,8 +2729,7 @@ static void drain_dma_buffers(struct comedi_device *dev, unsigned int channel)
2750{ 2729{
2751 const struct pcidas64_board *thisboard = dev->board_ptr; 2730 const struct pcidas64_board *thisboard = dev->board_ptr;
2752 struct pcidas64_private *devpriv = dev->private; 2731 struct pcidas64_private *devpriv = dev->private;
2753 struct comedi_async *async = dev->read_subdev->async; 2732 struct comedi_subdevice *s = dev->read_subdev;
2754 struct comedi_cmd *cmd = &async->cmd;
2755 uint32_t next_transfer_addr; 2733 uint32_t next_transfer_addr;
2756 int j; 2734 int j;
2757 int num_samples = 0; 2735 int num_samples = 0;
@@ -2772,16 +2750,10 @@ static void drain_dma_buffers(struct comedi_device *dev, unsigned int channel)
2772 devpriv->ai_buffer_bus_addr[devpriv->ai_dma_index] + 2750 devpriv->ai_buffer_bus_addr[devpriv->ai_dma_index] +
2773 DMA_BUFFER_SIZE) && j < ai_dma_ring_count(thisboard); j++) { 2751 DMA_BUFFER_SIZE) && j < ai_dma_ring_count(thisboard); j++) {
2774 /* transfer data from dma buffer to comedi buffer */ 2752 /* transfer data from dma buffer to comedi buffer */
2775 num_samples = dma_transfer_size(dev); 2753 num_samples = comedi_nsamples_left(s, dma_transfer_size(dev));
2776 if (cmd->stop_src == TRIG_COUNT) { 2754 comedi_buf_write_samples(s,
2777 if (num_samples > devpriv->ai_count) 2755 devpriv->ai_buffer[devpriv->ai_dma_index],
2778 num_samples = devpriv->ai_count; 2756 num_samples);
2779 devpriv->ai_count -= num_samples;
2780 }
2781 cfc_write_array_to_buffer(dev->read_subdev,
2782 devpriv->ai_buffer[devpriv->
2783 ai_dma_index],
2784 num_samples * sizeof(uint16_t));
2785 devpriv->ai_dma_index = (devpriv->ai_dma_index + 1) % 2757 devpriv->ai_dma_index = (devpriv->ai_dma_index + 1) %
2786 ai_dma_ring_count(thisboard); 2758 ai_dma_ring_count(thisboard);
2787 } 2759 }
@@ -2831,12 +2803,12 @@ static void handle_ai_interrupt(struct comedi_device *dev,
2831 spin_unlock_irqrestore(&dev->spinlock, flags); 2803 spin_unlock_irqrestore(&dev->spinlock, flags);
2832 } 2804 }
2833 /* if we are have all the data, then quit */ 2805 /* if we are have all the data, then quit */
2834 if ((cmd->stop_src == TRIG_COUNT && (int)devpriv->ai_count <= 0) || 2806 if ((cmd->stop_src == TRIG_COUNT &&
2835 (cmd->stop_src == TRIG_EXT && (status & ADC_STOP_BIT))) { 2807 async->scans_done >= cmd->stop_arg) ||
2808 (cmd->stop_src == TRIG_EXT && (status & ADC_STOP_BIT)))
2836 async->events |= COMEDI_CB_EOA; 2809 async->events |= COMEDI_CB_EOA;
2837 }
2838 2810
2839 cfc_handle_events(dev, s); 2811 comedi_handle_events(dev, s);
2840} 2812}
2841 2813
2842static inline unsigned int prev_ao_dma_index(struct comedi_device *dev) 2814static inline unsigned int prev_ao_dma_index(struct comedi_device *dev)
@@ -2871,22 +2843,6 @@ static int last_ao_dma_load_completed(struct comedi_device *dev)
2871 return 1; 2843 return 1;
2872} 2844}
2873 2845
2874static int ao_stopped_by_error(struct comedi_device *dev,
2875 const struct comedi_cmd *cmd)
2876{
2877 struct pcidas64_private *devpriv = dev->private;
2878
2879 if (cmd->stop_src == TRIG_NONE)
2880 return 1;
2881 if (cmd->stop_src == TRIG_COUNT) {
2882 if (devpriv->ao_count)
2883 return 1;
2884 if (last_ao_dma_load_completed(dev) == 0)
2885 return 1;
2886 }
2887 return 0;
2888}
2889
2890static inline int ao_dma_needs_restart(struct comedi_device *dev, 2846static inline int ao_dma_needs_restart(struct comedi_device *dev,
2891 unsigned short dma_status) 2847 unsigned short dma_status)
2892{ 2848{
@@ -2912,32 +2868,39 @@ static void restart_ao_dma(struct comedi_device *dev)
2912 dma_start_sync(dev, 0); 2868 dma_start_sync(dev, 0);
2913} 2869}
2914 2870
2871static unsigned int cb_pcidas64_ao_fill_buffer(struct comedi_device *dev,
2872 struct comedi_subdevice *s,
2873 unsigned short *dest,
2874 unsigned int max_bytes)
2875{
2876 unsigned int nsamples = comedi_bytes_to_samples(s, max_bytes);
2877 unsigned int actual_bytes;
2878
2879 nsamples = comedi_nsamples_left(s, nsamples);
2880 actual_bytes = comedi_buf_read_samples(s, dest, nsamples);
2881
2882 return comedi_bytes_to_samples(s, actual_bytes);
2883}
2884
2915static unsigned int load_ao_dma_buffer(struct comedi_device *dev, 2885static unsigned int load_ao_dma_buffer(struct comedi_device *dev,
2916 const struct comedi_cmd *cmd) 2886 const struct comedi_cmd *cmd)
2917{ 2887{
2918 struct pcidas64_private *devpriv = dev->private; 2888 struct pcidas64_private *devpriv = dev->private;
2919 unsigned int num_bytes, buffer_index, prev_buffer_index; 2889 struct comedi_subdevice *s = dev->write_subdev;
2890 unsigned int buffer_index = devpriv->ao_dma_index;
2891 unsigned int prev_buffer_index = prev_ao_dma_index(dev);
2892 unsigned int nsamples;
2893 unsigned int nbytes;
2920 unsigned int next_bits; 2894 unsigned int next_bits;
2921 2895
2922 buffer_index = devpriv->ao_dma_index; 2896 nsamples = cb_pcidas64_ao_fill_buffer(dev, s,
2923 prev_buffer_index = prev_ao_dma_index(dev); 2897 devpriv->ao_buffer[buffer_index],
2924 2898 DMA_BUFFER_SIZE);
2925 num_bytes = comedi_buf_read_n_available(dev->write_subdev); 2899 if (nsamples == 0)
2926 if (num_bytes > DMA_BUFFER_SIZE)
2927 num_bytes = DMA_BUFFER_SIZE;
2928 if (cmd->stop_src == TRIG_COUNT && num_bytes > devpriv->ao_count)
2929 num_bytes = devpriv->ao_count;
2930 num_bytes -= num_bytes % bytes_in_sample;
2931
2932 if (num_bytes == 0)
2933 return 0; 2900 return 0;
2934 2901
2935 num_bytes = cfc_read_array_from_buffer(dev->write_subdev, 2902 nbytes = comedi_samples_to_bytes(s, nsamples);
2936 devpriv-> 2903 devpriv->ao_dma_desc[buffer_index].transfer_size = cpu_to_le32(nbytes);
2937 ao_buffer[buffer_index],
2938 num_bytes);
2939 devpriv->ao_dma_desc[buffer_index].transfer_size =
2940 cpu_to_le32(num_bytes);
2941 /* set end of chain bit so we catch underruns */ 2904 /* set end of chain bit so we catch underruns */
2942 next_bits = le32_to_cpu(devpriv->ao_dma_desc[buffer_index].next); 2905 next_bits = le32_to_cpu(devpriv->ao_dma_desc[buffer_index].next);
2943 next_bits |= PLX_END_OF_CHAIN_BIT; 2906 next_bits |= PLX_END_OF_CHAIN_BIT;
@@ -2949,9 +2912,8 @@ static unsigned int load_ao_dma_buffer(struct comedi_device *dev,
2949 devpriv->ao_dma_desc[prev_buffer_index].next = cpu_to_le32(next_bits); 2912 devpriv->ao_dma_desc[prev_buffer_index].next = cpu_to_le32(next_bits);
2950 2913
2951 devpriv->ao_dma_index = (buffer_index + 1) % AO_DMA_RING_COUNT; 2914 devpriv->ao_dma_index = (buffer_index + 1) % AO_DMA_RING_COUNT;
2952 devpriv->ao_count -= num_bytes;
2953 2915
2954 return num_bytes; 2916 return nbytes;
2955} 2917}
2956 2918
2957static void load_ao_dma(struct comedi_device *dev, const struct comedi_cmd *cmd) 2919static void load_ao_dma(struct comedi_device *dev, const struct comedi_cmd *cmd)
@@ -3016,11 +2978,14 @@ static void handle_ao_interrupt(struct comedi_device *dev,
3016 } 2978 }
3017 2979
3018 if ((status & DAC_DONE_BIT)) { 2980 if ((status & DAC_DONE_BIT)) {
3019 async->events |= COMEDI_CB_EOA; 2981 if ((cmd->stop_src == TRIG_COUNT &&
3020 if (ao_stopped_by_error(dev, cmd)) 2982 async->scans_done >= cmd->stop_arg) ||
2983 last_ao_dma_load_completed(dev))
2984 async->events |= COMEDI_CB_EOA;
2985 else
3021 async->events |= COMEDI_CB_ERROR; 2986 async->events |= COMEDI_CB_ERROR;
3022 } 2987 }
3023 cfc_handle_events(dev, s); 2988 comedi_handle_events(dev, s);
3024} 2989}
3025 2990
3026static irqreturn_t handle_interrupt(int irq, void *d) 2991static irqreturn_t handle_interrupt(int irq, void *d)
@@ -3191,7 +3156,9 @@ static void set_dac_interval_regs(struct comedi_device *dev,
3191static int prep_ao_dma(struct comedi_device *dev, const struct comedi_cmd *cmd) 3156static int prep_ao_dma(struct comedi_device *dev, const struct comedi_cmd *cmd)
3192{ 3157{
3193 struct pcidas64_private *devpriv = dev->private; 3158 struct pcidas64_private *devpriv = dev->private;
3194 unsigned int num_bytes; 3159 struct comedi_subdevice *s = dev->write_subdev;
3160 unsigned int nsamples;
3161 unsigned int nbytes;
3195 int i; 3162 int i;
3196 3163
3197 /* clear queue pointer too, since external queue has 3164 /* clear queue pointer too, since external queue has
@@ -3199,22 +3166,23 @@ static int prep_ao_dma(struct comedi_device *dev, const struct comedi_cmd *cmd)
3199 writew(0, devpriv->main_iobase + ADC_QUEUE_CLEAR_REG); 3166 writew(0, devpriv->main_iobase + ADC_QUEUE_CLEAR_REG);
3200 writew(0, devpriv->main_iobase + DAC_BUFFER_CLEAR_REG); 3167 writew(0, devpriv->main_iobase + DAC_BUFFER_CLEAR_REG);
3201 3168
3202 num_bytes = (DAC_FIFO_SIZE / 2) * bytes_in_sample; 3169 nsamples = cb_pcidas64_ao_fill_buffer(dev, s,
3203 if (cmd->stop_src == TRIG_COUNT && 3170 devpriv->ao_bounce_buffer,
3204 num_bytes / bytes_in_sample > devpriv->ao_count) 3171 DAC_FIFO_SIZE);
3205 num_bytes = devpriv->ao_count * bytes_in_sample; 3172 if (nsamples == 0)
3206 num_bytes = cfc_read_array_from_buffer(dev->write_subdev, 3173 return -1;
3207 devpriv->ao_bounce_buffer, 3174
3208 num_bytes); 3175 for (i = 0; i < nsamples; i++) {
3209 for (i = 0; i < num_bytes / bytes_in_sample; i++) {
3210 writew(devpriv->ao_bounce_buffer[i], 3176 writew(devpriv->ao_bounce_buffer[i],
3211 devpriv->main_iobase + DAC_FIFO_REG); 3177 devpriv->main_iobase + DAC_FIFO_REG);
3212 } 3178 }
3213 devpriv->ao_count -= num_bytes / bytes_in_sample; 3179
3214 if (cmd->stop_src == TRIG_COUNT && devpriv->ao_count == 0) 3180 if (cmd->stop_src == TRIG_COUNT &&
3181 s->async->scans_done >= cmd->stop_arg)
3215 return 0; 3182 return 0;
3216 num_bytes = load_ao_dma_buffer(dev, cmd); 3183
3217 if (num_bytes == 0) 3184 nbytes = load_ao_dma_buffer(dev, cmd);
3185 if (nbytes == 0)
3218 return -1; 3186 return -1;
3219 load_ao_dma(dev, cmd); 3187 load_ao_dma(dev, cmd);
3220 3188
@@ -3275,7 +3243,6 @@ static int ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
3275 writew(0x0, devpriv->main_iobase + DAC_CONTROL0_REG); 3243 writew(0x0, devpriv->main_iobase + DAC_CONTROL0_REG);
3276 3244
3277 devpriv->ao_dma_index = 0; 3245 devpriv->ao_dma_index = 0;
3278 devpriv->ao_count = cmd->stop_arg * cmd->chanlist_len;
3279 3246
3280 set_dac_select_reg(dev, cmd); 3247 set_dac_select_reg(dev, cmd);
3281 set_dac_interval_regs(dev, cmd); 3248 set_dac_interval_regs(dev, cmd);
@@ -3580,9 +3547,6 @@ static void caldac_write(struct comedi_device *dev, unsigned int channel,
3580 unsigned int value) 3547 unsigned int value)
3581{ 3548{
3582 const struct pcidas64_board *thisboard = dev->board_ptr; 3549 const struct pcidas64_board *thisboard = dev->board_ptr;
3583 struct pcidas64_private *devpriv = dev->private;
3584
3585 devpriv->caldac_state[channel] = value;
3586 3550
3587 switch (thisboard->layout) { 3551 switch (thisboard->layout) {
3588 case LAYOUT_60XX: 3552 case LAYOUT_60XX:
@@ -3597,33 +3561,27 @@ static void caldac_write(struct comedi_device *dev, unsigned int channel,
3597 } 3561 }
3598} 3562}
3599 3563
3600static int calib_write_insn(struct comedi_device *dev, 3564static int cb_pcidas64_calib_insn_write(struct comedi_device *dev,
3601 struct comedi_subdevice *s, 3565 struct comedi_subdevice *s,
3602 struct comedi_insn *insn, unsigned int *data) 3566 struct comedi_insn *insn,
3567 unsigned int *data)
3603{ 3568{
3604 struct pcidas64_private *devpriv = dev->private; 3569 unsigned int chan = CR_CHAN(insn->chanspec);
3605 int channel = CR_CHAN(insn->chanspec);
3606
3607 /* return immediately if setting hasn't changed, since
3608 * programming these things is slow */
3609 if (devpriv->caldac_state[channel] == data[0])
3610 return 1;
3611
3612 caldac_write(dev, channel, data[0]);
3613
3614 return 1;
3615}
3616 3570
3617static int calib_read_insn(struct comedi_device *dev, 3571 /*
3618 struct comedi_subdevice *s, struct comedi_insn *insn, 3572 * Programming the calib device is slow. Only write the
3619 unsigned int *data) 3573 * last data value if the value has changed.
3620{ 3574 */
3621 struct pcidas64_private *devpriv = dev->private; 3575 if (insn->n) {
3622 unsigned int channel = CR_CHAN(insn->chanspec); 3576 unsigned int val = data[insn->n - 1];
3623 3577
3624 data[0] = devpriv->caldac_state[channel]; 3578 if (s->readback[chan] != val) {
3579 caldac_write(dev, chan, val);
3580 s->readback[chan] = val;
3581 }
3582 }
3625 3583
3626 return 1; 3584 return insn->n;
3627} 3585}
3628 3586
3629static void ad8402_write(struct comedi_device *dev, unsigned int channel, 3587static void ad8402_write(struct comedi_device *dev, unsigned int channel,
@@ -3635,8 +3593,6 @@ static void ad8402_write(struct comedi_device *dev, unsigned int channel,
3635 unsigned int bitstream = ((channel & 0x3) << 8) | (value & 0xff); 3593 unsigned int bitstream = ((channel & 0x3) << 8) | (value & 0xff);
3636 static const int ad8402_udelay = 1; 3594 static const int ad8402_udelay = 1;
3637 3595
3638 devpriv->ad8402_state[channel] = value;
3639
3640 register_bits = SELECT_8402_64XX_BIT; 3596 register_bits = SELECT_8402_64XX_BIT;
3641 udelay(ad8402_udelay); 3597 udelay(ad8402_udelay);
3642 writew(register_bits, devpriv->main_iobase + CALIBRATION_REG); 3598 writew(register_bits, devpriv->main_iobase + CALIBRATION_REG);
@@ -3658,35 +3614,27 @@ static void ad8402_write(struct comedi_device *dev, unsigned int channel,
3658} 3614}
3659 3615
3660/* for pci-das6402/16, channel 0 is analog input gain and channel 1 is offset */ 3616/* for pci-das6402/16, channel 0 is analog input gain and channel 1 is offset */
3661static int ad8402_write_insn(struct comedi_device *dev, 3617static int cb_pcidas64_ad8402_insn_write(struct comedi_device *dev,
3662 struct comedi_subdevice *s, 3618 struct comedi_subdevice *s,
3663 struct comedi_insn *insn, unsigned int *data) 3619 struct comedi_insn *insn,
3620 unsigned int *data)
3664{ 3621{
3665 struct pcidas64_private *devpriv = dev->private; 3622 unsigned int chan = CR_CHAN(insn->chanspec);
3666 int channel = CR_CHAN(insn->chanspec);
3667
3668 /* return immediately if setting hasn't changed, since
3669 * programming these things is slow */
3670 if (devpriv->ad8402_state[channel] == data[0])
3671 return 1;
3672
3673 devpriv->ad8402_state[channel] = data[0];
3674
3675 ad8402_write(dev, channel, data[0]);
3676
3677 return 1;
3678}
3679 3623
3680static int ad8402_read_insn(struct comedi_device *dev, 3624 /*
3681 struct comedi_subdevice *s, 3625 * Programming the calib device is slow. Only write the
3682 struct comedi_insn *insn, unsigned int *data) 3626 * last data value if the value has changed.
3683{ 3627 */
3684 struct pcidas64_private *devpriv = dev->private; 3628 if (insn->n) {
3685 unsigned int channel = CR_CHAN(insn->chanspec); 3629 unsigned int val = data[insn->n - 1];
3686 3630
3687 data[0] = devpriv->ad8402_state[channel]; 3631 if (s->readback[chan] != val) {
3632 ad8402_write(dev, chan, val);
3633 s->readback[chan] = val;
3634 }
3635 }
3688 3636
3689 return 1; 3637 return insn->n;
3690} 3638}
3691 3639
3692static uint16_t read_eeprom(struct comedi_device *dev, uint8_t address) 3640static uint16_t read_eeprom(struct comedi_device *dev, uint8_t address)
@@ -3816,7 +3764,6 @@ static int setup_subdevices(struct comedi_device *dev)
3816 s->maxdata = (1 << thisboard->ao_bits) - 1; 3764 s->maxdata = (1 << thisboard->ao_bits) - 1;
3817 s->range_table = thisboard->ao_range_table; 3765 s->range_table = thisboard->ao_range_table;
3818 s->insn_write = ao_winsn; 3766 s->insn_write = ao_winsn;
3819 s->insn_read = comedi_readback_insn_read;
3820 3767
3821 ret = comedi_alloc_subdev_readback(s); 3768 ret = comedi_alloc_subdev_readback(s);
3822 if (ret) 3769 if (ret)
@@ -3849,7 +3796,7 @@ static int setup_subdevices(struct comedi_device *dev)
3849 if (thisboard->layout == LAYOUT_64XX) { 3796 if (thisboard->layout == LAYOUT_64XX) {
3850 s = &dev->subdevices[3]; 3797 s = &dev->subdevices[3];
3851 s->type = COMEDI_SUBD_DO; 3798 s->type = COMEDI_SUBD_DO;
3852 s->subdev_flags = SDF_WRITABLE | SDF_READABLE; 3799 s->subdev_flags = SDF_WRITABLE;
3853 s->n_chan = 4; 3800 s->n_chan = 4;
3854 s->maxdata = 1; 3801 s->maxdata = 1;
3855 s->range_table = &range_digital; 3802 s->range_table = &range_digital;
@@ -3895,10 +3842,16 @@ static int setup_subdevices(struct comedi_device *dev)
3895 s->maxdata = 0xfff; 3842 s->maxdata = 0xfff;
3896 else 3843 else
3897 s->maxdata = 0xff; 3844 s->maxdata = 0xff;
3898 s->insn_read = calib_read_insn; 3845 s->insn_write = cb_pcidas64_calib_insn_write;
3899 s->insn_write = calib_write_insn; 3846
3900 for (i = 0; i < s->n_chan; i++) 3847 ret = comedi_alloc_subdev_readback(s);
3848 if (ret)
3849 return ret;
3850
3851 for (i = 0; i < s->n_chan; i++) {
3901 caldac_write(dev, i, s->maxdata / 2); 3852 caldac_write(dev, i, s->maxdata / 2);
3853 s->readback[i] = s->maxdata / 2;
3854 }
3902 3855
3903 /* 2 channel ad8402 potentiometer */ 3856 /* 2 channel ad8402 potentiometer */
3904 s = &dev->subdevices[7]; 3857 s = &dev->subdevices[7];
@@ -3906,11 +3859,17 @@ static int setup_subdevices(struct comedi_device *dev)
3906 s->type = COMEDI_SUBD_CALIB; 3859 s->type = COMEDI_SUBD_CALIB;
3907 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; 3860 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
3908 s->n_chan = 2; 3861 s->n_chan = 2;
3909 s->insn_read = ad8402_read_insn;
3910 s->insn_write = ad8402_write_insn;
3911 s->maxdata = 0xff; 3862 s->maxdata = 0xff;
3912 for (i = 0; i < s->n_chan; i++) 3863 s->insn_write = cb_pcidas64_ad8402_insn_write;
3864
3865 ret = comedi_alloc_subdev_readback(s);
3866 if (ret)
3867 return ret;
3868
3869 for (i = 0; i < s->n_chan; i++) {
3913 ad8402_write(dev, i, s->maxdata / 2); 3870 ad8402_write(dev, i, s->maxdata / 2);
3871 s->readback[i] = s->maxdata / 2;
3872 }
3914 } else 3873 } else
3915 s->type = COMEDI_SUBD_UNUSED; 3874 s->type = COMEDI_SUBD_UNUSED;
3916 3875
diff --git a/drivers/staging/comedi/drivers/cb_pcimdas.c b/drivers/staging/comedi/drivers/cb_pcimdas.c
index fe4d2544f3dc..70dd2c9eecdb 100644
--- a/drivers/staging/comedi/drivers/cb_pcimdas.c
+++ b/drivers/staging/comedi/drivers/cb_pcimdas.c
@@ -1,40 +1,45 @@
1/* 1/*
2 comedi/drivers/cb_pcimdas.c 2 * comedi/drivers/cb_pcimdas.c
3 Comedi driver for Computer Boards PCIM-DAS1602/16 3 * Comedi driver for Computer Boards PCIM-DAS1602/16 and PCIe-DAS1602/16
4 4 *
5 COMEDI - Linux Control and Measurement Device Interface 5 * COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 2000 David A. Schleef <ds@schleef.org> 6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 7 *
8 This program is free software; you can redistribute it and/or modify 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 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 10 * the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 * (at your option) any later version.
12 12 *
13 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 * GNU General Public License for more details.
17*/ 17 */
18
18/* 19/*
19Driver: cb_pcimdas 20 * Driver: cb_pcimdas
20Description: Measurement Computing PCI Migration series boards 21 * Description: Measurement Computing PCI Migration series boards
21Devices: [ComputerBoards] PCIM-DAS1602/16 (cb_pcimdas) 22 * Devices: [ComputerBoards] PCIM-DAS1602/16 (cb_pcimdas), PCIe-DAS1602/16
22Author: Richard Bytheway 23 * Author: Richard Bytheway
23Updated: Wed, 13 Nov 2002 12:34:56 +0000 24 * Updated: Mon, 13 Oct 2014 11:57:39 +0000
24Status: experimental 25 * Status: experimental
25 26 *
26Written to support the PCIM-DAS1602/16 on a 2.4 series kernel. 27 * Written to support the PCIM-DAS1602/16 and PCIe-DAS1602/16.
27 28 *
28Configuration Options: 29 * Configuration Options:
29 [0] - PCI bus number 30 * none
30 [1] - PCI slot number 31 *
31 32 * Manual configuration of PCI(e) cards is not supported; they are configured
32Developed from cb_pcidas and skel by Richard Bytheway (mocelet@sucs.org). 33 * automatically.
33Only supports DIO, AO and simple AI in it's present form. 34 *
34No interrupts, multi channel or FIFO AI, 35 * Developed from cb_pcidas and skel by Richard Bytheway (mocelet@sucs.org).
35although the card looks like it could support this. 36 * Only supports DIO, AO and simple AI in it's present form.
36See http://www.mccdaq.com/PDFs/Manuals/pcim-das1602-16.pdf for more details. 37 * No interrupts, multi channel or FIFO AI,
37*/ 38 * although the card looks like it could support this.
39 *
40 * http://www.mccdaq.com/PDFs/Manuals/pcim-das1602-16.pdf
41 * http://www.mccdaq.com/PDFs/Manuals/pcie-das1602-16.pdf
42 */
38 43
39#include <linux/module.h> 44#include <linux/module.h>
40#include <linux/pci.h> 45#include <linux/pci.h>
@@ -45,7 +50,7 @@ See http://www.mccdaq.com/PDFs/Manuals/pcim-das1602-16.pdf for more details.
45#include "plx9052.h" 50#include "plx9052.h"
46#include "8255.h" 51#include "8255.h"
47 52
48/* Registers for the PCIM-DAS1602/16 */ 53/* Registers for the PCIM-DAS1602/16 and PCIe-DAS1602/16 */
49 54
50/* DAC Offsets */ 55/* DAC Offsets */
51#define ADC_TRIG 0 56#define ADC_TRIG 0
@@ -221,7 +226,6 @@ static int cb_pcimdas_auto_attach(struct comedi_device *dev,
221 /* ranges are hardware settable, but not software readable. */ 226 /* ranges are hardware settable, but not software readable. */
222 s->range_table = &range_unknown; 227 s->range_table = &range_unknown;
223 s->insn_write = cb_pcimdas_ao_insn_write; 228 s->insn_write = cb_pcimdas_ao_insn_write;
224 s->insn_read = comedi_readback_insn_read;
225 229
226 ret = comedi_alloc_subdev_readback(s); 230 ret = comedi_alloc_subdev_readback(s);
227 if (ret) 231 if (ret)
@@ -251,7 +255,8 @@ static int cb_pcimdas_pci_probe(struct pci_dev *dev,
251} 255}
252 256
253static const struct pci_device_id cb_pcimdas_pci_table[] = { 257static const struct pci_device_id cb_pcimdas_pci_table[] = {
254 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0056) }, 258 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0056) }, /* PCIM-DAS1602/16 */
259 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0115) }, /* PCIe-DAS1602/16 */
255 { 0 } 260 { 0 }
256}; 261};
257MODULE_DEVICE_TABLE(pci, cb_pcimdas_pci_table); 262MODULE_DEVICE_TABLE(pci, cb_pcimdas_pci_table);
@@ -265,5 +270,5 @@ static struct pci_driver cb_pcimdas_pci_driver = {
265module_comedi_pci_driver(cb_pcimdas_driver, cb_pcimdas_pci_driver); 270module_comedi_pci_driver(cb_pcimdas_driver, cb_pcimdas_pci_driver);
266 271
267MODULE_AUTHOR("Comedi http://www.comedi.org"); 272MODULE_AUTHOR("Comedi http://www.comedi.org");
268MODULE_DESCRIPTION("Comedi low-level driver"); 273MODULE_DESCRIPTION("Comedi driver for PCIM-DAS1602/16 and PCIe-DAS1602/16");
269MODULE_LICENSE("GPL"); 274MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/comedi_bond.c b/drivers/staging/comedi/drivers/comedi_bond.c
index 8450c99af8b0..85b2f4ab1ba4 100644
--- a/drivers/staging/comedi/drivers/comedi_bond.c
+++ b/drivers/staging/comedi/drivers/comedi_bond.c
@@ -61,8 +61,7 @@ struct bonded_device {
61}; 61};
62 62
63struct comedi_bond_private { 63struct comedi_bond_private {
64# define MAX_BOARD_NAME 256 64 char name[256];
65 char name[MAX_BOARD_NAME];
66 struct bonded_device **devs; 65 struct bonded_device **devs;
67 unsigned ndevs; 66 unsigned ndevs;
68 unsigned nchans; 67 unsigned nchans;
@@ -262,12 +261,10 @@ static int do_dev_config(struct comedi_device *dev, struct comedi_devconfig *it)
262 { 261 {
263 /* Append dev:subdev to devpriv->name */ 262 /* Append dev:subdev to devpriv->name */
264 char buf[20]; 263 char buf[20];
265 int left =
266 MAX_BOARD_NAME - strlen(devpriv->name) - 1;
267 snprintf(buf, sizeof(buf), "%u:%u ", 264 snprintf(buf, sizeof(buf), "%u:%u ",
268 bdev->minor, bdev->subdev); 265 bdev->minor, bdev->subdev);
269 buf[sizeof(buf) - 1] = 0; 266 strlcat(devpriv->name, buf,
270 strncat(devpriv->name, buf, left); 267 sizeof(devpriv->name));
271 } 268 }
272 269
273 } 270 }
diff --git a/drivers/staging/comedi/drivers/comedi_fc.h b/drivers/staging/comedi/drivers/comedi_fc.h
index ce2835972507..756be931c1a4 100644
--- a/drivers/staging/comedi/drivers/comedi_fc.h
+++ b/drivers/staging/comedi/drivers/comedi_fc.h
@@ -23,49 +23,6 @@
23 23
24#include "../comedidev.h" 24#include "../comedidev.h"
25 25
26static inline unsigned int cfc_bytes_per_scan(struct comedi_subdevice *s)
27{
28 return comedi_bytes_per_scan(s);
29}
30
31static inline void cfc_inc_scan_progress(struct comedi_subdevice *s,
32 unsigned int num_bytes)
33{
34 comedi_inc_scan_progress(s, num_bytes);
35}
36
37static inline unsigned int cfc_write_array_to_buffer(struct comedi_subdevice *s,
38 const void *data,
39 unsigned int num_bytes)
40{
41 return comedi_write_array_to_buffer(s, data, num_bytes);
42}
43
44static inline unsigned int cfc_write_to_buffer(struct comedi_subdevice *s,
45 unsigned short data)
46{
47 return comedi_write_array_to_buffer(s, &data, sizeof(data));
48};
49
50static inline unsigned int cfc_write_long_to_buffer(struct comedi_subdevice *s,
51 unsigned int data)
52{
53 return comedi_write_array_to_buffer(s, &data, sizeof(data));
54};
55
56static inline unsigned int
57cfc_read_array_from_buffer(struct comedi_subdevice *s, void *data,
58 unsigned int num_bytes)
59{
60 return comedi_read_array_from_buffer(s, data, num_bytes);
61}
62
63static inline unsigned int cfc_handle_events(struct comedi_device *dev,
64 struct comedi_subdevice *s)
65{
66 return comedi_handle_events(dev, s);
67}
68
69/** 26/**
70 * cfc_check_trigger_src() - trivially validate a comedi_cmd trigger source 27 * cfc_check_trigger_src() - trivially validate a comedi_cmd trigger source
71 * @src: pointer to the trigger source to validate 28 * @src: pointer to the trigger source to validate
diff --git a/drivers/staging/comedi/drivers/comedi_parport.c b/drivers/staging/comedi/drivers/comedi_parport.c
index bf002988192d..3bac903c8627 100644
--- a/drivers/staging/comedi/drivers/comedi_parport.c
+++ b/drivers/staging/comedi/drivers/comedi_parport.c
@@ -225,10 +225,9 @@ static irqreturn_t parport_interrupt(int irq, void *d)
225 if (!(ctrl & PARPORT_CTRL_IRQ_ENA)) 225 if (!(ctrl & PARPORT_CTRL_IRQ_ENA))
226 return IRQ_NONE; 226 return IRQ_NONE;
227 227
228 comedi_buf_put(s, 0); 228 comedi_buf_write_samples(s, &s->state, 1);
229 s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOS; 229 comedi_handle_events(dev, s);
230 230
231 comedi_event(dev, s);
232 return IRQ_HANDLED; 231 return IRQ_HANDLED;
233} 232}
234 233
diff --git a/drivers/staging/comedi/drivers/comedi_test.c b/drivers/staging/comedi/drivers/comedi_test.c
index 00c03df72523..e56525a1c8f3 100644
--- a/drivers/staging/comedi/drivers/comedi_test.c
+++ b/drivers/staging/comedi/drivers/comedi_test.c
@@ -52,18 +52,23 @@ zero volts).
52 52
53#include "comedi_fc.h" 53#include "comedi_fc.h"
54#include <linux/timer.h> 54#include <linux/timer.h>
55#include <linux/ktime.h>
55 56
56#define N_CHANS 8 57#define N_CHANS 8
57 58
59enum waveform_state_bits {
60 WAVEFORM_AI_RUNNING = 0
61};
62
58/* Data unique to this driver */ 63/* Data unique to this driver */
59struct waveform_private { 64struct waveform_private {
60 struct timer_list timer; 65 struct timer_list timer;
61 struct timeval last; /* time last timer interrupt occurred */ 66 ktime_t last; /* time last timer interrupt occurred */
62 unsigned int uvolt_amplitude; /* waveform amplitude in microvolts */ 67 unsigned int uvolt_amplitude; /* waveform amplitude in microvolts */
63 unsigned long usec_period; /* waveform period in microseconds */ 68 unsigned long usec_period; /* waveform period in microseconds */
64 unsigned long usec_current; /* current time (mod waveform period) */ 69 unsigned long usec_current; /* current time (mod waveform period) */
65 unsigned long usec_remainder; /* usec since last scan */ 70 unsigned long usec_remainder; /* usec since last scan */
66 unsigned long ai_count; /* number of conversions remaining */ 71 unsigned long state_bits;
67 unsigned int scan_period; /* scan period in usec */ 72 unsigned int scan_period; /* scan period in usec */
68 unsigned int convert_period; /* conversion period in usec */ 73 unsigned int convert_period; /* conversion period in usec */
69 unsigned int ao_loopbacks[N_CHANS]; 74 unsigned int ao_loopbacks[N_CHANS];
@@ -164,36 +169,29 @@ static void waveform_ai_interrupt(unsigned long arg)
164{ 169{
165 struct comedi_device *dev = (struct comedi_device *)arg; 170 struct comedi_device *dev = (struct comedi_device *)arg;
166 struct waveform_private *devpriv = dev->private; 171 struct waveform_private *devpriv = dev->private;
167 struct comedi_async *async = dev->read_subdev->async; 172 struct comedi_subdevice *s = dev->read_subdev;
173 struct comedi_async *async = s->async;
168 struct comedi_cmd *cmd = &async->cmd; 174 struct comedi_cmd *cmd = &async->cmd;
169 unsigned int i, j; 175 unsigned int i, j;
170 /* all times in microsec */ 176 /* all times in microsec */
171 unsigned long elapsed_time; 177 unsigned long elapsed_time;
172 unsigned int num_scans; 178 unsigned int num_scans;
173 struct timeval now; 179 ktime_t now;
174 bool stopping = false; 180
181 /* check command is still active */
182 if (!test_bit(WAVEFORM_AI_RUNNING, &devpriv->state_bits))
183 return;
175 184
176 do_gettimeofday(&now); 185 now = ktime_get();
177 186
178 elapsed_time = 187 elapsed_time = ktime_to_us(ktime_sub(now, devpriv->last));
179 1000000 * (now.tv_sec - devpriv->last.tv_sec) + now.tv_usec -
180 devpriv->last.tv_usec;
181 devpriv->last = now; 188 devpriv->last = now;
182 num_scans = 189 num_scans =
183 (devpriv->usec_remainder + elapsed_time) / devpriv->scan_period; 190 (devpriv->usec_remainder + elapsed_time) / devpriv->scan_period;
184 devpriv->usec_remainder = 191 devpriv->usec_remainder =
185 (devpriv->usec_remainder + elapsed_time) % devpriv->scan_period; 192 (devpriv->usec_remainder + elapsed_time) % devpriv->scan_period;
186 193
187 if (cmd->stop_src == TRIG_COUNT) { 194 num_scans = comedi_nscans_left(s, num_scans);
188 unsigned int remaining = cmd->stop_arg - devpriv->ai_count;
189
190 if (num_scans >= remaining) {
191 /* about to finish */
192 num_scans = remaining;
193 stopping = true;
194 }
195 }
196
197 for (i = 0; i < num_scans; i++) { 195 for (i = 0; i < num_scans; i++) {
198 for (j = 0; j < cmd->chanlist_len; j++) { 196 for (j = 0; j < cmd->chanlist_len; j++) {
199 unsigned short sample; 197 unsigned short sample;
@@ -203,20 +201,19 @@ static void waveform_ai_interrupt(unsigned long arg)
203 devpriv->usec_current + 201 devpriv->usec_current +
204 i * devpriv->scan_period + 202 i * devpriv->scan_period +
205 j * devpriv->convert_period); 203 j * devpriv->convert_period);
206 cfc_write_to_buffer(dev->read_subdev, sample); 204 comedi_buf_write_samples(s, &sample, 1);
207 } 205 }
208 } 206 }
209 207
210 devpriv->ai_count += i;
211 devpriv->usec_current += elapsed_time; 208 devpriv->usec_current += elapsed_time;
212 devpriv->usec_current %= devpriv->usec_period; 209 devpriv->usec_current %= devpriv->usec_period;
213 210
214 if (stopping) 211 if (cmd->stop_src == TRIG_COUNT && async->scans_done >= cmd->stop_arg)
215 async->events |= COMEDI_CB_EOA; 212 async->events |= COMEDI_CB_EOA;
216 else 213 else
217 mod_timer(&devpriv->timer, jiffies + 1); 214 mod_timer(&devpriv->timer, jiffies + 1);
218 215
219 comedi_event(dev, dev->read_subdev); 216 comedi_handle_events(dev, s);
220} 217}
221 218
222static int waveform_ai_cmdtest(struct comedi_device *dev, 219static int waveform_ai_cmdtest(struct comedi_device *dev,
@@ -308,7 +305,6 @@ static int waveform_ai_cmd(struct comedi_device *dev,
308 return -1; 305 return -1;
309 } 306 }
310 307
311 devpriv->ai_count = 0;
312 devpriv->scan_period = cmd->scan_begin_arg / nano_per_micro; 308 devpriv->scan_period = cmd->scan_begin_arg / nano_per_micro;
313 309
314 if (cmd->convert_src == TRIG_NOW) 310 if (cmd->convert_src == TRIG_NOW)
@@ -316,11 +312,16 @@ static int waveform_ai_cmd(struct comedi_device *dev,
316 else /* TRIG_TIMER */ 312 else /* TRIG_TIMER */
317 devpriv->convert_period = cmd->convert_arg / nano_per_micro; 313 devpriv->convert_period = cmd->convert_arg / nano_per_micro;
318 314
319 do_gettimeofday(&devpriv->last); 315 devpriv->last = ktime_get();
320 devpriv->usec_current = devpriv->last.tv_usec % devpriv->usec_period; 316 devpriv->usec_current =
317 ((u32)ktime_to_us(devpriv->last)) % devpriv->usec_period;
321 devpriv->usec_remainder = 0; 318 devpriv->usec_remainder = 0;
322 319
323 devpriv->timer.expires = jiffies + 1; 320 devpriv->timer.expires = jiffies + 1;
321 /* mark command as active */
322 smp_mb__before_atomic();
323 set_bit(WAVEFORM_AI_RUNNING, &devpriv->state_bits);
324 smp_mb__after_atomic();
324 add_timer(&devpriv->timer); 325 add_timer(&devpriv->timer);
325 return 0; 326 return 0;
326} 327}
@@ -330,7 +331,11 @@ static int waveform_ai_cancel(struct comedi_device *dev,
330{ 331{
331 struct waveform_private *devpriv = dev->private; 332 struct waveform_private *devpriv = dev->private;
332 333
333 del_timer_sync(&devpriv->timer); 334 /* mark command as no longer active */
335 clear_bit(WAVEFORM_AI_RUNNING, &devpriv->state_bits);
336 smp_mb__after_atomic();
337 /* cannot call del_timer_sync() as may be called from timer routine */
338 del_timer(&devpriv->timer);
334 return 0; 339 return 0;
335} 340}
336 341
@@ -405,7 +410,7 @@ static int waveform_attach(struct comedi_device *dev,
405 dev->write_subdev = s; 410 dev->write_subdev = s;
406 /* analog output subdevice (loopback) */ 411 /* analog output subdevice (loopback) */
407 s->type = COMEDI_SUBD_AO; 412 s->type = COMEDI_SUBD_AO;
408 s->subdev_flags = SDF_WRITEABLE | SDF_GROUND; 413 s->subdev_flags = SDF_WRITABLE | SDF_GROUND;
409 s->n_chan = N_CHANS; 414 s->n_chan = N_CHANS;
410 s->maxdata = 0xffff; 415 s->maxdata = 0xffff;
411 s->range_table = &waveform_ai_ranges; 416 s->range_table = &waveform_ai_ranges;
@@ -432,7 +437,7 @@ static void waveform_detach(struct comedi_device *dev)
432 struct waveform_private *devpriv = dev->private; 437 struct waveform_private *devpriv = dev->private;
433 438
434 if (devpriv) 439 if (devpriv)
435 waveform_ai_cancel(dev, dev->read_subdev); 440 del_timer_sync(&devpriv->timer);
436} 441}
437 442
438static struct comedi_driver waveform_driver = { 443static struct comedi_driver waveform_driver = {
diff --git a/drivers/staging/comedi/drivers/dac02.c b/drivers/staging/comedi/drivers/dac02.c
index 34cbe83f0ce7..beb36c8dd00a 100644
--- a/drivers/staging/comedi/drivers/dac02.c
+++ b/drivers/staging/comedi/drivers/dac02.c
@@ -129,7 +129,6 @@ static int dac02_attach(struct comedi_device *dev, struct comedi_devconfig *it)
129 s->maxdata = 0x0fff; 129 s->maxdata = 0x0fff;
130 s->range_table = &das02_ao_ranges; 130 s->range_table = &das02_ao_ranges;
131 s->insn_write = dac02_ao_insn_write; 131 s->insn_write = dac02_ao_insn_write;
132 s->insn_read = comedi_readback_insn_read;
133 132
134 ret = comedi_alloc_subdev_readback(s); 133 ret = comedi_alloc_subdev_readback(s);
135 if (ret) 134 if (ret)
diff --git a/drivers/staging/comedi/drivers/daqboard2000.c b/drivers/staging/comedi/drivers/daqboard2000.c
index e5b5a8133b34..96697fbb5239 100644
--- a/drivers/staging/comedi/drivers/daqboard2000.c
+++ b/drivers/staging/comedi/drivers/daqboard2000.c
@@ -707,7 +707,6 @@ static int daqboard2000_auto_attach(struct comedi_device *dev,
707 s->n_chan = 2; 707 s->n_chan = 2;
708 s->maxdata = 0xffff; 708 s->maxdata = 0xffff;
709 s->insn_write = daqboard2000_ao_insn_write; 709 s->insn_write = daqboard2000_ao_insn_write;
710 s->insn_read = comedi_readback_insn_read;
711 s->range_table = &range_bipolar10; 710 s->range_table = &range_bipolar10;
712 711
713 result = comedi_alloc_subdev_readback(s); 712 result = comedi_alloc_subdev_readback(s);
diff --git a/drivers/staging/comedi/drivers/das08.c b/drivers/staging/comedi/drivers/das08.c
index bdb671a66e22..20a9f0eb72b5 100644
--- a/drivers/staging/comedi/drivers/das08.c
+++ b/drivers/staging/comedi/drivers/das08.c
@@ -474,7 +474,6 @@ int das08_common_attach(struct comedi_device *dev, unsigned long iobase)
474 s->maxdata = (1 << thisboard->ao_nbits) - 1; 474 s->maxdata = (1 << thisboard->ao_nbits) - 1;
475 s->range_table = &range_bipolar5; 475 s->range_table = &range_bipolar5;
476 s->insn_write = das08_ao_insn_write; 476 s->insn_write = das08_ao_insn_write;
477 s->insn_read = comedi_readback_insn_read;
478 477
479 ret = comedi_alloc_subdev_readback(s); 478 ret = comedi_alloc_subdev_readback(s);
480 if (ret) 479 if (ret)
@@ -507,7 +506,7 @@ int das08_common_attach(struct comedi_device *dev, unsigned long iobase)
507 /* do */ 506 /* do */
508 if (thisboard->do_nchan) { 507 if (thisboard->do_nchan) {
509 s->type = COMEDI_SUBD_DO; 508 s->type = COMEDI_SUBD_DO;
510 s->subdev_flags = SDF_WRITABLE | SDF_READABLE; 509 s->subdev_flags = SDF_WRITABLE;
511 s->n_chan = thisboard->do_nchan; 510 s->n_chan = thisboard->do_nchan;
512 s->maxdata = 1; 511 s->maxdata = 1;
513 s->range_table = &range_digital; 512 s->range_table = &range_digital;
diff --git a/drivers/staging/comedi/drivers/das16.c b/drivers/staging/comedi/drivers/das16.c
index 2d8e86cec47a..2436057304a3 100644
--- a/drivers/staging/comedi/drivers/das16.c
+++ b/drivers/staging/comedi/drivers/das16.c
@@ -541,6 +541,7 @@ static void das16_interrupt(struct comedi_device *dev)
541 struct comedi_cmd *cmd = &async->cmd; 541 struct comedi_cmd *cmd = &async->cmd;
542 unsigned long spin_flags; 542 unsigned long spin_flags;
543 unsigned long dma_flags; 543 unsigned long dma_flags;
544 unsigned int nsamples;
544 int num_bytes, residue; 545 int num_bytes, residue;
545 int buffer_index; 546 int buffer_index;
546 547
@@ -583,21 +584,25 @@ static void das16_interrupt(struct comedi_device *dev)
583 584
584 spin_unlock_irqrestore(&dev->spinlock, spin_flags); 585 spin_unlock_irqrestore(&dev->spinlock, spin_flags);
585 586
586 cfc_write_array_to_buffer(s, 587 nsamples = comedi_bytes_to_samples(s, num_bytes);
587 devpriv->dma_buffer[buffer_index], num_bytes); 588 comedi_buf_write_samples(s, devpriv->dma_buffer[buffer_index],
589 nsamples);
588 590
589 cfc_handle_events(dev, s); 591 comedi_handle_events(dev, s);
590} 592}
591 593
592static void das16_timer_interrupt(unsigned long arg) 594static void das16_timer_interrupt(unsigned long arg)
593{ 595{
594 struct comedi_device *dev = (struct comedi_device *)arg; 596 struct comedi_device *dev = (struct comedi_device *)arg;
595 struct das16_private_struct *devpriv = dev->private; 597 struct das16_private_struct *devpriv = dev->private;
598 unsigned long flags;
596 599
597 das16_interrupt(dev); 600 das16_interrupt(dev);
598 601
602 spin_lock_irqsave(&dev->spinlock, flags);
599 if (devpriv->timer_running) 603 if (devpriv->timer_running)
600 mod_timer(&devpriv->timer, jiffies + timer_period()); 604 mod_timer(&devpriv->timer, jiffies + timer_period());
605 spin_unlock_irqrestore(&dev->spinlock, flags);
601} 606}
602 607
603static int das16_ai_check_chanlist(struct comedi_device *dev, 608static int das16_ai_check_chanlist(struct comedi_device *dev,
@@ -764,7 +769,7 @@ static int das16_cmd_exec(struct comedi_device *dev, struct comedi_subdevice *s)
764 return -1; 769 return -1;
765 } 770 }
766 771
767 devpriv->adc_byte_count = cmd->stop_arg * cfc_bytes_per_scan(s); 772 devpriv->adc_byte_count = cmd->stop_arg * comedi_bytes_per_scan(s);
768 773
769 if (devpriv->can_burst) 774 if (devpriv->can_burst)
770 outb(DAS1600_CONV_DISABLE, dev->iobase + DAS1600_CONV_REG); 775 outb(DAS1600_CONV_DISABLE, dev->iobase + DAS1600_CONV_REG);
@@ -814,7 +819,8 @@ static int das16_cmd_exec(struct comedi_device *dev, struct comedi_subdevice *s)
814 enable_dma(devpriv->dma_chan); 819 enable_dma(devpriv->dma_chan);
815 release_dma_lock(flags); 820 release_dma_lock(flags);
816 821
817 /* set up interrupt */ 822 /* set up timer */
823 spin_lock_irqsave(&dev->spinlock, flags);
818 devpriv->timer_running = 1; 824 devpriv->timer_running = 1;
819 devpriv->timer.expires = jiffies + timer_period(); 825 devpriv->timer.expires = jiffies + timer_period();
820 add_timer(&devpriv->timer); 826 add_timer(&devpriv->timer);
@@ -823,6 +829,7 @@ static int das16_cmd_exec(struct comedi_device *dev, struct comedi_subdevice *s)
823 829
824 if (devpriv->can_burst) 830 if (devpriv->can_burst)
825 outb(0, dev->iobase + DAS1600_CONV_REG); 831 outb(0, dev->iobase + DAS1600_CONV_REG);
832 spin_unlock_irqrestore(&dev->spinlock, flags);
826 833
827 return 0; 834 return 0;
828} 835}
@@ -856,8 +863,9 @@ static void das16_ai_munge(struct comedi_device *dev,
856 unsigned int num_bytes, 863 unsigned int num_bytes,
857 unsigned int start_chan_index) 864 unsigned int start_chan_index)
858{ 865{
859 unsigned int i, num_samples = num_bytes / sizeof(short);
860 unsigned short *data = array; 866 unsigned short *data = array;
867 unsigned int num_samples = comedi_bytes_to_samples(s, num_bytes);
868 unsigned int i;
861 869
862 for (i = 0; i < num_samples; i++) { 870 for (i = 0; i < num_samples; i++) {
863 data[i] = le16_to_cpu(data[i]); 871 data[i] = le16_to_cpu(data[i]);
@@ -1167,7 +1175,6 @@ static int das16_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1167 s->maxdata = 0x0fff; 1175 s->maxdata = 0x0fff;
1168 s->range_table = devpriv->user_ao_range_table; 1176 s->range_table = devpriv->user_ao_range_table;
1169 s->insn_write = das16_ao_insn_write; 1177 s->insn_write = das16_ao_insn_write;
1170 s->insn_read = comedi_readback_insn_read;
1171 1178
1172 ret = comedi_alloc_subdev_readback(s); 1179 ret = comedi_alloc_subdev_readback(s);
1173 if (ret) 1180 if (ret)
@@ -1226,6 +1233,8 @@ static void das16_detach(struct comedi_device *dev)
1226 int i; 1233 int i;
1227 1234
1228 if (devpriv) { 1235 if (devpriv) {
1236 if (devpriv->timer.data)
1237 del_timer_sync(&devpriv->timer);
1229 if (dev->iobase) 1238 if (dev->iobase)
1230 das16_reset(dev); 1239 das16_reset(dev);
1231 1240
diff --git a/drivers/staging/comedi/drivers/das16m1.c b/drivers/staging/comedi/drivers/das16m1.c
index 24b63c452f51..80f41b7e8273 100644
--- a/drivers/staging/comedi/drivers/das16m1.c
+++ b/drivers/staging/comedi/drivers/das16m1.c
@@ -442,8 +442,7 @@ static void das16m1_handler(struct comedi_device *dev, unsigned int status)
442 num_samples = FIFO_SIZE; 442 num_samples = FIFO_SIZE;
443 insw(dev->iobase, devpriv->ai_buffer, num_samples); 443 insw(dev->iobase, devpriv->ai_buffer, num_samples);
444 munge_sample_array(devpriv->ai_buffer, num_samples); 444 munge_sample_array(devpriv->ai_buffer, num_samples);
445 cfc_write_array_to_buffer(s, devpriv->ai_buffer, 445 comedi_buf_write_samples(s, devpriv->ai_buffer, num_samples);
446 num_samples * sizeof(short));
447 devpriv->adc_count += num_samples; 446 devpriv->adc_count += num_samples;
448 447
449 if (cmd->stop_src == TRIG_COUNT) { 448 if (cmd->stop_src == TRIG_COUNT) {
@@ -460,7 +459,7 @@ static void das16m1_handler(struct comedi_device *dev, unsigned int status)
460 dev_err(dev->class_dev, "fifo overflow\n"); 459 dev_err(dev->class_dev, "fifo overflow\n");
461 } 460 }
462 461
463 cfc_handle_events(dev, s); 462 comedi_handle_events(dev, s);
464} 463}
465 464
466static int das16m1_poll(struct comedi_device *dev, struct comedi_subdevice *s) 465static int das16m1_poll(struct comedi_device *dev, struct comedi_subdevice *s)
@@ -598,7 +597,7 @@ static int das16m1_attach(struct comedi_device *dev,
598 s = &dev->subdevices[2]; 597 s = &dev->subdevices[2];
599 /* do */ 598 /* do */
600 s->type = COMEDI_SUBD_DO; 599 s->type = COMEDI_SUBD_DO;
601 s->subdev_flags = SDF_WRITABLE | SDF_READABLE; 600 s->subdev_flags = SDF_WRITABLE;
602 s->n_chan = 4; 601 s->n_chan = 4;
603 s->maxdata = 1; 602 s->maxdata = 1;
604 s->range_table = &range_digital; 603 s->range_table = &range_digital;
diff --git a/drivers/staging/comedi/drivers/das1800.c b/drivers/staging/comedi/drivers/das1800.c
index a53d87ce9b14..be825d21a185 100644
--- a/drivers/staging/comedi/drivers/das1800.c
+++ b/drivers/staging/comedi/drivers/das1800.c
@@ -421,7 +421,6 @@ static const struct das1800_board das1800_boards[] = {
421}; 421};
422 422
423struct das1800_private { 423struct das1800_private {
424 unsigned int count; /* number of data points left to be taken */
425 unsigned int divisor1; /* value to load into board's counter 1 for timed conversions */ 424 unsigned int divisor1; /* value to load into board's counter 1 for timed conversions */
426 unsigned int divisor2; /* value to load into board's counter 2 for timed conversions */ 425 unsigned int divisor2; /* value to load into board's counter 2 for timed conversions */
427 int irq_dma_bits; /* bits for control register b */ 426 int irq_dma_bits; /* bits for control register b */
@@ -479,42 +478,33 @@ static void das1800_handle_fifo_half_full(struct comedi_device *dev,
479 struct comedi_subdevice *s) 478 struct comedi_subdevice *s)
480{ 479{
481 struct das1800_private *devpriv = dev->private; 480 struct das1800_private *devpriv = dev->private;
482 int numPoints = 0; /* number of points to read */ 481 unsigned int nsamples = comedi_nsamples_left(s, FIFO_SIZE / 2);
483 struct comedi_cmd *cmd = &s->async->cmd;
484 482
485 numPoints = FIFO_SIZE / 2; 483 insw(dev->iobase + DAS1800_FIFO, devpriv->ai_buf0, nsamples);
486 /* if we only need some of the points */ 484 munge_data(dev, devpriv->ai_buf0, nsamples);
487 if (cmd->stop_src == TRIG_COUNT && devpriv->count < numPoints) 485 comedi_buf_write_samples(s, devpriv->ai_buf0, nsamples);
488 numPoints = devpriv->count;
489 insw(dev->iobase + DAS1800_FIFO, devpriv->ai_buf0, numPoints);
490 munge_data(dev, devpriv->ai_buf0, numPoints);
491 cfc_write_array_to_buffer(s, devpriv->ai_buf0,
492 numPoints * sizeof(devpriv->ai_buf0[0]));
493 if (cmd->stop_src == TRIG_COUNT)
494 devpriv->count -= numPoints;
495} 486}
496 487
497static void das1800_handle_fifo_not_empty(struct comedi_device *dev, 488static void das1800_handle_fifo_not_empty(struct comedi_device *dev,
498 struct comedi_subdevice *s) 489 struct comedi_subdevice *s)
499{ 490{
500 struct das1800_private *devpriv = dev->private; 491 struct comedi_cmd *cmd = &s->async->cmd;
501 unsigned short dpnt; 492 unsigned short dpnt;
502 int unipolar; 493 int unipolar;
503 struct comedi_cmd *cmd = &s->async->cmd;
504 494
505 unipolar = inb(dev->iobase + DAS1800_CONTROL_C) & UB; 495 unipolar = inb(dev->iobase + DAS1800_CONTROL_C) & UB;
506 496
507 while (inb(dev->iobase + DAS1800_STATUS) & FNE) { 497 while (inb(dev->iobase + DAS1800_STATUS) & FNE) {
508 if (cmd->stop_src == TRIG_COUNT && devpriv->count == 0)
509 break;
510 dpnt = inw(dev->iobase + DAS1800_FIFO); 498 dpnt = inw(dev->iobase + DAS1800_FIFO);
511 /* convert to unsigned type if we are in a bipolar mode */ 499 /* convert to unsigned type if we are in a bipolar mode */
512 if (!unipolar) 500 if (!unipolar)
513 ; 501 ;
514 dpnt = munge_bipolar_sample(dev, dpnt); 502 dpnt = munge_bipolar_sample(dev, dpnt);
515 cfc_write_to_buffer(s, dpnt); 503 comedi_buf_write_samples(s, &dpnt, 1);
516 if (cmd->stop_src == TRIG_COUNT) 504
517 devpriv->count--; 505 if (cmd->stop_src == TRIG_COUNT &&
506 s->async->scans_done >= cmd->stop_arg)
507 break;
518 } 508 }
519} 509}
520 510
@@ -525,8 +515,8 @@ static void das1800_flush_dma_channel(struct comedi_device *dev,
525 unsigned int channel, uint16_t *buffer) 515 unsigned int channel, uint16_t *buffer)
526{ 516{
527 struct das1800_private *devpriv = dev->private; 517 struct das1800_private *devpriv = dev->private;
528 unsigned int num_bytes, num_samples; 518 unsigned int nbytes;
529 struct comedi_cmd *cmd = &s->async->cmd; 519 unsigned int nsamples;
530 520
531 disable_dma(channel); 521 disable_dma(channel);
532 522
@@ -535,17 +525,12 @@ static void das1800_flush_dma_channel(struct comedi_device *dev,
535 clear_dma_ff(channel); 525 clear_dma_ff(channel);
536 526
537 /* figure out how many points to read */ 527 /* figure out how many points to read */
538 num_bytes = devpriv->dma_transfer_size - get_dma_residue(channel); 528 nbytes = devpriv->dma_transfer_size - get_dma_residue(channel);
539 num_samples = num_bytes / sizeof(short); 529 nsamples = comedi_bytes_to_samples(s, nbytes);
540 530 nsamples = comedi_nsamples_left(s, nsamples);
541 /* if we only need some of the points */
542 if (cmd->stop_src == TRIG_COUNT && devpriv->count < num_samples)
543 num_samples = devpriv->count;
544 531
545 munge_data(dev, buffer, num_samples); 532 munge_data(dev, buffer, nsamples);
546 cfc_write_array_to_buffer(s, buffer, num_bytes); 533 comedi_buf_write_samples(s, buffer, nsamples);
547 if (cmd->stop_src == TRIG_COUNT)
548 devpriv->count -= num_samples;
549} 534}
550 535
551/* flushes remaining data from board when external trigger has stopped acquisition 536/* flushes remaining data from board when external trigger has stopped acquisition
@@ -649,14 +634,13 @@ static void das1800_ai_handler(struct comedi_device *dev)
649 das1800_handle_fifo_not_empty(dev, s); 634 das1800_handle_fifo_not_empty(dev, s);
650 } 635 }
651 636
652 async->events |= COMEDI_CB_BLOCK;
653 /* if the card's fifo has overflowed */ 637 /* if the card's fifo has overflowed */
654 if (status & OVF) { 638 if (status & OVF) {
655 /* clear OVF interrupt bit */ 639 /* clear OVF interrupt bit */
656 outb(CLEAR_INTR_MASK & ~OVF, dev->iobase + DAS1800_STATUS); 640 outb(CLEAR_INTR_MASK & ~OVF, dev->iobase + DAS1800_STATUS);
657 dev_err(dev->class_dev, "FIFO overflow\n"); 641 dev_err(dev->class_dev, "FIFO overflow\n");
658 async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; 642 async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA;
659 cfc_handle_events(dev, s); 643 comedi_handle_events(dev, s);
660 return; 644 return;
661 } 645 }
662 /* stop taking data if appropriate */ 646 /* stop taking data if appropriate */
@@ -670,11 +654,12 @@ static void das1800_ai_handler(struct comedi_device *dev)
670 else 654 else
671 das1800_handle_fifo_not_empty(dev, s); 655 das1800_handle_fifo_not_empty(dev, s);
672 async->events |= COMEDI_CB_EOA; 656 async->events |= COMEDI_CB_EOA;
673 } else if (cmd->stop_src == TRIG_COUNT && devpriv->count == 0) { /* stop_src TRIG_COUNT */ 657 } else if (cmd->stop_src == TRIG_COUNT &&
658 async->scans_done >= cmd->stop_arg) {
674 async->events |= COMEDI_CB_EOA; 659 async->events |= COMEDI_CB_EOA;
675 } 660 }
676 661
677 cfc_handle_events(dev, s); 662 comedi_handle_events(dev, s);
678} 663}
679 664
680static int das1800_ai_poll(struct comedi_device *dev, 665static int das1800_ai_poll(struct comedi_device *dev,
@@ -1102,9 +1087,6 @@ static int das1800_ai_do_cmd(struct comedi_device *dev,
1102 /* interrupt fifo half full */ 1087 /* interrupt fifo half full */
1103 devpriv->irq_dma_bits |= FIMD; 1088 devpriv->irq_dma_bits |= FIMD;
1104 } 1089 }
1105 /* determine how many conversions we need */
1106 if (cmd->stop_src == TRIG_COUNT)
1107 devpriv->count = cmd->stop_arg * cmd->chanlist_len;
1108 1090
1109 das1800_cancel(dev, s); 1091 das1800_cancel(dev, s);
1110 1092
@@ -1515,7 +1497,7 @@ static int das1800_attach(struct comedi_device *dev,
1515 /* do */ 1497 /* do */
1516 s = &dev->subdevices[3]; 1498 s = &dev->subdevices[3];
1517 s->type = COMEDI_SUBD_DO; 1499 s->type = COMEDI_SUBD_DO;
1518 s->subdev_flags = SDF_WRITABLE | SDF_READABLE; 1500 s->subdev_flags = SDF_WRITABLE;
1519 s->n_chan = thisboard->do_n_chan; 1501 s->n_chan = thisboard->do_n_chan;
1520 s->maxdata = 1; 1502 s->maxdata = 1;
1521 s->range_table = &range_digital; 1503 s->range_table = &range_digital;
diff --git a/drivers/staging/comedi/drivers/das6402.c b/drivers/staging/comedi/drivers/das6402.c
index ab6e40608885..780f4f646ea0 100644
--- a/drivers/staging/comedi/drivers/das6402.c
+++ b/drivers/staging/comedi/drivers/das6402.c
@@ -35,6 +35,7 @@
35#include <linux/interrupt.h> 35#include <linux/interrupt.h>
36 36
37#include "../comedidev.h" 37#include "../comedidev.h"
38#include "comedi_fc.h"
38#include "8253.h" 39#include "8253.h"
39 40
40/* 41/*
@@ -192,26 +193,197 @@ static void das6402_enable_counter(struct comedi_device *dev, bool load)
192 } 193 }
193} 194}
194 195
196static unsigned int das6402_ai_read_sample(struct comedi_device *dev,
197 struct comedi_subdevice *s)
198{
199 unsigned int val;
200
201 val = inw(dev->iobase + DAS6402_AI_DATA_REG);
202 if (s->maxdata == 0x0fff)
203 val >>= 4;
204 return val;
205}
206
195static irqreturn_t das6402_interrupt(int irq, void *d) 207static irqreturn_t das6402_interrupt(int irq, void *d)
196{ 208{
197 struct comedi_device *dev = d; 209 struct comedi_device *dev = d;
210 struct comedi_subdevice *s = dev->read_subdev;
211 struct comedi_async *async = s->async;
212 struct comedi_cmd *cmd = &async->cmd;
213 unsigned int status;
214
215 status = inb(dev->iobase + DAS6402_STATUS_REG);
216 if ((status & DAS6402_STATUS_INT) == 0)
217 return IRQ_NONE;
218
219 if (status & DAS6402_STATUS_FFULL) {
220 async->events |= COMEDI_CB_OVERFLOW;
221 } else if (status & DAS6402_STATUS_FFNE) {
222 unsigned int val;
223
224 val = das6402_ai_read_sample(dev, s);
225 comedi_buf_write_samples(s, &val, 1);
226
227 if (cmd->stop_src == TRIG_COUNT &&
228 async->scans_done >= cmd->stop_arg)
229 async->events |= COMEDI_CB_EOA;
230 }
198 231
199 das6402_clear_all_interrupts(dev); 232 das6402_clear_all_interrupts(dev);
200 233
234 comedi_handle_events(dev, s);
235
201 return IRQ_HANDLED; 236 return IRQ_HANDLED;
202} 237}
203 238
239static void das6402_ai_set_mode(struct comedi_device *dev,
240 struct comedi_subdevice *s,
241 unsigned int chanspec,
242 unsigned int mode)
243{
244 unsigned int range = CR_RANGE(chanspec);
245 unsigned int aref = CR_AREF(chanspec);
246
247 mode |= DAS6402_MODE_RANGE(range);
248 if (aref == AREF_GROUND)
249 mode |= DAS6402_MODE_SE;
250 if (comedi_range_is_unipolar(s, range))
251 mode |= DAS6402_MODE_UNI;
252
253 das6402_set_mode(dev, mode);
254}
255
204static int das6402_ai_cmd(struct comedi_device *dev, 256static int das6402_ai_cmd(struct comedi_device *dev,
205 struct comedi_subdevice *s) 257 struct comedi_subdevice *s)
206{ 258{
207 return -EINVAL; 259 struct das6402_private *devpriv = dev->private;
260 struct comedi_cmd *cmd = &s->async->cmd;
261 unsigned int chan_lo = CR_CHAN(cmd->chanlist[0]);
262 unsigned int chan_hi = CR_CHAN(cmd->chanlist[cmd->chanlist_len - 1]);
263
264 das6402_ai_set_mode(dev, s, cmd->chanlist[0], DAS6402_MODE_FIFONEPTY);
265
266 /* load the mux for chanlist conversion */
267 outw(DAS6402_AI_MUX_HI(chan_hi) | DAS6402_AI_MUX_LO(chan_lo),
268 dev->iobase + DAS6402_AI_MUX_REG);
269
270 das6402_enable_counter(dev, true);
271
272 /* enable interrupt and pacer trigger */
273 outb(DAS6402_CTRL_INTE |
274 DAS6402_CTRL_IRQ(devpriv->irq) |
275 DAS6402_CTRL_PACER_TRIG, dev->iobase + DAS6402_CTRL_REG);
276
277 return 0;
278}
279
280static int das6402_ai_check_chanlist(struct comedi_device *dev,
281 struct comedi_subdevice *s,
282 struct comedi_cmd *cmd)
283{
284 unsigned int chan0 = CR_CHAN(cmd->chanlist[0]);
285 unsigned int range0 = CR_RANGE(cmd->chanlist[0]);
286 unsigned int aref0 = CR_AREF(cmd->chanlist[0]);
287 int i;
288
289 for (i = 1; i < cmd->chanlist_len; i++) {
290 unsigned int chan = CR_CHAN(cmd->chanlist[i]);
291 unsigned int range = CR_RANGE(cmd->chanlist[i]);
292 unsigned int aref = CR_AREF(cmd->chanlist[i]);
293
294 if (chan != chan0 + i) {
295 dev_dbg(dev->class_dev,
296 "chanlist must be consecutive\n");
297 return -EINVAL;
298 }
299
300 if (range != range0) {
301 dev_dbg(dev->class_dev,
302 "chanlist must have the same range\n");
303 return -EINVAL;
304 }
305
306 if (aref != aref0) {
307 dev_dbg(dev->class_dev,
308 "chanlist must have the same reference\n");
309 return -EINVAL;
310 }
311
312 if (aref0 == AREF_DIFF && chan > (s->n_chan / 2)) {
313 dev_dbg(dev->class_dev,
314 "chanlist differential channel to large\n");
315 return -EINVAL;
316 }
317 }
318 return 0;
208} 319}
209 320
210static int das6402_ai_cmdtest(struct comedi_device *dev, 321static int das6402_ai_cmdtest(struct comedi_device *dev,
211 struct comedi_subdevice *s, 322 struct comedi_subdevice *s,
212 struct comedi_cmd *cmd) 323 struct comedi_cmd *cmd)
213{ 324{
214 return -EINVAL; 325 struct das6402_private *devpriv = dev->private;
326 int err = 0;
327 unsigned int arg;
328
329 /* Step 1 : check if triggers are trivially valid */
330
331 err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
332 err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_FOLLOW);
333 err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_TIMER);
334 err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
335 err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
336
337 if (err)
338 return 1;
339
340 /* Step 2a : make sure trigger sources are unique */
341
342 err |= cfc_check_trigger_is_unique(cmd->stop_src);
343
344 /* Step 2b : and mutually compatible */
345
346 if (err)
347 return 2;
348
349 /* Step 3: check if arguments are trivially valid */
350
351 err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
352 err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0);
353 err |= cfc_check_trigger_arg_min(&cmd->convert_arg, 10000);
354 err |= cfc_check_trigger_arg_min(&cmd->chanlist_len, 1);
355 err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len);
356
357 if (cmd->stop_src == TRIG_COUNT)
358 err |= cfc_check_trigger_arg_min(&cmd->stop_arg, 1);
359 else /* TRIG_NONE */
360 err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0);
361
362 if (err)
363 return 3;
364
365 /* step 4: fix up any arguments */
366
367 if (cmd->convert_src == TRIG_TIMER) {
368 arg = cmd->convert_arg;
369 i8253_cascade_ns_to_timer(I8254_OSC_BASE_10MHZ,
370 &devpriv->divider1,
371 &devpriv->divider2,
372 &arg, cmd->flags);
373 err |= cfc_check_trigger_arg_is(&cmd->convert_arg, arg);
374 }
375
376 if (err)
377 return 4;
378
379 /* Step 5: check channel list if it exists */
380 if (cmd->chanlist && cmd->chanlist_len > 0)
381 err |= das6402_ai_check_chanlist(dev, s, cmd);
382
383 if (err)
384 return 5;
385
386 return 0;
215} 387}
216 388
217static int das6402_ai_cancel(struct comedi_device *dev, 389static int das6402_ai_cancel(struct comedi_device *dev,
@@ -246,26 +418,17 @@ static int das6402_ai_insn_read(struct comedi_device *dev,
246 unsigned int *data) 418 unsigned int *data)
247{ 419{
248 unsigned int chan = CR_CHAN(insn->chanspec); 420 unsigned int chan = CR_CHAN(insn->chanspec);
249 unsigned int range = CR_RANGE(insn->chanspec);
250 unsigned int aref = CR_AREF(insn->chanspec); 421 unsigned int aref = CR_AREF(insn->chanspec);
251 unsigned int val;
252 int ret; 422 int ret;
253 int i; 423 int i;
254 424
255 val = DAS6402_MODE_RANGE(range) | DAS6402_MODE_POLLED; 425 if (aref == AREF_DIFF && chan > (s->n_chan / 2))
256 if (aref == AREF_DIFF) { 426 return -EINVAL;
257 if (chan > s->n_chan / 2)
258 return -EINVAL;
259 } else {
260 val |= DAS6402_MODE_SE;
261 }
262 if (comedi_range_is_unipolar(s, range))
263 val |= DAS6402_MODE_UNI;
264 427
265 /* enable software conversion trigger */ 428 /* enable software conversion trigger */
266 outb(DAS6402_CTRL_SOFT_TRIG, dev->iobase + DAS6402_CTRL_REG); 429 outb(DAS6402_CTRL_SOFT_TRIG, dev->iobase + DAS6402_CTRL_REG);
267 430
268 das6402_set_mode(dev, val); 431 das6402_ai_set_mode(dev, s, insn->chanspec, DAS6402_MODE_POLLED);
269 432
270 /* load the mux for single channel conversion */ 433 /* load the mux for single channel conversion */
271 outw(DAS6402_AI_MUX_HI(chan) | DAS6402_AI_MUX_LO(chan), 434 outw(DAS6402_AI_MUX_HI(chan) | DAS6402_AI_MUX_LO(chan),
@@ -279,12 +442,7 @@ static int das6402_ai_insn_read(struct comedi_device *dev,
279 if (ret) 442 if (ret)
280 break; 443 break;
281 444
282 val = inw(dev->iobase + DAS6402_AI_DATA_REG); 445 data[i] = das6402_ai_read_sample(dev, s);
283
284 if (s->maxdata == 0x0fff)
285 val >>= 4;
286
287 data[i] = val;
288 } 446 }
289 447
290 das6402_ai_clear_eoc(dev); 448 das6402_ai_clear_eoc(dev);
@@ -497,7 +655,7 @@ static int das6402_attach(struct comedi_device *dev,
497 /* Analog Output subdevice */ 655 /* Analog Output subdevice */
498 s = &dev->subdevices[1]; 656 s = &dev->subdevices[1];
499 s->type = COMEDI_SUBD_AO; 657 s->type = COMEDI_SUBD_AO;
500 s->subdev_flags = SDF_WRITEABLE; 658 s->subdev_flags = SDF_WRITABLE;
501 s->n_chan = 2; 659 s->n_chan = 2;
502 s->maxdata = board->maxdata; 660 s->maxdata = board->maxdata;
503 s->range_table = &das6402_ao_ranges; 661 s->range_table = &das6402_ao_ranges;
@@ -520,7 +678,7 @@ static int das6402_attach(struct comedi_device *dev,
520 /* Digital Input subdevice */ 678 /* Digital Input subdevice */
521 s = &dev->subdevices[3]; 679 s = &dev->subdevices[3];
522 s->type = COMEDI_SUBD_DO; 680 s->type = COMEDI_SUBD_DO;
523 s->subdev_flags = SDF_WRITEABLE; 681 s->subdev_flags = SDF_WRITABLE;
524 s->n_chan = 8; 682 s->n_chan = 8;
525 s->maxdata = 1; 683 s->maxdata = 1;
526 s->range_table = &range_digital; 684 s->range_table = &range_digital;
diff --git a/drivers/staging/comedi/drivers/das800.c b/drivers/staging/comedi/drivers/das800.c
index d75e5528258c..e5bdc2423445 100644
--- a/drivers/staging/comedi/drivers/das800.c
+++ b/drivers/staging/comedi/drivers/das800.c
@@ -219,7 +219,6 @@ static const struct das800_board das800_boards[] = {
219}; 219};
220 220
221struct das800_private { 221struct das800_private {
222 unsigned int count; /* number of data points left to be taken */
223 unsigned int divisor1; /* counter 1 value for timed conversions */ 222 unsigned int divisor1; /* counter 1 value for timed conversions */
224 unsigned int divisor2; /* counter 2 value for timed conversions */ 223 unsigned int divisor2; /* counter 2 value for timed conversions */
225 unsigned int do_bits; /* digital output bits */ 224 unsigned int do_bits; /* digital output bits */
@@ -286,9 +285,6 @@ static void das800_set_frequency(struct comedi_device *dev)
286 285
287static int das800_cancel(struct comedi_device *dev, struct comedi_subdevice *s) 286static int das800_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
288{ 287{
289 struct das800_private *devpriv = dev->private;
290
291 devpriv->count = 0;
292 das800_disable(dev); 288 das800_disable(dev);
293 return 0; 289 return 0;
294} 290}
@@ -399,7 +395,6 @@ static int das800_ai_do_cmd(struct comedi_device *dev,
399 struct comedi_subdevice *s) 395 struct comedi_subdevice *s)
400{ 396{
401 const struct das800_board *thisboard = dev->board_ptr; 397 const struct das800_board *thisboard = dev->board_ptr;
402 struct das800_private *devpriv = dev->private;
403 struct comedi_async *async = s->async; 398 struct comedi_async *async = s->async;
404 struct comedi_cmd *cmd = &async->cmd; 399 struct comedi_cmd *cmd = &async->cmd;
405 unsigned int gain = CR_RANGE(cmd->chanlist[0]); 400 unsigned int gain = CR_RANGE(cmd->chanlist[0]);
@@ -422,11 +417,6 @@ static int das800_ai_do_cmd(struct comedi_device *dev,
422 gain &= 0xf; 417 gain &= 0xf;
423 outb(gain, dev->iobase + DAS800_GAIN); 418 outb(gain, dev->iobase + DAS800_GAIN);
424 419
425 if (cmd->stop_src == TRIG_COUNT)
426 devpriv->count = cmd->stop_arg * cmd->chanlist_len;
427 else /* TRIG_NONE */
428 devpriv->count = 0;
429
430 /* enable auto channel scan, send interrupts on end of conversion 420 /* enable auto channel scan, send interrupts on end of conversion
431 * and set clock source to internal or external 421 * and set clock source to internal or external
432 */ 422 */
@@ -509,25 +499,28 @@ static irqreturn_t das800_interrupt(int irq, void *d)
509 if (s->maxdata == 0x0fff) 499 if (s->maxdata == 0x0fff)
510 val >>= 4; /* 12-bit sample */ 500 val >>= 4; /* 12-bit sample */
511 501
512 /* if there are more data points to collect */ 502 val &= s->maxdata;
513 if (cmd->stop_src == TRIG_NONE || devpriv->count > 0) { 503 comedi_buf_write_samples(s, &val, 1);
514 /* write data point to buffer */ 504
515 cfc_write_to_buffer(s, val & s->maxdata); 505 if (cmd->stop_src == TRIG_COUNT &&
516 devpriv->count--; 506 async->scans_done >= cmd->stop_arg) {
507 async->events |= COMEDI_CB_EOA;
508 break;
517 } 509 }
518 } 510 }
519 async->events |= COMEDI_CB_BLOCK;
520 511
521 if (fifo_overflow) { 512 if (fifo_overflow) {
522 spin_unlock_irqrestore(&dev->spinlock, irq_flags); 513 spin_unlock_irqrestore(&dev->spinlock, irq_flags);
523 async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; 514 async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA;
524 cfc_handle_events(dev, s); 515 comedi_handle_events(dev, s);
525 return IRQ_HANDLED; 516 return IRQ_HANDLED;
526 } 517 }
527 518
528 if (cmd->stop_src == TRIG_NONE || devpriv->count > 0) { 519 if (!(async->events & COMEDI_CB_CANCEL_MASK)) {
529 /* Re-enable card's interrupt. 520 /*
530 * We already have spinlock, so indirect addressing is safe */ 521 * Re-enable card's interrupt.
522 * We already have spinlock, so indirect addressing is safe
523 */
531 das800_ind_write(dev, CONTROL1_INTE | devpriv->do_bits, 524 das800_ind_write(dev, CONTROL1_INTE | devpriv->do_bits,
532 CONTROL1); 525 CONTROL1);
533 spin_unlock_irqrestore(&dev->spinlock, irq_flags); 526 spin_unlock_irqrestore(&dev->spinlock, irq_flags);
@@ -535,9 +528,8 @@ static irqreturn_t das800_interrupt(int irq, void *d)
535 /* otherwise, stop taking data */ 528 /* otherwise, stop taking data */
536 spin_unlock_irqrestore(&dev->spinlock, irq_flags); 529 spin_unlock_irqrestore(&dev->spinlock, irq_flags);
537 das800_disable(dev); 530 das800_disable(dev);
538 async->events |= COMEDI_CB_EOA;
539 } 531 }
540 cfc_handle_events(dev, s); 532 comedi_handle_events(dev, s);
541 return IRQ_HANDLED; 533 return IRQ_HANDLED;
542} 534}
543 535
@@ -738,7 +730,7 @@ static int das800_attach(struct comedi_device *dev, struct comedi_devconfig *it)
738 /* Digital Output subdevice */ 730 /* Digital Output subdevice */
739 s = &dev->subdevices[2]; 731 s = &dev->subdevices[2];
740 s->type = COMEDI_SUBD_DO; 732 s->type = COMEDI_SUBD_DO;
741 s->subdev_flags = SDF_WRITABLE | SDF_READABLE; 733 s->subdev_flags = SDF_WRITABLE;
742 s->n_chan = 4; 734 s->n_chan = 4;
743 s->maxdata = 1; 735 s->maxdata = 1;
744 s->range_table = &range_digital; 736 s->range_table = &range_digital;
diff --git a/drivers/staging/comedi/drivers/dmm32at.c b/drivers/staging/comedi/drivers/dmm32at.c
index 7215e09305cf..6df298a99cc6 100644
--- a/drivers/staging/comedi/drivers/dmm32at.c
+++ b/drivers/staging/comedi/drivers/dmm32at.c
@@ -1,125 +1,139 @@
1/* 1/*
2 comedi/drivers/dmm32at.c 2 * dmm32at.c
3 Diamond Systems mm32at code for a Comedi driver 3 * Diamond Systems Diamond-MM-32-AT Comedi driver
4 4 *
5 COMEDI - Linux Control and Measurement Device Interface 5 * COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 2000 David A. Schleef <ds@schleef.org> 6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 7 *
8 This program is free software; you can redistribute it and/or modify 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 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 10 * the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 * (at your option) any later version.
12 12 *
13 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 * GNU General Public License for more details.
17*/ 17 */
18
18/* 19/*
19Driver: dmm32at 20 * Driver: dmm32at
20Description: Diamond Systems mm32at driver. 21 * Description: Diamond Systems Diamond-MM-32-AT
21Devices: 22 * Devices: (Diamond Systems) Diamond-MM-32-AT [dmm32at]
22Author: Perry J. Piplani <perry.j.piplani@nasa.gov> 23 * Author: Perry J. Piplani <perry.j.piplani@nasa.gov>
23Updated: Fri Jun 4 09:13:24 CDT 2004 24 * Updated: Fri Jun 4 09:13:24 CDT 2004
24Status: experimental 25 * Status: experimental
25 26 *
26This driver is for the Diamond Systems MM-32-AT board 27 * Configuration Options:
27http://www.diamondsystems.com/products/diamondmm32at It is being used 28 * comedi_config /dev/comedi0 dmm32at baseaddr,irq
28on serveral projects inside NASA, without problems so far. For analog 29 *
29input commands, TRIG_EXT is not yet supported at all.. 30 * This driver is for the Diamond Systems MM-32-AT board
30 31 * http://www.diamondsystems.com/products/diamondmm32at
31Configuration Options: 32 *
32 comedi_config /dev/comedi0 dmm32at baseaddr,irq 33 * It is being used on serveral projects inside NASA, without
33*/ 34 * problems so far. For analog input commands, TRIG_EXT is not
35 * yet supported.
36 */
34 37
35#include <linux/module.h> 38#include <linux/module.h>
36#include <linux/delay.h> 39#include <linux/delay.h>
37#include <linux/interrupt.h> 40#include <linux/interrupt.h>
38#include "../comedidev.h" 41#include "../comedidev.h"
39 42
43#include "8255.h"
40#include "comedi_fc.h" 44#include "comedi_fc.h"
41 45
42/* Board register addresses */ 46/* Board register addresses */
43#define DMM32AT_CONV 0x00 47#define DMM32AT_AI_START_CONV_REG 0x00
44#define DMM32AT_AILSB 0x00 48#define DMM32AT_AI_LSB_REG 0x00
45#define DMM32AT_AUXDOUT 0x01 49#define DMM32AT_AUX_DOUT_REG 0x01
46#define DMM32AT_AIMSB 0x01 50#define DMM32AT_AUX_DOUT2 (1 << 2) /* J3.42 - OUT2 (OUT2EN) */
47#define DMM32AT_AILOW 0x02 51#define DMM32AT_AUX_DOUT1 (1 << 1) /* J3.43 */
48#define DMM32AT_AIHIGH 0x03 52#define DMM32AT_AUX_DOUT0 (1 << 0) /* J3.44 - OUT0 (OUT0EN) */
49 53#define DMM32AT_AI_MSB_REG 0x01
50#define DMM32AT_DACSTAT 0x04 54#define DMM32AT_AI_LO_CHAN_REG 0x02
51#define DMM32AT_DACLSB_REG 0x04 55#define DMM32AT_AI_HI_CHAN_REG 0x03
52#define DMM32AT_DACMSB_REG 0x05 56#define DMM32AT_AUX_DI_REG 0x04
53#define DMM32AT_DACMSB_CHAN(x) ((x) << 6) 57#define DMM32AT_AUX_DI_DACBUSY (1 << 7)
54 58#define DMM32AT_AUX_DI_CALBUSY (1 << 6)
55#define DMM32AT_FIFOCNTRL 0x07 59#define DMM32AT_AUX_DI3 (1 << 3) /* J3.45 - ADCLK (CLKSEL) */
56#define DMM32AT_FIFOSTAT 0x07 60#define DMM32AT_AUX_DI2 (1 << 2) /* J3.46 - GATE12 (GT12EN) */
57 61#define DMM32AT_AUX_DI1 (1 << 1) /* J3.47 - GATE0 (GT0EN) */
58#define DMM32AT_CNTRL 0x08 62#define DMM32AT_AUX_DI0 (1 << 0) /* J3.48 - CLK0 (SRC0) */
59#define DMM32AT_AISTAT 0x08 63#define DMM32AT_AO_LSB_REG 0x04
60 64#define DMM32AT_AO_MSB_REG 0x05
61#define DMM32AT_INTCLOCK 0x09 65#define DMM32AT_AO_MSB_DACH(x) ((x) << 6)
62 66#define DMM32AT_FIFO_DEPTH_REG 0x06
63#define DMM32AT_CNTRDIO 0x0a 67#define DMM32AT_FIFO_CTRL_REG 0x07
64 68#define DMM32AT_FIFO_CTRL_FIFOEN (1 << 3)
65#define DMM32AT_AICONF 0x0b 69#define DMM32AT_FIFO_CTRL_SCANEN (1 << 2)
66#define DMM32AT_AIRBACK 0x0b 70#define DMM32AT_FIFO_CTRL_FIFORST (1 << 1)
71#define DMM32AT_FIFO_STATUS_REG 0x07
72#define DMM32AT_FIFO_STATUS_EF (1 << 7)
73#define DMM32AT_FIFO_STATUS_HF (1 << 6)
74#define DMM32AT_FIFO_STATUS_FF (1 << 5)
75#define DMM32AT_FIFO_STATUS_OVF (1 << 4)
76#define DMM32AT_FIFO_STATUS_FIFOEN (1 << 3)
77#define DMM32AT_FIFO_STATUS_SCANEN (1 << 2)
78#define DMM32AT_FIFO_STATUS_PAGE_MASK (3 << 0)
79#define DMM32AT_CTRL_REG 0x08
80#define DMM32AT_CTRL_RESETA (1 << 5)
81#define DMM32AT_CTRL_RESETD (1 << 4)
82#define DMM32AT_CTRL_INTRST (1 << 3)
83#define DMM32AT_CTRL_PAGE_8254 (0 << 0)
84#define DMM32AT_CTRL_PAGE_8255 (1 << 0)
85#define DMM32AT_CTRL_PAGE_CALIB (3 << 0)
86#define DMM32AT_AI_STATUS_REG 0x08
87#define DMM32AT_AI_STATUS_STS (1 << 7)
88#define DMM32AT_AI_STATUS_SD1 (1 << 6)
89#define DMM32AT_AI_STATUS_SD0 (1 << 5)
90#define DMM32AT_AI_STATUS_ADCH_MASK (0x1f << 0)
91#define DMM32AT_INTCLK_REG 0x09
92#define DMM32AT_INTCLK_ADINT (1 << 7)
93#define DMM32AT_INTCLK_DINT (1 << 6)
94#define DMM32AT_INTCLK_TINT (1 << 5)
95#define DMM32AT_INTCLK_CLKEN (1 << 1) /* 1=see below 0=software */
96#define DMM32AT_INTCLK_CLKSEL (1 << 0) /* 1=OUT2 0=EXTCLK */
97#define DMM32AT_CTRDIO_CFG_REG 0x0a
98#define DMM32AT_CTRDIO_CFG_FREQ12 (1 << 7) /* CLK12 1=100KHz 0=10MHz */
99#define DMM32AT_CTRDIO_CFG_FREQ0 (1 << 6) /* CLK0 1=10KHz 0=10MHz */
100#define DMM32AT_CTRDIO_CFG_OUT2EN (1 << 5) /* J3.42 1=OUT2 is DOUT2 */
101#define DMM32AT_CTRDIO_CFG_OUT0EN (1 << 4) /* J3,44 1=OUT0 is DOUT0 */
102#define DMM32AT_CTRDIO_CFG_GT0EN (1 << 2) /* J3.47 1=DIN1 is GATE0 */
103#define DMM32AT_CTRDIO_CFG_SRC0 (1 << 1) /* CLK0 is 0=FREQ0 1=J3.48 */
104#define DMM32AT_CTRDIO_CFG_GT12EN (1 << 0) /* J3.46 1=DIN2 is GATE12 */
105#define DMM32AT_AI_CFG_REG 0x0b
106#define DMM32AT_AI_CFG_SCINT_20US (0 << 4)
107#define DMM32AT_AI_CFG_SCINT_15US (1 << 4)
108#define DMM32AT_AI_CFG_SCINT_10US (2 << 4)
109#define DMM32AT_AI_CFG_SCINT_5US (3 << 4)
110#define DMM32AT_AI_CFG_RANGE (1 << 3) /* 0=5V 1=10V */
111#define DMM32AT_AI_CFG_ADBU (1 << 2) /* 0=bipolar 1=unipolar */
112#define DMM32AT_AI_CFG_GAIN(x) ((x) << 0)
113#define DMM32AT_AI_READBACK_REG 0x0b
114#define DMM32AT_AI_READBACK_WAIT (1 << 7) /* DMM32AT_AI_STATUS_STS */
115#define DMM32AT_AI_READBACK_RANGE (1 << 3)
116#define DMM32AT_AI_READBACK_ADBU (1 << 2)
117#define DMM32AT_AI_READBACK_GAIN_MASK (3 << 0)
67 118
68#define DMM32AT_CLK1 0x0d 119#define DMM32AT_CLK1 0x0d
69#define DMM32AT_CLK2 0x0e 120#define DMM32AT_CLK2 0x0e
70#define DMM32AT_CLKCT 0x0f 121#define DMM32AT_CLKCT 0x0f
71 122
72#define DMM32AT_DIOA 0x0c 123#define DMM32AT_8255_IOBASE 0x0c /* Page 1 registers */
73#define DMM32AT_DIOB 0x0d
74#define DMM32AT_DIOC 0x0e
75#define DMM32AT_DIOCONF 0x0f
76 124
77/* Board register values. */ 125/* Board register values. */
78 126
79/* DMM32AT_DACSTAT 0x04 */ 127/* DMM32AT_AI_CFG_REG 0x0b */
80#define DMM32AT_DACBUSY 0x80
81
82/* DMM32AT_FIFOCNTRL 0x07 */
83#define DMM32AT_FIFORESET 0x02
84#define DMM32AT_SCANENABLE 0x04
85
86/* DMM32AT_CNTRL 0x08 */
87#define DMM32AT_RESET 0x20
88#define DMM32AT_INTRESET 0x08
89#define DMM32AT_CLKACC 0x00
90#define DMM32AT_DIOACC 0x01
91
92/* DMM32AT_AISTAT 0x08 */
93#define DMM32AT_STATUS 0x80
94
95/* DMM32AT_INTCLOCK 0x09 */
96#define DMM32AT_ADINT 0x80
97#define DMM32AT_CLKSEL 0x03
98
99/* DMM32AT_CNTRDIO 0x0a */
100#define DMM32AT_FREQ12 0x80
101
102/* DMM32AT_AICONF 0x0b */
103#define DMM32AT_RANGE_U10 0x0c 128#define DMM32AT_RANGE_U10 0x0c
104#define DMM32AT_RANGE_U5 0x0d 129#define DMM32AT_RANGE_U5 0x0d
105#define DMM32AT_RANGE_B10 0x08 130#define DMM32AT_RANGE_B10 0x08
106#define DMM32AT_RANGE_B5 0x00 131#define DMM32AT_RANGE_B5 0x00
107#define DMM32AT_SCINT_20 0x00
108#define DMM32AT_SCINT_15 0x10
109#define DMM32AT_SCINT_10 0x20
110#define DMM32AT_SCINT_5 0x30
111 132
112/* DMM32AT_CLKCT 0x0f */ 133/* DMM32AT_CLKCT 0x0f */
113#define DMM32AT_CLKCT1 0x56 /* mode3 counter 1 - write low byte only */ 134#define DMM32AT_CLKCT1 0x56 /* mode3 counter 1 - write low byte only */
114#define DMM32AT_CLKCT2 0xb6 /* mode3 counter 2 - write high and low byte */ 135#define DMM32AT_CLKCT2 0xb6 /* mode3 counter 2 - write high and low byte */
115 136
116/* DMM32AT_DIOCONF 0x0f */
117#define DMM32AT_DIENABLE 0x80
118#define DMM32AT_DIRA 0x10
119#define DMM32AT_DIRB 0x02
120#define DMM32AT_DIRCL 0x01
121#define DMM32AT_DIRCH 0x08
122
123/* board AI ranges in comedi structure */ 137/* board AI ranges in comedi structure */
124static const struct comedi_lrange dmm32at_airanges = { 138static const struct comedi_lrange dmm32at_airanges = {
125 4, { 139 4, {
@@ -150,12 +164,36 @@ static const struct comedi_lrange dmm32at_aoranges = {
150 } 164 }
151}; 165};
152 166
153struct dmm32at_private { 167static void dmm32at_ai_set_chanspec(struct comedi_device *dev,
154 int data; 168 struct comedi_subdevice *s,
155 int ai_inuse; 169 unsigned int chanspec, int nchan)
156 unsigned int ai_scans_left; 170{
157 unsigned char dio_config; 171 unsigned int chan = CR_CHAN(chanspec);
158}; 172 unsigned int range = CR_RANGE(chanspec);
173 unsigned int last_chan = (chan + nchan - 1) % s->n_chan;
174
175 outb(DMM32AT_FIFO_CTRL_FIFORST, dev->iobase + DMM32AT_FIFO_CTRL_REG);
176
177 if (nchan > 1)
178 outb(DMM32AT_FIFO_CTRL_SCANEN,
179 dev->iobase + DMM32AT_FIFO_CTRL_REG);
180
181 outb(chan, dev->iobase + DMM32AT_AI_LO_CHAN_REG);
182 outb(last_chan, dev->iobase + DMM32AT_AI_HI_CHAN_REG);
183 outb(dmm32at_rangebits[range], dev->iobase + DMM32AT_AI_CFG_REG);
184}
185
186static unsigned int dmm32at_ai_get_sample(struct comedi_device *dev,
187 struct comedi_subdevice *s)
188{
189 unsigned int val;
190
191 val = inb(dev->iobase + DMM32AT_AI_LSB_REG);
192 val |= (inb(dev->iobase + DMM32AT_AI_MSB_REG) << 8);
193
194 /* munge two's complement value to offset binary */
195 return comedi_offset_munge(s, val);
196}
159 197
160static int dmm32at_ai_status(struct comedi_device *dev, 198static int dmm32at_ai_status(struct comedi_device *dev,
161 struct comedi_subdevice *s, 199 struct comedi_subdevice *s,
@@ -165,75 +203,39 @@ static int dmm32at_ai_status(struct comedi_device *dev,
165 unsigned char status; 203 unsigned char status;
166 204
167 status = inb(dev->iobase + context); 205 status = inb(dev->iobase + context);
168 if ((status & DMM32AT_STATUS) == 0) 206 if ((status & DMM32AT_AI_STATUS_STS) == 0)
169 return 0; 207 return 0;
170 return -EBUSY; 208 return -EBUSY;
171} 209}
172 210
173static int dmm32at_ai_rinsn(struct comedi_device *dev, 211static int dmm32at_ai_insn_read(struct comedi_device *dev,
174 struct comedi_subdevice *s, 212 struct comedi_subdevice *s,
175 struct comedi_insn *insn, unsigned int *data) 213 struct comedi_insn *insn,
214 unsigned int *data)
176{ 215{
177 int n;
178 unsigned int d;
179 unsigned short msb, lsb;
180 unsigned char chan;
181 int range;
182 int ret; 216 int ret;
217 int i;
183 218
184 /* get the channel and range number */ 219 dmm32at_ai_set_chanspec(dev, s, insn->chanspec, 1);
185
186 chan = CR_CHAN(insn->chanspec) & (s->n_chan - 1);
187 range = CR_RANGE(insn->chanspec);
188
189 /* zero scan and fifo control and reset fifo */
190 outb(DMM32AT_FIFORESET, dev->iobase + DMM32AT_FIFOCNTRL);
191
192 /* write the ai channel range regs */
193 outb(chan, dev->iobase + DMM32AT_AILOW);
194 outb(chan, dev->iobase + DMM32AT_AIHIGH);
195 /* set the range bits */
196 outb(dmm32at_rangebits[range], dev->iobase + DMM32AT_AICONF);
197 220
198 /* wait for circuit to settle */ 221 /* wait for circuit to settle */
199 ret = comedi_timeout(dev, s, insn, dmm32at_ai_status, DMM32AT_AIRBACK); 222 ret = comedi_timeout(dev, s, insn, dmm32at_ai_status,
223 DMM32AT_AI_READBACK_REG);
200 if (ret) 224 if (ret)
201 return ret; 225 return ret;
202 226
203 /* convert n samples */ 227 for (i = 0; i < insn->n; i++) {
204 for (n = 0; n < insn->n; n++) { 228 outb(0xff, dev->iobase + DMM32AT_AI_START_CONV_REG);
205 /* trigger conversion */
206 outb(0xff, dev->iobase + DMM32AT_CONV);
207 229
208 /* wait for conversion to end */
209 ret = comedi_timeout(dev, s, insn, dmm32at_ai_status, 230 ret = comedi_timeout(dev, s, insn, dmm32at_ai_status,
210 DMM32AT_AISTAT); 231 DMM32AT_AI_STATUS_REG);
211 if (ret) 232 if (ret)
212 return ret; 233 return ret;
213 234
214 /* read data */ 235 data[i] = dmm32at_ai_get_sample(dev, s);
215 lsb = inb(dev->iobase + DMM32AT_AILSB);
216 msb = inb(dev->iobase + DMM32AT_AIMSB);
217
218 /* invert sign bit to make range unsigned, this is an
219 idiosyncrasy of the diamond board, it return
220 conversions as a signed value, i.e. -32768 to
221 32767, flipping the bit and interpreting it as
222 signed gives you a range of 0 to 65535 which is
223 used by comedi */
224 d = ((msb ^ 0x0080) << 8) + lsb;
225
226 data[n] = d;
227 } 236 }
228 237
229 /* return the number of samples read/written */ 238 return insn->n;
230 return n;
231}
232
233static int dmm32at_ns_to_timer(unsigned int *ns, unsigned int flags)
234{
235 /* trivial timer */
236 return *ns;
237} 239}
238 240
239static int dmm32at_ai_check_chanlist(struct comedi_device *dev, 241static int dmm32at_ai_check_chanlist(struct comedi_device *dev,
@@ -273,10 +275,8 @@ static int dmm32at_ai_cmdtest(struct comedi_device *dev,
273 /* Step 1 : check if triggers are trivially valid */ 275 /* Step 1 : check if triggers are trivially valid */
274 276
275 err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW); 277 err |= cfc_check_trigger_src(&cmd->start_src, TRIG_NOW);
276 err |= cfc_check_trigger_src(&cmd->scan_begin_src, 278 err |= cfc_check_trigger_src(&cmd->scan_begin_src, TRIG_TIMER);
277 TRIG_TIMER /*| TRIG_EXT */); 279 err |= cfc_check_trigger_src(&cmd->convert_src, TRIG_TIMER);
278 err |= cfc_check_trigger_src(&cmd->convert_src,
279 TRIG_TIMER /*| TRIG_EXT */);
280 err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT); 280 err |= cfc_check_trigger_src(&cmd->scan_end_src, TRIG_COUNT);
281 err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE); 281 err |= cfc_check_trigger_src(&cmd->stop_src, TRIG_COUNT | TRIG_NONE);
282 282
@@ -285,8 +285,6 @@ static int dmm32at_ai_cmdtest(struct comedi_device *dev,
285 285
286 /* Step 2a : make sure trigger sources are unique */ 286 /* Step 2a : make sure trigger sources are unique */
287 287
288 err |= cfc_check_trigger_is_unique(cmd->scan_begin_src);
289 err |= cfc_check_trigger_is_unique(cmd->convert_src);
290 err |= cfc_check_trigger_is_unique(cmd->stop_src); 288 err |= cfc_check_trigger_is_unique(cmd->stop_src);
291 289
292 /* Step 2b : and mutually compatible */ 290 /* Step 2b : and mutually compatible */
@@ -298,67 +296,32 @@ static int dmm32at_ai_cmdtest(struct comedi_device *dev,
298 296
299 err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0); 297 err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
300 298
301#define MAX_SCAN_SPEED 1000000 /* in nanoseconds */ 299 err |= cfc_check_trigger_arg_min(&cmd->scan_begin_arg, 1000000);
302#define MIN_SCAN_SPEED 1000000000 /* in nanoseconds */ 300 err |= cfc_check_trigger_arg_max(&cmd->scan_begin_arg, 1000000000);
303
304 if (cmd->scan_begin_src == TRIG_TIMER) {
305 err |= cfc_check_trigger_arg_min(&cmd->scan_begin_arg,
306 MAX_SCAN_SPEED);
307 err |= cfc_check_trigger_arg_max(&cmd->scan_begin_arg,
308 MIN_SCAN_SPEED);
309 } else {
310 /* external trigger */
311 /* should be level/edge, hi/lo specification here */
312 /* should specify multiple external triggers */
313 err |= cfc_check_trigger_arg_max(&cmd->scan_begin_arg, 9);
314 }
315 301
316 if (cmd->convert_src == TRIG_TIMER) { 302 if (cmd->convert_arg >= 17500)
317 if (cmd->convert_arg >= 17500) 303 cmd->convert_arg = 20000;
318 cmd->convert_arg = 20000; 304 else if (cmd->convert_arg >= 12500)
319 else if (cmd->convert_arg >= 12500) 305 cmd->convert_arg = 15000;
320 cmd->convert_arg = 15000; 306 else if (cmd->convert_arg >= 7500)
321 else if (cmd->convert_arg >= 7500) 307 cmd->convert_arg = 10000;
322 cmd->convert_arg = 10000; 308 else
323 else 309 cmd->convert_arg = 5000;
324 cmd->convert_arg = 5000;
325 } else {
326 /* external trigger */
327 /* see above */
328 err |= cfc_check_trigger_arg_max(&cmd->convert_arg, 9);
329 }
330 310
331 err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len); 311 err |= cfc_check_trigger_arg_is(&cmd->scan_end_arg, cmd->chanlist_len);
332 312
333 if (cmd->stop_src == TRIG_COUNT) { 313 if (cmd->stop_src == TRIG_COUNT)
334 err |= cfc_check_trigger_arg_max(&cmd->stop_arg, 0xfffffff0);
335 err |= cfc_check_trigger_arg_min(&cmd->stop_arg, 1); 314 err |= cfc_check_trigger_arg_min(&cmd->stop_arg, 1);
336 } else { 315 else /* TRIG_NONE */
337 /* TRIG_NONE */
338 err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0); 316 err |= cfc_check_trigger_arg_is(&cmd->stop_arg, 0);
339 }
340 317
341 if (err) 318 if (err)
342 return 3; 319 return 3;
343 320
344 /* step 4: fix up any arguments */ 321 /* Step 4: fix up any arguments */
345 322
346 if (cmd->scan_begin_src == TRIG_TIMER) { 323 arg = cmd->convert_arg * cmd->scan_end_arg;
347 arg = cmd->scan_begin_arg; 324 err |= cfc_check_trigger_arg_min(&cmd->scan_begin_arg, arg);
348 dmm32at_ns_to_timer(&arg, cmd->flags);
349 err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, arg);
350 }
351 if (cmd->convert_src == TRIG_TIMER) {
352 arg = cmd->convert_arg;
353 dmm32at_ns_to_timer(&arg, cmd->flags);
354 err |= cfc_check_trigger_arg_is(&cmd->convert_arg, arg);
355
356 if (cmd->scan_begin_src == TRIG_TIMER) {
357 arg = cmd->convert_arg * cmd->scan_end_arg;
358 err |= cfc_check_trigger_arg_min(&cmd->scan_begin_arg,
359 arg);
360 }
361 }
362 325
363 if (err) 326 if (err)
364 return 4; 327 return 4;
@@ -384,11 +347,11 @@ static void dmm32at_setaitimer(struct comedi_device *dev, unsigned int nansec)
384 hi2 = (both2 & 0xff00) >> 8; 347 hi2 = (both2 & 0xff00) >> 8;
385 lo2 = both2 & 0x00ff; 348 lo2 = both2 & 0x00ff;
386 349
387 /* set the counter frequency to 10mhz */ 350 /* set counter clocks to 10MHz, disable all aux dio */
388 outb(0, dev->iobase + DMM32AT_CNTRDIO); 351 outb(0, dev->iobase + DMM32AT_CTRDIO_CFG_REG);
389 352
390 /* get access to the clock regs */ 353 /* get access to the clock regs */
391 outb(DMM32AT_CLKACC, dev->iobase + DMM32AT_CNTRL); 354 outb(DMM32AT_CTRL_PAGE_8254, dev->iobase + DMM32AT_CTRL_REG);
392 355
393 /* write the counter 1 control word and low byte to counter */ 356 /* write the counter 1 control word and low byte to counter */
394 outb(DMM32AT_CLKCT1, dev->iobase + DMM32AT_CLKCT); 357 outb(DMM32AT_CLKCT1, dev->iobase + DMM32AT_CLKCT);
@@ -400,65 +363,37 @@ static void dmm32at_setaitimer(struct comedi_device *dev, unsigned int nansec)
400 outb(hi2, dev->iobase + DMM32AT_CLK2); 363 outb(hi2, dev->iobase + DMM32AT_CLK2);
401 364
402 /* enable the ai conversion interrupt and the clock to start scans */ 365 /* enable the ai conversion interrupt and the clock to start scans */
403 outb(DMM32AT_ADINT | DMM32AT_CLKSEL, dev->iobase + DMM32AT_INTCLOCK); 366 outb(DMM32AT_INTCLK_ADINT |
367 DMM32AT_INTCLK_CLKEN | DMM32AT_INTCLK_CLKSEL,
368 dev->iobase + DMM32AT_INTCLK_REG);
404} 369}
405 370
406static int dmm32at_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) 371static int dmm32at_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
407{ 372{
408 struct dmm32at_private *devpriv = dev->private;
409 struct comedi_cmd *cmd = &s->async->cmd; 373 struct comedi_cmd *cmd = &s->async->cmd;
410 int range;
411 unsigned char chanlo, chanhi;
412 int ret; 374 int ret;
413 375
414 if (!cmd->chanlist) 376 dmm32at_ai_set_chanspec(dev, s, cmd->chanlist[0], cmd->chanlist_len);
415 return -EINVAL;
416
417 /* get the channel list and range */
418 chanlo = CR_CHAN(cmd->chanlist[0]) & (s->n_chan - 1);
419 chanhi = chanlo + cmd->chanlist_len - 1;
420 if (chanhi >= s->n_chan)
421 return -EINVAL;
422 range = CR_RANGE(cmd->chanlist[0]);
423
424 /* reset fifo */
425 outb(DMM32AT_FIFORESET, dev->iobase + DMM32AT_FIFOCNTRL);
426
427 /* set scan enable */
428 outb(DMM32AT_SCANENABLE, dev->iobase + DMM32AT_FIFOCNTRL);
429
430 /* write the ai channel range regs */
431 outb(chanlo, dev->iobase + DMM32AT_AILOW);
432 outb(chanhi, dev->iobase + DMM32AT_AIHIGH);
433
434 /* set the range bits */
435 outb(dmm32at_rangebits[range], dev->iobase + DMM32AT_AICONF);
436 377
437 /* reset the interrupt just in case */ 378 /* reset the interrupt just in case */
438 outb(DMM32AT_INTRESET, dev->iobase + DMM32AT_CNTRL); 379 outb(DMM32AT_CTRL_INTRST, dev->iobase + DMM32AT_CTRL_REG);
439
440 if (cmd->stop_src == TRIG_COUNT)
441 devpriv->ai_scans_left = cmd->stop_arg;
442 else { /* TRIG_NONE */
443 devpriv->ai_scans_left = 0xffffffff; /* indicates TRIG_NONE to
444 * isr */
445 }
446 380
447 /* 381 /*
448 * wait for circuit to settle 382 * wait for circuit to settle
449 * we don't have the 'insn' here but it's not needed 383 * we don't have the 'insn' here but it's not needed
450 */ 384 */
451 ret = comedi_timeout(dev, s, NULL, dmm32at_ai_status, DMM32AT_AIRBACK); 385 ret = comedi_timeout(dev, s, NULL, dmm32at_ai_status,
386 DMM32AT_AI_READBACK_REG);
452 if (ret) 387 if (ret)
453 return ret; 388 return ret;
454 389
455 if (devpriv->ai_scans_left > 1) { 390 if (cmd->stop_src == TRIG_NONE || cmd->stop_arg > 1) {
456 /* start the clock and enable the interrupts */ 391 /* start the clock and enable the interrupts */
457 dmm32at_setaitimer(dev, cmd->scan_begin_arg); 392 dmm32at_setaitimer(dev, cmd->scan_begin_arg);
458 } else { 393 } else {
459 /* start the interrups and initiate a single scan */ 394 /* start the interrups and initiate a single scan */
460 outb(DMM32AT_ADINT, dev->iobase + DMM32AT_INTCLOCK); 395 outb(DMM32AT_INTCLK_ADINT, dev->iobase + DMM32AT_INTCLK_REG);
461 outb(0xff, dev->iobase + DMM32AT_CONV); 396 outb(0xff, dev->iobase + DMM32AT_AI_START_CONV_REG);
462 } 397 }
463 398
464 return 0; 399 return 0;
@@ -468,19 +403,16 @@ static int dmm32at_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
468static int dmm32at_ai_cancel(struct comedi_device *dev, 403static int dmm32at_ai_cancel(struct comedi_device *dev,
469 struct comedi_subdevice *s) 404 struct comedi_subdevice *s)
470{ 405{
471 struct dmm32at_private *devpriv = dev->private; 406 /* disable further interrupts and clocks */
472 407 outb(0x0, dev->iobase + DMM32AT_INTCLK_REG);
473 devpriv->ai_scans_left = 1;
474 return 0; 408 return 0;
475} 409}
476 410
477static irqreturn_t dmm32at_isr(int irq, void *d) 411static irqreturn_t dmm32at_isr(int irq, void *d)
478{ 412{
479 struct comedi_device *dev = d; 413 struct comedi_device *dev = d;
480 struct dmm32at_private *devpriv = dev->private;
481 unsigned char intstat; 414 unsigned char intstat;
482 unsigned int samp; 415 unsigned int val;
483 unsigned short msb, lsb;
484 int i; 416 int i;
485 417
486 if (!dev->attached) { 418 if (!dev->attached) {
@@ -488,38 +420,26 @@ static irqreturn_t dmm32at_isr(int irq, void *d)
488 return IRQ_HANDLED; 420 return IRQ_HANDLED;
489 } 421 }
490 422
491 intstat = inb(dev->iobase + DMM32AT_INTCLOCK); 423 intstat = inb(dev->iobase + DMM32AT_INTCLK_REG);
492 424
493 if (intstat & DMM32AT_ADINT) { 425 if (intstat & DMM32AT_INTCLK_ADINT) {
494 struct comedi_subdevice *s = dev->read_subdev; 426 struct comedi_subdevice *s = dev->read_subdev;
495 struct comedi_cmd *cmd = &s->async->cmd; 427 struct comedi_cmd *cmd = &s->async->cmd;
496 428
497 for (i = 0; i < cmd->chanlist_len; i++) { 429 for (i = 0; i < cmd->chanlist_len; i++) {
498 /* read data */ 430 val = dmm32at_ai_get_sample(dev, s);
499 lsb = inb(dev->iobase + DMM32AT_AILSB); 431 comedi_buf_write_samples(s, &val, 1);
500 msb = inb(dev->iobase + DMM32AT_AIMSB);
501
502 /* invert sign bit to make range unsigned */
503 samp = ((msb ^ 0x0080) << 8) + lsb;
504 comedi_buf_put(s, samp);
505 } 432 }
506 433
507 if (devpriv->ai_scans_left != 0xffffffff) { /* TRIG_COUNT */ 434 if (cmd->stop_src == TRIG_COUNT &&
508 devpriv->ai_scans_left--; 435 s->async->scans_done >= cmd->stop_arg)
509 if (devpriv->ai_scans_left == 0) { 436 s->async->events |= COMEDI_CB_EOA;
510 /* disable further interrupts and clocks */
511 outb(0x0, dev->iobase + DMM32AT_INTCLOCK);
512 /* set the buffer to be flushed with an EOF */
513 s->async->events |= COMEDI_CB_EOA;
514 }
515 437
516 } 438 comedi_handle_events(dev, s);
517 /* flush the buffer */
518 comedi_event(dev, s);
519 } 439 }
520 440
521 /* reset the interrupt */ 441 /* reset the interrupt */
522 outb(DMM32AT_INTRESET, dev->iobase + DMM32AT_CNTRL); 442 outb(DMM32AT_CTRL_INTRST, dev->iobase + DMM32AT_CTRL_REG);
523 return IRQ_HANDLED; 443 return IRQ_HANDLED;
524} 444}
525 445
@@ -530,8 +450,8 @@ static int dmm32at_ao_eoc(struct comedi_device *dev,
530{ 450{
531 unsigned char status; 451 unsigned char status;
532 452
533 status = inb(dev->iobase + DMM32AT_DACSTAT); 453 status = inb(dev->iobase + DMM32AT_AUX_DI_REG);
534 if ((status & DMM32AT_DACBUSY) == 0) 454 if ((status & DMM32AT_AUX_DI_DACBUSY) == 0)
535 return 0; 455 return 0;
536 return -EBUSY; 456 return -EBUSY;
537} 457}
@@ -549,9 +469,9 @@ static int dmm32at_ao_insn_write(struct comedi_device *dev,
549 int ret; 469 int ret;
550 470
551 /* write LSB then MSB + chan to load DAC */ 471 /* write LSB then MSB + chan to load DAC */
552 outb(val & 0xff, dev->iobase + DMM32AT_DACLSB_REG); 472 outb(val & 0xff, dev->iobase + DMM32AT_AO_LSB_REG);
553 outb((val >> 8) | DMM32AT_DACMSB_CHAN(chan), 473 outb((val >> 8) | DMM32AT_AO_MSB_DACH(chan),
554 dev->iobase + DMM32AT_DACMSB_REG); 474 dev->iobase + DMM32AT_AO_MSB_REG);
555 475
556 /* wait for circuit to settle */ 476 /* wait for circuit to settle */
557 ret = comedi_timeout(dev, s, insn, dmm32at_ao_eoc, 0); 477 ret = comedi_timeout(dev, s, insn, dmm32at_ao_eoc, 0);
@@ -559,7 +479,7 @@ static int dmm32at_ao_insn_write(struct comedi_device *dev,
559 return ret; 479 return ret;
560 480
561 /* dummy read to update DAC */ 481 /* dummy read to update DAC */
562 inb(dev->iobase + DMM32AT_DACMSB_REG); 482 inb(dev->iobase + DMM32AT_AO_MSB_REG);
563 483
564 s->readback[chan] = val; 484 s->readback[chan] = val;
565 } 485 }
@@ -567,136 +487,82 @@ static int dmm32at_ao_insn_write(struct comedi_device *dev,
567 return insn->n; 487 return insn->n;
568} 488}
569 489
570static int dmm32at_dio_insn_bits(struct comedi_device *dev, 490static int dmm32at_8255_io(struct comedi_device *dev,
571 struct comedi_subdevice *s, 491 int dir, int port, int data, unsigned long regbase)
572 struct comedi_insn *insn,
573 unsigned int *data)
574{
575 struct dmm32at_private *devpriv = dev->private;
576 unsigned int mask;
577 unsigned int val;
578
579 mask = comedi_dio_update_state(s, data);
580 if (mask) {
581 /* get access to the DIO regs */
582 outb(DMM32AT_DIOACC, dev->iobase + DMM32AT_CNTRL);
583
584 /* if either part of dio is set for output */
585 if (((devpriv->dio_config & DMM32AT_DIRCL) == 0) ||
586 ((devpriv->dio_config & DMM32AT_DIRCH) == 0)) {
587 val = (s->state & 0x00ff0000) >> 16;
588 outb(val, dev->iobase + DMM32AT_DIOC);
589 }
590 if ((devpriv->dio_config & DMM32AT_DIRB) == 0) {
591 val = (s->state & 0x0000ff00) >> 8;
592 outb(val, dev->iobase + DMM32AT_DIOB);
593 }
594 if ((devpriv->dio_config & DMM32AT_DIRA) == 0) {
595 val = (s->state & 0x000000ff);
596 outb(val, dev->iobase + DMM32AT_DIOA);
597 }
598 }
599
600 val = inb(dev->iobase + DMM32AT_DIOA);
601 val |= inb(dev->iobase + DMM32AT_DIOB) << 8;
602 val |= inb(dev->iobase + DMM32AT_DIOC) << 16;
603 s->state = val;
604
605 data[1] = val;
606
607 return insn->n;
608}
609
610static int dmm32at_dio_insn_config(struct comedi_device *dev,
611 struct comedi_subdevice *s,
612 struct comedi_insn *insn,
613 unsigned int *data)
614{ 492{
615 struct dmm32at_private *devpriv = dev->private;
616 unsigned int chan = CR_CHAN(insn->chanspec);
617 unsigned int mask;
618 unsigned char chanbit;
619 int ret;
620
621 if (chan < 8) {
622 mask = 0x0000ff;
623 chanbit = DMM32AT_DIRA;
624 } else if (chan < 16) {
625 mask = 0x00ff00;
626 chanbit = DMM32AT_DIRB;
627 } else if (chan < 20) {
628 mask = 0x0f0000;
629 chanbit = DMM32AT_DIRCL;
630 } else {
631 mask = 0xf00000;
632 chanbit = DMM32AT_DIRCH;
633 }
634
635 ret = comedi_dio_insn_config(dev, s, insn, data, mask);
636 if (ret)
637 return ret;
638
639 if (data[0] == INSN_CONFIG_DIO_OUTPUT)
640 devpriv->dio_config &= ~chanbit;
641 else
642 devpriv->dio_config |= chanbit;
643 /* get access to the DIO regs */ 493 /* get access to the DIO regs */
644 outb(DMM32AT_DIOACC, dev->iobase + DMM32AT_CNTRL); 494 outb(DMM32AT_CTRL_PAGE_8255, dev->iobase + DMM32AT_CTRL_REG);
645 /* set the DIO's to the new configuration setting */
646 outb(devpriv->dio_config, dev->iobase + DMM32AT_DIOCONF);
647 495
648 return insn->n; 496 if (dir) {
497 outb(data, dev->iobase + regbase + port);
498 return 0;
499 }
500 return inb(dev->iobase + regbase + port);
649} 501}
650 502
651static int dmm32at_attach(struct comedi_device *dev, 503/* Make sure the board is there and put it to a known state */
652 struct comedi_devconfig *it) 504static int dmm32at_reset(struct comedi_device *dev)
653{ 505{
654 struct dmm32at_private *devpriv;
655 int ret;
656 struct comedi_subdevice *s;
657 unsigned char aihi, ailo, fifostat, aistat, intstat, airback; 506 unsigned char aihi, ailo, fifostat, aistat, intstat, airback;
658 507
659 ret = comedi_request_region(dev, it->options[0], 0x10);
660 if (ret)
661 return ret;
662
663 /* the following just makes sure the board is there and gets
664 it to a known state */
665
666 /* reset the board */ 508 /* reset the board */
667 outb(DMM32AT_RESET, dev->iobase + DMM32AT_CNTRL); 509 outb(DMM32AT_CTRL_RESETA, dev->iobase + DMM32AT_CTRL_REG);
668 510
669 /* allow a millisecond to reset */ 511 /* allow a millisecond to reset */
670 udelay(1000); 512 udelay(1000);
671 513
672 /* zero scan and fifo control */ 514 /* zero scan and fifo control */
673 outb(0x0, dev->iobase + DMM32AT_FIFOCNTRL); 515 outb(0x0, dev->iobase + DMM32AT_FIFO_CTRL_REG);
674 516
675 /* zero interrupt and clock control */ 517 /* zero interrupt and clock control */
676 outb(0x0, dev->iobase + DMM32AT_INTCLOCK); 518 outb(0x0, dev->iobase + DMM32AT_INTCLK_REG);
677 519
678 /* write a test channel range, the high 3 bits should drop */ 520 /* write a test channel range, the high 3 bits should drop */
679 outb(0x80, dev->iobase + DMM32AT_AILOW); 521 outb(0x80, dev->iobase + DMM32AT_AI_LO_CHAN_REG);
680 outb(0xff, dev->iobase + DMM32AT_AIHIGH); 522 outb(0xff, dev->iobase + DMM32AT_AI_HI_CHAN_REG);
681 523
682 /* set the range at 10v unipolar */ 524 /* set the range at 10v unipolar */
683 outb(DMM32AT_RANGE_U10, dev->iobase + DMM32AT_AICONF); 525 outb(DMM32AT_RANGE_U10, dev->iobase + DMM32AT_AI_CFG_REG);
684 526
685 /* should take 10 us to settle, here's a hundred */ 527 /* should take 10 us to settle, here's a hundred */
686 udelay(100); 528 udelay(100);
687 529
688 /* read back the values */ 530 /* read back the values */
689 ailo = inb(dev->iobase + DMM32AT_AILOW); 531 ailo = inb(dev->iobase + DMM32AT_AI_LO_CHAN_REG);
690 aihi = inb(dev->iobase + DMM32AT_AIHIGH); 532 aihi = inb(dev->iobase + DMM32AT_AI_HI_CHAN_REG);
691 fifostat = inb(dev->iobase + DMM32AT_FIFOSTAT); 533 fifostat = inb(dev->iobase + DMM32AT_FIFO_STATUS_REG);
692 aistat = inb(dev->iobase + DMM32AT_AISTAT); 534 aistat = inb(dev->iobase + DMM32AT_AI_STATUS_REG);
693 intstat = inb(dev->iobase + DMM32AT_INTCLOCK); 535 intstat = inb(dev->iobase + DMM32AT_INTCLK_REG);
694 airback = inb(dev->iobase + DMM32AT_AIRBACK); 536 airback = inb(dev->iobase + DMM32AT_AI_READBACK_REG);
695 537
696 if ((ailo != 0x00) || (aihi != 0x1f) || (fifostat != 0x80) || 538 /*
697 (aistat != 0x60 || (intstat != 0x00) || airback != 0x0c)) { 539 * NOTE: The (DMM32AT_AI_STATUS_SD1 | DMM32AT_AI_STATUS_SD0)
698 dev_err(dev->class_dev, "board detection failed\n"); 540 * test makes this driver only work if the board is configured
541 * with all A/D channels set for single-ended operation.
542 */
543 if (ailo != 0x00 || aihi != 0x1f ||
544 fifostat != DMM32AT_FIFO_STATUS_EF ||
545 aistat != (DMM32AT_AI_STATUS_SD1 | DMM32AT_AI_STATUS_SD0) ||
546 intstat != 0x00 || airback != 0x0c)
699 return -EIO; 547 return -EIO;
548
549 return 0;
550}
551
552static int dmm32at_attach(struct comedi_device *dev,
553 struct comedi_devconfig *it)
554{
555 struct comedi_subdevice *s;
556 int ret;
557
558 ret = comedi_request_region(dev, it->options[0], 0x10);
559 if (ret)
560 return ret;
561
562 ret = dmm32at_reset(dev);
563 if (ret) {
564 dev_err(dev->class_dev, "board detection failed\n");
565 return ret;
700 } 566 }
701 567
702 if (it->options[1]) { 568 if (it->options[1]) {
@@ -706,65 +572,45 @@ static int dmm32at_attach(struct comedi_device *dev,
706 dev->irq = it->options[1]; 572 dev->irq = it->options[1];
707 } 573 }
708 574
709 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
710 if (!devpriv)
711 return -ENOMEM;
712
713 ret = comedi_alloc_subdevices(dev, 3); 575 ret = comedi_alloc_subdevices(dev, 3);
714 if (ret) 576 if (ret)
715 return ret; 577 return ret;
716 578
579 /* Analog Input subdevice */
717 s = &dev->subdevices[0]; 580 s = &dev->subdevices[0];
718 /* analog input subdevice */ 581 s->type = COMEDI_SUBD_AI;
719 s->type = COMEDI_SUBD_AI; 582 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF;
720 /* we support single-ended (ground) and differential */ 583 s->n_chan = 32;
721 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF; 584 s->maxdata = 0xffff;
722 s->n_chan = 32; 585 s->range_table = &dmm32at_airanges;
723 s->maxdata = 0xffff; 586 s->insn_read = dmm32at_ai_insn_read;
724 s->range_table = &dmm32at_airanges;
725 s->insn_read = dmm32at_ai_rinsn;
726 if (dev->irq) { 587 if (dev->irq) {
727 dev->read_subdev = s; 588 dev->read_subdev = s;
728 s->subdev_flags |= SDF_CMD_READ; 589 s->subdev_flags |= SDF_CMD_READ;
729 s->len_chanlist = 32; 590 s->len_chanlist = s->n_chan;
730 s->do_cmd = dmm32at_ai_cmd; 591 s->do_cmd = dmm32at_ai_cmd;
731 s->do_cmdtest = dmm32at_ai_cmdtest; 592 s->do_cmdtest = dmm32at_ai_cmdtest;
732 s->cancel = dmm32at_ai_cancel; 593 s->cancel = dmm32at_ai_cancel;
733 } 594 }
734 595
596 /* Analog Output subdevice */
735 s = &dev->subdevices[1]; 597 s = &dev->subdevices[1];
736 /* analog output subdevice */ 598 s->type = COMEDI_SUBD_AO;
737 s->type = COMEDI_SUBD_AO; 599 s->subdev_flags = SDF_WRITABLE;
738 s->subdev_flags = SDF_WRITABLE; 600 s->n_chan = 4;
739 s->n_chan = 4; 601 s->maxdata = 0x0fff;
740 s->maxdata = 0x0fff; 602 s->range_table = &dmm32at_aoranges;
741 s->range_table = &dmm32at_aoranges; 603 s->insn_write = dmm32at_ao_insn_write;
742 s->insn_write = dmm32at_ao_insn_write;
743 s->insn_read = comedi_readback_insn_read;
744 604
745 ret = comedi_alloc_subdev_readback(s); 605 ret = comedi_alloc_subdev_readback(s);
746 if (ret) 606 if (ret)
747 return ret; 607 return ret;
748 608
609 /* Digital I/O subdevice */
749 s = &dev->subdevices[2]; 610 s = &dev->subdevices[2];
750 /* digital i/o subdevice */ 611 ret = subdev_8255_init(dev, s, dmm32at_8255_io, DMM32AT_8255_IOBASE);
751 612 if (ret)
752 /* get access to the DIO regs */ 613 return ret;
753 outb(DMM32AT_DIOACC, dev->iobase + DMM32AT_CNTRL);
754 /* set the DIO's to the defualt input setting */
755 devpriv->dio_config = DMM32AT_DIRA | DMM32AT_DIRB |
756 DMM32AT_DIRCL | DMM32AT_DIRCH | DMM32AT_DIENABLE;
757 outb(devpriv->dio_config, dev->iobase + DMM32AT_DIOCONF);
758
759 /* set up the subdevice */
760 s->type = COMEDI_SUBD_DIO;
761 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
762 s->n_chan = 24;
763 s->maxdata = 1;
764 s->state = 0;
765 s->range_table = &range_digital;
766 s->insn_bits = dmm32at_dio_insn_bits;
767 s->insn_config = dmm32at_dio_insn_config;
768 614
769 return 0; 615 return 0;
770} 616}
@@ -778,5 +624,5 @@ static struct comedi_driver dmm32at_driver = {
778module_comedi_driver(dmm32at_driver); 624module_comedi_driver(dmm32at_driver);
779 625
780MODULE_AUTHOR("Comedi http://www.comedi.org"); 626MODULE_AUTHOR("Comedi http://www.comedi.org");
781MODULE_DESCRIPTION("Comedi low-level driver"); 627MODULE_DESCRIPTION("Comedi: Diamond Systems Diamond-MM-32-AT");
782MODULE_LICENSE("GPL"); 628MODULE_LICENSE("GPL");
diff --git a/drivers/staging/comedi/drivers/dt2801.c b/drivers/staging/comedi/drivers/dt2801.c
index e97386343a0e..b96e60ffad73 100644
--- a/drivers/staging/comedi/drivers/dt2801.c
+++ b/drivers/staging/comedi/drivers/dt2801.c
@@ -597,7 +597,6 @@ havetype:
597 devpriv->dac_range_types[0] = dac_range_lkup(it->options[4]); 597 devpriv->dac_range_types[0] = dac_range_lkup(it->options[4]);
598 devpriv->dac_range_types[1] = dac_range_lkup(it->options[5]); 598 devpriv->dac_range_types[1] = dac_range_lkup(it->options[5]);
599 s->insn_write = dt2801_ao_insn_write; 599 s->insn_write = dt2801_ao_insn_write;
600 s->insn_read = comedi_readback_insn_read;
601 600
602 ret = comedi_alloc_subdev_readback(s); 601 ret = comedi_alloc_subdev_readback(s);
603 if (ret) 602 if (ret)
diff --git a/drivers/staging/comedi/drivers/dt2811.c b/drivers/staging/comedi/drivers/dt2811.c
index 1736e397ad2c..d660f277487e 100644
--- a/drivers/staging/comedi/drivers/dt2811.c
+++ b/drivers/staging/comedi/drivers/dt2811.c
@@ -418,7 +418,6 @@ static int dt2811_attach(struct comedi_device *dev, struct comedi_devconfig *it)
418 devpriv->range_type_list[0] = dac_range_types[devpriv->dac_range[0]]; 418 devpriv->range_type_list[0] = dac_range_types[devpriv->dac_range[0]];
419 devpriv->range_type_list[1] = dac_range_types[devpriv->dac_range[1]]; 419 devpriv->range_type_list[1] = dac_range_types[devpriv->dac_range[1]];
420 s->insn_write = dt2811_ao_insn_write; 420 s->insn_write = dt2811_ao_insn_write;
421 s->insn_read = comedi_readback_insn_read;
422 421
423 ret = comedi_alloc_subdev_readback(s); 422 ret = comedi_alloc_subdev_readback(s);
424 if (ret) 423 if (ret)
diff --git a/drivers/staging/comedi/drivers/dt2814.c b/drivers/staging/comedi/drivers/dt2814.c
index 9216c35c414e..9805be13005a 100644
--- a/drivers/staging/comedi/drivers/dt2814.c
+++ b/drivers/staging/comedi/drivers/dt2814.c
@@ -230,7 +230,7 @@ static irqreturn_t dt2814_interrupt(int irq, void *d)
230 230
231 s->async->events |= COMEDI_CB_EOA; 231 s->async->events |= COMEDI_CB_EOA;
232 } 232 }
233 comedi_event(dev, s); 233 comedi_handle_events(dev, s);
234 return IRQ_HANDLED; 234 return IRQ_HANDLED;
235} 235}
236 236
diff --git a/drivers/staging/comedi/drivers/dt282x.c b/drivers/staging/comedi/drivers/dt282x.c
index cc974a5e5cf6..2be98bb9a809 100644
--- a/drivers/staging/comedi/drivers/dt282x.c
+++ b/drivers/staging/comedi/drivers/dt282x.c
@@ -449,13 +449,29 @@ static void dt282x_munge(struct comedi_device *dev,
449 } 449 }
450} 450}
451 451
452static unsigned int dt282x_ao_setup_dma(struct comedi_device *dev,
453 struct comedi_subdevice *s,
454 int cur_dma)
455{
456 struct dt282x_private *devpriv = dev->private;
457 void *ptr = devpriv->dma[cur_dma].buf;
458 unsigned int nsamples = comedi_bytes_to_samples(s, devpriv->dma_maxsize);
459 unsigned int nbytes;
460
461 nbytes = comedi_buf_read_samples(s, ptr, nsamples);
462 if (nbytes)
463 dt282x_prep_ao_dma(dev, cur_dma, nbytes);
464 else
465 dev_err(dev->class_dev, "AO underrun\n");
466
467 return nbytes;
468}
469
452static void dt282x_ao_dma_interrupt(struct comedi_device *dev, 470static void dt282x_ao_dma_interrupt(struct comedi_device *dev,
453 struct comedi_subdevice *s) 471 struct comedi_subdevice *s)
454{ 472{
455 struct dt282x_private *devpriv = dev->private; 473 struct dt282x_private *devpriv = dev->private;
456 int cur_dma = devpriv->current_dma_index; 474 int cur_dma = devpriv->current_dma_index;
457 void *ptr = devpriv->dma[cur_dma].buf;
458 int size;
459 475
460 outw(devpriv->supcsr | DT2821_SUPCSR_CLRDMADNE, 476 outw(devpriv->supcsr | DT2821_SUPCSR_CLRDMADNE,
461 dev->iobase + DT2821_SUPCSR_REG); 477 dev->iobase + DT2821_SUPCSR_REG);
@@ -464,13 +480,8 @@ static void dt282x_ao_dma_interrupt(struct comedi_device *dev,
464 480
465 devpriv->current_dma_index = 1 - cur_dma; 481 devpriv->current_dma_index = 1 - cur_dma;
466 482
467 size = cfc_read_array_from_buffer(s, ptr, devpriv->dma_maxsize); 483 if (!dt282x_ao_setup_dma(dev, s, cur_dma))
468 if (size == 0) {
469 dev_err(dev->class_dev, "AO underrun\n");
470 s->async->events |= COMEDI_CB_OVERFLOW; 484 s->async->events |= COMEDI_CB_OVERFLOW;
471 } else {
472 dt282x_prep_ao_dma(dev, cur_dma, size);
473 }
474} 485}
475 486
476static void dt282x_ai_dma_interrupt(struct comedi_device *dev, 487static void dt282x_ai_dma_interrupt(struct comedi_device *dev,
@@ -480,6 +491,7 @@ static void dt282x_ai_dma_interrupt(struct comedi_device *dev,
480 int cur_dma = devpriv->current_dma_index; 491 int cur_dma = devpriv->current_dma_index;
481 void *ptr = devpriv->dma[cur_dma].buf; 492 void *ptr = devpriv->dma[cur_dma].buf;
482 int size = devpriv->dma[cur_dma].size; 493 int size = devpriv->dma[cur_dma].size;
494 unsigned int nsamples = comedi_bytes_to_samples(s, size);
483 int ret; 495 int ret;
484 496
485 outw(devpriv->supcsr | DT2821_SUPCSR_CLRDMADNE, 497 outw(devpriv->supcsr | DT2821_SUPCSR_CLRDMADNE,
@@ -490,13 +502,11 @@ static void dt282x_ai_dma_interrupt(struct comedi_device *dev,
490 devpriv->current_dma_index = 1 - cur_dma; 502 devpriv->current_dma_index = 1 - cur_dma;
491 503
492 dt282x_munge(dev, s, ptr, size); 504 dt282x_munge(dev, s, ptr, size);
493 ret = cfc_write_array_to_buffer(s, ptr, size); 505 ret = comedi_buf_write_samples(s, ptr, nsamples);
494 if (ret != size) { 506 if (ret != size)
495 s->async->events |= COMEDI_CB_OVERFLOW;
496 return; 507 return;
497 }
498 508
499 devpriv->nread -= size / 2; 509 devpriv->nread -= nsamples;
500 if (devpriv->nread < 0) { 510 if (devpriv->nread < 0) {
501 dev_info(dev->class_dev, "nread off by one\n"); 511 dev_info(dev->class_dev, "nread off by one\n");
502 devpriv->nread = 0; 512 devpriv->nread = 0;
@@ -555,7 +565,6 @@ static irqreturn_t dt282x_interrupt(int irq, void *d)
555 } 565 }
556#if 0 566#if 0
557 if (adcsr & DT2821_ADCSR_ADDONE) { 567 if (adcsr & DT2821_ADCSR_ADDONE) {
558 int ret;
559 unsigned short data; 568 unsigned short data;
560 569
561 data = inw(dev->iobase + DT2821_ADDAT_REG); 570 data = inw(dev->iobase + DT2821_ADDAT_REG);
@@ -563,10 +572,7 @@ static irqreturn_t dt282x_interrupt(int irq, void *d)
563 if (devpriv->ad_2scomp) 572 if (devpriv->ad_2scomp)
564 data = comedi_offset_munge(s, data); 573 data = comedi_offset_munge(s, data);
565 574
566 ret = comedi_buf_put(s, data); 575 comedi_buf_write_samples(s, &data, 1);
567
568 if (ret == 0)
569 s->async->events |= COMEDI_CB_OVERFLOW;
570 576
571 devpriv->nread--; 577 devpriv->nread--;
572 if (!devpriv->nread) { 578 if (!devpriv->nread) {
@@ -579,8 +585,8 @@ static irqreturn_t dt282x_interrupt(int irq, void *d)
579 handled = 1; 585 handled = 1;
580 } 586 }
581#endif 587#endif
582 cfc_handle_events(dev, s); 588 comedi_handle_events(dev, s);
583 cfc_handle_events(dev, s_ao); 589 comedi_handle_events(dev, s_ao);
584 590
585 return IRQ_RETVAL(handled); 591 return IRQ_RETVAL(handled);
586} 592}
@@ -916,26 +922,15 @@ static int dt282x_ao_inttrig(struct comedi_device *dev,
916{ 922{
917 struct dt282x_private *devpriv = dev->private; 923 struct dt282x_private *devpriv = dev->private;
918 struct comedi_cmd *cmd = &s->async->cmd; 924 struct comedi_cmd *cmd = &s->async->cmd;
919 int size;
920 925
921 if (trig_num != cmd->start_src) 926 if (trig_num != cmd->start_src)
922 return -EINVAL; 927 return -EINVAL;
923 928
924 size = cfc_read_array_from_buffer(s, devpriv->dma[0].buf, 929 if (!dt282x_ao_setup_dma(dev, s, 0))
925 devpriv->dma_maxsize);
926 if (size == 0) {
927 dev_err(dev->class_dev, "AO underrun\n");
928 return -EPIPE; 930 return -EPIPE;
929 }
930 dt282x_prep_ao_dma(dev, 0, size);
931 931
932 size = cfc_read_array_from_buffer(s, devpriv->dma[1].buf, 932 if (!dt282x_ao_setup_dma(dev, s, 1))
933 devpriv->dma_maxsize);
934 if (size == 0) {
935 dev_err(dev->class_dev, "AO underrun\n");
936 return -EPIPE; 933 return -EPIPE;
937 }
938 dt282x_prep_ao_dma(dev, 1, size);
939 934
940 outw(devpriv->supcsr | DT2821_SUPCSR_STRIG, 935 outw(devpriv->supcsr | DT2821_SUPCSR_STRIG,
941 dev->iobase + DT2821_SUPCSR_REG); 936 dev->iobase + DT2821_SUPCSR_REG);
@@ -1236,7 +1231,6 @@ static int dt282x_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1236 /* ranges are per-channel, set by jumpers on the board */ 1231 /* ranges are per-channel, set by jumpers on the board */
1237 s->range_table = &dt282x_ao_range; 1232 s->range_table = &dt282x_ao_range;
1238 s->insn_write = dt282x_ao_insn_write; 1233 s->insn_write = dt282x_ao_insn_write;
1239 s->insn_read = comedi_readback_insn_read;
1240 if (dev->irq) { 1234 if (dev->irq) {
1241 dev->write_subdev = s; 1235 dev->write_subdev = s;
1242 s->subdev_flags |= SDF_CMD_WRITE; 1236 s->subdev_flags |= SDF_CMD_WRITE;
diff --git a/drivers/staging/comedi/drivers/dt3000.c b/drivers/staging/comedi/drivers/dt3000.c
index 825561046b6f..1d9a7a63e06f 100644
--- a/drivers/staging/comedi/drivers/dt3000.c
+++ b/drivers/staging/comedi/drivers/dt3000.c
@@ -315,7 +315,7 @@ static void dt3k_ai_empty_fifo(struct comedi_device *dev,
315 315
316 for (i = 0; i < count; i++) { 316 for (i = 0; i < count; i++) {
317 data = readw(dev->mmio + DPR_ADC_buffer + rear); 317 data = readw(dev->mmio + DPR_ADC_buffer + rear);
318 comedi_buf_put(s, data); 318 comedi_buf_write_samples(s, &data, 1);
319 rear++; 319 rear++;
320 if (rear >= AI_FIFO_DEPTH) 320 if (rear >= AI_FIFO_DEPTH)
321 rear = 0; 321 rear = 0;
@@ -351,10 +351,8 @@ static irqreturn_t dt3k_interrupt(int irq, void *d)
351 351
352 status = readw(dev->mmio + DPR_Intr_Flag); 352 status = readw(dev->mmio + DPR_Intr_Flag);
353 353
354 if (status & DT3000_ADFULL) { 354 if (status & DT3000_ADFULL)
355 dt3k_ai_empty_fifo(dev, s); 355 dt3k_ai_empty_fifo(dev, s);
356 s->async->events |= COMEDI_CB_BLOCK;
357 }
358 356
359 if (status & (DT3000_ADSWERR | DT3000_ADHWERR)) 357 if (status & (DT3000_ADSWERR | DT3000_ADHWERR))
360 s->async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; 358 s->async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA;
@@ -363,7 +361,7 @@ static irqreturn_t dt3k_interrupt(int irq, void *d)
363 if (debug_n_ints >= 10) 361 if (debug_n_ints >= 10)
364 s->async->events |= COMEDI_CB_EOA; 362 s->async->events |= COMEDI_CB_EOA;
365 363
366 cfc_handle_events(dev, s); 364 comedi_handle_events(dev, s);
367 return IRQ_HANDLED; 365 return IRQ_HANDLED;
368} 366}
369 367
@@ -699,7 +697,6 @@ static int dt3000_auto_attach(struct comedi_device *dev,
699 s->len_chanlist = 1; 697 s->len_chanlist = 1;
700 s->range_table = &range_bipolar10; 698 s->range_table = &range_bipolar10;
701 s->insn_write = dt3k_ao_insn_write; 699 s->insn_write = dt3k_ao_insn_write;
702 s->insn_read = comedi_readback_insn_read;
703 700
704 ret = comedi_alloc_subdev_readback(s); 701 ret = comedi_alloc_subdev_readback(s);
705 if (ret) 702 if (ret)
diff --git a/drivers/staging/comedi/drivers/dt9812.c b/drivers/staging/comedi/drivers/dt9812.c
index 77bb89fee327..06c601d8fdff 100644
--- a/drivers/staging/comedi/drivers/dt9812.c
+++ b/drivers/staging/comedi/drivers/dt9812.c
@@ -804,7 +804,7 @@ static int dt9812_auto_attach(struct comedi_device *dev,
804 /* Digital Output subdevice */ 804 /* Digital Output subdevice */
805 s = &dev->subdevices[1]; 805 s = &dev->subdevices[1];
806 s->type = COMEDI_SUBD_DO; 806 s->type = COMEDI_SUBD_DO;
807 s->subdev_flags = SDF_WRITEABLE; 807 s->subdev_flags = SDF_WRITABLE;
808 s->n_chan = 8; 808 s->n_chan = 8;
809 s->maxdata = 1; 809 s->maxdata = 1;
810 s->range_table = &range_digital; 810 s->range_table = &range_digital;
@@ -822,7 +822,7 @@ static int dt9812_auto_attach(struct comedi_device *dev,
822 /* Analog Output subdevice */ 822 /* Analog Output subdevice */
823 s = &dev->subdevices[3]; 823 s = &dev->subdevices[3];
824 s->type = COMEDI_SUBD_AO; 824 s->type = COMEDI_SUBD_AO;
825 s->subdev_flags = SDF_WRITEABLE; 825 s->subdev_flags = SDF_WRITABLE;
826 s->n_chan = 2; 826 s->n_chan = 2;
827 s->maxdata = 0x0fff; 827 s->maxdata = 0x0fff;
828 s->range_table = is_unipolar ? &range_unipolar2_5 : &range_bipolar10; 828 s->range_table = is_unipolar ? &range_unipolar2_5 : &range_bipolar10;
diff --git a/drivers/staging/comedi/drivers/dyna_pci10xx.c b/drivers/staging/comedi/drivers/dyna_pci10xx.c
index 608aee0c3a15..1b6324c6eb29 100644
--- a/drivers/staging/comedi/drivers/dyna_pci10xx.c
+++ b/drivers/staging/comedi/drivers/dyna_pci10xx.c
@@ -218,7 +218,7 @@ static int dyna_pci10xx_auto_attach(struct comedi_device *dev,
218 /* digital input */ 218 /* digital input */
219 s = &dev->subdevices[2]; 219 s = &dev->subdevices[2];
220 s->type = COMEDI_SUBD_DI; 220 s->type = COMEDI_SUBD_DI;
221 s->subdev_flags = SDF_READABLE | SDF_GROUND; 221 s->subdev_flags = SDF_READABLE;
222 s->n_chan = 16; 222 s->n_chan = 16;
223 s->maxdata = 1; 223 s->maxdata = 1;
224 s->range_table = &range_digital; 224 s->range_table = &range_digital;
@@ -228,7 +228,7 @@ static int dyna_pci10xx_auto_attach(struct comedi_device *dev,
228 /* digital output */ 228 /* digital output */
229 s = &dev->subdevices[3]; 229 s = &dev->subdevices[3];
230 s->type = COMEDI_SUBD_DO; 230 s->type = COMEDI_SUBD_DO;
231 s->subdev_flags = SDF_WRITABLE | SDF_GROUND; 231 s->subdev_flags = SDF_WRITABLE;
232 s->n_chan = 16; 232 s->n_chan = 16;
233 s->maxdata = 1; 233 s->maxdata = 1;
234 s->range_table = &range_digital; 234 s->range_table = &range_digital;
diff --git a/drivers/staging/comedi/drivers/fl512.c b/drivers/staging/comedi/drivers/fl512.c
index 5a1e3c8fc01c..e1f493241cd6 100644
--- a/drivers/staging/comedi/drivers/fl512.c
+++ b/drivers/staging/comedi/drivers/fl512.c
@@ -135,7 +135,6 @@ static int fl512_attach(struct comedi_device *dev, struct comedi_devconfig *it)
135 s->maxdata = 0x0fff; 135 s->maxdata = 0x0fff;
136 s->range_table = &range_fl512; 136 s->range_table = &range_fl512;
137 s->insn_write = fl512_ao_insn_write; 137 s->insn_write = fl512_ao_insn_write;
138 s->insn_read = comedi_readback_insn_read;
139 138
140 ret = comedi_alloc_subdev_readback(s); 139 ret = comedi_alloc_subdev_readback(s);
141 if (ret) 140 if (ret)
diff --git a/drivers/staging/comedi/drivers/gsc_hpdi.c b/drivers/staging/comedi/drivers/gsc_hpdi.c
index b8975a4606ea..0979f536ed39 100644
--- a/drivers/staging/comedi/drivers/gsc_hpdi.c
+++ b/drivers/staging/comedi/drivers/gsc_hpdi.c
@@ -196,8 +196,8 @@ static void gsc_hpdi_drain_dma(struct comedi_device *dev, unsigned int channel)
196 size = devpriv->dio_count; 196 size = devpriv->dio_count;
197 devpriv->dio_count -= size; 197 devpriv->dio_count -= size;
198 } 198 }
199 cfc_write_array_to_buffer(s, devpriv->desc_dio_buffer[idx], 199 comedi_buf_write_samples(s, devpriv->desc_dio_buffer[idx],
200 size * sizeof(uint32_t)); 200 size);
201 idx++; 201 idx++;
202 idx %= devpriv->num_dma_descriptors; 202 idx %= devpriv->num_dma_descriptors;
203 start = le32_to_cpu(devpriv->dma_desc[idx].pci_start_addr); 203 start = le32_to_cpu(devpriv->dma_desc[idx].pci_start_addr);
@@ -272,7 +272,7 @@ static irqreturn_t gsc_hpdi_interrupt(int irq, void *d)
272 if (devpriv->dio_count == 0) 272 if (devpriv->dio_count == 0)
273 async->events |= COMEDI_CB_EOA; 273 async->events |= COMEDI_CB_EOA;
274 274
275 cfc_handle_events(dev, s); 275 comedi_handle_events(dev, s);
276 276
277 return IRQ_HANDLED; 277 return IRQ_HANDLED;
278} 278}
@@ -689,7 +689,7 @@ static int gsc_hpdi_auto_attach(struct comedi_device *dev,
689 s = &dev->subdevices[0]; 689 s = &dev->subdevices[0];
690 dev->read_subdev = s; 690 dev->read_subdev = s;
691 s->type = COMEDI_SUBD_DIO; 691 s->type = COMEDI_SUBD_DIO;
692 s->subdev_flags = SDF_READABLE | SDF_WRITEABLE | SDF_LSAMPL | 692 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_LSAMPL |
693 SDF_CMD_READ; 693 SDF_CMD_READ;
694 s->n_chan = 32; 694 s->n_chan = 32;
695 s->len_chanlist = 32; 695 s->len_chanlist = 32;
diff --git a/drivers/staging/comedi/drivers/icp_multi.c b/drivers/staging/comedi/drivers/icp_multi.c
index f4e1c1cf4178..1ea168620103 100644
--- a/drivers/staging/comedi/drivers/icp_multi.c
+++ b/drivers/staging/comedi/drivers/icp_multi.c
@@ -53,7 +53,7 @@ Configuration options: not applicable, uses PCI auto config
53#define ICP_MULTI_AI 2 /* R: Analogue input data */ 53#define ICP_MULTI_AI 2 /* R: Analogue input data */
54#define ICP_MULTI_DAC_CSR 4 /* R/W: DAC command/status register */ 54#define ICP_MULTI_DAC_CSR 4 /* R/W: DAC command/status register */
55#define ICP_MULTI_AO 6 /* R/W: Analogue output data */ 55#define ICP_MULTI_AO 6 /* R/W: Analogue output data */
56#define ICP_MULTI_DI 8 /* R/W: Digital inouts */ 56#define ICP_MULTI_DI 8 /* R/W: Digital inputs */
57#define ICP_MULTI_DO 0x0A /* R/W: Digital outputs */ 57#define ICP_MULTI_DO 0x0A /* R/W: Digital outputs */
58#define ICP_MULTI_INT_EN 0x0C /* R/W: Interrupt enable register */ 58#define ICP_MULTI_INT_EN 0x0C /* R/W: Interrupt enable register */
59#define ICP_MULTI_INT_STAT 0x0E /* R/W: Interrupt status register */ 59#define ICP_MULTI_INT_STAT 0x0E /* R/W: Interrupt status register */
@@ -319,7 +319,7 @@ static int icp_multi_insn_bits_do(struct comedi_device *dev,
319 if (comedi_dio_update_state(s, data)) 319 if (comedi_dio_update_state(s, data))
320 writew(s->state, dev->mmio + ICP_MULTI_DO); 320 writew(s->state, dev->mmio + ICP_MULTI_DO);
321 321
322 data[1] = readw(dev->mmio + ICP_MULTI_DI); 322 data[1] = s->state;
323 323
324 return insn->n; 324 return insn->n;
325} 325}
@@ -495,7 +495,6 @@ static int icp_multi_auto_attach(struct comedi_device *dev,
495 s->len_chanlist = 4; 495 s->len_chanlist = 4;
496 s->range_table = &range_analog; 496 s->range_table = &range_analog;
497 s->insn_write = icp_multi_ao_insn_write; 497 s->insn_write = icp_multi_ao_insn_write;
498 s->insn_read = comedi_readback_insn_read;
499 498
500 ret = comedi_alloc_subdev_readback(s); 499 ret = comedi_alloc_subdev_readback(s);
501 if (ret) 500 if (ret)
@@ -512,7 +511,7 @@ static int icp_multi_auto_attach(struct comedi_device *dev,
512 511
513 s = &dev->subdevices[3]; 512 s = &dev->subdevices[3];
514 s->type = COMEDI_SUBD_DO; 513 s->type = COMEDI_SUBD_DO;
515 s->subdev_flags = SDF_WRITABLE | SDF_READABLE; 514 s->subdev_flags = SDF_WRITABLE;
516 s->n_chan = 8; 515 s->n_chan = 8;
517 s->maxdata = 1; 516 s->maxdata = 1;
518 s->len_chanlist = 8; 517 s->len_chanlist = 8;
@@ -521,7 +520,7 @@ static int icp_multi_auto_attach(struct comedi_device *dev,
521 520
522 s = &dev->subdevices[4]; 521 s = &dev->subdevices[4];
523 s->type = COMEDI_SUBD_COUNTER; 522 s->type = COMEDI_SUBD_COUNTER;
524 s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON; 523 s->subdev_flags = SDF_WRITABLE;
525 s->n_chan = 4; 524 s->n_chan = 4;
526 s->maxdata = 0xffff; 525 s->maxdata = 0xffff;
527 s->len_chanlist = 4; 526 s->len_chanlist = 4;
diff --git a/drivers/staging/comedi/drivers/ii_pci20kc.c b/drivers/staging/comedi/drivers/ii_pci20kc.c
index cc5fd75b8bc0..1085d66935fe 100644
--- a/drivers/staging/comedi/drivers/ii_pci20kc.c
+++ b/drivers/staging/comedi/drivers/ii_pci20kc.c
@@ -392,7 +392,6 @@ static int ii20k_init_module(struct comedi_device *dev,
392 s->maxdata = 0xffff; 392 s->maxdata = 0xffff;
393 s->range_table = &ii20k_ao_ranges; 393 s->range_table = &ii20k_ao_ranges;
394 s->insn_write = ii20k_ao_insn_write; 394 s->insn_write = ii20k_ao_insn_write;
395 s->insn_read = comedi_readback_insn_read;
396 395
397 ret = comedi_alloc_subdev_readback(s); 396 ret = comedi_alloc_subdev_readback(s);
398 if (ret) 397 if (ret)
diff --git a/drivers/staging/comedi/drivers/me4000.c b/drivers/staging/comedi/drivers/me4000.c
index 6561b00bea59..915685c1c85c 100644
--- a/drivers/staging/comedi/drivers/me4000.c
+++ b/drivers/staging/comedi/drivers/me4000.c
@@ -44,8 +44,6 @@ broken.
44#include <linux/pci.h> 44#include <linux/pci.h>
45#include <linux/delay.h> 45#include <linux/delay.h>
46#include <linux/interrupt.h> 46#include <linux/interrupt.h>
47#include <linux/list.h>
48#include <linux/spinlock.h>
49 47
50#include "../comedidev.h" 48#include "../comedidev.h"
51 49
@@ -53,10 +51,7 @@ broken.
53#include "8253.h" 51#include "8253.h"
54#include "plx9052.h" 52#include "plx9052.h"
55 53
56#if 0 54#define ME4000_FIRMWARE "me4000_firmware.bin"
57/* file removed due to GPL incompatibility */
58#include "me4000_fw.h"
59#endif
60 55
61/* 56/*
62 * ME4000 Register map and bit defines 57 * ME4000 Register map and bit defines
@@ -333,27 +328,20 @@ static const struct comedi_lrange me4000_ai_range = {
333 } 328 }
334}; 329};
335 330
336#define FIRMWARE_NOT_AVAILABLE 1 331static int me4000_xilinx_download(struct comedi_device *dev,
337#if FIRMWARE_NOT_AVAILABLE 332 const u8 *data, size_t size,
338extern unsigned char *xilinx_firm; 333 unsigned long context)
339#endif
340
341static int xilinx_download(struct comedi_device *dev)
342{ 334{
343 struct pci_dev *pcidev = comedi_to_pci_dev(dev); 335 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
344 struct me4000_info *info = dev->private; 336 struct me4000_info *info = dev->private;
345 unsigned long xilinx_iobase = pci_resource_start(pcidev, 5); 337 unsigned long xilinx_iobase = pci_resource_start(pcidev, 5);
346 u32 value = 0; 338 unsigned int file_length;
347 wait_queue_head_t queue; 339 unsigned int val;
348 int idx = 0; 340 unsigned int i;
349 int size = 0;
350 unsigned int intcsr;
351 341
352 if (!xilinx_iobase) 342 if (!xilinx_iobase)
353 return -ENODEV; 343 return -ENODEV;
354 344
355 init_waitqueue_head(&queue);
356
357 /* 345 /*
358 * Set PLX local interrupt 2 polarity to high. 346 * Set PLX local interrupt 2 polarity to high.
359 * Interrupt is thrown by init pin of xilinx. 347 * Interrupt is thrown by init pin of xilinx.
@@ -361,61 +349,58 @@ static int xilinx_download(struct comedi_device *dev)
361 outl(PLX9052_INTCSR_LI2POL, info->plx_regbase + PLX9052_INTCSR); 349 outl(PLX9052_INTCSR_LI2POL, info->plx_regbase + PLX9052_INTCSR);
362 350
363 /* Set /CS and /WRITE of the Xilinx */ 351 /* Set /CS and /WRITE of the Xilinx */
364 value = inl(info->plx_regbase + PLX9052_CNTRL); 352 val = inl(info->plx_regbase + PLX9052_CNTRL);
365 value |= PLX9052_CNTRL_UIO2_DATA; 353 val |= PLX9052_CNTRL_UIO2_DATA;
366 outl(value, info->plx_regbase + PLX9052_CNTRL); 354 outl(val, info->plx_regbase + PLX9052_CNTRL);
367 355
368 /* Init Xilinx with CS1 */ 356 /* Init Xilinx with CS1 */
369 inb(xilinx_iobase + 0xC8); 357 inb(xilinx_iobase + 0xC8);
370 358
371 /* Wait until /INIT pin is set */ 359 /* Wait until /INIT pin is set */
372 udelay(20); 360 udelay(20);
373 intcsr = inl(info->plx_regbase + PLX9052_INTCSR); 361 val = inl(info->plx_regbase + PLX9052_INTCSR);
374 if (!(intcsr & PLX9052_INTCSR_LI2STAT)) { 362 if (!(val & PLX9052_INTCSR_LI2STAT)) {
375 dev_err(dev->class_dev, "Can't init Xilinx\n"); 363 dev_err(dev->class_dev, "Can't init Xilinx\n");
376 return -EIO; 364 return -EIO;
377 } 365 }
378 366
379 /* Reset /CS and /WRITE of the Xilinx */ 367 /* Reset /CS and /WRITE of the Xilinx */
380 value = inl(info->plx_regbase + PLX9052_CNTRL); 368 val = inl(info->plx_regbase + PLX9052_CNTRL);
381 value &= ~PLX9052_CNTRL_UIO2_DATA; 369 val &= ~PLX9052_CNTRL_UIO2_DATA;
382 outl(value, info->plx_regbase + PLX9052_CNTRL); 370 outl(val, info->plx_regbase + PLX9052_CNTRL);
383 if (FIRMWARE_NOT_AVAILABLE) {
384 dev_err(dev->class_dev,
385 "xilinx firmware unavailable due to licensing, aborting");
386 return -EIO;
387 } else {
388 /* Download Xilinx firmware */
389 size = (xilinx_firm[0] << 24) + (xilinx_firm[1] << 16) +
390 (xilinx_firm[2] << 8) + xilinx_firm[3];
391 udelay(10);
392 371
393 for (idx = 0; idx < size; idx++) { 372 /* Download Xilinx firmware */
394 outb(xilinx_firm[16 + idx], xilinx_iobase); 373 file_length = (((unsigned int)data[0] & 0xff) << 24) +
395 udelay(10); 374 (((unsigned int)data[1] & 0xff) << 16) +
375 (((unsigned int)data[2] & 0xff) << 8) +
376 ((unsigned int)data[3] & 0xff);
377 udelay(10);
396 378
397 /* Check if BUSY flag is low */ 379 for (i = 0; i < file_length; i++) {
398 if (inl(info->plx_regbase + PLX9052_CNTRL) & PLX9052_CNTRL_UIO1_DATA) { 380 outb(data[16 + i], xilinx_iobase);
399 dev_err(dev->class_dev, 381 udelay(10);
400 "Xilinx is still busy (idx = %d)\n", 382
401 idx); 383 /* Check if BUSY flag is low */
402 return -EIO; 384 val = inl(info->plx_regbase + PLX9052_CNTRL);
403 } 385 if (val & PLX9052_CNTRL_UIO1_DATA) {
386 dev_err(dev->class_dev,
387 "Xilinx is still busy (i = %d)\n", i);
388 return -EIO;
404 } 389 }
405 } 390 }
406 391
407 /* If done flag is high download was successful */ 392 /* If done flag is high download was successful */
408 if (inl(info->plx_regbase + PLX9052_CNTRL) & PLX9052_CNTRL_UIO0_DATA) { 393 val = inl(info->plx_regbase + PLX9052_CNTRL);
409 } else { 394 if (!(val & PLX9052_CNTRL_UIO0_DATA)) {
410 dev_err(dev->class_dev, "DONE flag is not set\n"); 395 dev_err(dev->class_dev, "DONE flag is not set\n");
411 dev_err(dev->class_dev, "Download not successful\n"); 396 dev_err(dev->class_dev, "Download not successful\n");
412 return -EIO; 397 return -EIO;
413 } 398 }
414 399
415 /* Set /CS and /WRITE */ 400 /* Set /CS and /WRITE */
416 value = inl(info->plx_regbase + PLX9052_CNTRL); 401 val = inl(info->plx_regbase + PLX9052_CNTRL);
417 value |= PLX9052_CNTRL_UIO2_DATA; 402 val |= PLX9052_CNTRL_UIO2_DATA;
418 outl(value, info->plx_regbase + PLX9052_CNTRL); 403 outl(val, info->plx_regbase + PLX9052_CNTRL);
419 404
420 return 0; 405 return 0;
421} 406}
@@ -431,7 +416,7 @@ static void me4000_reset(struct comedi_device *dev)
431 val |= PLX9052_CNTRL_PCI_RESET; 416 val |= PLX9052_CNTRL_PCI_RESET;
432 outl(val, info->plx_regbase + PLX9052_CNTRL); 417 outl(val, info->plx_regbase + PLX9052_CNTRL);
433 val &= ~PLX9052_CNTRL_PCI_RESET; 418 val &= ~PLX9052_CNTRL_PCI_RESET;
434 outl(val , info->plx_regbase + PLX9052_CNTRL); 419 outl(val, info->plx_regbase + PLX9052_CNTRL);
435 420
436 /* 0x8000 to the DACs means an output voltage of 0V */ 421 /* 0x8000 to the DACs means an output voltage of 0V */
437 for (chan = 0; chan < 4; chan++) 422 for (chan = 0; chan < 4; chan++)
@@ -848,9 +833,6 @@ static int me4000_ai_do_cmd_test(struct comedi_device *dev,
848 unsigned int scan_ticks; 833 unsigned int scan_ticks;
849 int err = 0; 834 int err = 0;
850 835
851 /* Only rounding flags are implemented */
852 cmd->flags &= CMDF_ROUND_NEAREST | CMDF_ROUND_UP | CMDF_ROUND_DOWN;
853
854 /* Round the timer arguments */ 836 /* Round the timer arguments */
855 ai_round_cmd_args(dev, s, cmd, &init_ticks, &scan_ticks, &chan_ticks); 837 ai_round_cmd_args(dev, s, cmd, &init_ticks, &scan_ticks, &chan_ticks);
856 838
@@ -1092,8 +1074,6 @@ static irqreturn_t me4000_ai_isr(int irq, void *dev_id)
1092 } else if ((tmp & ME4000_AI_STATUS_BIT_FF_DATA) 1074 } else if ((tmp & ME4000_AI_STATUS_BIT_FF_DATA)
1093 && !(tmp & ME4000_AI_STATUS_BIT_HF_DATA) 1075 && !(tmp & ME4000_AI_STATUS_BIT_HF_DATA)
1094 && (tmp & ME4000_AI_STATUS_BIT_EF_DATA)) { 1076 && (tmp & ME4000_AI_STATUS_BIT_EF_DATA)) {
1095 s->async->events |= COMEDI_CB_BLOCK;
1096
1097 c = ME4000_AI_FIFO_COUNT / 2; 1077 c = ME4000_AI_FIFO_COUNT / 2;
1098 } else { 1078 } else {
1099 dev_err(dev->class_dev, 1079 dev_err(dev->class_dev,
@@ -1119,7 +1099,7 @@ static irqreturn_t me4000_ai_isr(int irq, void *dev_id)
1119 lval = inl(dev->iobase + ME4000_AI_DATA_REG) & 0xFFFF; 1099 lval = inl(dev->iobase + ME4000_AI_DATA_REG) & 0xFFFF;
1120 lval ^= 0x8000; 1100 lval ^= 0x8000;
1121 1101
1122 if (!comedi_buf_put(s, lval)) { 1102 if (!comedi_buf_write_samples(s, &lval, 1)) {
1123 /* 1103 /*
1124 * Buffer overflow, so stop conversion 1104 * Buffer overflow, so stop conversion
1125 * and disable all interrupts 1105 * and disable all interrupts
@@ -1128,11 +1108,6 @@ static irqreturn_t me4000_ai_isr(int irq, void *dev_id)
1128 tmp &= ~(ME4000_AI_CTRL_BIT_HF_IRQ | 1108 tmp &= ~(ME4000_AI_CTRL_BIT_HF_IRQ |
1129 ME4000_AI_CTRL_BIT_SC_IRQ); 1109 ME4000_AI_CTRL_BIT_SC_IRQ);
1130 outl(tmp, dev->iobase + ME4000_AI_CTRL_REG); 1110 outl(tmp, dev->iobase + ME4000_AI_CTRL_REG);
1131
1132 s->async->events |= COMEDI_CB_OVERFLOW;
1133
1134 dev_err(dev->class_dev, "Buffer overflow\n");
1135
1136 break; 1111 break;
1137 } 1112 }
1138 } 1113 }
@@ -1146,7 +1121,7 @@ static irqreturn_t me4000_ai_isr(int irq, void *dev_id)
1146 1121
1147 if (inl(dev->iobase + ME4000_IRQ_STATUS_REG) & 1122 if (inl(dev->iobase + ME4000_IRQ_STATUS_REG) &
1148 ME4000_IRQ_STATUS_BIT_SC) { 1123 ME4000_IRQ_STATUS_BIT_SC) {
1149 s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOA; 1124 s->async->events |= COMEDI_CB_EOA;
1150 1125
1151 /* 1126 /*
1152 * Acquisition is complete, so stop 1127 * Acquisition is complete, so stop
@@ -1164,11 +1139,8 @@ static irqreturn_t me4000_ai_isr(int irq, void *dev_id)
1164 lval = inl(dev->iobase + ME4000_AI_DATA_REG) & 0xFFFF; 1139 lval = inl(dev->iobase + ME4000_AI_DATA_REG) & 0xFFFF;
1165 lval ^= 0x8000; 1140 lval ^= 0x8000;
1166 1141
1167 if (!comedi_buf_put(s, lval)) { 1142 if (!comedi_buf_write_samples(s, &lval, 1))
1168 dev_err(dev->class_dev, "Buffer overflow\n");
1169 s->async->events |= COMEDI_CB_OVERFLOW;
1170 break; 1143 break;
1171 }
1172 } 1144 }
1173 1145
1174 /* Work is done, so reset the interrupt */ 1146 /* Work is done, so reset the interrupt */
@@ -1178,8 +1150,7 @@ static irqreturn_t me4000_ai_isr(int irq, void *dev_id)
1178 outl(tmp, dev->iobase + ME4000_AI_CTRL_REG); 1150 outl(tmp, dev->iobase + ME4000_AI_CTRL_REG);
1179 } 1151 }
1180 1152
1181 if (s->async->events) 1153 comedi_handle_events(dev, s);
1182 comedi_event(dev, s);
1183 1154
1184 return IRQ_HANDLED; 1155 return IRQ_HANDLED;
1185} 1156}
@@ -1397,8 +1368,9 @@ static int me4000_auto_attach(struct comedi_device *dev,
1397 if (!info->plx_regbase || !dev->iobase || !info->timer_regbase) 1368 if (!info->plx_regbase || !dev->iobase || !info->timer_regbase)
1398 return -ENODEV; 1369 return -ENODEV;
1399 1370
1400 result = xilinx_download(dev); 1371 result = comedi_load_firmware(dev, &pcidev->dev, ME4000_FIRMWARE,
1401 if (result) 1372 me4000_xilinx_download, 0);
1373 if (result < 0)
1402 return result; 1374 return result;
1403 1375
1404 me4000_reset(dev); 1376 me4000_reset(dev);
@@ -1449,12 +1421,11 @@ static int me4000_auto_attach(struct comedi_device *dev,
1449 1421
1450 if (thisboard->ao_nchan) { 1422 if (thisboard->ao_nchan) {
1451 s->type = COMEDI_SUBD_AO; 1423 s->type = COMEDI_SUBD_AO;
1452 s->subdev_flags = SDF_WRITEABLE | SDF_COMMON | SDF_GROUND; 1424 s->subdev_flags = SDF_WRITABLE | SDF_COMMON | SDF_GROUND;
1453 s->n_chan = thisboard->ao_nchan; 1425 s->n_chan = thisboard->ao_nchan;
1454 s->maxdata = 0xFFFF; /* 16 bit DAC */ 1426 s->maxdata = 0xFFFF; /* 16 bit DAC */
1455 s->range_table = &range_bipolar10; 1427 s->range_table = &range_bipolar10;
1456 s->insn_write = me4000_ao_insn_write; 1428 s->insn_write = me4000_ao_insn_write;
1457 s->insn_read = comedi_readback_insn_read;
1458 1429
1459 result = comedi_alloc_subdev_readback(s); 1430 result = comedi_alloc_subdev_readback(s);
1460 if (result) 1431 if (result)
@@ -1561,3 +1532,4 @@ module_comedi_pci_driver(me4000_driver, me4000_pci_driver);
1561MODULE_AUTHOR("Comedi http://www.comedi.org"); 1532MODULE_AUTHOR("Comedi http://www.comedi.org");
1562MODULE_DESCRIPTION("Comedi low-level driver"); 1533MODULE_DESCRIPTION("Comedi low-level driver");
1563MODULE_LICENSE("GPL"); 1534MODULE_LICENSE("GPL");
1535MODULE_FIRMWARE(ME4000_FIRMWARE);
diff --git a/drivers/staging/comedi/drivers/me_daq.c b/drivers/staging/comedi/drivers/me_daq.c
index 00eaaf8ac148..b5278c11e622 100644
--- a/drivers/staging/comedi/drivers/me_daq.c
+++ b/drivers/staging/comedi/drivers/me_daq.c
@@ -511,13 +511,12 @@ static int me_auto_attach(struct comedi_device *dev,
511 s = &dev->subdevices[1]; 511 s = &dev->subdevices[1];
512 if (board->has_ao) { 512 if (board->has_ao) {
513 s->type = COMEDI_SUBD_AO; 513 s->type = COMEDI_SUBD_AO;
514 s->subdev_flags = SDF_WRITEABLE | SDF_COMMON; 514 s->subdev_flags = SDF_WRITABLE | SDF_COMMON;
515 s->n_chan = 4; 515 s->n_chan = 4;
516 s->maxdata = 0x0fff; 516 s->maxdata = 0x0fff;
517 s->len_chanlist = 4; 517 s->len_chanlist = 4;
518 s->range_table = &me_ao_range; 518 s->range_table = &me_ao_range;
519 s->insn_write = me_ao_insn_write; 519 s->insn_write = me_ao_insn_write;
520 s->insn_read = comedi_readback_insn_read;
521 520
522 ret = comedi_alloc_subdev_readback(s); 521 ret = comedi_alloc_subdev_readback(s);
523 if (ret) 522 if (ret)
@@ -528,7 +527,7 @@ static int me_auto_attach(struct comedi_device *dev,
528 527
529 s = &dev->subdevices[2]; 528 s = &dev->subdevices[2];
530 s->type = COMEDI_SUBD_DIO; 529 s->type = COMEDI_SUBD_DIO;
531 s->subdev_flags = SDF_READABLE | SDF_WRITEABLE; 530 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
532 s->n_chan = 32; 531 s->n_chan = 32;
533 s->maxdata = 1; 532 s->maxdata = 1;
534 s->len_chanlist = 32; 533 s->len_chanlist = 32;
diff --git a/drivers/staging/comedi/drivers/mf6x4.c b/drivers/staging/comedi/drivers/mf6x4.c
index c8d3a22c5896..af21bc180c46 100644
--- a/drivers/staging/comedi/drivers/mf6x4.c
+++ b/drivers/staging/comedi/drivers/mf6x4.c
@@ -259,7 +259,6 @@ static int mf6x4_auto_attach(struct comedi_device *dev, unsigned long context)
259 s->maxdata = 0x3fff; /* 14 bits DAC */ 259 s->maxdata = 0x3fff; /* 14 bits DAC */
260 s->range_table = &range_bipolar10; 260 s->range_table = &range_bipolar10;
261 s->insn_write = mf6x4_ao_insn_write; 261 s->insn_write = mf6x4_ao_insn_write;
262 s->insn_read = comedi_readback_insn_read;
263 262
264 ret = comedi_alloc_subdev_readback(s); 263 ret = comedi_alloc_subdev_readback(s);
265 if (ret) 264 if (ret)
diff --git a/drivers/staging/comedi/drivers/mite.c b/drivers/staging/comedi/drivers/mite.c
index 4f7829010a99..ffc9e61d6cdd 100644
--- a/drivers/staging/comedi/drivers/mite.c
+++ b/drivers/staging/comedi/drivers/mite.c
@@ -494,13 +494,10 @@ EXPORT_SYMBOL_GPL(mite_bytes_read_from_memory_ub);
494unsigned mite_dma_tcr(struct mite_channel *mite_chan) 494unsigned mite_dma_tcr(struct mite_channel *mite_chan)
495{ 495{
496 struct mite_struct *mite = mite_chan->mite; 496 struct mite_struct *mite = mite_chan->mite;
497 int tcr;
498 int lkar; 497 int lkar;
499 498
500 lkar = readl(mite->mite_io_addr + MITE_LKAR(mite_chan->channel)); 499 lkar = readl(mite->mite_io_addr + MITE_LKAR(mite_chan->channel));
501 tcr = readl(mite->mite_io_addr + MITE_TCR(mite_chan->channel)); 500 return readl(mite->mite_io_addr + MITE_TCR(mite_chan->channel));
502
503 return tcr;
504} 501}
505EXPORT_SYMBOL_GPL(mite_dma_tcr); 502EXPORT_SYMBOL_GPL(mite_dma_tcr);
506 503
@@ -542,7 +539,7 @@ int mite_sync_input_dma(struct mite_channel *mite_chan,
542 return 0; 539 return 0;
543 540
544 comedi_buf_write_free(s, count); 541 comedi_buf_write_free(s, count);
545 cfc_inc_scan_progress(s, count); 542 comedi_inc_scan_progress(s, count);
546 async->events |= COMEDI_CB_BLOCK; 543 async->events |= COMEDI_CB_BLOCK;
547 return 0; 544 return 0;
548} 545}
@@ -553,7 +550,7 @@ int mite_sync_output_dma(struct mite_channel *mite_chan,
553{ 550{
554 struct comedi_async *async = s->async; 551 struct comedi_async *async = s->async;
555 struct comedi_cmd *cmd = &async->cmd; 552 struct comedi_cmd *cmd = &async->cmd;
556 u32 stop_count = cmd->stop_arg * cfc_bytes_per_scan(s); 553 u32 stop_count = cmd->stop_arg * comedi_bytes_per_scan(s);
557 unsigned int old_alloc_count = async->buf_read_alloc_count; 554 unsigned int old_alloc_count = async->buf_read_alloc_count;
558 u32 nbytes_ub, nbytes_lb; 555 u32 nbytes_ub, nbytes_lb;
559 int count; 556 int count;
diff --git a/drivers/staging/comedi/drivers/multiq3.c b/drivers/staging/comedi/drivers/multiq3.c
index f710c8e81320..8471219210b6 100644
--- a/drivers/staging/comedi/drivers/multiq3.c
+++ b/drivers/staging/comedi/drivers/multiq3.c
@@ -238,7 +238,6 @@ static int multiq3_attach(struct comedi_device *dev,
238 s->maxdata = 0xfff; 238 s->maxdata = 0xfff;
239 s->range_table = &range_bipolar5; 239 s->range_table = &range_bipolar5;
240 s->insn_write = multiq3_ao_insn_write; 240 s->insn_write = multiq3_ao_insn_write;
241 s->insn_read = comedi_readback_insn_read;
242 241
243 ret = comedi_alloc_subdev_readback(s); 242 ret = comedi_alloc_subdev_readback(s);
244 if (ret) 243 if (ret)
diff --git a/drivers/staging/comedi/drivers/ni_6527.c b/drivers/staging/comedi/drivers/ni_6527.c
index 45fb601e4080..f99847f3999f 100644
--- a/drivers/staging/comedi/drivers/ni_6527.c
+++ b/drivers/staging/comedi/drivers/ni_6527.c
@@ -208,9 +208,8 @@ static irqreturn_t ni6527_interrupt(int irq, void *d)
208 return IRQ_NONE; 208 return IRQ_NONE;
209 209
210 if (status & NI6527_STATUS_EDGE) { 210 if (status & NI6527_STATUS_EDGE) {
211 comedi_buf_put(s, 0); 211 comedi_buf_write_samples(s, &s->state, 1);
212 s->async->events |= COMEDI_CB_EOS; 212 comedi_handle_events(dev, s);
213 comedi_event(dev, s);
214 } 213 }
215 214
216 writeb(NI6527_CLR_IRQS, dev->mmio + NI6527_CLR_REG); 215 writeb(NI6527_CLR_IRQS, dev->mmio + NI6527_CLR_REG);
@@ -238,9 +237,6 @@ static int ni6527_intr_cmdtest(struct comedi_device *dev,
238 /* Step 2a : make sure trigger sources are unique */ 237 /* Step 2a : make sure trigger sources are unique */
239 /* Step 2b : and mutually compatible */ 238 /* Step 2b : and mutually compatible */
240 239
241 if (err)
242 return 2;
243
244 /* Step 3: check if arguments are trivially valid */ 240 /* Step 3: check if arguments are trivially valid */
245 241
246 err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0); 242 err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
diff --git a/drivers/staging/comedi/drivers/ni_65xx.c b/drivers/staging/comedi/drivers/ni_65xx.c
index 3b642861eb36..bcb326e31562 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -508,9 +508,9 @@ static irqreturn_t ni_65xx_interrupt(int irq, void *d)
508 writeb(NI_65XX_CLR_EDGE_INT | NI_65XX_CLR_OVERFLOW_INT, 508 writeb(NI_65XX_CLR_EDGE_INT | NI_65XX_CLR_OVERFLOW_INT,
509 dev->mmio + NI_65XX_CLR_REG); 509 dev->mmio + NI_65XX_CLR_REG);
510 510
511 comedi_buf_put(s, 0); 511 comedi_buf_write_samples(s, &s->state, 1);
512 s->async->events |= COMEDI_CB_EOS; 512 comedi_handle_events(dev, s);
513 comedi_event(dev, s); 513
514 return IRQ_HANDLED; 514 return IRQ_HANDLED;
515} 515}
516 516
@@ -534,9 +534,6 @@ static int ni_65xx_intr_cmdtest(struct comedi_device *dev,
534 /* Step 2a : make sure trigger sources are unique */ 534 /* Step 2a : make sure trigger sources are unique */
535 /* Step 2b : and mutually compatible */ 535 /* Step 2b : and mutually compatible */
536 536
537 if (err)
538 return 2;
539
540 /* Step 3: check if arguments are trivially valid */ 537 /* Step 3: check if arguments are trivially valid */
541 538
542 err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0); 539 err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
diff --git a/drivers/staging/comedi/drivers/ni_660x.c b/drivers/staging/comedi/drivers/ni_660x.c
index 5b6794c8232e..1e4dd82b12ea 100644
--- a/drivers/staging/comedi/drivers/ni_660x.c
+++ b/drivers/staging/comedi/drivers/ni_660x.c
@@ -780,7 +780,7 @@ static void ni_660x_handle_gpct_interrupt(struct comedi_device *dev,
780 struct ni_gpct *counter = s->private; 780 struct ni_gpct *counter = s->private;
781 781
782 ni_tio_handle_interrupt(counter, s); 782 ni_tio_handle_interrupt(counter, s);
783 cfc_handle_events(dev, s); 783 comedi_handle_events(dev, s);
784} 784}
785 785
786static irqreturn_t ni_660x_interrupt(int irq, void *d) 786static irqreturn_t ni_660x_interrupt(int irq, void *d)
diff --git a/drivers/staging/comedi/drivers/ni_670x.c b/drivers/staging/comedi/drivers/ni_670x.c
index 54721deb80cc..c42a81c0bfa1 100644
--- a/drivers/staging/comedi/drivers/ni_670x.c
+++ b/drivers/staging/comedi/drivers/ni_670x.c
@@ -228,7 +228,6 @@ static int ni_670x_auto_attach(struct comedi_device *dev,
228 s->range_table = &range_bipolar10; 228 s->range_table = &range_bipolar10;
229 } 229 }
230 s->insn_write = ni_670x_ao_insn_write; 230 s->insn_write = ni_670x_ao_insn_write;
231 s->insn_read = comedi_readback_insn_read;
232 231
233 ret = comedi_alloc_subdev_readback(s); 232 ret = comedi_alloc_subdev_readback(s);
234 if (ret) 233 if (ret)
diff --git a/drivers/staging/comedi/drivers/ni_at_a2150.c b/drivers/staging/comedi/drivers/ni_at_a2150.c
index 72ec857d073e..69e543a0bf22 100644
--- a/drivers/staging/comedi/drivers/ni_at_a2150.c
+++ b/drivers/staging/comedi/drivers/ni_at_a2150.c
@@ -168,7 +168,6 @@ static irqreturn_t a2150_interrupt(int irq, void *d)
168 struct comedi_cmd *cmd; 168 struct comedi_cmd *cmd;
169 unsigned int max_points, num_points, residue, leftover; 169 unsigned int max_points, num_points, residue, leftover;
170 unsigned short dpnt; 170 unsigned short dpnt;
171 static const int sample_size = sizeof(devpriv->dma_buffer[0]);
172 171
173 if (!dev->attached) { 172 if (!dev->attached) {
174 dev_err(dev->class_dev, "premature interrupt\n"); 173 dev_err(dev->class_dev, "premature interrupt\n");
@@ -188,14 +187,14 @@ static irqreturn_t a2150_interrupt(int irq, void *d)
188 if (status & OVFL_BIT) { 187 if (status & OVFL_BIT) {
189 dev_err(dev->class_dev, "fifo overflow\n"); 188 dev_err(dev->class_dev, "fifo overflow\n");
190 async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; 189 async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA;
191 cfc_handle_events(dev, s); 190 comedi_handle_events(dev, s);
192 } 191 }
193 192
194 if ((status & DMA_TC_BIT) == 0) { 193 if ((status & DMA_TC_BIT) == 0) {
195 dev_err(dev->class_dev, 194 dev_err(dev->class_dev,
196 "caught non-dma interrupt? Aborting.\n"); 195 "caught non-dma interrupt? Aborting.\n");
197 async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; 196 async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA;
198 cfc_handle_events(dev, s); 197 comedi_handle_events(dev, s);
199 return IRQ_HANDLED; 198 return IRQ_HANDLED;
200 } 199 }
201 200
@@ -206,12 +205,12 @@ static irqreturn_t a2150_interrupt(int irq, void *d)
206 clear_dma_ff(devpriv->dma); 205 clear_dma_ff(devpriv->dma);
207 206
208 /* figure out how many points to read */ 207 /* figure out how many points to read */
209 max_points = devpriv->dma_transfer_size / sample_size; 208 max_points = comedi_bytes_to_samples(s, devpriv->dma_transfer_size);
210 /* residue is the number of points left to be done on the dma 209 /* residue is the number of points left to be done on the dma
211 * transfer. It should always be zero at this point unless 210 * transfer. It should always be zero at this point unless
212 * the stop_src is set to external triggering. 211 * the stop_src is set to external triggering.
213 */ 212 */
214 residue = get_dma_residue(devpriv->dma) / sample_size; 213 residue = comedi_bytes_to_samples(s, get_dma_residue(devpriv->dma));
215 num_points = max_points - residue; 214 num_points = max_points - residue;
216 if (devpriv->count < num_points && cmd->stop_src == TRIG_COUNT) 215 if (devpriv->count < num_points && cmd->stop_src == TRIG_COUNT)
217 num_points = devpriv->count; 216 num_points = devpriv->count;
@@ -219,7 +218,8 @@ static irqreturn_t a2150_interrupt(int irq, void *d)
219 /* figure out how many points will be stored next time */ 218 /* figure out how many points will be stored next time */
220 leftover = 0; 219 leftover = 0;
221 if (cmd->stop_src == TRIG_NONE) { 220 if (cmd->stop_src == TRIG_NONE) {
222 leftover = devpriv->dma_transfer_size / sample_size; 221 leftover = comedi_bytes_to_samples(s,
222 devpriv->dma_transfer_size);
223 } else if (devpriv->count > max_points) { 223 } else if (devpriv->count > max_points) {
224 leftover = devpriv->count - max_points; 224 leftover = devpriv->count - max_points;
225 if (leftover > max_points) 225 if (leftover > max_points)
@@ -237,7 +237,7 @@ static irqreturn_t a2150_interrupt(int irq, void *d)
237 dpnt = devpriv->dma_buffer[i]; 237 dpnt = devpriv->dma_buffer[i];
238 /* convert from 2's complement to unsigned coding */ 238 /* convert from 2's complement to unsigned coding */
239 dpnt ^= 0x8000; 239 dpnt ^= 0x8000;
240 cfc_write_to_buffer(s, dpnt); 240 comedi_buf_write_samples(s, &dpnt, 1);
241 if (cmd->stop_src == TRIG_COUNT) { 241 if (cmd->stop_src == TRIG_COUNT) {
242 if (--devpriv->count == 0) { /* end of acquisition */ 242 if (--devpriv->count == 0) { /* end of acquisition */
243 async->events |= COMEDI_CB_EOA; 243 async->events |= COMEDI_CB_EOA;
@@ -248,14 +248,13 @@ static irqreturn_t a2150_interrupt(int irq, void *d)
248 /* re-enable dma */ 248 /* re-enable dma */
249 if (leftover) { 249 if (leftover) {
250 set_dma_addr(devpriv->dma, virt_to_bus(devpriv->dma_buffer)); 250 set_dma_addr(devpriv->dma, virt_to_bus(devpriv->dma_buffer));
251 set_dma_count(devpriv->dma, leftover * sample_size); 251 set_dma_count(devpriv->dma,
252 comedi_samples_to_bytes(s, leftover));
252 enable_dma(devpriv->dma); 253 enable_dma(devpriv->dma);
253 } 254 }
254 release_dma_lock(flags); 255 release_dma_lock(flags);
255 256
256 async->events |= COMEDI_CB_BLOCK; 257 comedi_handle_events(dev, s);
257
258 cfc_handle_events(dev, s);
259 258
260 /* clear interrupt */ 259 /* clear interrupt */
261 outw(0x00, dev->iobase + DMA_TC_CLEAR_REG); 260 outw(0x00, dev->iobase + DMA_TC_CLEAR_REG);
diff --git a/drivers/staging/comedi/drivers/ni_at_ao.c b/drivers/staging/comedi/drivers/ni_at_ao.c
index 3e1ce5866147..05370a4a74a5 100644
--- a/drivers/staging/comedi/drivers/ni_at_ao.c
+++ b/drivers/staging/comedi/drivers/ni_at_ao.c
@@ -244,47 +244,31 @@ static int atao_calib_insn_write(struct comedi_device *dev,
244 struct comedi_insn *insn, 244 struct comedi_insn *insn,
245 unsigned int *data) 245 unsigned int *data)
246{ 246{
247 struct atao_private *devpriv = dev->private;
248 unsigned int chan = CR_CHAN(insn->chanspec); 247 unsigned int chan = CR_CHAN(insn->chanspec);
249 unsigned int bitstring;
250 unsigned int val;
251 int bit;
252 248
253 if (insn->n == 0) 249 if (insn->n) {
254 return 0; 250 unsigned int val = data[insn->n - 1];
251 unsigned int bitstring = ((chan & 0x7) << 8) | val;
252 unsigned int bits;
253 int bit;
255 254
256 devpriv->caldac[chan] = data[insn->n - 1] & s->maxdata; 255 /* write the channel and last data value to the caldac */
256 /* clock the bitstring to the caldac; MSB -> LSB */
257 for (bit = 1 << 10; bit; bit >>= 1) {
258 bits = (bit & bitstring) ? ATAO_CFG2_SDATA : 0;
257 259
258 /* write the channel and last data value to the caldac */ 260 outw(bits, dev->iobase + ATAO_CFG2_REG);
259 bitstring = ((chan & 0x7) << 8) | devpriv->caldac[chan]; 261 outw(bits | ATAO_CFG2_SCLK,
262 dev->iobase + ATAO_CFG2_REG);
263 }
260 264
261 /* clock the bitstring to the caldac; MSB -> LSB */ 265 /* strobe the caldac to load the value */
262 for (bit = 1 << 10; bit; bit >>= 1) { 266 outw(ATAO_CFG2_CALLD(chan), dev->iobase + ATAO_CFG2_REG);
263 val = (bit & bitstring) ? ATAO_CFG2_SDATA : 0; 267 outw(ATAO_CFG2_CALLD_NOP, dev->iobase + ATAO_CFG2_REG);
264 268
265 outw(val, dev->iobase + ATAO_CFG2_REG); 269 s->readback[chan] = val;
266 outw(val | ATAO_CFG2_SCLK, dev->iobase + ATAO_CFG2_REG);
267 } 270 }
268 271
269 /* strobe the caldac to load the value */
270 outw(ATAO_CFG2_CALLD(chan), dev->iobase + ATAO_CFG2_REG);
271 outw(ATAO_CFG2_CALLD_NOP, dev->iobase + ATAO_CFG2_REG);
272
273 return insn->n;
274}
275
276static int atao_calib_insn_read(struct comedi_device *dev,
277 struct comedi_subdevice *s,
278 struct comedi_insn *insn,
279 unsigned int *data)
280{
281 struct atao_private *devpriv = dev->private;
282 unsigned int chan = CR_CHAN(insn->chanspec);
283 int i;
284
285 for (i = 0; i < insn->n; i++)
286 data[i] = devpriv->caldac[chan];
287
288 return insn->n; 272 return insn->n;
289} 273}
290 274
@@ -344,7 +328,6 @@ static int atao_attach(struct comedi_device *dev, struct comedi_devconfig *it)
344 s->maxdata = 0x0fff; 328 s->maxdata = 0x0fff;
345 s->range_table = it->options[3] ? &range_unipolar10 : &range_bipolar10; 329 s->range_table = it->options[3] ? &range_unipolar10 : &range_bipolar10;
346 s->insn_write = atao_ao_insn_write; 330 s->insn_write = atao_ao_insn_write;
347 s->insn_read = comedi_readback_insn_read;
348 331
349 ret = comedi_alloc_subdev_readback(s); 332 ret = comedi_alloc_subdev_readback(s);
350 if (ret) 333 if (ret)
@@ -366,9 +349,12 @@ static int atao_attach(struct comedi_device *dev, struct comedi_devconfig *it)
366 s->subdev_flags = SDF_WRITABLE | SDF_INTERNAL; 349 s->subdev_flags = SDF_WRITABLE | SDF_INTERNAL;
367 s->n_chan = (board->n_ao_chans * 2) + 1; 350 s->n_chan = (board->n_ao_chans * 2) + 1;
368 s->maxdata = 0xff; 351 s->maxdata = 0xff;
369 s->insn_read = atao_calib_insn_read;
370 s->insn_write = atao_calib_insn_write; 352 s->insn_write = atao_calib_insn_write;
371 353
354 ret = comedi_alloc_subdev_readback(s);
355 if (ret)
356 return ret;
357
372 /* EEPROM subdevice */ 358 /* EEPROM subdevice */
373 s = &dev->subdevices[3]; 359 s = &dev->subdevices[3];
374 s->type = COMEDI_SUBD_UNUSED; 360 s->type = COMEDI_SUBD_UNUSED;
diff --git a/drivers/staging/comedi/drivers/ni_atmio16d.c b/drivers/staging/comedi/drivers/ni_atmio16d.c
index fc3c19de7005..c484c89c94b5 100644
--- a/drivers/staging/comedi/drivers/ni_atmio16d.c
+++ b/drivers/staging/comedi/drivers/ni_atmio16d.c
@@ -217,10 +217,12 @@ static irqreturn_t atmio16d_interrupt(int irq, void *d)
217{ 217{
218 struct comedi_device *dev = d; 218 struct comedi_device *dev = d;
219 struct comedi_subdevice *s = dev->read_subdev; 219 struct comedi_subdevice *s = dev->read_subdev;
220 unsigned short val;
220 221
221 comedi_buf_put(s, inw(dev->iobase + AD_FIFO_REG)); 222 val = inw(dev->iobase + AD_FIFO_REG);
223 comedi_buf_write_samples(s, &val, 1);
224 comedi_handle_events(dev, s);
222 225
223 comedi_event(dev, s);
224 return IRQ_HANDLED; 226 return IRQ_HANDLED;
225} 227}
226 228
@@ -298,7 +300,6 @@ static int atmio16d_ai_cmd(struct comedi_device *dev,
298 * It is still uber-experimental */ 300 * It is still uber-experimental */
299 301
300 reset_counters(dev); 302 reset_counters(dev);
301 s->async->cur_chan = 0;
302 303
303 /* check if scanning multiple channels */ 304 /* check if scanning multiple channels */
304 if (cmd->chanlist_len < 2) { 305 if (cmd->chanlist_len < 2) {
@@ -691,7 +692,6 @@ static int atmio16d_attach(struct comedi_device *dev,
691 break; 692 break;
692 } 693 }
693 s->insn_write = atmio16d_ao_insn_write; 694 s->insn_write = atmio16d_ao_insn_write;
694 s->insn_read = comedi_readback_insn_read;
695 695
696 ret = comedi_alloc_subdev_readback(s); 696 ret = comedi_alloc_subdev_readback(s);
697 if (ret) 697 if (ret)
diff --git a/drivers/staging/comedi/drivers/ni_labpc.h b/drivers/staging/comedi/drivers/ni_labpc.h
index f6e5cd15a409..ac2c01f9dfdc 100644
--- a/drivers/staging/comedi/drivers/ni_labpc.h
+++ b/drivers/staging/comedi/drivers/ni_labpc.h
@@ -37,8 +37,6 @@ struct labpc_boardinfo {
37struct labpc_private { 37struct labpc_private {
38 /* number of data points left to be taken */ 38 /* number of data points left to be taken */
39 unsigned long long count; 39 unsigned long long count;
40 /* software copy of analog output values */
41 unsigned int ao_value[NUM_AO_CHAN];
42 /* software copys of bits written to command registers */ 40 /* software copys of bits written to command registers */
43 unsigned int cmd1; 41 unsigned int cmd1;
44 unsigned int cmd2; 42 unsigned int cmd2;
@@ -70,10 +68,6 @@ struct labpc_private {
70 unsigned int dma_transfer_size; 68 unsigned int dma_transfer_size;
71 /* we are using dma/fifo-half-full/etc. */ 69 /* we are using dma/fifo-half-full/etc. */
72 enum transfer_type current_transfer; 70 enum transfer_type current_transfer;
73 /* stores contents of board's eeprom */
74 unsigned int eeprom_data[EEPROM_SIZE];
75 /* stores settings of calibration dacs */
76 unsigned int caldac[16];
77 /* 71 /*
78 * function pointers so we can use inb/outb or readb/writeb as 72 * function pointers so we can use inb/outb or readb/writeb as
79 * appropriate 73 * appropriate
diff --git a/drivers/staging/comedi/drivers/ni_labpc_common.c b/drivers/staging/comedi/drivers/ni_labpc_common.c
index 35bc2c25ddfb..d89d5852aeea 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_common.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_common.c
@@ -818,7 +818,7 @@ static int labpc_drain_fifo(struct comedi_device *dev)
818 devpriv->count--; 818 devpriv->count--;
819 } 819 }
820 data = labpc_read_adc_fifo(dev); 820 data = labpc_read_adc_fifo(dev);
821 cfc_write_to_buffer(dev->read_subdev, data); 821 comedi_buf_write_samples(dev->read_subdev, &data, 1);
822 devpriv->stat1 = devpriv->read_byte(dev, STAT1_REG); 822 devpriv->stat1 = devpriv->read_byte(dev, STAT1_REG);
823 } 823 }
824 if (i == timeout) { 824 if (i == timeout) {
@@ -876,7 +876,7 @@ static irqreturn_t labpc_interrupt(int irq, void *d)
876 /* clear error interrupt */ 876 /* clear error interrupt */
877 devpriv->write_byte(dev, 0x1, ADC_FIFO_CLEAR_REG); 877 devpriv->write_byte(dev, 0x1, ADC_FIFO_CLEAR_REG);
878 async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; 878 async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA;
879 cfc_handle_events(dev, s); 879 comedi_handle_events(dev, s);
880 dev_err(dev->class_dev, "overrun\n"); 880 dev_err(dev->class_dev, "overrun\n");
881 return IRQ_HANDLED; 881 return IRQ_HANDLED;
882 } 882 }
@@ -896,7 +896,7 @@ static irqreturn_t labpc_interrupt(int irq, void *d)
896 /* clear error interrupt */ 896 /* clear error interrupt */
897 devpriv->write_byte(dev, 0x1, ADC_FIFO_CLEAR_REG); 897 devpriv->write_byte(dev, 0x1, ADC_FIFO_CLEAR_REG);
898 async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA; 898 async->events |= COMEDI_CB_ERROR | COMEDI_CB_EOA;
899 cfc_handle_events(dev, s); 899 comedi_handle_events(dev, s);
900 dev_err(dev->class_dev, "overflow\n"); 900 dev_err(dev->class_dev, "overflow\n");
901 return IRQ_HANDLED; 901 return IRQ_HANDLED;
902 } 902 }
@@ -914,10 +914,22 @@ static irqreturn_t labpc_interrupt(int irq, void *d)
914 async->events |= COMEDI_CB_EOA; 914 async->events |= COMEDI_CB_EOA;
915 } 915 }
916 916
917 cfc_handle_events(dev, s); 917 comedi_handle_events(dev, s);
918 return IRQ_HANDLED; 918 return IRQ_HANDLED;
919} 919}
920 920
921static void labpc_ao_write(struct comedi_device *dev,
922 struct comedi_subdevice *s,
923 unsigned int chan, unsigned int val)
924{
925 struct labpc_private *devpriv = dev->private;
926
927 devpriv->write_byte(dev, val & 0xff, DAC_LSB_REG(chan));
928 devpriv->write_byte(dev, (val >> 8) & 0xff, DAC_MSB_REG(chan));
929
930 s->readback[chan] = val;
931}
932
921static int labpc_ao_insn_write(struct comedi_device *dev, 933static int labpc_ao_insn_write(struct comedi_device *dev,
922 struct comedi_subdevice *s, 934 struct comedi_subdevice *s,
923 struct comedi_insn *insn, 935 struct comedi_insn *insn,
@@ -927,7 +939,6 @@ static int labpc_ao_insn_write(struct comedi_device *dev,
927 struct labpc_private *devpriv = dev->private; 939 struct labpc_private *devpriv = dev->private;
928 int channel, range; 940 int channel, range;
929 unsigned long flags; 941 unsigned long flags;
930 int lsb, msb;
931 942
932 channel = CR_CHAN(insn->chanspec); 943 channel = CR_CHAN(insn->chanspec);
933 944
@@ -950,25 +961,7 @@ static int labpc_ao_insn_write(struct comedi_device *dev,
950 devpriv->write_byte(dev, devpriv->cmd6, CMD6_REG); 961 devpriv->write_byte(dev, devpriv->cmd6, CMD6_REG);
951 } 962 }
952 /* send data */ 963 /* send data */
953 lsb = data[0] & 0xff; 964 labpc_ao_write(dev, s, channel, data[0]);
954 msb = (data[0] >> 8) & 0xff;
955 devpriv->write_byte(dev, lsb, DAC_LSB_REG(channel));
956 devpriv->write_byte(dev, msb, DAC_MSB_REG(channel));
957
958 /* remember value for readback */
959 devpriv->ao_value[channel] = data[0];
960
961 return 1;
962}
963
964static int labpc_ao_insn_read(struct comedi_device *dev,
965 struct comedi_subdevice *s,
966 struct comedi_insn *insn,
967 unsigned int *data)
968{
969 struct labpc_private *devpriv = dev->private;
970
971 data[0] = devpriv->ao_value[CR_CHAN(insn->chanspec)];
972 965
973 return 1; 966 return 1;
974} 967}
@@ -1085,29 +1078,13 @@ static unsigned int labpc_eeprom_read_status(struct comedi_device *dev)
1085 return value; 1078 return value;
1086} 1079}
1087 1080
1088static int labpc_eeprom_write(struct comedi_device *dev, 1081static void labpc_eeprom_write(struct comedi_device *dev,
1089 unsigned int address, unsigned int value) 1082 unsigned int address, unsigned int value)
1090{ 1083{
1091 struct labpc_private *devpriv = dev->private; 1084 struct labpc_private *devpriv = dev->private;
1092 const int write_enable_instruction = 0x6; 1085 const int write_enable_instruction = 0x6;
1093 const int write_instruction = 0x2; 1086 const int write_instruction = 0x2;
1094 const int write_length = 8; /* 8 bit write lengths to eeprom */ 1087 const int write_length = 8; /* 8 bit write lengths to eeprom */
1095 const int write_in_progress_bit = 0x1;
1096 const int timeout = 10000;
1097 int i;
1098
1099 /* make sure there isn't already a write in progress */
1100 for (i = 0; i < timeout; i++) {
1101 if ((labpc_eeprom_read_status(dev) & write_in_progress_bit) ==
1102 0)
1103 break;
1104 }
1105 if (i == timeout) {
1106 dev_err(dev->class_dev, "eeprom write timed out\n");
1107 return -ETIME;
1108 }
1109 /* update software copy of eeprom */
1110 devpriv->eeprom_data[address] = value;
1111 1088
1112 /* enable read/write to eeprom */ 1089 /* enable read/write to eeprom */
1113 devpriv->cmd5 &= ~CMD5_EEPROMCS; 1090 devpriv->cmd5 &= ~CMD5_EEPROMCS;
@@ -1140,8 +1117,6 @@ static int labpc_eeprom_write(struct comedi_device *dev,
1140 devpriv->cmd5 &= ~(CMD5_EEPROMCS | CMD5_WRTPRT); 1117 devpriv->cmd5 &= ~(CMD5_EEPROMCS | CMD5_WRTPRT);
1141 udelay(1); 1118 udelay(1);
1142 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG); 1119 devpriv->write_byte(dev, devpriv->cmd5, CMD5_REG);
1143
1144 return 0;
1145} 1120}
1146 1121
1147/* writes to 8 bit calibration dacs */ 1122/* writes to 8 bit calibration dacs */
@@ -1150,10 +1125,6 @@ static void write_caldac(struct comedi_device *dev, unsigned int channel,
1150{ 1125{
1151 struct labpc_private *devpriv = dev->private; 1126 struct labpc_private *devpriv = dev->private;
1152 1127
1153 if (value == devpriv->caldac[channel])
1154 return;
1155 devpriv->caldac[channel] = value;
1156
1157 /* clear caldac load bit and make sure we don't write to eeprom */ 1128 /* clear caldac load bit and make sure we don't write to eeprom */
1158 devpriv->cmd5 &= ~(CMD5_CALDACLD | CMD5_EEPROMCS | CMD5_WRTPRT); 1129 devpriv->cmd5 &= ~(CMD5_CALDACLD | CMD5_EEPROMCS | CMD5_WRTPRT);
1159 udelay(1); 1130 udelay(1);
@@ -1184,25 +1155,30 @@ static int labpc_calib_insn_write(struct comedi_device *dev,
1184 * Only write the last data value to the caldac. Preceding 1155 * Only write the last data value to the caldac. Preceding
1185 * data would be overwritten anyway. 1156 * data would be overwritten anyway.
1186 */ 1157 */
1187 if (insn->n > 0) 1158 if (insn->n > 0) {
1188 write_caldac(dev, chan, data[insn->n - 1]); 1159 unsigned int val = data[insn->n - 1];
1160
1161 if (s->readback[chan] != val) {
1162 write_caldac(dev, chan, val);
1163 s->readback[chan] = val;
1164 }
1165 }
1189 1166
1190 return insn->n; 1167 return insn->n;
1191} 1168}
1192 1169
1193static int labpc_calib_insn_read(struct comedi_device *dev, 1170static int labpc_eeprom_ready(struct comedi_device *dev,
1194 struct comedi_subdevice *s, 1171 struct comedi_subdevice *s,
1195 struct comedi_insn *insn, 1172 struct comedi_insn *insn,
1196 unsigned int *data) 1173 unsigned long context)
1197{ 1174{
1198 struct labpc_private *devpriv = dev->private; 1175 unsigned int status;
1199 unsigned int chan = CR_CHAN(insn->chanspec);
1200 int i;
1201
1202 for (i = 0; i < insn->n; i++)
1203 data[i] = devpriv->caldac[chan];
1204 1176
1205 return insn->n; 1177 /* make sure there isn't already a write in progress */
1178 status = labpc_eeprom_read_status(dev);
1179 if ((status & 0x1) == 0)
1180 return 0;
1181 return -EBUSY;
1206} 1182}
1207 1183
1208static int labpc_eeprom_insn_write(struct comedi_device *dev, 1184static int labpc_eeprom_insn_write(struct comedi_device *dev,
@@ -1222,25 +1198,15 @@ static int labpc_eeprom_insn_write(struct comedi_device *dev,
1222 * data would be overwritten anyway. 1198 * data would be overwritten anyway.
1223 */ 1199 */
1224 if (insn->n > 0) { 1200 if (insn->n > 0) {
1225 ret = labpc_eeprom_write(dev, chan, data[insn->n - 1]); 1201 unsigned int val = data[insn->n - 1];
1202
1203 ret = comedi_timeout(dev, s, insn, labpc_eeprom_ready, 0);
1226 if (ret) 1204 if (ret)
1227 return ret; 1205 return ret;
1228 }
1229
1230 return insn->n;
1231}
1232
1233static int labpc_eeprom_insn_read(struct comedi_device *dev,
1234 struct comedi_subdevice *s,
1235 struct comedi_insn *insn,
1236 unsigned int *data)
1237{
1238 struct labpc_private *devpriv = dev->private;
1239 unsigned int chan = CR_CHAN(insn->chanspec);
1240 int i;
1241 1206
1242 for (i = 0; i < insn->n; i++) 1207 labpc_eeprom_write(dev, chan, val);
1243 data[i] = devpriv->eeprom_data[chan]; 1208 s->readback[chan] = val;
1209 }
1244 1210
1245 return insn->n; 1211 return insn->n;
1246} 1212}
@@ -1309,19 +1275,15 @@ int labpc_common_attach(struct comedi_device *dev,
1309 s->n_chan = NUM_AO_CHAN; 1275 s->n_chan = NUM_AO_CHAN;
1310 s->maxdata = 0x0fff; 1276 s->maxdata = 0x0fff;
1311 s->range_table = &range_labpc_ao; 1277 s->range_table = &range_labpc_ao;
1312 s->insn_read = labpc_ao_insn_read;
1313 s->insn_write = labpc_ao_insn_write; 1278 s->insn_write = labpc_ao_insn_write;
1314 1279
1315 /* initialize analog outputs to a known value */ 1280 ret = comedi_alloc_subdev_readback(s);
1316 for (i = 0; i < s->n_chan; i++) { 1281 if (ret)
1317 short lsb, msb; 1282 return ret;
1318 1283
1319 devpriv->ao_value[i] = s->maxdata / 2; 1284 /* initialize analog outputs to a known value */
1320 lsb = devpriv->ao_value[i] & 0xff; 1285 for (i = 0; i < s->n_chan; i++)
1321 msb = (devpriv->ao_value[i] >> 8) & 0xff; 1286 labpc_ao_write(dev, s, i, s->maxdata / 2);
1322 devpriv->write_byte(dev, lsb, DAC_LSB_REG(i));
1323 devpriv->write_byte(dev, msb, DAC_MSB_REG(i));
1324 }
1325 } else { 1287 } else {
1326 s->type = COMEDI_SUBD_UNUSED; 1288 s->type = COMEDI_SUBD_UNUSED;
1327 } 1289 }
@@ -1342,11 +1304,16 @@ int labpc_common_attach(struct comedi_device *dev,
1342 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; 1304 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
1343 s->n_chan = 16; 1305 s->n_chan = 16;
1344 s->maxdata = 0xff; 1306 s->maxdata = 0xff;
1345 s->insn_read = labpc_calib_insn_read;
1346 s->insn_write = labpc_calib_insn_write; 1307 s->insn_write = labpc_calib_insn_write;
1347 1308
1348 for (i = 0; i < s->n_chan; i++) 1309 ret = comedi_alloc_subdev_readback(s);
1310 if (ret)
1311 return ret;
1312
1313 for (i = 0; i < s->n_chan; i++) {
1349 write_caldac(dev, i, s->maxdata / 2); 1314 write_caldac(dev, i, s->maxdata / 2);
1315 s->readback[i] = s->maxdata / 2;
1316 }
1350 } else { 1317 } else {
1351 s->type = COMEDI_SUBD_UNUSED; 1318 s->type = COMEDI_SUBD_UNUSED;
1352 } 1319 }
@@ -1358,11 +1325,14 @@ int labpc_common_attach(struct comedi_device *dev,
1358 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL; 1325 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
1359 s->n_chan = EEPROM_SIZE; 1326 s->n_chan = EEPROM_SIZE;
1360 s->maxdata = 0xff; 1327 s->maxdata = 0xff;
1361 s->insn_read = labpc_eeprom_insn_read;
1362 s->insn_write = labpc_eeprom_insn_write; 1328 s->insn_write = labpc_eeprom_insn_write;
1363 1329
1330 ret = comedi_alloc_subdev_readback(s);
1331 if (ret)
1332 return ret;
1333
1364 for (i = 0; i < s->n_chan; i++) 1334 for (i = 0; i < s->n_chan; i++)
1365 devpriv->eeprom_data[i] = labpc_eeprom_read(dev, i); 1335 s->readback[i] = labpc_eeprom_read(dev, i);
1366 } else { 1336 } else {
1367 s->type = COMEDI_SUBD_UNUSED; 1337 s->type = COMEDI_SUBD_UNUSED;
1368 } 1338 }
diff --git a/drivers/staging/comedi/drivers/ni_labpc_isadma.c b/drivers/staging/comedi/drivers/ni_labpc_isadma.c
index 967202e0635e..6d386050e59d 100644
--- a/drivers/staging/comedi/drivers/ni_labpc_isadma.c
+++ b/drivers/staging/comedi/drivers/ni_labpc_isadma.c
@@ -91,7 +91,6 @@ void labpc_drain_dma(struct comedi_device *dev)
91 int status; 91 int status;
92 unsigned long flags; 92 unsigned long flags;
93 unsigned int max_points, num_points, residue, leftover; 93 unsigned int max_points, num_points, residue, leftover;
94 int i;
95 94
96 status = devpriv->stat1; 95 status = devpriv->stat1;
97 96
@@ -122,9 +121,7 @@ void labpc_drain_dma(struct comedi_device *dev)
122 leftover = max_points; 121 leftover = max_points;
123 } 122 }
124 123
125 /* write data to comedi buffer */ 124 comedi_buf_write_samples(s, devpriv->dma_buffer, num_points);
126 for (i = 0; i < num_points; i++)
127 cfc_write_to_buffer(s, devpriv->dma_buffer[i]);
128 125
129 if (cmd->stop_src == TRIG_COUNT) 126 if (cmd->stop_src == TRIG_COUNT)
130 devpriv->count -= num_points; 127 devpriv->count -= num_points;
@@ -133,8 +130,6 @@ void labpc_drain_dma(struct comedi_device *dev)
133 set_dma_addr(devpriv->dma_chan, devpriv->dma_addr); 130 set_dma_addr(devpriv->dma_chan, devpriv->dma_addr);
134 set_dma_count(devpriv->dma_chan, leftover * sample_size); 131 set_dma_count(devpriv->dma_chan, leftover * sample_size);
135 release_dma_lock(flags); 132 release_dma_lock(flags);
136
137 async->events |= COMEDI_CB_BLOCK;
138} 133}
139EXPORT_SYMBOL_GPL(labpc_drain_dma); 134EXPORT_SYMBOL_GPL(labpc_drain_dma);
140 135
diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c b/drivers/staging/comedi/drivers/ni_mio_common.c
index 320b080149b6..11e70173712d 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -686,13 +686,12 @@ static inline void ni_set_ai_dma_channel(struct comedi_device *dev, int channel)
686{ 686{
687 unsigned bitfield; 687 unsigned bitfield;
688 688
689 if (channel >= 0) { 689 if (channel >= 0)
690 bitfield = 690 bitfield =
691 (ni_stc_dma_channel_select_bitfield(channel) << 691 (ni_stc_dma_channel_select_bitfield(channel) <<
692 AI_DMA_Select_Shift) & AI_DMA_Select_Mask; 692 AI_DMA_Select_Shift) & AI_DMA_Select_Mask;
693 } else { 693 else
694 bitfield = 0; 694 bitfield = 0;
695 }
696 ni_set_bitfield(dev, AI_AO_Select, AI_DMA_Select_Mask, bitfield); 695 ni_set_bitfield(dev, AI_AO_Select, AI_DMA_Select_Mask, bitfield);
697} 696}
698 697
@@ -701,13 +700,12 @@ static inline void ni_set_ao_dma_channel(struct comedi_device *dev, int channel)
701{ 700{
702 unsigned bitfield; 701 unsigned bitfield;
703 702
704 if (channel >= 0) { 703 if (channel >= 0)
705 bitfield = 704 bitfield =
706 (ni_stc_dma_channel_select_bitfield(channel) << 705 (ni_stc_dma_channel_select_bitfield(channel) <<
707 AO_DMA_Select_Shift) & AO_DMA_Select_Mask; 706 AO_DMA_Select_Shift) & AO_DMA_Select_Mask;
708 } else { 707 else
709 bitfield = 0; 708 bitfield = 0;
710 }
711 ni_set_bitfield(dev, AI_AO_Select, AO_DMA_Select_Mask, bitfield); 709 ni_set_bitfield(dev, AI_AO_Select, AO_DMA_Select_Mask, bitfield);
712} 710}
713 711
@@ -1127,31 +1125,18 @@ static void ni_ao_fifo_load(struct comedi_device *dev,
1127 struct comedi_subdevice *s, int n) 1125 struct comedi_subdevice *s, int n)
1128{ 1126{
1129 struct ni_private *devpriv = dev->private; 1127 struct ni_private *devpriv = dev->private;
1130 struct comedi_async *async = s->async;
1131 struct comedi_cmd *cmd = &async->cmd;
1132 int chan;
1133 int i; 1128 int i;
1134 unsigned short d; 1129 unsigned short d;
1135 u32 packed_data; 1130 u32 packed_data;
1136 int range;
1137 int err = 1;
1138 1131
1139 chan = async->cur_chan;
1140 for (i = 0; i < n; i++) { 1132 for (i = 0; i < n; i++) {
1141 err &= comedi_buf_get(s, &d); 1133 comedi_buf_read_samples(s, &d, 1);
1142 if (err == 0)
1143 break;
1144
1145 range = CR_RANGE(cmd->chanlist[chan]);
1146 1134
1147 if (devpriv->is_6xxx) { 1135 if (devpriv->is_6xxx) {
1148 packed_data = d & 0xffff; 1136 packed_data = d & 0xffff;
1149 /* 6711 only has 16 bit wide ao fifo */ 1137 /* 6711 only has 16 bit wide ao fifo */
1150 if (!devpriv->is_6711) { 1138 if (!devpriv->is_6711) {
1151 err &= comedi_buf_get(s, &d); 1139 comedi_buf_read_samples(s, &d, 1);
1152 if (err == 0)
1153 break;
1154 chan++;
1155 i++; 1140 i++;
1156 packed_data |= (d << 16) & 0xffff0000; 1141 packed_data |= (d << 16) & 0xffff0000;
1157 } 1142 }
@@ -1159,12 +1144,7 @@ static void ni_ao_fifo_load(struct comedi_device *dev,
1159 } else { 1144 } else {
1160 ni_writew(dev, d, DAC_FIFO_Data); 1145 ni_writew(dev, d, DAC_FIFO_Data);
1161 } 1146 }
1162 chan++;
1163 chan %= cmd->chanlist_len;
1164 } 1147 }
1165 async->cur_chan = chan;
1166 if (err == 0)
1167 async->events |= COMEDI_CB_OVERFLOW;
1168} 1148}
1169 1149
1170/* 1150/*
@@ -1187,21 +1167,20 @@ static int ni_ao_fifo_half_empty(struct comedi_device *dev,
1187 struct comedi_subdevice *s) 1167 struct comedi_subdevice *s)
1188{ 1168{
1189 const struct ni_board_struct *board = dev->board_ptr; 1169 const struct ni_board_struct *board = dev->board_ptr;
1190 int n; 1170 unsigned int nbytes;
1171 unsigned int nsamples;
1191 1172
1192 n = comedi_buf_read_n_available(s); 1173 nbytes = comedi_buf_read_n_available(s);
1193 if (n == 0) { 1174 if (nbytes == 0) {
1194 s->async->events |= COMEDI_CB_OVERFLOW; 1175 s->async->events |= COMEDI_CB_OVERFLOW;
1195 return 0; 1176 return 0;
1196 } 1177 }
1197 1178
1198 n /= sizeof(short); 1179 nsamples = comedi_bytes_to_samples(s, nbytes);
1199 if (n > board->ao_fifo_depth / 2) 1180 if (nsamples > board->ao_fifo_depth / 2)
1200 n = board->ao_fifo_depth / 2; 1181 nsamples = board->ao_fifo_depth / 2;
1201
1202 ni_ao_fifo_load(dev, s, n);
1203 1182
1204 s->async->events |= COMEDI_CB_BLOCK; 1183 ni_ao_fifo_load(dev, s, nsamples);
1205 1184
1206 return 1; 1185 return 1;
1207} 1186}
@@ -1211,7 +1190,8 @@ static int ni_ao_prep_fifo(struct comedi_device *dev,
1211{ 1190{
1212 const struct ni_board_struct *board = dev->board_ptr; 1191 const struct ni_board_struct *board = dev->board_ptr;
1213 struct ni_private *devpriv = dev->private; 1192 struct ni_private *devpriv = dev->private;
1214 int n; 1193 unsigned int nbytes;
1194 unsigned int nsamples;
1215 1195
1216 /* reset fifo */ 1196 /* reset fifo */
1217 ni_stc_writew(dev, 1, DAC_FIFO_Clear); 1197 ni_stc_writew(dev, 1, DAC_FIFO_Clear);
@@ -1219,17 +1199,17 @@ static int ni_ao_prep_fifo(struct comedi_device *dev,
1219 ni_ao_win_outl(dev, 0x6, AO_FIFO_Offset_Load_611x); 1199 ni_ao_win_outl(dev, 0x6, AO_FIFO_Offset_Load_611x);
1220 1200
1221 /* load some data */ 1201 /* load some data */
1222 n = comedi_buf_read_n_available(s); 1202 nbytes = comedi_buf_read_n_available(s);
1223 if (n == 0) 1203 if (nbytes == 0)
1224 return 0; 1204 return 0;
1225 1205
1226 n /= sizeof(short); 1206 nsamples = comedi_bytes_to_samples(s, nbytes);
1227 if (n > board->ao_fifo_depth) 1207 if (nsamples > board->ao_fifo_depth)
1228 n = board->ao_fifo_depth; 1208 nsamples = board->ao_fifo_depth;
1229 1209
1230 ni_ao_fifo_load(dev, s, n); 1210 ni_ao_fifo_load(dev, s, nsamples);
1231 1211
1232 return n; 1212 return nsamples;
1233} 1213}
1234 1214
1235static void ni_ai_fifo_read(struct comedi_device *dev, 1215static void ni_ai_fifo_read(struct comedi_device *dev,
@@ -1237,44 +1217,42 @@ static void ni_ai_fifo_read(struct comedi_device *dev,
1237{ 1217{
1238 struct ni_private *devpriv = dev->private; 1218 struct ni_private *devpriv = dev->private;
1239 struct comedi_async *async = s->async; 1219 struct comedi_async *async = s->async;
1220 u32 dl;
1221 unsigned short data;
1240 int i; 1222 int i;
1241 1223
1242 if (devpriv->is_611x) { 1224 if (devpriv->is_611x) {
1243 unsigned short data[2];
1244 u32 dl;
1245
1246 for (i = 0; i < n / 2; i++) { 1225 for (i = 0; i < n / 2; i++) {
1247 dl = ni_readl(dev, ADC_FIFO_Data_611x); 1226 dl = ni_readl(dev, ADC_FIFO_Data_611x);
1248 /* This may get the hi/lo data in the wrong order */ 1227 /* This may get the hi/lo data in the wrong order */
1249 data[0] = (dl >> 16) & 0xffff; 1228 data = (dl >> 16) & 0xffff;
1250 data[1] = dl & 0xffff; 1229 comedi_buf_write_samples(s, &data, 1);
1251 cfc_write_array_to_buffer(s, data, sizeof(data)); 1230 data = dl & 0xffff;
1231 comedi_buf_write_samples(s, &data, 1);
1252 } 1232 }
1253 /* Check if there's a single sample stuck in the FIFO */ 1233 /* Check if there's a single sample stuck in the FIFO */
1254 if (n % 2) { 1234 if (n % 2) {
1255 dl = ni_readl(dev, ADC_FIFO_Data_611x); 1235 dl = ni_readl(dev, ADC_FIFO_Data_611x);
1256 data[0] = dl & 0xffff; 1236 data = dl & 0xffff;
1257 cfc_write_to_buffer(s, data[0]); 1237 comedi_buf_write_samples(s, &data, 1);
1258 } 1238 }
1259 } else if (devpriv->is_6143) { 1239 } else if (devpriv->is_6143) {
1260 unsigned short data[2];
1261 u32 dl;
1262
1263 /* This just reads the FIFO assuming the data is present, no checks on the FIFO status are performed */ 1240 /* This just reads the FIFO assuming the data is present, no checks on the FIFO status are performed */
1264 for (i = 0; i < n / 2; i++) { 1241 for (i = 0; i < n / 2; i++) {
1265 dl = ni_readl(dev, AIFIFO_Data_6143); 1242 dl = ni_readl(dev, AIFIFO_Data_6143);
1266 1243
1267 data[0] = (dl >> 16) & 0xffff; 1244 data = (dl >> 16) & 0xffff;
1268 data[1] = dl & 0xffff; 1245 comedi_buf_write_samples(s, &data, 1);
1269 cfc_write_array_to_buffer(s, data, sizeof(data)); 1246 data = dl & 0xffff;
1247 comedi_buf_write_samples(s, &data, 1);
1270 } 1248 }
1271 if (n % 2) { 1249 if (n % 2) {
1272 /* Assume there is a single sample stuck in the FIFO */ 1250 /* Assume there is a single sample stuck in the FIFO */
1273 /* Get stranded sample into FIFO */ 1251 /* Get stranded sample into FIFO */
1274 ni_writel(dev, 0x01, AIFIFO_Control_6143); 1252 ni_writel(dev, 0x01, AIFIFO_Control_6143);
1275 dl = ni_readl(dev, AIFIFO_Data_6143); 1253 dl = ni_readl(dev, AIFIFO_Data_6143);
1276 data[0] = (dl >> 16) & 0xffff; 1254 data = (dl >> 16) & 0xffff;
1277 cfc_write_to_buffer(s, data[0]); 1255 comedi_buf_write_samples(s, &data, 1);
1278 } 1256 }
1279 } else { 1257 } else {
1280 if (n > sizeof(devpriv->ai_fifo_buffer) / 1258 if (n > sizeof(devpriv->ai_fifo_buffer) /
@@ -1288,9 +1266,7 @@ static void ni_ai_fifo_read(struct comedi_device *dev,
1288 devpriv->ai_fifo_buffer[i] = 1266 devpriv->ai_fifo_buffer[i] =
1289 ni_readw(dev, ADC_FIFO_Data_Register); 1267 ni_readw(dev, ADC_FIFO_Data_Register);
1290 } 1268 }
1291 cfc_write_array_to_buffer(s, devpriv->ai_fifo_buffer, 1269 comedi_buf_write_samples(s, devpriv->ai_fifo_buffer, n);
1292 n *
1293 sizeof(devpriv->ai_fifo_buffer[0]));
1294 } 1270 }
1295} 1271}
1296 1272
@@ -1313,8 +1289,8 @@ static void ni_handle_fifo_dregs(struct comedi_device *dev)
1313{ 1289{
1314 struct ni_private *devpriv = dev->private; 1290 struct ni_private *devpriv = dev->private;
1315 struct comedi_subdevice *s = dev->read_subdev; 1291 struct comedi_subdevice *s = dev->read_subdev;
1316 unsigned short data[2];
1317 u32 dl; 1292 u32 dl;
1293 unsigned short data;
1318 unsigned short fifo_empty; 1294 unsigned short fifo_empty;
1319 int i; 1295 int i;
1320 1296
@@ -1324,9 +1300,10 @@ static void ni_handle_fifo_dregs(struct comedi_device *dev)
1324 dl = ni_readl(dev, ADC_FIFO_Data_611x); 1300 dl = ni_readl(dev, ADC_FIFO_Data_611x);
1325 1301
1326 /* This may get the hi/lo data in the wrong order */ 1302 /* This may get the hi/lo data in the wrong order */
1327 data[0] = (dl >> 16); 1303 data = dl >> 16;
1328 data[1] = (dl & 0xffff); 1304 comedi_buf_write_samples(s, &data, 1);
1329 cfc_write_array_to_buffer(s, data, sizeof(data)); 1305 data = dl & 0xffff;
1306 comedi_buf_write_samples(s, &data, 1);
1330 } 1307 }
1331 } else if (devpriv->is_6143) { 1308 } else if (devpriv->is_6143) {
1332 i = 0; 1309 i = 0;
@@ -1334,9 +1311,10 @@ static void ni_handle_fifo_dregs(struct comedi_device *dev)
1334 dl = ni_readl(dev, AIFIFO_Data_6143); 1311 dl = ni_readl(dev, AIFIFO_Data_6143);
1335 1312
1336 /* This may get the hi/lo data in the wrong order */ 1313 /* This may get the hi/lo data in the wrong order */
1337 data[0] = (dl >> 16); 1314 data = dl >> 16;
1338 data[1] = (dl & 0xffff); 1315 comedi_buf_write_samples(s, &data, 1);
1339 cfc_write_array_to_buffer(s, data, sizeof(data)); 1316 data = dl & 0xffff;
1317 comedi_buf_write_samples(s, &data, 1);
1340 i += 2; 1318 i += 2;
1341 } 1319 }
1342 /* Check if stranded sample is present */ 1320 /* Check if stranded sample is present */
@@ -1344,8 +1322,8 @@ static void ni_handle_fifo_dregs(struct comedi_device *dev)
1344 /* Get stranded sample into FIFO */ 1322 /* Get stranded sample into FIFO */
1345 ni_writel(dev, 0x01, AIFIFO_Control_6143); 1323 ni_writel(dev, 0x01, AIFIFO_Control_6143);
1346 dl = ni_readl(dev, AIFIFO_Data_6143); 1324 dl = ni_readl(dev, AIFIFO_Data_6143);
1347 data[0] = (dl >> 16) & 0xffff; 1325 data = (dl >> 16) & 0xffff;
1348 cfc_write_to_buffer(s, data[0]); 1326 comedi_buf_write_samples(s, &data, 1);
1349 } 1327 }
1350 1328
1351 } else { 1329 } else {
@@ -1364,10 +1342,7 @@ static void ni_handle_fifo_dregs(struct comedi_device *dev)
1364 devpriv->ai_fifo_buffer[i] = 1342 devpriv->ai_fifo_buffer[i] =
1365 ni_readw(dev, ADC_FIFO_Data_Register); 1343 ni_readw(dev, ADC_FIFO_Data_Register);
1366 } 1344 }
1367 cfc_write_array_to_buffer(s, devpriv->ai_fifo_buffer, 1345 comedi_buf_write_samples(s, devpriv->ai_fifo_buffer, i);
1368 i *
1369 sizeof(devpriv->
1370 ai_fifo_buffer[0]));
1371 } 1346 }
1372 } 1347 }
1373} 1348}
@@ -1386,7 +1361,7 @@ static void get_last_sample_611x(struct comedi_device *dev)
1386 if (ni_readb(dev, XXX_Status) & 0x80) { 1361 if (ni_readb(dev, XXX_Status) & 0x80) {
1387 dl = ni_readl(dev, ADC_FIFO_Data_611x); 1362 dl = ni_readl(dev, ADC_FIFO_Data_611x);
1388 data = (dl & 0xffff); 1363 data = (dl & 0xffff);
1389 cfc_write_to_buffer(s, data); 1364 comedi_buf_write_samples(s, &data, 1);
1390 } 1365 }
1391} 1366}
1392 1367
@@ -1408,7 +1383,7 @@ static void get_last_sample_6143(struct comedi_device *dev)
1408 1383
1409 /* This may get the hi/lo data in the wrong order */ 1384 /* This may get the hi/lo data in the wrong order */
1410 data = (dl >> 16) & 0xffff; 1385 data = (dl >> 16) & 0xffff;
1411 cfc_write_to_buffer(s, data); 1386 comedi_buf_write_samples(s, &data, 1);
1412 } 1387 }
1413} 1388}
1414 1389
@@ -1462,7 +1437,7 @@ static void handle_gpct_interrupt(struct comedi_device *dev,
1462 1437
1463 ni_tio_handle_interrupt(&devpriv->counter_dev->counters[counter_index], 1438 ni_tio_handle_interrupt(&devpriv->counter_dev->counters[counter_index],
1464 s); 1439 s);
1465 cfc_handle_events(dev, s); 1440 comedi_handle_events(dev, s);
1466#endif 1441#endif
1467} 1442}
1468 1443
@@ -1518,7 +1493,7 @@ static void handle_a_interrupt(struct comedi_device *dev, unsigned short status,
1518 if (comedi_is_subdevice_running(s)) { 1493 if (comedi_is_subdevice_running(s)) {
1519 s->async->events |= 1494 s->async->events |=
1520 COMEDI_CB_ERROR | COMEDI_CB_EOA; 1495 COMEDI_CB_ERROR | COMEDI_CB_EOA;
1521 cfc_handle_events(dev, s); 1496 comedi_handle_events(dev, s);
1522 } 1497 }
1523 return; 1498 return;
1524 } 1499 }
@@ -1533,7 +1508,7 @@ static void handle_a_interrupt(struct comedi_device *dev, unsigned short status,
1533 if (status & (AI_Overrun_St | AI_Overflow_St)) 1508 if (status & (AI_Overrun_St | AI_Overflow_St))
1534 s->async->events |= COMEDI_CB_OVERFLOW; 1509 s->async->events |= COMEDI_CB_OVERFLOW;
1535 1510
1536 cfc_handle_events(dev, s); 1511 comedi_handle_events(dev, s);
1537 return; 1512 return;
1538 } 1513 }
1539 if (status & AI_SC_TC_St) { 1514 if (status & AI_SC_TC_St) {
@@ -1559,7 +1534,7 @@ static void handle_a_interrupt(struct comedi_device *dev, unsigned short status,
1559 if ((status & AI_STOP_St)) 1534 if ((status & AI_STOP_St))
1560 ni_handle_eos(dev, s); 1535 ni_handle_eos(dev, s);
1561 1536
1562 cfc_handle_events(dev, s); 1537 comedi_handle_events(dev, s);
1563} 1538}
1564 1539
1565static void ack_b_interrupt(struct comedi_device *dev, unsigned short b_status) 1540static void ack_b_interrupt(struct comedi_device *dev, unsigned short b_status)
@@ -1635,7 +1610,7 @@ static void handle_b_interrupt(struct comedi_device *dev,
1635 } 1610 }
1636#endif 1611#endif
1637 1612
1638 cfc_handle_events(dev, s); 1613 comedi_handle_events(dev, s);
1639} 1614}
1640 1615
1641static void ni_ai_munge(struct comedi_device *dev, struct comedi_subdevice *s, 1616static void ni_ai_munge(struct comedi_device *dev, struct comedi_subdevice *s,
@@ -1645,12 +1620,12 @@ static void ni_ai_munge(struct comedi_device *dev, struct comedi_subdevice *s,
1645 struct ni_private *devpriv = dev->private; 1620 struct ni_private *devpriv = dev->private;
1646 struct comedi_async *async = s->async; 1621 struct comedi_async *async = s->async;
1647 struct comedi_cmd *cmd = &async->cmd; 1622 struct comedi_cmd *cmd = &async->cmd;
1648 unsigned int length = num_bytes / bytes_per_sample(s); 1623 unsigned int nsamples = comedi_bytes_to_samples(s, num_bytes);
1649 unsigned short *array = data; 1624 unsigned short *array = data;
1650 unsigned int *larray = data; 1625 unsigned int *larray = data;
1651 unsigned int i; 1626 unsigned int i;
1652 1627
1653 for (i = 0; i < length; i++) { 1628 for (i = 0; i < nsamples; i++) {
1654#ifdef PCIDMA 1629#ifdef PCIDMA
1655 if (s->subdev_flags & SDF_LSAMPL) 1630 if (s->subdev_flags & SDF_LSAMPL)
1656 larray[i] = le32_to_cpu(larray[i]); 1631 larray[i] = le32_to_cpu(larray[i]);
@@ -2253,9 +2228,6 @@ static int ni_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
2253 2228
2254 /* Step 1 : check if triggers are trivially valid */ 2229 /* Step 1 : check if triggers are trivially valid */
2255 2230
2256 if ((cmd->flags & CMDF_WRITE))
2257 cmd->flags &= ~CMDF_WRITE;
2258
2259 err |= cfc_check_trigger_src(&cmd->start_src, 2231 err |= cfc_check_trigger_src(&cmd->start_src,
2260 TRIG_NOW | TRIG_INT | TRIG_EXT); 2232 TRIG_NOW | TRIG_INT | TRIG_EXT);
2261 err |= cfc_check_trigger_src(&cmd->scan_begin_src, 2233 err |= cfc_check_trigger_src(&cmd->scan_begin_src,
@@ -2762,11 +2734,11 @@ static void ni_ao_munge(struct comedi_device *dev, struct comedi_subdevice *s,
2762 unsigned int chan_index) 2734 unsigned int chan_index)
2763{ 2735{
2764 struct comedi_cmd *cmd = &s->async->cmd; 2736 struct comedi_cmd *cmd = &s->async->cmd;
2765 unsigned int length = num_bytes / bytes_per_sample(s); 2737 unsigned int nsamples = comedi_bytes_to_samples(s, num_bytes);
2766 unsigned short *array = data; 2738 unsigned short *array = data;
2767 unsigned int i; 2739 unsigned int i;
2768 2740
2769 for (i = 0; i < length; i++) { 2741 for (i = 0; i < nsamples; i++) {
2770 unsigned int range = CR_RANGE(cmd->chanlist[chan_index]); 2742 unsigned int range = CR_RANGE(cmd->chanlist[chan_index]);
2771 unsigned short val = array[i]; 2743 unsigned short val = array[i];
2772 2744
@@ -2981,12 +2953,15 @@ static int ni_ao_insn_config(struct comedi_device *dev,
2981{ 2953{
2982 const struct ni_board_struct *board = dev->board_ptr; 2954 const struct ni_board_struct *board = dev->board_ptr;
2983 struct ni_private *devpriv = dev->private; 2955 struct ni_private *devpriv = dev->private;
2956 unsigned int nbytes;
2984 2957
2985 switch (data[0]) { 2958 switch (data[0]) {
2986 case INSN_CONFIG_GET_HARDWARE_BUFFER_SIZE: 2959 case INSN_CONFIG_GET_HARDWARE_BUFFER_SIZE:
2987 switch (data[1]) { 2960 switch (data[1]) {
2988 case COMEDI_OUTPUT: 2961 case COMEDI_OUTPUT:
2989 data[2] = 1 + board->ao_fifo_depth * sizeof(short); 2962 nbytes = comedi_samples_to_bytes(s,
2963 board->ao_fifo_depth);
2964 data[2] = 1 + nbytes;
2990 if (devpriv->mite) 2965 if (devpriv->mite)
2991 data[2] += devpriv->mite->fifo_size; 2966 data[2] += devpriv->mite->fifo_size;
2992 break; 2967 break;
@@ -3288,9 +3263,6 @@ static int ni_ao_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
3288 3263
3289 /* Step 1 : check if triggers are trivially valid */ 3264 /* Step 1 : check if triggers are trivially valid */
3290 3265
3291 if ((cmd->flags & CMDF_WRITE) == 0)
3292 cmd->flags |= CMDF_WRITE;
3293
3294 err |= cfc_check_trigger_src(&cmd->start_src, TRIG_INT | TRIG_EXT); 3266 err |= cfc_check_trigger_src(&cmd->start_src, TRIG_INT | TRIG_EXT);
3295 err |= cfc_check_trigger_src(&cmd->scan_begin_src, 3267 err |= cfc_check_trigger_src(&cmd->scan_begin_src,
3296 TRIG_TIMER | TRIG_EXT); 3268 TRIG_TIMER | TRIG_EXT);
@@ -3515,9 +3487,6 @@ static int ni_cdio_cmdtest(struct comedi_device *dev,
3515 /* Step 2a : make sure trigger sources are unique */ 3487 /* Step 2a : make sure trigger sources are unique */
3516 /* Step 2b : and mutually compatible */ 3488 /* Step 2b : and mutually compatible */
3517 3489
3518 if (err)
3519 return 2;
3520
3521 /* Step 3: check if arguments are trivially valid */ 3490 /* Step 3: check if arguments are trivially valid */
3522 3491
3523 err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0); 3492 err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
@@ -3693,7 +3662,7 @@ static void handle_cdio_interrupt(struct comedi_device *dev)
3693 M_Offset_CDIO_Command); 3662 M_Offset_CDIO_Command);
3694 /* s->async->events |= COMEDI_CB_EOA; */ 3663 /* s->async->events |= COMEDI_CB_EOA; */
3695 } 3664 }
3696 cfc_handle_events(dev, s); 3665 comedi_handle_events(dev, s);
3697} 3666}
3698 3667
3699static int ni_serial_hw_readwrite8(struct comedi_device *dev, 3668static int ni_serial_hw_readwrite8(struct comedi_device *dev,
@@ -3976,7 +3945,7 @@ static unsigned ni_gpct_to_stc_register(enum ni_gpct_register reg)
3976 stc_register = Interrupt_B_Enable_Register; 3945 stc_register = Interrupt_B_Enable_Register;
3977 break; 3946 break;
3978 default: 3947 default:
3979 printk("%s: unhandled register 0x%x in switch.\n", 3948 pr_err("%s: unhandled register 0x%x in switch.\n",
3980 __func__, reg); 3949 __func__, reg);
3981 BUG(); 3950 BUG();
3982 return 0; 3951 return 0;
@@ -5472,7 +5441,6 @@ static int ni_E_init(struct comedi_device *dev,
5472 s->range_table = board->ao_range_table; 5441 s->range_table = board->ao_range_table;
5473 s->insn_config = ni_ao_insn_config; 5442 s->insn_config = ni_ao_insn_config;
5474 s->insn_write = ni_ao_insn_write; 5443 s->insn_write = ni_ao_insn_write;
5475 s->insn_read = comedi_readback_insn_read;
5476 5444
5477 ret = comedi_alloc_subdev_readback(s); 5445 ret = comedi_alloc_subdev_readback(s);
5478 if (ret) 5446 if (ret)
diff --git a/drivers/staging/comedi/drivers/ni_pcidio.c b/drivers/staging/comedi/drivers/ni_pcidio.c
index 5252cba82e5e..db7e8aac67b5 100644
--- a/drivers/staging/comedi/drivers/ni_pcidio.c
+++ b/drivers/staging/comedi/drivers/ni_pcidio.c
@@ -384,11 +384,7 @@ static irqreturn_t nidio_interrupt(int irq, void *d)
384 struct comedi_subdevice *s = dev->read_subdev; 384 struct comedi_subdevice *s = dev->read_subdev;
385 struct comedi_async *async = s->async; 385 struct comedi_async *async = s->async;
386 struct mite_struct *mite = devpriv->mite; 386 struct mite_struct *mite = devpriv->mite;
387 387 unsigned int auxdata;
388 /* int i, j; */
389 unsigned int auxdata = 0;
390 unsigned short data1 = 0;
391 unsigned short data2 = 0;
392 int flags; 388 int flags;
393 int status; 389 int status;
394 int work = 0; 390 int work = 0;
@@ -451,13 +447,9 @@ static irqreturn_t nidio_interrupt(int irq, void *d)
451 goto out; 447 goto out;
452 } 448 }
453 auxdata = readl(dev->mmio + Group_1_FIFO); 449 auxdata = readl(dev->mmio + Group_1_FIFO);
454 data1 = auxdata & 0xffff; 450 comedi_buf_write_samples(s, &auxdata, 1);
455 data2 = (auxdata & 0xffff0000) >> 16;
456 comedi_buf_put(s, data1);
457 comedi_buf_put(s, data2);
458 flags = readb(dev->mmio + Group_1_Flags); 451 flags = readb(dev->mmio + Group_1_Flags);
459 } 452 }
460 async->events |= COMEDI_CB_BLOCK;
461 } 453 }
462 454
463 if (flags & CountExpired) { 455 if (flags & CountExpired) {
@@ -485,7 +477,7 @@ static irqreturn_t nidio_interrupt(int irq, void *d)
485 } 477 }
486 478
487out: 479out:
488 cfc_handle_events(dev, s); 480 comedi_handle_events(dev, s);
489#if 0 481#if 0
490 if (!tag) 482 if (!tag)
491 writeb(0x03, dev->mmio + Master_DMA_And_Interrupt_Control); 483 writeb(0x03, dev->mmio + Master_DMA_And_Interrupt_Control);
diff --git a/drivers/staging/comedi/drivers/ni_stc.h b/drivers/staging/comedi/drivers/ni_stc.h
index 29efce30eb7f..bd69c3f0acdc 100644
--- a/drivers/staging/comedi/drivers/ni_stc.h
+++ b/drivers/staging/comedi/drivers/ni_stc.h
@@ -334,7 +334,7 @@ static inline unsigned RTSI_Output_Bit(unsigned channel, int is_mseries)
334 max_channel = 6; 334 max_channel = 6;
335 } 335 }
336 if (channel > max_channel) { 336 if (channel > max_channel) {
337 printk("%s: bug, invalid RTSI_channel=%i\n", __func__, channel); 337 pr_err("%s: bug, invalid RTSI_channel=%i\n", __func__, channel);
338 return 0; 338 return 0;
339 } 339 }
340 return 1 << (base_bit_shift + channel); 340 return 1 << (base_bit_shift + channel);
@@ -1090,7 +1090,7 @@ static inline int M_Offset_Static_AI_Control(int i)
1090 0x263, 1090 0x263,
1091 }; 1091 };
1092 if (((unsigned)i) >= ARRAY_SIZE(offset)) { 1092 if (((unsigned)i) >= ARRAY_SIZE(offset)) {
1093 printk("%s: invalid channel=%i\n", __func__, i); 1093 pr_err("%s: invalid channel=%i\n", __func__, i);
1094 return offset[0]; 1094 return offset[0];
1095 } 1095 }
1096 return offset[i]; 1096 return offset[i];
@@ -1105,7 +1105,7 @@ static inline int M_Offset_AO_Reference_Attenuation(int channel)
1105 0x267 1105 0x267
1106 }; 1106 };
1107 if (((unsigned)channel) >= ARRAY_SIZE(offset)) { 1107 if (((unsigned)channel) >= ARRAY_SIZE(offset)) {
1108 printk("%s: invalid channel=%i\n", __func__, channel); 1108 pr_err("%s: invalid channel=%i\n", __func__, channel);
1109 return offset[0]; 1109 return offset[0];
1110 } 1110 }
1111 return offset[channel]; 1111 return offset[channel];
@@ -1114,7 +1114,7 @@ static inline int M_Offset_AO_Reference_Attenuation(int channel)
1114static inline unsigned M_Offset_PFI_Output_Select(unsigned n) 1114static inline unsigned M_Offset_PFI_Output_Select(unsigned n)
1115{ 1115{
1116 if (n < 1 || n > NUM_PFI_OUTPUT_SELECT_REGS) { 1116 if (n < 1 || n > NUM_PFI_OUTPUT_SELECT_REGS) {
1117 printk("%s: invalid pfi output select register=%i\n", 1117 pr_err("%s: invalid pfi output select register=%i\n",
1118 __func__, n); 1118 __func__, n);
1119 return M_Offset_PFI_Output_Select_1; 1119 return M_Offset_PFI_Output_Select_1;
1120 } 1120 }
@@ -1171,7 +1171,7 @@ static inline unsigned MSeries_PLL_In_Source_Select_RTSI_Bits(unsigned
1171 RTSI_channel) 1171 RTSI_channel)
1172{ 1172{
1173 if (RTSI_channel > 7) { 1173 if (RTSI_channel > 7) {
1174 printk("%s: bug, invalid RTSI_channel=%i\n", __func__, 1174 pr_err("%s: bug, invalid RTSI_channel=%i\n", __func__,
1175 RTSI_channel); 1175 RTSI_channel);
1176 return 0; 1176 return 0;
1177 } 1177 }
@@ -1192,7 +1192,7 @@ static inline unsigned MSeries_PLL_Divisor_Bits(unsigned divisor)
1192{ 1192{
1193 static const unsigned max_divisor = 0x10; 1193 static const unsigned max_divisor = 0x10;
1194 if (divisor < 1 || divisor > max_divisor) { 1194 if (divisor < 1 || divisor > max_divisor) {
1195 printk("%s: bug, invalid divisor=%i\n", __func__, divisor); 1195 pr_err("%s: bug, invalid divisor=%i\n", __func__, divisor);
1196 return 0; 1196 return 0;
1197 } 1197 }
1198 return (divisor & 0xf) << 8; 1198 return (divisor & 0xf) << 8;
@@ -1202,7 +1202,7 @@ static inline unsigned MSeries_PLL_Multiplier_Bits(unsigned multiplier)
1202{ 1202{
1203 static const unsigned max_multiplier = 0x100; 1203 static const unsigned max_multiplier = 0x100;
1204 if (multiplier < 1 || multiplier > max_multiplier) { 1204 if (multiplier < 1 || multiplier > max_multiplier) {
1205 printk("%s: bug, invalid multiplier=%i\n", __func__, 1205 pr_err("%s: bug, invalid multiplier=%i\n", __func__,
1206 multiplier); 1206 multiplier);
1207 return 0; 1207 return 0;
1208 } 1208 }
@@ -1464,7 +1464,7 @@ struct ni_private {
1464 1464
1465 unsigned short ai_fifo_buffer[0x2000]; 1465 unsigned short ai_fifo_buffer[0x2000];
1466 uint8_t eeprom_buffer[M_SERIES_EEPROM_SIZE]; 1466 uint8_t eeprom_buffer[M_SERIES_EEPROM_SIZE];
1467 uint32_t serial_number; 1467 __be32 serial_number;
1468 1468
1469 struct mite_struct *mite; 1469 struct mite_struct *mite;
1470 struct mite_channel *ai_mite_chan; 1470 struct mite_channel *ai_mite_chan;
diff --git a/drivers/staging/comedi/drivers/ni_tiocmd.c b/drivers/staging/comedi/drivers/ni_tiocmd.c
index 26e7291c4a51..6037bec77ef1 100644
--- a/drivers/staging/comedi/drivers/ni_tiocmd.c
+++ b/drivers/staging/comedi/drivers/ni_tiocmd.c
@@ -371,9 +371,8 @@ static void ni_tio_acknowledge_and_confirm(struct ni_gpct *counter,
371 of gate interrupt via dma read/write 371 of gate interrupt via dma read/write
372 and report bogus gate errors */ 372 and report bogus gate errors */
373 if (counter->counter_dev->variant != 373 if (counter->counter_dev->variant !=
374 ni_gpct_variant_660x) { 374 ni_gpct_variant_660x)
375 *gate_error = 1; 375 *gate_error = 1;
376 }
377 } 376 }
378 } 377 }
379 if (gxx_status & GI_TC_ERROR(cidx)) { 378 if (gxx_status & GI_TC_ERROR(cidx)) {
@@ -450,11 +449,10 @@ void ni_tio_handle_interrupt(struct ni_gpct *counter,
450 return; 449 return;
451 } 450 }
452 gpct_mite_status = mite_get_status(counter->mite_chan); 451 gpct_mite_status = mite_get_status(counter->mite_chan);
453 if (gpct_mite_status & CHSR_LINKC) { 452 if (gpct_mite_status & CHSR_LINKC)
454 writel(CHOR_CLRLC, 453 writel(CHOR_CLRLC,
455 counter->mite_chan->mite->mite_io_addr + 454 counter->mite_chan->mite->mite_io_addr +
456 MITE_CHOR(counter->mite_chan->channel)); 455 MITE_CHOR(counter->mite_chan->channel));
457 }
458 mite_sync_input_dma(counter->mite_chan, s); 456 mite_sync_input_dma(counter->mite_chan, s);
459 spin_unlock_irqrestore(&counter->lock, flags); 457 spin_unlock_irqrestore(&counter->lock, flags);
460} 458}
diff --git a/drivers/staging/comedi/drivers/ni_usb6501.c b/drivers/staging/comedi/drivers/ni_usb6501.c
index df7ada8611f4..3b5a1b90366d 100644
--- a/drivers/staging/comedi/drivers/ni_usb6501.c
+++ b/drivers/staging/comedi/drivers/ni_usb6501.c
@@ -561,7 +561,7 @@ static int ni6501_auto_attach(struct comedi_device *dev,
561 /* Counter subdevice */ 561 /* Counter subdevice */
562 s = &dev->subdevices[1]; 562 s = &dev->subdevices[1];
563 s->type = COMEDI_SUBD_COUNTER; 563 s->type = COMEDI_SUBD_COUNTER;
564 s->subdev_flags = SDF_READABLE | SDF_WRITEABLE | SDF_LSAMPL; 564 s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_LSAMPL;
565 s->n_chan = 1; 565 s->n_chan = 1;
566 s->maxdata = 0xffffffff; 566 s->maxdata = 0xffffffff;
567 s->insn_read = ni6501_cnt_insn_read; 567 s->insn_read = ni6501_cnt_insn_read;
diff --git a/drivers/staging/comedi/drivers/pcl711.c b/drivers/staging/comedi/drivers/pcl711.c
index 47f4887108a7..938aebc8e0ea 100644
--- a/drivers/staging/comedi/drivers/pcl711.c
+++ b/drivers/staging/comedi/drivers/pcl711.c
@@ -156,7 +156,6 @@ static const struct pcl711_board boardtypes[] = {
156}; 156};
157 157
158struct pcl711_private { 158struct pcl711_private {
159 unsigned int ntrig;
160 unsigned int divisor1; 159 unsigned int divisor1;
161 unsigned int divisor2; 160 unsigned int divisor2;
162}; 161};
@@ -199,7 +198,6 @@ static int pcl711_ai_cancel(struct comedi_device *dev,
199static irqreturn_t pcl711_interrupt(int irq, void *d) 198static irqreturn_t pcl711_interrupt(int irq, void *d)
200{ 199{
201 struct comedi_device *dev = d; 200 struct comedi_device *dev = d;
202 struct pcl711_private *devpriv = dev->private;
203 struct comedi_subdevice *s = dev->read_subdev; 201 struct comedi_subdevice *s = dev->read_subdev;
204 struct comedi_cmd *cmd = &s->async->cmd; 202 struct comedi_cmd *cmd = &s->async->cmd;
205 unsigned int data; 203 unsigned int data;
@@ -213,16 +211,14 @@ static irqreturn_t pcl711_interrupt(int irq, void *d)
213 211
214 outb(PCL711_INT_STAT_CLR, dev->iobase + PCL711_INT_STAT_REG); 212 outb(PCL711_INT_STAT_CLR, dev->iobase + PCL711_INT_STAT_REG);
215 213
216 if (comedi_buf_put(s, data) == 0) { 214 comedi_buf_write_samples(s, &data, 1);
217 s->async->events |= COMEDI_CB_OVERFLOW | COMEDI_CB_ERROR; 215
218 } else { 216 if (cmd->stop_src == TRIG_COUNT &&
219 s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOS; 217 s->async->scans_done >= cmd->stop_arg)
220 if (cmd->stop_src == TRIG_COUNT && !(--devpriv->ntrig)) { 218 s->async->events |= COMEDI_CB_EOA;
221 pcl711_ai_set_mode(dev, PCL711_MODE_SOFTTRIG); 219
222 s->async->events |= COMEDI_CB_EOA; 220 comedi_handle_events(dev, s);
223 } 221
224 }
225 comedi_event(dev, s);
226 return IRQ_HANDLED; 222 return IRQ_HANDLED;
227} 223}
228 224
@@ -373,14 +369,10 @@ static void pcl711_ai_load_counters(struct comedi_device *dev)
373 369
374static int pcl711_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) 370static int pcl711_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
375{ 371{
376 struct pcl711_private *devpriv = dev->private;
377 struct comedi_cmd *cmd = &s->async->cmd; 372 struct comedi_cmd *cmd = &s->async->cmd;
378 373
379 pcl711_set_changain(dev, s, cmd->chanlist[0]); 374 pcl711_set_changain(dev, s, cmd->chanlist[0]);
380 375
381 if (cmd->stop_src == TRIG_COUNT)
382 devpriv->ntrig = cmd->stop_arg;
383
384 if (cmd->scan_begin_src == TRIG_TIMER) { 376 if (cmd->scan_begin_src == TRIG_TIMER) {
385 pcl711_ai_load_counters(dev); 377 pcl711_ai_load_counters(dev);
386 outb(PCL711_INT_STAT_CLR, dev->iobase + PCL711_INT_STAT_REG); 378 outb(PCL711_INT_STAT_CLR, dev->iobase + PCL711_INT_STAT_REG);
@@ -505,7 +497,6 @@ static int pcl711_attach(struct comedi_device *dev, struct comedi_devconfig *it)
505 s->maxdata = 0xfff; 497 s->maxdata = 0xfff;
506 s->range_table = &range_bipolar5; 498 s->range_table = &range_bipolar5;
507 s->insn_write = pcl711_ao_insn_write; 499 s->insn_write = pcl711_ao_insn_write;
508 s->insn_read = comedi_readback_insn_read;
509 500
510 ret = comedi_alloc_subdev_readback(s); 501 ret = comedi_alloc_subdev_readback(s);
511 if (ret) 502 if (ret)
diff --git a/drivers/staging/comedi/drivers/pcl726.c b/drivers/staging/comedi/drivers/pcl726.c
index dc179bd02dfd..86f713fdf1d0 100644
--- a/drivers/staging/comedi/drivers/pcl726.c
+++ b/drivers/staging/comedi/drivers/pcl726.c
@@ -235,9 +235,8 @@ static irqreturn_t pcl726_interrupt(int irq, void *d)
235 if (devpriv->cmd_running) { 235 if (devpriv->cmd_running) {
236 pcl726_intr_cancel(dev, s); 236 pcl726_intr_cancel(dev, s);
237 237
238 comedi_buf_put(s, 0); 238 comedi_buf_write_samples(s, &s->state, 1);
239 s->async->events |= (COMEDI_CB_BLOCK | COMEDI_CB_EOS); 239 comedi_handle_events(dev, s);
240 comedi_event(dev, s);
241 } 240 }
242 241
243 return IRQ_HANDLED; 242 return IRQ_HANDLED;
@@ -377,7 +376,6 @@ static int pcl726_attach(struct comedi_device *dev,
377 s->maxdata = 0x0fff; 376 s->maxdata = 0x0fff;
378 s->range_table_list = devpriv->rangelist; 377 s->range_table_list = devpriv->rangelist;
379 s->insn_write = pcl726_ao_insn_write; 378 s->insn_write = pcl726_ao_insn_write;
380 s->insn_read = comedi_readback_insn_read;
381 379
382 ret = comedi_alloc_subdev_readback(s); 380 ret = comedi_alloc_subdev_readback(s);
383 if (ret) 381 if (ret)
diff --git a/drivers/staging/comedi/drivers/pcl812.c b/drivers/staging/comedi/drivers/pcl812.c
index fd5ea6e01619..ac243ca5e0f8 100644
--- a/drivers/staging/comedi/drivers/pcl812.c
+++ b/drivers/staging/comedi/drivers/pcl812.c
@@ -512,7 +512,6 @@ struct pcl812_private {
512 unsigned int last_ai_chanspec; 512 unsigned int last_ai_chanspec;
513 unsigned char mode_reg_int; /* there is stored INT number for some card */ 513 unsigned char mode_reg_int; /* there is stored INT number for some card */
514 unsigned int ai_poll_ptr; /* how many sampes transfer poll */ 514 unsigned int ai_poll_ptr; /* how many sampes transfer poll */
515 unsigned int ai_act_scan; /* how many scans we finished */
516 unsigned int dmapages; 515 unsigned int dmapages;
517 unsigned int hwdmasize; 516 unsigned int hwdmasize;
518 unsigned long dmabuf[2]; /* PTR to DMA buf */ 517 unsigned long dmabuf[2]; /* PTR to DMA buf */
@@ -556,8 +555,8 @@ static void pcl812_ai_setup_dma(struct comedi_device *dev,
556 555
557 /* we use EOS, so adapt DMA buffer to one scan */ 556 /* we use EOS, so adapt DMA buffer to one scan */
558 if (devpriv->ai_eos) { 557 if (devpriv->ai_eos) {
559 devpriv->dmabytestomove[0] = cfc_bytes_per_scan(s); 558 devpriv->dmabytestomove[0] = comedi_bytes_per_scan(s);
560 devpriv->dmabytestomove[1] = cfc_bytes_per_scan(s); 559 devpriv->dmabytestomove[1] = comedi_bytes_per_scan(s);
561 devpriv->dma_runs_to_end = 1; 560 devpriv->dma_runs_to_end = 1;
562 } else { 561 } else {
563 devpriv->dmabytestomove[0] = devpriv->hwdmasize; 562 devpriv->dmabytestomove[0] = devpriv->hwdmasize;
@@ -572,7 +571,7 @@ static void pcl812_ai_setup_dma(struct comedi_device *dev,
572 devpriv->dma_runs_to_end = 1; 571 devpriv->dma_runs_to_end = 1;
573 } else { 572 } else {
574 /* how many samples we must transfer? */ 573 /* how many samples we must transfer? */
575 bytes = cmd->stop_arg * cfc_bytes_per_scan(s); 574 bytes = cmd->stop_arg * comedi_bytes_per_scan(s);
576 575
577 /* how many DMA pages we must fill */ 576 /* how many DMA pages we must fill */
578 devpriv->dma_runs_to_end = 577 devpriv->dma_runs_to_end =
@@ -807,9 +806,7 @@ static int pcl812_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
807 devpriv->ai_dma = 0; 806 devpriv->ai_dma = 0;
808 } 807 }
809 808
810 devpriv->ai_act_scan = 0;
811 devpriv->ai_poll_ptr = 0; 809 devpriv->ai_poll_ptr = 0;
812 s->async->cur_chan = 0;
813 810
814 /* don't we want wake up every scan? */ 811 /* don't we want wake up every scan? */
815 if (cmd->flags & CMDF_WAKE_EOS) { 812 if (cmd->flags & CMDF_WAKE_EOS) {
@@ -841,21 +838,10 @@ static int pcl812_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
841static bool pcl812_ai_next_chan(struct comedi_device *dev, 838static bool pcl812_ai_next_chan(struct comedi_device *dev,
842 struct comedi_subdevice *s) 839 struct comedi_subdevice *s)
843{ 840{
844 struct pcl812_private *devpriv = dev->private;
845 struct comedi_cmd *cmd = &s->async->cmd; 841 struct comedi_cmd *cmd = &s->async->cmd;
846 842
847 s->async->events |= COMEDI_CB_BLOCK;
848
849 s->async->cur_chan++;
850 if (s->async->cur_chan >= cmd->chanlist_len) {
851 s->async->cur_chan = 0;
852 devpriv->ai_act_scan++;
853 s->async->events |= COMEDI_CB_EOS;
854 }
855
856 if (cmd->stop_src == TRIG_COUNT && 843 if (cmd->stop_src == TRIG_COUNT &&
857 devpriv->ai_act_scan >= cmd->stop_arg) { 844 s->async->scans_done >= cmd->stop_arg) {
858 /* all data sampled */
859 s->async->events |= COMEDI_CB_EOA; 845 s->async->events |= COMEDI_CB_EOA;
860 return false; 846 return false;
861 } 847 }
@@ -867,7 +853,9 @@ static void pcl812_handle_eoc(struct comedi_device *dev,
867 struct comedi_subdevice *s) 853 struct comedi_subdevice *s)
868{ 854{
869 struct comedi_cmd *cmd = &s->async->cmd; 855 struct comedi_cmd *cmd = &s->async->cmd;
856 unsigned int chan = s->async->cur_chan;
870 unsigned int next_chan; 857 unsigned int next_chan;
858 unsigned short val;
871 859
872 if (pcl812_ai_eoc(dev, s, NULL, 0)) { 860 if (pcl812_ai_eoc(dev, s, NULL, 0)) {
873 dev_dbg(dev->class_dev, "A/D cmd IRQ without DRDY!\n"); 861 dev_dbg(dev->class_dev, "A/D cmd IRQ without DRDY!\n");
@@ -875,13 +863,12 @@ static void pcl812_handle_eoc(struct comedi_device *dev,
875 return; 863 return;
876 } 864 }
877 865
878 comedi_buf_put(s, pcl812_ai_get_sample(dev, s)); 866 val = pcl812_ai_get_sample(dev, s);
867 comedi_buf_write_samples(s, &val, 1);
879 868
880 /* Set up next channel. Added by abbotti 2010-01-20, but untested. */ 869 /* Set up next channel. Added by abbotti 2010-01-20, but untested. */
881 next_chan = s->async->cur_chan + 1; 870 next_chan = s->async->cur_chan;
882 if (next_chan >= cmd->chanlist_len) 871 if (cmd->chanlist[chan] != cmd->chanlist[next_chan])
883 next_chan = 0;
884 if (cmd->chanlist[s->async->cur_chan] != cmd->chanlist[next_chan])
885 pcl812_ai_set_chan_range(dev, cmd->chanlist[next_chan], 0); 872 pcl812_ai_set_chan_range(dev, cmd->chanlist[next_chan], 0);
886 873
887 pcl812_ai_next_chan(dev, s); 874 pcl812_ai_next_chan(dev, s);
@@ -893,9 +880,11 @@ static void transfer_from_dma_buf(struct comedi_device *dev,
893 unsigned int bufptr, unsigned int len) 880 unsigned int bufptr, unsigned int len)
894{ 881{
895 unsigned int i; 882 unsigned int i;
883 unsigned short val;
896 884
897 for (i = len; i; i--) { 885 for (i = len; i; i--) {
898 comedi_buf_put(s, ptr[bufptr++]); 886 val = ptr[bufptr++];
887 comedi_buf_write_samples(s, &val, 1);
899 888
900 if (!pcl812_ai_next_chan(dev, s)) 889 if (!pcl812_ai_next_chan(dev, s))
901 break; 890 break;
@@ -939,7 +928,7 @@ static irqreturn_t pcl812_interrupt(int irq, void *d)
939 928
940 pcl812_ai_clear_eoc(dev); 929 pcl812_ai_clear_eoc(dev);
941 930
942 cfc_handle_events(dev, s); 931 comedi_handle_events(dev, s);
943 return IRQ_HANDLED; 932 return IRQ_HANDLED;
944} 933}
945 934
@@ -1335,7 +1324,6 @@ static int pcl812_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1335 break; 1324 break;
1336 } 1325 }
1337 s->insn_write = pcl812_ao_insn_write; 1326 s->insn_write = pcl812_ao_insn_write;
1338 s->insn_read = comedi_readback_insn_read;
1339 1327
1340 ret = comedi_alloc_subdev_readback(s); 1328 ret = comedi_alloc_subdev_readback(s);
1341 if (ret) 1329 if (ret)
diff --git a/drivers/staging/comedi/drivers/pcl816.c b/drivers/staging/comedi/drivers/pcl816.c
index aa6487132017..73deb4bd5c93 100644
--- a/drivers/staging/comedi/drivers/pcl816.c
+++ b/drivers/staging/comedi/drivers/pcl816.c
@@ -122,7 +122,6 @@ struct pcl816_private {
122 int next_dma_buf; /* which DMA buffer will be used next round */ 122 int next_dma_buf; /* which DMA buffer will be used next round */
123 long dma_runs_to_end; /* how many we must permorm DMA transfer to end of record */ 123 long dma_runs_to_end; /* how many we must permorm DMA transfer to end of record */
124 unsigned long last_dma_run; /* how many bytes we must transfer on last DMA page */ 124 unsigned long last_dma_run; /* how many bytes we must transfer on last DMA page */
125 int ai_act_scan; /* how many scans we finished */
126 unsigned int ai_poll_ptr; /* how many sampes transfer poll */ 125 unsigned int ai_poll_ptr; /* how many sampes transfer poll */
127 unsigned int divisor1; 126 unsigned int divisor1;
128 unsigned int divisor2; 127 unsigned int divisor2;
@@ -160,7 +159,7 @@ static void pcl816_ai_setup_dma(struct comedi_device *dev,
160 bytes = devpriv->hwdmasize; 159 bytes = devpriv->hwdmasize;
161 if (cmd->stop_src == TRIG_COUNT) { 160 if (cmd->stop_src == TRIG_COUNT) {
162 /* how many */ 161 /* how many */
163 bytes = cmd->stop_arg * cfc_bytes_per_scan(s); 162 bytes = cmd->stop_arg * comedi_bytes_per_scan(s);
164 163
165 /* how many DMA pages we must fill */ 164 /* how many DMA pages we must fill */
166 devpriv->dma_runs_to_end = bytes / devpriv->hwdmasize; 165 devpriv->dma_runs_to_end = bytes / devpriv->hwdmasize;
@@ -286,21 +285,10 @@ static int pcl816_ai_eoc(struct comedi_device *dev,
286static bool pcl816_ai_next_chan(struct comedi_device *dev, 285static bool pcl816_ai_next_chan(struct comedi_device *dev,
287 struct comedi_subdevice *s) 286 struct comedi_subdevice *s)
288{ 287{
289 struct pcl816_private *devpriv = dev->private;
290 struct comedi_cmd *cmd = &s->async->cmd; 288 struct comedi_cmd *cmd = &s->async->cmd;
291 289
292 s->async->events |= COMEDI_CB_BLOCK;
293
294 s->async->cur_chan++;
295 if (s->async->cur_chan >= cmd->chanlist_len) {
296 s->async->cur_chan = 0;
297 devpriv->ai_act_scan++;
298 s->async->events |= COMEDI_CB_EOS;
299 }
300
301 if (cmd->stop_src == TRIG_COUNT && 290 if (cmd->stop_src == TRIG_COUNT &&
302 devpriv->ai_act_scan >= cmd->stop_arg) { 291 s->async->scans_done >= cmd->stop_arg) {
303 /* all data sampled */
304 s->async->events |= COMEDI_CB_EOA; 292 s->async->events |= COMEDI_CB_EOA;
305 return false; 293 return false;
306 } 294 }
@@ -313,10 +301,12 @@ static void transfer_from_dma_buf(struct comedi_device *dev,
313 unsigned short *ptr, 301 unsigned short *ptr,
314 unsigned int bufptr, unsigned int len) 302 unsigned int bufptr, unsigned int len)
315{ 303{
304 unsigned short val;
316 int i; 305 int i;
317 306
318 for (i = 0; i < len; i++) { 307 for (i = 0; i < len; i++) {
319 comedi_buf_put(s, ptr[bufptr++]); 308 val = ptr[bufptr++];
309 comedi_buf_write_samples(s, &val, 1);
320 310
321 if (!pcl816_ai_next_chan(dev, s)) 311 if (!pcl816_ai_next_chan(dev, s))
322 return; 312 return;
@@ -355,7 +345,7 @@ static irqreturn_t pcl816_interrupt(int irq, void *d)
355 345
356 pcl816_ai_clear_eoc(dev); 346 pcl816_ai_clear_eoc(dev);
357 347
358 cfc_handle_events(dev, s); 348 comedi_handle_events(dev, s);
359 return IRQ_HANDLED; 349 return IRQ_HANDLED;
360} 350}
361 351
@@ -508,8 +498,6 @@ static int pcl816_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
508 pcl816_ai_setup_chanlist(dev, cmd->chanlist, seglen); 498 pcl816_ai_setup_chanlist(dev, cmd->chanlist, seglen);
509 udelay(1); 499 udelay(1);
510 500
511 devpriv->ai_act_scan = 0;
512 s->async->cur_chan = 0;
513 devpriv->ai_cmd_running = 1; 501 devpriv->ai_cmd_running = 1;
514 devpriv->ai_poll_ptr = 0; 502 devpriv->ai_poll_ptr = 0;
515 devpriv->ai_cmd_canceled = 0; 503 devpriv->ai_cmd_canceled = 0;
@@ -566,7 +554,7 @@ static int pcl816_ai_poll(struct comedi_device *dev, struct comedi_subdevice *s)
566 devpriv->ai_poll_ptr = top1; /* new buffer position */ 554 devpriv->ai_poll_ptr = top1; /* new buffer position */
567 spin_unlock_irqrestore(&dev->spinlock, flags); 555 spin_unlock_irqrestore(&dev->spinlock, flags);
568 556
569 cfc_handle_events(dev, s); 557 comedi_handle_events(dev, s);
570 558
571 return comedi_buf_n_bytes_ready(s); 559 return comedi_buf_n_bytes_ready(s);
572} 560}
diff --git a/drivers/staging/comedi/drivers/pcl818.c b/drivers/staging/comedi/drivers/pcl818.c
index ac19e83ce62a..8edea35532a9 100644
--- a/drivers/staging/comedi/drivers/pcl818.c
+++ b/drivers/staging/comedi/drivers/pcl818.c
@@ -313,8 +313,6 @@ struct pcl818_private {
313 unsigned long last_dma_run; /* how many bytes we must transfer on last DMA page */ 313 unsigned long last_dma_run; /* how many bytes we must transfer on last DMA page */
314 unsigned int ns_min; /* manimal allowed delay between samples (in us) for actual card */ 314 unsigned int ns_min; /* manimal allowed delay between samples (in us) for actual card */
315 int i8253_osc_base; /* 1/frequency of on board oscilator in ns */ 315 int i8253_osc_base; /* 1/frequency of on board oscilator in ns */
316 int ai_act_scan; /* how many scans we finished */
317 int ai_act_chan; /* actual position in actual scan */
318 unsigned int act_chanlist[16]; /* MUX setting for actual AI operations */ 316 unsigned int act_chanlist[16]; /* MUX setting for actual AI operations */
319 unsigned int act_chanlist_len; /* how long is actual MUX list */ 317 unsigned int act_chanlist_len; /* how long is actual MUX list */
320 unsigned int act_chanlist_pos; /* actual position in MUX list */ 318 unsigned int act_chanlist_pos; /* actual position in MUX list */
@@ -352,7 +350,7 @@ static void pcl818_ai_setup_dma(struct comedi_device *dev,
352 disable_dma(devpriv->dma); /* disable dma */ 350 disable_dma(devpriv->dma); /* disable dma */
353 bytes = devpriv->hwdmasize; 351 bytes = devpriv->hwdmasize;
354 if (cmd->stop_src == TRIG_COUNT) { 352 if (cmd->stop_src == TRIG_COUNT) {
355 bytes = cmd->stop_arg * cfc_bytes_per_scan(s); 353 bytes = cmd->stop_arg * comedi_bytes_per_scan(s);
356 devpriv->dma_runs_to_end = bytes / devpriv->hwdmasize; 354 devpriv->dma_runs_to_end = bytes / devpriv->hwdmasize;
357 devpriv->last_dma_run = bytes % devpriv->hwdmasize; 355 devpriv->last_dma_run = bytes % devpriv->hwdmasize;
358 devpriv->dma_runs_to_end--; 356 devpriv->dma_runs_to_end--;
@@ -521,21 +519,12 @@ static bool pcl818_ai_next_chan(struct comedi_device *dev,
521 struct pcl818_private *devpriv = dev->private; 519 struct pcl818_private *devpriv = dev->private;
522 struct comedi_cmd *cmd = &s->async->cmd; 520 struct comedi_cmd *cmd = &s->async->cmd;
523 521
524 s->async->events |= COMEDI_CB_BLOCK;
525
526 devpriv->act_chanlist_pos++; 522 devpriv->act_chanlist_pos++;
527 if (devpriv->act_chanlist_pos >= devpriv->act_chanlist_len) 523 if (devpriv->act_chanlist_pos >= devpriv->act_chanlist_len)
528 devpriv->act_chanlist_pos = 0; 524 devpriv->act_chanlist_pos = 0;
529 525
530 s->async->cur_chan++; 526 if (cmd->stop_src == TRIG_COUNT &&
531 if (s->async->cur_chan >= cmd->chanlist_len) { 527 s->async->scans_done >= cmd->stop_arg) {
532 s->async->cur_chan = 0;
533 devpriv->ai_act_scan--;
534 s->async->events |= COMEDI_CB_EOS;
535 }
536
537 if (cmd->stop_src == TRIG_COUNT && devpriv->ai_act_scan == 0) {
538 /* all data sampled */
539 s->async->events |= COMEDI_CB_EOA; 528 s->async->events |= COMEDI_CB_EOA;
540 return false; 529 return false;
541 } 530 }
@@ -560,7 +549,7 @@ static void pcl818_handle_eoc(struct comedi_device *dev,
560 if (pcl818_ai_dropout(dev, s, chan)) 549 if (pcl818_ai_dropout(dev, s, chan))
561 return; 550 return;
562 551
563 comedi_buf_put(s, val); 552 comedi_buf_write_samples(s, &val, 1);
564 553
565 pcl818_ai_next_chan(dev, s); 554 pcl818_ai_next_chan(dev, s);
566} 555}
@@ -589,7 +578,7 @@ static void pcl818_handle_dma(struct comedi_device *dev,
589 if (pcl818_ai_dropout(dev, s, chan)) 578 if (pcl818_ai_dropout(dev, s, chan))
590 break; 579 break;
591 580
592 comedi_buf_put(s, val); 581 comedi_buf_write_samples(s, &val, 1);
593 582
594 if (!pcl818_ai_next_chan(dev, s)) 583 if (!pcl818_ai_next_chan(dev, s))
595 break; 584 break;
@@ -630,7 +619,7 @@ static void pcl818_handle_fifo(struct comedi_device *dev,
630 if (pcl818_ai_dropout(dev, s, chan)) 619 if (pcl818_ai_dropout(dev, s, chan))
631 break; 620 break;
632 621
633 comedi_buf_put(s, val); 622 comedi_buf_write_samples(s, &val, 1);
634 623
635 if (!pcl818_ai_next_chan(dev, s)) 624 if (!pcl818_ai_next_chan(dev, s))
636 break; 625 break;
@@ -642,6 +631,7 @@ static irqreturn_t pcl818_interrupt(int irq, void *d)
642 struct comedi_device *dev = d; 631 struct comedi_device *dev = d;
643 struct pcl818_private *devpriv = dev->private; 632 struct pcl818_private *devpriv = dev->private;
644 struct comedi_subdevice *s = dev->read_subdev; 633 struct comedi_subdevice *s = dev->read_subdev;
634 struct comedi_cmd *cmd = &s->async->cmd;
645 635
646 if (!dev->attached || !devpriv->ai_cmd_running) { 636 if (!dev->attached || !devpriv->ai_cmd_running) {
647 pcl818_ai_clear_eoc(dev); 637 pcl818_ai_clear_eoc(dev);
@@ -655,7 +645,7 @@ static irqreturn_t pcl818_interrupt(int irq, void *d)
655 * being reprogrammed while a DMA transfer is in 645 * being reprogrammed while a DMA transfer is in
656 * progress. 646 * progress.
657 */ 647 */
658 devpriv->ai_act_scan = 0; 648 s->async->scans_done = cmd->stop_arg;
659 s->cancel(dev, s); 649 s->cancel(dev, s);
660 return IRQ_HANDLED; 650 return IRQ_HANDLED;
661 } 651 }
@@ -669,7 +659,7 @@ static irqreturn_t pcl818_interrupt(int irq, void *d)
669 659
670 pcl818_ai_clear_eoc(dev); 660 pcl818_ai_clear_eoc(dev);
671 661
672 cfc_handle_events(dev, s); 662 comedi_handle_events(dev, s);
673 return IRQ_HANDLED; 663 return IRQ_HANDLED;
674} 664}
675 665
@@ -829,8 +819,6 @@ static int pcl818_ai_cmd(struct comedi_device *dev,
829 pcl818_ai_setup_chanlist(dev, cmd->chanlist, seglen); 819 pcl818_ai_setup_chanlist(dev, cmd->chanlist, seglen);
830 820
831 devpriv->ai_data_len = s->async->prealloc_bufsz; 821 devpriv->ai_data_len = s->async->prealloc_bufsz;
832 devpriv->ai_act_scan = cmd->stop_arg;
833 devpriv->ai_act_chan = 0;
834 devpriv->ai_cmd_running = 1; 822 devpriv->ai_cmd_running = 1;
835 devpriv->ai_cmd_canceled = 0; 823 devpriv->ai_cmd_canceled = 0;
836 devpriv->act_chanlist_pos = 0; 824 devpriv->act_chanlist_pos = 0;
@@ -873,7 +861,8 @@ static int pcl818_ai_cancel(struct comedi_device *dev,
873 861
874 if (devpriv->dma) { 862 if (devpriv->dma) {
875 if (cmd->stop_src == TRIG_NONE || 863 if (cmd->stop_src == TRIG_NONE ||
876 (cmd->stop_src == TRIG_COUNT && devpriv->ai_act_scan > 0)) { 864 (cmd->stop_src == TRIG_COUNT &&
865 s->async->scans_done < cmd->stop_arg)) {
877 if (!devpriv->ai_cmd_canceled) { 866 if (!devpriv->ai_cmd_canceled) {
878 /* 867 /*
879 * Wait for running dma transfer to end, 868 * Wait for running dma transfer to end,
@@ -1169,7 +1158,6 @@ static int pcl818_attach(struct comedi_device *dev, struct comedi_devconfig *it)
1169 s->range_table = &range_unknown; 1158 s->range_table = &range_unknown;
1170 } 1159 }
1171 s->insn_write = pcl818_ao_insn_write; 1160 s->insn_write = pcl818_ao_insn_write;
1172 s->insn_read = comedi_readback_insn_read;
1173 1161
1174 ret = comedi_alloc_subdev_readback(s); 1162 ret = comedi_alloc_subdev_readback(s);
1175 if (ret) 1163 if (ret)
diff --git a/drivers/staging/comedi/drivers/pcmmio.c b/drivers/staging/comedi/drivers/pcmmio.c
index fc40ee2b34e9..f0059e935da0 100644
--- a/drivers/staging/comedi/drivers/pcmmio.c
+++ b/drivers/staging/comedi/drivers/pcmmio.c
@@ -190,7 +190,6 @@ struct pcmmio_private {
190 spinlock_t pagelock; /* protects the page registers */ 190 spinlock_t pagelock; /* protects the page registers */
191 spinlock_t spinlock; /* protects the member variables */ 191 spinlock_t spinlock; /* protects the member variables */
192 unsigned int enabled_mask; 192 unsigned int enabled_mask;
193 unsigned int stop_count;
194 unsigned int active:1; 193 unsigned int active:1;
195}; 194};
196 195
@@ -337,7 +336,6 @@ static void pcmmio_handle_dio_intr(struct comedi_device *dev,
337{ 336{
338 struct pcmmio_private *devpriv = dev->private; 337 struct pcmmio_private *devpriv = dev->private;
339 struct comedi_cmd *cmd = &s->async->cmd; 338 struct comedi_cmd *cmd = &s->async->cmd;
340 unsigned int oldevents = s->async->events;
341 unsigned int val = 0; 339 unsigned int val = 0;
342 unsigned long flags; 340 unsigned long flags;
343 int i; 341 int i;
@@ -357,31 +355,16 @@ static void pcmmio_handle_dio_intr(struct comedi_device *dev,
357 val |= (1 << i); 355 val |= (1 << i);
358 } 356 }
359 357
360 /* Write the scan to the buffer. */ 358 comedi_buf_write_samples(s, &val, 1);
361 if (comedi_buf_put(s, val) &&
362 comedi_buf_put(s, val >> 16)) {
363 s->async->events |= (COMEDI_CB_BLOCK | COMEDI_CB_EOS);
364 } else {
365 /* Overflow! Stop acquisition!! */
366 /* TODO: STOP_ACQUISITION_CALL_HERE!! */
367 pcmmio_stop_intr(dev, s);
368 }
369 359
370 /* Check for end of acquisition. */ 360 if (cmd->stop_src == TRIG_COUNT &&
371 if (cmd->stop_src == TRIG_COUNT && devpriv->stop_count > 0) { 361 s->async->scans_done >= cmd->stop_arg)
372 devpriv->stop_count--; 362 s->async->events |= COMEDI_CB_EOA;
373 if (devpriv->stop_count == 0) {
374 s->async->events |= COMEDI_CB_EOA;
375 /* TODO: STOP_ACQUISITION_CALL_HERE!! */
376 pcmmio_stop_intr(dev, s);
377 }
378 }
379 363
380done: 364done:
381 spin_unlock_irqrestore(&devpriv->spinlock, flags); 365 spin_unlock_irqrestore(&devpriv->spinlock, flags);
382 366
383 if (oldevents != s->async->events) 367 comedi_handle_events(dev, s);
384 comedi_event(dev, s);
385} 368}
386 369
387static irqreturn_t interrupt_pcmmio(int irq, void *d) 370static irqreturn_t interrupt_pcmmio(int irq, void *d)
@@ -481,8 +464,6 @@ static int pcmmio_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
481 spin_lock_irqsave(&devpriv->spinlock, flags); 464 spin_lock_irqsave(&devpriv->spinlock, flags);
482 devpriv->active = 1; 465 devpriv->active = 1;
483 466
484 devpriv->stop_count = cmd->stop_arg;
485
486 /* Set up start of acquisition. */ 467 /* Set up start of acquisition. */
487 if (cmd->start_src == TRIG_INT) 468 if (cmd->start_src == TRIG_INT)
488 s->async->inttrig = pcmmio_inttrig_start_intr; 469 s->async->inttrig = pcmmio_inttrig_start_intr;
@@ -751,7 +732,6 @@ static int pcmmio_attach(struct comedi_device *dev, struct comedi_devconfig *it)
751 s->maxdata = 0xffff; 732 s->maxdata = 0xffff;
752 s->range_table = &pcmmio_ao_ranges; 733 s->range_table = &pcmmio_ao_ranges;
753 s->insn_write = pcmmio_ao_insn_write; 734 s->insn_write = pcmmio_ao_insn_write;
754 s->insn_read = comedi_readback_insn_read;
755 735
756 ret = comedi_alloc_subdev_readback(s); 736 ret = comedi_alloc_subdev_readback(s);
757 if (ret) 737 if (ret)
@@ -774,7 +754,7 @@ static int pcmmio_attach(struct comedi_device *dev, struct comedi_devconfig *it)
774 s->insn_config = pcmmio_dio_insn_config; 754 s->insn_config = pcmmio_dio_insn_config;
775 if (dev->irq) { 755 if (dev->irq) {
776 dev->read_subdev = s; 756 dev->read_subdev = s;
777 s->subdev_flags |= SDF_CMD_READ; 757 s->subdev_flags |= SDF_CMD_READ | SDF_LSAMPL | SDF_PACKED;
778 s->len_chanlist = s->n_chan; 758 s->len_chanlist = s->n_chan;
779 s->cancel = pcmmio_cancel; 759 s->cancel = pcmmio_cancel;
780 s->do_cmd = pcmmio_cmd; 760 s->do_cmd = pcmmio_cmd;
diff --git a/drivers/staging/comedi/drivers/pcmuio.c b/drivers/staging/comedi/drivers/pcmuio.c
index d4fe2ec25ecf..0f5483b6147f 100644
--- a/drivers/staging/comedi/drivers/pcmuio.c
+++ b/drivers/staging/comedi/drivers/pcmuio.c
@@ -130,7 +130,6 @@ struct pcmuio_asic {
130 spinlock_t pagelock; /* protects the page registers */ 130 spinlock_t pagelock; /* protects the page registers */
131 spinlock_t spinlock; /* protects member variables */ 131 spinlock_t spinlock; /* protects member variables */
132 unsigned int enabled_mask; 132 unsigned int enabled_mask;
133 unsigned int stop_count;
134 unsigned int active:1; 133 unsigned int active:1;
135}; 134};
136 135
@@ -317,7 +316,6 @@ static void pcmuio_handle_intr_subdev(struct comedi_device *dev,
317 int asic = pcmuio_subdevice_to_asic(s); 316 int asic = pcmuio_subdevice_to_asic(s);
318 struct pcmuio_asic *chip = &devpriv->asics[asic]; 317 struct pcmuio_asic *chip = &devpriv->asics[asic];
319 struct comedi_cmd *cmd = &s->async->cmd; 318 struct comedi_cmd *cmd = &s->async->cmd;
320 unsigned oldevents = s->async->events;
321 unsigned int val = 0; 319 unsigned int val = 0;
322 unsigned long flags; 320 unsigned long flags;
323 unsigned int i; 321 unsigned int i;
@@ -337,33 +335,16 @@ static void pcmuio_handle_intr_subdev(struct comedi_device *dev,
337 val |= (1 << i); 335 val |= (1 << i);
338 } 336 }
339 337
340 /* Write the scan to the buffer. */ 338 comedi_buf_write_samples(s, &val, 1);
341 if (comedi_buf_put(s, val) &&
342 comedi_buf_put(s, val >> 16)) {
343 s->async->events |= (COMEDI_CB_BLOCK | COMEDI_CB_EOS);
344 } else {
345 /* Overflow! Stop acquisition!! */
346 /* TODO: STOP_ACQUISITION_CALL_HERE!! */
347 pcmuio_stop_intr(dev, s);
348 }
349 339
350 /* Check for end of acquisition. */ 340 if (cmd->stop_src == TRIG_COUNT &&
351 if (cmd->stop_src == TRIG_COUNT) { 341 s->async->scans_done >= cmd->stop_arg)
352 if (chip->stop_count > 0) { 342 s->async->events |= COMEDI_CB_EOA;
353 chip->stop_count--;
354 if (chip->stop_count == 0) {
355 s->async->events |= COMEDI_CB_EOA;
356 /* TODO: STOP_ACQUISITION_CALL_HERE!! */
357 pcmuio_stop_intr(dev, s);
358 }
359 }
360 }
361 343
362done: 344done:
363 spin_unlock_irqrestore(&chip->spinlock, flags); 345 spin_unlock_irqrestore(&chip->spinlock, flags);
364 346
365 if (oldevents != s->async->events) 347 comedi_handle_events(dev, s);
366 comedi_event(dev, s);
367} 348}
368 349
369static int pcmuio_handle_asic_interrupt(struct comedi_device *dev, int asic) 350static int pcmuio_handle_asic_interrupt(struct comedi_device *dev, int asic)
@@ -487,8 +468,6 @@ static int pcmuio_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
487 spin_lock_irqsave(&chip->spinlock, flags); 468 spin_lock_irqsave(&chip->spinlock, flags);
488 chip->active = 1; 469 chip->active = 1;
489 470
490 chip->stop_count = cmd->stop_arg;
491
492 /* Set up start of acquisition. */ 471 /* Set up start of acquisition. */
493 if (cmd->start_src == TRIG_INT) 472 if (cmd->start_src == TRIG_INT)
494 s->async->inttrig = pcmuio_inttrig_start_intr; 473 s->async->inttrig = pcmuio_inttrig_start_intr;
@@ -614,7 +593,8 @@ static int pcmuio_attach(struct comedi_device *dev, struct comedi_devconfig *it)
614 if ((i == 0 && dev->irq) || (i == 2 && devpriv->irq2)) { 593 if ((i == 0 && dev->irq) || (i == 2 && devpriv->irq2)) {
615 /* setup the interrupt subdevice */ 594 /* setup the interrupt subdevice */
616 dev->read_subdev = s; 595 dev->read_subdev = s;
617 s->subdev_flags |= SDF_CMD_READ; 596 s->subdev_flags |= SDF_CMD_READ | SDF_LSAMPL |
597 SDF_PACKED;
618 s->len_chanlist = s->n_chan; 598 s->len_chanlist = s->n_chan;
619 s->cancel = pcmuio_cancel; 599 s->cancel = pcmuio_cancel;
620 s->do_cmd = pcmuio_cmd; 600 s->do_cmd = pcmuio_cmd;
diff --git a/drivers/staging/comedi/drivers/quatech_daqp_cs.c b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
index 6407df0404f0..96098110b0b3 100644
--- a/drivers/staging/comedi/drivers/quatech_daqp_cs.c
+++ b/drivers/staging/comedi/drivers/quatech_daqp_cs.c
@@ -65,8 +65,6 @@ struct daqp_private {
65 enum { semaphore, buffer } interrupt_mode; 65 enum { semaphore, buffer } interrupt_mode;
66 66
67 struct completion eos; 67 struct completion eos;
68
69 int count;
70}; 68};
71 69
72/* The DAQP communicates with the system through a 16 byte I/O window. */ 70/* The DAQP communicates with the system through a 16 byte I/O window. */
@@ -194,6 +192,7 @@ static enum irqreturn daqp_interrupt(int irq, void *dev_id)
194 struct comedi_device *dev = dev_id; 192 struct comedi_device *dev = dev_id;
195 struct daqp_private *devpriv = dev->private; 193 struct daqp_private *devpriv = dev->private;
196 struct comedi_subdevice *s = dev->read_subdev; 194 struct comedi_subdevice *s = dev->read_subdev;
195 struct comedi_cmd *cmd = &s->async->cmd;
197 int loop_limit = 10000; 196 int loop_limit = 10000;
198 int status; 197 int status;
199 198
@@ -221,18 +220,16 @@ static enum irqreturn daqp_interrupt(int irq, void *dev_id)
221 data |= inb(dev->iobase + DAQP_FIFO) << 8; 220 data |= inb(dev->iobase + DAQP_FIFO) << 8;
222 data ^= 0x8000; 221 data ^= 0x8000;
223 222
224 comedi_buf_put(s, data); 223 comedi_buf_write_samples(s, &data, 1);
225 224
226 /* If there's a limit, decrement it 225 /* If there's a limit, decrement it
227 * and stop conversion if zero 226 * and stop conversion if zero
228 */ 227 */
229 228
230 if (devpriv->count > 0) { 229 if (cmd->stop_src == TRIG_COUNT &&
231 devpriv->count--; 230 s->async->scans_done >= cmd->stop_arg) {
232 if (devpriv->count == 0) { 231 s->async->events |= COMEDI_CB_EOA;
233 s->async->events |= COMEDI_CB_EOA; 232 break;
234 break;
235 }
236 } 233 }
237 234
238 if ((loop_limit--) <= 0) 235 if ((loop_limit--) <= 0)
@@ -245,9 +242,7 @@ static enum irqreturn daqp_interrupt(int irq, void *dev_id)
245 s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR; 242 s->async->events |= COMEDI_CB_EOA | COMEDI_CB_ERROR;
246 } 243 }
247 244
248 s->async->events |= COMEDI_CB_BLOCK; 245 comedi_handle_events(dev, s);
249
250 cfc_handle_events(dev, s);
251 } 246 }
252 return IRQ_HANDLED; 247 return IRQ_HANDLED;
253} 248}
@@ -575,12 +570,16 @@ static int daqp_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
575 */ 570 */
576 571
577 if (cmd->stop_src == TRIG_COUNT) { 572 if (cmd->stop_src == TRIG_COUNT) {
578 devpriv->count = cmd->stop_arg * cmd->scan_end_arg; 573 unsigned long long nsamples;
579 threshold = 2 * devpriv->count; 574 unsigned long long nbytes;
580 while (threshold > DAQP_FIFO_SIZE * 3 / 4) 575
581 threshold /= 2; 576 nsamples = (unsigned long long)cmd->stop_arg *
577 cmd->scan_end_arg;
578 nbytes = nsamples * comedi_bytes_per_sample(s);
579 while (nbytes > DAQP_FIFO_SIZE * 3 / 4)
580 nbytes /= 2;
581 threshold = nbytes;
582 } else { 582 } else {
583 devpriv->count = -1;
584 threshold = DAQP_FIFO_SIZE / 2; 583 threshold = DAQP_FIFO_SIZE / 2;
585 } 584 }
586 585
@@ -736,12 +735,11 @@ static int daqp_auto_attach(struct comedi_device *dev,
736 735
737 s = &dev->subdevices[1]; 736 s = &dev->subdevices[1];
738 s->type = COMEDI_SUBD_AO; 737 s->type = COMEDI_SUBD_AO;
739 s->subdev_flags = SDF_WRITEABLE; 738 s->subdev_flags = SDF_WRITABLE;
740 s->n_chan = 2; 739 s->n_chan = 2;
741 s->maxdata = 0x0fff; 740 s->maxdata = 0x0fff;
742 s->range_table = &range_bipolar5; 741 s->range_table = &range_bipolar5;
743 s->insn_write = daqp_ao_insn_write; 742 s->insn_write = daqp_ao_insn_write;
744 s->insn_read = comedi_readback_insn_read;
745 743
746 ret = comedi_alloc_subdev_readback(s); 744 ret = comedi_alloc_subdev_readback(s);
747 if (ret) 745 if (ret)
@@ -756,7 +754,7 @@ static int daqp_auto_attach(struct comedi_device *dev,
756 754
757 s = &dev->subdevices[3]; 755 s = &dev->subdevices[3];
758 s->type = COMEDI_SUBD_DO; 756 s->type = COMEDI_SUBD_DO;
759 s->subdev_flags = SDF_WRITEABLE; 757 s->subdev_flags = SDF_WRITABLE;
760 s->n_chan = 1; 758 s->n_chan = 1;
761 s->maxdata = 1; 759 s->maxdata = 1;
762 s->insn_bits = daqp_do_insn_bits; 760 s->insn_bits = daqp_do_insn_bits;
diff --git a/drivers/staging/comedi/drivers/rtd520.c b/drivers/staging/comedi/drivers/rtd520.c
index 7d4cb140959c..581aa58d9c0a 100644
--- a/drivers/staging/comedi/drivers/rtd520.c
+++ b/drivers/staging/comedi/drivers/rtd520.c
@@ -379,7 +379,6 @@ struct rtd_private {
379 long ai_count; /* total transfer size (samples) */ 379 long ai_count; /* total transfer size (samples) */
380 int xfer_count; /* # to transfer data. 0->1/2FIFO */ 380 int xfer_count; /* # to transfer data. 0->1/2FIFO */
381 int flags; /* flag event modes */ 381 int flags; /* flag event modes */
382 DECLARE_BITMAP(chan_is_bipolar, RTD_MAX_CHANLIST);
383 unsigned fifosz; 382 unsigned fifosz;
384}; 383};
385 384
@@ -438,7 +437,6 @@ static unsigned short rtd_convert_chan_gain(struct comedi_device *dev,
438 unsigned int chanspec, int index) 437 unsigned int chanspec, int index)
439{ 438{
440 const struct rtd_boardinfo *board = dev->board_ptr; 439 const struct rtd_boardinfo *board = dev->board_ptr;
441 struct rtd_private *devpriv = dev->private;
442 unsigned int chan = CR_CHAN(chanspec); 440 unsigned int chan = CR_CHAN(chanspec);
443 unsigned int range = CR_RANGE(chanspec); 441 unsigned int range = CR_RANGE(chanspec);
444 unsigned int aref = CR_AREF(chanspec); 442 unsigned int aref = CR_AREF(chanspec);
@@ -451,17 +449,14 @@ static unsigned short rtd_convert_chan_gain(struct comedi_device *dev,
451 /* +-5 range */ 449 /* +-5 range */
452 r |= 0x000; 450 r |= 0x000;
453 r |= (range & 0x7) << 4; 451 r |= (range & 0x7) << 4;
454 __set_bit(index, devpriv->chan_is_bipolar);
455 } else if (range < board->range_uni10) { 452 } else if (range < board->range_uni10) {
456 /* +-10 range */ 453 /* +-10 range */
457 r |= 0x100; 454 r |= 0x100;
458 r |= ((range - board->range_bip10) & 0x7) << 4; 455 r |= ((range - board->range_bip10) & 0x7) << 4;
459 __set_bit(index, devpriv->chan_is_bipolar);
460 } else { 456 } else {
461 /* +10 range */ 457 /* +10 range */
462 r |= 0x200; 458 r |= 0x200;
463 r |= ((range - board->range_uni10) & 0x7) << 4; 459 r |= ((range - board->range_uni10) & 0x7) << 4;
464 __clear_bit(index, devpriv->chan_is_bipolar);
465 } 460 }
466 461
467 switch (aref) { 462 switch (aref) {
@@ -561,6 +556,7 @@ static int rtd_ai_rinsn(struct comedi_device *dev,
561 unsigned int *data) 556 unsigned int *data)
562{ 557{
563 struct rtd_private *devpriv = dev->private; 558 struct rtd_private *devpriv = dev->private;
559 unsigned int range = CR_RANGE(insn->chanspec);
564 int ret; 560 int ret;
565 int n; 561 int n;
566 562
@@ -586,9 +582,11 @@ static int rtd_ai_rinsn(struct comedi_device *dev,
586 /* read data */ 582 /* read data */
587 d = readw(devpriv->las1 + LAS1_ADC_FIFO); 583 d = readw(devpriv->las1 + LAS1_ADC_FIFO);
588 d = d >> 3; /* low 3 bits are marker lines */ 584 d = d >> 3; /* low 3 bits are marker lines */
589 if (test_bit(0, devpriv->chan_is_bipolar)) 585
590 /* convert to comedi unsigned data */ 586 /* convert bipolar data to comedi unsigned data */
587 if (comedi_range_is_bipolar(s, range))
591 d = comedi_offset_munge(s, d); 588 d = comedi_offset_munge(s, d);
589
592 data[n] = d & s->maxdata; 590 data[n] = d & s->maxdata;
593 } 591 }
594 592
@@ -606,9 +604,12 @@ static int ai_read_n(struct comedi_device *dev, struct comedi_subdevice *s,
606 int count) 604 int count)
607{ 605{
608 struct rtd_private *devpriv = dev->private; 606 struct rtd_private *devpriv = dev->private;
607 struct comedi_async *async = s->async;
608 struct comedi_cmd *cmd = &async->cmd;
609 int ii; 609 int ii;
610 610
611 for (ii = 0; ii < count; ii++) { 611 for (ii = 0; ii < count; ii++) {
612 unsigned int range = CR_RANGE(cmd->chanlist[async->cur_chan]);
612 unsigned short d; 613 unsigned short d;
613 614
614 if (0 == devpriv->ai_count) { /* done */ 615 if (0 == devpriv->ai_count) { /* done */
@@ -618,41 +619,13 @@ static int ai_read_n(struct comedi_device *dev, struct comedi_subdevice *s,
618 619
619 d = readw(devpriv->las1 + LAS1_ADC_FIFO); 620 d = readw(devpriv->las1 + LAS1_ADC_FIFO);
620 d = d >> 3; /* low 3 bits are marker lines */ 621 d = d >> 3; /* low 3 bits are marker lines */
621 if (test_bit(s->async->cur_chan, devpriv->chan_is_bipolar))
622 /* convert to comedi unsigned data */
623 d = comedi_offset_munge(s, d);
624 d &= s->maxdata;
625
626 if (!comedi_buf_put(s, d))
627 return -1;
628
629 if (devpriv->ai_count > 0) /* < 0, means read forever */
630 devpriv->ai_count--;
631 }
632 return 0;
633}
634
635/*
636 unknown amout of data is waiting in fifo.
637*/
638static int ai_read_dregs(struct comedi_device *dev, struct comedi_subdevice *s)
639{
640 struct rtd_private *devpriv = dev->private;
641
642 while (readl(dev->mmio + LAS0_ADC) & FS_ADC_NOT_EMPTY) {
643 unsigned short d = readw(devpriv->las1 + LAS1_ADC_FIFO);
644
645 if (0 == devpriv->ai_count) { /* done */
646 continue; /* read rest */
647 }
648 622
649 d = d >> 3; /* low 3 bits are marker lines */ 623 /* convert bipolar data to comedi unsigned data */
650 if (test_bit(s->async->cur_chan, devpriv->chan_is_bipolar)) 624 if (comedi_range_is_bipolar(s, range))
651 /* convert to comedi unsigned data */
652 d = comedi_offset_munge(s, d); 625 d = comedi_offset_munge(s, d);
653 d &= s->maxdata; 626 d &= s->maxdata;
654 627
655 if (!comedi_buf_put(s, d)) 628 if (!comedi_buf_write_samples(s, &d, 1))
656 return -1; 629 return -1;
657 630
658 if (devpriv->ai_count > 0) /* < 0, means read forever */ 631 if (devpriv->ai_count > 0) /* < 0, means read forever */
@@ -703,8 +676,6 @@ static irqreturn_t rtd_interrupt(int irq, void *d)
703 676
704 if (0 == devpriv->ai_count) 677 if (0 == devpriv->ai_count)
705 goto xfer_done; 678 goto xfer_done;
706
707 comedi_event(dev, s);
708 } else if (devpriv->xfer_count > 0) { 679 } else if (devpriv->xfer_count > 0) {
709 if (fifo_status & FS_ADC_NOT_EMPTY) { 680 if (fifo_status & FS_ADC_NOT_EMPTY) {
710 /* FIFO not empty */ 681 /* FIFO not empty */
@@ -713,8 +684,6 @@ static irqreturn_t rtd_interrupt(int irq, void *d)
713 684
714 if (0 == devpriv->ai_count) 685 if (0 == devpriv->ai_count)
715 goto xfer_done; 686 goto xfer_done;
716
717 comedi_event(dev, s);
718 } 687 }
719 } 688 }
720 } 689 }
@@ -726,28 +695,16 @@ static irqreturn_t rtd_interrupt(int irq, void *d)
726 /* clear the interrupt */ 695 /* clear the interrupt */
727 writew(status, dev->mmio + LAS0_CLEAR); 696 writew(status, dev->mmio + LAS0_CLEAR);
728 readw(dev->mmio + LAS0_CLEAR); 697 readw(dev->mmio + LAS0_CLEAR);
698
699 comedi_handle_events(dev, s);
700
729 return IRQ_HANDLED; 701 return IRQ_HANDLED;
730 702
731xfer_abort: 703xfer_abort:
732 writel(0, dev->mmio + LAS0_ADC_FIFO_CLEAR);
733 s->async->events |= COMEDI_CB_ERROR; 704 s->async->events |= COMEDI_CB_ERROR;
734 devpriv->ai_count = 0; /* stop and don't transfer any more */
735 /* fall into xfer_done */
736 705
737xfer_done: 706xfer_done:
738 /* pacer stop source: SOFTWARE */ 707 s->async->events |= COMEDI_CB_EOA;
739 writel(0, dev->mmio + LAS0_PACER_STOP);
740 writel(0, dev->mmio + LAS0_PACER); /* stop pacer */
741 writel(0, dev->mmio + LAS0_ADC_CONVERSION);
742 writew(0, dev->mmio + LAS0_IT);
743
744 if (devpriv->ai_count > 0) { /* there shouldn't be anything left */
745 fifo_status = readl(dev->mmio + LAS0_ADC);
746 ai_read_dregs(dev, s); /* read anything left in FIFO */
747 }
748
749 s->async->events |= COMEDI_CB_EOA; /* signal end to comedi */
750 comedi_event(dev, s);
751 708
752 /* clear the interrupt */ 709 /* clear the interrupt */
753 status = readw(dev->mmio + LAS0_IT); 710 status = readw(dev->mmio + LAS0_IT);
@@ -757,6 +714,8 @@ xfer_done:
757 fifo_status = readl(dev->mmio + LAS0_ADC); 714 fifo_status = readl(dev->mmio + LAS0_ADC);
758 overrun = readl(dev->mmio + LAS0_OVERRUN) & 0xffff; 715 overrun = readl(dev->mmio + LAS0_OVERRUN) & 0xffff;
759 716
717 comedi_handle_events(dev, s);
718
760 return IRQ_HANDLED; 719 return IRQ_HANDLED;
761} 720}
762 721
@@ -1083,6 +1042,7 @@ static int rtd_ai_cancel(struct comedi_device *dev, struct comedi_subdevice *s)
1083 devpriv->ai_count = 0; /* stop and don't transfer any more */ 1042 devpriv->ai_count = 0; /* stop and don't transfer any more */
1084 status = readw(dev->mmio + LAS0_IT); 1043 status = readw(dev->mmio + LAS0_IT);
1085 overrun = readl(dev->mmio + LAS0_OVERRUN) & 0xffff; 1044 overrun = readl(dev->mmio + LAS0_OVERRUN) & 0xffff;
1045 writel(0, dev->mmio + LAS0_ADC_FIFO_CLEAR);
1086 return 0; 1046 return 0;
1087} 1047}
1088 1048
@@ -1303,7 +1263,6 @@ static int rtd_auto_attach(struct comedi_device *dev,
1303 s->maxdata = 0x0fff; 1263 s->maxdata = 0x0fff;
1304 s->range_table = &rtd_ao_range; 1264 s->range_table = &rtd_ao_range;
1305 s->insn_write = rtd_ao_winsn; 1265 s->insn_write = rtd_ao_winsn;
1306 s->insn_read = comedi_readback_insn_read;
1307 1266
1308 ret = comedi_alloc_subdev_readback(s); 1267 ret = comedi_alloc_subdev_readback(s);
1309 if (ret) 1268 if (ret)
diff --git a/drivers/staging/comedi/drivers/rti800.c b/drivers/staging/comedi/drivers/rti800.c
index e3d9f44cefb9..67b4b378bd01 100644
--- a/drivers/staging/comedi/drivers/rti800.c
+++ b/drivers/staging/comedi/drivers/rti800.c
@@ -313,7 +313,6 @@ static int rti800_attach(struct comedi_device *dev, struct comedi_devconfig *it)
313 ? rti800_ao_ranges[it->options[7]] 313 ? rti800_ao_ranges[it->options[7]]
314 : &range_unknown; 314 : &range_unknown;
315 s->insn_write = rti800_ao_insn_write; 315 s->insn_write = rti800_ao_insn_write;
316 s->insn_read = comedi_readback_insn_read;
317 316
318 ret = comedi_alloc_subdev_readback(s); 317 ret = comedi_alloc_subdev_readback(s);
319 if (ret) 318 if (ret)
diff --git a/drivers/staging/comedi/drivers/rti802.c b/drivers/staging/comedi/drivers/rti802.c
index c81b01c40f12..96c3974207ae 100644
--- a/drivers/staging/comedi/drivers/rti802.c
+++ b/drivers/staging/comedi/drivers/rti802.c
@@ -100,7 +100,6 @@ static int rti802_attach(struct comedi_device *dev, struct comedi_devconfig *it)
100 s->maxdata = 0xfff; 100 s->maxdata = 0xfff;
101 s->n_chan = 8; 101 s->n_chan = 8;
102 s->insn_write = rti802_ao_insn_write; 102 s->insn_write = rti802_ao_insn_write;
103 s->insn_read = comedi_readback_insn_read;
104 103
105 ret = comedi_alloc_subdev_readback(s); 104 ret = comedi_alloc_subdev_readback(s);
106 if (ret) 105 if (ret)
diff --git a/drivers/staging/comedi/drivers/s526.c b/drivers/staging/comedi/drivers/s526.c
index 75872c6aec2a..6f3e8a08e75c 100644
--- a/drivers/staging/comedi/drivers/s526.c
+++ b/drivers/staging/comedi/drivers/s526.c
@@ -583,7 +583,6 @@ static int s526_attach(struct comedi_device *dev, struct comedi_devconfig *it)
583 s->maxdata = 0xffff; 583 s->maxdata = 0xffff;
584 s->range_table = &range_bipolar10; 584 s->range_table = &range_bipolar10;
585 s->insn_write = s526_ao_insn_write; 585 s->insn_write = s526_ao_insn_write;
586 s->insn_read = comedi_readback_insn_read;
587 586
588 ret = comedi_alloc_subdev_readback(s); 587 ret = comedi_alloc_subdev_readback(s);
589 if (ret) 588 if (ret)
diff --git a/drivers/staging/comedi/drivers/s626.c b/drivers/staging/comedi/drivers/s626.c
index 0e7621e890c3..14932c5f3798 100644
--- a/drivers/staging/comedi/drivers/s626.c
+++ b/drivers/staging/comedi/drivers/s626.c
@@ -78,7 +78,6 @@ struct s626_buffer_dma {
78 78
79struct s626_private { 79struct s626_private {
80 uint8_t ai_cmd_running; /* ai_cmd is running */ 80 uint8_t ai_cmd_running; /* ai_cmd is running */
81 int ai_sample_count; /* number of samples to acquire */
82 unsigned int ai_sample_timer; /* time between samples in 81 unsigned int ai_sample_timer; /* time between samples in
83 * units of the timer */ 82 * units of the timer */
84 int ai_convert_count; /* conversion counter */ 83 int ai_convert_count; /* conversion counter */
@@ -1480,7 +1479,6 @@ static bool s626_handle_eos_interrupt(struct comedi_device *dev)
1480 * from the final ADC of the previous poll list scan. 1479 * from the final ADC of the previous poll list scan.
1481 */ 1480 */
1482 uint32_t *readaddr = (uint32_t *)devpriv->ana_buf.logical_base + 1; 1481 uint32_t *readaddr = (uint32_t *)devpriv->ana_buf.logical_base + 1;
1483 bool finished = false;
1484 int i; 1482 int i;
1485 1483
1486 /* get the data and hand it over to comedi */ 1484 /* get the data and hand it over to comedi */
@@ -1494,36 +1492,21 @@ static bool s626_handle_eos_interrupt(struct comedi_device *dev)
1494 tempdata = s626_ai_reg_to_uint(*readaddr); 1492 tempdata = s626_ai_reg_to_uint(*readaddr);
1495 readaddr++; 1493 readaddr++;
1496 1494
1497 /* put data into read buffer */ 1495 comedi_buf_write_samples(s, &tempdata, 1);
1498 cfc_write_to_buffer(s, tempdata);
1499 } 1496 }
1500 1497
1501 /* end of scan occurs */ 1498 if (cmd->stop_src == TRIG_COUNT && async->scans_done >= cmd->stop_arg)
1502 async->events |= COMEDI_CB_EOS; 1499 async->events |= COMEDI_CB_EOA;
1503 1500
1504 if (cmd->stop_src == TRIG_COUNT) { 1501 if (async->events & COMEDI_CB_CANCEL_MASK)
1505 devpriv->ai_sample_count--; 1502 devpriv->ai_cmd_running = 0;
1506 if (devpriv->ai_sample_count <= 0) {
1507 devpriv->ai_cmd_running = 0;
1508
1509 /* Stop RPS program */
1510 s626_mc_disable(dev, S626_MC1_ERPS1, S626_P_MC1);
1511
1512 /* send end of acquisition */
1513 async->events |= COMEDI_CB_EOA;
1514
1515 /* disable master interrupt */
1516 finished = true;
1517 }
1518 }
1519 1503
1520 if (devpriv->ai_cmd_running && cmd->scan_begin_src == TRIG_EXT) 1504 if (devpriv->ai_cmd_running && cmd->scan_begin_src == TRIG_EXT)
1521 s626_dio_set_irq(dev, cmd->scan_begin_arg); 1505 s626_dio_set_irq(dev, cmd->scan_begin_arg);
1522 1506
1523 /* tell comedi that data is there */ 1507 comedi_handle_events(dev, s);
1524 comedi_event(dev, s);
1525 1508
1526 return finished; 1509 return !devpriv->ai_cmd_running;
1527} 1510}
1528 1511
1529static irqreturn_t s626_irq_handler(int irq, void *d) 1512static irqreturn_t s626_irq_handler(int irq, void *d)
@@ -1970,13 +1953,13 @@ static int s626_ns_to_timer(unsigned int *nanosec, unsigned int flags)
1970 switch (flags & CMDF_ROUND_MASK) { 1953 switch (flags & CMDF_ROUND_MASK) {
1971 case CMDF_ROUND_NEAREST: 1954 case CMDF_ROUND_NEAREST:
1972 default: 1955 default:
1973 divider = (*nanosec + base / 2) / base; 1956 divider = DIV_ROUND_CLOSEST(*nanosec, base);
1974 break; 1957 break;
1975 case CMDF_ROUND_DOWN: 1958 case CMDF_ROUND_DOWN:
1976 divider = (*nanosec) / base; 1959 divider = (*nanosec) / base;
1977 break; 1960 break;
1978 case CMDF_ROUND_UP: 1961 case CMDF_ROUND_UP:
1979 divider = (*nanosec + base - 1) / base; 1962 divider = DIV_ROUND_UP(*nanosec, base);
1980 break; 1963 break;
1981 } 1964 }
1982 1965
@@ -2102,8 +2085,6 @@ static int s626_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
2102 break; 2085 break;
2103 } 2086 }
2104 2087
2105 devpriv->ai_sample_count = cmd->stop_arg;
2106
2107 s626_reset_adc(dev, ppl); 2088 s626_reset_adc(dev, ppl);
2108 2089
2109 switch (cmd->start_src) { 2090 switch (cmd->start_src) {
@@ -2820,7 +2801,6 @@ static int s626_auto_attach(struct comedi_device *dev,
2820 s->maxdata = 0x3fff; 2801 s->maxdata = 0x3fff;
2821 s->range_table = &range_bipolar10; 2802 s->range_table = &range_bipolar10;
2822 s->insn_write = s626_ao_insn_write; 2803 s->insn_write = s626_ao_insn_write;
2823 s->insn_read = comedi_readback_insn_read;
2824 2804
2825 ret = comedi_alloc_subdev_readback(s); 2805 ret = comedi_alloc_subdev_readback(s);
2826 if (ret) 2806 if (ret)
diff --git a/drivers/staging/comedi/drivers/serial2002.c b/drivers/staging/comedi/drivers/serial2002.c
index 167f82418cb4..71226ee9064e 100644
--- a/drivers/staging/comedi/drivers/serial2002.c
+++ b/drivers/staging/comedi/drivers/serial2002.c
@@ -742,7 +742,7 @@ static int serial2002_attach(struct comedi_device *dev,
742 /* digital output subdevice */ 742 /* digital output subdevice */
743 s = &dev->subdevices[1]; 743 s = &dev->subdevices[1];
744 s->type = COMEDI_SUBD_DO; 744 s->type = COMEDI_SUBD_DO;
745 s->subdev_flags = SDF_WRITEABLE; 745 s->subdev_flags = SDF_WRITABLE;
746 s->n_chan = 0; 746 s->n_chan = 0;
747 s->maxdata = 1; 747 s->maxdata = 1;
748 s->range_table = &range_digital; 748 s->range_table = &range_digital;
@@ -760,7 +760,7 @@ static int serial2002_attach(struct comedi_device *dev,
760 /* analog output subdevice */ 760 /* analog output subdevice */
761 s = &dev->subdevices[3]; 761 s = &dev->subdevices[3];
762 s->type = COMEDI_SUBD_AO; 762 s->type = COMEDI_SUBD_AO;
763 s->subdev_flags = SDF_WRITEABLE; 763 s->subdev_flags = SDF_WRITABLE;
764 s->n_chan = 0; 764 s->n_chan = 0;
765 s->maxdata = 1; 765 s->maxdata = 1;
766 s->range_table = NULL; 766 s->range_table = NULL;
diff --git a/drivers/staging/comedi/drivers/usbdux.c b/drivers/staging/comedi/drivers/usbdux.c
index 5adbfedf780f..4737dbf8e01d 100644
--- a/drivers/staging/comedi/drivers/usbdux.c
+++ b/drivers/staging/comedi/drivers/usbdux.c
@@ -1,37 +1,34 @@
1/* 1/*
2 comedi/drivers/usbdux.c 2 * usbdux.c
3 Copyright (C) 2003-2007 Bernd Porr, Bernd.Porr@f2s.com 3 * Copyright (C) 2003-2014 Bernd Porr, mail@berndporr.me.uk
4 4 *
5 This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 * the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 * (at your option) any later version.
9 9
10 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,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 * GNU General Public License for more details.
14 */ 14 */
15
15/* 16/*
16Driver: usbdux 17 * Driver: usbdux
17Description: University of Stirling USB DAQ & INCITE Technology Limited 18 * Description: University of Stirling USB DAQ & INCITE Technology Limited
18Devices: [ITL] USB-DUX (usbdux.o) 19 * Devices: (ITL) USB-DUX [usbdux]
19Author: Bernd Porr <BerndPorr@f2s.com> 20 * Author: Bernd Porr <mail@berndporr.me.uk>
20Updated: 8 Dec 2008 21 * Updated: 10 Oct 2014
21Status: Stable 22 * Status: Stable
22Configuration options: 23 * Connection scheme for the counter at the digital port:
23 You have to upload firmware with the -i option. The 24 * 0=/CLK0, 1=UP/DOWN0, 2=RESET0, 4=/CLK1, 5=UP/DOWN1, 6=RESET1.
24 firmware is usually installed under /usr/share/usb or 25 * The sampling rate of the counter is approximately 500Hz.
25 /usr/local/share/usb or /lib/firmware. 26 *
26 27 * Note that under USB2.0 the length of the channel list determines
27Connection scheme for the counter at the digital port: 28 * the max sampling rate. If you sample only one channel you get 8kHz
28 0=/CLK0, 1=UP/DOWN0, 2=RESET0, 4=/CLK1, 5=UP/DOWN1, 6=RESET1. 29 * sampling rate. If you sample two channels you get 4kHz and so on.
29 The sampling rate of the counter is approximately 500Hz. 30 */
30 31
31Please note that under USB2.0 the length of the channel list determines
32the max sampling rate. If you sample only one channel you get 8kHz
33sampling rate. If you sample two channels you get 4kHz and so on.
34*/
35/* 32/*
36 * I must give credit here to Chris Baugher who 33 * I must give credit here to Chris Baugher who
37 * wrote the driver for AT-MIO-16d. I used some parts of this 34 * wrote the driver for AT-MIO-16d. I used some parts of this
@@ -205,9 +202,6 @@ struct usbdux_private {
205 unsigned int ao_cmd_running:1; 202 unsigned int ao_cmd_running:1;
206 unsigned int pwm_cmd_running:1; 203 unsigned int pwm_cmd_running:1;
207 204
208 /* number of samples to acquire */
209 int ai_sample_count;
210 int ao_sample_count;
211 /* time between samples in units of the timer */ 205 /* time between samples in units of the timer */
212 unsigned int ai_timer; 206 unsigned int ai_timer;
213 unsigned int ao_timer; 207 unsigned int ao_timer;
@@ -253,128 +247,107 @@ static int usbdux_ai_cancel(struct comedi_device *dev,
253 return 0; 247 return 0;
254} 248}
255 249
256/* analogue IN - interrupt service routine */ 250static void usbduxsub_ai_handle_urb(struct comedi_device *dev,
251 struct comedi_subdevice *s,
252 struct urb *urb)
253{
254 struct usbdux_private *devpriv = dev->private;
255 struct comedi_async *async = s->async;
256 struct comedi_cmd *cmd = &async->cmd;
257 int ret;
258 int i;
259
260 devpriv->ai_counter--;
261 if (devpriv->ai_counter == 0) {
262 devpriv->ai_counter = devpriv->ai_timer;
263
264 /* get the data from the USB bus and hand it over to comedi */
265 for (i = 0; i < cmd->chanlist_len; i++) {
266 unsigned int range = CR_RANGE(cmd->chanlist[i]);
267 uint16_t val = le16_to_cpu(devpriv->in_buf[i]);
268
269 /* bipolar data is two's-complement */
270 if (comedi_range_is_bipolar(s, range))
271 val ^= ((s->maxdata + 1) >> 1);
272
273 /* transfer data */
274 if (!comedi_buf_write_samples(s, &val, 1))
275 return;
276 }
277
278 if (cmd->stop_src == TRIG_COUNT &&
279 async->scans_done >= cmd->stop_arg)
280 async->events |= COMEDI_CB_EOA;
281 }
282
283 /* if command is still running, resubmit urb */
284 if (!(async->events & COMEDI_CB_CANCEL_MASK)) {
285 urb->dev = comedi_to_usb_dev(dev);
286 ret = usb_submit_urb(urb, GFP_ATOMIC);
287 if (ret < 0) {
288 dev_err(dev->class_dev,
289 "urb resubmit failed in int-context! err=%d\n",
290 ret);
291 if (ret == -EL2NSYNC)
292 dev_err(dev->class_dev,
293 "buggy USB host controller or bug in IRQ handler!\n");
294 async->events |= COMEDI_CB_ERROR;
295 }
296 }
297}
298
257static void usbduxsub_ai_isoc_irq(struct urb *urb) 299static void usbduxsub_ai_isoc_irq(struct urb *urb)
258{ 300{
259 struct comedi_device *dev = urb->context; 301 struct comedi_device *dev = urb->context;
260 struct comedi_subdevice *s = dev->read_subdev; 302 struct comedi_subdevice *s = dev->read_subdev;
303 struct comedi_async *async = s->async;
261 struct usbdux_private *devpriv = dev->private; 304 struct usbdux_private *devpriv = dev->private;
262 struct comedi_cmd *cmd = &s->async->cmd;
263 int i, err;
264 305
265 /* first we test if something unusual has just happened */ 306 /* exit if not running a command, do not resubmit urb */
307 if (!devpriv->ai_cmd_running)
308 return;
309
266 switch (urb->status) { 310 switch (urb->status) {
267 case 0: 311 case 0:
268 /* copy the result in the transfer buffer */ 312 /* copy the result in the transfer buffer */
269 memcpy(devpriv->in_buf, urb->transfer_buffer, SIZEINBUF); 313 memcpy(devpriv->in_buf, urb->transfer_buffer, SIZEINBUF);
314 usbduxsub_ai_handle_urb(dev, s, urb);
270 break; 315 break;
316
271 case -EILSEQ: 317 case -EILSEQ:
272 /* error in the ISOchronous data */ 318 /*
273 /* we don't copy the data into the transfer buffer */ 319 * error in the ISOchronous data
274 /* and recycle the last data byte */ 320 * we don't copy the data into the transfer buffer
321 * and recycle the last data byte
322 */
275 dev_dbg(dev->class_dev, "CRC error in ISO IN stream\n"); 323 dev_dbg(dev->class_dev, "CRC error in ISO IN stream\n");
324 usbduxsub_ai_handle_urb(dev, s, urb);
276 break; 325 break;
277 326
278 case -ECONNRESET: 327 case -ECONNRESET:
279 case -ENOENT: 328 case -ENOENT:
280 case -ESHUTDOWN: 329 case -ESHUTDOWN:
281 case -ECONNABORTED: 330 case -ECONNABORTED:
282 /* happens after an unlink command */ 331 /* after an unlink command, unplug, ... etc */
283 if (devpriv->ai_cmd_running) { 332 async->events |= COMEDI_CB_ERROR;
284 s->async->events |= COMEDI_CB_EOA; 333 break;
285 s->async->events |= COMEDI_CB_ERROR;
286 comedi_event(dev, s);
287 /* stop the transfer w/o unlink */
288 usbdux_ai_stop(dev, 0);
289 }
290 return;
291 334
292 default: 335 default:
293 /* a real error on the bus */ 336 /* a real error */
294 /* pass error to comedi if we are really running a command */ 337 dev_err(dev->class_dev,
295 if (devpriv->ai_cmd_running) { 338 "Non-zero urb status received in ai intr context: %d\n",
296 dev_err(dev->class_dev, 339 urb->status);
297 "Non-zero urb status received in ai intr context: %d\n", 340 async->events |= COMEDI_CB_ERROR;
298 urb->status); 341 break;
299 s->async->events |= COMEDI_CB_EOA;
300 s->async->events |= COMEDI_CB_ERROR;
301 comedi_event(dev, s);
302 /* don't do an unlink here */
303 usbdux_ai_stop(dev, 0);
304 }
305 return;
306 } 342 }
307 343
308 /* 344 /*
309 * at this point we are reasonably sure that nothing dodgy has happened 345 * comedi_handle_events() cannot be used in this driver. The (*cancel)
310 * are we running a command? 346 * operation would unlink the urb.
311 */ 347 */
312 if (unlikely(!devpriv->ai_cmd_running)) { 348 if (async->events & COMEDI_CB_CANCEL_MASK)
313 /*
314 * not running a command, do not continue execution if no
315 * asynchronous command is running in particular not resubmit
316 */
317 return;
318 }
319
320 urb->dev = comedi_to_usb_dev(dev);
321
322 /* resubmit the urb */
323 err = usb_submit_urb(urb, GFP_ATOMIC);
324 if (unlikely(err < 0)) {
325 dev_err(dev->class_dev,
326 "urb resubmit failed in int-context! err=%d\n", err);
327 if (err == -EL2NSYNC)
328 dev_err(dev->class_dev,
329 "buggy USB host controller or bug in IRQ handler!\n");
330 s->async->events |= COMEDI_CB_EOA;
331 s->async->events |= COMEDI_CB_ERROR;
332 comedi_event(dev, s);
333 /* don't do an unlink here */
334 usbdux_ai_stop(dev, 0); 349 usbdux_ai_stop(dev, 0);
335 return;
336 }
337
338 devpriv->ai_counter--;
339 if (likely(devpriv->ai_counter > 0))
340 return;
341
342 /* timer zero, transfer measurements to comedi */
343 devpriv->ai_counter = devpriv->ai_timer;
344
345 /* test, if we transmit only a fixed number of samples */
346 if (cmd->stop_src == TRIG_COUNT) {
347 /* not continuous, fixed number of samples */
348 devpriv->ai_sample_count--;
349 /* all samples received? */
350 if (devpriv->ai_sample_count < 0) {
351 /* prevent a resubmit next time */
352 usbdux_ai_stop(dev, 0);
353 /* say comedi that the acquistion is over */
354 s->async->events |= COMEDI_CB_EOA;
355 comedi_event(dev, s);
356 return;
357 }
358 }
359 /* get the data from the USB bus and hand it over to comedi */
360 for (i = 0; i < cmd->chanlist_len; i++) {
361 unsigned int range = CR_RANGE(cmd->chanlist[i]);
362 uint16_t val = le16_to_cpu(devpriv->in_buf[i]);
363
364 /* bipolar data is two's-complement */
365 if (comedi_range_is_bipolar(s, range))
366 val ^= ((s->maxdata + 1) >> 1);
367 350
368 /* transfer data */
369 err = comedi_buf_put(s, val);
370 if (unlikely(err == 0)) {
371 /* buffer overflow */
372 usbdux_ai_stop(dev, 0);
373 return;
374 }
375 }
376 /* tell comedi that data is there */
377 s->async->events |= COMEDI_CB_BLOCK | COMEDI_CB_EOS;
378 comedi_event(dev, s); 351 comedi_event(dev, s);
379} 352}
380 353
@@ -402,71 +375,25 @@ static int usbdux_ao_cancel(struct comedi_device *dev,
402 return 0; 375 return 0;
403} 376}
404 377
405static void usbduxsub_ao_isoc_irq(struct urb *urb) 378static void usbduxsub_ao_handle_urb(struct comedi_device *dev,
379 struct comedi_subdevice *s,
380 struct urb *urb)
406{ 381{
407 struct comedi_device *dev = urb->context;
408 struct comedi_subdevice *s = dev->write_subdev;
409 struct usbdux_private *devpriv = dev->private; 382 struct usbdux_private *devpriv = dev->private;
410 struct comedi_cmd *cmd = &s->async->cmd; 383 struct comedi_async *async = s->async;
384 struct comedi_cmd *cmd = &async->cmd;
411 uint8_t *datap; 385 uint8_t *datap;
412 int ret; 386 int ret;
413 int i; 387 int i;
414 388
415 switch (urb->status) {
416 case 0:
417 /* success */
418 break;
419
420 case -ECONNRESET:
421 case -ENOENT:
422 case -ESHUTDOWN:
423 case -ECONNABORTED:
424 /* after an unlink command, unplug, ... etc */
425 /* no unlink needed here. Already shutting down. */
426 if (devpriv->ao_cmd_running) {
427 s->async->events |= COMEDI_CB_EOA;
428 comedi_event(dev, s);
429 usbdux_ao_stop(dev, 0);
430 }
431 return;
432
433 default:
434 /* a real error */
435 if (devpriv->ao_cmd_running) {
436 dev_err(dev->class_dev,
437 "Non-zero urb status received in ao intr context: %d\n",
438 urb->status);
439 s->async->events |= COMEDI_CB_ERROR;
440 s->async->events |= COMEDI_CB_EOA;
441 comedi_event(dev, s);
442 /* we do an unlink if we are in the high speed mode */
443 usbdux_ao_stop(dev, 0);
444 }
445 return;
446 }
447
448 /* are we actually running? */
449 if (!devpriv->ao_cmd_running)
450 return;
451
452 /* normal operation: executing a command in this subdevice */
453 devpriv->ao_counter--; 389 devpriv->ao_counter--;
454 if ((int)devpriv->ao_counter <= 0) { 390 if (devpriv->ao_counter == 0) {
455 /* timer zero */
456 devpriv->ao_counter = devpriv->ao_timer; 391 devpriv->ao_counter = devpriv->ao_timer;
457 392
458 /* handle non continous acquisition */ 393 if (cmd->stop_src == TRIG_COUNT &&
459 if (cmd->stop_src == TRIG_COUNT) { 394 async->scans_done >= cmd->stop_arg) {
460 /* fixed number of samples */ 395 async->events |= COMEDI_CB_EOA;
461 devpriv->ao_sample_count--; 396 return;
462 if (devpriv->ao_sample_count < 0) {
463 /* all samples transmitted */
464 usbdux_ao_stop(dev, 0);
465 s->async->events |= COMEDI_CB_EOA;
466 comedi_event(dev, s);
467 /* no resubmit of the urb */
468 return;
469 }
470 } 397 }
471 398
472 /* transmit data to the USB bus */ 399 /* transmit data to the USB bus */
@@ -476,26 +403,25 @@ static void usbduxsub_ao_isoc_irq(struct urb *urb)
476 unsigned int chan = CR_CHAN(cmd->chanlist[i]); 403 unsigned int chan = CR_CHAN(cmd->chanlist[i]);
477 unsigned short val; 404 unsigned short val;
478 405
479 ret = comedi_buf_get(s, &val); 406 if (!comedi_buf_read_samples(s, &val, 1)) {
480 if (ret < 0) {
481 dev_err(dev->class_dev, "buffer underflow\n"); 407 dev_err(dev->class_dev, "buffer underflow\n");
482 s->async->events |= (COMEDI_CB_EOA | 408 async->events |= COMEDI_CB_OVERFLOW;
483 COMEDI_CB_OVERFLOW); 409 return;
484 } 410 }
411
485 /* pointer to the DA */ 412 /* pointer to the DA */
486 *datap++ = val & 0xff; 413 *datap++ = val & 0xff;
487 *datap++ = (val >> 8) & 0xff; 414 *datap++ = (val >> 8) & 0xff;
488 *datap++ = chan << 6; 415 *datap++ = chan << 6;
489 s->readback[chan] = val; 416 s->readback[chan] = val;
490
491 s->async->events |= COMEDI_CB_BLOCK;
492 comedi_event(dev, s);
493 } 417 }
494 } 418 }
495 urb->transfer_buffer_length = SIZEOUTBUF; 419
496 urb->dev = comedi_to_usb_dev(dev); 420 /* if command is still running, resubmit urb for BULK transfer */
497 urb->status = 0; 421 if (!(async->events & COMEDI_CB_CANCEL_MASK)) {
498 if (devpriv->ao_cmd_running) { 422 urb->transfer_buffer_length = SIZEOUTBUF;
423 urb->dev = comedi_to_usb_dev(dev);
424 urb->status = 0;
499 if (devpriv->high_speed) 425 if (devpriv->high_speed)
500 urb->interval = 8; /* uframes */ 426 urb->interval = 8; /* uframes */
501 else 427 else
@@ -512,16 +438,54 @@ static void usbduxsub_ao_isoc_irq(struct urb *urb)
512 if (ret == -EL2NSYNC) 438 if (ret == -EL2NSYNC)
513 dev_err(dev->class_dev, 439 dev_err(dev->class_dev,
514 "buggy USB host controller or bug in IRQ handling!\n"); 440 "buggy USB host controller or bug in IRQ handling!\n");
515 441 async->events |= COMEDI_CB_ERROR;
516 s->async->events |= COMEDI_CB_EOA;
517 s->async->events |= COMEDI_CB_ERROR;
518 comedi_event(dev, s);
519 /* don't do an unlink here */
520 usbdux_ao_stop(dev, 0);
521 } 442 }
522 } 443 }
523} 444}
524 445
446static void usbduxsub_ao_isoc_irq(struct urb *urb)
447{
448 struct comedi_device *dev = urb->context;
449 struct comedi_subdevice *s = dev->write_subdev;
450 struct comedi_async *async = s->async;
451 struct usbdux_private *devpriv = dev->private;
452
453 /* exit if not running a command, do not resubmit urb */
454 if (!devpriv->ao_cmd_running)
455 return;
456
457 switch (urb->status) {
458 case 0:
459 usbduxsub_ao_handle_urb(dev, s, urb);
460 break;
461
462 case -ECONNRESET:
463 case -ENOENT:
464 case -ESHUTDOWN:
465 case -ECONNABORTED:
466 /* after an unlink command, unplug, ... etc */
467 async->events |= COMEDI_CB_ERROR;
468 break;
469
470 default:
471 /* a real error */
472 dev_err(dev->class_dev,
473 "Non-zero urb status received in ao intr context: %d\n",
474 urb->status);
475 async->events |= COMEDI_CB_ERROR;
476 break;
477 }
478
479 /*
480 * comedi_handle_events() cannot be used in this driver. The (*cancel)
481 * operation would unlink the urb.
482 */
483 if (async->events & COMEDI_CB_CANCEL_MASK)
484 usbdux_ao_stop(dev, 0);
485
486 comedi_event(dev, s);
487}
488
525static int usbdux_submit_urbs(struct comedi_device *dev, 489static int usbdux_submit_urbs(struct comedi_device *dev,
526 struct urb **urbs, int num_urbs, 490 struct urb **urbs, int num_urbs,
527 int input_urb) 491 int input_urb)
@@ -725,9 +689,6 @@ static int usbdux_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
725 if (devpriv->ai_cmd_running) 689 if (devpriv->ai_cmd_running)
726 goto ai_cmd_exit; 690 goto ai_cmd_exit;
727 691
728 /* set current channel of the running acquisition to zero */
729 s->async->cur_chan = 0;
730
731 devpriv->dux_commands[1] = len; 692 devpriv->dux_commands[1] = len;
732 for (i = 0; i < len; ++i) { 693 for (i = 0; i < len; ++i) {
733 unsigned int chan = CR_CHAN(cmd->chanlist[i]); 694 unsigned int chan = CR_CHAN(cmd->chanlist[i]);
@@ -765,14 +726,6 @@ static int usbdux_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
765 726
766 devpriv->ai_counter = devpriv->ai_timer; 727 devpriv->ai_counter = devpriv->ai_timer;
767 728
768 if (cmd->stop_src == TRIG_COUNT) {
769 /* data arrives as one packet */
770 devpriv->ai_sample_count = cmd->stop_arg;
771 } else {
772 /* continous acquisition */
773 devpriv->ai_sample_count = 0;
774 }
775
776 if (cmd->start_src == TRIG_NOW) { 729 if (cmd->start_src == TRIG_NOW) {
777 /* enable this acquisition operation */ 730 /* enable this acquisition operation */
778 devpriv->ai_cmd_running = 1; 731 devpriv->ai_cmd_running = 1;
@@ -1023,9 +976,6 @@ static int usbdux_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
1023 if (devpriv->ao_cmd_running) 976 if (devpriv->ao_cmd_running)
1024 goto ao_cmd_exit; 977 goto ao_cmd_exit;
1025 978
1026 /* set current channel of the running acquisition to zero */
1027 s->async->cur_chan = 0;
1028
1029 /* we count in steps of 1ms (125us) */ 979 /* we count in steps of 1ms (125us) */
1030 /* 125us mode not used yet */ 980 /* 125us mode not used yet */
1031 if (0) { /* (devpriv->high_speed) */ 981 if (0) { /* (devpriv->high_speed) */
@@ -1044,24 +994,6 @@ static int usbdux_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
1044 994
1045 devpriv->ao_counter = devpriv->ao_timer; 995 devpriv->ao_counter = devpriv->ao_timer;
1046 996
1047 if (cmd->stop_src == TRIG_COUNT) {
1048 /* not continuous */
1049 /* counter */
1050 /* high speed also scans everything at once */
1051 if (0) { /* (devpriv->high_speed) */
1052 devpriv->ao_sample_count = cmd->stop_arg *
1053 cmd->scan_end_arg;
1054 } else {
1055 /* there's no scan as the scan has been */
1056 /* perf inside the FX2 */
1057 /* data arrives as one packet */
1058 devpriv->ao_sample_count = cmd->stop_arg;
1059 }
1060 } else {
1061 /* continous acquisition */
1062 devpriv->ao_sample_count = 0;
1063 }
1064
1065 if (cmd->start_src == TRIG_NOW) { 997 if (cmd->start_src == TRIG_NOW) {
1066 /* enable this acquisition operation */ 998 /* enable this acquisition operation */
1067 devpriv->ao_cmd_running = 1; 999 devpriv->ao_cmd_running = 1;
diff --git a/drivers/staging/comedi/drivers/usbduxfast.c b/drivers/staging/comedi/drivers/usbduxfast.c
index f85818dd5e11..ddc4cb9d5ed4 100644
--- a/drivers/staging/comedi/drivers/usbduxfast.c
+++ b/drivers/staging/comedi/drivers/usbduxfast.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2004 Bernd Porr, Bernd.Porr@f2s.com 2 * Copyright (C) 2004-2014 Bernd Porr, mail@berndporr.me.uk
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
@@ -13,6 +13,15 @@
13 */ 13 */
14 14
15/* 15/*
16 * Driver: usbduxfast
17 * Description: University of Stirling USB DAQ & INCITE Technology Limited
18 * Devices: (ITL) USB-DUX [usbduxfast]
19 * Author: Bernd Porr <mail@berndporr.me.uk>
20 * Updated: 10 Oct 2014
21 * Status: stable
22 */
23
24/*
16 * I must give credit here to Chris Baugher who 25 * I must give credit here to Chris Baugher who
17 * wrote the driver for AT-MIO-16d. I used some parts of this 26 * wrote the driver for AT-MIO-16d. I used some parts of this
18 * driver. I also must give credits to David Brownell 27 * driver. I also must give credits to David Brownell
@@ -152,7 +161,6 @@ struct usbduxfast_private {
152 uint8_t *duxbuf; 161 uint8_t *duxbuf;
153 int8_t *inbuf; 162 int8_t *inbuf;
154 short int ai_cmd_running; /* asynchronous command is running */ 163 short int ai_cmd_running; /* asynchronous command is running */
155 long int ai_sample_count; /* number of samples to acquire */
156 int ignore; /* counter which ignores the first 164 int ignore; /* counter which ignores the first
157 buffers */ 165 buffers */
158 struct semaphore sem; 166 struct semaphore sem;
@@ -227,114 +235,82 @@ static int usbduxfast_ai_cancel(struct comedi_device *dev,
227 return ret; 235 return ret;
228} 236}
229 237
230/* 238static void usbduxfast_ai_handle_urb(struct comedi_device *dev,
231 * analogue IN 239 struct comedi_subdevice *s,
232 * interrupt service routine 240 struct urb *urb)
233 */ 241{
242 struct usbduxfast_private *devpriv = dev->private;
243 struct comedi_async *async = s->async;
244 struct comedi_cmd *cmd = &async->cmd;
245 int ret;
246
247 if (devpriv->ignore) {
248 devpriv->ignore--;
249 } else {
250 unsigned int nsamples;
251
252 nsamples = comedi_bytes_to_samples(s, urb->actual_length);
253 nsamples = comedi_nsamples_left(s, nsamples);
254 comedi_buf_write_samples(s, urb->transfer_buffer, nsamples);
255
256 if (cmd->stop_src == TRIG_COUNT &&
257 async->scans_done >= cmd->stop_arg)
258 async->events |= COMEDI_CB_EOA;
259 }
260
261 /* if command is still running, resubmit urb for BULK transfer */
262 if (!(async->events & COMEDI_CB_CANCEL_MASK)) {
263 urb->dev = comedi_to_usb_dev(dev);
264 urb->status = 0;
265 ret = usb_submit_urb(urb, GFP_ATOMIC);
266 if (ret < 0) {
267 dev_err(dev->class_dev, "urb resubm failed: %d", ret);
268 async->events |= COMEDI_CB_ERROR;
269 }
270 }
271}
272
234static void usbduxfast_ai_interrupt(struct urb *urb) 273static void usbduxfast_ai_interrupt(struct urb *urb)
235{ 274{
236 struct comedi_device *dev = urb->context; 275 struct comedi_device *dev = urb->context;
237 struct comedi_subdevice *s = dev->read_subdev; 276 struct comedi_subdevice *s = dev->read_subdev;
238 struct comedi_async *async = s->async; 277 struct comedi_async *async = s->async;
239 struct comedi_cmd *cmd = &async->cmd;
240 struct usb_device *usb = comedi_to_usb_dev(dev);
241 struct usbduxfast_private *devpriv = dev->private; 278 struct usbduxfast_private *devpriv = dev->private;
242 int n, err;
243 279
244 /* are we running a command? */ 280 /* exit if not running a command, do not resubmit urb */
245 if (unlikely(!devpriv->ai_cmd_running)) { 281 if (!devpriv->ai_cmd_running)
246 /*
247 * not running a command
248 * do not continue execution if no asynchronous command
249 * is running in particular not resubmit
250 */
251 return; 282 return;
252 }
253 283
254 /* first we test if something unusual has just happened */
255 switch (urb->status) { 284 switch (urb->status) {
256 case 0: 285 case 0:
286 usbduxfast_ai_handle_urb(dev, s, urb);
257 break; 287 break;
258 288
259 /*
260 * happens after an unlink command or when the device
261 * is plugged out
262 */
263 case -ECONNRESET: 289 case -ECONNRESET:
264 case -ENOENT: 290 case -ENOENT:
265 case -ESHUTDOWN: 291 case -ESHUTDOWN:
266 case -ECONNABORTED: 292 case -ECONNABORTED:
267 /* tell this comedi */ 293 /* after an unlink command, unplug, ... etc */
268 async->events |= COMEDI_CB_EOA;
269 async->events |= COMEDI_CB_ERROR; 294 async->events |= COMEDI_CB_ERROR;
270 comedi_event(dev, s); 295 break;
271 /* stop the transfer w/o unlink */
272 usbduxfast_ai_stop(dev, 0);
273 return;
274 296
275 default: 297 default:
298 /* a real error */
276 dev_err(dev->class_dev, 299 dev_err(dev->class_dev,
277 "non-zero urb status received in ai intr context: %d\n", 300 "non-zero urb status received in ai intr context: %d\n",
278 urb->status); 301 urb->status);
279 async->events |= COMEDI_CB_EOA;
280 async->events |= COMEDI_CB_ERROR; 302 async->events |= COMEDI_CB_ERROR;
281 comedi_event(dev, s); 303 break;
282 usbduxfast_ai_stop(dev, 0);
283 return;
284 }
285
286 if (!devpriv->ignore) {
287 if (cmd->stop_src == TRIG_COUNT) {
288 /* not continuous, fixed number of samples */
289 n = urb->actual_length / sizeof(uint16_t);
290 if (unlikely(devpriv->ai_sample_count < n)) {
291 unsigned int num_bytes;
292
293 /* partial sample received */
294 num_bytes = devpriv->ai_sample_count *
295 sizeof(uint16_t);
296 cfc_write_array_to_buffer(s,
297 urb->transfer_buffer,
298 num_bytes);
299 usbduxfast_ai_stop(dev, 0);
300 /* tell comedi that the acquistion is over */
301 async->events |= COMEDI_CB_EOA;
302 comedi_event(dev, s);
303 return;
304 }
305 devpriv->ai_sample_count -= n;
306 }
307 /* write the full buffer to comedi */
308 err = cfc_write_array_to_buffer(s, urb->transfer_buffer,
309 urb->actual_length);
310 if (unlikely(err == 0)) {
311 /* buffer overflow */
312 usbduxfast_ai_stop(dev, 0);
313 return;
314 }
315
316 /* tell comedi that data is there */
317 comedi_event(dev, s);
318 } else {
319 /* ignore this packet */
320 devpriv->ignore--;
321 } 304 }
322 305
323 /* 306 /*
324 * command is still running 307 * comedi_handle_events() cannot be used in this driver. The (*cancel)
325 * resubmit urb for BULK transfer 308 * operation would unlink the urb.
326 */ 309 */
327 urb->dev = usb; 310 if (async->events & COMEDI_CB_CANCEL_MASK)
328 urb->status = 0;
329 err = usb_submit_urb(urb, GFP_ATOMIC);
330 if (err < 0) {
331 dev_err(dev->class_dev,
332 "urb resubm failed: %d", err);
333 async->events |= COMEDI_CB_EOA;
334 async->events |= COMEDI_CB_ERROR;
335 comedi_event(dev, s);
336 usbduxfast_ai_stop(dev, 0); 311 usbduxfast_ai_stop(dev, 0);
337 } 312
313 comedi_event(dev, s);
338} 314}
339 315
340static int usbduxfast_submit_urb(struct comedi_device *dev) 316static int usbduxfast_submit_urb(struct comedi_device *dev)
@@ -499,8 +475,6 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev,
499 up(&devpriv->sem); 475 up(&devpriv->sem);
500 return -EBUSY; 476 return -EBUSY;
501 } 477 }
502 /* set current channel of the running acquisition to zero */
503 s->async->cur_chan = 0;
504 478
505 /* 479 /*
506 * ignore the first buffers from the device if there 480 * ignore the first buffers from the device if there
@@ -810,11 +784,6 @@ static int usbduxfast_ai_cmd(struct comedi_device *dev,
810 return result; 784 return result;
811 } 785 }
812 786
813 if (cmd->stop_src == TRIG_COUNT)
814 devpriv->ai_sample_count = cmd->stop_arg * cmd->scan_end_arg;
815 else /* TRIG_NONE */
816 devpriv->ai_sample_count = 0;
817
818 if ((cmd->start_src == TRIG_NOW) || (cmd->start_src == TRIG_EXT)) { 787 if ((cmd->start_src == TRIG_NOW) || (cmd->start_src == TRIG_EXT)) {
819 /* enable this acquisition operation */ 788 /* enable this acquisition operation */
820 devpriv->ai_cmd_running = 1; 789 devpriv->ai_cmd_running = 1;
diff --git a/drivers/staging/comedi/drivers/usbduxsigma.c b/drivers/staging/comedi/drivers/usbduxsigma.c
index ebd68e365bac..dc19435b6520 100644
--- a/drivers/staging/comedi/drivers/usbduxsigma.c
+++ b/drivers/staging/comedi/drivers/usbduxsigma.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * usbduxsigma.c 2 * usbduxsigma.c
3 * Copyright (C) 2011 Bernd Porr, Bernd.Porr@f2s.com 3 * Copyright (C) 2011-2014 Bernd Porr, mail@berndporr.me.uk
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify 5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
@@ -17,9 +17,9 @@
17 * Driver: usbduxsigma 17 * Driver: usbduxsigma
18 * Description: University of Stirling USB DAQ & INCITE Technology Limited 18 * Description: University of Stirling USB DAQ & INCITE Technology Limited
19 * Devices: (ITL) USB-DUX [usbduxsigma] 19 * Devices: (ITL) USB-DUX [usbduxsigma]
20 * Author: Bernd Porr <BerndPorr@f2s.com> 20 * Author: Bernd Porr <mail@berndporr.me.uk>
21 * Updated: 8 Nov 2011 21 * Updated: 10 Oct 2014
22 * Status: testing 22 * Status: stable
23 */ 23 */
24 24
25/* 25/*
@@ -164,9 +164,6 @@ struct usbduxsigma_private {
164 unsigned ao_cmd_running:1; 164 unsigned ao_cmd_running:1;
165 unsigned pwm_cmd_running:1; 165 unsigned pwm_cmd_running:1;
166 166
167 /* number of samples to acquire */
168 int ai_sample_count;
169 int ao_sample_count;
170 /* time between samples in units of the timer */ 167 /* time between samples in units of the timer */
171 unsigned int ai_timer; 168 unsigned int ai_timer;
172 unsigned int ao_timer; 169 unsigned int ao_timer;
@@ -211,23 +208,75 @@ static int usbduxsigma_ai_cancel(struct comedi_device *dev,
211 return 0; 208 return 0;
212} 209}
213 210
214static void usbduxsigma_ai_urb_complete(struct urb *urb) 211static void usbduxsigma_ai_handle_urb(struct comedi_device *dev,
212 struct comedi_subdevice *s,
213 struct urb *urb)
215{ 214{
216 struct comedi_device *dev = urb->context;
217 struct usbduxsigma_private *devpriv = dev->private; 215 struct usbduxsigma_private *devpriv = dev->private;
218 struct comedi_subdevice *s = dev->read_subdev; 216 struct comedi_async *async = s->async;
219 struct comedi_cmd *cmd = &s->async->cmd; 217 struct comedi_cmd *cmd = &async->cmd;
220 unsigned int dio_state; 218 unsigned int dio_state;
221 uint32_t val; 219 uint32_t val;
222 int ret; 220 int ret;
223 int i; 221 int i;
224 222
225 /* first we test if something unusual has just happened */ 223 devpriv->ai_counter--;
224 if (devpriv->ai_counter == 0) {
225 devpriv->ai_counter = devpriv->ai_timer;
226
227 /* get the state of the dio pins to allow external trigger */
228 dio_state = be32_to_cpu(devpriv->in_buf[0]);
229
230 /* get the data from the USB bus and hand it over to comedi */
231 for (i = 0; i < cmd->chanlist_len; i++) {
232 /* transfer data, note first byte is the DIO state */
233 val = be32_to_cpu(devpriv->in_buf[i+1]);
234 val &= 0x00ffffff; /* strip status byte */
235 val ^= 0x00800000; /* convert to unsigned */
236
237 if (!comedi_buf_write_samples(s, &val, 1))
238 return;
239 }
240
241 if (cmd->stop_src == TRIG_COUNT &&
242 async->scans_done >= cmd->stop_arg)
243 async->events |= COMEDI_CB_EOA;
244 }
245
246 /* if command is still running, resubmit urb */
247 if (!(async->events & COMEDI_CB_CANCEL_MASK)) {
248 urb->dev = comedi_to_usb_dev(dev);
249 ret = usb_submit_urb(urb, GFP_ATOMIC);
250 if (ret < 0) {
251 dev_err(dev->class_dev,
252 "%s: urb resubmit failed (%d)\n",
253 __func__, ret);
254 if (ret == -EL2NSYNC)
255 dev_err(dev->class_dev,
256 "buggy USB host controller or bug in IRQ handler\n");
257 async->events |= COMEDI_CB_ERROR;
258 }
259 }
260}
261
262static void usbduxsigma_ai_urb_complete(struct urb *urb)
263{
264 struct comedi_device *dev = urb->context;
265 struct usbduxsigma_private *devpriv = dev->private;
266 struct comedi_subdevice *s = dev->read_subdev;
267 struct comedi_async *async = s->async;
268
269 /* exit if not running a command, do not resubmit urb */
270 if (!devpriv->ai_cmd_running)
271 return;
272
226 switch (urb->status) { 273 switch (urb->status) {
227 case 0: 274 case 0:
228 /* copy the result in the transfer buffer */ 275 /* copy the result in the transfer buffer */
229 memcpy(devpriv->in_buf, urb->transfer_buffer, SIZEINBUF); 276 memcpy(devpriv->in_buf, urb->transfer_buffer, SIZEINBUF);
277 usbduxsigma_ai_handle_urb(dev, s, urb);
230 break; 278 break;
279
231 case -EILSEQ: 280 case -EILSEQ:
232 /* 281 /*
233 * error in the ISOchronous data 282 * error in the ISOchronous data
@@ -235,7 +284,7 @@ static void usbduxsigma_ai_urb_complete(struct urb *urb)
235 * and recycle the last data byte 284 * and recycle the last data byte
236 */ 285 */
237 dev_dbg(dev->class_dev, "CRC error in ISO IN stream\n"); 286 dev_dbg(dev->class_dev, "CRC error in ISO IN stream\n");
238 287 usbduxsigma_ai_handle_urb(dev, s, urb);
239 break; 288 break;
240 289
241 case -ECONNRESET: 290 case -ECONNRESET:
@@ -243,86 +292,24 @@ static void usbduxsigma_ai_urb_complete(struct urb *urb)
243 case -ESHUTDOWN: 292 case -ESHUTDOWN:
244 case -ECONNABORTED: 293 case -ECONNABORTED:
245 /* happens after an unlink command */ 294 /* happens after an unlink command */
246 if (devpriv->ai_cmd_running) { 295 async->events |= COMEDI_CB_ERROR;
247 usbduxsigma_ai_stop(dev, 0); /* w/o unlink */ 296 break;
248 /* we are still running a command, tell comedi */
249 s->async->events |= (COMEDI_CB_EOA | COMEDI_CB_ERROR);
250 comedi_event(dev, s);
251 }
252 return;
253 297
254 default: 298 default:
255 /* 299 /* a real error */
256 * a real error on the bus 300 dev_err(dev->class_dev, "%s: non-zero urb status (%d)\n",
257 * pass error to comedi if we are really running a command 301 __func__, urb->status);
258 */ 302 async->events |= COMEDI_CB_ERROR;
259 if (devpriv->ai_cmd_running) { 303 break;
260 dev_err(dev->class_dev,
261 "%s: non-zero urb status (%d)\n",
262 __func__, urb->status);
263 usbduxsigma_ai_stop(dev, 0); /* w/o unlink */
264 s->async->events |= (COMEDI_CB_EOA | COMEDI_CB_ERROR);
265 comedi_event(dev, s);
266 }
267 return;
268 }
269
270 if (unlikely(!devpriv->ai_cmd_running))
271 return;
272
273 urb->dev = comedi_to_usb_dev(dev);
274
275 ret = usb_submit_urb(urb, GFP_ATOMIC);
276 if (unlikely(ret < 0)) {
277 dev_err(dev->class_dev, "%s: urb resubmit failed (%d)\n",
278 __func__, ret);
279 if (ret == -EL2NSYNC)
280 dev_err(dev->class_dev,
281 "buggy USB host controller or bug in IRQ handler\n");
282 usbduxsigma_ai_stop(dev, 0); /* w/o unlink */
283 s->async->events |= (COMEDI_CB_EOA | COMEDI_CB_ERROR);
284 comedi_event(dev, s);
285 return;
286 }
287
288 /* get the state of the dio pins to allow external trigger */
289 dio_state = be32_to_cpu(devpriv->in_buf[0]);
290
291 devpriv->ai_counter--;
292 if (likely(devpriv->ai_counter > 0))
293 return;
294
295 /* timer zero, transfer measurements to comedi */
296 devpriv->ai_counter = devpriv->ai_timer;
297
298 if (cmd->stop_src == TRIG_COUNT) {
299 /* not continuous, fixed number of samples */
300 devpriv->ai_sample_count--;
301 if (devpriv->ai_sample_count < 0) {
302 usbduxsigma_ai_stop(dev, 0); /* w/o unlink */
303 /* acquistion is over, tell comedi */
304 s->async->events |= COMEDI_CB_EOA;
305 comedi_event(dev, s);
306 return;
307 }
308 } 304 }
309 305
310 /* get the data from the USB bus and hand it over to comedi */ 306 /*
311 for (i = 0; i < cmd->chanlist_len; i++) { 307 * comedi_handle_events() cannot be used in this driver. The (*cancel)
312 /* transfer data, note first byte is the DIO state */ 308 * operation would unlink the urb.
313 val = be32_to_cpu(devpriv->in_buf[i+1]); 309 */
314 val &= 0x00ffffff; /* strip status byte */ 310 if (async->events & COMEDI_CB_CANCEL_MASK)
315 val ^= 0x00800000; /* convert to unsigned */ 311 usbduxsigma_ai_stop(dev, 0);
316 312
317 ret = cfc_write_array_to_buffer(s, &val, sizeof(uint32_t));
318 if (unlikely(ret == 0)) {
319 /* buffer overflow */
320 usbduxsigma_ai_stop(dev, 0); /* w/o unlink */
321 return;
322 }
323 }
324 /* tell comedi that data is there */
325 s->async->events |= (COMEDI_CB_BLOCK | COMEDI_CB_EOS);
326 comedi_event(dev, s); 313 comedi_event(dev, s);
327} 314}
328 315
@@ -349,64 +336,25 @@ static int usbduxsigma_ao_cancel(struct comedi_device *dev,
349 return 0; 336 return 0;
350} 337}
351 338
352static void usbduxsigma_ao_urb_complete(struct urb *urb) 339static void usbduxsigma_ao_handle_urb(struct comedi_device *dev,
340 struct comedi_subdevice *s,
341 struct urb *urb)
353{ 342{
354 struct comedi_device *dev = urb->context;
355 struct usbduxsigma_private *devpriv = dev->private; 343 struct usbduxsigma_private *devpriv = dev->private;
356 struct comedi_subdevice *s = dev->write_subdev; 344 struct comedi_async *async = s->async;
357 struct comedi_cmd *cmd = &s->async->cmd; 345 struct comedi_cmd *cmd = &async->cmd;
358 uint8_t *datap; 346 uint8_t *datap;
359 int ret; 347 int ret;
360 int i; 348 int i;
361 349
362 switch (urb->status) {
363 case 0:
364 /* success */
365 break;
366
367 case -ECONNRESET:
368 case -ENOENT:
369 case -ESHUTDOWN:
370 case -ECONNABORTED:
371 /* happens after an unlink command */
372 if (devpriv->ao_cmd_running) {
373 usbduxsigma_ao_stop(dev, 0); /* w/o unlink */
374 s->async->events |= COMEDI_CB_EOA;
375 comedi_event(dev, s);
376 }
377 return;
378
379 default:
380 /* a real error */
381 if (devpriv->ao_cmd_running) {
382 dev_err(dev->class_dev,
383 "%s: non-zero urb status (%d)\n",
384 __func__, urb->status);
385 usbduxsigma_ao_stop(dev, 0); /* w/o unlink */
386 s->async->events |= (COMEDI_CB_ERROR | COMEDI_CB_EOA);
387 comedi_event(dev, s);
388 }
389 return;
390 }
391
392 if (!devpriv->ao_cmd_running)
393 return;
394
395 devpriv->ao_counter--; 350 devpriv->ao_counter--;
396 if ((int)devpriv->ao_counter <= 0) { 351 if (devpriv->ao_counter == 0) {
397 /* timer zero, transfer from comedi */
398 devpriv->ao_counter = devpriv->ao_timer; 352 devpriv->ao_counter = devpriv->ao_timer;
399 353
400 if (cmd->stop_src == TRIG_COUNT) { 354 if (cmd->stop_src == TRIG_COUNT &&
401 /* not continuous, fixed number of samples */ 355 async->scans_done >= cmd->stop_arg) {
402 devpriv->ao_sample_count--; 356 async->events |= COMEDI_CB_EOA;
403 if (devpriv->ao_sample_count < 0) { 357 return;
404 usbduxsigma_ao_stop(dev, 0); /* w/o unlink */
405 /* acquistion is over, tell comedi */
406 s->async->events |= COMEDI_CB_EOA;
407 comedi_event(dev, s);
408 return;
409 }
410 } 358 }
411 359
412 /* transmit data to the USB bus */ 360 /* transmit data to the USB bus */
@@ -416,46 +364,86 @@ static void usbduxsigma_ao_urb_complete(struct urb *urb)
416 unsigned int chan = CR_CHAN(cmd->chanlist[i]); 364 unsigned int chan = CR_CHAN(cmd->chanlist[i]);
417 unsigned short val; 365 unsigned short val;
418 366
419 ret = comedi_buf_get(s, &val); 367 if (!comedi_buf_read_samples(s, &val, 1)) {
420 if (ret < 0) {
421 dev_err(dev->class_dev, "buffer underflow\n"); 368 dev_err(dev->class_dev, "buffer underflow\n");
422 s->async->events |= (COMEDI_CB_EOA | 369 async->events |= COMEDI_CB_OVERFLOW;
423 COMEDI_CB_OVERFLOW); 370 return;
424 } 371 }
372
425 *datap++ = val; 373 *datap++ = val;
426 *datap++ = chan; 374 *datap++ = chan;
427 s->readback[chan] = val; 375 s->readback[chan] = val;
428
429 s->async->events |= COMEDI_CB_BLOCK;
430 comedi_event(dev, s);
431 } 376 }
432 } 377 }
433 378
434 urb->transfer_buffer_length = SIZEOUTBUF; 379 /* if command is still running, resubmit urb */
435 urb->dev = comedi_to_usb_dev(dev); 380 if (!(async->events & COMEDI_CB_CANCEL_MASK)) {
436 urb->status = 0; 381 urb->transfer_buffer_length = SIZEOUTBUF;
437 if (devpriv->high_speed) 382 urb->dev = comedi_to_usb_dev(dev);
438 urb->interval = 8; /* uframes */ 383 urb->status = 0;
439 else 384 if (devpriv->high_speed)
440 urb->interval = 1; /* frames */ 385 urb->interval = 8; /* uframes */
441 urb->number_of_packets = 1; 386 else
442 urb->iso_frame_desc[0].offset = 0; 387 urb->interval = 1; /* frames */
443 urb->iso_frame_desc[0].length = SIZEOUTBUF; 388 urb->number_of_packets = 1;
444 urb->iso_frame_desc[0].status = 0; 389 urb->iso_frame_desc[0].offset = 0;
445 ret = usb_submit_urb(urb, GFP_ATOMIC); 390 urb->iso_frame_desc[0].length = SIZEOUTBUF;
446 if (ret < 0) { 391 urb->iso_frame_desc[0].status = 0;
447 dev_err(dev->class_dev, 392 ret = usb_submit_urb(urb, GFP_ATOMIC);
448 "%s: urb resubmit failed (%d)\n", 393 if (ret < 0) {
449 __func__, ret);
450 if (ret == -EL2NSYNC)
451 dev_err(dev->class_dev, 394 dev_err(dev->class_dev,
452 "buggy USB host controller or bug in IRQ handler\n"); 395 "%s: urb resubmit failed (%d)\n",
453 usbduxsigma_ao_stop(dev, 0); /* w/o unlink */ 396 __func__, ret);
454 s->async->events |= (COMEDI_CB_EOA | COMEDI_CB_ERROR); 397 if (ret == -EL2NSYNC)
455 comedi_event(dev, s); 398 dev_err(dev->class_dev,
399 "buggy USB host controller or bug in IRQ handler\n");
400 async->events |= COMEDI_CB_ERROR;
401 }
456 } 402 }
457} 403}
458 404
405static void usbduxsigma_ao_urb_complete(struct urb *urb)
406{
407 struct comedi_device *dev = urb->context;
408 struct usbduxsigma_private *devpriv = dev->private;
409 struct comedi_subdevice *s = dev->write_subdev;
410 struct comedi_async *async = s->async;
411
412 /* exit if not running a command, do not resubmit urb */
413 if (!devpriv->ao_cmd_running)
414 return;
415
416 switch (urb->status) {
417 case 0:
418 usbduxsigma_ao_handle_urb(dev, s, urb);
419 break;
420
421 case -ECONNRESET:
422 case -ENOENT:
423 case -ESHUTDOWN:
424 case -ECONNABORTED:
425 /* happens after an unlink command */
426 async->events |= COMEDI_CB_ERROR;
427 break;
428
429 default:
430 /* a real error */
431 dev_err(dev->class_dev, "%s: non-zero urb status (%d)\n",
432 __func__, urb->status);
433 async->events |= COMEDI_CB_ERROR;
434 break;
435 }
436
437 /*
438 * comedi_handle_events() cannot be used in this driver. The (*cancel)
439 * operation would unlink the urb.
440 */
441 if (async->events & COMEDI_CB_CANCEL_MASK)
442 usbduxsigma_ao_stop(dev, 0);
443
444 comedi_event(dev, s);
445}
446
459static int usbduxsigma_submit_urbs(struct comedi_device *dev, 447static int usbduxsigma_submit_urbs(struct comedi_device *dev,
460 struct urb **urbs, int num_urbs, 448 struct urb **urbs, int num_urbs,
461 int input_urb) 449 int input_urb)
@@ -584,14 +572,6 @@ static int usbduxsigma_ai_cmdtest(struct comedi_device *dev,
584 if (devpriv->ai_timer < 1) 572 if (devpriv->ai_timer < 1)
585 err |= -EINVAL; 573 err |= -EINVAL;
586 574
587 if (cmd->stop_src == TRIG_COUNT) {
588 /* data arrives as one packet */
589 devpriv->ai_sample_count = cmd->stop_arg;
590 } else {
591 /* continuous acquisition */
592 devpriv->ai_sample_count = 0;
593 }
594
595 if (err) 575 if (err)
596 return 4; 576 return 4;
597 577
@@ -692,8 +672,6 @@ static int usbduxsigma_ai_cmd(struct comedi_device *dev,
692 672
693 down(&devpriv->sem); 673 down(&devpriv->sem);
694 674
695 /* set current channel of the running acquisition to zero */
696 s->async->cur_chan = 0;
697 for (i = 0; i < len; i++) { 675 for (i = 0; i < len; i++) {
698 unsigned int chan = CR_CHAN(cmd->chanlist[i]); 676 unsigned int chan = CR_CHAN(cmd->chanlist[i]);
699 677
@@ -957,25 +935,6 @@ static int usbduxsigma_ao_cmdtest(struct comedi_device *dev,
957 if (devpriv->ao_timer < 1) 935 if (devpriv->ao_timer < 1)
958 err |= -EINVAL; 936 err |= -EINVAL;
959 937
960 if (cmd->stop_src == TRIG_COUNT) {
961 /* not continuous, use counter */
962 if (high_speed) {
963 /* high speed also scans everything at once */
964 devpriv->ao_sample_count = cmd->stop_arg *
965 cmd->scan_end_arg;
966 } else {
967 /*
968 * There's no scan as the scan has been
969 * handled inside the FX2. Data arrives as
970 * one packet.
971 */
972 devpriv->ao_sample_count = cmd->stop_arg;
973 }
974 } else {
975 /* continuous acquisition */
976 devpriv->ao_sample_count = 0;
977 }
978
979 if (err) 938 if (err)
980 return 4; 939 return 4;
981 940
@@ -991,9 +950,6 @@ static int usbduxsigma_ao_cmd(struct comedi_device *dev,
991 950
992 down(&devpriv->sem); 951 down(&devpriv->sem);
993 952
994 /* set current channel of the running acquisition to zero */
995 s->async->cur_chan = 0;
996
997 devpriv->ao_counter = devpriv->ao_timer; 953 devpriv->ao_counter = devpriv->ao_timer;
998 954
999 if (cmd->start_src == TRIG_NOW) { 955 if (cmd->start_src == TRIG_NOW) {
diff --git a/drivers/staging/comedi/drivers/vmk80xx.c b/drivers/staging/comedi/drivers/vmk80xx.c
index 71003416edcf..a19a56ee0eef 100644
--- a/drivers/staging/comedi/drivers/vmk80xx.c
+++ b/drivers/staging/comedi/drivers/vmk80xx.c
@@ -797,7 +797,7 @@ static int vmk80xx_init_subdevices(struct comedi_device *dev)
797 /* Analog output subdevice */ 797 /* Analog output subdevice */
798 s = &dev->subdevices[1]; 798 s = &dev->subdevices[1];
799 s->type = COMEDI_SUBD_AO; 799 s->type = COMEDI_SUBD_AO;
800 s->subdev_flags = SDF_WRITEABLE | SDF_GROUND; 800 s->subdev_flags = SDF_WRITABLE | SDF_GROUND;
801 s->n_chan = boardinfo->ao_nchans; 801 s->n_chan = boardinfo->ao_nchans;
802 s->maxdata = 0x00ff; 802 s->maxdata = 0x00ff;
803 s->range_table = boardinfo->range; 803 s->range_table = boardinfo->range;
@@ -819,7 +819,7 @@ static int vmk80xx_init_subdevices(struct comedi_device *dev)
819 /* Digital output subdevice */ 819 /* Digital output subdevice */
820 s = &dev->subdevices[3]; 820 s = &dev->subdevices[3];
821 s->type = COMEDI_SUBD_DO; 821 s->type = COMEDI_SUBD_DO;
822 s->subdev_flags = SDF_WRITEABLE; 822 s->subdev_flags = SDF_WRITABLE;
823 s->n_chan = 8; 823 s->n_chan = 8;
824 s->maxdata = 1; 824 s->maxdata = 1;
825 s->range_table = &range_digital; 825 s->range_table = &range_digital;
@@ -834,7 +834,7 @@ static int vmk80xx_init_subdevices(struct comedi_device *dev)
834 s->insn_read = vmk80xx_cnt_insn_read; 834 s->insn_read = vmk80xx_cnt_insn_read;
835 s->insn_config = vmk80xx_cnt_insn_config; 835 s->insn_config = vmk80xx_cnt_insn_config;
836 if (devpriv->model == VMK8055_MODEL) { 836 if (devpriv->model == VMK8055_MODEL) {
837 s->subdev_flags |= SDF_WRITEABLE; 837 s->subdev_flags |= SDF_WRITABLE;
838 s->insn_write = vmk80xx_cnt_insn_write; 838 s->insn_write = vmk80xx_cnt_insn_write;
839 } 839 }
840 840
@@ -842,7 +842,7 @@ static int vmk80xx_init_subdevices(struct comedi_device *dev)
842 if (devpriv->model == VMK8061_MODEL) { 842 if (devpriv->model == VMK8061_MODEL) {
843 s = &dev->subdevices[5]; 843 s = &dev->subdevices[5];
844 s->type = COMEDI_SUBD_PWM; 844 s->type = COMEDI_SUBD_PWM;
845 s->subdev_flags = SDF_READABLE | SDF_WRITEABLE; 845 s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
846 s->n_chan = boardinfo->pwm_nchans; 846 s->n_chan = boardinfo->pwm_nchans;
847 s->maxdata = boardinfo->pwm_maxdata; 847 s->maxdata = boardinfo->pwm_maxdata;
848 s->insn_read = vmk80xx_pwm_insn_read; 848 s->insn_read = vmk80xx_pwm_insn_read;
diff --git a/drivers/staging/comedi/range.c b/drivers/staging/comedi/range.c
index b6849545b810..9a1dc56f21d1 100644
--- a/drivers/staging/comedi/range.c
+++ b/drivers/staging/comedi/range.c
@@ -97,39 +97,6 @@ int do_rangeinfo_ioctl(struct comedi_device *dev,
97 return 0; 97 return 0;
98} 98}
99 99
100static int aref_invalid(struct comedi_subdevice *s, unsigned int chanspec)
101{
102 unsigned int aref;
103
104 /* disable reporting invalid arefs... maybe someday */
105 return 0;
106
107 aref = CR_AREF(chanspec);
108 switch (aref) {
109 case AREF_DIFF:
110 if (s->subdev_flags & SDF_DIFF)
111 return 0;
112 break;
113 case AREF_COMMON:
114 if (s->subdev_flags & SDF_COMMON)
115 return 0;
116 break;
117 case AREF_GROUND:
118 if (s->subdev_flags & SDF_GROUND)
119 return 0;
120 break;
121 case AREF_OTHER:
122 if (s->subdev_flags & SDF_OTHER)
123 return 0;
124 break;
125 default:
126 break;
127 }
128 dev_dbg(s->device->class_dev, "subdevice does not support aref %i",
129 aref);
130 return 1;
131}
132
133/** 100/**
134 * comedi_check_chanlist() - Validate each element in a chanlist. 101 * comedi_check_chanlist() - Validate each element in a chanlist.
135 * @s: comedi_subdevice struct 102 * @s: comedi_subdevice struct
@@ -153,8 +120,7 @@ int comedi_check_chanlist(struct comedi_subdevice *s, int n,
153 else 120 else
154 range_len = 0; 121 range_len = 0;
155 if (chan >= s->n_chan || 122 if (chan >= s->n_chan ||
156 CR_RANGE(chanspec) >= range_len || 123 CR_RANGE(chanspec) >= range_len) {
157 aref_invalid(s, chanspec)) {
158 dev_warn(dev->class_dev, 124 dev_warn(dev->class_dev,
159 "bad chanlist[%d]=0x%08x chan=%d range length=%d\n", 125 "bad chanlist[%d]=0x%08x chan=%d range length=%d\n",
160 i, chanspec, chan, range_len); 126 i, chanspec, chan, range_len);
diff --git a/drivers/staging/cptm1217/clearpad_tm1217.c b/drivers/staging/cptm1217/clearpad_tm1217.c
index edf9ff2ea25b..7f265ce0dd13 100644
--- a/drivers/staging/cptm1217/clearpad_tm1217.c
+++ b/drivers/staging/cptm1217/clearpad_tm1217.c
@@ -278,7 +278,7 @@ static void cp_tm1217_get_data(struct cp_tm1217_device *ts)
278 278
279static irqreturn_t cp_tm1217_sample_thread(int irq, void *handle) 279static irqreturn_t cp_tm1217_sample_thread(int irq, void *handle)
280{ 280{
281 struct cp_tm1217_device *ts = (struct cp_tm1217_device *) handle; 281 struct cp_tm1217_device *ts = handle;
282 u8 req[2]; 282 u8 req[2];
283 int retval; 283 int retval;
284 284
diff --git a/drivers/staging/dgap/dgap.c b/drivers/staging/dgap/dgap.c
index d0be1cebf5a9..bdb5317e3d9d 100644
--- a/drivers/staging/dgap/dgap.c
+++ b/drivers/staging/dgap/dgap.c
@@ -65,144 +65,6 @@
65 65
66#include "dgap.h" 66#include "dgap.h"
67 67
68MODULE_LICENSE("GPL");
69MODULE_AUTHOR("Digi International, http://www.digi.com");
70MODULE_DESCRIPTION("Driver for the Digi International EPCA PCI based product line");
71MODULE_SUPPORTED_DEVICE("dgap");
72
73static int dgap_start(void);
74static void dgap_init_globals(void);
75static struct board_t *dgap_found_board(struct pci_dev *pdev, int id,
76 int boardnum);
77static void dgap_cleanup_board(struct board_t *brd);
78static void dgap_poll_handler(ulong dummy);
79static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
80static void dgap_remove_one(struct pci_dev *dev);
81static int dgap_do_remap(struct board_t *brd);
82static void dgap_release_remap(struct board_t *brd);
83static irqreturn_t dgap_intr(int irq, void *voidbrd);
84
85static int dgap_tty_open(struct tty_struct *tty, struct file *file);
86static void dgap_tty_close(struct tty_struct *tty, struct file *file);
87static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
88 struct channel_t *ch);
89static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
90 unsigned long arg);
91static int dgap_tty_digigeta(struct channel_t *ch,
92 struct digi_t __user *retinfo);
93static int dgap_tty_digiseta(struct channel_t *ch, struct board_t *bd,
94 struct un_t *un, struct digi_t __user *new_info);
95static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo);
96static int dgap_tty_digisetedelay(struct channel_t *ch, struct board_t *bd,
97 struct un_t *un, int __user *new_info);
98static int dgap_tty_write_room(struct tty_struct *tty);
99static int dgap_tty_chars_in_buffer(struct tty_struct *tty);
100static void dgap_tty_start(struct tty_struct *tty);
101static void dgap_tty_stop(struct tty_struct *tty);
102static void dgap_tty_throttle(struct tty_struct *tty);
103static void dgap_tty_unthrottle(struct tty_struct *tty);
104static void dgap_tty_flush_chars(struct tty_struct *tty);
105static void dgap_tty_flush_buffer(struct tty_struct *tty);
106static void dgap_tty_hangup(struct tty_struct *tty);
107static int dgap_wait_for_drain(struct tty_struct *tty);
108static int dgap_set_modem_info(struct channel_t *ch, struct board_t *bd,
109 struct un_t *un, unsigned int command,
110 unsigned int __user *value);
111static int dgap_get_modem_info(struct channel_t *ch,
112 unsigned int __user *value);
113static int dgap_tty_digisetcustombaud(struct channel_t *ch, struct board_t *bd,
114 struct un_t *un, int __user *new_info);
115static int dgap_tty_digigetcustombaud(struct channel_t *ch, struct un_t *un,
116 int __user *retinfo);
117static int dgap_tty_tiocmget(struct tty_struct *tty);
118static int dgap_tty_tiocmset(struct tty_struct *tty, unsigned int set,
119 unsigned int clear);
120static int dgap_tty_send_break(struct tty_struct *tty, int msec);
121static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout);
122static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
123 int count);
124static void dgap_tty_set_termios(struct tty_struct *tty,
125 struct ktermios *old_termios);
126static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c);
127static void dgap_tty_send_xchar(struct tty_struct *tty, char ch);
128
129static int dgap_tty_register(struct board_t *brd);
130static void dgap_tty_unregister(struct board_t *brd);
131static int dgap_tty_init(struct board_t *);
132static void dgap_tty_free(struct board_t *);
133static void dgap_cleanup_tty(struct board_t *);
134static void dgap_carrier(struct channel_t *ch);
135static void dgap_input(struct channel_t *ch);
136
137/*
138 * Our function prototypes from dgap_fep5
139 */
140static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds);
141static int dgap_event(struct board_t *bd);
142
143static void dgap_poll_tasklet(unsigned long data);
144static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
145 u8 byte2, uint ncmds);
146static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds);
147static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt);
148static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type);
149static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
150 unsigned char *fbuf, int *len);
151static uint dgap_get_custom_baud(struct channel_t *ch);
152static void dgap_firmware_reset_port(struct channel_t *ch);
153
154/*
155 * Function prototypes from dgap_parse.c.
156 */
157static int dgap_gettok(char **in);
158static char *dgap_getword(char **in);
159static int dgap_checknode(struct cnode *p);
160
161/*
162 * Function prototypes from dgap_sysfs.h
163 */
164static void dgap_create_ports_sysfiles(struct board_t *bd);
165static void dgap_remove_ports_sysfiles(struct board_t *bd);
166
167static int dgap_create_driver_sysfiles(struct pci_driver *);
168static void dgap_remove_driver_sysfiles(struct pci_driver *);
169
170static void dgap_create_tty_sysfs(struct un_t *un, struct device *c);
171static void dgap_remove_tty_sysfs(struct device *c);
172
173/*
174 * Function prototypes from dgap_parse.h
175 */
176static int dgap_parsefile(char **in);
177static struct cnode *dgap_find_config(int type, int bus, int slot);
178static uint dgap_config_get_num_prts(struct board_t *bd);
179static char *dgap_create_config_string(struct board_t *bd, char *string);
180static uint dgap_config_get_useintr(struct board_t *bd);
181static uint dgap_config_get_altpin(struct board_t *bd);
182
183static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len);
184static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len);
185#ifdef DIGI_CONCENTRATORS_SUPPORTED
186static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len);
187#endif
188static int dgap_alloc_flipbuf(struct board_t *brd);
189static void dgap_free_flipbuf(struct board_t *brd);
190static int dgap_request_irq(struct board_t *brd);
191static void dgap_free_irq(struct board_t *brd);
192
193static void dgap_get_vpd(struct board_t *brd);
194static void dgap_do_reset_board(struct board_t *brd);
195static int dgap_test_bios(struct board_t *brd);
196static int dgap_test_fep(struct board_t *brd);
197static int dgap_tty_register_ports(struct board_t *brd);
198static int dgap_firmware_load(struct pci_dev *pdev, int card_type,
199 struct board_t *brd);
200static void dgap_cleanup_nodes(void);
201
202static void dgap_cleanup_module(void);
203
204module_exit(dgap_cleanup_module);
205
206/* 68/*
207 * File operations permitted on Control/Management major. 69 * File operations permitted on Control/Management major.
208 */ 70 */
@@ -218,7 +80,6 @@ static int dgap_poll_tick = 20; /* Poll interval - 20 ms */
218 80
219static struct class *dgap_class; 81static struct class *dgap_class;
220 82
221static struct board_t *dgap_boards_by_major[256];
222static uint dgap_count = 500; 83static uint dgap_count = 500;
223 84
224/* 85/*
@@ -297,13 +158,6 @@ static struct board_id dgap_ids[] = {
297 {0,} /* 0 terminated list. */ 158 {0,} /* 0 terminated list. */
298}; 159};
299 160
300static struct pci_driver dgap_driver = {
301 .name = "dgap",
302 .probe = dgap_init_one,
303 .id_table = dgap_pci_tbl,
304 .remove = dgap_remove_one,
305};
306
307struct firmware_info { 161struct firmware_info {
308 u8 *conf_name; /* dgap.conf */ 162 u8 *conf_name; /* dgap.conf */
309 u8 *bios_name; /* BIOS filename */ 163 u8 *bios_name; /* BIOS filename */
@@ -366,29 +220,6 @@ static struct ktermios dgap_default_termios = {
366 .c_line = 0, 220 .c_line = 0,
367}; 221};
368 222
369static const struct tty_operations dgap_tty_ops = {
370 .open = dgap_tty_open,
371 .close = dgap_tty_close,
372 .write = dgap_tty_write,
373 .write_room = dgap_tty_write_room,
374 .flush_buffer = dgap_tty_flush_buffer,
375 .chars_in_buffer = dgap_tty_chars_in_buffer,
376 .flush_chars = dgap_tty_flush_chars,
377 .ioctl = dgap_tty_ioctl,
378 .set_termios = dgap_tty_set_termios,
379 .stop = dgap_tty_stop,
380 .start = dgap_tty_start,
381 .throttle = dgap_tty_throttle,
382 .unthrottle = dgap_tty_unthrottle,
383 .hangup = dgap_tty_hangup,
384 .put_char = dgap_tty_put_char,
385 .tiocmget = dgap_tty_tiocmget,
386 .tiocmset = dgap_tty_tiocmset,
387 .break_ctl = dgap_tty_send_break,
388 .wait_until_sent = dgap_tty_wait_until_sent,
389 .send_xchar = dgap_tty_send_xchar
390};
391
392/* 223/*
393 * Our needed internal static variables from dgap_parse.c 224 * Our needed internal static variables from dgap_parse.c
394 */ 225 */
@@ -456,1078 +287,1226 @@ static struct toklist dgap_tlist[] = {
456 { 0, NULL } 287 { 0, NULL }
457}; 288};
458 289
459/************************************************************************
460 *
461 * Driver load/unload functions
462 *
463 ************************************************************************/
464 290
465/* 291/*
466 * init_module() 292 * dgap_sindex: much like index(), but it looks for a match of any character in
467 * 293 * the group, and returns that position. If the first character is a ^, then
468 * Module load. This is where it all starts. 294 * this will match the first occurrence not in that group.
469 */ 295 */
470static int dgap_init_module(void) 296static char *dgap_sindex(char *string, char *group)
471{ 297{
472 int rc; 298 char *ptr;
473 299
474 pr_info("%s, Digi International Part Number %s\n", DG_NAME, DG_PART); 300 if (!string || !group)
301 return NULL;
475 302
476 rc = dgap_start(); 303 if (*group == '^') {
477 if (rc) 304 group++;
478 return rc; 305 for (; *string; string++) {
306 for (ptr = group; *ptr; ptr++) {
307 if (*ptr == *string)
308 break;
309 }
310 if (*ptr == '\0')
311 return string;
312 }
313 } else {
314 for (; *string; string++) {
315 for (ptr = group; *ptr; ptr++) {
316 if (*ptr == *string)
317 return string;
318 }
319 }
320 }
479 321
480 rc = pci_register_driver(&dgap_driver); 322 return NULL;
481 if (rc) 323}
482 goto err_cleanup;
483 324
484 rc = dgap_create_driver_sysfiles(&dgap_driver); 325/*
485 if (rc) 326 * get a word from the input stream, also keep track of current line number.
486 goto err_cleanup; 327 * words are separated by whitespace.
328 */
329static char *dgap_getword(char **in)
330{
331 char *ret_ptr = *in;
487 332
488 dgap_driver_state = DRIVER_READY; 333 char *ptr = dgap_sindex(*in, " \t\n");
489 334
490 return 0; 335 /* If no word found, return null */
336 if (!ptr)
337 return NULL;
491 338
492err_cleanup: 339 /* Mark new location for our buffer */
340 *ptr = '\0';
341 *in = ptr + 1;
493 342
494 dgap_cleanup_module(); 343 /* Eat any extra spaces/tabs/newlines that might be present */
344 while (*in && **in && ((**in == ' ') ||
345 (**in == '\t') ||
346 (**in == '\n'))) {
347 **in = '\0';
348 *in = *in + 1;
349 }
495 350
496 return rc; 351 return ret_ptr;
497} 352}
498module_init(dgap_init_module); 353
499 354
500/* 355/*
501 * Start of driver. 356 * Get a token from the input file; return 0 if end of file is reached
502 */ 357 */
503static int dgap_start(void) 358static int dgap_gettok(char **in)
504{ 359{
505 int rc; 360 char *w;
506 unsigned long flags; 361 struct toklist *t;
507 struct device *device;
508
509 /*
510 * make sure that the globals are
511 * init'd before we do anything else
512 */
513 dgap_init_globals();
514
515 dgap_numboards = 0;
516 362
517 pr_info("For the tools package please visit http://www.digi.com\n"); 363 if (strstr(dgap_cword, "board")) {
364 w = dgap_getword(in);
365 snprintf(dgap_cword, MAXCWORD, "%s", w);
366 for (t = dgap_brdtype; t->token != 0; t++) {
367 if (!strcmp(w, t->string))
368 return t->token;
369 }
370 } else {
371 while ((w = dgap_getword(in))) {
372 snprintf(dgap_cword, MAXCWORD, "%s", w);
373 for (t = dgap_tlist; t->token != 0; t++) {
374 if (!strcmp(w, t->string))
375 return t->token;
376 }
377 }
378 }
518 379
519 /* 380 return 0;
520 * Register our base character device into the kernel. 381}
521 */
522 382
523 /* 383/*
524 * Register management/dpa devices 384 * dgap_checknode: see if all the necessary info has been supplied for a node
525 */ 385 * before creating the next node.
526 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &dgap_board_fops); 386 */
527 if (rc < 0) 387static int dgap_checknode(struct cnode *p)
528 return rc; 388{
389 switch (p->type) {
390 case LNODE:
391 if (p->u.line.v_speed == 0) {
392 pr_err("line speed not specified");
393 return 1;
394 }
395 return 0;
529 396
530 dgap_class = class_create(THIS_MODULE, "dgap_mgmt"); 397 case CNODE:
531 if (IS_ERR(dgap_class)) { 398 if (p->u.conc.v_speed == 0) {
532 rc = PTR_ERR(dgap_class); 399 pr_err("concentrator line speed not specified");
533 goto failed_class; 400 return 1;
534 } 401 }
402 if (p->u.conc.v_nport == 0) {
403 pr_err("number of ports on concentrator not specified");
404 return 1;
405 }
406 if (p->u.conc.v_id == 0) {
407 pr_err("concentrator id letter not specified");
408 return 1;
409 }
410 return 0;
535 411
536 device = device_create(dgap_class, NULL, 412 case MNODE:
537 MKDEV(DIGI_DGAP_MAJOR, 0), 413 if (p->u.module.v_nport == 0) {
538 NULL, "dgap_mgmt"); 414 pr_err("number of ports on EBI module not specified");
539 if (IS_ERR(device)) { 415 return 1;
540 rc = PTR_ERR(device); 416 }
541 goto failed_device; 417 if (p->u.module.v_id == 0) {
418 pr_err("EBI module id letter not specified");
419 return 1;
420 }
421 return 0;
542 } 422 }
423 return 0;
424}
543 425
544 /* Start the poller */ 426/*
545 spin_lock_irqsave(&dgap_poll_lock, flags); 427 * Given a board pointer, returns whether we should use interrupts or not.
546 init_timer(&dgap_poll_timer); 428 */
547 dgap_poll_timer.function = dgap_poll_handler; 429static uint dgap_config_get_useintr(struct board_t *bd)
548 dgap_poll_timer.data = 0; 430{
549 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick); 431 struct cnode *p;
550 dgap_poll_timer.expires = dgap_poll_time;
551 spin_unlock_irqrestore(&dgap_poll_lock, flags);
552 432
553 add_timer(&dgap_poll_timer); 433 if (!bd)
434 return 0;
554 435
555 return rc; 436 for (p = bd->bd_config; p; p = p->next) {
437 if (p->type == INTRNODE) {
438 /*
439 * check for pcxr types.
440 */
441 return p->u.useintr;
442 }
443 }
556 444
557failed_device: 445 /* If not found, then don't turn on interrupts. */
558 class_destroy(dgap_class); 446 return 0;
559failed_class:
560 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
561 return rc;
562} 447}
563 448
564static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 449/*
450 * Given a board pointer, returns whether we turn on altpin or not.
451 */
452static uint dgap_config_get_altpin(struct board_t *bd)
565{ 453{
566 int rc; 454 struct cnode *p;
567 struct board_t *brd;
568 455
569 if (dgap_numboards >= MAXBOARDS) 456 if (!bd)
570 return -EPERM; 457 return 0;
571 458
572 rc = pci_enable_device(pdev); 459 for (p = bd->bd_config; p; p = p->next) {
573 if (rc) 460 if (p->type == ANODE) {
574 return -EIO; 461 /*
462 * check for pcxr types.
463 */
464 return p->u.altpin;
465 }
466 }
575 467
576 brd = dgap_found_board(pdev, ent->driver_data, dgap_numboards); 468 /* If not found, then don't turn on interrupts. */
577 if (IS_ERR(brd)) 469 return 0;
578 return PTR_ERR(brd); 470}
579 471
580 rc = dgap_firmware_load(pdev, ent->driver_data, brd); 472/*
581 if (rc) 473 * Given a specific type of board, if found, detached link and
582 goto cleanup_brd; 474 * returns the first occurrence in the list.
475 */
476static struct cnode *dgap_find_config(int type, int bus, int slot)
477{
478 struct cnode *p, *prev, *prev2, *found;
583 479
584 rc = dgap_alloc_flipbuf(brd); 480 p = &dgap_head;
585 if (rc)
586 goto cleanup_brd;
587 481
588 rc = dgap_tty_register(brd); 482 while (p->next) {
589 if (rc) 483 prev = p;
590 goto free_flipbuf; 484 p = p->next;
591 485
592 rc = dgap_request_irq(brd); 486 if (p->type != BNODE)
593 if (rc) 487 continue;
594 goto unregister_tty;
595 488
596 /* 489 if (p->u.board.type != type)
597 * Do tty device initialization. 490 continue;
598 */
599 rc = dgap_tty_init(brd);
600 if (rc < 0)
601 goto free_irq;
602 491
603 rc = dgap_tty_register_ports(brd); 492 if (p->u.board.v_pcibus &&
604 if (rc) 493 p->u.board.pcibus != bus)
605 goto tty_free; 494 continue;
606 495
607 brd->state = BOARD_READY; 496 if (p->u.board.v_pcislot &&
608 brd->dpastatus = BD_RUNNING; 497 p->u.board.pcislot != slot)
498 continue;
609 499
610 dgap_board[dgap_numboards++] = brd; 500 found = p;
501 /*
502 * Keep walking thru the list till we
503 * find the next board.
504 */
505 while (p->next) {
506 prev2 = p;
507 p = p->next;
611 508
612 return 0; 509 if (p->type != BNODE)
510 continue;
613 511
614tty_free: 512 /*
615 dgap_tty_free(brd); 513 * Mark the end of our 1 board
616free_irq: 514 * chain of configs.
617 dgap_free_irq(brd); 515 */
618unregister_tty: 516 prev2->next = NULL;
619 dgap_tty_unregister(brd);
620free_flipbuf:
621 dgap_free_flipbuf(brd);
622cleanup_brd:
623 dgap_cleanup_nodes();
624 dgap_release_remap(brd);
625 kfree(brd);
626 517
627 return rc; 518 /*
628} 519 * Link the "next" board to the
520 * previous board, effectively
521 * "unlinking" our board from
522 * the main config.
523 */
524 prev->next = p;
629 525
630static void dgap_remove_one(struct pci_dev *dev) 526 return found;
631{ 527 }
632 /* Do Nothing */ 528 /*
529 * It must be the last board in the list.
530 */
531 prev->next = NULL;
532 return found;
533 }
534 return NULL;
633} 535}
634 536
635/* 537/*
636 * dgap_cleanup_module() 538 * Given a board pointer, walks the config link, counting up
637 * 539 * all ports user specified should be on the board.
638 * Module unload. This is where it all ends. 540 * (This does NOT mean they are all actually present right now tho)
639 */ 541 */
640static void dgap_cleanup_module(void) 542static uint dgap_config_get_num_prts(struct board_t *bd)
641{ 543{
642 int i; 544 int count = 0;
643 ulong lock_flags; 545 struct cnode *p;
644
645 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
646 dgap_poll_stop = 1;
647 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
648
649 /* Turn off poller right away. */
650 del_timer_sync(&dgap_poll_timer);
651 546
652 dgap_remove_driver_sysfiles(&dgap_driver); 547 if (!bd)
548 return 0;
653 549
654 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0)); 550 for (p = bd->bd_config; p; p = p->next) {
655 class_destroy(dgap_class);
656 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
657 551
658 for (i = 0; i < dgap_numboards; ++i) { 552 switch (p->type) {
659 dgap_remove_ports_sysfiles(dgap_board[i]); 553 case BNODE:
660 dgap_cleanup_tty(dgap_board[i]); 554 /*
661 dgap_cleanup_board(dgap_board[i]); 555 * check for pcxr types.
556 */
557 if (p->u.board.type > EPCFE)
558 count += p->u.board.nport;
559 break;
560 case CNODE:
561 count += p->u.conc.nport;
562 break;
563 case MNODE:
564 count += p->u.module.nport;
565 break;
566 }
662 } 567 }
663 568 return count;
664 dgap_cleanup_nodes();
665
666 if (dgap_numboards)
667 pci_unregister_driver(&dgap_driver);
668} 569}
669 570
670/* 571static char *dgap_create_config_string(struct board_t *bd, char *string)
671 * dgap_cleanup_board()
672 *
673 * Free all the memory associated with a board
674 */
675static void dgap_cleanup_board(struct board_t *brd)
676{ 572{
677 int i; 573 char *ptr = string;
678 574 struct cnode *p;
679 if (!brd || brd->magic != DGAP_BOARD_MAGIC) 575 struct cnode *q;
680 return; 576 int speed;
681
682 dgap_free_irq(brd);
683
684 tasklet_kill(&brd->helper_tasklet);
685 577
686 dgap_release_remap(brd); 578 if (!bd) {
579 *ptr = 0xff;
580 return string;
581 }
687 582
688 /* Free all allocated channels structs */ 583 for (p = bd->bd_config; p; p = p->next) {
689 for (i = 0; i < MAXPORTS ; i++)
690 kfree(brd->channels[i]);
691 584
692 kfree(brd->flipbuf); 585 switch (p->type) {
693 kfree(brd->flipflagbuf); 586 case LNODE:
587 *ptr = '\0';
588 ptr++;
589 *ptr = p->u.line.speed;
590 ptr++;
591 break;
592 case CNODE:
593 /*
594 * Because the EPC/con concentrators can have EM modules
595 * hanging off of them, we have to walk ahead in the
596 * list and keep adding the number of ports on each EM
597 * to the config. UGH!
598 */
599 speed = p->u.conc.speed;
600 q = p->next;
601 if (q && (q->type == MNODE)) {
602 *ptr = (p->u.conc.nport + 0x80);
603 ptr++;
604 p = q;
605 while (q->next && (q->next->type) == MNODE) {
606 *ptr = (q->u.module.nport + 0x80);
607 ptr++;
608 p = q;
609 q = q->next;
610 }
611 *ptr = q->u.module.nport;
612 ptr++;
613 } else {
614 *ptr = p->u.conc.nport;
615 ptr++;
616 }
694 617
695 dgap_board[brd->boardnum] = NULL; 618 *ptr = speed;
619 ptr++;
620 break;
621 }
622 }
696 623
697 kfree(brd); 624 *ptr = 0xff;
625 return string;
698} 626}
699 627
700/* 628/*
701 * dgap_found_board() 629 * Parse a configuration file read into memory as a string.
702 *
703 * A board has been found, init it.
704 */ 630 */
705static struct board_t *dgap_found_board(struct pci_dev *pdev, int id, 631static int dgap_parsefile(char **in)
706 int boardnum)
707{ 632{
708 struct board_t *brd; 633 struct cnode *p, *brd, *line, *conc;
709 unsigned int pci_irq; 634 int rc;
710 int i; 635 char *s;
711 int ret; 636 int linecnt = 0;
712
713 /* get the board structure and prep it */
714 brd = kzalloc(sizeof(struct board_t), GFP_KERNEL);
715 if (!brd)
716 return ERR_PTR(-ENOMEM);
717 637
718 /* store the info for the board we've found */ 638 p = &dgap_head;
719 brd->magic = DGAP_BOARD_MAGIC; 639 brd = line = conc = NULL;
720 brd->boardnum = boardnum;
721 brd->vendor = dgap_pci_tbl[id].vendor;
722 brd->device = dgap_pci_tbl[id].device;
723 brd->pdev = pdev;
724 brd->pci_bus = pdev->bus->number;
725 brd->pci_slot = PCI_SLOT(pdev->devfn);
726 brd->name = dgap_ids[id].name;
727 brd->maxports = dgap_ids[id].maxports;
728 brd->type = dgap_ids[id].config_type;
729 brd->dpatype = dgap_ids[id].dpatype;
730 brd->dpastatus = BD_NOFEP;
731 init_waitqueue_head(&brd->state_wait);
732 640
733 spin_lock_init(&brd->bd_lock); 641 /* perhaps we are adding to an existing list? */
642 while (p->next)
643 p = p->next;
734 644
735 brd->inhibit_poller = FALSE; 645 /* file must start with a BEGIN */
736 brd->wait_for_bios = 0; 646 while ((rc = dgap_gettok(in)) != BEGIN) {
737 brd->wait_for_fep = 0; 647 if (rc == 0) {
648 pr_err("unexpected EOF");
649 return -1;
650 }
651 }
738 652
739 for (i = 0; i < MAXPORTS; i++) 653 for (; ;) {
740 brd->channels[i] = NULL; 654 int board_type = 0;
655 int conc_type = 0;
656 int module_type = 0;
741 657
742 /* store which card & revision we have */ 658 rc = dgap_gettok(in);
743 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor); 659 if (rc == 0) {
744 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice); 660 pr_err("unexpected EOF");
745 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev); 661 return -1;
662 }
746 663
747 pci_irq = pdev->irq; 664 switch (rc) {
748 brd->irq = pci_irq; 665 case BEGIN: /* should only be 1 begin */
666 pr_err("unexpected config_begin\n");
667 return -1;
749 668
750 /* get the PCI Base Address Registers */ 669 case END:
670 return 0;
751 671
752 /* Xr Jupiter and EPC use BAR 2 */ 672 case BOARD: /* board info */
753 if (brd->device == PCI_DEV_XRJ_DID || brd->device == PCI_DEV_EPCJ_DID) { 673 if (dgap_checknode(p))
754 brd->membase = pci_resource_start(pdev, 2); 674 return -1;
755 brd->membase_end = pci_resource_end(pdev, 2);
756 }
757 /* Everyone else uses BAR 0 */
758 else {
759 brd->membase = pci_resource_start(pdev, 0);
760 brd->membase_end = pci_resource_end(pdev, 0);
761 }
762 675
763 if (!brd->membase) { 676 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
764 ret = -ENODEV; 677 if (!p->next)
765 goto free_brd; 678 return -1;
766 }
767 679
768 if (brd->membase & 1) 680 p = p->next;
769 brd->membase &= ~3;
770 else
771 brd->membase &= ~15;
772 681
773 /* 682 p->type = BNODE;
774 * On the PCI boards, there is no IO space allocated 683 p->u.board.status = kstrdup("No", GFP_KERNEL);
775 * The I/O registers will be in the first 3 bytes of the 684 line = conc = NULL;
776 * upper 2MB of the 4MB memory space. The board memory 685 brd = p;
777 * will be mapped into the low 2MB of the 4MB memory space 686 linecnt = -1;
778 */
779 brd->port = brd->membase + PCI_IO_OFFSET;
780 brd->port_end = brd->port + PCI_IO_SIZE;
781 687
782 /* 688 board_type = dgap_gettok(in);
783 * Special initialization for non-PLX boards 689 if (board_type == 0) {
784 */ 690 pr_err("board !!type not specified");
785 if (brd->device != PCI_DEV_XRJ_DID && brd->device != PCI_DEV_EPCJ_DID) { 691 return -1;
786 unsigned short cmd; 692 }
787 693
788 pci_write_config_byte(pdev, 0x40, 0); 694 p->u.board.type = board_type;
789 pci_write_config_byte(pdev, 0x46, 0);
790 695
791 /* Limit burst length to 2 doubleword transactions */ 696 break;
792 pci_write_config_byte(pdev, 0x42, 1);
793 697
794 /* 698 case IO: /* i/o port */
795 * Enable IO and mem if not already done. 699 if (p->type != BNODE) {
796 * This was needed for support on Itanium. 700 pr_err("IO port only valid for boards");
797 */ 701 return -1;
798 pci_read_config_word(pdev, PCI_COMMAND, &cmd); 702 }
799 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY); 703 s = dgap_getword(in);
800 pci_write_config_word(pdev, PCI_COMMAND, cmd); 704 if (!s) {
801 } 705 pr_err("unexpected end of file");
706 return -1;
707 }
708 p->u.board.portstr = kstrdup(s, GFP_KERNEL);
709 if (kstrtol(s, 0, &p->u.board.port)) {
710 pr_err("bad number for IO port");
711 return -1;
712 }
713 p->u.board.v_port = 1;
714 break;
802 715
803 /* init our poll helper tasklet */ 716 case MEM: /* memory address */
804 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet, 717 if (p->type != BNODE) {
805 (unsigned long) brd); 718 pr_err("memory address only valid for boards");
719 return -1;
720 }
721 s = dgap_getword(in);
722 if (!s) {
723 pr_err("unexpected end of file");
724 return -1;
725 }
726 p->u.board.addrstr = kstrdup(s, GFP_KERNEL);
727 if (kstrtoul(s, 0, &p->u.board.addr)) {
728 pr_err("bad number for memory address");
729 return -1;
730 }
731 p->u.board.v_addr = 1;
732 break;
806 733
807 ret = dgap_do_remap(brd); 734 case PCIINFO: /* pci information */
808 if (ret) 735 if (p->type != BNODE) {
809 goto free_brd; 736 pr_err("memory address only valid for boards");
737 return -1;
738 }
739 s = dgap_getword(in);
740 if (!s) {
741 pr_err("unexpected end of file");
742 return -1;
743 }
744 p->u.board.pcibusstr = kstrdup(s, GFP_KERNEL);
745 if (kstrtoul(s, 0, &p->u.board.pcibus)) {
746 pr_err("bad number for pci bus");
747 return -1;
748 }
749 p->u.board.v_pcibus = 1;
750 s = dgap_getword(in);
751 if (!s) {
752 pr_err("unexpected end of file");
753 return -1;
754 }
755 p->u.board.pcislotstr = kstrdup(s, GFP_KERNEL);
756 if (kstrtoul(s, 0, &p->u.board.pcislot)) {
757 pr_err("bad number for pci slot");
758 return -1;
759 }
760 p->u.board.v_pcislot = 1;
761 break;
810 762
811 pr_info("dgap: board %d: %s (rev %d), irq %ld\n", 763 case METHOD:
812 boardnum, brd->name, brd->rev, brd->irq); 764 if (p->type != BNODE) {
765 pr_err("install method only valid for boards");
766 return -1;
767 }
768 s = dgap_getword(in);
769 if (!s) {
770 pr_err("unexpected end of file");
771 return -1;
772 }
773 p->u.board.method = kstrdup(s, GFP_KERNEL);
774 p->u.board.v_method = 1;
775 break;
813 776
814 return brd; 777 case STATUS:
778 if (p->type != BNODE) {
779 pr_err("config status only valid for boards");
780 return -1;
781 }
782 s = dgap_getword(in);
783 if (!s) {
784 pr_err("unexpected end of file");
785 return -1;
786 }
787 p->u.board.status = kstrdup(s, GFP_KERNEL);
788 break;
815 789
816free_brd: 790 case NPORTS: /* number of ports */
817 kfree(brd); 791 if (p->type == BNODE) {
792 s = dgap_getword(in);
793 if (!s) {
794 pr_err("unexpected end of file");
795 return -1;
796 }
797 if (kstrtol(s, 0, &p->u.board.nport)) {
798 pr_err("bad number for number of ports");
799 return -1;
800 }
801 p->u.board.v_nport = 1;
802 } else if (p->type == CNODE) {
803 s = dgap_getword(in);
804 if (!s) {
805 pr_err("unexpected end of file");
806 return -1;
807 }
808 if (kstrtol(s, 0, &p->u.conc.nport)) {
809 pr_err("bad number for number of ports");
810 return -1;
811 }
812 p->u.conc.v_nport = 1;
813 } else if (p->type == MNODE) {
814 s = dgap_getword(in);
815 if (!s) {
816 pr_err("unexpected end of file");
817 return -1;
818 }
819 if (kstrtol(s, 0, &p->u.module.nport)) {
820 pr_err("bad number for number of ports");
821 return -1;
822 }
823 p->u.module.v_nport = 1;
824 } else {
825 pr_err("nports only valid for concentrators or modules");
826 return -1;
827 }
828 break;
818 829
819 return ERR_PTR(ret); 830 case ID: /* letter ID used in tty name */
820} 831 s = dgap_getword(in);
832 if (!s) {
833 pr_err("unexpected end of file");
834 return -1;
835 }
821 836
837 p->u.board.status = kstrdup(s, GFP_KERNEL);
822 838
823static int dgap_request_irq(struct board_t *brd) 839 if (p->type == CNODE) {
824{ 840 p->u.conc.id = kstrdup(s, GFP_KERNEL);
825 int rc; 841 p->u.conc.v_id = 1;
842 } else if (p->type == MNODE) {
843 p->u.module.id = kstrdup(s, GFP_KERNEL);
844 p->u.module.v_id = 1;
845 } else {
846 pr_err("id only valid for concentrators or modules");
847 return -1;
848 }
849 break;
826 850
827 if (!brd || brd->magic != DGAP_BOARD_MAGIC) 851 case STARTO: /* start offset of ID */
828 return -ENODEV; 852 if (p->type == BNODE) {
853 s = dgap_getword(in);
854 if (!s) {
855 pr_err("unexpected end of file");
856 return -1;
857 }
858 if (kstrtol(s, 0, &p->u.board.start)) {
859 pr_err("bad number for start of tty count");
860 return -1;
861 }
862 p->u.board.v_start = 1;
863 } else if (p->type == CNODE) {
864 s = dgap_getword(in);
865 if (!s) {
866 pr_err("unexpected end of file");
867 return -1;
868 }
869 if (kstrtol(s, 0, &p->u.conc.start)) {
870 pr_err("bad number for start of tty count");
871 return -1;
872 }
873 p->u.conc.v_start = 1;
874 } else if (p->type == MNODE) {
875 s = dgap_getword(in);
876 if (!s) {
877 pr_err("unexpected end of file");
878 return -1;
879 }
880 if (kstrtol(s, 0, &p->u.module.start)) {
881 pr_err("bad number for start of tty count");
882 return -1;
883 }
884 p->u.module.v_start = 1;
885 } else {
886 pr_err("start only valid for concentrators or modules");
887 return -1;
888 }
889 break;
829 890
830 /* 891 case TTYN: /* tty name prefix */
831 * Set up our interrupt handler if we are set to do interrupts. 892 if (dgap_checknode(p))
832 */ 893 return -1;
833 if (dgap_config_get_useintr(brd) && brd->irq) {
834 894
835 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd); 895 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
896 if (!p->next)
897 return -1;
836 898
837 if (!rc) 899 p = p->next;
838 brd->intr_used = 1; 900 p->type = TNODE;
839 }
840 return 0;
841}
842 901
843static void dgap_free_irq(struct board_t *brd) 902 s = dgap_getword(in);
844{ 903 if (!s) {
845 if (brd->intr_used && brd->irq) 904 pr_err("unexpeced end of file");
846 free_irq(brd->irq, brd); 905 return -1;
847} 906 }
907 p->u.ttyname = kstrdup(s, GFP_KERNEL);
908 if (!p->u.ttyname)
909 return -1;
848 910
849static int dgap_firmware_load(struct pci_dev *pdev, int card_type, 911 break;
850 struct board_t *brd)
851{
852 const struct firmware *fw;
853 char *tmp_ptr;
854 int ret;
855 char *dgap_config_buf;
856 912
857 dgap_get_vpd(brd); 913 case CU: /* cu name prefix */
858 dgap_do_reset_board(brd); 914 if (dgap_checknode(p))
915 return -1;
859 916
860 if (fw_info[card_type].conf_name) { 917 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
861 ret = request_firmware(&fw, fw_info[card_type].conf_name, 918 if (!p->next)
862 &pdev->dev); 919 return -1;
863 if (ret) {
864 dev_err(&pdev->dev, "config file %s not found\n",
865 fw_info[card_type].conf_name);
866 return ret;
867 }
868 920
869 dgap_config_buf = kzalloc(fw->size + 1, GFP_KERNEL); 921 p = p->next;
870 if (!dgap_config_buf) { 922 p->type = CUNODE;
871 release_firmware(fw);
872 return -ENOMEM;
873 }
874 923
875 memcpy(dgap_config_buf, fw->data, fw->size); 924 s = dgap_getword(in);
876 release_firmware(fw); 925 if (!s) {
926 pr_err("unexpeced end of file");
927 return -1;
928 }
929 p->u.cuname = kstrdup(s, GFP_KERNEL);
930 if (!p->u.cuname)
931 return -1;
877 932
878 /* 933 break;
879 * preserve dgap_config_buf
880 * as dgap_parsefile would
881 * otherwise alter it.
882 */
883 tmp_ptr = dgap_config_buf;
884 934
885 if (dgap_parsefile(&tmp_ptr) != 0) { 935 case LINE: /* line information */
886 kfree(dgap_config_buf); 936 if (dgap_checknode(p))
887 return -EINVAL; 937 return -1;
888 } 938 if (!brd) {
889 kfree(dgap_config_buf); 939 pr_err("must specify board before line info");
890 } 940 return -1;
941 }
942 switch (brd->u.board.type) {
943 case PPCM:
944 pr_err("line not valid for PC/em");
945 return -1;
946 }
891 947
892 /* 948 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
893 * Match this board to a config the user created for us. 949 if (!p->next)
894 */ 950 return -1;
895 brd->bd_config =
896 dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot);
897 951
898 /* 952 p = p->next;
899 * Because the 4 port Xr products share the same PCI ID 953 p->type = LNODE;
900 * as the 8 port Xr products, if we receive a NULL config 954 conc = NULL;
901 * back, and this is a PAPORT8 board, retry with a 955 line = p;
902 * PAPORT4 attempt as well. 956 linecnt++;
903 */ 957 break;
904 if (brd->type == PAPORT8 && !brd->bd_config)
905 brd->bd_config =
906 dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot);
907 958
908 if (!brd->bd_config) { 959 case CONC: /* concentrator information */
909 dev_err(&pdev->dev, "No valid configuration found\n"); 960 if (dgap_checknode(p))
910 return -EINVAL; 961 return -1;
911 } 962 if (!line) {
963 pr_err("must specify line info before concentrator");
964 return -1;
965 }
912 966
913 if (fw_info[card_type].bios_name) { 967 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
914 ret = request_firmware(&fw, fw_info[card_type].bios_name, 968 if (!p->next)
915 &pdev->dev); 969 return -1;
916 if (ret) {
917 dev_err(&pdev->dev, "bios file %s not found\n",
918 fw_info[card_type].bios_name);
919 return ret;
920 }
921 dgap_do_bios_load(brd, fw->data, fw->size);
922 release_firmware(fw);
923 970
924 /* Wait for BIOS to test board... */ 971 p = p->next;
925 ret = dgap_test_bios(brd); 972 p->type = CNODE;
926 if (ret) 973 conc = p;
927 return ret;
928 }
929 974
930 if (fw_info[card_type].fep_name) { 975 if (linecnt)
931 ret = request_firmware(&fw, fw_info[card_type].fep_name, 976 brd->u.board.conc2++;
932 &pdev->dev); 977 else
933 if (ret) { 978 brd->u.board.conc1++;
934 dev_err(&pdev->dev, "dgap: fep file %s not found\n",
935 fw_info[card_type].fep_name);
936 return ret;
937 }
938 dgap_do_fep_load(brd, fw->data, fw->size);
939 release_firmware(fw);
940 979
941 /* Wait for FEP to load on board... */ 980 conc_type = dgap_gettok(in);
942 ret = dgap_test_fep(brd); 981 if (conc_type == 0 || conc_type != CX ||
943 if (ret) 982 conc_type != EPC) {
944 return ret; 983 pr_err("failed to set a type of concentratros");
945 } 984 return -1;
985 }
946 986
947#ifdef DIGI_CONCENTRATORS_SUPPORTED 987 p->u.conc.type = conc_type;
948 /*
949 * If this is a CX or EPCX, we need to see if the firmware
950 * is requesting a concentrator image from us.
951 */
952 if ((bd->type == PCX) || (bd->type == PEPC)) {
953 chk_addr = (u16 *) (vaddr + DOWNREQ);
954 /* Nonzero if FEP is requesting concentrator image. */
955 check = readw(chk_addr);
956 vaddr = brd->re_map_membase;
957 }
958 988
959 if (fw_info[card_type].con_name && check && vaddr) { 989 break;
960 ret = request_firmware(&fw, fw_info[card_type].con_name,
961 &pdev->dev);
962 if (ret) {
963 dev_err(&pdev->dev, "conc file %s not found\n",
964 fw_info[card_type].con_name);
965 return ret;
966 }
967 /* Put concentrator firmware loading code here */
968 offset = readw((u16 *) (vaddr + DOWNREQ));
969 memcpy_toio(offset, fw->data, fw->size);
970 990
971 dgap_do_conc_load(brd, (char *)fw->data, fw->size) 991 case MOD: /* EBI module */
972 release_firmware(fw); 992 if (dgap_checknode(p))
973 } 993 return -1;
974#endif 994 if (!brd) {
995 pr_err("must specify board info before EBI modules");
996 return -1;
997 }
998 switch (brd->u.board.type) {
999 case PPCM:
1000 linecnt = 0;
1001 break;
1002 default:
1003 if (!conc) {
1004 pr_err("must specify concentrator info before EBI module");
1005 return -1;
1006 }
1007 }
975 1008
976 return 0; 1009 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
977} 1010 if (!p->next)
1011 return -1;
978 1012
979/* 1013 p = p->next;
980 * Remap PCI memory. 1014 p->type = MNODE;
981 */
982static int dgap_do_remap(struct board_t *brd)
983{
984 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
985 return -EIO;
986 1015
987 if (!request_mem_region(brd->membase, 0x200000, "dgap")) 1016 if (linecnt)
988 return -ENOMEM; 1017 brd->u.board.module2++;
1018 else
1019 brd->u.board.module1++;
989 1020
990 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000, 1021 module_type = dgap_gettok(in);
991 "dgap")) { 1022 if (module_type == 0 || module_type != PORTS ||
992 release_mem_region(brd->membase, 0x200000); 1023 module_type != MODEM) {
993 return -ENOMEM; 1024 pr_err("failed to set a type of module");
994 } 1025 return -1;
1026 }
995 1027
996 brd->re_map_membase = ioremap(brd->membase, 0x200000); 1028 p->u.module.type = module_type;
997 if (!brd->re_map_membase) {
998 release_mem_region(brd->membase, 0x200000);
999 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1000 return -ENOMEM;
1001 }
1002 1029
1003 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000); 1030 break;
1004 if (!brd->re_map_port) {
1005 release_mem_region(brd->membase, 0x200000);
1006 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1007 iounmap(brd->re_map_membase);
1008 return -ENOMEM;
1009 }
1010 1031
1011 return 0; 1032 case CABLE:
1012} 1033 if (p->type == LNODE) {
1034 s = dgap_getword(in);
1035 if (!s) {
1036 pr_err("unexpected end of file");
1037 return -1;
1038 }
1039 p->u.line.cable = kstrdup(s, GFP_KERNEL);
1040 p->u.line.v_cable = 1;
1041 }
1042 break;
1013 1043
1014static void dgap_release_remap(struct board_t *brd) 1044 case SPEED: /* sync line speed indication */
1015{ 1045 if (p->type == LNODE) {
1016 if (brd->re_map_membase) { 1046 s = dgap_getword(in);
1017 release_mem_region(brd->membase, 0x200000); 1047 if (!s) {
1018 iounmap(brd->re_map_membase); 1048 pr_err("unexpected end of file");
1019 } 1049 return -1;
1050 }
1051 if (kstrtol(s, 0, &p->u.line.speed)) {
1052 pr_err("bad number for line speed");
1053 return -1;
1054 }
1055 p->u.line.v_speed = 1;
1056 } else if (p->type == CNODE) {
1057 s = dgap_getword(in);
1058 if (!s) {
1059 pr_err("unexpected end of file");
1060 return -1;
1061 }
1062 if (kstrtol(s, 0, &p->u.conc.speed)) {
1063 pr_err("bad number for line speed");
1064 return -1;
1065 }
1066 p->u.conc.v_speed = 1;
1067 } else {
1068 pr_err("speed valid only for lines or concentrators.");
1069 return -1;
1070 }
1071 break;
1020 1072
1021 if (brd->re_map_port) { 1073 case CONNECT:
1022 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000); 1074 if (p->type == CNODE) {
1023 iounmap(brd->re_map_port); 1075 s = dgap_getword(in);
1024 } 1076 if (!s) {
1025} 1077 pr_err("unexpected end of file");
1026/***************************************************************************** 1078 return -1;
1027* 1079 }
1028* Function: 1080 p->u.conc.connect = kstrdup(s, GFP_KERNEL);
1029* 1081 p->u.conc.v_connect = 1;
1030* dgap_poll_handler 1082 }
1031* 1083 break;
1032* Author: 1084 case PRINT: /* transparent print name prefix */
1033* 1085 if (dgap_checknode(p))
1034* Scott H Kilau 1086 return -1;
1035*
1036* Parameters:
1037*
1038* dummy -- ignored
1039*
1040* Return Values:
1041*
1042* none
1043*
1044* Description:
1045*
1046* As each timer expires, it determines (a) whether the "transmit"
1047* waiter needs to be woken up, and (b) whether the poller needs to
1048* be rescheduled.
1049*
1050******************************************************************************/
1051 1087
1052static void dgap_poll_handler(ulong dummy) 1088 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1053{ 1089 if (!p->next)
1054 int i; 1090 return -1;
1055 struct board_t *brd;
1056 unsigned long lock_flags;
1057 ulong new_time;
1058 1091
1059 dgap_poll_counter++; 1092 p = p->next;
1093 p->type = PNODE;
1060 1094
1061 /* 1095 s = dgap_getword(in);
1062 * Do not start the board state machine until 1096 if (!s) {
1063 * driver tells us its up and running, and has 1097 pr_err("unexpeced end of file");
1064 * everything it needs. 1098 return -1;
1065 */ 1099 }
1066 if (dgap_driver_state != DRIVER_READY) 1100 p->u.printname = kstrdup(s, GFP_KERNEL);
1067 goto schedule_poller; 1101 if (!p->u.printname)
1102 return -1;
1068 1103
1069 /* 1104 break;
1070 * If we have just 1 board, or the system is not SMP,
1071 * then use the typical old style poller.
1072 * Otherwise, use our new tasklet based poller, which should
1073 * speed things up for multiple boards.
1074 */
1075 if ((dgap_numboards == 1) || (num_online_cpus() <= 1)) {
1076 for (i = 0; i < dgap_numboards; i++) {
1077 1105
1078 brd = dgap_board[i]; 1106 case CMAJOR: /* major number */
1107 if (dgap_checknode(p))
1108 return -1;
1079 1109
1080 if (brd->state == BOARD_FAILED) 1110 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1081 continue; 1111 if (!p->next)
1082 if (!brd->intr_running) 1112 return -1;
1083 /* Call the real board poller directly */
1084 dgap_poll_tasklet((unsigned long) brd);
1085 }
1086 } else {
1087 /*
1088 * Go thru each board, kicking off a
1089 * tasklet for each if needed
1090 */
1091 for (i = 0; i < dgap_numboards; i++) {
1092 brd = dgap_board[i];
1093 1113
1094 /* 1114 p = p->next;
1095 * Attempt to grab the board lock. 1115 p->type = JNODE;
1096 *
1097 * If we can't get it, no big deal, the next poll
1098 * will get it. Basically, I just really don't want
1099 * to spin in here, because I want to kick off my
1100 * tasklets as fast as I can, and then get out the
1101 * poller.
1102 */
1103 if (!spin_trylock(&brd->bd_lock))
1104 continue;
1105 1116
1106 /* 1117 s = dgap_getword(in);
1107 * If board is in a failed state, don't bother 1118 if (!s) {
1108 * scheduling a tasklet 1119 pr_err("unexpected end of file");
1109 */ 1120 return -1;
1110 if (brd->state == BOARD_FAILED) {
1111 spin_unlock(&brd->bd_lock);
1112 continue;
1113 } 1121 }
1122 if (kstrtol(s, 0, &p->u.majornumber)) {
1123 pr_err("bad number for major number");
1124 return -1;
1125 }
1126 break;
1114 1127
1115 /* Schedule a poll helper task */ 1128 case ALTPIN: /* altpin setting */
1116 if (!brd->intr_running) 1129 if (dgap_checknode(p))
1117 tasklet_schedule(&brd->helper_tasklet); 1130 return -1;
1118
1119 /*
1120 * Can't do DGAP_UNLOCK here, as we don't have
1121 * lock_flags because we did a trylock above.
1122 */
1123 spin_unlock(&brd->bd_lock);
1124 }
1125 }
1126 1131
1127schedule_poller: 1132 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1133 if (!p->next)
1134 return -1;
1128 1135
1129 /* 1136 p = p->next;
1130 * Schedule ourself back at the nominal wakeup interval. 1137 p->type = ANODE;
1131 */
1132 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
1133 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1134 1138
1135 new_time = dgap_poll_time - jiffies; 1139 s = dgap_getword(in);
1140 if (!s) {
1141 pr_err("unexpected end of file");
1142 return -1;
1143 }
1144 if (kstrtol(s, 0, &p->u.altpin)) {
1145 pr_err("bad number for altpin");
1146 return -1;
1147 }
1148 break;
1136 1149
1137 if ((ulong) new_time >= 2 * dgap_poll_tick) { 1150 case USEINTR: /* enable interrupt setting */
1138 dgap_poll_time = 1151 if (dgap_checknode(p))
1139 jiffies + dgap_jiffies_from_ms(dgap_poll_tick); 1152 return -1;
1140 }
1141 1153
1142 dgap_poll_timer.function = dgap_poll_handler; 1154 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1143 dgap_poll_timer.data = 0; 1155 if (!p->next)
1144 dgap_poll_timer.expires = dgap_poll_time; 1156 return -1;
1145 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
1146 1157
1147 if (!dgap_poll_stop) 1158 p = p->next;
1148 add_timer(&dgap_poll_timer); 1159 p->type = INTRNODE;
1149} 1160 s = dgap_getword(in);
1161 if (!s) {
1162 pr_err("unexpected end of file");
1163 return -1;
1164 }
1165 if (kstrtol(s, 0, &p->u.useintr)) {
1166 pr_err("bad number for useintr");
1167 return -1;
1168 }
1169 break;
1150 1170
1151/* 1171 case TTSIZ: /* size of tty structure */
1152 * dgap_intr() 1172 if (dgap_checknode(p))
1153 * 1173 return -1;
1154 * Driver interrupt handler.
1155 */
1156static irqreturn_t dgap_intr(int irq, void *voidbrd)
1157{
1158 struct board_t *brd = (struct board_t *) voidbrd;
1159 1174
1160 if (!brd) 1175 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1161 return IRQ_NONE; 1176 if (!p->next)
1177 return -1;
1162 1178
1163 /* 1179 p = p->next;
1164 * Check to make sure its for us. 1180 p->type = TSNODE;
1165 */
1166 if (brd->magic != DGAP_BOARD_MAGIC)
1167 return IRQ_NONE;
1168 1181
1169 brd->intr_count++; 1182 s = dgap_getword(in);
1183 if (!s) {
1184 pr_err("unexpected end of file");
1185 return -1;
1186 }
1187 if (kstrtol(s, 0, &p->u.ttysize)) {
1188 pr_err("bad number for ttysize");
1189 return -1;
1190 }
1191 break;
1170 1192
1171 /* 1193 case CHSIZ: /* channel structure size */
1172 * Schedule tasklet to run at a better time. 1194 if (dgap_checknode(p))
1173 */ 1195 return -1;
1174 tasklet_schedule(&brd->helper_tasklet);
1175 return IRQ_HANDLED;
1176}
1177 1196
1178/* 1197 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1179 * dgap_init_globals() 1198 if (!p->next)
1180 * 1199 return -1;
1181 * This is where we initialize the globals from the static insmod
1182 * configuration variables. These are declared near the head of
1183 * this file.
1184 */
1185static void dgap_init_globals(void)
1186{
1187 int i;
1188 1200
1189 for (i = 0; i < MAXBOARDS; i++) 1201 p = p->next;
1190 dgap_board[i] = NULL; 1202 p->type = CSNODE;
1191 1203
1192 init_timer(&dgap_poll_timer); 1204 s = dgap_getword(in);
1193} 1205 if (!s) {
1206 pr_err("unexpected end of file");
1207 return -1;
1208 }
1209 if (kstrtol(s, 0, &p->u.chsize)) {
1210 pr_err("bad number for chsize");
1211 return -1;
1212 }
1213 break;
1194 1214
1195/************************************************************************ 1215 case BSSIZ: /* board structure size */
1196 * 1216 if (dgap_checknode(p))
1197 * TTY Initialization/Cleanup Functions 1217 return -1;
1198 *
1199 ************************************************************************/
1200 1218
1201/* 1219 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1202 * dgap_tty_register() 1220 if (!p->next)
1203 * 1221 return -1;
1204 * Init the tty subsystem for this board.
1205 */
1206static int dgap_tty_register(struct board_t *brd)
1207{
1208 int rc;
1209 1222
1210 brd->serial_driver = tty_alloc_driver(MAXPORTS, 0); 1223 p = p->next;
1211 if (IS_ERR(brd->serial_driver)) 1224 p->type = BSNODE;
1212 return PTR_ERR(brd->serial_driver);
1213 1225
1214 snprintf(brd->serial_name, MAXTTYNAMELEN, "tty_dgap_%d_", 1226 s = dgap_getword(in);
1215 brd->boardnum); 1227 if (!s) {
1216 brd->serial_driver->name = brd->serial_name; 1228 pr_err("unexpected end of file");
1217 brd->serial_driver->name_base = 0; 1229 return -1;
1218 brd->serial_driver->major = 0; 1230 }
1219 brd->serial_driver->minor_start = 0; 1231 if (kstrtol(s, 0, &p->u.bssize)) {
1220 brd->serial_driver->type = TTY_DRIVER_TYPE_SERIAL; 1232 pr_err("bad number for bssize");
1221 brd->serial_driver->subtype = SERIAL_TYPE_NORMAL; 1233 return -1;
1222 brd->serial_driver->init_termios = dgap_default_termios; 1234 }
1223 brd->serial_driver->driver_name = DRVSTR; 1235 break;
1224 brd->serial_driver->flags = (TTY_DRIVER_REAL_RAW |
1225 TTY_DRIVER_DYNAMIC_DEV |
1226 TTY_DRIVER_HARDWARE_BREAK);
1227
1228 /* The kernel wants space to store pointers to tty_structs */
1229 brd->serial_driver->ttys =
1230 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1231 if (!brd->serial_driver->ttys) {
1232 rc = -ENOMEM;
1233 goto free_serial_drv;
1234 }
1235 1236
1236 /* 1237 case UNTSIZ: /* sched structure size */
1237 * Entry points for driver. Called by the kernel from 1238 if (dgap_checknode(p))
1238 * tty_io.c and n_tty.c. 1239 return -1;
1239 */
1240 tty_set_operations(brd->serial_driver, &dgap_tty_ops);
1241 1240
1242 /* 1241 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1243 * If we're doing transparent print, we have to do all of the above 1242 if (!p->next)
1244 * again, separately so we don't get the LD confused about what major 1243 return -1;
1245 * we are when we get into the dgap_tty_open() routine.
1246 */
1247 brd->print_driver = tty_alloc_driver(MAXPORTS, 0);
1248 if (IS_ERR(brd->print_driver)) {
1249 rc = PTR_ERR(brd->print_driver);
1250 goto free_serial_drv;
1251 }
1252 1244
1253 snprintf(brd->print_name, MAXTTYNAMELEN, "pr_dgap_%d_", 1245 p = p->next;
1254 brd->boardnum); 1246 p->type = USNODE;
1255 brd->print_driver->name = brd->print_name;
1256 brd->print_driver->name_base = 0;
1257 brd->print_driver->major = 0;
1258 brd->print_driver->minor_start = 0;
1259 brd->print_driver->type = TTY_DRIVER_TYPE_SERIAL;
1260 brd->print_driver->subtype = SERIAL_TYPE_NORMAL;
1261 brd->print_driver->init_termios = dgap_default_termios;
1262 brd->print_driver->driver_name = DRVSTR;
1263 brd->print_driver->flags = (TTY_DRIVER_REAL_RAW |
1264 TTY_DRIVER_DYNAMIC_DEV |
1265 TTY_DRIVER_HARDWARE_BREAK);
1266
1267 /* The kernel wants space to store pointers to tty_structs */
1268 brd->print_driver->ttys =
1269 kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
1270 if (!brd->print_driver->ttys) {
1271 rc = -ENOMEM;
1272 goto free_print_drv;
1273 }
1274 1247
1275 /* 1248 s = dgap_getword(in);
1276 * Entry points for driver. Called by the kernel from 1249 if (!s) {
1277 * tty_io.c and n_tty.c. 1250 pr_err("unexpected end of file");
1278 */ 1251 return -1;
1279 tty_set_operations(brd->print_driver, &dgap_tty_ops); 1252 }
1253 if (kstrtol(s, 0, &p->u.unsize)) {
1254 pr_err("bad number for schedsize");
1255 return -1;
1256 }
1257 break;
1280 1258
1281 /* Register tty devices */ 1259 case F2SIZ: /* f2200 structure size */
1282 rc = tty_register_driver(brd->serial_driver); 1260 if (dgap_checknode(p))
1283 if (rc < 0) 1261 return -1;
1284 goto free_print_drv;
1285 1262
1286 /* Register Transparent Print devices */ 1263 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1287 rc = tty_register_driver(brd->print_driver); 1264 if (!p->next)
1288 if (rc < 0) 1265 return -1;
1289 goto unregister_serial_drv;
1290 1266
1291 dgap_boards_by_major[brd->serial_driver->major] = brd; 1267 p = p->next;
1292 brd->dgap_serial_major = brd->serial_driver->major; 1268 p->type = FSNODE;
1293 1269
1294 dgap_boards_by_major[brd->print_driver->major] = brd; 1270 s = dgap_getword(in);
1295 brd->dgap_transparent_print_major = brd->print_driver->major; 1271 if (!s) {
1272 pr_err("unexpected end of file");
1273 return -1;
1274 }
1275 if (kstrtol(s, 0, &p->u.f2size)) {
1276 pr_err("bad number for f2200size");
1277 return -1;
1278 }
1279 break;
1296 1280
1297 return 0; 1281 case VPSIZ: /* vpix structure size */
1282 if (dgap_checknode(p))
1283 return -1;
1298 1284
1299unregister_serial_drv: 1285 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
1300 tty_unregister_driver(brd->serial_driver); 1286 if (!p->next)
1301free_print_drv: 1287 return -1;
1302 put_tty_driver(brd->print_driver);
1303free_serial_drv:
1304 put_tty_driver(brd->serial_driver);
1305 1288
1306 return rc; 1289 p = p->next;
1307} 1290 p->type = VSNODE;
1308 1291
1309static void dgap_tty_unregister(struct board_t *brd) 1292 s = dgap_getword(in);
1310{ 1293 if (!s) {
1311 tty_unregister_driver(brd->print_driver); 1294 pr_err("unexpected end of file");
1312 tty_unregister_driver(brd->serial_driver); 1295 return -1;
1313 put_tty_driver(brd->print_driver); 1296 }
1314 put_tty_driver(brd->serial_driver); 1297 if (kstrtol(s, 0, &p->u.vpixsize)) {
1298 pr_err("bad number for vpixsize");
1299 return -1;
1300 }
1301 break;
1302 }
1303 }
1315} 1304}
1316 1305
1317/* 1306static void dgap_cleanup_nodes(void)
1318 * dgap_tty_init()
1319 *
1320 * Init the tty subsystem. Called once per board after board has been
1321 * downloaded and init'ed.
1322 */
1323static int dgap_tty_init(struct board_t *brd)
1324{ 1307{
1325 int i; 1308 struct cnode *p;
1326 int tlw;
1327 uint true_count;
1328 u8 __iomem *vaddr;
1329 u8 modem;
1330 struct channel_t *ch;
1331 struct bs_t __iomem *bs;
1332 struct cm_t __iomem *cm;
1333 int ret;
1334
1335 /*
1336 * Initialize board structure elements.
1337 */
1338
1339 vaddr = brd->re_map_membase;
1340 true_count = readw((vaddr + NCHAN));
1341
1342 brd->nasync = dgap_config_get_num_prts(brd);
1343
1344 if (!brd->nasync)
1345 brd->nasync = brd->maxports;
1346 1309
1347 if (brd->nasync > brd->maxports) 1310 p = &dgap_head;
1348 brd->nasync = brd->maxports;
1349 1311
1350 if (true_count != brd->nasync) { 1312 while (p) {
1351 dev_warn(&brd->pdev->dev, 1313 struct cnode *tmp = p->next;
1352 "%s configured for %d ports, has %d ports.\n",
1353 brd->name, brd->nasync, true_count);
1354 1314
1355 if ((brd->type == PPCM) && 1315 if (p->type == NULLNODE) {
1356 (true_count == 64 || true_count == 0)) { 1316 p = tmp;
1357 dev_warn(&brd->pdev->dev, 1317 continue;
1358 "Please make SURE the EBI cable running from the card\n");
1359 dev_warn(&brd->pdev->dev,
1360 "to each EM module is plugged into EBI IN!\n");
1361 } 1318 }
1362 1319
1363 brd->nasync = true_count; 1320 switch (p->type) {
1364 1321 case BNODE:
1365 /* If no ports, don't bother going any further */ 1322 kfree(p->u.board.portstr);
1366 if (!brd->nasync) { 1323 kfree(p->u.board.addrstr);
1367 brd->state = BOARD_FAILED; 1324 kfree(p->u.board.pcibusstr);
1368 brd->dpastatus = BD_NOFEP; 1325 kfree(p->u.board.pcislotstr);
1369 return -EIO; 1326 kfree(p->u.board.method);
1327 break;
1328 case CNODE:
1329 kfree(p->u.conc.id);
1330 kfree(p->u.conc.connect);
1331 break;
1332 case MNODE:
1333 kfree(p->u.module.id);
1334 break;
1335 case TNODE:
1336 kfree(p->u.ttyname);
1337 break;
1338 case CUNODE:
1339 kfree(p->u.cuname);
1340 break;
1341 case LNODE:
1342 kfree(p->u.line.cable);
1343 break;
1344 case PNODE:
1345 kfree(p->u.printname);
1346 break;
1370 } 1347 }
1371 }
1372 1348
1373 /* 1349 kfree(p->u.board.status);
1374 * Allocate channel memory that might not have been allocated 1350 kfree(p);
1375 * when the driver was first loaded. 1351 p = tmp;
1376 */
1377 for (i = 0; i < brd->nasync; i++) {
1378 brd->channels[i] =
1379 kzalloc(sizeof(struct channel_t), GFP_KERNEL);
1380 if (!brd->channels[i]) {
1381 ret = -ENOMEM;
1382 goto free_chan;
1383 }
1384 } 1352 }
1353}
1385 1354
1386 ch = brd->channels[0]; 1355/*
1387 vaddr = brd->re_map_membase; 1356 * Retrives the current custom baud rate from FEP memory,
1388 1357 * and returns it back to the user.
1389 bs = (struct bs_t __iomem *) ((ulong) vaddr + CHANBUF); 1358 * Returns 0 on error.
1390 cm = (struct cm_t __iomem *) ((ulong) vaddr + CMDBUF); 1359 */
1391 1360static uint dgap_get_custom_baud(struct channel_t *ch)
1392 brd->bd_bs = bs; 1361{
1393 1362 u8 __iomem *vaddr;
1394 /* Set up channel variables */ 1363 ulong offset;
1395 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) { 1364 uint value;
1396
1397 spin_lock_init(&ch->ch_lock);
1398
1399 /* Store all our magic numbers */
1400 ch->magic = DGAP_CHANNEL_MAGIC;
1401 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
1402 ch->ch_tun.un_type = DGAP_SERIAL;
1403 ch->ch_tun.un_ch = ch;
1404 ch->ch_tun.un_dev = i;
1405
1406 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
1407 ch->ch_pun.un_type = DGAP_PRINT;
1408 ch->ch_pun.un_ch = ch;
1409 ch->ch_pun.un_dev = i;
1410 1365
1411 ch->ch_vaddr = vaddr; 1366 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1412 ch->ch_bs = bs; 1367 return 0;
1413 ch->ch_cm = cm;
1414 ch->ch_bd = brd;
1415 ch->ch_portnum = i;
1416 ch->ch_digi = dgap_digi_init;
1417 1368
1418 /* 1369 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
1419 * Set up digi dsr and dcd bits based on altpin flag. 1370 return 0;
1420 */
1421 if (dgap_config_get_altpin(brd)) {
1422 ch->ch_dsr = DM_CD;
1423 ch->ch_cd = DM_DSR;
1424 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
1425 } else {
1426 ch->ch_cd = DM_CD;
1427 ch->ch_dsr = DM_DSR;
1428 }
1429 1371
1430 ch->ch_taddr = vaddr + (ioread16(&(ch->ch_bs->tx_seg)) << 4); 1372 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
1431 ch->ch_raddr = vaddr + (ioread16(&(ch->ch_bs->rx_seg)) << 4); 1373 return 0;
1432 ch->ch_tx_win = 0;
1433 ch->ch_rx_win = 0;
1434 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
1435 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
1436 ch->ch_tstart = 0;
1437 ch->ch_rstart = 0;
1438 1374
1439 /* 1375 vaddr = ch->ch_bd->re_map_membase;
1440 * Set queue water marks, interrupt mask,
1441 * and general tty parameters.
1442 */
1443 tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) :
1444 ch->ch_tsize / 2;
1445 ch->ch_tlw = tlw;
1446 1376
1447 dgap_cmdw(ch, STLOW, tlw, 0); 1377 if (!vaddr)
1378 return 0;
1448 1379
1449 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0); 1380 /*
1381 * Go get from fep mem, what the fep
1382 * believes the custom baud rate is.
1383 */
1384 offset = (ioread16(vaddr + ECS_SEG) << 4) + (ch->ch_portnum * 0x28)
1385 + LINE_SPEED;
1450 1386
1451 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0); 1387 value = readw(vaddr + offset);
1388 return value;
1389}
1452 1390
1453 ch->ch_mistat = readb(&(ch->ch_bs->m_stat)); 1391/*
1392 * Remap PCI memory.
1393 */
1394static int dgap_remap(struct board_t *brd)
1395{
1396 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
1397 return -EIO;
1454 1398
1455 init_waitqueue_head(&ch->ch_flags_wait); 1399 if (!request_mem_region(brd->membase, 0x200000, "dgap"))
1456 init_waitqueue_head(&ch->ch_tun.un_flags_wait); 1400 return -ENOMEM;
1457 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
1458 1401
1459 /* Turn on all modem interrupts for now */ 1402 if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000,
1460 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI); 1403 "dgap")) {
1461 writeb(modem, &(ch->ch_bs->m_int)); 1404 release_mem_region(brd->membase, 0x200000);
1405 return -ENOMEM;
1406 }
1462 1407
1463 /* 1408 brd->re_map_membase = ioremap(brd->membase, 0x200000);
1464 * Set edelay to 0 if interrupts are turned on, 1409 if (!brd->re_map_membase) {
1465 * otherwise set edelay to the usual 100. 1410 release_mem_region(brd->membase, 0x200000);
1466 */ 1411 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1467 if (brd->intr_used) 1412 return -ENOMEM;
1468 writew(0, &(ch->ch_bs->edelay)); 1413 }
1469 else
1470 writew(100, &(ch->ch_bs->edelay));
1471 1414
1472 writeb(1, &(ch->ch_bs->idata)); 1415 brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
1416 if (!brd->re_map_port) {
1417 release_mem_region(brd->membase, 0x200000);
1418 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1419 iounmap(brd->re_map_membase);
1420 return -ENOMEM;
1473 } 1421 }
1474 1422
1475 return 0; 1423 return 0;
1476
1477free_chan:
1478 while (--i >= 0) {
1479 kfree(brd->channels[i]);
1480 brd->channels[i] = NULL;
1481 }
1482 return ret;
1483} 1424}
1484 1425
1485/* 1426static void dgap_unmap(struct board_t *brd)
1486 * dgap_tty_free()
1487 *
1488 * Free the channles which are allocated in dgap_tty_init().
1489 */
1490static void dgap_tty_free(struct board_t *brd)
1491{ 1427{
1492 int i; 1428 iounmap(brd->re_map_port);
1493 1429 iounmap(brd->re_map_membase);
1494 for (i = 0; i < brd->nasync; i++) 1430 release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
1495 kfree(brd->channels[i]); 1431 release_mem_region(brd->membase, 0x200000);
1496} 1432}
1433
1497/* 1434/*
1498 * dgap_cleanup_tty() 1435 * dgap_parity_scan()
1499 * 1436 *
1500 * Uninitialize the TTY portion of this driver. Free all memory and 1437 * Convert the FEP5 way of reporting parity errors and breaks into
1501 * resources. 1438 * the Linux line discipline way.
1502 */ 1439 */
1503static void dgap_cleanup_tty(struct board_t *brd) 1440static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
1441 unsigned char *fbuf, int *len)
1504{ 1442{
1505 struct device *dev; 1443 int l = *len;
1506 int i; 1444 int count = 0;
1445 unsigned char *in, *cout, *fout;
1446 unsigned char c;
1507 1447
1508 dgap_boards_by_major[brd->serial_driver->major] = NULL; 1448 in = cbuf;
1509 brd->dgap_serial_major = 0; 1449 cout = cbuf;
1510 for (i = 0; i < brd->nasync; i++) { 1450 fout = fbuf;
1511 tty_port_destroy(&brd->serial_ports[i]);
1512 dev = brd->channels[i]->ch_tun.un_sysfs;
1513 dgap_remove_tty_sysfs(dev);
1514 tty_unregister_device(brd->serial_driver, i);
1515 }
1516 tty_unregister_driver(brd->serial_driver);
1517 put_tty_driver(brd->serial_driver);
1518 kfree(brd->serial_ports);
1519 1451
1520 dgap_boards_by_major[brd->print_driver->major] = NULL; 1452 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1521 brd->dgap_transparent_print_major = 0; 1453 return;
1522 for (i = 0; i < brd->nasync; i++) { 1454
1523 tty_port_destroy(&brd->printer_ports[i]); 1455 while (l--) {
1524 dev = brd->channels[i]->ch_pun.un_sysfs; 1456 c = *in++;
1525 dgap_remove_tty_sysfs(dev); 1457 switch (ch->pscan_state) {
1526 tty_unregister_device(brd->print_driver, i); 1458 default:
1459 /* reset to sanity and fall through */
1460 ch->pscan_state = 0;
1461
1462 case 0:
1463 /* No FF seen yet */
1464 if (c == (unsigned char) '\377')
1465 /* delete this character from stream */
1466 ch->pscan_state = 1;
1467 else {
1468 *cout++ = c;
1469 *fout++ = TTY_NORMAL;
1470 count += 1;
1471 }
1472 break;
1473
1474 case 1:
1475 /* first FF seen */
1476 if (c == (unsigned char) '\377') {
1477 /* doubled ff, transform to single ff */
1478 *cout++ = c;
1479 *fout++ = TTY_NORMAL;
1480 count += 1;
1481 ch->pscan_state = 0;
1482 } else {
1483 /* save value examination in next state */
1484 ch->pscan_savechar = c;
1485 ch->pscan_state = 2;
1486 }
1487 break;
1488
1489 case 2:
1490 /* third character of ff sequence */
1491
1492 *cout++ = c;
1493
1494 if (ch->pscan_savechar == 0x0) {
1495
1496 if (c == 0x0) {
1497 ch->ch_err_break++;
1498 *fout++ = TTY_BREAK;
1499 } else {
1500 ch->ch_err_parity++;
1501 *fout++ = TTY_PARITY;
1502 }
1503 }
1504
1505 count += 1;
1506 ch->pscan_state = 0;
1507 }
1527 } 1508 }
1528 tty_unregister_driver(brd->print_driver); 1509 *len = count;
1529 put_tty_driver(brd->print_driver);
1530 kfree(brd->printer_ports);
1531} 1510}
1532 1511
1533/*======================================================================= 1512/*=======================================================================
@@ -1738,6 +1717,33 @@ static void dgap_input(struct channel_t *ch)
1738 1717
1739} 1718}
1740 1719
1720static void dgap_write_wakeup(struct board_t *bd, struct channel_t *ch,
1721 struct un_t *un, u32 mask,
1722 unsigned long *irq_flags1,
1723 unsigned long *irq_flags2)
1724{
1725 if (!(un->un_flags & mask))
1726 return;
1727
1728 un->un_flags &= ~mask;
1729
1730 if (!(un->un_flags & UN_ISOPEN))
1731 return;
1732
1733 if ((un->un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1734 un->un_tty->ldisc->ops->write_wakeup) {
1735 spin_unlock_irqrestore(&ch->ch_lock, *irq_flags2);
1736 spin_unlock_irqrestore(&bd->bd_lock, *irq_flags1);
1737
1738 (un->un_tty->ldisc->ops->write_wakeup)(un->un_tty);
1739
1740 spin_lock_irqsave(&bd->bd_lock, *irq_flags1);
1741 spin_lock_irqsave(&ch->ch_lock, *irq_flags2);
1742 }
1743 wake_up_interruptible(&un->un_tty->write_wait);
1744 wake_up_interruptible(&un->un_flags_wait);
1745}
1746
1741/************************************************************************ 1747/************************************************************************
1742 * Determines when CARRIER changes state and takes appropriate 1748 * Determines when CARRIER changes state and takes appropriate
1743 * action. 1749 * action.
@@ -1852,163 +1858,1207 @@ static void dgap_carrier(struct channel_t *ch)
1852 ch->ch_flags &= ~CH_CD; 1858 ch->ch_flags &= ~CH_CD;
1853} 1859}
1854 1860
1855/************************************************************************ 1861/*=======================================================================
1856 * 1862 *
1857 * TTY Entry points and helper functions 1863 * dgap_event - FEP to host event processing routine.
1858 * 1864 *
1859 ************************************************************************/ 1865 * bd - Board of current event.
1860
1861/*
1862 * dgap_tty_open()
1863 * 1866 *
1864 */ 1867 *=======================================================================*/
1865static int dgap_tty_open(struct tty_struct *tty, struct file *file) 1868static int dgap_event(struct board_t *bd)
1866{ 1869{
1867 struct board_t *brd;
1868 struct channel_t *ch; 1870 struct channel_t *ch;
1869 struct un_t *un;
1870 struct bs_t __iomem *bs;
1871 uint major;
1872 uint minor;
1873 int rc;
1874 ulong lock_flags; 1871 ulong lock_flags;
1875 ulong lock_flags2; 1872 ulong lock_flags2;
1876 u16 head; 1873 struct bs_t __iomem *bs;
1874 u8 __iomem *event;
1875 u8 __iomem *vaddr;
1876 struct ev_t __iomem *eaddr;
1877 uint head;
1878 uint tail;
1879 int port;
1880 int reason;
1881 int modem;
1882 int b1;
1877 1883
1878 major = MAJOR(tty_devnum(tty)); 1884 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1879 minor = MINOR(tty_devnum(tty)); 1885 return -EIO;
1886
1887 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1888
1889 vaddr = bd->re_map_membase;
1880 1890
1881 if (major > 255) 1891 if (!vaddr) {
1892 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1882 return -EIO; 1893 return -EIO;
1894 }
1883 1895
1884 /* Get board pointer from our array of majors we have allocated */ 1896 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
1885 brd = dgap_boards_by_major[major]; 1897
1886 if (!brd) 1898 /* Get our head and tail */
1899 head = readw(&(eaddr->ev_head));
1900 tail = readw(&(eaddr->ev_tail));
1901
1902 /*
1903 * Forget it if pointers out of range.
1904 */
1905
1906 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
1907 (head | tail) & 03) {
1908 /* Let go of board lock */
1909 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1887 return -EIO; 1910 return -EIO;
1911 }
1888 1912
1889 /* 1913 /*
1890 * If board is not yet up to a state of READY, go to 1914 * Loop to process all the events in the buffer.
1891 * sleep waiting for it to happen or they cancel the open.
1892 */ 1915 */
1893 rc = wait_event_interruptible(brd->state_wait, 1916 while (tail != head) {
1894 (brd->state & BOARD_READY));
1895 1917
1896 if (rc) 1918 /*
1897 return rc; 1919 * Get interrupt information.
1920 */
1898 1921
1899 spin_lock_irqsave(&brd->bd_lock, lock_flags); 1922 event = bd->re_map_membase + tail + EVSTART;
1900 1923
1901 /* The wait above should guarantee this cannot happen */ 1924 port = ioread8(event);
1902 if (brd->state != BOARD_READY) { 1925 reason = ioread8(event + 1);
1903 spin_unlock_irqrestore(&brd->bd_lock, lock_flags); 1926 modem = ioread8(event + 2);
1904 return -EIO; 1927 b1 = ioread8(event + 3);
1928
1929 /*
1930 * Make sure the interrupt is valid.
1931 */
1932 if (port >= bd->nasync)
1933 goto next;
1934
1935 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
1936 goto next;
1937
1938 ch = bd->channels[port];
1939
1940 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1941 goto next;
1942
1943 /*
1944 * If we have made it here, the event was valid.
1945 * Lock down the channel.
1946 */
1947 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1948
1949 bs = ch->ch_bs;
1950
1951 if (!bs) {
1952 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1953 goto next;
1954 }
1955
1956 /*
1957 * Process received data.
1958 */
1959 if (reason & IFDATA) {
1960
1961 /*
1962 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
1963 * input could send some data to ld, which in turn
1964 * could do a callback to one of our other functions.
1965 */
1966 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
1967 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1968
1969 dgap_input(ch);
1970
1971 spin_lock_irqsave(&bd->bd_lock, lock_flags);
1972 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
1973
1974 if (ch->ch_flags & CH_RACTIVE)
1975 ch->ch_flags |= CH_RENABLE;
1976 else
1977 writeb(1, &(bs->idata));
1978
1979 if (ch->ch_flags & CH_RWAIT) {
1980 ch->ch_flags &= ~CH_RWAIT;
1981
1982 wake_up_interruptible
1983 (&ch->ch_tun.un_flags_wait);
1984 }
1985 }
1986
1987 /*
1988 * Process Modem change signals.
1989 */
1990 if (reason & IFMODEM) {
1991 ch->ch_mistat = modem;
1992 dgap_carrier(ch);
1993 }
1994
1995 /*
1996 * Process break.
1997 */
1998 if (reason & IFBREAK) {
1999
2000 if (ch->ch_tun.un_tty) {
2001 /* A break has been indicated */
2002 ch->ch_err_break++;
2003 tty_buffer_request_room
2004 (ch->ch_tun.un_tty->port, 1);
2005 tty_insert_flip_char(ch->ch_tun.un_tty->port,
2006 0, TTY_BREAK);
2007 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
2008 }
2009 }
2010
2011 /*
2012 * Process Transmit low.
2013 */
2014 if (reason & IFTLW) {
2015 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_LOW,
2016 &lock_flags, &lock_flags2);
2017 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_LOW,
2018 &lock_flags, &lock_flags2);
2019 if (ch->ch_flags & CH_WLOW) {
2020 ch->ch_flags &= ~CH_WLOW;
2021 wake_up_interruptible(&ch->ch_flags_wait);
2022 }
2023 }
2024
2025 /*
2026 * Process Transmit empty.
2027 */
2028 if (reason & IFTEM) {
2029 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_EMPTY,
2030 &lock_flags, &lock_flags2);
2031 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_EMPTY,
2032 &lock_flags, &lock_flags2);
2033 if (ch->ch_flags & CH_WEMPTY) {
2034 ch->ch_flags &= ~CH_WEMPTY;
2035 wake_up_interruptible(&ch->ch_flags_wait);
2036 }
2037 }
2038
2039 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
2040
2041next:
2042 tail = (tail + 4) & (EVMAX - EVSTART - 4);
1905 } 2043 }
1906 2044
1907 /* If opened device is greater than our number of ports, bail. */ 2045 writew(tail, &(eaddr->ev_tail));
1908 if (MINOR(tty_devnum(tty)) > brd->nasync) { 2046 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1909 spin_unlock_irqrestore(&brd->bd_lock, lock_flags); 2047
1910 return -EIO; 2048 return 0;
2049}
2050
2051/*
2052 * Our board poller function.
2053 */
2054static void dgap_poll_tasklet(unsigned long data)
2055{
2056 struct board_t *bd = (struct board_t *) data;
2057 ulong lock_flags;
2058 char __iomem *vaddr;
2059 u16 head, tail;
2060
2061 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
2062 return;
2063
2064 if (bd->inhibit_poller)
2065 return;
2066
2067 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2068
2069 vaddr = bd->re_map_membase;
2070
2071 /*
2072 * If board is ready, parse deeper to see if there is anything to do.
2073 */
2074 if (bd->state == BOARD_READY) {
2075
2076 struct ev_t __iomem *eaddr;
2077
2078 if (!bd->re_map_membase) {
2079 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2080 return;
2081 }
2082 if (!bd->re_map_port) {
2083 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2084 return;
2085 }
2086
2087 if (!bd->nasync)
2088 goto out;
2089
2090 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
2091
2092 /* Get our head and tail */
2093 head = readw(&(eaddr->ev_head));
2094 tail = readw(&(eaddr->ev_tail));
2095
2096 /*
2097 * If there is an event pending. Go service it.
2098 */
2099 if (head != tail) {
2100 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2101 dgap_event(bd);
2102 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2103 }
2104
2105out:
2106 /*
2107 * If board is doing interrupts, ACK the interrupt.
2108 */
2109 if (bd && bd->intr_running)
2110 readb(bd->re_map_port + 2);
2111
2112 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
2113 return;
1911 } 2114 }
1912 2115
1913 ch = brd->channels[minor]; 2116 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
1914 if (!ch) { 2117}
1915 spin_unlock_irqrestore(&brd->bd_lock, lock_flags); 2118
1916 return -EIO; 2119/*
2120 * dgap_found_board()
2121 *
2122 * A board has been found, init it.
2123 */
2124static struct board_t *dgap_found_board(struct pci_dev *pdev, int id,
2125 int boardnum)
2126{
2127 struct board_t *brd;
2128 unsigned int pci_irq;
2129 int i;
2130 int ret;
2131
2132 /* get the board structure and prep it */
2133 brd = kzalloc(sizeof(struct board_t), GFP_KERNEL);
2134 if (!brd)
2135 return ERR_PTR(-ENOMEM);
2136
2137 /* store the info for the board we've found */
2138 brd->magic = DGAP_BOARD_MAGIC;
2139 brd->boardnum = boardnum;
2140 brd->vendor = dgap_pci_tbl[id].vendor;
2141 brd->device = dgap_pci_tbl[id].device;
2142 brd->pdev = pdev;
2143 brd->pci_bus = pdev->bus->number;
2144 brd->pci_slot = PCI_SLOT(pdev->devfn);
2145 brd->name = dgap_ids[id].name;
2146 brd->maxports = dgap_ids[id].maxports;
2147 brd->type = dgap_ids[id].config_type;
2148 brd->dpatype = dgap_ids[id].dpatype;
2149 brd->dpastatus = BD_NOFEP;
2150 init_waitqueue_head(&brd->state_wait);
2151
2152 spin_lock_init(&brd->bd_lock);
2153
2154 brd->inhibit_poller = FALSE;
2155 brd->wait_for_bios = 0;
2156 brd->wait_for_fep = 0;
2157
2158 for (i = 0; i < MAXPORTS; i++)
2159 brd->channels[i] = NULL;
2160
2161 /* store which card & revision we have */
2162 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
2163 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
2164 pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
2165
2166 pci_irq = pdev->irq;
2167 brd->irq = pci_irq;
2168
2169 /* get the PCI Base Address Registers */
2170
2171 /* Xr Jupiter and EPC use BAR 2 */
2172 if (brd->device == PCI_DEV_XRJ_DID || brd->device == PCI_DEV_EPCJ_DID) {
2173 brd->membase = pci_resource_start(pdev, 2);
2174 brd->membase_end = pci_resource_end(pdev, 2);
2175 }
2176 /* Everyone else uses BAR 0 */
2177 else {
2178 brd->membase = pci_resource_start(pdev, 0);
2179 brd->membase_end = pci_resource_end(pdev, 0);
1917 } 2180 }
1918 2181
1919 /* Grab channel lock */ 2182 if (!brd->membase) {
1920 spin_lock_irqsave(&ch->ch_lock, lock_flags2); 2183 ret = -ENODEV;
2184 goto free_brd;
2185 }
1921 2186
1922 /* Figure out our type */ 2187 if (brd->membase & 1)
1923 if (major == brd->dgap_serial_major) { 2188 brd->membase &= ~3;
1924 un = &brd->channels[minor]->ch_tun; 2189 else
1925 un->un_type = DGAP_SERIAL; 2190 brd->membase &= ~15;
1926 } else if (major == brd->dgap_transparent_print_major) { 2191
1927 un = &brd->channels[minor]->ch_pun; 2192 /*
1928 un->un_type = DGAP_PRINT; 2193 * On the PCI boards, there is no IO space allocated
2194 * The I/O registers will be in the first 3 bytes of the
2195 * upper 2MB of the 4MB memory space. The board memory
2196 * will be mapped into the low 2MB of the 4MB memory space
2197 */
2198 brd->port = brd->membase + PCI_IO_OFFSET;
2199 brd->port_end = brd->port + PCI_IO_SIZE;
2200
2201 /*
2202 * Special initialization for non-PLX boards
2203 */
2204 if (brd->device != PCI_DEV_XRJ_DID && brd->device != PCI_DEV_EPCJ_DID) {
2205 unsigned short cmd;
2206
2207 pci_write_config_byte(pdev, 0x40, 0);
2208 pci_write_config_byte(pdev, 0x46, 0);
2209
2210 /* Limit burst length to 2 doubleword transactions */
2211 pci_write_config_byte(pdev, 0x42, 1);
2212
2213 /*
2214 * Enable IO and mem if not already done.
2215 * This was needed for support on Itanium.
2216 */
2217 pci_read_config_word(pdev, PCI_COMMAND, &cmd);
2218 cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
2219 pci_write_config_word(pdev, PCI_COMMAND, cmd);
2220 }
2221
2222 /* init our poll helper tasklet */
2223 tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet,
2224 (unsigned long) brd);
2225
2226 ret = dgap_remap(brd);
2227 if (ret)
2228 goto free_brd;
2229
2230 pr_info("dgap: board %d: %s (rev %d), irq %ld\n",
2231 boardnum, brd->name, brd->rev, brd->irq);
2232
2233 return brd;
2234
2235free_brd:
2236 kfree(brd);
2237
2238 return ERR_PTR(ret);
2239}
2240
2241/*
2242 * dgap_intr()
2243 *
2244 * Driver interrupt handler.
2245 */
2246static irqreturn_t dgap_intr(int irq, void *voidbrd)
2247{
2248 struct board_t *brd = voidbrd;
2249
2250 if (!brd)
2251 return IRQ_NONE;
2252
2253 /*
2254 * Check to make sure its for us.
2255 */
2256 if (brd->magic != DGAP_BOARD_MAGIC)
2257 return IRQ_NONE;
2258
2259 brd->intr_count++;
2260
2261 /*
2262 * Schedule tasklet to run at a better time.
2263 */
2264 tasklet_schedule(&brd->helper_tasklet);
2265 return IRQ_HANDLED;
2266}
2267
2268/*****************************************************************************
2269*
2270* Function:
2271*
2272* dgap_poll_handler
2273*
2274* Author:
2275*
2276* Scott H Kilau
2277*
2278* Parameters:
2279*
2280* dummy -- ignored
2281*
2282* Return Values:
2283*
2284* none
2285*
2286* Description:
2287*
2288* As each timer expires, it determines (a) whether the "transmit"
2289* waiter needs to be woken up, and (b) whether the poller needs to
2290* be rescheduled.
2291*
2292******************************************************************************/
2293
2294static void dgap_poll_handler(ulong dummy)
2295{
2296 unsigned int i;
2297 struct board_t *brd;
2298 unsigned long lock_flags;
2299 ulong new_time;
2300
2301 dgap_poll_counter++;
2302
2303 /*
2304 * Do not start the board state machine until
2305 * driver tells us its up and running, and has
2306 * everything it needs.
2307 */
2308 if (dgap_driver_state != DRIVER_READY)
2309 goto schedule_poller;
2310
2311 /*
2312 * If we have just 1 board, or the system is not SMP,
2313 * then use the typical old style poller.
2314 * Otherwise, use our new tasklet based poller, which should
2315 * speed things up for multiple boards.
2316 */
2317 if ((dgap_numboards == 1) || (num_online_cpus() <= 1)) {
2318 for (i = 0; i < dgap_numboards; i++) {
2319
2320 brd = dgap_board[i];
2321
2322 if (brd->state == BOARD_FAILED)
2323 continue;
2324 if (!brd->intr_running)
2325 /* Call the real board poller directly */
2326 dgap_poll_tasklet((unsigned long) brd);
2327 }
1929 } else { 2328 } else {
1930 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); 2329 /*
1931 spin_unlock_irqrestore(&brd->bd_lock, lock_flags); 2330 * Go thru each board, kicking off a
1932 return -EIO; 2331 * tasklet for each if needed
2332 */
2333 for (i = 0; i < dgap_numboards; i++) {
2334 brd = dgap_board[i];
2335
2336 /*
2337 * Attempt to grab the board lock.
2338 *
2339 * If we can't get it, no big deal, the next poll
2340 * will get it. Basically, I just really don't want
2341 * to spin in here, because I want to kick off my
2342 * tasklets as fast as I can, and then get out the
2343 * poller.
2344 */
2345 if (!spin_trylock(&brd->bd_lock))
2346 continue;
2347
2348 /*
2349 * If board is in a failed state, don't bother
2350 * scheduling a tasklet
2351 */
2352 if (brd->state == BOARD_FAILED) {
2353 spin_unlock(&brd->bd_lock);
2354 continue;
2355 }
2356
2357 /* Schedule a poll helper task */
2358 if (!brd->intr_running)
2359 tasklet_schedule(&brd->helper_tasklet);
2360
2361 /*
2362 * Can't do DGAP_UNLOCK here, as we don't have
2363 * lock_flags because we did a trylock above.
2364 */
2365 spin_unlock(&brd->bd_lock);
2366 }
1933 } 2367 }
1934 2368
1935 /* Store our unit into driver_data, so we always have it available. */ 2369schedule_poller:
1936 tty->driver_data = un;
1937 2370
1938 /* 2371 /*
1939 * Error if channel info pointer is NULL. 2372 * Schedule ourself back at the nominal wakeup interval.
1940 */ 2373 */
1941 bs = ch->ch_bs; 2374 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
1942 if (!bs) { 2375 dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
1943 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); 2376
1944 spin_unlock_irqrestore(&brd->bd_lock, lock_flags); 2377 new_time = dgap_poll_time - jiffies;
1945 return -EIO; 2378
2379 if ((ulong) new_time >= 2 * dgap_poll_tick) {
2380 dgap_poll_time =
2381 jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
2382 }
2383
2384 dgap_poll_timer.function = dgap_poll_handler;
2385 dgap_poll_timer.data = 0;
2386 dgap_poll_timer.expires = dgap_poll_time;
2387 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
2388
2389 if (!dgap_poll_stop)
2390 add_timer(&dgap_poll_timer);
2391}
2392
2393/*=======================================================================
2394 *
2395 * dgap_cmdb - Sends a 2 byte command to the FEP.
2396 *
2397 * ch - Pointer to channel structure.
2398 * cmd - Command to be sent.
2399 * byte1 - Integer containing first byte to be sent.
2400 * byte2 - Integer containing second byte to be sent.
2401 * ncmds - Wait until ncmds or fewer cmds are left
2402 * in the cmd buffer before returning.
2403 *
2404 *=======================================================================*/
2405static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
2406 u8 byte2, uint ncmds)
2407{
2408 char __iomem *vaddr;
2409 struct __iomem cm_t *cm_addr;
2410 uint count;
2411 uint n;
2412 u16 head;
2413 u16 tail;
2414
2415 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2416 return;
2417
2418 /*
2419 * Check if board is still alive.
2420 */
2421 if (ch->ch_bd->state == BOARD_FAILED)
2422 return;
2423
2424 /*
2425 * Make sure the pointers are in range before
2426 * writing to the FEP memory.
2427 */
2428 vaddr = ch->ch_bd->re_map_membase;
2429
2430 if (!vaddr)
2431 return;
2432
2433 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
2434 head = readw(&(cm_addr->cm_head));
2435
2436 /*
2437 * Forget it if pointers out of range.
2438 */
2439 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
2440 ch->ch_bd->state = BOARD_FAILED;
2441 return;
1946 } 2442 }
1947 2443
1948 /* 2444 /*
1949 * Initialize tty's 2445 * Put the data in the circular command buffer.
1950 */ 2446 */
1951 if (!(un->un_flags & UN_ISOPEN)) { 2447 writeb(cmd, (vaddr + head + CMDSTART + 0));
1952 /* Store important variables. */ 2448 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
1953 un->un_tty = tty; 2449 writeb(byte1, (vaddr + head + CMDSTART + 2));
2450 writeb(byte2, (vaddr + head + CMDSTART + 3));
1954 2451
1955 /* Maybe do something here to the TTY struct as well? */ 2452 head = (head + 4) & (CMDMAX - CMDSTART - 4);
2453
2454 writew(head, &(cm_addr->cm_head));
2455
2456 /*
2457 * Wait if necessary before updating the head
2458 * pointer to limit the number of outstanding
2459 * commands to the FEP. If the time spent waiting
2460 * is outlandish, declare the FEP dead.
2461 */
2462 for (count = dgap_count ;;) {
2463
2464 head = readw(&(cm_addr->cm_head));
2465 tail = readw(&(cm_addr->cm_tail));
2466
2467 n = (head - tail) & (CMDMAX - CMDSTART - 4);
2468
2469 if (n <= ncmds * sizeof(struct cm_t))
2470 break;
2471
2472 if (--count == 0) {
2473 ch->ch_bd->state = BOARD_FAILED;
2474 return;
2475 }
2476 udelay(10);
1956 } 2477 }
2478}
2479
2480/*=======================================================================
2481 *
2482 * dgap_cmdw - Sends a 1 word command to the FEP.
2483 *
2484 * ch - Pointer to channel structure.
2485 * cmd - Command to be sent.
2486 * word - Integer containing word to be sent.
2487 * ncmds - Wait until ncmds or fewer cmds are left
2488 * in the cmd buffer before returning.
2489 *
2490 *=======================================================================*/
2491static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds)
2492{
2493 char __iomem *vaddr;
2494 struct __iomem cm_t *cm_addr;
2495 uint count;
2496 uint n;
2497 u16 head;
2498 u16 tail;
2499
2500 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2501 return;
1957 2502
1958 /* 2503 /*
1959 * Initialize if neither terminal or printer is open. 2504 * Check if board is still alive.
1960 */ 2505 */
1961 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) { 2506 if (ch->ch_bd->state == BOARD_FAILED)
2507 return;
1962 2508
1963 ch->ch_mforce = 0; 2509 /*
1964 ch->ch_mval = 0; 2510 * Make sure the pointers are in range before
2511 * writing to the FEP memory.
2512 */
2513 vaddr = ch->ch_bd->re_map_membase;
2514 if (!vaddr)
2515 return;
2516
2517 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
2518 head = readw(&(cm_addr->cm_head));
2519
2520 /*
2521 * Forget it if pointers out of range.
2522 */
2523 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
2524 ch->ch_bd->state = BOARD_FAILED;
2525 return;
2526 }
2527
2528 /*
2529 * Put the data in the circular command buffer.
2530 */
2531 writeb(cmd, (vaddr + head + CMDSTART + 0));
2532 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
2533 writew((u16) word, (vaddr + head + CMDSTART + 2));
2534
2535 head = (head + 4) & (CMDMAX - CMDSTART - 4);
2536
2537 writew(head, &(cm_addr->cm_head));
2538
2539 /*
2540 * Wait if necessary before updating the head
2541 * pointer to limit the number of outstanding
2542 * commands to the FEP. If the time spent waiting
2543 * is outlandish, declare the FEP dead.
2544 */
2545 for (count = dgap_count ;;) {
2546
2547 head = readw(&(cm_addr->cm_head));
2548 tail = readw(&(cm_addr->cm_tail));
2549
2550 n = (head - tail) & (CMDMAX - CMDSTART - 4);
2551
2552 if (n <= ncmds * sizeof(struct cm_t))
2553 break;
2554
2555 if (--count == 0) {
2556 ch->ch_bd->state = BOARD_FAILED;
2557 return;
2558 }
2559 udelay(10);
2560 }
2561}
2562
2563/*=======================================================================
2564 *
2565 * dgap_cmdw_ext - Sends a extended word command to the FEP.
2566 *
2567 * ch - Pointer to channel structure.
2568 * cmd - Command to be sent.
2569 * word - Integer containing word to be sent.
2570 * ncmds - Wait until ncmds or fewer cmds are left
2571 * in the cmd buffer before returning.
2572 *
2573 *=======================================================================*/
2574static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
2575{
2576 char __iomem *vaddr;
2577 struct __iomem cm_t *cm_addr;
2578 uint count;
2579 uint n;
2580 u16 head;
2581 u16 tail;
2582
2583 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2584 return;
2585
2586 /*
2587 * Check if board is still alive.
2588 */
2589 if (ch->ch_bd->state == BOARD_FAILED)
2590 return;
2591
2592 /*
2593 * Make sure the pointers are in range before
2594 * writing to the FEP memory.
2595 */
2596 vaddr = ch->ch_bd->re_map_membase;
2597 if (!vaddr)
2598 return;
2599
2600 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
2601 head = readw(&(cm_addr->cm_head));
2602
2603 /*
2604 * Forget it if pointers out of range.
2605 */
2606 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
2607 ch->ch_bd->state = BOARD_FAILED;
2608 return;
2609 }
2610
2611 /*
2612 * Put the data in the circular command buffer.
2613 */
2614
2615 /* Write an FF to tell the FEP that we want an extended command */
2616 writeb((u8) 0xff, (vaddr + head + CMDSTART + 0));
2617
2618 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
2619 writew((u16) cmd, (vaddr + head + CMDSTART + 2));
2620
2621 /*
2622 * If the second part of the command won't fit,
2623 * put it at the beginning of the circular buffer.
2624 */
2625 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
2626 writew((u16) word, (vaddr + CMDSTART));
2627 else
2628 writew((u16) word, (vaddr + head + CMDSTART + 4));
2629
2630 head = (head + 8) & (CMDMAX - CMDSTART - 4);
2631
2632 writew(head, &(cm_addr->cm_head));
2633
2634 /*
2635 * Wait if necessary before updating the head
2636 * pointer to limit the number of outstanding
2637 * commands to the FEP. If the time spent waiting
2638 * is outlandish, declare the FEP dead.
2639 */
2640 for (count = dgap_count ;;) {
2641
2642 head = readw(&(cm_addr->cm_head));
2643 tail = readw(&(cm_addr->cm_tail));
2644
2645 n = (head - tail) & (CMDMAX - CMDSTART - 4);
2646
2647 if (n <= ncmds * sizeof(struct cm_t))
2648 break;
2649
2650 if (--count == 0) {
2651 ch->ch_bd->state = BOARD_FAILED;
2652 return;
2653 }
2654 udelay(10);
2655 }
2656}
2657
2658/*=======================================================================
2659 *
2660 * dgap_wmove - Write data to FEP buffer.
2661 *
2662 * ch - Pointer to channel structure.
2663 * buf - Poiter to characters to be moved.
2664 * cnt - Number of characters to move.
2665 *
2666 *=======================================================================*/
2667static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
2668{
2669 int n;
2670 char __iomem *taddr;
2671 struct bs_t __iomem *bs;
2672 u16 head;
2673
2674 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2675 return;
2676
2677 /*
2678 * Check parameters.
2679 */
2680 bs = ch->ch_bs;
2681 head = readw(&(bs->tx_head));
2682
2683 /*
2684 * If pointers are out of range, just return.
2685 */
2686 if ((cnt > ch->ch_tsize) ||
2687 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
2688 return;
2689
2690 /*
2691 * If the write wraps over the top of the circular buffer,
2692 * move the portion up to the wrap point, and reset the
2693 * pointers to the bottom.
2694 */
2695 n = ch->ch_tstart + ch->ch_tsize - head;
2696
2697 if (cnt >= n) {
2698 cnt -= n;
2699 taddr = ch->ch_taddr + head;
2700 memcpy_toio(taddr, buf, n);
2701 head = ch->ch_tstart;
2702 buf += n;
2703 }
2704
2705 /*
2706 * Move rest of data.
2707 */
2708 taddr = ch->ch_taddr + head;
2709 n = cnt;
2710 memcpy_toio(taddr, buf, n);
2711 head += cnt;
2712
2713 writew(head, &(bs->tx_head));
2714}
2715
2716/*
2717 * Calls the firmware to reset this channel.
2718 */
2719static void dgap_firmware_reset_port(struct channel_t *ch)
2720{
2721 dgap_cmdb(ch, CHRESET, 0, 0, 0);
2722
2723 /*
2724 * Now that the channel is reset, we need to make sure
2725 * all the current settings get reapplied to the port
2726 * in the firmware.
2727 *
2728 * So we will set the driver's cache of firmware
2729 * settings all to 0, and then call param.
2730 */
2731 ch->ch_fepiflag = 0;
2732 ch->ch_fepcflag = 0;
2733 ch->ch_fepoflag = 0;
2734 ch->ch_fepstartc = 0;
2735 ch->ch_fepstopc = 0;
2736 ch->ch_fepastartc = 0;
2737 ch->ch_fepastopc = 0;
2738 ch->ch_mostat = 0;
2739 ch->ch_hflow = 0;
2740}
2741
2742/*=======================================================================
2743 *
2744 * dgap_param - Set Digi parameters.
2745 *
2746 * struct tty_struct * - TTY for port.
2747 *
2748 *=======================================================================*/
2749static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type)
2750{
2751 u16 head;
2752 u16 cflag;
2753 u16 iflag;
2754 u8 mval;
2755 u8 hflow;
2756
2757 /*
2758 * If baud rate is zero, flush queues, and set mval to drop DTR.
2759 */
2760 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
2761
2762 /* flush rx */
2763 head = readw(&(ch->ch_bs->rx_head));
2764 writew(head, &(ch->ch_bs->rx_tail));
2765
2766 /* flush tx */
2767 head = readw(&(ch->ch_bs->tx_head));
2768 writew(head, &(ch->ch_bs->tx_tail));
1965 2769
2770 ch->ch_flags |= (CH_BAUD0);
2771
2772 /* Drop RTS and DTR */
2773 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
2774 mval = D_DTR(ch) | D_RTS(ch);
2775 ch->ch_baud_info = 0;
2776
2777 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
1966 /* 2778 /*
1967 * Flush input queue. 2779 * Tell the fep to do the command
1968 */ 2780 */
1969 head = readw(&(bs->rx_head));
1970 writew(head, &(bs->rx_tail));
1971 2781
1972 ch->ch_flags = 0; 2782 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
1973 ch->pscan_state = 0;
1974 ch->pscan_savechar = 0;
1975 2783
1976 ch->ch_c_cflag = tty->termios.c_cflag; 2784 /*
1977 ch->ch_c_iflag = tty->termios.c_iflag; 2785 * Now go get from fep mem, what the fep
1978 ch->ch_c_oflag = tty->termios.c_oflag; 2786 * believes the custom baud rate is.
1979 ch->ch_c_lflag = tty->termios.c_lflag; 2787 */
1980 ch->ch_startc = tty->termios.c_cc[VSTART]; 2788 ch->ch_custom_speed = dgap_get_custom_baud(ch);
1981 ch->ch_stopc = tty->termios.c_cc[VSTOP]; 2789 ch->ch_baud_info = ch->ch_custom_speed;
1982 2790
1983 /* TODO: flush our TTY struct here? */ 2791 /* Handle transition from B0 */
2792 if (ch->ch_flags & CH_BAUD0) {
2793 ch->ch_flags &= ~(CH_BAUD0);
2794 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
2795 }
2796 mval = D_DTR(ch) | D_RTS(ch);
2797
2798 } else {
2799 /*
2800 * Set baud rate, character size, and parity.
2801 */
2802
2803
2804 int iindex = 0;
2805 int jindex = 0;
2806 int baud = 0;
2807
2808 ulong bauds[4][16] = {
2809 { /* slowbaud */
2810 0, 50, 75, 110,
2811 134, 150, 200, 300,
2812 600, 1200, 1800, 2400,
2813 4800, 9600, 19200, 38400 },
2814 { /* slowbaud & CBAUDEX */
2815 0, 57600, 115200, 230400,
2816 460800, 150, 200, 921600,
2817 600, 1200, 1800, 2400,
2818 4800, 9600, 19200, 38400 },
2819 { /* fastbaud */
2820 0, 57600, 76800, 115200,
2821 14400, 57600, 230400, 76800,
2822 115200, 230400, 28800, 460800,
2823 921600, 9600, 19200, 38400 },
2824 { /* fastbaud & CBAUDEX */
2825 0, 57600, 115200, 230400,
2826 460800, 150, 200, 921600,
2827 600, 1200, 1800, 2400,
2828 4800, 9600, 19200, 38400 }
2829 };
2830
2831 /*
2832 * Only use the TXPrint baud rate if the
2833 * terminal unit is NOT open
2834 */
2835 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
2836 un_type == DGAP_PRINT)
2837 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
2838 else
2839 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
2840
2841 if (ch->ch_c_cflag & CBAUDEX)
2842 iindex = 1;
2843
2844 if (ch->ch_digi.digi_flags & DIGI_FAST)
2845 iindex += 2;
2846
2847 jindex = baud;
2848
2849 if ((iindex >= 0) && (iindex < 4) &&
2850 (jindex >= 0) && (jindex < 16))
2851 baud = bauds[iindex][jindex];
2852 else
2853 baud = 0;
2854
2855 if (baud == 0)
2856 baud = 9600;
2857
2858 ch->ch_baud_info = baud;
2859
2860 /*
2861 * CBAUD has bit position 0x1000 set these days to
2862 * indicate Linux baud rate remap.
2863 * We use a different bit assignment for high speed.
2864 * Clear this bit out while grabbing the parts of
2865 * "cflag" we want.
2866 */
2867 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
2868 CSTOPB | CSIZE);
2869
2870 /*
2871 * HUPCL bit is used by FEP to indicate fast baud
2872 * table is to be used.
2873 */
2874 if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
2875 (ch->ch_c_cflag & CBAUDEX))
2876 cflag |= HUPCL;
2877
2878 if ((ch->ch_c_cflag & CBAUDEX) &&
2879 !(ch->ch_digi.digi_flags & DIGI_FAST)) {
2880 /*
2881 * The below code is trying to guarantee that only
2882 * baud rates 115200, 230400, 460800, 921600 are
2883 * remapped. We use exclusive or because the various
2884 * baud rates share common bit positions and therefore
2885 * can't be tested for easily.
2886 */
2887 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
2888 int baudpart = 0;
2889
2890 /*
2891 * Map high speed requests to index
2892 * into FEP's baud table
2893 */
2894 switch (tcflag) {
2895 case B57600:
2896 baudpart = 1;
2897 break;
2898#ifdef B76800
2899 case B76800:
2900 baudpart = 2;
2901 break;
2902#endif
2903 case B115200:
2904 baudpart = 3;
2905 break;
2906 case B230400:
2907 baudpart = 9;
2908 break;
2909 case B460800:
2910 baudpart = 11;
2911 break;
2912#ifdef B921600
2913 case B921600:
2914 baudpart = 12;
2915 break;
2916#endif
2917 default:
2918 baudpart = 0;
2919 }
2920
2921 if (baudpart)
2922 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
2923 }
2924
2925 cflag &= 0xffff;
2926
2927 if (cflag != ch->ch_fepcflag) {
2928 ch->ch_fepcflag = (u16) (cflag & 0xffff);
2929
2930 /*
2931 * Okay to have channel and board
2932 * locks held calling this
2933 */
2934 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
2935 }
2936
2937 /* Handle transition from B0 */
2938 if (ch->ch_flags & CH_BAUD0) {
2939 ch->ch_flags &= ~(CH_BAUD0);
2940 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
2941 }
2942 mval = D_DTR(ch) | D_RTS(ch);
1984 } 2943 }
1985 2944
1986 dgap_carrier(ch);
1987 /* 2945 /*
1988 * Run param in case we changed anything 2946 * Get input flags.
1989 */ 2947 */
1990 dgap_param(ch, brd, un->un_type); 2948 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
2949 INPCK | ISTRIP | IXON | IXANY | IXOFF);
2950
2951 if ((ch->ch_startc == _POSIX_VDISABLE) ||
2952 (ch->ch_stopc == _POSIX_VDISABLE)) {
2953 iflag &= ~(IXON | IXOFF);
2954 ch->ch_c_iflag &= ~(IXON | IXOFF);
2955 }
1991 2956
1992 /* 2957 /*
1993 * follow protocol for opening port 2958 * Only the IBM Xr card can switch between
2959 * 232 and 422 modes on the fly
2960 */
2961 if (bd->device == PCI_DEV_XR_IBM_DID) {
2962 if (ch->ch_digi.digi_flags & DIGI_422)
2963 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
2964 else
2965 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
2966 }
2967
2968 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
2969 iflag |= IALTPIN;
2970
2971 if (iflag != ch->ch_fepiflag) {
2972 ch->ch_fepiflag = iflag;
2973
2974 /* Okay to have channel and board locks held calling this */
2975 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
2976 }
2977
2978 /*
2979 * Select hardware handshaking.
1994 */ 2980 */
2981 hflow = 0;
1995 2982
1996 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); 2983 if (ch->ch_c_cflag & CRTSCTS)
1997 spin_unlock_irqrestore(&brd->bd_lock, lock_flags); 2984 hflow |= (D_RTS(ch) | D_CTS(ch));
2985 if (ch->ch_digi.digi_flags & RTSPACE)
2986 hflow |= D_RTS(ch);
2987 if (ch->ch_digi.digi_flags & DTRPACE)
2988 hflow |= D_DTR(ch);
2989 if (ch->ch_digi.digi_flags & CTSPACE)
2990 hflow |= D_CTS(ch);
2991 if (ch->ch_digi.digi_flags & DSRPACE)
2992 hflow |= D_DSR(ch);
2993 if (ch->ch_digi.digi_flags & DCDPACE)
2994 hflow |= D_CD(ch);
1998 2995
1999 rc = dgap_block_til_ready(tty, file, ch); 2996 if (hflow != ch->ch_hflow) {
2997 ch->ch_hflow = hflow;
2000 2998
2001 if (!un->un_tty) 2999 /* Okay to have channel and board locks held calling this */
2002 return -ENODEV; 3000 dgap_cmdb(ch, SHFLOW, (u8) hflow, 0xff, 0);
3001 }
2003 3002
2004 /* No going back now, increment our unit and channel counters */ 3003 /*
2005 spin_lock_irqsave(&ch->ch_lock, lock_flags); 3004 * Set RTS and/or DTR Toggle if needed,
2006 ch->ch_open_count++; 3005 * but only if product is FEP5+ based.
2007 un->un_open_count++; 3006 */
2008 un->un_flags |= (UN_ISOPEN); 3007 if (bd->bd_flags & BD_FEP5PLUS) {
2009 spin_unlock_irqrestore(&ch->ch_lock, lock_flags); 3008 u16 hflow2 = 0;
2010 3009
2011 return rc; 3010 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
3011 hflow2 |= (D_RTS(ch));
3012 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
3013 hflow2 |= (D_DTR(ch));
3014
3015 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
3016 }
3017
3018 /*
3019 * Set modem control lines.
3020 */
3021
3022 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
3023
3024 if (ch->ch_mostat ^ mval) {
3025 ch->ch_mostat = mval;
3026
3027 /* Okay to have channel and board locks held calling this */
3028 dgap_cmdb(ch, SMODEM, (u8) mval, D_RTS(ch)|D_DTR(ch), 0);
3029 }
3030
3031 /*
3032 * Read modem signals, and then call carrier function.
3033 */
3034 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
3035 dgap_carrier(ch);
3036
3037 /*
3038 * Set the start and stop characters.
3039 */
3040 if (ch->ch_startc != ch->ch_fepstartc ||
3041 ch->ch_stopc != ch->ch_fepstopc) {
3042 ch->ch_fepstartc = ch->ch_startc;
3043 ch->ch_fepstopc = ch->ch_stopc;
3044
3045 /* Okay to have channel and board locks held calling this */
3046 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
3047 }
3048
3049 /*
3050 * Set the Auxiliary start and stop characters.
3051 */
3052 if (ch->ch_astartc != ch->ch_fepastartc ||
3053 ch->ch_astopc != ch->ch_fepastopc) {
3054 ch->ch_fepastartc = ch->ch_astartc;
3055 ch->ch_fepastopc = ch->ch_astopc;
3056
3057 /* Okay to have channel and board locks held calling this */
3058 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
3059 }
3060
3061 return 0;
2012} 3062}
2013 3063
2014/* 3064/*
@@ -2143,15 +3193,18 @@ static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
2143} 3193}
2144 3194
2145/* 3195/*
2146 * dgap_tty_hangup() 3196 * dgap_tty_flush_buffer()
2147 * 3197 *
2148 * Hangup the port. Like a close, but don't wait for output to drain. 3198 * Flush Tx buffer (make in == out)
2149 */ 3199 */
2150static void dgap_tty_hangup(struct tty_struct *tty) 3200static void dgap_tty_flush_buffer(struct tty_struct *tty)
2151{ 3201{
2152 struct board_t *bd; 3202 struct board_t *bd;
2153 struct channel_t *ch; 3203 struct channel_t *ch;
2154 struct un_t *un; 3204 struct un_t *un;
3205 ulong lock_flags;
3206 ulong lock_flags2;
3207 u16 head;
2155 3208
2156 if (!tty || tty->magic != TTY_MAGIC) 3209 if (!tty || tty->magic != TTY_MAGIC)
2157 return; 3210 return;
@@ -2168,21 +3221,39 @@ static void dgap_tty_hangup(struct tty_struct *tty)
2168 if (!bd || bd->magic != DGAP_BOARD_MAGIC) 3221 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2169 return; 3222 return;
2170 3223
2171 /* flush the transmit queues */ 3224 spin_lock_irqsave(&bd->bd_lock, lock_flags);
2172 dgap_tty_flush_buffer(tty); 3225 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3226
3227 ch->ch_flags &= ~CH_STOP;
3228 head = readw(&(ch->ch_bs->tx_head));
3229 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3230 dgap_cmdw(ch, RESUMETX, 0, 0);
3231 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3232 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3233 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3234 }
3235 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3236 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3237 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3238 }
3239
3240 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3241 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3242 if (waitqueue_active(&tty->write_wait))
3243 wake_up_interruptible(&tty->write_wait);
3244 tty_wakeup(tty);
2173} 3245}
2174 3246
2175/* 3247/*
2176 * dgap_tty_close() 3248 * dgap_tty_hangup()
2177 * 3249 *
3250 * Hangup the port. Like a close, but don't wait for output to drain.
2178 */ 3251 */
2179static void dgap_tty_close(struct tty_struct *tty, struct file *file) 3252static void dgap_tty_hangup(struct tty_struct *tty)
2180{ 3253{
2181 struct ktermios *ts;
2182 struct board_t *bd; 3254 struct board_t *bd;
2183 struct channel_t *ch; 3255 struct channel_t *ch;
2184 struct un_t *un; 3256 struct un_t *un;
2185 ulong lock_flags;
2186 3257
2187 if (!tty || tty->magic != TTY_MAGIC) 3258 if (!tty || tty->magic != TTY_MAGIC)
2188 return; 3259 return;
@@ -2199,107 +3270,8 @@ static void dgap_tty_close(struct tty_struct *tty, struct file *file)
2199 if (!bd || bd->magic != DGAP_BOARD_MAGIC) 3270 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2200 return; 3271 return;
2201 3272
2202 ts = &tty->termios; 3273 /* flush the transmit queues */
2203 3274 dgap_tty_flush_buffer(tty);
2204 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2205
2206 /*
2207 * Determine if this is the last close or not - and if we agree about
2208 * which type of close it is with the Line Discipline
2209 */
2210 if ((tty->count == 1) && (un->un_open_count != 1)) {
2211 /*
2212 * Uh, oh. tty->count is 1, which means that the tty
2213 * structure will be freed. un_open_count should always
2214 * be one in these conditions. If it's greater than
2215 * one, we've got real problems, since it means the
2216 * serial port won't be shutdown.
2217 */
2218 un->un_open_count = 1;
2219 }
2220
2221 if (--un->un_open_count < 0)
2222 un->un_open_count = 0;
2223
2224 ch->ch_open_count--;
2225
2226 if (ch->ch_open_count && un->un_open_count) {
2227 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2228 return;
2229 }
2230
2231 /* OK, its the last close on the unit */
2232
2233 un->un_flags |= UN_CLOSING;
2234
2235 tty->closing = 1;
2236
2237 /*
2238 * Only officially close channel if count is 0 and
2239 * DIGI_PRINTER bit is not set.
2240 */
2241 if ((ch->ch_open_count == 0) &&
2242 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
2243
2244 ch->ch_flags &= ~(CH_RXBLOCK);
2245
2246 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2247
2248 /* wait for output to drain */
2249 /* This will also return if we take an interrupt */
2250
2251 dgap_wait_for_drain(tty);
2252
2253 dgap_tty_flush_buffer(tty);
2254 tty_ldisc_flush(tty);
2255
2256 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2257
2258 tty->closing = 0;
2259
2260 /*
2261 * If we have HUPCL set, lower DTR and RTS
2262 */
2263 if (ch->ch_c_cflag & HUPCL) {
2264 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
2265 dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0);
2266
2267 /*
2268 * Go to sleep to ensure RTS/DTR
2269 * have been dropped for modems to see it.
2270 */
2271 spin_unlock_irqrestore(&ch->ch_lock,
2272 lock_flags);
2273
2274 /* .25 second delay for dropping RTS/DTR */
2275 schedule_timeout_interruptible(msecs_to_jiffies(250));
2276
2277 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2278 }
2279
2280 ch->pscan_state = 0;
2281 ch->pscan_savechar = 0;
2282 ch->ch_baud_info = 0;
2283
2284 }
2285
2286 /*
2287 * turn off print device when closing print device.
2288 */
2289 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2290 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2291 (int) ch->ch_digi.digi_offlen);
2292 ch->ch_flags &= ~CH_PRON;
2293 }
2294
2295 un->un_tty = NULL;
2296 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
2297 tty->driver_data = NULL;
2298
2299 wake_up_interruptible(&ch->ch_flags_wait);
2300 wake_up_interruptible(&un->un_flags_wait);
2301
2302 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
2303} 3275}
2304 3276
2305/* 3277/*
@@ -2599,22 +3571,6 @@ static int dgap_tty_write_room(struct tty_struct *tty)
2599} 3571}
2600 3572
2601/* 3573/*
2602 * dgap_tty_put_char()
2603 *
2604 * Put a character into ch->ch_buf
2605 *
2606 * - used by the line discipline for OPOST processing
2607 */
2608static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
2609{
2610 /*
2611 * Simply call tty_write.
2612 */
2613 dgap_tty_write(tty, &c, 1);
2614 return 1;
2615}
2616
2617/*
2618 * dgap_tty_write() 3574 * dgap_tty_write()
2619 * 3575 *
2620 * Take data from the user or kernel and send it out to the FEP. 3576 * Take data from the user or kernel and send it out to the FEP.
@@ -2629,7 +3585,6 @@ static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
2629 char __iomem *vaddr; 3585 char __iomem *vaddr;
2630 u16 head, tail, tmask, remain; 3586 u16 head, tail, tmask, remain;
2631 int bufcount, n; 3587 int bufcount, n;
2632 int orig_count;
2633 ulong lock_flags; 3588 ulong lock_flags;
2634 3589
2635 if (!tty) 3590 if (!tty)
@@ -2650,13 +3605,6 @@ static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
2650 if (!count) 3605 if (!count)
2651 return 0; 3606 return 0;
2652 3607
2653 /*
2654 * Store original amount of characters passed in.
2655 * This helps to figure out if we should ask the FEP
2656 * to send us an event when it has more space available.
2657 */
2658 orig_count = count;
2659
2660 spin_lock_irqsave(&ch->ch_lock, lock_flags); 3608 spin_lock_irqsave(&ch->ch_lock, lock_flags);
2661 3609
2662 /* Get our space available for the channel from the board */ 3610 /* Get our space available for the channel from the board */
@@ -2784,6 +3732,22 @@ static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
2784} 3732}
2785 3733
2786/* 3734/*
3735 * dgap_tty_put_char()
3736 *
3737 * Put a character into ch->ch_buf
3738 *
3739 * - used by the line discipline for OPOST processing
3740 */
3741static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
3742{
3743 /*
3744 * Simply call tty_write.
3745 */
3746 dgap_tty_write(tty, &c, 1);
3747 return 1;
3748}
3749
3750/*
2787 * Return modem signals to ld. 3751 * Return modem signals to ld.
2788 */ 3752 */
2789static int dgap_tty_tiocmget(struct tty_struct *tty) 3753static int dgap_tty_tiocmget(struct tty_struct *tty)
@@ -3444,13 +4408,189 @@ static void dgap_tty_unthrottle(struct tty_struct *tty)
3444 spin_unlock_irqrestore(&bd->bd_lock, lock_flags); 4408 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3445} 4409}
3446 4410
3447static void dgap_tty_start(struct tty_struct *tty) 4411static struct board_t *find_board_by_major(unsigned int major)
3448{ 4412{
3449 struct board_t *bd; 4413 unsigned int i;
4414
4415 for (i = 0; i < MAXBOARDS; i++) {
4416 struct board_t *brd = dgap_board[i];
4417
4418 if (!brd)
4419 return NULL;
4420 if (major == brd->serial_driver->major ||
4421 major == brd->print_driver->major)
4422 return brd;
4423 }
4424
4425 return NULL;
4426}
4427
4428/************************************************************************
4429 *
4430 * TTY Entry points and helper functions
4431 *
4432 ************************************************************************/
4433
4434/*
4435 * dgap_tty_open()
4436 *
4437 */
4438static int dgap_tty_open(struct tty_struct *tty, struct file *file)
4439{
4440 struct board_t *brd;
3450 struct channel_t *ch; 4441 struct channel_t *ch;
3451 struct un_t *un; 4442 struct un_t *un;
4443 struct bs_t __iomem *bs;
4444 uint major;
4445 uint minor;
4446 int rc;
3452 ulong lock_flags; 4447 ulong lock_flags;
3453 ulong lock_flags2; 4448 ulong lock_flags2;
4449 u16 head;
4450
4451 major = MAJOR(tty_devnum(tty));
4452 minor = MINOR(tty_devnum(tty));
4453
4454 brd = find_board_by_major(major);
4455 if (!brd)
4456 return -EIO;
4457
4458 /*
4459 * If board is not yet up to a state of READY, go to
4460 * sleep waiting for it to happen or they cancel the open.
4461 */
4462 rc = wait_event_interruptible(brd->state_wait,
4463 (brd->state & BOARD_READY));
4464
4465 if (rc)
4466 return rc;
4467
4468 spin_lock_irqsave(&brd->bd_lock, lock_flags);
4469
4470 /* The wait above should guarantee this cannot happen */
4471 if (brd->state != BOARD_READY) {
4472 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4473 return -EIO;
4474 }
4475
4476 /* If opened device is greater than our number of ports, bail. */
4477 if (MINOR(tty_devnum(tty)) > brd->nasync) {
4478 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4479 return -EIO;
4480 }
4481
4482 ch = brd->channels[minor];
4483 if (!ch) {
4484 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4485 return -EIO;
4486 }
4487
4488 /* Grab channel lock */
4489 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
4490
4491 /* Figure out our type */
4492 if (major == brd->serial_driver->major) {
4493 un = &brd->channels[minor]->ch_tun;
4494 un->un_type = DGAP_SERIAL;
4495 } else if (major == brd->print_driver->major) {
4496 un = &brd->channels[minor]->ch_pun;
4497 un->un_type = DGAP_PRINT;
4498 } else {
4499 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4500 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4501 return -EIO;
4502 }
4503
4504 /* Store our unit into driver_data, so we always have it available. */
4505 tty->driver_data = un;
4506
4507 /*
4508 * Error if channel info pointer is NULL.
4509 */
4510 bs = ch->ch_bs;
4511 if (!bs) {
4512 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4513 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4514 return -EIO;
4515 }
4516
4517 /*
4518 * Initialize tty's
4519 */
4520 if (!(un->un_flags & UN_ISOPEN)) {
4521 /* Store important variables. */
4522 un->un_tty = tty;
4523
4524 /* Maybe do something here to the TTY struct as well? */
4525 }
4526
4527 /*
4528 * Initialize if neither terminal or printer is open.
4529 */
4530 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
4531
4532 ch->ch_mforce = 0;
4533 ch->ch_mval = 0;
4534
4535 /*
4536 * Flush input queue.
4537 */
4538 head = readw(&(bs->rx_head));
4539 writew(head, &(bs->rx_tail));
4540
4541 ch->ch_flags = 0;
4542 ch->pscan_state = 0;
4543 ch->pscan_savechar = 0;
4544
4545 ch->ch_c_cflag = tty->termios.c_cflag;
4546 ch->ch_c_iflag = tty->termios.c_iflag;
4547 ch->ch_c_oflag = tty->termios.c_oflag;
4548 ch->ch_c_lflag = tty->termios.c_lflag;
4549 ch->ch_startc = tty->termios.c_cc[VSTART];
4550 ch->ch_stopc = tty->termios.c_cc[VSTOP];
4551
4552 /* TODO: flush our TTY struct here? */
4553 }
4554
4555 dgap_carrier(ch);
4556 /*
4557 * Run param in case we changed anything
4558 */
4559 dgap_param(ch, brd, un->un_type);
4560
4561 /*
4562 * follow protocol for opening port
4563 */
4564
4565 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
4566 spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
4567
4568 rc = dgap_block_til_ready(tty, file, ch);
4569
4570 if (!un->un_tty)
4571 return -ENODEV;
4572
4573 /* No going back now, increment our unit and channel counters */
4574 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4575 ch->ch_open_count++;
4576 un->un_open_count++;
4577 un->un_flags |= (UN_ISOPEN);
4578 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4579
4580 return rc;
4581}
4582
4583/*
4584 * dgap_tty_close()
4585 *
4586 */
4587static void dgap_tty_close(struct tty_struct *tty, struct file *file)
4588{
4589 struct ktermios *ts;
4590 struct board_t *bd;
4591 struct channel_t *ch;
4592 struct un_t *un;
4593 ulong lock_flags;
3454 4594
3455 if (!tty || tty->magic != TTY_MAGIC) 4595 if (!tty || tty->magic != TTY_MAGIC)
3456 return; 4596 return;
@@ -3467,16 +4607,110 @@ static void dgap_tty_start(struct tty_struct *tty)
3467 if (!bd || bd->magic != DGAP_BOARD_MAGIC) 4607 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3468 return; 4608 return;
3469 4609
3470 spin_lock_irqsave(&bd->bd_lock, lock_flags); 4610 ts = &tty->termios;
3471 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3472 4611
3473 dgap_cmdw(ch, RESUMETX, 0, 0); 4612 spin_lock_irqsave(&ch->ch_lock, lock_flags);
3474 4613
3475 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); 4614 /*
3476 spin_unlock_irqrestore(&bd->bd_lock, lock_flags); 4615 * Determine if this is the last close or not - and if we agree about
4616 * which type of close it is with the Line Discipline
4617 */
4618 if ((tty->count == 1) && (un->un_open_count != 1)) {
4619 /*
4620 * Uh, oh. tty->count is 1, which means that the tty
4621 * structure will be freed. un_open_count should always
4622 * be one in these conditions. If it's greater than
4623 * one, we've got real problems, since it means the
4624 * serial port won't be shutdown.
4625 */
4626 un->un_open_count = 1;
4627 }
4628
4629 if (--un->un_open_count < 0)
4630 un->un_open_count = 0;
4631
4632 ch->ch_open_count--;
4633
4634 if (ch->ch_open_count && un->un_open_count) {
4635 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4636 return;
4637 }
4638
4639 /* OK, its the last close on the unit */
4640
4641 un->un_flags |= UN_CLOSING;
4642
4643 tty->closing = 1;
4644
4645 /*
4646 * Only officially close channel if count is 0 and
4647 * DIGI_PRINTER bit is not set.
4648 */
4649 if ((ch->ch_open_count == 0) &&
4650 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
4651
4652 ch->ch_flags &= ~(CH_RXBLOCK);
4653
4654 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
4655
4656 /* wait for output to drain */
4657 /* This will also return if we take an interrupt */
4658
4659 dgap_wait_for_drain(tty);
4660
4661 dgap_tty_flush_buffer(tty);
4662 tty_ldisc_flush(tty);
4663
4664 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4665
4666 tty->closing = 0;
4667
4668 /*
4669 * If we have HUPCL set, lower DTR and RTS
4670 */
4671 if (ch->ch_c_cflag & HUPCL) {
4672 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
4673 dgap_cmdb(ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0);
4674
4675 /*
4676 * Go to sleep to ensure RTS/DTR
4677 * have been dropped for modems to see it.
4678 */
4679 spin_unlock_irqrestore(&ch->ch_lock,
4680 lock_flags);
4681
4682 /* .25 second delay for dropping RTS/DTR */
4683 schedule_timeout_interruptible(msecs_to_jiffies(250));
4684
4685 spin_lock_irqsave(&ch->ch_lock, lock_flags);
4686 }
4687
4688 ch->pscan_state = 0;
4689 ch->pscan_savechar = 0;
4690 ch->ch_baud_info = 0;
4691
4692 }
4693
4694 /*
4695 * turn off print device when closing print device.
4696 */
4697 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
4698 dgap_wmove(ch, ch->ch_digi.digi_offstr,
4699 (int) ch->ch_digi.digi_offlen);
4700 ch->ch_flags &= ~CH_PRON;
4701 }
4702
4703 un->un_tty = NULL;
4704 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
4705 tty->driver_data = NULL;
4706
4707 wake_up_interruptible(&ch->ch_flags_wait);
4708 wake_up_interruptible(&un->un_flags_wait);
4709
4710 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
3477} 4711}
3478 4712
3479static void dgap_tty_stop(struct tty_struct *tty) 4713static void dgap_tty_start(struct tty_struct *tty)
3480{ 4714{
3481 struct board_t *bd; 4715 struct board_t *bd;
3482 struct channel_t *ch; 4716 struct channel_t *ch;
@@ -3502,26 +4736,13 @@ static void dgap_tty_stop(struct tty_struct *tty)
3502 spin_lock_irqsave(&bd->bd_lock, lock_flags); 4736 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3503 spin_lock_irqsave(&ch->ch_lock, lock_flags2); 4737 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3504 4738
3505 dgap_cmdw(ch, PAUSETX, 0, 0); 4739 dgap_cmdw(ch, RESUMETX, 0, 0);
3506 4740
3507 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); 4741 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3508 spin_unlock_irqrestore(&bd->bd_lock, lock_flags); 4742 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3509} 4743}
3510 4744
3511/* 4745static void dgap_tty_stop(struct tty_struct *tty)
3512 * dgap_tty_flush_chars()
3513 *
3514 * Flush the cook buffer
3515 *
3516 * Note to self, and any other poor souls who venture here:
3517 *
3518 * flush in this case DOES NOT mean dispose of the data.
3519 * instead, it means "stop buffering and send it if you
3520 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
3521 *
3522 * It is also always called in interrupt context - JAR 8-Sept-99
3523 */
3524static void dgap_tty_flush_chars(struct tty_struct *tty)
3525{ 4746{
3526 struct board_t *bd; 4747 struct board_t *bd;
3527 struct channel_t *ch; 4748 struct channel_t *ch;
@@ -3547,25 +4768,32 @@ static void dgap_tty_flush_chars(struct tty_struct *tty)
3547 spin_lock_irqsave(&bd->bd_lock, lock_flags); 4768 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3548 spin_lock_irqsave(&ch->ch_lock, lock_flags2); 4769 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3549 4770
3550 /* TODO: Do something here */ 4771 dgap_cmdw(ch, PAUSETX, 0, 0);
3551 4772
3552 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); 4773 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3553 spin_unlock_irqrestore(&bd->bd_lock, lock_flags); 4774 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3554} 4775}
3555 4776
3556/* 4777/*
3557 * dgap_tty_flush_buffer() 4778 * dgap_tty_flush_chars()
3558 * 4779 *
3559 * Flush Tx buffer (make in == out) 4780 * Flush the cook buffer
4781 *
4782 * Note to self, and any other poor souls who venture here:
4783 *
4784 * flush in this case DOES NOT mean dispose of the data.
4785 * instead, it means "stop buffering and send it if you
4786 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
4787 *
4788 * It is also always called in interrupt context - JAR 8-Sept-99
3560 */ 4789 */
3561static void dgap_tty_flush_buffer(struct tty_struct *tty) 4790static void dgap_tty_flush_chars(struct tty_struct *tty)
3562{ 4791{
3563 struct board_t *bd; 4792 struct board_t *bd;
3564 struct channel_t *ch; 4793 struct channel_t *ch;
3565 struct un_t *un; 4794 struct un_t *un;
3566 ulong lock_flags; 4795 ulong lock_flags;
3567 ulong lock_flags2; 4796 ulong lock_flags2;
3568 u16 head;
3569 4797
3570 if (!tty || tty->magic != TTY_MAGIC) 4798 if (!tty || tty->magic != TTY_MAGIC)
3571 return; 4799 return;
@@ -3585,24 +4813,10 @@ static void dgap_tty_flush_buffer(struct tty_struct *tty)
3585 spin_lock_irqsave(&bd->bd_lock, lock_flags); 4813 spin_lock_irqsave(&bd->bd_lock, lock_flags);
3586 spin_lock_irqsave(&ch->ch_lock, lock_flags2); 4814 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
3587 4815
3588 ch->ch_flags &= ~CH_STOP; 4816 /* TODO: Do something here */
3589 head = readw(&(ch->ch_bs->tx_head));
3590 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3591 dgap_cmdw(ch, RESUMETX, 0, 0);
3592 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3593 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3594 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3595 }
3596 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3597 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3598 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3599 }
3600 4817
3601 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2); 4818 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
3602 spin_unlock_irqrestore(&bd->bd_lock, lock_flags); 4819 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
3603 if (waitqueue_active(&tty->write_wait))
3604 wake_up_interruptible(&tty->write_wait);
3605 tty_wakeup(tty);
3606} 4820}
3607 4821
3608/***************************************************************************** 4822/*****************************************************************************
@@ -3996,1614 +5210,151 @@ static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
3996 } 5210 }
3997} 5211}
3998 5212
3999static int dgap_alloc_flipbuf(struct board_t *brd) 5213static const struct tty_operations dgap_tty_ops = {
4000{ 5214 .open = dgap_tty_open,
4001 /* 5215 .close = dgap_tty_close,
4002 * allocate flip buffer for board. 5216 .write = dgap_tty_write,
4003 */ 5217 .write_room = dgap_tty_write_room,
4004 brd->flipbuf = kmalloc(MYFLIPLEN, GFP_KERNEL); 5218 .flush_buffer = dgap_tty_flush_buffer,
4005 if (!brd->flipbuf) 5219 .chars_in_buffer = dgap_tty_chars_in_buffer,
4006 return -ENOMEM; 5220 .flush_chars = dgap_tty_flush_chars,
4007 5221 .ioctl = dgap_tty_ioctl,
4008 brd->flipflagbuf = kmalloc(MYFLIPLEN, GFP_KERNEL); 5222 .set_termios = dgap_tty_set_termios,
4009 if (!brd->flipflagbuf) { 5223 .stop = dgap_tty_stop,
4010 kfree(brd->flipbuf); 5224 .start = dgap_tty_start,
4011 return -ENOMEM; 5225 .throttle = dgap_tty_throttle,
4012 } 5226 .unthrottle = dgap_tty_unthrottle,
4013 5227 .hangup = dgap_tty_hangup,
4014 return 0; 5228 .put_char = dgap_tty_put_char,
4015} 5229 .tiocmget = dgap_tty_tiocmget,
4016 5230 .tiocmset = dgap_tty_tiocmset,
4017static void dgap_free_flipbuf(struct board_t *brd) 5231 .break_ctl = dgap_tty_send_break,
4018{ 5232 .wait_until_sent = dgap_tty_wait_until_sent,
4019 kfree(brd->flipbuf); 5233 .send_xchar = dgap_tty_send_xchar
4020 kfree(brd->flipflagbuf); 5234};
4021}
4022
4023/*
4024 * Create pr and tty device entries
4025 */
4026static int dgap_tty_register_ports(struct board_t *brd)
4027{
4028 struct channel_t *ch;
4029 int i;
4030 int ret;
4031
4032 brd->serial_ports = kcalloc(brd->nasync, sizeof(*brd->serial_ports),
4033 GFP_KERNEL);
4034 if (!brd->serial_ports)
4035 return -ENOMEM;
4036
4037 brd->printer_ports = kcalloc(brd->nasync, sizeof(*brd->printer_ports),
4038 GFP_KERNEL);
4039 if (!brd->printer_ports) {
4040 ret = -ENOMEM;
4041 goto free_serial_ports;
4042 }
4043
4044 for (i = 0; i < brd->nasync; i++) {
4045 tty_port_init(&brd->serial_ports[i]);
4046 tty_port_init(&brd->printer_ports[i]);
4047 }
4048
4049 ch = brd->channels[0];
4050 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
4051
4052 struct device *classp;
4053
4054 classp = tty_port_register_device(&brd->serial_ports[i],
4055 brd->serial_driver,
4056 i, NULL);
4057
4058 if (IS_ERR(classp)) {
4059 ret = PTR_ERR(classp);
4060 goto unregister_ttys;
4061 }
4062
4063 dgap_create_tty_sysfs(&ch->ch_tun, classp);
4064 ch->ch_tun.un_sysfs = classp;
4065
4066 classp = tty_port_register_device(&brd->printer_ports[i],
4067 brd->print_driver,
4068 i, NULL);
4069
4070 if (IS_ERR(classp)) {
4071 ret = PTR_ERR(classp);
4072 goto unregister_ttys;
4073 }
4074
4075 dgap_create_tty_sysfs(&ch->ch_pun, classp);
4076 ch->ch_pun.un_sysfs = classp;
4077 }
4078 dgap_create_ports_sysfiles(brd);
4079
4080 return 0;
4081
4082unregister_ttys:
4083 while (i >= 0) {
4084 ch = brd->channels[i];
4085 if (ch->ch_tun.un_sysfs) {
4086 dgap_remove_tty_sysfs(ch->ch_tun.un_sysfs);
4087 tty_unregister_device(brd->serial_driver, i);
4088 }
4089
4090 if (ch->ch_pun.un_sysfs) {
4091 dgap_remove_tty_sysfs(ch->ch_pun.un_sysfs);
4092 tty_unregister_device(brd->print_driver, i);
4093 }
4094 i--;
4095 }
4096
4097 for (i = 0; i < brd->nasync; i++) {
4098 tty_port_destroy(&brd->serial_ports[i]);
4099 tty_port_destroy(&brd->printer_ports[i]);
4100 }
4101
4102 kfree(brd->printer_ports);
4103 brd->printer_ports = NULL;
4104
4105free_serial_ports:
4106 kfree(brd->serial_ports);
4107 brd->serial_ports = NULL;
4108
4109 return ret;
4110}
4111
4112/*
4113 * Copies the BIOS code from the user to the board,
4114 * and starts the BIOS running.
4115 */
4116static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len)
4117{
4118 u8 __iomem *addr;
4119 uint offset;
4120 int i;
4121
4122 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4123 return;
4124
4125 addr = brd->re_map_membase;
4126
4127 /*
4128 * clear POST area
4129 */
4130 for (i = 0; i < 16; i++)
4131 writeb(0, addr + POSTAREA + i);
4132
4133 /*
4134 * Download bios
4135 */
4136 offset = 0x1000;
4137 memcpy_toio(addr + offset, ubios, len);
4138
4139 writel(0x0bf00401, addr);
4140 writel(0, (addr + 4));
4141
4142 /* Clear the reset, and change states. */
4143 writeb(FEPCLR, brd->re_map_port);
4144}
4145
4146/*
4147 * Checks to see if the BIOS completed running on the card.
4148 */
4149static int dgap_test_bios(struct board_t *brd)
4150{
4151 u8 __iomem *addr;
4152 u16 word;
4153 u16 err1;
4154 u16 err2;
4155
4156 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4157 return -EINVAL;
4158
4159 addr = brd->re_map_membase;
4160 word = readw(addr + POSTAREA);
4161
4162 /*
4163 * It can take 5-6 seconds for a board to
4164 * pass the bios self test and post results.
4165 * Give it 10 seconds.
4166 */
4167 brd->wait_for_bios = 0;
4168 while (brd->wait_for_bios < 1000) {
4169 /* Check to see if BIOS thinks board is good. (GD). */
4170 if (word == *(u16 *) "GD")
4171 return 0;
4172 msleep_interruptible(10);
4173 brd->wait_for_bios++;
4174 word = readw(addr + POSTAREA);
4175 }
4176
4177 /* Gave up on board after too long of time taken */
4178 err1 = readw(addr + SEQUENCE);
4179 err2 = readw(addr + ERROR);
4180 dev_warn(&brd->pdev->dev, "%s failed diagnostics. Error #(%x,%x).\n",
4181 brd->name, err1, err2);
4182 brd->state = BOARD_FAILED;
4183 brd->dpastatus = BD_NOBIOS;
4184
4185 return -EIO;
4186}
4187
4188/*
4189 * Copies the FEP code from the user to the board,
4190 * and starts the FEP running.
4191 */
4192static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len)
4193{
4194 u8 __iomem *addr;
4195 uint offset;
4196
4197 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4198 return;
4199
4200 addr = brd->re_map_membase;
4201
4202 /*
4203 * Download FEP
4204 */
4205 offset = 0x1000;
4206 memcpy_toio(addr + offset, ufep, len);
4207
4208 /*
4209 * If board is a concentrator product, we need to give
4210 * it its config string describing how the concentrators look.
4211 */
4212 if ((brd->type == PCX) || (brd->type == PEPC)) {
4213 u8 string[100];
4214 u8 __iomem *config;
4215 u8 *xconfig;
4216 int i = 0;
4217
4218 xconfig = dgap_create_config_string(brd, string);
4219
4220 /* Write string to board memory */
4221 config = addr + CONFIG;
4222 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
4223 writeb(*xconfig, config);
4224 if ((*xconfig & 0xff) == 0xff)
4225 break;
4226 }
4227 }
4228
4229 writel(0xbfc01004, (addr + 0xc34));
4230 writel(0x3, (addr + 0xc30));
4231
4232}
4233
4234/*
4235 * Waits for the FEP to report thats its ready for us to use.
4236 */
4237static int dgap_test_fep(struct board_t *brd)
4238{
4239 u8 __iomem *addr;
4240 u16 word;
4241 u16 err1;
4242 u16 err2;
4243
4244 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4245 return -EINVAL;
4246
4247 addr = brd->re_map_membase;
4248 word = readw(addr + FEPSTAT);
4249
4250 /*
4251 * It can take 2-3 seconds for the FEP to
4252 * be up and running. Give it 5 secs.
4253 */
4254 brd->wait_for_fep = 0;
4255 while (brd->wait_for_fep < 500) {
4256 /* Check to see if FEP is up and running now. */
4257 if (word == *(u16 *) "OS") {
4258 /*
4259 * Check to see if the board can support FEP5+ commands.
4260 */
4261 word = readw(addr + FEP5_PLUS);
4262 if (word == *(u16 *) "5A")
4263 brd->bd_flags |= BD_FEP5PLUS;
4264
4265 return 0;
4266 }
4267 msleep_interruptible(10);
4268 brd->wait_for_fep++;
4269 word = readw(addr + FEPSTAT);
4270 }
4271
4272 /* Gave up on board after too long of time taken */
4273 err1 = readw(addr + SEQUENCE);
4274 err2 = readw(addr + ERROR);
4275 dev_warn(&brd->pdev->dev,
4276 "FEPOS for %s not functioning. Error #(%x,%x).\n",
4277 brd->name, err1, err2);
4278 brd->state = BOARD_FAILED;
4279 brd->dpastatus = BD_NOFEP;
4280
4281 return -EIO;
4282}
4283
4284/*
4285 * Physically forces the FEP5 card to reset itself.
4286 */
4287static void dgap_do_reset_board(struct board_t *brd)
4288{
4289 u8 check;
4290 u32 check1;
4291 u32 check2;
4292 int i;
4293
4294 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
4295 !brd->re_map_membase || !brd->re_map_port)
4296 return;
4297
4298 /* FEPRST does not vary among supported boards */
4299 writeb(FEPRST, brd->re_map_port);
4300
4301 for (i = 0; i <= 1000; i++) {
4302 check = readb(brd->re_map_port) & 0xe;
4303 if (check == FEPRST)
4304 break;
4305 udelay(10);
4306
4307 }
4308 if (i > 1000) {
4309 dev_warn(&brd->pdev->dev,
4310 "dgap: Board not resetting... Failing board.\n");
4311 brd->state = BOARD_FAILED;
4312 brd->dpastatus = BD_NOFEP;
4313 return;
4314 }
4315
4316 /*
4317 * Make sure there really is memory out there.
4318 */
4319 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
4320 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
4321 check1 = readl(brd->re_map_membase + LOWMEM);
4322 check2 = readl(brd->re_map_membase + HIGHMEM);
4323
4324 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
4325 dev_warn(&brd->pdev->dev,
4326 "No memory at %p for board.\n",
4327 brd->re_map_membase);
4328 brd->state = BOARD_FAILED;
4329 brd->dpastatus = BD_NOFEP;
4330 return;
4331 }
4332}
4333
4334#ifdef DIGI_CONCENTRATORS_SUPPORTED
4335/*
4336 * Sends a concentrator image into the FEP5 board.
4337 */
4338static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len)
4339{
4340 char __iomem *vaddr;
4341 u16 offset;
4342 struct downld_t *to_dp;
4343
4344 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
4345 return;
4346
4347 vaddr = brd->re_map_membase;
4348
4349 offset = readw((u16 *) (vaddr + DOWNREQ));
4350 to_dp = (struct downld_t *) (vaddr + (int) offset);
4351 memcpy_toio(to_dp, uaddr, len);
4352
4353 /* Tell card we have data for it */
4354 writew(0, vaddr + (DOWNREQ));
4355
4356 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
4357}
4358#endif
4359
4360#define EXPANSION_ROM_SIZE (64 * 1024)
4361#define FEP5_ROM_MAGIC (0xFEFFFFFF)
4362
4363static void dgap_get_vpd(struct board_t *brd)
4364{
4365 u32 magic;
4366 u32 base_offset;
4367 u16 rom_offset;
4368 u16 vpd_offset;
4369 u16 image_length;
4370 u16 i;
4371 u8 byte1;
4372 u8 byte2;
4373
4374 /*
4375 * Poke the magic number at the PCI Rom Address location.
4376 * If VPD is supported, the value read from that address
4377 * will be non-zero.
4378 */
4379 magic = FEP5_ROM_MAGIC;
4380 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4381 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4382
4383 /* VPD not supported, bail */
4384 if (!magic)
4385 return;
4386
4387 /*
4388 * To get to the OTPROM memory, we have to send the boards base
4389 * address or'ed with 1 into the PCI Rom Address location.
4390 */
4391 magic = brd->membase | 0x01;
4392 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4393 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
4394
4395 byte1 = readb(brd->re_map_membase);
4396 byte2 = readb(brd->re_map_membase + 1);
4397
4398 /*
4399 * If the board correctly swapped to the OTPROM memory,
4400 * the first 2 bytes (header) should be 0x55, 0xAA
4401 */
4402 if (byte1 == 0x55 && byte2 == 0xAA) {
4403
4404 base_offset = 0;
4405
4406 /*
4407 * We have to run through all the OTPROM memory looking
4408 * for the VPD offset.
4409 */
4410 while (base_offset <= EXPANSION_ROM_SIZE) {
4411
4412 /*
4413 * Lots of magic numbers here.
4414 *
4415 * The VPD offset is located inside the ROM Data
4416 * Structure.
4417 *
4418 * We also have to remember the length of each
4419 * ROM Data Structure, so we can "hop" to the next
4420 * entry if the VPD isn't in the current
4421 * ROM Data Structure.
4422 */
4423 rom_offset = readw(brd->re_map_membase +
4424 base_offset + 0x18);
4425 image_length = readw(brd->re_map_membase +
4426 rom_offset + 0x10) * 512;
4427 vpd_offset = readw(brd->re_map_membase +
4428 rom_offset + 0x08);
4429
4430 /* Found the VPD entry */
4431 if (vpd_offset)
4432 break;
4433
4434 /* We didn't find a VPD entry, go to next ROM entry. */
4435 base_offset += image_length;
4436
4437 byte1 = readb(brd->re_map_membase + base_offset);
4438 byte2 = readb(brd->re_map_membase + base_offset + 1);
4439
4440 /*
4441 * If the new ROM offset doesn't have 0x55, 0xAA
4442 * as its header, we have run out of ROM.
4443 */
4444 if (byte1 != 0x55 || byte2 != 0xAA)
4445 break;
4446 }
4447
4448 /*
4449 * If we have a VPD offset, then mark the board
4450 * as having a valid VPD, and copy VPDSIZE (512) bytes of
4451 * that VPD to the buffer we have in our board structure.
4452 */
4453 if (vpd_offset) {
4454 brd->bd_flags |= BD_HAS_VPD;
4455 for (i = 0; i < VPDSIZE; i++) {
4456 brd->vpd[i] = readb(brd->re_map_membase +
4457 vpd_offset + i);
4458 }
4459 }
4460 }
4461
4462 /*
4463 * We MUST poke the magic number at the PCI Rom Address location again.
4464 * This makes the card report the regular board memory back to us,
4465 * rather than the OTPROM memory.
4466 */
4467 magic = FEP5_ROM_MAGIC;
4468 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
4469}
4470
4471/*
4472 * Our board poller function.
4473 */
4474static void dgap_poll_tasklet(unsigned long data)
4475{
4476 struct board_t *bd = (struct board_t *) data;
4477 ulong lock_flags;
4478 char __iomem *vaddr;
4479 u16 head, tail;
4480
4481 if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
4482 return;
4483
4484 if (bd->inhibit_poller)
4485 return;
4486
4487 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4488
4489 vaddr = bd->re_map_membase;
4490
4491 /*
4492 * If board is ready, parse deeper to see if there is anything to do.
4493 */
4494 if (bd->state == BOARD_READY) {
4495
4496 struct ev_t __iomem *eaddr;
4497
4498 if (!bd->re_map_membase) {
4499 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4500 return;
4501 }
4502 if (!bd->re_map_port) {
4503 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4504 return;
4505 }
4506
4507 if (!bd->nasync)
4508 goto out;
4509
4510 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
4511
4512 /* Get our head and tail */
4513 head = readw(&(eaddr->ev_head));
4514 tail = readw(&(eaddr->ev_tail));
4515
4516 /*
4517 * If there is an event pending. Go service it.
4518 */
4519 if (head != tail) {
4520 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4521 dgap_event(bd);
4522 spin_lock_irqsave(&bd->bd_lock, lock_flags);
4523 }
4524
4525out:
4526 /*
4527 * If board is doing interrupts, ACK the interrupt.
4528 */
4529 if (bd && bd->intr_running)
4530 readb(bd->re_map_port + 2);
4531
4532 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4533 return;
4534 }
4535
4536 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
4537}
4538
4539/*=======================================================================
4540 *
4541 * dgap_cmdb - Sends a 2 byte command to the FEP.
4542 *
4543 * ch - Pointer to channel structure.
4544 * cmd - Command to be sent.
4545 * byte1 - Integer containing first byte to be sent.
4546 * byte2 - Integer containing second byte to be sent.
4547 * ncmds - Wait until ncmds or fewer cmds are left
4548 * in the cmd buffer before returning.
4549 *
4550 *=======================================================================*/
4551static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
4552 u8 byte2, uint ncmds)
4553{
4554 char __iomem *vaddr;
4555 struct __iomem cm_t *cm_addr;
4556 uint count;
4557 uint n;
4558 u16 head;
4559 u16 tail;
4560
4561 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4562 return;
4563
4564 /*
4565 * Check if board is still alive.
4566 */
4567 if (ch->ch_bd->state == BOARD_FAILED)
4568 return;
4569
4570 /*
4571 * Make sure the pointers are in range before
4572 * writing to the FEP memory.
4573 */
4574 vaddr = ch->ch_bd->re_map_membase;
4575
4576 if (!vaddr)
4577 return;
4578
4579 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4580 head = readw(&(cm_addr->cm_head));
4581
4582 /*
4583 * Forget it if pointers out of range.
4584 */
4585 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4586 ch->ch_bd->state = BOARD_FAILED;
4587 return;
4588 }
4589
4590 /*
4591 * Put the data in the circular command buffer.
4592 */
4593 writeb(cmd, (vaddr + head + CMDSTART + 0));
4594 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4595 writeb(byte1, (vaddr + head + CMDSTART + 2));
4596 writeb(byte2, (vaddr + head + CMDSTART + 3));
4597
4598 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4599
4600 writew(head, &(cm_addr->cm_head));
4601
4602 /*
4603 * Wait if necessary before updating the head
4604 * pointer to limit the number of outstanding
4605 * commands to the FEP. If the time spent waiting
4606 * is outlandish, declare the FEP dead.
4607 */
4608 for (count = dgap_count ;;) {
4609
4610 head = readw(&(cm_addr->cm_head));
4611 tail = readw(&(cm_addr->cm_tail));
4612
4613 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4614
4615 if (n <= ncmds * sizeof(struct cm_t))
4616 break;
4617
4618 if (--count == 0) {
4619 ch->ch_bd->state = BOARD_FAILED;
4620 return;
4621 }
4622 udelay(10);
4623 }
4624}
4625
4626/*=======================================================================
4627 *
4628 * dgap_cmdw - Sends a 1 word command to the FEP.
4629 *
4630 * ch - Pointer to channel structure.
4631 * cmd - Command to be sent.
4632 * word - Integer containing word to be sent.
4633 * ncmds - Wait until ncmds or fewer cmds are left
4634 * in the cmd buffer before returning.
4635 *
4636 *=======================================================================*/
4637static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds)
4638{
4639 char __iomem *vaddr;
4640 struct __iomem cm_t *cm_addr;
4641 uint count;
4642 uint n;
4643 u16 head;
4644 u16 tail;
4645
4646 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4647 return;
4648
4649 /*
4650 * Check if board is still alive.
4651 */
4652 if (ch->ch_bd->state == BOARD_FAILED)
4653 return;
4654
4655 /*
4656 * Make sure the pointers are in range before
4657 * writing to the FEP memory.
4658 */
4659 vaddr = ch->ch_bd->re_map_membase;
4660 if (!vaddr)
4661 return;
4662
4663 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4664 head = readw(&(cm_addr->cm_head));
4665
4666 /*
4667 * Forget it if pointers out of range.
4668 */
4669 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4670 ch->ch_bd->state = BOARD_FAILED;
4671 return;
4672 }
4673
4674 /*
4675 * Put the data in the circular command buffer.
4676 */
4677 writeb(cmd, (vaddr + head + CMDSTART + 0));
4678 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4679 writew((u16) word, (vaddr + head + CMDSTART + 2));
4680
4681 head = (head + 4) & (CMDMAX - CMDSTART - 4);
4682
4683 writew(head, &(cm_addr->cm_head));
4684
4685 /*
4686 * Wait if necessary before updating the head
4687 * pointer to limit the number of outstanding
4688 * commands to the FEP. If the time spent waiting
4689 * is outlandish, declare the FEP dead.
4690 */
4691 for (count = dgap_count ;;) {
4692
4693 head = readw(&(cm_addr->cm_head));
4694 tail = readw(&(cm_addr->cm_tail));
4695
4696 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4697
4698 if (n <= ncmds * sizeof(struct cm_t))
4699 break;
4700
4701 if (--count == 0) {
4702 ch->ch_bd->state = BOARD_FAILED;
4703 return;
4704 }
4705 udelay(10);
4706 }
4707}
4708
4709/*=======================================================================
4710 *
4711 * dgap_cmdw_ext - Sends a extended word command to the FEP.
4712 *
4713 * ch - Pointer to channel structure.
4714 * cmd - Command to be sent.
4715 * word - Integer containing word to be sent.
4716 * ncmds - Wait until ncmds or fewer cmds are left
4717 * in the cmd buffer before returning.
4718 *
4719 *=======================================================================*/
4720static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
4721{
4722 char __iomem *vaddr;
4723 struct __iomem cm_t *cm_addr;
4724 uint count;
4725 uint n;
4726 u16 head;
4727 u16 tail;
4728
4729 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4730 return;
4731
4732 /*
4733 * Check if board is still alive.
4734 */
4735 if (ch->ch_bd->state == BOARD_FAILED)
4736 return;
4737
4738 /*
4739 * Make sure the pointers are in range before
4740 * writing to the FEP memory.
4741 */
4742 vaddr = ch->ch_bd->re_map_membase;
4743 if (!vaddr)
4744 return;
4745
4746 cm_addr = (struct cm_t __iomem *) (vaddr + CMDBUF);
4747 head = readw(&(cm_addr->cm_head));
4748
4749 /*
4750 * Forget it if pointers out of range.
4751 */
4752 if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
4753 ch->ch_bd->state = BOARD_FAILED;
4754 return;
4755 }
4756
4757 /*
4758 * Put the data in the circular command buffer.
4759 */
4760
4761 /* Write an FF to tell the FEP that we want an extended command */
4762 writeb((u8) 0xff, (vaddr + head + CMDSTART + 0));
4763
4764 writeb((u8) ch->ch_portnum, (vaddr + head + CMDSTART + 1));
4765 writew((u16) cmd, (vaddr + head + CMDSTART + 2));
4766
4767 /*
4768 * If the second part of the command won't fit,
4769 * put it at the beginning of the circular buffer.
4770 */
4771 if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
4772 writew((u16) word, (vaddr + CMDSTART));
4773 else
4774 writew((u16) word, (vaddr + head + CMDSTART + 4));
4775
4776 head = (head + 8) & (CMDMAX - CMDSTART - 4);
4777
4778 writew(head, &(cm_addr->cm_head));
4779
4780 /*
4781 * Wait if necessary before updating the head
4782 * pointer to limit the number of outstanding
4783 * commands to the FEP. If the time spent waiting
4784 * is outlandish, declare the FEP dead.
4785 */
4786 for (count = dgap_count ;;) {
4787
4788 head = readw(&(cm_addr->cm_head));
4789 tail = readw(&(cm_addr->cm_tail));
4790
4791 n = (head - tail) & (CMDMAX - CMDSTART - 4);
4792
4793 if (n <= ncmds * sizeof(struct cm_t))
4794 break;
4795
4796 if (--count == 0) {
4797 ch->ch_bd->state = BOARD_FAILED;
4798 return;
4799 }
4800 udelay(10);
4801 }
4802}
4803 5235
4804/*======================================================================= 5236/************************************************************************
4805 *
4806 * dgap_wmove - Write data to FEP buffer.
4807 * 5237 *
4808 * ch - Pointer to channel structure. 5238 * TTY Initialization/Cleanup Functions
4809 * buf - Poiter to characters to be moved.
4810 * cnt - Number of characters to move.
4811 * 5239 *
4812 *=======================================================================*/ 5240 ************************************************************************/
4813static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
4814{
4815 int n;
4816 char __iomem *taddr;
4817 struct bs_t __iomem *bs;
4818 u16 head;
4819
4820 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4821 return;
4822
4823 /*
4824 * Check parameters.
4825 */
4826 bs = ch->ch_bs;
4827 head = readw(&(bs->tx_head));
4828
4829 /*
4830 * If pointers are out of range, just return.
4831 */
4832 if ((cnt > ch->ch_tsize) ||
4833 (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
4834 return;
4835
4836 /*
4837 * If the write wraps over the top of the circular buffer,
4838 * move the portion up to the wrap point, and reset the
4839 * pointers to the bottom.
4840 */
4841 n = ch->ch_tstart + ch->ch_tsize - head;
4842
4843 if (cnt >= n) {
4844 cnt -= n;
4845 taddr = ch->ch_taddr + head;
4846 memcpy_toio(taddr, buf, n);
4847 head = ch->ch_tstart;
4848 buf += n;
4849 }
4850
4851 /*
4852 * Move rest of data.
4853 */
4854 taddr = ch->ch_taddr + head;
4855 n = cnt;
4856 memcpy_toio(taddr, buf, n);
4857 head += cnt;
4858
4859 writew(head, &(bs->tx_head));
4860}
4861
4862/*
4863 * Retrives the current custom baud rate from FEP memory,
4864 * and returns it back to the user.
4865 * Returns 0 on error.
4866 */
4867static uint dgap_get_custom_baud(struct channel_t *ch)
4868{
4869 u8 __iomem *vaddr;
4870 ulong offset;
4871 uint value;
4872
4873 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
4874 return 0;
4875
4876 if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
4877 return 0;
4878
4879 if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
4880 return 0;
4881
4882 vaddr = ch->ch_bd->re_map_membase;
4883
4884 if (!vaddr)
4885 return 0;
4886
4887 /*
4888 * Go get from fep mem, what the fep
4889 * believes the custom baud rate is.
4890 */
4891 offset = (ioread16(vaddr + ECS_SEG) << 4) + (ch->ch_portnum * 0x28)
4892 + LINE_SPEED;
4893
4894 value = readw(vaddr + offset);
4895 return value;
4896}
4897 5241
4898/* 5242/*
4899 * Calls the firmware to reset this channel. 5243 * dgap_tty_register()
4900 */
4901static void dgap_firmware_reset_port(struct channel_t *ch)
4902{
4903 dgap_cmdb(ch, CHRESET, 0, 0, 0);
4904
4905 /*
4906 * Now that the channel is reset, we need to make sure
4907 * all the current settings get reapplied to the port
4908 * in the firmware.
4909 *
4910 * So we will set the driver's cache of firmware
4911 * settings all to 0, and then call param.
4912 */
4913 ch->ch_fepiflag = 0;
4914 ch->ch_fepcflag = 0;
4915 ch->ch_fepoflag = 0;
4916 ch->ch_fepstartc = 0;
4917 ch->ch_fepstopc = 0;
4918 ch->ch_fepastartc = 0;
4919 ch->ch_fepastopc = 0;
4920 ch->ch_mostat = 0;
4921 ch->ch_hflow = 0;
4922}
4923
4924/*=======================================================================
4925 *
4926 * dgap_param - Set Digi parameters.
4927 *
4928 * struct tty_struct * - TTY for port.
4929 * 5244 *
4930 *=======================================================================*/ 5245 * Init the tty subsystem for this board.
4931static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type) 5246 */
5247static int dgap_tty_register(struct board_t *brd)
4932{ 5248{
4933 u16 head; 5249 int rc;
4934 u16 cflag;
4935 u16 iflag;
4936 u8 mval;
4937 u8 hflow;
4938
4939 /*
4940 * If baud rate is zero, flush queues, and set mval to drop DTR.
4941 */
4942 if ((ch->ch_c_cflag & (CBAUD)) == 0) {
4943
4944 /* flush rx */
4945 head = readw(&(ch->ch_bs->rx_head));
4946 writew(head, &(ch->ch_bs->rx_tail));
4947
4948 /* flush tx */
4949 head = readw(&(ch->ch_bs->tx_head));
4950 writew(head, &(ch->ch_bs->tx_tail));
4951
4952 ch->ch_flags |= (CH_BAUD0);
4953
4954 /* Drop RTS and DTR */
4955 ch->ch_mval &= ~(D_RTS(ch)|D_DTR(ch));
4956 mval = D_DTR(ch) | D_RTS(ch);
4957 ch->ch_baud_info = 0;
4958
4959 } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
4960 /*
4961 * Tell the fep to do the command
4962 */
4963
4964 dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
4965
4966 /*
4967 * Now go get from fep mem, what the fep
4968 * believes the custom baud rate is.
4969 */
4970 ch->ch_custom_speed = dgap_get_custom_baud(ch);
4971 ch->ch_baud_info = ch->ch_custom_speed;
4972
4973 /* Handle transition from B0 */
4974 if (ch->ch_flags & CH_BAUD0) {
4975 ch->ch_flags &= ~(CH_BAUD0);
4976 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
4977 }
4978 mval = D_DTR(ch) | D_RTS(ch);
4979
4980 } else {
4981 /*
4982 * Set baud rate, character size, and parity.
4983 */
4984
4985
4986 int iindex = 0;
4987 int jindex = 0;
4988 int baud = 0;
4989
4990 ulong bauds[4][16] = {
4991 { /* slowbaud */
4992 0, 50, 75, 110,
4993 134, 150, 200, 300,
4994 600, 1200, 1800, 2400,
4995 4800, 9600, 19200, 38400 },
4996 { /* slowbaud & CBAUDEX */
4997 0, 57600, 115200, 230400,
4998 460800, 150, 200, 921600,
4999 600, 1200, 1800, 2400,
5000 4800, 9600, 19200, 38400 },
5001 { /* fastbaud */
5002 0, 57600, 76800, 115200,
5003 14400, 57600, 230400, 76800,
5004 115200, 230400, 28800, 460800,
5005 921600, 9600, 19200, 38400 },
5006 { /* fastbaud & CBAUDEX */
5007 0, 57600, 115200, 230400,
5008 460800, 150, 200, 921600,
5009 600, 1200, 1800, 2400,
5010 4800, 9600, 19200, 38400 }
5011 };
5012
5013 /*
5014 * Only use the TXPrint baud rate if the
5015 * terminal unit is NOT open
5016 */
5017 if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
5018 un_type == DGAP_PRINT)
5019 baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
5020 else
5021 baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
5022
5023 if (ch->ch_c_cflag & CBAUDEX)
5024 iindex = 1;
5025
5026 if (ch->ch_digi.digi_flags & DIGI_FAST)
5027 iindex += 2;
5028
5029 jindex = baud;
5030
5031 if ((iindex >= 0) && (iindex < 4) &&
5032 (jindex >= 0) && (jindex < 16))
5033 baud = bauds[iindex][jindex];
5034 else
5035 baud = 0;
5036
5037 if (baud == 0)
5038 baud = 9600;
5039
5040 ch->ch_baud_info = baud;
5041
5042 /*
5043 * CBAUD has bit position 0x1000 set these days to
5044 * indicate Linux baud rate remap.
5045 * We use a different bit assignment for high speed.
5046 * Clear this bit out while grabbing the parts of
5047 * "cflag" we want.
5048 */
5049 cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
5050 CSTOPB | CSIZE);
5051
5052 /*
5053 * HUPCL bit is used by FEP to indicate fast baud
5054 * table is to be used.
5055 */
5056 if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
5057 (ch->ch_c_cflag & CBAUDEX))
5058 cflag |= HUPCL;
5059
5060 if ((ch->ch_c_cflag & CBAUDEX) &&
5061 !(ch->ch_digi.digi_flags & DIGI_FAST)) {
5062 /*
5063 * The below code is trying to guarantee that only
5064 * baud rates 115200, 230400, 460800, 921600 are
5065 * remapped. We use exclusive or because the various
5066 * baud rates share common bit positions and therefore
5067 * can't be tested for easily.
5068 */
5069 tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
5070 int baudpart = 0;
5071
5072 /*
5073 * Map high speed requests to index
5074 * into FEP's baud table
5075 */
5076 switch (tcflag) {
5077 case B57600:
5078 baudpart = 1;
5079 break;
5080#ifdef B76800
5081 case B76800:
5082 baudpart = 2;
5083 break;
5084#endif
5085 case B115200:
5086 baudpart = 3;
5087 break;
5088 case B230400:
5089 baudpart = 9;
5090 break;
5091 case B460800:
5092 baudpart = 11;
5093 break;
5094#ifdef B921600
5095 case B921600:
5096 baudpart = 12;
5097 break;
5098#endif
5099 default:
5100 baudpart = 0;
5101 }
5102
5103 if (baudpart)
5104 cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
5105 }
5106
5107 cflag &= 0xffff;
5108
5109 if (cflag != ch->ch_fepcflag) {
5110 ch->ch_fepcflag = (u16) (cflag & 0xffff);
5111
5112 /*
5113 * Okay to have channel and board
5114 * locks held calling this
5115 */
5116 dgap_cmdw(ch, SCFLAG, (u16) cflag, 0);
5117 }
5118
5119 /* Handle transition from B0 */
5120 if (ch->ch_flags & CH_BAUD0) {
5121 ch->ch_flags &= ~(CH_BAUD0);
5122 ch->ch_mval |= (D_RTS(ch)|D_DTR(ch));
5123 }
5124 mval = D_DTR(ch) | D_RTS(ch);
5125 }
5126
5127 /*
5128 * Get input flags.
5129 */
5130 iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
5131 INPCK | ISTRIP | IXON | IXANY | IXOFF);
5132
5133 if ((ch->ch_startc == _POSIX_VDISABLE) ||
5134 (ch->ch_stopc == _POSIX_VDISABLE)) {
5135 iflag &= ~(IXON | IXOFF);
5136 ch->ch_c_iflag &= ~(IXON | IXOFF);
5137 }
5138
5139 /*
5140 * Only the IBM Xr card can switch between
5141 * 232 and 422 modes on the fly
5142 */
5143 if (bd->device == PCI_DEV_XR_IBM_DID) {
5144 if (ch->ch_digi.digi_flags & DIGI_422)
5145 dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
5146 else
5147 dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
5148 }
5149
5150 if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
5151 iflag |= IALTPIN;
5152
5153 if (iflag != ch->ch_fepiflag) {
5154 ch->ch_fepiflag = iflag;
5155
5156 /* Okay to have channel and board locks held calling this */
5157 dgap_cmdw(ch, SIFLAG, (u16) ch->ch_fepiflag, 0);
5158 }
5159
5160 /*
5161 * Select hardware handshaking.
5162 */
5163 hflow = 0;
5164
5165 if (ch->ch_c_cflag & CRTSCTS)
5166 hflow |= (D_RTS(ch) | D_CTS(ch));
5167 if (ch->ch_digi.digi_flags & RTSPACE)
5168 hflow |= D_RTS(ch);
5169 if (ch->ch_digi.digi_flags & DTRPACE)
5170 hflow |= D_DTR(ch);
5171 if (ch->ch_digi.digi_flags & CTSPACE)
5172 hflow |= D_CTS(ch);
5173 if (ch->ch_digi.digi_flags & DSRPACE)
5174 hflow |= D_DSR(ch);
5175 if (ch->ch_digi.digi_flags & DCDPACE)
5176 hflow |= D_CD(ch);
5177 5250
5178 if (hflow != ch->ch_hflow) { 5251 brd->serial_driver = tty_alloc_driver(MAXPORTS,
5179 ch->ch_hflow = hflow; 5252 TTY_DRIVER_REAL_RAW |
5253 TTY_DRIVER_DYNAMIC_DEV |
5254 TTY_DRIVER_HARDWARE_BREAK);
5255 if (IS_ERR(brd->serial_driver))
5256 return PTR_ERR(brd->serial_driver);
5180 5257
5181 /* Okay to have channel and board locks held calling this */ 5258 snprintf(brd->serial_name, MAXTTYNAMELEN, "tty_dgap_%d_",
5182 dgap_cmdb(ch, SHFLOW, (u8) hflow, 0xff, 0); 5259 brd->boardnum);
5183 } 5260 brd->serial_driver->name = brd->serial_name;
5261 brd->serial_driver->name_base = 0;
5262 brd->serial_driver->major = 0;
5263 brd->serial_driver->minor_start = 0;
5264 brd->serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
5265 brd->serial_driver->subtype = SERIAL_TYPE_NORMAL;
5266 brd->serial_driver->init_termios = dgap_default_termios;
5267 brd->serial_driver->driver_name = DRVSTR;
5184 5268
5185 /* 5269 /*
5186 * Set RTS and/or DTR Toggle if needed, 5270 * Entry points for driver. Called by the kernel from
5187 * but only if product is FEP5+ based. 5271 * tty_io.c and n_tty.c.
5188 */ 5272 */
5189 if (bd->bd_flags & BD_FEP5PLUS) { 5273 tty_set_operations(brd->serial_driver, &dgap_tty_ops);
5190 u16 hflow2 = 0;
5191
5192 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
5193 hflow2 |= (D_RTS(ch));
5194 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
5195 hflow2 |= (D_DTR(ch));
5196
5197 dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
5198 }
5199 5274
5200 /* 5275 /*
5201 * Set modem control lines. 5276 * If we're doing transparent print, we have to do all of the above
5277 * again, separately so we don't get the LD confused about what major
5278 * we are when we get into the dgap_tty_open() routine.
5202 */ 5279 */
5203 5280 brd->print_driver = tty_alloc_driver(MAXPORTS,
5204 mval ^= ch->ch_mforce & (mval ^ ch->ch_mval); 5281 TTY_DRIVER_REAL_RAW |
5205 5282 TTY_DRIVER_DYNAMIC_DEV |
5206 if (ch->ch_mostat ^ mval) { 5283 TTY_DRIVER_HARDWARE_BREAK);
5207 ch->ch_mostat = mval; 5284 if (IS_ERR(brd->print_driver)) {
5208 5285 rc = PTR_ERR(brd->print_driver);
5209 /* Okay to have channel and board locks held calling this */ 5286 goto free_serial_drv;
5210 dgap_cmdb(ch, SMODEM, (u8) mval, D_RTS(ch)|D_DTR(ch), 0);
5211 } 5287 }
5212 5288
5213 /* 5289 snprintf(brd->print_name, MAXTTYNAMELEN, "pr_dgap_%d_",
5214 * Read modem signals, and then call carrier function. 5290 brd->boardnum);
5215 */ 5291 brd->print_driver->name = brd->print_name;
5216 ch->ch_mistat = readb(&(ch->ch_bs->m_stat)); 5292 brd->print_driver->name_base = 0;
5217 dgap_carrier(ch); 5293 brd->print_driver->major = 0;
5294 brd->print_driver->minor_start = 0;
5295 brd->print_driver->type = TTY_DRIVER_TYPE_SERIAL;
5296 brd->print_driver->subtype = SERIAL_TYPE_NORMAL;
5297 brd->print_driver->init_termios = dgap_default_termios;
5298 brd->print_driver->driver_name = DRVSTR;
5218 5299
5219 /* 5300 /*
5220 * Set the start and stop characters. 5301 * Entry points for driver. Called by the kernel from
5302 * tty_io.c and n_tty.c.
5221 */ 5303 */
5222 if (ch->ch_startc != ch->ch_fepstartc || 5304 tty_set_operations(brd->print_driver, &dgap_tty_ops);
5223 ch->ch_stopc != ch->ch_fepstopc) {
5224 ch->ch_fepstartc = ch->ch_startc;
5225 ch->ch_fepstopc = ch->ch_stopc;
5226
5227 /* Okay to have channel and board locks held calling this */
5228 dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
5229 }
5230 5305
5231 /* 5306 /* Register tty devices */
5232 * Set the Auxiliary start and stop characters. 5307 rc = tty_register_driver(brd->serial_driver);
5233 */ 5308 if (rc < 0)
5234 if (ch->ch_astartc != ch->ch_fepastartc || 5309 goto free_print_drv;
5235 ch->ch_astopc != ch->ch_fepastopc) {
5236 ch->ch_fepastartc = ch->ch_astartc;
5237 ch->ch_fepastopc = ch->ch_astopc;
5238 5310
5239 /* Okay to have channel and board locks held calling this */ 5311 /* Register Transparent Print devices */
5240 dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0); 5312 rc = tty_register_driver(brd->print_driver);
5241 } 5313 if (rc < 0)
5314 goto unregister_serial_drv;
5242 5315
5243 return 0; 5316 return 0;
5244}
5245
5246/*
5247 * dgap_parity_scan()
5248 *
5249 * Convert the FEP5 way of reporting parity errors and breaks into
5250 * the Linux line discipline way.
5251 */
5252static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
5253 unsigned char *fbuf, int *len)
5254{
5255 int l = *len;
5256 int count = 0;
5257 unsigned char *in, *cout, *fout;
5258 unsigned char c;
5259
5260 in = cbuf;
5261 cout = cbuf;
5262 fout = fbuf;
5263
5264 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5265 return;
5266 5317
5267 while (l--) { 5318unregister_serial_drv:
5268 c = *in++; 5319 tty_unregister_driver(brd->serial_driver);
5269 switch (ch->pscan_state) { 5320free_print_drv:
5270 default: 5321 put_tty_driver(brd->print_driver);
5271 /* reset to sanity and fall through */ 5322free_serial_drv:
5272 ch->pscan_state = 0; 5323 put_tty_driver(brd->serial_driver);
5273
5274 case 0:
5275 /* No FF seen yet */
5276 if (c == (unsigned char) '\377')
5277 /* delete this character from stream */
5278 ch->pscan_state = 1;
5279 else {
5280 *cout++ = c;
5281 *fout++ = TTY_NORMAL;
5282 count += 1;
5283 }
5284 break;
5285
5286 case 1:
5287 /* first FF seen */
5288 if (c == (unsigned char) '\377') {
5289 /* doubled ff, transform to single ff */
5290 *cout++ = c;
5291 *fout++ = TTY_NORMAL;
5292 count += 1;
5293 ch->pscan_state = 0;
5294 } else {
5295 /* save value examination in next state */
5296 ch->pscan_savechar = c;
5297 ch->pscan_state = 2;
5298 }
5299 break;
5300
5301 case 2:
5302 /* third character of ff sequence */
5303
5304 *cout++ = c;
5305
5306 if (ch->pscan_savechar == 0x0) {
5307
5308 if (c == 0x0) {
5309 ch->ch_err_break++;
5310 *fout++ = TTY_BREAK;
5311 } else {
5312 ch->ch_err_parity++;
5313 *fout++ = TTY_PARITY;
5314 }
5315 }
5316 5324
5317 count += 1; 5325 return rc;
5318 ch->pscan_state = 0;
5319 }
5320 }
5321 *len = count;
5322} 5326}
5323 5327
5324static void dgap_write_wakeup(struct board_t *bd, struct channel_t *ch, 5328static void dgap_tty_unregister(struct board_t *brd)
5325 struct un_t *un, u32 mask,
5326 unsigned long *irq_flags1,
5327 unsigned long *irq_flags2)
5328{ 5329{
5329 if (!(un->un_flags & mask)) 5330 tty_unregister_driver(brd->print_driver);
5330 return; 5331 tty_unregister_driver(brd->serial_driver);
5331 5332 put_tty_driver(brd->print_driver);
5332 un->un_flags &= ~mask; 5333 put_tty_driver(brd->serial_driver);
5333
5334 if (!(un->un_flags & UN_ISOPEN))
5335 return;
5336
5337 if ((un->un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
5338 un->un_tty->ldisc->ops->write_wakeup) {
5339 spin_unlock_irqrestore(&ch->ch_lock, *irq_flags2);
5340 spin_unlock_irqrestore(&bd->bd_lock, *irq_flags1);
5341
5342 (un->un_tty->ldisc->ops->write_wakeup)(un->un_tty);
5343
5344 spin_lock_irqsave(&bd->bd_lock, *irq_flags1);
5345 spin_lock_irqsave(&ch->ch_lock, *irq_flags2);
5346 }
5347 wake_up_interruptible(&un->un_tty->write_wait);
5348 wake_up_interruptible(&un->un_flags_wait);
5349} 5334}
5350 5335
5351/*======================================================================= 5336static int dgap_alloc_flipbuf(struct board_t *brd)
5352 *
5353 * dgap_event - FEP to host event processing routine.
5354 *
5355 * bd - Board of current event.
5356 *
5357 *=======================================================================*/
5358static int dgap_event(struct board_t *bd)
5359{ 5337{
5360 struct channel_t *ch;
5361 ulong lock_flags;
5362 ulong lock_flags2;
5363 struct bs_t __iomem *bs;
5364 u8 __iomem *event;
5365 u8 __iomem *vaddr;
5366 struct ev_t __iomem *eaddr;
5367 uint head;
5368 uint tail;
5369 int port;
5370 int reason;
5371 int modem;
5372 int b1;
5373
5374 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
5375 return -EIO;
5376
5377 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5378
5379 vaddr = bd->re_map_membase;
5380
5381 if (!vaddr) {
5382 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5383 return -EIO;
5384 }
5385
5386 eaddr = (struct ev_t __iomem *) (vaddr + EVBUF);
5387
5388 /* Get our head and tail */
5389 head = readw(&(eaddr->ev_head));
5390 tail = readw(&(eaddr->ev_tail));
5391
5392 /*
5393 * Forget it if pointers out of range.
5394 */
5395
5396 if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
5397 (head | tail) & 03) {
5398 /* Let go of board lock */
5399 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5400 return -EIO;
5401 }
5402
5403 /* 5338 /*
5404 * Loop to process all the events in the buffer. 5339 * allocate flip buffer for board.
5405 */ 5340 */
5406 while (tail != head) { 5341 brd->flipbuf = kmalloc(MYFLIPLEN, GFP_KERNEL);
5407 5342 if (!brd->flipbuf)
5408 /* 5343 return -ENOMEM;
5409 * Get interrupt information.
5410 */
5411
5412 event = bd->re_map_membase + tail + EVSTART;
5413
5414 port = ioread8(event);
5415 reason = ioread8(event + 1);
5416 modem = ioread8(event + 2);
5417 b1 = ioread8(event + 3);
5418
5419 /*
5420 * Make sure the interrupt is valid.
5421 */
5422 if (port >= bd->nasync)
5423 goto next;
5424
5425 if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
5426 goto next;
5427
5428 ch = bd->channels[port];
5429
5430 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
5431 goto next;
5432
5433 /*
5434 * If we have made it here, the event was valid.
5435 * Lock down the channel.
5436 */
5437 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5438
5439 bs = ch->ch_bs;
5440
5441 if (!bs) {
5442 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5443 goto next;
5444 }
5445
5446 /*
5447 * Process received data.
5448 */
5449 if (reason & IFDATA) {
5450
5451 /*
5452 * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
5453 * input could send some data to ld, which in turn
5454 * could do a callback to one of our other functions.
5455 */
5456 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5457 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5458
5459 dgap_input(ch);
5460
5461 spin_lock_irqsave(&bd->bd_lock, lock_flags);
5462 spin_lock_irqsave(&ch->ch_lock, lock_flags2);
5463
5464 if (ch->ch_flags & CH_RACTIVE)
5465 ch->ch_flags |= CH_RENABLE;
5466 else
5467 writeb(1, &(bs->idata));
5468
5469 if (ch->ch_flags & CH_RWAIT) {
5470 ch->ch_flags &= ~CH_RWAIT;
5471
5472 wake_up_interruptible
5473 (&ch->ch_tun.un_flags_wait);
5474 }
5475 }
5476
5477 /*
5478 * Process Modem change signals.
5479 */
5480 if (reason & IFMODEM) {
5481 ch->ch_mistat = modem;
5482 dgap_carrier(ch);
5483 }
5484
5485 /*
5486 * Process break.
5487 */
5488 if (reason & IFBREAK) {
5489
5490 if (ch->ch_tun.un_tty) {
5491 /* A break has been indicated */
5492 ch->ch_err_break++;
5493 tty_buffer_request_room
5494 (ch->ch_tun.un_tty->port, 1);
5495 tty_insert_flip_char(ch->ch_tun.un_tty->port,
5496 0, TTY_BREAK);
5497 tty_flip_buffer_push(ch->ch_tun.un_tty->port);
5498 }
5499 }
5500
5501 /*
5502 * Process Transmit low.
5503 */
5504 if (reason & IFTLW) {
5505 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_LOW,
5506 &lock_flags, &lock_flags2);
5507 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_LOW,
5508 &lock_flags, &lock_flags2);
5509 if (ch->ch_flags & CH_WLOW) {
5510 ch->ch_flags &= ~CH_WLOW;
5511 wake_up_interruptible(&ch->ch_flags_wait);
5512 }
5513 }
5514
5515 /*
5516 * Process Transmit empty.
5517 */
5518 if (reason & IFTEM) {
5519 dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_EMPTY,
5520 &lock_flags, &lock_flags2);
5521 dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_EMPTY,
5522 &lock_flags, &lock_flags2);
5523 if (ch->ch_flags & CH_WEMPTY) {
5524 ch->ch_flags &= ~CH_WEMPTY;
5525 wake_up_interruptible(&ch->ch_flags_wait);
5526 }
5527 }
5528
5529 spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
5530 5344
5531next: 5345 brd->flipflagbuf = kmalloc(MYFLIPLEN, GFP_KERNEL);
5532 tail = (tail + 4) & (EVMAX - EVSTART - 4); 5346 if (!brd->flipflagbuf) {
5347 kfree(brd->flipbuf);
5348 return -ENOMEM;
5533 } 5349 }
5534 5350
5535 writew(tail, &(eaddr->ev_tail));
5536 spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
5537
5538 return 0; 5351 return 0;
5539} 5352}
5540 5353
5541static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf) 5354static void dgap_free_flipbuf(struct board_t *brd)
5542{
5543 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
5544}
5545static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
5546
5547
5548static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
5549{
5550 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_numboards);
5551}
5552static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
5553
5554
5555static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
5556{
5557 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
5558}
5559static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
5560
5561
5562static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp,
5563 char *buf)
5564{
5565 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
5566}
5567static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
5568
5569static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
5570{
5571 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
5572}
5573
5574static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp,
5575 const char *buf, size_t count)
5576{
5577 if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
5578 return -EINVAL;
5579 return count;
5580}
5581static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show,
5582 dgap_driver_pollrate_store);
5583
5584static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
5585{
5586 int rc = 0;
5587 struct device_driver *driverfs = &dgap_driver->driver;
5588
5589 rc |= driver_create_file(driverfs, &driver_attr_version);
5590 rc |= driver_create_file(driverfs, &driver_attr_boards);
5591 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
5592 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
5593 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
5594
5595 return rc;
5596}
5597
5598static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
5599{ 5355{
5600 struct device_driver *driverfs = &dgap_driver->driver; 5356 kfree(brd->flipbuf);
5601 5357 kfree(brd->flipflagbuf);
5602 driver_remove_file(driverfs, &driver_attr_version);
5603 driver_remove_file(driverfs, &driver_attr_boards);
5604 driver_remove_file(driverfs, &driver_attr_maxboards);
5605 driver_remove_file(driverfs, &driver_attr_pollrate);
5606 driver_remove_file(driverfs, &driver_attr_pollcounter);
5607} 5358}
5608 5359
5609static struct board_t *dgap_verify_board(struct device *p) 5360static struct board_t *dgap_verify_board(struct device *p)
@@ -5626,7 +5377,7 @@ static ssize_t dgap_ports_state_show(struct device *p,
5626{ 5377{
5627 struct board_t *bd; 5378 struct board_t *bd;
5628 int count = 0; 5379 int count = 0;
5629 int i; 5380 unsigned int i;
5630 5381
5631 bd = dgap_verify_board(p); 5382 bd = dgap_verify_board(p);
5632 if (!bd) 5383 if (!bd)
@@ -5647,7 +5398,7 @@ static ssize_t dgap_ports_baud_show(struct device *p,
5647{ 5398{
5648 struct board_t *bd; 5399 struct board_t *bd;
5649 int count = 0; 5400 int count = 0;
5650 int i; 5401 unsigned int i;
5651 5402
5652 bd = dgap_verify_board(p); 5403 bd = dgap_verify_board(p);
5653 if (!bd) 5404 if (!bd)
@@ -5668,7 +5419,7 @@ static ssize_t dgap_ports_msignals_show(struct device *p,
5668{ 5419{
5669 struct board_t *bd; 5420 struct board_t *bd;
5670 int count = 0; 5421 int count = 0;
5671 int i; 5422 unsigned int i;
5672 5423
5673 bd = dgap_verify_board(p); 5424 bd = dgap_verify_board(p);
5674 if (!bd) 5425 if (!bd)
@@ -5705,7 +5456,7 @@ static ssize_t dgap_ports_iflag_show(struct device *p,
5705{ 5456{
5706 struct board_t *bd; 5457 struct board_t *bd;
5707 int count = 0; 5458 int count = 0;
5708 int i; 5459 unsigned int i;
5709 5460
5710 bd = dgap_verify_board(p); 5461 bd = dgap_verify_board(p);
5711 if (!bd) 5462 if (!bd)
@@ -5725,7 +5476,7 @@ static ssize_t dgap_ports_cflag_show(struct device *p,
5725{ 5476{
5726 struct board_t *bd; 5477 struct board_t *bd;
5727 int count = 0; 5478 int count = 0;
5728 int i; 5479 unsigned int i;
5729 5480
5730 bd = dgap_verify_board(p); 5481 bd = dgap_verify_board(p);
5731 if (!bd) 5482 if (!bd)
@@ -5745,7 +5496,7 @@ static ssize_t dgap_ports_oflag_show(struct device *p,
5745{ 5496{
5746 struct board_t *bd; 5497 struct board_t *bd;
5747 int count = 0; 5498 int count = 0;
5748 int i; 5499 unsigned int i;
5749 5500
5750 bd = dgap_verify_board(p); 5501 bd = dgap_verify_board(p);
5751 if (!bd) 5502 if (!bd)
@@ -5765,7 +5516,7 @@ static ssize_t dgap_ports_lflag_show(struct device *p,
5765{ 5516{
5766 struct board_t *bd; 5517 struct board_t *bd;
5767 int count = 0; 5518 int count = 0;
5768 int i; 5519 unsigned int i;
5769 5520
5770 bd = dgap_verify_board(p); 5521 bd = dgap_verify_board(p);
5771 if (!bd) 5522 if (!bd)
@@ -5785,7 +5536,7 @@ static ssize_t dgap_ports_digi_flag_show(struct device *p,
5785{ 5536{
5786 struct board_t *bd; 5537 struct board_t *bd;
5787 int count = 0; 5538 int count = 0;
5788 int i; 5539 unsigned int i;
5789 5540
5790 bd = dgap_verify_board(p); 5541 bd = dgap_verify_board(p);
5791 if (!bd) 5542 if (!bd)
@@ -5805,7 +5556,7 @@ static ssize_t dgap_ports_rxcount_show(struct device *p,
5805{ 5556{
5806 struct board_t *bd; 5557 struct board_t *bd;
5807 int count = 0; 5558 int count = 0;
5808 int i; 5559 unsigned int i;
5809 5560
5810 bd = dgap_verify_board(p); 5561 bd = dgap_verify_board(p);
5811 if (!bd) 5562 if (!bd)
@@ -5825,7 +5576,7 @@ static ssize_t dgap_ports_txcount_show(struct device *p,
5825{ 5576{
5826 struct board_t *bd; 5577 struct board_t *bd;
5827 int count = 0; 5578 int count = 0;
5828 int i; 5579 unsigned int i;
5829 5580
5830 bd = dgap_verify_board(p); 5581 bd = dgap_verify_board(p);
5831 if (!bd) 5582 if (!bd)
@@ -5839,39 +5590,6 @@ static ssize_t dgap_ports_txcount_show(struct device *p,
5839} 5590}
5840static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL); 5591static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
5841 5592
5842/* this function creates the sys files that will export each signal status
5843 * to sysfs each value will be put in a separate filename
5844 */
5845static void dgap_create_ports_sysfiles(struct board_t *bd)
5846{
5847 dev_set_drvdata(&bd->pdev->dev, bd);
5848 device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
5849 device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
5850 device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
5851 device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
5852 device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
5853 device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
5854 device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
5855 device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
5856 device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
5857 device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
5858}
5859
5860/* removes all the sys files created for that port */
5861static void dgap_remove_ports_sysfiles(struct board_t *bd)
5862{
5863 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
5864 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
5865 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
5866 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
5867 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
5868 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
5869 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
5870 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
5871 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
5872 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
5873}
5874
5875static ssize_t dgap_tty_state_show(struct device *d, 5593static ssize_t dgap_tty_state_show(struct device *d,
5876 struct device_attribute *attr, 5594 struct device_attribute *attr,
5877 char *buf) 5595 char *buf)
@@ -6242,7 +5960,6 @@ static ssize_t dgap_tty_name_show(struct device *d,
6242 } 5960 }
6243 5961
6244 ncount += cptr->u.module.nport; 5962 ncount += cptr->u.module.nport;
6245
6246 } 5963 }
6247 } 5964 }
6248 5965
@@ -6266,1086 +5983,1211 @@ static struct attribute *dgap_sysfs_tty_entries[] = {
6266 NULL 5983 NULL
6267}; 5984};
6268 5985
6269static struct attribute_group dgap_tty_attribute_group = {
6270 .name = NULL,
6271 .attrs = dgap_sysfs_tty_entries,
6272};
6273 5986
6274static void dgap_create_tty_sysfs(struct un_t *un, struct device *c) 5987/* this function creates the sys files that will export each signal status
5988 * to sysfs each value will be put in a separate filename
5989 */
5990static void dgap_create_ports_sysfiles(struct board_t *bd)
6275{ 5991{
6276 int ret; 5992 dev_set_drvdata(&bd->pdev->dev, bd);
6277 5993 device_create_file(&(bd->pdev->dev), &dev_attr_ports_state);
6278 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group); 5994 device_create_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6279 if (ret) 5995 device_create_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6280 return; 5996 device_create_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6281 5997 device_create_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6282 dev_set_drvdata(c, un); 5998 device_create_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6283 5999 device_create_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6000 device_create_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6001 device_create_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6002 device_create_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6284} 6003}
6285 6004
6286static void dgap_remove_tty_sysfs(struct device *c) 6005/* removes all the sys files created for that port */
6006static void dgap_remove_ports_sysfiles(struct board_t *bd)
6287{ 6007{
6288 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group); 6008 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_state);
6009 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_baud);
6010 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_msignals);
6011 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_iflag);
6012 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_cflag);
6013 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_oflag);
6014 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_lflag);
6015 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_digi_flag);
6016 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_rxcount);
6017 device_remove_file(&(bd->pdev->dev), &dev_attr_ports_txcount);
6289} 6018}
6290 6019
6291static void dgap_cleanup_nodes(void) 6020/*
6021 * Copies the BIOS code from the user to the board,
6022 * and starts the BIOS running.
6023 */
6024static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len)
6292{ 6025{
6293 struct cnode *p; 6026 u8 __iomem *addr;
6027 uint offset;
6028 unsigned int i;
6294 6029
6295 p = &dgap_head; 6030 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
6031 return;
6296 6032
6297 while (p) { 6033 addr = brd->re_map_membase;
6298 struct cnode *tmp = p->next;
6299 6034
6300 if (p->type == NULLNODE) { 6035 /*
6301 p = tmp; 6036 * clear POST area
6302 continue; 6037 */
6303 } 6038 for (i = 0; i < 16; i++)
6039 writeb(0, addr + POSTAREA + i);
6304 6040
6305 switch (p->type) { 6041 /*
6306 case BNODE: 6042 * Download bios
6307 kfree(p->u.board.portstr); 6043 */
6308 kfree(p->u.board.addrstr); 6044 offset = 0x1000;
6309 kfree(p->u.board.pcibusstr); 6045 memcpy_toio(addr + offset, ubios, len);
6310 kfree(p->u.board.pcislotstr);
6311 kfree(p->u.board.method);
6312 break;
6313 case CNODE:
6314 kfree(p->u.conc.id);
6315 kfree(p->u.conc.connect);
6316 break;
6317 case MNODE:
6318 kfree(p->u.module.id);
6319 break;
6320 case TNODE:
6321 kfree(p->u.ttyname);
6322 break;
6323 case CUNODE:
6324 kfree(p->u.cuname);
6325 break;
6326 case LNODE:
6327 kfree(p->u.line.cable);
6328 break;
6329 case PNODE:
6330 kfree(p->u.printname);
6331 break;
6332 }
6333 6046
6334 kfree(p->u.board.status); 6047 writel(0x0bf00401, addr);
6335 kfree(p); 6048 writel(0, (addr + 4));
6336 p = tmp; 6049
6337 } 6050 /* Clear the reset, and change states. */
6051 writeb(FEPCLR, brd->re_map_port);
6338} 6052}
6053
6339/* 6054/*
6340 * Parse a configuration file read into memory as a string. 6055 * Checks to see if the BIOS completed running on the card.
6341 */ 6056 */
6342static int dgap_parsefile(char **in) 6057static int dgap_test_bios(struct board_t *brd)
6343{ 6058{
6344 struct cnode *p, *brd, *line, *conc; 6059 u8 __iomem *addr;
6345 int rc; 6060 u16 word;
6346 char *s; 6061 u16 err1;
6347 int linecnt = 0; 6062 u16 err2;
6348 6063
6349 p = &dgap_head; 6064 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
6350 brd = line = conc = NULL; 6065 return -EINVAL;
6351 6066
6352 /* perhaps we are adding to an existing list? */ 6067 addr = brd->re_map_membase;
6353 while (p->next) 6068 word = readw(addr + POSTAREA);
6354 p = p->next;
6355 6069
6356 /* file must start with a BEGIN */ 6070 /*
6357 while ((rc = dgap_gettok(in)) != BEGIN) { 6071 * It can take 5-6 seconds for a board to
6358 if (rc == 0) { 6072 * pass the bios self test and post results.
6359 pr_err("unexpected EOF"); 6073 * Give it 10 seconds.
6360 return -1; 6074 */
6361 } 6075 brd->wait_for_bios = 0;
6076 while (brd->wait_for_bios < 1000) {
6077 /* Check to see if BIOS thinks board is good. (GD). */
6078 if (word == *(u16 *) "GD")
6079 return 0;
6080 msleep_interruptible(10);
6081 brd->wait_for_bios++;
6082 word = readw(addr + POSTAREA);
6362 } 6083 }
6363 6084
6364 for (; ;) { 6085 /* Gave up on board after too long of time taken */
6365 int board_type = 0; 6086 err1 = readw(addr + SEQUENCE);
6366 int conc_type = 0; 6087 err2 = readw(addr + ERROR);
6367 int module_type = 0; 6088 dev_warn(&brd->pdev->dev, "%s failed diagnostics. Error #(%x,%x).\n",
6089 brd->name, err1, err2);
6090 brd->state = BOARD_FAILED;
6091 brd->dpastatus = BD_NOBIOS;
6368 6092
6369 rc = dgap_gettok(in); 6093 return -EIO;
6370 if (rc == 0) { 6094}
6371 pr_err("unexpected EOF");
6372 return -1;
6373 }
6374 6095
6375 switch (rc) { 6096/*
6376 case BEGIN: /* should only be 1 begin */ 6097 * Copies the FEP code from the user to the board,
6377 pr_err("unexpected config_begin\n"); 6098 * and starts the FEP running.
6378 return -1; 6099 */
6100static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len)
6101{
6102 u8 __iomem *addr;
6103 uint offset;
6379 6104
6380 case END: 6105 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
6381 return 0; 6106 return;
6382 6107
6383 case BOARD: /* board info */ 6108 addr = brd->re_map_membase;
6384 if (dgap_checknode(p))
6385 return -1;
6386 6109
6387 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); 6110 /*
6388 if (!p->next) 6111 * Download FEP
6389 return -1; 6112 */
6113 offset = 0x1000;
6114 memcpy_toio(addr + offset, ufep, len);
6390 6115
6391 p = p->next; 6116 /*
6117 * If board is a concentrator product, we need to give
6118 * it its config string describing how the concentrators look.
6119 */
6120 if ((brd->type == PCX) || (brd->type == PEPC)) {
6121 u8 string[100];
6122 u8 __iomem *config;
6123 u8 *xconfig;
6124 unsigned int i = 0;
6392 6125
6393 p->type = BNODE; 6126 xconfig = dgap_create_config_string(brd, string);
6394 p->u.board.status = kstrdup("No", GFP_KERNEL);
6395 line = conc = NULL;
6396 brd = p;
6397 linecnt = -1;
6398 6127
6399 board_type = dgap_gettok(in); 6128 /* Write string to board memory */
6400 if (board_type == 0) { 6129 config = addr + CONFIG;
6401 pr_err("board !!type not specified"); 6130 for (; i < CONFIGSIZE; i++, config++, xconfig++) {
6402 return -1; 6131 writeb(*xconfig, config);
6403 } 6132 if ((*xconfig & 0xff) == 0xff)
6133 break;
6134 }
6135 }
6404 6136
6405 p->u.board.type = board_type; 6137 writel(0xbfc01004, (addr + 0xc34));
6138 writel(0x3, (addr + 0xc30));
6406 6139
6407 break; 6140}
6408 6141
6409 case IO: /* i/o port */ 6142/*
6410 if (p->type != BNODE) { 6143 * Waits for the FEP to report thats its ready for us to use.
6411 pr_err("IO port only vaild for boards"); 6144 */
6412 return -1; 6145static int dgap_test_fep(struct board_t *brd)
6413 } 6146{
6414 s = dgap_getword(in); 6147 u8 __iomem *addr;
6415 if (!s) { 6148 u16 word;
6416 pr_err("unexpected end of file"); 6149 u16 err1;
6417 return -1; 6150 u16 err2;
6418 }
6419 p->u.board.portstr = kstrdup(s, GFP_KERNEL);
6420 if (kstrtol(s, 0, &p->u.board.port)) {
6421 pr_err("bad number for IO port");
6422 return -1;
6423 }
6424 p->u.board.v_port = 1;
6425 break;
6426 6151
6427 case MEM: /* memory address */ 6152 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
6428 if (p->type != BNODE) { 6153 return -EINVAL;
6429 pr_err("memory address only vaild for boards");
6430 return -1;
6431 }
6432 s = dgap_getword(in);
6433 if (!s) {
6434 pr_err("unexpected end of file");
6435 return -1;
6436 }
6437 p->u.board.addrstr = kstrdup(s, GFP_KERNEL);
6438 if (kstrtoul(s, 0, &p->u.board.addr)) {
6439 pr_err("bad number for memory address");
6440 return -1;
6441 }
6442 p->u.board.v_addr = 1;
6443 break;
6444 6154
6445 case PCIINFO: /* pci information */ 6155 addr = brd->re_map_membase;
6446 if (p->type != BNODE) { 6156 word = readw(addr + FEPSTAT);
6447 pr_err("memory address only vaild for boards");
6448 return -1;
6449 }
6450 s = dgap_getword(in);
6451 if (!s) {
6452 pr_err("unexpected end of file");
6453 return -1;
6454 }
6455 p->u.board.pcibusstr = kstrdup(s, GFP_KERNEL);
6456 if (kstrtoul(s, 0, &p->u.board.pcibus)) {
6457 pr_err("bad number for pci bus");
6458 return -1;
6459 }
6460 p->u.board.v_pcibus = 1;
6461 s = dgap_getword(in);
6462 if (!s) {
6463 pr_err("unexpected end of file");
6464 return -1;
6465 }
6466 p->u.board.pcislotstr = kstrdup(s, GFP_KERNEL);
6467 if (kstrtoul(s, 0, &p->u.board.pcislot)) {
6468 pr_err("bad number for pci slot");
6469 return -1;
6470 }
6471 p->u.board.v_pcislot = 1;
6472 break;
6473 6157
6474 case METHOD: 6158 /*
6475 if (p->type != BNODE) { 6159 * It can take 2-3 seconds for the FEP to
6476 pr_err("install method only vaild for boards"); 6160 * be up and running. Give it 5 secs.
6477 return -1; 6161 */
6478 } 6162 brd->wait_for_fep = 0;
6479 s = dgap_getword(in); 6163 while (brd->wait_for_fep < 500) {
6480 if (!s) { 6164 /* Check to see if FEP is up and running now. */
6481 pr_err("unexpected end of file"); 6165 if (word == *(u16 *) "OS") {
6482 return -1; 6166 /*
6483 } 6167 * Check to see if the board can support FEP5+ commands.
6484 p->u.board.method = kstrdup(s, GFP_KERNEL); 6168 */
6485 p->u.board.v_method = 1; 6169 word = readw(addr + FEP5_PLUS);
6486 break; 6170 if (word == *(u16 *) "5A")
6171 brd->bd_flags |= BD_FEP5PLUS;
6487 6172
6488 case STATUS: 6173 return 0;
6489 if (p->type != BNODE) { 6174 }
6490 pr_err("config status only vaild for boards"); 6175 msleep_interruptible(10);
6491 return -1; 6176 brd->wait_for_fep++;
6492 } 6177 word = readw(addr + FEPSTAT);
6493 s = dgap_getword(in); 6178 }
6494 if (!s) {
6495 pr_err("unexpected end of file");
6496 return -1;
6497 }
6498 p->u.board.status = kstrdup(s, GFP_KERNEL);
6499 break;
6500 6179
6501 case NPORTS: /* number of ports */ 6180 /* Gave up on board after too long of time taken */
6502 if (p->type == BNODE) { 6181 err1 = readw(addr + SEQUENCE);
6503 s = dgap_getword(in); 6182 err2 = readw(addr + ERROR);
6504 if (!s) { 6183 dev_warn(&brd->pdev->dev,
6505 pr_err("unexpected end of file"); 6184 "FEPOS for %s not functioning. Error #(%x,%x).\n",
6506 return -1; 6185 brd->name, err1, err2);
6507 } 6186 brd->state = BOARD_FAILED;
6508 if (kstrtol(s, 0, &p->u.board.nport)) { 6187 brd->dpastatus = BD_NOFEP;
6509 pr_err("bad number for number of ports");
6510 return -1;
6511 }
6512 p->u.board.v_nport = 1;
6513 } else if (p->type == CNODE) {
6514 s = dgap_getword(in);
6515 if (!s) {
6516 pr_err("unexpected end of file");
6517 return -1;
6518 }
6519 if (kstrtol(s, 0, &p->u.conc.nport)) {
6520 pr_err("bad number for number of ports");
6521 return -1;
6522 }
6523 p->u.conc.v_nport = 1;
6524 } else if (p->type == MNODE) {
6525 s = dgap_getword(in);
6526 if (!s) {
6527 pr_err("unexpected end of file");
6528 return -1;
6529 }
6530 if (kstrtol(s, 0, &p->u.module.nport)) {
6531 pr_err("bad number for number of ports");
6532 return -1;
6533 }
6534 p->u.module.v_nport = 1;
6535 } else {
6536 pr_err("nports only valid for concentrators or modules");
6537 return -1;
6538 }
6539 break;
6540 6188
6541 case ID: /* letter ID used in tty name */ 6189 return -EIO;
6542 s = dgap_getword(in); 6190}
6543 if (!s) {
6544 pr_err("unexpected end of file");
6545 return -1;
6546 }
6547 6191
6548 p->u.board.status = kstrdup(s, GFP_KERNEL); 6192/*
6193 * Physically forces the FEP5 card to reset itself.
6194 */
6195static void dgap_do_reset_board(struct board_t *brd)
6196{
6197 u8 check;
6198 u32 check1;
6199 u32 check2;
6200 unsigned int i;
6549 6201
6550 if (p->type == CNODE) { 6202 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
6551 p->u.conc.id = kstrdup(s, GFP_KERNEL); 6203 !brd->re_map_membase || !brd->re_map_port)
6552 p->u.conc.v_id = 1; 6204 return;
6553 } else if (p->type == MNODE) {
6554 p->u.module.id = kstrdup(s, GFP_KERNEL);
6555 p->u.module.v_id = 1;
6556 } else {
6557 pr_err("id only valid for concentrators or modules");
6558 return -1;
6559 }
6560 break;
6561 6205
6562 case STARTO: /* start offset of ID */ 6206 /* FEPRST does not vary among supported boards */
6563 if (p->type == BNODE) { 6207 writeb(FEPRST, brd->re_map_port);
6564 s = dgap_getword(in); 6208
6565 if (!s) { 6209 for (i = 0; i <= 1000; i++) {
6566 pr_err("unexpected end of file"); 6210 check = readb(brd->re_map_port) & 0xe;
6567 return -1; 6211 if (check == FEPRST)
6568 }
6569 if (kstrtol(s, 0, &p->u.board.start)) {
6570 pr_err("bad number for start of tty count");
6571 return -1;
6572 }
6573 p->u.board.v_start = 1;
6574 } else if (p->type == CNODE) {
6575 s = dgap_getword(in);
6576 if (!s) {
6577 pr_err("unexpected end of file");
6578 return -1;
6579 }
6580 if (kstrtol(s, 0, &p->u.conc.start)) {
6581 pr_err("bad number for start of tty count");
6582 return -1;
6583 }
6584 p->u.conc.v_start = 1;
6585 } else if (p->type == MNODE) {
6586 s = dgap_getword(in);
6587 if (!s) {
6588 pr_err("unexpected end of file");
6589 return -1;
6590 }
6591 if (kstrtol(s, 0, &p->u.module.start)) {
6592 pr_err("bad number for start of tty count");
6593 return -1;
6594 }
6595 p->u.module.v_start = 1;
6596 } else {
6597 pr_err("start only valid for concentrators or modules");
6598 return -1;
6599 }
6600 break; 6212 break;
6213 udelay(10);
6601 6214
6602 case TTYN: /* tty name prefix */ 6215 }
6603 if (dgap_checknode(p)) 6216 if (i > 1000) {
6604 return -1; 6217 dev_warn(&brd->pdev->dev,
6218 "dgap: Board not resetting... Failing board.\n");
6219 brd->state = BOARD_FAILED;
6220 brd->dpastatus = BD_NOFEP;
6221 return;
6222 }
6605 6223
6606 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); 6224 /*
6607 if (!p->next) 6225 * Make sure there really is memory out there.
6608 return -1; 6226 */
6227 writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
6228 writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
6229 check1 = readl(brd->re_map_membase + LOWMEM);
6230 check2 = readl(brd->re_map_membase + HIGHMEM);
6609 6231
6610 p = p->next; 6232 if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
6611 p->type = TNODE; 6233 dev_warn(&brd->pdev->dev,
6234 "No memory at %p for board.\n",
6235 brd->re_map_membase);
6236 brd->state = BOARD_FAILED;
6237 brd->dpastatus = BD_NOFEP;
6238 return;
6239 }
6240}
6612 6241
6613 s = dgap_getword(in); 6242#ifdef DIGI_CONCENTRATORS_SUPPORTED
6614 if (!s) { 6243/*
6615 pr_err("unexpeced end of file"); 6244 * Sends a concentrator image into the FEP5 board.
6616 return -1; 6245 */
6617 } 6246static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len)
6618 p->u.ttyname = kstrdup(s, GFP_KERNEL); 6247{
6619 if (!p->u.ttyname) 6248 char __iomem *vaddr;
6620 return -1; 6249 u16 offset;
6250 struct downld_t *to_dp;
6621 6251
6622 break; 6252 if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
6253 return;
6623 6254
6624 case CU: /* cu name prefix */ 6255 vaddr = brd->re_map_membase;
6625 if (dgap_checknode(p))
6626 return -1;
6627 6256
6628 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); 6257 offset = readw((u16 *) (vaddr + DOWNREQ));
6629 if (!p->next) 6258 to_dp = (struct downld_t *) (vaddr + (int) offset);
6630 return -1; 6259 memcpy_toio(to_dp, uaddr, len);
6631 6260
6632 p = p->next; 6261 /* Tell card we have data for it */
6633 p->type = CUNODE; 6262 writew(0, vaddr + (DOWNREQ));
6634 6263
6635 s = dgap_getword(in); 6264 brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
6636 if (!s) { 6265}
6637 pr_err("unexpeced end of file"); 6266#endif
6638 return -1;
6639 }
6640 p->u.cuname = kstrdup(s, GFP_KERNEL);
6641 if (!p->u.cuname)
6642 return -1;
6643 6267
6644 break; 6268#define EXPANSION_ROM_SIZE (64 * 1024)
6269#define FEP5_ROM_MAGIC (0xFEFFFFFF)
6645 6270
6646 case LINE: /* line information */ 6271static void dgap_get_vpd(struct board_t *brd)
6647 if (dgap_checknode(p)) 6272{
6648 return -1; 6273 u32 magic;
6649 if (!brd) { 6274 u32 base_offset;
6650 pr_err("must specify board before line info"); 6275 u16 rom_offset;
6651 return -1; 6276 u16 vpd_offset;
6652 } 6277 u16 image_length;
6653 switch (brd->u.board.type) { 6278 u16 i;
6654 case PPCM: 6279 u8 byte1;
6655 pr_err("line not vaild for PC/em"); 6280 u8 byte2;
6656 return -1;
6657 }
6658 6281
6659 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); 6282 /*
6660 if (!p->next) 6283 * Poke the magic number at the PCI Rom Address location.
6661 return -1; 6284 * If VPD is supported, the value read from that address
6285 * will be non-zero.
6286 */
6287 magic = FEP5_ROM_MAGIC;
6288 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
6289 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
6662 6290
6663 p = p->next; 6291 /* VPD not supported, bail */
6664 p->type = LNODE; 6292 if (!magic)
6665 conc = NULL; 6293 return;
6666 line = p;
6667 linecnt++;
6668 break;
6669 6294
6670 case CONC: /* concentrator information */ 6295 /*
6671 if (dgap_checknode(p)) 6296 * To get to the OTPROM memory, we have to send the boards base
6672 return -1; 6297 * address or'ed with 1 into the PCI Rom Address location.
6673 if (!line) { 6298 */
6674 pr_err("must specify line info before concentrator"); 6299 magic = brd->membase | 0x01;
6675 return -1; 6300 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
6676 } 6301 pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
6677 6302
6678 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); 6303 byte1 = readb(brd->re_map_membase);
6679 if (!p->next) 6304 byte2 = readb(brd->re_map_membase + 1);
6680 return -1;
6681 6305
6682 p = p->next; 6306 /*
6683 p->type = CNODE; 6307 * If the board correctly swapped to the OTPROM memory,
6684 conc = p; 6308 * the first 2 bytes (header) should be 0x55, 0xAA
6309 */
6310 if (byte1 == 0x55 && byte2 == 0xAA) {
6685 6311
6686 if (linecnt) 6312 base_offset = 0;
6687 brd->u.board.conc2++;
6688 else
6689 brd->u.board.conc1++;
6690 6313
6691 conc_type = dgap_gettok(in); 6314 /*
6692 if (conc_type == 0 || conc_type != CX || 6315 * We have to run through all the OTPROM memory looking
6693 conc_type != EPC) { 6316 * for the VPD offset.
6694 pr_err("failed to set a type of concentratros"); 6317 */
6695 return -1; 6318 while (base_offset <= EXPANSION_ROM_SIZE) {
6696 }
6697 6319
6698 p->u.conc.type = conc_type; 6320 /*
6321 * Lots of magic numbers here.
6322 *
6323 * The VPD offset is located inside the ROM Data
6324 * Structure.
6325 *
6326 * We also have to remember the length of each
6327 * ROM Data Structure, so we can "hop" to the next
6328 * entry if the VPD isn't in the current
6329 * ROM Data Structure.
6330 */
6331 rom_offset = readw(brd->re_map_membase +
6332 base_offset + 0x18);
6333 image_length = readw(brd->re_map_membase +
6334 rom_offset + 0x10) * 512;
6335 vpd_offset = readw(brd->re_map_membase +
6336 rom_offset + 0x08);
6699 6337
6700 break; 6338 /* Found the VPD entry */
6339 if (vpd_offset)
6340 break;
6701 6341
6702 case MOD: /* EBI module */ 6342 /* We didn't find a VPD entry, go to next ROM entry. */
6703 if (dgap_checknode(p)) 6343 base_offset += image_length;
6704 return -1; 6344
6705 if (!brd) { 6345 byte1 = readb(brd->re_map_membase + base_offset);
6706 pr_err("must specify board info before EBI modules"); 6346 byte2 = readb(brd->re_map_membase + base_offset + 1);
6707 return -1; 6347
6708 } 6348 /*
6709 switch (brd->u.board.type) { 6349 * If the new ROM offset doesn't have 0x55, 0xAA
6710 case PPCM: 6350 * as its header, we have run out of ROM.
6711 linecnt = 0; 6351 */
6352 if (byte1 != 0x55 || byte2 != 0xAA)
6712 break; 6353 break;
6713 default: 6354 }
6714 if (!conc) { 6355
6715 pr_err("must specify concentrator info before EBI module"); 6356 /*
6716 return -1; 6357 * If we have a VPD offset, then mark the board
6717 } 6358 * as having a valid VPD, and copy VPDSIZE (512) bytes of
6359 * that VPD to the buffer we have in our board structure.
6360 */
6361 if (vpd_offset) {
6362 brd->bd_flags |= BD_HAS_VPD;
6363 for (i = 0; i < VPDSIZE; i++) {
6364 brd->vpd[i] = readb(brd->re_map_membase +
6365 vpd_offset + i);
6718 } 6366 }
6367 }
6368 }
6719 6369
6720 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); 6370 /*
6721 if (!p->next) 6371 * We MUST poke the magic number at the PCI Rom Address location again.
6722 return -1; 6372 * This makes the card report the regular board memory back to us,
6373 * rather than the OTPROM memory.
6374 */
6375 magic = FEP5_ROM_MAGIC;
6376 pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
6377}
6723 6378
6724 p = p->next;
6725 p->type = MNODE;
6726 6379
6727 if (linecnt) 6380static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
6728 brd->u.board.module2++; 6381{
6729 else 6382 return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
6730 brd->u.board.module1++; 6383}
6384static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
6731 6385
6732 module_type = dgap_gettok(in);
6733 if (module_type == 0 || module_type != PORTS ||
6734 module_type != MODEM) {
6735 pr_err("failed to set a type of module");
6736 return -1;
6737 }
6738 6386
6739 p->u.module.type = module_type; 6387static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
6388{
6389 return snprintf(buf, PAGE_SIZE, "%d\n", dgap_numboards);
6390}
6391static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
6740 6392
6741 break;
6742 6393
6743 case CABLE: 6394static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
6744 if (p->type == LNODE) { 6395{
6745 s = dgap_getword(in); 6396 return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
6746 if (!s) { 6397}
6747 pr_err("unexpected end of file"); 6398static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
6748 return -1;
6749 }
6750 p->u.line.cable = kstrdup(s, GFP_KERNEL);
6751 p->u.line.v_cable = 1;
6752 }
6753 break;
6754 6399
6755 case SPEED: /* sync line speed indication */
6756 if (p->type == LNODE) {
6757 s = dgap_getword(in);
6758 if (!s) {
6759 pr_err("unexpected end of file");
6760 return -1;
6761 }
6762 if (kstrtol(s, 0, &p->u.line.speed)) {
6763 pr_err("bad number for line speed");
6764 return -1;
6765 }
6766 p->u.line.v_speed = 1;
6767 } else if (p->type == CNODE) {
6768 s = dgap_getword(in);
6769 if (!s) {
6770 pr_err("unexpected end of file");
6771 return -1;
6772 }
6773 if (kstrtol(s, 0, &p->u.conc.speed)) {
6774 pr_err("bad number for line speed");
6775 return -1;
6776 }
6777 p->u.conc.v_speed = 1;
6778 } else {
6779 pr_err("speed valid only for lines or concentrators.");
6780 return -1;
6781 }
6782 break;
6783 6400
6784 case CONNECT: 6401static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp,
6785 if (p->type == CNODE) { 6402 char *buf)
6786 s = dgap_getword(in); 6403{
6787 if (!s) { 6404 return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
6788 pr_err("unexpected end of file"); 6405}
6789 return -1; 6406static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
6790 }
6791 p->u.conc.connect = kstrdup(s, GFP_KERNEL);
6792 p->u.conc.v_connect = 1;
6793 }
6794 break;
6795 case PRINT: /* transparent print name prefix */
6796 if (dgap_checknode(p))
6797 return -1;
6798 6407
6799 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); 6408static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
6800 if (!p->next) 6409{
6801 return -1; 6410 return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
6411}
6802 6412
6803 p = p->next; 6413static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp,
6804 p->type = PNODE; 6414 const char *buf, size_t count)
6415{
6416 if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
6417 return -EINVAL;
6418 return count;
6419}
6420static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show,
6421 dgap_driver_pollrate_store);
6805 6422
6806 s = dgap_getword(in);
6807 if (!s) {
6808 pr_err("unexpeced end of file");
6809 return -1;
6810 }
6811 p->u.printname = kstrdup(s, GFP_KERNEL);
6812 if (!p->u.printname)
6813 return -1;
6814 6423
6815 break; 6424static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
6425{
6426 int rc = 0;
6427 struct device_driver *driverfs = &dgap_driver->driver;
6816 6428
6817 case CMAJOR: /* major number */ 6429 rc |= driver_create_file(driverfs, &driver_attr_version);
6818 if (dgap_checknode(p)) 6430 rc |= driver_create_file(driverfs, &driver_attr_boards);
6819 return -1; 6431 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
6432 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
6433 rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
6820 6434
6821 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); 6435 return rc;
6822 if (!p->next) 6436}
6823 return -1;
6824 6437
6825 p = p->next; 6438static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
6826 p->type = JNODE; 6439{
6440 struct device_driver *driverfs = &dgap_driver->driver;
6827 6441
6828 s = dgap_getword(in); 6442 driver_remove_file(driverfs, &driver_attr_version);
6829 if (!s) { 6443 driver_remove_file(driverfs, &driver_attr_boards);
6830 pr_err("unexpected end of file"); 6444 driver_remove_file(driverfs, &driver_attr_maxboards);
6831 return -1; 6445 driver_remove_file(driverfs, &driver_attr_pollrate);
6832 } 6446 driver_remove_file(driverfs, &driver_attr_pollcounter);
6833 if (kstrtol(s, 0, &p->u.majornumber)) { 6447}
6834 pr_err("bad number for major number");
6835 return -1;
6836 }
6837 break;
6838 6448
6839 case ALTPIN: /* altpin setting */ 6449static struct attribute_group dgap_tty_attribute_group = {
6840 if (dgap_checknode(p)) 6450 .name = NULL,
6841 return -1; 6451 .attrs = dgap_sysfs_tty_entries,
6452};
6842 6453
6843 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); 6454static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
6844 if (!p->next) 6455{
6845 return -1; 6456 int ret;
6846 6457
6847 p = p->next; 6458 ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
6848 p->type = ANODE; 6459 if (ret)
6460 return;
6849 6461
6850 s = dgap_getword(in); 6462 dev_set_drvdata(c, un);
6851 if (!s) {
6852 pr_err("unexpected end of file");
6853 return -1;
6854 }
6855 if (kstrtol(s, 0, &p->u.altpin)) {
6856 pr_err("bad number for altpin");
6857 return -1;
6858 }
6859 break;
6860 6463
6861 case USEINTR: /* enable interrupt setting */ 6464}
6862 if (dgap_checknode(p))
6863 return -1;
6864 6465
6865 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); 6466static void dgap_remove_tty_sysfs(struct device *c)
6866 if (!p->next) 6467{
6867 return -1; 6468 sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
6469}
6868 6470
6869 p = p->next; 6471/*
6870 p->type = INTRNODE; 6472 * Create pr and tty device entries
6871 s = dgap_getword(in); 6473 */
6872 if (!s) { 6474static int dgap_tty_register_ports(struct board_t *brd)
6873 pr_err("unexpected end of file"); 6475{
6874 return -1; 6476 struct channel_t *ch;
6875 } 6477 int i;
6876 if (kstrtol(s, 0, &p->u.useintr)) { 6478 int ret;
6877 pr_err("bad number for useintr");
6878 return -1;
6879 }
6880 break;
6881 6479
6882 case TTSIZ: /* size of tty structure */ 6480 brd->serial_ports = kcalloc(brd->nasync, sizeof(*brd->serial_ports),
6883 if (dgap_checknode(p)) 6481 GFP_KERNEL);
6884 return -1; 6482 if (!brd->serial_ports)
6483 return -ENOMEM;
6885 6484
6886 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); 6485 brd->printer_ports = kcalloc(brd->nasync, sizeof(*brd->printer_ports),
6887 if (!p->next) 6486 GFP_KERNEL);
6888 return -1; 6487 if (!brd->printer_ports) {
6488 ret = -ENOMEM;
6489 goto free_serial_ports;
6490 }
6889 6491
6890 p = p->next; 6492 for (i = 0; i < brd->nasync; i++) {
6891 p->type = TSNODE; 6493 tty_port_init(&brd->serial_ports[i]);
6494 tty_port_init(&brd->printer_ports[i]);
6495 }
6892 6496
6893 s = dgap_getword(in); 6497 ch = brd->channels[0];
6894 if (!s) { 6498 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
6895 pr_err("unexpected end of file");
6896 return -1;
6897 }
6898 if (kstrtol(s, 0, &p->u.ttysize)) {
6899 pr_err("bad number for ttysize");
6900 return -1;
6901 }
6902 break;
6903 6499
6904 case CHSIZ: /* channel structure size */ 6500 struct device *classp;
6905 if (dgap_checknode(p))
6906 return -1;
6907 6501
6908 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); 6502 classp = tty_port_register_device(&brd->serial_ports[i],
6909 if (!p->next) 6503 brd->serial_driver,
6910 return -1; 6504 i, NULL);
6911 6505
6912 p = p->next; 6506 if (IS_ERR(classp)) {
6913 p->type = CSNODE; 6507 ret = PTR_ERR(classp);
6508 goto unregister_ttys;
6509 }
6914 6510
6915 s = dgap_getword(in); 6511 dgap_create_tty_sysfs(&ch->ch_tun, classp);
6916 if (!s) { 6512 ch->ch_tun.un_sysfs = classp;
6917 pr_err("unexpected end of file");
6918 return -1;
6919 }
6920 if (kstrtol(s, 0, &p->u.chsize)) {
6921 pr_err("bad number for chsize");
6922 return -1;
6923 }
6924 break;
6925 6513
6926 case BSSIZ: /* board structure size */ 6514 classp = tty_port_register_device(&brd->printer_ports[i],
6927 if (dgap_checknode(p)) 6515 brd->print_driver,
6928 return -1; 6516 i, NULL);
6929 6517
6930 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); 6518 if (IS_ERR(classp)) {
6931 if (!p->next) 6519 ret = PTR_ERR(classp);
6932 return -1; 6520 goto unregister_ttys;
6521 }
6933 6522
6934 p = p->next; 6523 dgap_create_tty_sysfs(&ch->ch_pun, classp);
6935 p->type = BSNODE; 6524 ch->ch_pun.un_sysfs = classp;
6525 }
6526 dgap_create_ports_sysfiles(brd);
6936 6527
6937 s = dgap_getword(in); 6528 return 0;
6938 if (!s) {
6939 pr_err("unexpected end of file");
6940 return -1;
6941 }
6942 if (kstrtol(s, 0, &p->u.bssize)) {
6943 pr_err("bad number for bssize");
6944 return -1;
6945 }
6946 break;
6947 6529
6948 case UNTSIZ: /* sched structure size */ 6530unregister_ttys:
6949 if (dgap_checknode(p)) 6531 while (i >= 0) {
6950 return -1; 6532 ch = brd->channels[i];
6533 if (ch->ch_tun.un_sysfs) {
6534 dgap_remove_tty_sysfs(ch->ch_tun.un_sysfs);
6535 tty_unregister_device(brd->serial_driver, i);
6536 }
6951 6537
6952 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); 6538 if (ch->ch_pun.un_sysfs) {
6953 if (!p->next) 6539 dgap_remove_tty_sysfs(ch->ch_pun.un_sysfs);
6954 return -1; 6540 tty_unregister_device(brd->print_driver, i);
6541 }
6542 i--;
6543 }
6955 6544
6956 p = p->next; 6545 for (i = 0; i < brd->nasync; i++) {
6957 p->type = USNODE; 6546 tty_port_destroy(&brd->serial_ports[i]);
6547 tty_port_destroy(&brd->printer_ports[i]);
6548 }
6958 6549
6959 s = dgap_getword(in); 6550 kfree(brd->printer_ports);
6960 if (!s) { 6551 brd->printer_ports = NULL;
6961 pr_err("unexpected end of file");
6962 return -1;
6963 }
6964 if (kstrtol(s, 0, &p->u.unsize)) {
6965 pr_err("bad number for schedsize");
6966 return -1;
6967 }
6968 break;
6969 6552
6970 case F2SIZ: /* f2200 structure size */ 6553free_serial_ports:
6971 if (dgap_checknode(p)) 6554 kfree(brd->serial_ports);
6972 return -1; 6555 brd->serial_ports = NULL;
6973 6556
6974 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); 6557 return ret;
6975 if (!p->next) 6558}
6976 return -1;
6977 6559
6978 p = p->next; 6560/*
6979 p->type = FSNODE; 6561 * dgap_cleanup_tty()
6562 *
6563 * Uninitialize the TTY portion of this driver. Free all memory and
6564 * resources.
6565 */
6566static void dgap_cleanup_tty(struct board_t *brd)
6567{
6568 struct device *dev;
6569 unsigned int i;
6980 6570
6981 s = dgap_getword(in); 6571 for (i = 0; i < brd->nasync; i++) {
6982 if (!s) { 6572 tty_port_destroy(&brd->serial_ports[i]);
6983 pr_err("unexpected end of file"); 6573 dev = brd->channels[i]->ch_tun.un_sysfs;
6984 return -1; 6574 dgap_remove_tty_sysfs(dev);
6985 } 6575 tty_unregister_device(brd->serial_driver, i);
6986 if (kstrtol(s, 0, &p->u.f2size)) { 6576 }
6987 pr_err("bad number for f2200size"); 6577 tty_unregister_driver(brd->serial_driver);
6988 return -1; 6578 put_tty_driver(brd->serial_driver);
6989 } 6579 kfree(brd->serial_ports);
6990 break;
6991 6580
6992 case VPSIZ: /* vpix structure size */ 6581 for (i = 0; i < brd->nasync; i++) {
6993 if (dgap_checknode(p)) 6582 tty_port_destroy(&brd->printer_ports[i]);
6994 return -1; 6583 dev = brd->channels[i]->ch_pun.un_sysfs;
6584 dgap_remove_tty_sysfs(dev);
6585 tty_unregister_device(brd->print_driver, i);
6586 }
6587 tty_unregister_driver(brd->print_driver);
6588 put_tty_driver(brd->print_driver);
6589 kfree(brd->printer_ports);
6590}
6995 6591
6996 p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL); 6592static int dgap_request_irq(struct board_t *brd)
6997 if (!p->next) 6593{
6998 return -1; 6594 int rc;
6999 6595
7000 p = p->next; 6596 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
7001 p->type = VSNODE; 6597 return -ENODEV;
7002 6598
7003 s = dgap_getword(in); 6599 /*
7004 if (!s) { 6600 * Set up our interrupt handler if we are set to do interrupts.
7005 pr_err("unexpected end of file"); 6601 */
7006 return -1; 6602 if (dgap_config_get_useintr(brd) && brd->irq) {
7007 } 6603
7008 if (kstrtol(s, 0, &p->u.vpixsize)) { 6604 rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
7009 pr_err("bad number for vpixsize"); 6605
7010 return -1; 6606 if (!rc)
7011 } 6607 brd->intr_used = 1;
7012 break;
7013 }
7014 } 6608 }
6609 return 0;
7015} 6610}
7016 6611
7017/* 6612static void dgap_free_irq(struct board_t *brd)
7018 * dgap_sindex: much like index(), but it looks for a match of any character in
7019 * the group, and returns that position. If the first character is a ^, then
7020 * this will match the first occurrence not in that group.
7021 */
7022static char *dgap_sindex(char *string, char *group)
7023{ 6613{
7024 char *ptr; 6614 if (brd->intr_used && brd->irq)
6615 free_irq(brd->irq, brd);
6616}
7025 6617
7026 if (!string || !group) 6618static int dgap_firmware_load(struct pci_dev *pdev, int card_type,
7027 return (char *) NULL; 6619 struct board_t *brd)
6620{
6621 const struct firmware *fw;
6622 char *tmp_ptr;
6623 int ret;
6624 char *dgap_config_buf;
7028 6625
7029 if (*group == '^') { 6626 dgap_get_vpd(brd);
7030 group++; 6627 dgap_do_reset_board(brd);
7031 for (; *string; string++) { 6628
7032 for (ptr = group; *ptr; ptr++) { 6629 if (fw_info[card_type].conf_name) {
7033 if (*ptr == *string) 6630 ret = request_firmware(&fw, fw_info[card_type].conf_name,
7034 break; 6631 &pdev->dev);
7035 } 6632 if (ret) {
7036 if (*ptr == '\0') 6633 dev_err(&pdev->dev, "config file %s not found\n",
7037 return string; 6634 fw_info[card_type].conf_name);
6635 return ret;
7038 } 6636 }
7039 } else { 6637
7040 for (; *string; string++) { 6638 dgap_config_buf = kzalloc(fw->size + 1, GFP_KERNEL);
7041 for (ptr = group; *ptr; ptr++) { 6639 if (!dgap_config_buf) {
7042 if (*ptr == *string) 6640 release_firmware(fw);
7043 return string; 6641 return -ENOMEM;
7044 } 6642 }
6643
6644 memcpy(dgap_config_buf, fw->data, fw->size);
6645 release_firmware(fw);
6646
6647 /*
6648 * preserve dgap_config_buf
6649 * as dgap_parsefile would
6650 * otherwise alter it.
6651 */
6652 tmp_ptr = dgap_config_buf;
6653
6654 if (dgap_parsefile(&tmp_ptr) != 0) {
6655 kfree(dgap_config_buf);
6656 return -EINVAL;
7045 } 6657 }
6658 kfree(dgap_config_buf);
7046 } 6659 }
7047 6660
7048 return (char *) NULL; 6661 /*
7049} 6662 * Match this board to a config the user created for us.
6663 */
6664 brd->bd_config =
6665 dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot);
7050 6666
7051/* 6667 /*
7052 * Get a token from the input file; return 0 if end of file is reached 6668 * Because the 4 port Xr products share the same PCI ID
7053 */ 6669 * as the 8 port Xr products, if we receive a NULL config
7054static int dgap_gettok(char **in) 6670 * back, and this is a PAPORT8 board, retry with a
7055{ 6671 * PAPORT4 attempt as well.
7056 char *w; 6672 */
7057 struct toklist *t; 6673 if (brd->type == PAPORT8 && !brd->bd_config)
6674 brd->bd_config =
6675 dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot);
7058 6676
7059 if (strstr(dgap_cword, "board")) { 6677 if (!brd->bd_config) {
7060 w = dgap_getword(in); 6678 dev_err(&pdev->dev, "No valid configuration found\n");
7061 snprintf(dgap_cword, MAXCWORD, "%s", w); 6679 return -EINVAL;
7062 for (t = dgap_brdtype; t->token != 0; t++) { 6680 }
7063 if (!strcmp(w, t->string)) 6681
7064 return t->token; 6682 if (fw_info[card_type].bios_name) {
6683 ret = request_firmware(&fw, fw_info[card_type].bios_name,
6684 &pdev->dev);
6685 if (ret) {
6686 dev_err(&pdev->dev, "bios file %s not found\n",
6687 fw_info[card_type].bios_name);
6688 return ret;
7065 } 6689 }
7066 } else { 6690 dgap_do_bios_load(brd, fw->data, fw->size);
7067 while ((w = dgap_getword(in))) { 6691 release_firmware(fw);
7068 snprintf(dgap_cword, MAXCWORD, "%s", w); 6692
7069 for (t = dgap_tlist; t->token != 0; t++) { 6693 /* Wait for BIOS to test board... */
7070 if (!strcmp(w, t->string)) 6694 ret = dgap_test_bios(brd);
7071 return t->token; 6695 if (ret)
7072 } 6696 return ret;
6697 }
6698
6699 if (fw_info[card_type].fep_name) {
6700 ret = request_firmware(&fw, fw_info[card_type].fep_name,
6701 &pdev->dev);
6702 if (ret) {
6703 dev_err(&pdev->dev, "dgap: fep file %s not found\n",
6704 fw_info[card_type].fep_name);
6705 return ret;
6706 }
6707 dgap_do_fep_load(brd, fw->data, fw->size);
6708 release_firmware(fw);
6709
6710 /* Wait for FEP to load on board... */
6711 ret = dgap_test_fep(brd);
6712 if (ret)
6713 return ret;
6714 }
6715
6716#ifdef DIGI_CONCENTRATORS_SUPPORTED
6717 /*
6718 * If this is a CX or EPCX, we need to see if the firmware
6719 * is requesting a concentrator image from us.
6720 */
6721 if ((bd->type == PCX) || (bd->type == PEPC)) {
6722 chk_addr = (u16 *) (vaddr + DOWNREQ);
6723 /* Nonzero if FEP is requesting concentrator image. */
6724 check = readw(chk_addr);
6725 vaddr = brd->re_map_membase;
6726 }
6727
6728 if (fw_info[card_type].con_name && check && vaddr) {
6729 ret = request_firmware(&fw, fw_info[card_type].con_name,
6730 &pdev->dev);
6731 if (ret) {
6732 dev_err(&pdev->dev, "conc file %s not found\n",
6733 fw_info[card_type].con_name);
6734 return ret;
7073 } 6735 }
6736 /* Put concentrator firmware loading code here */
6737 offset = readw((u16 *) (vaddr + DOWNREQ));
6738 memcpy_toio(offset, fw->data, fw->size);
6739
6740 dgap_do_conc_load(brd, (char *)fw->data, fw->size)
6741 release_firmware(fw);
7074 } 6742 }
6743#endif
7075 6744
7076 return 0; 6745 return 0;
7077} 6746}
7078 6747
7079/* 6748/*
7080 * get a word from the input stream, also keep track of current line number. 6749 * dgap_tty_init()
7081 * words are separated by whitespace. 6750 *
6751 * Init the tty subsystem. Called once per board after board has been
6752 * downloaded and init'ed.
7082 */ 6753 */
7083static char *dgap_getword(char **in) 6754static int dgap_tty_init(struct board_t *brd)
7084{ 6755{
7085 char *ret_ptr = *in; 6756 int i;
6757 int tlw;
6758 uint true_count;
6759 u8 __iomem *vaddr;
6760 u8 modem;
6761 struct channel_t *ch;
6762 struct bs_t __iomem *bs;
6763 struct cm_t __iomem *cm;
6764 int ret;
7086 6765
7087 char *ptr = dgap_sindex(*in, " \t\n"); 6766 /*
6767 * Initialize board structure elements.
6768 */
7088 6769
7089 /* If no word found, return null */ 6770 vaddr = brd->re_map_membase;
7090 if (!ptr) 6771 true_count = readw((vaddr + NCHAN));
7091 return NULL;
7092 6772
7093 /* Mark new location for our buffer */ 6773 brd->nasync = dgap_config_get_num_prts(brd);
7094 *ptr = '\0';
7095 *in = ptr + 1;
7096 6774
7097 /* Eat any extra spaces/tabs/newlines that might be present */ 6775 if (!brd->nasync)
7098 while (*in && **in && ((**in == ' ') || 6776 brd->nasync = brd->maxports;
7099 (**in == '\t') ||
7100 (**in == '\n'))) {
7101 **in = '\0';
7102 *in = *in + 1;
7103 }
7104 6777
7105 return ret_ptr; 6778 if (brd->nasync > brd->maxports)
7106} 6779 brd->nasync = brd->maxports;
7107 6780
7108/* 6781 if (true_count != brd->nasync) {
7109 * dgap_checknode: see if all the necessary info has been supplied for a node 6782 dev_warn(&brd->pdev->dev,
7110 * before creating the next node. 6783 "%s configured for %d ports, has %d ports.\n",
7111 */ 6784 brd->name, brd->nasync, true_count);
7112static int dgap_checknode(struct cnode *p)
7113{
7114 switch (p->type) {
7115 case LNODE:
7116 if (p->u.line.v_speed == 0) {
7117 pr_err("line speed not specified");
7118 return 1;
7119 }
7120 return 0;
7121 6785
7122 case CNODE: 6786 if ((brd->type == PPCM) &&
7123 if (p->u.conc.v_speed == 0) { 6787 (true_count == 64 || true_count == 0)) {
7124 pr_err("concentrator line speed not specified"); 6788 dev_warn(&brd->pdev->dev,
7125 return 1; 6789 "Please make SURE the EBI cable running from the card\n");
7126 } 6790 dev_warn(&brd->pdev->dev,
7127 if (p->u.conc.v_nport == 0) { 6791 "to each EM module is plugged into EBI IN!\n");
7128 pr_err("number of ports on concentrator not specified");
7129 return 1;
7130 } 6792 }
7131 if (p->u.conc.v_id == 0) { 6793
7132 pr_err("concentrator id letter not specified"); 6794 brd->nasync = true_count;
7133 return 1; 6795
6796 /* If no ports, don't bother going any further */
6797 if (!brd->nasync) {
6798 brd->state = BOARD_FAILED;
6799 brd->dpastatus = BD_NOFEP;
6800 return -EIO;
7134 } 6801 }
7135 return 0; 6802 }
7136 6803
7137 case MNODE: 6804 /*
7138 if (p->u.module.v_nport == 0) { 6805 * Allocate channel memory that might not have been allocated
7139 pr_err("number of ports on EBI module not specified"); 6806 * when the driver was first loaded.
7140 return 1; 6807 */
6808 for (i = 0; i < brd->nasync; i++) {
6809 brd->channels[i] =
6810 kzalloc(sizeof(struct channel_t), GFP_KERNEL);
6811 if (!brd->channels[i]) {
6812 ret = -ENOMEM;
6813 goto free_chan;
7141 } 6814 }
7142 if (p->u.module.v_id == 0) { 6815 }
7143 pr_err("EBI module id letter not specified"); 6816
7144 return 1; 6817 ch = brd->channels[0];
6818 vaddr = brd->re_map_membase;
6819
6820 bs = (struct bs_t __iomem *) ((ulong) vaddr + CHANBUF);
6821 cm = (struct cm_t __iomem *) ((ulong) vaddr + CMDBUF);
6822
6823 brd->bd_bs = bs;
6824
6825 /* Set up channel variables */
6826 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
6827
6828 spin_lock_init(&ch->ch_lock);
6829
6830 /* Store all our magic numbers */
6831 ch->magic = DGAP_CHANNEL_MAGIC;
6832 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
6833 ch->ch_tun.un_type = DGAP_SERIAL;
6834 ch->ch_tun.un_ch = ch;
6835 ch->ch_tun.un_dev = i;
6836
6837 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
6838 ch->ch_pun.un_type = DGAP_PRINT;
6839 ch->ch_pun.un_ch = ch;
6840 ch->ch_pun.un_dev = i;
6841
6842 ch->ch_vaddr = vaddr;
6843 ch->ch_bs = bs;
6844 ch->ch_cm = cm;
6845 ch->ch_bd = brd;
6846 ch->ch_portnum = i;
6847 ch->ch_digi = dgap_digi_init;
6848
6849 /*
6850 * Set up digi dsr and dcd bits based on altpin flag.
6851 */
6852 if (dgap_config_get_altpin(brd)) {
6853 ch->ch_dsr = DM_CD;
6854 ch->ch_cd = DM_DSR;
6855 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
6856 } else {
6857 ch->ch_cd = DM_CD;
6858 ch->ch_dsr = DM_DSR;
7145 } 6859 }
7146 return 0; 6860
6861 ch->ch_taddr = vaddr + (ioread16(&(ch->ch_bs->tx_seg)) << 4);
6862 ch->ch_raddr = vaddr + (ioread16(&(ch->ch_bs->rx_seg)) << 4);
6863 ch->ch_tx_win = 0;
6864 ch->ch_rx_win = 0;
6865 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
6866 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
6867 ch->ch_tstart = 0;
6868 ch->ch_rstart = 0;
6869
6870 /*
6871 * Set queue water marks, interrupt mask,
6872 * and general tty parameters.
6873 */
6874 tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) :
6875 ch->ch_tsize / 2;
6876 ch->ch_tlw = tlw;
6877
6878 dgap_cmdw(ch, STLOW, tlw, 0);
6879
6880 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
6881
6882 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
6883
6884 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
6885
6886 init_waitqueue_head(&ch->ch_flags_wait);
6887 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
6888 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
6889
6890 /* Turn on all modem interrupts for now */
6891 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
6892 writeb(modem, &(ch->ch_bs->m_int));
6893
6894 /*
6895 * Set edelay to 0 if interrupts are turned on,
6896 * otherwise set edelay to the usual 100.
6897 */
6898 if (brd->intr_used)
6899 writew(0, &(ch->ch_bs->edelay));
6900 else
6901 writew(100, &(ch->ch_bs->edelay));
6902
6903 writeb(1, &(ch->ch_bs->idata));
7147 } 6904 }
6905
7148 return 0; 6906 return 0;
6907
6908free_chan:
6909 while (--i >= 0) {
6910 kfree(brd->channels[i]);
6911 brd->channels[i] = NULL;
6912 }
6913 return ret;
7149} 6914}
7150 6915
7151/* 6916/*
7152 * Given a board pointer, returns whether we should use interrupts or not. 6917 * dgap_tty_free()
6918 *
6919 * Free the channles which are allocated in dgap_tty_init().
7153 */ 6920 */
7154static uint dgap_config_get_useintr(struct board_t *bd) 6921static void dgap_tty_free(struct board_t *brd)
7155{ 6922{
7156 struct cnode *p; 6923 int i;
7157 6924
7158 if (!bd) 6925 for (i = 0; i < brd->nasync; i++)
7159 return 0; 6926 kfree(brd->channels[i]);
6927}
7160 6928
7161 for (p = bd->bd_config; p; p = p->next) { 6929static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
7162 if (p->type == INTRNODE) { 6930{
7163 /* 6931 int rc;
7164 * check for pcxr types. 6932 struct board_t *brd;
7165 */ 6933
7166 return p->u.useintr; 6934 if (dgap_numboards >= MAXBOARDS)
7167 } 6935 return -EPERM;
7168 } 6936
6937 rc = pci_enable_device(pdev);
6938 if (rc)
6939 return -EIO;
6940
6941 brd = dgap_found_board(pdev, ent->driver_data, dgap_numboards);
6942 if (IS_ERR(brd))
6943 return PTR_ERR(brd);
6944
6945 rc = dgap_firmware_load(pdev, ent->driver_data, brd);
6946 if (rc)
6947 goto cleanup_brd;
6948
6949 rc = dgap_alloc_flipbuf(brd);
6950 if (rc)
6951 goto cleanup_brd;
6952
6953 rc = dgap_tty_register(brd);
6954 if (rc)
6955 goto free_flipbuf;
6956
6957 rc = dgap_request_irq(brd);
6958 if (rc)
6959 goto unregister_tty;
6960
6961 /*
6962 * Do tty device initialization.
6963 */
6964 rc = dgap_tty_init(brd);
6965 if (rc < 0)
6966 goto free_irq;
6967
6968 rc = dgap_tty_register_ports(brd);
6969 if (rc)
6970 goto tty_free;
6971
6972 brd->state = BOARD_READY;
6973 brd->dpastatus = BD_RUNNING;
6974
6975 dgap_board[dgap_numboards++] = brd;
7169 6976
7170 /* If not found, then don't turn on interrupts. */
7171 return 0; 6977 return 0;
6978
6979tty_free:
6980 dgap_tty_free(brd);
6981free_irq:
6982 dgap_free_irq(brd);
6983unregister_tty:
6984 dgap_tty_unregister(brd);
6985free_flipbuf:
6986 dgap_free_flipbuf(brd);
6987cleanup_brd:
6988 dgap_cleanup_nodes();
6989 dgap_unmap(brd);
6990 kfree(brd);
6991
6992 return rc;
7172} 6993}
7173 6994
6995static void dgap_remove_one(struct pci_dev *dev)
6996{
6997 /* Do Nothing */
6998}
6999
7000static struct pci_driver dgap_driver = {
7001 .name = "dgap",
7002 .probe = dgap_init_one,
7003 .id_table = dgap_pci_tbl,
7004 .remove = dgap_remove_one,
7005};
7006
7174/* 7007/*
7175 * Given a board pointer, returns whether we turn on altpin or not. 7008 * Start of driver.
7176 */ 7009 */
7177static uint dgap_config_get_altpin(struct board_t *bd) 7010static int dgap_start(void)
7178{ 7011{
7179 struct cnode *p; 7012 int rc;
7013 unsigned long flags;
7014 struct device *device;
7180 7015
7181 if (!bd) 7016 dgap_numboards = 0;
7182 return 0;
7183 7017
7184 for (p = bd->bd_config; p; p = p->next) { 7018 pr_info("For the tools package please visit http://www.digi.com\n");
7185 if (p->type == ANODE) { 7019
7186 /* 7020 /*
7187 * check for pcxr types. 7021 * Register our base character device into the kernel.
7188 */ 7022 */
7189 return p->u.altpin; 7023
7190 } 7024 /*
7025 * Register management/dpa devices
7026 */
7027 rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &dgap_board_fops);
7028 if (rc < 0)
7029 return rc;
7030
7031 dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
7032 if (IS_ERR(dgap_class)) {
7033 rc = PTR_ERR(dgap_class);
7034 goto failed_class;
7191 } 7035 }
7192 7036
7193 /* If not found, then don't turn on interrupts. */ 7037 device = device_create(dgap_class, NULL,
7194 return 0; 7038 MKDEV(DIGI_DGAP_MAJOR, 0),
7039 NULL, "dgap_mgmt");
7040 if (IS_ERR(device)) {
7041 rc = PTR_ERR(device);
7042 goto failed_device;
7043 }
7044
7045 /* Start the poller */
7046 spin_lock_irqsave(&dgap_poll_lock, flags);
7047 init_timer(&dgap_poll_timer);
7048 dgap_poll_timer.function = dgap_poll_handler;
7049 dgap_poll_timer.data = 0;
7050 dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
7051 dgap_poll_timer.expires = dgap_poll_time;
7052 spin_unlock_irqrestore(&dgap_poll_lock, flags);
7053
7054 add_timer(&dgap_poll_timer);
7055
7056 return rc;
7057
7058failed_device:
7059 class_destroy(dgap_class);
7060failed_class:
7061 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
7062 return rc;
7195} 7063}
7196 7064
7197/* 7065static void dgap_stop(void)
7198 * Given a specific type of board, if found, detached link and
7199 * returns the first occurrence in the list.
7200 */
7201static struct cnode *dgap_find_config(int type, int bus, int slot)
7202{ 7066{
7203 struct cnode *p, *prev, *prev2, *found; 7067 unsigned long lock_flags;
7204 7068
7205 p = &dgap_head; 7069 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
7070 dgap_poll_stop = 1;
7071 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
7206 7072
7207 while (p->next) { 7073 del_timer_sync(&dgap_poll_timer);
7208 prev = p;
7209 p = p->next;
7210 7074
7211 if (p->type != BNODE) 7075 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
7212 continue; 7076 class_destroy(dgap_class);
7077 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
7078}
7213 7079
7214 if (p->u.board.type != type) 7080/*
7215 continue; 7081 * dgap_cleanup_board()
7082 *
7083 * Free all the memory associated with a board
7084 */
7085static void dgap_cleanup_board(struct board_t *brd)
7086{
7087 unsigned int i;
7216 7088
7217 if (p->u.board.v_pcibus && 7089 if (!brd || brd->magic != DGAP_BOARD_MAGIC)
7218 p->u.board.pcibus != bus) 7090 return;
7219 continue;
7220 7091
7221 if (p->u.board.v_pcislot && 7092 dgap_free_irq(brd);
7222 p->u.board.pcislot != slot)
7223 continue;
7224 7093
7225 found = p; 7094 tasklet_kill(&brd->helper_tasklet);
7226 /*
7227 * Keep walking thru the list till we
7228 * find the next board.
7229 */
7230 while (p->next) {
7231 prev2 = p;
7232 p = p->next;
7233 7095
7234 if (p->type != BNODE) 7096 dgap_unmap(brd);
7235 continue;
7236 7097
7237 /* 7098 /* Free all allocated channels structs */
7238 * Mark the end of our 1 board 7099 for (i = 0; i < MAXPORTS ; i++)
7239 * chain of configs. 7100 kfree(brd->channels[i]);
7240 */
7241 prev2->next = NULL;
7242 7101
7243 /* 7102 kfree(brd->flipbuf);
7244 * Link the "next" board to the 7103 kfree(brd->flipflagbuf);
7245 * previous board, effectively
7246 * "unlinking" our board from
7247 * the main config.
7248 */
7249 prev->next = p;
7250 7104
7251 return found; 7105 dgap_board[brd->boardnum] = NULL;
7252 } 7106
7253 /* 7107 kfree(brd);
7254 * It must be the last board in the list.
7255 */
7256 prev->next = NULL;
7257 return found;
7258 }
7259 return NULL;
7260} 7108}
7261 7109
7110
7111/************************************************************************
7112 *
7113 * Driver load/unload functions
7114 *
7115 ************************************************************************/
7116
7262/* 7117/*
7263 * Given a board pointer, walks the config link, counting up 7118 * init_module()
7264 * all ports user specified should be on the board. 7119 *
7265 * (This does NOT mean they are all actually present right now tho) 7120 * Module load. This is where it all starts.
7266 */ 7121 */
7267static uint dgap_config_get_num_prts(struct board_t *bd) 7122static int dgap_init_module(void)
7268{ 7123{
7269 int count = 0; 7124 int rc;
7270 struct cnode *p;
7271 7125
7272 if (!bd) 7126 pr_info("%s, Digi International Part Number %s\n", DG_NAME, DG_PART);
7273 return 0;
7274 7127
7275 for (p = bd->bd_config; p; p = p->next) { 7128 rc = dgap_start();
7129 if (rc)
7130 return rc;
7276 7131
7277 switch (p->type) { 7132 rc = pci_register_driver(&dgap_driver);
7278 case BNODE: 7133 if (rc)
7279 /* 7134 goto err_stop;
7280 * check for pcxr types. 7135
7281 */ 7136 rc = dgap_create_driver_sysfiles(&dgap_driver);
7282 if (p->u.board.type > EPCFE) 7137 if (rc)
7283 count += p->u.board.nport; 7138 goto err_unregister;
7284 break; 7139
7285 case CNODE: 7140 dgap_driver_state = DRIVER_READY;
7286 count += p->u.conc.nport; 7141
7287 break; 7142 return 0;
7288 case MNODE: 7143
7289 count += p->u.module.nport; 7144err_unregister:
7290 break; 7145 pci_unregister_driver(&dgap_driver);
7291 } 7146err_stop:
7292 } 7147 dgap_stop();
7293 return count; 7148
7149 return rc;
7294} 7150}
7295 7151
7296static char *dgap_create_config_string(struct board_t *bd, char *string) 7152/*
7153 * dgap_cleanup_module()
7154 *
7155 * Module unload. This is where it all ends.
7156 */
7157static void dgap_cleanup_module(void)
7297{ 7158{
7298 char *ptr = string; 7159 unsigned int i;
7299 struct cnode *p; 7160 ulong lock_flags;
7300 struct cnode *q;
7301 int speed;
7302 7161
7303 if (!bd) { 7162 spin_lock_irqsave(&dgap_poll_lock, lock_flags);
7304 *ptr = 0xff; 7163 dgap_poll_stop = 1;
7305 return string; 7164 spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
7306 }
7307 7165
7308 for (p = bd->bd_config; p; p = p->next) { 7166 /* Turn off poller right away. */
7167 del_timer_sync(&dgap_poll_timer);
7309 7168
7310 switch (p->type) { 7169 dgap_remove_driver_sysfiles(&dgap_driver);
7311 case LNODE:
7312 *ptr = '\0';
7313 ptr++;
7314 *ptr = p->u.line.speed;
7315 ptr++;
7316 break;
7317 case CNODE:
7318 /*
7319 * Because the EPC/con concentrators can have EM modules
7320 * hanging off of them, we have to walk ahead in the
7321 * list and keep adding the number of ports on each EM
7322 * to the config. UGH!
7323 */
7324 speed = p->u.conc.speed;
7325 q = p->next;
7326 if (q && (q->type == MNODE)) {
7327 *ptr = (p->u.conc.nport + 0x80);
7328 ptr++;
7329 p = q;
7330 while (q->next && (q->next->type) == MNODE) {
7331 *ptr = (q->u.module.nport + 0x80);
7332 ptr++;
7333 p = q;
7334 q = q->next;
7335 }
7336 *ptr = q->u.module.nport;
7337 ptr++;
7338 } else {
7339 *ptr = p->u.conc.nport;
7340 ptr++;
7341 }
7342 7170
7343 *ptr = speed; 7171 device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
7344 ptr++; 7172 class_destroy(dgap_class);
7345 break; 7173 unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
7346 } 7174
7175 for (i = 0; i < dgap_numboards; ++i) {
7176 dgap_remove_ports_sysfiles(dgap_board[i]);
7177 dgap_cleanup_tty(dgap_board[i]);
7178 dgap_cleanup_board(dgap_board[i]);
7347 } 7179 }
7348 7180
7349 *ptr = 0xff; 7181 dgap_cleanup_nodes();
7350 return string; 7182
7183 if (dgap_numboards)
7184 pci_unregister_driver(&dgap_driver);
7351} 7185}
7186
7187module_init(dgap_init_module);
7188module_exit(dgap_cleanup_module);
7189
7190MODULE_LICENSE("GPL");
7191MODULE_AUTHOR("Digi International, http://www.digi.com");
7192MODULE_DESCRIPTION("Driver for the Digi International EPCA PCI based product line");
7193MODULE_SUPPORTED_DEVICE("dgap");
diff --git a/drivers/staging/dgap/dgap.h b/drivers/staging/dgap/dgap.h
index 14e2ed0fe39b..684033156e8c 100644
--- a/drivers/staging/dgap/dgap.h
+++ b/drivers/staging/dgap/dgap.h
@@ -584,9 +584,6 @@ struct board_t {
584 struct tty_port *printer_ports; 584 struct tty_port *printer_ports;
585 char print_name[200]; 585 char print_name[200];
586 586
587 u32 dgap_serial_major;
588 u32 dgap_transparent_print_major;
589
590 struct bs_t __iomem *bd_bs; /* Base structure pointer */ 587 struct bs_t __iomem *bd_bs; /* Base structure pointer */
591 588
592 char *flipbuf; /* Our flip buffer, alloced if */ 589 char *flipbuf; /* Our flip buffer, alloced if */
diff --git a/drivers/staging/dgnc/dgnc_cls.c b/drivers/staging/dgnc/dgnc_cls.c
index a17f4f6095c8..bedc5221b6fc 100644
--- a/drivers/staging/dgnc/dgnc_cls.c
+++ b/drivers/staging/dgnc/dgnc_cls.c
@@ -724,10 +724,8 @@ static void cls_tasklet(unsigned long data)
724 int state = 0; 724 int state = 0;
725 int ports = 0; 725 int ports = 0;
726 726
727 if (!bd || bd->magic != DGNC_BOARD_MAGIC) { 727 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
728 APR(("poll_tasklet() - NULL or bad bd.\n"));
729 return; 728 return;
730 }
731 729
732 /* Cache a couple board values */ 730 /* Cache a couple board values */
733 spin_lock_irqsave(&bd->bd_lock, flags); 731 spin_lock_irqsave(&bd->bd_lock, flags);
@@ -794,25 +792,17 @@ static void cls_tasklet(unsigned long data)
794 */ 792 */
795static irqreturn_t cls_intr(int irq, void *voidbrd) 793static irqreturn_t cls_intr(int irq, void *voidbrd)
796{ 794{
797 struct dgnc_board *brd = (struct dgnc_board *) voidbrd; 795 struct dgnc_board *brd = voidbrd;
798 uint i = 0; 796 uint i = 0;
799 unsigned char poll_reg; 797 unsigned char poll_reg;
800 unsigned long flags; 798 unsigned long flags;
801 799
802 if (!brd) {
803 APR(("Received interrupt (%d) with null board associated\n",
804 irq));
805 return IRQ_NONE;
806 }
807
808 /* 800 /*
809 * Check to make sure its for us. 801 * Check to make sure it didn't receive interrupt with a null board
802 * associated or a board pointer that wasn't ours.
810 */ 803 */
811 if (brd->magic != DGNC_BOARD_MAGIC) { 804 if (!brd || brd->magic != DGNC_BOARD_MAGIC)
812 APR(("Received interrupt (%d) with a board pointer that wasn't ours!\n",
813 irq));
814 return IRQ_NONE; 805 return IRQ_NONE;
815 }
816 806
817 spin_lock_irqsave(&brd->bd_intr_lock, flags); 807 spin_lock_irqsave(&brd->bd_intr_lock, flags);
818 808
@@ -928,8 +918,6 @@ static void cls_copy_data_from_uart_to_queue(struct channel_t *ch)
928 ch->ch_equeue[head] = linestatus & (UART_LSR_BI | UART_LSR_PE 918 ch->ch_equeue[head] = linestatus & (UART_LSR_BI | UART_LSR_PE
929 | UART_LSR_FE); 919 | UART_LSR_FE);
930 ch->ch_rqueue[head] = readb(&ch->ch_cls_uart->txrx); 920 ch->ch_rqueue[head] = readb(&ch->ch_cls_uart->txrx);
931 dgnc_sniff_nowait_nolock(ch, "UART READ",
932 ch->ch_rqueue + head, 1);
933 921
934 qleft--; 922 qleft--;
935 923
@@ -964,7 +952,6 @@ static int cls_drain(struct tty_struct *tty, uint seconds)
964 unsigned long flags; 952 unsigned long flags;
965 struct channel_t *ch; 953 struct channel_t *ch;
966 struct un_t *un; 954 struct un_t *un;
967 int rc = 0;
968 955
969 if (!tty || tty->magic != TTY_MAGIC) 956 if (!tty || tty->magic != TTY_MAGIC)
970 return -ENXIO; 957 return -ENXIO;
@@ -984,12 +971,11 @@ static int cls_drain(struct tty_struct *tty, uint seconds)
984 /* 971 /*
985 * NOTE: Do something with time passed in. 972 * NOTE: Do something with time passed in.
986 */ 973 */
987 rc = wait_event_interruptible(un->un_flags_wait,
988 ((un->un_flags & UN_EMPTY) == 0));
989 974
990 /* If ret is non-zero, user ctrl-c'ed us */ 975 /* If ret is non-zero, user ctrl-c'ed us */
991 976
992 return rc; 977 return wait_event_interruptible(un->un_flags_wait,
978 ((un->un_flags & UN_EMPTY) == 0));
993} 979}
994 980
995 981
@@ -1098,8 +1084,6 @@ static void cls_copy_data_from_queue_to_uart(struct channel_t *ch)
1098 ch->ch_tun.un_flags |= (UN_EMPTY); 1084 ch->ch_tun.un_flags |= (UN_EMPTY);
1099 } 1085 }
1100 writeb(ch->ch_wqueue[ch->ch_w_tail], &ch->ch_cls_uart->txrx); 1086 writeb(ch->ch_wqueue[ch->ch_w_tail], &ch->ch_cls_uart->txrx);
1101 dgnc_sniff_nowait_nolock(ch, "UART WRITE",
1102 ch->ch_wqueue + ch->ch_w_tail, 1);
1103 ch->ch_w_tail++; 1087 ch->ch_w_tail++;
1104 ch->ch_w_tail &= WQUEUEMASK; 1088 ch->ch_w_tail &= WQUEUEMASK;
1105 ch->ch_txcount++; 1089 ch->ch_txcount++;
diff --git a/drivers/staging/dgnc/dgnc_driver.c b/drivers/staging/dgnc/dgnc_driver.c
index 21546659ff07..ba98ff348112 100644
--- a/drivers/staging/dgnc/dgnc_driver.c
+++ b/drivers/staging/dgnc/dgnc_driver.c
@@ -49,16 +49,6 @@ MODULE_AUTHOR("Digi International, http://www.digi.com");
49MODULE_DESCRIPTION("Driver for the Digi International Neo and Classic PCI based product line"); 49MODULE_DESCRIPTION("Driver for the Digi International Neo and Classic PCI based product line");
50MODULE_SUPPORTED_DEVICE("dgnc"); 50MODULE_SUPPORTED_DEVICE("dgnc");
51 51
52/*
53 * insmod command line overrideable parameters
54 *
55 * NOTE: we use a set of macros to create the variables, which allows
56 * us to specify the variable type, name, initial value, and description.
57 */
58PARM_INT(debug, 0x00, 0644, "Driver debugging level");
59PARM_INT(rawreadok, 1, 0644, "Bypass flip buffers on input");
60PARM_INT(trcbuf_size, 0x100000, 0644, "Debugging trace buffer size.");
61
62/************************************************************************** 52/**************************************************************************
63 * 53 *
64 * protos for this file 54 * protos for this file
@@ -207,8 +197,6 @@ static int __init dgnc_init_module(void)
207{ 197{
208 int rc = 0; 198 int rc = 0;
209 199
210 APR(("%s, Digi International Part Number %s\n", DG_NAME, DG_PART));
211
212 /* 200 /*
213 * Initialize global stuff 201 * Initialize global stuff
214 */ 202 */
@@ -254,8 +242,6 @@ static int dgnc_start(void)
254 /* make sure that the globals are init'd before we do anything else */ 242 /* make sure that the globals are init'd before we do anything else */
255 dgnc_init_globals(); 243 dgnc_init_globals();
256 244
257 APR(("For the tools package or updated drivers please visit http://www.digi.com\n"));
258
259 /* 245 /*
260 * Register our base character device into the kernel. 246 * Register our base character device into the kernel.
261 * This allows the download daemon to connect to the downld device 247 * This allows the download daemon to connect to the downld device
@@ -265,7 +251,7 @@ static int dgnc_start(void)
265 */ 251 */
266 rc = register_chrdev(0, "dgnc", &dgnc_BoardFops); 252 rc = register_chrdev(0, "dgnc", &dgnc_BoardFops);
267 if (rc <= 0) { 253 if (rc <= 0) {
268 APR(("Can't register dgnc driver device (%d)\n", rc)); 254 pr_err(DRVSTR ": Can't register dgnc driver device (%d)\n", rc);
269 return -ENXIO; 255 return -ENXIO;
270 } 256 }
271 dgnc_Major = rc; 257 dgnc_Major = rc;
@@ -281,7 +267,7 @@ static int dgnc_start(void)
281 rc = dgnc_tty_preinit(); 267 rc = dgnc_tty_preinit();
282 268
283 if (rc < 0) { 269 if (rc < 0) {
284 APR(("tty preinit - not enough memory (%d)\n", rc)); 270 pr_err(DRVSTR ": tty preinit - not enough memory (%d)\n", rc);
285 return rc; 271 return rc;
286 } 272 }
287 273
@@ -468,7 +454,8 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
468 brd->membase = pci_resource_start(pdev, 4); 454 brd->membase = pci_resource_start(pdev, 4);
469 455
470 if (!brd->membase) { 456 if (!brd->membase) {
471 APR(("card has no PCI IO resources, failing board.\n")); 457 dev_err(&brd->pdev->dev,
458 "Card has no PCI IO resources, failing.\n");
472 return -ENODEV; 459 return -ENODEV;
473 } 460 }
474 461
@@ -555,7 +542,8 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
555 break; 542 break;
556 543
557 default: 544 default:
558 APR(("Did not find any compatible Neo or Classic PCI boards in system.\n")); 545 dev_err(&brd->pdev->dev,
546 "Didn't find any compatible Neo/Classic PCI boards.\n");
559 return -ENXIO; 547 return -ENXIO;
560 548
561 } 549 }
@@ -567,7 +555,7 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
567 rc = dgnc_tty_register(brd); 555 rc = dgnc_tty_register(brd);
568 if (rc < 0) { 556 if (rc < 0) {
569 dgnc_tty_uninit(brd); 557 dgnc_tty_uninit(brd);
570 APR(("Can't register tty devices (%d)\n", rc)); 558 pr_err(DRVSTR ": Can't register tty devices (%d)\n", rc);
571 brd->state = BOARD_FAILED; 559 brd->state = BOARD_FAILED;
572 brd->dpastatus = BD_NOFEP; 560 brd->dpastatus = BD_NOFEP;
573 goto failed; 561 goto failed;
@@ -575,7 +563,7 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
575 563
576 rc = dgnc_finalize_board_init(brd); 564 rc = dgnc_finalize_board_init(brd);
577 if (rc < 0) { 565 if (rc < 0) {
578 APR(("Can't finalize board init (%d)\n", rc)); 566 pr_err(DRVSTR ": Can't finalize board init (%d)\n", rc);
579 brd->state = BOARD_FAILED; 567 brd->state = BOARD_FAILED;
580 brd->dpastatus = BD_NOFEP; 568 brd->dpastatus = BD_NOFEP;
581 569
@@ -585,7 +573,7 @@ static int dgnc_found_board(struct pci_dev *pdev, int id)
585 rc = dgnc_tty_init(brd); 573 rc = dgnc_tty_init(brd);
586 if (rc < 0) { 574 if (rc < 0) {
587 dgnc_tty_uninit(brd); 575 dgnc_tty_uninit(brd);
588 APR(("Can't init tty devices (%d)\n", rc)); 576 pr_err(DRVSTR ": Can't init tty devices (%d)\n", rc);
589 brd->state = BOARD_FAILED; 577 brd->state = BOARD_FAILED;
590 brd->dpastatus = BD_NOFEP; 578 brd->dpastatus = BD_NOFEP;
591 579
@@ -744,9 +732,6 @@ static void dgnc_init_globals(void)
744{ 732{
745 int i = 0; 733 int i = 0;
746 734
747 dgnc_rawreadok = rawreadok;
748 dgnc_trcbuf_size = trcbuf_size;
749 dgnc_debug = debug;
750 dgnc_NumBoards = 0; 735 dgnc_NumBoards = 0;
751 736
752 for (i = 0; i < MAXBOARDS; i++) 737 for (i = 0; i < MAXBOARDS; i++)
diff --git a/drivers/staging/dgnc/dgnc_driver.h b/drivers/staging/dgnc/dgnc_driver.h
index f901957c757f..a8157eba28da 100644
--- a/drivers/staging/dgnc/dgnc_driver.h
+++ b/drivers/staging/dgnc/dgnc_driver.h
@@ -42,53 +42,13 @@
42 * 42 *
43 *************************************************************************/ 43 *************************************************************************/
44 44
45/* 45/* Driver identification and error statments */
46 * Driver identification, error and debugging statments
47 *
48 * In theory, you can change all occurrences of "digi" in the next
49 * three lines, and the driver printk's will all automagically change.
50 *
51 * APR((fmt, args, ...)); Always prints message
52 */
53#define PROCSTR "dgnc" /* /proc entries */ 46#define PROCSTR "dgnc" /* /proc entries */
54#define DEVSTR "/dev/dg/dgnc" /* /dev entries */ 47#define DEVSTR "/dev/dg/dgnc" /* /dev entries */
55#define DRVSTR "dgnc" /* Driver name string 48#define DRVSTR "dgnc" /* Driver name string */
56 * displayed by APR */
57#define APR(args) do { printk(DRVSTR": "); printk args; \
58 } while (0)
59#define RAPR(args) do { printk args; } while (0)
60 49
61#define TRC_TO_CONSOLE 1 50#define TRC_TO_CONSOLE 1
62 51
63/*
64 * Debugging levels can be set using debug insmod variable
65 * They can also be compiled out completely.
66 */
67
68#define DBG_INIT (dgnc_debug & 0x01)
69#define DBG_BASIC (dgnc_debug & 0x02)
70#define DBG_CORE (dgnc_debug & 0x04)
71
72#define DBG_OPEN (dgnc_debug & 0x08)
73#define DBG_CLOSE (dgnc_debug & 0x10)
74#define DBG_READ (dgnc_debug & 0x20)
75#define DBG_WRITE (dgnc_debug & 0x40)
76
77#define DBG_IOCTL (dgnc_debug & 0x80)
78
79#define DBG_PROC (dgnc_debug & 0x100)
80#define DBG_PARAM (dgnc_debug & 0x200)
81#define DBG_PSCAN (dgnc_debug & 0x400)
82#define DBG_EVENT (dgnc_debug & 0x800)
83
84#define DBG_DRAIN (dgnc_debug & 0x1000)
85#define DBG_MSIGS (dgnc_debug & 0x2000)
86
87#define DBG_MGMT (dgnc_debug & 0x4000)
88#define DBG_INTR (dgnc_debug & 0x8000)
89
90#define DBG_CARR (dgnc_debug & 0x10000)
91
92/* Number of boards we support at once. */ 52/* Number of boards we support at once. */
93#define MAXBOARDS 20 53#define MAXBOARDS 20
94#define MAXPORTS 8 54#define MAXPORTS 8
@@ -134,8 +94,6 @@
134#define _POSIX_VDISABLE '\0' 94#define _POSIX_VDISABLE '\0'
135#endif 95#endif
136 96
137#define SNIFF_MAX 65536 /* Sniff buffer size (2^n) */
138#define SNIFF_MASK (SNIFF_MAX - 1) /* Sniff wrap mask */
139 97
140/* 98/*
141 * All the possible states the driver can be while being loaded. 99 * All the possible states the driver can be while being loaded.
@@ -342,13 +300,6 @@ struct un_t {
342#define CH_FORCED_STOP 0x20000 /* Output is forcibly stopped */ 300#define CH_FORCED_STOP 0x20000 /* Output is forcibly stopped */
343#define CH_FORCED_STOPI 0x40000 /* Input is forcibly stopped */ 301#define CH_FORCED_STOPI 0x40000 /* Input is forcibly stopped */
344 302
345/*
346 * Definitions for ch_sniff_flags
347 */
348#define SNIFF_OPEN 0x1
349#define SNIFF_WAIT_DATA 0x2
350#define SNIFF_WAIT_SPACE 0x4
351
352 303
353/* Our Read/Error/Write queue sizes */ 304/* Our Read/Error/Write queue sizes */
354#define RQUEUEMASK 0x1FFF /* 8 K - 1 */ 305#define RQUEUEMASK 0x1FFF /* 8 K - 1 */
@@ -442,21 +393,13 @@ struct channel_t {
442 struct proc_dir_entry *proc_entry_pointer; 393 struct proc_dir_entry *proc_entry_pointer;
443 struct dgnc_proc_entry *dgnc_channel_table; 394 struct dgnc_proc_entry *dgnc_channel_table;
444 395
445 uint ch_sniff_in;
446 uint ch_sniff_out;
447 char *ch_sniff_buf; /* Sniff buffer for proc */
448 ulong ch_sniff_flags; /* Channel flags */
449 wait_queue_head_t ch_sniff_wait;
450}; 396};
451 397
452/* 398/*
453 * Our Global Variables. 399 * Our Global Variables.
454 */ 400 */
455extern uint dgnc_Major; /* Our driver/mgmt major */ 401extern uint dgnc_Major; /* Our driver/mgmt major */
456extern int dgnc_debug; /* Debug variable */
457extern int dgnc_rawreadok; /* Set if user wants rawreads */
458extern int dgnc_poll_tick; /* Poll interval - 20 ms */ 402extern int dgnc_poll_tick; /* Poll interval - 20 ms */
459extern int dgnc_trcbuf_size; /* Size of the ringbuffer */
460extern spinlock_t dgnc_global_lock; /* Driver global spinlock */ 403extern spinlock_t dgnc_global_lock; /* Driver global spinlock */
461extern uint dgnc_NumBoards; /* Total number of boards */ 404extern uint dgnc_NumBoards; /* Total number of boards */
462extern struct dgnc_board *dgnc_Board[MAXBOARDS]; /* Array of board structs */ 405extern struct dgnc_board *dgnc_Board[MAXBOARDS]; /* Array of board structs */
diff --git a/drivers/staging/dgnc/dgnc_kcompat.h b/drivers/staging/dgnc/dgnc_kcompat.h
index eaec7e6a28e1..566cad0d33e7 100644
--- a/drivers/staging/dgnc/dgnc_kcompat.h
+++ b/drivers/staging/dgnc/dgnc_kcompat.h
@@ -43,22 +43,4 @@
43# endif 43# endif
44 44
45 45
46# define PARM_STR(VAR, INIT, PERM, DESC) \
47 static char *VAR = INIT; \
48 char *dgnc_##VAR; \
49 module_param(VAR, charp, PERM); \
50 MODULE_PARM_DESC(VAR, DESC);
51
52# define PARM_INT(VAR, INIT, PERM, DESC) \
53 static int VAR = INIT; \
54 int dgnc_##VAR; \
55 module_param(VAR, int, PERM); \
56 MODULE_PARM_DESC(VAR, DESC);
57
58# define PARM_ULONG(VAR, INIT, PERM, DESC) \
59 static ulong VAR = INIT; \
60 ulong dgnc_##VAR; \
61 module_param(VAR, long, PERM); \
62 MODULE_PARM_DESC(VAR, DESC);
63
64#endif /* ! __DGNC_KCOMPAT_H */ 46#endif /* ! __DGNC_KCOMPAT_H */
diff --git a/drivers/staging/dgnc/dgnc_neo.c b/drivers/staging/dgnc/dgnc_neo.c
index a5bd08fef270..c9a8a9825cfb 100644
--- a/drivers/staging/dgnc/dgnc_neo.c
+++ b/drivers/staging/dgnc/dgnc_neo.c
@@ -530,10 +530,11 @@ static inline void neo_parse_lsr(struct dgnc_board *brd, uint port)
530 int linestatus; 530 int linestatus;
531 unsigned long flags; 531 unsigned long flags;
532 532
533 if (!brd) 533 /*
534 return; 534 * Check to make sure it didn't receive interrupt with a null board
535 535 * associated or a board pointer that wasn't ours.
536 if (brd->magic != DGNC_BOARD_MAGIC) 536 */
537 if (!brd || brd->magic != DGNC_BOARD_MAGIC)
537 return; 538 return;
538 539
539 if (port > brd->maxports) 540 if (port > brd->maxports)
@@ -869,10 +870,8 @@ static void neo_tasklet(unsigned long data)
869 int state = 0; 870 int state = 0;
870 int ports = 0; 871 int ports = 0;
871 872
872 if (!bd || bd->magic != DGNC_BOARD_MAGIC) { 873 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
873 APR(("poll_tasklet() - NULL or bad bd.\n"));
874 return; 874 return;
875 }
876 875
877 /* Cache a couple board values */ 876 /* Cache a couple board values */
878 spin_lock_irqsave(&bd->bd_lock, flags); 877 spin_lock_irqsave(&bd->bd_lock, flags);
@@ -945,7 +944,7 @@ static void neo_tasklet(unsigned long data)
945 */ 944 */
946static irqreturn_t neo_intr(int irq, void *voidbrd) 945static irqreturn_t neo_intr(int irq, void *voidbrd)
947{ 946{
948 struct dgnc_board *brd = (struct dgnc_board *) voidbrd; 947 struct dgnc_board *brd = voidbrd;
949 struct channel_t *ch; 948 struct channel_t *ch;
950 int port = 0; 949 int port = 0;
951 int type = 0; 950 int type = 0;
@@ -955,18 +954,12 @@ static irqreturn_t neo_intr(int irq, void *voidbrd)
955 unsigned long flags; 954 unsigned long flags;
956 unsigned long flags2; 955 unsigned long flags2;
957 956
958 if (!brd) {
959 APR(("Received interrupt (%d) with null board associated\n", irq));
960 return IRQ_NONE;
961 }
962
963 /* 957 /*
964 * Check to make sure its for us. 958 * Check to make sure it didn't receive interrupt with a null board
959 * associated or a board pointer that wasn't ours.
965 */ 960 */
966 if (brd->magic != DGNC_BOARD_MAGIC) { 961 if (!brd || brd->magic != DGNC_BOARD_MAGIC)
967 APR(("Received interrupt (%d) with a board pointer that wasn't ours!\n", irq));
968 return IRQ_NONE; 962 return IRQ_NONE;
969 }
970 963
971 brd->intr_count++; 964 brd->intr_count++;
972 965
@@ -1224,7 +1217,6 @@ static void neo_copy_data_from_uart_to_queue(struct channel_t *ch)
1224 1217
1225 /* Copy data from uart to the queue */ 1218 /* Copy data from uart to the queue */
1226 memcpy_fromio(ch->ch_rqueue + head, &ch->ch_neo_uart->txrxburst, n); 1219 memcpy_fromio(ch->ch_rqueue + head, &ch->ch_neo_uart->txrxburst, n);
1227 dgnc_sniff_nowait_nolock(ch, "UART READ", ch->ch_rqueue + head, n);
1228 1220
1229 /* 1221 /*
1230 * Since RX_FIFO_DATA_ERROR was 0, we are guarenteed 1222 * Since RX_FIFO_DATA_ERROR was 0, we are guarenteed
@@ -1310,7 +1302,6 @@ static void neo_copy_data_from_uart_to_queue(struct channel_t *ch)
1310 1302
1311 memcpy_fromio(ch->ch_rqueue + head, &ch->ch_neo_uart->txrxburst, 1); 1303 memcpy_fromio(ch->ch_rqueue + head, &ch->ch_neo_uart->txrxburst, 1);
1312 ch->ch_equeue[head] = (unsigned char) linestatus; 1304 ch->ch_equeue[head] = (unsigned char) linestatus;
1313 dgnc_sniff_nowait_nolock(ch, "UART READ", ch->ch_rqueue + head, 1);
1314 1305
1315 /* Ditch any remaining linestatus value. */ 1306 /* Ditch any remaining linestatus value. */
1316 linestatus = 0; 1307 linestatus = 0;
@@ -1563,7 +1554,6 @@ static void neo_copy_data_from_queue_to_uart(struct channel_t *ch)
1563 } 1554 }
1564 1555
1565 memcpy_toio(&ch->ch_neo_uart->txrxburst, ch->ch_wqueue + tail, s); 1556 memcpy_toio(&ch->ch_neo_uart->txrxburst, ch->ch_wqueue + tail, s);
1566 dgnc_sniff_nowait_nolock(ch, "UART WRITE", ch->ch_wqueue + tail, s);
1567 1557
1568 /* Add and flip queue if needed */ 1558 /* Add and flip queue if needed */
1569 tail = (tail + s) & WQUEUEMASK; 1559 tail = (tail + s) & WQUEUEMASK;
diff --git a/drivers/staging/dgnc/dgnc_sysfs.c b/drivers/staging/dgnc/dgnc_sysfs.c
index 6c3b387622e9..2fd34ca70c59 100644
--- a/drivers/staging/dgnc/dgnc_sysfs.c
+++ b/drivers/staging/dgnc/dgnc_sysfs.c
@@ -63,39 +63,6 @@ static ssize_t dgnc_driver_maxboards_show(struct device_driver *ddp, char *buf)
63} 63}
64static DRIVER_ATTR(maxboards, S_IRUSR, dgnc_driver_maxboards_show, NULL); 64static DRIVER_ATTR(maxboards, S_IRUSR, dgnc_driver_maxboards_show, NULL);
65 65
66static ssize_t dgnc_driver_debug_show(struct device_driver *ddp, char *buf)
67{
68 return snprintf(buf, PAGE_SIZE, "0x%x\n", dgnc_debug);
69}
70
71static ssize_t dgnc_driver_debug_store(struct device_driver *ddp, const char *buf, size_t count)
72{
73 int ret;
74
75 ret = sscanf(buf, "0x%x\n", &dgnc_debug);
76 if (ret != 1)
77 return -EINVAL;
78 return count;
79}
80static DRIVER_ATTR(debug, (S_IRUSR | S_IWUSR), dgnc_driver_debug_show, dgnc_driver_debug_store);
81
82
83static ssize_t dgnc_driver_rawreadok_show(struct device_driver *ddp, char *buf)
84{
85 return snprintf(buf, PAGE_SIZE, "0x%x\n", dgnc_rawreadok);
86}
87
88static ssize_t dgnc_driver_rawreadok_store(struct device_driver *ddp, const char *buf, size_t count)
89{
90 int ret;
91
92 ret = sscanf(buf, "0x%x\n", &dgnc_rawreadok);
93 if (ret != 1)
94 return -EINVAL;
95 return count;
96}
97static DRIVER_ATTR(rawreadok, (S_IRUSR | S_IWUSR), dgnc_driver_rawreadok_show, dgnc_driver_rawreadok_store);
98
99 66
100static ssize_t dgnc_driver_pollrate_show(struct device_driver *ddp, char *buf) 67static ssize_t dgnc_driver_pollrate_show(struct device_driver *ddp, char *buf)
101{ 68{
@@ -122,8 +89,6 @@ void dgnc_create_driver_sysfiles(struct pci_driver *dgnc_driver)
122 rc |= driver_create_file(driverfs, &driver_attr_version); 89 rc |= driver_create_file(driverfs, &driver_attr_version);
123 rc |= driver_create_file(driverfs, &driver_attr_boards); 90 rc |= driver_create_file(driverfs, &driver_attr_boards);
124 rc |= driver_create_file(driverfs, &driver_attr_maxboards); 91 rc |= driver_create_file(driverfs, &driver_attr_maxboards);
125 rc |= driver_create_file(driverfs, &driver_attr_debug);
126 rc |= driver_create_file(driverfs, &driver_attr_rawreadok);
127 rc |= driver_create_file(driverfs, &driver_attr_pollrate); 92 rc |= driver_create_file(driverfs, &driver_attr_pollrate);
128 if (rc) 93 if (rc)
129 printk(KERN_ERR "DGNC: sysfs driver_create_file failed!\n"); 94 printk(KERN_ERR "DGNC: sysfs driver_create_file failed!\n");
@@ -137,8 +102,6 @@ void dgnc_remove_driver_sysfiles(struct pci_driver *dgnc_driver)
137 driver_remove_file(driverfs, &driver_attr_version); 102 driver_remove_file(driverfs, &driver_attr_version);
138 driver_remove_file(driverfs, &driver_attr_boards); 103 driver_remove_file(driverfs, &driver_attr_boards);
139 driver_remove_file(driverfs, &driver_attr_maxboards); 104 driver_remove_file(driverfs, &driver_attr_maxboards);
140 driver_remove_file(driverfs, &driver_attr_debug);
141 driver_remove_file(driverfs, &driver_attr_rawreadok);
142 driver_remove_file(driverfs, &driver_attr_pollrate); 105 driver_remove_file(driverfs, &driver_attr_pollrate);
143} 106}
144 107
diff --git a/drivers/staging/dgnc/dgnc_tty.c b/drivers/staging/dgnc/dgnc_tty.c
index 03c15069731f..f81a375f8bc1 100644
--- a/drivers/staging/dgnc/dgnc_tty.c
+++ b/drivers/staging/dgnc/dgnc_tty.c
@@ -49,7 +49,6 @@
49#include <linux/delay.h> /* For udelay */ 49#include <linux/delay.h> /* For udelay */
50#include <linux/uaccess.h> /* For copy_from_user/copy_to_user */ 50#include <linux/uaccess.h> /* For copy_from_user/copy_to_user */
51#include <linux/pci.h> 51#include <linux/pci.h>
52
53#include "dgnc_driver.h" 52#include "dgnc_driver.h"
54#include "dgnc_tty.h" 53#include "dgnc_tty.h"
55#include "dgnc_types.h" 54#include "dgnc_types.h"
@@ -233,7 +232,8 @@ int dgnc_tty_register(struct dgnc_board *brd)
233 /* Register tty devices */ 232 /* Register tty devices */
234 rc = tty_register_driver(&brd->SerialDriver); 233 rc = tty_register_driver(&brd->SerialDriver);
235 if (rc < 0) { 234 if (rc < 0) {
236 APR(("Can't register tty device (%d)\n", rc)); 235 dev_dbg(&brd->pdev->dev,
236 "Can't register tty device (%d)\n", rc);
237 return rc; 237 return rc;
238 } 238 }
239 brd->dgnc_Major_Serial_Registered = TRUE; 239 brd->dgnc_Major_Serial_Registered = TRUE;
@@ -281,7 +281,9 @@ int dgnc_tty_register(struct dgnc_board *brd)
281 /* Register Transparent Print devices */ 281 /* Register Transparent Print devices */
282 rc = tty_register_driver(&brd->PrintDriver); 282 rc = tty_register_driver(&brd->PrintDriver);
283 if (rc < 0) { 283 if (rc < 0) {
284 APR(("Can't register Transparent Print device (%d)\n", rc)); 284 dev_dbg(&brd->pdev->dev,
285 "Can't register Transparent Print device(%d)\n",
286 rc);
285 return rc; 287 return rc;
286 } 288 }
287 brd->dgnc_Major_TransparentPrint_Registered = TRUE; 289 brd->dgnc_Major_TransparentPrint_Registered = TRUE;
@@ -371,7 +373,6 @@ int dgnc_tty_init(struct dgnc_board *brd)
371 init_waitqueue_head(&ch->ch_flags_wait); 373 init_waitqueue_head(&ch->ch_flags_wait);
372 init_waitqueue_head(&ch->ch_tun.un_flags_wait); 374 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
373 init_waitqueue_head(&ch->ch_pun.un_flags_wait); 375 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
374 init_waitqueue_head(&ch->ch_sniff_wait);
375 376
376 { 377 {
377 struct device *classp; 378 struct device *classp;
@@ -446,127 +447,6 @@ void dgnc_tty_uninit(struct dgnc_board *brd)
446 447
447#define TMPBUFLEN (1024) 448#define TMPBUFLEN (1024)
448 449
449/*
450 * dgnc_sniff - Dump data out to the "sniff" buffer if the
451 * proc sniff file is opened...
452 */
453void dgnc_sniff_nowait_nolock(struct channel_t *ch, unsigned char *text, unsigned char *buf, int len)
454{
455 struct timeval tv;
456 int n;
457 int r;
458 int nbuf;
459 int i;
460 int tmpbuflen;
461 char *tmpbuf;
462 char *p;
463 int too_much_data;
464
465 tmpbuf = kzalloc(TMPBUFLEN, GFP_ATOMIC);
466 if (!tmpbuf)
467 return;
468 p = tmpbuf;
469
470 /* Leave if sniff not open */
471 if (!(ch->ch_sniff_flags & SNIFF_OPEN))
472 goto exit;
473
474 do_gettimeofday(&tv);
475
476 /* Create our header for data dump */
477 p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
478 tmpbuflen = p - tmpbuf;
479
480 do {
481 too_much_data = 0;
482
483 for (i = 0; i < len && tmpbuflen < (TMPBUFLEN - 4); i++) {
484 p += sprintf(p, "%02x ", *buf);
485 buf++;
486 tmpbuflen = p - tmpbuf;
487 }
488
489 if (tmpbuflen < (TMPBUFLEN - 4)) {
490 if (i > 0)
491 p += sprintf(p - 1, "%s\n", ">");
492 else
493 p += sprintf(p, "%s\n", ">");
494 } else {
495 too_much_data = 1;
496 len -= i;
497 }
498
499 nbuf = strlen(tmpbuf);
500 p = tmpbuf;
501
502 /*
503 * Loop while data remains.
504 */
505 while (nbuf > 0 && ch->ch_sniff_buf) {
506 /*
507 * Determine the amount of available space left in the
508 * buffer. If there's none, wait until some appears.
509 */
510 n = (ch->ch_sniff_out - ch->ch_sniff_in - 1) & SNIFF_MASK;
511
512 /*
513 * If there is no space left to write to in our sniff buffer,
514 * we have no choice but to drop the data.
515 * We *cannot* sleep here waiting for space, because this
516 * function was probably called by the interrupt/timer routines!
517 */
518 if (n == 0)
519 goto exit;
520
521 /*
522 * Copy as much data as will fit.
523 */
524
525 if (n > nbuf)
526 n = nbuf;
527
528 r = SNIFF_MAX - ch->ch_sniff_in;
529
530 if (r <= n) {
531 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, r);
532
533 n -= r;
534 ch->ch_sniff_in = 0;
535 p += r;
536 nbuf -= r;
537 }
538
539 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, n);
540
541 ch->ch_sniff_in += n;
542 p += n;
543 nbuf -= n;
544
545 /*
546 * Wakeup any thread waiting for data
547 */
548 if (ch->ch_sniff_flags & SNIFF_WAIT_DATA) {
549 ch->ch_sniff_flags &= ~SNIFF_WAIT_DATA;
550 wake_up_interruptible(&ch->ch_sniff_wait);
551 }
552 }
553
554 /*
555 * If the user sent us too much data to push into our tmpbuf,
556 * we need to keep looping around on all the data.
557 */
558 if (too_much_data) {
559 p = tmpbuf;
560 tmpbuflen = 0;
561 }
562
563 } while (too_much_data);
564
565exit:
566 kfree(tmpbuf);
567}
568
569
570/*======================================================================= 450/*=======================================================================
571 * 451 *
572 * dgnc_wmove - Write data to transmit queue. 452 * dgnc_wmove - Write data to transmit queue.
@@ -781,8 +661,6 @@ void dgnc_input(struct channel_t *ch)
781 tty_insert_flip_string(tp->port, ch->ch_rqueue + tail, s); 661 tty_insert_flip_string(tp->port, ch->ch_rqueue + tail, s);
782 } 662 }
783 663
784 dgnc_sniff_nowait_nolock(ch, "USER READ", ch->ch_rqueue + tail, s);
785
786 tail += s; 664 tail += s;
787 n -= s; 665 n -= s;
788 /* Flip queue if needed */ 666 /* Flip queue if needed */
@@ -1546,14 +1424,18 @@ static void dgnc_tty_close(struct tty_struct *tty, struct file *file)
1546 * one, we've got real problems, since it means the 1424 * one, we've got real problems, since it means the
1547 * serial port won't be shutdown. 1425 * serial port won't be shutdown.
1548 */ 1426 */
1549 APR(("tty->count is 1, un open count is %d\n", un->un_open_count)); 1427 dev_dbg(tty->dev,
1428 "tty->count is 1, un open count is %d\n",
1429 un->un_open_count);
1550 un->un_open_count = 1; 1430 un->un_open_count = 1;
1551 } 1431 }
1552 1432
1553 if (un->un_open_count) 1433 if (un->un_open_count)
1554 un->un_open_count--; 1434 un->un_open_count--;
1555 else 1435 else
1556 APR(("bad serial port open count of %d\n", un->un_open_count)); 1436 dev_dbg(tty->dev,
1437 "bad serial port open count of %d\n",
1438 un->un_open_count);
1557 1439
1558 ch->ch_open_count--; 1440 ch->ch_open_count--;
1559 1441
@@ -1974,7 +1856,6 @@ static int dgnc_tty_write(struct tty_struct *tty,
1974 if (n >= remain) { 1856 if (n >= remain) {
1975 n -= remain; 1857 n -= remain;
1976 memcpy(ch->ch_wqueue + head, buf, remain); 1858 memcpy(ch->ch_wqueue + head, buf, remain);
1977 dgnc_sniff_nowait_nolock(ch, "USER WRITE", ch->ch_wqueue + head, remain);
1978 head = 0; 1859 head = 0;
1979 buf += remain; 1860 buf += remain;
1980 } 1861 }
@@ -1985,7 +1866,6 @@ static int dgnc_tty_write(struct tty_struct *tty,
1985 */ 1866 */
1986 remain = n; 1867 remain = n;
1987 memcpy(ch->ch_wqueue + head, buf, remain); 1868 memcpy(ch->ch_wqueue + head, buf, remain);
1988 dgnc_sniff_nowait_nolock(ch, "USER WRITE", ch->ch_wqueue + head, remain);
1989 head += remain; 1869 head += remain;
1990 } 1870 }
1991 1871
@@ -2325,8 +2205,6 @@ static int dgnc_set_modem_info(struct tty_struct *tty, unsigned int command, uns
2325 if (!bd || bd->magic != DGNC_BOARD_MAGIC) 2205 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
2326 return ret; 2206 return ret;
2327 2207
2328 ret = 0;
2329
2330 ret = get_user(arg, value); 2208 ret = get_user(arg, value);
2331 if (ret) 2209 if (ret)
2332 return ret; 2210 return ret;
@@ -3089,7 +2967,7 @@ static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
3089 struct digi_getcounter buf; 2967 struct digi_getcounter buf;
3090 2968
3091 buf.norun = ch->ch_err_overrun; 2969 buf.norun = ch->ch_err_overrun;
3092 buf.noflow = 0; /* The driver doesn't keep this stat */ 2970 buf.noflow = 0; /* The driver doesn't keep this stat */
3093 buf.nframe = ch->ch_err_frame; 2971 buf.nframe = ch->ch_err_frame;
3094 buf.nparity = ch->ch_err_parity; 2972 buf.nparity = ch->ch_err_parity;
3095 buf.nbreak = ch->ch_err_break; 2973 buf.nbreak = ch->ch_err_break;
diff --git a/drivers/staging/dgnc/dgnc_tty.h b/drivers/staging/dgnc/dgnc_tty.h
index 58eef257c2ec..3975f0407143 100644
--- a/drivers/staging/dgnc/dgnc_tty.h
+++ b/drivers/staging/dgnc/dgnc_tty.h
@@ -37,6 +37,4 @@ void dgnc_carrier(struct channel_t *ch);
37void dgnc_wakeup_writes(struct channel_t *ch); 37void dgnc_wakeup_writes(struct channel_t *ch);
38void dgnc_check_queue_flow_control(struct channel_t *ch); 38void dgnc_check_queue_flow_control(struct channel_t *ch);
39 39
40void dgnc_sniff_nowait_nolock(struct channel_t *ch, unsigned char *text, unsigned char *buf, int nbuf);
41
42#endif 40#endif
diff --git a/drivers/staging/emxx_udc/emxx_udc.c b/drivers/staging/emxx_udc/emxx_udc.c
index ed8d86c98f65..eb178fcb7954 100644
--- a/drivers/staging/emxx_udc/emxx_udc.c
+++ b/drivers/staging/emxx_udc/emxx_udc.c
@@ -2622,7 +2622,7 @@ static int nbu2ss_ep_enable(
2622 return -EINVAL; 2622 return -EINVAL;
2623 } 2623 }
2624 2624
2625 ep_type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; 2625 ep_type = usb_endpoint_type(desc);
2626 if ((ep_type == USB_ENDPOINT_XFER_CONTROL) 2626 if ((ep_type == USB_ENDPOINT_XFER_CONTROL)
2627 || (ep_type == USB_ENDPOINT_XFER_ISOC)) { 2627 || (ep_type == USB_ENDPOINT_XFER_ISOC)) {
2628 2628
@@ -2644,7 +2644,7 @@ static int nbu2ss_ep_enable(
2644 spin_lock_irqsave(&udc->lock, flags); 2644 spin_lock_irqsave(&udc->lock, flags);
2645 2645
2646 ep->desc = desc; 2646 ep->desc = desc;
2647 ep->epnum = desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; 2647 ep->epnum = usb_endpoint_num(desc);
2648 ep->direct = desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK; 2648 ep->direct = desc->bEndpointAddress & USB_ENDPOINT_DIR_MASK;
2649 ep->ep_type = ep_type; 2649 ep->ep_type = ep_type;
2650 ep->wedged = 0; 2650 ep->wedged = 0;
@@ -2722,8 +2722,7 @@ static void nbu2ss_ep_free_request(
2722 if (_req != NULL) { 2722 if (_req != NULL) {
2723 req = container_of(_req, struct nbu2ss_req, req); 2723 req = container_of(_req, struct nbu2ss_req, req);
2724 2724
2725 if (req != NULL) 2725 kfree(req);
2726 kfree(req);
2727 } 2726 }
2728} 2727}
2729 2728
diff --git a/drivers/staging/ft1000/ft1000-pcmcia/boot.h b/drivers/staging/ft1000/ft1000-pcmcia/boot.h
index 60c015c1c28a..e4a698528520 100644
--- a/drivers/staging/ft1000/ft1000-pcmcia/boot.h
+++ b/drivers/staging/ft1000/ft1000-pcmcia/boot.h
@@ -1,28 +1,28 @@
1/*--------------------------------------------------------------------------- 1/*---------------------------------------------------------------------------
2 FT1000 driver for Flarion Flash OFDM NIC Device 2 FT1000 driver for Flarion Flash OFDM NIC Device
3 3
4 Copyright (C) 2002 Flarion Technologies, All rights reserved. 4 Copyright (C) 2002 Flarion Technologies, All rights reserved.
5 5
6 This program is free software; you can redistribute it and/or modify it 6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free 7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option) any 8 Software Foundation; either version 2 of the License, or (at your option) any
9 later version. This program is distributed in the hope that it will be useful, 9 later version. This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 more details. You should have received a copy of the GNU General Public 12 more details. You should have received a copy of the GNU General Public
13 License along with this program; if not, write to the 13 License along with this program; if not, write to the
14 Free Software Foundation, Inc., 59 Temple Place - 14 Free Software Foundation, Inc., 59 Temple Place -
15 Suite 330, Boston, MA 02111-1307, USA. 15 Suite 330, Boston, MA 02111-1307, USA.
16 --------------------------------------------------------------------------- 16 ---------------------------------------------------------------------------
17 17
18 File: boot.h 18 File: boot.h
19 19
20 Description: boatloader 20 Description: boatloader
21 21
22 History: 22 History:
23 1/11/05 Whc Ported to Linux. 23 1/11/05 Whc Ported to Linux.
24 24
25---------------------------------------------------------------------------*/ 25 ---------------------------------------------------------------------------*/
26#ifndef _BOOTH_ 26#ifndef _BOOTH_
27#define _BOOTH_ 27#define _BOOTH_
28 28
diff --git a/drivers/staging/ft1000/ft1000-pcmcia/ft1000.h b/drivers/staging/ft1000/ft1000-pcmcia/ft1000.h
index 1d52738fff49..5992670f7747 100644
--- a/drivers/staging/ft1000/ft1000-pcmcia/ft1000.h
+++ b/drivers/staging/ft1000/ft1000-pcmcia/ft1000.h
@@ -1,21 +1,21 @@
1/*--------------------------------------------------------------------------- 1/*---------------------------------------------------------------------------
2 FT1000 driver for Flarion Flash OFDM NIC Device 2 FT1000 driver for Flarion Flash OFDM NIC Device
3 3
4 Copyright (C) 2002 Flarion Technologies, All rights reserved. 4 Copyright (C) 2002 Flarion Technologies, All rights reserved.
5 5
6 This program is free software; you can redistribute it and/or modify it 6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free 7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option) any 8 Software Foundation; either version 2 of the License, or (at your option) any
9 later version. This program is distributed in the hope that it will be useful, 9 later version. This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 more details. You should have received a copy of the GNU General Public 12 more details. You should have received a copy of the GNU General Public
13 License along with this program; if not, write to the 13 License along with this program; if not, write to the
14 Free Software Foundation, Inc., 59 Temple Place - 14 Free Software Foundation, Inc., 59 Temple Place -
15 Suite 330, Boston, MA 02111-1307, USA. 15 Suite 330, Boston, MA 02111-1307, USA.
16--------------------------------------------------------------------------- 16 ---------------------------------------------------------------------------
17 Description: Common structures and defines 17 Description: Common structures and defines
18---------------------------------------------------------------------------*/ 18 ---------------------------------------------------------------------------*/
19#ifndef _FT1000H_ 19#ifndef _FT1000H_
20#define _FT1000H_ 20#define _FT1000H_
21 21
diff --git a/drivers/staging/ft1000/ft1000-pcmcia/ft1000_cs.c b/drivers/staging/ft1000/ft1000-pcmcia/ft1000_cs.c
index 1f8b3ca35c69..922478e1cb57 100644
--- a/drivers/staging/ft1000/ft1000-pcmcia/ft1000_cs.c
+++ b/drivers/staging/ft1000/ft1000-pcmcia/ft1000_cs.c
@@ -1,30 +1,30 @@
1/*--------------------------------------------------------------------------- 1/*---------------------------------------------------------------------------
2 FT1000 driver for Flarion Flash OFDM NIC Device 2 FT1000 driver for Flarion Flash OFDM NIC Device
3 3
4 Copyright (C) 1999 David A. Hinds. All Rights Reserved. 4 Copyright (C) 1999 David A. Hinds. All Rights Reserved.
5 Copyright (C) 2002 Flarion Technologies, All rights reserved. 5 Copyright (C) 2002 Flarion Technologies, All rights reserved.
6 Copyright (C) 2006 Patrik Ostrihon, All rights reserved. 6 Copyright (C) 2006 Patrik Ostrihon, All rights reserved.
7 Copyright (C) 2006 ProWeb Consulting, a.s, All rights reserved. 7 Copyright (C) 2006 ProWeb Consulting, a.s, All rights reserved.
8 8
9 The initial developer of the original code is David A. Hinds 9 The initial developer of the original code is David A. Hinds
10 <dahinds@users.sourceforge.net>. Portions created by David A. Hinds. 10 <dahinds@users.sourceforge.net>. Portions created by David A. Hinds.
11 11
12 This file was modified to support the Flarion Flash OFDM NIC Device 12 This file was modified to support the Flarion Flash OFDM NIC Device
13 by Wai Chan (w.chan@flarion.com). 13 by Wai Chan (w.chan@flarion.com).
14 14
15 Port for kernel 2.6 created by Patrik Ostrihon (patrik.ostrihon@pwc.sk) 15 Port for kernel 2.6 created by Patrik Ostrihon (patrik.ostrihon@pwc.sk)
16 16
17 This program is free software; you can redistribute it and/or modify it 17 This program is free software; you can redistribute it and/or modify it
18 under the terms of the GNU General Public License as published by the Free 18 under the terms of the GNU General Public License as published by the Free
19 Software Foundation; either version 2 of the License, or (at your option) any 19 Software Foundation; either version 2 of the License, or (at your option) any
20 later version. This program is distributed in the hope that it will be useful, 20 later version. This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 21 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 22 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
23 more details. You should have received a copy of the GNU General Public 23 more details. You should have received a copy of the GNU General Public
24 License along with this program; if not, write to the 24 License along with this program; if not, write to the
25 Free Software Foundation, Inc., 59 Temple Place - 25 Free Software Foundation, Inc., 59 Temple Place -
26 Suite 330, Boston, MA 02111-1307, USA. 26 Suite 330, Boston, MA 02111-1307, USA.
27-----------------------------------------------------------------------------*/ 27 -----------------------------------------------------------------------------*/
28 28
29#include <linux/kernel.h> 29#include <linux/kernel.h>
30#include <linux/module.h> 30#include <linux/module.h>
@@ -80,11 +80,11 @@ static int ft1000_confcheck(struct pcmcia_device *link, void *priv_data)
80 80
81/*====================================================================== 81/*======================================================================
82 82
83 ft1000_config() is scheduled to run after a CARD_INSERTION event 83 ft1000_config() is scheduled to run after a CARD_INSERTION event
84 is received, to configure the PCMCIA socket, and to make the 84 is received, to configure the PCMCIA socket, and to make the
85 device available to the system. 85 device available to the system.
86 86
87======================================================================*/ 87 ======================================================================*/
88 88
89static int ft1000_config(struct pcmcia_device *link) 89static int ft1000_config(struct pcmcia_device *link)
90{ 90{
diff --git a/drivers/staging/ft1000/ft1000-pcmcia/ft1000_dnld.c b/drivers/staging/ft1000/ft1000-pcmcia/ft1000_dnld.c
index c1856f7d1e26..06b0e9cfb9b1 100644
--- a/drivers/staging/ft1000/ft1000-pcmcia/ft1000_dnld.c
+++ b/drivers/staging/ft1000/ft1000-pcmcia/ft1000_dnld.c
@@ -1,24 +1,26 @@
1/*--------------------------------------------------------------------------- 1/*---------------------------------------------------------------------------
2 FT1000 driver for Flarion Flash OFDM NIC Device 2 FT1000 driver for Flarion Flash OFDM NIC Device
3 3
4 Copyright (C) 2002 Flarion Technologies, All rights reserved. 4 Copyright (C) 2002 Flarion Technologies, All rights reserved.
5 5
6 This program is free software; you can redistribute it and/or modify it 6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free 7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option) any 8 Software Foundation; either version 2 of the License, or (at your option) any
9 later version. This program is distributed in the hope that it will be useful, 9 later version. This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 10 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 more details. You should have received a copy of the GNU General Public 12 more details. You should have received a copy of the GNU General Public
13 License along with this program; if not, write to the 13 License along with this program; if not, write to the
14 Free Software Foundation, Inc., 59 Temple Place - 14 Free Software Foundation, Inc., 59 Temple Place -
15 Suite 330, Boston, MA 02111-1307, USA. 15 Suite 330, Boston, MA 02111-1307, USA.
16 -------------------------------------------------------------------------- 16 --------------------------------------------------------------------------
17 17
18 Description: This module will handshake with the DSP bootloader to 18 Description: This module will handshake with the DSP bootloader to
19 download the DSP runtime image. 19 download the DSP runtime image.
20 20
21---------------------------------------------------------------------------*/ 21 ---------------------------------------------------------------------------*/
22
23#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22 24
23#define __KERNEL_SYSCALLS__ 25#define __KERNEL_SYSCALLS__
24 26
@@ -99,7 +101,7 @@ struct dsp_file_hdr {
99 u32 version_data_offset; /* Offset were scrambled version data begins. */ 101 u32 version_data_offset; /* Offset were scrambled version data begins. */
100 u32 version_data_size; /* Size, in words, of scrambled version data. */ 102 u32 version_data_size; /* Size, in words, of scrambled version data. */
101 u32 nDspImages; /* Number of DSP images in file. */ 103 u32 nDspImages; /* Number of DSP images in file. */
102} __attribute__ ((packed)); 104} __packed;
103 105
104struct dsp_image_info { 106struct dsp_image_info {
105 u32 coff_date; /* Date/time when DSP Coff image was built. */ 107 u32 coff_date; /* Date/time when DSP Coff image was built. */
@@ -110,11 +112,11 @@ struct dsp_image_info {
110 u32 version; /* Embedded version # of DSP code. */ 112 u32 version; /* Embedded version # of DSP code. */
111 unsigned short checksum; /* Dsp File checksum */ 113 unsigned short checksum; /* Dsp File checksum */
112 unsigned short pad1; 114 unsigned short pad1;
113} __attribute__ ((packed)); 115} __packed;
114 116
115void card_bootload(struct net_device *dev) 117void card_bootload(struct net_device *dev)
116{ 118{
117 struct ft1000_info *info = (struct ft1000_info *) netdev_priv(dev); 119 struct ft1000_info *info = (struct ft1000_info *)netdev_priv(dev);
118 unsigned long flags; 120 unsigned long flags;
119 u32 *pdata; 121 u32 *pdata;
120 u32 size; 122 u32 size;
@@ -123,7 +125,7 @@ void card_bootload(struct net_device *dev)
123 125
124 netdev_dbg(dev, "card_bootload is called\n"); 126 netdev_dbg(dev, "card_bootload is called\n");
125 127
126 pdata = (u32 *) bootimage; 128 pdata = (u32 *)bootimage;
127 size = sizeof(bootimage); 129 size = sizeof(bootimage);
128 130
129 /* check for odd word */ 131 /* check for odd word */
@@ -146,7 +148,7 @@ void card_bootload(struct net_device *dev)
146 148
147u16 get_handshake(struct net_device *dev, u16 expected_value) 149u16 get_handshake(struct net_device *dev, u16 expected_value)
148{ 150{
149 struct ft1000_info *info = (struct ft1000_info *) netdev_priv(dev); 151 struct ft1000_info *info = (struct ft1000_info *)netdev_priv(dev);
150 u16 handshake; 152 u16 handshake;
151 u32 tempx; 153 u32 tempx;
152 int loopcnt; 154 int loopcnt;
@@ -161,12 +163,12 @@ u16 get_handshake(struct net_device *dev, u16 expected_value)
161 } else { 163 } else {
162 tempx = 164 tempx =
163 ntohl(ft1000_read_dpram_mag_32 165 ntohl(ft1000_read_dpram_mag_32
164 (dev, DWNLD_MAG_HANDSHAKE_LOC)); 166 (dev, DWNLD_MAG_HANDSHAKE_LOC));
165 handshake = (u16) tempx; 167 handshake = (u16)tempx;
166 } 168 }
167 169
168 if ((handshake == expected_value) 170 if ((handshake == expected_value)
169 || (handshake == HANDSHAKE_RESET_VALUE)) { 171 || (handshake == HANDSHAKE_RESET_VALUE)) {
170 return handshake; 172 return handshake;
171 } 173 }
172 loopcnt++; 174 loopcnt++;
@@ -180,7 +182,7 @@ u16 get_handshake(struct net_device *dev, u16 expected_value)
180 182
181void put_handshake(struct net_device *dev, u16 handshake_value) 183void put_handshake(struct net_device *dev, u16 handshake_value)
182{ 184{
183 struct ft1000_info *info = (struct ft1000_info *) netdev_priv(dev); 185 struct ft1000_info *info = (struct ft1000_info *)netdev_priv(dev);
184 u32 tempx; 186 u32 tempx;
185 187
186 if (info->AsicID == ELECTRABUZZ_ID) { 188 if (info->AsicID == ELECTRABUZZ_ID) {
@@ -188,7 +190,7 @@ void put_handshake(struct net_device *dev, u16 handshake_value)
188 DWNLD_HANDSHAKE_LOC); 190 DWNLD_HANDSHAKE_LOC);
189 ft1000_write_reg(dev, FT1000_REG_DPRAM_DATA, handshake_value); /* Handshake */ 191 ft1000_write_reg(dev, FT1000_REG_DPRAM_DATA, handshake_value); /* Handshake */
190 } else { 192 } else {
191 tempx = (u32) handshake_value; 193 tempx = (u32)handshake_value;
192 tempx = ntohl(tempx); 194 tempx = ntohl(tempx);
193 ft1000_write_dpram_mag_32(dev, DWNLD_MAG_HANDSHAKE_LOC, tempx); /* Handshake */ 195 ft1000_write_dpram_mag_32(dev, DWNLD_MAG_HANDSHAKE_LOC, tempx); /* Handshake */
194 } 196 }
@@ -196,7 +198,7 @@ void put_handshake(struct net_device *dev, u16 handshake_value)
196 198
197u16 get_request_type(struct net_device *dev) 199u16 get_request_type(struct net_device *dev)
198{ 200{
199 struct ft1000_info *info = (struct ft1000_info *) netdev_priv(dev); 201 struct ft1000_info *info = (struct ft1000_info *)netdev_priv(dev);
200 u16 request_type; 202 u16 request_type;
201 u32 tempx; 203 u32 tempx;
202 204
@@ -206,7 +208,7 @@ u16 get_request_type(struct net_device *dev)
206 } else { 208 } else {
207 tempx = ft1000_read_dpram_mag_32(dev, DWNLD_MAG_TYPE_LOC); 209 tempx = ft1000_read_dpram_mag_32(dev, DWNLD_MAG_TYPE_LOC);
208 tempx = ntohl(tempx); 210 tempx = ntohl(tempx);
209 request_type = (u16) tempx; 211 request_type = (u16)tempx;
210 } 212 }
211 213
212 return request_type; 214 return request_type;
@@ -215,7 +217,7 @@ u16 get_request_type(struct net_device *dev)
215 217
216long get_request_value(struct net_device *dev) 218long get_request_value(struct net_device *dev)
217{ 219{
218 struct ft1000_info *info = (struct ft1000_info *) netdev_priv(dev); 220 struct ft1000_info *info = (struct ft1000_info *)netdev_priv(dev);
219 long value; 221 long value;
220 u16 w_val; 222 u16 w_val;
221 223
@@ -244,7 +246,7 @@ long get_request_value(struct net_device *dev)
244 246
245void put_request_value(struct net_device *dev, long lvalue) 247void put_request_value(struct net_device *dev, long lvalue)
246{ 248{
247 struct ft1000_info *info = (struct ft1000_info *) netdev_priv(dev); 249 struct ft1000_info *info = (struct ft1000_info *)netdev_priv(dev);
248 u16 size; 250 u16 size;
249 u32 tempx; 251 u32 tempx;
250 252
@@ -271,11 +273,11 @@ void put_request_value(struct net_device *dev, long lvalue)
271 273
272u16 hdr_checksum(struct pseudo_hdr *pHdr) 274u16 hdr_checksum(struct pseudo_hdr *pHdr)
273{ 275{
274 u16 *usPtr = (u16 *) pHdr; 276 u16 *usPtr = (u16 *)pHdr;
275 u16 chksum; 277 u16 chksum;
276 278
277 chksum = ((((((usPtr[0] ^ usPtr[1]) ^ usPtr[2]) ^ usPtr[3]) ^ 279 chksum = ((((((usPtr[0] ^ usPtr[1]) ^ usPtr[2]) ^ usPtr[3]) ^
278 usPtr[4]) ^ usPtr[5]) ^ usPtr[6]); 280 usPtr[4]) ^ usPtr[5]) ^ usPtr[6]);
279 281
280 return chksum; 282 return chksum;
281} 283}
@@ -283,7 +285,7 @@ u16 hdr_checksum(struct pseudo_hdr *pHdr)
283int card_download(struct net_device *dev, const u8 *pFileStart, 285int card_download(struct net_device *dev, const u8 *pFileStart,
284 size_t FileLength) 286 size_t FileLength)
285{ 287{
286 struct ft1000_info *info = (struct ft1000_info *) netdev_priv(dev); 288 struct ft1000_info *info = (struct ft1000_info *)netdev_priv(dev);
287 int Status = SUCCESS; 289 int Status = SUCCESS;
288 u32 uiState; 290 u32 uiState;
289 u16 handshake; 291 u16 handshake;
@@ -316,13 +318,13 @@ int card_download(struct net_device *dev, const u8 *pFileStart,
316 318
317 file_version = *(long *)pFileStart; 319 file_version = *(long *)pFileStart;
318 if (file_version != 6) { 320 if (file_version != 6) {
319 printk(KERN_ERR "ft1000: unsupported firmware version %ld\n", file_version); 321 pr_err("unsupported firmware version %ld\n", file_version);
320 Status = FAILURE; 322 Status = FAILURE;
321 } 323 }
322 324
323 uiState = STATE_START_DWNLD; 325 uiState = STATE_START_DWNLD;
324 326
325 pFileHdr5 = (struct dsp_file_hdr *) pFileStart; 327 pFileHdr5 = (struct dsp_file_hdr *)pFileStart;
326 328
327 pUsFile = (u16 *) ((long)pFileStart + pFileHdr5->loader_offset); 329 pUsFile = (u16 *) ((long)pFileStart + pFileHdr5->loader_offset);
328 pUcFile = (u8 *) ((long)pFileStart + pFileHdr5->loader_offset); 330 pUcFile = (u8 *) ((long)pFileStart + pFileHdr5->loader_offset);
@@ -376,7 +378,7 @@ int card_download(struct net_device *dev, const u8 *pFileStart,
376 break; 378 break;
377 } 379 }
378 if ((word_length * 2 + (long)pUcFile) > 380 if ((word_length * 2 + (long)pUcFile) >
379 (long)pBootEnd) { 381 (long)pBootEnd) {
380 /* 382 /*
381 * Error, beyond boot code range. 383 * Error, beyond boot code range.
382 */ 384 */
@@ -390,8 +392,8 @@ int card_download(struct net_device *dev, const u8 *pFileStart,
390 * Position ASIC DPRAM auto-increment pointer. 392 * Position ASIC DPRAM auto-increment pointer.
391 */ 393 */
392 outw(DWNLD_MAG_PS_HDR_LOC, 394 outw(DWNLD_MAG_PS_HDR_LOC,
393 dev->base_addr + 395 dev->base_addr +
394 FT1000_REG_DPRAM_ADDR); 396 FT1000_REG_DPRAM_ADDR);
395 if (word_length & 0x01) 397 if (word_length & 0x01)
396 word_length++; 398 word_length++;
397 word_length = word_length / 2; 399 word_length = word_length / 2;
@@ -402,12 +404,12 @@ int card_download(struct net_device *dev, const u8 *pFileStart,
402 (*pUsFile++ << 16); 404 (*pUsFile++ << 16);
403 pUcFile += 4; 405 pUcFile += 4;
404 outl(templong, 406 outl(templong,
405 dev->base_addr + 407 dev->base_addr +
406 FT1000_REG_MAG_DPDATAL); 408 FT1000_REG_MAG_DPDATAL);
407 } 409 }
408 spin_unlock_irqrestore(&info-> 410 spin_unlock_irqrestore(&info->
409 dpram_lock, 411 dpram_lock,
410 flags); 412 flags);
411 break; 413 break;
412 default: 414 default:
413 Status = FAILURE; 415 Status = FAILURE;
@@ -430,7 +432,7 @@ int card_download(struct net_device *dev, const u8 *pFileStart,
430 switch (request) { 432 switch (request) {
431 case REQUEST_FILE_CHECKSUM: 433 case REQUEST_FILE_CHECKSUM:
432 netdev_dbg(dev, 434 netdev_dbg(dev,
433 "ft1000_dnld: REQUEST_FOR_CHECKSUM\n"); 435 "ft1000_dnld: REQUEST_FOR_CHECKSUM\n");
434 put_request_value(dev, image_chksum); 436 put_request_value(dev, image_chksum);
435 break; 437 break;
436 case REQUEST_RUN_ADDRESS: 438 case REQUEST_RUN_ADDRESS:
@@ -468,7 +470,7 @@ int card_download(struct net_device *dev, const u8 *pFileStart,
468 break; 470 break;
469 } 471 }
470 if ((word_length * 2 + (long)pUcFile) > 472 if ((word_length * 2 + (long)pUcFile) >
471 (long)pCodeEnd) { 473 (long)pCodeEnd) {
472 /* 474 /*
473 * Error, beyond boot code range. 475 * Error, beyond boot code range.
474 */ 476 */
@@ -479,8 +481,8 @@ int card_download(struct net_device *dev, const u8 *pFileStart,
479 * Position ASIC DPRAM auto-increment pointer. 481 * Position ASIC DPRAM auto-increment pointer.
480 */ 482 */
481 outw(DWNLD_MAG_PS_HDR_LOC, 483 outw(DWNLD_MAG_PS_HDR_LOC,
482 dev->base_addr + 484 dev->base_addr +
483 FT1000_REG_DPRAM_ADDR); 485 FT1000_REG_DPRAM_ADDR);
484 if (word_length & 0x01) 486 if (word_length & 0x01)
485 word_length++; 487 word_length++;
486 word_length = word_length / 2; 488 word_length = word_length / 2;
@@ -491,8 +493,8 @@ int card_download(struct net_device *dev, const u8 *pFileStart,
491 (*pUsFile++ << 16); 493 (*pUsFile++ << 16);
492 pUcFile += 4; 494 pUcFile += 4;
493 outl(templong, 495 outl(templong,
494 dev->base_addr + 496 dev->base_addr +
495 FT1000_REG_MAG_DPDATAL); 497 FT1000_REG_MAG_DPDATAL);
496 } 498 }
497 break; 499 break;
498 500
@@ -502,9 +504,9 @@ int card_download(struct net_device *dev, const u8 *pFileStart,
502 (long)(info->DSPInfoBlklen + 1) / 2; 504 (long)(info->DSPInfoBlklen + 1) / 2;
503 put_request_value(dev, word_length); 505 put_request_value(dev, word_length);
504 pMailBoxData = 506 pMailBoxData =
505 (struct drv_msg *) &info->DSPInfoBlk[0]; 507 (struct drv_msg *)&info->DSPInfoBlk[0];
506 pUsData = 508 pUsData =
507 (u16 *) &pMailBoxData->data[0]; 509 (u16 *)&pMailBoxData->data[0];
508 /* Provide mutual exclusive access while reading ASIC registers. */ 510 /* Provide mutual exclusive access while reading ASIC registers. */
509 spin_lock_irqsave(&info->dpram_lock, 511 spin_lock_irqsave(&info->dpram_lock,
510 flags); 512 flags);
@@ -528,8 +530,8 @@ int card_download(struct net_device *dev, const u8 *pFileStart,
528 * Position ASIC DPRAM auto-increment pointer. 530 * Position ASIC DPRAM auto-increment pointer.
529 */ 531 */
530 outw(DWNLD_MAG_PS_HDR_LOC, 532 outw(DWNLD_MAG_PS_HDR_LOC,
531 dev->base_addr + 533 dev->base_addr +
532 FT1000_REG_DPRAM_ADDR); 534 FT1000_REG_DPRAM_ADDR);
533 if (word_length & 0x01) 535 if (word_length & 0x01)
534 word_length++; 536 word_length++;
535 537
@@ -540,13 +542,13 @@ int card_download(struct net_device *dev, const u8 *pFileStart,
540 templong |= 542 templong |=
541 (*pUsData++ << 16); 543 (*pUsData++ << 16);
542 outl(templong, 544 outl(templong,
543 dev->base_addr + 545 dev->base_addr +
544 FT1000_REG_MAG_DPDATAL); 546 FT1000_REG_MAG_DPDATAL);
545 } 547 }
546 } 548 }
547 spin_unlock_irqrestore(&info-> 549 spin_unlock_irqrestore(&info->
548 dpram_lock, 550 dpram_lock,
549 flags); 551 flags);
550 break; 552 break;
551 553
552 case REQUEST_VERSION_INFO: 554 case REQUEST_VERSION_INFO:
@@ -555,8 +557,8 @@ int card_download(struct net_device *dev, const u8 *pFileStart,
555 put_request_value(dev, word_length); 557 put_request_value(dev, word_length);
556 pUsFile = 558 pUsFile =
557 (u16 *) ((long)pFileStart + 559 (u16 *) ((long)pFileStart +
558 pFileHdr5-> 560 pFileHdr5->
559 version_data_offset); 561 version_data_offset);
560 /* Provide mutual exclusive access while reading ASIC registers. */ 562 /* Provide mutual exclusive access while reading ASIC registers. */
561 spin_lock_irqsave(&info->dpram_lock, 563 spin_lock_irqsave(&info->dpram_lock,
562 flags); 564 flags);
@@ -564,8 +566,8 @@ int card_download(struct net_device *dev, const u8 *pFileStart,
564 * Position ASIC DPRAM auto-increment pointer. 566 * Position ASIC DPRAM auto-increment pointer.
565 */ 567 */
566 outw(DWNLD_MAG_PS_HDR_LOC, 568 outw(DWNLD_MAG_PS_HDR_LOC,
567 dev->base_addr + 569 dev->base_addr +
568 FT1000_REG_DPRAM_ADDR); 570 FT1000_REG_DPRAM_ADDR);
569 if (word_length & 0x01) 571 if (word_length & 0x01)
570 word_length++; 572 word_length++;
571 word_length = word_length / 2; 573 word_length = word_length / 2;
@@ -578,12 +580,12 @@ int card_download(struct net_device *dev, const u8 *pFileStart,
578 templong |= 580 templong |=
579 (temp << 16); 581 (temp << 16);
580 outl(templong, 582 outl(templong,
581 dev->base_addr + 583 dev->base_addr +
582 FT1000_REG_MAG_DPDATAL); 584 FT1000_REG_MAG_DPDATAL);
583 } 585 }
584 spin_unlock_irqrestore(&info-> 586 spin_unlock_irqrestore(&info->
585 dpram_lock, 587 dpram_lock,
586 flags); 588 flags);
587 break; 589 break;
588 590
589 case REQUEST_CODE_BY_VERSION: 591 case REQUEST_CODE_BY_VERSION:
@@ -592,14 +594,14 @@ int card_download(struct net_device *dev, const u8 *pFileStart,
592 get_request_value(dev); 594 get_request_value(dev);
593 pDspImageInfoV6 = 595 pDspImageInfoV6 =
594 (struct dsp_image_info *) ((long) 596 (struct dsp_image_info *) ((long)
595 pFileStart 597 pFileStart
596 + 598 +
597 sizeof 599 sizeof
598 (struct dsp_file_hdr)); 600 (struct dsp_file_hdr));
599 for (imageN = 0; 601 for (imageN = 0;
600 imageN < 602 imageN <
601 pFileHdr5->nDspImages; 603 pFileHdr5->nDspImages;
602 imageN++) { 604 imageN++) {
603 temp = (u16) 605 temp = (u16)
604 (pDspImageInfoV6-> 606 (pDspImageInfoV6->
605 version); 607 version);
@@ -610,30 +612,30 @@ int card_download(struct net_device *dev, const u8 *pFileStart,
610 templong |= 612 templong |=
611 (temp << 16); 613 (temp << 16);
612 if (templong == 614 if (templong ==
613 requested_version) { 615 requested_version) {
614 bGoodVersion = 616 bGoodVersion =
615 true; 617 true;
616 pUsFile = 618 pUsFile =
617 (u16 619 (u16
618 *) ((long) 620 *) ((long)
619 pFileStart 621 pFileStart
620 + 622 +
621 pDspImageInfoV6-> 623 pDspImageInfoV6->
622 begin_offset); 624 begin_offset);
623 pUcFile = 625 pUcFile =
624 (u8 626 (u8
625 *) ((long) 627 *) ((long)
626 pFileStart 628 pFileStart
627 + 629 +
628 pDspImageInfoV6-> 630 pDspImageInfoV6->
629 begin_offset); 631 begin_offset);
630 pCodeEnd = 632 pCodeEnd =
631 (u8 633 (u8
632 *) ((long) 634 *) ((long)
633 pFileStart 635 pFileStart
634 + 636 +
635 pDspImageInfoV6-> 637 pDspImageInfoV6->
636 end_offset); 638 end_offset);
637 run_address = 639 run_address =
638 pDspImageInfoV6-> 640 pDspImageInfoV6->
639 run_address; 641 run_address;
@@ -645,10 +647,10 @@ int card_download(struct net_device *dev, const u8 *pFileStart,
645 pDspImageInfoV6-> 647 pDspImageInfoV6->
646 checksum; 648 checksum;
647 netdev_dbg(dev, 649 netdev_dbg(dev,
648 "ft1000_dnld: image_chksum = 0x%8x\n", 650 "ft1000_dnld: image_chksum = 0x%8x\n",
649 (unsigned 651 (unsigned
650 int) 652 int)
651 image_chksum); 653 image_chksum);
652 break; 654 break;
653 } 655 }
654 pDspImageInfoV6++; 656 pDspImageInfoV6++;
@@ -674,25 +676,25 @@ int card_download(struct net_device *dev, const u8 *pFileStart,
674 break; 676 break;
675 677
676 case STATE_DONE_DWNLD: 678 case STATE_DONE_DWNLD:
677 if (((unsigned long) (pUcFile) - (unsigned long) pFileStart) >= 679 if (((unsigned long)(pUcFile) - (unsigned long) pFileStart) >=
678 (unsigned long) FileLength) { 680 (unsigned long)FileLength) {
679 uiState = STATE_DONE_FILE; 681 uiState = STATE_DONE_FILE;
680 break; 682 break;
681 } 683 }
682 684
683 pHdr = (struct pseudo_hdr *) pUsFile; 685 pHdr = (struct pseudo_hdr *)pUsFile;
684 686
685 if (pHdr->portdest == 0x80 /* DspOAM */ 687 if (pHdr->portdest == 0x80 /* DspOAM */
686 && (pHdr->portsrc == 0x00 /* Driver */ 688 && (pHdr->portsrc == 0x00 /* Driver */
687 || pHdr->portsrc == 0x10 /* FMM */)) { 689 || pHdr->portsrc == 0x10 /* FMM */)) {
688 uiState = STATE_SECTION_PROV; 690 uiState = STATE_SECTION_PROV;
689 } else { 691 } else {
690 netdev_dbg(dev, 692 netdev_dbg(dev,
691 "FT1000:download:Download error: Bad Port IDs in Pseudo Record\n"); 693 "Download error: Bad Port IDs in Pseudo Record\n");
692 netdev_dbg(dev, "\t Port Source = 0x%2.2x\n", 694 netdev_dbg(dev, "\t Port Source = 0x%2.2x\n",
693 pHdr->portsrc); 695 pHdr->portsrc);
694 netdev_dbg(dev, "\t Port Destination = 0x%2.2x\n", 696 netdev_dbg(dev, "\t Port Destination = 0x%2.2x\n",
695 pHdr->portdest); 697 pHdr->portdest);
696 Status = FAILURE; 698 Status = FAILURE;
697 } 699 }
698 700
@@ -700,7 +702,7 @@ int card_download(struct net_device *dev, const u8 *pFileStart,
700 702
701 case STATE_SECTION_PROV: 703 case STATE_SECTION_PROV:
702 704
703 pHdr = (struct pseudo_hdr *) pUcFile; 705 pHdr = (struct pseudo_hdr *)pUcFile;
704 706
705 if (pHdr->checksum == hdr_checksum(pHdr)) { 707 if (pHdr->checksum == hdr_checksum(pHdr)) {
706 if (pHdr->portdest != 0x80 /* Dsp OAM */) { 708 if (pHdr->portdest != 0x80 /* Dsp OAM */) {
@@ -715,8 +717,8 @@ int card_download(struct net_device *dev, const u8 *pFileStart,
715 GFP_ATOMIC); 717 GFP_ATOMIC);
716 if (pbuffer) { 718 if (pbuffer) {
717 memcpy(pbuffer, (void *)pUcFile, 719 memcpy(pbuffer, (void *)pUcFile,
718 (u32) (usHdrLength + 720 (u32) (usHdrLength +
719 sizeof(struct pseudo_hdr))); 721 sizeof(struct pseudo_hdr)));
720 /* link provisioning data */ 722 /* link provisioning data */
721 pprov_record = 723 pprov_record =
722 kmalloc(sizeof(struct prov_record), 724 kmalloc(sizeof(struct prov_record),
@@ -725,15 +727,15 @@ int card_download(struct net_device *dev, const u8 *pFileStart,
725 pprov_record->pprov_data = 727 pprov_record->pprov_data =
726 pbuffer; 728 pbuffer;
727 list_add_tail(&pprov_record-> 729 list_add_tail(&pprov_record->
728 list, 730 list,
729 &info->prov_list); 731 &info->prov_list);
730 /* Move to next entry if available */ 732 /* Move to next entry if available */
731 pUcFile = 733 pUcFile =
732 (u8 *) ((unsigned long) pUcFile + 734 (u8 *)((unsigned long) pUcFile +
733 (unsigned long) ((usHdrLength + 1) & 0xFFFFFFFE) + sizeof(struct pseudo_hdr)); 735 (unsigned long) ((usHdrLength + 1) & 0xFFFFFFFE) + sizeof(struct pseudo_hdr));
734 if ((unsigned long) (pUcFile) - 736 if ((unsigned long) (pUcFile) -
735 (unsigned long) (pFileStart) >= 737 (unsigned long) (pFileStart) >=
736 (unsigned long) FileLength) { 738 (unsigned long)FileLength) {
737 uiState = 739 uiState =
738 STATE_DONE_FILE; 740 STATE_DONE_FILE;
739 } 741 }
diff --git a/drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c b/drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c
index 44575c78cf0c..d5475b7270a8 100644
--- a/drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c
+++ b/drivers/staging/ft1000/ft1000-pcmcia/ft1000_hw.c
@@ -1,22 +1,24 @@
1/*--------------------------------------------------------------------------- 1/*---------------------------------------------------------------------------
2 FT1000 driver for Flarion Flash OFDM NIC Device 2 FT1000 driver for Flarion Flash OFDM NIC Device
3 3
4 Copyright (C) 2002 Flarion Technologies, All rights reserved. 4 Copyright (C) 2002 Flarion Technologies, All rights reserved.
5 Copyright (C) 2006 Patrik Ostrihon, All rights reserved. 5 Copyright (C) 2006 Patrik Ostrihon, All rights reserved.
6 Copyright (C) 2006 ProWeb Consulting, a.s, All rights reserved. 6 Copyright (C) 2006 ProWeb Consulting, a.s, All rights reserved.
7 7
8 This program is free software; you can redistribute it and/or modify it 8 This program is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the Free 9 under the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2 of the License, or (at your option) any 10 Software Foundation; either version 2 of the License, or (at your option) any
11 later version. This program is distributed in the hope that it will be useful, 11 later version. This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 12 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details. You should have received a copy of the GNU General Public 14 more details. You should have received a copy of the GNU General Public
15 License along with this program; if not, write to the 15 License along with this program; if not, write to the
16 Free Software Foundation, Inc., 59 Temple Place - 16 Free Software Foundation, Inc., 59 Temple Place -
17 Suite 330, Boston, MA 02111-1307, USA. 17 Suite 330, Boston, MA 02111-1307, USA.
18 -------------------------------------------------------------------------*/ 18 -------------------------------------------------------------------------*/
19 19
20#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21
20#include <linux/kernel.h> 22#include <linux/kernel.h>
21#include <linux/module.h> 23#include <linux/module.h>
22#include <linux/sched.h> 24#include <linux/sched.h>
@@ -44,12 +46,6 @@
44#include <pcmcia/cisreg.h> 46#include <pcmcia/cisreg.h>
45#include <pcmcia/ds.h> 47#include <pcmcia/ds.h>
46 48
47#ifdef FT_DEBUG
48#define DEBUG(n, args...) printk(KERN_DEBUG args);
49#else
50#define DEBUG(n, args...)
51#endif
52
53#include <linux/delay.h> 49#include <linux/delay.h>
54#include "ft1000.h" 50#include "ft1000.h"
55 51
@@ -57,7 +53,7 @@ static const struct firmware *fw_entry;
57 53
58static void ft1000_hbchk(u_long data); 54static void ft1000_hbchk(u_long data);
59static struct timer_list poll_timer = { 55static struct timer_list poll_timer = {
60 .function = ft1000_hbchk 56 .function = ft1000_hbchk
61}; 57};
62 58
63static u16 cmdbuffer[1024]; 59static u16 cmdbuffer[1024];
@@ -72,7 +68,7 @@ static void ft1000_disable_interrupts(struct net_device *dev);
72/* new kernel */ 68/* new kernel */
73MODULE_AUTHOR(""); 69MODULE_AUTHOR("");
74MODULE_DESCRIPTION 70MODULE_DESCRIPTION
75 ("Support for Flarion Flash OFDM NIC Device. Support for PCMCIA when used with ft1000_cs."); 71("Support for Flarion Flash OFDM NIC Device. Support for PCMCIA when used with ft1000_cs.");
76MODULE_LICENSE("GPL"); 72MODULE_LICENSE("GPL");
77MODULE_SUPPORTED_DEVICE("FT1000"); 73MODULE_SUPPORTED_DEVICE("FT1000");
78 74
@@ -80,15 +76,15 @@ MODULE_SUPPORTED_DEVICE("FT1000");
80 76
81/*--------------------------------------------------------------------------- 77/*---------------------------------------------------------------------------
82 78
83 Function: ft1000_read_fifo_len 79 Function: ft1000_read_fifo_len
84 Description: This function will read the ASIC Uplink FIFO status register 80 Description: This function will read the ASIC Uplink FIFO status register
85 which will return the number of bytes remaining in the Uplink FIFO. 81 which will return the number of bytes remaining in the Uplink FIFO.
86 Sixteen bytes are subtracted to make sure that the ASIC does not 82 Sixteen bytes are subtracted to make sure that the ASIC does not
87 reach its threshold. 83 reach its threshold.
88 Input: 84 Input:
89 dev - network device structure 85 dev - network device structure
90 Output: 86 Output:
91 value - number of bytes available in the ASIC Uplink FIFO. 87 value - number of bytes available in the ASIC Uplink FIFO.
92 88
93 -------------------------------------------------------------------------*/ 89 -------------------------------------------------------------------------*/
94static inline u16 ft1000_read_fifo_len(struct net_device *dev) 90static inline u16 ft1000_read_fifo_len(struct net_device *dev)
@@ -103,14 +99,14 @@ static inline u16 ft1000_read_fifo_len(struct net_device *dev)
103 99
104/*--------------------------------------------------------------------------- 100/*---------------------------------------------------------------------------
105 101
106 Function: ft1000_read_dpram 102 Function: ft1000_read_dpram
107 Description: This function will read the specific area of dpram 103 Description: This function will read the specific area of dpram
108 (Electrabuzz ASIC only) 104 (Electrabuzz ASIC only)
109 Input: 105 Input:
110 dev - device structure 106 dev - device structure
111 offset - index of dpram 107 offset - index of dpram
112 Output: 108 Output:
113 value - value of dpram 109 value - value of dpram
114 110
115 -------------------------------------------------------------------------*/ 111 -------------------------------------------------------------------------*/
116u16 ft1000_read_dpram(struct net_device *dev, int offset) 112u16 ft1000_read_dpram(struct net_device *dev, int offset)
@@ -130,19 +126,19 @@ u16 ft1000_read_dpram(struct net_device *dev, int offset)
130 126
131/*--------------------------------------------------------------------------- 127/*---------------------------------------------------------------------------
132 128
133 Function: ft1000_write_dpram 129 Function: ft1000_write_dpram
134 Description: This function will write to a specific area of dpram 130 Description: This function will write to a specific area of dpram
135 (Electrabuzz ASIC only) 131 (Electrabuzz ASIC only)
136 Input: 132 Input:
137 dev - device structure 133 dev - device structure
138 offset - index of dpram 134 offset - index of dpram
139 value - value to write 135 value - value to write
140 Output: 136 Output:
141 none. 137 none.
142 138
143 -------------------------------------------------------------------------*/ 139 -------------------------------------------------------------------------*/
144static inline void ft1000_write_dpram(struct net_device *dev, 140static inline void ft1000_write_dpram(struct net_device *dev,
145 int offset, u16 value) 141 int offset, u16 value)
146{ 142{
147 struct ft1000_info *info = netdev_priv(dev); 143 struct ft1000_info *info = netdev_priv(dev);
148 unsigned long flags; 144 unsigned long flags;
@@ -156,14 +152,14 @@ static inline void ft1000_write_dpram(struct net_device *dev,
156 152
157/*--------------------------------------------------------------------------- 153/*---------------------------------------------------------------------------
158 154
159 Function: ft1000_read_dpram_mag_16 155 Function: ft1000_read_dpram_mag_16
160 Description: This function will read the specific area of dpram 156 Description: This function will read the specific area of dpram
161 (Magnemite ASIC only) 157 (Magnemite ASIC only)
162 Input: 158 Input:
163 dev - device structure 159 dev - device structure
164 offset - index of dpram 160 offset - index of dpram
165 Output: 161 Output:
166 value - value of dpram 162 value - value of dpram
167 163
168 -------------------------------------------------------------------------*/ 164 -------------------------------------------------------------------------*/
169u16 ft1000_read_dpram_mag_16(struct net_device *dev, int offset, int Index) 165u16 ft1000_read_dpram_mag_16(struct net_device *dev, int offset, int Index)
@@ -188,19 +184,19 @@ u16 ft1000_read_dpram_mag_16(struct net_device *dev, int offset, int Index)
188 184
189/*--------------------------------------------------------------------------- 185/*---------------------------------------------------------------------------
190 186
191 Function: ft1000_write_dpram_mag_16 187 Function: ft1000_write_dpram_mag_16
192 Description: This function will write to a specific area of dpram 188 Description: This function will write to a specific area of dpram
193 (Magnemite ASIC only) 189 (Magnemite ASIC only)
194 Input: 190 Input:
195 dev - device structure 191 dev - device structure
196 offset - index of dpram 192 offset - index of dpram
197 value - value to write 193 value - value to write
198 Output: 194 Output:
199 none. 195 none.
200 196
201 -------------------------------------------------------------------------*/ 197 -------------------------------------------------------------------------*/
202static inline void ft1000_write_dpram_mag_16(struct net_device *dev, 198static inline void ft1000_write_dpram_mag_16(struct net_device *dev,
203 int offset, u16 value, int Index) 199 int offset, u16 value, int Index)
204{ 200{
205 struct ft1000_info *info = netdev_priv(dev); 201 struct ft1000_info *info = netdev_priv(dev);
206 unsigned long flags; 202 unsigned long flags;
@@ -218,14 +214,14 @@ static inline void ft1000_write_dpram_mag_16(struct net_device *dev,
218 214
219/*--------------------------------------------------------------------------- 215/*---------------------------------------------------------------------------
220 216
221 Function: ft1000_read_dpram_mag_32 217 Function: ft1000_read_dpram_mag_32
222 Description: This function will read the specific area of dpram 218 Description: This function will read the specific area of dpram
223 (Magnemite ASIC only) 219 (Magnemite ASIC only)
224 Input: 220 Input:
225 dev - device structure 221 dev - device structure
226 offset - index of dpram 222 offset - index of dpram
227 Output: 223 Output:
228 value - value of dpram 224 value - value of dpram
229 225
230 -------------------------------------------------------------------------*/ 226 -------------------------------------------------------------------------*/
231u32 ft1000_read_dpram_mag_32(struct net_device *dev, int offset) 227u32 ft1000_read_dpram_mag_32(struct net_device *dev, int offset)
@@ -245,15 +241,15 @@ u32 ft1000_read_dpram_mag_32(struct net_device *dev, int offset)
245 241
246/*--------------------------------------------------------------------------- 242/*---------------------------------------------------------------------------
247 243
248 Function: ft1000_write_dpram_mag_32 244 Function: ft1000_write_dpram_mag_32
249 Description: This function will write to a specific area of dpram 245 Description: This function will write to a specific area of dpram
250 (Magnemite ASIC only) 246 (Magnemite ASIC only)
251 Input: 247 Input:
252 dev - device structure 248 dev - device structure
253 offset - index of dpram 249 offset - index of dpram
254 value - value to write 250 value - value to write
255 Output: 251 Output:
256 none. 252 none.
257 253
258 -------------------------------------------------------------------------*/ 254 -------------------------------------------------------------------------*/
259void ft1000_write_dpram_mag_32(struct net_device *dev, int offset, u32 value) 255void ft1000_write_dpram_mag_32(struct net_device *dev, int offset, u32 value)
@@ -270,57 +266,51 @@ void ft1000_write_dpram_mag_32(struct net_device *dev, int offset, u32 value)
270 266
271/*--------------------------------------------------------------------------- 267/*---------------------------------------------------------------------------
272 268
273 Function: ft1000_enable_interrupts 269 Function: ft1000_enable_interrupts
274 Description: This function will enable interrupts base on the current interrupt mask. 270 Description: This function will enable interrupts base on the current interrupt mask.
275 Input: 271 Input:
276 dev - device structure 272 dev - device structure
277 Output: 273 Output:
278 None. 274 None.
279 275
280 -------------------------------------------------------------------------*/ 276 -------------------------------------------------------------------------*/
281static void ft1000_enable_interrupts(struct net_device *dev) 277static void ft1000_enable_interrupts(struct net_device *dev)
282{ 278{
283 u16 tempword; 279 u16 tempword;
284 280
285 DEBUG(1, "ft1000_hw:ft1000_enable_interrupts()\n");
286 ft1000_write_reg(dev, FT1000_REG_SUP_IMASK, ISR_DEFAULT_MASK); 281 ft1000_write_reg(dev, FT1000_REG_SUP_IMASK, ISR_DEFAULT_MASK);
287 tempword = ft1000_read_reg(dev, FT1000_REG_SUP_IMASK); 282 tempword = ft1000_read_reg(dev, FT1000_REG_SUP_IMASK);
288 DEBUG(1, 283 pr_debug("current interrupt enable mask = 0x%x\n", tempword);
289 "ft1000_hw:ft1000_enable_interrupts:current interrupt enable mask = 0x%x\n",
290 tempword);
291} 284}
292 285
293/*--------------------------------------------------------------------------- 286/*---------------------------------------------------------------------------
294 287
295 Function: ft1000_disable_interrupts 288 Function: ft1000_disable_interrupts
296 Description: This function will disable all interrupts. 289 Description: This function will disable all interrupts.
297 Input: 290 Input:
298 dev - device structure 291 dev - device structure
299 Output: 292 Output:
300 None. 293 None.
301 294
302 -------------------------------------------------------------------------*/ 295 -------------------------------------------------------------------------*/
303static void ft1000_disable_interrupts(struct net_device *dev) 296static void ft1000_disable_interrupts(struct net_device *dev)
304{ 297{
305 u16 tempword; 298 u16 tempword;
306 299
307 DEBUG(1, "ft1000_hw: ft1000_disable_interrupts()\n");
308 ft1000_write_reg(dev, FT1000_REG_SUP_IMASK, ISR_MASK_ALL); 300 ft1000_write_reg(dev, FT1000_REG_SUP_IMASK, ISR_MASK_ALL);
309 tempword = ft1000_read_reg(dev, FT1000_REG_SUP_IMASK); 301 tempword = ft1000_read_reg(dev, FT1000_REG_SUP_IMASK);
310 DEBUG(1, 302 pr_debug("current interrupt enable mask = 0x%x\n", tempword);
311 "ft1000_hw:ft1000_disable_interrupts:current interrupt enable mask = 0x%x\n",
312 tempword);
313} 303}
314 304
315/*--------------------------------------------------------------------------- 305/*---------------------------------------------------------------------------
316 306
317 Function: ft1000_reset_asic 307 Function: ft1000_reset_asic
318 Description: This function will call the Card Service function to reset the 308 Description: This function will call the Card Service function to reset the
319 ASIC. 309 ASIC.
320 Input: 310 Input:
321 dev - device structure 311 dev - device structure
322 Output: 312 Output:
323 none 313 none
324 314
325 -------------------------------------------------------------------------*/ 315 -------------------------------------------------------------------------*/
326static void ft1000_reset_asic(struct net_device *dev) 316static void ft1000_reset_asic(struct net_device *dev)
@@ -329,8 +319,6 @@ static void ft1000_reset_asic(struct net_device *dev)
329 struct ft1000_pcmcia *pcmcia = info->priv; 319 struct ft1000_pcmcia *pcmcia = info->priv;
330 u16 tempword; 320 u16 tempword;
331 321
332 DEBUG(1, "ft1000_hw:ft1000_reset_asic called\n");
333
334 (*info->ft1000_reset) (pcmcia->link); 322 (*info->ft1000_reset) (pcmcia->link);
335 323
336 /* 324 /*
@@ -351,22 +339,22 @@ static void ft1000_reset_asic(struct net_device *dev)
351 } 339 }
352 /* clear interrupts */ 340 /* clear interrupts */
353 tempword = ft1000_read_reg(dev, FT1000_REG_SUP_ISR); 341 tempword = ft1000_read_reg(dev, FT1000_REG_SUP_ISR);
354 DEBUG(1, "ft1000_hw: interrupt status register = 0x%x\n", tempword); 342 pr_debug("interrupt status register = 0x%x\n", tempword);
355 ft1000_write_reg(dev, FT1000_REG_SUP_ISR, tempword); 343 ft1000_write_reg(dev, FT1000_REG_SUP_ISR, tempword);
356 tempword = ft1000_read_reg(dev, FT1000_REG_SUP_ISR); 344 tempword = ft1000_read_reg(dev, FT1000_REG_SUP_ISR);
357 DEBUG(1, "ft1000_hw: interrupt status register = 0x%x\n", tempword); 345 pr_debug("interrupt status register = 0x%x\n", tempword);
358 346
359} 347}
360 348
361/*--------------------------------------------------------------------------- 349/*---------------------------------------------------------------------------
362 350
363 Function: ft1000_reset_card 351 Function: ft1000_reset_card
364 Description: This function will reset the card 352 Description: This function will reset the card
365 Input: 353 Input:
366 dev - device structure 354 dev - device structure
367 Output: 355 Output:
368 status - false (card reset fail) 356 status - false (card reset fail)
369 true (card reset successful) 357 true (card reset successful)
370 358
371 -------------------------------------------------------------------------*/ 359 -------------------------------------------------------------------------*/
372static int ft1000_reset_card(struct net_device *dev) 360static int ft1000_reset_card(struct net_device *dev)
@@ -377,8 +365,6 @@ static int ft1000_reset_card(struct net_device *dev)
377 unsigned long flags; 365 unsigned long flags;
378 struct prov_record *ptr; 366 struct prov_record *ptr;
379 367
380 DEBUG(1, "ft1000_hw:ft1000_reset_card called.....\n");
381
382 info->CardReady = 0; 368 info->CardReady = 0;
383 info->ProgConStat = 0; 369 info->ProgConStat = 0;
384 info->squeseqnum = 0; 370 info->squeseqnum = 0;
@@ -388,8 +374,7 @@ static int ft1000_reset_card(struct net_device *dev)
388 374
389 /* Make sure we free any memory reserve for provisioning */ 375 /* Make sure we free any memory reserve for provisioning */
390 while (list_empty(&info->prov_list) == 0) { 376 while (list_empty(&info->prov_list) == 0) {
391 DEBUG(0, 377 pr_debug("deleting provisioning record\n");
392 "ft1000_hw:ft1000_reset_card:deleting provisioning record\n");
393 ptr = list_entry(info->prov_list.next, struct prov_record, list); 378 ptr = list_entry(info->prov_list.next, struct prov_record, list);
394 list_del(&ptr->list); 379 list_del(&ptr->list);
395 kfree(ptr->pprov_data); 380 kfree(ptr->pprov_data);
@@ -397,11 +382,10 @@ static int ft1000_reset_card(struct net_device *dev)
397 } 382 }
398 383
399 if (info->AsicID == ELECTRABUZZ_ID) { 384 if (info->AsicID == ELECTRABUZZ_ID) {
400 DEBUG(1, "ft1000_hw:ft1000_reset_card:resetting DSP\n"); 385 pr_debug("resetting DSP\n");
401 ft1000_write_reg(dev, FT1000_REG_RESET, DSP_RESET_BIT); 386 ft1000_write_reg(dev, FT1000_REG_RESET, DSP_RESET_BIT);
402 } else { 387 } else {
403 DEBUG(1, 388 pr_debug("resetting ASIC and DSP\n");
404 "ft1000_hw:ft1000_reset_card:resetting ASIC and DSP\n");
405 ft1000_write_reg(dev, FT1000_REG_RESET, 389 ft1000_write_reg(dev, FT1000_REG_RESET,
406 (DSP_RESET_BIT | ASIC_RESET_BIT)); 390 (DSP_RESET_BIT | ASIC_RESET_BIT));
407 } 391 }
@@ -428,17 +412,16 @@ static int ft1000_reset_card(struct net_device *dev)
428 spin_unlock_irqrestore(&info->dpram_lock, flags); 412 spin_unlock_irqrestore(&info->dpram_lock, flags);
429 } 413 }
430 414
431 DEBUG(1, "ft1000_hw:ft1000_reset_card:resetting ASIC\n"); 415 pr_debug("resetting ASIC\n");
432 mdelay(10); 416 mdelay(10);
433 /* reset ASIC */ 417 /* reset ASIC */
434 ft1000_reset_asic(dev); 418 ft1000_reset_asic(dev);
435 419
436 DEBUG(1, "ft1000_hw:ft1000_reset_card:downloading dsp image\n"); 420 pr_debug("downloading dsp image\n");
437 421
438 if (info->AsicID == MAGNEMITE_ID) { 422 if (info->AsicID == MAGNEMITE_ID) {
439 /* Put dsp in reset and take ASIC out of reset */ 423 /* Put dsp in reset and take ASIC out of reset */
440 DEBUG(0, 424 pr_debug("Put DSP in reset and take ASIC out of reset\n");
441 "ft1000_hw:ft1000_reset_card:Put DSP in reset and take ASIC out of reset\n");
442 ft1000_write_reg(dev, FT1000_REG_RESET, DSP_RESET_BIT); 425 ft1000_write_reg(dev, FT1000_REG_RESET, DSP_RESET_BIT);
443 426
444 /* Setting MAGNEMITE ASIC to big endian mode */ 427 /* Setting MAGNEMITE ASIC to big endian mode */
@@ -450,7 +433,7 @@ static int ft1000_reset_card(struct net_device *dev)
450 ft1000_write_reg(dev, FT1000_REG_RESET, 0); 433 ft1000_write_reg(dev, FT1000_REG_RESET, 0);
451 /* FLARION_DSP_ACTIVE; */ 434 /* FLARION_DSP_ACTIVE; */
452 mdelay(10); 435 mdelay(10);
453 DEBUG(0, "ft1000_hw:ft1000_reset_card:Take DSP out of reset\n"); 436 pr_debug("Take DSP out of reset\n");
454 437
455 /* Wait for 0xfefe indicating dsp ready before starting download */ 438 /* Wait for 0xfefe indicating dsp ready before starting download */
456 for (i = 0; i < 50; i++) { 439 for (i = 0; i < 50; i++) {
@@ -464,8 +447,7 @@ static int ft1000_reset_card(struct net_device *dev)
464 } 447 }
465 448
466 if (i == 50) { 449 if (i == 50) {
467 DEBUG(0, 450 pr_debug("No FEFE detected from DSP\n");
468 "ft1000_hw:ft1000_reset_card:No FEFE detected from DSP\n");
469 return false; 451 return false;
470 } 452 }
471 453
@@ -476,10 +458,10 @@ static int ft1000_reset_card(struct net_device *dev)
476 } 458 }
477 459
478 if (card_download(dev, fw_entry->data, fw_entry->size)) { 460 if (card_download(dev, fw_entry->data, fw_entry->size)) {
479 DEBUG(1, "card download unsuccessful\n"); 461 pr_debug("card download unsuccessful\n");
480 return false; 462 return false;
481 } else { 463 } else {
482 DEBUG(1, "card download successful\n"); 464 pr_debug("card download successful\n");
483 } 465 }
484 466
485 mdelay(10); 467 mdelay(10);
@@ -494,8 +476,7 @@ static int ft1000_reset_card(struct net_device *dev)
494 /* Initialize DSP heartbeat area to ho */ 476 /* Initialize DSP heartbeat area to ho */
495 ft1000_write_dpram(dev, FT1000_HI_HO, ho); 477 ft1000_write_dpram(dev, FT1000_HI_HO, ho);
496 tempword = ft1000_read_dpram(dev, FT1000_HI_HO); 478 tempword = ft1000_read_dpram(dev, FT1000_HI_HO);
497 DEBUG(1, "ft1000_hw:ft1000_reset_asic:hi_ho value = 0x%x\n", 479 pr_debug("hi_ho value = 0x%x\n", tempword);
498 tempword);
499 } else { 480 } else {
500 /* Initialize DSP heartbeat area to ho */ 481 /* Initialize DSP heartbeat area to ho */
501 ft1000_write_dpram_mag_16(dev, FT1000_MAG_HI_HO, ho_mag, 482 ft1000_write_dpram_mag_16(dev, FT1000_MAG_HI_HO, ho_mag,
@@ -503,8 +484,7 @@ static int ft1000_reset_card(struct net_device *dev)
503 tempword = 484 tempword =
504 ft1000_read_dpram_mag_16(dev, FT1000_MAG_HI_HO, 485 ft1000_read_dpram_mag_16(dev, FT1000_MAG_HI_HO,
505 FT1000_MAG_HI_HO_INDX); 486 FT1000_MAG_HI_HO_INDX);
506 DEBUG(1, "ft1000_hw:ft1000_reset_card:hi_ho value = 0x%x\n", 487 pr_debug("hi_ho value = 0x%x\n", tempword);
507 tempword);
508 } 488 }
509 489
510 info->CardReady = 1; 490 info->CardReady = 1;
@@ -521,14 +501,14 @@ static int ft1000_reset_card(struct net_device *dev)
521 501
522/*--------------------------------------------------------------------------- 502/*---------------------------------------------------------------------------
523 503
524 Function: ft1000_chkcard 504 Function: ft1000_chkcard
525 Description: This function will check if the device is presently available on 505 Description: This function will check if the device is presently available on
526 the system. 506 the system.
527 Input: 507 Input:
528 dev - device structure 508 dev - device structure
529 Output: 509 Output:
530 status - false (device is not present) 510 status - false (device is not present)
531 true (device is present) 511 true (device is present)
532 512
533 -------------------------------------------------------------------------*/ 513 -------------------------------------------------------------------------*/
534static int ft1000_chkcard(struct net_device *dev) 514static int ft1000_chkcard(struct net_device *dev)
@@ -541,8 +521,7 @@ static int ft1000_chkcard(struct net_device *dev)
541 */ 521 */
542 tempword = ft1000_read_reg(dev, FT1000_REG_SUP_IMASK); 522 tempword = ft1000_read_reg(dev, FT1000_REG_SUP_IMASK);
543 if (tempword == 0) { 523 if (tempword == 0) {
544 DEBUG(1, 524 pr_debug("IMASK = 0 Card not detected\n");
545 "ft1000_hw:ft1000_chkcard: IMASK = 0 Card not detected\n");
546 return false; 525 return false;
547 } 526 }
548 /* 527 /*
@@ -551,8 +530,7 @@ static int ft1000_chkcard(struct net_device *dev)
551 */ 530 */
552 tempword = ft1000_read_reg(dev, FT1000_REG_ASIC_ID); 531 tempword = ft1000_read_reg(dev, FT1000_REG_ASIC_ID);
553 if (tempword == 0xffff) { 532 if (tempword == 0xffff) {
554 DEBUG(1, 533 pr_debug("Version = 0xffff Card not detected\n");
555 "ft1000_hw:ft1000_chkcard: Version = 0xffff Card not detected\n");
556 return false; 534 return false;
557 } 535 }
558 return true; 536 return true;
@@ -561,13 +539,13 @@ static int ft1000_chkcard(struct net_device *dev)
561 539
562/*--------------------------------------------------------------------------- 540/*---------------------------------------------------------------------------
563 541
564 Function: ft1000_hbchk 542 Function: ft1000_hbchk
565 Description: This function will perform the heart beat check of the DSP as 543 Description: This function will perform the heart beat check of the DSP as
566 well as the ASIC. 544 well as the ASIC.
567 Input: 545 Input:
568 dev - device structure 546 dev - device structure
569 Output: 547 Output:
570 none 548 none
571 549
572 -------------------------------------------------------------------------*/ 550 -------------------------------------------------------------------------*/
573static void ft1000_hbchk(u_long data) 551static void ft1000_hbchk(u_long data)
@@ -586,11 +564,10 @@ static void ft1000_hbchk(u_long data)
586 } else { 564 } else {
587 tempword = 565 tempword =
588 ntohs(ft1000_read_dpram_mag_16 566 ntohs(ft1000_read_dpram_mag_16
589 (dev, FT1000_MAG_HI_HO, 567 (dev, FT1000_MAG_HI_HO,
590 FT1000_MAG_HI_HO_INDX)); 568 FT1000_MAG_HI_HO_INDX));
591 } 569 }
592 DEBUG(1, "ft1000_hw:ft1000_hbchk:hi_ho value = 0x%x\n", 570 pr_debug("hi_ho value = 0x%x\n", tempword);
593 tempword);
594 /* Let's perform another check if ho is not detected */ 571 /* Let's perform another check if ho is not detected */
595 if (tempword != ho) { 572 if (tempword != ho) {
596 if (info->AsicID == ELECTRABUZZ_ID) { 573 if (info->AsicID == ELECTRABUZZ_ID) {
@@ -601,8 +578,7 @@ static void ft1000_hbchk(u_long data)
601 } 578 }
602 } 579 }
603 if (tempword != ho) { 580 if (tempword != ho) {
604 printk(KERN_INFO 581 pr_info("heartbeat failed - no ho detected\n");
605 "ft1000: heartbeat failed - no ho detected\n");
606 if (info->AsicID == ELECTRABUZZ_ID) { 582 if (info->AsicID == ELECTRABUZZ_ID) {
607 info->DSP_TIME[0] = 583 info->DSP_TIME[0] =
608 ft1000_read_dpram(dev, FT1000_DSP_TIMER0); 584 ft1000_read_dpram(dev, FT1000_DSP_TIMER0);
@@ -632,8 +608,7 @@ static void ft1000_hbchk(u_long data)
632 } 608 }
633 info->DrvErrNum = DSP_HB_INFO; 609 info->DrvErrNum = DSP_HB_INFO;
634 if (ft1000_reset_card(dev) == 0) { 610 if (ft1000_reset_card(dev) == 0) {
635 printk(KERN_INFO 611 pr_info("Hardware Failure Detected - PC Card disabled\n");
636 "ft1000: Hardware Failure Detected - PC Card disabled\n");
637 info->ProgConStat = 0xff; 612 info->ProgConStat = 0xff;
638 return; 613 return;
639 } 614 }
@@ -650,8 +625,7 @@ static void ft1000_hbchk(u_long data)
650 tempword = ft1000_read_reg(dev, FT1000_REG_DOORBELL); 625 tempword = ft1000_read_reg(dev, FT1000_REG_DOORBELL);
651 } 626 }
652 if (tempword & FT1000_DB_HB) { 627 if (tempword & FT1000_DB_HB) {
653 printk(KERN_INFO 628 pr_info("heartbeat doorbell not clear by firmware\n");
654 "ft1000: heartbeat doorbell not clear by firmware\n");
655 if (info->AsicID == ELECTRABUZZ_ID) { 629 if (info->AsicID == ELECTRABUZZ_ID) {
656 info->DSP_TIME[0] = 630 info->DSP_TIME[0] =
657 ft1000_read_dpram(dev, FT1000_DSP_TIMER0); 631 ft1000_read_dpram(dev, FT1000_DSP_TIMER0);
@@ -681,8 +655,7 @@ static void ft1000_hbchk(u_long data)
681 } 655 }
682 info->DrvErrNum = DSP_HB_INFO; 656 info->DrvErrNum = DSP_HB_INFO;
683 if (ft1000_reset_card(dev) == 0) { 657 if (ft1000_reset_card(dev) == 0) {
684 printk(KERN_INFO 658 pr_info("Hardware Failure Detected - PC Card disabled\n");
685 "ft1000: Hardware Failure Detected - PC Card disabled\n");
686 info->ProgConStat = 0xff; 659 info->ProgConStat = 0xff;
687 return; 660 return;
688 } 661 }
@@ -708,8 +681,8 @@ static void ft1000_hbchk(u_long data)
708 } else { 681 } else {
709 tempword = 682 tempword =
710 ntohs(ft1000_read_dpram_mag_16 683 ntohs(ft1000_read_dpram_mag_16
711 (dev, FT1000_MAG_HI_HO, 684 (dev, FT1000_MAG_HI_HO,
712 FT1000_MAG_HI_HO_INDX)); 685 FT1000_MAG_HI_HO_INDX));
713 } 686 }
714 /* Let's write hi again if fail */ 687 /* Let's write hi again if fail */
715 if (tempword != hi) { 688 if (tempword != hi) {
@@ -730,8 +703,7 @@ static void ft1000_hbchk(u_long data)
730 } 703 }
731 704
732 if (tempword != hi) { 705 if (tempword != hi) {
733 printk(KERN_INFO 706 pr_info("heartbeat failed - cannot write hi into DPRAM\n");
734 "ft1000: heartbeat failed - cannot write hi into DPRAM\n");
735 if (info->AsicID == ELECTRABUZZ_ID) { 707 if (info->AsicID == ELECTRABUZZ_ID) {
736 info->DSP_TIME[0] = 708 info->DSP_TIME[0] =
737 ft1000_read_dpram(dev, FT1000_DSP_TIMER0); 709 ft1000_read_dpram(dev, FT1000_DSP_TIMER0);
@@ -761,8 +733,7 @@ static void ft1000_hbchk(u_long data)
761 } 733 }
762 info->DrvErrNum = DSP_HB_INFO; 734 info->DrvErrNum = DSP_HB_INFO;
763 if (ft1000_reset_card(dev) == 0) { 735 if (ft1000_reset_card(dev) == 0) {
764 printk(KERN_INFO 736 pr_info("Hardware Failure Detected - PC Card disabled\n");
765 "ft1000: Hardware Failure Detected - PC Card disabled\n");
766 info->ProgConStat = 0xff; 737 info->ProgConStat = 0xff;
767 return; 738 return;
768 } 739 }
@@ -778,19 +749,19 @@ static void ft1000_hbchk(u_long data)
778 749
779 /* Schedule this module to run every 2 seconds */ 750 /* Schedule this module to run every 2 seconds */
780 poll_timer.expires = jiffies + (2 * HZ); 751 poll_timer.expires = jiffies + (2 * HZ);
781 poll_timer.data = (u_long) dev; 752 poll_timer.data = (u_long)dev;
782 add_timer(&poll_timer); 753 add_timer(&poll_timer);
783} 754}
784 755
785/*--------------------------------------------------------------------------- 756/*---------------------------------------------------------------------------
786 757
787 Function: ft1000_send_cmd 758 Function: ft1000_send_cmd
788 Description: 759 Description:
789 Input: 760 Input:
790 Output: 761 Output:
791 762
792 -------------------------------------------------------------------------*/ 763 -------------------------------------------------------------------------*/
793static void ft1000_send_cmd (struct net_device *dev, u16 *ptempbuffer, int size, u16 qtype) 764static void ft1000_send_cmd(struct net_device *dev, u16 *ptempbuffer, int size, u16 qtype)
794{ 765{
795 struct ft1000_info *info = netdev_priv(dev); 766 struct ft1000_info *info = netdev_priv(dev);
796 int i; 767 int i;
@@ -802,26 +773,26 @@ static void ft1000_send_cmd (struct net_device *dev, u16 *ptempbuffer, int size,
802 if ((size & 0x0001)) { 773 if ((size & 0x0001)) {
803 size++; 774 size++;
804 } 775 }
805 DEBUG(1, "FT1000:ft1000_send_cmd:total length = %d\n", size); 776 pr_debug("total length = %d\n", size);
806 DEBUG(1, "FT1000:ft1000_send_cmd:length = %d\n", ntohs(*ptempbuffer)); 777 pr_debug("length = %d\n", ntohs(*ptempbuffer));
807 /* 778 /*
808 * put message into slow queue area 779 * put message into slow queue area
809 * All messages are in the form total_len + pseudo header + message body 780 * All messages are in the form total_len + pseudo header + message body
810 */ 781 */
811 spin_lock_irqsave(&info->dpram_lock, flags); 782 spin_lock_irqsave(&info->dpram_lock, flags);
812 783
813 /* Make sure SLOWQ doorbell is clear */ 784 /* Make sure SLOWQ doorbell is clear */
814 tempword = ft1000_read_reg(dev, FT1000_REG_DOORBELL); 785 tempword = ft1000_read_reg(dev, FT1000_REG_DOORBELL);
815 i=0; 786 i = 0;
816 while (tempword & FT1000_DB_DPRAM_TX) { 787 while (tempword & FT1000_DB_DPRAM_TX) {
817 mdelay(10); 788 mdelay(10);
818 i++; 789 i++;
819 if (i==10) { 790 if (i == 10) {
820 spin_unlock_irqrestore(&info->dpram_lock, flags); 791 spin_unlock_irqrestore(&info->dpram_lock, flags);
821 return; 792 return;
822 } 793 }
823 tempword = ft1000_read_reg(dev, FT1000_REG_DOORBELL); 794 tempword = ft1000_read_reg(dev, FT1000_REG_DOORBELL);
824 } 795 }
825 796
826 if (info->AsicID == ELECTRABUZZ_ID) { 797 if (info->AsicID == ELECTRABUZZ_ID) {
827 ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR, 798 ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR,
@@ -830,8 +801,7 @@ static void ft1000_send_cmd (struct net_device *dev, u16 *ptempbuffer, int size,
830 ft1000_write_reg(dev, FT1000_REG_DPRAM_DATA, size); 801 ft1000_write_reg(dev, FT1000_REG_DPRAM_DATA, size);
831 /* Write pseudo header and messgae body */ 802 /* Write pseudo header and messgae body */
832 for (i = 0; i < (size >> 1); i++) { 803 for (i = 0; i < (size >> 1); i++) {
833 DEBUG(1, "FT1000:ft1000_send_cmd:data %d = 0x%x\n", i, 804 pr_debug("data %d = 0x%x\n", i, *ptempbuffer);
834 *ptempbuffer);
835 tempword = htons(*ptempbuffer++); 805 tempword = htons(*ptempbuffer++);
836 ft1000_write_reg(dev, FT1000_REG_DPRAM_DATA, tempword); 806 ft1000_write_reg(dev, FT1000_REG_DPRAM_DATA, tempword);
837 } 807 }
@@ -844,18 +814,16 @@ static void ft1000_send_cmd (struct net_device *dev, u16 *ptempbuffer, int size,
844 ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR, 814 ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR,
845 FT1000_DPRAM_MAG_TX_BASE + 1); 815 FT1000_DPRAM_MAG_TX_BASE + 1);
846 for (i = 0; i < (size >> 2); i++) { 816 for (i = 0; i < (size >> 2); i++) {
847 DEBUG(1, "FT1000:ft1000_send_cmd:data = 0x%x\n", 817 pr_debug("data = 0x%x\n", *ptempbuffer);
848 *ptempbuffer);
849 outw(*ptempbuffer++, 818 outw(*ptempbuffer++,
850 dev->base_addr + FT1000_REG_MAG_DPDATAL); 819 dev->base_addr + FT1000_REG_MAG_DPDATAL);
851 DEBUG(1, "FT1000:ft1000_send_cmd:data = 0x%x\n", 820 pr_debug("data = 0x%x\n", *ptempbuffer);
852 *ptempbuffer);
853 outw(*ptempbuffer++, 821 outw(*ptempbuffer++,
854 dev->base_addr + FT1000_REG_MAG_DPDATAH); 822 dev->base_addr + FT1000_REG_MAG_DPDATAH);
855 } 823 }
856 DEBUG(1, "FT1000:ft1000_send_cmd:data = 0x%x\n", *ptempbuffer); 824 pr_debug("data = 0x%x\n", *ptempbuffer);
857 outw(*ptempbuffer++, dev->base_addr + FT1000_REG_MAG_DPDATAL); 825 outw(*ptempbuffer++, dev->base_addr + FT1000_REG_MAG_DPDATAL);
858 DEBUG(1, "FT1000:ft1000_send_cmd:data = 0x%x\n", *ptempbuffer); 826 pr_debug("data = 0x%x\n", *ptempbuffer);
859 outw(*ptempbuffer++, dev->base_addr + FT1000_REG_MAG_DPDATAH); 827 outw(*ptempbuffer++, dev->base_addr + FT1000_REG_MAG_DPDATAH);
860 } 828 }
861 spin_unlock_irqrestore(&info->dpram_lock, flags); 829 spin_unlock_irqrestore(&info->dpram_lock, flags);
@@ -866,19 +834,19 @@ static void ft1000_send_cmd (struct net_device *dev, u16 *ptempbuffer, int size,
866 834
867/*--------------------------------------------------------------------------- 835/*---------------------------------------------------------------------------
868 836
869 Function: ft1000_receive_cmd 837 Function: ft1000_receive_cmd
870 Description: This function will read a message from the dpram area. 838 Description: This function will read a message from the dpram area.
871 Input: 839 Input:
872 dev - network device structure 840 dev - network device structure
873 pbuffer - caller supply address to buffer 841 pbuffer - caller supply address to buffer
874 pnxtph - pointer to next pseudo header 842 pnxtph - pointer to next pseudo header
875 Output: 843 Output:
876 Status = 0 (unsuccessful) 844 Status = 0 (unsuccessful)
877 = 1 (successful) 845 = 1 (successful)
878 846
879 -------------------------------------------------------------------------*/ 847 -------------------------------------------------------------------------*/
880static bool ft1000_receive_cmd(struct net_device *dev, u16 *pbuffer, 848static bool ft1000_receive_cmd(struct net_device *dev, u16 *pbuffer,
881 int maxsz, u16 *pnxtph) 849 int maxsz, u16 *pnxtph)
882{ 850{
883 struct ft1000_info *info = netdev_priv(dev); 851 struct ft1000_info *info = netdev_priv(dev);
884 u16 size; 852 u16 size;
@@ -888,20 +856,18 @@ static bool ft1000_receive_cmd(struct net_device *dev, u16 *pbuffer,
888 unsigned long flags; 856 unsigned long flags;
889 857
890 if (info->AsicID == ELECTRABUZZ_ID) { 858 if (info->AsicID == ELECTRABUZZ_ID) {
891 size = ( ft1000_read_dpram(dev, *pnxtph) ) + sizeof(struct pseudo_hdr); 859 size = (ft1000_read_dpram(dev, *pnxtph)) + sizeof(struct pseudo_hdr);
892 } else { 860 } else {
893 size = 861 size =
894 ntohs(ft1000_read_dpram_mag_16 862 ntohs(ft1000_read_dpram_mag_16
895 (dev, FT1000_MAG_PH_LEN, 863 (dev, FT1000_MAG_PH_LEN,
896 FT1000_MAG_PH_LEN_INDX)) + sizeof(struct pseudo_hdr); 864 FT1000_MAG_PH_LEN_INDX)) + sizeof(struct pseudo_hdr);
897 } 865 }
898 if (size > maxsz) { 866 if (size > maxsz) {
899 DEBUG(1, 867 pr_debug("Invalid command length = %d\n", size);
900 "FT1000:ft1000_receive_cmd:Invalid command length = %d\n",
901 size);
902 return false; 868 return false;
903 } else { 869 } else {
904 ppseudohdr = (u16 *) pbuffer; 870 ppseudohdr = (u16 *)pbuffer;
905 spin_lock_irqsave(&info->dpram_lock, flags); 871 spin_lock_irqsave(&info->dpram_lock, flags);
906 if (info->AsicID == ELECTRABUZZ_ID) { 872 if (info->AsicID == ELECTRABUZZ_ID) {
907 ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR, 873 ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR,
@@ -915,26 +881,26 @@ static bool ft1000_receive_cmd(struct net_device *dev, u16 *pbuffer,
915 ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR, 881 ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR,
916 FT1000_DPRAM_MAG_RX_BASE); 882 FT1000_DPRAM_MAG_RX_BASE);
917 *pbuffer = inw(dev->base_addr + FT1000_REG_MAG_DPDATAH); 883 *pbuffer = inw(dev->base_addr + FT1000_REG_MAG_DPDATAH);
918 DEBUG(1, "ft1000_hw:received data = 0x%x\n", *pbuffer); 884 pr_debug("received data = 0x%x\n", *pbuffer);
919 pbuffer++; 885 pbuffer++;
920 ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR, 886 ft1000_write_reg(dev, FT1000_REG_DPRAM_ADDR,
921 FT1000_DPRAM_MAG_RX_BASE + 1); 887 FT1000_DPRAM_MAG_RX_BASE + 1);
922 for (i = 0; i <= (size >> 2); i++) { 888 for (i = 0; i <= (size >> 2); i++) {
923 *pbuffer = 889 *pbuffer =
924 inw(dev->base_addr + 890 inw(dev->base_addr +
925 FT1000_REG_MAG_DPDATAL); 891 FT1000_REG_MAG_DPDATAL);
926 pbuffer++; 892 pbuffer++;
927 *pbuffer = 893 *pbuffer =
928 inw(dev->base_addr + 894 inw(dev->base_addr +
929 FT1000_REG_MAG_DPDATAH); 895 FT1000_REG_MAG_DPDATAH);
930 pbuffer++; 896 pbuffer++;
931 } 897 }
932 /* copy odd aligned word */ 898 /* copy odd aligned word */
933 *pbuffer = inw(dev->base_addr + FT1000_REG_MAG_DPDATAL); 899 *pbuffer = inw(dev->base_addr + FT1000_REG_MAG_DPDATAL);
934 DEBUG(1, "ft1000_hw:received data = 0x%x\n", *pbuffer); 900 pr_debug("received data = 0x%x\n", *pbuffer);
935 pbuffer++; 901 pbuffer++;
936 *pbuffer = inw(dev->base_addr + FT1000_REG_MAG_DPDATAH); 902 *pbuffer = inw(dev->base_addr + FT1000_REG_MAG_DPDATAH);
937 DEBUG(1, "ft1000_hw:received data = 0x%x\n", *pbuffer); 903 pr_debug("received data = 0x%x\n", *pbuffer);
938 pbuffer++; 904 pbuffer++;
939 } 905 }
940 if (size & 0x0001) { 906 if (size & 0x0001) {
@@ -953,8 +919,7 @@ static bool ft1000_receive_cmd(struct net_device *dev, u16 *pbuffer,
953 tempword ^= *ppseudohdr++; 919 tempword ^= *ppseudohdr++;
954 } 920 }
955 if ((tempword != *ppseudohdr)) { 921 if ((tempword != *ppseudohdr)) {
956 DEBUG(1, 922 pr_debug("Pseudo header checksum mismatch\n");
957 "FT1000:ft1000_receive_cmd:Pseudo header checksum mismatch\n");
958 /* Drop this message */ 923 /* Drop this message */
959 return false; 924 return false;
960 } 925 }
@@ -964,13 +929,13 @@ static bool ft1000_receive_cmd(struct net_device *dev, u16 *pbuffer,
964 929
965/*--------------------------------------------------------------------------- 930/*---------------------------------------------------------------------------
966 931
967 Function: ft1000_proc_drvmsg 932 Function: ft1000_proc_drvmsg
968 Description: This function will process the various driver messages. 933 Description: This function will process the various driver messages.
969 Input: 934 Input:
970 dev - device structure 935 dev - device structure
971 pnxtph - pointer to next pseudo header 936 pnxtph - pointer to next pseudo header
972 Output: 937 Output:
973 none 938 none
974 939
975 -------------------------------------------------------------------------*/ 940 -------------------------------------------------------------------------*/
976static void ft1000_proc_drvmsg(struct net_device *dev) 941static void ft1000_proc_drvmsg(struct net_device *dev)
@@ -992,25 +957,24 @@ static void ft1000_proc_drvmsg(struct net_device *dev)
992 u16 wrd; 957 u16 wrd;
993 } convert; 958 } convert;
994 959
995 if (info->AsicID == ELECTRABUZZ_ID) { 960 if (info->AsicID == ELECTRABUZZ_ID) {
996 tempword = FT1000_DPRAM_RX_BASE+2; 961 tempword = FT1000_DPRAM_RX_BASE+2;
997 } 962 }
998 else { 963 else {
999 tempword = FT1000_DPRAM_MAG_RX_BASE; 964 tempword = FT1000_DPRAM_MAG_RX_BASE;
1000 } 965 }
1001 if ( ft1000_receive_cmd(dev, &cmdbuffer[0], MAX_CMD_SQSIZE, &tempword) ) { 966 if (ft1000_receive_cmd(dev, &cmdbuffer[0], MAX_CMD_SQSIZE, &tempword)) {
1002 967
1003 /* Get the message type which is total_len + PSEUDO header + msgtype + message body */ 968 /* Get the message type which is total_len + PSEUDO header + msgtype + message body */
1004 pdrvmsg = (struct drv_msg *) & cmdbuffer[0]; 969 pdrvmsg = (struct drv_msg *)&cmdbuffer[0];
1005 msgtype = ntohs(pdrvmsg->type); 970 msgtype = ntohs(pdrvmsg->type);
1006 DEBUG(1, "Command message type = 0x%x\n", msgtype); 971 pr_debug("Command message type = 0x%x\n", msgtype);
1007 switch (msgtype) { 972 switch (msgtype) {
1008 case DSP_PROVISION: 973 case DSP_PROVISION:
1009 DEBUG(0, 974 pr_debug("Got a provisioning request message from DSP\n");
1010 "Got a provisioning request message from DSP\n");
1011 mdelay(25); 975 mdelay(25);
1012 while (list_empty(&info->prov_list) == 0) { 976 while (list_empty(&info->prov_list) == 0) {
1013 DEBUG(0, "Sending a provisioning message\n"); 977 pr_debug("Sending a provisioning message\n");
1014 /* Make sure SLOWQ doorbell is clear */ 978 /* Make sure SLOWQ doorbell is clear */
1015 tempword = 979 tempword =
1016 ft1000_read_reg(dev, FT1000_REG_DOORBELL); 980 ft1000_read_reg(dev, FT1000_REG_DOORBELL);
@@ -1025,25 +989,25 @@ static void ft1000_proc_drvmsg(struct net_device *dev)
1025 ptr = 989 ptr =
1026 list_entry(info->prov_list.next, 990 list_entry(info->prov_list.next,
1027 struct prov_record, list); 991 struct prov_record, list);
1028 len = *(u16 *) ptr->pprov_data; 992 len = *(u16 *)ptr->pprov_data;
1029 len = htons(len); 993 len = htons(len);
1030 994
1031 pmsg = (u16 *) ptr->pprov_data; 995 pmsg = (u16 *)ptr->pprov_data;
1032 ppseudo_hdr = (struct pseudo_hdr *) pmsg; 996 ppseudo_hdr = (struct pseudo_hdr *)pmsg;
1033 /* Insert slow queue sequence number */ 997 /* Insert slow queue sequence number */
1034 ppseudo_hdr->seq_num = info->squeseqnum++; 998 ppseudo_hdr->seq_num = info->squeseqnum++;
1035 ppseudo_hdr->portsrc = 0; 999 ppseudo_hdr->portsrc = 0;
1036 /* Calculate new checksum */ 1000 /* Calculate new checksum */
1037 ppseudo_hdr->checksum = *pmsg++; 1001 ppseudo_hdr->checksum = *pmsg++;
1038 DEBUG(1, "checksum = 0x%x\n", 1002 pr_debug("checksum = 0x%x\n",
1039 ppseudo_hdr->checksum); 1003 ppseudo_hdr->checksum);
1040 for (i = 1; i < 7; i++) { 1004 for (i = 1; i < 7; i++) {
1041 ppseudo_hdr->checksum ^= *pmsg++; 1005 ppseudo_hdr->checksum ^= *pmsg++;
1042 DEBUG(1, "checksum = 0x%x\n", 1006 pr_debug("checksum = 0x%x\n",
1043 ppseudo_hdr->checksum); 1007 ppseudo_hdr->checksum);
1044 } 1008 }
1045 1009
1046 ft1000_send_cmd (dev, (u16 *)ptr->pprov_data, len, SLOWQ_TYPE); 1010 ft1000_send_cmd(dev, (u16 *)ptr->pprov_data, len, SLOWQ_TYPE);
1047 list_del(&ptr->list); 1011 list_del(&ptr->list);
1048 kfree(ptr->pprov_data); 1012 kfree(ptr->pprov_data);
1049 kfree(ptr); 1013 kfree(ptr);
@@ -1055,19 +1019,29 @@ static void ft1000_proc_drvmsg(struct net_device *dev)
1055 info->CardReady = 1; 1019 info->CardReady = 1;
1056 break; 1020 break;
1057 case MEDIA_STATE: 1021 case MEDIA_STATE:
1058 pmediamsg = (struct media_msg *) & cmdbuffer[0]; 1022 pmediamsg = (struct media_msg *)&cmdbuffer[0];
1059 if (info->ProgConStat != 0xFF) { 1023 if (info->ProgConStat != 0xFF) {
1060 if (pmediamsg->state) { 1024 if (pmediamsg->state) {
1061 DEBUG(1, "Media is up\n"); 1025 pr_debug("Media is up\n");
1062 if (info->mediastate == 0) { 1026 if (info->mediastate == 0) {
1063 netif_carrier_on(dev); 1027 netif_carrier_on(dev);
1064 netif_wake_queue(dev); 1028 netif_wake_queue(dev);
1065 info->mediastate = 1; 1029 info->mediastate = 1;
1066 do_gettimeofday(&tv); 1030 do_gettimeofday(&tv);
1067 info->ConTm = tv.tv_sec; 1031 info->ConTm = tv.tv_sec;
1032 }
1033 } else {
1034 pr_debug("Media is down\n");
1035 if (info->mediastate == 1) {
1036 info->mediastate = 0;
1037 netif_carrier_off(dev);
1038 netif_stop_queue(dev);
1039 info->ConTm = 0;
1040 }
1068 } 1041 }
1069 } else { 1042 }
1070 DEBUG(1, "Media is down\n"); 1043 else {
1044 pr_debug("Media is down\n");
1071 if (info->mediastate == 1) { 1045 if (info->mediastate == 1) {
1072 info->mediastate = 0; 1046 info->mediastate = 0;
1073 netif_carrier_off(dev); 1047 netif_carrier_off(dev);
@@ -1075,25 +1049,15 @@ static void ft1000_proc_drvmsg(struct net_device *dev)
1075 info->ConTm = 0; 1049 info->ConTm = 0;
1076 } 1050 }
1077 } 1051 }
1078 }
1079 else {
1080 DEBUG(1, "Media is down\n");
1081 if (info->mediastate == 1) {
1082 info->mediastate = 0;
1083 netif_carrier_off(dev);
1084 netif_stop_queue(dev);
1085 info->ConTm = 0;
1086 }
1087 }
1088 break; 1052 break;
1089 case DSP_INIT_MSG: 1053 case DSP_INIT_MSG:
1090 pdspinitmsg = (struct dsp_init_msg *) & cmdbuffer[0]; 1054 pdspinitmsg = (struct dsp_init_msg *)&cmdbuffer[0];
1091 memcpy(info->DspVer, pdspinitmsg->DspVer, DSPVERSZ); 1055 memcpy(info->DspVer, pdspinitmsg->DspVer, DSPVERSZ);
1092 DEBUG(1, "DSPVER = 0x%2x 0x%2x 0x%2x 0x%2x\n", 1056 pr_debug("DSPVER = 0x%2x 0x%2x 0x%2x 0x%2x\n",
1093 info->DspVer[0], info->DspVer[1], info->DspVer[2], 1057 info->DspVer[0], info->DspVer[1],
1094 info->DspVer[3]); 1058 info->DspVer[2], info->DspVer[3]);
1095 memcpy(info->HwSerNum, pdspinitmsg->HwSerNum, 1059 memcpy(info->HwSerNum, pdspinitmsg->HwSerNum,
1096 HWSERNUMSZ); 1060 HWSERNUMSZ);
1097 memcpy(info->Sku, pdspinitmsg->Sku, SKUSZ); 1061 memcpy(info->Sku, pdspinitmsg->Sku, SKUSZ);
1098 memcpy(info->eui64, pdspinitmsg->eui64, EUISZ); 1062 memcpy(info->eui64, pdspinitmsg->eui64, EUISZ);
1099 dev->dev_addr[0] = info->eui64[0]; 1063 dev->dev_addr[0] = info->eui64[0];
@@ -1104,34 +1068,33 @@ static void ft1000_proc_drvmsg(struct net_device *dev)
1104 dev->dev_addr[5] = info->eui64[7]; 1068 dev->dev_addr[5] = info->eui64[7];
1105 1069
1106 if (ntohs(pdspinitmsg->length) == 1070 if (ntohs(pdspinitmsg->length) ==
1107 (sizeof(struct dsp_init_msg) - 20)) { 1071 (sizeof(struct dsp_init_msg) - 20)) {
1108 memcpy(info->ProductMode, 1072 memcpy(info->ProductMode,
1109 pdspinitmsg->ProductMode, MODESZ); 1073 pdspinitmsg->ProductMode, MODESZ);
1110 memcpy(info->RfCalVer, pdspinitmsg->RfCalVer, 1074 memcpy(info->RfCalVer, pdspinitmsg->RfCalVer,
1111 CALVERSZ); 1075 CALVERSZ);
1112 memcpy(info->RfCalDate, pdspinitmsg->RfCalDate, 1076 memcpy(info->RfCalDate, pdspinitmsg->RfCalDate,
1113 CALDATESZ); 1077 CALDATESZ);
1114 DEBUG(1, "RFCalVer = 0x%2x 0x%2x\n", 1078 pr_debug("RFCalVer = 0x%2x 0x%2x\n",
1115 info->RfCalVer[0], info->RfCalVer[1]); 1079 info->RfCalVer[0], info->RfCalVer[1]);
1116 } 1080 }
1117 1081
1118 break ; 1082 break;
1119 case DSP_STORE_INFO: 1083 case DSP_STORE_INFO:
1120 DEBUG(1, "FT1000:drivermsg:Got DSP_STORE_INFO\n"); 1084 pr_debug("Got DSP_STORE_INFO\n");
1121 tempword = ntohs(pdrvmsg->length); 1085 tempword = ntohs(pdrvmsg->length);
1122 info->DSPInfoBlklen = tempword; 1086 info->DSPInfoBlklen = tempword;
1123 if (tempword < (MAX_DSP_SESS_REC - 4)) { 1087 if (tempword < (MAX_DSP_SESS_REC - 4)) {
1124 pmsg = (u16 *) & pdrvmsg->data[0]; 1088 pmsg = (u16 *)&pdrvmsg->data[0];
1125 for (i = 0; i < ((tempword + 1) / 2); i++) { 1089 for (i = 0; i < ((tempword + 1) / 2); i++) {
1126 DEBUG(1, 1090 pr_debug("dsp info data = 0x%x\n",
1127 "FT1000:drivermsg:dsp info data = 0x%x\n", 1091 *pmsg);
1128 *pmsg);
1129 info->DSPInfoBlk[i + 10] = *pmsg++; 1092 info->DSPInfoBlk[i + 10] = *pmsg++;
1130 } 1093 }
1131 } 1094 }
1132 break; 1095 break;
1133 case DSP_GET_INFO: 1096 case DSP_GET_INFO:
1134 DEBUG(1, "FT1000:drivermsg:Got DSP_GET_INFO\n"); 1097 pr_debug("Got DSP_GET_INFO\n");
1135 /* 1098 /*
1136 * copy dsp info block to dsp 1099 * copy dsp info block to dsp
1137 * allow any outstanding ioctl to finish 1100 * allow any outstanding ioctl to finish
@@ -1152,8 +1115,8 @@ static void ft1000_proc_drvmsg(struct net_device *dev)
1152 * Put message into Slow Queue 1115 * Put message into Slow Queue
1153 * Form Pseudo header 1116 * Form Pseudo header
1154 */ 1117 */
1155 pmsg = (u16 *) info->DSPInfoBlk; 1118 pmsg = (u16 *)info->DSPInfoBlk;
1156 ppseudo_hdr = (struct pseudo_hdr *) pmsg; 1119 ppseudo_hdr = (struct pseudo_hdr *)pmsg;
1157 ppseudo_hdr->length = 1120 ppseudo_hdr->length =
1158 htons(info->DSPInfoBlklen + 4); 1121 htons(info->DSPInfoBlklen + 4);
1159 ppseudo_hdr->source = 0x10; 1122 ppseudo_hdr->source = 0x10;
@@ -1177,12 +1140,12 @@ static void ft1000_proc_drvmsg(struct net_device *dev)
1177 info->DSPInfoBlk[8] = 0x7200; 1140 info->DSPInfoBlk[8] = 0x7200;
1178 info->DSPInfoBlk[9] = 1141 info->DSPInfoBlk[9] =
1179 htons(info->DSPInfoBlklen); 1142 htons(info->DSPInfoBlklen);
1180 ft1000_send_cmd (dev, (u16 *)info->DSPInfoBlk, (u16)(info->DSPInfoBlklen+4), 0); 1143 ft1000_send_cmd(dev, (u16 *)info->DSPInfoBlk, (u16)(info->DSPInfoBlklen+4), 0);
1181 } 1144 }
1182 1145
1183 break; 1146 break;
1184 case GET_DRV_ERR_RPT_MSG: 1147 case GET_DRV_ERR_RPT_MSG:
1185 DEBUG(1, "FT1000:drivermsg:Got GET_DRV_ERR_RPT_MSG\n"); 1148 pr_debug("Got GET_DRV_ERR_RPT_MSG\n");
1186 /* 1149 /*
1187 * copy driver error message to dsp 1150 * copy driver error message to dsp
1188 * allow any outstanding ioctl to finish 1151 * allow any outstanding ioctl to finish
@@ -1203,8 +1166,8 @@ static void ft1000_proc_drvmsg(struct net_device *dev)
1203 * Put message into Slow Queue 1166 * Put message into Slow Queue
1204 * Form Pseudo header 1167 * Form Pseudo header
1205 */ 1168 */
1206 pmsg = (u16 *) & tempbuffer[0]; 1169 pmsg = (u16 *)&tempbuffer[0];
1207 ppseudo_hdr = (struct pseudo_hdr *) pmsg; 1170 ppseudo_hdr = (struct pseudo_hdr *)pmsg;
1208 ppseudo_hdr->length = htons(0x0012); 1171 ppseudo_hdr->length = htons(0x0012);
1209 ppseudo_hdr->source = 0x10; 1172 ppseudo_hdr->source = 0x10;
1210 ppseudo_hdr->destination = 0x20; 1173 ppseudo_hdr->destination = 0x20;
@@ -1220,11 +1183,11 @@ static void ft1000_proc_drvmsg(struct net_device *dev)
1220 /* Insert application id */ 1183 /* Insert application id */
1221 ppseudo_hdr->portsrc = 0; 1184 ppseudo_hdr->portsrc = 0;
1222 /* Calculate new checksum */ 1185 /* Calculate new checksum */
1223 ppseudo_hdr->checksum = *pmsg++; 1186 ppseudo_hdr->checksum = *pmsg++;
1224 for (i=1; i<7; i++) { 1187 for (i = 1; i < 7; i++) {
1225 ppseudo_hdr->checksum ^= *pmsg++; 1188 ppseudo_hdr->checksum ^= *pmsg++;
1226 } 1189 }
1227 pmsg = (u16 *) & tempbuffer[16]; 1190 pmsg = (u16 *)&tempbuffer[16];
1228 *pmsg++ = htons(RSP_DRV_ERR_RPT_MSG); 1191 *pmsg++ = htons(RSP_DRV_ERR_RPT_MSG);
1229 *pmsg++ = htons(0x000e); 1192 *pmsg++ = htons(0x000e);
1230 *pmsg++ = htons(info->DSP_TIME[0]); 1193 *pmsg++ = htons(info->DSP_TIME[0]);
@@ -1239,7 +1202,7 @@ static void ft1000_proc_drvmsg(struct net_device *dev)
1239 *pmsg++ = convert.wrd; 1202 *pmsg++ = convert.wrd;
1240 *pmsg++ = htons(info->DrvErrNum); 1203 *pmsg++ = htons(info->DrvErrNum);
1241 1204
1242 ft1000_send_cmd (dev, (u16 *)&tempbuffer[0], (u16)(0x0012), 0); 1205 ft1000_send_cmd(dev, (u16 *)&tempbuffer[0], (u16)(0x0012), 0);
1243 info->DrvErrNum = 0; 1206 info->DrvErrNum = 0;
1244 } 1207 }
1245 1208
@@ -1252,14 +1215,14 @@ static void ft1000_proc_drvmsg(struct net_device *dev)
1252 1215
1253/*--------------------------------------------------------------------------- 1216/*---------------------------------------------------------------------------
1254 1217
1255 Function: ft1000_parse_dpram_msg 1218 Function: ft1000_parse_dpram_msg
1256 Description: This function will parse the message received from the DSP 1219 Description: This function will parse the message received from the DSP
1257 via the DPRAM interface. 1220 via the DPRAM interface.
1258 Input: 1221 Input:
1259 dev - device structure 1222 dev - device structure
1260 Output: 1223 Output:
1261 status - FAILURE 1224 status - FAILURE
1262 SUCCESS 1225 SUCCESS
1263 1226
1264 -------------------------------------------------------------------------*/ 1227 -------------------------------------------------------------------------*/
1265static int ft1000_parse_dpram_msg(struct net_device *dev) 1228static int ft1000_parse_dpram_msg(struct net_device *dev)
@@ -1270,11 +1233,10 @@ static int ft1000_parse_dpram_msg(struct net_device *dev)
1270 u16 nxtph; 1233 u16 nxtph;
1271 u16 total_len; 1234 u16 total_len;
1272 int i = 0; 1235 int i = 0;
1273 int cnt;
1274 unsigned long flags; 1236 unsigned long flags;
1275 1237
1276 doorbell = ft1000_read_reg(dev, FT1000_REG_DOORBELL); 1238 doorbell = ft1000_read_reg(dev, FT1000_REG_DOORBELL);
1277 DEBUG(1, "Doorbell = 0x%x\n", doorbell); 1239 pr_debug("Doorbell = 0x%x\n", doorbell);
1278 1240
1279 if (doorbell & FT1000_ASIC_RESET_REQ) { 1241 if (doorbell & FT1000_ASIC_RESET_REQ) {
1280 /* Copy DSP session record from info block */ 1242 /* Copy DSP session record from info block */
@@ -1291,7 +1253,7 @@ static int ft1000_parse_dpram_msg(struct net_device *dev)
1291 FT1000_DPRAM_MAG_RX_BASE); 1253 FT1000_DPRAM_MAG_RX_BASE);
1292 for (i = 0; i < MAX_DSP_SESS_REC / 2; i++) { 1254 for (i = 0; i < MAX_DSP_SESS_REC / 2; i++) {
1293 outl(info->DSPSess.MagRec[i], 1255 outl(info->DSPSess.MagRec[i],
1294 dev->base_addr + FT1000_REG_MAG_DPDATA); 1256 dev->base_addr + FT1000_REG_MAG_DPDATA);
1295 } 1257 }
1296 } 1258 }
1297 spin_unlock_irqrestore(&info->dpram_lock, flags); 1259 spin_unlock_irqrestore(&info->dpram_lock, flags);
@@ -1299,7 +1261,7 @@ static int ft1000_parse_dpram_msg(struct net_device *dev)
1299 /* clear ASIC RESET request */ 1261 /* clear ASIC RESET request */
1300 ft1000_write_reg(dev, FT1000_REG_DOORBELL, 1262 ft1000_write_reg(dev, FT1000_REG_DOORBELL,
1301 FT1000_ASIC_RESET_REQ); 1263 FT1000_ASIC_RESET_REQ);
1302 DEBUG(1, "Got an ASIC RESET Request\n"); 1264 pr_debug("Got an ASIC RESET Request\n");
1303 ft1000_write_reg(dev, FT1000_REG_DOORBELL, 1265 ft1000_write_reg(dev, FT1000_REG_DOORBELL,
1304 FT1000_ASIC_RESET_DSP); 1266 FT1000_ASIC_RESET_DSP);
1305 1267
@@ -1311,8 +1273,7 @@ static int ft1000_parse_dpram_msg(struct net_device *dev)
1311 } 1273 }
1312 1274
1313 if (doorbell & FT1000_DSP_ASIC_RESET) { 1275 if (doorbell & FT1000_DSP_ASIC_RESET) {
1314 DEBUG(0, 1276 pr_debug("Got a dsp ASIC reset message\n");
1315 "FT1000:ft1000_parse_dpram_msg: Got a dsp ASIC reset message\n");
1316 ft1000_write_reg(dev, FT1000_REG_DOORBELL, 1277 ft1000_write_reg(dev, FT1000_REG_DOORBELL,
1317 FT1000_DSP_ASIC_RESET); 1278 FT1000_DSP_ASIC_RESET);
1318 udelay(200); 1279 udelay(200);
@@ -1320,8 +1281,7 @@ static int ft1000_parse_dpram_msg(struct net_device *dev)
1320 } 1281 }
1321 1282
1322 if (doorbell & FT1000_DB_DPRAM_RX) { 1283 if (doorbell & FT1000_DB_DPRAM_RX) {
1323 DEBUG(1, 1284 pr_debug("Got a slow queue message\n");
1324 "FT1000:ft1000_parse_dpram_msg: Got a slow queue message\n");
1325 nxtph = FT1000_DPRAM_RX_BASE + 2; 1285 nxtph = FT1000_DPRAM_RX_BASE + 2;
1326 if (info->AsicID == ELECTRABUZZ_ID) { 1286 if (info->AsicID == ELECTRABUZZ_ID) {
1327 total_len = 1287 total_len =
@@ -1329,14 +1289,12 @@ static int ft1000_parse_dpram_msg(struct net_device *dev)
1329 } else { 1289 } else {
1330 total_len = 1290 total_len =
1331 ntohs(ft1000_read_dpram_mag_16 1291 ntohs(ft1000_read_dpram_mag_16
1332 (dev, FT1000_MAG_TOTAL_LEN, 1292 (dev, FT1000_MAG_TOTAL_LEN,
1333 FT1000_MAG_TOTAL_LEN_INDX)); 1293 FT1000_MAG_TOTAL_LEN_INDX));
1334 } 1294 }
1335 DEBUG(1, "FT1000:ft1000_parse_dpram_msg:total length = %d\n", 1295 pr_debug("total length = %d\n", total_len);
1336 total_len);
1337 if ((total_len < MAX_CMD_SQSIZE) && (total_len > sizeof(struct pseudo_hdr))) { 1296 if ((total_len < MAX_CMD_SQSIZE) && (total_len > sizeof(struct pseudo_hdr))) {
1338 total_len += nxtph; 1297 total_len += nxtph;
1339 cnt = 0;
1340 /* 1298 /*
1341 * ft1000_read_reg will return a value that needs to be byteswap 1299 * ft1000_read_reg will return a value that needs to be byteswap
1342 * in order to get DSP_QID_OFFSET. 1300 * in order to get DSP_QID_OFFSET.
@@ -1353,7 +1311,7 @@ static int ft1000_parse_dpram_msg(struct net_device *dev)
1353 (dev, FT1000_MAG_PORT_ID, 1311 (dev, FT1000_MAG_PORT_ID,
1354 FT1000_MAG_PORT_ID_INDX) & 0xff); 1312 FT1000_MAG_PORT_ID_INDX) & 0xff);
1355 } 1313 }
1356 DEBUG(1, "DSP_QID = 0x%x\n", portid); 1314 pr_debug("DSP_QID = 0x%x\n", portid);
1357 1315
1358 if (portid == DRIVERID) { 1316 if (portid == DRIVERID) {
1359 /* We are assumming one driver message from the DSP at a time. */ 1317 /* We are assumming one driver message from the DSP at a time. */
@@ -1389,7 +1347,7 @@ static int ft1000_parse_dpram_msg(struct net_device *dev)
1389 FT1000_MAG_DSP_TIMER3_INDX); 1347 FT1000_MAG_DSP_TIMER3_INDX);
1390 } 1348 }
1391 info->DrvErrNum = DSP_CONDRESET_INFO; 1349 info->DrvErrNum = DSP_CONDRESET_INFO;
1392 DEBUG(1, "ft1000_hw:DSP conditional reset requested\n"); 1350 pr_debug("DSP conditional reset requested\n");
1393 ft1000_reset_card(dev); 1351 ft1000_reset_card(dev);
1394 ft1000_write_reg(dev, FT1000_REG_DOORBELL, 1352 ft1000_write_reg(dev, FT1000_REG_DOORBELL,
1395 FT1000_DB_COND_RESET); 1353 FT1000_DB_COND_RESET);
@@ -1397,9 +1355,9 @@ static int ft1000_parse_dpram_msg(struct net_device *dev)
1397 /* let's clear any unexpected doorbells from DSP */ 1355 /* let's clear any unexpected doorbells from DSP */
1398 doorbell = 1356 doorbell =
1399 doorbell & ~(FT1000_DB_DPRAM_RX | FT1000_ASIC_RESET_REQ | 1357 doorbell & ~(FT1000_DB_DPRAM_RX | FT1000_ASIC_RESET_REQ |
1400 FT1000_DB_COND_RESET | 0xff00); 1358 FT1000_DB_COND_RESET | 0xff00);
1401 if (doorbell) { 1359 if (doorbell) {
1402 DEBUG(1, "Clearing unexpected doorbell = 0x%x\n", doorbell); 1360 pr_debug("Clearing unexpected doorbell = 0x%x\n", doorbell);
1403 ft1000_write_reg(dev, FT1000_REG_DOORBELL, doorbell); 1361 ft1000_write_reg(dev, FT1000_REG_DOORBELL, doorbell);
1404 } 1362 }
1405 1363
@@ -1409,14 +1367,14 @@ static int ft1000_parse_dpram_msg(struct net_device *dev)
1409 1367
1410/*--------------------------------------------------------------------------- 1368/*---------------------------------------------------------------------------
1411 1369
1412 Function: ft1000_flush_fifo 1370 Function: ft1000_flush_fifo
1413 Description: This function will flush one packet from the downlink 1371 Description: This function will flush one packet from the downlink
1414 FIFO. 1372 FIFO.
1415 Input: 1373 Input:
1416 dev - device structure 1374 dev - device structure
1417 drv_err - driver error causing the flush fifo 1375 drv_err - driver error causing the flush fifo
1418 Output: 1376 Output:
1419 None. 1377 None.
1420 1378
1421 -------------------------------------------------------------------------*/ 1379 -------------------------------------------------------------------------*/
1422static void ft1000_flush_fifo(struct net_device *dev, u16 DrvErrNum) 1380static void ft1000_flush_fifo(struct net_device *dev, u16 DrvErrNum)
@@ -1427,7 +1385,6 @@ static void ft1000_flush_fifo(struct net_device *dev, u16 DrvErrNum)
1427 u32 templong; 1385 u32 templong;
1428 u16 tempword; 1386 u16 tempword;
1429 1387
1430 DEBUG(1, "ft1000:ft1000_hw:ft1000_flush_fifo called\n");
1431 if (pcmcia->PktIntfErr > MAX_PH_ERR) { 1388 if (pcmcia->PktIntfErr > MAX_PH_ERR) {
1432 if (info->AsicID == ELECTRABUZZ_ID) { 1389 if (info->AsicID == ELECTRABUZZ_ID) {
1433 info->DSP_TIME[0] = 1390 info->DSP_TIME[0] =
@@ -1514,7 +1471,7 @@ static void ft1000_flush_fifo(struct net_device *dev, u16 DrvErrNum)
1514 */ 1471 */
1515 tempword = 1472 tempword =
1516 inw(dev->base_addr + 1473 inw(dev->base_addr +
1517 FT1000_REG_SUP_IMASK); 1474 FT1000_REG_SUP_IMASK);
1518 if (tempword == 0) { 1475 if (tempword == 0) {
1519 /* This indicates that we can not communicate with the ASIC */ 1476 /* This indicates that we can not communicate with the ASIC */
1520 info->DrvErrNum = 1477 info->DrvErrNum =
@@ -1533,23 +1490,23 @@ static void ft1000_flush_fifo(struct net_device *dev, u16 DrvErrNum)
1533 } while ((tempword & 0x03) != 0x03); 1490 } while ((tempword & 0x03) != 0x03);
1534 if (info->AsicID == ELECTRABUZZ_ID) { 1491 if (info->AsicID == ELECTRABUZZ_ID) {
1535 i++; 1492 i++;
1536 DEBUG(0, "Flushing FIFO complete = %x\n", tempword); 1493 pr_debug("Flushing FIFO complete = %x\n", tempword);
1537 /* Flush last word in FIFO. */ 1494 /* Flush last word in FIFO. */
1538 tempword = ft1000_read_reg(dev, FT1000_REG_DFIFO); 1495 tempword = ft1000_read_reg(dev, FT1000_REG_DFIFO);
1539 /* Update FIFO counter for DSP */ 1496 /* Update FIFO counter for DSP */
1540 i = i * 2; 1497 i = i * 2;
1541 DEBUG(0, "Flush Data byte count to dsp = %d\n", i); 1498 pr_debug("Flush Data byte count to dsp = %d\n", i);
1542 info->fifo_cnt += i; 1499 info->fifo_cnt += i;
1543 ft1000_write_dpram(dev, FT1000_FIFO_LEN, 1500 ft1000_write_dpram(dev, FT1000_FIFO_LEN,
1544 info->fifo_cnt); 1501 info->fifo_cnt);
1545 } else { 1502 } else {
1546 DEBUG(0, "Flushing FIFO complete = %x\n", tempword); 1503 pr_debug("Flushing FIFO complete = %x\n", tempword);
1547 /* Flush last word in FIFO */ 1504 /* Flush last word in FIFO */
1548 templong = inl(dev->base_addr + FT1000_REG_MAG_DFR); 1505 templong = inl(dev->base_addr + FT1000_REG_MAG_DFR);
1549 tempword = inw(dev->base_addr + FT1000_REG_SUP_STAT); 1506 tempword = inw(dev->base_addr + FT1000_REG_SUP_STAT);
1550 DEBUG(0, "FT1000_REG_SUP_STAT = 0x%x\n", tempword); 1507 pr_debug("FT1000_REG_SUP_STAT = 0x%x\n", tempword);
1551 tempword = inw(dev->base_addr + FT1000_REG_MAG_DFSR); 1508 tempword = inw(dev->base_addr + FT1000_REG_MAG_DFSR);
1552 DEBUG(0, "FT1000_REG_MAG_DFSR = 0x%x\n", tempword); 1509 pr_debug("FT1000_REG_MAG_DFSR = 0x%x\n", tempword);
1553 } 1510 }
1554 if (DrvErrNum) { 1511 if (DrvErrNum) {
1555 pcmcia->PktIntfErr++; 1512 pcmcia->PktIntfErr++;
@@ -1559,15 +1516,15 @@ static void ft1000_flush_fifo(struct net_device *dev, u16 DrvErrNum)
1559 1516
1560/*--------------------------------------------------------------------------- 1517/*---------------------------------------------------------------------------
1561 1518
1562 Function: ft1000_copy_up_pkt 1519 Function: ft1000_copy_up_pkt
1563 Description: This function will pull Flarion packets out of the Downlink 1520 Description: This function will pull Flarion packets out of the Downlink
1564 FIFO and convert it to an ethernet packet. The ethernet packet will 1521 FIFO and convert it to an ethernet packet. The ethernet packet will
1565 then be deliver to the TCP/IP stack. 1522 then be deliver to the TCP/IP stack.
1566 Input: 1523 Input:
1567 dev - device structure 1524 dev - device structure
1568 Output: 1525 Output:
1569 status - FAILURE 1526 status - FAILURE
1570 SUCCESS 1527 SUCCESS
1571 1528
1572 -------------------------------------------------------------------------*/ 1529 -------------------------------------------------------------------------*/
1573static int ft1000_copy_up_pkt(struct net_device *dev) 1530static int ft1000_copy_up_pkt(struct net_device *dev)
@@ -1583,7 +1540,6 @@ static int ft1000_copy_up_pkt(struct net_device *dev)
1583 u32 *ptemplong; 1540 u32 *ptemplong;
1584 u32 templong; 1541 u32 templong;
1585 1542
1586 DEBUG(1, "ft1000_copy_up_pkt\n");
1587 /* Read length */ 1543 /* Read length */
1588 if (info->AsicID == ELECTRABUZZ_ID) { 1544 if (info->AsicID == ELECTRABUZZ_ID) {
1589 tempword = ft1000_read_reg(dev, FT1000_REG_DFIFO); 1545 tempword = ft1000_read_reg(dev, FT1000_REG_DFIFO);
@@ -1593,10 +1549,10 @@ static int ft1000_copy_up_pkt(struct net_device *dev)
1593 len = ntohs(tempword); 1549 len = ntohs(tempword);
1594 } 1550 }
1595 chksum = tempword; 1551 chksum = tempword;
1596 DEBUG(1, "Number of Bytes in FIFO = %d\n", len); 1552 pr_debug("Number of Bytes in FIFO = %d\n", len);
1597 1553
1598 if (len > ENET_MAX_SIZE) { 1554 if (len > ENET_MAX_SIZE) {
1599 DEBUG(0, "size of ethernet packet invalid\n"); 1555 pr_debug("size of ethernet packet invalid\n");
1600 if (info->AsicID == MAGNEMITE_ID) { 1556 if (info->AsicID == MAGNEMITE_ID) {
1601 /* Read High word to complete 32 bit access */ 1557 /* Read High word to complete 32 bit access */
1602 tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRH); 1558 tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRH);
@@ -1609,7 +1565,7 @@ static int ft1000_copy_up_pkt(struct net_device *dev)
1609 skb = dev_alloc_skb(len + 12 + 2); 1565 skb = dev_alloc_skb(len + 12 + 2);
1610 1566
1611 if (skb == NULL) { 1567 if (skb == NULL) {
1612 DEBUG(0, "No Network buffers available\n"); 1568 pr_debug("No Network buffers available\n");
1613 /* Read High word to complete 32 bit access */ 1569 /* Read High word to complete 32 bit access */
1614 if (info->AsicID == MAGNEMITE_ID) { 1570 if (info->AsicID == MAGNEMITE_ID) {
1615 tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRH); 1571 tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRH);
@@ -1618,7 +1574,7 @@ static int ft1000_copy_up_pkt(struct net_device *dev)
1618 info->stats.rx_errors++; 1574 info->stats.rx_errors++;
1619 return FAILURE; 1575 return FAILURE;
1620 } 1576 }
1621 pbuffer = (u8 *) skb_put(skb, len + 12); 1577 pbuffer = (u8 *)skb_put(skb, len + 12);
1622 1578
1623 /* Pseudo header */ 1579 /* Pseudo header */
1624 if (info->AsicID == ELECTRABUZZ_ID) { 1580 if (info->AsicID == ELECTRABUZZ_ID) {
@@ -1630,37 +1586,37 @@ static int ft1000_copy_up_pkt(struct net_device *dev)
1630 tempword = ft1000_read_reg(dev, FT1000_REG_DFIFO); 1586 tempword = ft1000_read_reg(dev, FT1000_REG_DFIFO);
1631 } else { 1587 } else {
1632 tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRH); 1588 tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRH);
1633 DEBUG(1, "Pseudo = 0x%x\n", tempword); 1589 pr_debug("Pseudo = 0x%x\n", tempword);
1634 chksum ^= tempword; 1590 chksum ^= tempword;
1635 1591
1636 tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRL); 1592 tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRL);
1637 DEBUG(1, "Pseudo = 0x%x\n", tempword); 1593 pr_debug("Pseudo = 0x%x\n", tempword);
1638 chksum ^= tempword; 1594 chksum ^= tempword;
1639 1595
1640 tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRH); 1596 tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRH);
1641 DEBUG(1, "Pseudo = 0x%x\n", tempword); 1597 pr_debug("Pseudo = 0x%x\n", tempword);
1642 chksum ^= tempword; 1598 chksum ^= tempword;
1643 1599
1644 tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRL); 1600 tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRL);
1645 DEBUG(1, "Pseudo = 0x%x\n", tempword); 1601 pr_debug("Pseudo = 0x%x\n", tempword);
1646 chksum ^= tempword; 1602 chksum ^= tempword;
1647 1603
1648 tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRH); 1604 tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRH);
1649 DEBUG(1, "Pseudo = 0x%x\n", tempword); 1605 pr_debug("Pseudo = 0x%x\n", tempword);
1650 chksum ^= tempword; 1606 chksum ^= tempword;
1651 1607
1652 tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRL); 1608 tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRL);
1653 DEBUG(1, "Pseudo = 0x%x\n", tempword); 1609 pr_debug("Pseudo = 0x%x\n", tempword);
1654 chksum ^= tempword; 1610 chksum ^= tempword;
1655 1611
1656 /* read checksum value */ 1612 /* read checksum value */
1657 tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRH); 1613 tempword = ft1000_read_reg(dev, FT1000_REG_MAG_DFRH);
1658 DEBUG(1, "Pseudo = 0x%x\n", tempword); 1614 pr_debug("Pseudo = 0x%x\n", tempword);
1659 } 1615 }
1660 1616
1661 if (chksum != tempword) { 1617 if (chksum != tempword) {
1662 DEBUG(0, "Packet checksum mismatch 0x%x 0x%x\n", chksum, 1618 pr_debug("Packet checksum mismatch 0x%x 0x%x\n",
1663 tempword); 1619 chksum, tempword);
1664 ft1000_flush_fifo(dev, DSP_PKTPHCKSUM_INFO); 1620 ft1000_flush_fifo(dev, DSP_PKTPHCKSUM_INFO);
1665 info->stats.rx_errors++; 1621 info->stats.rx_errors++;
1666 kfree_skb(skb); 1622 kfree_skb(skb);
@@ -1687,7 +1643,7 @@ static int ft1000_copy_up_pkt(struct net_device *dev)
1687 for (i = 0; i < len / 2; i++) { 1643 for (i = 0; i < len / 2; i++) {
1688 tempword = ft1000_read_reg(dev, FT1000_REG_DFIFO); 1644 tempword = ft1000_read_reg(dev, FT1000_REG_DFIFO);
1689 *pbuffer++ = (u8) (tempword >> 8); 1645 *pbuffer++ = (u8) (tempword >> 8);
1690 *pbuffer++ = (u8) tempword; 1646 *pbuffer++ = (u8)tempword;
1691 if (ft1000_chkcard(dev) == false) { 1647 if (ft1000_chkcard(dev) == false) {
1692 kfree_skb(skb); 1648 kfree_skb(skb);
1693 return FAILURE; 1649 return FAILURE;
@@ -1700,25 +1656,25 @@ static int ft1000_copy_up_pkt(struct net_device *dev)
1700 *pbuffer++ = (u8) (tempword >> 8); 1656 *pbuffer++ = (u8) (tempword >> 8);
1701 } 1657 }
1702 } else { 1658 } else {
1703 ptemplong = (u32 *) pbuffer; 1659 ptemplong = (u32 *)pbuffer;
1704 for (i = 0; i < len / 4; i++) { 1660 for (i = 0; i < len / 4; i++) {
1705 templong = inl(dev->base_addr + FT1000_REG_MAG_DFR); 1661 templong = inl(dev->base_addr + FT1000_REG_MAG_DFR);
1706 DEBUG(1, "Data = 0x%8x\n", templong); 1662 pr_debug("Data = 0x%8x\n", templong);
1707 *ptemplong++ = templong; 1663 *ptemplong++ = templong;
1708 } 1664 }
1709 1665
1710 /* Need to read one more word if odd align. */ 1666 /* Need to read one more word if odd align. */
1711 if (len & 0x0003) { 1667 if (len & 0x0003) {
1712 templong = inl(dev->base_addr + FT1000_REG_MAG_DFR); 1668 templong = inl(dev->base_addr + FT1000_REG_MAG_DFR);
1713 DEBUG(1, "Data = 0x%8x\n", templong); 1669 pr_debug("Data = 0x%8x\n", templong);
1714 *ptemplong++ = templong; 1670 *ptemplong++ = templong;
1715 } 1671 }
1716 1672
1717 } 1673 }
1718 1674
1719 DEBUG(1, "Data passed to Protocol layer:\n"); 1675 pr_debug("Data passed to Protocol layer:\n");
1720 for (i = 0; i < len + 12; i++) { 1676 for (i = 0; i < len + 12; i++) {
1721 DEBUG(1, "Protocol Data: 0x%x\n ", *ptemp++); 1677 pr_debug("Protocol Data: 0x%x\n", *ptemp++);
1722 } 1678 }
1723 1679
1724 skb->dev = dev; 1680 skb->dev = dev;
@@ -1745,20 +1701,20 @@ static int ft1000_copy_up_pkt(struct net_device *dev)
1745 1701
1746/*--------------------------------------------------------------------------- 1702/*---------------------------------------------------------------------------
1747 1703
1748 Function: ft1000_copy_down_pkt 1704 Function: ft1000_copy_down_pkt
1749 Description: This function will take an ethernet packet and convert it to 1705 Description: This function will take an ethernet packet and convert it to
1750 a Flarion packet prior to sending it to the ASIC Downlink 1706 a Flarion packet prior to sending it to the ASIC Downlink
1751 FIFO. 1707 FIFO.
1752 Input: 1708 Input:
1753 dev - device structure 1709 dev - device structure
1754 packet - address of ethernet packet 1710 packet - address of ethernet packet
1755 len - length of IP packet 1711 len - length of IP packet
1756 Output: 1712 Output:
1757 status - FAILURE 1713 status - FAILURE
1758 SUCCESS 1714 SUCCESS
1759 1715
1760 -------------------------------------------------------------------------*/ 1716 -------------------------------------------------------------------------*/
1761static int ft1000_copy_down_pkt(struct net_device *dev, u16 * packet, u16 len) 1717static int ft1000_copy_down_pkt(struct net_device *dev, u16 *packet, u16 len)
1762{ 1718{
1763 struct ft1000_info *info = netdev_priv(dev); 1719 struct ft1000_info *info = netdev_priv(dev);
1764 struct ft1000_pcmcia *pcmcia = info->priv; 1720 struct ft1000_pcmcia *pcmcia = info->priv;
@@ -1770,8 +1726,6 @@ static int ft1000_copy_down_pkt(struct net_device *dev, u16 * packet, u16 len)
1770 int i; 1726 int i;
1771 u32 *plong; 1727 u32 *plong;
1772 1728
1773 DEBUG(1, "ft1000_hw: copy_down_pkt()\n");
1774
1775 /* Check if there is room on the FIFO */ 1729 /* Check if there is room on the FIFO */
1776 if (len > ft1000_read_fifo_len(dev)) { 1730 if (len > ft1000_read_fifo_len(dev)) {
1777 udelay(10); 1731 udelay(10);
@@ -1791,8 +1745,7 @@ static int ft1000_copy_down_pkt(struct net_device *dev, u16 * packet, u16 len)
1791 udelay(20); 1745 udelay(20);
1792 } 1746 }
1793 if (len > ft1000_read_fifo_len(dev)) { 1747 if (len > ft1000_read_fifo_len(dev)) {
1794 DEBUG(1, 1748 pr_debug("Transmit FIFO is full - pkt drop\n");
1795 "ft1000_hw:ft1000_copy_down_pkt:Transmit FIFO is fulli - pkt drop\n");
1796 info->stats.tx_errors++; 1749 info->stats.tx_errors++;
1797 return SUCCESS; 1750 return SUCCESS;
1798 } 1751 }
@@ -1823,39 +1776,30 @@ static int ft1000_copy_down_pkt(struct net_device *dev, u16 * packet, u16 len)
1823 if (info->AsicID == ELECTRABUZZ_ID) { 1776 if (info->AsicID == ELECTRABUZZ_ID) {
1824 /* copy first word to UFIFO_BEG reg */ 1777 /* copy first word to UFIFO_BEG reg */
1825 ft1000_write_reg(dev, FT1000_REG_UFIFO_BEG, pseudo.buff[0]); 1778 ft1000_write_reg(dev, FT1000_REG_UFIFO_BEG, pseudo.buff[0]);
1826 DEBUG(1, "ft1000_hw:ft1000_copy_down_pkt:data 0 BEG = 0x%04x\n", 1779 pr_debug("data 0 BEG = 0x%04x\n", pseudo.buff[0]);
1827 pseudo.buff[0]);
1828 1780
1829 /* copy subsequent words to UFIFO_MID reg */ 1781 /* copy subsequent words to UFIFO_MID reg */
1830 ft1000_write_reg(dev, FT1000_REG_UFIFO_MID, pseudo.buff[1]); 1782 ft1000_write_reg(dev, FT1000_REG_UFIFO_MID, pseudo.buff[1]);
1831 DEBUG(1, "ft1000_hw:ft1000_copy_down_pkt:data 1 MID = 0x%04x\n", 1783 pr_debug("data 1 MID = 0x%04x\n", pseudo.buff[1]);
1832 pseudo.buff[1]);
1833 ft1000_write_reg(dev, FT1000_REG_UFIFO_MID, pseudo.buff[2]); 1784 ft1000_write_reg(dev, FT1000_REG_UFIFO_MID, pseudo.buff[2]);
1834 DEBUG(1, "ft1000_hw:ft1000_copy_down_pkt:data 2 MID = 0x%04x\n", 1785 pr_debug("data 2 MID = 0x%04x\n", pseudo.buff[2]);
1835 pseudo.buff[2]);
1836 ft1000_write_reg(dev, FT1000_REG_UFIFO_MID, pseudo.buff[3]); 1786 ft1000_write_reg(dev, FT1000_REG_UFIFO_MID, pseudo.buff[3]);
1837 DEBUG(1, "ft1000_hw:ft1000_copy_down_pkt:data 3 MID = 0x%04x\n", 1787 pr_debug("data 3 MID = 0x%04x\n", pseudo.buff[3]);
1838 pseudo.buff[3]);
1839 ft1000_write_reg(dev, FT1000_REG_UFIFO_MID, pseudo.buff[4]); 1788 ft1000_write_reg(dev, FT1000_REG_UFIFO_MID, pseudo.buff[4]);
1840 DEBUG(1, "ft1000_hw:ft1000_copy_down_pkt:data 4 MID = 0x%04x\n", 1789 pr_debug("data 4 MID = 0x%04x\n", pseudo.buff[4]);
1841 pseudo.buff[4]);
1842 ft1000_write_reg(dev, FT1000_REG_UFIFO_MID, pseudo.buff[5]); 1790 ft1000_write_reg(dev, FT1000_REG_UFIFO_MID, pseudo.buff[5]);
1843 DEBUG(1, "ft1000_hw:ft1000_copy_down_pkt:data 5 MID = 0x%04x\n", 1791 pr_debug("data 5 MID = 0x%04x\n", pseudo.buff[5]);
1844 pseudo.buff[5]);
1845 ft1000_write_reg(dev, FT1000_REG_UFIFO_MID, pseudo.buff[6]); 1792 ft1000_write_reg(dev, FT1000_REG_UFIFO_MID, pseudo.buff[6]);
1846 DEBUG(1, "ft1000_hw:ft1000_copy_down_pkt:data 6 MID = 0x%04x\n", 1793 pr_debug("data 6 MID = 0x%04x\n", pseudo.buff[6]);
1847 pseudo.buff[6]);
1848 ft1000_write_reg(dev, FT1000_REG_UFIFO_MID, pseudo.buff[7]); 1794 ft1000_write_reg(dev, FT1000_REG_UFIFO_MID, pseudo.buff[7]);
1849 DEBUG(1, "ft1000_hw:ft1000_copy_down_pkt:data 7 MID = 0x%04x\n", 1795 pr_debug("data 7 MID = 0x%04x\n", pseudo.buff[7]);
1850 pseudo.buff[7]);
1851 1796
1852 /* Write PPP type + IP Packet into Downlink FIFO */ 1797 /* Write PPP type + IP Packet into Downlink FIFO */
1853 for (i = 0; i < (len >> 1) - 1; i++) { 1798 for (i = 0; i < (len >> 1) - 1; i++) {
1854 ft1000_write_reg(dev, FT1000_REG_UFIFO_MID, 1799 ft1000_write_reg(dev, FT1000_REG_UFIFO_MID,
1855 htons(*packet)); 1800 htons(*packet));
1856 DEBUG(1, 1801 pr_debug("data %d MID = 0x%04x\n",
1857 "ft1000_hw:ft1000_copy_down_pkt:data %d MID = 0x%04x\n", 1802 i + 8, htons(*packet));
1858 i + 8, htons(*packet));
1859 packet++; 1803 packet++;
1860 } 1804 }
1861 1805
@@ -1863,41 +1807,33 @@ static int ft1000_copy_down_pkt(struct net_device *dev, u16 * packet, u16 len)
1863 if (len & 0x0001) { 1807 if (len & 0x0001) {
1864 ft1000_write_reg(dev, FT1000_REG_UFIFO_MID, 1808 ft1000_write_reg(dev, FT1000_REG_UFIFO_MID,
1865 htons(*packet)); 1809 htons(*packet));
1866 DEBUG(1, 1810 pr_debug("data MID = 0x%04x\n", htons(*packet));
1867 "ft1000_hw:ft1000_copy_down_pkt:data MID = 0x%04x\n",
1868 htons(*packet));
1869 packet++; 1811 packet++;
1870 ft1000_write_reg(dev, FT1000_REG_UFIFO_END, 1812 ft1000_write_reg(dev, FT1000_REG_UFIFO_END,
1871 htons(*packet)); 1813 htons(*packet));
1872 DEBUG(1, 1814 pr_debug("data %d MID = 0x%04x\n",
1873 "ft1000_hw:ft1000_copy_down_pkt:data %d MID = 0x%04x\n", 1815 i + 8, htons(*packet));
1874 i + 8, htons(*packet));
1875 } else { 1816 } else {
1876 ft1000_write_reg(dev, FT1000_REG_UFIFO_END, 1817 ft1000_write_reg(dev, FT1000_REG_UFIFO_END,
1877 htons(*packet)); 1818 htons(*packet));
1878 DEBUG(1, 1819 pr_debug("data %d MID = 0x%04x\n",
1879 "ft1000_hw:ft1000_copy_down_pkt:data %d MID = 0x%04x\n", 1820 i + 8, htons(*packet));
1880 i + 8, htons(*packet));
1881 } 1821 }
1882 } else { 1822 } else {
1883 outl(*(u32 *) & pseudo.buff[0], 1823 outl(*(u32 *)&pseudo.buff[0],
1884 dev->base_addr + FT1000_REG_MAG_UFDR); 1824 dev->base_addr + FT1000_REG_MAG_UFDR);
1885 DEBUG(1, "ft1000_copy_down_pkt: Pseudo = 0x%8x\n", 1825 pr_debug("Pseudo = 0x%8x\n", *(u32 *)&pseudo.buff[0]);
1886 *(u32 *) & pseudo.buff[0]); 1826 outl(*(u32 *)&pseudo.buff[2],
1887 outl(*(u32 *) & pseudo.buff[2], 1827 dev->base_addr + FT1000_REG_MAG_UFDR);
1888 dev->base_addr + FT1000_REG_MAG_UFDR); 1828 pr_debug("Pseudo = 0x%8x\n", *(u32 *)&pseudo.buff[2]);
1889 DEBUG(1, "ft1000_copy_down_pkt: Pseudo = 0x%8x\n", 1829 outl(*(u32 *)&pseudo.buff[4],
1890 *(u32 *) & pseudo.buff[2]); 1830 dev->base_addr + FT1000_REG_MAG_UFDR);
1891 outl(*(u32 *) & pseudo.buff[4], 1831 pr_debug("Pseudo = 0x%8x\n", *(u32 *)&pseudo.buff[4]);
1892 dev->base_addr + FT1000_REG_MAG_UFDR); 1832 outl(*(u32 *)&pseudo.buff[6],
1893 DEBUG(1, "ft1000_copy_down_pkt: Pseudo = 0x%8x\n", 1833 dev->base_addr + FT1000_REG_MAG_UFDR);
1894 *(u32 *) & pseudo.buff[4]); 1834 pr_debug("Pseudo = 0x%8x\n", *(u32 *)&pseudo.buff[6]);
1895 outl(*(u32 *) & pseudo.buff[6], 1835
1896 dev->base_addr + FT1000_REG_MAG_UFDR); 1836 plong = (u32 *)packet;
1897 DEBUG(1, "ft1000_copy_down_pkt: Pseudo = 0x%8x\n",
1898 *(u32 *) & pseudo.buff[6]);
1899
1900 plong = (u32 *) packet;
1901 /* Write PPP type + IP Packet into Downlink FIFO */ 1837 /* Write PPP type + IP Packet into Downlink FIFO */
1902 for (i = 0; i < (len >> 2); i++) { 1838 for (i = 0; i < (len >> 2); i++) {
1903 outl(*plong++, dev->base_addr + FT1000_REG_MAG_UFDR); 1839 outl(*plong++, dev->base_addr + FT1000_REG_MAG_UFDR);
@@ -1905,9 +1841,7 @@ static int ft1000_copy_down_pkt(struct net_device *dev, u16 * packet, u16 len)
1905 1841
1906 /* Check for odd alignment */ 1842 /* Check for odd alignment */
1907 if (len & 0x0003) { 1843 if (len & 0x0003) {
1908 DEBUG(1, 1844 pr_debug("data = 0x%8x\n", *plong);
1909 "ft1000_hw:ft1000_copy_down_pkt:data = 0x%8x\n",
1910 *plong);
1911 outl(*plong++, dev->base_addr + FT1000_REG_MAG_UFDR); 1845 outl(*plong++, dev->base_addr + FT1000_REG_MAG_UFDR);
1912 } 1846 }
1913 outl(1, dev->base_addr + FT1000_REG_MAG_UFER); 1847 outl(1, dev->base_addr + FT1000_REG_MAG_UFER);
@@ -1928,19 +1862,14 @@ static struct net_device_stats *ft1000_stats(struct net_device *dev)
1928 1862
1929static int ft1000_open(struct net_device *dev) 1863static int ft1000_open(struct net_device *dev)
1930{ 1864{
1931
1932 DEBUG(0, "ft1000_hw: ft1000_open is called\n");
1933
1934 ft1000_reset_card(dev); 1865 ft1000_reset_card(dev);
1935 DEBUG(0, "ft1000_hw: ft1000_open is ended\n");
1936 1866
1937 /* schedule ft1000_hbchk to perform periodic heartbeat checks on DSP and ASIC */ 1867 /* schedule ft1000_hbchk to perform periodic heartbeat checks on DSP and ASIC */
1938 init_timer(&poll_timer); 1868 init_timer(&poll_timer);
1939 poll_timer.expires = jiffies + (2 * HZ); 1869 poll_timer.expires = jiffies + (2 * HZ);
1940 poll_timer.data = (u_long) dev; 1870 poll_timer.data = (u_long)dev;
1941 add_timer(&poll_timer); 1871 add_timer(&poll_timer);
1942 1872
1943 DEBUG(0, "ft1000_hw: ft1000_open is ended2\n");
1944 return 0; 1873 return 0;
1945} 1874}
1946 1875
@@ -1948,13 +1877,11 @@ static int ft1000_close(struct net_device *dev)
1948{ 1877{
1949 struct ft1000_info *info = netdev_priv(dev); 1878 struct ft1000_info *info = netdev_priv(dev);
1950 1879
1951 DEBUG(0, "ft1000_hw: ft1000_close()\n");
1952
1953 info->CardReady = 0; 1880 info->CardReady = 0;
1954 del_timer(&poll_timer); 1881 del_timer(&poll_timer);
1955 1882
1956 if (ft1000_card_present == 1) { 1883 if (ft1000_card_present == 1) {
1957 DEBUG(0, "Media is down\n"); 1884 pr_debug("Media is down\n");
1958 netif_stop_queue(dev); 1885 netif_stop_queue(dev);
1959 1886
1960 ft1000_disable_interrupts(dev); 1887 ft1000_disable_interrupts(dev);
@@ -1971,31 +1898,28 @@ static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
1971 struct ft1000_info *info = netdev_priv(dev); 1898 struct ft1000_info *info = netdev_priv(dev);
1972 u8 *pdata; 1899 u8 *pdata;
1973 1900
1974 DEBUG(1, "ft1000_hw: ft1000_start_xmit()\n");
1975 if (skb == NULL) { 1901 if (skb == NULL) {
1976 DEBUG(1, "ft1000_hw: ft1000_start_xmit:skb == NULL!!!\n"); 1902 pr_debug("skb == NULL!!!\n");
1977 return 0; 1903 return 0;
1978 } 1904 }
1979 1905
1980 DEBUG(1, "ft1000_hw: ft1000_start_xmit:length of packet = %d\n", 1906 pr_debug("length of packet = %d\n", skb->len);
1981 skb->len);
1982 1907
1983 pdata = (u8 *) skb->data; 1908 pdata = (u8 *)skb->data;
1984 1909
1985 if (info->mediastate == 0) { 1910 if (info->mediastate == 0) {
1986 /* Drop packet is mediastate is down */ 1911 /* Drop packet is mediastate is down */
1987 DEBUG(1, "ft1000_hw:ft1000_copy_down_pkt:mediastate is down\n"); 1912 pr_debug("mediastate is down\n");
1988 return SUCCESS; 1913 return SUCCESS;
1989 } 1914 }
1990 1915
1991 if ((skb->len < ENET_HEADER_SIZE) || (skb->len > ENET_MAX_SIZE)) { 1916 if ((skb->len < ENET_HEADER_SIZE) || (skb->len > ENET_MAX_SIZE)) {
1992 /* Drop packet which has invalid size */ 1917 /* Drop packet which has invalid size */
1993 DEBUG(1, 1918 pr_debug("invalid ethernet length\n");
1994 "ft1000_hw:ft1000_copy_down_pkt:invalid ethernet length\n");
1995 return SUCCESS; 1919 return SUCCESS;
1996 } 1920 }
1997 ft1000_copy_down_pkt(dev, (u16 *) (pdata + ENET_HEADER_SIZE - 2), 1921 ft1000_copy_down_pkt(dev, (u16 *) (pdata + ENET_HEADER_SIZE - 2),
1998 skb->len - ENET_HEADER_SIZE + 2); 1922 skb->len - ENET_HEADER_SIZE + 2);
1999 1923
2000 dev_kfree_skb(skb); 1924 dev_kfree_skb(skb);
2001 1925
@@ -2004,14 +1928,12 @@ static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
2004 1928
2005static irqreturn_t ft1000_interrupt(int irq, void *dev_id) 1929static irqreturn_t ft1000_interrupt(int irq, void *dev_id)
2006{ 1930{
2007 struct net_device *dev = (struct net_device *)dev_id; 1931 struct net_device *dev = dev_id;
2008 struct ft1000_info *info = netdev_priv(dev); 1932 struct ft1000_info *info = netdev_priv(dev);
2009 u16 tempword; 1933 u16 tempword;
2010 u16 inttype; 1934 u16 inttype;
2011 int cnt; 1935 int cnt;
2012 1936
2013 DEBUG(1, "ft1000_hw: ft1000_interrupt()\n");
2014
2015 if (info->CardReady == 0) { 1937 if (info->CardReady == 0) {
2016 ft1000_disable_interrupts(dev); 1938 ft1000_disable_interrupts(dev);
2017 return IRQ_HANDLED; 1939 return IRQ_HANDLED;
@@ -2033,19 +1955,19 @@ static irqreturn_t ft1000_interrupt(int irq, void *dev_id)
2033 ft1000_parse_dpram_msg(dev); 1955 ft1000_parse_dpram_msg(dev);
2034 1956
2035 if (inttype & ISR_RCV) { 1957 if (inttype & ISR_RCV) {
2036 DEBUG(1, "Data in FIFO\n"); 1958 pr_debug("Data in FIFO\n");
2037 1959
2038 cnt = 0; 1960 cnt = 0;
2039 do { 1961 do {
2040 /* Check if we have packets in the Downlink FIFO */ 1962 /* Check if we have packets in the Downlink FIFO */
2041 if (info->AsicID == ELECTRABUZZ_ID) { 1963 if (info->AsicID == ELECTRABUZZ_ID) {
2042 tempword = 1964 tempword =
2043 ft1000_read_reg(dev, 1965 ft1000_read_reg(dev,
2044 FT1000_REG_DFIFO_STAT); 1966 FT1000_REG_DFIFO_STAT);
2045 } else { 1967 } else {
2046 tempword = 1968 tempword =
2047 ft1000_read_reg(dev, 1969 ft1000_read_reg(dev,
2048 FT1000_REG_MAG_DFSR); 1970 FT1000_REG_MAG_DFSR);
2049 } 1971 }
2050 if (tempword & 0x1f) { 1972 if (tempword & 0x1f) {
2051 ft1000_copy_up_pkt(dev); 1973 ft1000_copy_up_pkt(dev);
@@ -2058,12 +1980,13 @@ static irqreturn_t ft1000_interrupt(int irq, void *dev_id)
2058 } 1980 }
2059 /* clear interrupts */ 1981 /* clear interrupts */
2060 tempword = ft1000_read_reg(dev, FT1000_REG_SUP_ISR); 1982 tempword = ft1000_read_reg(dev, FT1000_REG_SUP_ISR);
2061 DEBUG(1, "ft1000_hw: interrupt status register = 0x%x\n", tempword); 1983 pr_debug("interrupt status register = 0x%x\n", tempword);
2062 ft1000_write_reg(dev, FT1000_REG_SUP_ISR, tempword); 1984 ft1000_write_reg(dev, FT1000_REG_SUP_ISR, tempword);
2063 1985
2064 /* Read interrupt type */ 1986 /* Read interrupt type */
2065 inttype = ft1000_read_reg (dev, FT1000_REG_SUP_ISR); 1987 inttype = ft1000_read_reg(dev, FT1000_REG_SUP_ISR);
2066 DEBUG(1, "ft1000_hw: interrupt status register after clear = 0x%x\n", inttype); 1988 pr_debug("interrupt status register after clear = 0x%x\n",
1989 inttype);
2067 } 1990 }
2068 ft1000_enable_interrupts(dev); 1991 ft1000_enable_interrupts(dev);
2069 return IRQ_HANDLED; 1992 return IRQ_HANDLED;
@@ -2075,8 +1998,6 @@ void stop_ft1000_card(struct net_device *dev)
2075 struct prov_record *ptr; 1998 struct prov_record *ptr;
2076 /* int cnt; */ 1999 /* int cnt; */
2077 2000
2078 DEBUG(0, "ft1000_hw: stop_ft1000_card()\n");
2079
2080 info->CardReady = 0; 2001 info->CardReady = 0;
2081 ft1000_card_present = 0; 2002 ft1000_card_present = 0;
2082 netif_stop_queue(dev); 2003 netif_stop_queue(dev);
@@ -2105,7 +2026,7 @@ void stop_ft1000_card(struct net_device *dev)
2105} 2026}
2106 2027
2107static void ft1000_get_drvinfo(struct net_device *dev, 2028static void ft1000_get_drvinfo(struct net_device *dev,
2108 struct ethtool_drvinfo *info) 2029 struct ethtool_drvinfo *info)
2109{ 2030{
2110 struct ft1000_info *ft_info; 2031 struct ft1000_info *ft_info;
2111 ft_info = netdev_priv(dev); 2032 ft_info = netdev_priv(dev);
@@ -2121,6 +2042,7 @@ static void ft1000_get_drvinfo(struct net_device *dev,
2121static u32 ft1000_get_link(struct net_device *dev) 2042static u32 ft1000_get_link(struct net_device *dev)
2122{ 2043{
2123 struct ft1000_info *info; 2044 struct ft1000_info *info;
2045
2124 info = netdev_priv(dev); 2046 info = netdev_priv(dev);
2125 return info->mediastate; 2047 return info->mediastate;
2126} 2048}
@@ -2131,37 +2053,36 @@ static const struct ethtool_ops ops = {
2131}; 2053};
2132 2054
2133struct net_device *init_ft1000_card(struct pcmcia_device *link, 2055struct net_device *init_ft1000_card(struct pcmcia_device *link,
2134 void *ft1000_reset) 2056 void *ft1000_reset)
2135{ 2057{
2136 struct ft1000_info *info; 2058 struct ft1000_info *info;
2137 struct ft1000_pcmcia *pcmcia; 2059 struct ft1000_pcmcia *pcmcia;
2138 struct net_device *dev; 2060 struct net_device *dev;
2139 2061
2140 static const struct net_device_ops ft1000ops = /* Slavius 21.10.2009 due to kernel changes */ 2062 static const struct net_device_ops ft1000ops = /* Slavius 21.10.2009 due to kernel changes */
2141 { 2063 {
2142 .ndo_open = &ft1000_open, 2064 .ndo_open = &ft1000_open,
2143 .ndo_stop = &ft1000_close, 2065 .ndo_stop = &ft1000_close,
2144 .ndo_start_xmit = &ft1000_start_xmit, 2066 .ndo_start_xmit = &ft1000_start_xmit,
2145 .ndo_get_stats = &ft1000_stats, 2067 .ndo_get_stats = &ft1000_stats,
2146 }; 2068 };
2147 2069
2148 DEBUG(1, "ft1000_hw: init_ft1000_card()\n"); 2070 pr_debug("irq = %d, port = 0x%04llx\n",
2149 DEBUG(1, "ft1000_hw: irq = %d\n", link->irq); 2071 link->irq, (unsigned long long)link->resource[0]->start);
2150 DEBUG(1, "ft1000_hw: port = 0x%04x\n", link->resource[0]->start);
2151 2072
2152 flarion_ft1000_cnt++; 2073 flarion_ft1000_cnt++;
2153 2074
2154 if (flarion_ft1000_cnt > 1) { 2075 if (flarion_ft1000_cnt > 1) {
2155 flarion_ft1000_cnt--; 2076 flarion_ft1000_cnt--;
2156 2077
2157 printk(KERN_INFO 2078 dev_info(&link->dev,
2158 "ft1000: This driver can not support more than one instance\n"); 2079 "This driver can not support more than one instance\n");
2159 return NULL; 2080 return NULL;
2160 } 2081 }
2161 2082
2162 dev = alloc_etherdev(sizeof(struct ft1000_info)); 2083 dev = alloc_etherdev(sizeof(struct ft1000_info));
2163 if (!dev) { 2084 if (!dev) {
2164 printk(KERN_ERR "ft1000: failed to allocate etherdev\n"); 2085 dev_err(&link->dev, "Failed to allocate etherdev\n");
2165 return NULL; 2086 return NULL;
2166 } 2087 }
2167 2088
@@ -2170,9 +2091,9 @@ struct net_device *init_ft1000_card(struct pcmcia_device *link,
2170 2091
2171 memset(info, 0, sizeof(struct ft1000_info)); 2092 memset(info, 0, sizeof(struct ft1000_info));
2172 2093
2173 DEBUG(1, "address of dev = 0x%8x\n", (u32) dev); 2094 pr_debug("address of dev = 0x%p\n", dev);
2174 DEBUG(1, "address of dev info = 0x%8x\n", (u32) info); 2095 pr_debug("address of dev info = 0x%p\n", info);
2175 DEBUG(0, "device name = %s\n", dev->name); 2096 pr_debug("device name = %s\n", dev->name);
2176 2097
2177 memset(&info->stats, 0, sizeof(struct net_device_stats)); 2098 memset(&info->stats, 0, sizeof(struct net_device_stats));
2178 2099
@@ -2204,41 +2125,41 @@ struct net_device *init_ft1000_card(struct pcmcia_device *link,
2204 2125
2205 dev->netdev_ops = &ft1000ops; /* Slavius 21.10.2009 due to kernel changes */ 2126 dev->netdev_ops = &ft1000ops; /* Slavius 21.10.2009 due to kernel changes */
2206 2127
2207 DEBUG(0, "device name = %s\n", dev->name); 2128 pr_debug("device name = %s\n", dev->name);
2208 2129
2209 dev->irq = link->irq; 2130 dev->irq = link->irq;
2210 dev->base_addr = link->resource[0]->start; 2131 dev->base_addr = link->resource[0]->start;
2211 if (pcmcia_get_mac_from_cis(link, dev)) { 2132 if (pcmcia_get_mac_from_cis(link, dev)) {
2212 printk(KERN_ERR "ft1000: Could not read mac address\n"); 2133 netdev_err(dev, "Could not read mac address\n");
2213 goto err_dev; 2134 goto err_dev;
2214 } 2135 }
2215 2136
2216 if (request_irq(dev->irq, ft1000_interrupt, IRQF_SHARED, dev->name, dev)) { 2137 if (request_irq(dev->irq, ft1000_interrupt, IRQF_SHARED, dev->name, dev)) {
2217 printk(KERN_ERR "ft1000: Could not request_irq\n"); 2138 netdev_err(dev, "Could not request_irq\n");
2218 goto err_dev; 2139 goto err_dev;
2219 } 2140 }
2220 2141
2221 if (request_region(dev->base_addr, 256, dev->name) == NULL) { 2142 if (request_region(dev->base_addr, 256, dev->name) == NULL) {
2222 printk(KERN_ERR "ft1000: Could not request_region\n"); 2143 netdev_err(dev, "Could not request_region\n");
2223 goto err_irq; 2144 goto err_irq;
2224 } 2145 }
2225 2146
2226 if (register_netdev(dev) != 0) { 2147 if (register_netdev(dev) != 0) {
2227 DEBUG(0, "ft1000: Could not register netdev"); 2148 pr_debug("Could not register netdev\n");
2228 goto err_reg; 2149 goto err_reg;
2229 } 2150 }
2230 2151
2231 info->AsicID = ft1000_read_reg(dev, FT1000_REG_ASIC_ID); 2152 info->AsicID = ft1000_read_reg(dev, FT1000_REG_ASIC_ID);
2232 if (info->AsicID == ELECTRABUZZ_ID) { 2153 if (info->AsicID == ELECTRABUZZ_ID) {
2233 DEBUG(0, "ft1000_hw: ELECTRABUZZ ASIC\n"); 2154 pr_debug("ELECTRABUZZ ASIC\n");
2234 if (request_firmware(&fw_entry, "ft1000.img", &link->dev) != 0) { 2155 if (request_firmware(&fw_entry, "ft1000.img", &link->dev) != 0) {
2235 printk(KERN_INFO "ft1000: Could not open ft1000.img\n"); 2156 pr_info("Could not open ft1000.img\n");
2236 goto err_unreg; 2157 goto err_unreg;
2237 } 2158 }
2238 } else { 2159 } else {
2239 DEBUG(0, "ft1000_hw: MAGNEMITE ASIC\n"); 2160 pr_debug("MAGNEMITE ASIC\n");
2240 if (request_firmware(&fw_entry, "ft2000.img", &link->dev) != 0) { 2161 if (request_firmware(&fw_entry, "ft2000.img", &link->dev) != 0) {
2241 printk(KERN_INFO "ft1000: Could not open ft2000.img\n"); 2162 pr_info("Could not open ft2000.img\n");
2242 goto err_unreg; 2163 goto err_unreg;
2243 } 2164 }
2244 } 2165 }
@@ -2247,8 +2168,8 @@ struct net_device *init_ft1000_card(struct pcmcia_device *link,
2247 2168
2248 ft1000_card_present = 1; 2169 ft1000_card_present = 1;
2249 dev->ethtool_ops = &ops; 2170 dev->ethtool_ops = &ops;
2250 printk(KERN_INFO "ft1000: %s: addr 0x%04lx irq %d, MAC addr %pM\n", 2171 pr_info("%s: addr 0x%04lx irq %d, MAC addr %pM\n",
2251 dev->name, dev->base_addr, dev->irq, dev->dev_addr); 2172 dev->name, dev->base_addr, dev->irq, dev->dev_addr);
2252 return dev; 2173 return dev;
2253 2174
2254err_unreg: 2175err_unreg:
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c b/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c
index 0f347ab0d300..c8d278229940 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_debug.c
@@ -1,31 +1,34 @@
1/* 1/*
2*--------------------------------------------------------------------------- 2 *---------------------------------------------------------------------------
3* FT1000 driver for Flarion Flash OFDM NIC Device 3 * FT1000 driver for Flarion Flash OFDM NIC Device
4* 4 *
5* Copyright (C) 2006 Flarion Technologies, All rights reserved. 5 * Copyright (C) 2006 Flarion Technologies, All rights reserved.
6* 6 *
7* This program is free software; you can redistribute it and/or modify it 7 * This program is free software; you can redistribute it and/or modify it
8* under the terms of the GNU General Public License as published by the Free 8 * under the terms of the GNU General Public License as published by the Free
9* Software Foundation; either version 2 of the License, or (at your option) any 9 * Software Foundation; either version 2 of the License, or (at your option) any
10* later version. This program is distributed in the hope that it will be useful, 10 * later version. This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13* more details. You should have received a copy of the GNU General Public 13 * more details. You should have received a copy of the GNU General Public
14* License along with this program; if not, write to the 14 * License along with this program; if not, write to the
15* Free Software Foundation, Inc., 59 Temple Place - 15 * Free Software Foundation, Inc., 59 Temple Place -
16* Suite 330, Boston, MA 02111-1307, USA. 16 * Suite 330, Boston, MA 02111-1307, USA.
17*--------------------------------------------------------------------------- 17 *---------------------------------------------------------------------------
18* 18 *
19* File: ft1000_chdev.c 19 * File: ft1000_chdev.c
20* 20 *
21* Description: Custom character device dispatch routines. 21 * Description: Custom character device dispatch routines.
22* 22 *
23* History: 23 * History:
24* 8/29/02 Whc Ported to Linux. 24 * 8/29/02 Whc Ported to Linux.
25* 6/05/06 Whc Porting to Linux 2.6.9 25 * 6/05/06 Whc Porting to Linux 2.6.9
26* 26 *
27*--------------------------------------------------------------------------- 27 *---------------------------------------------------------------------------
28*/ 28 */
29
30#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31
29#include <linux/module.h> 32#include <linux/module.h>
30#include <linux/kernel.h> 33#include <linux/kernel.h>
31#include <linux/sched.h> 34#include <linux/sched.h>
@@ -38,12 +41,12 @@
38#include <linux/debugfs.h> 41#include <linux/debugfs.h>
39#include "ft1000_usb.h" 42#include "ft1000_usb.h"
40 43
41static int ft1000_flarion_cnt = 0; 44static int ft1000_flarion_cnt;
42 45
43static int ft1000_open(struct inode *inode, struct file *file); 46static int ft1000_open(struct inode *inode, struct file *file);
44static unsigned int ft1000_poll_dev(struct file *file, poll_table *wait); 47static unsigned int ft1000_poll_dev(struct file *file, poll_table *wait);
45static long ft1000_ioctl(struct file *file, unsigned int command, 48static long ft1000_ioctl(struct file *file, unsigned int command,
46 unsigned long argument); 49 unsigned long argument);
47static int ft1000_release(struct inode *inode, struct file *file); 50static int ft1000_release(struct inode *inode, struct file *file);
48 51
49/* List to free receive command buffer pool */ 52/* List to free receive command buffer pool */
@@ -55,8 +58,8 @@ spinlock_t free_buff_lock;
55int numofmsgbuf = 0; 58int numofmsgbuf = 0;
56 59
57/* 60/*
58* Table of entry-point routines for char device 61 * Table of entry-point routines for char device
59*/ 62 */
60static const struct file_operations ft1000fops = { 63static const struct file_operations ft1000fops = {
61 .unlocked_ioctl = ft1000_ioctl, 64 .unlocked_ioctl = ft1000_ioctl,
62 .poll = ft1000_poll_dev, 65 .poll = ft1000_poll_dev,
@@ -66,104 +69,104 @@ static const struct file_operations ft1000fops = {
66}; 69};
67 70
68/* 71/*
69--------------------------------------------------------------------------- 72 ---------------------------------------------------------------------------
70* Function: ft1000_get_buffer 73 * Function: ft1000_get_buffer
71* 74 *
72* Parameters: 75 * Parameters:
73* 76 *
74* Returns: 77 * Returns:
75* 78 *
76* Description: 79 * Description:
77* 80 *
78* Notes: 81 * Notes:
79* 82 *
80*--------------------------------------------------------------------------- 83 *---------------------------------------------------------------------------
81*/ 84 */
82struct dpram_blk *ft1000_get_buffer(struct list_head *bufflist) 85struct dpram_blk *ft1000_get_buffer(struct list_head *bufflist)
83{ 86{
84 unsigned long flags; 87 unsigned long flags;
85 struct dpram_blk *ptr; 88 struct dpram_blk *ptr;
86 89
87 spin_lock_irqsave(&free_buff_lock, flags); 90 spin_lock_irqsave(&free_buff_lock, flags);
88 /* Check if buffer is available */ 91 /* Check if buffer is available */
89 if (list_empty(bufflist)) { 92 if (list_empty(bufflist)) {
90 DEBUG("ft1000_get_buffer: No more buffer - %d\n", numofmsgbuf); 93 pr_debug("No more buffer - %d\n", numofmsgbuf);
91 ptr = NULL; 94 ptr = NULL;
92 } else { 95 } else {
93 numofmsgbuf--; 96 numofmsgbuf--;
94 ptr = list_entry(bufflist->next, struct dpram_blk, list); 97 ptr = list_entry(bufflist->next, struct dpram_blk, list);
95 list_del(&ptr->list); 98 list_del(&ptr->list);
96 /* DEBUG("ft1000_get_buffer: number of free msg buffers = %d\n", numofmsgbuf); */ 99 /* pr_debug("number of free msg buffers = %d\n", numofmsgbuf); */
97 } 100 }
98 spin_unlock_irqrestore(&free_buff_lock, flags); 101 spin_unlock_irqrestore(&free_buff_lock, flags);
99 102
100 return ptr; 103 return ptr;
101} 104}
102 105
103 106
104 107
105 108
106/* 109/*
107*--------------------------------------------------------------------------- 110 *---------------------------------------------------------------------------
108* Function: ft1000_free_buffer 111 * Function: ft1000_free_buffer
109* 112 *
110* Parameters: 113 * Parameters:
111* 114 *
112* Returns: 115 * Returns:
113* 116 *
114* Description: 117 * Description:
115* 118 *
116* Notes: 119 * Notes:
117* 120 *
118*--------------------------------------------------------------------------- 121 *---------------------------------------------------------------------------
119*/ 122 */
120void ft1000_free_buffer(struct dpram_blk *pdpram_blk, struct list_head *plist) 123void ft1000_free_buffer(struct dpram_blk *pdpram_blk, struct list_head *plist)
121{ 124{
122 unsigned long flags; 125 unsigned long flags;
123 126
124 spin_lock_irqsave(&free_buff_lock, flags); 127 spin_lock_irqsave(&free_buff_lock, flags);
125 /* Put memory back to list */ 128 /* Put memory back to list */
126 list_add_tail(&pdpram_blk->list, plist); 129 list_add_tail(&pdpram_blk->list, plist);
127 numofmsgbuf++; 130 numofmsgbuf++;
128 /*DEBUG("ft1000_free_buffer: number of free msg buffers = %d\n", numofmsgbuf); */ 131 /*pr_debug("number of free msg buffers = %d\n", numofmsgbuf); */
129 spin_unlock_irqrestore(&free_buff_lock, flags); 132 spin_unlock_irqrestore(&free_buff_lock, flags);
130} 133}
131 134
132/* 135/*
133*--------------------------------------------------------------------------- 136 *---------------------------------------------------------------------------
134* Function: ft1000_CreateDevice 137 * Function: ft1000_CreateDevice
135* 138 *
136* Parameters: dev - pointer to adapter object 139 * Parameters: dev - pointer to adapter object
137* 140 *
138* Returns: 0 if successful 141 * Returns: 0 if successful
139* 142 *
140* Description: Creates a private char device. 143 * Description: Creates a private char device.
141* 144 *
142* Notes: Only called by init_module(). 145 * Notes: Only called by init_module().
143* 146 *
144*--------------------------------------------------------------------------- 147 *---------------------------------------------------------------------------
145*/ 148 */
146int ft1000_create_dev(struct ft1000_usb *dev) 149int ft1000_create_dev(struct ft1000_usb *dev)
147{ 150{
148 int result; 151 int result;
149 int i; 152 int i;
150 struct dentry *dir, *file; 153 struct dentry *dir, *file;
151 struct ft1000_debug_dirs *tmp; 154 struct ft1000_debug_dirs *tmp;
152 155
153 /* make a new device name */ 156 /* make a new device name */
154 sprintf(dev->DeviceName, "%s%d", "FT1000_", dev->CardNumber); 157 sprintf(dev->DeviceName, "%s%d", "FT1000_", dev->CardNumber);
155 158
156 DEBUG("%s: number of instance = %d\n", __func__, ft1000_flarion_cnt); 159 pr_debug("number of instance = %d\n", ft1000_flarion_cnt);
157 DEBUG("DeviceCreated = %x\n", dev->DeviceCreated); 160 pr_debug("DeviceCreated = %x\n", dev->DeviceCreated);
158 161
159 if (dev->DeviceCreated) { 162 if (dev->DeviceCreated) {
160 DEBUG("%s: \"%s\" already registered\n", __func__, dev->DeviceName); 163 pr_debug("\"%s\" already registered\n", dev->DeviceName);
161 return -EIO; 164 return -EIO;
162 } 165 }
163 166
164 167
165 /* register the device */ 168 /* register the device */
166 DEBUG("%s: \"%s\" debugfs device registration\n", __func__, dev->DeviceName); 169 pr_debug("\"%s\" debugfs device registration\n", dev->DeviceName);
167 170
168 tmp = kmalloc(sizeof(struct ft1000_debug_dirs), GFP_KERNEL); 171 tmp = kmalloc(sizeof(struct ft1000_debug_dirs), GFP_KERNEL);
169 if (tmp == NULL) { 172 if (tmp == NULL) {
@@ -178,7 +181,7 @@ int ft1000_create_dev(struct ft1000_usb *dev)
178 } 181 }
179 182
180 file = debugfs_create_file("device", S_IRUGO | S_IWUSR, dir, 183 file = debugfs_create_file("device", S_IRUGO | S_IWUSR, dir,
181 dev, &ft1000fops); 184 dev, &ft1000fops);
182 if (IS_ERR(file)) { 185 if (IS_ERR(file)) {
183 result = PTR_ERR(file); 186 result = PTR_ERR(file);
184 goto debug_file_fail; 187 goto debug_file_fail;
@@ -189,25 +192,25 @@ int ft1000_create_dev(struct ft1000_usb *dev)
189 tmp->int_number = dev->CardNumber; 192 tmp->int_number = dev->CardNumber;
190 list_add(&(tmp->list), &(dev->nodes.list)); 193 list_add(&(tmp->list), &(dev->nodes.list));
191 194
192 DEBUG("%s: registered debugfs directory \"%s\"\n", __func__, dev->DeviceName); 195 pr_debug("registered debugfs directory \"%s\"\n", dev->DeviceName);
193 196
194 /* initialize application information */ 197 /* initialize application information */
195 dev->appcnt = 0; 198 dev->appcnt = 0;
196 for (i=0; i<MAX_NUM_APP; i++) { 199 for (i = 0; i < MAX_NUM_APP; i++) {
197 dev->app_info[i].nTxMsg = 0; 200 dev->app_info[i].nTxMsg = 0;
198 dev->app_info[i].nRxMsg = 0; 201 dev->app_info[i].nRxMsg = 0;
199 dev->app_info[i].nTxMsgReject = 0; 202 dev->app_info[i].nTxMsgReject = 0;
200 dev->app_info[i].nRxMsgMiss = 0; 203 dev->app_info[i].nRxMsgMiss = 0;
201 dev->app_info[i].fileobject = NULL; 204 dev->app_info[i].fileobject = NULL;
202 dev->app_info[i].app_id = i+1; 205 dev->app_info[i].app_id = i+1;
203 dev->app_info[i].DspBCMsgFlag = 0; 206 dev->app_info[i].DspBCMsgFlag = 0;
204 dev->app_info[i].NumOfMsg = 0; 207 dev->app_info[i].NumOfMsg = 0;
205 init_waitqueue_head(&dev->app_info[i].wait_dpram_msg); 208 init_waitqueue_head(&dev->app_info[i].wait_dpram_msg);
206 INIT_LIST_HEAD(&dev->app_info[i].app_sqlist); 209 INIT_LIST_HEAD(&dev->app_info[i].app_sqlist);
207 } 210 }
208 211
209 dev->DeviceCreated = TRUE; 212 dev->DeviceCreated = TRUE;
210 ft1000_flarion_cnt++; 213 ft1000_flarion_cnt++;
211 214
212 return 0; 215 return 0;
213 216
@@ -220,33 +223,29 @@ fail:
220} 223}
221 224
222/* 225/*
223*--------------------------------------------------------------------------- 226 *---------------------------------------------------------------------------
224* Function: ft1000_DestroyDeviceDEBUG 227 * Function: ft1000_DestroyDeviceDEBUG
225* 228 *
226* Parameters: dev - pointer to adapter object 229 * Parameters: dev - pointer to adapter object
227* 230 *
228* Description: Destroys a private char device. 231 * Description: Destroys a private char device.
229* 232 *
230* Notes: Only called by cleanup_module(). 233 * Notes: Only called by cleanup_module().
231* 234 *
232*--------------------------------------------------------------------------- 235 *---------------------------------------------------------------------------
233*/ 236 */
234void ft1000_destroy_dev(struct net_device *netdev) 237void ft1000_destroy_dev(struct net_device *netdev)
235{ 238{
236 struct ft1000_info *info = netdev_priv(netdev); 239 struct ft1000_info *info = netdev_priv(netdev);
237 struct ft1000_usb *dev = info->priv; 240 struct ft1000_usb *dev = info->priv;
238 int i; 241 int i;
239 struct dpram_blk *pdpram_blk; 242 struct dpram_blk *pdpram_blk;
240 struct dpram_blk *ptr; 243 struct dpram_blk *ptr;
241 struct list_head *pos, *q; 244 struct list_head *pos, *q;
242 struct ft1000_debug_dirs *dir; 245 struct ft1000_debug_dirs *dir;
243 246
244 DEBUG("%s called\n", __func__); 247 if (dev->DeviceCreated) {
245 248 ft1000_flarion_cnt--;
246
247
248 if (dev->DeviceCreated) {
249 ft1000_flarion_cnt--;
250 list_for_each_safe(pos, q, &dev->nodes.list) { 249 list_for_each_safe(pos, q, &dev->nodes.list) {
251 dir = list_entry(pos, struct ft1000_debug_dirs, list); 250 dir = list_entry(pos, struct ft1000_debug_dirs, list);
252 if (dir->int_number == dev->CardNumber) { 251 if (dir->int_number == dev->CardNumber) {
@@ -256,29 +255,28 @@ void ft1000_destroy_dev(struct net_device *netdev)
256 kfree(dir); 255 kfree(dir);
257 } 256 }
258 } 257 }
259 DEBUG("%s: unregistered device \"%s\"\n", __func__, 258 pr_debug("unregistered device \"%s\"\n", dev->DeviceName);
260 dev->DeviceName); 259
261 260 /* Make sure we free any memory reserve for slow Queue */
262 /* Make sure we free any memory reserve for slow Queue */ 261 for (i = 0; i < MAX_NUM_APP; i++) {
263 for (i=0; i<MAX_NUM_APP; i++) { 262 while (list_empty(&dev->app_info[i].app_sqlist) == 0) {
264 while (list_empty(&dev->app_info[i].app_sqlist) == 0) { 263 pdpram_blk = list_entry(dev->app_info[i].app_sqlist.next, struct dpram_blk, list);
265 pdpram_blk = list_entry(dev->app_info[i].app_sqlist.next, struct dpram_blk, list); 264 list_del(&pdpram_blk->list);
266 list_del(&pdpram_blk->list); 265 ft1000_free_buffer(pdpram_blk, &freercvpool);
267 ft1000_free_buffer(pdpram_blk, &freercvpool); 266
268 267 }
269 } 268 wake_up_interruptible(&dev->app_info[i].wait_dpram_msg);
270 wake_up_interruptible(&dev->app_info[i].wait_dpram_msg); 269 }
271 } 270
272 271 /* Remove buffer allocated for receive command data */
273 /* Remove buffer allocated for receive command data */ 272 if (ft1000_flarion_cnt == 0) {
274 if (ft1000_flarion_cnt == 0) { 273 while (list_empty(&freercvpool) == 0) {
275 while (list_empty(&freercvpool) == 0) { 274 ptr = list_entry(freercvpool.next, struct dpram_blk, list);
276 ptr = list_entry(freercvpool.next, struct dpram_blk, list); 275 list_del(&ptr->list);
277 list_del(&ptr->list); 276 kfree(ptr->pbuffer);
278 kfree(ptr->pbuffer); 277 kfree(ptr);
279 kfree(ptr); 278 }
280 } 279 }
281 }
282 dev->DeviceCreated = FALSE; 280 dev->DeviceCreated = FALSE;
283 } 281 }
284 282
@@ -286,507 +284,499 @@ void ft1000_destroy_dev(struct net_device *netdev)
286} 284}
287 285
288/* 286/*
289*--------------------------------------------------------------------------- 287 *---------------------------------------------------------------------------
290* Function: ft1000_open 288 * Function: ft1000_open
291* 289 *
292* Parameters: 290 * Parameters:
293* 291 *
294* Description: 292 * Description:
295* 293 *
296* Notes: 294 * Notes:
297* 295 *
298*--------------------------------------------------------------------------- 296 *---------------------------------------------------------------------------
299*/ 297 */
300static int ft1000_open(struct inode *inode, struct file *file) 298static int ft1000_open(struct inode *inode, struct file *file)
301{ 299{
302 struct ft1000_info *info; 300 struct ft1000_info *info;
303 struct ft1000_usb *dev = (struct ft1000_usb *)inode->i_private; 301 struct ft1000_usb *dev = (struct ft1000_usb *)inode->i_private;
304 int i,num; 302 int i, num;
305 303
306 DEBUG("%s called\n", __func__); 304 num = (MINOR(inode->i_rdev) & 0xf);
307 num = (MINOR(inode->i_rdev) & 0xf); 305 pr_debug("minor number=%d\n", num);
308 DEBUG("ft1000_open: minor number=%d\n", num);
309 306
310 info = file->private_data = netdev_priv(dev->net); 307 info = file->private_data = netdev_priv(dev->net);
311 308
312 DEBUG("f_owner = %p number of application = %d\n", (&file->f_owner), dev->appcnt); 309 pr_debug("f_owner = %p number of application = %d\n",
313 310 &file->f_owner, dev->appcnt);
314 /* Check if maximum number of application exceeded */ 311
315 if (dev->appcnt > MAX_NUM_APP) { 312 /* Check if maximum number of application exceeded */
316 DEBUG("Maximum number of application exceeded\n"); 313 if (dev->appcnt > MAX_NUM_APP) {
317 return -EACCES; 314 pr_debug("Maximum number of application exceeded\n");
318 } 315 return -EACCES;
319 316 }
320 /* Search for available application info block */ 317
321 for (i=0; i<MAX_NUM_APP; i++) { 318 /* Search for available application info block */
322 if ((dev->app_info[i].fileobject == NULL)) { 319 for (i = 0; i < MAX_NUM_APP; i++) {
323 break; 320 if ((dev->app_info[i].fileobject == NULL)) {
324 } 321 break;
325 } 322 }
326 323 }
327 /* Fail due to lack of application info block */ 324
328 if (i == MAX_NUM_APP) { 325 /* Fail due to lack of application info block */
329 DEBUG("Could not find an application info block\n"); 326 if (i == MAX_NUM_APP) {
330 return -EACCES; 327 pr_debug("Could not find an application info block\n");
331 } 328 return -EACCES;
332 329 }
333 dev->appcnt++; 330
334 dev->app_info[i].fileobject = &file->f_owner; 331 dev->appcnt++;
335 dev->app_info[i].nTxMsg = 0; 332 dev->app_info[i].fileobject = &file->f_owner;
336 dev->app_info[i].nRxMsg = 0; 333 dev->app_info[i].nTxMsg = 0;
337 dev->app_info[i].nTxMsgReject = 0; 334 dev->app_info[i].nRxMsg = 0;
338 dev->app_info[i].nRxMsgMiss = 0; 335 dev->app_info[i].nTxMsgReject = 0;
336 dev->app_info[i].nRxMsgMiss = 0;
339 337
340 nonseekable_open(inode, file); 338 nonseekable_open(inode, file);
341 return 0; 339 return 0;
342} 340}
343 341
344 342
345/* 343/*
346*--------------------------------------------------------------------------- 344 *---------------------------------------------------------------------------
347* Function: ft1000_poll_dev 345 * Function: ft1000_poll_dev
348* 346 *
349* Parameters: 347 * Parameters:
350* 348 *
351* Description: 349 * Description:
352* 350 *
353* Notes: 351 * Notes:
354* 352 *
355*--------------------------------------------------------------------------- 353 *---------------------------------------------------------------------------
356*/ 354 */
357 355
358static unsigned int ft1000_poll_dev(struct file *file, poll_table *wait) 356static unsigned int ft1000_poll_dev(struct file *file, poll_table *wait)
359{ 357{
360 struct net_device *netdev = file->private_data; 358 struct net_device *netdev = file->private_data;
361 struct ft1000_info *info = netdev_priv(netdev); 359 struct ft1000_info *info = netdev_priv(netdev);
362 struct ft1000_usb *dev = info->priv; 360 struct ft1000_usb *dev = info->priv;
363 int i; 361 int i;
364 362
365 /* DEBUG("ft1000_poll_dev called\n"); */ 363 if (ft1000_flarion_cnt == 0) {
366 if (ft1000_flarion_cnt == 0) { 364 pr_debug("called with ft1000_flarion_cnt value zero\n");
367 DEBUG("FT1000:ft1000_poll_dev called when ft1000_flarion_cnt is zero\n"); 365 return -EBADF;
368 return (-EBADF); 366 }
369 } 367
370 368 /* Search for matching file object */
371 /* Search for matching file object */ 369 for (i = 0; i < MAX_NUM_APP; i++) {
372 for (i=0; i<MAX_NUM_APP; i++) { 370 if (dev->app_info[i].fileobject == &file->f_owner) {
373 if (dev->app_info[i].fileobject == &file->f_owner) { 371 /* pr_debug("Message is for AppId = %d\n", dev->app_info[i].app_id); */
374 /* DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", dev->app_info[i].app_id); */ 372 break;
375 break; 373 }
376 } 374 }
377 } 375
378 376 /* Could not find application info block */
379 /* Could not find application info block */ 377 if (i == MAX_NUM_APP) {
380 if (i == MAX_NUM_APP) { 378 pr_debug("Could not find application info block\n");
381 DEBUG("FT1000:ft1000_ioctl:Could not find application info block\n"); 379 return -EACCES;
382 return (-EACCES); 380 }
383 } 381
384 382 if (list_empty(&dev->app_info[i].app_sqlist) == 0) {
385 if (list_empty(&dev->app_info[i].app_sqlist) == 0) { 383 pr_debug("Message detected in slow queue\n");
386 DEBUG("FT1000:ft1000_poll_dev:Message detected in slow queue\n"); 384 return(POLLIN | POLLRDNORM | POLLPRI);
387 return(POLLIN | POLLRDNORM | POLLPRI); 385 }
388 } 386
389 387 poll_wait(file, &dev->app_info[i].wait_dpram_msg, wait);
390 poll_wait(file, &dev->app_info[i].wait_dpram_msg, wait); 388 /* pr_debug("Polling for data from DSP\n"); */
391 /* DEBUG("FT1000:ft1000_poll_dev:Polling for data from DSP\n"); */
392 389
393 return 0; 390 return 0;
394} 391}
395 392
396/* 393/*
397*--------------------------------------------------------------------------- 394 *---------------------------------------------------------------------------
398* Function: ft1000_ioctl 395 * Function: ft1000_ioctl
399* 396 *
400* Parameters: 397 * Parameters:
401* 398 *
402* Description: 399 * Description:
403* 400 *
404* Notes: 401 * Notes:
405* 402 *
406*--------------------------------------------------------------------------- 403 *---------------------------------------------------------------------------
407*/ 404 */
408static long ft1000_ioctl(struct file *file, unsigned int command, 405static long ft1000_ioctl(struct file *file, unsigned int command,
409 unsigned long argument) 406 unsigned long argument)
410{ 407{
411 void __user *argp = (void __user *)argument; 408 void __user *argp = (void __user *)argument;
412 struct ft1000_info *info; 409 struct ft1000_info *info;
413 struct ft1000_usb *ft1000dev; 410 struct ft1000_usb *ft1000dev;
414 int result=0; 411 int result = 0;
415 int cmd; 412 int cmd;
416 int i; 413 int i;
417 u16 tempword; 414 u16 tempword;
418 unsigned long flags; 415 unsigned long flags;
419 struct timeval tv; 416 struct timeval tv;
420 struct IOCTL_GET_VER get_ver_data; 417 struct IOCTL_GET_VER get_ver_data;
421 struct IOCTL_GET_DSP_STAT get_stat_data; 418 struct IOCTL_GET_DSP_STAT get_stat_data;
422 u8 ConnectionMsg[] = {0x00,0x44,0x10,0x20,0x80,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x93,0x64, 419 u8 ConnectionMsg[] = {0x00, 0x44, 0x10, 0x20, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x93, 0x64,
423 0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0a, 420 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x0a,
424 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 421 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
425 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 422 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
426 0x00,0x00,0x02,0x37,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x01,0x00,0x01,0x7f,0x00, 423 0x00, 0x00, 0x02, 0x37, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x7f, 0x00,
427 0x00,0x01,0x00,0x00}; 424 0x00, 0x01, 0x00, 0x00};
425
426 unsigned short ledStat = 0;
427 unsigned short conStat = 0;
428
429 if (ft1000_flarion_cnt == 0) {
430 pr_debug("called with ft1000_flarion_cnt of zero\n");
431 return -EBADF;
432 }
428 433
429 unsigned short ledStat=0; 434 /* pr_debug("command = 0x%x argument = 0x%8x\n", command, (u32)argument); */
430 unsigned short conStat=0;
431 435
432 /* DEBUG("ft1000_ioctl called\n"); */ 436 info = file->private_data;
437 ft1000dev = info->priv;
438 cmd = _IOC_NR(command);
439 /* pr_debug("cmd = 0x%x\n", cmd); */
440
441 /* process the command */
442 switch (cmd) {
443 case IOCTL_REGISTER_CMD:
444 pr_debug("IOCTL_FT1000_REGISTER called\n");
445 result = get_user(tempword, (__u16 __user *)argp);
446 if (result) {
447 pr_debug("result = %d failed to get_user\n", result);
448 break;
449 }
450 if (tempword == DSPBCMSGID) {
451 /* Search for matching file object */
452 for (i = 0; i < MAX_NUM_APP; i++) {
453 if (ft1000dev->app_info[i].fileobject == &file->f_owner) {
454 ft1000dev->app_info[i].DspBCMsgFlag = 1;
455 pr_debug("Registered for broadcast messages\n");
456 break;
457 }
458 }
459 }
460 break;
433 461
434 if (ft1000_flarion_cnt == 0) { 462 case IOCTL_GET_VER_CMD:
435 DEBUG("FT1000:ft1000_ioctl called when ft1000_flarion_cnt is zero\n"); 463 pr_debug("IOCTL_FT1000_GET_VER called\n");
436 return (-EBADF);
437 }
438 464
439 /* DEBUG("FT1000:ft1000_ioctl:command = 0x%x argument = 0x%8x\n", command, (u32)argument); */ 465 get_ver_data.drv_ver = FT1000_DRV_VER;
440 466
441 info = file->private_data; 467 if (copy_to_user(argp, &get_ver_data, sizeof(get_ver_data))) {
442 ft1000dev = info->priv; 468 pr_debug("copy fault occurred\n");
443 cmd = _IOC_NR(command); 469 result = -EFAULT;
444 /* DEBUG("FT1000:ft1000_ioctl:cmd = 0x%x\n", cmd); */ 470 break;
445 471 }
446 /* process the command */ 472
447 switch (cmd) { 473 pr_debug("driver version = 0x%x\n",
448 case IOCTL_REGISTER_CMD: 474 (unsigned int)get_ver_data.drv_ver);
449 DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_REGISTER called\n"); 475
450 result = get_user(tempword, (__u16 __user*)argp); 476 break;
451 if (result) { 477 case IOCTL_CONNECT:
452 DEBUG("result = %d failed to get_user\n", result); 478 /* Connect Message */
453 break; 479 pr_debug("IOCTL_FT1000_CONNECT\n");
454 } 480 ConnectionMsg[79] = 0xfc;
455 if (tempword == DSPBCMSGID) { 481 result = card_send_command(ft1000dev, (unsigned short *)ConnectionMsg, 0x4c);
456 /* Search for matching file object */ 482
457 for (i=0; i<MAX_NUM_APP; i++) { 483 break;
458 if (ft1000dev->app_info[i].fileobject == &file->f_owner) { 484 case IOCTL_DISCONNECT:
459 ft1000dev->app_info[i].DspBCMsgFlag = 1; 485 /* Disconnect Message */
460 DEBUG("FT1000:ft1000_ioctl:Registered for broadcast messages\n"); 486 pr_debug("IOCTL_FT1000_DISCONNECT\n");
461 break; 487 ConnectionMsg[79] = 0xfd;
462 } 488 result = card_send_command(ft1000dev, (unsigned short *)ConnectionMsg, 0x4c);
463 } 489 break;
464 } 490 case IOCTL_GET_DSP_STAT_CMD:
465 break; 491 /* pr_debug("IOCTL_FT1000_GET_DSP_STAT\n"); */
466 492 memset(&get_stat_data, 0, sizeof(get_stat_data));
467 case IOCTL_GET_VER_CMD: 493 memcpy(get_stat_data.DspVer, info->DspVer, DSPVERSZ);
468 DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_GET_VER called\n"); 494 memcpy(get_stat_data.HwSerNum, info->HwSerNum, HWSERNUMSZ);
469 495 memcpy(get_stat_data.Sku, info->Sku, SKUSZ);
470 get_ver_data.drv_ver = FT1000_DRV_VER; 496 memcpy(get_stat_data.eui64, info->eui64, EUISZ);
471 497
472 if (copy_to_user(argp, &get_ver_data, sizeof(get_ver_data))) { 498 if (info->ProgConStat != 0xFF) {
473 DEBUG("FT1000:ft1000_ioctl: copy fault occurred\n"); 499 ft1000_read_dpram16(ft1000dev, FT1000_MAG_DSP_LED, (u8 *)&ledStat, FT1000_MAG_DSP_LED_INDX);
474 result = -EFAULT; 500 get_stat_data.LedStat = ntohs(ledStat);
475 break; 501 pr_debug("LedStat = 0x%x\n", get_stat_data.LedStat);
476 } 502 ft1000_read_dpram16(ft1000dev, FT1000_MAG_DSP_CON_STATE, (u8 *)&conStat, FT1000_MAG_DSP_CON_STATE_INDX);
477 503 get_stat_data.ConStat = ntohs(conStat);
478 DEBUG("FT1000:ft1000_ioctl:driver version = 0x%x\n",(unsigned int)get_ver_data.drv_ver); 504 pr_debug("ConStat = 0x%x\n", get_stat_data.ConStat);
479 505 } else {
480 break; 506 get_stat_data.ConStat = 0x0f;
481 case IOCTL_CONNECT: 507 }
482 /* Connect Message */ 508
483 DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_CONNECT\n"); 509
484 ConnectionMsg[79] = 0xfc; 510 get_stat_data.nTxPkts = info->stats.tx_packets;
485 result = card_send_command(ft1000dev, (unsigned short *)ConnectionMsg, 0x4c); 511 get_stat_data.nRxPkts = info->stats.rx_packets;
486 512 get_stat_data.nTxBytes = info->stats.tx_bytes;
487 break; 513 get_stat_data.nRxBytes = info->stats.rx_bytes;
488 case IOCTL_DISCONNECT: 514 do_gettimeofday(&tv);
489 /* Disconnect Message */ 515 get_stat_data.ConTm = (u32)(tv.tv_sec - info->ConTm);
490 DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_DISCONNECT\n"); 516 pr_debug("Connection Time = %d\n", (int)get_stat_data.ConTm);
491 ConnectionMsg[79] = 0xfd; 517 if (copy_to_user(argp, &get_stat_data, sizeof(get_stat_data))) {
492 result = card_send_command(ft1000dev, (unsigned short *)ConnectionMsg, 0x4c); 518 pr_debug("copy fault occurred\n");
493 break; 519 result = -EFAULT;
494 case IOCTL_GET_DSP_STAT_CMD: 520 break;
495 /* DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_GET_DSP_STAT called\n"); */ 521 }
496 memset(&get_stat_data, 0, sizeof(get_stat_data)); 522 pr_debug("GET_DSP_STAT succeed\n");
497 memcpy(get_stat_data.DspVer, info->DspVer, DSPVERSZ); 523 break;
498 memcpy(get_stat_data.HwSerNum, info->HwSerNum, HWSERNUMSZ); 524 case IOCTL_SET_DPRAM_CMD:
499 memcpy(get_stat_data.Sku, info->Sku, SKUSZ); 525 {
500 memcpy(get_stat_data.eui64, info->eui64, EUISZ);
501
502 if (info->ProgConStat != 0xFF) {
503 ft1000_read_dpram16(ft1000dev, FT1000_MAG_DSP_LED, (u8 *)&ledStat, FT1000_MAG_DSP_LED_INDX);
504 get_stat_data.LedStat = ntohs(ledStat);
505 DEBUG("FT1000:ft1000_ioctl: LedStat = 0x%x\n", get_stat_data.LedStat);
506 ft1000_read_dpram16(ft1000dev, FT1000_MAG_DSP_CON_STATE, (u8 *)&conStat, FT1000_MAG_DSP_CON_STATE_INDX);
507 get_stat_data.ConStat = ntohs(conStat);
508 DEBUG("FT1000:ft1000_ioctl: ConStat = 0x%x\n", get_stat_data.ConStat);
509 } else {
510 get_stat_data.ConStat = 0x0f;
511 }
512
513
514 get_stat_data.nTxPkts = info->stats.tx_packets;
515 get_stat_data.nRxPkts = info->stats.rx_packets;
516 get_stat_data.nTxBytes = info->stats.tx_bytes;
517 get_stat_data.nRxBytes = info->stats.rx_bytes;
518 do_gettimeofday(&tv);
519 get_stat_data.ConTm = (u32)(tv.tv_sec - info->ConTm);
520 DEBUG("Connection Time = %d\n", (int)get_stat_data.ConTm);
521 if (copy_to_user(argp, &get_stat_data, sizeof(get_stat_data))) {
522 DEBUG("FT1000:ft1000_ioctl: copy fault occurred\n");
523 result = -EFAULT;
524 break;
525 }
526 DEBUG("ft1000_chioctl: GET_DSP_STAT succeed\n");
527 break;
528 case IOCTL_SET_DPRAM_CMD:
529 {
530 struct IOCTL_DPRAM_BLK *dpram_data = NULL; 526 struct IOCTL_DPRAM_BLK *dpram_data = NULL;
531 /* struct IOCTL_DPRAM_COMMAND dpram_command; */ 527 /* struct IOCTL_DPRAM_COMMAND dpram_command; */
532 u16 qtype; 528 u16 qtype;
533 u16 msgsz; 529 u16 msgsz;
534 struct pseudo_hdr *ppseudo_hdr; 530 struct pseudo_hdr *ppseudo_hdr;
535 u16 *pmsg; 531 u16 *pmsg;
536 u16 total_len; 532 u16 total_len;
537 u16 app_index; 533 u16 app_index;
538 u16 status; 534 u16 status;
539 535
540 /* DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_SET_DPRAM called\n");*/ 536 /* pr_debug("IOCTL_FT1000_SET_DPRAM called\n");*/
541 537
542 538
543 if (ft1000_flarion_cnt == 0) { 539 if (ft1000_flarion_cnt == 0)
544 return (-EBADF); 540 return -EBADF;
545 }
546 541
547 if (ft1000dev->DrvMsgPend) { 542 if (ft1000dev->DrvMsgPend)
548 return (-ENOTTY); 543 return -ENOTTY;
549 }
550 544
551 if (ft1000dev->fProvComplete == 0) { 545 if (ft1000dev->fProvComplete == 0)
552 return (-EACCES); 546 return -EACCES;
553 }
554 547
555 ft1000dev->fAppMsgPend = 1; 548 ft1000dev->fAppMsgPend = 1;
556 549
557 if (info->CardReady) { 550 if (info->CardReady) {
558 551
559 /* DEBUG("FT1000:ft1000_ioctl: try to SET_DPRAM \n"); */ 552 /* pr_debug("try to SET_DPRAM\n"); */
560 553
561 /* Get the length field to see how many bytes to copy */ 554 /* Get the length field to see how many bytes to copy */
562 result = get_user(msgsz, (__u16 __user *)argp); 555 result = get_user(msgsz, (__u16 __user *)argp);
563 if (result) 556 if (result)
564 break; 557 break;
565 msgsz = ntohs(msgsz); 558 msgsz = ntohs(msgsz);
566 /* DEBUG("FT1000:ft1000_ioctl: length of message = %d\n", msgsz); */ 559 /* pr_debug("length of message = %d\n", msgsz); */
567 560
568 if (msgsz > MAX_CMD_SQSIZE) { 561 if (msgsz > MAX_CMD_SQSIZE) {
569 DEBUG("FT1000:ft1000_ioctl: bad message length = %d\n", msgsz); 562 pr_debug("bad message length = %d\n", msgsz);
570 result = -EINVAL; 563 result = -EINVAL;
571 break; 564 break;
572 } 565 }
573
574 result = -ENOMEM;
575 dpram_data = kmalloc(msgsz + 2, GFP_KERNEL);
576 if (!dpram_data)
577 break;
578 566
579 if (copy_from_user(dpram_data, argp, msgsz+2)) { 567 result = -ENOMEM;
580 DEBUG("FT1000:ft1000_ChIoctl: copy fault occurred\n"); 568 dpram_data = kmalloc(msgsz + 2, GFP_KERNEL);
581 result = -EFAULT; 569 if (!dpram_data)
582 } else { 570 break;
583 /* Check if this message came from a registered application */ 571
584 for (i=0; i<MAX_NUM_APP; i++) { 572 if (copy_from_user(dpram_data, argp, msgsz+2)) {
585 if (ft1000dev->app_info[i].fileobject == &file->f_owner) { 573 pr_debug("copy fault occurred\n");
586 break; 574 result = -EFAULT;
587 } 575 } else {
588 } 576 /* Check if this message came from a registered application */
589 if (i==MAX_NUM_APP) { 577 for (i = 0; i < MAX_NUM_APP; i++) {
590 DEBUG("FT1000:No matching application fileobject\n"); 578 if (ft1000dev->app_info[i].fileobject == &file->f_owner) {
591 result = -EINVAL; 579 break;
592 kfree(dpram_data); 580 }
593 break; 581 }
594 } 582 if (i == MAX_NUM_APP) {
595 app_index = i; 583 pr_debug("No matching application fileobject\n");
596 584 result = -EINVAL;
597 /* Check message qtype type which is the lower byte within qos_class */ 585 kfree(dpram_data);
598 qtype = ntohs(dpram_data->pseudohdr.qos_class) & 0xff; 586 break;
599 /* DEBUG("FT1000_ft1000_ioctl: qtype = %d\n", qtype); */ 587 }
600 if (qtype) { 588 app_index = i;
601 } else { 589
602 /* Put message into Slow Queue */ 590 /* Check message qtype type which is the lower byte within qos_class */
603 /* Only put a message into the DPRAM if msg doorbell is available */ 591 qtype = ntohs(dpram_data->pseudohdr.qos_class) & 0xff;
604 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL); 592 /* pr_debug("qtype = %d\n", qtype); */
605 /* DEBUG("FT1000_ft1000_ioctl: READ REGISTER tempword=%x\n", tempword); */ 593 if (qtype) {
606 if (tempword & FT1000_DB_DPRAM_TX) { 594 } else {
607 /* Suspend for 2ms and try again due to DSP doorbell busy */ 595 /* Put message into Slow Queue */
608 mdelay(2); 596 /* Only put a message into the DPRAM if msg doorbell is available */
609 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL); 597 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL);
610 if (tempword & FT1000_DB_DPRAM_TX) { 598 /* pr_debug("READ REGISTER tempword=%x\n", tempword); */
611 /* Suspend for 1ms and try again due to DSP doorbell busy */ 599 if (tempword & FT1000_DB_DPRAM_TX) {
612 mdelay(1); 600 /* Suspend for 2ms and try again due to DSP doorbell busy */
613 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL); 601 mdelay(2);
614 if (tempword & FT1000_DB_DPRAM_TX) { 602 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL);
615 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL); 603 if (tempword & FT1000_DB_DPRAM_TX) {
616 if (tempword & FT1000_DB_DPRAM_TX) { 604 /* Suspend for 1ms and try again due to DSP doorbell busy */
617 /* Suspend for 3ms and try again due to DSP doorbell busy */ 605 mdelay(1);
618 mdelay(3); 606 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL);
619 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL); 607 if (tempword & FT1000_DB_DPRAM_TX) {
620 if (tempword & FT1000_DB_DPRAM_TX) { 608 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL);
621 DEBUG("FT1000:ft1000_ioctl:Doorbell not available\n"); 609 if (tempword & FT1000_DB_DPRAM_TX) {
622 result = -ENOTTY; 610 /* Suspend for 3ms and try again due to DSP doorbell busy */
623 kfree(dpram_data); 611 mdelay(3);
624 break; 612 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL);
625 } 613 if (tempword & FT1000_DB_DPRAM_TX) {
626 } 614 pr_debug("Doorbell not available\n");
627 } 615 result = -ENOTTY;
628 } 616 kfree(dpram_data);
629 } 617 break;
630 618 }
631 /*DEBUG("FT1000_ft1000_ioctl: finished reading register\n"); */ 619 }
632 620 }
633 /* Make sure we are within the limits of the slow queue memory limitation */ 621 }
634 if ((msgsz < MAX_CMD_SQSIZE) && (msgsz > PSEUDOSZ)) { 622 }
635 /* Need to put sequence number plus new checksum for message */ 623
636 pmsg = (u16 *)&dpram_data->pseudohdr; 624 /*pr_debug("finished reading register\n"); */
637 ppseudo_hdr = (struct pseudo_hdr *)pmsg; 625
638 total_len = msgsz+2; 626 /* Make sure we are within the limits of the slow queue memory limitation */
639 if (total_len & 0x1) { 627 if ((msgsz < MAX_CMD_SQSIZE) && (msgsz > PSEUDOSZ)) {
640 total_len++; 628 /* Need to put sequence number plus new checksum for message */
641 } 629 pmsg = (u16 *)&dpram_data->pseudohdr;
642 630 ppseudo_hdr = (struct pseudo_hdr *)pmsg;
643 /* Insert slow queue sequence number */ 631 total_len = msgsz+2;
644 ppseudo_hdr->seq_num = info->squeseqnum++; 632 if (total_len & 0x1) {
645 ppseudo_hdr->portsrc = ft1000dev->app_info[app_index].app_id; 633 total_len++;
646 /* Calculate new checksum */ 634 }
647 ppseudo_hdr->checksum = *pmsg++; 635
648 /* DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum); */ 636 /* Insert slow queue sequence number */
649 for (i=1; i<7; i++) { 637 ppseudo_hdr->seq_num = info->squeseqnum++;
650 ppseudo_hdr->checksum ^= *pmsg++; 638 ppseudo_hdr->portsrc = ft1000dev->app_info[app_index].app_id;
651 /* DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum); */ 639 /* Calculate new checksum */
652 } 640 ppseudo_hdr->checksum = *pmsg++;
653 pmsg++; 641 /* pr_debug("checksum = 0x%x\n", ppseudo_hdr->checksum); */
654 ppseudo_hdr = (struct pseudo_hdr *)pmsg; 642 for (i = 1; i < 7; i++) {
655 result = card_send_command(ft1000dev,(unsigned short*)dpram_data,total_len+2); 643 ppseudo_hdr->checksum ^= *pmsg++;
656 644 /* pr_debug("checksum = 0x%x\n", ppseudo_hdr->checksum); */
657 645 }
658 ft1000dev->app_info[app_index].nTxMsg++; 646 pmsg++;
659 } else { 647 ppseudo_hdr = (struct pseudo_hdr *)pmsg;
660 result = -EINVAL; 648 result = card_send_command(ft1000dev, (unsigned short *)dpram_data, total_len+2);
661 } 649
662 } 650
663 } 651 ft1000dev->app_info[app_index].nTxMsg++;
664 } else { 652 } else {
665 DEBUG("FT1000:ft1000_ioctl: Card not ready take messages\n"); 653 result = -EINVAL;
666 result = -EACCES; 654 }
667 } 655 }
668 kfree(dpram_data); 656 }
669 657 } else {
670 } 658 pr_debug("Card not ready take messages\n");
671 break; 659 result = -EACCES;
672 case IOCTL_GET_DPRAM_CMD: 660 }
673 { 661 kfree(dpram_data);
662
663 }
664 break;
665 case IOCTL_GET_DPRAM_CMD:
666 {
674 struct dpram_blk *pdpram_blk; 667 struct dpram_blk *pdpram_blk;
675 struct IOCTL_DPRAM_BLK __user *pioctl_dpram; 668 struct IOCTL_DPRAM_BLK __user *pioctl_dpram;
676 int msglen; 669 int msglen;
677 670
678 /* DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_GET_DPRAM called\n"); */ 671 /* pr_debug("IOCTL_FT1000_GET_DPRAM called\n"); */
679 672
680 if (ft1000_flarion_cnt == 0) { 673 if (ft1000_flarion_cnt == 0)
681 return (-EBADF); 674 return -EBADF;
682 } 675
683 676 /* Search for matching file object */
684 /* Search for matching file object */ 677 for (i = 0; i < MAX_NUM_APP; i++) {
685 for (i=0; i<MAX_NUM_APP; i++) { 678 if (ft1000dev->app_info[i].fileobject == &file->f_owner) {
686 if (ft1000dev->app_info[i].fileobject == &file->f_owner) { 679 /*pr_debug("Message is for AppId = %d\n", ft1000dev->app_info[i].app_id); */
687 /*DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", ft1000dev->app_info[i].app_id); */ 680 break;
688 break; 681 }
689 } 682 }
690 } 683
691 684 /* Could not find application info block */
692 /* Could not find application info block */ 685 if (i == MAX_NUM_APP) {
693 if (i == MAX_NUM_APP) { 686 pr_debug("Could not find application info block\n");
694 DEBUG("FT1000:ft1000_ioctl:Could not find application info block\n"); 687 result = -EBADF;
695 result = -EBADF;
696 break;
697 }
698
699 result = 0;
700 pioctl_dpram = argp;
701 if (list_empty(&ft1000dev->app_info[i].app_sqlist) == 0) {
702 /* DEBUG("FT1000:ft1000_ioctl:Message detected in slow queue\n"); */
703 spin_lock_irqsave(&free_buff_lock, flags);
704 pdpram_blk = list_entry(ft1000dev->app_info[i].app_sqlist.next, struct dpram_blk, list);
705 list_del(&pdpram_blk->list);
706 ft1000dev->app_info[i].NumOfMsg--;
707 /* DEBUG("FT1000:ft1000_ioctl:NumOfMsg for app %d = %d\n", i, ft1000dev->app_info[i].NumOfMsg); */
708 spin_unlock_irqrestore(&free_buff_lock, flags);
709 msglen = ntohs(*(u16 *)pdpram_blk->pbuffer) + PSEUDOSZ;
710 result = get_user(msglen, &pioctl_dpram->total_len);
711 if (result)
712 break;
713 msglen = htons(msglen);
714 /* DEBUG("FT1000:ft1000_ioctl:msg length = %x\n", msglen); */
715 if (copy_to_user (&pioctl_dpram->pseudohdr, pdpram_blk->pbuffer, msglen)) {
716 DEBUG("FT1000:ft1000_ioctl: copy fault occurred\n");
717 result = -EFAULT;
718 break; 688 break;
719 } 689 }
690
691 result = 0;
692 pioctl_dpram = argp;
693 if (list_empty(&ft1000dev->app_info[i].app_sqlist) == 0) {
694 /* pr_debug("Message detected in slow queue\n"); */
695 spin_lock_irqsave(&free_buff_lock, flags);
696 pdpram_blk = list_entry(ft1000dev->app_info[i].app_sqlist.next, struct dpram_blk, list);
697 list_del(&pdpram_blk->list);
698 ft1000dev->app_info[i].NumOfMsg--;
699 /* pr_debug("NumOfMsg for app %d = %d\n", i, ft1000dev->app_info[i].NumOfMsg); */
700 spin_unlock_irqrestore(&free_buff_lock, flags);
701 msglen = ntohs(*(u16 *)pdpram_blk->pbuffer) + PSEUDOSZ;
702 result = get_user(msglen, &pioctl_dpram->total_len);
703 if (result)
704 break;
705 msglen = htons(msglen);
706 /* pr_debug("msg length = %x\n", msglen); */
707 if (copy_to_user(&pioctl_dpram->pseudohdr, pdpram_blk->pbuffer, msglen)) {
708 pr_debug("copy fault occurred\n");
709 result = -EFAULT;
710 break;
711 }
712
713 ft1000_free_buffer(pdpram_blk, &freercvpool);
714 result = msglen;
715 }
716 /* pr_debug("IOCTL_FT1000_GET_DPRAM no message\n"); */
717 }
718 break;
720 719
721 ft1000_free_buffer(pdpram_blk, &freercvpool); 720 default:
722 result = msglen; 721 pr_debug("unknown command: 0x%x\n", command);
723 } 722 result = -ENOTTY;
724 /* DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_GET_DPRAM no message\n"); */ 723 break;
725 } 724 }
726 break; 725 ft1000dev->fAppMsgPend = 0;
727 726 return result;
728 default:
729 DEBUG("FT1000:ft1000_ioctl:unknown command: 0x%x\n", command);
730 result = -ENOTTY;
731 break;
732 }
733 ft1000dev->fAppMsgPend = 0;
734 return result;
735} 727}
736 728
737/* 729/*
738*--------------------------------------------------------------------------- 730 *---------------------------------------------------------------------------
739* Function: ft1000_release 731 * Function: ft1000_release
740* 732 *
741* Parameters: 733 * Parameters:
742* 734 *
743* Description: 735 * Description:
744* 736 *
745* Notes: 737 * Notes:
746* 738 *
747*--------------------------------------------------------------------------- 739 *---------------------------------------------------------------------------
748*/ 740 */
749static int ft1000_release(struct inode *inode, struct file *file) 741static int ft1000_release(struct inode *inode, struct file *file)
750{ 742{
751 struct ft1000_info *info; 743 struct ft1000_info *info;
752 struct net_device *dev; 744 struct net_device *dev;
753 struct ft1000_usb *ft1000dev; 745 struct ft1000_usb *ft1000dev;
754 int i; 746 int i;
755 struct dpram_blk *pdpram_blk; 747 struct dpram_blk *pdpram_blk;
756 748
757 DEBUG("ft1000_release called\n"); 749 dev = file->private_data;
758
759 dev = file->private_data;
760 info = netdev_priv(dev); 750 info = netdev_priv(dev);
761 ft1000dev = info->priv; 751 ft1000dev = info->priv;
762 752
763 if (ft1000_flarion_cnt == 0) { 753 if (ft1000_flarion_cnt == 0) {
764 ft1000dev->appcnt--; 754 ft1000dev->appcnt--;
765 return (-EBADF); 755 return -EBADF;
766 } 756 }
767 757
768 /* Search for matching file object */ 758 /* Search for matching file object */
769 for (i=0; i<MAX_NUM_APP; i++) { 759 for (i = 0; i < MAX_NUM_APP; i++) {
770 if (ft1000dev->app_info[i].fileobject == &file->f_owner) { 760 if (ft1000dev->app_info[i].fileobject == &file->f_owner) {
771 /* DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", ft1000dev->app_info[i].app_id); */ 761 /* pr_debug("Message is for AppId = %d\n", ft1000dev->app_info[i].app_id); */
772 break; 762 break;
773 } 763 }
774 } 764 }
775 765
776 if (i==MAX_NUM_APP) 766 if (i == MAX_NUM_APP)
777 return 0; 767 return 0;
778 768
779 while (list_empty(&ft1000dev->app_info[i].app_sqlist) == 0) { 769 while (list_empty(&ft1000dev->app_info[i].app_sqlist) == 0) {
780 DEBUG("Remove and free memory queue up on slow queue\n"); 770 pr_debug("Remove and free memory queue up on slow queue\n");
781 pdpram_blk = list_entry(ft1000dev->app_info[i].app_sqlist.next, struct dpram_blk, list); 771 pdpram_blk = list_entry(ft1000dev->app_info[i].app_sqlist.next, struct dpram_blk, list);
782 list_del(&pdpram_blk->list); 772 list_del(&pdpram_blk->list);
783 ft1000_free_buffer(pdpram_blk, &freercvpool); 773 ft1000_free_buffer(pdpram_blk, &freercvpool);
784 } 774 }
785 775
786 /* initialize application information */ 776 /* initialize application information */
787 ft1000dev->appcnt--; 777 ft1000dev->appcnt--;
788 DEBUG("ft1000_chdev:%s:appcnt = %d\n", __func__, ft1000dev->appcnt); 778 pr_debug("appcnt = %d\n", ft1000dev->appcnt);
789 ft1000dev->app_info[i].fileobject = NULL; 779 ft1000dev->app_info[i].fileobject = NULL;
790 780
791 return 0; 781 return 0;
792} 782}
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_download.c b/drivers/staging/ft1000/ft1000-usb/ft1000_download.c
index 37707da09e9c..e8126325877b 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_download.c
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_download.c
@@ -1,8 +1,10 @@
1/* 1/*
2* CopyRight (C) 2007 Qualcomm Inc. All Rights Reserved. 2 * CopyRight (C) 2007 Qualcomm Inc. All Rights Reserved.
3* 3 *
4* This file is part of Express Card USB Driver 4 * This file is part of Express Card USB Driver
5*/ 5 */
6
7#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
6 8
7#include <linux/kernel.h> 9#include <linux/kernel.h>
8#include <linux/module.h> 10#include <linux/module.h>
@@ -117,17 +119,16 @@ static int check_usb_db(struct ft1000_usb *ft1000dev)
117 119
118 while (loopcnt < 10) { 120 while (loopcnt < 10) {
119 status = ft1000_read_register(ft1000dev, &temp, 121 status = ft1000_read_register(ft1000dev, &temp,
120 FT1000_REG_DOORBELL); 122 FT1000_REG_DOORBELL);
121 DEBUG("check_usb_db: read FT1000_REG_DOORBELL value is %x\n", 123 pr_debug("read FT1000_REG_DOORBELL value is %x\n", temp);
122 temp);
123 if (temp & 0x0080) { 124 if (temp & 0x0080) {
124 DEBUG("FT1000:Got checkusb doorbell\n"); 125 pr_debug("Got checkusb doorbell\n");
125 status = ft1000_write_register(ft1000dev, 0x0080, 126 status = ft1000_write_register(ft1000dev, 0x0080,
126 FT1000_REG_DOORBELL); 127 FT1000_REG_DOORBELL);
127 status = ft1000_write_register(ft1000dev, 0x0100, 128 status = ft1000_write_register(ft1000dev, 0x0100,
128 FT1000_REG_DOORBELL); 129 FT1000_REG_DOORBELL);
129 status = ft1000_write_register(ft1000dev, 0x8000, 130 status = ft1000_write_register(ft1000dev, 0x8000,
130 FT1000_REG_DOORBELL); 131 FT1000_REG_DOORBELL);
131 break; 132 break;
132 } 133 }
133 loopcnt++; 134 loopcnt++;
@@ -138,13 +139,13 @@ static int check_usb_db(struct ft1000_usb *ft1000dev)
138 loopcnt = 0; 139 loopcnt = 0;
139 while (loopcnt < 20) { 140 while (loopcnt < 20) {
140 status = ft1000_read_register(ft1000dev, &temp, 141 status = ft1000_read_register(ft1000dev, &temp,
141 FT1000_REG_DOORBELL); 142 FT1000_REG_DOORBELL);
142 DEBUG("FT1000:check_usb_db:Doorbell = 0x%x\n", temp); 143 pr_debug("Doorbell = 0x%x\n", temp);
143 if (temp & 0x8000) { 144 if (temp & 0x8000) {
144 loopcnt++; 145 loopcnt++;
145 msleep(10); 146 msleep(10);
146 } else { 147 } else {
147 DEBUG("check_usb_db: door bell is cleared, return 0\n"); 148 pr_debug("door bell is cleared, return 0\n");
148 return 0; 149 return 0;
149 } 150 }
150 } 151 }
@@ -164,23 +165,22 @@ static u16 get_handshake(struct ft1000_usb *ft1000dev, u16 expected_value)
164 while (loopcnt < 100) { 165 while (loopcnt < 100) {
165 /* Need to clear downloader doorbell if Hartley ASIC */ 166 /* Need to clear downloader doorbell if Hartley ASIC */
166 status = ft1000_write_register(ft1000dev, FT1000_DB_DNLD_RX, 167 status = ft1000_write_register(ft1000dev, FT1000_DB_DNLD_RX,
167 FT1000_REG_DOORBELL); 168 FT1000_REG_DOORBELL);
168 if (ft1000dev->fcodeldr) { 169 if (ft1000dev->fcodeldr) {
169 DEBUG(" get_handshake: fcodeldr is %d\n", 170 pr_debug("fcodeldr is %d\n", ft1000dev->fcodeldr);
170 ft1000dev->fcodeldr);
171 ft1000dev->fcodeldr = 0; 171 ft1000dev->fcodeldr = 0;
172 status = check_usb_db(ft1000dev); 172 status = check_usb_db(ft1000dev);
173 if (status != 0) { 173 if (status != 0) {
174 DEBUG("get_handshake: check_usb_db failed\n"); 174 pr_debug("check_usb_db failed\n");
175 break; 175 break;
176 } 176 }
177 status = ft1000_write_register(ft1000dev, 177 status = ft1000_write_register(ft1000dev,
178 FT1000_DB_DNLD_RX, 178 FT1000_DB_DNLD_RX,
179 FT1000_REG_DOORBELL); 179 FT1000_REG_DOORBELL);
180 } 180 }
181 181
182 status = ft1000_read_dpram16(ft1000dev, 182 status = ft1000_read_dpram16(ft1000dev,
183 DWNLD_MAG1_HANDSHAKE_LOC, (u8 *)&handshake, 1); 183 DWNLD_MAG1_HANDSHAKE_LOC, (u8 *)&handshake, 1);
184 handshake = ntohs(handshake); 184 handshake = ntohs(handshake);
185 185
186 if (status) 186 if (status)
@@ -209,12 +209,12 @@ static void put_handshake(struct ft1000_usb *ft1000dev, u16 handshake_value)
209 209
210 tempword = (u16)(tempx & 0xffff); 210 tempword = (u16)(tempx & 0xffff);
211 status = ft1000_write_dpram16(ft1000dev, DWNLD_MAG1_HANDSHAKE_LOC, 211 status = ft1000_write_dpram16(ft1000dev, DWNLD_MAG1_HANDSHAKE_LOC,
212 tempword, 0); 212 tempword, 0);
213 tempword = (u16)(tempx >> 16); 213 tempword = (u16)(tempx >> 16);
214 status = ft1000_write_dpram16(ft1000dev, DWNLD_MAG1_HANDSHAKE_LOC, 214 status = ft1000_write_dpram16(ft1000dev, DWNLD_MAG1_HANDSHAKE_LOC,
215 tempword, 1); 215 tempword, 1);
216 status = ft1000_write_register(ft1000dev, FT1000_DB_DNLD_TX, 216 status = ft1000_write_register(ft1000dev, FT1000_DB_DNLD_TX,
217 FT1000_REG_DOORBELL); 217 FT1000_REG_DOORBELL);
218} 218}
219 219
220static u16 get_handshake_usb(struct ft1000_usb *ft1000dev, u16 expected_value) 220static u16 get_handshake_usb(struct ft1000_usb *ft1000dev, u16 expected_value)
@@ -230,27 +230,27 @@ static u16 get_handshake_usb(struct ft1000_usb *ft1000dev, u16 expected_value)
230 while (loopcnt < 100) { 230 while (loopcnt < 100) {
231 if (ft1000dev->usbboot == 2) { 231 if (ft1000dev->usbboot == 2) {
232 status = ft1000_read_dpram32(ft1000dev, 0, 232 status = ft1000_read_dpram32(ft1000dev, 0,
233 (u8 *)&(ft1000dev->tempbuf[0]), 64); 233 (u8 *)&(ft1000dev->tempbuf[0]), 64);
234 for (temp = 0; temp < 16; temp++) { 234 for (temp = 0; temp < 16; temp++) {
235 DEBUG("tempbuf %d = 0x%x\n", temp, 235 pr_debug("tempbuf %d = 0x%x\n",
236 ft1000dev->tempbuf[temp]); 236 temp, ft1000dev->tempbuf[temp]);
237 } 237 }
238 status = ft1000_read_dpram16(ft1000dev, 238 status = ft1000_read_dpram16(ft1000dev,
239 DWNLD_MAG1_HANDSHAKE_LOC, 239 DWNLD_MAG1_HANDSHAKE_LOC,
240 (u8 *)&handshake, 1); 240 (u8 *)&handshake, 1);
241 DEBUG("handshake from read_dpram16 = 0x%x\n", 241 pr_debug("handshake from read_dpram16 = 0x%x\n",
242 handshake); 242 handshake);
243 if (ft1000dev->dspalive == ft1000dev->tempbuf[6]) { 243 if (ft1000dev->dspalive == ft1000dev->tempbuf[6]) {
244 handshake = 0; 244 handshake = 0;
245 } else { 245 } else {
246 handshake = ft1000dev->tempbuf[1]; 246 handshake = ft1000dev->tempbuf[1];
247 ft1000dev->dspalive = 247 ft1000dev->dspalive =
248 ft1000dev->tempbuf[6]; 248 ft1000dev->tempbuf[6];
249 } 249 }
250 } else { 250 } else {
251 status = ft1000_read_dpram16(ft1000dev, 251 status = ft1000_read_dpram16(ft1000dev,
252 DWNLD_MAG1_HANDSHAKE_LOC, 252 DWNLD_MAG1_HANDSHAKE_LOC,
253 (u8 *)&handshake, 1); 253 (u8 *)&handshake, 1);
254 } 254 }
255 255
256 loopcnt++; 256 loopcnt++;
@@ -281,12 +281,12 @@ static u16 get_request_type(struct ft1000_usb *ft1000dev)
281 281
282 if (ft1000dev->bootmode == 1) { 282 if (ft1000dev->bootmode == 1) {
283 status = fix_ft1000_read_dpram32(ft1000dev, 283 status = fix_ft1000_read_dpram32(ft1000dev,
284 DWNLD_MAG1_TYPE_LOC, (u8 *)&tempx); 284 DWNLD_MAG1_TYPE_LOC, (u8 *)&tempx);
285 tempx = ntohl(tempx); 285 tempx = ntohl(tempx);
286 } else { 286 } else {
287 tempx = 0; 287 tempx = 0;
288 status = ft1000_read_dpram16(ft1000dev, 288 status = ft1000_read_dpram16(ft1000dev,
289 DWNLD_MAG1_TYPE_LOC, (u8 *)&tempword, 1); 289 DWNLD_MAG1_TYPE_LOC, (u8 *)&tempword, 1);
290 tempx |= (tempword << 16); 290 tempx |= (tempword << 16);
291 tempx = ntohl(tempx); 291 tempx = ntohl(tempx);
292 } 292 }
@@ -304,7 +304,7 @@ static u16 get_request_type_usb(struct ft1000_usb *ft1000dev)
304 304
305 if (ft1000dev->bootmode == 1) { 305 if (ft1000dev->bootmode == 1) {
306 status = fix_ft1000_read_dpram32(ft1000dev, 306 status = fix_ft1000_read_dpram32(ft1000dev,
307 DWNLD_MAG1_TYPE_LOC, (u8 *)&tempx); 307 DWNLD_MAG1_TYPE_LOC, (u8 *)&tempx);
308 tempx = ntohl(tempx); 308 tempx = ntohl(tempx);
309 } else { 309 } else {
310 if (ft1000dev->usbboot == 2) { 310 if (ft1000dev->usbboot == 2) {
@@ -313,8 +313,8 @@ static u16 get_request_type_usb(struct ft1000_usb *ft1000dev)
313 } else { 313 } else {
314 tempx = 0; 314 tempx = 0;
315 status = ft1000_read_dpram16(ft1000dev, 315 status = ft1000_read_dpram16(ft1000dev,
316 DWNLD_MAG1_TYPE_LOC, 316 DWNLD_MAG1_TYPE_LOC,
317 (u8 *)&tempword, 1); 317 (u8 *)&tempword, 1);
318 } 318 }
319 tempx |= (tempword << 16); 319 tempx |= (tempword << 16);
320 tempx = ntohl(tempx); 320 tempx = ntohl(tempx);
@@ -332,14 +332,14 @@ static long get_request_value(struct ft1000_usb *ft1000dev)
332 332
333 if (ft1000dev->bootmode == 1) { 333 if (ft1000dev->bootmode == 1) {
334 status = fix_ft1000_read_dpram32(ft1000dev, 334 status = fix_ft1000_read_dpram32(ft1000dev,
335 DWNLD_MAG1_SIZE_LOC, (u8 *)&value); 335 DWNLD_MAG1_SIZE_LOC, (u8 *)&value);
336 value = ntohl(value); 336 value = ntohl(value);
337 } else { 337 } else {
338 status = ft1000_read_dpram16(ft1000dev, 338 status = ft1000_read_dpram16(ft1000dev,
339 DWNLD_MAG1_SIZE_LOC, (u8 *)&tempword, 0); 339 DWNLD_MAG1_SIZE_LOC, (u8 *)&tempword, 0);
340 value = tempword; 340 value = tempword;
341 status = ft1000_read_dpram16(ft1000dev, 341 status = ft1000_read_dpram16(ft1000dev,
342 DWNLD_MAG1_SIZE_LOC, (u8 *)&tempword, 1); 342 DWNLD_MAG1_SIZE_LOC, (u8 *)&tempword, 1);
343 value |= (tempword << 16); 343 value |= (tempword << 16);
344 value = ntohl(value); 344 value = ntohl(value);
345 } 345 }
@@ -369,7 +369,7 @@ static u16 hdr_checksum(struct pseudo_hdr *pHdr)
369 369
370 370
371 chksum = ((((((usPtr[0] ^ usPtr[1]) ^ usPtr[2]) ^ usPtr[3]) ^ 371 chksum = ((((((usPtr[0] ^ usPtr[1]) ^ usPtr[2]) ^ usPtr[3]) ^
372 usPtr[4]) ^ usPtr[5]) ^ usPtr[6]); 372 usPtr[4]) ^ usPtr[5]) ^ usPtr[6]);
373 373
374 return chksum; 374 return chksum;
375} 375}
@@ -387,7 +387,7 @@ static int check_buffers(u16 *buff_w, u16 *buff_r, int len, int offset)
387} 387}
388 388
389static int write_dpram32_and_check(struct ft1000_usb *ft1000dev, 389static int write_dpram32_and_check(struct ft1000_usb *ft1000dev,
390 u16 tempbuffer[], u16 dpram) 390 u16 tempbuffer[], u16 dpram)
391{ 391{
392 int status; 392 int status;
393 u16 resultbuffer[64]; 393 u16 resultbuffer[64];
@@ -395,38 +395,38 @@ static int write_dpram32_and_check(struct ft1000_usb *ft1000dev,
395 395
396 for (i = 0; i < 10; i++) { 396 for (i = 0; i < 10; i++) {
397 status = ft1000_write_dpram32(ft1000dev, dpram, 397 status = ft1000_write_dpram32(ft1000dev, dpram,
398 (u8 *)&tempbuffer[0], 64); 398 (u8 *)&tempbuffer[0], 64);
399 if (status == 0) { 399 if (status == 0) {
400 /* Work around for ASIC bit stuffing problem. */ 400 /* Work around for ASIC bit stuffing problem. */
401 if ((tempbuffer[31] & 0xfe00) == 0xfe00) { 401 if ((tempbuffer[31] & 0xfe00) == 0xfe00) {
402 status = ft1000_write_dpram32(ft1000dev, 402 status = ft1000_write_dpram32(ft1000dev,
403 dpram+12, (u8 *)&tempbuffer[24], 403 dpram+12, (u8 *)&tempbuffer[24],
404 64); 404 64);
405 } 405 }
406 /* Let's check the data written */ 406 /* Let's check the data written */
407 status = ft1000_read_dpram32(ft1000dev, dpram, 407 status = ft1000_read_dpram32(ft1000dev, dpram,
408 (u8 *)&resultbuffer[0], 64); 408 (u8 *)&resultbuffer[0], 64);
409 if ((tempbuffer[31] & 0xfe00) == 0xfe00) { 409 if ((tempbuffer[31] & 0xfe00) == 0xfe00) {
410 if (check_buffers(tempbuffer, resultbuffer, 28, 410 if (check_buffers(tempbuffer, resultbuffer, 28,
411 0)) { 411 0)) {
412 DEBUG("FT1000:download:DPRAM write failed 1 during bootloading\n"); 412 pr_debug("DPRAM write failed 1 during bootloading\n");
413 usleep_range(9000, 11000); 413 usleep_range(9000, 11000);
414 break; 414 break;
415 } 415 }
416 status = ft1000_read_dpram32(ft1000dev, 416 status = ft1000_read_dpram32(ft1000dev,
417 dpram+12, 417 dpram+12,
418 (u8 *)&resultbuffer[0], 64); 418 (u8 *)&resultbuffer[0], 64);
419 419
420 if (check_buffers(tempbuffer, resultbuffer, 16, 420 if (check_buffers(tempbuffer, resultbuffer, 16,
421 24)) { 421 24)) {
422 DEBUG("FT1000:download:DPRAM write failed 2 during bootloading\n"); 422 pr_debug("DPRAM write failed 2 during bootloading\n");
423 usleep_range(9000, 11000); 423 usleep_range(9000, 11000);
424 break; 424 break;
425 } 425 }
426 } else { 426 } else {
427 if (check_buffers(tempbuffer, resultbuffer, 32, 427 if (check_buffers(tempbuffer, resultbuffer, 32,
428 0)) { 428 0)) {
429 DEBUG("FT1000:download:DPRAM write failed 3 during bootloading\n"); 429 pr_debug("DPRAM write failed 3 during bootloading\n");
430 usleep_range(9000, 11000); 430 usleep_range(9000, 11000);
431 break; 431 break;
432 } 432 }
@@ -445,7 +445,7 @@ static int write_dpram32_and_check(struct ft1000_usb *ft1000dev,
445 * long word_length - length of the buffer to be written to DPRAM 445 * long word_length - length of the buffer to be written to DPRAM
446 */ 446 */
447static int write_blk(struct ft1000_usb *ft1000dev, u16 **pUsFile, u8 **pUcFile, 447static int write_blk(struct ft1000_usb *ft1000dev, u16 **pUsFile, u8 **pUcFile,
448 long word_length) 448 long word_length)
449{ 449{
450 int status = 0; 450 int status = 0;
451 u16 dpram; 451 u16 dpram;
@@ -453,7 +453,7 @@ static int write_blk(struct ft1000_usb *ft1000dev, u16 **pUsFile, u8 **pUcFile,
453 u16 tempword; 453 u16 tempword;
454 u16 tempbuffer[64]; 454 u16 tempbuffer[64];
455 455
456 /*DEBUG("FT1000:download:start word_length = %d\n",(int)word_length); */ 456 /*pr_debug("start word_length = %d\n",(int)word_length); */
457 dpram = (u16)DWNLD_MAG1_PS_HDR_LOC; 457 dpram = (u16)DWNLD_MAG1_PS_HDR_LOC;
458 tempword = *(*pUsFile); 458 tempword = *(*pUsFile);
459 (*pUsFile)++; 459 (*pUsFile)++;
@@ -483,21 +483,22 @@ static int write_blk(struct ft1000_usb *ft1000dev, u16 **pUsFile, u8 **pUcFile,
483 } 483 }
484 } 484 }
485 485
486 /*DEBUG("write_blk: loopcnt is %d\n", loopcnt); */ 486 /*pr_debug("loopcnt is %d\n", loopcnt); */
487 /*DEBUG("write_blk: bootmode = %d\n", bootmode); */ 487 /*pr_debug("write_blk: bootmode = %d\n", bootmode); */
488 /*DEBUG("write_blk: dpram = %x\n", dpram); */ 488 /*pr_debug("write_blk: dpram = %x\n", dpram); */
489 if (ft1000dev->bootmode == 0) { 489 if (ft1000dev->bootmode == 0) {
490 if (dpram >= 0x3F4) 490 if (dpram >= 0x3F4)
491 status = ft1000_write_dpram32(ft1000dev, dpram, 491 status = ft1000_write_dpram32(ft1000dev, dpram,
492 (u8 *)&tempbuffer[0], 8); 492 (u8 *)&tempbuffer[0], 8);
493 else 493 else
494 status = ft1000_write_dpram32(ft1000dev, dpram, 494 status = ft1000_write_dpram32(ft1000dev, dpram,
495 (u8 *)&tempbuffer[0], 64); 495 (u8 *)&tempbuffer[0], 64);
496 } else { 496 } else {
497 status = write_dpram32_and_check(ft1000dev, tempbuffer, 497 status = write_dpram32_and_check(ft1000dev, tempbuffer,
498 dpram); 498 dpram);
499 if (status != 0) { 499 if (status != 0) {
500 DEBUG("FT1000:download:Write failed tempbuffer[31] = 0x%x\n", tempbuffer[31]); 500 pr_debug("Write failed tempbuffer[31] = 0x%x\n",
501 tempbuffer[31]);
501 break; 502 break;
502 } 503 }
503 } 504 }
@@ -508,7 +509,7 @@ static int write_blk(struct ft1000_usb *ft1000dev, u16 **pUsFile, u8 **pUcFile,
508 509
509static void usb_dnld_complete(struct urb *urb) 510static void usb_dnld_complete(struct urb *urb)
510{ 511{
511 /* DEBUG("****** usb_dnld_complete\n"); */ 512 /* pr_debug("****** usb_dnld_complete\n"); */
512} 513}
513 514
514/* writes a block of DSP image to DPRAM 515/* writes a block of DSP image to DPRAM
@@ -548,22 +549,21 @@ static int write_blk_fifo(struct ft1000_usb *ft1000dev, u16 **pUsFile,
548} 549}
549 550
550static int scram_start_dwnld(struct ft1000_usb *ft1000dev, u16 *hshake, 551static int scram_start_dwnld(struct ft1000_usb *ft1000dev, u16 *hshake,
551 u32 *state) 552 u32 *state)
552{ 553{
553 int status = 0; 554 int status = 0;
554 555
555 DEBUG("FT1000:STATE_START_DWNLD\n");
556 if (ft1000dev->usbboot) 556 if (ft1000dev->usbboot)
557 *hshake = get_handshake_usb(ft1000dev, HANDSHAKE_DSP_BL_READY); 557 *hshake = get_handshake_usb(ft1000dev, HANDSHAKE_DSP_BL_READY);
558 else 558 else
559 *hshake = get_handshake(ft1000dev, HANDSHAKE_DSP_BL_READY); 559 *hshake = get_handshake(ft1000dev, HANDSHAKE_DSP_BL_READY);
560 if (*hshake == HANDSHAKE_DSP_BL_READY) { 560 if (*hshake == HANDSHAKE_DSP_BL_READY) {
561 DEBUG("scram_dnldr: handshake is HANDSHAKE_DSP_BL_READY, call put_handshake(HANDSHAKE_DRIVER_READY)\n"); 561 pr_debug("handshake is HANDSHAKE_DSP_BL_READY, call put_handshake(HANDSHAKE_DRIVER_READY)\n");
562 put_handshake(ft1000dev, HANDSHAKE_DRIVER_READY); 562 put_handshake(ft1000dev, HANDSHAKE_DRIVER_READY);
563 } else if (*hshake == HANDSHAKE_TIMEOUT_VALUE) { 563 } else if (*hshake == HANDSHAKE_TIMEOUT_VALUE) {
564 status = -ETIMEDOUT; 564 status = -ETIMEDOUT;
565 } else { 565 } else {
566 DEBUG("FT1000:download:Download error: Handshake failed\n"); 566 pr_debug("Download error: Handshake failed\n");
567 status = -ENETRESET; 567 status = -ENETRESET;
568 } 568 }
569 *state = STATE_BOOT_DWNLD; 569 *state = STATE_BOOT_DWNLD;
@@ -571,22 +571,22 @@ static int scram_start_dwnld(struct ft1000_usb *ft1000dev, u16 *hshake,
571} 571}
572 572
573static int request_code_segment(struct ft1000_usb *ft1000dev, u16 **s_file, 573static int request_code_segment(struct ft1000_usb *ft1000dev, u16 **s_file,
574 u8 **c_file, const u8 *endpoint, bool boot_case) 574 u8 **c_file, const u8 *endpoint, bool boot_case)
575{ 575{
576 long word_length; 576 long word_length;
577 int status = 0; 577 int status = 0;
578 578
579 /*DEBUG("FT1000:REQUEST_CODE_SEGMENT\n");i*/
580 word_length = get_request_value(ft1000dev); 579 word_length = get_request_value(ft1000dev);
581 /*DEBUG("FT1000:word_length = 0x%x\n", (int)word_length); */ 580 /*pr_debug("word_length = 0x%x\n", (int)word_length); */
582 /*NdisMSleep (100); */ 581 /*NdisMSleep (100); */
583 if (word_length > MAX_LENGTH) { 582 if (word_length > MAX_LENGTH) {
584 DEBUG("FT1000:download:Download error: Max length exceeded\n"); 583 pr_debug("Download error: Max length exceeded\n");
585 return -1; 584 return -1;
586 } 585 }
587 if ((word_length * 2 + (long)c_file) > (long)endpoint) { 586 if ((word_length * 2 + (long)c_file) > (long)endpoint) {
588 /* Error, beyond boot code range.*/ 587 /* Error, beyond boot code range.*/
589 DEBUG("FT1000:download:Download error: Requested len=%d exceeds BOOT code boundary.\n", (int)word_length); 588 pr_debug("Download error: Requested len=%d exceeds BOOT code boundary\n",
589 (int)word_length);
590 return -1; 590 return -1;
591 } 591 }
592 if (word_length & 0x1) 592 if (word_length & 0x1)
@@ -595,14 +595,14 @@ static int request_code_segment(struct ft1000_usb *ft1000dev, u16 **s_file,
595 595
596 if (boot_case) { 596 if (boot_case) {
597 status = write_blk(ft1000dev, s_file, c_file, word_length); 597 status = write_blk(ft1000dev, s_file, c_file, word_length);
598 /*DEBUG("write_blk returned %d\n", status); */ 598 /*pr_debug("write_blk returned %d\n", status); */
599 } else { 599 } else {
600 status = write_blk_fifo(ft1000dev, s_file, c_file, word_length); 600 status = write_blk_fifo(ft1000dev, s_file, c_file, word_length);
601 if (ft1000dev->usbboot == 0) 601 if (ft1000dev->usbboot == 0)
602 ft1000dev->usbboot++; 602 ft1000dev->usbboot++;
603 if (ft1000dev->usbboot == 1) 603 if (ft1000dev->usbboot == 1)
604 status |= ft1000_write_dpram16(ft1000dev, 604 status |= ft1000_write_dpram16(ft1000dev,
605 DWNLD_MAG1_PS_HDR_LOC, 0, 0); 605 DWNLD_MAG1_PS_HDR_LOC, 0, 0);
606 } 606 }
607 return status; 607 return status;
608} 608}
@@ -641,8 +641,6 @@ int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart,
641 struct prov_record *pprov_record; 641 struct prov_record *pprov_record;
642 struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net); 642 struct ft1000_info *pft1000info = netdev_priv(ft1000dev->net);
643 643
644 DEBUG("Entered scram_dnldr...\n");
645
646 ft1000dev->fcodeldr = 0; 644 ft1000dev->fcodeldr = 0;
647 ft1000dev->usbboot = 0; 645 ft1000dev->usbboot = 0;
648 ft1000dev->dspalive = 0xffff; 646 ft1000dev->dspalive = 0xffff;
@@ -653,7 +651,7 @@ int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart,
653 651
654 state = STATE_START_DWNLD; 652 state = STATE_START_DWNLD;
655 653
656 file_hdr = (struct dsp_file_hdr *)pFileStart; 654 file_hdr = pFileStart;
657 655
658 ft1000_write_register(ft1000dev, 0x800, FT1000_REG_MAG_WATERMARK); 656 ft1000_write_register(ft1000dev, 0x800, FT1000_REG_MAG_WATERMARK);
659 657
@@ -674,7 +672,7 @@ int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart,
674 break; 672 break;
675 673
676 case STATE_BOOT_DWNLD: 674 case STATE_BOOT_DWNLD:
677 DEBUG("FT1000:STATE_BOOT_DWNLD\n"); 675 pr_debug("STATE_BOOT_DWNLD\n");
678 ft1000dev->bootmode = 1; 676 ft1000dev->bootmode = 1;
679 handshake = get_handshake(ft1000dev, HANDSHAKE_REQUEST); 677 handshake = get_handshake(ft1000dev, HANDSHAKE_REQUEST);
680 if (handshake == HANDSHAKE_REQUEST) { 678 if (handshake == HANDSHAKE_REQUEST) {
@@ -684,35 +682,34 @@ int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart,
684 request = get_request_type(ft1000dev); 682 request = get_request_type(ft1000dev);
685 switch (request) { 683 switch (request) {
686 case REQUEST_RUN_ADDRESS: 684 case REQUEST_RUN_ADDRESS:
687 DEBUG("FT1000:REQUEST_RUN_ADDRESS\n"); 685 pr_debug("REQUEST_RUN_ADDRESS\n");
688 put_request_value(ft1000dev, 686 put_request_value(ft1000dev,
689 loader_code_address); 687 loader_code_address);
690 break; 688 break;
691 case REQUEST_CODE_LENGTH: 689 case REQUEST_CODE_LENGTH:
692 DEBUG("FT1000:REQUEST_CODE_LENGTH\n"); 690 pr_debug("REQUEST_CODE_LENGTH\n");
693 put_request_value(ft1000dev, 691 put_request_value(ft1000dev,
694 loader_code_size); 692 loader_code_size);
695 break; 693 break;
696 case REQUEST_DONE_BL: 694 case REQUEST_DONE_BL:
697 DEBUG("FT1000:REQUEST_DONE_BL\n"); 695 pr_debug("REQUEST_DONE_BL\n");
698 /* Reposition ptrs to beginning of code section */ 696 /* Reposition ptrs to beginning of code section */
699 s_file = (u16 *) (boot_end); 697 s_file = (u16 *) (boot_end);
700 c_file = (u8 *) (boot_end); 698 c_file = (u8 *) (boot_end);
701 /* DEBUG("FT1000:download:s_file = 0x%8x\n", (int)s_file); */ 699 /* pr_debug("download:s_file = 0x%8x\n", (int)s_file); */
702 /* DEBUG("FT1000:download:c_file = 0x%8x\n", (int)c_file); */ 700 /* pr_debug("FT1000:download:c_file = 0x%8x\n", (int)c_file); */
703 state = STATE_CODE_DWNLD; 701 state = STATE_CODE_DWNLD;
704 ft1000dev->fcodeldr = 1; 702 ft1000dev->fcodeldr = 1;
705 break; 703 break;
706 case REQUEST_CODE_SEGMENT: 704 case REQUEST_CODE_SEGMENT:
707 status = request_code_segment(ft1000dev, 705 status = request_code_segment(ft1000dev,
708 &s_file, &c_file, 706 &s_file, &c_file,
709 (const u8 *)boot_end, 707 (const u8 *)boot_end,
710 true); 708 true);
711 break; 709 break;
712 default: 710 default:
713 DEBUG 711 pr_debug("Download error: Bad request type=%d in BOOT download state\n",
714 ("FT1000:download:Download error: Bad request type=%d in BOOT download state.\n", 712 request);
715 request);
716 status = -1; 713 status = -1;
717 break; 714 break;
718 } 715 }
@@ -723,68 +720,60 @@ int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart,
723 put_handshake(ft1000dev, 720 put_handshake(ft1000dev,
724 HANDSHAKE_RESPONSE); 721 HANDSHAKE_RESPONSE);
725 } else { 722 } else {
726 DEBUG 723 pr_debug("Download error: Handshake failed\n");
727 ("FT1000:download:Download error: Handshake failed\n");
728 status = -1; 724 status = -1;
729 } 725 }
730 726
731 break; 727 break;
732 728
733 case STATE_CODE_DWNLD: 729 case STATE_CODE_DWNLD:
734 /* DEBUG("FT1000:STATE_CODE_DWNLD\n"); */ 730 /* pr_debug("STATE_CODE_DWNLD\n"); */
735 ft1000dev->bootmode = 0; 731 ft1000dev->bootmode = 0;
736 if (ft1000dev->usbboot) 732 if (ft1000dev->usbboot)
737 handshake = 733 handshake =
738 get_handshake_usb(ft1000dev, 734 get_handshake_usb(ft1000dev,
739 HANDSHAKE_REQUEST); 735 HANDSHAKE_REQUEST);
740 else 736 else
741 handshake = 737 handshake =
742 get_handshake(ft1000dev, HANDSHAKE_REQUEST); 738 get_handshake(ft1000dev, HANDSHAKE_REQUEST);
743 if (handshake == HANDSHAKE_REQUEST) { 739 if (handshake == HANDSHAKE_REQUEST) {
744 /* 740 /*
745 * Get type associated with the request. 741 * Get type associated with the request.
746 */ 742 */
747 if (ft1000dev->usbboot) 743 if (ft1000dev->usbboot)
748 request = 744 request =
749 get_request_type_usb(ft1000dev); 745 get_request_type_usb(ft1000dev);
750 else 746 else
751 request = get_request_type(ft1000dev); 747 request = get_request_type(ft1000dev);
752 switch (request) { 748 switch (request) {
753 case REQUEST_FILE_CHECKSUM: 749 case REQUEST_FILE_CHECKSUM:
754 DEBUG 750 pr_debug("image_chksum = 0x%8x\n",
755 ("FT1000:download:image_chksum = 0x%8x\n", 751 image_chksum);
756 image_chksum);
757 put_request_value(ft1000dev, 752 put_request_value(ft1000dev,
758 image_chksum); 753 image_chksum);
759 break; 754 break;
760 case REQUEST_RUN_ADDRESS: 755 case REQUEST_RUN_ADDRESS:
761 DEBUG 756 pr_debug("REQUEST_RUN_ADDRESS\n");
762 ("FT1000:download: REQUEST_RUN_ADDRESS\n");
763 if (correct_version) { 757 if (correct_version) {
764 DEBUG 758 pr_debug("run_address = 0x%8x\n",
765 ("FT1000:download:run_address = 0x%8x\n", 759 (int)run_address);
766 (int)run_address);
767 put_request_value(ft1000dev, 760 put_request_value(ft1000dev,
768 run_address); 761 run_address);
769 } else { 762 } else {
770 DEBUG 763 pr_debug("Download error: Got Run address request before image offset request\n");
771 ("FT1000:download:Download error: Got Run address request before image offset request.\n");
772 status = -1; 764 status = -1;
773 break; 765 break;
774 } 766 }
775 break; 767 break;
776 case REQUEST_CODE_LENGTH: 768 case REQUEST_CODE_LENGTH:
777 DEBUG 769 pr_debug("REQUEST_CODE_LENGTH\n");
778 ("FT1000:download:REQUEST_CODE_LENGTH\n");
779 if (correct_version) { 770 if (correct_version) {
780 DEBUG 771 pr_debug("run_size = 0x%8x\n",
781 ("FT1000:download:run_size = 0x%8x\n", 772 (int)run_size);
782 (int)run_size);
783 put_request_value(ft1000dev, 773 put_request_value(ft1000dev,
784 run_size); 774 run_size);
785 } else { 775 } else {
786 DEBUG 776 pr_debug("Download error: Got Size request before image offset request\n");
787 ("FT1000:download:Download error: Got Size request before image offset request.\n");
788 status = -1; 777 status = -1;
789 break; 778 break;
790 } 779 }
@@ -793,69 +782,66 @@ int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart,
793 ft1000dev->usbboot = 3; 782 ft1000dev->usbboot = 3;
794 /* Reposition ptrs to beginning of provisioning section */ 783 /* Reposition ptrs to beginning of provisioning section */
795 s_file = 784 s_file =
796 (u16 *) (pFileStart + 785 (u16 *) (pFileStart +
797 file_hdr->commands_offset); 786 file_hdr->commands_offset);
798 c_file = 787 c_file =
799 (u8 *) (pFileStart + 788 (u8 *) (pFileStart +
800 file_hdr->commands_offset); 789 file_hdr->commands_offset);
801 state = STATE_DONE_DWNLD; 790 state = STATE_DONE_DWNLD;
802 break; 791 break;
803 case REQUEST_CODE_SEGMENT: 792 case REQUEST_CODE_SEGMENT:
804 /* DEBUG("FT1000:download: REQUEST_CODE_SEGMENT - CODELOADER\n"); */ 793 /* pr_debug("REQUEST_CODE_SEGMENT - CODELOADER\n"); */
805 if (!correct_version) { 794 if (!correct_version) {
806 DEBUG 795 pr_debug("Download error: Got Code Segment request before image offset request\n");
807 ("FT1000:download:Download error: Got Code Segment request before image offset request.\n");
808 status = -1; 796 status = -1;
809 break; 797 break;
810 } 798 }
811 799
812 status = request_code_segment(ft1000dev, 800 status = request_code_segment(ft1000dev,
813 &s_file, &c_file, 801 &s_file, &c_file,
814 (const u8 *)code_end, 802 (const u8 *)code_end,
815 false); 803 false);
816 804
817 break; 805 break;
818 806
819 case REQUEST_MAILBOX_DATA: 807 case REQUEST_MAILBOX_DATA:
820 DEBUG 808 pr_debug("REQUEST_MAILBOX_DATA\n");
821 ("FT1000:download: REQUEST_MAILBOX_DATA\n");
822 /* Convert length from byte count to word count. Make sure we round up. */ 809 /* Convert length from byte count to word count. Make sure we round up. */
823 word_length = 810 word_length =
824 (long)(pft1000info->DSPInfoBlklen + 811 (long)(pft1000info->DSPInfoBlklen +
825 1) / 2; 812 1) / 2;
826 put_request_value(ft1000dev, 813 put_request_value(ft1000dev,
827 word_length); 814 word_length);
828 mailbox_data = 815 mailbox_data =
829 (struct drv_msg *)&(pft1000info-> 816 (struct drv_msg *)&(pft1000info->
830 DSPInfoBlk[0]); 817 DSPInfoBlk[0]);
831 /* 818 /*
832 * Position ASIC DPRAM auto-increment pointer. 819 * Position ASIC DPRAM auto-increment pointer.
833 */ 820 */
834 821
835 data = (u16 *) &mailbox_data->data[0]; 822 data = (u16 *)&mailbox_data->data[0];
836 dpram = (u16) DWNLD_MAG1_PS_HDR_LOC; 823 dpram = (u16)DWNLD_MAG1_PS_HDR_LOC;
837 if (word_length & 0x1) 824 if (word_length & 0x1)
838 word_length++; 825 word_length++;
839 826
840 word_length = (word_length / 2); 827 word_length = word_length / 2;
841 828
842 for (; word_length > 0; word_length--) { /* In words */ 829 for (; word_length > 0; word_length--) { /* In words */
843 830
844 templong = *data++; 831 templong = *data++;
845 templong |= (*data++ << 16); 832 templong |= (*data++ << 16);
846 status = 833 status =
847 fix_ft1000_write_dpram32 834 fix_ft1000_write_dpram32
848 (ft1000dev, dpram++, 835 (ft1000dev, dpram++,
849 (u8 *) &templong); 836 (u8 *)&templong);
850 837
851 } 838 }
852 break; 839 break;
853 840
854 case REQUEST_VERSION_INFO: 841 case REQUEST_VERSION_INFO:
855 DEBUG 842 pr_debug("REQUEST_VERSION_INFO\n");
856 ("FT1000:download:REQUEST_VERSION_INFO\n");
857 word_length = 843 word_length =
858 file_hdr->version_data_size; 844 file_hdr->version_data_size;
859 put_request_value(ft1000dev, 845 put_request_value(ft1000dev,
860 word_length); 846 word_length);
861 /* 847 /*
@@ -863,15 +849,15 @@ int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart,
863 */ 849 */
864 850
865 s_file = 851 s_file =
866 (u16 *) (pFileStart + 852 (u16 *) (pFileStart +
867 file_hdr-> 853 file_hdr->
868 version_data_offset); 854 version_data_offset);
869 855
870 dpram = (u16) DWNLD_MAG1_PS_HDR_LOC; 856 dpram = (u16)DWNLD_MAG1_PS_HDR_LOC;
871 if (word_length & 0x1) 857 if (word_length & 0x1)
872 word_length++; 858 word_length++;
873 859
874 word_length = (word_length / 2); 860 word_length = word_length / 2;
875 861
876 for (; word_length > 0; word_length--) { /* In words */ 862 for (; word_length > 0; word_length--) { /* In words */
877 863
@@ -879,26 +865,25 @@ int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart,
879 temp = ntohs(*s_file++); 865 temp = ntohs(*s_file++);
880 templong |= (temp << 16); 866 templong |= (temp << 16);
881 status = 867 status =
882 fix_ft1000_write_dpram32 868 fix_ft1000_write_dpram32
883 (ft1000dev, dpram++, 869 (ft1000dev, dpram++,
884 (u8 *) &templong); 870 (u8 *)&templong);
885 871
886 } 872 }
887 break; 873 break;
888 874
889 case REQUEST_CODE_BY_VERSION: 875 case REQUEST_CODE_BY_VERSION:
890 DEBUG 876 pr_debug("REQUEST_CODE_BY_VERSION\n");
891 ("FT1000:download:REQUEST_CODE_BY_VERSION\n");
892 correct_version = false; 877 correct_version = false;
893 requested_version = 878 requested_version =
894 get_request_value(ft1000dev); 879 get_request_value(ft1000dev);
895 880
896 dsp_img_info = 881 dsp_img_info =
897 (struct dsp_image_info *)(pFileStart 882 (struct dsp_image_info *)(pFileStart
898 + 883 +
899 sizeof 884 sizeof
900 (struct 885 (struct
901 dsp_file_hdr)); 886 dsp_file_hdr));
902 887
903 for (image = 0; 888 for (image = 0;
904 image < file_hdr->nDspImages; 889 image < file_hdr->nDspImages;
@@ -907,30 +892,29 @@ int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart,
907 if (dsp_img_info->version == 892 if (dsp_img_info->version ==
908 requested_version) { 893 requested_version) {
909 correct_version = true; 894 correct_version = true;
910 DEBUG 895 pr_debug("correct_version is TRUE\n");
911 ("FT1000:download: correct_version is TRUE\n");
912 s_file = 896 s_file =
913 (u16 *) (pFileStart 897 (u16 *) (pFileStart
914 + 898 +
915 dsp_img_info-> 899 dsp_img_info->
916 begin_offset); 900 begin_offset);
917 c_file = 901 c_file =
918 (u8 *) (pFileStart + 902 (u8 *) (pFileStart +
919 dsp_img_info-> 903 dsp_img_info->
920 begin_offset); 904 begin_offset);
921 code_end = 905 code_end =
922 (u8 *) (pFileStart + 906 (u8 *) (pFileStart +
923 dsp_img_info-> 907 dsp_img_info->
924 end_offset); 908 end_offset);
925 run_address = 909 run_address =
926 dsp_img_info-> 910 dsp_img_info->
927 run_address; 911 run_address;
928 run_size = 912 run_size =
929 dsp_img_info-> 913 dsp_img_info->
930 image_size; 914 image_size;
931 image_chksum = 915 image_chksum =
932 (u32) dsp_img_info-> 916 (u32)dsp_img_info->
933 checksum; 917 checksum;
934 break; 918 break;
935 } 919 }
936 dsp_img_info++; 920 dsp_img_info++;
@@ -941,18 +925,16 @@ int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart,
941 /* 925 /*
942 * Error, beyond boot code range. 926 * Error, beyond boot code range.
943 */ 927 */
944 DEBUG 928 pr_debug("Download error: Bad Version Request = 0x%x.\n",
945 ("FT1000:download:Download error: Bad Version Request = 0x%x.\n", 929 (int)requested_version);
946 (int)requested_version);
947 status = -1; 930 status = -1;
948 break; 931 break;
949 } 932 }
950 break; 933 break;
951 934
952 default: 935 default:
953 DEBUG 936 pr_debug("Download error: Bad request type=%d in CODE download state.\n",
954 ("FT1000:download:Download error: Bad request type=%d in CODE download state.\n", 937 request);
955 request);
956 status = -1; 938 status = -1;
957 break; 939 break;
958 } 940 }
@@ -963,20 +945,19 @@ int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart,
963 put_handshake(ft1000dev, 945 put_handshake(ft1000dev,
964 HANDSHAKE_RESPONSE); 946 HANDSHAKE_RESPONSE);
965 } else { 947 } else {
966 DEBUG 948 pr_debug("Download error: Handshake failed\n");
967 ("FT1000:download:Download error: Handshake failed\n");
968 status = -1; 949 status = -1;
969 } 950 }
970 951
971 break; 952 break;
972 953
973 case STATE_DONE_DWNLD: 954 case STATE_DONE_DWNLD:
974 DEBUG("FT1000:download:Code loader is done...\n"); 955 pr_debug("Code loader is done...\n");
975 state = STATE_SECTION_PROV; 956 state = STATE_SECTION_PROV;
976 break; 957 break;
977 958
978 case STATE_SECTION_PROV: 959 case STATE_SECTION_PROV:
979 DEBUG("FT1000:download:STATE_SECTION_PROV\n"); 960 pr_debug("STATE_SECTION_PROV\n");
980 pseudo_header = (struct pseudo_hdr *)c_file; 961 pseudo_header = (struct pseudo_hdr *)c_file;
981 962
982 if (pseudo_header->checksum == 963 if (pseudo_header->checksum ==
@@ -990,9 +971,9 @@ int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart,
990 971
991 /* Get buffer for provisioning data */ 972 /* Get buffer for provisioning data */
992 pbuffer = 973 pbuffer =
993 kmalloc((pseudo_header_len + 974 kmalloc((pseudo_header_len +
994 sizeof(struct pseudo_hdr)), 975 sizeof(struct pseudo_hdr)),
995 GFP_ATOMIC); 976 GFP_ATOMIC);
996 if (pbuffer) { 977 if (pbuffer) {
997 memcpy(pbuffer, (void *)c_file, 978 memcpy(pbuffer, (void *)c_file,
998 (u32) (pseudo_header_len + 979 (u32) (pseudo_header_len +
@@ -1000,20 +981,20 @@ int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart,
1000 pseudo_hdr))); 981 pseudo_hdr)));
1001 /* link provisioning data */ 982 /* link provisioning data */
1002 pprov_record = 983 pprov_record =
1003 kmalloc(sizeof(struct prov_record), 984 kmalloc(sizeof(struct prov_record),
1004 GFP_ATOMIC); 985 GFP_ATOMIC);
1005 if (pprov_record) { 986 if (pprov_record) {
1006 pprov_record->pprov_data = 987 pprov_record->pprov_data =
1007 pbuffer; 988 pbuffer;
1008 list_add_tail(&pprov_record-> 989 list_add_tail(&pprov_record->
1009 list, 990 list,
1010 &pft1000info-> 991 &pft1000info->
1011 prov_list); 992 prov_list);
1012 /* Move to next entry if available */ 993 /* Move to next entry if available */
1013 c_file = 994 c_file =
1014 (u8 *) ((unsigned long) 995 (u8 *) ((unsigned long)
1015 c_file + 996 c_file +
1016 (u32) ((pseudo_header_len + 1) & 0xFFFFFFFE) + sizeof(struct pseudo_hdr)); 997 (u32) ((pseudo_header_len + 1) & 0xFFFFFFFE) + sizeof(struct pseudo_hdr));
1017 if ((unsigned long)(c_file) - 998 if ((unsigned long)(c_file) -
1018 (unsigned long)(pFileStart) 999 (unsigned long)(pFileStart)
1019 >= 1000 >=
@@ -1031,13 +1012,12 @@ int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart,
1031 /* Checksum did not compute */ 1012 /* Checksum did not compute */
1032 status = -1; 1013 status = -1;
1033 } 1014 }
1034 DEBUG 1015 pr_debug("after STATE_SECTION_PROV, state = %d, status= %d\n",
1035 ("ft1000:download: after STATE_SECTION_PROV, state = %d, status= %d\n", 1016 state, status);
1036 state, status);
1037 break; 1017 break;
1038 1018
1039 case STATE_DONE_PROV: 1019 case STATE_DONE_PROV:
1040 DEBUG("FT1000:download:STATE_DONE_PROV\n"); 1020 pr_debug("STATE_DONE_PROV\n");
1041 state = STATE_DONE_FILE; 1021 state = STATE_DONE_FILE;
1042 break; 1022 break;
1043 1023
@@ -1050,21 +1030,21 @@ int scram_dnldr(struct ft1000_usb *ft1000dev, void *pFileStart,
1050 break; 1030 break;
1051 1031
1052/**** 1032/****
1053 // Check if Card is present 1033 // Check if Card is present
1054 status = Harley_Read_Register(&temp, FT1000_REG_SUP_IMASK); 1034 status = Harley_Read_Register(&temp, FT1000_REG_SUP_IMASK);
1055 if ( (status != NDIS_STATUS_SUCCESS) || (temp == 0x0000) ) { 1035 if ( (status != NDIS_STATUS_SUCCESS) || (temp == 0x0000) ) {
1056 break; 1036 break;
1057 } 1037 }
1058 1038
1059 status = Harley_Read_Register(&temp, FT1000_REG_ASIC_ID); 1039 status = Harley_Read_Register(&temp, FT1000_REG_ASIC_ID);
1060 if ( (status != NDIS_STATUS_SUCCESS) || (temp == 0xffff) ) { 1040 if ( (status != NDIS_STATUS_SUCCESS) || (temp == 0xffff) ) {
1061 break; 1041 break;
1062 } 1042 }
1063****/ 1043****/
1064 1044
1065 } /* End while */ 1045 } /* End while */
1066 1046
1067 DEBUG("Download exiting with status = 0x%8x\n", status); 1047 pr_debug("Download exiting with status = 0x%8x\n", status);
1068 ft1000_write_register(ft1000dev, FT1000_DB_DNLD_TX, 1048 ft1000_write_register(ft1000dev, FT1000_DB_DNLD_TX,
1069 FT1000_REG_DOORBELL); 1049 FT1000_REG_DOORBELL);
1070 1050
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c
index 2e13e7b7ec10..d12cfc9aa32a 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c
@@ -1,8 +1,10 @@
1/* CopyRight (C) 2007 Qualcomm Inc. All Rights Reserved. 1/* CopyRight (C) 2007 Qualcomm Inc. All Rights Reserved.
2* 2 *
3* 3 *
4* This file is part of Express Card USB Driver 4 * This file is part of Express Card USB Driver
5*/ 5 */
6
7#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
6 8
7#include <linux/kernel.h> 9#include <linux/kernel.h>
8#include <linux/module.h> 10#include <linux/module.h>
@@ -35,16 +37,16 @@ static u8 tempbuffer[1600];
35#define MAX_RCV_LOOP 100 37#define MAX_RCV_LOOP 100
36 38
37/* send a control message via USB interface synchronously 39/* send a control message via USB interface synchronously
38* Parameters: ft1000_usb - device structure 40 * Parameters: ft1000_usb - device structure
39* pipe - usb control message pipe 41 * pipe - usb control message pipe
40* request - control request 42 * request - control request
41* requesttype - control message request type 43 * requesttype - control message request type
42* value - value to be written or 0 44 * value - value to be written or 0
43* index - register index 45 * index - register index
44* data - data buffer to hold the read/write values 46 * data - data buffer to hold the read/write values
45* size - data size 47 * size - data size
46* timeout - control message time out value 48 * timeout - control message time out value
47*/ 49 */
48static int ft1000_control(struct ft1000_usb *ft1000dev, unsigned int pipe, 50static int ft1000_control(struct ft1000_usb *ft1000dev, unsigned int pipe,
49 u8 request, u8 requesttype, u16 value, u16 index, 51 u8 request, u8 requesttype, u16 value, u16 index,
50 void *data, u16 size, int timeout) 52 void *data, u16 size, int timeout)
@@ -52,7 +54,7 @@ static int ft1000_control(struct ft1000_usb *ft1000dev, unsigned int pipe,
52 int ret; 54 int ret;
53 55
54 if ((ft1000dev == NULL) || (ft1000dev->dev == NULL)) { 56 if ((ft1000dev == NULL) || (ft1000dev->dev == NULL)) {
55 DEBUG("ft1000dev or ft1000dev->dev == NULL, failure\n"); 57 pr_debug("ft1000dev or ft1000dev->dev == NULL, failure\n");
56 return -ENODEV; 58 return -ENODEV;
57 } 59 }
58 60
@@ -171,7 +173,7 @@ int ft1000_read_dpram16(struct ft1000_usb *ft1000dev, u16 indx, u8 *buffer,
171 173
172/* write into DPRAM a number of bytes */ 174/* write into DPRAM a number of bytes */
173int ft1000_write_dpram16(struct ft1000_usb *ft1000dev, u16 indx, u16 value, 175int ft1000_write_dpram16(struct ft1000_usb *ft1000dev, u16 indx, u16 value,
174 u8 highlow) 176 u8 highlow)
175{ 177{
176 int ret = 0; 178 int ret = 0;
177 u8 request; 179 u8 request;
@@ -212,7 +214,7 @@ int fix_ft1000_read_dpram32(struct ft1000_usb *ft1000dev, u16 indx,
212 *buffer++ = buf[pos++]; 214 *buffer++ = buf[pos++];
213 *buffer++ = buf[pos++]; 215 *buffer++ = buf[pos++];
214 } else { 216 } else {
215 DEBUG("fix_ft1000_read_dpram32: DPRAM32 Read failed\n"); 217 pr_debug("DPRAM32 Read failed\n");
216 *buffer++ = 0; 218 *buffer++ = 0;
217 *buffer++ = 0; 219 *buffer++ = 0;
218 *buffer++ = 0; 220 *buffer++ = 0;
@@ -246,7 +248,7 @@ int fix_ft1000_write_dpram32(struct ft1000_usb *ft1000dev, u16 indx, u8 *buffer)
246 buf[pos2++] = *buffer++; 248 buf[pos2++] = *buffer++;
247 ret = ft1000_write_dpram32(ft1000dev, pos1, buf, 16); 249 ret = ft1000_write_dpram32(ft1000dev, pos1, buf, 16);
248 } else { 250 } else {
249 DEBUG("fix_ft1000_write_dpram32: DPRAM32 Read failed\n"); 251 pr_debug("DPRAM32 Read failed\n");
250 return ret; 252 return ret;
251 } 253 }
252 254
@@ -270,8 +272,7 @@ int fix_ft1000_write_dpram32(struct ft1000_usb *ft1000dev, u16 indx, u8 *buffer)
270 for (i = 0; i < 16; i++) { 272 for (i = 0; i < 16; i++) {
271 if (tempbuffer[i] != resultbuffer[i]) { 273 if (tempbuffer[i] != resultbuffer[i]) {
272 ret = -1; 274 ret = -1;
273 DEBUG("%s Failed to write\n", 275 pr_debug("Failed to write\n");
274 __func__);
275 } 276 }
276 } 277 }
277 } 278 }
@@ -287,19 +288,19 @@ static void card_reset_dsp(struct ft1000_usb *ft1000dev, bool value)
287 u16 tempword; 288 u16 tempword;
288 289
289 status = ft1000_write_register(ft1000dev, HOST_INTF_BE, 290 status = ft1000_write_register(ft1000dev, HOST_INTF_BE,
290 FT1000_REG_SUP_CTRL); 291 FT1000_REG_SUP_CTRL);
291 status = ft1000_read_register(ft1000dev, &tempword, 292 status = ft1000_read_register(ft1000dev, &tempword,
292 FT1000_REG_SUP_CTRL); 293 FT1000_REG_SUP_CTRL);
293 294
294 if (value) { 295 if (value) {
295 DEBUG("Reset DSP\n"); 296 pr_debug("Reset DSP\n");
296 status = ft1000_read_register(ft1000dev, &tempword, 297 status = ft1000_read_register(ft1000dev, &tempword,
297 FT1000_REG_RESET); 298 FT1000_REG_RESET);
298 tempword |= DSP_RESET_BIT; 299 tempword |= DSP_RESET_BIT;
299 status = ft1000_write_register(ft1000dev, tempword, 300 status = ft1000_write_register(ft1000dev, tempword,
300 FT1000_REG_RESET); 301 FT1000_REG_RESET);
301 } else { 302 } else {
302 DEBUG("Activate DSP\n"); 303 pr_debug("Activate DSP\n");
303 status = ft1000_read_register(ft1000dev, &tempword, 304 status = ft1000_read_register(ft1000dev, &tempword,
304 FT1000_REG_RESET); 305 FT1000_REG_RESET);
305 tempword |= DSP_ENCRYPTED; 306 tempword |= DSP_ENCRYPTED;
@@ -318,18 +319,18 @@ static void card_reset_dsp(struct ft1000_usb *ft1000dev, bool value)
318} 319}
319 320
320/* send a command to ASIC 321/* send a command to ASIC
321* Parameters: ft1000_usb - device structure 322 * Parameters: ft1000_usb - device structure
322* ptempbuffer - command buffer 323 * ptempbuffer - command buffer
323* size - command buffer size 324 * size - command buffer size
324*/ 325 */
325int card_send_command(struct ft1000_usb *ft1000dev, void *ptempbuffer, 326int card_send_command(struct ft1000_usb *ft1000dev, void *ptempbuffer,
326 int size) 327 int size)
327{ 328{
328 int ret; 329 int ret;
329 unsigned short temp; 330 unsigned short temp;
330 unsigned char *commandbuf; 331 unsigned char *commandbuf;
331 332
332 DEBUG("card_send_command: enter card_send_command... size=%d\n", size); 333 pr_debug("enter card_send_command... size=%d\n", size);
333 334
334 commandbuf = kmalloc(size + 2, GFP_KERNEL); 335 commandbuf = kmalloc(size + 2, GFP_KERNEL);
335 if (!commandbuf) 336 if (!commandbuf)
@@ -355,7 +356,7 @@ int card_send_command(struct ft1000_usb *ft1000dev, void *ptempbuffer,
355 return ret; 356 return ret;
356 usleep_range(900, 1100); 357 usleep_range(900, 1100);
357 ret = ft1000_write_register(ft1000dev, FT1000_DB_DPRAM_TX, 358 ret = ft1000_write_register(ft1000dev, FT1000_DB_DPRAM_TX,
358 FT1000_REG_DOORBELL); 359 FT1000_REG_DOORBELL);
359 if (ret) 360 if (ret)
360 return ret; 361 return ret;
361 usleep_range(900, 1100); 362 usleep_range(900, 1100);
@@ -364,7 +365,7 @@ int card_send_command(struct ft1000_usb *ft1000dev, void *ptempbuffer,
364 365
365#if 0 366#if 0
366 if ((temp & 0x0100) == 0) 367 if ((temp & 0x0100) == 0)
367 DEBUG("card_send_command: Message sent\n"); 368 pr_debug("Message sent\n");
368#endif 369#endif
369 return ret; 370 return ret;
370} 371}
@@ -390,7 +391,7 @@ int dsp_reload(struct ft1000_usb *ft1000dev)
390 status = ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET); 391 status = ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
391 msleep(1000); 392 msleep(1000);
392 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET); 393 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
393 DEBUG("Reset Register = 0x%x\n", tempword); 394 pr_debug("Reset Register = 0x%x\n", tempword);
394 395
395 /* Toggle DSP reset */ 396 /* Toggle DSP reset */
396 card_reset_dsp(ft1000dev, 1); 397 card_reset_dsp(ft1000dev, 1);
@@ -399,13 +400,13 @@ int dsp_reload(struct ft1000_usb *ft1000dev)
399 msleep(1000); 400 msleep(1000);
400 401
401 status = 402 status =
402 ft1000_write_register(ft1000dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL); 403 ft1000_write_register(ft1000dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
403 404
404 /* Let's check for FEFE */ 405 /* Let's check for FEFE */
405 status = 406 status =
406 ft1000_read_dpram32(ft1000dev, FT1000_MAG_DPRAM_FEFE_INDX, 407 ft1000_read_dpram32(ft1000dev, FT1000_MAG_DPRAM_FEFE_INDX,
407 (u8 *) &templong, 4); 408 (u8 *)&templong, 4);
408 DEBUG("templong (fefe) = 0x%8x\n", templong); 409 pr_debug("templong (fefe) = 0x%8x\n", templong);
409 410
410 /* call codeloader */ 411 /* call codeloader */
411 status = scram_dnldr(ft1000dev, pFileStart, FileLength); 412 status = scram_dnldr(ft1000dev, pFileStart, FileLength);
@@ -415,8 +416,6 @@ int dsp_reload(struct ft1000_usb *ft1000dev)
415 416
416 msleep(1000); 417 msleep(1000);
417 418
418 DEBUG("dsp_reload returned\n");
419
420 return 0; 419 return 0;
421} 420}
422 421
@@ -427,8 +426,6 @@ static void ft1000_reset_asic(struct net_device *dev)
427 struct ft1000_usb *ft1000dev = info->priv; 426 struct ft1000_usb *ft1000dev = info->priv;
428 u16 tempword; 427 u16 tempword;
429 428
430 DEBUG("ft1000_hw:ft1000_reset_asic called\n");
431
432 /* Let's use the register provided by the Magnemite ASIC to reset the 429 /* Let's use the register provided by the Magnemite ASIC to reset the
433 * ASIC and DSP. 430 * ASIC and DSP.
434 */ 431 */
@@ -442,10 +439,10 @@ static void ft1000_reset_asic(struct net_device *dev)
442 439
443 /* clear interrupts */ 440 /* clear interrupts */
444 ft1000_read_register(ft1000dev, &tempword, FT1000_REG_SUP_ISR); 441 ft1000_read_register(ft1000dev, &tempword, FT1000_REG_SUP_ISR);
445 DEBUG("ft1000_hw: interrupt status register = 0x%x\n", tempword); 442 pr_debug("interrupt status register = 0x%x\n", tempword);
446 ft1000_write_register(ft1000dev, tempword, FT1000_REG_SUP_ISR); 443 ft1000_write_register(ft1000dev, tempword, FT1000_REG_SUP_ISR);
447 ft1000_read_register(ft1000dev, &tempword, FT1000_REG_SUP_ISR); 444 ft1000_read_register(ft1000dev, &tempword, FT1000_REG_SUP_ISR);
448 DEBUG("ft1000_hw: interrupt status register = 0x%x\n", tempword); 445 pr_debug("interrupt status register = 0x%x\n", tempword);
449} 446}
450 447
451static int ft1000_reset_card(struct net_device *dev) 448static int ft1000_reset_card(struct net_device *dev)
@@ -455,38 +452,36 @@ static int ft1000_reset_card(struct net_device *dev)
455 u16 tempword; 452 u16 tempword;
456 struct prov_record *ptr; 453 struct prov_record *ptr;
457 454
458 DEBUG("ft1000_hw:ft1000_reset_card called.....\n");
459
460 ft1000dev->fCondResetPend = true; 455 ft1000dev->fCondResetPend = true;
461 info->CardReady = 0; 456 info->CardReady = 0;
462 ft1000dev->fProvComplete = false; 457 ft1000dev->fProvComplete = false;
463 458
464 /* Make sure we free any memory reserve for provisioning */ 459 /* Make sure we free any memory reserve for provisioning */
465 while (list_empty(&info->prov_list) == 0) { 460 while (list_empty(&info->prov_list) == 0) {
466 DEBUG("ft1000_reset_card:deleting provisioning record\n"); 461 pr_debug("deleting provisioning record\n");
467 ptr = 462 ptr =
468 list_entry(info->prov_list.next, struct prov_record, list); 463 list_entry(info->prov_list.next, struct prov_record, list);
469 list_del(&ptr->list); 464 list_del(&ptr->list);
470 kfree(ptr->pprov_data); 465 kfree(ptr->pprov_data);
471 kfree(ptr); 466 kfree(ptr);
472 } 467 }
473 468
474 DEBUG("ft1000_hw:ft1000_reset_card: reset asic\n"); 469 pr_debug("reset asic\n");
475 ft1000_reset_asic(dev); 470 ft1000_reset_asic(dev);
476 471
477 DEBUG("ft1000_hw:ft1000_reset_card: call dsp_reload\n"); 472 pr_debug("call dsp_reload\n");
478 dsp_reload(ft1000dev); 473 dsp_reload(ft1000dev);
479 474
480 DEBUG("dsp reload successful\n"); 475 pr_debug("dsp reload successful\n");
481 476
482 mdelay(10); 477 mdelay(10);
483 478
484 /* Initialize DSP heartbeat area */ 479 /* Initialize DSP heartbeat area */
485 ft1000_write_dpram16(ft1000dev, FT1000_MAG_HI_HO, ho_mag, 480 ft1000_write_dpram16(ft1000dev, FT1000_MAG_HI_HO, ho_mag,
486 FT1000_MAG_HI_HO_INDX); 481 FT1000_MAG_HI_HO_INDX);
487 ft1000_read_dpram16(ft1000dev, FT1000_MAG_HI_HO, (u8 *) &tempword, 482 ft1000_read_dpram16(ft1000dev, FT1000_MAG_HI_HO, (u8 *)&tempword,
488 FT1000_MAG_HI_HO_INDX); 483 FT1000_MAG_HI_HO_INDX);
489 DEBUG("ft1000_hw:ft1000_reset_card:hi_ho value = 0x%x\n", tempword); 484 pr_debug("hi_ho value = 0x%x\n", tempword);
490 485
491 info->CardReady = 1; 486 info->CardReady = 1;
492 487
@@ -508,8 +503,8 @@ static void ft1000_usb_transmit_complete(struct urb *urb)
508} 503}
509 504
510/* take an ethernet packet and convert it to a Flarion 505/* take an ethernet packet and convert it to a Flarion
511* packet prior to sending it to the ASIC Downlink FIFO. 506 * packet prior to sending it to the ASIC Downlink FIFO.
512*/ 507 */
513static int ft1000_copy_down_pkt(struct net_device *netdev, u8 *packet, u16 len) 508static int ft1000_copy_down_pkt(struct net_device *netdev, u8 *packet, u16 len)
514{ 509{
515 struct ft1000_info *pInfo = netdev_priv(netdev); 510 struct ft1000_info *pInfo = netdev_priv(netdev);
@@ -520,14 +515,13 @@ static int ft1000_copy_down_pkt(struct net_device *netdev, u8 *packet, u16 len)
520 struct pseudo_hdr hdr; 515 struct pseudo_hdr hdr;
521 516
522 if (!pInfo->CardReady) { 517 if (!pInfo->CardReady) {
523 DEBUG("ft1000_copy_down_pkt::Card Not Ready\n"); 518 pr_debug("Card Not Ready\n");
524 return -ENODEV; 519 return -ENODEV;
525 } 520 }
526 521
527 count = sizeof(struct pseudo_hdr) + len; 522 count = sizeof(struct pseudo_hdr) + len;
528 if (count > MAX_BUF_SIZE) { 523 if (count > MAX_BUF_SIZE) {
529 DEBUG("Error:ft1000_copy_down_pkt:Message Size Overflow!\n"); 524 pr_debug("Message Size Overflow! size = %d\n", count);
530 DEBUG("size = %d\n", count);
531 return -EINVAL; 525 return -EINVAL;
532 } 526 }
533 527
@@ -545,7 +539,7 @@ static int ft1000_copy_down_pkt(struct net_device *netdev, u8 *packet, u16 len)
545 hdr.control = 0x00; 539 hdr.control = 0x00;
546 540
547 hdr.checksum = hdr.length ^ hdr.source ^ hdr.destination ^ 541 hdr.checksum = hdr.length ^ hdr.source ^ hdr.destination ^
548 hdr.portdest ^ hdr.portsrc ^ hdr.sh_str_id ^ hdr.control; 542 hdr.portdest ^ hdr.portsrc ^ hdr.sh_str_id ^ hdr.control;
549 543
550 memcpy(&pFt1000Dev->tx_buf[0], &hdr, sizeof(hdr)); 544 memcpy(&pFt1000Dev->tx_buf[0], &hdr, sizeof(hdr));
551 memcpy(&(pFt1000Dev->tx_buf[sizeof(struct pseudo_hdr)]), packet, len); 545 memcpy(&(pFt1000Dev->tx_buf[sizeof(struct pseudo_hdr)]), packet, len);
@@ -559,12 +553,12 @@ static int ft1000_copy_down_pkt(struct net_device *netdev, u8 *packet, u16 len)
559 pFt1000Dev->tx_buf, count, 553 pFt1000Dev->tx_buf, count,
560 ft1000_usb_transmit_complete, (void *)pFt1000Dev); 554 ft1000_usb_transmit_complete, (void *)pFt1000Dev);
561 555
562 t = (u8 *) pFt1000Dev->tx_urb->transfer_buffer; 556 t = (u8 *)pFt1000Dev->tx_urb->transfer_buffer;
563 557
564 ret = usb_submit_urb(pFt1000Dev->tx_urb, GFP_ATOMIC); 558 ret = usb_submit_urb(pFt1000Dev->tx_urb, GFP_ATOMIC);
565 559
566 if (ret) { 560 if (ret) {
567 DEBUG("ft1000 failed tx_urb %d\n", ret); 561 pr_debug("failed tx_urb %d\n", ret);
568 return ret; 562 return ret;
569 } 563 }
570 pInfo->stats.tx_packets++; 564 pInfo->stats.tx_packets++;
@@ -574,9 +568,9 @@ static int ft1000_copy_down_pkt(struct net_device *netdev, u8 *packet, u16 len)
574} 568}
575 569
576/* transmit an ethernet packet 570/* transmit an ethernet packet
577* Parameters: skb - socket buffer to be sent 571 * Parameters: skb - socket buffer to be sent
578* dev - network device 572 * dev - network device
579*/ 573 */
580static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev) 574static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
581{ 575{
582 struct ft1000_info *pInfo = netdev_priv(dev); 576 struct ft1000_info *pInfo = netdev_priv(dev);
@@ -585,30 +579,30 @@ static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
585 int maxlen, pipe; 579 int maxlen, pipe;
586 580
587 if (skb == NULL) { 581 if (skb == NULL) {
588 DEBUG("ft1000_hw: ft1000_start_xmit:skb == NULL!!!\n"); 582 pr_debug("skb == NULL!!!\n");
589 return NETDEV_TX_OK; 583 return NETDEV_TX_OK;
590 } 584 }
591 585
592 if (pFt1000Dev->status & FT1000_STATUS_CLOSING) { 586 if (pFt1000Dev->status & FT1000_STATUS_CLOSING) {
593 DEBUG("network driver is closed, return\n"); 587 pr_debug("network driver is closed, return\n");
594 goto err; 588 goto err;
595 } 589 }
596 590
597 pipe = 591 pipe =
598 usb_sndbulkpipe(pFt1000Dev->dev, pFt1000Dev->bulk_out_endpointAddr); 592 usb_sndbulkpipe(pFt1000Dev->dev, pFt1000Dev->bulk_out_endpointAddr);
599 maxlen = usb_maxpacket(pFt1000Dev->dev, pipe, usb_pipeout(pipe)); 593 maxlen = usb_maxpacket(pFt1000Dev->dev, pipe, usb_pipeout(pipe));
600 594
601 pdata = (u8 *) skb->data; 595 pdata = (u8 *)skb->data;
602 596
603 if (pInfo->mediastate == 0) { 597 if (pInfo->mediastate == 0) {
604 /* Drop packet is mediastate is down */ 598 /* Drop packet is mediastate is down */
605 DEBUG("ft1000_hw:ft1000_start_xmit:mediastate is down\n"); 599 pr_debug("mediastate is down\n");
606 goto err; 600 goto err;
607 } 601 }
608 602
609 if ((skb->len < ENET_HEADER_SIZE) || (skb->len > ENET_MAX_SIZE)) { 603 if ((skb->len < ENET_HEADER_SIZE) || (skb->len > ENET_MAX_SIZE)) {
610 /* Drop packet which has invalid size */ 604 /* Drop packet which has invalid size */
611 DEBUG("ft1000_hw:ft1000_start_xmit:invalid ethernet length\n"); 605 pr_debug("invalid ethernet length\n");
612 goto err; 606 goto err;
613 } 607 }
614 608
@@ -628,7 +622,7 @@ static int ft1000_open(struct net_device *dev)
628 struct ft1000_usb *pFt1000Dev = pInfo->priv; 622 struct ft1000_usb *pFt1000Dev = pInfo->priv;
629 struct timeval tv; 623 struct timeval tv;
630 624
631 DEBUG("ft1000_open is called for card %d\n", pFt1000Dev->CardNumber); 625 pr_debug("ft1000_open is called for card %d\n", pFt1000Dev->CardNumber);
632 626
633 pInfo->stats.rx_bytes = 0; 627 pInfo->stats.rx_bytes = 0;
634 pInfo->stats.tx_bytes = 0; 628 pInfo->stats.tx_bytes = 0;
@@ -676,11 +670,9 @@ int init_ft1000_netdev(struct ft1000_usb *ft1000dev)
676 char card_nr[2]; 670 char card_nr[2];
677 u8 gCardIndex = 0; 671 u8 gCardIndex = 0;
678 672
679 DEBUG("Enter init_ft1000_netdev...\n");
680
681 netdev = alloc_etherdev(sizeof(struct ft1000_info)); 673 netdev = alloc_etherdev(sizeof(struct ft1000_info));
682 if (!netdev) { 674 if (!netdev) {
683 DEBUG("init_ft1000_netdev: can not allocate network device\n"); 675 pr_debug("can not allocate network device\n");
684 return -ENOMEM; 676 return -ENOMEM;
685 } 677 }
686 678
@@ -690,7 +682,7 @@ int init_ft1000_netdev(struct ft1000_usb *ft1000dev)
690 682
691 dev_alloc_name(netdev, netdev->name); 683 dev_alloc_name(netdev, netdev->name);
692 684
693 DEBUG("init_ft1000_netdev: network device name is %s\n", netdev->name); 685 pr_debug("network device name is %s\n", netdev->name);
694 686
695 if (strncmp(netdev->name, "eth", 3) == 0) { 687 if (strncmp(netdev->name, "eth", 3) == 0) {
696 card_nr[0] = netdev->name[3]; 688 card_nr[0] = netdev->name[3];
@@ -702,7 +694,7 @@ int init_ft1000_netdev(struct ft1000_usb *ft1000dev)
702 } 694 }
703 695
704 ft1000dev->CardNumber = gCardIndex; 696 ft1000dev->CardNumber = gCardIndex;
705 DEBUG("card number = %d\n", ft1000dev->CardNumber); 697 pr_debug("card number = %d\n", ft1000dev->CardNumber);
706 } else { 698 } else {
707 netdev_err(ft1000dev->net, "ft1000: Invalid device name\n"); 699 netdev_err(ft1000dev->net, "ft1000: Invalid device name\n");
708 ret_val = -ENXIO; 700 ret_val = -ENXIO;
@@ -738,7 +730,7 @@ int init_ft1000_netdev(struct ft1000_usb *ft1000dev)
738 730
739 ft1000dev->net = netdev; 731 ft1000dev->net = netdev;
740 732
741 DEBUG("Initialize free_buff_lock and freercvpool\n"); 733 pr_debug("Initialize free_buff_lock and freercvpool\n");
742 spin_lock_init(&free_buff_lock); 734 spin_lock_init(&free_buff_lock);
743 735
744 /* initialize a list of buffers to be use for queuing 736 /* initialize a list of buffers to be use for queuing
@@ -790,7 +782,6 @@ int reg_ft1000_netdev(struct ft1000_usb *ft1000dev,
790 782
791 netdev = ft1000dev->net; 783 netdev = ft1000dev->net;
792 pInfo = netdev_priv(ft1000dev->net); 784 pInfo = netdev_priv(ft1000dev->net);
793 DEBUG("Enter reg_ft1000_netdev...\n");
794 785
795 ft1000_read_register(ft1000dev, &pInfo->AsicID, FT1000_REG_ASIC_ID); 786 ft1000_read_register(ft1000dev, &pInfo->AsicID, FT1000_REG_ASIC_ID);
796 787
@@ -799,23 +790,21 @@ int reg_ft1000_netdev(struct ft1000_usb *ft1000dev,
799 790
800 rc = register_netdev(netdev); 791 rc = register_netdev(netdev);
801 if (rc) { 792 if (rc) {
802 DEBUG("reg_ft1000_netdev: could not register network device\n"); 793 pr_debug("could not register network device\n");
803 free_netdev(netdev); 794 free_netdev(netdev);
804 return rc; 795 return rc;
805 } 796 }
806 797
807 ft1000_create_dev(ft1000dev); 798 ft1000_create_dev(ft1000dev);
808 799
809 DEBUG("reg_ft1000_netdev returned\n");
810
811 pInfo->CardReady = 1; 800 pInfo->CardReady = 1;
812 801
813 return 0; 802 return 0;
814} 803}
815 804
816/* take a packet from the FIFO up link and 805/* take a packet from the FIFO up link and
817* convert it into an ethernet packet and deliver it to the IP stack 806 * convert it into an ethernet packet and deliver it to the IP stack
818*/ 807 */
819static int ft1000_copy_up_pkt(struct urb *urb) 808static int ft1000_copy_up_pkt(struct urb *urb)
820{ 809{
821 struct ft1000_info *info = urb->context; 810 struct ft1000_info *info = urb->context;
@@ -832,14 +821,14 @@ static int ft1000_copy_up_pkt(struct urb *urb)
832 u16 *chksum; 821 u16 *chksum;
833 822
834 if (ft1000dev->status & FT1000_STATUS_CLOSING) { 823 if (ft1000dev->status & FT1000_STATUS_CLOSING) {
835 DEBUG("network driver is closed, return\n"); 824 pr_debug("network driver is closed, return\n");
836 return 0; 825 return 0;
837 } 826 }
838 /* Read length */ 827 /* Read length */
839 len = urb->transfer_buffer_length; 828 len = urb->transfer_buffer_length;
840 lena = urb->actual_length; 829 lena = urb->actual_length;
841 830
842 chksum = (u16 *) ft1000dev->rx_buf; 831 chksum = (u16 *)ft1000dev->rx_buf;
843 832
844 tempword = *chksum++; 833 tempword = *chksum++;
845 for (i = 1; i < 7; i++) 834 for (i = 1; i < 7; i++)
@@ -854,13 +843,13 @@ static int ft1000_copy_up_pkt(struct urb *urb)
854 skb = dev_alloc_skb(len + 12 + 2); 843 skb = dev_alloc_skb(len + 12 + 2);
855 844
856 if (skb == NULL) { 845 if (skb == NULL) {
857 DEBUG("ft1000_copy_up_pkt: No Network buffers available\n"); 846 pr_debug("No Network buffers available\n");
858 info->stats.rx_errors++; 847 info->stats.rx_errors++;
859 ft1000_submit_rx_urb(info); 848 ft1000_submit_rx_urb(info);
860 return -1; 849 return -1;
861 } 850 }
862 851
863 pbuffer = (u8 *) skb_put(skb, len + 12); 852 pbuffer = (u8 *)skb_put(skb, len + 12);
864 853
865 /* subtract the number of bytes read already */ 854 /* subtract the number of bytes read already */
866 ptemp = pbuffer; 855 ptemp = pbuffer;
@@ -905,7 +894,7 @@ static int ft1000_submit_rx_urb(struct ft1000_info *info)
905 struct ft1000_usb *pFt1000Dev = info->priv; 894 struct ft1000_usb *pFt1000Dev = info->priv;
906 895
907 if (pFt1000Dev->status & FT1000_STATUS_CLOSING) { 896 if (pFt1000Dev->status & FT1000_STATUS_CLOSING) {
908 DEBUG("network driver is closed, return\n"); 897 pr_debug("network driver is closed, return\n");
909 return -ENODEV; 898 return -ENODEV;
910 } 899 }
911 900
@@ -914,13 +903,12 @@ static int ft1000_submit_rx_urb(struct ft1000_info *info)
914 usb_rcvbulkpipe(pFt1000Dev->dev, 903 usb_rcvbulkpipe(pFt1000Dev->dev,
915 pFt1000Dev->bulk_in_endpointAddr), 904 pFt1000Dev->bulk_in_endpointAddr),
916 pFt1000Dev->rx_buf, MAX_BUF_SIZE, 905 pFt1000Dev->rx_buf, MAX_BUF_SIZE,
917 (usb_complete_t) ft1000_copy_up_pkt, info); 906 (usb_complete_t)ft1000_copy_up_pkt, info);
918 907
919 result = usb_submit_urb(pFt1000Dev->rx_urb, GFP_ATOMIC); 908 result = usb_submit_urb(pFt1000Dev->rx_urb, GFP_ATOMIC);
920 909
921 if (result) { 910 if (result) {
922 pr_err("ft1000_submit_rx_urb: submitting rx_urb %d failed\n", 911 pr_err("submitting rx_urb %d failed\n", result);
923 result);
924 return result; 912 return result;
925 } 913 }
926 914
@@ -935,7 +923,7 @@ int ft1000_close(struct net_device *net)
935 923
936 ft1000dev->status |= FT1000_STATUS_CLOSING; 924 ft1000dev->status |= FT1000_STATUS_CLOSING;
937 925
938 DEBUG("ft1000_close: pInfo=%p, ft1000dev=%p\n", pInfo, ft1000dev); 926 pr_debug("pInfo=%p, ft1000dev=%p\n", pInfo, ft1000dev);
939 netif_carrier_off(net); 927 netif_carrier_off(net);
940 netif_stop_queue(net); 928 netif_stop_queue(net);
941 ft1000dev->status &= ~FT1000_STATUS_CLOSING; 929 ft1000dev->status &= ~FT1000_STATUS_CLOSING;
@@ -952,7 +940,7 @@ static int ft1000_chkcard(struct ft1000_usb *dev)
952 int status; 940 int status;
953 941
954 if (dev->fCondResetPend) { 942 if (dev->fCondResetPend) {
955 DEBUG("ft1000_hw:ft1000_chkcard:Card is being reset, return FALSE\n"); 943 pr_debug("Card is being reset, return FALSE\n");
956 return TRUE; 944 return TRUE;
957 } 945 }
958 /* Mask register is used to check for device presence since it is never 946 /* Mask register is used to check for device presence since it is never
@@ -960,7 +948,7 @@ static int ft1000_chkcard(struct ft1000_usb *dev)
960 */ 948 */
961 status = ft1000_read_register(dev, &tempword, FT1000_REG_SUP_IMASK); 949 status = ft1000_read_register(dev, &tempword, FT1000_REG_SUP_IMASK);
962 if (tempword == 0) { 950 if (tempword == 0) {
963 DEBUG("ft1000_hw:ft1000_chkcard: IMASK = 0 Card not detected\n"); 951 pr_debug("IMASK = 0 Card not detected\n");
964 return FALSE; 952 return FALSE;
965 } 953 }
966 /* The system will return the value of 0xffff for the version register 954 /* The system will return the value of 0xffff for the version register
@@ -969,17 +957,17 @@ static int ft1000_chkcard(struct ft1000_usb *dev)
969 status = ft1000_read_register(dev, &tempword, FT1000_REG_ASIC_ID); 957 status = ft1000_read_register(dev, &tempword, FT1000_REG_ASIC_ID);
970 if (tempword != 0x1b01) { 958 if (tempword != 0x1b01) {
971 dev->status |= FT1000_STATUS_CLOSING; 959 dev->status |= FT1000_STATUS_CLOSING;
972 DEBUG("ft1000_hw:ft1000_chkcard: Version = 0xffff Card not detected\n"); 960 pr_debug("Version = 0xffff Card not detected\n");
973 return FALSE; 961 return FALSE;
974 } 962 }
975 return TRUE; 963 return TRUE;
976} 964}
977 965
978/* read a message from the dpram area. 966/* read a message from the dpram area.
979* Input: 967 * Input:
980* dev - network device structure 968 * dev - network device structure
981* pbuffer - caller supply address to buffer 969 * pbuffer - caller supply address to buffer
982*/ 970 */
983static bool ft1000_receive_cmd(struct ft1000_usb *dev, u16 *pbuffer, 971static bool ft1000_receive_cmd(struct ft1000_usb *dev, u16 *pbuffer,
984 int maxsz) 972 int maxsz)
985{ 973{
@@ -990,46 +978,45 @@ static bool ft1000_receive_cmd(struct ft1000_usb *dev, u16 *pbuffer,
990 u16 tempword; 978 u16 tempword;
991 979
992 ret = 980 ret =
993 ft1000_read_dpram16(dev, FT1000_MAG_PH_LEN, (u8 *) &size, 981 ft1000_read_dpram16(dev, FT1000_MAG_PH_LEN, (u8 *)&size,
994 FT1000_MAG_PH_LEN_INDX); 982 FT1000_MAG_PH_LEN_INDX);
995 size = ntohs(size) + PSEUDOSZ; 983 size = ntohs(size) + PSEUDOSZ;
996 if (size > maxsz) { 984 if (size > maxsz) {
997 DEBUG("FT1000:ft1000_receive_cmd:Invalid command length = %d\n", 985 pr_debug("Invalid command length = %d\n", size);
998 size);
999 return FALSE; 986 return FALSE;
1000 } 987 }
1001 ppseudohdr = (u16 *) pbuffer; 988 ppseudohdr = (u16 *)pbuffer;
1002 ft1000_write_register(dev, FT1000_DPRAM_MAG_RX_BASE, 989 ft1000_write_register(dev, FT1000_DPRAM_MAG_RX_BASE,
1003 FT1000_REG_DPRAM_ADDR); 990 FT1000_REG_DPRAM_ADDR);
1004 ret = 991 ret =
1005 ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH); 992 ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH);
1006 pbuffer++; 993 pbuffer++;
1007 ft1000_write_register(dev, FT1000_DPRAM_MAG_RX_BASE + 1, 994 ft1000_write_register(dev, FT1000_DPRAM_MAG_RX_BASE + 1,
1008 FT1000_REG_DPRAM_ADDR); 995 FT1000_REG_DPRAM_ADDR);
1009 for (i = 0; i <= (size >> 2); i++) { 996 for (i = 0; i <= (size >> 2); i++) {
1010 ret = 997 ret =
1011 ft1000_read_register(dev, pbuffer, 998 ft1000_read_register(dev, pbuffer,
1012 FT1000_REG_MAG_DPDATAL); 999 FT1000_REG_MAG_DPDATAL);
1013 pbuffer++; 1000 pbuffer++;
1014 ret = 1001 ret =
1015 ft1000_read_register(dev, pbuffer, 1002 ft1000_read_register(dev, pbuffer,
1016 FT1000_REG_MAG_DPDATAH); 1003 FT1000_REG_MAG_DPDATAH);
1017 pbuffer++; 1004 pbuffer++;
1018 } 1005 }
1019 /* copy odd aligned word */ 1006 /* copy odd aligned word */
1020 ret = 1007 ret =
1021 ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAL); 1008 ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAL);
1022 1009
1023 pbuffer++; 1010 pbuffer++;
1024 ret = 1011 ret =
1025 ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH); 1012 ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH);
1026 1013
1027 pbuffer++; 1014 pbuffer++;
1028 if (size & 0x0001) { 1015 if (size & 0x0001) {
1029 /* copy odd byte from fifo */ 1016 /* copy odd byte from fifo */
1030 ret = 1017 ret =
1031 ft1000_read_register(dev, &tempword, 1018 ft1000_read_register(dev, &tempword,
1032 FT1000_REG_DPRAM_DATA); 1019 FT1000_REG_DPRAM_DATA);
1033 *pbuffer = ntohs(tempword); 1020 *pbuffer = ntohs(tempword);
1034 } 1021 }
1035 /* Check if pseudo header checksum is good 1022 /* Check if pseudo header checksum is good
@@ -1058,17 +1045,15 @@ static int ft1000_dsp_prov(void *arg)
1058 int status; 1045 int status;
1059 u16 TempShortBuf[256]; 1046 u16 TempShortBuf[256];
1060 1047
1061 DEBUG("*** DspProv Entered\n");
1062
1063 while (list_empty(&info->prov_list) == 0) { 1048 while (list_empty(&info->prov_list) == 0) {
1064 DEBUG("DSP Provisioning List Entry\n"); 1049 pr_debug("DSP Provisioning List Entry\n");
1065 1050
1066 /* Check if doorbell is available */ 1051 /* Check if doorbell is available */
1067 DEBUG("check if doorbell is cleared\n"); 1052 pr_debug("check if doorbell is cleared\n");
1068 status = 1053 status =
1069 ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL); 1054 ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
1070 if (status) { 1055 if (status) {
1071 DEBUG("ft1000_dsp_prov::ft1000_read_register error\n"); 1056 pr_debug("ft1000_read_register error\n");
1072 break; 1057 break;
1073 } 1058 }
1074 1059
@@ -1076,7 +1061,7 @@ static int ft1000_dsp_prov(void *arg)
1076 mdelay(10); 1061 mdelay(10);
1077 i++; 1062 i++;
1078 if (i == 10) { 1063 if (i == 10) {
1079 DEBUG("FT1000:ft1000_dsp_prov:message drop\n"); 1064 pr_debug("message drop\n");
1080 return -1; 1065 return -1;
1081 } 1066 }
1082 ft1000_read_register(dev, &tempword, 1067 ft1000_read_register(dev, &tempword,
@@ -1084,17 +1069,17 @@ static int ft1000_dsp_prov(void *arg)
1084 } 1069 }
1085 1070
1086 if (!(tempword & FT1000_DB_DPRAM_TX)) { 1071 if (!(tempword & FT1000_DB_DPRAM_TX)) {
1087 DEBUG("*** Provision Data Sent to DSP\n"); 1072 pr_debug("*** Provision Data Sent to DSP\n");
1088 1073
1089 /* Send provisioning data */ 1074 /* Send provisioning data */
1090 ptr = 1075 ptr =
1091 list_entry(info->prov_list.next, struct prov_record, 1076 list_entry(info->prov_list.next, struct prov_record,
1092 list); 1077 list);
1093 len = *(u16 *) ptr->pprov_data; 1078 len = *(u16 *)ptr->pprov_data;
1094 len = htons(len); 1079 len = htons(len);
1095 len += PSEUDOSZ; 1080 len += PSEUDOSZ;
1096 1081
1097 pmsg = (u16 *) ptr->pprov_data; 1082 pmsg = (u16 *)ptr->pprov_data;
1098 ppseudo_hdr = (struct pseudo_hdr *)pmsg; 1083 ppseudo_hdr = (struct pseudo_hdr *)pmsg;
1099 /* Insert slow queue sequence number */ 1084 /* Insert slow queue sequence number */
1100 ppseudo_hdr->seq_num = info->squeseqnum++; 1085 ppseudo_hdr->seq_num = info->squeseqnum++;
@@ -1109,12 +1094,12 @@ static int ft1000_dsp_prov(void *arg)
1109 memcpy(&TempShortBuf[2], ppseudo_hdr, len); 1094 memcpy(&TempShortBuf[2], ppseudo_hdr, len);
1110 1095
1111 status = 1096 status =
1112 ft1000_write_dpram32(dev, 0, 1097 ft1000_write_dpram32(dev, 0,
1113 (u8 *) &TempShortBuf[0], 1098 (u8 *)&TempShortBuf[0],
1114 (unsigned short)(len + 2)); 1099 (unsigned short)(len + 2));
1115 status = 1100 status =
1116 ft1000_write_register(dev, FT1000_DB_DPRAM_TX, 1101 ft1000_write_register(dev, FT1000_DB_DPRAM_TX,
1117 FT1000_REG_DOORBELL); 1102 FT1000_REG_DOORBELL);
1118 1103
1119 list_del(&ptr->list); 1104 list_del(&ptr->list);
1120 kfree(ptr->pprov_data); 1105 kfree(ptr->pprov_data);
@@ -1123,7 +1108,7 @@ static int ft1000_dsp_prov(void *arg)
1123 usleep_range(9000, 11000); 1108 usleep_range(9000, 11000);
1124 } 1109 }
1125 1110
1126 DEBUG("DSP Provisioning List Entry finished\n"); 1111 pr_debug("DSP Provisioning List Entry finished\n");
1127 1112
1128 msleep(100); 1113 msleep(100);
1129 1114
@@ -1158,37 +1143,26 @@ static int ft1000_proc_drvmsg(struct ft1000_usb *dev, u16 size)
1158 status = ft1000_read_dpram32(dev, 0x200, cmdbuffer, size); 1143 status = ft1000_read_dpram32(dev, 0x200, cmdbuffer, size);
1159 1144
1160#ifdef JDEBUG 1145#ifdef JDEBUG
1161 DEBUG("ft1000_proc_drvmsg:cmdbuffer\n"); 1146 print_hex_dump_debug("cmdbuffer: ", HEX_DUMP_OFFSET, 16, 1,
1162 for (i = 0; i < size; i += 5) { 1147 cmdbuffer, size, true);
1163 if ((i + 5) < size)
1164 DEBUG("0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n", cmdbuffer[i],
1165 cmdbuffer[i + 1], cmdbuffer[i + 2],
1166 cmdbuffer[i + 3], cmdbuffer[i + 4]);
1167 else {
1168 for (j = i; j < size; j++)
1169 DEBUG("0x%x ", cmdbuffer[j]);
1170 DEBUG("\n");
1171 break;
1172 }
1173 }
1174#endif 1148#endif
1175 pdrvmsg = (struct drv_msg *)&cmdbuffer[2]; 1149 pdrvmsg = (struct drv_msg *)&cmdbuffer[2];
1176 msgtype = ntohs(pdrvmsg->type); 1150 msgtype = ntohs(pdrvmsg->type);
1177 DEBUG("ft1000_proc_drvmsg:Command message type = 0x%x\n", msgtype); 1151 pr_debug("Command message type = 0x%x\n", msgtype);
1178 switch (msgtype) { 1152 switch (msgtype) {
1179 case MEDIA_STATE:{ 1153 case MEDIA_STATE:{
1180 DEBUG("ft1000_proc_drvmsg:Command message type = MEDIA_STATE"); 1154 pr_debug("Command message type = MEDIA_STATE\n");
1181 pmediamsg = (struct media_msg *)&cmdbuffer[0]; 1155 pmediamsg = (struct media_msg *)&cmdbuffer[0];
1182 if (info->ProgConStat != 0xFF) { 1156 if (info->ProgConStat != 0xFF) {
1183 if (pmediamsg->state) { 1157 if (pmediamsg->state) {
1184 DEBUG("Media is up\n"); 1158 pr_debug("Media is up\n");
1185 if (info->mediastate == 0) { 1159 if (info->mediastate == 0) {
1186 if (dev->NetDevRegDone) 1160 if (dev->NetDevRegDone)
1187 netif_wake_queue(dev->net); 1161 netif_wake_queue(dev->net);
1188 info->mediastate = 1; 1162 info->mediastate = 1;
1189 } 1163 }
1190 } else { 1164 } else {
1191 DEBUG("Media is down\n"); 1165 pr_debug("Media is down\n");
1192 if (info->mediastate == 1) { 1166 if (info->mediastate == 1) {
1193 info->mediastate = 0; 1167 info->mediastate = 0;
1194 if (dev->NetDevRegDone) 1168 if (dev->NetDevRegDone)
@@ -1196,7 +1170,7 @@ static int ft1000_proc_drvmsg(struct ft1000_usb *dev, u16 size)
1196 } 1170 }
1197 } 1171 }
1198 } else { 1172 } else {
1199 DEBUG("Media is down\n"); 1173 pr_debug("Media is down\n");
1200 if (info->mediastate == 1) { 1174 if (info->mediastate == 1) {
1201 info->mediastate = 0; 1175 info->mediastate = 0;
1202 info->ConTm = 0; 1176 info->ConTm = 0;
@@ -1205,20 +1179,20 @@ static int ft1000_proc_drvmsg(struct ft1000_usb *dev, u16 size)
1205 break; 1179 break;
1206 } 1180 }
1207 case DSP_INIT_MSG:{ 1181 case DSP_INIT_MSG:{
1208 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_INIT_MSG"); 1182 pr_debug("Command message type = DSP_INIT_MSG\n");
1209 pdspinitmsg = (struct dsp_init_msg *)&cmdbuffer[2]; 1183 pdspinitmsg = (struct dsp_init_msg *)&cmdbuffer[2];
1210 memcpy(info->DspVer, pdspinitmsg->DspVer, DSPVERSZ); 1184 memcpy(info->DspVer, pdspinitmsg->DspVer, DSPVERSZ);
1211 DEBUG("DSPVER = 0x%2x 0x%2x 0x%2x 0x%2x\n", 1185 pr_debug("DSPVER = 0x%2x 0x%2x 0x%2x 0x%2x\n",
1212 info->DspVer[0], info->DspVer[1], info->DspVer[2], 1186 info->DspVer[0], info->DspVer[1], info->DspVer[2],
1213 info->DspVer[3]); 1187 info->DspVer[3]);
1214 memcpy(info->HwSerNum, pdspinitmsg->HwSerNum, 1188 memcpy(info->HwSerNum, pdspinitmsg->HwSerNum,
1215 HWSERNUMSZ); 1189 HWSERNUMSZ);
1216 memcpy(info->Sku, pdspinitmsg->Sku, SKUSZ); 1190 memcpy(info->Sku, pdspinitmsg->Sku, SKUSZ);
1217 memcpy(info->eui64, pdspinitmsg->eui64, EUISZ); 1191 memcpy(info->eui64, pdspinitmsg->eui64, EUISZ);
1218 DEBUG("EUI64=%2x.%2x.%2x.%2x.%2x.%2x.%2x.%2x\n", 1192 pr_debug("EUI64=%2x.%2x.%2x.%2x.%2x.%2x.%2x.%2x\n",
1219 info->eui64[0], info->eui64[1], info->eui64[2], 1193 info->eui64[0], info->eui64[1], info->eui64[2],
1220 info->eui64[3], info->eui64[4], info->eui64[5], 1194 info->eui64[3], info->eui64[4], info->eui64[5],
1221 info->eui64[6], info->eui64[7]); 1195 info->eui64[6], info->eui64[7]);
1222 dev->net->dev_addr[0] = info->eui64[0]; 1196 dev->net->dev_addr[0] = info->eui64[0];
1223 dev->net->dev_addr[1] = info->eui64[1]; 1197 dev->net->dev_addr[1] = info->eui64[1];
1224 dev->net->dev_addr[2] = info->eui64[2]; 1198 dev->net->dev_addr[2] = info->eui64[2];
@@ -1229,17 +1203,17 @@ static int ft1000_proc_drvmsg(struct ft1000_usb *dev, u16 size)
1229 if (ntohs(pdspinitmsg->length) == 1203 if (ntohs(pdspinitmsg->length) ==
1230 (sizeof(struct dsp_init_msg) - 20)) { 1204 (sizeof(struct dsp_init_msg) - 20)) {
1231 memcpy(info->ProductMode, pdspinitmsg->ProductMode, 1205 memcpy(info->ProductMode, pdspinitmsg->ProductMode,
1232 MODESZ); 1206 MODESZ);
1233 memcpy(info->RfCalVer, pdspinitmsg->RfCalVer, CALVERSZ); 1207 memcpy(info->RfCalVer, pdspinitmsg->RfCalVer, CALVERSZ);
1234 memcpy(info->RfCalDate, pdspinitmsg->RfCalDate, 1208 memcpy(info->RfCalDate, pdspinitmsg->RfCalDate,
1235 CALDATESZ); 1209 CALDATESZ);
1236 DEBUG("RFCalVer = 0x%2x 0x%2x\n", info->RfCalVer[0], 1210 pr_debug("RFCalVer = 0x%2x 0x%2x\n",
1237 info->RfCalVer[1]); 1211 info->RfCalVer[0], info->RfCalVer[1]);
1238 } 1212 }
1239 break; 1213 break;
1240 } 1214 }
1241 case DSP_PROVISION:{ 1215 case DSP_PROVISION:{
1242 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_PROVISION\n"); 1216 pr_debug("Command message type = DSP_PROVISION\n");
1243 1217
1244 /* kick off dspprov routine to start provisioning 1218 /* kick off dspprov routine to start provisioning
1245 * Send provisioning data to DSP 1219 * Send provisioning data to DSP
@@ -1252,21 +1226,20 @@ static int ft1000_proc_drvmsg(struct ft1000_usb *dev, u16 size)
1252 } else { 1226 } else {
1253 dev->fProvComplete = true; 1227 dev->fProvComplete = true;
1254 status = ft1000_write_register(dev, FT1000_DB_HB, 1228 status = ft1000_write_register(dev, FT1000_DB_HB,
1255 FT1000_REG_DOORBELL); 1229 FT1000_REG_DOORBELL);
1256 DEBUG("FT1000:drivermsg:No more DSP provisioning data in dsp image\n"); 1230 pr_debug("No more DSP provisioning data in dsp image\n");
1257 } 1231 }
1258 DEBUG("ft1000_proc_drvmsg:DSP PROVISION is done\n"); 1232 pr_debug("DSP PROVISION is done\n");
1259 break; 1233 break;
1260 } 1234 }
1261 case DSP_STORE_INFO:{ 1235 case DSP_STORE_INFO:{
1262 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_STORE_INFO"); 1236 pr_debug("Command message type = DSP_STORE_INFO");
1263 DEBUG("FT1000:drivermsg:Got DSP_STORE_INFO\n");
1264 tempword = ntohs(pdrvmsg->length); 1237 tempword = ntohs(pdrvmsg->length);
1265 info->DSPInfoBlklen = tempword; 1238 info->DSPInfoBlklen = tempword;
1266 if (tempword < (MAX_DSP_SESS_REC - 4)) { 1239 if (tempword < (MAX_DSP_SESS_REC - 4)) {
1267 pmsg = (u16 *) &pdrvmsg->data[0]; 1240 pmsg = (u16 *)&pdrvmsg->data[0];
1268 for (i = 0; i < ((tempword + 1) / 2); i++) { 1241 for (i = 0; i < ((tempword + 1) / 2); i++) {
1269 DEBUG("FT1000:drivermsg:dsp info data = 0x%x\n", *pmsg); 1242 pr_debug("dsp info data = 0x%x\n", *pmsg);
1270 info->DSPInfoBlk[i + 10] = *pmsg++; 1243 info->DSPInfoBlk[i + 10] = *pmsg++;
1271 } 1244 }
1272 } else { 1245 } else {
@@ -1275,33 +1248,33 @@ static int ft1000_proc_drvmsg(struct ft1000_usb *dev, u16 size)
1275 break; 1248 break;
1276 } 1249 }
1277 case DSP_GET_INFO:{ 1250 case DSP_GET_INFO:{
1278 DEBUG("FT1000:drivermsg:Got DSP_GET_INFO\n"); 1251 pr_debug("Got DSP_GET_INFO\n");
1279 /* copy dsp info block to dsp */ 1252 /* copy dsp info block to dsp */
1280 dev->DrvMsgPend = 1; 1253 dev->DrvMsgPend = 1;
1281 /* allow any outstanding ioctl to finish */ 1254 /* allow any outstanding ioctl to finish */
1282 mdelay(10); 1255 mdelay(10);
1283 status = ft1000_read_register(dev, &tempword, 1256 status = ft1000_read_register(dev, &tempword,
1284 FT1000_REG_DOORBELL); 1257 FT1000_REG_DOORBELL);
1285 if (tempword & FT1000_DB_DPRAM_TX) { 1258 if (tempword & FT1000_DB_DPRAM_TX) {
1286 mdelay(10); 1259 mdelay(10);
1287 status = ft1000_read_register(dev, &tempword, 1260 status = ft1000_read_register(dev, &tempword,
1288 FT1000_REG_DOORBELL); 1261 FT1000_REG_DOORBELL);
1289 if (tempword & FT1000_DB_DPRAM_TX) { 1262 if (tempword & FT1000_DB_DPRAM_TX) {
1290 mdelay(10); 1263 mdelay(10);
1291 status = ft1000_read_register(dev, &tempword, 1264 status = ft1000_read_register(dev, &tempword,
1292 FT1000_REG_DOORBELL); 1265 FT1000_REG_DOORBELL);
1293 if (tempword & FT1000_DB_DPRAM_TX) 1266 if (tempword & FT1000_DB_DPRAM_TX)
1294 break; 1267 break;
1295 } 1268 }
1296 } 1269 }
1297 /* Put message into Slow Queue Form Pseudo header */ 1270 /* Put message into Slow Queue Form Pseudo header */
1298 pmsg = (u16 *) info->DSPInfoBlk; 1271 pmsg = (u16 *)info->DSPInfoBlk;
1299 *pmsg++ = 0; 1272 *pmsg++ = 0;
1300 *pmsg++ = htons(info->DSPInfoBlklen + 20 + info->DSPInfoBlklen); 1273 *pmsg++ = htons(info->DSPInfoBlklen + 20 + info->DSPInfoBlklen);
1301 ppseudo_hdr = 1274 ppseudo_hdr =
1302 (struct pseudo_hdr *)(u16 *) &info->DSPInfoBlk[2]; 1275 (struct pseudo_hdr *)(u16 *)&info->DSPInfoBlk[2];
1303 ppseudo_hdr->length = htons(info->DSPInfoBlklen + 4 1276 ppseudo_hdr->length = htons(info->DSPInfoBlklen + 4
1304 + info->DSPInfoBlklen); 1277 + info->DSPInfoBlklen);
1305 ppseudo_hdr->source = 0x10; 1278 ppseudo_hdr->source = 0x10;
1306 ppseudo_hdr->destination = 0x20; 1279 ppseudo_hdr->destination = 0x20;
1307 ppseudo_hdr->portdest = 0; 1280 ppseudo_hdr->portdest = 0;
@@ -1323,31 +1296,31 @@ static int ft1000_proc_drvmsg(struct ft1000_usb *dev, u16 size)
1323 info->DSPInfoBlk[10] = 0x7200; 1296 info->DSPInfoBlk[10] = 0x7200;
1324 info->DSPInfoBlk[11] = htons(info->DSPInfoBlklen); 1297 info->DSPInfoBlk[11] = htons(info->DSPInfoBlklen);
1325 status = ft1000_write_dpram32(dev, 0, 1298 status = ft1000_write_dpram32(dev, 0,
1326 (u8 *)&info->DSPInfoBlk[0], 1299 (u8 *)&info->DSPInfoBlk[0],
1327 (unsigned short)(info->DSPInfoBlklen + 22)); 1300 (unsigned short)(info->DSPInfoBlklen + 22));
1328 status = ft1000_write_register(dev, FT1000_DB_DPRAM_TX, 1301 status = ft1000_write_register(dev, FT1000_DB_DPRAM_TX,
1329 FT1000_REG_DOORBELL); 1302 FT1000_REG_DOORBELL);
1330 dev->DrvMsgPend = 0; 1303 dev->DrvMsgPend = 0;
1331 break; 1304 break;
1332 } 1305 }
1333 case GET_DRV_ERR_RPT_MSG:{ 1306 case GET_DRV_ERR_RPT_MSG:{
1334 DEBUG("FT1000:drivermsg:Got GET_DRV_ERR_RPT_MSG\n"); 1307 pr_debug("Got GET_DRV_ERR_RPT_MSG\n");
1335 /* copy driver error message to dsp */ 1308 /* copy driver error message to dsp */
1336 dev->DrvMsgPend = 1; 1309 dev->DrvMsgPend = 1;
1337 /* allow any outstanding ioctl to finish */ 1310 /* allow any outstanding ioctl to finish */
1338 mdelay(10); 1311 mdelay(10);
1339 status = ft1000_read_register(dev, &tempword, 1312 status = ft1000_read_register(dev, &tempword,
1340 FT1000_REG_DOORBELL); 1313 FT1000_REG_DOORBELL);
1341 if (tempword & FT1000_DB_DPRAM_TX) { 1314 if (tempword & FT1000_DB_DPRAM_TX) {
1342 mdelay(10); 1315 mdelay(10);
1343 status = ft1000_read_register(dev, &tempword, 1316 status = ft1000_read_register(dev, &tempword,
1344 FT1000_REG_DOORBELL); 1317 FT1000_REG_DOORBELL);
1345 if (tempword & FT1000_DB_DPRAM_TX) 1318 if (tempword & FT1000_DB_DPRAM_TX)
1346 mdelay(10); 1319 mdelay(10);
1347 } 1320 }
1348 if ((tempword & FT1000_DB_DPRAM_TX) == 0) { 1321 if ((tempword & FT1000_DB_DPRAM_TX) == 0) {
1349 /* Put message into Slow Queue Form Pseudo header */ 1322 /* Put message into Slow Queue Form Pseudo header */
1350 pmsg = (u16 *) &tempbuffer[0]; 1323 pmsg = (u16 *)&tempbuffer[0];
1351 ppseudo_hdr = (struct pseudo_hdr *)pmsg; 1324 ppseudo_hdr = (struct pseudo_hdr *)pmsg;
1352 ppseudo_hdr->length = htons(0x0012); 1325 ppseudo_hdr->length = htons(0x0012);
1353 ppseudo_hdr->source = 0x10; 1326 ppseudo_hdr->source = 0x10;
@@ -1368,7 +1341,7 @@ static int ft1000_proc_drvmsg(struct ft1000_usb *dev, u16 size)
1368 for (i = 1; i < 7; i++) 1341 for (i = 1; i < 7; i++)
1369 ppseudo_hdr->checksum ^= *pmsg++; 1342 ppseudo_hdr->checksum ^= *pmsg++;
1370 1343
1371 pmsg = (u16 *) &tempbuffer[16]; 1344 pmsg = (u16 *)&tempbuffer[16];
1372 *pmsg++ = htons(RSP_DRV_ERR_RPT_MSG); 1345 *pmsg++ = htons(RSP_DRV_ERR_RPT_MSG);
1373 *pmsg++ = htons(0x000e); 1346 *pmsg++ = htons(0x000e);
1374 *pmsg++ = htons(info->DSP_TIME[0]); 1347 *pmsg++ = htons(info->DSP_TIME[0]);
@@ -1384,7 +1357,7 @@ static int ft1000_proc_drvmsg(struct ft1000_usb *dev, u16 size)
1384 *pmsg++ = htons(info->DrvErrNum); 1357 *pmsg++ = htons(info->DrvErrNum);
1385 1358
1386 status = card_send_command(dev, (unsigned char *)&tempbuffer[0], 1359 status = card_send_command(dev, (unsigned char *)&tempbuffer[0],
1387 (u16)(0x0012 + PSEUDOSZ)); 1360 (u16)(0x0012 + PSEUDOSZ));
1388 if (status) 1361 if (status)
1389 goto out; 1362 goto out;
1390 info->DrvErrNum = 0; 1363 info->DrvErrNum = 0;
@@ -1399,7 +1372,6 @@ static int ft1000_proc_drvmsg(struct ft1000_usb *dev, u16 size)
1399 status = 0; 1372 status = 0;
1400out: 1373out:
1401 kfree(cmdbuffer); 1374 kfree(cmdbuffer);
1402 DEBUG("return from ft1000_proc_drvmsg\n");
1403 return status; 1375 return status;
1404} 1376}
1405 1377
@@ -1412,32 +1384,32 @@ static int dsp_broadcast_msg_id(struct ft1000_usb *dev)
1412 1384
1413 for (i = 0; i < MAX_NUM_APP; i++) { 1385 for (i = 0; i < MAX_NUM_APP; i++) {
1414 if ((dev->app_info[i].DspBCMsgFlag) 1386 if ((dev->app_info[i].DspBCMsgFlag)
1415 && (dev->app_info[i].fileobject) 1387 && (dev->app_info[i].fileobject)
1416 && (dev->app_info[i].NumOfMsg 1388 && (dev->app_info[i].NumOfMsg
1417 < MAX_MSG_LIMIT)) { 1389 < MAX_MSG_LIMIT)) {
1418 pdpram_blk = ft1000_get_buffer(&freercvpool); 1390 pdpram_blk = ft1000_get_buffer(&freercvpool);
1419 if (pdpram_blk == NULL) { 1391 if (pdpram_blk == NULL) {
1420 DEBUG("Out of memory in free receive command pool\n"); 1392 pr_debug("Out of memory in free receive command pool\n");
1421 dev->app_info[i].nRxMsgMiss++; 1393 dev->app_info[i].nRxMsgMiss++;
1422 return -1; 1394 return -1;
1423 } 1395 }
1424 if (ft1000_receive_cmd(dev, pdpram_blk->pbuffer, 1396 if (ft1000_receive_cmd(dev, pdpram_blk->pbuffer,
1425 MAX_CMD_SQSIZE)) { 1397 MAX_CMD_SQSIZE)) {
1426 /* Put message into the 1398 /* Put message into the
1427 * appropriate application block 1399 * appropriate application block
1428 */ 1400 */
1429 dev->app_info[i].nRxMsg++; 1401 dev->app_info[i].nRxMsg++;
1430 spin_lock_irqsave(&free_buff_lock, flags); 1402 spin_lock_irqsave(&free_buff_lock, flags);
1431 list_add_tail(&pdpram_blk->list, 1403 list_add_tail(&pdpram_blk->list,
1432 &dev->app_info[i] .app_sqlist); 1404 &dev->app_info[i] .app_sqlist);
1433 dev->app_info[i].NumOfMsg++; 1405 dev->app_info[i].NumOfMsg++;
1434 spin_unlock_irqrestore(&free_buff_lock, flags); 1406 spin_unlock_irqrestore(&free_buff_lock, flags);
1435 wake_up_interruptible(&dev->app_info[i] 1407 wake_up_interruptible(&dev->app_info[i]
1436 .wait_dpram_msg); 1408 .wait_dpram_msg);
1437 } else { 1409 } else {
1438 dev->app_info[i].nRxMsgMiss++; 1410 dev->app_info[i].nRxMsgMiss++;
1439 ft1000_free_buffer(pdpram_blk, &freercvpool); 1411 ft1000_free_buffer(pdpram_blk, &freercvpool);
1440 DEBUG("pdpram_blk::ft1000_get_buffer NULL\n"); 1412 pr_debug("ft1000_get_buffer NULL\n");
1441 return -1; 1413 return -1;
1442 } 1414 }
1443 } 1415 }
@@ -1452,7 +1424,7 @@ static int handle_misc_portid(struct ft1000_usb *dev)
1452 1424
1453 pdpram_blk = ft1000_get_buffer(&freercvpool); 1425 pdpram_blk = ft1000_get_buffer(&freercvpool);
1454 if (pdpram_blk == NULL) { 1426 if (pdpram_blk == NULL) {
1455 DEBUG("Out of memory in free receive command pool\n"); 1427 pr_debug("Out of memory in free receive command pool\n");
1456 return -1; 1428 return -1;
1457 } 1429 }
1458 if (!ft1000_receive_cmd(dev, pdpram_blk->pbuffer, MAX_CMD_SQSIZE)) 1430 if (!ft1000_receive_cmd(dev, pdpram_blk->pbuffer, MAX_CMD_SQSIZE))
@@ -1461,11 +1433,12 @@ static int handle_misc_portid(struct ft1000_usb *dev)
1461 /* Search for correct application block */ 1433 /* Search for correct application block */
1462 for (i = 0; i < MAX_NUM_APP; i++) { 1434 for (i = 0; i < MAX_NUM_APP; i++) {
1463 if (dev->app_info[i].app_id == ((struct pseudo_hdr *) 1435 if (dev->app_info[i].app_id == ((struct pseudo_hdr *)
1464 pdpram_blk->pbuffer)->portdest) 1436 pdpram_blk->pbuffer)->portdest)
1465 break; 1437 break;
1466 } 1438 }
1467 if (i == MAX_NUM_APP) { 1439 if (i == MAX_NUM_APP) {
1468 DEBUG("FT1000:ft1000_parse_dpram_msg: No application matching id = %d\n", ((struct pseudo_hdr *)pdpram_blk->pbuffer)->portdest); 1440 pr_debug("No application matching id = %d\n",
1441 ((struct pseudo_hdr *)pdpram_blk->pbuffer)->portdest);
1469 goto exit_failure; 1442 goto exit_failure;
1470 } else if (dev->app_info[i].NumOfMsg > MAX_MSG_LIMIT) { 1443 } else if (dev->app_info[i].NumOfMsg > MAX_MSG_LIMIT) {
1471 goto exit_failure; 1444 goto exit_failure;
@@ -1495,26 +1468,26 @@ int ft1000_poll(void *dev_id)
1495 u16 portid; 1468 u16 portid;
1496 1469
1497 if (ft1000_chkcard(dev) == FALSE) { 1470 if (ft1000_chkcard(dev) == FALSE) {
1498 DEBUG("ft1000_poll::ft1000_chkcard: failed\n"); 1471 pr_debug("failed\n");
1499 return -1; 1472 return -1;
1500 } 1473 }
1501 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL); 1474 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
1502 if (!status) { 1475 if (!status) {
1503 if (tempword & FT1000_DB_DPRAM_RX) { 1476 if (tempword & FT1000_DB_DPRAM_RX) {
1504 status = ft1000_read_dpram16(dev, 1477 status = ft1000_read_dpram16(dev,
1505 0x200, (u8 *)&data, 0); 1478 0x200, (u8 *)&data, 0);
1506 size = ntohs(data) + 16 + 2; 1479 size = ntohs(data) + 16 + 2;
1507 if (size % 4) { 1480 if (size % 4) {
1508 modulo = 4 - (size % 4); 1481 modulo = 4 - (size % 4);
1509 size = size + modulo; 1482 size = size + modulo;
1510 } 1483 }
1511 status = ft1000_read_dpram16(dev, 0x201, 1484 status = ft1000_read_dpram16(dev, 0x201,
1512 (u8 *)&portid, 1); 1485 (u8 *)&portid, 1);
1513 portid &= 0xff; 1486 portid &= 0xff;
1514 if (size < MAX_CMD_SQSIZE) { 1487 if (size < MAX_CMD_SQSIZE) {
1515 switch (portid) { 1488 switch (portid) {
1516 case DRIVERID: 1489 case DRIVERID:
1517 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid DRIVERID\n"); 1490 pr_debug("FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid DRIVERID\n");
1518 status = ft1000_proc_drvmsg(dev, size); 1491 status = ft1000_proc_drvmsg(dev, size);
1519 if (status != 0) 1492 if (status != 0)
1520 return status; 1493 return status;
@@ -1527,87 +1500,88 @@ int ft1000_poll(void *dev_id)
1527 break; 1500 break;
1528 } 1501 }
1529 } else 1502 } else
1530 DEBUG("FT1000:dpc:Invalid total length for SlowQ = %d\n", size); 1503 pr_debug("Invalid total length for SlowQ = %d\n",
1504 size);
1531 status = ft1000_write_register(dev, 1505 status = ft1000_write_register(dev,
1532 FT1000_DB_DPRAM_RX, 1506 FT1000_DB_DPRAM_RX,
1533 FT1000_REG_DOORBELL); 1507 FT1000_REG_DOORBELL);
1534 } else if (tempword & FT1000_DSP_ASIC_RESET) { 1508 } else if (tempword & FT1000_DSP_ASIC_RESET) {
1535 /* Let's reset the ASIC from the Host side as well */ 1509 /* Let's reset the ASIC from the Host side as well */
1536 status = ft1000_write_register(dev, ASIC_RESET_BIT, 1510 status = ft1000_write_register(dev, ASIC_RESET_BIT,
1537 FT1000_REG_RESET); 1511 FT1000_REG_RESET);
1538 status = ft1000_read_register(dev, &tempword, 1512 status = ft1000_read_register(dev, &tempword,
1539 FT1000_REG_RESET); 1513 FT1000_REG_RESET);
1540 i = 0; 1514 i = 0;
1541 while (tempword & ASIC_RESET_BIT) { 1515 while (tempword & ASIC_RESET_BIT) {
1542 status = ft1000_read_register(dev, &tempword, 1516 status = ft1000_read_register(dev, &tempword,
1543 FT1000_REG_RESET); 1517 FT1000_REG_RESET);
1544 usleep_range(9000, 11000); 1518 usleep_range(9000, 11000);
1545 i++; 1519 i++;
1546 if (i == 100) 1520 if (i == 100)
1547 break; 1521 break;
1548 } 1522 }
1549 if (i == 100) { 1523 if (i == 100) {
1550 DEBUG("Unable to reset ASIC\n"); 1524 pr_debug("Unable to reset ASIC\n");
1551 return 0; 1525 return 0;
1552 } 1526 }
1553 usleep_range(9000, 11000); 1527 usleep_range(9000, 11000);
1554 /* Program WMARK register */ 1528 /* Program WMARK register */
1555 status = ft1000_write_register(dev, 0x600, 1529 status = ft1000_write_register(dev, 0x600,
1556 FT1000_REG_MAG_WATERMARK); 1530 FT1000_REG_MAG_WATERMARK);
1557 /* clear ASIC reset doorbell */ 1531 /* clear ASIC reset doorbell */
1558 status = ft1000_write_register(dev, 1532 status = ft1000_write_register(dev,
1559 FT1000_DSP_ASIC_RESET, 1533 FT1000_DSP_ASIC_RESET,
1560 FT1000_REG_DOORBELL); 1534 FT1000_REG_DOORBELL);
1561 usleep_range(9000, 11000); 1535 usleep_range(9000, 11000);
1562 } else if (tempword & FT1000_ASIC_RESET_REQ) { 1536 } else if (tempword & FT1000_ASIC_RESET_REQ) {
1563 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_ASIC_RESET_REQ\n"); 1537 pr_debug("FT1000_REG_DOORBELL message type: FT1000_ASIC_RESET_REQ\n");
1564 /* clear ASIC reset request from DSP */ 1538 /* clear ASIC reset request from DSP */
1565 status = ft1000_write_register(dev, 1539 status = ft1000_write_register(dev,
1566 FT1000_ASIC_RESET_REQ, 1540 FT1000_ASIC_RESET_REQ,
1567 FT1000_REG_DOORBELL); 1541 FT1000_REG_DOORBELL);
1568 status = ft1000_write_register(dev, HOST_INTF_BE, 1542 status = ft1000_write_register(dev, HOST_INTF_BE,
1569 FT1000_REG_SUP_CTRL); 1543 FT1000_REG_SUP_CTRL);
1570 /* copy dsp session record from Adapter block */ 1544 /* copy dsp session record from Adapter block */
1571 status = ft1000_write_dpram32(dev, 0, 1545 status = ft1000_write_dpram32(dev, 0,
1572 (u8 *)&info->DSPSess.Rec[0], 1024); 1546 (u8 *)&info->DSPSess.Rec[0], 1024);
1573 status = ft1000_write_register(dev, 0x600, 1547 status = ft1000_write_register(dev, 0x600,
1574 FT1000_REG_MAG_WATERMARK); 1548 FT1000_REG_MAG_WATERMARK);
1575 /* ring doorbell to tell DSP that 1549 /* ring doorbell to tell DSP that
1576 * ASIC is out of reset 1550 * ASIC is out of reset
1577 * */ 1551 * */
1578 status = ft1000_write_register(dev, 1552 status = ft1000_write_register(dev,
1579 FT1000_ASIC_RESET_DSP, 1553 FT1000_ASIC_RESET_DSP,
1580 FT1000_REG_DOORBELL); 1554 FT1000_REG_DOORBELL);
1581 } else if (tempword & FT1000_DB_COND_RESET) { 1555 } else if (tempword & FT1000_DB_COND_RESET) {
1582 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_COND_RESET\n"); 1556 pr_debug("FT1000_REG_DOORBELL message type: FT1000_DB_COND_RESET\n");
1583 if (!dev->fAppMsgPend) { 1557 if (!dev->fAppMsgPend) {
1584 /* Reset ASIC and DSP */ 1558 /* Reset ASIC and DSP */
1585 status = ft1000_read_dpram16(dev, 1559 status = ft1000_read_dpram16(dev,
1586 FT1000_MAG_DSP_TIMER0, 1560 FT1000_MAG_DSP_TIMER0,
1587 (u8 *)&(info->DSP_TIME[0]), 1561 (u8 *)&(info->DSP_TIME[0]),
1588 FT1000_MAG_DSP_TIMER0_INDX); 1562 FT1000_MAG_DSP_TIMER0_INDX);
1589 status = ft1000_read_dpram16(dev, 1563 status = ft1000_read_dpram16(dev,
1590 FT1000_MAG_DSP_TIMER1, 1564 FT1000_MAG_DSP_TIMER1,
1591 (u8 *)&(info->DSP_TIME[1]), 1565 (u8 *)&(info->DSP_TIME[1]),
1592 FT1000_MAG_DSP_TIMER1_INDX); 1566 FT1000_MAG_DSP_TIMER1_INDX);
1593 status = ft1000_read_dpram16(dev, 1567 status = ft1000_read_dpram16(dev,
1594 FT1000_MAG_DSP_TIMER2, 1568 FT1000_MAG_DSP_TIMER2,
1595 (u8 *)&(info->DSP_TIME[2]), 1569 (u8 *)&(info->DSP_TIME[2]),
1596 FT1000_MAG_DSP_TIMER2_INDX); 1570 FT1000_MAG_DSP_TIMER2_INDX);
1597 status = ft1000_read_dpram16(dev, 1571 status = ft1000_read_dpram16(dev,
1598 FT1000_MAG_DSP_TIMER3, 1572 FT1000_MAG_DSP_TIMER3,
1599 (u8 *)&(info->DSP_TIME[3]), 1573 (u8 *)&(info->DSP_TIME[3]),
1600 FT1000_MAG_DSP_TIMER3_INDX); 1574 FT1000_MAG_DSP_TIMER3_INDX);
1601 info->CardReady = 0; 1575 info->CardReady = 0;
1602 info->DrvErrNum = DSP_CONDRESET_INFO; 1576 info->DrvErrNum = DSP_CONDRESET_INFO;
1603 DEBUG("ft1000_hw:DSP conditional reset requested\n"); 1577 pr_debug("DSP conditional reset requested\n");
1604 info->ft1000_reset(dev->net); 1578 info->ft1000_reset(dev->net);
1605 } else { 1579 } else {
1606 dev->fProvComplete = false; 1580 dev->fProvComplete = false;
1607 dev->fCondResetPend = true; 1581 dev->fCondResetPend = true;
1608 } 1582 }
1609 ft1000_write_register(dev, FT1000_DB_COND_RESET, 1583 ft1000_write_register(dev, FT1000_DB_COND_RESET,
1610 FT1000_REG_DOORBELL); 1584 FT1000_REG_DOORBELL);
1611 } 1585 }
1612 } 1586 }
1613 return 0; 1587 return 0;
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_ioctl.h b/drivers/staging/ft1000/ft1000-usb/ft1000_ioctl.h
index cb644a58d9f3..e9472bebda0b 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_ioctl.h
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_ioctl.h
@@ -1,30 +1,30 @@
1/* 1/*
2*--------------------------------------------------------------------------- 2 *---------------------------------------------------------------------------
3* FT1000 driver for Flarion Flash OFDM NIC Device 3 * FT1000 driver for Flarion Flash OFDM NIC Device
4* 4 *
5* Copyright (C) 2002 Flarion Technologies, All rights reserved. 5 * Copyright (C) 2002 Flarion Technologies, All rights reserved.
6* 6 *
7* This program is free software; you can redistribute it and/or modify it 7 * This program is free software; you can redistribute it and/or modify it
8* under the terms of the GNU General Public License as published by the Free 8 * under the terms of the GNU General Public License as published by the Free
9* Software Foundation; either version 2 of the License, or (at your option) any 9 * Software Foundation; either version 2 of the License, or (at your option) any
10* later version. This program is distributed in the hope that it will be useful, 10 * later version. This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13* more details. You should have received a copy of the GNU General Public 13 * more details. You should have received a copy of the GNU General Public
14* License along with this program; if not, write to the 14 * License along with this program; if not, write to the
15* Free Software Foundation, Inc., 59 Temple Place - 15 * Free Software Foundation, Inc., 59 Temple Place -
16* Suite 330, Boston, MA 02111-1307, USA. 16 * Suite 330, Boston, MA 02111-1307, USA.
17*--------------------------------------------------------------------------- 17 *---------------------------------------------------------------------------
18* 18 *
19* File: ft1000_ioctl.h 19 * File: ft1000_ioctl.h
20* 20 *
21* Description: Common structures and defines relating to IOCTL 21 * Description: Common structures and defines relating to IOCTL
22* 22 *
23* History: 23 * History:
24* 11/5/02 Whc Created. 24 * 11/5/02 Whc Created.
25* 25 *
26*--------------------------------------------------------------------------- 26 *---------------------------------------------------------------------------
27*/ 27 */
28#ifndef _FT1000IOCTLH_ 28#ifndef _FT1000IOCTLH_
29#define _FT1000IOCTLH_ 29#define _FT1000IOCTLH_
30 30
@@ -94,8 +94,8 @@ struct IOCTL_DPRAM_COMMAND {
94} __packed; 94} __packed;
95 95
96/* 96/*
97* Custom IOCTL command codes 97 * Custom IOCTL command codes
98*/ 98 */
99#define FT1000_MAGIC_CODE 'F' 99#define FT1000_MAGIC_CODE 'F'
100 100
101#define IOCTL_REGISTER_CMD 0 101#define IOCTL_REGISTER_CMD 0
@@ -106,8 +106,8 @@ struct IOCTL_DPRAM_COMMAND {
106#define IOCTL_CONNECT 10 106#define IOCTL_CONNECT 10
107#define IOCTL_DISCONNECT 11 107#define IOCTL_DISCONNECT 11
108 108
109#define IOCTL_FT1000_GET_DSP_STAT _IOR(FT1000_MAGIC_CODE, \ 109#define IOCTL_FT1000_GET_DSP_STAT _IOR(FT1000_MAGIC_CODE, \
110 IOCTL_GET_DSP_STAT_CMD, \ 110 IOCTL_GET_DSP_STAT_CMD, \
111 struct IOCTL_GET_DSP_STAT) 111 struct IOCTL_GET_DSP_STAT)
112#define IOCTL_FT1000_GET_VER _IOR(FT1000_MAGIC_CODE, IOCTL_GET_VER_CMD, \ 112#define IOCTL_FT1000_GET_VER _IOR(FT1000_MAGIC_CODE, IOCTL_GET_VER_CMD, \
113 struct IOCTL_GET_VER) 113 struct IOCTL_GET_VER)
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c
index 39be30c0eedf..a6b55f42c07c 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.c
@@ -7,6 +7,9 @@
7 * $Id: 7 * $Id:
8 *==================================================== 8 *====================================================
9 */ 9 */
10
11#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12
10#include <linux/kernel.h> 13#include <linux/kernel.h>
11#include <linux/module.h> 14#include <linux/module.h>
12#include <linux/usb.h> 15#include <linux/usb.h>
@@ -45,7 +48,7 @@ static int ft1000_poll_thread(void *arg)
45 if (!gPollingfailed) { 48 if (!gPollingfailed) {
46 ret = ft1000_poll(arg); 49 ret = ft1000_poll(arg);
47 if (ret != 0) { 50 if (ret != 0) {
48 DEBUG("ft1000_poll_thread: polling failed\n"); 51 pr_debug("polling failed\n");
49 gPollingfailed = true; 52 gPollingfailed = true;
50 } 53 }
51 } 54 }
@@ -71,9 +74,8 @@ static int ft1000_probe(struct usb_interface *interface,
71 return -ENOMEM; 74 return -ENOMEM;
72 75
73 dev = interface_to_usbdev(interface); 76 dev = interface_to_usbdev(interface);
74 DEBUG("ft1000_probe: usb device descriptor info:\n"); 77 pr_debug("usb device descriptor info - number of configuration is %d\n",
75 DEBUG("ft1000_probe: number of configuration is %d\n", 78 dev->descriptor.bNumConfigurations);
76 dev->descriptor.bNumConfigurations);
77 79
78 ft1000dev->dev = dev; 80 ft1000dev->dev = dev;
79 ft1000dev->status = 0; 81 ft1000dev->status = 0;
@@ -85,60 +87,56 @@ static int ft1000_probe(struct usb_interface *interface,
85 goto err_fw; 87 goto err_fw;
86 } 88 }
87 89
88 DEBUG("ft1000_probe is called\n");
89 numaltsetting = interface->num_altsetting; 90 numaltsetting = interface->num_altsetting;
90 DEBUG("ft1000_probe: number of alt settings is :%d\n", numaltsetting); 91 pr_debug("number of alt settings is: %d\n", numaltsetting);
91 iface_desc = interface->cur_altsetting; 92 iface_desc = interface->cur_altsetting;
92 DEBUG("ft1000_probe: number of endpoints is %d\n", 93 pr_debug("number of endpoints is: %d\n",
93 iface_desc->desc.bNumEndpoints); 94 iface_desc->desc.bNumEndpoints);
94 DEBUG("ft1000_probe: descriptor type is %d\n", 95 pr_debug("descriptor type is: %d\n", iface_desc->desc.bDescriptorType);
95 iface_desc->desc.bDescriptorType); 96 pr_debug("interface number is: %d\n",
96 DEBUG("ft1000_probe: interface number is %d\n", 97 iface_desc->desc.bInterfaceNumber);
97 iface_desc->desc.bInterfaceNumber); 98 pr_debug("alternatesetting is: %d\n",
98 DEBUG("ft1000_probe: alternatesetting is %d\n", 99 iface_desc->desc.bAlternateSetting);
99 iface_desc->desc.bAlternateSetting); 100 pr_debug("interface class is: %d\n", iface_desc->desc.bInterfaceClass);
100 DEBUG("ft1000_probe: interface class is %d\n", 101 pr_debug("control endpoint info:\n");
101 iface_desc->desc.bInterfaceClass); 102 pr_debug("descriptor0 type -- %d\n",
102 DEBUG("ft1000_probe: control endpoint info:\n"); 103 iface_desc->endpoint[0].desc.bmAttributes);
103 DEBUG("ft1000_probe: descriptor0 type -- %d\n", 104 pr_debug("descriptor1 type -- %d\n",
104 iface_desc->endpoint[0].desc.bmAttributes); 105 iface_desc->endpoint[1].desc.bmAttributes);
105 DEBUG("ft1000_probe: descriptor1 type -- %d\n", 106 pr_debug("descriptor2 type -- %d\n",
106 iface_desc->endpoint[1].desc.bmAttributes); 107 iface_desc->endpoint[2].desc.bmAttributes);
107 DEBUG("ft1000_probe: descriptor2 type -- %d\n",
108 iface_desc->endpoint[2].desc.bmAttributes);
109 108
110 for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) { 109 for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) {
111 endpoint = 110 endpoint =
112 (struct usb_endpoint_descriptor *)&iface_desc-> 111 (struct usb_endpoint_descriptor *)&iface_desc->
113 endpoint[i].desc; 112 endpoint[i].desc;
114 DEBUG("endpoint %d\n", i); 113 pr_debug("endpoint %d\n", i);
115 DEBUG("bEndpointAddress=%x, bmAttributes=%x\n", 114 pr_debug("bEndpointAddress=%x, bmAttributes=%x\n",
116 endpoint->bEndpointAddress, endpoint->bmAttributes); 115 endpoint->bEndpointAddress, endpoint->bmAttributes);
117 if ((endpoint->bEndpointAddress & USB_DIR_IN) 116 if ((endpoint->bEndpointAddress & USB_DIR_IN)
118 && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == 117 && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
119 USB_ENDPOINT_XFER_BULK)) { 118 USB_ENDPOINT_XFER_BULK)) {
120 ft1000dev->bulk_in_endpointAddr = 119 ft1000dev->bulk_in_endpointAddr =
121 endpoint->bEndpointAddress; 120 endpoint->bEndpointAddress;
122 DEBUG("ft1000_probe: in: %d\n", 121 pr_debug("in: %d\n", endpoint->bEndpointAddress);
123 endpoint->bEndpointAddress);
124 } 122 }
125 123
126 if (!(endpoint->bEndpointAddress & USB_DIR_IN) 124 if (!(endpoint->bEndpointAddress & USB_DIR_IN)
127 && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == 125 && ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
128 USB_ENDPOINT_XFER_BULK)) { 126 USB_ENDPOINT_XFER_BULK)) {
129 ft1000dev->bulk_out_endpointAddr = 127 ft1000dev->bulk_out_endpointAddr =
130 endpoint->bEndpointAddress; 128 endpoint->bEndpointAddress;
131 DEBUG("ft1000_probe: out: %d\n", 129 pr_debug("out: %d\n", endpoint->bEndpointAddress);
132 endpoint->bEndpointAddress);
133 } 130 }
134 } 131 }
135 132
136 DEBUG("bulk_in=%d, bulk_out=%d\n", ft1000dev->bulk_in_endpointAddr, 133 pr_debug("bulk_in=%d, bulk_out=%d\n",
137 ft1000dev->bulk_out_endpointAddr); 134 ft1000dev->bulk_in_endpointAddr,
135 ft1000dev->bulk_out_endpointAddr);
138 136
139 ret = request_firmware(&dsp_fw, "ft3000.img", &dev->dev); 137 ret = request_firmware(&dsp_fw, "ft3000.img", &dev->dev);
140 if (ret < 0) { 138 if (ret < 0) {
141 pr_err("Error request_firmware().\n"); 139 pr_err("Error request_firmware()\n");
142 goto err_fw; 140 goto err_fw;
143 } 141 }
144 142
@@ -155,7 +153,7 @@ static int ft1000_probe(struct usb_interface *interface,
155 FileLength = dsp_fw->size; 153 FileLength = dsp_fw->size;
156 release_firmware(dsp_fw); 154 release_firmware(dsp_fw);
157 155
158 DEBUG("ft1000_probe: start downloading dsp image...\n"); 156 pr_debug("start downloading dsp image...\n");
159 157
160 ret = init_ft1000_netdev(ft1000dev); 158 ret = init_ft1000_netdev(ft1000dev);
161 if (ret) 159 if (ret)
@@ -163,7 +161,7 @@ static int ft1000_probe(struct usb_interface *interface,
163 161
164 pft1000info = netdev_priv(ft1000dev->net); 162 pft1000info = netdev_priv(ft1000dev->net);
165 163
166 DEBUG("In probe: pft1000info=%p\n", pft1000info); 164 pr_debug("pft1000info=%p\n", pft1000info);
167 ret = dsp_reload(ft1000dev); 165 ret = dsp_reload(ft1000dev);
168 if (ret) { 166 if (ret) {
169 pr_err("Problem with DSP image loading\n"); 167 pr_err("Problem with DSP image loading\n");
@@ -172,7 +170,7 @@ static int ft1000_probe(struct usb_interface *interface,
172 170
173 gPollingfailed = false; 171 gPollingfailed = false;
174 ft1000dev->pPollThread = 172 ft1000dev->pPollThread =
175 kthread_run(ft1000_poll_thread, ft1000dev, "ft1000_poll"); 173 kthread_run(ft1000_poll_thread, ft1000dev, "ft1000_poll");
176 174
177 if (IS_ERR(ft1000dev->pPollThread)) { 175 if (IS_ERR(ft1000dev->pPollThread)) {
178 ret = PTR_ERR(ft1000dev->pPollThread); 176 ret = PTR_ERR(ft1000dev->pPollThread);
@@ -187,10 +185,10 @@ static int ft1000_probe(struct usb_interface *interface,
187 goto err_thread; 185 goto err_thread;
188 } 186 }
189 msleep(100); 187 msleep(100);
190 DEBUG("ft1000_probe::Waiting for Card Ready\n"); 188 pr_debug("Waiting for Card Ready\n");
191 } 189 }
192 190
193 DEBUG("ft1000_probe::Card Ready!!!! Registering network device\n"); 191 pr_debug("Card Ready!!!! Registering network device\n");
194 192
195 ret = reg_ft1000_netdev(ft1000dev, interface); 193 ret = reg_ft1000_netdev(ft1000dev, interface);
196 if (ret) 194 if (ret)
@@ -216,24 +214,21 @@ static void ft1000_disconnect(struct usb_interface *interface)
216 struct ft1000_info *pft1000info; 214 struct ft1000_info *pft1000info;
217 struct ft1000_usb *ft1000dev; 215 struct ft1000_usb *ft1000dev;
218 216
219 DEBUG("ft1000_disconnect is called\n"); 217 pft1000info = (struct ft1000_info *)usb_get_intfdata(interface);
220 218 pr_debug("In disconnect pft1000info=%p\n", pft1000info);
221 pft1000info = (struct ft1000_info *) usb_get_intfdata(interface);
222 DEBUG("In disconnect pft1000info=%p\n", pft1000info);
223 219
224 if (pft1000info) { 220 if (pft1000info) {
225 ft1000dev = pft1000info->priv; 221 ft1000dev = pft1000info->priv;
226 if (ft1000dev->pPollThread) 222 if (ft1000dev->pPollThread)
227 kthread_stop(ft1000dev->pPollThread); 223 kthread_stop(ft1000dev->pPollThread);
228 224
229 DEBUG("ft1000_disconnect: threads are terminated\n"); 225 pr_debug("threads are terminated\n");
230 226
231 if (ft1000dev->net) { 227 if (ft1000dev->net) {
232 DEBUG("ft1000_disconnect: destroy char driver\n"); 228 pr_debug("destroy char driver\n");
233 ft1000_destroy_dev(ft1000dev->net); 229 ft1000_destroy_dev(ft1000dev->net);
234 unregister_netdev(ft1000dev->net); 230 unregister_netdev(ft1000dev->net);
235 DEBUG 231 pr_debug("network device unregistered\n");
236 ("ft1000_disconnect: network device unregistered\n");
237 free_netdev(ft1000dev->net); 232 free_netdev(ft1000dev->net);
238 233
239 } 234 }
@@ -241,7 +236,7 @@ static void ft1000_disconnect(struct usb_interface *interface)
241 usb_free_urb(ft1000dev->rx_urb); 236 usb_free_urb(ft1000dev->rx_urb);
242 usb_free_urb(ft1000dev->tx_urb); 237 usb_free_urb(ft1000dev->tx_urb);
243 238
244 DEBUG("ft1000_disconnect: urb freed\n"); 239 pr_debug("urb freed\n");
245 240
246 kfree(ft1000dev); 241 kfree(ft1000dev);
247 } 242 }
diff --git a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h
index 8f7ccae57f31..fea60d5651a7 100644
--- a/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h
+++ b/drivers/staging/ft1000/ft1000-usb/ft1000_usb.h
@@ -28,8 +28,6 @@ struct app_info_block {
28 */ 28 */
29} __packed; 29} __packed;
30 30
31#define DEBUG(args...) pr_info(args)
32
33#define FALSE 0 31#define FALSE 0
34#define TRUE 1 32#define TRUE 1
35 33
@@ -137,7 +135,7 @@ extern spinlock_t free_buff_lock;
137int ft1000_create_dev(struct ft1000_usb *dev); 135int ft1000_create_dev(struct ft1000_usb *dev);
138void ft1000_destroy_dev(struct net_device *dev); 136void ft1000_destroy_dev(struct net_device *dev);
139extern int card_send_command(struct ft1000_usb *ft1000dev, 137extern int card_send_command(struct ft1000_usb *ft1000dev,
140 void *ptempbuffer, int size); 138 void *ptempbuffer, int size);
141 139
142struct dpram_blk *ft1000_get_buffer(struct list_head *bufflist); 140struct dpram_blk *ft1000_get_buffer(struct list_head *bufflist);
143void ft1000_free_buffer(struct dpram_blk *pdpram_blk, struct list_head *plist); 141void ft1000_free_buffer(struct dpram_blk *pdpram_blk, struct list_head *plist);
diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c
index af0c3878358c..73deae3cd9eb 100644
--- a/drivers/staging/fwserial/fwserial.c
+++ b/drivers/staging/fwserial/fwserial.c
@@ -278,7 +278,6 @@ static void fwtty_send_txn_async(struct fwtty_peer *peer,
278 len, fwtty_common_callback, txn); 278 len, fwtty_common_callback, txn);
279} 279}
280 280
281
282static void __fwtty_restart_tx(struct fwtty_port *port) 281static void __fwtty_restart_tx(struct fwtty_port *port)
283{ 282{
284 int len, avail; 283 int len, avail;
@@ -508,7 +507,6 @@ static void fwtty_do_hangup(struct work_struct *work)
508 tty_kref_put(tty); 507 tty_kref_put(tty);
509} 508}
510 509
511
512static void fwtty_emit_breaks(struct work_struct *work) 510static void fwtty_emit_breaks(struct work_struct *work)
513{ 511{
514 struct fwtty_port *port = to_port(to_delayed_work(work), emit_breaks); 512 struct fwtty_port *port = to_port(to_delayed_work(work), emit_breaks);
@@ -1622,7 +1620,6 @@ static inline int mgmt_pkt_expected_len(__be16 code)
1622 case FWSC_VIRT_CABLE_PLUG_RSP: /* | FWSC_RSP_OK */ 1620 case FWSC_VIRT_CABLE_PLUG_RSP: /* | FWSC_RSP_OK */
1623 return sizeof(pkt.hdr) + sizeof(pkt.plug_rsp); 1621 return sizeof(pkt.hdr) + sizeof(pkt.plug_rsp);
1624 1622
1625
1626 case FWSC_VIRT_CABLE_UNPLUG: 1623 case FWSC_VIRT_CABLE_UNPLUG:
1627 case FWSC_VIRT_CABLE_UNPLUG_RSP: 1624 case FWSC_VIRT_CABLE_UNPLUG_RSP:
1628 case FWSC_VIRT_CABLE_PLUG_RSP | FWSC_RSP_NACK: 1625 case FWSC_VIRT_CABLE_PLUG_RSP | FWSC_RSP_NACK:
diff --git a/drivers/staging/gdm724x/gdm_lte.c b/drivers/staging/gdm724x/gdm_lte.c
index c657639f884b..73eede163820 100644
--- a/drivers/staging/gdm724x/gdm_lte.c
+++ b/drivers/staging/gdm724x/gdm_lte.c
@@ -626,7 +626,7 @@ static void gdm_lte_netif_rx(struct net_device *dev, char *buf,
626 void *addr = buf + sizeof(struct iphdr) + 626 void *addr = buf + sizeof(struct iphdr) +
627 sizeof(struct udphdr) + 627 sizeof(struct udphdr) +
628 offsetof(struct dhcp_packet, chaddr); 628 offsetof(struct dhcp_packet, chaddr);
629 memcpy(nic->dest_mac_addr, addr, ETH_ALEN); 629 ether_addr_copy(nic->dest_mac_addr, addr);
630 } 630 }
631 } 631 }
632 632
@@ -639,7 +639,7 @@ static void gdm_lte_netif_rx(struct net_device *dev, char *buf,
639 } 639 }
640 640
641 /* Format the data so that it can be put to skb */ 641 /* Format the data so that it can be put to skb */
642 memcpy(mac_header_data, nic->dest_mac_addr, ETH_ALEN); 642 ether_addr_copy(mac_header_data, nic->dest_mac_addr);
643 memcpy(mac_header_data + ETH_ALEN, nic->src_mac_addr, ETH_ALEN); 643 memcpy(mac_header_data + ETH_ALEN, nic->src_mac_addr, ETH_ALEN);
644 644
645 vlan_eth.h_vlan_TCI = htons(nic->vlan_id); 645 vlan_eth.h_vlan_TCI = htons(nic->vlan_id);
@@ -842,9 +842,9 @@ static void form_mac_address(u8 *dev_addr, u8 *nic_src, u8 *nic_dest,
842{ 842{
843 /* Form the dev_addr */ 843 /* Form the dev_addr */
844 if (!mac_address) 844 if (!mac_address)
845 memcpy(dev_addr, gdm_lte_macaddr, ETH_ALEN); 845 ether_addr_copy(dev_addr, gdm_lte_macaddr);
846 else 846 else
847 memcpy(dev_addr, mac_address, ETH_ALEN); 847 ether_addr_copy(dev_addr, mac_address);
848 848
849 /* The last byte of the mac address 849 /* The last byte of the mac address
850 * should be less than or equal to 0xFC 850 * should be less than or equal to 0xFC
@@ -858,7 +858,7 @@ static void form_mac_address(u8 *dev_addr, u8 *nic_src, u8 *nic_dest,
858 memcpy(nic_src, dev_addr, 3); 858 memcpy(nic_src, dev_addr, 3);
859 859
860 /* Copy the nic_dest from dev_addr*/ 860 /* Copy the nic_dest from dev_addr*/
861 memcpy(nic_dest, dev_addr, ETH_ALEN); 861 ether_addr_copy(nic_dest, dev_addr);
862} 862}
863 863
864static void validate_mac_address(u8 *mac_address) 864static void validate_mac_address(u8 *mac_address)
diff --git a/drivers/staging/gdm724x/gdm_mux.h b/drivers/staging/gdm724x/gdm_mux.h
index 0163b243d3e0..3d50383c6ced 100644
--- a/drivers/staging/gdm724x/gdm_mux.h
+++ b/drivers/staging/gdm724x/gdm_mux.h
@@ -35,10 +35,10 @@
35#define RETRY_TIMER 30 /* msec */ 35#define RETRY_TIMER 30 /* msec */
36 36
37struct mux_pkt_header { 37struct mux_pkt_header {
38 unsigned int start_flag; 38 __le32 start_flag;
39 unsigned int seq_num; 39 __le32 seq_num;
40 unsigned int payload_size; 40 __le32 payload_size;
41 unsigned short packet_type; 41 __le16 packet_type;
42 unsigned char data[0]; 42 unsigned char data[0];
43}; 43};
44 44
diff --git a/drivers/staging/gdm72xx/gdm_wimax.c b/drivers/staging/gdm72xx/gdm_wimax.c
index f5a3378c3951..9cab54bfa6f4 100644
--- a/drivers/staging/gdm72xx/gdm_wimax.c
+++ b/drivers/staging/gdm72xx/gdm_wimax.c
@@ -115,7 +115,7 @@ static void gdm_wimax_event_rcv(struct net_device *dev, u16 type, void *msg,
115{ 115{
116 struct nic *nic = netdev_priv(dev); 116 struct nic *nic = netdev_priv(dev);
117 117
118 u8 *buf = (u8 *)msg; 118 u8 *buf = msg;
119 u16 hci_cmd = (buf[0]<<8) | buf[1]; 119 u16 hci_cmd = (buf[0]<<8) | buf[1];
120 u16 hci_len = (buf[2]<<8) | buf[3]; 120 u16 hci_len = (buf[2]<<8) | buf[3];
121 121
@@ -605,10 +605,8 @@ static void gdm_wimax_netif_rx(struct net_device *dev, char *buf, int len)
605 int ret; 605 int ret;
606 606
607 skb = dev_alloc_skb(len + 2); 607 skb = dev_alloc_skb(len + 2);
608 if (!skb) { 608 if (!skb)
609 netdev_err(dev, "%s: dev_alloc_skb failed!\n", __func__);
610 return; 609 return;
611 }
612 skb_reserve(skb, 2); 610 skb_reserve(skb, 2);
613 611
614 dev->stats.rx_packets++; 612 dev->stats.rx_packets++;
diff --git a/drivers/staging/gs_fpgaboot/gs_fpgaboot.c b/drivers/staging/gs_fpgaboot/gs_fpgaboot.c
index 6aa9d7c30139..6da72858d28c 100644
--- a/drivers/staging/gs_fpgaboot/gs_fpgaboot.c
+++ b/drivers/staging/gs_fpgaboot/gs_fpgaboot.c
@@ -46,27 +46,6 @@ static char *file = "xlinx_fpga_firmware.bit";
46module_param(file, charp, S_IRUGO); 46module_param(file, charp, S_IRUGO);
47MODULE_PARM_DESC(file, "Xilinx FPGA firmware file."); 47MODULE_PARM_DESC(file, "Xilinx FPGA firmware file.");
48 48
49#ifdef DEBUG_FPGA
50static void datadump(char *msg, void *m, int n)
51{
52 int i;
53 unsigned char *c;
54
55 pr_info("=== %s ===\n", msg);
56
57 c = m;
58
59 for (i = 0; i < n; i++) {
60 if ((i&0xf) == 0)
61 pr_info(KERN_INFO "\n 0x%4x: ", i);
62
63 pr_info("%02X ", c[i]);
64 }
65
66 pr_info("\n");
67}
68#endif /* DEBUG_FPGA */
69
70static void read_bitstream(char *bitdata, char *buf, int *offset, int rdsize) 49static void read_bitstream(char *bitdata, char *buf, int *offset, int rdsize)
71{ 50{
72 memcpy(buf, bitdata + *offset, rdsize); 51 memcpy(buf, bitdata + *offset, rdsize);
@@ -157,12 +136,10 @@ static void gs_print_header(struct fpgaimage *fimage)
157static void gs_read_bitstream(struct fpgaimage *fimage) 136static void gs_read_bitstream(struct fpgaimage *fimage)
158{ 137{
159 char *bitdata; 138 char *bitdata;
160 int size;
161 int offset; 139 int offset;
162 140
163 offset = 0; 141 offset = 0;
164 bitdata = (char *)fimage->fw_entry->data; 142 bitdata = (char *)fimage->fw_entry->data;
165 size = fimage->fw_entry->size;
166 143
167 readmagic_bitstream(bitdata, &offset); 144 readmagic_bitstream(bitdata, &offset);
168 readinfo_bitstream(bitdata, fimage->filename, &offset); 145 readinfo_bitstream(bitdata, fimage->filename, &offset);
@@ -195,15 +172,15 @@ static int gs_read_image(struct fpgaimage *fimage)
195 return 0; 172 return 0;
196} 173}
197 174
198static int gs_load_image(struct fpgaimage *fimage, char *file) 175static int gs_load_image(struct fpgaimage *fimage, char *fw_file)
199{ 176{
200 int err; 177 int err;
201 178
202 pr_info("load fpgaimage %s\n", file); 179 pr_info("load fpgaimage %s\n", fw_file);
203 180
204 err = request_firmware(&fimage->fw_entry, file, &firmware_pdev->dev); 181 err = request_firmware(&fimage->fw_entry, fw_file, &firmware_pdev->dev);
205 if (err != 0) { 182 if (err != 0) {
206 pr_err("firmware %s is missing, cannot continue.\n", file); 183 pr_err("firmware %s is missing, cannot continue.\n", fw_file);
207 return err; 184 return err;
208 } 185 }
209 186
@@ -220,9 +197,9 @@ static int gs_download_image(struct fpgaimage *fimage, enum wbus bus_bytes)
220 size = fimage->lendata; 197 size = fimage->lendata;
221 198
222#ifdef DEBUG_FPGA 199#ifdef DEBUG_FPGA
223 datadump("bitfile sample", bitdata, 0x100); 200 print_hex_dump_bytes("bitfile sample: ", DUMP_PREFIX_OFFSET,
201 bitdata, 0x100);
224#endif /* DEBUG_FPGA */ 202#endif /* DEBUG_FPGA */
225
226 if (!xl_supported_prog_bus_width(bus_bytes)) { 203 if (!xl_supported_prog_bus_width(bus_bytes)) {
227 pr_err("unsupported program bus width %d\n", 204 pr_err("unsupported program bus width %d\n",
228 bus_bytes); 205 bus_bytes);
@@ -316,10 +293,8 @@ static int gs_fpgaboot(void)
316 struct fpgaimage *fimage; 293 struct fpgaimage *fimage;
317 294
318 fimage = kmalloc(sizeof(struct fpgaimage), GFP_KERNEL); 295 fimage = kmalloc(sizeof(struct fpgaimage), GFP_KERNEL);
319 if (fimage == NULL) { 296 if (!fimage)
320 pr_err("No memory is available\n"); 297 return -ENOMEM;
321 goto err_out;
322 }
323 298
324 err = gs_load_image(fimage, file); 299 err = gs_load_image(fimage, file);
325 if (err) { 300 if (err) {
@@ -361,50 +336,44 @@ err_out2:
361err_out1: 336err_out1:
362 kfree(fimage); 337 kfree(fimage);
363 338
364err_out:
365 return -1; 339 return -1;
366 340
367} 341}
368 342
369static int __init gs_fpgaboot_init(void) 343static int __init gs_fpgaboot_init(void)
370{ 344{
371 int err, r; 345 int err;
372
373 r = -1;
374 346
375 pr_info("FPGA DOWNLOAD --->\n"); 347 pr_info("FPGA DOWNLOAD --->\n");
376 348
377 pr_info("FPGA image file name: %s\n", file); 349 pr_info("FPGA image file name: %s\n", file);
378 350
379 err = init_driver(); 351 err = init_driver();
380 if (err != 0) { 352 if (err) {
381 pr_err("FPGA DRIVER INIT FAIL!!\n"); 353 pr_err("FPGA DRIVER INIT FAIL!!\n");
382 return r; 354 return err;
383 } 355 }
384 356
385 err = xl_init_io(); 357 err = xl_init_io();
386 if (err) { 358 if (err) {
387 pr_err("GPIO INIT FAIL!!\n"); 359 pr_err("GPIO INIT FAIL!!\n");
388 r = -1;
389 goto errout; 360 goto errout;
390 } 361 }
391 362
392 err = gs_fpgaboot(); 363 err = gs_fpgaboot();
393 if (err) { 364 if (err) {
394 pr_err("FPGA DOWNLOAD FAIL!!\n"); 365 pr_err("FPGA DOWNLOAD FAIL!!\n");
395 r = -1;
396 goto errout; 366 goto errout;
397 } 367 }
398 368
399 pr_info("FPGA DOWNLOAD DONE <---\n"); 369 pr_info("FPGA DOWNLOAD DONE <---\n");
400 370
401 r = 0; 371 return 0;
402 return r;
403 372
404errout: 373errout:
405 finish_driver(); 374 finish_driver();
406 375
407 return r; 376 return err;
408} 377}
409 378
410static void __exit gs_fpgaboot_exit(void) 379static void __exit gs_fpgaboot_exit(void)
diff --git a/drivers/staging/iio/Documentation/generic_buffer.c b/drivers/staging/iio/Documentation/generic_buffer.c
index 044ea196aa6f..de4647e2495e 100644
--- a/drivers/staging/iio/Documentation/generic_buffer.c
+++ b/drivers/staging/iio/Documentation/generic_buffer.c
@@ -47,6 +47,7 @@ int size_from_channelarray(struct iio_channel_info *channels, int num_channels)
47{ 47{
48 int bytes = 0; 48 int bytes = 0;
49 int i = 0; 49 int i = 0;
50
50 while (i < num_channels) { 51 while (i < num_channels) {
51 if (bytes % channels[i].bytes == 0) 52 if (bytes % channels[i].bytes == 0)
52 channels[i].location = bytes; 53 channels[i].location = bytes;
@@ -74,12 +75,14 @@ void print2byte(int input, struct iio_channel_info *info)
74 input = input >> info->shift; 75 input = input >> info->shift;
75 if (info->is_signed) { 76 if (info->is_signed) {
76 int16_t val = input; 77 int16_t val = input;
78
77 val &= (1 << info->bits_used) - 1; 79 val &= (1 << info->bits_used) - 1;
78 val = (int16_t)(val << (16 - info->bits_used)) >> 80 val = (int16_t)(val << (16 - info->bits_used)) >>
79 (16 - info->bits_used); 81 (16 - info->bits_used);
80 printf("%05f ", ((float)val + info->offset)*info->scale); 82 printf("%05f ", ((float)val + info->offset)*info->scale);
81 } else { 83 } else {
82 uint16_t val = input; 84 uint16_t val = input;
85
83 val &= (1 << info->bits_used) - 1; 86 val &= (1 << info->bits_used) - 1;
84 printf("%05f ", ((float)val + info->offset)*info->scale); 87 printf("%05f ", ((float)val + info->offset)*info->scale);
85 } 88 }
@@ -97,6 +100,7 @@ void process_scan(char *data,
97 int num_channels) 100 int num_channels)
98{ 101{
99 int k; 102 int k;
103
100 for (k = 0; k < num_channels; k++) 104 for (k = 0; k < num_channels; k++)
101 switch (channels[k].bytes) { 105 switch (channels[k].bytes) {
102 /* only a few cases implemented so far */ 106 /* only a few cases implemented so far */
@@ -158,11 +162,12 @@ int main(int argc, char **argv)
158 char *buffer_access; 162 char *buffer_access;
159 int scan_size; 163 int scan_size;
160 int noevents = 0; 164 int noevents = 0;
165 int notrigger = 0;
161 char *dummy; 166 char *dummy;
162 167
163 struct iio_channel_info *channels; 168 struct iio_channel_info *channels;
164 169
165 while ((c = getopt(argc, argv, "l:w:c:et:n:")) != -1) { 170 while ((c = getopt(argc, argv, "l:w:c:et:n:g")) != -1) {
166 switch (c) { 171 switch (c) {
167 case 'n': 172 case 'n':
168 device_name = optarg; 173 device_name = optarg;
@@ -183,6 +188,9 @@ int main(int argc, char **argv)
183 case 'l': 188 case 'l':
184 buf_len = strtoul(optarg, &dummy, 10); 189 buf_len = strtoul(optarg, &dummy, 10);
185 break; 190 break;
191 case 'g':
192 notrigger = 1;
193 break;
186 case '?': 194 case '?':
187 return -1; 195 return -1;
188 } 196 }
@@ -201,28 +209,32 @@ int main(int argc, char **argv)
201 printf("iio device number being used is %d\n", dev_num); 209 printf("iio device number being used is %d\n", dev_num);
202 210
203 asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num); 211 asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num);
204 if (trigger_name == NULL) { 212
205 /* 213 if (!notrigger) {
206 * Build the trigger name. If it is device associated its 214 if (trigger_name == NULL) {
207 * name is <device_name>_dev[n] where n matches the device 215 /*
208 * number found above 216 * Build the trigger name. If it is device associated
209 */ 217 * its name is <device_name>_dev[n] where n matches
210 ret = asprintf(&trigger_name, 218 * the device number found above.
211 "%s-dev%d", device_name, dev_num); 219 */
212 if (ret < 0) { 220 ret = asprintf(&trigger_name,
213 ret = -ENOMEM; 221 "%s-dev%d", device_name, dev_num);
214 goto error_ret; 222 if (ret < 0) {
223 ret = -ENOMEM;
224 goto error_ret;
225 }
215 } 226 }
216 }
217 227
218 /* Verify the trigger exists */ 228 /* Verify the trigger exists */
219 trig_num = find_type_by_name(trigger_name, "trigger"); 229 trig_num = find_type_by_name(trigger_name, "trigger");
220 if (trig_num < 0) { 230 if (trig_num < 0) {
221 printf("Failed to find the trigger %s\n", trigger_name); 231 printf("Failed to find the trigger %s\n", trigger_name);
222 ret = -ENODEV; 232 ret = -ENODEV;
223 goto error_free_triggername; 233 goto error_free_triggername;
224 } 234 }
225 printf("iio trigger number being used is %d\n", trig_num); 235 printf("iio trigger number being used is %d\n", trig_num);
236 } else
237 printf("trigger-less mode selected\n");
226 238
227 /* 239 /*
228 * Parse the files in scan_elements to identify what channels are 240 * Parse the files in scan_elements to identify what channels are
@@ -246,14 +258,18 @@ int main(int argc, char **argv)
246 ret = -ENOMEM; 258 ret = -ENOMEM;
247 goto error_free_triggername; 259 goto error_free_triggername;
248 } 260 }
249 printf("%s %s\n", dev_dir_name, trigger_name); 261
250 /* Set the device trigger to be the data ready trigger found above */ 262 if (!notrigger) {
251 ret = write_sysfs_string_and_verify("trigger/current_trigger", 263 printf("%s %s\n", dev_dir_name, trigger_name);
252 dev_dir_name, 264 /* Set the device trigger to be the data ready trigger found
253 trigger_name); 265 * above */
254 if (ret < 0) { 266 ret = write_sysfs_string_and_verify("trigger/current_trigger",
255 printf("Failed to write current_trigger file\n"); 267 dev_dir_name,
256 goto error_free_buf_dir_name; 268 trigger_name);
269 if (ret < 0) {
270 printf("Failed to write current_trigger file\n");
271 goto error_free_buf_dir_name;
272 }
257 } 273 }
258 274
259 /* Setup ring buffer parameters */ 275 /* Setup ring buffer parameters */
@@ -323,9 +339,10 @@ int main(int argc, char **argv)
323 if (ret < 0) 339 if (ret < 0)
324 goto error_close_buffer_access; 340 goto error_close_buffer_access;
325 341
326 /* Disconnect the trigger - just write a dummy name. */ 342 if (!notrigger)
327 write_sysfs_string("trigger/current_trigger", 343 /* Disconnect the trigger - just write a dummy name. */
328 dev_dir_name, "NULL"); 344 write_sysfs_string("trigger/current_trigger",
345 dev_dir_name, "NULL");
329 346
330error_close_buffer_access: 347error_close_buffer_access:
331 close(fp); 348 close(fp);
diff --git a/drivers/staging/iio/Documentation/iio_event_monitor.c b/drivers/staging/iio/Documentation/iio_event_monitor.c
index 569d6f8face5..940ed2399e73 100644
--- a/drivers/staging/iio/Documentation/iio_event_monitor.c
+++ b/drivers/staging/iio/Documentation/iio_event_monitor.c
@@ -69,16 +69,29 @@ static const char * const iio_modifier_names[] = {
69 [IIO_MOD_X] = "x", 69 [IIO_MOD_X] = "x",
70 [IIO_MOD_Y] = "y", 70 [IIO_MOD_Y] = "y",
71 [IIO_MOD_Z] = "z", 71 [IIO_MOD_Z] = "z",
72 [IIO_MOD_X_AND_Y] = "x&y",
73 [IIO_MOD_X_AND_Z] = "x&z",
74 [IIO_MOD_Y_AND_Z] = "y&z",
75 [IIO_MOD_X_AND_Y_AND_Z] = "x&y&z",
76 [IIO_MOD_X_OR_Y] = "x|y",
77 [IIO_MOD_X_OR_Z] = "x|z",
78 [IIO_MOD_Y_OR_Z] = "y|z",
79 [IIO_MOD_X_OR_Y_OR_Z] = "x|y|z",
72 [IIO_MOD_LIGHT_BOTH] = "both", 80 [IIO_MOD_LIGHT_BOTH] = "both",
73 [IIO_MOD_LIGHT_IR] = "ir", 81 [IIO_MOD_LIGHT_IR] = "ir",
74 [IIO_MOD_ROOT_SUM_SQUARED_X_Y] = "sqrt(x^2+y^2)", 82 [IIO_MOD_ROOT_SUM_SQUARED_X_Y] = "sqrt(x^2+y^2)",
75 [IIO_MOD_SUM_SQUARED_X_Y_Z] = "x^2+y^2+z^2", 83 [IIO_MOD_SUM_SQUARED_X_Y_Z] = "x^2+y^2+z^2",
76 [IIO_MOD_LIGHT_BOTH] = "both",
77 [IIO_MOD_LIGHT_IR] = "ir",
78 [IIO_MOD_LIGHT_CLEAR] = "clear", 84 [IIO_MOD_LIGHT_CLEAR] = "clear",
79 [IIO_MOD_LIGHT_RED] = "red", 85 [IIO_MOD_LIGHT_RED] = "red",
80 [IIO_MOD_LIGHT_GREEN] = "green", 86 [IIO_MOD_LIGHT_GREEN] = "green",
81 [IIO_MOD_LIGHT_BLUE] = "blue", 87 [IIO_MOD_LIGHT_BLUE] = "blue",
88 [IIO_MOD_QUATERNION] = "quaternion",
89 [IIO_MOD_TEMP_AMBIENT] = "ambient",
90 [IIO_MOD_TEMP_OBJECT] = "object",
91 [IIO_MOD_NORTH_MAGN] = "from_north_magnetic",
92 [IIO_MOD_NORTH_TRUE] = "from_north_true",
93 [IIO_MOD_NORTH_MAGN_TILT_COMP] = "from_north_magnetic_tilt_comp",
94 [IIO_MOD_NORTH_TRUE_TILT_COMP] = "from_north_true_tilt_comp",
82}; 95};
83 96
84static bool event_is_known(struct iio_event_data *event) 97static bool event_is_known(struct iio_event_data *event)
@@ -118,6 +131,14 @@ static bool event_is_known(struct iio_event_data *event)
118 case IIO_MOD_X: 131 case IIO_MOD_X:
119 case IIO_MOD_Y: 132 case IIO_MOD_Y:
120 case IIO_MOD_Z: 133 case IIO_MOD_Z:
134 case IIO_MOD_X_AND_Y:
135 case IIO_MOD_X_AND_Z:
136 case IIO_MOD_Y_AND_Z:
137 case IIO_MOD_X_AND_Y_AND_Z:
138 case IIO_MOD_X_OR_Y:
139 case IIO_MOD_X_OR_Z:
140 case IIO_MOD_Y_OR_Z:
141 case IIO_MOD_X_OR_Y_OR_Z:
121 case IIO_MOD_LIGHT_BOTH: 142 case IIO_MOD_LIGHT_BOTH:
122 case IIO_MOD_LIGHT_IR: 143 case IIO_MOD_LIGHT_IR:
123 case IIO_MOD_ROOT_SUM_SQUARED_X_Y: 144 case IIO_MOD_ROOT_SUM_SQUARED_X_Y:
@@ -126,6 +147,13 @@ static bool event_is_known(struct iio_event_data *event)
126 case IIO_MOD_LIGHT_RED: 147 case IIO_MOD_LIGHT_RED:
127 case IIO_MOD_LIGHT_GREEN: 148 case IIO_MOD_LIGHT_GREEN:
128 case IIO_MOD_LIGHT_BLUE: 149 case IIO_MOD_LIGHT_BLUE:
150 case IIO_MOD_QUATERNION:
151 case IIO_MOD_TEMP_AMBIENT:
152 case IIO_MOD_TEMP_OBJECT:
153 case IIO_MOD_NORTH_MAGN:
154 case IIO_MOD_NORTH_TRUE:
155 case IIO_MOD_NORTH_MAGN_TILT_COMP:
156 case IIO_MOD_NORTH_TRUE_TILT_COMP:
129 break; 157 break;
130 default: 158 default:
131 return false; 159 return false;
diff --git a/drivers/staging/iio/Documentation/iio_utils.h b/drivers/staging/iio/Documentation/iio_utils.h
index 0973a092224a..568eff06f803 100644
--- a/drivers/staging/iio/Documentation/iio_utils.h
+++ b/drivers/staging/iio/Documentation/iio_utils.h
@@ -34,6 +34,7 @@ inline int iioutils_break_up_name(const char *full_name,
34 char *current; 34 char *current;
35 char *w, *r; 35 char *w, *r;
36 char *working; 36 char *working;
37
37 current = strdup(full_name); 38 current = strdup(full_name);
38 working = strtok(current, "_\0"); 39 working = strtok(current, "_\0");
39 w = working; 40 w = working;
@@ -335,6 +336,7 @@ inline int build_channel_array(const char *device_dir,
335 if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"), 336 if (strcmp(ent->d_name + strlen(ent->d_name) - strlen("_en"),
336 "_en") == 0) { 337 "_en") == 0) {
337 int current_enabled = 0; 338 int current_enabled = 0;
339
338 current = &(*ci_array)[count++]; 340 current = &(*ci_array)[count++];
339 ret = asprintf(&filename, 341 ret = asprintf(&filename,
340 "%s/%s", scan_el_dir, ent->d_name); 342 "%s/%s", scan_el_dir, ent->d_name);
@@ -506,6 +508,7 @@ inline int _write_sysfs_int(char *filename, char *basedir, int val, int verify)
506 FILE *sysfsfp; 508 FILE *sysfsfp;
507 int test; 509 int test;
508 char *temp = malloc(strlen(basedir) + strlen(filename) + 2); 510 char *temp = malloc(strlen(basedir) + strlen(filename) + 2);
511
509 if (temp == NULL) 512 if (temp == NULL)
510 return -ENOMEM; 513 return -ENOMEM;
511 sprintf(temp, "%s/%s", basedir, filename); 514 sprintf(temp, "%s/%s", basedir, filename);
@@ -554,6 +557,7 @@ int _write_sysfs_string(char *filename, char *basedir, char *val, int verify)
554 int ret = 0; 557 int ret = 0;
555 FILE *sysfsfp; 558 FILE *sysfsfp;
556 char *temp = malloc(strlen(basedir) + strlen(filename) + 2); 559 char *temp = malloc(strlen(basedir) + strlen(filename) + 2);
560
557 if (temp == NULL) { 561 if (temp == NULL) {
558 printf("Memory allocation failed\n"); 562 printf("Memory allocation failed\n");
559 return -ENOMEM; 563 return -ENOMEM;
@@ -614,6 +618,7 @@ int read_sysfs_posint(char *filename, char *basedir)
614 int ret; 618 int ret;
615 FILE *sysfsfp; 619 FILE *sysfsfp;
616 char *temp = malloc(strlen(basedir) + strlen(filename) + 2); 620 char *temp = malloc(strlen(basedir) + strlen(filename) + 2);
621
617 if (temp == NULL) { 622 if (temp == NULL) {
618 printf("Memory allocation failed"); 623 printf("Memory allocation failed");
619 return -ENOMEM; 624 return -ENOMEM;
@@ -636,6 +641,7 @@ int read_sysfs_float(char *filename, char *basedir, float *val)
636 int ret = 0; 641 int ret = 0;
637 FILE *sysfsfp; 642 FILE *sysfsfp;
638 char *temp = malloc(strlen(basedir) + strlen(filename) + 2); 643 char *temp = malloc(strlen(basedir) + strlen(filename) + 2);
644
639 if (temp == NULL) { 645 if (temp == NULL) {
640 printf("Memory allocation failed"); 646 printf("Memory allocation failed");
641 return -ENOMEM; 647 return -ENOMEM;
@@ -658,6 +664,7 @@ int read_sysfs_string(const char *filename, const char *basedir, char *str)
658 int ret = 0; 664 int ret = 0;
659 FILE *sysfsfp; 665 FILE *sysfsfp;
660 char *temp = malloc(strlen(basedir) + strlen(filename) + 2); 666 char *temp = malloc(strlen(basedir) + strlen(filename) + 2);
667
661 if (temp == NULL) { 668 if (temp == NULL) {
662 printf("Memory allocation failed"); 669 printf("Memory allocation failed");
663 return -ENOMEM; 670 return -ENOMEM;
diff --git a/drivers/staging/iio/Documentation/lsiio.c b/drivers/staging/iio/Documentation/lsiio.c
index 24ae9694eb41..98a0de098130 100644
--- a/drivers/staging/iio/Documentation/lsiio.c
+++ b/drivers/staging/iio/Documentation/lsiio.c
@@ -46,6 +46,7 @@ static int dump_channels(const char *dev_dir_name)
46{ 46{
47 DIR *dp; 47 DIR *dp;
48 const struct dirent *ent; 48 const struct dirent *ent;
49
49 dp = opendir(dev_dir_name); 50 dp = opendir(dev_dir_name);
50 if (dp == NULL) 51 if (dp == NULL)
51 return -errno; 52 return -errno;
@@ -62,17 +63,17 @@ static int dump_one_device(const char *dev_dir_name)
62{ 63{
63 char name[IIO_MAX_NAME_LENGTH]; 64 char name[IIO_MAX_NAME_LENGTH];
64 int dev_idx; 65 int dev_idx;
66 int retval;
65 67
66 sscanf(dev_dir_name + strlen(iio_dir) + strlen(type_device), 68 retval = sscanf(dev_dir_name + strlen(iio_dir) + strlen(type_device),
67 "%i", &dev_idx); 69 "%i", &dev_idx);
70 if (retval != 1)
71 return -EINVAL;
68 read_sysfs_string("name", dev_dir_name, name); 72 read_sysfs_string("name", dev_dir_name, name);
69 printf("Device %03d: %s\n", dev_idx, name); 73 printf("Device %03d: %s\n", dev_idx, name);
70 74
71 if (verblevel >= VERBLEVEL_SENSORS) { 75 if (verblevel >= VERBLEVEL_SENSORS)
72 int ret = dump_channels(dev_dir_name); 76 return dump_channels(dev_dir_name);
73 if (ret)
74 return ret;
75 }
76 return 0; 77 return 0;
77} 78}
78 79
@@ -80,9 +81,12 @@ static int dump_one_trigger(const char *dev_dir_name)
80{ 81{
81 char name[IIO_MAX_NAME_LENGTH]; 82 char name[IIO_MAX_NAME_LENGTH];
82 int dev_idx; 83 int dev_idx;
84 int retval;
83 85
84 sscanf(dev_dir_name + strlen(iio_dir) + strlen(type_trigger), 86 retval = sscanf(dev_dir_name + strlen(iio_dir) + strlen(type_trigger),
85 "%i", &dev_idx); 87 "%i", &dev_idx);
88 if (retval != 1)
89 return -EINVAL;
86 read_sysfs_string("name", dev_dir_name, name); 90 read_sysfs_string("name", dev_dir_name, name);
87 printf("Trigger %03d: %s\n", dev_idx, name); 91 printf("Trigger %03d: %s\n", dev_idx, name);
88 return 0; 92 return 0;
@@ -107,6 +111,7 @@ static void dump_devices(void)
107 while (ent = readdir(dp), ent != NULL) { 111 while (ent = readdir(dp), ent != NULL) {
108 if (check_prefix(ent->d_name, type_device)) { 112 if (check_prefix(ent->d_name, type_device)) {
109 char *dev_dir_name; 113 char *dev_dir_name;
114
110 asprintf(&dev_dir_name, "%s%s", iio_dir, ent->d_name); 115 asprintf(&dev_dir_name, "%s%s", iio_dir, ent->d_name);
111 dump_one_device(dev_dir_name); 116 dump_one_device(dev_dir_name);
112 free(dev_dir_name); 117 free(dev_dir_name);
@@ -118,6 +123,7 @@ static void dump_devices(void)
118 while (ent = readdir(dp), ent != NULL) { 123 while (ent = readdir(dp), ent != NULL) {
119 if (check_prefix(ent->d_name, type_trigger)) { 124 if (check_prefix(ent->d_name, type_trigger)) {
120 char *dev_dir_name; 125 char *dev_dir_name;
126
121 asprintf(&dev_dir_name, "%s%s", iio_dir, ent->d_name); 127 asprintf(&dev_dir_name, "%s%s", iio_dir, ent->d_name);
122 dump_one_trigger(dev_dir_name); 128 dump_one_trigger(dev_dir_name);
123 free(dev_dir_name); 129 free(dev_dir_name);
diff --git a/drivers/staging/iio/accel/Kconfig b/drivers/staging/iio/accel/Kconfig
index ad45dfbdf417..07b7ffa00ab5 100644
--- a/drivers/staging/iio/accel/Kconfig
+++ b/drivers/staging/iio/accel/Kconfig
@@ -9,53 +9,71 @@ config ADIS16201
9 select IIO_ADIS_LIB 9 select IIO_ADIS_LIB
10 select IIO_ADIS_LIB_BUFFER if IIO_BUFFER 10 select IIO_ADIS_LIB_BUFFER if IIO_BUFFER
11 help 11 help
12 Say yes here to build support for Analog Devices adis16201 dual-axis 12 Say Y here to build support for Analog Devices adis16201 dual-axis
13 digital inclinometer and accelerometer. 13 digital inclinometer and accelerometer.
14 14
15 To compile this driver as a module, say M here: the module will
16 be called adis16201.
17
15config ADIS16203 18config ADIS16203
16 tristate "Analog Devices ADIS16203 Programmable 360 Degrees Inclinometer" 19 tristate "Analog Devices ADIS16203 Programmable 360 Degrees Inclinometer"
17 depends on SPI 20 depends on SPI
18 select IIO_ADIS_LIB 21 select IIO_ADIS_LIB
19 select IIO_ADIS_LIB_BUFFER if IIO_BUFFER 22 select IIO_ADIS_LIB_BUFFER if IIO_BUFFER
20 help 23 help
21 Say yes here to build support for Analog Devices adis16203 Programmable 24 Say Y here to build support for Analog Devices adis16203 Programmable
22 360 Degrees Inclinometer. 25 360 Degrees Inclinometer.
23 26
27 To compile this driver as a module, say M here: the module will be
28 called adis16203.
29
24config ADIS16204 30config ADIS16204
25 tristate "Analog Devices ADIS16204 Programmable High-g Digital Impact Sensor and Recorder" 31 tristate "Analog Devices ADIS16204 Programmable High-g Digital Impact Sensor and Recorder"
26 depends on SPI 32 depends on SPI
27 select IIO_ADIS_LIB 33 select IIO_ADIS_LIB
28 select IIO_ADIS_LIB_BUFFER if IIO_BUFFER 34 select IIO_ADIS_LIB_BUFFER if IIO_BUFFER
29 help 35 help
30 Say yes here to build support for Analog Devices adis16204 Programmable 36 Say Y here to build support for Analog Devices adis16204 Programmable
31 High-g Digital Impact Sensor and Recorder. 37 High-g Digital Impact Sensor and Recorder.
32 38
39 To compile this driver as a module, say M here: the module will be
40 called adis16204.
41
33config ADIS16209 42config ADIS16209
34 tristate "Analog Devices ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer" 43 tristate "Analog Devices ADIS16209 Dual-Axis Digital Inclinometer and Accelerometer"
35 depends on SPI 44 depends on SPI
36 select IIO_ADIS_LIB 45 select IIO_ADIS_LIB
37 select IIO_ADIS_LIB_BUFFER if IIO_BUFFER 46 select IIO_ADIS_LIB_BUFFER if IIO_BUFFER
38 help 47 help
39 Say yes here to build support for Analog Devices adis16209 dual-axis digital inclinometer 48 Say Y here to build support for Analog Devices adis16209 dual-axis digital inclinometer
40 and accelerometer. 49 and accelerometer.
41 50
51 To compile this driver as a module, say M here: the module will be
52 called adis16209.
53
42config ADIS16220 54config ADIS16220
43 tristate "Analog Devices ADIS16220 Programmable Digital Vibration Sensor" 55 tristate "Analog Devices ADIS16220 Programmable Digital Vibration Sensor"
44 depends on SPI 56 depends on SPI
45 select IIO_ADIS_LIB 57 select IIO_ADIS_LIB
46 help 58 help
47 Say yes here to build support for Analog Devices adis16220 programmable 59 Say Y here to build support for Analog Devices adis16220 programmable
48 digital vibration sensor. 60 digital vibration sensor.
49 61
62 To compile this driver as a module, say M here: the module will be
63 called adis16220.
64
50config ADIS16240 65config ADIS16240
51 tristate "Analog Devices ADIS16240 Programmable Impact Sensor and Recorder" 66 tristate "Analog Devices ADIS16240 Programmable Impact Sensor and Recorder"
52 depends on SPI 67 depends on SPI
53 select IIO_ADIS_LIB 68 select IIO_ADIS_LIB
54 select IIO_ADIS_LIB_BUFFER if IIO_BUFFER 69 select IIO_ADIS_LIB_BUFFER if IIO_BUFFER
55 help 70 help
56 Say yes here to build support for Analog Devices adis16240 programmable 71 Say Y here to build support for Analog Devices adis16240 programmable
57 impact Sensor and recorder. 72 impact Sensor and recorder.
58 73
74 To compile this driver as a module, say M here: the module will be
75 called adis16240.
76
59config LIS3L02DQ 77config LIS3L02DQ
60 tristate "ST Microelectronics LIS3L02DQ Accelerometer Driver" 78 tristate "ST Microelectronics LIS3L02DQ Accelerometer Driver"
61 depends on SPI 79 depends on SPI
@@ -63,16 +81,21 @@ config LIS3L02DQ
63 depends on !IIO_BUFFER || IIO_KFIFO_BUF 81 depends on !IIO_BUFFER || IIO_KFIFO_BUF
64 depends on GPIOLIB 82 depends on GPIOLIB
65 help 83 help
66 Say yes here to build SPI support for the ST microelectronics 84 Say Y here to build SPI support for the ST microelectronics
67 accelerometer. The driver supplies direct access via sysfs files 85 accelerometer. The driver supplies direct access via sysfs files
68 and an event interface via a character device. 86 and an event interface via a character device.
69 87
88 To compile this driver as a module, say M here: the module will be
89 called lis3l02dq.
90
70config SCA3000 91config SCA3000
71 depends on IIO_BUFFER 92 depends on IIO_BUFFER
72 depends on SPI 93 depends on SPI
73 tristate "VTI SCA3000 series accelerometers" 94 tristate "VTI SCA3000 series accelerometers"
74 help 95 help
75 Say yes here to build support for the VTI SCA3000 series of SPI 96 Say Y here to build support for the VTI SCA3000 series of SPI
76 accelerometers. These devices use a hardware ring buffer. 97 accelerometers. These devices use a hardware ring buffer.
77 98
99 To compile this driver as a module, say M here: the module will be
100 called sca3000.
78endmenu 101endmenu
diff --git a/drivers/staging/iio/accel/lis3l02dq_ring.c b/drivers/staging/iio/accel/lis3l02dq_ring.c
index 61f94221b8b7..9efc77b0ebdd 100644
--- a/drivers/staging/iio/accel/lis3l02dq_ring.c
+++ b/drivers/staging/iio/accel/lis3l02dq_ring.c
@@ -35,6 +35,7 @@ irqreturn_t lis3l02dq_data_rdy_trig_poll(int irq, void *private)
35 iio_trigger_poll(st->trig); 35 iio_trigger_poll(st->trig);
36 return IRQ_HANDLED; 36 return IRQ_HANDLED;
37 } 37 }
38
38 return IRQ_WAKE_THREAD; 39 return IRQ_WAKE_THREAD;
39} 40}
40 41
diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c
index c110a255d4e8..f6526aa22e8a 100644
--- a/drivers/staging/iio/adc/ad7192.c
+++ b/drivers/staging/iio/adc/ad7192.c
@@ -223,7 +223,8 @@ static int ad7192_setup(struct ad7192_state *st,
223 id &= AD7192_ID_MASK; 223 id &= AD7192_ID_MASK;
224 224
225 if (id != st->devid) 225 if (id != st->devid)
226 dev_warn(&st->sd.spi->dev, "device ID query failed (0x%X)\n", id); 226 dev_warn(&st->sd.spi->dev, "device ID query failed (0x%X)\n",
227 id);
227 228
228 switch (pdata->clock_source_sel) { 229 switch (pdata->clock_source_sel) {
229 case AD7192_CLK_EXT_MCLK1_2: 230 case AD7192_CLK_EXT_MCLK1_2:
diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c
index d215edf66af2..4d4870787eed 100644
--- a/drivers/staging/iio/adc/ad7280a.c
+++ b/drivers/staging/iio/adc/ad7280a.c
@@ -188,7 +188,7 @@ static void ad7280_delay(struct ad7280_state *st)
188 if (st->readback_delay_us < 50) 188 if (st->readback_delay_us < 50)
189 udelay(st->readback_delay_us); 189 udelay(st->readback_delay_us);
190 else 190 else
191 msleep(1); 191 usleep_range(250, 500);
192} 192}
193 193
194static int __ad7280_read32(struct ad7280_state *st, unsigned *val) 194static int __ad7280_read32(struct ad7280_state *st, unsigned *val)
diff --git a/drivers/staging/iio/adc/ad7606_spi.c b/drivers/staging/iio/adc/ad7606_spi.c
index 6a8ecd73a1a7..7303983e64a7 100644
--- a/drivers/staging/iio/adc/ad7606_spi.c
+++ b/drivers/staging/iio/adc/ad7606_spi.c
@@ -23,7 +23,7 @@ static int ad7606_spi_read_block(struct device *dev,
23 int i, ret; 23 int i, ret;
24 unsigned short *data = buf; 24 unsigned short *data = buf;
25 25
26 ret = spi_read(spi, (u8 *)buf, count * 2); 26 ret = spi_read(spi, buf, count * 2);
27 if (ret < 0) { 27 if (ret < 0) {
28 dev_err(&spi->dev, "SPI read error\n"); 28 dev_err(&spi->dev, "SPI read error\n");
29 return ret; 29 return ret;
diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c
index 734a7e4886a0..48b1c3740030 100644
--- a/drivers/staging/iio/adc/ad7816.c
+++ b/drivers/staging/iio/adc/ad7816.c
@@ -152,7 +152,8 @@ static ssize_t ad7816_show_available_modes(struct device *dev,
152 return sprintf(buf, "full\npower-save\n"); 152 return sprintf(buf, "full\npower-save\n");
153} 153}
154 154
155static IIO_DEVICE_ATTR(available_modes, S_IRUGO, ad7816_show_available_modes, NULL, 0); 155static IIO_DEVICE_ATTR(available_modes, S_IRUGO, ad7816_show_available_modes,
156 NULL, 0);
156 157
157static ssize_t ad7816_show_channel(struct device *dev, 158static ssize_t ad7816_show_channel(struct device *dev,
158 struct device_attribute *attr, 159 struct device_attribute *attr,
diff --git a/drivers/staging/iio/adc/lpc32xx_adc.c b/drivers/staging/iio/adc/lpc32xx_adc.c
index 4708e9a41633..5331c442fcfc 100644
--- a/drivers/staging/iio/adc/lpc32xx_adc.c
+++ b/drivers/staging/iio/adc/lpc32xx_adc.c
@@ -116,7 +116,7 @@ static const struct iio_chan_spec lpc32xx_adc_iio_channels[] = {
116 116
117static irqreturn_t lpc32xx_adc_isr(int irq, void *dev_id) 117static irqreturn_t lpc32xx_adc_isr(int irq, void *dev_id)
118{ 118{
119 struct lpc32xx_adc_info *info = (struct lpc32xx_adc_info *) dev_id; 119 struct lpc32xx_adc_info *info = dev_id;
120 120
121 /* Read value and clear irq */ 121 /* Read value and clear irq */
122 info->value = __raw_readl(LPC32XX_ADC_VALUE(info->adc_base)) & 122 info->value = __raw_readl(LPC32XX_ADC_VALUE(info->adc_base)) &
diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c
index 51931045bedd..f053535385bf 100644
--- a/drivers/staging/iio/adc/mxs-lradc.c
+++ b/drivers/staging/iio/adc/mxs-lradc.c
@@ -455,7 +455,8 @@ static void mxs_lradc_setup_ts_channel(struct mxs_lradc *lradc, unsigned ch)
455 * SoC's delay unit and start the conversion later 455 * SoC's delay unit and start the conversion later
456 * and automatically. 456 * and automatically.
457 */ 457 */
458 mxs_lradc_reg_wrt(lradc, LRADC_DELAY_TRIGGER(0) | /* don't trigger ADC */ 458 mxs_lradc_reg_wrt(lradc,
459 LRADC_DELAY_TRIGGER(0) | /* don't trigger ADC */
459 LRADC_DELAY_TRIGGER_DELAYS(1 << 3) | /* trigger DELAY unit#3 */ 460 LRADC_DELAY_TRIGGER_DELAYS(1 << 3) | /* trigger DELAY unit#3 */
460 LRADC_DELAY_KICK | 461 LRADC_DELAY_KICK |
461 LRADC_DELAY_DELAY(lradc->settling_delay), 462 LRADC_DELAY_DELAY(lradc->settling_delay),
@@ -513,7 +514,8 @@ static void mxs_lradc_setup_ts_pressure(struct mxs_lradc *lradc, unsigned ch1,
513 * SoC's delay unit and start the conversion later 514 * SoC's delay unit and start the conversion later
514 * and automatically. 515 * and automatically.
515 */ 516 */
516 mxs_lradc_reg_wrt(lradc, LRADC_DELAY_TRIGGER(0) | /* don't trigger ADC */ 517 mxs_lradc_reg_wrt(lradc,
518 LRADC_DELAY_TRIGGER(0) | /* don't trigger ADC */
517 LRADC_DELAY_TRIGGER_DELAYS(1 << 3) | /* trigger DELAY unit#3 */ 519 LRADC_DELAY_TRIGGER_DELAYS(1 << 3) | /* trigger DELAY unit#3 */
518 LRADC_DELAY_KICK | 520 LRADC_DELAY_KICK |
519 LRADC_DELAY_DELAY(lradc->settling_delay), LRADC_DELAY(2)); 521 LRADC_DELAY_DELAY(lradc->settling_delay), LRADC_DELAY(2));
diff --git a/drivers/staging/iio/adc/spear_adc.c b/drivers/staging/iio/adc/spear_adc.c
index 750697832b96..8ad71691fc09 100644
--- a/drivers/staging/iio/adc/spear_adc.c
+++ b/drivers/staging/iio/adc/spear_adc.c
@@ -98,7 +98,7 @@ static void spear_adc_set_clk(struct spear_adc_state *st, u32 val)
98 u32 clk_high, clk_low, count; 98 u32 clk_high, clk_low, count;
99 u32 apb_clk = clk_get_rate(st->clk); 99 u32 apb_clk = clk_get_rate(st->clk);
100 100
101 count = (apb_clk + val - 1) / val; 101 count = DIV_ROUND_UP(apb_clk, val);
102 clk_low = count / 2; 102 clk_low = count / 2;
103 clk_high = count - clk_low; 103 clk_high = count - clk_low;
104 st->current_clk = apb_clk / count; 104 st->current_clk = apb_clk / count;
@@ -226,7 +226,7 @@ static const struct iio_chan_spec spear_adc_iio_channels[] = {
226 226
227static irqreturn_t spear_adc_isr(int irq, void *dev_id) 227static irqreturn_t spear_adc_isr(int irq, void *dev_id)
228{ 228{
229 struct spear_adc_state *st = (struct spear_adc_state *)dev_id; 229 struct spear_adc_state *st = dev_id;
230 230
231 /* Read value to clear IRQ */ 231 /* Read value to clear IRQ */
232 st->value = spear_adc_get_average(st); 232 st->value = spear_adc_get_average(st);
diff --git a/drivers/staging/iio/addac/Kconfig b/drivers/staging/iio/addac/Kconfig
index e6795e0bed1d..0ed7e13e2283 100644
--- a/drivers/staging/iio/addac/Kconfig
+++ b/drivers/staging/iio/addac/Kconfig
@@ -10,6 +10,9 @@ config ADT7316
10 Say yes here to build support for Analog Devices ADT7316, ADT7317, ADT7318 10 Say yes here to build support for Analog Devices ADT7316, ADT7317, ADT7318
11 and ADT7516, ADT7517, ADT7519 temperature sensors, ADC and DAC. 11 and ADT7516, ADT7517, ADT7519 temperature sensors, ADC and DAC.
12 12
13 To compile this driver as a module, choose M here: the module will
14 be called adt7316.
15
13config ADT7316_SPI 16config ADT7316_SPI
14 tristate "support SPI bus connection" 17 tristate "support SPI bus connection"
15 depends on SPI && ADT7316 18 depends on SPI && ADT7316
@@ -18,6 +21,9 @@ config ADT7316_SPI
18 Say yes here to build SPI bus support for Analog Devices ADT7316/7/8 21 Say yes here to build SPI bus support for Analog Devices ADT7316/7/8
19 and ADT7516/7/9. 22 and ADT7516/7/9.
20 23
24 To compile this driver as a module, choose M here: the module will
25 be called adt7316_spi.
26
21config ADT7316_I2C 27config ADT7316_I2C
22 tristate "support I2C bus connection" 28 tristate "support I2C bus connection"
23 depends on I2C && ADT7316 29 depends on I2C && ADT7316
@@ -25,4 +31,7 @@ config ADT7316_I2C
25 Say yes here to build I2C bus support for Analog Devices ADT7316/7/8 31 Say yes here to build I2C bus support for Analog Devices ADT7316/7/8
26 and ADT7516/7/9. 32 and ADT7516/7/9.
27 33
34 To compile this driver as a module, choose M here: the module will
35 be called adt7316_i2c.
36
28endmenu 37endmenu
diff --git a/drivers/staging/iio/addac/adt7316.h b/drivers/staging/iio/addac/adt7316.h
index ec50bf34628d..ec40fbb698a6 100644
--- a/drivers/staging/iio/addac/adt7316.h
+++ b/drivers/staging/iio/addac/adt7316.h
@@ -30,6 +30,7 @@ extern const struct dev_pm_ops adt7316_pm_ops;
30#else 30#else
31#define ADT7316_PM_OPS NULL 31#define ADT7316_PM_OPS NULL
32#endif 32#endif
33int adt7316_probe(struct device *dev, struct adt7316_bus *bus, const char *name); 33int adt7316_probe(struct device *dev, struct adt7316_bus *bus,
34 const char *name);
34 35
35#endif 36#endif
diff --git a/drivers/staging/iio/gyro/Kconfig b/drivers/staging/iio/gyro/Kconfig
index 88b199bb2926..f62f68fd6f3f 100644
--- a/drivers/staging/iio/gyro/Kconfig
+++ b/drivers/staging/iio/gyro/Kconfig
@@ -7,7 +7,10 @@ config ADIS16060
7 tristate "Analog Devices ADIS16060 Yaw Rate Gyroscope with SPI driver" 7 tristate "Analog Devices ADIS16060 Yaw Rate Gyroscope with SPI driver"
8 depends on SPI 8 depends on SPI
9 help 9 help
10 Say yes here to build support for Analog Devices adis16060 wide bandwidth 10 Say Y (yes) here to build support for Analog Devices adis16060 wide bandwidth
11 yaw rate gyroscope with SPI. 11 yaw rate gyroscope with SPI.
12 12
13 To compile this driver as a module, say M here: the module will be
14 called adis16060. If unsure, say N.
15
13endmenu 16endmenu
diff --git a/drivers/staging/iio/light/tsl2x7x_core.c b/drivers/staging/iio/light/tsl2x7x_core.c
index e0d88fa2a5b5..423f96bdf595 100644
--- a/drivers/staging/iio/light/tsl2x7x_core.c
+++ b/drivers/staging/iio/light/tsl2x7x_core.c
@@ -1040,8 +1040,8 @@ static ssize_t tsl2x7x_als_persistence_show(struct device *dev,
1040 y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.als_time) + 1; 1040 y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.als_time) + 1;
1041 z = y * TSL2X7X_MIN_ITIME; 1041 z = y * TSL2X7X_MIN_ITIME;
1042 filter_delay = z * (chip->tsl2x7x_settings.persistence & 0x0F); 1042 filter_delay = z * (chip->tsl2x7x_settings.persistence & 0x0F);
1043 y = (filter_delay / 1000); 1043 y = filter_delay / 1000;
1044 z = (filter_delay % 1000); 1044 z = filter_delay % 1000;
1045 1045
1046 return snprintf(buf, PAGE_SIZE, "%d.%03d\n", y, z); 1046 return snprintf(buf, PAGE_SIZE, "%d.%03d\n", y, z);
1047} 1047}
@@ -1086,8 +1086,8 @@ static ssize_t tsl2x7x_prox_persistence_show(struct device *dev,
1086 y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.prx_time) + 1; 1086 y = (TSL2X7X_MAX_TIMER_CNT - (u8)chip->tsl2x7x_settings.prx_time) + 1;
1087 z = y * TSL2X7X_MIN_ITIME; 1087 z = y * TSL2X7X_MIN_ITIME;
1088 filter_delay = z * ((chip->tsl2x7x_settings.persistence & 0xF0) >> 4); 1088 filter_delay = z * ((chip->tsl2x7x_settings.persistence & 0xF0) >> 4);
1089 y = (filter_delay / 1000); 1089 y = filter_delay / 1000;
1090 z = (filter_delay % 1000); 1090 z = filter_delay % 1000;
1091 1091
1092 return snprintf(buf, PAGE_SIZE, "%d.%03d\n", y, z); 1092 return snprintf(buf, PAGE_SIZE, "%d.%03d\n", y, z);
1093} 1093}
@@ -1573,8 +1573,7 @@ static struct attribute *tsl2x7x_ALS_device_attrs[] = {
1573 &dev_attr_power_state.attr, 1573 &dev_attr_power_state.attr,
1574 &dev_attr_in_illuminance0_calibscale_available.attr, 1574 &dev_attr_in_illuminance0_calibscale_available.attr,
1575 &dev_attr_in_illuminance0_integration_time.attr, 1575 &dev_attr_in_illuminance0_integration_time.attr,
1576 &iio_const_attr_in_illuminance0_integration_time_available\ 1576 &iio_const_attr_in_illuminance0_integration_time_available.dev_attr.attr,
1577 .dev_attr.attr,
1578 &dev_attr_in_illuminance0_target_input.attr, 1577 &dev_attr_in_illuminance0_target_input.attr,
1579 &dev_attr_in_illuminance0_calibrate.attr, 1578 &dev_attr_in_illuminance0_calibrate.attr,
1580 &dev_attr_in_illuminance0_lux_table.attr, 1579 &dev_attr_in_illuminance0_lux_table.attr,
@@ -1591,8 +1590,7 @@ static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = {
1591 &dev_attr_power_state.attr, 1590 &dev_attr_power_state.attr,
1592 &dev_attr_in_illuminance0_calibscale_available.attr, 1591 &dev_attr_in_illuminance0_calibscale_available.attr,
1593 &dev_attr_in_illuminance0_integration_time.attr, 1592 &dev_attr_in_illuminance0_integration_time.attr,
1594 &iio_const_attr_in_illuminance0_integration_time_available\ 1593 &iio_const_attr_in_illuminance0_integration_time_available.dev_attr.attr,
1595 .dev_attr.attr,
1596 &dev_attr_in_illuminance0_target_input.attr, 1594 &dev_attr_in_illuminance0_target_input.attr,
1597 &dev_attr_in_illuminance0_calibrate.attr, 1595 &dev_attr_in_illuminance0_calibrate.attr,
1598 &dev_attr_in_illuminance0_lux_table.attr, 1596 &dev_attr_in_illuminance0_lux_table.attr,
@@ -1611,8 +1609,7 @@ static struct attribute *tsl2x7x_ALSPRX2_device_attrs[] = {
1611 &dev_attr_power_state.attr, 1609 &dev_attr_power_state.attr,
1612 &dev_attr_in_illuminance0_calibscale_available.attr, 1610 &dev_attr_in_illuminance0_calibscale_available.attr,
1613 &dev_attr_in_illuminance0_integration_time.attr, 1611 &dev_attr_in_illuminance0_integration_time.attr,
1614 &iio_const_attr_in_illuminance0_integration_time_available\ 1612 &iio_const_attr_in_illuminance0_integration_time_available.dev_attr.attr,
1615 .dev_attr.attr,
1616 &dev_attr_in_illuminance0_target_input.attr, 1613 &dev_attr_in_illuminance0_target_input.attr,
1617 &dev_attr_in_illuminance0_calibrate.attr, 1614 &dev_attr_in_illuminance0_calibrate.attr,
1618 &dev_attr_in_illuminance0_lux_table.attr, 1615 &dev_attr_in_illuminance0_lux_table.attr,
diff --git a/drivers/staging/iio/meter/Kconfig b/drivers/staging/iio/meter/Kconfig
index e53274b64ae1..64cd3704ec6e 100644
--- a/drivers/staging/iio/meter/Kconfig
+++ b/drivers/staging/iio/meter/Kconfig
@@ -10,6 +10,9 @@ config ADE7753
10 Say yes here to build support for Analog Devices ADE7753 Single-Phase Multifunction 10 Say yes here to build support for Analog Devices ADE7753 Single-Phase Multifunction
11 Metering IC with di/dt Sensor Interface. 11 Metering IC with di/dt Sensor Interface.
12 12
13 To compile this driver as a module, choose M here: the
14 module will be called ade7753.
15
13config ADE7754 16config ADE7754
14 tristate "Analog Devices ADE7754 Polyphase Multifunction Energy Metering IC Driver" 17 tristate "Analog Devices ADE7754 Polyphase Multifunction Energy Metering IC Driver"
15 depends on SPI 18 depends on SPI
@@ -17,6 +20,9 @@ config ADE7754
17 Say yes here to build support for Analog Devices ADE7754 Polyphase 20 Say yes here to build support for Analog Devices ADE7754 Polyphase
18 Multifunction Energy Metering IC Driver. 21 Multifunction Energy Metering IC Driver.
19 22
23 To compile this driver as a module, choose M here: the
24 module will be called ade7754.
25
20config ADE7758 26config ADE7758
21 tristate "Analog Devices ADE7758 Poly Phase Multifunction Energy Metering IC Driver" 27 tristate "Analog Devices ADE7758 Poly Phase Multifunction Energy Metering IC Driver"
22 depends on SPI 28 depends on SPI
@@ -26,6 +32,9 @@ config ADE7758
26 Say yes here to build support for Analog Devices ADE7758 Polyphase 32 Say yes here to build support for Analog Devices ADE7758 Polyphase
27 Multifunction Energy Metering IC with Per Phase Information Driver. 33 Multifunction Energy Metering IC with Per Phase Information Driver.
28 34
35 To compile this driver as a module, choose M here: the
36 module will be called ade7758.
37
29config ADE7759 38config ADE7759
30 tristate "Analog Devices ADE7759 Active Energy Metering IC Driver" 39 tristate "Analog Devices ADE7759 Active Energy Metering IC Driver"
31 depends on SPI 40 depends on SPI
@@ -33,6 +42,9 @@ config ADE7759
33 Say yes here to build support for Analog Devices ADE7758 Active Energy 42 Say yes here to build support for Analog Devices ADE7758 Active Energy
34 Metering IC with di/dt Sensor Interface. 43 Metering IC with di/dt Sensor Interface.
35 44
45 To compile this driver as a module, choose M here: the
46 module will be called ade7759.
47
36config ADE7854 48config ADE7854
37 tristate "Analog Devices ADE7854/58/68/78 Polyphase Multifunction Energy Metering IC Driver" 49 tristate "Analog Devices ADE7854/58/68/78 Polyphase Multifunction Energy Metering IC Driver"
38 depends on SPI || I2C 50 depends on SPI || I2C
@@ -40,6 +52,9 @@ config ADE7854
40 Say yes here to build support for Analog Devices ADE7854/58/68/78 Polyphase 52 Say yes here to build support for Analog Devices ADE7854/58/68/78 Polyphase
41 Multifunction Energy Metering IC Driver. 53 Multifunction Energy Metering IC Driver.
42 54
55 To compile this driver as a module, choose M here: the
56 module will be called ade7854.
57
43config ADE7854_I2C 58config ADE7854_I2C
44 tristate "support I2C bus connection" 59 tristate "support I2C bus connection"
45 depends on ADE7854 && I2C 60 depends on ADE7854 && I2C
diff --git a/drivers/staging/iio/trigger/Kconfig b/drivers/staging/iio/trigger/Kconfig
index 2fd18c60323d..710a2f3e787e 100644
--- a/drivers/staging/iio/trigger/Kconfig
+++ b/drivers/staging/iio/trigger/Kconfig
@@ -1,4 +1,4 @@
1# 1 #
2# Industrial I/O standalone triggers 2# Industrial I/O standalone triggers
3# 3#
4comment "Triggers - standalone" 4comment "Triggers - standalone"
@@ -12,6 +12,9 @@ config IIO_PERIODIC_RTC_TRIGGER
12 Provides support for using periodic capable real time 12 Provides support for using periodic capable real time
13 clocks as IIO triggers. 13 clocks as IIO triggers.
14 14
15 To compile this driver as a module, choose M here: the
16 module will be called iio-trig-periodic-rtc.
17
15config IIO_BFIN_TMR_TRIGGER 18config IIO_BFIN_TMR_TRIGGER
16 tristate "Blackfin TIMER trigger" 19 tristate "Blackfin TIMER trigger"
17 depends on BLACKFIN 20 depends on BLACKFIN
diff --git a/drivers/staging/iio/trigger/iio-trig-periodic-rtc.c b/drivers/staging/iio/trigger/iio-trig-periodic-rtc.c
index 82c2e6d3f5a7..a24caf73ae0b 100644
--- a/drivers/staging/iio/trigger/iio-trig-periodic-rtc.c
+++ b/drivers/staging/iio/trigger/iio-trig-periodic-rtc.c
@@ -72,7 +72,8 @@ static ssize_t iio_trig_periodic_write_freq(struct device *dev,
72 if (val > 0) { 72 if (val > 0) {
73 ret = rtc_irq_set_freq(trig_info->rtc, &trig_info->task, val); 73 ret = rtc_irq_set_freq(trig_info->rtc, &trig_info->task, val);
74 if (ret == 0 && trig_info->state && trig_info->frequency == 0) 74 if (ret == 0 && trig_info->state && trig_info->frequency == 0)
75 ret = rtc_irq_set_state(trig_info->rtc, &trig_info->task, 1); 75 ret = rtc_irq_set_state(trig_info->rtc,
76 &trig_info->task, 1);
76 } else if (val == 0) { 77 } else if (val == 0) {
77 ret = rtc_irq_set_state(trig_info->rtc, &trig_info->task, 0); 78 ret = rtc_irq_set_state(trig_info->rtc, &trig_info->task, 0);
78 } else 79 } else
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h
index 8888b2756174..2e5a9e5965b1 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_debug.h
@@ -242,18 +242,6 @@ do { \
242 242
243#define LCONSOLE_EMERG(format, ...) CDEBUG(D_CONSOLE | D_EMERG, format, ## __VA_ARGS__) 243#define LCONSOLE_EMERG(format, ...) CDEBUG(D_CONSOLE | D_EMERG, format, ## __VA_ARGS__)
244 244
245void libcfs_log_goto(struct libcfs_debug_msg_data *, const char *, long_ptr_t);
246#define GOTO(label, rc) \
247do { \
248 if (cfs_cdebug_show(D_TRACE, DEBUG_SUBSYSTEM)) { \
249 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, D_TRACE, NULL); \
250 libcfs_log_goto(&msgdata, #label, (long_ptr_t)(rc)); \
251 } else { \
252 (void)(rc); \
253 } \
254 goto label; \
255} while (0)
256
257int libcfs_debug_msg(struct libcfs_debug_msg_data *msgdata, 245int libcfs_debug_msg(struct libcfs_debug_msg_data *msgdata,
258 const char *format1, ...) 246 const char *format1, ...)
259 __attribute__ ((format (printf, 2, 3))); 247 __attribute__ ((format (printf, 2, 3)));
diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
index 8f5cdd584f85..62b575deac3a 100644
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c
@@ -930,8 +930,7 @@ kiblnd_close_peer_conns_locked (kib_peer_t *peer, int why)
930 list_for_each_safe (ctmp, cnxt, &peer->ibp_conns) { 930 list_for_each_safe (ctmp, cnxt, &peer->ibp_conns) {
931 conn = list_entry(ctmp, kib_conn_t, ibc_list); 931 conn = list_entry(ctmp, kib_conn_t, ibc_list);
932 932
933 CDEBUG(D_NET, "Closing conn -> %s, " 933 CDEBUG(D_NET, "Closing conn -> %s, version: %x, reason: %d\n",
934 "version: %x, reason: %d\n",
935 libcfs_nid2str(peer->ibp_nid), 934 libcfs_nid2str(peer->ibp_nid),
936 conn->ibc_version, why); 935 conn->ibc_version, why);
937 936
@@ -958,8 +957,7 @@ kiblnd_close_stale_conns_locked (kib_peer_t *peer,
958 conn->ibc_incarnation == incarnation) 957 conn->ibc_incarnation == incarnation)
959 continue; 958 continue;
960 959
961 CDEBUG(D_NET, "Closing stale conn -> %s version: %x, " 960 CDEBUG(D_NET, "Closing stale conn -> %s version: %x, incarnation:%#llx(%x, %#llx)\n",
962 "incarnation:%#llx(%x, %#llx)\n",
963 libcfs_nid2str(peer->ibp_nid), 961 libcfs_nid2str(peer->ibp_nid),
964 conn->ibc_version, conn->ibc_incarnation, 962 conn->ibc_version, conn->ibc_incarnation,
965 version, incarnation); 963 version, incarnation);
@@ -1599,8 +1597,7 @@ kiblnd_fmr_pool_map(kib_fmr_poolset_t *fps, __u64 *pages, int npages,
1599 1597
1600 if (fps->fps_increasing) { 1598 if (fps->fps_increasing) {
1601 spin_unlock(&fps->fps_lock); 1599 spin_unlock(&fps->fps_lock);
1602 CDEBUG(D_NET, "Another thread is allocating new " 1600 CDEBUG(D_NET, "Another thread is allocating new FMR pool, waiting for her to complete\n");
1603 "FMR pool, waiting for her to complete\n");
1604 schedule(); 1601 schedule();
1605 goto again; 1602 goto again;
1606 1603
@@ -1801,8 +1798,7 @@ kiblnd_pool_alloc_node(kib_poolset_t *ps)
1801 if (ps->ps_increasing) { 1798 if (ps->ps_increasing) {
1802 /* another thread is allocating a new pool */ 1799 /* another thread is allocating a new pool */
1803 spin_unlock(&ps->ps_lock); 1800 spin_unlock(&ps->ps_lock);
1804 CDEBUG(D_NET, "Another thread is allocating new " 1801 CDEBUG(D_NET, "Another thread is allocating new %s pool, waiting for her to complete\n",
1805 "%s pool, waiting for her to complete\n",
1806 ps->ps_name); 1802 ps->ps_name);
1807 schedule(); 1803 schedule();
1808 goto again; 1804 goto again;
@@ -2411,7 +2407,7 @@ kiblnd_hdev_setup_mrs(kib_hca_dev_t *hdev)
2411 goto out; 2407 goto out;
2412 } 2408 }
2413 2409
2414 mr_size = (1ULL << hdev->ibh_mr_shift); 2410 mr_size = 1ULL << hdev->ibh_mr_shift;
2415 mm_size = (unsigned long)high_memory - PAGE_OFFSET; 2411 mm_size = (unsigned long)high_memory - PAGE_OFFSET;
2416 2412
2417 hdev->ibh_nmrs = (int)((mm_size + mr_size - 1) >> hdev->ibh_mr_shift); 2413 hdev->ibh_nmrs = (int)((mm_size + mr_size - 1) >> hdev->ibh_mr_shift);
@@ -3081,7 +3077,7 @@ kiblnd_startup (lnet_ni_t *ni)
3081 LIBCFS_ALLOC(net, sizeof(*net)); 3077 LIBCFS_ALLOC(net, sizeof(*net));
3082 ni->ni_data = net; 3078 ni->ni_data = net;
3083 if (net == NULL) 3079 if (net == NULL)
3084 goto failed; 3080 goto net_failed;
3085 3081
3086 do_gettimeofday(&tv); 3082 do_gettimeofday(&tv);
3087 net->ibn_incarnation = (((__u64)tv.tv_sec) * 1000000) + tv.tv_usec; 3083 net->ibn_incarnation = (((__u64)tv.tv_sec) * 1000000) + tv.tv_usec;
@@ -3147,6 +3143,7 @@ failed:
3147 if (net->ibn_dev == NULL && ibdev != NULL) 3143 if (net->ibn_dev == NULL && ibdev != NULL)
3148 kiblnd_destroy_dev(ibdev); 3144 kiblnd_destroy_dev(ibdev);
3149 3145
3146net_failed:
3150 kiblnd_shutdown(ni); 3147 kiblnd_shutdown(ni);
3151 3148
3152 CDEBUG(D_NET, "kiblnd_startup failed\n"); 3149 CDEBUG(D_NET, "kiblnd_startup failed\n");
diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c
index 14c9c8d18d02..b48d7edf5669 100644
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c
@@ -1116,8 +1116,7 @@ kiblnd_init_rdma (kib_conn_t *conn, kib_tx_t *tx, int type,
1116 } 1116 }
1117 1117
1118 if (tx->tx_nwrq == IBLND_RDMA_FRAGS(conn->ibc_version)) { 1118 if (tx->tx_nwrq == IBLND_RDMA_FRAGS(conn->ibc_version)) {
1119 CERROR("RDMA too fragmented for %s (%d): " 1119 CERROR("RDMA too fragmented for %s (%d): %d/%d src %d/%d dst frags\n",
1120 "%d/%d src %d/%d dst frags\n",
1121 libcfs_nid2str(conn->ibc_peer->ibp_nid), 1120 libcfs_nid2str(conn->ibc_peer->ibp_nid),
1122 IBLND_RDMA_FRAGS(conn->ibc_version), 1121 IBLND_RDMA_FRAGS(conn->ibc_version),
1123 srcidx, srcrd->rd_nfrags, 1122 srcidx, srcrd->rd_nfrags,
@@ -2254,8 +2253,8 @@ kiblnd_passive_connect (struct rdma_cm_id *cmid, void *priv, int priv_nob)
2254 if (ni == NULL || /* no matching net */ 2253 if (ni == NULL || /* no matching net */
2255 ni->ni_nid != reqmsg->ibm_dstnid || /* right NET, wrong NID! */ 2254 ni->ni_nid != reqmsg->ibm_dstnid || /* right NET, wrong NID! */
2256 net->ibn_dev != ibdev) { /* wrong device */ 2255 net->ibn_dev != ibdev) { /* wrong device */
2257 CERROR("Can't accept %s on %s (%s:%d:%pI4h): " 2256 CERROR("Can't accept %s on %s (%s:%d:%pI4h): bad dst nid %s\n",
2258 "bad dst nid %s\n", libcfs_nid2str(nid), 2257 libcfs_nid2str(nid),
2259 ni == NULL ? "NA" : libcfs_nid2str(ni->ni_nid), 2258 ni == NULL ? "NA" : libcfs_nid2str(ni->ni_nid),
2260 ibdev->ibd_ifname, ibdev->ibd_nnets, 2259 ibdev->ibd_ifname, ibdev->ibd_nnets,
2261 &ibdev->ibd_ifip, 2260 &ibdev->ibd_ifip,
@@ -2295,8 +2294,7 @@ kiblnd_passive_connect (struct rdma_cm_id *cmid, void *priv, int priv_nob)
2295 2294
2296 if (reqmsg->ibm_u.connparams.ibcp_max_frags != 2295 if (reqmsg->ibm_u.connparams.ibcp_max_frags !=
2297 IBLND_RDMA_FRAGS(version)) { 2296 IBLND_RDMA_FRAGS(version)) {
2298 CERROR("Can't accept %s(version %x): " 2297 CERROR("Can't accept %s(version %x): incompatible max_frags %d (%d wanted)\n",
2299 "incompatible max_frags %d (%d wanted)\n",
2300 libcfs_nid2str(nid), version, 2298 libcfs_nid2str(nid), version,
2301 reqmsg->ibm_u.connparams.ibcp_max_frags, 2299 reqmsg->ibm_u.connparams.ibcp_max_frags,
2302 IBLND_RDMA_FRAGS(version)); 2300 IBLND_RDMA_FRAGS(version));
@@ -2502,8 +2500,7 @@ kiblnd_reconnect (kib_conn_t *conn, int version,
2502 break; 2500 break;
2503 } 2501 }
2504 2502
2505 CNETERR("%s: retrying (%s), %x, %x, " 2503 CNETERR("%s: retrying (%s), %x, %x, queue_dep: %d, max_frag: %d, msg_size: %d\n",
2506 "queue_dep: %d, max_frag: %d, msg_size: %d\n",
2507 libcfs_nid2str(peer->ibp_nid), 2504 libcfs_nid2str(peer->ibp_nid),
2508 reason, IBLND_MSG_VERSION, version, 2505 reason, IBLND_MSG_VERSION, version,
2509 cp != NULL? cp->ibcp_queue_depth :IBLND_MSG_QUEUE_SIZE(version), 2506 cp != NULL? cp->ibcp_queue_depth :IBLND_MSG_QUEUE_SIZE(version),
@@ -2679,8 +2676,7 @@ kiblnd_check_connreply (kib_conn_t *conn, void *priv, int priv_nob)
2679 } 2676 }
2680 2677
2681 if (ver != msg->ibm_version) { 2678 if (ver != msg->ibm_version) {
2682 CERROR("%s replied version %x is different with " 2679 CERROR("%s replied version %x is different with requested version %x\n",
2683 "requested version %x\n",
2684 libcfs_nid2str(peer->ibp_nid), msg->ibm_version, ver); 2680 libcfs_nid2str(peer->ibp_nid), msg->ibm_version, ver);
2685 rc = -EPROTO; 2681 rc = -EPROTO;
2686 goto failed; 2682 goto failed;
@@ -2724,8 +2720,7 @@ kiblnd_check_connreply (kib_conn_t *conn, void *priv, int priv_nob)
2724 read_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags); 2720 read_unlock_irqrestore(&kiblnd_data.kib_global_lock, flags);
2725 2721
2726 if (rc != 0) { 2722 if (rc != 0) {
2727 CERROR("Bad connection reply from %s, rc = %d, " 2723 CERROR("Bad connection reply from %s, rc = %d, version: %x max_frags: %d\n",
2728 "version: %x max_frags: %d\n",
2729 libcfs_nid2str(peer->ibp_nid), rc, 2724 libcfs_nid2str(peer->ibp_nid), rc,
2730 msg->ibm_version, msg->ibm_u.connparams.ibcp_max_frags); 2725 msg->ibm_version, msg->ibm_u.connparams.ibcp_max_frags);
2731 goto failed; 2726 goto failed;
@@ -3060,8 +3055,7 @@ kiblnd_check_conns (int idx)
3060 } 3055 }
3061 3056
3062 if (timedout) { 3057 if (timedout) {
3063 CERROR("Timed out RDMA with %s (%lu): " 3058 CERROR("Timed out RDMA with %s (%lu): c: %u, oc: %u, rc: %u\n",
3064 "c: %u, oc: %u, rc: %u\n",
3065 libcfs_nid2str(peer->ibp_nid), 3059 libcfs_nid2str(peer->ibp_nid),
3066 cfs_duration_sec(cfs_time_current() - 3060 cfs_duration_sec(cfs_time_current() -
3067 peer->ibp_last_alive), 3061 peer->ibp_last_alive),
@@ -3334,10 +3328,8 @@ kiblnd_scheduler(void *arg)
3334 3328
3335 rc = cfs_cpt_bind(lnet_cpt_table(), sched->ibs_cpt); 3329 rc = cfs_cpt_bind(lnet_cpt_table(), sched->ibs_cpt);
3336 if (rc != 0) { 3330 if (rc != 0) {
3337 CWARN("Failed to bind on CPT %d, please verify whether " 3331 CWARN("Failed to bind on CPT %d, please verify whether all CPUs are healthy and reload modules if necessary, otherwise your system might under risk of low performance\n",
3338 "all CPUs are healthy and reload modules if necessary, " 3332 sched->ibs_cpt);
3339 "otherwise your system might under risk of low "
3340 "performance\n", sched->ibs_cpt);
3341 } 3333 }
3342 3334
3343 spin_lock_irqsave(&sched->ibs_lock, flags); 3335 spin_lock_irqsave(&sched->ibs_lock, flags);
@@ -3369,8 +3361,7 @@ kiblnd_scheduler(void *arg)
3369 rc = ib_req_notify_cq(conn->ibc_cq, 3361 rc = ib_req_notify_cq(conn->ibc_cq,
3370 IB_CQ_NEXT_COMP); 3362 IB_CQ_NEXT_COMP);
3371 if (rc < 0) { 3363 if (rc < 0) {
3372 CWARN("%s: ib_req_notify_cq failed: %d, " 3364 CWARN("%s: ib_req_notify_cq failed: %d, closing connection\n",
3373 "closing connection\n",
3374 libcfs_nid2str(conn->ibc_peer->ibp_nid), rc); 3365 libcfs_nid2str(conn->ibc_peer->ibp_nid), rc);
3375 kiblnd_close_conn(conn, -EIO); 3366 kiblnd_close_conn(conn, -EIO);
3376 kiblnd_conn_decref(conn); 3367 kiblnd_conn_decref(conn);
@@ -3383,8 +3374,7 @@ kiblnd_scheduler(void *arg)
3383 } 3374 }
3384 3375
3385 if (rc < 0) { 3376 if (rc < 0) {
3386 CWARN("%s: ib_poll_cq failed: %d, " 3377 CWARN("%s: ib_poll_cq failed: %d, closing connection\n",
3387 "closing connection\n",
3388 libcfs_nid2str(conn->ibc_peer->ibp_nid), 3378 libcfs_nid2str(conn->ibc_peer->ibp_nid),
3389 rc); 3379 rc);
3390 kiblnd_close_conn(conn, -EIO); 3380 kiblnd_close_conn(conn, -EIO);
diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c
index cefdfb6b1bec..8b4a8e9a29b4 100644
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_modparams.c
@@ -222,8 +222,7 @@ kiblnd_tunables_init (void)
222 *kiblnd_tunables.kib_concurrent_sends = *kiblnd_tunables.kib_peertxcredits / 2; 222 *kiblnd_tunables.kib_concurrent_sends = *kiblnd_tunables.kib_peertxcredits / 2;
223 223
224 if (*kiblnd_tunables.kib_concurrent_sends < *kiblnd_tunables.kib_peertxcredits) { 224 if (*kiblnd_tunables.kib_concurrent_sends < *kiblnd_tunables.kib_peertxcredits) {
225 CWARN("Concurrent sends %d is lower than message queue size: %d, " 225 CWARN("Concurrent sends %d is lower than message queue size: %d, performance may drop slightly.\n",
226 "performance may drop slightly.\n",
227 *kiblnd_tunables.kib_concurrent_sends, *kiblnd_tunables.kib_peertxcredits); 226 *kiblnd_tunables.kib_concurrent_sends, *kiblnd_tunables.kib_peertxcredits);
228 } 227 }
229 228
diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c
index 038854e8302f..9188b34e6948 100644
--- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c
+++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c
@@ -337,8 +337,7 @@ ksocknal_associate_route_conn_locked(ksock_route_t *route, ksock_conn_t *conn)
337 &route->ksnr_ipaddr, 337 &route->ksnr_ipaddr,
338 &conn->ksnc_myipaddr); 338 &conn->ksnc_myipaddr);
339 } else { 339 } else {
340 CDEBUG(D_NET, "Rebinding %s %pI4h from " 340 CDEBUG(D_NET, "Rebinding %s %pI4h from %pI4h to %pI4h\n",
341 "%pI4h to %pI4h\n",
342 libcfs_id2str(peer->ksnp_id), 341 libcfs_id2str(peer->ksnp_id),
343 &route->ksnr_ipaddr, 342 &route->ksnr_ipaddr,
344 &route->ksnr_myipaddr, 343 &route->ksnr_myipaddr,
@@ -974,8 +973,7 @@ ksocknal_accept (lnet_ni_t *ni, struct socket *sock)
974 973
975 LIBCFS_ALLOC(cr, sizeof(*cr)); 974 LIBCFS_ALLOC(cr, sizeof(*cr));
976 if (cr == NULL) { 975 if (cr == NULL) {
977 LCONSOLE_ERROR_MSG(0x12f, "Dropping connection request from " 976 LCONSOLE_ERROR_MSG(0x12f, "Dropping connection request from %pI4h: memory exhausted\n",
978 "%pI4h: memory exhausted\n",
979 &peer_ip); 977 &peer_ip);
980 return -ENOMEM; 978 return -ENOMEM;
981 } 979 }
@@ -1288,8 +1286,7 @@ ksocknal_create_conn (lnet_ni_t *ni, ksock_route_t *route,
1288 * socket callbacks. 1286 * socket callbacks.
1289 */ 1287 */
1290 1288
1291 CDEBUG(D_NET, "New conn %s p %d.x %pI4h -> %pI4h/%d" 1289 CDEBUG(D_NET, "New conn %s p %d.x %pI4h -> %pI4h/%d incarnation:%lld sched[%d:%d]\n",
1292 " incarnation:%lld sched[%d:%d]\n",
1293 libcfs_id2str(peerid), conn->ksnc_proto->pro_version, 1290 libcfs_id2str(peerid), conn->ksnc_proto->pro_version,
1294 &conn->ksnc_myipaddr, &conn->ksnc_ipaddr, 1291 &conn->ksnc_myipaddr, &conn->ksnc_ipaddr,
1295 conn->ksnc_port, incarnation, cpt, 1292 conn->ksnc_port, incarnation, cpt,
@@ -1638,37 +1635,32 @@ ksocknal_destroy_conn (ksock_conn_t *conn)
1638 case SOCKNAL_RX_LNET_PAYLOAD: 1635 case SOCKNAL_RX_LNET_PAYLOAD:
1639 last_rcv = conn->ksnc_rx_deadline - 1636 last_rcv = conn->ksnc_rx_deadline -
1640 cfs_time_seconds(*ksocknal_tunables.ksnd_timeout); 1637 cfs_time_seconds(*ksocknal_tunables.ksnd_timeout);
1641 CERROR("Completing partial receive from %s[%d]" 1638 CERROR("Completing partial receive from %s[%d], ip %pI4h:%d, with error, wanted: %d, left: %d, last alive is %ld secs ago\n",
1642 ", ip %pI4h:%d, with error, wanted: %d, left: %d, "
1643 "last alive is %ld secs ago\n",
1644 libcfs_id2str(conn->ksnc_peer->ksnp_id), conn->ksnc_type, 1639 libcfs_id2str(conn->ksnc_peer->ksnp_id), conn->ksnc_type,
1645 &conn->ksnc_ipaddr, conn->ksnc_port, 1640 &conn->ksnc_ipaddr, conn->ksnc_port,
1646 conn->ksnc_rx_nob_wanted, conn->ksnc_rx_nob_left, 1641 conn->ksnc_rx_nob_wanted, conn->ksnc_rx_nob_left,
1647 cfs_duration_sec(cfs_time_sub(cfs_time_current(), 1642 cfs_duration_sec(cfs_time_sub(cfs_time_current(),
1648 last_rcv))); 1643 last_rcv)));
1649 lnet_finalize (conn->ksnc_peer->ksnp_ni, 1644 lnet_finalize (conn->ksnc_peer->ksnp_ni,
1650 conn->ksnc_cookie, -EIO); 1645 conn->ksnc_cookie, -EIO);
1651 break; 1646 break;
1652 case SOCKNAL_RX_LNET_HEADER: 1647 case SOCKNAL_RX_LNET_HEADER:
1653 if (conn->ksnc_rx_started) 1648 if (conn->ksnc_rx_started)
1654 CERROR("Incomplete receive of lnet header from %s" 1649 CERROR("Incomplete receive of lnet header from %s, ip %pI4h:%d, with error, protocol: %d.x.\n",
1655 ", ip %pI4h:%d, with error, protocol: %d.x.\n",
1656 libcfs_id2str(conn->ksnc_peer->ksnp_id), 1650 libcfs_id2str(conn->ksnc_peer->ksnp_id),
1657 &conn->ksnc_ipaddr, conn->ksnc_port, 1651 &conn->ksnc_ipaddr, conn->ksnc_port,
1658 conn->ksnc_proto->pro_version); 1652 conn->ksnc_proto->pro_version);
1659 break; 1653 break;
1660 case SOCKNAL_RX_KSM_HEADER: 1654 case SOCKNAL_RX_KSM_HEADER:
1661 if (conn->ksnc_rx_started) 1655 if (conn->ksnc_rx_started)
1662 CERROR("Incomplete receive of ksock message from %s" 1656 CERROR("Incomplete receive of ksock message from %s, ip %pI4h:%d, with error, protocol: %d.x.\n",
1663 ", ip %pI4h:%d, with error, protocol: %d.x.\n",
1664 libcfs_id2str(conn->ksnc_peer->ksnp_id), 1657 libcfs_id2str(conn->ksnc_peer->ksnp_id),
1665 &conn->ksnc_ipaddr, conn->ksnc_port, 1658 &conn->ksnc_ipaddr, conn->ksnc_port,
1666 conn->ksnc_proto->pro_version); 1659 conn->ksnc_proto->pro_version);
1667 break; 1660 break;
1668 case SOCKNAL_RX_SLOP: 1661 case SOCKNAL_RX_SLOP:
1669 if (conn->ksnc_rx_started) 1662 if (conn->ksnc_rx_started)
1670 CERROR("Incomplete receive of slops from %s" 1663 CERROR("Incomplete receive of slops from %s, ip %pI4h:%d, with error\n",
1671 ", ip %pI4h:%d, with error\n",
1672 libcfs_id2str(conn->ksnc_peer->ksnp_id), 1664 libcfs_id2str(conn->ksnc_peer->ksnp_id),
1673 &conn->ksnc_ipaddr, conn->ksnc_port); 1665 &conn->ksnc_ipaddr, conn->ksnc_port);
1674 break; 1666 break;
@@ -2348,16 +2340,11 @@ ksocknal_base_shutdown(void)
2348static __u64 2340static __u64
2349ksocknal_new_incarnation (void) 2341ksocknal_new_incarnation (void)
2350{ 2342{
2351 struct timeval tv;
2352 2343
2353 /* The incarnation number is the time this module loaded and it 2344 /* The incarnation number is the time this module loaded and it
2354 * identifies this particular instance of the socknal. Hopefully 2345 * identifies this particular instance of the socknal.
2355 * we won't be able to reboot more frequently than 1MHz for the 2346 */
2356 * foreseeable future :) */ 2347 return ktime_get_ns();
2357
2358 do_gettimeofday(&tv);
2359
2360 return (((__u64)tv.tv_sec) * 1000000) + tv.tv_usec;
2361} 2348}
2362 2349
2363static int 2350static int
@@ -2516,22 +2503,21 @@ ksocknal_debug_peerhash (lnet_ni_t *ni)
2516 ksock_route_t *route; 2503 ksock_route_t *route;
2517 ksock_conn_t *conn; 2504 ksock_conn_t *conn;
2518 2505
2519 CWARN ("Active peer on shutdown: %s, ref %d, scnt %d, " 2506 CWARN("Active peer on shutdown: %s, ref %d, scnt %d, closing %d, accepting %d, err %d, zcookie %llu, txq %d, zc_req %d\n",
2520 "closing %d, accepting %d, err %d, zcookie %llu, " 2507 libcfs_id2str(peer->ksnp_id),
2521 "txq %d, zc_req %d\n", libcfs_id2str(peer->ksnp_id), 2508 atomic_read(&peer->ksnp_refcount),
2522 atomic_read(&peer->ksnp_refcount), 2509 peer->ksnp_sharecount, peer->ksnp_closing,
2523 peer->ksnp_sharecount, peer->ksnp_closing, 2510 peer->ksnp_accepting, peer->ksnp_error,
2524 peer->ksnp_accepting, peer->ksnp_error, 2511 peer->ksnp_zc_next_cookie,
2525 peer->ksnp_zc_next_cookie, 2512 !list_empty(&peer->ksnp_tx_queue),
2526 !list_empty(&peer->ksnp_tx_queue), 2513 !list_empty(&peer->ksnp_zc_req_list));
2527 !list_empty(&peer->ksnp_zc_req_list));
2528 2514
2529 list_for_each (tmp, &peer->ksnp_routes) { 2515 list_for_each (tmp, &peer->ksnp_routes) {
2530 route = list_entry(tmp, ksock_route_t, ksnr_list); 2516 route = list_entry(tmp, ksock_route_t, ksnr_list);
2531 CWARN ("Route: ref %d, schd %d, conn %d, cnted %d, " 2517 CWARN("Route: ref %d, schd %d, conn %d, cnted %d, del %d\n",
2532 "del %d\n", atomic_read(&route->ksnr_refcount), 2518 atomic_read(&route->ksnr_refcount),
2533 route->ksnr_scheduled, route->ksnr_connecting, 2519 route->ksnr_scheduled, route->ksnr_connecting,
2534 route->ksnr_connected, route->ksnr_deleted); 2520 route->ksnr_connected, route->ksnr_deleted);
2535 } 2521 }
2536 2522
2537 list_for_each (tmp, &peer->ksnp_conns) { 2523 list_for_each (tmp, &peer->ksnp_conns) {
diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
index d29f5f134b89..e6c1d3647952 100644
--- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
+++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
@@ -551,19 +551,16 @@ ksocknal_process_transmit (ksock_conn_t *conn, ksock_tx_t *tx)
551 if (!conn->ksnc_closing) { 551 if (!conn->ksnc_closing) {
552 switch (rc) { 552 switch (rc) {
553 case -ECONNRESET: 553 case -ECONNRESET:
554 LCONSOLE_WARN("Host %pI4h reset our connection " 554 LCONSOLE_WARN("Host %pI4h reset our connection while we were sending data; it may have rebooted.\n",
555 "while we were sending data; it may have "
556 "rebooted.\n",
557 &conn->ksnc_ipaddr); 555 &conn->ksnc_ipaddr);
558 break; 556 break;
559 default: 557 default:
560 LCONSOLE_WARN("There was an unexpected network error " 558 LCONSOLE_WARN("There was an unexpected network error while writing to %pI4h: %d.\n",
561 "while writing to %pI4h: %d.\n",
562 &conn->ksnc_ipaddr, rc); 559 &conn->ksnc_ipaddr, rc);
563 break; 560 break;
564 } 561 }
565 CDEBUG(D_NET, "[%p] Error %d on write to %s" 562 CDEBUG(D_NET, "[%p] Error %d on write to %s ip %pI4h:%d\n",
566 " ip %pI4h:%d\n", conn, rc, 563 conn, rc,
567 libcfs_id2str(conn->ksnc_peer->ksnp_id), 564 libcfs_id2str(conn->ksnc_peer->ksnp_id),
568 &conn->ksnc_ipaddr, 565 &conn->ksnc_ipaddr,
569 conn->ksnc_port); 566 conn->ksnc_port);
@@ -799,8 +796,7 @@ ksocknal_find_connectable_route_locked (ksock_peer_t *peer)
799 if (!(route->ksnr_retry_interval == 0 || /* first attempt */ 796 if (!(route->ksnr_retry_interval == 0 || /* first attempt */
800 cfs_time_aftereq(now, route->ksnr_timeout))) { 797 cfs_time_aftereq(now, route->ksnr_timeout))) {
801 CDEBUG(D_NET, 798 CDEBUG(D_NET,
802 "Too soon to retry route %pI4h " 799 "Too soon to retry route %pI4h (cnted %d, interval %ld, %ld secs later)\n",
803 "(cnted %d, interval %ld, %ld secs later)\n",
804 &route->ksnr_ipaddr, 800 &route->ksnr_ipaddr,
805 route->ksnr_connected, 801 route->ksnr_connected,
806 route->ksnr_retry_interval, 802 route->ksnr_retry_interval,
@@ -874,8 +870,8 @@ ksocknal_launch_packet (lnet_ni_t *ni, ksock_tx_t *tx, lnet_process_id_t id)
874 write_unlock_bh(g_lock); 870 write_unlock_bh(g_lock);
875 871
876 if ((id.pid & LNET_PID_USERFLAG) != 0) { 872 if ((id.pid & LNET_PID_USERFLAG) != 0) {
877 CERROR("Refusing to create a connection to " 873 CERROR("Refusing to create a connection to userspace process %s\n",
878 "userspace process %s\n", libcfs_id2str(id)); 874 libcfs_id2str(id));
879 return -EHOSTUNREACH; 875 return -EHOSTUNREACH;
880 } 876 }
881 877
@@ -1132,18 +1128,17 @@ ksocknal_process_receive (ksock_conn_t *conn)
1132 LASSERT (rc != -EAGAIN); 1128 LASSERT (rc != -EAGAIN);
1133 1129
1134 if (rc == 0) 1130 if (rc == 0)
1135 CDEBUG(D_NET, "[%p] EOF from %s" 1131 CDEBUG(D_NET, "[%p] EOF from %s ip %pI4h:%d\n",
1136 " ip %pI4h:%d\n", conn, 1132 conn,
1137 libcfs_id2str(conn->ksnc_peer->ksnp_id), 1133 libcfs_id2str(conn->ksnc_peer->ksnp_id),
1138 &conn->ksnc_ipaddr, 1134 &conn->ksnc_ipaddr,
1139 conn->ksnc_port); 1135 conn->ksnc_port);
1140 else if (!conn->ksnc_closing) 1136 else if (!conn->ksnc_closing)
1141 CERROR("[%p] Error %d on read from %s" 1137 CERROR("[%p] Error %d on read from %s ip %pI4h:%d\n",
1142 " ip %pI4h:%d\n", 1138 conn, rc,
1143 conn, rc, 1139 libcfs_id2str(conn->ksnc_peer->ksnp_id),
1144 libcfs_id2str(conn->ksnc_peer->ksnp_id), 1140 &conn->ksnc_ipaddr,
1145 &conn->ksnc_ipaddr, 1141 conn->ksnc_port);
1146 conn->ksnc_port);
1147 1142
1148 /* it's not an error if conn is being closed */ 1143 /* it's not an error if conn is being closed */
1149 ksocknal_close_conn_and_siblings (conn, 1144 ksocknal_close_conn_and_siblings (conn,
@@ -1724,10 +1719,10 @@ ksocknal_recv_hello (lnet_ni_t *ni, ksock_conn_t *conn,
1724 hello->kshm_magic != __swab32(LNET_PROTO_MAGIC) && 1719 hello->kshm_magic != __swab32(LNET_PROTO_MAGIC) &&
1725 hello->kshm_magic != le32_to_cpu (LNET_PROTO_TCP_MAGIC)) { 1720 hello->kshm_magic != le32_to_cpu (LNET_PROTO_TCP_MAGIC)) {
1726 /* Unexpected magic! */ 1721 /* Unexpected magic! */
1727 CERROR("Bad magic(1) %#08x (%#08x expected) from " 1722 CERROR("Bad magic(1) %#08x (%#08x expected) from %pI4h\n",
1728 "%pI4h\n", __cpu_to_le32 (hello->kshm_magic), 1723 __cpu_to_le32 (hello->kshm_magic),
1729 LNET_PROTO_TCP_MAGIC, 1724 LNET_PROTO_TCP_MAGIC,
1730 &conn->ksnc_ipaddr); 1725 &conn->ksnc_ipaddr);
1731 return -EPROTO; 1726 return -EPROTO;
1732 } 1727 }
1733 1728
@@ -1755,10 +1750,9 @@ ksocknal_recv_hello (lnet_ni_t *ni, ksock_conn_t *conn,
1755 ksocknal_send_hello(ni, conn, ni->ni_nid, hello); 1750 ksocknal_send_hello(ni, conn, ni->ni_nid, hello);
1756 } 1751 }
1757 1752
1758 CERROR("Unknown protocol version (%d.x expected)" 1753 CERROR("Unknown protocol version (%d.x expected) from %pI4h\n",
1759 " from %pI4h\n", 1754 conn->ksnc_proto->pro_version,
1760 conn->ksnc_proto->pro_version, 1755 &conn->ksnc_ipaddr);
1761 &conn->ksnc_ipaddr);
1762 1756
1763 return -EPROTO; 1757 return -EPROTO;
1764 } 1758 }
@@ -1778,8 +1772,8 @@ ksocknal_recv_hello (lnet_ni_t *ni, ksock_conn_t *conn,
1778 *incarnation = hello->kshm_src_incarnation; 1772 *incarnation = hello->kshm_src_incarnation;
1779 1773
1780 if (hello->kshm_src_nid == LNET_NID_ANY) { 1774 if (hello->kshm_src_nid == LNET_NID_ANY) {
1781 CERROR("Expecting a HELLO hdr with a NID, but got LNET_NID_ANY" 1775 CERROR("Expecting a HELLO hdr with a NID, but got LNET_NID_ANY from %pI4h\n",
1782 "from %pI4h\n", &conn->ksnc_ipaddr); 1776 &conn->ksnc_ipaddr);
1783 return -EPROTO; 1777 return -EPROTO;
1784 } 1778 }
1785 1779
@@ -1810,10 +1804,7 @@ ksocknal_recv_hello (lnet_ni_t *ni, ksock_conn_t *conn,
1810 1804
1811 if (peerid->pid != recv_id.pid || 1805 if (peerid->pid != recv_id.pid ||
1812 peerid->nid != recv_id.nid) { 1806 peerid->nid != recv_id.nid) {
1813 LCONSOLE_ERROR_MSG(0x130, "Connected successfully to %s on host" 1807 LCONSOLE_ERROR_MSG(0x130, "Connected successfully to %s on host %pI4h, but they claimed they were %s; please check your Lustre configuration.\n",
1814 " %pI4h, but they claimed they were "
1815 "%s; please check your Lustre "
1816 "configuration.\n",
1817 libcfs_id2str(*peerid), 1808 libcfs_id2str(*peerid),
1818 &conn->ksnc_ipaddr, 1809 &conn->ksnc_ipaddr,
1819 libcfs_id2str(recv_id)); 1810 libcfs_id2str(recv_id));
@@ -2199,8 +2190,7 @@ ksocknal_connd (void *arg)
2199 if (ksocknal_connect(route)) { 2190 if (ksocknal_connect(route)) {
2200 /* consecutive retry */ 2191 /* consecutive retry */
2201 if (cons_retry++ > SOCKNAL_INSANITY_RECONN) { 2192 if (cons_retry++ > SOCKNAL_INSANITY_RECONN) {
2202 CWARN("massive consecutive " 2193 CWARN("massive consecutive re-connecting to %pI4h\n",
2203 "re-connecting to %pI4h\n",
2204 &route->ksnr_ipaddr); 2194 &route->ksnr_ipaddr);
2205 cons_retry = 0; 2195 cons_retry = 0;
2206 } 2196 }
@@ -2264,25 +2254,20 @@ ksocknal_find_timed_out_conn (ksock_peer_t *peer)
2264 2254
2265 switch (error) { 2255 switch (error) {
2266 case ECONNRESET: 2256 case ECONNRESET:
2267 CNETERR("A connection with %s " 2257 CNETERR("A connection with %s (%pI4h:%d) was reset; it may have rebooted.\n",
2268 "(%pI4h:%d) was reset; "
2269 "it may have rebooted.\n",
2270 libcfs_id2str(peer->ksnp_id), 2258 libcfs_id2str(peer->ksnp_id),
2271 &conn->ksnc_ipaddr, 2259 &conn->ksnc_ipaddr,
2272 conn->ksnc_port); 2260 conn->ksnc_port);
2273 break; 2261 break;
2274 case ETIMEDOUT: 2262 case ETIMEDOUT:
2275 CNETERR("A connection with %s " 2263 CNETERR("A connection with %s (%pI4h:%d) timed out; the network or node may be down.\n",
2276 "(%pI4h:%d) timed out; the "
2277 "network or node may be down.\n",
2278 libcfs_id2str(peer->ksnp_id), 2264 libcfs_id2str(peer->ksnp_id),
2279 &conn->ksnc_ipaddr, 2265 &conn->ksnc_ipaddr,
2280 conn->ksnc_port); 2266 conn->ksnc_port);
2281 break; 2267 break;
2282 default: 2268 default:
2283 CNETERR("An unexpected network error %d " 2269 CNETERR("An unexpected network error %d occurred with %s (%pI4h:%d\n",
2284 "occurred with %s " 2270 error,
2285 "(%pI4h:%d\n", error,
2286 libcfs_id2str(peer->ksnp_id), 2271 libcfs_id2str(peer->ksnp_id),
2287 &conn->ksnc_ipaddr, 2272 &conn->ksnc_ipaddr,
2288 conn->ksnc_port); 2273 conn->ksnc_port);
@@ -2297,8 +2282,7 @@ ksocknal_find_timed_out_conn (ksock_peer_t *peer)
2297 conn->ksnc_rx_deadline)) { 2282 conn->ksnc_rx_deadline)) {
2298 /* Timed out incomplete incoming message */ 2283 /* Timed out incomplete incoming message */
2299 ksocknal_conn_addref(conn); 2284 ksocknal_conn_addref(conn);
2300 CNETERR("Timeout receiving from %s (%pI4h:%d), " 2285 CNETERR("Timeout receiving from %s (%pI4h:%d), state %d wanted %d left %d\n",
2301 "state %d wanted %d left %d\n",
2302 libcfs_id2str(peer->ksnp_id), 2286 libcfs_id2str(peer->ksnp_id),
2303 &conn->ksnc_ipaddr, 2287 &conn->ksnc_ipaddr,
2304 conn->ksnc_port, 2288 conn->ksnc_port,
@@ -2315,8 +2299,7 @@ ksocknal_find_timed_out_conn (ksock_peer_t *peer)
2315 /* Timed out messages queued for sending or 2299 /* Timed out messages queued for sending or
2316 * buffered in the socket's send buffer */ 2300 * buffered in the socket's send buffer */
2317 ksocknal_conn_addref(conn); 2301 ksocknal_conn_addref(conn);
2318 CNETERR("Timeout sending data to %s (%pI4h:%d) " 2302 CNETERR("Timeout sending data to %s (%pI4h:%d) the network or that node may be down.\n",
2319 "the network or that node may be down.\n",
2320 libcfs_id2str(peer->ksnp_id), 2303 libcfs_id2str(peer->ksnp_id),
2321 &conn->ksnc_ipaddr, 2304 &conn->ksnc_ipaddr,
2322 conn->ksnc_port); 2305 conn->ksnc_port);
@@ -2500,9 +2483,7 @@ ksocknal_check_peer_timeouts (int idx)
2500 spin_unlock(&peer->ksnp_lock); 2483 spin_unlock(&peer->ksnp_lock);
2501 read_unlock(&ksocknal_data.ksnd_global_lock); 2484 read_unlock(&ksocknal_data.ksnd_global_lock);
2502 2485
2503 CERROR("Total %d stale ZC_REQs for peer %s detected; the " 2486 CERROR("Total %d stale ZC_REQs for peer %s detected; the oldest(%p) timed out %ld secs ago, resid: %d, wmem: %d\n",
2504 "oldest(%p) timed out %ld secs ago, "
2505 "resid: %d, wmem: %d\n",
2506 n, libcfs_nid2str(peer->ksnp_id.nid), tx, 2487 n, libcfs_nid2str(peer->ksnp_id.nid), tx,
2507 cfs_duration_sec(cfs_time_current() - deadline), 2488 cfs_duration_sec(cfs_time_current() - deadline),
2508 resid, conn->ksnc_sock->sk->sk_wmem_queued); 2489 resid, conn->ksnc_sock->sk->sk_wmem_queued);
diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c
index 9dde548070af..ea9d80f40cab 100644
--- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c
+++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd_proto.c
@@ -515,8 +515,8 @@ ksocknal_send_hello_v1 (ksock_conn_t *conn, ksock_hello_msg_t *hello)
515 hello->kshm_nips * sizeof(__u32), 515 hello->kshm_nips * sizeof(__u32),
516 lnet_acceptor_timeout()); 516 lnet_acceptor_timeout());
517 if (rc != 0) { 517 if (rc != 0) {
518 CNETERR("Error %d sending HELLO payload (%d)" 518 CNETERR("Error %d sending HELLO payload (%d) to %pI4h/%d\n",
519 " to %pI4h/%d\n", rc, hello->kshm_nips, 519 rc, hello->kshm_nips,
520 &conn->ksnc_ipaddr, conn->ksnc_port); 520 &conn->ksnc_ipaddr, conn->ksnc_port);
521 } 521 }
522out: 522out:
@@ -560,8 +560,8 @@ ksocknal_send_hello_v2 (ksock_conn_t *conn, ksock_hello_msg_t *hello)
560 hello->kshm_nips * sizeof(__u32), 560 hello->kshm_nips * sizeof(__u32),
561 lnet_acceptor_timeout()); 561 lnet_acceptor_timeout());
562 if (rc != 0) { 562 if (rc != 0) {
563 CNETERR("Error %d sending HELLO payload (%d)" 563 CNETERR("Error %d sending HELLO payload (%d) to %pI4h/%d\n",
564 " to %pI4h/%d\n", rc, hello->kshm_nips, 564 rc, hello->kshm_nips,
565 &conn->ksnc_ipaddr, conn->ksnc_port); 565 &conn->ksnc_ipaddr, conn->ksnc_port);
566 } 566 }
567 567
@@ -595,10 +595,9 @@ ksocknal_recv_hello_v1(ksock_conn_t *conn, ksock_hello_msg_t *hello,
595 595
596 /* ...and check we got what we expected */ 596 /* ...and check we got what we expected */
597 if (hdr->type != cpu_to_le32 (LNET_MSG_HELLO)) { 597 if (hdr->type != cpu_to_le32 (LNET_MSG_HELLO)) {
598 CERROR("Expecting a HELLO hdr," 598 CERROR("Expecting a HELLO hdr, but got type %d from %pI4h\n",
599 " but got type %d from %pI4h\n", 599 le32_to_cpu(hdr->type),
600 le32_to_cpu (hdr->type), 600 &conn->ksnc_ipaddr);
601 &conn->ksnc_ipaddr);
602 rc = -EPROTO; 601 rc = -EPROTO;
603 goto out; 602 goto out;
604 } 603 }
diff --git a/drivers/staging/lustre/lnet/lnet/api-ni.c b/drivers/staging/lustre/lnet/lnet/api-ni.c
index 60bc2ae4fdf1..faceb9505d84 100644
--- a/drivers/staging/lustre/lnet/lnet/api-ni.c
+++ b/drivers/staging/lustre/lnet/lnet/api-ni.c
@@ -37,6 +37,7 @@
37#define DEBUG_SUBSYSTEM S_LNET 37#define DEBUG_SUBSYSTEM S_LNET
38#include "../../include/linux/lnet/lib-lnet.h" 38#include "../../include/linux/lnet/lib-lnet.h"
39#include <linux/log2.h> 39#include <linux/log2.h>
40#include <linux/ktime.h>
40 41
41#define D_LNI D_CONSOLE 42#define D_LNI D_CONSOLE
42 43
@@ -276,7 +277,7 @@ lnet_find_lnd_by_type(int type)
276 struct list_head *tmp; 277 struct list_head *tmp;
277 278
278 /* holding lnd mutex */ 279 /* holding lnd mutex */
279 list_for_each (tmp, &the_lnet.ln_lnds) { 280 list_for_each(tmp, &the_lnet.ln_lnds) {
280 lnd = list_entry(tmp, lnd_t, lnd_list); 281 lnd = list_entry(tmp, lnd_t, lnd_list);
281 282
282 if ((int)lnd->lnd_type == type) 283 if ((int)lnd->lnd_type == type)
@@ -417,17 +418,9 @@ static __u64
417lnet_create_interface_cookie(void) 418lnet_create_interface_cookie(void)
418{ 419{
419 /* NB the interface cookie in wire handles guards against delayed 420 /* NB the interface cookie in wire handles guards against delayed
420 * replies and ACKs appearing valid after reboot. Initialisation time, 421 * replies and ACKs appearing valid after reboot.
421 * even if it's only implemented to millisecond resolution is probably 422 */
422 * easily good enough. */ 423 return ktime_get_ns();
423 struct timeval tv;
424 __u64 cookie;
425
426 do_gettimeofday(&tv);
427 cookie = tv.tv_sec;
428 cookie *= 1000000;
429 cookie += tv.tv_usec;
430 return cookie;
431} 424}
432 425
433static char * 426static char *
@@ -1652,7 +1645,6 @@ lnet_destroy_ping_info(void)
1652 offsetof(lnet_ping_info_t, 1645 offsetof(lnet_ping_info_t,
1653 pi_ni[the_lnet.ln_ping_info->pi_nnis])); 1646 pi_ni[the_lnet.ln_ping_info->pi_nnis]));
1654 the_lnet.ln_ping_info = NULL; 1647 the_lnet.ln_ping_info = NULL;
1655 return;
1656} 1648}
1657 1649
1658int 1650int
diff --git a/drivers/staging/lustre/lnet/lnet/lib-md.c b/drivers/staging/lustre/lnet/lnet/lib-md.c
index e4d906a65635..3225c069637d 100644
--- a/drivers/staging/lustre/lnet/lnet/lib-md.c
+++ b/drivers/staging/lustre/lnet/lnet/lib-md.c
@@ -218,7 +218,7 @@ lnet_md_deconstruct(lnet_libmd_t *lmd, lnet_md_t *umd)
218 lnet_eq2handle(&umd->eq_handle, lmd->md_eq); 218 lnet_eq2handle(&umd->eq_handle, lmd->md_eq);
219} 219}
220 220
221int 221static int
222lnet_md_validate(lnet_md_t *umd) 222lnet_md_validate(lnet_md_t *umd)
223{ 223{
224 if (umd->start == NULL && umd->length != 0) { 224 if (umd->start == NULL && umd->length != 0) {
diff --git a/drivers/staging/lustre/lnet/lnet/lib-move.c b/drivers/staging/lustre/lnet/lnet/lib-move.c
index 4b9567d67f33..c8c1ed84fe5c 100644
--- a/drivers/staging/lustre/lnet/lnet/lib-move.c
+++ b/drivers/staging/lustre/lnet/lnet/lib-move.c
@@ -561,7 +561,7 @@ lnet_extract_kiov(int dst_niov, lnet_kiov_t *dst,
561} 561}
562EXPORT_SYMBOL(lnet_extract_kiov); 562EXPORT_SYMBOL(lnet_extract_kiov);
563 563
564void 564static void
565lnet_ni_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg, int delayed, 565lnet_ni_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg, int delayed,
566 unsigned int offset, unsigned int mlen, unsigned int rlen) 566 unsigned int offset, unsigned int mlen, unsigned int rlen)
567{ 567{
@@ -599,7 +599,7 @@ lnet_ni_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg, int delayed,
599 lnet_finalize(ni, msg, rc); 599 lnet_finalize(ni, msg, rc);
600} 600}
601 601
602void 602static void
603lnet_setpayloadbuffer(lnet_msg_t *msg) 603lnet_setpayloadbuffer(lnet_msg_t *msg)
604{ 604{
605 lnet_libmd_t *md = msg->msg_md; 605 lnet_libmd_t *md = msg->msg_md;
@@ -639,7 +639,7 @@ lnet_prep_send(lnet_msg_t *msg, int type, lnet_process_id_t target,
639 msg->msg_hdr.payload_length = cpu_to_le32(len); 639 msg->msg_hdr.payload_length = cpu_to_le32(len);
640} 640}
641 641
642void 642static void
643lnet_ni_send(lnet_ni_t *ni, lnet_msg_t *msg) 643lnet_ni_send(lnet_ni_t *ni, lnet_msg_t *msg)
644{ 644{
645 void *priv = msg->msg_private; 645 void *priv = msg->msg_private;
@@ -654,7 +654,7 @@ lnet_ni_send(lnet_ni_t *ni, lnet_msg_t *msg)
654 lnet_finalize(ni, msg, rc); 654 lnet_finalize(ni, msg, rc);
655} 655}
656 656
657int 657static int
658lnet_ni_eager_recv(lnet_ni_t *ni, lnet_msg_t *msg) 658lnet_ni_eager_recv(lnet_ni_t *ni, lnet_msg_t *msg)
659{ 659{
660 int rc; 660 int rc;
@@ -668,8 +668,7 @@ lnet_ni_eager_recv(lnet_ni_t *ni, lnet_msg_t *msg)
668 rc = (ni->ni_lnd->lnd_eager_recv)(ni, msg->msg_private, msg, 668 rc = (ni->ni_lnd->lnd_eager_recv)(ni, msg->msg_private, msg,
669 &msg->msg_private); 669 &msg->msg_private);
670 if (rc != 0) { 670 if (rc != 0) {
671 CERROR("recv from %s / send to %s aborted: " 671 CERROR("recv from %s / send to %s aborted: eager_recv failed %d\n",
672 "eager_recv failed %d\n",
673 libcfs_nid2str(msg->msg_rxpeer->lp_nid), 672 libcfs_nid2str(msg->msg_rxpeer->lp_nid),
674 libcfs_id2str(msg->msg_target), rc); 673 libcfs_id2str(msg->msg_target), rc);
675 LASSERT(rc < 0); /* required by my callers */ 674 LASSERT(rc < 0); /* required by my callers */
@@ -679,7 +678,7 @@ lnet_ni_eager_recv(lnet_ni_t *ni, lnet_msg_t *msg)
679} 678}
680 679
681/* NB: caller shall hold a ref on 'lp' as I'd drop lnet_net_lock */ 680/* NB: caller shall hold a ref on 'lp' as I'd drop lnet_net_lock */
682void 681static void
683lnet_ni_query_locked(lnet_ni_t *ni, lnet_peer_t *lp) 682lnet_ni_query_locked(lnet_ni_t *ni, lnet_peer_t *lp)
684{ 683{
685 unsigned long last_alive = 0; 684 unsigned long last_alive = 0;
@@ -731,7 +730,7 @@ lnet_peer_is_alive(lnet_peer_t *lp, unsigned long now)
731 730
732/* NB: returns 1 when alive, 0 when dead, negative when error; 731/* NB: returns 1 when alive, 0 when dead, negative when error;
733 * may drop the lnet_net_lock */ 732 * may drop the lnet_net_lock */
734int 733static int
735lnet_peer_alive_locked(lnet_peer_t *lp) 734lnet_peer_alive_locked(lnet_peer_t *lp)
736{ 735{
737 unsigned long now = cfs_time_current(); 736 unsigned long now = cfs_time_current();
@@ -753,8 +752,7 @@ lnet_peer_alive_locked(lnet_peer_t *lp)
753 752
754 if (time_before(now, next_query)) { 753 if (time_before(now, next_query)) {
755 if (lp->lp_alive) 754 if (lp->lp_alive)
756 CWARN("Unexpected aliveness of peer %s: " 755 CWARN("Unexpected aliveness of peer %s: %d < %d (%d/%d)\n",
757 "%d < %d (%d/%d)\n",
758 libcfs_nid2str(lp->lp_nid), 756 libcfs_nid2str(lp->lp_nid),
759 (int)now, (int)next_query, 757 (int)now, (int)next_query,
760 lnet_queryinterval, 758 lnet_queryinterval,
@@ -817,8 +815,7 @@ lnet_post_send_locked(lnet_msg_t *msg, int do_send)
817 (msg->msg_md->md_flags & LNET_MD_FLAG_ABORTED) != 0) { 815 (msg->msg_md->md_flags & LNET_MD_FLAG_ABORTED) != 0) {
818 lnet_net_unlock(cpt); 816 lnet_net_unlock(cpt);
819 817
820 CNETERR("Aborting message for %s: LNetM[DE]Unlink() already " 818 CNETERR("Aborting message for %s: LNetM[DE]Unlink() already called on the MD/ME.\n",
821 "called on the MD/ME.\n",
822 libcfs_id2str(msg->msg_target)); 819 libcfs_id2str(msg->msg_target));
823 if (do_send) 820 if (do_send)
824 lnet_finalize(ni, msg, -ECANCELED); 821 lnet_finalize(ni, msg, -ECANCELED);
@@ -871,7 +868,7 @@ lnet_post_send_locked(lnet_msg_t *msg, int do_send)
871} 868}
872 869
873 870
874lnet_rtrbufpool_t * 871static lnet_rtrbufpool_t *
875lnet_msg2bufpool(lnet_msg_t *msg) 872lnet_msg2bufpool(lnet_msg_t *msg)
876{ 873{
877 lnet_rtrbufpool_t *rbp; 874 lnet_rtrbufpool_t *rbp;
@@ -891,7 +888,7 @@ lnet_msg2bufpool(lnet_msg_t *msg)
891 return rbp; 888 return rbp;
892} 889}
893 890
894int 891static int
895lnet_post_routed_recv_locked(lnet_msg_t *msg, int do_recv) 892lnet_post_routed_recv_locked(lnet_msg_t *msg, int do_recv)
896{ 893{
897 /* lnet_parse is going to lnet_net_unlock immediately after this, so it 894 /* lnet_parse is going to lnet_net_unlock immediately after this, so it
@@ -1220,8 +1217,8 @@ lnet_send(lnet_nid_t src_nid, lnet_msg_t *msg, lnet_nid_t rtr_nid)
1220 src_ni = lnet_nid2ni_locked(src_nid, cpt); 1217 src_ni = lnet_nid2ni_locked(src_nid, cpt);
1221 if (src_ni == NULL) { 1218 if (src_ni == NULL) {
1222 lnet_net_unlock(cpt); 1219 lnet_net_unlock(cpt);
1223 LCONSOLE_WARN("Can't send to %s: src %s is not a " 1220 LCONSOLE_WARN("Can't send to %s: src %s is not a local nid\n",
1224 "local nid\n", libcfs_nid2str(dst_nid), 1221 libcfs_nid2str(dst_nid),
1225 libcfs_nid2str(src_nid)); 1222 libcfs_nid2str(src_nid));
1226 return -EINVAL; 1223 return -EINVAL;
1227 } 1224 }
@@ -1283,8 +1280,7 @@ lnet_send(lnet_nid_t src_nid, lnet_msg_t *msg, lnet_nid_t rtr_nid)
1283 lnet_ni_decref_locked(src_ni, cpt); 1280 lnet_ni_decref_locked(src_ni, cpt);
1284 lnet_net_unlock(cpt); 1281 lnet_net_unlock(cpt);
1285 1282
1286 LCONSOLE_WARN("No route to %s via %s " 1283 LCONSOLE_WARN("No route to %s via %s (all routers down)\n",
1287 "(all routers down)\n",
1288 libcfs_id2str(msg->msg_target), 1284 libcfs_id2str(msg->msg_target),
1289 libcfs_nid2str(src_nid)); 1285 libcfs_nid2str(src_nid));
1290 return -EHOSTUNREACH; 1286 return -EHOSTUNREACH;
@@ -1676,8 +1672,7 @@ lnet_print_hdr(lnet_hdr_t *hdr)
1676 break; 1672 break;
1677 1673
1678 case LNET_MSG_PUT: 1674 case LNET_MSG_PUT:
1679 CWARN(" Ptl index %d, ack md %#llx.%#llx, " 1675 CWARN(" Ptl index %d, ack md %#llx.%#llx, match bits %llu\n",
1680 "match bits %llu\n",
1681 hdr->msg.put.ptl_index, 1676 hdr->msg.put.ptl_index,
1682 hdr->msg.put.ack_wmd.wh_interface_cookie, 1677 hdr->msg.put.ack_wmd.wh_interface_cookie,
1683 hdr->msg.put.ack_wmd.wh_object_cookie, 1678 hdr->msg.put.ack_wmd.wh_object_cookie,
@@ -1688,8 +1683,8 @@ lnet_print_hdr(lnet_hdr_t *hdr)
1688 break; 1683 break;
1689 1684
1690 case LNET_MSG_GET: 1685 case LNET_MSG_GET:
1691 CWARN(" Ptl index %d, return md %#llx.%#llx, " 1686 CWARN(" Ptl index %d, return md %#llx.%#llx, match bits %llu\n",
1692 "match bits %llu\n", hdr->msg.get.ptl_index, 1687 hdr->msg.get.ptl_index,
1693 hdr->msg.get.return_wmd.wh_interface_cookie, 1688 hdr->msg.get.return_wmd.wh_interface_cookie,
1694 hdr->msg.get.return_wmd.wh_object_cookie, 1689 hdr->msg.get.return_wmd.wh_object_cookie,
1695 hdr->msg.get.match_bits); 1690 hdr->msg.get.match_bits);
@@ -1699,16 +1694,14 @@ lnet_print_hdr(lnet_hdr_t *hdr)
1699 break; 1694 break;
1700 1695
1701 case LNET_MSG_ACK: 1696 case LNET_MSG_ACK:
1702 CWARN(" dst md %#llx.%#llx, " 1697 CWARN(" dst md %#llx.%#llx, manipulated length %d\n",
1703 "manipulated length %d\n",
1704 hdr->msg.ack.dst_wmd.wh_interface_cookie, 1698 hdr->msg.ack.dst_wmd.wh_interface_cookie,
1705 hdr->msg.ack.dst_wmd.wh_object_cookie, 1699 hdr->msg.ack.dst_wmd.wh_object_cookie,
1706 hdr->msg.ack.mlength); 1700 hdr->msg.ack.mlength);
1707 break; 1701 break;
1708 1702
1709 case LNET_MSG_REPLY: 1703 case LNET_MSG_REPLY:
1710 CWARN(" dst md %#llx.%#llx, " 1704 CWARN(" dst md %#llx.%#llx, length %d\n",
1711 "length %d\n",
1712 hdr->msg.reply.dst_wmd.wh_interface_cookie, 1705 hdr->msg.reply.dst_wmd.wh_interface_cookie,
1713 hdr->msg.reply.dst_wmd.wh_object_cookie, 1706 hdr->msg.reply.dst_wmd.wh_object_cookie,
1714 hdr->payload_length); 1707 hdr->payload_length);
@@ -1757,8 +1750,7 @@ lnet_parse(lnet_ni_t *ni, lnet_hdr_t *hdr, lnet_nid_t from_nid,
1757 case LNET_MSG_REPLY: 1750 case LNET_MSG_REPLY:
1758 if (payload_length > 1751 if (payload_length >
1759 (__u32)(for_me ? LNET_MAX_PAYLOAD : LNET_MTU)) { 1752 (__u32)(for_me ? LNET_MAX_PAYLOAD : LNET_MTU)) {
1760 CERROR("%s, src %s: bad %s payload %d " 1753 CERROR("%s, src %s: bad %s payload %d (%d max expected)\n",
1761 "(%d max expected)\n",
1762 libcfs_nid2str(from_nid), 1754 libcfs_nid2str(from_nid),
1763 libcfs_nid2str(src_nid), 1755 libcfs_nid2str(src_nid),
1764 lnet_msgtyp2str(type), 1756 lnet_msgtyp2str(type),
@@ -1794,40 +1786,36 @@ lnet_parse(lnet_ni_t *ni, lnet_hdr_t *hdr, lnet_nid_t from_nid,
1794 if (!for_me) { 1786 if (!for_me) {
1795 if (LNET_NIDNET(dest_nid) == LNET_NIDNET(ni->ni_nid)) { 1787 if (LNET_NIDNET(dest_nid) == LNET_NIDNET(ni->ni_nid)) {
1796 /* should have gone direct */ 1788 /* should have gone direct */
1797 CERROR("%s, src %s: Bad dest nid %s " 1789 CERROR("%s, src %s: Bad dest nid %s (should have been sent direct)\n",
1798 "(should have been sent direct)\n", 1790 libcfs_nid2str(from_nid),
1799 libcfs_nid2str(from_nid), 1791 libcfs_nid2str(src_nid),
1800 libcfs_nid2str(src_nid), 1792 libcfs_nid2str(dest_nid));
1801 libcfs_nid2str(dest_nid));
1802 return -EPROTO; 1793 return -EPROTO;
1803 } 1794 }
1804 1795
1805 if (lnet_islocalnid(dest_nid)) { 1796 if (lnet_islocalnid(dest_nid)) {
1806 /* dest is another local NI; sender should have used 1797 /* dest is another local NI; sender should have used
1807 * this node's NID on its own network */ 1798 * this node's NID on its own network */
1808 CERROR("%s, src %s: Bad dest nid %s " 1799 CERROR("%s, src %s: Bad dest nid %s (it's my nid but on a different network)\n",
1809 "(it's my nid but on a different network)\n", 1800 libcfs_nid2str(from_nid),
1810 libcfs_nid2str(from_nid), 1801 libcfs_nid2str(src_nid),
1811 libcfs_nid2str(src_nid), 1802 libcfs_nid2str(dest_nid));
1812 libcfs_nid2str(dest_nid));
1813 return -EPROTO; 1803 return -EPROTO;
1814 } 1804 }
1815 1805
1816 if (rdma_req && type == LNET_MSG_GET) { 1806 if (rdma_req && type == LNET_MSG_GET) {
1817 CERROR("%s, src %s: Bad optimized GET for %s " 1807 CERROR("%s, src %s: Bad optimized GET for %s (final destination must be me)\n",
1818 "(final destination must be me)\n", 1808 libcfs_nid2str(from_nid),
1819 libcfs_nid2str(from_nid), 1809 libcfs_nid2str(src_nid),
1820 libcfs_nid2str(src_nid), 1810 libcfs_nid2str(dest_nid));
1821 libcfs_nid2str(dest_nid));
1822 return -EPROTO; 1811 return -EPROTO;
1823 } 1812 }
1824 1813
1825 if (!the_lnet.ln_routing) { 1814 if (!the_lnet.ln_routing) {
1826 CERROR("%s, src %s: Dropping message for %s " 1815 CERROR("%s, src %s: Dropping message for %s (routing not enabled)\n",
1827 "(routing not enabled)\n", 1816 libcfs_nid2str(from_nid),
1828 libcfs_nid2str(from_nid), 1817 libcfs_nid2str(src_nid),
1829 libcfs_nid2str(src_nid), 1818 libcfs_nid2str(dest_nid));
1830 libcfs_nid2str(dest_nid));
1831 goto drop; 1819 goto drop;
1832 } 1820 }
1833 } 1821 }
@@ -1882,8 +1870,7 @@ lnet_parse(lnet_ni_t *ni, lnet_hdr_t *hdr, lnet_nid_t from_nid,
1882 rc = lnet_nid2peer_locked(&msg->msg_rxpeer, from_nid, cpt); 1870 rc = lnet_nid2peer_locked(&msg->msg_rxpeer, from_nid, cpt);
1883 if (rc != 0) { 1871 if (rc != 0) {
1884 lnet_net_unlock(cpt); 1872 lnet_net_unlock(cpt);
1885 CERROR("%s, src %s: Dropping %s " 1873 CERROR("%s, src %s: Dropping %s (error %d looking up sender)\n",
1886 "(error %d looking up sender)\n",
1887 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid), 1874 libcfs_nid2str(from_nid), libcfs_nid2str(src_nid),
1888 lnet_msgtyp2str(type), rc); 1875 lnet_msgtyp2str(type), rc);
1889 lnet_msg_free(msg); 1876 lnet_msg_free(msg);
@@ -2003,12 +1990,11 @@ lnet_recv_delayed_msg_list(struct list_head *head)
2003 LASSERT(msg->msg_rxpeer != NULL); 1990 LASSERT(msg->msg_rxpeer != NULL);
2004 LASSERT(msg->msg_hdr.type == LNET_MSG_PUT); 1991 LASSERT(msg->msg_hdr.type == LNET_MSG_PUT);
2005 1992
2006 CDEBUG(D_NET, "Resuming delayed PUT from %s portal %d " 1993 CDEBUG(D_NET, "Resuming delayed PUT from %s portal %d match %llu offset %d length %d.\n",
2007 "match %llu offset %d length %d.\n", 1994 libcfs_id2str(id), msg->msg_hdr.msg.put.ptl_index,
2008 libcfs_id2str(id), msg->msg_hdr.msg.put.ptl_index, 1995 msg->msg_hdr.msg.put.match_bits,
2009 msg->msg_hdr.msg.put.match_bits, 1996 msg->msg_hdr.msg.put.offset,
2010 msg->msg_hdr.msg.put.offset, 1997 msg->msg_hdr.payload_length);
2011 msg->msg_hdr.payload_length);
2012 1998
2013 lnet_recv_put(msg->msg_rxpeer->lp_ni, msg); 1999 lnet_recv_put(msg->msg_rxpeer->lp_ni, msg);
2014 } 2000 }
diff --git a/drivers/staging/lustre/lnet/lnet/lib-ptl.c b/drivers/staging/lustre/lnet/lnet/lib-ptl.c
index 720c73be4d3c..19ed696344fe 100644
--- a/drivers/staging/lustre/lnet/lnet/lib-ptl.c
+++ b/drivers/staging/lustre/lnet/lnet/lib-ptl.c
@@ -192,8 +192,7 @@ lnet_try_match_md(lnet_libmd_t *md,
192 } 192 }
193 193
194 /* Commit to this ME/MD */ 194 /* Commit to this ME/MD */
195 CDEBUG(D_NET, "Incoming %s index %x from %s of " 195 CDEBUG(D_NET, "Incoming %s index %x from %s of length %d/%d into md %#llx [%d] + %d\n",
196 "length %d/%d into md %#llx [%d] + %d\n",
197 (info->mi_opc == LNET_MD_OP_PUT) ? "put" : "get", 196 (info->mi_opc == LNET_MD_OP_PUT) ? "put" : "get",
198 info->mi_portal, libcfs_id2str(info->mi_id), mlength, 197 info->mi_portal, libcfs_id2str(info->mi_id), mlength,
199 info->mi_rlength, md->md_lh.lh_cookie, md->md_niov, offset); 198 info->mi_rlength, md->md_lh.lh_cookie, md->md_niov, offset);
diff --git a/drivers/staging/lustre/lnet/lnet/lo.c b/drivers/staging/lustre/lnet/lnet/lo.c
index be31dfc5fa4b..17e1643fd675 100644
--- a/drivers/staging/lustre/lnet/lnet/lo.c
+++ b/drivers/staging/lustre/lnet/lnet/lo.c
@@ -35,7 +35,7 @@
35#define DEBUG_SUBSYSTEM S_LNET 35#define DEBUG_SUBSYSTEM S_LNET
36#include "../../include/linux/lnet/lib-lnet.h" 36#include "../../include/linux/lnet/lib-lnet.h"
37 37
38int 38static int
39lolnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg) 39lolnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg)
40{ 40{
41 LASSERT(!lntmsg->msg_routing); 41 LASSERT(!lntmsg->msg_routing);
@@ -44,7 +44,7 @@ lolnd_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg)
44 return lnet_parse(ni, &lntmsg->msg_hdr, ni->ni_nid, lntmsg, 0); 44 return lnet_parse(ni, &lntmsg->msg_hdr, ni->ni_nid, lntmsg, 0);
45} 45}
46 46
47int 47static int
48lolnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg, 48lolnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg,
49 int delayed, unsigned int niov, 49 int delayed, unsigned int niov,
50 struct iovec *iov, lnet_kiov_t *kiov, 50 struct iovec *iov, lnet_kiov_t *kiov,
@@ -86,7 +86,7 @@ lolnd_recv(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg,
86 86
87static int lolnd_instanced; 87static int lolnd_instanced;
88 88
89void 89static void
90lolnd_shutdown(lnet_ni_t *ni) 90lolnd_shutdown(lnet_ni_t *ni)
91{ 91{
92 CDEBUG(D_NET, "shutdown\n"); 92 CDEBUG(D_NET, "shutdown\n");
@@ -95,7 +95,7 @@ lolnd_shutdown(lnet_ni_t *ni)
95 lolnd_instanced = 0; 95 lolnd_instanced = 0;
96} 96}
97 97
98int 98static int
99lolnd_startup(lnet_ni_t *ni) 99lolnd_startup(lnet_ni_t *ni)
100{ 100{
101 LASSERT(ni->ni_lnd == &the_lolnd); 101 LASSERT(ni->ni_lnd == &the_lolnd);
diff --git a/drivers/staging/lustre/lnet/lnet/module.c b/drivers/staging/lustre/lnet/lnet/module.c
index e84d59d23ae0..3c23677bc280 100644
--- a/drivers/staging/lustre/lnet/lnet/module.c
+++ b/drivers/staging/lustre/lnet/lnet/module.c
@@ -43,7 +43,7 @@ MODULE_PARM_DESC(config_on_load, "configure network at module load");
43 43
44static struct mutex lnet_config_mutex; 44static struct mutex lnet_config_mutex;
45 45
46int 46static int
47lnet_configure(void *arg) 47lnet_configure(void *arg)
48{ 48{
49 /* 'arg' only there so I can be passed to cfs_create_thread() */ 49 /* 'arg' only there so I can be passed to cfs_create_thread() */
@@ -63,7 +63,7 @@ lnet_configure(void *arg)
63 return rc; 63 return rc;
64} 64}
65 65
66int 66static int
67lnet_unconfigure(void) 67lnet_unconfigure(void)
68{ 68{
69 int refcount; 69 int refcount;
@@ -83,7 +83,7 @@ lnet_unconfigure(void)
83 return (refcount == 0) ? 0 : -EBUSY; 83 return (refcount == 0) ? 0 : -EBUSY;
84} 84}
85 85
86int 86static int
87lnet_ioctl(unsigned int cmd, struct libcfs_ioctl_data *data) 87lnet_ioctl(unsigned int cmd, struct libcfs_ioctl_data *data)
88{ 88{
89 int rc; 89 int rc;
@@ -110,7 +110,7 @@ lnet_ioctl(unsigned int cmd, struct libcfs_ioctl_data *data)
110 110
111DECLARE_IOCTL_HANDLER(lnet_ioctl_handler, lnet_ioctl); 111DECLARE_IOCTL_HANDLER(lnet_ioctl_handler, lnet_ioctl);
112 112
113int 113static int __init
114init_lnet(void) 114init_lnet(void)
115{ 115{
116 int rc; 116 int rc;
@@ -135,7 +135,7 @@ init_lnet(void)
135 return 0; 135 return 0;
136} 136}
137 137
138void 138static void __exit
139fini_lnet(void) 139fini_lnet(void)
140{ 140{
141 int rc; 141 int rc;
diff --git a/drivers/staging/lustre/lnet/lnet/router.c b/drivers/staging/lustre/lnet/lnet/router.c
index b5b8fb576bfb..c667b5b76761 100644
--- a/drivers/staging/lustre/lnet/lnet/router.c
+++ b/drivers/staging/lustre/lnet/lnet/router.c
@@ -457,8 +457,7 @@ lnet_check_routes(void)
457 457
458 lnet_net_unlock(cpt); 458 lnet_net_unlock(cpt);
459 459
460 CERROR("Routes to %s via %s and %s not " 460 CERROR("Routes to %s via %s and %s not supported\n",
461 "supported\n",
462 libcfs_net2str(net), 461 libcfs_net2str(net),
463 libcfs_nid2str(nid1), 462 libcfs_nid2str(nid1),
464 libcfs_nid2str(nid2)); 463 libcfs_nid2str(nid2));
@@ -752,7 +751,7 @@ lnet_router_checker_event(lnet_event_t *event)
752 lnet_net_unlock(lp->lp_cpt); 751 lnet_net_unlock(lp->lp_cpt);
753} 752}
754 753
755void 754static void
756lnet_wait_known_routerstate(void) 755lnet_wait_known_routerstate(void)
757{ 756{
758 lnet_peer_t *rtr; 757 lnet_peer_t *rtr;
@@ -784,7 +783,7 @@ lnet_wait_known_routerstate(void)
784 } 783 }
785} 784}
786 785
787void 786static void
788lnet_update_ni_status_locked(void) 787lnet_update_ni_status_locked(void)
789{ 788{
790 lnet_ni_t *ni; 789 lnet_ni_t *ni;
@@ -824,7 +823,7 @@ lnet_update_ni_status_locked(void)
824 } 823 }
825} 824}
826 825
827void 826static void
828lnet_destroy_rc_data(lnet_rc_data_t *rcd) 827lnet_destroy_rc_data(lnet_rc_data_t *rcd)
829{ 828{
830 LASSERT(list_empty(&rcd->rcd_list)); 829 LASSERT(list_empty(&rcd->rcd_list));
@@ -845,7 +844,7 @@ lnet_destroy_rc_data(lnet_rc_data_t *rcd)
845 LIBCFS_FREE(rcd, sizeof(*rcd)); 844 LIBCFS_FREE(rcd, sizeof(*rcd));
846} 845}
847 846
848lnet_rc_data_t * 847static lnet_rc_data_t *
849lnet_create_rc_data_locked(lnet_peer_t *gateway) 848lnet_create_rc_data_locked(lnet_peer_t *gateway)
850{ 849{
851 lnet_rc_data_t *rcd = NULL; 850 lnet_rc_data_t *rcd = NULL;
@@ -959,8 +958,7 @@ lnet_ping_router_locked (lnet_peer_t *rtr)
959 secs = lnet_router_check_interval(rtr); 958 secs = lnet_router_check_interval(rtr);
960 959
961 CDEBUG(D_NET, 960 CDEBUG(D_NET,
962 "rtr %s %d: deadline %lu ping_notsent %d alive %d " 961 "rtr %s %d: deadline %lu ping_notsent %d alive %d alive_count %d lp_ping_timestamp %lu\n",
963 "alive_count %d lp_ping_timestamp %lu\n",
964 libcfs_nid2str(rtr->lp_nid), secs, 962 libcfs_nid2str(rtr->lp_nid), secs,
965 rtr->lp_ping_deadline, rtr->lp_ping_notsent, 963 rtr->lp_ping_deadline, rtr->lp_ping_notsent,
966 rtr->lp_alive, rtr->lp_alive_count, rtr->lp_ping_timestamp); 964 rtr->lp_alive, rtr->lp_alive_count, rtr->lp_ping_timestamp);
@@ -1010,9 +1008,7 @@ lnet_router_checker_start(void)
1010 1008
1011 if (check_routers_before_use && 1009 if (check_routers_before_use &&
1012 dead_router_check_interval <= 0) { 1010 dead_router_check_interval <= 0) {
1013 LCONSOLE_ERROR_MSG(0x10a, "'dead_router_check_interval' must be" 1011 LCONSOLE_ERROR_MSG(0x10a, "'dead_router_check_interval' must be set if 'check_routers_before_use' is set\n");
1014 " set if 'check_routers_before_use' is set"
1015 "\n");
1016 return -EINVAL; 1012 return -EINVAL;
1017 } 1013 }
1018 1014
@@ -1224,7 +1220,7 @@ rescan:
1224 return 0; 1220 return 0;
1225} 1221}
1226 1222
1227void 1223static void
1228lnet_destroy_rtrbuf(lnet_rtrbuf_t *rb, int npages) 1224lnet_destroy_rtrbuf(lnet_rtrbuf_t *rb, int npages)
1229{ 1225{
1230 int sz = offsetof(lnet_rtrbuf_t, rb_kiov[npages]); 1226 int sz = offsetof(lnet_rtrbuf_t, rb_kiov[npages]);
@@ -1235,7 +1231,7 @@ lnet_destroy_rtrbuf(lnet_rtrbuf_t *rb, int npages)
1235 LIBCFS_FREE(rb, sz); 1231 LIBCFS_FREE(rb, sz);
1236} 1232}
1237 1233
1238lnet_rtrbuf_t * 1234static lnet_rtrbuf_t *
1239lnet_new_rtrbuf(lnet_rtrbufpool_t *rbp, int cpt) 1235lnet_new_rtrbuf(lnet_rtrbufpool_t *rbp, int cpt)
1240{ 1236{
1241 int npages = rbp->rbp_npages; 1237 int npages = rbp->rbp_npages;
@@ -1270,7 +1266,7 @@ lnet_new_rtrbuf(lnet_rtrbufpool_t *rbp, int cpt)
1270 return rb; 1266 return rb;
1271} 1267}
1272 1268
1273void 1269static void
1274lnet_rtrpool_free_bufs(lnet_rtrbufpool_t *rbp) 1270lnet_rtrpool_free_bufs(lnet_rtrbufpool_t *rbp)
1275{ 1271{
1276 int npages = rbp->rbp_npages; 1272 int npages = rbp->rbp_npages;
@@ -1299,7 +1295,7 @@ lnet_rtrpool_free_bufs(lnet_rtrbufpool_t *rbp)
1299 rbp->rbp_nbuffers = rbp->rbp_credits = 0; 1295 rbp->rbp_nbuffers = rbp->rbp_credits = 0;
1300} 1296}
1301 1297
1302int 1298static int
1303lnet_rtrpool_alloc_bufs(lnet_rtrbufpool_t *rbp, int nbufs, int cpt) 1299lnet_rtrpool_alloc_bufs(lnet_rtrbufpool_t *rbp, int nbufs, int cpt)
1304{ 1300{
1305 lnet_rtrbuf_t *rb; 1301 lnet_rtrbuf_t *rb;
@@ -1333,7 +1329,7 @@ lnet_rtrpool_alloc_bufs(lnet_rtrbufpool_t *rbp, int nbufs, int cpt)
1333 return 0; 1329 return 0;
1334} 1330}
1335 1331
1336void 1332static void
1337lnet_rtrpool_init(lnet_rtrbufpool_t *rbp, int npages) 1333lnet_rtrpool_init(lnet_rtrbufpool_t *rbp, int npages)
1338{ 1334{
1339 INIT_LIST_HEAD(&rbp->rbp_msgs); 1335 INIT_LIST_HEAD(&rbp->rbp_msgs);
@@ -1370,8 +1366,8 @@ lnet_nrb_tiny_calculate(int npages)
1370 1366
1371 if (tiny_router_buffers < 0) { 1367 if (tiny_router_buffers < 0) {
1372 LCONSOLE_ERROR_MSG(0x10c, 1368 LCONSOLE_ERROR_MSG(0x10c,
1373 "tiny_router_buffers=%d invalid when " 1369 "tiny_router_buffers=%d invalid when routing enabled\n",
1374 "routing enabled\n", tiny_router_buffers); 1370 tiny_router_buffers);
1375 return -1; 1371 return -1;
1376 } 1372 }
1377 1373
@@ -1389,8 +1385,8 @@ lnet_nrb_small_calculate(int npages)
1389 1385
1390 if (small_router_buffers < 0) { 1386 if (small_router_buffers < 0) {
1391 LCONSOLE_ERROR_MSG(0x10c, 1387 LCONSOLE_ERROR_MSG(0x10c,
1392 "small_router_buffers=%d invalid when " 1388 "small_router_buffers=%d invalid when routing enabled\n",
1393 "routing enabled\n", small_router_buffers); 1389 small_router_buffers);
1394 return -1; 1390 return -1;
1395 } 1391 }
1396 1392
@@ -1408,8 +1404,8 @@ lnet_nrb_large_calculate(int npages)
1408 1404
1409 if (large_router_buffers < 0) { 1405 if (large_router_buffers < 0) {
1410 LCONSOLE_ERROR_MSG(0x10c, 1406 LCONSOLE_ERROR_MSG(0x10c,
1411 "large_router_buffers=%d invalid when " 1407 "large_router_buffers=%d invalid when routing enabled\n",
1412 "routing enabled\n", large_router_buffers); 1408 large_router_buffers);
1413 return -1; 1409 return -1;
1414 } 1410 }
1415 1411
@@ -1442,8 +1438,7 @@ lnet_rtrpools_alloc(int im_a_router)
1442 } else if (!strcmp(forwarding, "enabled")) { 1438 } else if (!strcmp(forwarding, "enabled")) {
1443 /* explicitly enabled */ 1439 /* explicitly enabled */
1444 } else { 1440 } else {
1445 LCONSOLE_ERROR_MSG(0x10b, "'forwarding' not set to either " 1441 LCONSOLE_ERROR_MSG(0x10b, "'forwarding' not set to either 'enabled' or 'disabled'\n");
1446 "'enabled' or 'disabled'\n");
1447 return -EINVAL; 1442 return -EINVAL;
1448 } 1443 }
1449 1444
@@ -1520,11 +1515,10 @@ lnet_notify(lnet_ni_t *ni, lnet_nid_t nid, int alive, unsigned long when)
1520 1515
1521 /* can't do predictions... */ 1516 /* can't do predictions... */
1522 if (cfs_time_after(when, now)) { 1517 if (cfs_time_after(when, now)) {
1523 CWARN ("Ignoring prediction from %s of %s %s " 1518 CWARN("Ignoring prediction from %s of %s %s %ld seconds in the future\n",
1524 "%ld seconds in the future\n", 1519 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid),
1525 (ni == NULL) ? "userspace" : libcfs_nid2str(ni->ni_nid), 1520 libcfs_nid2str(nid), alive ? "up" : "down",
1526 libcfs_nid2str(nid), alive ? "up" : "down", 1521 cfs_duration_sec(cfs_time_sub(when, now)));
1527 cfs_duration_sec(cfs_time_sub(when, now)));
1528 return -EINVAL; 1522 return -EINVAL;
1529 } 1523 }
1530 1524
diff --git a/drivers/staging/lustre/lnet/lnet/router_proc.c b/drivers/staging/lustre/lnet/lnet/router_proc.c
index 6e8f7e2bbcfc..46cde7036f1d 100644
--- a/drivers/staging/lustre/lnet/lnet/router_proc.c
+++ b/drivers/staging/lustre/lnet/lnet/router_proc.c
@@ -164,8 +164,8 @@ static int proc_lnet_stats(struct ctl_table *table, int write,
164 __proc_lnet_stats); 164 __proc_lnet_stats);
165} 165}
166 166
167int proc_lnet_routes(struct ctl_table *table, int write, void __user *buffer, 167static int proc_lnet_routes(struct ctl_table *table, int write,
168 size_t *lenp, loff_t *ppos) 168 void __user *buffer, size_t *lenp, loff_t *ppos)
169{ 169{
170 const int tmpsiz = 256; 170 const int tmpsiz = 256;
171 char *tmpstr; 171 char *tmpstr;
@@ -290,8 +290,8 @@ int proc_lnet_routes(struct ctl_table *table, int write, void __user *buffer,
290 return rc; 290 return rc;
291} 291}
292 292
293int proc_lnet_routers(struct ctl_table *table, int write, void __user *buffer, 293static int proc_lnet_routers(struct ctl_table *table, int write,
294 size_t *lenp, loff_t *ppos) 294 void __user *buffer, size_t *lenp, loff_t *ppos)
295{ 295{
296 int rc = 0; 296 int rc = 0;
297 char *tmpstr; 297 char *tmpstr;
@@ -425,8 +425,8 @@ int proc_lnet_routers(struct ctl_table *table, int write, void __user *buffer,
425 return rc; 425 return rc;
426} 426}
427 427
428int proc_lnet_peers(struct ctl_table *table, int write, void __user *buffer, 428static int proc_lnet_peers(struct ctl_table *table, int write,
429 size_t *lenp, loff_t *ppos) 429 void __user *buffer, size_t *lenp, loff_t *ppos)
430{ 430{
431 const int tmpsiz = 256; 431 const int tmpsiz = 256;
432 struct lnet_peer_table *ptable; 432 struct lnet_peer_table *ptable;
@@ -657,8 +657,8 @@ static int proc_lnet_buffers(struct ctl_table *table, int write,
657 __proc_lnet_buffers); 657 __proc_lnet_buffers);
658} 658}
659 659
660int proc_lnet_nis(struct ctl_table *table, int write, void __user *buffer, 660static int proc_lnet_nis(struct ctl_table *table, int write,
661 size_t *lenp, loff_t *ppos) 661 void __user *buffer, size_t *lenp, loff_t *ppos)
662{ 662{
663 int tmpsiz = 128 * LNET_CPT_NUMBER; 663 int tmpsiz = 128 * LNET_CPT_NUMBER;
664 int rc = 0; 664 int rc = 0;
@@ -791,20 +791,17 @@ static struct lnet_portal_rotors portal_rotors[] = {
791 { 791 {
792 .pr_value = LNET_PTL_ROTOR_ON, 792 .pr_value = LNET_PTL_ROTOR_ON,
793 .pr_name = "ON", 793 .pr_name = "ON",
794 .pr_desc = "round-robin dispatch all PUT messages for " 794 .pr_desc = "round-robin dispatch all PUT messages for wildcard portals"
795 "wildcard portals"
796 }, 795 },
797 { 796 {
798 .pr_value = LNET_PTL_ROTOR_RR_RT, 797 .pr_value = LNET_PTL_ROTOR_RR_RT,
799 .pr_name = "RR_RT", 798 .pr_name = "RR_RT",
800 .pr_desc = "round-robin dispatch routed PUT message for " 799 .pr_desc = "round-robin dispatch routed PUT message for wildcard portals"
801 "wildcard portals"
802 }, 800 },
803 { 801 {
804 .pr_value = LNET_PTL_ROTOR_HASH_RT, 802 .pr_value = LNET_PTL_ROTOR_HASH_RT,
805 .pr_name = "HASH_RT", 803 .pr_name = "HASH_RT",
806 .pr_desc = "dispatch routed PUT message by hashing source " 804 .pr_desc = "dispatch routed PUT message by hashing source NID for wildcard portals"
807 "NID for wildcard portals"
808 }, 805 },
809 { 806 {
810 .pr_value = -1, 807 .pr_value = -1,
diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
index a94f336d578c..463da076fa70 100644
--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
@@ -233,7 +233,7 @@ brw_fill_bulk(srpc_bulk_t *bk, int pattern, __u64 magic)
233 } 233 }
234} 234}
235 235
236int 236static int
237brw_check_bulk(srpc_bulk_t *bk, int pattern, __u64 magic) 237brw_check_bulk(srpc_bulk_t *bk, int pattern, __u64 magic)
238{ 238{
239 int i; 239 int i;
@@ -358,7 +358,7 @@ out:
358 return; 358 return;
359} 359}
360 360
361void 361static void
362brw_server_rpc_done(srpc_server_rpc_t *rpc) 362brw_server_rpc_done(srpc_server_rpc_t *rpc)
363{ 363{
364 srpc_bulk_t *blk = rpc->srpc_bulk; 364 srpc_bulk_t *blk = rpc->srpc_bulk;
@@ -378,7 +378,7 @@ brw_server_rpc_done(srpc_server_rpc_t *rpc)
378 sfw_free_pages(rpc); 378 sfw_free_pages(rpc);
379} 379}
380 380
381int 381static int
382brw_bulk_ready(srpc_server_rpc_t *rpc, int status) 382brw_bulk_ready(srpc_server_rpc_t *rpc, int status)
383{ 383{
384 __u64 magic = BRW_MAGIC; 384 __u64 magic = BRW_MAGIC;
@@ -414,7 +414,7 @@ brw_bulk_ready(srpc_server_rpc_t *rpc, int status)
414 return 0; 414 return 0;
415} 415}
416 416
417int 417static int
418brw_server_handle(struct srpc_server_rpc *rpc) 418brw_server_handle(struct srpc_server_rpc *rpc)
419{ 419{
420 struct srpc_service *sv = rpc->srpc_scd->scd_svc; 420 struct srpc_service *sv = rpc->srpc_scd->scd_svc;
diff --git a/drivers/staging/lustre/lnet/selftest/conctl.c b/drivers/staging/lustre/lnet/selftest/conctl.c
index ae7b0fcd818d..5bc615309e72 100644
--- a/drivers/staging/lustre/lnet/selftest/conctl.c
+++ b/drivers/staging/lustre/lnet/selftest/conctl.c
@@ -45,7 +45,7 @@
45#include "../../include/linux/lnet/lnetst.h" 45#include "../../include/linux/lnet/lnetst.h"
46#include "console.h" 46#include "console.h"
47 47
48int 48static int
49lst_session_new_ioctl(lstio_session_new_args_t *args) 49lst_session_new_ioctl(lstio_session_new_args_t *args)
50{ 50{
51 char *name; 51 char *name;
@@ -82,7 +82,7 @@ lst_session_new_ioctl(lstio_session_new_args_t *args)
82 return rc; 82 return rc;
83} 83}
84 84
85int 85static int
86lst_session_end_ioctl(lstio_session_end_args_t *args) 86lst_session_end_ioctl(lstio_session_end_args_t *args)
87{ 87{
88 if (args->lstio_ses_key != console_session.ses_key) 88 if (args->lstio_ses_key != console_session.ses_key)
@@ -91,7 +91,7 @@ lst_session_end_ioctl(lstio_session_end_args_t *args)
91 return lstcon_session_end(); 91 return lstcon_session_end();
92} 92}
93 93
94int 94static int
95lst_session_info_ioctl(lstio_session_info_args_t *args) 95lst_session_info_ioctl(lstio_session_info_args_t *args)
96{ 96{
97 /* no checking of key */ 97 /* no checking of key */
@@ -113,7 +113,7 @@ lst_session_info_ioctl(lstio_session_info_args_t *args)
113 args->lstio_ses_nmlen); 113 args->lstio_ses_nmlen);
114} 114}
115 115
116int 116static int
117lst_debug_ioctl(lstio_debug_args_t *args) 117lst_debug_ioctl(lstio_debug_args_t *args)
118{ 118{
119 char *name = NULL; 119 char *name = NULL;
@@ -194,7 +194,7 @@ out:
194 return rc; 194 return rc;
195} 195}
196 196
197int 197static int
198lst_group_add_ioctl(lstio_group_add_args_t *args) 198lst_group_add_ioctl(lstio_group_add_args_t *args)
199{ 199{
200 char *name; 200 char *name;
@@ -228,7 +228,7 @@ lst_group_add_ioctl(lstio_group_add_args_t *args)
228 return rc; 228 return rc;
229} 229}
230 230
231int 231static int
232lst_group_del_ioctl(lstio_group_del_args_t *args) 232lst_group_del_ioctl(lstio_group_del_args_t *args)
233{ 233{
234 int rc; 234 int rc;
@@ -262,7 +262,7 @@ lst_group_del_ioctl(lstio_group_del_args_t *args)
262 return rc; 262 return rc;
263} 263}
264 264
265int 265static int
266lst_group_update_ioctl(lstio_group_update_args_t *args) 266lst_group_update_ioctl(lstio_group_update_args_t *args)
267{ 267{
268 int rc; 268 int rc;
@@ -320,7 +320,7 @@ lst_group_update_ioctl(lstio_group_update_args_t *args)
320 return rc; 320 return rc;
321} 321}
322 322
323int 323static int
324lst_nodes_add_ioctl(lstio_group_nodes_args_t *args) 324lst_nodes_add_ioctl(lstio_group_nodes_args_t *args)
325{ 325{
326 unsigned feats; 326 unsigned feats;
@@ -365,7 +365,7 @@ lst_nodes_add_ioctl(lstio_group_nodes_args_t *args)
365 return rc; 365 return rc;
366} 366}
367 367
368int 368static int
369lst_group_list_ioctl(lstio_group_list_args_t *args) 369lst_group_list_ioctl(lstio_group_list_args_t *args)
370{ 370{
371 if (args->lstio_grp_key != console_session.ses_key) 371 if (args->lstio_grp_key != console_session.ses_key)
@@ -382,7 +382,7 @@ lst_group_list_ioctl(lstio_group_list_args_t *args)
382 args->lstio_grp_namep); 382 args->lstio_grp_namep);
383} 383}
384 384
385int 385static int
386lst_group_info_ioctl(lstio_group_info_args_t *args) 386lst_group_info_ioctl(lstio_group_info_args_t *args)
387{ 387{
388 char *name; 388 char *name;
@@ -446,7 +446,7 @@ lst_group_info_ioctl(lstio_group_info_args_t *args)
446 return 0; 446 return 0;
447} 447}
448 448
449int 449static int
450lst_batch_add_ioctl(lstio_batch_add_args_t *args) 450lst_batch_add_ioctl(lstio_batch_add_args_t *args)
451{ 451{
452 int rc; 452 int rc;
@@ -480,7 +480,7 @@ lst_batch_add_ioctl(lstio_batch_add_args_t *args)
480 return rc; 480 return rc;
481} 481}
482 482
483int 483static int
484lst_batch_run_ioctl(lstio_batch_run_args_t *args) 484lst_batch_run_ioctl(lstio_batch_run_args_t *args)
485{ 485{
486 int rc; 486 int rc;
@@ -515,7 +515,7 @@ lst_batch_run_ioctl(lstio_batch_run_args_t *args)
515 return rc; 515 return rc;
516} 516}
517 517
518int 518static int
519lst_batch_stop_ioctl(lstio_batch_stop_args_t *args) 519lst_batch_stop_ioctl(lstio_batch_stop_args_t *args)
520{ 520{
521 int rc; 521 int rc;
@@ -551,7 +551,7 @@ lst_batch_stop_ioctl(lstio_batch_stop_args_t *args)
551 return rc; 551 return rc;
552} 552}
553 553
554int 554static int
555lst_batch_query_ioctl(lstio_batch_query_args_t *args) 555lst_batch_query_ioctl(lstio_batch_query_args_t *args)
556{ 556{
557 char *name; 557 char *name;
@@ -593,7 +593,7 @@ lst_batch_query_ioctl(lstio_batch_query_args_t *args)
593 return rc; 593 return rc;
594} 594}
595 595
596int 596static int
597lst_batch_list_ioctl(lstio_batch_list_args_t *args) 597lst_batch_list_ioctl(lstio_batch_list_args_t *args)
598{ 598{
599 if (args->lstio_bat_key != console_session.ses_key) 599 if (args->lstio_bat_key != console_session.ses_key)
@@ -610,7 +610,7 @@ lst_batch_list_ioctl(lstio_batch_list_args_t *args)
610 args->lstio_bat_namep); 610 args->lstio_bat_namep);
611} 611}
612 612
613int 613static int
614lst_batch_info_ioctl(lstio_batch_info_args_t *args) 614lst_batch_info_ioctl(lstio_batch_info_args_t *args)
615{ 615{
616 char *name; 616 char *name;
@@ -675,7 +675,7 @@ lst_batch_info_ioctl(lstio_batch_info_args_t *args)
675 return rc; 675 return rc;
676} 676}
677 677
678int 678static int
679lst_stat_query_ioctl(lstio_stat_args_t *args) 679lst_stat_query_ioctl(lstio_stat_args_t *args)
680{ 680{
681 int rc; 681 int rc;
diff --git a/drivers/staging/lustre/lnet/selftest/conrpc.c b/drivers/staging/lustre/lnet/selftest/conrpc.c
index a3a60d6e9081..9999b0dc03e4 100644
--- a/drivers/staging/lustre/lnet/selftest/conrpc.c
+++ b/drivers/staging/lustre/lnet/selftest/conrpc.c
@@ -88,7 +88,7 @@ lstcon_rpc_done(srpc_client_rpc_t *rpc)
88 spin_unlock(&rpc->crpc_lock); 88 spin_unlock(&rpc->crpc_lock);
89} 89}
90 90
91int 91static int
92lstcon_rpc_init(lstcon_node_t *nd, int service, unsigned feats, 92lstcon_rpc_init(lstcon_node_t *nd, int service, unsigned feats,
93 int bulk_npg, int bulk_len, int embedded, lstcon_rpc_t *crpc) 93 int bulk_npg, int bulk_len, int embedded, lstcon_rpc_t *crpc)
94{ 94{
@@ -113,7 +113,7 @@ lstcon_rpc_init(lstcon_node_t *nd, int service, unsigned feats,
113 return 0; 113 return 0;
114} 114}
115 115
116int 116static int
117lstcon_rpc_prep(lstcon_node_t *nd, int service, unsigned feats, 117lstcon_rpc_prep(lstcon_node_t *nd, int service, unsigned feats,
118 int bulk_npg, int bulk_len, lstcon_rpc_t **crpcpp) 118 int bulk_npg, int bulk_len, lstcon_rpc_t **crpcpp)
119{ 119{
@@ -182,7 +182,7 @@ lstcon_rpc_put(lstcon_rpc_t *crpc)
182 atomic_dec(&console_session.ses_rpc_counter); 182 atomic_dec(&console_session.ses_rpc_counter);
183} 183}
184 184
185void 185static void
186lstcon_rpc_post(lstcon_rpc_t *crpc) 186lstcon_rpc_post(lstcon_rpc_t *crpc)
187{ 187{
188 lstcon_rpc_trans_t *trans = crpc->crp_trans; 188 lstcon_rpc_trans_t *trans = crpc->crp_trans;
@@ -383,7 +383,7 @@ lstcon_rpc_trans_postwait(lstcon_rpc_trans_t *trans, int timeout)
383 return rc; 383 return rc;
384} 384}
385 385
386int 386static int
387lstcon_rpc_get_reply(lstcon_rpc_t *crpc, srpc_msg_t **msgpp) 387lstcon_rpc_get_reply(lstcon_rpc_t *crpc, srpc_msg_t **msgpp)
388{ 388{
389 lstcon_node_t *nd = crpc->crp_node; 389 lstcon_node_t *nd = crpc->crp_node;
@@ -718,7 +718,7 @@ lstcon_next_id(int idx, int nkiov, lnet_kiov_t *kiov)
718 return &pid[idx % SFW_ID_PER_PAGE]; 718 return &pid[idx % SFW_ID_PER_PAGE];
719} 719}
720 720
721int 721static int
722lstcon_dstnodes_prep(lstcon_group_t *grp, int idx, 722lstcon_dstnodes_prep(lstcon_group_t *grp, int idx,
723 int dist, int span, int nkiov, lnet_kiov_t *kiov) 723 int dist, int span, int nkiov, lnet_kiov_t *kiov)
724{ 724{
@@ -772,7 +772,7 @@ lstcon_dstnodes_prep(lstcon_group_t *grp, int idx,
772 return 0; 772 return 0;
773} 773}
774 774
775int 775static int
776lstcon_pingrpc_prep(lst_test_ping_param_t *param, srpc_test_reqst_t *req) 776lstcon_pingrpc_prep(lst_test_ping_param_t *param, srpc_test_reqst_t *req)
777{ 777{
778 test_ping_req_t *prq = &req->tsr_u.ping; 778 test_ping_req_t *prq = &req->tsr_u.ping;
@@ -783,7 +783,7 @@ lstcon_pingrpc_prep(lst_test_ping_param_t *param, srpc_test_reqst_t *req)
783 return 0; 783 return 0;
784} 784}
785 785
786int 786static int
787lstcon_bulkrpc_v0_prep(lst_test_bulk_param_t *param, srpc_test_reqst_t *req) 787lstcon_bulkrpc_v0_prep(lst_test_bulk_param_t *param, srpc_test_reqst_t *req)
788{ 788{
789 test_bulk_req_t *brq = &req->tsr_u.bulk_v0; 789 test_bulk_req_t *brq = &req->tsr_u.bulk_v0;
@@ -795,7 +795,7 @@ lstcon_bulkrpc_v0_prep(lst_test_bulk_param_t *param, srpc_test_reqst_t *req)
795 return 0; 795 return 0;
796} 796}
797 797
798int 798static int
799lstcon_bulkrpc_v1_prep(lst_test_bulk_param_t *param, srpc_test_reqst_t *req) 799lstcon_bulkrpc_v1_prep(lst_test_bulk_param_t *param, srpc_test_reqst_t *req)
800{ 800{
801 test_bulk_req_v1_t *brq = &req->tsr_u.bulk_v1; 801 test_bulk_req_v1_t *brq = &req->tsr_u.bulk_v1;
@@ -915,7 +915,7 @@ lstcon_testrpc_prep(lstcon_node_t *nd, int transop, unsigned feats,
915 return rc; 915 return rc;
916} 916}
917 917
918int 918static int
919lstcon_sesnew_stat_reply(lstcon_rpc_trans_t *trans, 919lstcon_sesnew_stat_reply(lstcon_rpc_trans_t *trans,
920 lstcon_node_t *nd, srpc_msg_t *reply) 920 lstcon_node_t *nd, srpc_msg_t *reply)
921{ 921{
@@ -1162,7 +1162,7 @@ lstcon_rpc_trans_ndlist(struct list_head *ndlist,
1162 return rc; 1162 return rc;
1163} 1163}
1164 1164
1165void 1165static void
1166lstcon_rpc_pinger(void *arg) 1166lstcon_rpc_pinger(void *arg)
1167{ 1167{
1168 stt_timer_t *ptimer = (stt_timer_t *)arg; 1168 stt_timer_t *ptimer = (stt_timer_t *)arg;
diff --git a/drivers/staging/lustre/lnet/selftest/console.c b/drivers/staging/lustre/lnet/selftest/console.c
index 5dad9f1f9462..49cb6543d538 100644
--- a/drivers/staging/lustre/lnet/selftest/console.c
+++ b/drivers/staging/lustre/lnet/selftest/console.c
@@ -1208,8 +1208,7 @@ again:
1208 1208
1209 lstcon_rpc_trans_destroy(trans); 1209 lstcon_rpc_trans_destroy(trans);
1210 /* return if any error */ 1210 /* return if any error */
1211 CDEBUG(D_NET, "Failed to add test %s, " 1211 CDEBUG(D_NET, "Failed to add test %s, RPC error %d, framework error %d\n",
1212 "RPC error %d, framework error %d\n",
1213 transop == LST_TRANS_TSBCLIADD ? "client" : "server", 1212 transop == LST_TRANS_TSBCLIADD ? "client" : "server",
1214 lstcon_trans_stat()->trs_rpc_errno, 1213 lstcon_trans_stat()->trs_rpc_errno,
1215 lstcon_trans_stat()->trs_fwk_errno); 1214 lstcon_trans_stat()->trs_fwk_errno);
@@ -1885,8 +1884,7 @@ lstcon_session_feats_check(unsigned feats)
1885 spin_unlock(&console_session.ses_rpc_lock); 1884 spin_unlock(&console_session.ses_rpc_lock);
1886 1885
1887 if (rc != 0) { 1886 if (rc != 0) {
1888 CERROR("remote features %x do not match with " 1887 CERROR("remote features %x do not match with session features %x of console\n",
1889 "session features %x of console\n",
1890 feats, console_session.ses_features); 1888 feats, console_session.ses_features);
1891 } 1889 }
1892 1890
diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
index df04ab7de835..cc9d1826ae66 100644
--- a/drivers/staging/lustre/lnet/selftest/framework.c
+++ b/drivers/staging/lustre/lnet/selftest/framework.c
@@ -156,7 +156,7 @@ sfw_register_test (srpc_service_t *service, sfw_test_client_ops_t *cliops)
156 return 0; 156 return 0;
157} 157}
158 158
159void 159static void
160sfw_add_session_timer (void) 160sfw_add_session_timer (void)
161{ 161{
162 sfw_session_t *sn = sfw_data.fw_session; 162 sfw_session_t *sn = sfw_data.fw_session;
@@ -176,7 +176,7 @@ sfw_add_session_timer (void)
176 return; 176 return;
177} 177}
178 178
179int 179static int
180sfw_del_session_timer (void) 180sfw_del_session_timer (void)
181{ 181{
182 sfw_session_t *sn = sfw_data.fw_session; 182 sfw_session_t *sn = sfw_data.fw_session;
@@ -238,7 +238,7 @@ sfw_deactivate_session (void)
238} 238}
239 239
240 240
241void 241static void
242sfw_session_expired (void *data) 242sfw_session_expired (void *data)
243{ 243{
244 sfw_session_t *sn = data; 244 sfw_session_t *sn = data;
@@ -284,15 +284,14 @@ sfw_init_session(sfw_session_t *sn, lst_sid_t sid,
284} 284}
285 285
286/* completion handler for incoming framework RPCs */ 286/* completion handler for incoming framework RPCs */
287void 287static void
288sfw_server_rpc_done(struct srpc_server_rpc *rpc) 288sfw_server_rpc_done(struct srpc_server_rpc *rpc)
289{ 289{
290 struct srpc_service *sv = rpc->srpc_scd->scd_svc; 290 struct srpc_service *sv = rpc->srpc_scd->scd_svc;
291 int status = rpc->srpc_status; 291 int status = rpc->srpc_status;
292 292
293 CDEBUG (D_NET, 293 CDEBUG (D_NET,
294 "Incoming framework RPC done: " 294 "Incoming framework RPC done: service %s, peer %s, status %s:%d\n",
295 "service %s, peer %s, status %s:%d\n",
296 sv->sv_name, libcfs_id2str(rpc->srpc_peer), 295 sv->sv_name, libcfs_id2str(rpc->srpc_peer),
297 swi_state2str(rpc->srpc_wi.swi_state), 296 swi_state2str(rpc->srpc_wi.swi_state),
298 status); 297 status);
@@ -302,7 +301,7 @@ sfw_server_rpc_done(struct srpc_server_rpc *rpc)
302 return; 301 return;
303} 302}
304 303
305void 304static void
306sfw_client_rpc_fini (srpc_client_rpc_t *rpc) 305sfw_client_rpc_fini (srpc_client_rpc_t *rpc)
307{ 306{
308 LASSERT (rpc->crpc_bulk.bk_niov == 0); 307 LASSERT (rpc->crpc_bulk.bk_niov == 0);
@@ -310,8 +309,7 @@ sfw_client_rpc_fini (srpc_client_rpc_t *rpc)
310 LASSERT (atomic_read(&rpc->crpc_refcount) == 0); 309 LASSERT (atomic_read(&rpc->crpc_refcount) == 0);
311 310
312 CDEBUG (D_NET, 311 CDEBUG (D_NET,
313 "Outgoing framework RPC done: " 312 "Outgoing framework RPC done: service %d, peer %s, status %s:%d:%d\n",
314 "service %d, peer %s, status %s:%d:%d\n",
315 rpc->crpc_service, libcfs_id2str(rpc->crpc_dest), 313 rpc->crpc_service, libcfs_id2str(rpc->crpc_dest),
316 swi_state2str(rpc->crpc_wi.swi_state), 314 swi_state2str(rpc->crpc_wi.swi_state),
317 rpc->crpc_aborted, rpc->crpc_status); 315 rpc->crpc_aborted, rpc->crpc_status);
@@ -325,7 +323,7 @@ sfw_client_rpc_fini (srpc_client_rpc_t *rpc)
325 spin_unlock(&sfw_data.fw_lock); 323 spin_unlock(&sfw_data.fw_lock);
326} 324}
327 325
328sfw_batch_t * 326static sfw_batch_t *
329sfw_find_batch (lst_bid_t bid) 327sfw_find_batch (lst_bid_t bid)
330{ 328{
331 sfw_session_t *sn = sfw_data.fw_session; 329 sfw_session_t *sn = sfw_data.fw_session;
@@ -341,7 +339,7 @@ sfw_find_batch (lst_bid_t bid)
341 return NULL; 339 return NULL;
342} 340}
343 341
344sfw_batch_t * 342static sfw_batch_t *
345sfw_bid2batch (lst_bid_t bid) 343sfw_bid2batch (lst_bid_t bid)
346{ 344{
347 sfw_session_t *sn = sfw_data.fw_session; 345 sfw_session_t *sn = sfw_data.fw_session;
@@ -367,7 +365,7 @@ sfw_bid2batch (lst_bid_t bid)
367 return bat; 365 return bat;
368} 366}
369 367
370int 368static int
371sfw_get_stats (srpc_stat_reqst_t *request, srpc_stat_reply_t *reply) 369sfw_get_stats (srpc_stat_reqst_t *request, srpc_stat_reply_t *reply)
372{ 370{
373 sfw_session_t *sn = sfw_data.fw_session; 371 sfw_session_t *sn = sfw_data.fw_session;
@@ -479,7 +477,7 @@ sfw_make_session(srpc_mksn_reqst_t *request, srpc_mksn_reply_t *reply)
479 return 0; 477 return 0;
480} 478}
481 479
482int 480static int
483sfw_remove_session (srpc_rmsn_reqst_t *request, srpc_rmsn_reply_t *reply) 481sfw_remove_session (srpc_rmsn_reqst_t *request, srpc_rmsn_reply_t *reply)
484{ 482{
485 sfw_session_t *sn = sfw_data.fw_session; 483 sfw_session_t *sn = sfw_data.fw_session;
@@ -511,7 +509,7 @@ sfw_remove_session (srpc_rmsn_reqst_t *request, srpc_rmsn_reply_t *reply)
511 return 0; 509 return 0;
512} 510}
513 511
514int 512static int
515sfw_debug_session (srpc_debug_reqst_t *request, srpc_debug_reply_t *reply) 513sfw_debug_session (srpc_debug_reqst_t *request, srpc_debug_reply_t *reply)
516{ 514{
517 sfw_session_t *sn = sfw_data.fw_session; 515 sfw_session_t *sn = sfw_data.fw_session;
@@ -532,7 +530,7 @@ sfw_debug_session (srpc_debug_reqst_t *request, srpc_debug_reply_t *reply)
532 return 0; 530 return 0;
533} 531}
534 532
535void 533static void
536sfw_test_rpc_fini (srpc_client_rpc_t *rpc) 534sfw_test_rpc_fini (srpc_client_rpc_t *rpc)
537{ 535{
538 sfw_test_unit_t *tsu = rpc->crpc_priv; 536 sfw_test_unit_t *tsu = rpc->crpc_priv;
@@ -554,7 +552,7 @@ sfw_test_buffers(sfw_test_instance_t *tsi)
554 return max(SFW_TEST_WI_MIN, nbuf + SFW_TEST_WI_EXTRA); 552 return max(SFW_TEST_WI_MIN, nbuf + SFW_TEST_WI_EXTRA);
555} 553}
556 554
557int 555static int
558sfw_load_test(struct sfw_test_instance *tsi) 556sfw_load_test(struct sfw_test_instance *tsi)
559{ 557{
560 struct sfw_test_case *tsc; 558 struct sfw_test_case *tsc;
@@ -575,8 +573,8 @@ sfw_load_test(struct sfw_test_instance *tsi)
575 573
576 rc = srpc_service_add_buffers(svc, nbuf); 574 rc = srpc_service_add_buffers(svc, nbuf);
577 if (rc != 0) { 575 if (rc != 0) {
578 CWARN("Failed to reserve enough buffers: " 576 CWARN("Failed to reserve enough buffers: service %s, %d needed: %d\n",
579 "service %s, %d needed: %d\n", svc->sv_name, nbuf, rc); 577 svc->sv_name, nbuf, rc);
580 /* NB: this error handler is not strictly correct, because 578 /* NB: this error handler is not strictly correct, because
581 * it may release more buffers than already allocated, 579 * it may release more buffers than already allocated,
582 * but it doesn't matter because request portal should 580 * but it doesn't matter because request portal should
@@ -591,7 +589,7 @@ sfw_load_test(struct sfw_test_instance *tsi)
591 return 0; 589 return 0;
592} 590}
593 591
594void 592static void
595sfw_unload_test(struct sfw_test_instance *tsi) 593sfw_unload_test(struct sfw_test_instance *tsi)
596{ 594{
597 struct sfw_test_case *tsc = sfw_find_test_case(tsi->tsi_service); 595 struct sfw_test_case *tsc = sfw_find_test_case(tsi->tsi_service);
@@ -609,7 +607,7 @@ sfw_unload_test(struct sfw_test_instance *tsi)
609 return; 607 return;
610} 608}
611 609
612void 610static void
613sfw_destroy_test_instance (sfw_test_instance_t *tsi) 611sfw_destroy_test_instance (sfw_test_instance_t *tsi)
614{ 612{
615 srpc_client_rpc_t *rpc; 613 srpc_client_rpc_t *rpc;
@@ -643,7 +641,7 @@ clean:
643 return; 641 return;
644} 642}
645 643
646void 644static void
647sfw_destroy_batch (sfw_batch_t *tsb) 645sfw_destroy_batch (sfw_batch_t *tsb)
648{ 646{
649 sfw_test_instance_t *tsi; 647 sfw_test_instance_t *tsi;
@@ -682,7 +680,7 @@ sfw_destroy_session (sfw_session_t *sn)
682 return; 680 return;
683} 681}
684 682
685void 683static void
686sfw_unpack_addtest_req(srpc_msg_t *msg) 684sfw_unpack_addtest_req(srpc_msg_t *msg)
687{ 685{
688 srpc_test_reqst_t *req = &msg->msg_body.tes_reqst; 686 srpc_test_reqst_t *req = &msg->msg_body.tes_reqst;
@@ -727,7 +725,7 @@ sfw_unpack_addtest_req(srpc_msg_t *msg)
727 return; 725 return;
728} 726}
729 727
730int 728static int
731sfw_add_test_instance (sfw_batch_t *tsb, srpc_server_rpc_t *rpc) 729sfw_add_test_instance (sfw_batch_t *tsb, srpc_server_rpc_t *rpc)
732{ 730{
733 srpc_msg_t *msg = &rpc->srpc_reqstbuf->buf_msg; 731 srpc_msg_t *msg = &rpc->srpc_reqstbuf->buf_msg;
@@ -865,7 +863,7 @@ sfw_test_unit_done (sfw_test_unit_t *tsu)
865 return; 863 return;
866} 864}
867 865
868void 866static void
869sfw_test_rpc_done (srpc_client_rpc_t *rpc) 867sfw_test_rpc_done (srpc_client_rpc_t *rpc)
870{ 868{
871 sfw_test_unit_t *tsu = rpc->crpc_priv; 869 sfw_test_unit_t *tsu = rpc->crpc_priv;
@@ -944,7 +942,7 @@ sfw_create_test_rpc(sfw_test_unit_t *tsu, lnet_process_id_t peer,
944 return 0; 942 return 0;
945} 943}
946 944
947int 945static int
948sfw_run_test (swi_workitem_t *wi) 946sfw_run_test (swi_workitem_t *wi)
949{ 947{
950 sfw_test_unit_t *tsu = wi->swi_workitem.wi_data; 948 sfw_test_unit_t *tsu = wi->swi_workitem.wi_data;
@@ -994,7 +992,7 @@ test_done:
994 return 1; 992 return 1;
995} 993}
996 994
997int 995static int
998sfw_run_batch (sfw_batch_t *tsb) 996sfw_run_batch (sfw_batch_t *tsb)
999{ 997{
1000 swi_workitem_t *wi; 998 swi_workitem_t *wi;
@@ -1072,7 +1070,7 @@ sfw_stop_batch (sfw_batch_t *tsb, int force)
1072 return 0; 1070 return 0;
1073} 1071}
1074 1072
1075int 1073static int
1076sfw_query_batch (sfw_batch_t *tsb, int testidx, srpc_batch_reply_t *reply) 1074sfw_query_batch (sfw_batch_t *tsb, int testidx, srpc_batch_reply_t *reply)
1077{ 1075{
1078 sfw_test_instance_t *tsi; 1076 sfw_test_instance_t *tsi;
@@ -1117,7 +1115,7 @@ sfw_alloc_pages(struct srpc_server_rpc *rpc, int cpt, int npages, int len,
1117 return 0; 1115 return 0;
1118} 1116}
1119 1117
1120int 1118static int
1121sfw_add_test (srpc_server_rpc_t *rpc) 1119sfw_add_test (srpc_server_rpc_t *rpc)
1122{ 1120{
1123 sfw_session_t *sn = sfw_data.fw_session; 1121 sfw_session_t *sn = sfw_data.fw_session;
@@ -1187,7 +1185,7 @@ sfw_add_test (srpc_server_rpc_t *rpc)
1187 return 0; 1185 return 0;
1188} 1186}
1189 1187
1190int 1188static int
1191sfw_control_batch (srpc_batch_reqst_t *request, srpc_batch_reply_t *reply) 1189sfw_control_batch (srpc_batch_reqst_t *request, srpc_batch_reply_t *reply)
1192{ 1190{
1193 sfw_session_t *sn = sfw_data.fw_session; 1191 sfw_session_t *sn = sfw_data.fw_session;
@@ -1228,7 +1226,7 @@ sfw_control_batch (srpc_batch_reqst_t *request, srpc_batch_reply_t *reply)
1228 return 0; 1226 return 0;
1229} 1227}
1230 1228
1231int 1229static int
1232sfw_handle_server_rpc(struct srpc_server_rpc *rpc) 1230sfw_handle_server_rpc(struct srpc_server_rpc *rpc)
1233{ 1231{
1234 struct srpc_service *sv = rpc->srpc_scd->scd_svc; 1232 struct srpc_service *sv = rpc->srpc_scd->scd_svc;
@@ -1270,8 +1268,7 @@ sfw_handle_server_rpc(struct srpc_server_rpc *rpc)
1270 1268
1271 if (sn != NULL && 1269 if (sn != NULL &&
1272 sn->sn_features != request->msg_ses_feats) { 1270 sn->sn_features != request->msg_ses_feats) {
1273 CNETERR("Features of framework RPC don't match " 1271 CNETERR("Features of framework RPC don't match features of current session: %x/%x\n",
1274 "features of current session: %x/%x\n",
1275 request->msg_ses_feats, sn->sn_features); 1272 request->msg_ses_feats, sn->sn_features);
1276 reply->msg_body.reply.status = EPROTO; 1273 reply->msg_body.reply.status = EPROTO;
1277 reply->msg_body.reply.sid = sn->sn_id; 1274 reply->msg_body.reply.sid = sn->sn_id;
@@ -1334,7 +1331,7 @@ sfw_handle_server_rpc(struct srpc_server_rpc *rpc)
1334 return rc; 1331 return rc;
1335} 1332}
1336 1333
1337int 1334static int
1338sfw_bulk_ready(struct srpc_server_rpc *rpc, int status) 1335sfw_bulk_ready(struct srpc_server_rpc *rpc, int status)
1339{ 1336{
1340 struct srpc_service *sv = rpc->srpc_scd->scd_svc; 1337 struct srpc_service *sv = rpc->srpc_scd->scd_svc;
@@ -1348,8 +1345,7 @@ sfw_bulk_ready(struct srpc_server_rpc *rpc, int status)
1348 spin_lock(&sfw_data.fw_lock); 1345 spin_lock(&sfw_data.fw_lock);
1349 1346
1350 if (status != 0) { 1347 if (status != 0) {
1351 CERROR("Bulk transfer failed for RPC: " 1348 CERROR("Bulk transfer failed for RPC: service %s, peer %s, status %d\n",
1352 "service %s, peer %s, status %d\n",
1353 sv->sv_name, libcfs_id2str(rpc->srpc_peer), status); 1349 sv->sv_name, libcfs_id2str(rpc->srpc_peer), status);
1354 spin_unlock(&sfw_data.fw_lock); 1350 spin_unlock(&sfw_data.fw_lock);
1355 return -EIO; 1351 return -EIO;
@@ -1664,12 +1660,10 @@ sfw_startup (void)
1664 } 1660 }
1665 1661
1666 if (session_timeout == 0) 1662 if (session_timeout == 0)
1667 CWARN ("Zero session_timeout specified " 1663 CWARN("Zero session_timeout specified - test sessions never expire.\n");
1668 "- test sessions never expire.\n");
1669 1664
1670 if (rpc_timeout == 0) 1665 if (rpc_timeout == 0)
1671 CWARN ("Zero rpc_timeout specified " 1666 CWARN("Zero rpc_timeout specified - test RPC never expire.\n");
1672 "- test RPC never expire.\n");
1673 1667
1674 memset(&sfw_data, 0, sizeof(struct smoketest_framework)); 1668 memset(&sfw_data, 0, sizeof(struct smoketest_framework));
1675 1669
@@ -1727,8 +1721,7 @@ sfw_startup (void)
1727 1721
1728 rc = srpc_service_add_buffers(sv, sv->sv_wi_total); 1722 rc = srpc_service_add_buffers(sv, sv->sv_wi_total);
1729 if (rc != 0) { 1723 if (rc != 0) {
1730 CWARN("Failed to reserve enough buffers: " 1724 CWARN("Failed to reserve enough buffers: service %s, %d needed: %d\n",
1731 "service %s, %d needed: %d\n",
1732 sv->sv_name, sv->sv_wi_total, rc); 1725 sv->sv_name, sv->sv_wi_total, rc);
1733 error = -ENOMEM; 1726 error = -ENOMEM;
1734 } 1727 }
diff --git a/drivers/staging/lustre/lnet/selftest/module.c b/drivers/staging/lustre/lnet/selftest/module.c
index 6dd4309dc5ea..c6ef5b0d8de1 100644
--- a/drivers/staging/lustre/lnet/selftest/module.c
+++ b/drivers/staging/lustre/lnet/selftest/module.c
@@ -55,7 +55,7 @@ static int lst_init_step = LST_INIT_NONE;
55struct cfs_wi_sched *lst_sched_serial; 55struct cfs_wi_sched *lst_sched_serial;
56struct cfs_wi_sched **lst_sched_test; 56struct cfs_wi_sched **lst_sched_test;
57 57
58void 58static void
59lnet_selftest_fini(void) 59lnet_selftest_fini(void)
60{ 60{
61 int i; 61 int i;
@@ -90,18 +90,7 @@ lnet_selftest_fini(void)
90 return; 90 return;
91} 91}
92 92
93void 93static int
94lnet_selftest_structure_assertion(void)
95{
96 CLASSERT(sizeof(srpc_msg_t) == 160);
97 CLASSERT(sizeof(srpc_test_reqst_t) == 70);
98 CLASSERT(offsetof(srpc_msg_t, msg_body.tes_reqst.tsr_concur) == 72);
99 CLASSERT(offsetof(srpc_msg_t, msg_body.tes_reqst.tsr_ndest) == 78);
100 CLASSERT(sizeof(srpc_stat_reply_t) == 136);
101 CLASSERT(sizeof(srpc_stat_reqst_t) == 28);
102}
103
104int
105lnet_selftest_init(void) 94lnet_selftest_init(void)
106{ 95{
107 int nscheds; 96 int nscheds;
@@ -130,8 +119,8 @@ lnet_selftest_init(void)
130 rc = cfs_wi_sched_create("lst_t", lnet_cpt_table(), i, 119 rc = cfs_wi_sched_create("lst_t", lnet_cpt_table(), i,
131 nthrs, &lst_sched_test[i]); 120 nthrs, &lst_sched_test[i]);
132 if (rc != 0) { 121 if (rc != 0) {
133 CERROR("Failed to create CPT affinity WI scheduler " 122 CERROR("Failed to create CPT affinity WI scheduler %d for LST\n",
134 "%d for LST\n", i); 123 i);
135 goto error; 124 goto error;
136 } 125 }
137 } 126 }
diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
index 750cac4afbb2..d8c0df6e6852 100644
--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
@@ -44,7 +44,7 @@
44 44
45#define LST_PING_TEST_MAGIC 0xbabeface 45#define LST_PING_TEST_MAGIC 0xbabeface
46 46
47int ping_srv_workitems = SFW_TEST_WI_MAX; 47static int ping_srv_workitems = SFW_TEST_WI_MAX;
48module_param(ping_srv_workitems, int, 0644); 48module_param(ping_srv_workitems, int, 0644);
49MODULE_PARM_DESC(ping_srv_workitems, "# PING server workitems"); 49MODULE_PARM_DESC(ping_srv_workitems, "# PING server workitems");
50 50
diff --git a/drivers/staging/lustre/lnet/selftest/rpc.c b/drivers/staging/lustre/lnet/selftest/rpc.c
index a9f29d8833a9..f753add7bfb3 100644
--- a/drivers/staging/lustre/lnet/selftest/rpc.c
+++ b/drivers/staging/lustre/lnet/selftest/rpc.c
@@ -87,7 +87,7 @@ void srpc_set_counters (const srpc_counters_t *cnt)
87 spin_unlock(&srpc_data.rpc_glock); 87 spin_unlock(&srpc_data.rpc_glock);
88} 88}
89 89
90int 90static int
91srpc_add_bulk_page(srpc_bulk_t *bk, struct page *pg, int i, int nob) 91srpc_add_bulk_page(srpc_bulk_t *bk, struct page *pg, int i, int nob)
92{ 92{
93 nob = min(nob, (int)PAGE_CACHE_SIZE); 93 nob = min(nob, (int)PAGE_CACHE_SIZE);
@@ -170,7 +170,7 @@ srpc_next_id (void)
170 return id; 170 return id;
171} 171}
172 172
173void 173static void
174srpc_init_server_rpc(struct srpc_server_rpc *rpc, 174srpc_init_server_rpc(struct srpc_server_rpc *rpc,
175 struct srpc_service_cd *scd, 175 struct srpc_service_cd *scd,
176 struct srpc_buffer *buffer) 176 struct srpc_buffer *buffer)
@@ -351,7 +351,7 @@ srpc_remove_service (srpc_service_t *sv)
351 return 0; 351 return 0;
352} 352}
353 353
354int 354static int
355srpc_post_passive_rdma(int portal, int local, __u64 matchbits, void *buf, 355srpc_post_passive_rdma(int portal, int local, __u64 matchbits, void *buf,
356 int len, int options, lnet_process_id_t peer, 356 int len, int options, lnet_process_id_t peer,
357 lnet_handle_md_t *mdh, srpc_event_t *ev) 357 lnet_handle_md_t *mdh, srpc_event_t *ev)
@@ -391,7 +391,7 @@ srpc_post_passive_rdma(int portal, int local, __u64 matchbits, void *buf,
391 return 0; 391 return 0;
392} 392}
393 393
394int 394static int
395srpc_post_active_rdma(int portal, __u64 matchbits, void *buf, int len, 395srpc_post_active_rdma(int portal, __u64 matchbits, void *buf, int len,
396 int options, lnet_process_id_t peer, lnet_nid_t self, 396 int options, lnet_process_id_t peer, lnet_nid_t self,
397 lnet_handle_md_t *mdh, srpc_event_t *ev) 397 lnet_handle_md_t *mdh, srpc_event_t *ev)
@@ -443,7 +443,7 @@ srpc_post_active_rdma(int portal, __u64 matchbits, void *buf, int len,
443 return 0; 443 return 0;
444} 444}
445 445
446int 446static int
447srpc_post_active_rqtbuf(lnet_process_id_t peer, int service, void *buf, 447srpc_post_active_rqtbuf(lnet_process_id_t peer, int service, void *buf,
448 int len, lnet_handle_md_t *mdh, srpc_event_t *ev) 448 int len, lnet_handle_md_t *mdh, srpc_event_t *ev)
449{ 449{
@@ -452,7 +452,7 @@ srpc_post_active_rqtbuf(lnet_process_id_t peer, int service, void *buf,
452 LNET_NID_ANY, mdh, ev); 452 LNET_NID_ANY, mdh, ev);
453} 453}
454 454
455int 455static int
456srpc_post_passive_rqtbuf(int service, int local, void *buf, int len, 456srpc_post_passive_rqtbuf(int service, int local, void *buf, int len,
457 lnet_handle_md_t *mdh, srpc_event_t *ev) 457 lnet_handle_md_t *mdh, srpc_event_t *ev)
458{ 458{
@@ -466,7 +466,7 @@ srpc_post_passive_rqtbuf(int service, int local, void *buf, int len,
466 LNET_MD_OP_PUT, any, mdh, ev); 466 LNET_MD_OP_PUT, any, mdh, ev);
467} 467}
468 468
469int 469static int
470srpc_service_post_buffer(struct srpc_service_cd *scd, struct srpc_buffer *buf) 470srpc_service_post_buffer(struct srpc_service_cd *scd, struct srpc_buffer *buf)
471{ 471{
472 struct srpc_service *sv = scd->scd_svc; 472 struct srpc_service *sv = scd->scd_svc;
@@ -678,9 +678,7 @@ srpc_finish_service(struct srpc_service *sv)
678 678
679 rpc = list_entry(scd->scd_rpc_active.next, 679 rpc = list_entry(scd->scd_rpc_active.next,
680 struct srpc_server_rpc, srpc_list); 680 struct srpc_server_rpc, srpc_list);
681 CNETERR("Active RPC %p on shutdown: sv %s, peer %s, " 681 CNETERR("Active RPC %p on shutdown: sv %s, peer %s, wi %s scheduled %d running %d, ev fired %d type %d status %d lnet %d\n",
682 "wi %s scheduled %d running %d, "
683 "ev fired %d type %d status %d lnet %d\n",
684 rpc, sv->sv_name, libcfs_id2str(rpc->srpc_peer), 682 rpc, sv->sv_name, libcfs_id2str(rpc->srpc_peer),
685 swi_state2str(rpc->srpc_wi.swi_state), 683 swi_state2str(rpc->srpc_wi.swi_state),
686 rpc->srpc_wi.swi_workitem.wi_scheduled, 684 rpc->srpc_wi.swi_workitem.wi_scheduled,
@@ -697,7 +695,7 @@ srpc_finish_service(struct srpc_service *sv)
697} 695}
698 696
699/* called with sv->sv_lock held */ 697/* called with sv->sv_lock held */
700void 698static void
701srpc_service_recycle_buffer(struct srpc_service_cd *scd, srpc_buffer_t *buf) 699srpc_service_recycle_buffer(struct srpc_service_cd *scd, srpc_buffer_t *buf)
702{ 700{
703 if (!scd->scd_svc->sv_shuttingdown && scd->scd_buf_adjust >= 0) { 701 if (!scd->scd_svc->sv_shuttingdown && scd->scd_buf_adjust >= 0) {
@@ -787,7 +785,7 @@ srpc_shutdown_service(srpc_service_t *sv)
787 } 785 }
788} 786}
789 787
790int 788static int
791srpc_send_request (srpc_client_rpc_t *rpc) 789srpc_send_request (srpc_client_rpc_t *rpc)
792{ 790{
793 srpc_event_t *ev = &rpc->crpc_reqstev; 791 srpc_event_t *ev = &rpc->crpc_reqstev;
@@ -807,7 +805,7 @@ srpc_send_request (srpc_client_rpc_t *rpc)
807 return rc; 805 return rc;
808} 806}
809 807
810int 808static int
811srpc_prepare_reply (srpc_client_rpc_t *rpc) 809srpc_prepare_reply (srpc_client_rpc_t *rpc)
812{ 810{
813 srpc_event_t *ev = &rpc->crpc_replyev; 811 srpc_event_t *ev = &rpc->crpc_replyev;
@@ -831,7 +829,7 @@ srpc_prepare_reply (srpc_client_rpc_t *rpc)
831 return rc; 829 return rc;
832} 830}
833 831
834int 832static int
835srpc_prepare_bulk (srpc_client_rpc_t *rpc) 833srpc_prepare_bulk (srpc_client_rpc_t *rpc)
836{ 834{
837 srpc_bulk_t *bk = &rpc->crpc_bulk; 835 srpc_bulk_t *bk = &rpc->crpc_bulk;
@@ -863,7 +861,7 @@ srpc_prepare_bulk (srpc_client_rpc_t *rpc)
863 return rc; 861 return rc;
864} 862}
865 863
866int 864static int
867srpc_do_bulk (srpc_server_rpc_t *rpc) 865srpc_do_bulk (srpc_server_rpc_t *rpc)
868{ 866{
869 srpc_event_t *ev = &rpc->srpc_ev; 867 srpc_event_t *ev = &rpc->srpc_ev;
@@ -891,7 +889,7 @@ srpc_do_bulk (srpc_server_rpc_t *rpc)
891} 889}
892 890
893/* only called from srpc_handle_rpc */ 891/* only called from srpc_handle_rpc */
894void 892static void
895srpc_server_rpc_done(srpc_server_rpc_t *rpc, int status) 893srpc_server_rpc_done(srpc_server_rpc_t *rpc, int status)
896{ 894{
897 struct srpc_service_cd *scd = rpc->srpc_scd; 895 struct srpc_service_cd *scd = rpc->srpc_scd;
@@ -1066,7 +1064,7 @@ srpc_handle_rpc(swi_workitem_t *wi)
1066 return 0; 1064 return 0;
1067} 1065}
1068 1066
1069void 1067static void
1070srpc_client_rpc_expired (void *data) 1068srpc_client_rpc_expired (void *data)
1071{ 1069{
1072 srpc_client_rpc_t *rpc = data; 1070 srpc_client_rpc_t *rpc = data;
@@ -1108,7 +1106,7 @@ srpc_add_client_rpc_timer (srpc_client_rpc_t *rpc)
1108 * 1106 *
1109 * Upon exit the RPC expiry timer is not queued and the handler is not 1107 * Upon exit the RPC expiry timer is not queued and the handler is not
1110 * running on any CPU. */ 1108 * running on any CPU. */
1111void 1109static void
1112srpc_del_client_rpc_timer (srpc_client_rpc_t *rpc) 1110srpc_del_client_rpc_timer (srpc_client_rpc_t *rpc)
1113{ 1111{
1114 /* timer not planted or already exploded */ 1112 /* timer not planted or already exploded */
@@ -1129,7 +1127,7 @@ srpc_del_client_rpc_timer (srpc_client_rpc_t *rpc)
1129 } 1127 }
1130} 1128}
1131 1129
1132void 1130static void
1133srpc_client_rpc_done (srpc_client_rpc_t *rpc, int status) 1131srpc_client_rpc_done (srpc_client_rpc_t *rpc, int status)
1134{ 1132{
1135 swi_workitem_t *wi = &rpc->crpc_wi; 1133 swi_workitem_t *wi = &rpc->crpc_wi;
@@ -1236,20 +1234,18 @@ srpc_send_rpc (swi_workitem_t *wi)
1236 if (reply->msg_type != type || 1234 if (reply->msg_type != type ||
1237 (reply->msg_magic != SRPC_MSG_MAGIC && 1235 (reply->msg_magic != SRPC_MSG_MAGIC &&
1238 reply->msg_magic != __swab32(SRPC_MSG_MAGIC))) { 1236 reply->msg_magic != __swab32(SRPC_MSG_MAGIC))) {
1239 CWARN ("Bad message from %s: type %u (%d expected)," 1237 CWARN("Bad message from %s: type %u (%d expected), magic %u (%d expected).\n",
1240 " magic %u (%d expected).\n", 1238 libcfs_id2str(rpc->crpc_dest),
1241 libcfs_id2str(rpc->crpc_dest), 1239 reply->msg_type, type,
1242 reply->msg_type, type, 1240 reply->msg_magic, SRPC_MSG_MAGIC);
1243 reply->msg_magic, SRPC_MSG_MAGIC);
1244 rc = -EBADMSG; 1241 rc = -EBADMSG;
1245 break; 1242 break;
1246 } 1243 }
1247 1244
1248 if (do_bulk && reply->msg_body.reply.status != 0) { 1245 if (do_bulk && reply->msg_body.reply.status != 0) {
1249 CWARN ("Remote error %d at %s, unlink bulk buffer in " 1246 CWARN("Remote error %d at %s, unlink bulk buffer in case peer didn't initiate bulk transfer\n",
1250 "case peer didn't initiate bulk transfer\n", 1247 reply->msg_body.reply.status,
1251 reply->msg_body.reply.status, 1248 libcfs_id2str(rpc->crpc_dest));
1252 libcfs_id2str(rpc->crpc_dest));
1253 LNetMDUnlink(rpc->crpc_bulk.bk_mdh); 1249 LNetMDUnlink(rpc->crpc_bulk.bk_mdh);
1254 } 1250 }
1255 1251
@@ -1393,7 +1389,7 @@ srpc_send_reply(struct srpc_server_rpc *rpc)
1393} 1389}
1394 1390
1395/* when in kernel always called with LNET_LOCK() held, and in thread context */ 1391/* when in kernel always called with LNET_LOCK() held, and in thread context */
1396void 1392static void
1397srpc_lnet_ev_handler(lnet_event_t *ev) 1393srpc_lnet_ev_handler(lnet_event_t *ev)
1398{ 1394{
1399 struct srpc_service_cd *scd; 1395 struct srpc_service_cd *scd;
@@ -1504,11 +1500,10 @@ srpc_lnet_ev_handler(lnet_event_t *ev)
1504 msg->msg_type != __swab32(type)) || 1500 msg->msg_type != __swab32(type)) ||
1505 (msg->msg_magic != SRPC_MSG_MAGIC && 1501 (msg->msg_magic != SRPC_MSG_MAGIC &&
1506 msg->msg_magic != __swab32(SRPC_MSG_MAGIC))) { 1502 msg->msg_magic != __swab32(SRPC_MSG_MAGIC))) {
1507 CERROR ("Dropping RPC (%s) from %s: " 1503 CERROR("Dropping RPC (%s) from %s: status %d mlength %d type %u magic %u.\n",
1508 "status %d mlength %d type %u magic %u.\n", 1504 sv->sv_name, libcfs_id2str(ev->initiator),
1509 sv->sv_name, libcfs_id2str(ev->initiator), 1505 ev->status, ev->mlength,
1510 ev->status, ev->mlength, 1506 msg->msg_type, msg->msg_magic);
1511 msg->msg_type, msg->msg_magic);
1512 1507
1513 /* NB can't call srpc_service_recycle_buffer here since 1508 /* NB can't call srpc_service_recycle_buffer here since
1514 * it may call LNetM[DE]Attach. The invalid magic tells 1509 * it may call LNetM[DE]Attach. The invalid magic tells
diff --git a/drivers/staging/lustre/lnet/selftest/timer.c b/drivers/staging/lustre/lnet/selftest/timer.c
index 91d4caa4edb0..f8352c2a7d37 100644
--- a/drivers/staging/lustre/lnet/selftest/timer.c
+++ b/drivers/staging/lustre/lnet/selftest/timer.c
@@ -121,7 +121,7 @@ stt_del_timer(stt_timer_t *timer)
121} 121}
122 122
123/* called with stt_data.stt_lock held */ 123/* called with stt_data.stt_lock held */
124int 124static int
125stt_expire_list(struct list_head *slot, unsigned long now) 125stt_expire_list(struct list_head *slot, unsigned long now)
126{ 126{
127 int expired = 0; 127 int expired = 0;
@@ -145,7 +145,7 @@ stt_expire_list(struct list_head *slot, unsigned long now)
145 return expired; 145 return expired;
146} 146}
147 147
148int 148static int
149stt_check_timers(unsigned long *last) 149stt_check_timers(unsigned long *last)
150{ 150{
151 int expired = 0; 151 int expired = 0;
@@ -168,7 +168,7 @@ stt_check_timers(unsigned long *last)
168} 168}
169 169
170 170
171int 171static int
172stt_timer_main(void *arg) 172stt_timer_main(void *arg)
173{ 173{
174 cfs_block_allsigs(); 174 cfs_block_allsigs();
@@ -187,7 +187,7 @@ stt_timer_main(void *arg)
187 return 0; 187 return 0;
188} 188}
189 189
190int 190static int
191stt_start_timer_thread(void) 191stt_start_timer_thread(void)
192{ 192{
193 struct task_struct *task; 193 struct task_struct *task;
diff --git a/drivers/staging/lustre/lustre/Kconfig b/drivers/staging/lustre/lustre/Kconfig
index 4f65ba1158bf..6725467ef4d0 100644
--- a/drivers/staging/lustre/lustre/Kconfig
+++ b/drivers/staging/lustre/lustre/Kconfig
@@ -57,5 +57,5 @@ config LUSTRE_TRANSLATE_ERRNOS
57config LUSTRE_LLITE_LLOOP 57config LUSTRE_LLITE_LLOOP
58 tristate "Lustre virtual block device" 58 tristate "Lustre virtual block device"
59 depends on LUSTRE_FS && BLOCK 59 depends on LUSTRE_FS && BLOCK
60 depends on !PPC_64K_PAGES && !ARM64_64K_PAGES 60 depends on !PPC_64K_PAGES && !ARM64_64K_PAGES && !MICROBLAZE_64K_PAGES && !PAGE_SIZE_64KB && !IA64_PAGE_SIZE_64KB && !PARISC_PAGE_SIZE_64KB
61 default m 61 default m
diff --git a/drivers/staging/lustre/lustre/include/dt_object.h b/drivers/staging/lustre/lustre/include/dt_object.h
index 212ebaea8555..be4c7d95e788 100644
--- a/drivers/staging/lustre/lustre/include/dt_object.h
+++ b/drivers/staging/lustre/lustre/include/dt_object.h
@@ -617,7 +617,7 @@ struct dt_index_operations {
617 int (*load)(const struct lu_env *env, 617 int (*load)(const struct lu_env *env,
618 const struct dt_it *di, __u64 hash); 618 const struct dt_it *di, __u64 hash);
619 int (*key_rec)(const struct lu_env *env, 619 int (*key_rec)(const struct lu_env *env,
620 const struct dt_it *di, void* key_rec); 620 const struct dt_it *di, void *key_rec);
621 } dio_it; 621 } dio_it;
622}; 622};
623 623
@@ -667,7 +667,7 @@ static inline int lu_device_is_dt(const struct lu_device *d)
667 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT); 667 return ergo(d != NULL, d->ld_type->ldt_tags & LU_DEVICE_DT);
668} 668}
669 669
670static inline struct dt_device * lu2dt_dev(struct lu_device *l) 670static inline struct dt_device *lu2dt_dev(struct lu_device *l)
671{ 671{
672 LASSERT(lu_device_is_dt(l)); 672 LASSERT(lu_device_is_dt(l));
673 return container_of0(l, struct dt_device, dd_lu_dev); 673 return container_of0(l, struct dt_device, dd_lu_dev);
diff --git a/drivers/staging/lustre/lustre/include/linux/lustre_compat25.h b/drivers/staging/lustre/lustre/include/linux/lustre_compat25.h
index e94ab343ab25..8156b4c0f568 100644
--- a/drivers/staging/lustre/lustre/include/linux/lustre_compat25.h
+++ b/drivers/staging/lustre/lustre/include/linux/lustre_compat25.h
@@ -91,8 +91,6 @@ static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
91# define inode_dio_read(i) atomic_inc(&(i)->i_dio_count) 91# define inode_dio_read(i) atomic_inc(&(i)->i_dio_count)
92/* inode_dio_done(i) use as-is for read unlock */ 92/* inode_dio_done(i) use as-is for read unlock */
93 93
94#define TREE_READ_LOCK_IRQ(mapping) spin_lock_irq(&(mapping)->tree_lock)
95#define TREE_READ_UNLOCK_IRQ(mapping) spin_unlock_irq(&(mapping)->tree_lock)
96 94
97#ifndef FS_HAS_FIEMAP 95#ifndef FS_HAS_FIEMAP
98#define FS_HAS_FIEMAP (0) 96#define FS_HAS_FIEMAP (0)
@@ -139,8 +137,7 @@ ll_quota_on(struct super_block *sb, int off, int ver, char *name, int remount)
139 ); 137 );
140 path_put(&path); 138 path_put(&path);
141 return rc; 139 return rc;
142 } 140 } else
143 else
144 return -ENOSYS; 141 return -ENOSYS;
145} 142}
146 143
@@ -149,8 +146,7 @@ static inline int ll_quota_off(struct super_block *sb, int off, int remount)
149 if (sb->s_qcop->quota_off) { 146 if (sb->s_qcop->quota_off) {
150 return sb->s_qcop->quota_off(sb, off 147 return sb->s_qcop->quota_off(sb, off
151 ); 148 );
152 } 149 } else
153 else
154 return -ENOSYS; 150 return -ENOSYS;
155} 151}
156 152
diff --git a/drivers/staging/lustre/lustre/include/linux/obd.h b/drivers/staging/lustre/lustre/include/linux/obd.h
index 9d7e28ace42d..9cd8683573ce 100644
--- a/drivers/staging/lustre/lustre/include/linux/obd.h
+++ b/drivers/staging/lustre/lustre/include/linux/obd.h
@@ -87,8 +87,7 @@ static inline void __client_obd_list_lock(client_obd_lock_t *lock,
87 if (task == NULL) 87 if (task == NULL)
88 continue; 88 continue;
89 89
90 LCONSOLE_WARN("%s:%d: lock %p was acquired" 90 LCONSOLE_WARN("%s:%d: lock %p was acquired by <%s:%d:%s:%d> for %lu seconds.\n",
91 " by <%s:%d:%s:%d> for %lu seconds.\n",
92 current->comm, current->pid, 91 current->comm, current->pid,
93 lock, task->comm, task->pid, 92 lock, task->comm, task->pid,
94 lock->func, lock->line, 93 lock->func, lock->line,
diff --git a/drivers/staging/lustre/lustre/include/lprocfs_status.h b/drivers/staging/lustre/lustre/include/lprocfs_status.h
index ccb6cd42a67d..cfe503b7df62 100644
--- a/drivers/staging/lustre/lustre/include/lprocfs_status.h
+++ b/drivers/staging/lustre/lustre/include/lprocfs_status.h
@@ -374,8 +374,8 @@ static inline void s2dhms(struct dhms *ts, time_t secs)
374#define JOBSTATS_PROCNAME_UID "procname_uid" 374#define JOBSTATS_PROCNAME_UID "procname_uid"
375#define JOBSTATS_NODELOCAL "nodelocal" 375#define JOBSTATS_NODELOCAL "nodelocal"
376 376
377extern int lprocfs_write_frac_helper(const char *buffer, unsigned long count, 377extern int lprocfs_write_frac_helper(const char __user *buffer,
378 int *val, int mult); 378 unsigned long count, int *val, int mult);
379extern int lprocfs_read_frac_helper(char *buffer, unsigned long count, 379extern int lprocfs_read_frac_helper(char *buffer, unsigned long count,
380 long val, int mult); 380 long val, int mult);
381#if defined (CONFIG_PROC_FS) 381#if defined (CONFIG_PROC_FS)
@@ -557,7 +557,7 @@ extern void lprocfs_free_obd_stats(struct obd_device *obddev);
557extern void lprocfs_free_md_stats(struct obd_device *obddev); 557extern void lprocfs_free_md_stats(struct obd_device *obddev);
558struct obd_export; 558struct obd_export;
559struct nid_stat; 559struct nid_stat;
560extern int lprocfs_add_clear_entry(struct obd_device * obd, 560extern int lprocfs_add_clear_entry(struct obd_device *obd,
561 struct proc_dir_entry *entry); 561 struct proc_dir_entry *entry);
562extern int lprocfs_exp_setup(struct obd_export *exp, 562extern int lprocfs_exp_setup(struct obd_export *exp,
563 lnet_nid_t *peer_nid, int *newnid); 563 lnet_nid_t *peer_nid, int *newnid);
@@ -647,7 +647,7 @@ extern int lprocfs_rd_kbytesavail(struct seq_file *m, void *data);
647extern int lprocfs_rd_filestotal(struct seq_file *m, void *data); 647extern int lprocfs_rd_filestotal(struct seq_file *m, void *data);
648extern int lprocfs_rd_filesfree(struct seq_file *m, void *data); 648extern int lprocfs_rd_filesfree(struct seq_file *m, void *data);
649 649
650extern int lprocfs_write_helper(const char *buffer, unsigned long count, 650extern int lprocfs_write_helper(const char __user *buffer, unsigned long count,
651 int *val); 651 int *val);
652extern int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult); 652extern int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult);
653extern int lprocfs_write_u64_helper(const char *buffer, unsigned long count, 653extern int lprocfs_write_u64_helper(const char *buffer, unsigned long count,
diff --git a/drivers/staging/lustre/lustre/include/lu_object.h b/drivers/staging/lustre/lustre/include/lu_object.h
index 6015ee5c4b64..2ddb2b054d8d 100644
--- a/drivers/staging/lustre/lustre/include/lu_object.h
+++ b/drivers/staging/lustre/lustre/include/lu_object.h
@@ -1120,7 +1120,7 @@ struct lu_context_key {
1120}; 1120};
1121 1121
1122#define LU_KEY_INIT(mod, type) \ 1122#define LU_KEY_INIT(mod, type) \
1123 static void* mod##_key_init(const struct lu_context *ctx, \ 1123 static void *mod##_key_init(const struct lu_context *ctx, \
1124 struct lu_context_key *key) \ 1124 struct lu_context_key *key) \
1125 { \ 1125 { \
1126 type *value; \ 1126 type *value; \
@@ -1137,7 +1137,7 @@ struct lu_context_key {
1137 1137
1138#define LU_KEY_FINI(mod, type) \ 1138#define LU_KEY_FINI(mod, type) \
1139 static void mod##_key_fini(const struct lu_context *ctx, \ 1139 static void mod##_key_fini(const struct lu_context *ctx, \
1140 struct lu_context_key *key, void* data) \ 1140 struct lu_context_key *key, void *data) \
1141 { \ 1141 { \
1142 type *info = data; \ 1142 type *info = data; \
1143 \ 1143 \
diff --git a/drivers/staging/lustre/lustre/include/lustre_capa.h b/drivers/staging/lustre/lustre/include/lustre_capa.h
index ab6b9ea98a70..fe19534ebd8f 100644
--- a/drivers/staging/lustre/lustre/include/lustre_capa.h
+++ b/drivers/staging/lustre/lustre/include/lustre_capa.h
@@ -154,7 +154,7 @@ static inline __u32 capa_expiry(struct lustre_capa *capa)
154} 154}
155 155
156void _debug_capa(struct lustre_capa *, struct libcfs_debug_msg_data *, 156void _debug_capa(struct lustre_capa *, struct libcfs_debug_msg_data *,
157 const char *fmt, ... ); 157 const char *fmt, ...);
158#define DEBUG_CAPA(level, capa, fmt, args...) \ 158#define DEBUG_CAPA(level, capa, fmt, args...) \
159do { \ 159do { \
160 if (((level) & D_CANTMASK) != 0 || \ 160 if (((level) & D_CANTMASK) != 0 || \
diff --git a/drivers/staging/lustre/lustre/include/lustre_disk.h b/drivers/staging/lustre/lustre/include/lustre_disk.h
index 515b835ce14d..9b2833131744 100644
--- a/drivers/staging/lustre/lustre/include/lustre_disk.h
+++ b/drivers/staging/lustre/lustre/include/lustre_disk.h
@@ -368,8 +368,7 @@ static inline void check_lcd(char *obd_name, int index,
368 if (strnlen((char*)lcd->lcd_uuid, length) == length) { 368 if (strnlen((char*)lcd->lcd_uuid, length) == length) {
369 lcd->lcd_uuid[length - 1] = '\0'; 369 lcd->lcd_uuid[length - 1] = '\0';
370 370
371 LCONSOLE_ERROR("the client UUID (%s) on %s for exports" 371 LCONSOLE_ERROR("the client UUID (%s) on %s for exports stored in last_rcvd(index = %d) is bad!\n",
372 "stored in last_rcvd(index = %d) is bad!\n",
373 lcd->lcd_uuid, obd_name, index); 372 lcd->lcd_uuid, obd_name, index);
374 } 373 }
375} 374}
diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
index 14ac46f45fd1..83bc0a9d7d4c 100644
--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
@@ -1446,7 +1446,7 @@ static inline void check_res_locked(struct ldlm_resource *res)
1446 assert_spin_locked(&res->lr_lock); 1446 assert_spin_locked(&res->lr_lock);
1447} 1447}
1448 1448
1449struct ldlm_resource * lock_res_and_lock(struct ldlm_lock *lock); 1449struct ldlm_resource *lock_res_and_lock(struct ldlm_lock *lock);
1450void unlock_res_and_lock(struct ldlm_lock *lock); 1450void unlock_res_and_lock(struct ldlm_lock *lock);
1451 1451
1452/* ldlm_pool.c */ 1452/* ldlm_pool.c */
diff --git a/drivers/staging/lustre/lustre/include/lustre_eacl.h b/drivers/staging/lustre/lustre/include/lustre_eacl.h
index b94f76a3301b..0f8f76c43ee1 100644
--- a/drivers/staging/lustre/lustre/include/lustre_eacl.h
+++ b/drivers/staging/lustre/lustre/include/lustre_eacl.h
@@ -74,7 +74,7 @@ typedef struct {
74extern ext_acl_xattr_header * 74extern ext_acl_xattr_header *
75lustre_posix_acl_xattr_2ext(posix_acl_xattr_header *header, int size); 75lustre_posix_acl_xattr_2ext(posix_acl_xattr_header *header, int size);
76extern int 76extern int
77lustre_posix_acl_xattr_filter(posix_acl_xattr_header *header, int size, 77lustre_posix_acl_xattr_filter(posix_acl_xattr_header *header, size_t size,
78 posix_acl_xattr_header **out); 78 posix_acl_xattr_header **out);
79extern void 79extern void
80lustre_posix_acl_xattr_free(posix_acl_xattr_header *header, int size); 80lustre_posix_acl_xattr_free(posix_acl_xattr_header *header, int size);
diff --git a/drivers/staging/lustre/lustre/include/lustre_lib.h b/drivers/staging/lustre/lustre/include/lustre_lib.h
index 12c7590e61fa..bf135630c39a 100644
--- a/drivers/staging/lustre/lustre/include/lustre_lib.h
+++ b/drivers/staging/lustre/lustre/include/lustre_lib.h
@@ -85,7 +85,7 @@ void target_send_reply(struct ptlrpc_request *req, int rc, int fail_id);
85 85
86/* client.c */ 86/* client.c */
87 87
88int client_sanobd_setup(struct obd_device *obddev, struct lustre_cfg* lcfg); 88int client_sanobd_setup(struct obd_device *obddev, struct lustre_cfg *lcfg);
89struct client_obd *client_conn2cli(struct lustre_handle *conn); 89struct client_obd *client_conn2cli(struct lustre_handle *conn);
90 90
91struct md_open_data; 91struct md_open_data;
diff --git a/drivers/staging/lustre/lustre/include/lustre_net.h b/drivers/staging/lustre/lustre/include/lustre_net.h
index 0a024d3cfeb7..36396d1c94dc 100644
--- a/drivers/staging/lustre/lustre/include/lustre_net.h
+++ b/drivers/staging/lustre/lustre/include/lustre_net.h
@@ -2627,12 +2627,7 @@ __u32 lustre_msg_get_timeout(struct lustre_msg *msg);
2627__u32 lustre_msg_get_service_time(struct lustre_msg *msg); 2627__u32 lustre_msg_get_service_time(struct lustre_msg *msg);
2628char *lustre_msg_get_jobid(struct lustre_msg *msg); 2628char *lustre_msg_get_jobid(struct lustre_msg *msg);
2629__u32 lustre_msg_get_cksum(struct lustre_msg *msg); 2629__u32 lustre_msg_get_cksum(struct lustre_msg *msg);
2630#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 50, 0)
2631__u32 lustre_msg_calc_cksum(struct lustre_msg *msg, int compat18);
2632#else
2633# warning "remove checksum compatibility support for b1_8"
2634__u32 lustre_msg_calc_cksum(struct lustre_msg *msg); 2630__u32 lustre_msg_calc_cksum(struct lustre_msg *msg);
2635#endif
2636void lustre_msg_set_handle(struct lustre_msg *msg, 2631void lustre_msg_set_handle(struct lustre_msg *msg,
2637 struct lustre_handle *handle); 2632 struct lustre_handle *handle);
2638void lustre_msg_set_type(struct lustre_msg *msg, __u32 type); 2633void lustre_msg_set_type(struct lustre_msg *msg, __u32 type);
@@ -2951,7 +2946,7 @@ void ptlrpcd_decref(void);
2951 * procfs output related functions 2946 * procfs output related functions
2952 * @{ 2947 * @{
2953 */ 2948 */
2954const char* ll_opcode2str(__u32 opcode); 2949const char *ll_opcode2str(__u32 opcode);
2955#if defined (CONFIG_PROC_FS) 2950#if defined (CONFIG_PROC_FS)
2956void ptlrpc_lprocfs_register_obd(struct obd_device *obd); 2951void ptlrpc_lprocfs_register_obd(struct obd_device *obd);
2957void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd); 2952void ptlrpc_lprocfs_unregister_obd(struct obd_device *obd);
diff --git a/drivers/staging/lustre/lustre/include/obd_class.h b/drivers/staging/lustre/lustre/include/obd_class.h
index 882e40bd584c..4a29261c514d 100644
--- a/drivers/staging/lustre/lustre/include/obd_class.h
+++ b/drivers/staging/lustre/lustre/include/obd_class.h
@@ -414,7 +414,7 @@ do { \
414#define EXP_MD_COUNTER_INCREMENT(exp, op) 414#define EXP_MD_COUNTER_INCREMENT(exp, op)
415#endif 415#endif
416 416
417static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp) 417static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat *tmp)
418{ 418{
419 /* Always add in ldlm_stats */ 419 /* Always add in ldlm_stats */
420 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC 420 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
diff --git a/drivers/staging/lustre/lustre/ldlm/interval_tree.c b/drivers/staging/lustre/lustre/ldlm/interval_tree.c
index a3d7a7292417..eab2bd60241b 100644
--- a/drivers/staging/lustre/lustre/ldlm/interval_tree.c
+++ b/drivers/staging/lustre/lustre/ldlm/interval_tree.c
@@ -73,6 +73,7 @@ static inline int extent_compare(struct interval_node_extent *e1,
73 struct interval_node_extent *e2) 73 struct interval_node_extent *e2)
74{ 74{
75 int rc; 75 int rc;
76
76 if (e1->start == e2->start) { 77 if (e1->start == e2->start) {
77 if (e1->end < e2->end) 78 if (e1->end < e2->end)
78 rc = -1; 79 rc = -1;
@@ -321,6 +322,7 @@ static void interval_insert_color(struct interval_node *node,
321 /* Parent is RED, so gparent must not be NULL */ 322 /* Parent is RED, so gparent must not be NULL */
322 if (node_is_left_child(parent)) { 323 if (node_is_left_child(parent)) {
323 struct interval_node *uncle; 324 struct interval_node *uncle;
325
324 uncle = gparent->in_right; 326 uncle = gparent->in_right;
325 if (uncle && node_is_red(uncle)) { 327 if (uncle && node_is_red(uncle)) {
326 uncle->in_color = INTERVAL_BLACK; 328 uncle->in_color = INTERVAL_BLACK;
@@ -340,6 +342,7 @@ static void interval_insert_color(struct interval_node *node,
340 __rotate_right(gparent, root); 342 __rotate_right(gparent, root);
341 } else { 343 } else {
342 struct interval_node *uncle; 344 struct interval_node *uncle;
345
343 uncle = gparent->in_left; 346 uncle = gparent->in_left;
344 if (uncle && node_is_red(uncle)) { 347 if (uncle && node_is_red(uncle)) {
345 uncle->in_color = INTERVAL_BLACK; 348 uncle->in_color = INTERVAL_BLACK;
@@ -427,6 +430,7 @@ static void interval_erase_color(struct interval_node *node,
427 } else { 430 } else {
428 if (node_is_black_or_0(tmp->in_right)) { 431 if (node_is_black_or_0(tmp->in_right)) {
429 struct interval_node *o_left; 432 struct interval_node *o_left;
433
430 o_left = tmp->in_left; 434 o_left = tmp->in_left;
431 if (o_left) 435 if (o_left)
432 o_left->in_color = INTERVAL_BLACK; 436 o_left->in_color = INTERVAL_BLACK;
@@ -458,6 +462,7 @@ static void interval_erase_color(struct interval_node *node,
458 } else { 462 } else {
459 if (node_is_black_or_0(tmp->in_left)) { 463 if (node_is_black_or_0(tmp->in_left)) {
460 struct interval_node *o_right; 464 struct interval_node *o_right;
465
461 o_right = tmp->in_right; 466 o_right = tmp->in_right;
462 if (o_right) 467 if (o_right)
463 o_right->in_color = INTERVAL_BLACK; 468 o_right->in_color = INTERVAL_BLACK;
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c b/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
index 0c09b611f4a6..a89eebaedabf 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
@@ -182,7 +182,9 @@ void ldlm_extent_add_lock(struct ldlm_resource *res,
182 root = &res->lr_itree[idx].lit_root; 182 root = &res->lr_itree[idx].lit_root;
183 found = interval_insert(&node->li_node, root); 183 found = interval_insert(&node->li_node, root);
184 if (found) { /* The policy group found. */ 184 if (found) { /* The policy group found. */
185 struct ldlm_interval *tmp = ldlm_interval_detach(lock); 185 struct ldlm_interval *tmp;
186
187 tmp = ldlm_interval_detach(lock);
186 LASSERT(tmp != NULL); 188 LASSERT(tmp != NULL);
187 ldlm_interval_free(tmp); 189 ldlm_interval_free(tmp);
188 ldlm_interval_attach(to_ldlm_interval(found), lock); 190 ldlm_interval_attach(to_ldlm_interval(found), lock);
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
index b798daa094bc..a4c252febfe4 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
@@ -260,7 +260,8 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
260 int splitted = 0; 260 int splitted = 0;
261 const struct ldlm_callback_suite null_cbs = { NULL }; 261 const struct ldlm_callback_suite null_cbs = { NULL };
262 262
263 CDEBUG(D_DLMTRACE, "flags %#llx owner %llu pid %u mode %u start %llu end %llu\n", 263 CDEBUG(D_DLMTRACE,
264 "flags %#llx owner %llu pid %u mode %u start %llu end %llu\n",
264 *flags, new->l_policy_data.l_flock.owner, 265 *flags, new->l_policy_data.l_flock.owner,
265 new->l_policy_data.l_flock.pid, mode, 266 new->l_policy_data.l_flock.pid, mode,
266 req->l_policy_data.l_flock.start, 267 req->l_policy_data.l_flock.start,
@@ -291,6 +292,7 @@ reprocess:
291 } 292 }
292 } else { 293 } else {
293 int reprocess_failed = 0; 294 int reprocess_failed = 0;
295
294 lockmode_verify(mode); 296 lockmode_verify(mode);
295 297
296 /* This loop determines if there are existing locks 298 /* This loop determines if there are existing locks
@@ -496,7 +498,8 @@ reprocess:
496 new->l_policy_data.l_flock.end + 1; 498 new->l_policy_data.l_flock.end + 1;
497 new2->l_conn_export = lock->l_conn_export; 499 new2->l_conn_export = lock->l_conn_export;
498 if (lock->l_export != NULL) { 500 if (lock->l_export != NULL) {
499 new2->l_export = class_export_lock_get(lock->l_export, new2); 501 new2->l_export = class_export_lock_get(lock->l_export,
502 new2);
500 if (new2->l_export->exp_lock_hash && 503 if (new2->l_export->exp_lock_hash &&
501 hlist_unhashed(&new2->l_exp_hash)) 504 hlist_unhashed(&new2->l_exp_hash))
502 cfs_hash_add(new2->l_export->exp_lock_hash, 505 cfs_hash_add(new2->l_export->exp_lock_hash,
@@ -619,8 +622,7 @@ ldlm_flock_completion_ast(struct ldlm_lock *lock, __u64 flags, void *data)
619 return 0; 622 return 0;
620 } 623 }
621 624
622 LDLM_DEBUG(lock, "client-side enqueue returned a blocked lock, " 625 LDLM_DEBUG(lock, "client-side enqueue returned a blocked lock, sleeping");
623 "sleeping");
624 fwd.fwd_lock = lock; 626 fwd.fwd_lock = lock;
625 obd = class_exp2obd(lock->l_conn_export); 627 obd = class_exp2obd(lock->l_conn_export);
626 628
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h b/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h
index f997566ef11e..6c6c57ca91de 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h
@@ -91,7 +91,8 @@ static inline int ldlm_ns_empty(struct ldlm_namespace *ns)
91} 91}
92 92
93void ldlm_namespace_move_to_active_locked(struct ldlm_namespace *, ldlm_side_t); 93void ldlm_namespace_move_to_active_locked(struct ldlm_namespace *, ldlm_side_t);
94void ldlm_namespace_move_to_inactive_locked(struct ldlm_namespace *, ldlm_side_t); 94void ldlm_namespace_move_to_inactive_locked(struct ldlm_namespace *,
95 ldlm_side_t);
95struct ldlm_namespace *ldlm_namespace_first_locked(ldlm_side_t); 96struct ldlm_namespace *ldlm_namespace_first_locked(ldlm_side_t);
96 97
97/* ldlm_request.c */ 98/* ldlm_request.c */
@@ -214,6 +215,7 @@ static inline struct ldlm_extent *
214ldlm_interval_extent(struct ldlm_interval *node) 215ldlm_interval_extent(struct ldlm_interval *node)
215{ 216{
216 struct ldlm_lock *lock; 217 struct ldlm_lock *lock;
218
217 LASSERT(!list_empty(&node->li_group)); 219 LASSERT(!list_empty(&node->li_group));
218 220
219 lock = list_entry(node->li_group.next, struct ldlm_lock, 221 lock = list_entry(node->li_group.next, struct ldlm_lock,
@@ -244,7 +246,7 @@ typedef enum ldlm_policy_res ldlm_policy_res_t;
244 \ 246 \
245 return lprocfs_rd_uint(m, &tmp); \ 247 return lprocfs_rd_uint(m, &tmp); \
246 } \ 248 } \
247 struct __##var##__dummy_read {;} /* semicolon catcher */ 249 struct __##var##__dummy_read {; } /* semicolon catcher */
248 250
249#define LDLM_POOL_PROC_WRITER(var, type) \ 251#define LDLM_POOL_PROC_WRITER(var, type) \
250 static int lprocfs_wr_##var(struct file *file, const char *buffer, \ 252 static int lprocfs_wr_##var(struct file *file, const char *buffer, \
@@ -266,7 +268,7 @@ typedef enum ldlm_policy_res ldlm_policy_res_t;
266 \ 268 \
267 return rc; \ 269 return rc; \
268 } \ 270 } \
269 struct __##var##__dummy_write {;} /* semicolon catcher */ 271 struct __##var##__dummy_write {; } /* semicolon catcher */
270 272
271static inline int is_granted_or_cancelled(struct ldlm_lock *lock) 273static inline int is_granted_or_cancelled(struct ldlm_lock *lock)
272{ 274{
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c
index c21e30a074b9..c5c86e73ca52 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lib.c
@@ -603,7 +603,8 @@ int client_disconnect_export(struct obd_export *exp)
603 /* obd_force == local only */ 603 /* obd_force == local only */
604 ldlm_cli_cancel_unused(obd->obd_namespace, NULL, 604 ldlm_cli_cancel_unused(obd->obd_namespace, NULL,
605 obd->obd_force ? LCF_LOCAL : 0, NULL); 605 obd->obd_force ? LCF_LOCAL : 0, NULL);
606 ldlm_namespace_free_prior(obd->obd_namespace, imp, obd->obd_force); 606 ldlm_namespace_free_prior(obd->obd_namespace, imp,
607 obd->obd_force);
607 } 608 }
608 609
609 /* There's no need to hold sem while disconnecting an import, 610 /* There's no need to hold sem while disconnecting an import,
@@ -858,8 +859,8 @@ void ldlm_dump_export_locks(struct obd_export *exp)
858 if (!list_empty(&exp->exp_locks_list)) { 859 if (!list_empty(&exp->exp_locks_list)) {
859 struct ldlm_lock *lock; 860 struct ldlm_lock *lock;
860 861
861 CERROR("dumping locks for export %p," 862 CERROR("dumping locks for export %p,ignore if the unmount doesn't hang\n",
862 "ignore if the unmount doesn't hang\n", exp); 863 exp);
863 list_for_each_entry(lock, &exp->exp_locks_list, 864 list_for_each_entry(lock, &exp->exp_locks_list,
864 l_exp_refs_link) 865 l_exp_refs_link)
865 LDLM_ERROR(lock, "lock:"); 866 LDLM_ERROR(lock, "lock:");
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
index 6140130b6056..8191005464b1 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
@@ -226,6 +226,7 @@ EXPORT_SYMBOL(ldlm_lock_put);
226int ldlm_lock_remove_from_lru_nolock(struct ldlm_lock *lock) 226int ldlm_lock_remove_from_lru_nolock(struct ldlm_lock *lock)
227{ 227{
228 int rc = 0; 228 int rc = 0;
229
229 if (!list_empty(&lock->l_lru)) { 230 if (!list_empty(&lock->l_lru)) {
230 struct ldlm_namespace *ns = ldlm_lock_to_ns(lock); 231 struct ldlm_namespace *ns = ldlm_lock_to_ns(lock);
231 232
@@ -575,7 +576,7 @@ struct ldlm_lock *__ldlm_handle2lock(const struct lustre_handle *handle,
575 576
576 /* It's unlikely but possible that someone marked the lock as 577 /* It's unlikely but possible that someone marked the lock as
577 * destroyed after we did handle2object on it */ 578 * destroyed after we did handle2object on it */
578 if (flags == 0 && ((lock->l_flags & LDLM_FL_DESTROYED)== 0)) { 579 if (flags == 0 && ((lock->l_flags & LDLM_FL_DESTROYED) == 0)) {
579 lu_ref_add(&lock->l_reference, "handle", current); 580 lu_ref_add(&lock->l_reference, "handle", current);
580 return lock; 581 return lock;
581 } 582 }
@@ -811,8 +812,7 @@ void ldlm_lock_decref_internal(struct ldlm_lock *lock, __u32 mode)
811 /* If we received a blocked AST and this was the last reference, 812 /* If we received a blocked AST and this was the last reference,
812 * run the callback. */ 813 * run the callback. */
813 if ((lock->l_flags & LDLM_FL_NS_SRV) && lock->l_export) 814 if ((lock->l_flags & LDLM_FL_NS_SRV) && lock->l_export)
814 CERROR("FL_CBPENDING set on non-local lock--just a " 815 CERROR("FL_CBPENDING set on non-local lock--just a warning\n");
815 "warning\n");
816 816
817 LDLM_DEBUG(lock, "final decref done on cbpending lock"); 817 LDLM_DEBUG(lock, "final decref done on cbpending lock");
818 818
@@ -859,6 +859,7 @@ void ldlm_lock_decref_internal(struct ldlm_lock *lock, __u32 mode)
859void ldlm_lock_decref(struct lustre_handle *lockh, __u32 mode) 859void ldlm_lock_decref(struct lustre_handle *lockh, __u32 mode)
860{ 860{
861 struct ldlm_lock *lock = __ldlm_handle2lock(lockh, 0); 861 struct ldlm_lock *lock = __ldlm_handle2lock(lockh, 0);
862
862 LASSERTF(lock != NULL, "Non-existing lock: %#llx\n", lockh->cookie); 863 LASSERTF(lock != NULL, "Non-existing lock: %#llx\n", lockh->cookie);
863 ldlm_lock_decref_internal(lock, mode); 864 ldlm_lock_decref_internal(lock, mode);
864 LDLM_LOCK_PUT(lock); 865 LDLM_LOCK_PUT(lock);
@@ -981,7 +982,6 @@ static void search_granted_lock(struct list_head *queue,
981 prev->res_link = queue->prev; 982 prev->res_link = queue->prev;
982 prev->mode_link = &req->l_sl_mode; 983 prev->mode_link = &req->l_sl_mode;
983 prev->policy_link = &req->l_sl_policy; 984 prev->policy_link = &req->l_sl_policy;
984 return;
985} 985}
986 986
987/** 987/**
@@ -1287,6 +1287,7 @@ ldlm_mode_t ldlm_lock_match(struct ldlm_namespace *ns, __u64 flags,
1287 __u64 wait_flags = LDLM_FL_LVB_READY | 1287 __u64 wait_flags = LDLM_FL_LVB_READY |
1288 LDLM_FL_DESTROYED | LDLM_FL_FAIL_NOTIFIED; 1288 LDLM_FL_DESTROYED | LDLM_FL_FAIL_NOTIFIED;
1289 struct l_wait_info lwi; 1289 struct l_wait_info lwi;
1290
1290 if (lock->l_completion_ast) { 1291 if (lock->l_completion_ast) {
1291 int err = lock->l_completion_ast(lock, 1292 int err = lock->l_completion_ast(lock,
1292 LDLM_FL_WAIT_NOREPROC, 1293 LDLM_FL_WAIT_NOREPROC,
@@ -1340,9 +1341,10 @@ ldlm_mode_t ldlm_lock_match(struct ldlm_namespace *ns, __u64 flags,
1340 1341
1341 } else if (!(flags & LDLM_FL_TEST_LOCK)) {/*less verbose for test-only*/ 1342 } else if (!(flags & LDLM_FL_TEST_LOCK)) {/*less verbose for test-only*/
1342 LDLM_DEBUG_NOLOCK("not matched ns %p type %u mode %u res %llu/%llu (%llu %llu)", 1343 LDLM_DEBUG_NOLOCK("not matched ns %p type %u mode %u res %llu/%llu (%llu %llu)",
1343 ns, type, mode, res_id->name[0], res_id->name[1], 1344 ns, type, mode, res_id->name[0],
1345 res_id->name[1],
1344 (type == LDLM_PLAIN || type == LDLM_IBITS) ? 1346 (type == LDLM_PLAIN || type == LDLM_IBITS) ?
1345 res_id->name[2] :policy->l_extent.start, 1347 res_id->name[2] : policy->l_extent.start,
1346 (type == LDLM_PLAIN || type == LDLM_IBITS) ? 1348 (type == LDLM_PLAIN || type == LDLM_IBITS) ?
1347 res_id->name[3] : policy->l_extent.end); 1349 res_id->name[3] : policy->l_extent.end);
1348 } 1350 }
@@ -1453,7 +1455,8 @@ int ldlm_fill_lvb(struct ldlm_lock *lock, struct req_capsule *pill,
1453 1455
1454 memcpy(data, lvb, size); 1456 memcpy(data, lvb, size);
1455 } else { 1457 } else {
1456 LDLM_ERROR(lock, "Replied unexpected lquota LVB size %d", 1458 LDLM_ERROR(lock,
1459 "Replied unexpected lquota LVB size %d",
1457 size); 1460 size);
1458 return -EINVAL; 1461 return -EINVAL;
1459 } 1462 }
@@ -1641,8 +1644,7 @@ ldlm_error_t ldlm_lock_enqueue(struct ldlm_namespace *ns,
1641 ldlm_grant_lock(lock, NULL); 1644 ldlm_grant_lock(lock, NULL);
1642 goto out; 1645 goto out;
1643 } else { 1646 } else {
1644 CERROR("This is client-side-only module, cannot handle " 1647 CERROR("This is client-side-only module, cannot handle LDLM_NAMESPACE_SERVER resource type lock.\n");
1645 "LDLM_NAMESPACE_SERVER resource type lock.\n");
1646 LBUG(); 1648 LBUG();
1647 } 1649 }
1648 1650
@@ -1820,24 +1822,24 @@ int ldlm_run_ast_work(struct ldlm_namespace *ns, struct list_head *rpc_list,
1820 arg->list = rpc_list; 1822 arg->list = rpc_list;
1821 1823
1822 switch (ast_type) { 1824 switch (ast_type) {
1823 case LDLM_WORK_BL_AST: 1825 case LDLM_WORK_BL_AST:
1824 arg->type = LDLM_BL_CALLBACK; 1826 arg->type = LDLM_BL_CALLBACK;
1825 work_ast_lock = ldlm_work_bl_ast_lock; 1827 work_ast_lock = ldlm_work_bl_ast_lock;
1826 break; 1828 break;
1827 case LDLM_WORK_CP_AST: 1829 case LDLM_WORK_CP_AST:
1828 arg->type = LDLM_CP_CALLBACK; 1830 arg->type = LDLM_CP_CALLBACK;
1829 work_ast_lock = ldlm_work_cp_ast_lock; 1831 work_ast_lock = ldlm_work_cp_ast_lock;
1830 break; 1832 break;
1831 case LDLM_WORK_REVOKE_AST: 1833 case LDLM_WORK_REVOKE_AST:
1832 arg->type = LDLM_BL_CALLBACK; 1834 arg->type = LDLM_BL_CALLBACK;
1833 work_ast_lock = ldlm_work_revoke_ast_lock; 1835 work_ast_lock = ldlm_work_revoke_ast_lock;
1834 break; 1836 break;
1835 case LDLM_WORK_GL_AST: 1837 case LDLM_WORK_GL_AST:
1836 arg->type = LDLM_GL_CALLBACK; 1838 arg->type = LDLM_GL_CALLBACK;
1837 work_ast_lock = ldlm_work_gl_ast_lock; 1839 work_ast_lock = ldlm_work_gl_ast_lock;
1838 break; 1840 break;
1839 default: 1841 default:
1840 LBUG(); 1842 LBUG();
1841 } 1843 }
1842 1844
1843 /* We create a ptlrpc request set with flow control extension. 1845 /* We create a ptlrpc request set with flow control extension.
@@ -1904,8 +1906,7 @@ void ldlm_reprocess_all(struct ldlm_resource *res)
1904 LIST_HEAD(rpc_list); 1906 LIST_HEAD(rpc_list);
1905 1907
1906 if (!ns_is_client(ldlm_res_to_ns(res))) { 1908 if (!ns_is_client(ldlm_res_to_ns(res))) {
1907 CERROR("This is client-side-only module, cannot handle " 1909 CERROR("This is client-side-only module, cannot handle LDLM_NAMESPACE_SERVER resource type lock.\n");
1908 "LDLM_NAMESPACE_SERVER resource type lock.\n");
1909 LBUG(); 1910 LBUG();
1910 } 1911 }
1911} 1912}
@@ -2038,8 +2039,7 @@ int ldlm_cancel_locks_for_export_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd,
2038 ecl->ecl_loop++; 2039 ecl->ecl_loop++;
2039 if ((ecl->ecl_loop & -ecl->ecl_loop) == ecl->ecl_loop) { 2040 if ((ecl->ecl_loop & -ecl->ecl_loop) == ecl->ecl_loop) {
2040 CDEBUG(D_INFO, 2041 CDEBUG(D_INFO,
2041 "Cancel lock %p for export %p (loop %d), still have " 2042 "Cancel lock %p for export %p (loop %d), still have %d locks left on hash table.\n",
2042 "%d locks left on hash table.\n",
2043 lock, exp, ecl->ecl_loop, 2043 lock, exp, ecl->ecl_loop,
2044 atomic_read(&hs->hs_count)); 2044 atomic_read(&hs->hs_count));
2045 } 2045 }
@@ -2169,8 +2169,7 @@ struct ldlm_resource *ldlm_lock_convert(struct ldlm_lock *lock, int new_mode,
2169 lock->l_completion_ast(lock, 0, NULL); 2169 lock->l_completion_ast(lock, 0, NULL);
2170 } 2170 }
2171 } else { 2171 } else {
2172 CERROR("This is client-side-only module, cannot handle " 2172 CERROR("This is client-side-only module, cannot handle LDLM_NAMESPACE_SERVER resource type lock.\n");
2173 "LDLM_NAMESPACE_SERVER resource type lock.\n");
2174 LBUG(); 2173 LBUG();
2175 } 2174 }
2176 unlock_res_and_lock(lock); 2175 unlock_res_and_lock(lock);
@@ -2224,23 +2223,21 @@ void _ldlm_lock_debug(struct ldlm_lock *lock,
2224 nid = libcfs_nid2str(exp->exp_connection->c_peer.nid); 2223 nid = libcfs_nid2str(exp->exp_connection->c_peer.nid);
2225 } else if (exp && exp->exp_obd != NULL) { 2224 } else if (exp && exp->exp_obd != NULL) {
2226 struct obd_import *imp = exp->exp_obd->u.cli.cl_import; 2225 struct obd_import *imp = exp->exp_obd->u.cli.cl_import;
2226
2227 nid = libcfs_nid2str(imp->imp_connection->c_peer.nid); 2227 nid = libcfs_nid2str(imp->imp_connection->c_peer.nid);
2228 } 2228 }
2229 2229
2230 if (resource == NULL) { 2230 if (resource == NULL) {
2231 libcfs_debug_vmsg2(msgdata, fmt, args, 2231 libcfs_debug_vmsg2(msgdata, fmt, args,
2232 " ns: \?\? lock: %p/%#llx lrc: %d/%d,%d mode: %s/%s " 2232 " ns: \?\? lock: %p/%#llx lrc: %d/%d,%d mode: %s/%s res: \?\? rrc=\?\? type: \?\?\? flags: %#llx nid: %s remote: %#llx expref: %d pid: %u timeout: %lu lvb_type: %d\n",
2233 "res: \?\? rrc=\?\? type: \?\?\? flags: %#llx nid: %s " 2233 lock,
2234 "remote: %#llx expref: %d pid: %u timeout: %lu " 2234 lock->l_handle.h_cookie, atomic_read(&lock->l_refc),
2235 "lvb_type: %d\n", 2235 lock->l_readers, lock->l_writers,
2236 lock, 2236 ldlm_lockname[lock->l_granted_mode],
2237 lock->l_handle.h_cookie, atomic_read(&lock->l_refc), 2237 ldlm_lockname[lock->l_req_mode],
2238 lock->l_readers, lock->l_writers, 2238 lock->l_flags, nid, lock->l_remote_handle.cookie,
2239 ldlm_lockname[lock->l_granted_mode], 2239 exp ? atomic_read(&exp->exp_refcount) : -99,
2240 ldlm_lockname[lock->l_req_mode], 2240 lock->l_pid, lock->l_callback_timeout, lock->l_lvb_type);
2241 lock->l_flags, nid, lock->l_remote_handle.cookie,
2242 exp ? atomic_read(&exp->exp_refcount) : -99,
2243 lock->l_pid, lock->l_callback_timeout, lock->l_lvb_type);
2244 va_end(args); 2241 va_end(args);
2245 return; 2242 return;
2246 } 2243 }
@@ -2248,90 +2245,78 @@ void _ldlm_lock_debug(struct ldlm_lock *lock,
2248 switch (resource->lr_type) { 2245 switch (resource->lr_type) {
2249 case LDLM_EXTENT: 2246 case LDLM_EXTENT:
2250 libcfs_debug_vmsg2(msgdata, fmt, args, 2247 libcfs_debug_vmsg2(msgdata, fmt, args,
2251 " ns: %s lock: %p/%#llx lrc: %d/%d,%d mode: %s/%s " 2248 " ns: %s lock: %p/%#llx lrc: %d/%d,%d mode: %s/%s res: " DLDLMRES " rrc: %d type: %s [%llu->%llu] (req %llu->%llu) flags: %#llx nid: %s remote: %#llx expref: %d pid: %u timeout: %lu lvb_type: %d\n",
2252 "res: "DLDLMRES" rrc: %d type: %s [%llu->%llu] " 2249 ldlm_lock_to_ns_name(lock), lock,
2253 "(req %llu->%llu) flags: %#llx nid: %s remote: " 2250 lock->l_handle.h_cookie, atomic_read(&lock->l_refc),
2254 "%#llx expref: %d pid: %u timeout: %lu lvb_type: %d\n", 2251 lock->l_readers, lock->l_writers,
2255 ldlm_lock_to_ns_name(lock), lock, 2252 ldlm_lockname[lock->l_granted_mode],
2256 lock->l_handle.h_cookie, atomic_read(&lock->l_refc), 2253 ldlm_lockname[lock->l_req_mode],
2257 lock->l_readers, lock->l_writers, 2254 PLDLMRES(resource),
2258 ldlm_lockname[lock->l_granted_mode], 2255 atomic_read(&resource->lr_refcount),
2259 ldlm_lockname[lock->l_req_mode], 2256 ldlm_typename[resource->lr_type],
2260 PLDLMRES(resource), 2257 lock->l_policy_data.l_extent.start,
2261 atomic_read(&resource->lr_refcount), 2258 lock->l_policy_data.l_extent.end,
2262 ldlm_typename[resource->lr_type], 2259 lock->l_req_extent.start, lock->l_req_extent.end,
2263 lock->l_policy_data.l_extent.start, 2260 lock->l_flags, nid, lock->l_remote_handle.cookie,
2264 lock->l_policy_data.l_extent.end, 2261 exp ? atomic_read(&exp->exp_refcount) : -99,
2265 lock->l_req_extent.start, lock->l_req_extent.end, 2262 lock->l_pid, lock->l_callback_timeout,
2266 lock->l_flags, nid, lock->l_remote_handle.cookie, 2263 lock->l_lvb_type);
2267 exp ? atomic_read(&exp->exp_refcount) : -99,
2268 lock->l_pid, lock->l_callback_timeout,
2269 lock->l_lvb_type);
2270 break; 2264 break;
2271 2265
2272 case LDLM_FLOCK: 2266 case LDLM_FLOCK:
2273 libcfs_debug_vmsg2(msgdata, fmt, args, 2267 libcfs_debug_vmsg2(msgdata, fmt, args,
2274 " ns: %s lock: %p/%#llx lrc: %d/%d,%d mode: %s/%s " 2268 " ns: %s lock: %p/%#llx lrc: %d/%d,%d mode: %s/%s res: " DLDLMRES " rrc: %d type: %s pid: %d [%llu->%llu] flags: %#llx nid: %s remote: %#llx expref: %d pid: %u timeout: %lu\n",
2275 "res: "DLDLMRES" rrc: %d type: %s pid: %d " 2269 ldlm_lock_to_ns_name(lock), lock,
2276 "[%llu->%llu] flags: %#llx nid: %s " 2270 lock->l_handle.h_cookie, atomic_read(&lock->l_refc),
2277 "remote: %#llx expref: %d pid: %u timeout: %lu\n", 2271 lock->l_readers, lock->l_writers,
2278 ldlm_lock_to_ns_name(lock), lock, 2272 ldlm_lockname[lock->l_granted_mode],
2279 lock->l_handle.h_cookie, atomic_read(&lock->l_refc), 2273 ldlm_lockname[lock->l_req_mode],
2280 lock->l_readers, lock->l_writers, 2274 PLDLMRES(resource),
2281 ldlm_lockname[lock->l_granted_mode], 2275 atomic_read(&resource->lr_refcount),
2282 ldlm_lockname[lock->l_req_mode], 2276 ldlm_typename[resource->lr_type],
2283 PLDLMRES(resource), 2277 lock->l_policy_data.l_flock.pid,
2284 atomic_read(&resource->lr_refcount), 2278 lock->l_policy_data.l_flock.start,
2285 ldlm_typename[resource->lr_type], 2279 lock->l_policy_data.l_flock.end,
2286 lock->l_policy_data.l_flock.pid, 2280 lock->l_flags, nid, lock->l_remote_handle.cookie,
2287 lock->l_policy_data.l_flock.start, 2281 exp ? atomic_read(&exp->exp_refcount) : -99,
2288 lock->l_policy_data.l_flock.end, 2282 lock->l_pid, lock->l_callback_timeout);
2289 lock->l_flags, nid, lock->l_remote_handle.cookie,
2290 exp ? atomic_read(&exp->exp_refcount) : -99,
2291 lock->l_pid, lock->l_callback_timeout);
2292 break; 2283 break;
2293 2284
2294 case LDLM_IBITS: 2285 case LDLM_IBITS:
2295 libcfs_debug_vmsg2(msgdata, fmt, args, 2286 libcfs_debug_vmsg2(msgdata, fmt, args,
2296 " ns: %s lock: %p/%#llx lrc: %d/%d,%d mode: %s/%s " 2287 " ns: %s lock: %p/%#llx lrc: %d/%d,%d mode: %s/%s res: " DLDLMRES " bits %#llx rrc: %d type: %s flags: %#llx nid: %s remote: %#llx expref: %d pid: %u timeout: %lu lvb_type: %d\n",
2297 "res: "DLDLMRES" bits %#llx rrc: %d type: %s " 2288 ldlm_lock_to_ns_name(lock),
2298 "flags: %#llx nid: %s remote: %#llx expref: %d " 2289 lock, lock->l_handle.h_cookie,
2299 "pid: %u timeout: %lu lvb_type: %d\n", 2290 atomic_read(&lock->l_refc),
2300 ldlm_lock_to_ns_name(lock), 2291 lock->l_readers, lock->l_writers,
2301 lock, lock->l_handle.h_cookie, 2292 ldlm_lockname[lock->l_granted_mode],
2302 atomic_read(&lock->l_refc), 2293 ldlm_lockname[lock->l_req_mode],
2303 lock->l_readers, lock->l_writers, 2294 PLDLMRES(resource),
2304 ldlm_lockname[lock->l_granted_mode], 2295 lock->l_policy_data.l_inodebits.bits,
2305 ldlm_lockname[lock->l_req_mode], 2296 atomic_read(&resource->lr_refcount),
2306 PLDLMRES(resource), 2297 ldlm_typename[resource->lr_type],
2307 lock->l_policy_data.l_inodebits.bits, 2298 lock->l_flags, nid, lock->l_remote_handle.cookie,
2308 atomic_read(&resource->lr_refcount), 2299 exp ? atomic_read(&exp->exp_refcount) : -99,
2309 ldlm_typename[resource->lr_type], 2300 lock->l_pid, lock->l_callback_timeout,
2310 lock->l_flags, nid, lock->l_remote_handle.cookie, 2301 lock->l_lvb_type);
2311 exp ? atomic_read(&exp->exp_refcount) : -99,
2312 lock->l_pid, lock->l_callback_timeout,
2313 lock->l_lvb_type);
2314 break; 2302 break;
2315 2303
2316 default: 2304 default:
2317 libcfs_debug_vmsg2(msgdata, fmt, args, 2305 libcfs_debug_vmsg2(msgdata, fmt, args,
2318 " ns: %s lock: %p/%#llx lrc: %d/%d,%d mode: %s/%s " 2306 " ns: %s lock: %p/%#llx lrc: %d/%d,%d mode: %s/%s res: " DLDLMRES " rrc: %d type: %s flags: %#llx nid: %s remote: %#llx expref: %d pid: %u timeout: %lu lvb_type: %d\n",
2319 "res: "DLDLMRES" rrc: %d type: %s flags: %#llx " 2307 ldlm_lock_to_ns_name(lock),
2320 "nid: %s remote: %#llx expref: %d pid: %u " 2308 lock, lock->l_handle.h_cookie,
2321 "timeout: %lu lvb_type: %d\n", 2309 atomic_read(&lock->l_refc),
2322 ldlm_lock_to_ns_name(lock), 2310 lock->l_readers, lock->l_writers,
2323 lock, lock->l_handle.h_cookie, 2311 ldlm_lockname[lock->l_granted_mode],
2324 atomic_read(&lock->l_refc), 2312 ldlm_lockname[lock->l_req_mode],
2325 lock->l_readers, lock->l_writers, 2313 PLDLMRES(resource),
2326 ldlm_lockname[lock->l_granted_mode], 2314 atomic_read(&resource->lr_refcount),
2327 ldlm_lockname[lock->l_req_mode], 2315 ldlm_typename[resource->lr_type],
2328 PLDLMRES(resource), 2316 lock->l_flags, nid, lock->l_remote_handle.cookie,
2329 atomic_read(&resource->lr_refcount), 2317 exp ? atomic_read(&exp->exp_refcount) : -99,
2330 ldlm_typename[resource->lr_type], 2318 lock->l_pid, lock->l_callback_timeout,
2331 lock->l_flags, nid, lock->l_remote_handle.cookie, 2319 lock->l_lvb_type);
2332 exp ? atomic_read(&exp->exp_refcount) : -99,
2333 lock->l_pid, lock->l_callback_timeout,
2334 lock->l_lvb_type);
2335 break; 2320 break;
2336 } 2321 }
2337 va_end(args); 2322 va_end(args);
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
index 91cf7ebae114..98fbd3f7e751 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
@@ -158,13 +158,15 @@ void ldlm_handle_bl_callback(struct ldlm_namespace *ns,
158 unlock_res_and_lock(lock); 158 unlock_res_and_lock(lock);
159 159
160 if (do_ast) { 160 if (do_ast) {
161 CDEBUG(D_DLMTRACE, "Lock %p already unused, calling callback (%p)\n", 161 CDEBUG(D_DLMTRACE,
162 lock, lock->l_blocking_ast); 162 "Lock %p already unused, calling callback (%p)\n", lock,
163 lock->l_blocking_ast);
163 if (lock->l_blocking_ast != NULL) 164 if (lock->l_blocking_ast != NULL)
164 lock->l_blocking_ast(lock, ld, lock->l_ast_data, 165 lock->l_blocking_ast(lock, ld, lock->l_ast_data,
165 LDLM_CB_BLOCKING); 166 LDLM_CB_BLOCKING);
166 } else { 167 } else {
167 CDEBUG(D_DLMTRACE, "Lock %p is referenced, will be cancelled later\n", 168 CDEBUG(D_DLMTRACE,
169 "Lock %p is referenced, will be cancelled later\n",
168 lock); 170 lock);
169 } 171 }
170 172
@@ -190,6 +192,7 @@ static void ldlm_handle_cp_callback(struct ptlrpc_request *req,
190 192
191 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL_BL_CB_RACE)) { 193 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CANCEL_BL_CB_RACE)) {
192 int to = cfs_time_seconds(1); 194 int to = cfs_time_seconds(1);
195
193 while (to > 0) { 196 while (to > 0) {
194 set_current_state(TASK_INTERRUPTIBLE); 197 set_current_state(TASK_INTERRUPTIBLE);
195 schedule_timeout(to); 198 schedule_timeout(to);
@@ -210,9 +213,7 @@ static void ldlm_handle_cp_callback(struct ptlrpc_request *req,
210 LASSERT(lock->l_lvb_data != NULL); 213 LASSERT(lock->l_lvb_data != NULL);
211 214
212 if (unlikely(lock->l_lvb_len < lvb_len)) { 215 if (unlikely(lock->l_lvb_len < lvb_len)) {
213 LDLM_ERROR(lock, "Replied LVB is larger than " 216 LDLM_ERROR(lock, "Replied LVB is larger than expectation, expected = %d, replied = %d",
214 "expectation, expected = %d, "
215 "replied = %d",
216 lock->l_lvb_len, lvb_len); 217 lock->l_lvb_len, lvb_len);
217 rc = -EINVAL; 218 rc = -EINVAL;
218 goto out; 219 goto out;
@@ -639,8 +640,8 @@ static int ldlm_callback_handler(struct ptlrpc_request *req)
639 640
640 lock = ldlm_handle2lock_long(&dlm_req->lock_handle[0], 0); 641 lock = ldlm_handle2lock_long(&dlm_req->lock_handle[0], 0);
641 if (!lock) { 642 if (!lock) {
642 CDEBUG(D_DLMTRACE, "callback on lock %#llx - lock " 643 CDEBUG(D_DLMTRACE, "callback on lock %#llx - lock disappeared\n",
643 "disappeared\n", dlm_req->lock_handle[0].cookie); 644 dlm_req->lock_handle[0].cookie);
644 rc = ldlm_callback_reply(req, -EINVAL); 645 rc = ldlm_callback_reply(req, -EINVAL);
645 ldlm_callback_errmsg(req, "Operate with invalid parameter", rc, 646 ldlm_callback_errmsg(req, "Operate with invalid parameter", rc,
646 &dlm_req->lock_handle[0]); 647 &dlm_req->lock_handle[0]);
@@ -663,8 +664,7 @@ static int ldlm_callback_handler(struct ptlrpc_request *req)
663 if (((lock->l_flags & LDLM_FL_CANCELING) && 664 if (((lock->l_flags & LDLM_FL_CANCELING) &&
664 (lock->l_flags & LDLM_FL_BL_DONE)) || 665 (lock->l_flags & LDLM_FL_BL_DONE)) ||
665 (lock->l_flags & LDLM_FL_FAILED)) { 666 (lock->l_flags & LDLM_FL_FAILED)) {
666 LDLM_DEBUG(lock, "callback on lock " 667 LDLM_DEBUG(lock, "callback on lock %#llx - lock disappeared\n",
667 "%#llx - lock disappeared\n",
668 dlm_req->lock_handle[0].cookie); 668 dlm_req->lock_handle[0].cookie);
669 unlock_res_and_lock(lock); 669 unlock_res_and_lock(lock);
670 LDLM_LOCK_RELEASE(lock); 670 LDLM_LOCK_RELEASE(lock);
@@ -724,7 +724,7 @@ static int ldlm_callback_handler(struct ptlrpc_request *req)
724static struct ldlm_bl_work_item *ldlm_bl_get_work(struct ldlm_bl_pool *blp) 724static struct ldlm_bl_work_item *ldlm_bl_get_work(struct ldlm_bl_pool *blp)
725{ 725{
726 struct ldlm_bl_work_item *blwi = NULL; 726 struct ldlm_bl_work_item *blwi = NULL;
727 static unsigned int num_bl = 0; 727 static unsigned int num_bl;
728 728
729 spin_lock(&blp->blp_lock); 729 spin_lock(&blp->blp_lock);
730 /* process a request from the blp_list at least every blp_num_threads */ 730 /* process a request from the blp_list at least every blp_num_threads */
@@ -887,6 +887,7 @@ void ldlm_put_ref(void)
887 mutex_lock(&ldlm_ref_mutex); 887 mutex_lock(&ldlm_ref_mutex);
888 if (ldlm_refcount == 1) { 888 if (ldlm_refcount == 1) {
889 int rc = ldlm_cleanup(); 889 int rc = ldlm_cleanup();
890
890 if (rc) 891 if (rc)
891 CERROR("ldlm_cleanup failed: %d\n", rc); 892 CERROR("ldlm_cleanup failed: %d\n", rc);
892 else 893 else
@@ -969,6 +970,7 @@ static cfs_hash_ops_t ldlm_export_lock_ops = {
969int ldlm_init_export(struct obd_export *exp) 970int ldlm_init_export(struct obd_export *exp)
970{ 971{
971 int rc; 972 int rc;
973
972 exp->exp_lock_hash = 974 exp->exp_lock_hash =
973 cfs_hash_create(obd_uuid2str(&exp->exp_client_uuid), 975 cfs_hash_create(obd_uuid2str(&exp->exp_client_uuid),
974 HASH_EXP_LOCK_CUR_BITS, 976 HASH_EXP_LOCK_CUR_BITS,
@@ -1049,7 +1051,7 @@ static int ldlm_setup(void)
1049 .so_req_handler = ldlm_callback_handler, 1051 .so_req_handler = ldlm_callback_handler,
1050 }, 1052 },
1051 }; 1053 };
1052 ldlm_state->ldlm_cb_service = \ 1054 ldlm_state->ldlm_cb_service =
1053 ptlrpc_register_service(&conf, ldlm_svc_proc_dir); 1055 ptlrpc_register_service(&conf, ldlm_svc_proc_dir);
1054 if (IS_ERR(ldlm_state->ldlm_cb_service)) { 1056 if (IS_ERR(ldlm_state->ldlm_cb_service)) {
1055 CERROR("failed to start service\n"); 1057 CERROR("failed to start service\n");
@@ -1077,7 +1079,7 @@ static int ldlm_setup(void)
1077 blp->blp_min_threads = LDLM_NTHRS_INIT; 1079 blp->blp_min_threads = LDLM_NTHRS_INIT;
1078 blp->blp_max_threads = LDLM_NTHRS_MAX; 1080 blp->blp_max_threads = LDLM_NTHRS_MAX;
1079 } else { 1081 } else {
1080 blp->blp_min_threads = blp->blp_max_threads = \ 1082 blp->blp_min_threads = blp->blp_max_threads =
1081 min_t(int, LDLM_NTHRS_MAX, max_t(int, LDLM_NTHRS_INIT, 1083 min_t(int, LDLM_NTHRS_MAX, max_t(int, LDLM_NTHRS_INIT,
1082 ldlm_num_threads)); 1084 ldlm_num_threads));
1083 } 1085 }
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
index 6054eee848d3..4c838f615a64 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
@@ -54,10 +54,10 @@
54 * calculated as the number of locks in LRU * lock live time in seconds. If 54 * calculated as the number of locks in LRU * lock live time in seconds. If
55 * CLV > SLV - lock is canceled. 55 * CLV > SLV - lock is canceled.
56 * 56 *
57 * Client has LVF, that is, lock volume factor which regulates how much sensitive 57 * Client has LVF, that is, lock volume factor which regulates how much
58 * client should be about last SLV from server. The higher LVF is the more locks 58 * sensitive client should be about last SLV from server. The higher LVF is the
59 * will be canceled on client. Default value for it is 1. Setting LVF to 2 means 59 * more locks will be canceled on client. Default value for it is 1. Setting LVF
60 * that client will cancel locks 2 times faster. 60 * to 2 means that client will cancel locks 2 times faster.
61 * 61 *
62 * Locks on a client will be canceled more intensively in these cases: 62 * Locks on a client will be canceled more intensively in these cases:
63 * (1) if SLV is smaller, that is, load is higher on the server; 63 * (1) if SLV is smaller, that is, load is higher on the server;
@@ -70,11 +70,12 @@
70 * if flow is getting thinner, more and more particles become outside of it and 70 * if flow is getting thinner, more and more particles become outside of it and
71 * as particles are locks, they should be canceled. 71 * as particles are locks, they should be canceled.
72 * 72 *
73 * General idea of this belongs to Vitaly Fertman (vitaly@clusterfs.com). Andreas 73 * General idea of this belongs to Vitaly Fertman (vitaly@clusterfs.com).
74 * Dilger (adilger@clusterfs.com) proposed few nice ideas like using LVF and many 74 * Andreas Dilger (adilger@clusterfs.com) proposed few nice ideas like using
75 * cleanups. Flow definition to allow more easy understanding of the logic belongs 75 * LVF and many cleanups. Flow definition to allow more easy understanding of
76 * to Nikita Danilov (nikita@clusterfs.com) as well as many cleanups and fixes. 76 * the logic belongs to Nikita Danilov (nikita@clusterfs.com) as well as many
77 * And design and implementation are done by Yury Umanets (umka@clusterfs.com). 77 * cleanups and fixes. And design and implementation are done by Yury Umanets
78 * (umka@clusterfs.com).
78 * 79 *
79 * Glossary for terms used: 80 * Glossary for terms used:
80 * 81 *
@@ -265,16 +266,15 @@ static void ldlm_pool_recalc_slv(struct ldlm_pool *pl)
265 * SLV. And the opposite, the more grant plan is over-consumed 266 * SLV. And the opposite, the more grant plan is over-consumed
266 * (load time) the faster drops SLV. 267 * (load time) the faster drops SLV.
267 */ 268 */
268 slv_factor = (grant_usage << LDLM_POOL_SLV_SHIFT); 269 slv_factor = grant_usage << LDLM_POOL_SLV_SHIFT;
269 do_div(slv_factor, limit); 270 do_div(slv_factor, limit);
270 slv = slv * slv_factor; 271 slv = slv * slv_factor;
271 slv = dru(slv, LDLM_POOL_SLV_SHIFT, round_up); 272 slv = dru(slv, LDLM_POOL_SLV_SHIFT, round_up);
272 273
273 if (slv > ldlm_pool_slv_max(limit)) { 274 if (slv > ldlm_pool_slv_max(limit))
274 slv = ldlm_pool_slv_max(limit); 275 slv = ldlm_pool_slv_max(limit);
275 } else if (slv < ldlm_pool_slv_min(limit)) { 276 else if (slv < ldlm_pool_slv_min(limit))
276 slv = ldlm_pool_slv_min(limit); 277 slv = ldlm_pool_slv_min(limit);
277 }
278 278
279 pl->pl_server_lock_volume = slv; 279 pl->pl_server_lock_volume = slv;
280} 280}
@@ -614,8 +614,8 @@ int ldlm_pool_shrink(struct ldlm_pool *pl, int nr,
614 lprocfs_counter_add(pl->pl_stats, 614 lprocfs_counter_add(pl->pl_stats,
615 LDLM_POOL_SHRINK_FREED_STAT, 615 LDLM_POOL_SHRINK_FREED_STAT,
616 cancel); 616 cancel);
617 CDEBUG(D_DLMTRACE, "%s: request to shrink %d locks, " 617 CDEBUG(D_DLMTRACE, "%s: request to shrink %d locks, shrunk %d\n",
618 "shrunk %d\n", pl->pl_name, nr, cancel); 618 pl->pl_name, nr, cancel);
619 } 619 }
620 } 620 }
621 return cancel; 621 return cancel;
@@ -636,7 +636,7 @@ int ldlm_pool_setup(struct ldlm_pool *pl, int limit)
636} 636}
637EXPORT_SYMBOL(ldlm_pool_setup); 637EXPORT_SYMBOL(ldlm_pool_setup);
638 638
639#if defined (CONFIG_PROC_FS) 639#if defined(CONFIG_PROC_FS)
640static int lprocfs_pool_state_seq_show(struct seq_file *m, void *unused) 640static int lprocfs_pool_state_seq_show(struct seq_file *m, void *unused)
641{ 641{
642 int granted, grant_rate, cancel_rate, grant_step; 642 int granted, grant_rate, cancel_rate, grant_step;
@@ -696,8 +696,9 @@ LPROC_SEQ_FOPS_RO(lprocfs_grant_plan);
696 696
697LDLM_POOL_PROC_READER_SEQ_SHOW(recalc_period, int); 697LDLM_POOL_PROC_READER_SEQ_SHOW(recalc_period, int);
698LDLM_POOL_PROC_WRITER(recalc_period, int); 698LDLM_POOL_PROC_WRITER(recalc_period, int);
699static ssize_t lprocfs_recalc_period_seq_write(struct file *file, const char *buf, 699static ssize_t lprocfs_recalc_period_seq_write(struct file *file,
700 size_t len, loff_t *off) 700 const char *buf, size_t len,
701 loff_t *off)
701{ 702{
702 struct seq_file *seq = file->private_data; 703 struct seq_file *seq = file->private_data;
703 704
@@ -943,6 +944,7 @@ EXPORT_SYMBOL(ldlm_pool_del);
943__u64 ldlm_pool_get_slv(struct ldlm_pool *pl) 944__u64 ldlm_pool_get_slv(struct ldlm_pool *pl)
944{ 945{
945 __u64 slv; 946 __u64 slv;
947
946 spin_lock(&pl->pl_lock); 948 spin_lock(&pl->pl_lock);
947 slv = pl->pl_server_lock_volume; 949 slv = pl->pl_server_lock_volume;
948 spin_unlock(&pl->pl_lock); 950 spin_unlock(&pl->pl_lock);
@@ -971,6 +973,7 @@ EXPORT_SYMBOL(ldlm_pool_set_slv);
971__u64 ldlm_pool_get_clv(struct ldlm_pool *pl) 973__u64 ldlm_pool_get_clv(struct ldlm_pool *pl)
972{ 974{
973 __u64 slv; 975 __u64 slv;
976
974 spin_lock(&pl->pl_lock); 977 spin_lock(&pl->pl_lock);
975 slv = pl->pl_client_lock_volume; 978 slv = pl->pl_client_lock_volume;
976 spin_unlock(&pl->pl_lock); 979 spin_unlock(&pl->pl_lock);
@@ -1132,23 +1135,27 @@ static unsigned long ldlm_pools_scan(ldlm_side_t client, int nr, gfp_t gfp_mask)
1132 return (client == LDLM_NAMESPACE_SERVER) ? SHRINK_STOP : freed; 1135 return (client == LDLM_NAMESPACE_SERVER) ? SHRINK_STOP : freed;
1133} 1136}
1134 1137
1135static unsigned long ldlm_pools_srv_count(struct shrinker *s, struct shrink_control *sc) 1138static unsigned long ldlm_pools_srv_count(struct shrinker *s,
1139 struct shrink_control *sc)
1136{ 1140{
1137 return ldlm_pools_count(LDLM_NAMESPACE_SERVER, sc->gfp_mask); 1141 return ldlm_pools_count(LDLM_NAMESPACE_SERVER, sc->gfp_mask);
1138} 1142}
1139 1143
1140static unsigned long ldlm_pools_srv_scan(struct shrinker *s, struct shrink_control *sc) 1144static unsigned long ldlm_pools_srv_scan(struct shrinker *s,
1145 struct shrink_control *sc)
1141{ 1146{
1142 return ldlm_pools_scan(LDLM_NAMESPACE_SERVER, sc->nr_to_scan, 1147 return ldlm_pools_scan(LDLM_NAMESPACE_SERVER, sc->nr_to_scan,
1143 sc->gfp_mask); 1148 sc->gfp_mask);
1144} 1149}
1145 1150
1146static unsigned long ldlm_pools_cli_count(struct shrinker *s, struct shrink_control *sc) 1151static unsigned long ldlm_pools_cli_count(struct shrinker *s,
1152 struct shrink_control *sc)
1147{ 1153{
1148 return ldlm_pools_count(LDLM_NAMESPACE_CLIENT, sc->gfp_mask); 1154 return ldlm_pools_count(LDLM_NAMESPACE_CLIENT, sc->gfp_mask);
1149} 1155}
1150 1156
1151static unsigned long ldlm_pools_cli_scan(struct shrinker *s, struct shrink_control *sc) 1157static unsigned long ldlm_pools_cli_scan(struct shrinker *s,
1158 struct shrink_control *sc)
1152{ 1159{
1153 return ldlm_pools_scan(LDLM_NAMESPACE_CLIENT, sc->nr_to_scan, 1160 return ldlm_pools_scan(LDLM_NAMESPACE_CLIENT, sc->nr_to_scan,
1154 sc->gfp_mask); 1161 sc->gfp_mask);
@@ -1194,10 +1201,8 @@ int ldlm_pools_recalc(ldlm_side_t client)
1194 * of limit. 1201 * of limit.
1195 */ 1202 */
1196 if (nr_l >= 2 * (LDLM_POOL_HOST_L / 3)) { 1203 if (nr_l >= 2 * (LDLM_POOL_HOST_L / 3)) {
1197 CWARN("\"Modest\" pools eat out 2/3 of server locks " 1204 CWARN("\"Modest\" pools eat out 2/3 of server locks limit (%d of %lu). This means that you have too many clients for this amount of server RAM. Upgrade server!\n",
1198 "limit (%d of %lu). This means that you have too " 1205 nr_l, LDLM_POOL_HOST_L);
1199 "many clients for this amount of server RAM. "
1200 "Upgrade server!\n", nr_l, LDLM_POOL_HOST_L);
1201 equal = 1; 1206 equal = 1;
1202 } 1207 }
1203 1208
@@ -1205,8 +1210,7 @@ int ldlm_pools_recalc(ldlm_side_t client)
1205 * The rest is given to greedy namespaces. 1210 * The rest is given to greedy namespaces.
1206 */ 1211 */
1207 list_for_each_entry(ns, ldlm_namespace_list(client), 1212 list_for_each_entry(ns, ldlm_namespace_list(client),
1208 ns_list_chain) 1213 ns_list_chain) {
1209 {
1210 if (!equal && ns->ns_appetite != LDLM_NAMESPACE_GREEDY) 1214 if (!equal && ns->ns_appetite != LDLM_NAMESPACE_GREEDY)
1211 continue; 1215 continue;
1212 1216
@@ -1383,9 +1387,8 @@ static int ldlm_pools_thread_start(void)
1383 1387
1384static void ldlm_pools_thread_stop(void) 1388static void ldlm_pools_thread_stop(void)
1385{ 1389{
1386 if (ldlm_pools_thread == NULL) { 1390 if (ldlm_pools_thread == NULL)
1387 return; 1391 return;
1388 }
1389 1392
1390 thread_set_flags(ldlm_pools_thread, SVC_STOPPING); 1393 thread_set_flags(ldlm_pools_thread, SVC_STOPPING);
1391 wake_up(&ldlm_pools_thread->t_ctl_waitq); 1394 wake_up(&ldlm_pools_thread->t_ctl_waitq);
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c
index 9ce437b18793..287da325d928 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_request.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_request.c
@@ -95,16 +95,14 @@ int ldlm_expired_completion_wait(void *data)
95 struct obd_device *obd; 95 struct obd_device *obd;
96 96
97 if (lock->l_conn_export == NULL) { 97 if (lock->l_conn_export == NULL) {
98 static unsigned long next_dump = 0, last_dump = 0; 98 static unsigned long next_dump, last_dump;
99 99
100 LCONSOLE_WARN("lock timed out (enqueued at "CFS_TIME_T", " 100 LCONSOLE_WARN("lock timed out (enqueued at "CFS_TIME_T", "
101 CFS_DURATION_T"s ago)\n", 101 CFS_DURATION_T"s ago)\n",
102 lock->l_last_activity, 102 lock->l_last_activity,
103 cfs_time_sub(get_seconds(), 103 cfs_time_sub(get_seconds(),
104 lock->l_last_activity)); 104 lock->l_last_activity));
105 LDLM_DEBUG(lock, "lock timed out (enqueued at "CFS_TIME_T", " 105 LDLM_DEBUG(lock, "lock timed out (enqueued at " CFS_TIME_T ", " CFS_DURATION_T "s ago); not entering recovery in server code, just going back to sleep",
106 CFS_DURATION_T"s ago); not entering recovery in "
107 "server code, just going back to sleep",
108 lock->l_last_activity, 106 lock->l_last_activity,
109 cfs_time_sub(get_seconds(), 107 cfs_time_sub(get_seconds(),
110 lock->l_last_activity)); 108 lock->l_last_activity));
@@ -137,6 +135,7 @@ EXPORT_SYMBOL(ldlm_expired_completion_wait);
137int ldlm_get_enq_timeout(struct ldlm_lock *lock) 135int ldlm_get_enq_timeout(struct ldlm_lock *lock)
138{ 136{
139 int timeout = at_get(ldlm_lock_to_ns_at(lock)); 137 int timeout = at_get(ldlm_lock_to_ns_at(lock));
138
140 if (AT_OFF) 139 if (AT_OFF)
141 return obd_timeout / 2; 140 return obd_timeout / 2;
142 /* Since these are non-updating timeouts, we should be conservative. 141 /* Since these are non-updating timeouts, we should be conservative.
@@ -191,8 +190,7 @@ int ldlm_completion_ast_async(struct ldlm_lock *lock, __u64 flags, void *data)
191 return ldlm_completion_tail(lock); 190 return ldlm_completion_tail(lock);
192 } 191 }
193 192
194 LDLM_DEBUG(lock, "client-side enqueue returned a blocked lock, " 193 LDLM_DEBUG(lock, "client-side enqueue returned a blocked lock, going forward");
195 "going forward");
196 ldlm_reprocess_all(lock->l_resource); 194 ldlm_reprocess_all(lock->l_resource);
197 return 0; 195 return 0;
198} 196}
@@ -240,17 +238,15 @@ int ldlm_completion_ast(struct ldlm_lock *lock, __u64 flags, void *data)
240 return 0; 238 return 0;
241 } 239 }
242 240
243 LDLM_DEBUG(lock, "client-side enqueue returned a blocked lock, " 241 LDLM_DEBUG(lock, "client-side enqueue returned a blocked lock, sleeping");
244 "sleeping");
245 242
246noreproc: 243noreproc:
247 244
248 obd = class_exp2obd(lock->l_conn_export); 245 obd = class_exp2obd(lock->l_conn_export);
249 246
250 /* if this is a local lock, then there is no import */ 247 /* if this is a local lock, then there is no import */
251 if (obd != NULL) { 248 if (obd != NULL)
252 imp = obd->u.cli.cl_import; 249 imp = obd->u.cli.cl_import;
253 }
254 250
255 /* Wait a long time for enqueue - server may have to callback a 251 /* Wait a long time for enqueue - server may have to callback a
256 lock from another client. Server will evict the other client if it 252 lock from another client. Server will evict the other client if it
@@ -324,8 +320,7 @@ int ldlm_blocking_ast_nocheck(struct ldlm_lock *lock)
324 if (rc < 0) 320 if (rc < 0)
325 CERROR("ldlm_cli_cancel: %d\n", rc); 321 CERROR("ldlm_cli_cancel: %d\n", rc);
326 } else { 322 } else {
327 LDLM_DEBUG(lock, "Lock still has references, will be " 323 LDLM_DEBUG(lock, "Lock still has references, will be cancelled later");
328 "cancelled later");
329 } 324 }
330 return 0; 325 return 0;
331} 326}
@@ -483,8 +478,7 @@ static void failed_lock_cleanup(struct ldlm_namespace *ns,
483 478
484 if (need_cancel) 479 if (need_cancel)
485 LDLM_DEBUG(lock, 480 LDLM_DEBUG(lock,
486 "setting FL_LOCAL_ONLY | LDLM_FL_FAILED | " 481 "setting FL_LOCAL_ONLY | LDLM_FL_FAILED | LDLM_FL_ATOMIC_CB | LDLM_FL_CBPENDING");
487 "LDLM_FL_ATOMIC_CB | LDLM_FL_CBPENDING");
488 else 482 else
489 LDLM_DEBUG(lock, "lock was granted or failed in race"); 483 LDLM_DEBUG(lock, "lock was granted or failed in race");
490 484
@@ -557,8 +551,7 @@ int ldlm_cli_enqueue_fini(struct obd_export *exp, struct ptlrpc_request *req,
557 rc = size; 551 rc = size;
558 goto cleanup; 552 goto cleanup;
559 } else if (unlikely(size > lvb_len)) { 553 } else if (unlikely(size > lvb_len)) {
560 LDLM_ERROR(lock, "Replied LVB is larger than " 554 LDLM_ERROR(lock, "Replied LVB is larger than expectation, expected = %d, replied = %d",
561 "expectation, expected = %d, replied = %d",
562 lvb_len, size); 555 lvb_len, size);
563 rc = -EINVAL; 556 rc = -EINVAL;
564 goto cleanup; 557 goto cleanup;
@@ -608,6 +601,7 @@ int ldlm_cli_enqueue_fini(struct obd_export *exp, struct ptlrpc_request *req,
608 * again. */ 601 * again. */
609 if ((*flags) & LDLM_FL_LOCK_CHANGED) { 602 if ((*flags) & LDLM_FL_LOCK_CHANGED) {
610 int newmode = reply->lock_desc.l_req_mode; 603 int newmode = reply->lock_desc.l_req_mode;
604
611 LASSERT(!is_replay); 605 LASSERT(!is_replay);
612 if (newmode && newmode != lock->l_req_mode) { 606 if (newmode && newmode != lock->l_req_mode) {
613 LDLM_DEBUG(lock, "server returned different mode %s", 607 LDLM_DEBUG(lock, "server returned different mode %s",
@@ -676,6 +670,7 @@ int ldlm_cli_enqueue_fini(struct obd_export *exp, struct ptlrpc_request *req,
676 rc = ldlm_lock_enqueue(ns, &lock, NULL, flags); 670 rc = ldlm_lock_enqueue(ns, &lock, NULL, flags);
677 if (lock->l_completion_ast != NULL) { 671 if (lock->l_completion_ast != NULL) {
678 int err = lock->l_completion_ast(lock, *flags, NULL); 672 int err = lock->l_completion_ast(lock, *flags, NULL);
673
679 if (!rc) 674 if (!rc)
680 rc = err; 675 rc = err;
681 if (rc) 676 if (rc)
@@ -725,6 +720,7 @@ static inline int ldlm_capsule_handles_avail(struct req_capsule *pill,
725 int off) 720 int off)
726{ 721{
727 int size = req_capsule_msg_size(pill, loc); 722 int size = req_capsule_msg_size(pill, loc);
723
728 return ldlm_req_handles_avail(size, off); 724 return ldlm_req_handles_avail(size, off);
729} 725}
730 726
@@ -733,6 +729,7 @@ static inline int ldlm_format_handles_avail(struct obd_import *imp,
733 enum req_location loc, int off) 729 enum req_location loc, int off)
734{ 730{
735 int size = req_capsule_fmt_size(imp->imp_msg_magic, fmt, loc); 731 int size = req_capsule_fmt_size(imp->imp_msg_magic, fmt, loc);
732
736 return ldlm_req_handles_avail(size, off); 733 return ldlm_req_handles_avail(size, off);
737} 734}
738 735
@@ -1107,8 +1104,7 @@ static __u64 ldlm_cli_cancel_local(struct ldlm_lock *lock)
1107 unlock_res_and_lock(lock); 1104 unlock_res_and_lock(lock);
1108 1105
1109 if (local_only) { 1106 if (local_only) {
1110 CDEBUG(D_DLMTRACE, "not sending request (at caller's " 1107 CDEBUG(D_DLMTRACE, "not sending request (at caller's instruction)\n");
1111 "instruction)\n");
1112 rc = LDLM_FL_LOCAL_ONLY; 1108 rc = LDLM_FL_LOCAL_ONLY;
1113 } 1109 }
1114 ldlm_lock_cancel(lock); 1110 ldlm_lock_cancel(lock);
@@ -1223,8 +1219,7 @@ int ldlm_cli_cancel_req(struct obd_export *exp, struct list_head *cancels,
1223 rc = ptlrpc_queue_wait(req); 1219 rc = ptlrpc_queue_wait(req);
1224 } 1220 }
1225 if (rc == LUSTRE_ESTALE) { 1221 if (rc == LUSTRE_ESTALE) {
1226 CDEBUG(D_DLMTRACE, "client/server (nid %s) " 1222 CDEBUG(D_DLMTRACE, "client/server (nid %s) out of sync -- not fatal\n",
1227 "out of sync -- not fatal\n",
1228 libcfs_nid2str(req->rq_import-> 1223 libcfs_nid2str(req->rq_import->
1229 imp_connection->c_peer.nid)); 1224 imp_connection->c_peer.nid));
1230 rc = 0; 1225 rc = 0;
@@ -1235,8 +1230,8 @@ int ldlm_cli_cancel_req(struct obd_export *exp, struct list_head *cancels,
1235 } else if (rc != ELDLM_OK) { 1230 } else if (rc != ELDLM_OK) {
1236 /* -ESHUTDOWN is common on umount */ 1231 /* -ESHUTDOWN is common on umount */
1237 CDEBUG_LIMIT(rc == -ESHUTDOWN ? D_DLMTRACE : D_ERROR, 1232 CDEBUG_LIMIT(rc == -ESHUTDOWN ? D_DLMTRACE : D_ERROR,
1238 "Got rc %d from cancel RPC: " 1233 "Got rc %d from cancel RPC: canceling anyway\n",
1239 "canceling anyway\n", rc); 1234 rc);
1240 break; 1235 break;
1241 } 1236 }
1242 sent = count; 1237 sent = count;
@@ -1279,7 +1274,8 @@ int ldlm_cli_update_pool(struct ptlrpc_request *req)
1279 * server-side namespace is not possible. */ 1274 * server-side namespace is not possible. */
1280 if (lustre_msg_get_slv(req->rq_repmsg) == 0 || 1275 if (lustre_msg_get_slv(req->rq_repmsg) == 0 ||
1281 lustre_msg_get_limit(req->rq_repmsg) == 0) { 1276 lustre_msg_get_limit(req->rq_repmsg) == 0) {
1282 DEBUG_REQ(D_HA, req, "Zero SLV or Limit found (SLV: %llu, Limit: %u)", 1277 DEBUG_REQ(D_HA, req,
1278 "Zero SLV or Limit found (SLV: %llu, Limit: %u)",
1283 lustre_msg_get_slv(req->rq_repmsg), 1279 lustre_msg_get_slv(req->rq_repmsg),
1284 lustre_msg_get_limit(req->rq_repmsg)); 1280 lustre_msg_get_limit(req->rq_repmsg));
1285 return 0; 1281 return 0;
@@ -1416,19 +1412,20 @@ static ldlm_policy_res_t ldlm_cancel_no_wait_policy(struct ldlm_namespace *ns,
1416{ 1412{
1417 ldlm_policy_res_t result = LDLM_POLICY_CANCEL_LOCK; 1413 ldlm_policy_res_t result = LDLM_POLICY_CANCEL_LOCK;
1418 ldlm_cancel_for_recovery cb = ns->ns_cancel_for_recovery; 1414 ldlm_cancel_for_recovery cb = ns->ns_cancel_for_recovery;
1415
1419 lock_res_and_lock(lock); 1416 lock_res_and_lock(lock);
1420 1417
1421 /* don't check added & count since we want to process all locks 1418 /* don't check added & count since we want to process all locks
1422 * from unused list */ 1419 * from unused list */
1423 switch (lock->l_resource->lr_type) { 1420 switch (lock->l_resource->lr_type) {
1424 case LDLM_EXTENT: 1421 case LDLM_EXTENT:
1425 case LDLM_IBITS: 1422 case LDLM_IBITS:
1426 if (cb && cb(lock)) 1423 if (cb && cb(lock))
1427 break;
1428 default:
1429 result = LDLM_POLICY_SKIP_LOCK;
1430 lock->l_flags |= LDLM_FL_SKIPPED;
1431 break; 1424 break;
1425 default:
1426 result = LDLM_POLICY_SKIP_LOCK;
1427 lock->l_flags |= LDLM_FL_SKIPPED;
1428 break;
1432 } 1429 }
1433 1430
1434 unlock_res_and_lock(lock); 1431 unlock_res_and_lock(lock);
@@ -1594,8 +1591,9 @@ ldlm_cancel_lru_policy(struct ldlm_namespace *ns, int flags)
1594 * sending any RPCs or waiting for any 1591 * sending any RPCs or waiting for any
1595 * outstanding RPC to complete. 1592 * outstanding RPC to complete.
1596 */ 1593 */
1597static int ldlm_prepare_lru_list(struct ldlm_namespace *ns, struct list_head *cancels, 1594static int ldlm_prepare_lru_list(struct ldlm_namespace *ns,
1598 int count, int max, int flags) 1595 struct list_head *cancels, int count, int max,
1596 int flags)
1599{ 1597{
1600 ldlm_cancel_lru_policy_t pf; 1598 ldlm_cancel_lru_policy_t pf;
1601 struct ldlm_lock *lock, *next; 1599 struct ldlm_lock *lock, *next;
@@ -1730,6 +1728,7 @@ int ldlm_cancel_lru_local(struct ldlm_namespace *ns, struct list_head *cancels,
1730 int flags) 1728 int flags)
1731{ 1729{
1732 int added; 1730 int added;
1731
1733 added = ldlm_prepare_lru_list(ns, cancels, count, max, flags); 1732 added = ldlm_prepare_lru_list(ns, cancels, count, max, flags);
1734 if (added <= 0) 1733 if (added <= 0)
1735 return added; 1734 return added;
@@ -1918,7 +1917,8 @@ struct ldlm_cli_cancel_arg {
1918 void *lc_opaque; 1917 void *lc_opaque;
1919}; 1918};
1920 1919
1921static int ldlm_cli_hash_cancel_unused(struct cfs_hash *hs, struct cfs_hash_bd *bd, 1920static int ldlm_cli_hash_cancel_unused(struct cfs_hash *hs,
1921 struct cfs_hash_bd *bd,
1922 struct hlist_node *hnode, void *arg) 1922 struct hlist_node *hnode, void *arg)
1923{ 1923{
1924 struct ldlm_resource *res = cfs_hash_object(hs, hnode); 1924 struct ldlm_resource *res = cfs_hash_object(hs, hnode);
@@ -2014,6 +2014,7 @@ struct iter_helper_data {
2014static int ldlm_iter_helper(struct ldlm_lock *lock, void *closure) 2014static int ldlm_iter_helper(struct ldlm_lock *lock, void *closure)
2015{ 2015{
2016 struct iter_helper_data *helper = closure; 2016 struct iter_helper_data *helper = closure;
2017
2017 return helper->iter(lock, helper->closure); 2018 return helper->iter(lock, helper->closure);
2018} 2019}
2019 2020
@@ -2080,7 +2081,8 @@ static int ldlm_chain_lock_for_replay(struct ldlm_lock *lock, void *closure)
2080 /* we use l_pending_chain here, because it's unused on clients. */ 2081 /* we use l_pending_chain here, because it's unused on clients. */
2081 LASSERTF(list_empty(&lock->l_pending_chain), 2082 LASSERTF(list_empty(&lock->l_pending_chain),
2082 "lock %p next %p prev %p\n", 2083 "lock %p next %p prev %p\n",
2083 lock, &lock->l_pending_chain.next,&lock->l_pending_chain.prev); 2084 lock, &lock->l_pending_chain.next,
2085 &lock->l_pending_chain.prev);
2084 /* bug 9573: don't replay locks left after eviction, or 2086 /* bug 9573: don't replay locks left after eviction, or
2085 * bug 17614: locks being actively cancelled. Get a reference 2087 * bug 17614: locks being actively cancelled. Get a reference
2086 * on a lock so that it does not disappear under us (e.g. due to cancel) 2088 * on a lock so that it does not disappear under us (e.g. due to cancel)
@@ -2114,8 +2116,7 @@ static int replay_lock_interpret(const struct lu_env *env,
2114 2116
2115 lock = ldlm_handle2lock(&aa->lock_handle); 2117 lock = ldlm_handle2lock(&aa->lock_handle);
2116 if (!lock) { 2118 if (!lock) {
2117 CERROR("received replay ack for unknown local cookie %#llx" 2119 CERROR("received replay ack for unknown local cookie %#llx remote cookie %#llx from server %s id %s\n",
2118 " remote cookie %#llx from server %s id %s\n",
2119 aa->lock_handle.cookie, reply->lock_handle.cookie, 2120 aa->lock_handle.cookie, reply->lock_handle.cookie,
2120 req->rq_export->exp_client_uuid.uuid, 2121 req->rq_export->exp_client_uuid.uuid,
2121 libcfs_id2str(req->rq_peer)); 2122 libcfs_id2str(req->rq_peer));
@@ -2243,9 +2244,8 @@ static void ldlm_cancel_unused_locks_for_replay(struct ldlm_namespace *ns)
2243 int canceled; 2244 int canceled;
2244 LIST_HEAD(cancels); 2245 LIST_HEAD(cancels);
2245 2246
2246 CDEBUG(D_DLMTRACE, "Dropping as many unused locks as possible before" 2247 CDEBUG(D_DLMTRACE, "Dropping as many unused locks as possible before replay for namespace %s (%d)\n",
2247 "replay for namespace %s (%d)\n", 2248 ldlm_ns_name(ns), ns->ns_nr_unused);
2248 ldlm_ns_name(ns), ns->ns_nr_unused);
2249 2249
2250 /* We don't need to care whether or not LRU resize is enabled 2250 /* We don't need to care whether or not LRU resize is enabled
2251 * because the LDLM_CANCEL_NO_WAIT policy doesn't use the 2251 * because the LDLM_CANCEL_NO_WAIT policy doesn't use the
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
index a785b7a7d1b3..1f150e46f50e 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
@@ -71,7 +71,7 @@ extern unsigned int ldlm_cancel_unused_locks_before_replay;
71 * DDOS. */ 71 * DDOS. */
72unsigned int ldlm_dump_granted_max = 256; 72unsigned int ldlm_dump_granted_max = 256;
73 73
74#if defined (CONFIG_PROC_FS) 74#if defined(CONFIG_PROC_FS)
75static ssize_t lprocfs_wr_dump_ns(struct file *file, const char *buffer, 75static ssize_t lprocfs_wr_dump_ns(struct file *file, const char *buffer,
76 size_t count, loff_t *off) 76 size_t count, loff_t *off)
77{ 77{
@@ -93,7 +93,7 @@ int ldlm_proc_setup(void)
93 &ldlm_dump_granted_max }, 93 &ldlm_dump_granted_max },
94 { "cancel_unused_locks_before_replay", &ldlm_rw_uint_fops, 94 { "cancel_unused_locks_before_replay", &ldlm_rw_uint_fops,
95 &ldlm_cancel_unused_locks_before_replay }, 95 &ldlm_cancel_unused_locks_before_replay },
96 { NULL }}; 96 { NULL } };
97 LASSERT(ldlm_ns_proc_dir == NULL); 97 LASSERT(ldlm_ns_proc_dir == NULL);
98 98
99 ldlm_type_proc_dir = lprocfs_register(OBD_LDLM_DEVICENAME, 99 ldlm_type_proc_dir = lprocfs_register(OBD_LDLM_DEVICENAME,
@@ -215,8 +215,8 @@ static ssize_t lprocfs_lru_size_seq_write(struct file *file,
215 LDLM_CANCEL_PASSED); 215 LDLM_CANCEL_PASSED);
216 if (canceled < unused) { 216 if (canceled < unused) {
217 CDEBUG(D_DLMTRACE, 217 CDEBUG(D_DLMTRACE,
218 "not all requested locks are canceled, " 218 "not all requested locks are canceled, requested: %d, canceled: %d\n",
219 "requested: %d, canceled: %d\n", unused, 219 unused,
220 canceled); 220 canceled);
221 return -EINVAL; 221 return -EINVAL;
222 } 222 }
@@ -385,8 +385,8 @@ int ldlm_namespace_proc_register(struct ldlm_namespace *ns)
385#undef MAX_STRING_SIZE 385#undef MAX_STRING_SIZE
386#else /* CONFIG_PROC_FS */ 386#else /* CONFIG_PROC_FS */
387 387
388#define ldlm_namespace_proc_unregister(ns) ({;}) 388#define ldlm_namespace_proc_unregister(ns) ({; })
389#define ldlm_namespace_proc_register(ns) ({0;}) 389#define ldlm_namespace_proc_register(ns) ({0; })
390 390
391#endif /* CONFIG_PROC_FS */ 391#endif /* CONFIG_PROC_FS */
392 392
@@ -454,7 +454,8 @@ static void *ldlm_res_hop_object(struct hlist_node *hnode)
454 return hlist_entry(hnode, struct ldlm_resource, lr_hash); 454 return hlist_entry(hnode, struct ldlm_resource, lr_hash);
455} 455}
456 456
457static void ldlm_res_hop_get_locked(struct cfs_hash *hs, struct hlist_node *hnode) 457static void ldlm_res_hop_get_locked(struct cfs_hash *hs,
458 struct hlist_node *hnode)
458{ 459{
459 struct ldlm_resource *res; 460 struct ldlm_resource *res;
460 461
@@ -462,7 +463,8 @@ static void ldlm_res_hop_get_locked(struct cfs_hash *hs, struct hlist_node *hnod
462 ldlm_resource_getref(res); 463 ldlm_resource_getref(res);
463} 464}
464 465
465static void ldlm_res_hop_put_locked(struct cfs_hash *hs, struct hlist_node *hnode) 466static void ldlm_res_hop_put_locked(struct cfs_hash *hs,
467 struct hlist_node *hnode)
466{ 468{
467 struct ldlm_resource *res; 469 struct ldlm_resource *res;
468 470
@@ -501,7 +503,7 @@ cfs_hash_ops_t ldlm_ns_fid_hash_ops = {
501 .hs_put = ldlm_res_hop_put 503 .hs_put = ldlm_res_hop_put
502}; 504};
503 505
504typedef struct { 506struct ldlm_ns_hash_def {
505 ldlm_ns_type_t nsd_type; 507 ldlm_ns_type_t nsd_type;
506 /** hash bucket bits */ 508 /** hash bucket bits */
507 unsigned nsd_bkt_bits; 509 unsigned nsd_bkt_bits;
@@ -509,9 +511,9 @@ typedef struct {
509 unsigned nsd_all_bits; 511 unsigned nsd_all_bits;
510 /** hash operations */ 512 /** hash operations */
511 cfs_hash_ops_t *nsd_hops; 513 cfs_hash_ops_t *nsd_hops;
512} ldlm_ns_hash_def_t; 514};
513 515
514ldlm_ns_hash_def_t ldlm_ns_hash_defs[] = { 516struct ldlm_ns_hash_def ldlm_ns_hash_defs[] = {
515 { 517 {
516 .nsd_type = LDLM_NS_TYPE_MDC, 518 .nsd_type = LDLM_NS_TYPE_MDC,
517 .nsd_bkt_bits = 11, 519 .nsd_bkt_bits = 11,
@@ -563,7 +565,7 @@ struct ldlm_namespace *ldlm_namespace_new(struct obd_device *obd, char *name,
563{ 565{
564 struct ldlm_namespace *ns = NULL; 566 struct ldlm_namespace *ns = NULL;
565 struct ldlm_ns_bucket *nsb; 567 struct ldlm_ns_bucket *nsb;
566 ldlm_ns_hash_def_t *nsd; 568 struct ldlm_ns_hash_def *nsd;
567 struct cfs_hash_bd bd; 569 struct cfs_hash_bd bd;
568 int idx; 570 int idx;
569 int rc; 571 int rc;
@@ -576,7 +578,7 @@ struct ldlm_namespace *ldlm_namespace_new(struct obd_device *obd, char *name,
576 return NULL; 578 return NULL;
577 } 579 }
578 580
579 for (idx = 0;;idx++) { 581 for (idx = 0;; idx++) {
580 nsd = &ldlm_ns_hash_defs[idx]; 582 nsd = &ldlm_ns_hash_defs[idx];
581 if (nsd->nsd_type == LDLM_NS_TYPE_UNKNOWN) { 583 if (nsd->nsd_type == LDLM_NS_TYPE_UNKNOWN) {
582 CERROR("Unknown type %d for ns %s\n", ns_type, name); 584 CERROR("Unknown type %d for ns %s\n", ns_type, name);
@@ -735,8 +737,7 @@ static void cleanup_resource(struct ldlm_resource *res, struct list_head *q,
735 } else { 737 } else {
736 ldlm_resource_unlink_lock(lock); 738 ldlm_resource_unlink_lock(lock);
737 unlock_res(res); 739 unlock_res(res);
738 LDLM_DEBUG(lock, "Freeing a lock still held by a " 740 LDLM_DEBUG(lock, "Freeing a lock still held by a client node");
739 "client node");
740 ldlm_lock_destroy(lock); 741 ldlm_lock_destroy(lock);
741 } 742 }
742 LDLM_LOCK_RELEASE(lock); 743 LDLM_LOCK_RELEASE(lock);
@@ -805,6 +806,7 @@ static int __ldlm_namespace_free(struct ldlm_namespace *ns, int force)
805 if (atomic_read(&ns->ns_bref) > 0) { 806 if (atomic_read(&ns->ns_bref) > 0) {
806 struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL); 807 struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
807 int rc; 808 int rc;
809
808 CDEBUG(D_DLMTRACE, 810 CDEBUG(D_DLMTRACE,
809 "dlm namespace %s free waiting on refcount %d\n", 811 "dlm namespace %s free waiting on refcount %d\n",
810 ldlm_ns_name(ns), atomic_read(&ns->ns_bref)); 812 ldlm_ns_name(ns), atomic_read(&ns->ns_bref));
@@ -818,16 +820,14 @@ force_wait:
818 /* Forced cleanups should be able to reclaim all references, 820 /* Forced cleanups should be able to reclaim all references,
819 * so it's safe to wait forever... we can't leak locks... */ 821 * so it's safe to wait forever... we can't leak locks... */
820 if (force && rc == -ETIMEDOUT) { 822 if (force && rc == -ETIMEDOUT) {
821 LCONSOLE_ERROR("Forced cleanup waiting for %s " 823 LCONSOLE_ERROR("Forced cleanup waiting for %s namespace with %d resources in use, (rc=%d)\n",
822 "namespace with %d resources in use, " 824 ldlm_ns_name(ns),
823 "(rc=%d)\n", ldlm_ns_name(ns),
824 atomic_read(&ns->ns_bref), rc); 825 atomic_read(&ns->ns_bref), rc);
825 goto force_wait; 826 goto force_wait;
826 } 827 }
827 828
828 if (atomic_read(&ns->ns_bref)) { 829 if (atomic_read(&ns->ns_bref)) {
829 LCONSOLE_ERROR("Cleanup waiting for %s namespace " 830 LCONSOLE_ERROR("Cleanup waiting for %s namespace with %d resources in use, (rc=%d)\n",
830 "with %d resources in use, (rc=%d)\n",
831 ldlm_ns_name(ns), 831 ldlm_ns_name(ns),
832 atomic_read(&ns->ns_bref), rc); 832 atomic_read(&ns->ns_bref), rc);
833 return ELDLM_NAMESPACE_EXISTS; 833 return ELDLM_NAMESPACE_EXISTS;
@@ -1335,6 +1335,7 @@ void ldlm_dump_all_namespaces(ldlm_side_t client, int level)
1335 1335
1336 list_for_each(tmp, ldlm_namespace_list(client)) { 1336 list_for_each(tmp, ldlm_namespace_list(client)) {
1337 struct ldlm_namespace *ns; 1337 struct ldlm_namespace *ns;
1338
1338 ns = list_entry(tmp, struct ldlm_namespace, ns_list_chain); 1339 ns = list_entry(tmp, struct ldlm_namespace, ns_list_chain);
1339 ldlm_namespace_dump(level, ns); 1340 ldlm_namespace_dump(level, ns);
1340 } 1341 }
@@ -1404,8 +1405,8 @@ void ldlm_resource_dump(int level, struct ldlm_resource *res)
1404 LDLM_DEBUG_LIMIT(level, lock, "###"); 1405 LDLM_DEBUG_LIMIT(level, lock, "###");
1405 if (!(level & D_CANTMASK) && 1406 if (!(level & D_CANTMASK) &&
1406 ++granted > ldlm_dump_granted_max) { 1407 ++granted > ldlm_dump_granted_max) {
1407 CDEBUG(level, "only dump %d granted locks to " 1408 CDEBUG(level, "only dump %d granted locks to avoid DDOS.\n",
1408 "avoid DDOS.\n", granted); 1409 granted);
1409 break; 1410 break;
1410 } 1411 }
1411 } 1412 }
diff --git a/drivers/staging/lustre/lustre/libcfs/debug.c b/drivers/staging/lustre/lustre/libcfs/debug.c
index ba43b3067fa3..a7a7ac626aaf 100644
--- a/drivers/staging/lustre/lustre/libcfs/debug.c
+++ b/drivers/staging/lustre/lustre/libcfs/debug.c
@@ -318,9 +318,7 @@ libcfs_debug_str2mask(int *mask, const char *str, int is_subsys)
318 if (t >= 1 && matched == n) { 318 if (t >= 1 && matched == n) {
319 /* don't print warning for lctl set_param debug=0 or -1 */ 319 /* don't print warning for lctl set_param debug=0 or -1 */
320 if (m != 0 && m != -1) 320 if (m != 0 && m != -1)
321 CWARN("You are trying to use a numerical value for the " 321 CWARN("You are trying to use a numerical value for the mask - this will be deprecated in a future release.\n");
322 "mask - this will be deprecated in a future "
323 "release.\n");
324 *mask = m; 322 *mask = m;
325 return 0; 323 return 0;
326 } 324 }
@@ -375,8 +373,8 @@ void libcfs_debug_dumplog(void)
375 (void *)(long)current_pid(), 373 (void *)(long)current_pid(),
376 "libcfs_debug_dumper"); 374 "libcfs_debug_dumper");
377 if (IS_ERR(dumper)) 375 if (IS_ERR(dumper))
378 pr_err("LustreError: cannot start log dump thread:" 376 pr_err("LustreError: cannot start log dump thread: %ld\n",
379 " %ld\n", PTR_ERR(dumper)); 377 PTR_ERR(dumper));
380 else 378 else
381 schedule(); 379 schedule();
382 380
@@ -412,7 +410,7 @@ int libcfs_debug_init(unsigned long bufsize)
412 max = TCD_MAX_PAGES; 410 max = TCD_MAX_PAGES;
413 } else { 411 } else {
414 max = (max / num_possible_cpus()); 412 max = (max / num_possible_cpus());
415 max = (max << (20 - PAGE_CACHE_SHIFT)); 413 max = max << (20 - PAGE_CACHE_SHIFT);
416 } 414 }
417 rc = cfs_tracefile_init(max); 415 rc = cfs_tracefile_init(max);
418 416
@@ -460,11 +458,3 @@ void libcfs_debug_set_level(unsigned int debug_level)
460} 458}
461 459
462EXPORT_SYMBOL(libcfs_debug_set_level); 460EXPORT_SYMBOL(libcfs_debug_set_level);
463
464void libcfs_log_goto(struct libcfs_debug_msg_data *msgdata, const char *label,
465 long_ptr_t rc)
466{
467 libcfs_debug_msg(msgdata, "Process leaving via %s (rc=%lu : %ld : %#lx)\n",
468 label, (ulong_ptr_t)rc, rc, rc);
469}
470EXPORT_SYMBOL(libcfs_log_goto);
diff --git a/drivers/staging/lustre/lustre/libcfs/fail.c b/drivers/staging/lustre/lustre/libcfs/fail.c
index e73ca3df9734..92444b0fe2a3 100644
--- a/drivers/staging/lustre/lustre/libcfs/fail.c
+++ b/drivers/staging/lustre/lustre/libcfs/fail.c
@@ -103,18 +103,18 @@ int __cfs_fail_check_set(__u32 id, __u32 value, int set)
103 } 103 }
104 104
105 switch (set) { 105 switch (set) {
106 case CFS_FAIL_LOC_NOSET: 106 case CFS_FAIL_LOC_NOSET:
107 case CFS_FAIL_LOC_VALUE: 107 case CFS_FAIL_LOC_VALUE:
108 break; 108 break;
109 case CFS_FAIL_LOC_ORSET: 109 case CFS_FAIL_LOC_ORSET:
110 cfs_fail_loc |= value & ~(CFS_FAILED | CFS_FAIL_ONCE); 110 cfs_fail_loc |= value & ~(CFS_FAILED | CFS_FAIL_ONCE);
111 break; 111 break;
112 case CFS_FAIL_LOC_RESET: 112 case CFS_FAIL_LOC_RESET:
113 cfs_fail_loc = value; 113 cfs_fail_loc = value;
114 break; 114 break;
115 default: 115 default:
116 LASSERTF(0, "called with bad set %u\n", set); 116 LASSERTF(0, "called with bad set %u\n", set);
117 break; 117 break;
118 } 118 }
119 119
120 return 1; 120 return 1;
diff --git a/drivers/staging/lustre/lustre/libcfs/hash.c b/drivers/staging/lustre/lustre/libcfs/hash.c
index 3b67b7b6428c..2d1e6729e996 100644
--- a/drivers/staging/lustre/lustre/libcfs/hash.c
+++ b/drivers/staging/lustre/lustre/libcfs/hash.c
@@ -1121,8 +1121,7 @@ cfs_hash_destroy(struct cfs_hash *hs)
1121 cfs_hash_bd_for_each_hlist(hs, &bd, hhead) { 1121 cfs_hash_bd_for_each_hlist(hs, &bd, hhead) {
1122 hlist_for_each_safe(hnode, pos, hhead) { 1122 hlist_for_each_safe(hnode, pos, hhead) {
1123 LASSERTF(!cfs_hash_with_assert_empty(hs), 1123 LASSERTF(!cfs_hash_with_assert_empty(hs),
1124 "hash %s bucket %u(%u) is not " 1124 "hash %s bucket %u(%u) is not empty: %u items left\n",
1125 " empty: %u items left\n",
1126 hs->hs_name, bd.bd_bucket->hsb_index, 1125 hs->hs_name, bd.bd_bucket->hsb_index,
1127 bd.bd_offset, bd.bd_bucket->hsb_count); 1126 bd.bd_offset, bd.bd_bucket->hsb_count);
1128 /* can't assert key valicate, because we 1127 /* can't assert key valicate, because we
@@ -1371,8 +1370,7 @@ cfs_hash_lookup(struct cfs_hash *hs, const void *key)
1371EXPORT_SYMBOL(cfs_hash_lookup); 1370EXPORT_SYMBOL(cfs_hash_lookup);
1372 1371
1373static void 1372static void
1374cfs_hash_for_each_enter(struct cfs_hash *hs) 1373cfs_hash_for_each_enter(struct cfs_hash *hs) {
1375{
1376 LASSERT(!cfs_hash_is_exiting(hs)); 1374 LASSERT(!cfs_hash_is_exiting(hs));
1377 1375
1378 if (!cfs_hash_with_rehash(hs)) 1376 if (!cfs_hash_with_rehash(hs))
@@ -1397,8 +1395,7 @@ cfs_hash_for_each_enter(struct cfs_hash *hs)
1397} 1395}
1398 1396
1399static void 1397static void
1400cfs_hash_for_each_exit(struct cfs_hash *hs) 1398cfs_hash_for_each_exit(struct cfs_hash *hs) {
1401{
1402 int remained; 1399 int remained;
1403 int bits; 1400 int bits;
1404 1401
@@ -1429,8 +1426,7 @@ cfs_hash_for_each_exit(struct cfs_hash *hs)
1429 */ 1426 */
1430static __u64 1427static __u64
1431cfs_hash_for_each_tight(struct cfs_hash *hs, cfs_hash_for_each_cb_t func, 1428cfs_hash_for_each_tight(struct cfs_hash *hs, cfs_hash_for_each_cb_t func,
1432 void *data, int remove_safe) 1429 void *data, int remove_safe) {
1433{
1434 struct hlist_node *hnode; 1430 struct hlist_node *hnode;
1435 struct hlist_node *pos; 1431 struct hlist_node *pos;
1436 struct cfs_hash_bd bd; 1432 struct cfs_hash_bd bd;
@@ -1523,8 +1519,7 @@ EXPORT_SYMBOL(cfs_hash_for_each);
1523 1519
1524void 1520void
1525cfs_hash_for_each_safe(struct cfs_hash *hs, 1521cfs_hash_for_each_safe(struct cfs_hash *hs,
1526 cfs_hash_for_each_cb_t func, void *data) 1522 cfs_hash_for_each_cb_t func, void *data) {
1527{
1528 cfs_hash_for_each_tight(hs, func, data, 1); 1523 cfs_hash_for_each_tight(hs, func, data, 1);
1529} 1524}
1530EXPORT_SYMBOL(cfs_hash_for_each_safe); 1525EXPORT_SYMBOL(cfs_hash_for_each_safe);
@@ -1572,8 +1567,8 @@ EXPORT_SYMBOL(cfs_hash_size_get);
1572 * two cases, so iteration has to be stopped on change. 1567 * two cases, so iteration has to be stopped on change.
1573 */ 1568 */
1574static int 1569static int
1575cfs_hash_for_each_relax(struct cfs_hash *hs, cfs_hash_for_each_cb_t func, void *data) 1570cfs_hash_for_each_relax(struct cfs_hash *hs, cfs_hash_for_each_cb_t func,
1576{ 1571 void *data) {
1577 struct hlist_node *hnode; 1572 struct hlist_node *hnode;
1578 struct hlist_node *tmp; 1573 struct hlist_node *tmp;
1579 struct cfs_hash_bd bd; 1574 struct cfs_hash_bd bd;
@@ -1634,8 +1629,7 @@ cfs_hash_for_each_relax(struct cfs_hash *hs, cfs_hash_for_each_cb_t func, void *
1634 1629
1635int 1630int
1636cfs_hash_for_each_nolock(struct cfs_hash *hs, 1631cfs_hash_for_each_nolock(struct cfs_hash *hs,
1637 cfs_hash_for_each_cb_t func, void *data) 1632 cfs_hash_for_each_cb_t func, void *data) {
1638{
1639 if (cfs_hash_with_no_lock(hs) || 1633 if (cfs_hash_with_no_lock(hs) ||
1640 cfs_hash_with_rehash_key(hs) || 1634 cfs_hash_with_rehash_key(hs) ||
1641 !cfs_hash_with_no_itemref(hs)) 1635 !cfs_hash_with_no_itemref(hs))
@@ -1667,8 +1661,7 @@ EXPORT_SYMBOL(cfs_hash_for_each_nolock);
1667 */ 1661 */
1668int 1662int
1669cfs_hash_for_each_empty(struct cfs_hash *hs, 1663cfs_hash_for_each_empty(struct cfs_hash *hs,
1670 cfs_hash_for_each_cb_t func, void *data) 1664 cfs_hash_for_each_cb_t func, void *data) {
1671{
1672 unsigned i = 0; 1665 unsigned i = 0;
1673 1666
1674 if (cfs_hash_with_no_lock(hs)) 1667 if (cfs_hash_with_no_lock(hs))
@@ -1726,8 +1719,7 @@ EXPORT_SYMBOL(cfs_hash_hlist_for_each);
1726 */ 1719 */
1727void 1720void
1728cfs_hash_for_each_key(struct cfs_hash *hs, const void *key, 1721cfs_hash_for_each_key(struct cfs_hash *hs, const void *key,
1729 cfs_hash_for_each_cb_t func, void *data) 1722 cfs_hash_for_each_cb_t func, void *data) {
1730{
1731 struct hlist_node *hnode; 1723 struct hlist_node *hnode;
1732 struct cfs_hash_bd bds[2]; 1724 struct cfs_hash_bd bds[2];
1733 unsigned i; 1725 unsigned i;
diff --git a/drivers/staging/lustre/lustre/libcfs/libcfs_cpu.c b/drivers/staging/lustre/lustre/libcfs/libcfs_cpu.c
index dbb81b6cc200..31a558115a96 100644
--- a/drivers/staging/lustre/lustre/libcfs/libcfs_cpu.c
+++ b/drivers/staging/lustre/lustre/libcfs/libcfs_cpu.c
@@ -38,7 +38,7 @@
38#include "../../include/linux/libcfs/libcfs.h" 38#include "../../include/linux/libcfs/libcfs.h"
39 39
40/** Global CPU partition table */ 40/** Global CPU partition table */
41struct cfs_cpt_table *cfs_cpt_table __read_mostly = NULL; 41struct cfs_cpt_table *cfs_cpt_table __read_mostly;
42EXPORT_SYMBOL(cfs_cpt_table); 42EXPORT_SYMBOL(cfs_cpt_table);
43 43
44#ifndef HAVE_LIBCFS_CPT 44#ifndef HAVE_LIBCFS_CPT
diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-cpu.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-cpu.c
index 224c65b5ce4e..05f7595f18aa 100644
--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-cpu.c
+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-cpu.c
@@ -333,8 +333,8 @@ cfs_cpt_unset_cpu(struct cfs_cpt_table *cptab, int cpt, int cpu)
333 /* caller doesn't know the partition ID */ 333 /* caller doesn't know the partition ID */
334 cpt = cptab->ctb_cpu2cpt[cpu]; 334 cpt = cptab->ctb_cpu2cpt[cpu];
335 if (cpt < 0) { /* not set in this CPT-table */ 335 if (cpt < 0) { /* not set in this CPT-table */
336 CDEBUG(D_INFO, "Try to unset cpu %d which is " 336 CDEBUG(D_INFO, "Try to unset cpu %d which is not in CPT-table %p\n",
337 "not in CPT-table %p\n", cpt, cptab); 337 cpt, cptab);
338 return; 338 return;
339 } 339 }
340 340
@@ -384,8 +384,8 @@ cfs_cpt_set_cpumask(struct cfs_cpt_table *cptab, int cpt, cpumask_t *mask)
384 int i; 384 int i;
385 385
386 if (cpus_weight(*mask) == 0 || any_online_cpu(*mask) == NR_CPUS) { 386 if (cpus_weight(*mask) == 0 || any_online_cpu(*mask) == NR_CPUS) {
387 CDEBUG(D_INFO, "No online CPU is found in the CPU mask " 387 CDEBUG(D_INFO, "No online CPU is found in the CPU mask for CPU partition %d\n",
388 "for CPU partition %d\n", cpt); 388 cpt);
389 return 0; 389 return 0;
390 } 390 }
391 391
@@ -579,9 +579,8 @@ cfs_cpt_bind(struct cfs_cpt_table *cptab, int cpt)
579 } 579 }
580 580
581 if (any_online_cpu(*cpumask) == NR_CPUS) { 581 if (any_online_cpu(*cpumask) == NR_CPUS) {
582 CERROR("No online CPU found in CPU partition %d, did someone " 582 CERROR("No online CPU found in CPU partition %d, did someone do CPU hotplug on system? You might need to reload Lustre modules to keep system working well.\n",
583 "do CPU hotplug on system? You might need to reload " 583 cpt);
584 "Lustre modules to keep system working well.\n", cpt);
585 return -EINVAL; 584 return -EINVAL;
586 } 585 }
587 586
@@ -737,16 +736,12 @@ cfs_cpt_table_create(int ncpt)
737 ncpt = rc; 736 ncpt = rc;
738 737
739 if (ncpt > num_online_cpus() || ncpt > 4 * rc) { 738 if (ncpt > num_online_cpus() || ncpt > 4 * rc) {
740 CWARN("CPU partition number %d is larger than suggested " 739 CWARN("CPU partition number %d is larger than suggested value (%d), your system may have performance issue or run out of memory while under pressure\n",
741 "value (%d), your system may have performance"
742 "issue or run out of memory while under pressure\n",
743 ncpt, rc); 740 ncpt, rc);
744 } 741 }
745 742
746 if (num_online_cpus() % ncpt != 0) { 743 if (num_online_cpus() % ncpt != 0) {
747 CERROR("CPU number %d is not multiple of cpu_npartition %d, " 744 CERROR("CPU number %d is not multiple of cpu_npartition %d, please try different cpu_npartitions value or set pattern string by cpu_pattern=STRING\n",
748 "please try different cpu_npartitions value or"
749 "set pattern string by cpu_pattern=STRING\n",
750 (int)num_online_cpus(), ncpt); 745 (int)num_online_cpus(), ncpt);
751 goto failed; 746 goto failed;
752 } 747 }
@@ -796,8 +791,7 @@ cfs_cpt_table_create(int ncpt)
796 791
797 if (cpt != ncpt || 792 if (cpt != ncpt ||
798 num != cpus_weight(*cptab->ctb_parts[ncpt - 1].cpt_cpumask)) { 793 num != cpus_weight(*cptab->ctb_parts[ncpt - 1].cpt_cpumask)) {
799 CERROR("Expect %d(%d) CPU partitions but got %d(%d), " 794 CERROR("Expect %d(%d) CPU partitions but got %d(%d), CPU hotplug/unplug while setting?\n",
800 "CPU hotplug/unplug while setting?\n",
801 cptab->ctb_nparts, num, cpt, 795 cptab->ctb_nparts, num, cpt,
802 cpus_weight(*cptab->ctb_parts[ncpt - 1].cpt_cpumask)); 796 cpus_weight(*cptab->ctb_parts[ncpt - 1].cpt_cpumask));
803 goto failed; 797 goto failed;
@@ -808,8 +802,7 @@ cfs_cpt_table_create(int ncpt)
808 return cptab; 802 return cptab;
809 803
810 failed: 804 failed:
811 CERROR("Failed to setup CPU-partition-table with %d " 805 CERROR("Failed to setup CPU-partition-table with %d CPU-partitions, online HW nodes: %d, HW cpus: %d.\n",
812 "CPU-partitions, online HW nodes: %d, HW cpus: %d.\n",
813 ncpt, num_online_nodes(), num_online_cpus()); 806 ncpt, num_online_nodes(), num_online_cpus());
814 807
815 if (mask != NULL) 808 if (mask != NULL)
@@ -975,9 +968,8 @@ cfs_cpu_notify(struct notifier_block *self, unsigned long action, void *hcpu)
975 warn = any_online_cpu(*cpt_data.cpt_cpumask) >= nr_cpu_ids; 968 warn = any_online_cpu(*cpt_data.cpt_cpumask) >= nr_cpu_ids;
976 mutex_unlock(&cpt_data.cpt_mutex); 969 mutex_unlock(&cpt_data.cpt_mutex);
977 CDEBUG(warn ? D_WARNING : D_INFO, 970 CDEBUG(warn ? D_WARNING : D_INFO,
978 "Lustre: can't support CPU plug-out well now, " 971 "Lustre: can't support CPU plug-out well now, performance and stability could be impacted [CPU %u action: %lx]\n",
979 "performance and stability could be impacted " 972 cpu, action);
980 "[CPU %u action: %lx]\n", cpu, action);
981 } 973 }
982 974
983 return NOTIFY_OK; 975 return NOTIFY_OK;
diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-debug.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-debug.c
index 3298ddf6d3be..12005a71aa73 100644
--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-debug.c
+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-debug.c
@@ -87,8 +87,7 @@ void libcfs_run_debug_log_upcall(char *file)
87 87
88 rc = call_usermodehelper(argv[0], argv, envp, 1); 88 rc = call_usermodehelper(argv[0], argv, envp, 1);
89 if (rc < 0 && rc != -ENOENT) { 89 if (rc < 0 && rc != -ENOENT) {
90 CERROR("Error %d invoking LNET debug log upcall %s %s; " 90 CERROR("Error %d invoking LNET debug log upcall %s %s; check /proc/sys/lnet/debug_log_upcall\n",
91 "check /proc/sys/lnet/debug_log_upcall\n",
92 rc, argv[0], argv[1]); 91 rc, argv[0], argv[1]);
93 } else { 92 } else {
94 CDEBUG(D_HA, "Invoked LNET debug log upcall %s %s\n", 93 CDEBUG(D_HA, "Invoked LNET debug log upcall %s %s\n",
@@ -114,8 +113,7 @@ void libcfs_run_upcall(char **argv)
114 113
115 rc = call_usermodehelper(argv[0], argv, envp, 1); 114 rc = call_usermodehelper(argv[0], argv, envp, 1);
116 if (rc < 0 && rc != -ENOENT) { 115 if (rc < 0 && rc != -ENOENT) {
117 CERROR("Error %d invoking LNET upcall %s %s%s%s%s%s%s%s%s; " 116 CERROR("Error %d invoking LNET upcall %s %s%s%s%s%s%s%s%s; check /proc/sys/lnet/upcall\n",
118 "check /proc/sys/lnet/upcall\n",
119 rc, argv[0], argv[1], 117 rc, argv[0], argv[1],
120 argc < 3 ? "" : ",", argc < 3 ? "" : argv[2], 118 argc < 3 ? "" : ",", argc < 3 ? "" : argv[2],
121 argc < 4 ? "" : ",", argc < 4 ? "" : argv[3], 119 argc < 4 ? "" : ",", argc < 4 ? "" : argv[3],
diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
index bbe2c68c18a6..83d3f08a37b2 100644
--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
@@ -365,8 +365,8 @@ static int __proc_cpt_table(void *data, int write,
365 if (rc >= 0) 365 if (rc >= 0)
366 break; 366 break;
367 367
368 LIBCFS_FREE(buf, len);
369 if (rc == -EFBIG) { 368 if (rc == -EFBIG) {
369 LIBCFS_FREE(buf, len);
370 len <<= 1; 370 len <<= 1;
371 continue; 371 continue;
372 } 372 }
diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-tcpip.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-tcpip.c
index 939b33dd6520..b91a1f95bbd0 100644
--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-tcpip.c
+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-tcpip.c
@@ -279,8 +279,7 @@ libcfs_sock_write (struct socket *sock, void *buffer, int nob, int timeout)
279 rc = kernel_setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, 279 rc = kernel_setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO,
280 (char *)&tv, sizeof(tv)); 280 (char *)&tv, sizeof(tv));
281 if (rc != 0) { 281 if (rc != 0) {
282 CERROR("Can't set socket send timeout " 282 CERROR("Can't set socket send timeout %ld.%06d: %d\n",
283 "%ld.%06d: %d\n",
284 (long)tv.tv_sec, (int)tv.tv_usec, rc); 283 (long)tv.tv_sec, (int)tv.tv_usec, rc);
285 return rc; 284 return rc;
286 } 285 }
diff --git a/drivers/staging/lustre/lustre/libcfs/tracefile.c b/drivers/staging/lustre/lustre/libcfs/tracefile.c
index 7561030c96e6..5917c31c7ed6 100644
--- a/drivers/staging/lustre/lustre/libcfs/tracefile.c
+++ b/drivers/staging/lustre/lustre/libcfs/tracefile.c
@@ -196,8 +196,7 @@ static void cfs_tcd_shrink(struct cfs_trace_cpu_data *tcd)
196 */ 196 */
197 197
198 if (printk_ratelimit()) 198 if (printk_ratelimit())
199 printk(KERN_WARNING "debug daemon buffer overflowed; " 199 printk(KERN_WARNING "debug daemon buffer overflowed; discarding 10%% of pages (%d of %ld)\n",
200 "discarding 10%% of pages (%d of %ld)\n",
201 pgcount + 1, tcd->tcd_cur_pages); 200 pgcount + 1, tcd->tcd_cur_pages);
202 201
203 INIT_LIST_HEAD(&pc.pc_pages); 202 INIT_LIST_HEAD(&pc.pc_pages);
@@ -357,8 +356,8 @@ int libcfs_debug_vmsg2(struct libcfs_debug_msg_data *msgdata,
357 } 356 }
358 357
359 if (*(string_buf+needed-1) != '\n') 358 if (*(string_buf+needed-1) != '\n')
360 printk(KERN_INFO "format at %s:%d:%s doesn't end in " 359 printk(KERN_INFO "format at %s:%d:%s doesn't end in newline\n",
361 "newline\n", file, msgdata->msg_line, msgdata->msg_fn); 360 file, msgdata->msg_line, msgdata->msg_fn);
362 361
363 header.ph_len = known_size + needed; 362 header.ph_len = known_size + needed;
364 debug_buf = (char *)page_address(tage->page) + tage->used; 363 debug_buf = (char *)page_address(tage->page) + tage->used;
@@ -715,8 +714,8 @@ int cfs_tracefile_dump_all_pages(char *filename)
715 kunmap(tage->page); 714 kunmap(tage->page);
716 715
717 if (rc != (int)tage->used) { 716 if (rc != (int)tage->used) {
718 printk(KERN_WARNING "wanted to write %u but wrote " 717 printk(KERN_WARNING "wanted to write %u but wrote %d\n",
719 "%d\n", tage->used, rc); 718 tage->used, rc);
720 put_pages_back(&pc); 719 put_pages_back(&pc);
721 __LASSERT(list_empty(&pc.pc_pages)); 720 __LASSERT(list_empty(&pc.pc_pages));
722 break; 721 break;
@@ -875,8 +874,8 @@ int cfs_trace_daemon_command(char *str)
875 strcpy(cfs_tracefile, str); 874 strcpy(cfs_tracefile, str);
876 875
877 printk(KERN_INFO 876 printk(KERN_INFO
878 "Lustre: debug daemon will attempt to start writing " 877 "Lustre: debug daemon will attempt to start writing to %s (%lukB max)\n",
879 "to %s (%lukB max)\n", cfs_tracefile, 878 cfs_tracefile,
880 (long)(cfs_tracefile_size >> 10)); 879 (long)(cfs_tracefile_size >> 10));
881 880
882 cfs_trace_start_thread(); 881 cfs_trace_start_thread();
@@ -914,15 +913,15 @@ int cfs_trace_set_debug_mb(int mb)
914 913
915 if (mb < num_possible_cpus()) { 914 if (mb < num_possible_cpus()) {
916 printk(KERN_WARNING 915 printk(KERN_WARNING
917 "Lustre: %d MB is too small for debug buffer size, " 916 "Lustre: %d MB is too small for debug buffer size, setting it to %d MB.\n",
918 "setting it to %d MB.\n", mb, num_possible_cpus()); 917 mb, num_possible_cpus());
919 mb = num_possible_cpus(); 918 mb = num_possible_cpus();
920 } 919 }
921 920
922 if (mb > limit) { 921 if (mb > limit) {
923 printk(KERN_WARNING 922 printk(KERN_WARNING
924 "Lustre: %d MB is too large for debug buffer size, " 923 "Lustre: %d MB is too large for debug buffer size, setting it to %d MB.\n",
925 "setting it to %d MB.\n", mb, limit); 924 mb, limit);
926 mb = limit; 925 mb = limit;
927 } 926 }
928 927
@@ -1004,8 +1003,8 @@ static int tracefiled(void *arg)
1004 if (IS_ERR(filp)) { 1003 if (IS_ERR(filp)) {
1005 rc = PTR_ERR(filp); 1004 rc = PTR_ERR(filp);
1006 filp = NULL; 1005 filp = NULL;
1007 printk(KERN_WARNING "couldn't open %s: " 1006 printk(KERN_WARNING "couldn't open %s: %d\n",
1008 "%d\n", cfs_tracefile, rc); 1007 cfs_tracefile, rc);
1009 } 1008 }
1010 } 1009 }
1011 cfs_tracefile_read_unlock(); 1010 cfs_tracefile_read_unlock();
@@ -1034,8 +1033,8 @@ static int tracefiled(void *arg)
1034 kunmap(tage->page); 1033 kunmap(tage->page);
1035 1034
1036 if (rc != (int)tage->used) { 1035 if (rc != (int)tage->used) {
1037 printk(KERN_WARNING "wanted to write %u " 1036 printk(KERN_WARNING "wanted to write %u but wrote %d\n",
1038 "but wrote %d\n", tage->used, rc); 1037 tage->used, rc);
1039 put_pages_back(&pc); 1038 put_pages_back(&pc);
1040 __LASSERT(list_empty(&pc.pc_pages)); 1039 __LASSERT(list_empty(&pc.pc_pages));
1041 } 1040 }
@@ -1047,8 +1046,7 @@ static int tracefiled(void *arg)
1047 if (!list_empty(&pc.pc_pages)) { 1046 if (!list_empty(&pc.pc_pages)) {
1048 int i; 1047 int i;
1049 1048
1050 printk(KERN_ALERT "Lustre: trace pages aren't " 1049 printk(KERN_ALERT "Lustre: trace pages aren't empty\n");
1051 " empty\n");
1052 printk(KERN_ERR "total cpus(%d): ", 1050 printk(KERN_ERR "total cpus(%d): ",
1053 num_possible_cpus()); 1051 num_possible_cpus());
1054 for (i = 0; i < num_possible_cpus(); i++) 1052 for (i = 0; i < num_possible_cpus(); i++)
@@ -1061,8 +1059,8 @@ static int tracefiled(void *arg)
1061 i = 0; 1059 i = 0;
1062 list_for_each_entry_safe(tage, tmp, &pc.pc_pages, 1060 list_for_each_entry_safe(tage, tmp, &pc.pc_pages,
1063 linkage) 1061 linkage)
1064 printk(KERN_ERR "page %d belongs to cpu " 1062 printk(KERN_ERR "page %d belongs to cpu %d\n",
1065 "%d\n", ++i, tage->cpu); 1063 ++i, tage->cpu);
1066 printk(KERN_ERR "There are %d pages unwritten\n", 1064 printk(KERN_ERR "There are %d pages unwritten\n",
1067 i); 1065 i);
1068 } 1066 }
diff --git a/drivers/staging/lustre/lustre/llite/dcache.c b/drivers/staging/lustre/lustre/llite/dcache.c
index f692261e9b5c..5bb9c85cec81 100644
--- a/drivers/staging/lustre/lustre/llite/dcache.c
+++ b/drivers/staging/lustre/lustre/llite/dcache.c
@@ -259,8 +259,8 @@ void ll_invalidate_aliases(struct inode *inode)
259 259
260 ll_lock_dcache(inode); 260 ll_lock_dcache(inode);
261 ll_d_hlist_for_each_entry(dentry, p, &inode->i_dentry, d_u.d_alias) { 261 ll_d_hlist_for_each_entry(dentry, p, &inode->i_dentry, d_u.d_alias) {
262 CDEBUG(D_DENTRY, "dentry in drop %pd (%p) parent %p " 262 CDEBUG(D_DENTRY, "dentry in drop %pd (%p) parent %p inode %p flags %d\n",
263 "inode %p flags %d\n", dentry, dentry, dentry->d_parent, 263 dentry, dentry, dentry->d_parent,
264 dentry->d_inode, dentry->d_flags); 264 dentry->d_inode, dentry->d_flags);
265 265
266 if (unlikely(dentry == dentry->d_sb->s_root)) { 266 if (unlikely(dentry == dentry->d_sb->s_root)) {
diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
index a79fd65ec4c6..407718a0026f 100644
--- a/drivers/staging/lustre/lustre/llite/dir.c
+++ b/drivers/staging/lustre/lustre/llite/dir.c
@@ -163,7 +163,7 @@ static int ll_dir_filler(void *_hash, struct page *page0)
163 163
164 LASSERT(max_pages > 0 && max_pages <= MD_MAX_BRW_PAGES); 164 LASSERT(max_pages > 0 && max_pages <= MD_MAX_BRW_PAGES);
165 165
166 page_pool = kzalloc(sizeof(page) * max_pages, GFP_NOFS); 166 page_pool = kcalloc(max_pages, sizeof(page), GFP_NOFS);
167 if (page_pool) { 167 if (page_pool) {
168 page_pool[0] = page0; 168 page_pool[0] = page0;
169 } else { 169 } else {
@@ -228,8 +228,8 @@ static int ll_dir_filler(void *_hash, struct page *page0)
228 if (ll_pagevec_add(&lru_pvec, page) == 0) 228 if (ll_pagevec_add(&lru_pvec, page) == 0)
229 ll_pagevec_lru_add_file(&lru_pvec); 229 ll_pagevec_lru_add_file(&lru_pvec);
230 } else { 230 } else {
231 CDEBUG(D_VFSTRACE, "page %lu add to page cache failed:" 231 CDEBUG(D_VFSTRACE, "page %lu add to page cache failed: %d\n",
232 " %d\n", offset, ret); 232 offset, ret);
233 } 233 }
234 page_cache_release(page); 234 page_cache_release(page);
235 } 235 }
@@ -275,14 +275,14 @@ static struct page *ll_dir_page_locate(struct inode *dir, __u64 *hash,
275 struct page *page; 275 struct page *page;
276 int found; 276 int found;
277 277
278 TREE_READ_LOCK_IRQ(mapping); 278 spin_lock_irq(&mapping->tree_lock);
279 found = radix_tree_gang_lookup(&mapping->page_tree, 279 found = radix_tree_gang_lookup(&mapping->page_tree,
280 (void **)&page, offset, 1); 280 (void **)&page, offset, 1);
281 if (found > 0) { 281 if (found > 0) {
282 struct lu_dirpage *dp; 282 struct lu_dirpage *dp;
283 283
284 page_cache_get(page); 284 page_cache_get(page);
285 TREE_READ_UNLOCK_IRQ(mapping); 285 spin_unlock_irq(&mapping->tree_lock);
286 /* 286 /*
287 * In contrast to find_lock_page() we are sure that directory 287 * In contrast to find_lock_page() we are sure that directory
288 * page cannot be truncated (while DLM lock is held) and, 288 * page cannot be truncated (while DLM lock is held) and,
@@ -326,7 +326,7 @@ static struct page *ll_dir_page_locate(struct inode *dir, __u64 *hash,
326 } 326 }
327 327
328 } else { 328 } else {
329 TREE_READ_UNLOCK_IRQ(mapping); 329 spin_unlock_irq(&mapping->tree_lock);
330 page = NULL; 330 page = NULL;
331 } 331 }
332 return page; 332 return page;
@@ -600,8 +600,8 @@ static int ll_readdir(struct file *filp, struct dir_context *ctx)
600 int api32 = ll_need_32bit_api(sbi); 600 int api32 = ll_need_32bit_api(sbi);
601 int rc; 601 int rc;
602 602
603 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p) pos %lu/%llu " 603 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p) pos %lu/%llu 32bit_api %d\n",
604 " 32bit_api %d\n", inode->i_ino, inode->i_generation, 604 inode->i_ino, inode->i_generation,
605 inode, (unsigned long)lfd->lfd_pos, i_size_read(inode), api32); 605 inode, (unsigned long)lfd->lfd_pos, i_size_read(inode), api32);
606 606
607 if (lfd->lfd_pos == MDS_DIR_END_OFF) { 607 if (lfd->lfd_pos == MDS_DIR_END_OFF) {
@@ -715,10 +715,9 @@ int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
715 break; 715 break;
716 } 716 }
717 default: { 717 default: {
718 CDEBUG(D_IOCTL, "bad userland LOV MAGIC:" 718 CDEBUG(D_IOCTL, "bad userland LOV MAGIC: %#08x != %#08x nor %#08x\n",
719 " %#08x != %#08x nor %#08x\n", 719 lump->lmm_magic, LOV_USER_MAGIC_V1,
720 lump->lmm_magic, LOV_USER_MAGIC_V1, 720 LOV_USER_MAGIC_V3);
721 LOV_USER_MAGIC_V3);
722 return -EINVAL; 721 return -EINVAL;
723 } 722 }
724 } 723 }
@@ -814,8 +813,8 @@ int ll_dir_getstripe(struct inode *inode, struct lov_mds_md **lmmp,
814 rc = md_getattr(sbi->ll_md_exp, op_data, &req); 813 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
815 ll_finish_md_op_data(op_data); 814 ll_finish_md_op_data(op_data);
816 if (rc < 0) { 815 if (rc < 0) {
817 CDEBUG(D_INFO, "md_getattr failed on inode " 816 CDEBUG(D_INFO, "md_getattr failed on inode %lu/%u: rc %d\n",
818 "%lu/%u: rc %d\n", inode->i_ino, 817 inode->i_ino,
819 inode->i_generation, rc); 818 inode->i_generation, rc);
820 goto out; 819 goto out;
821 } 820 }
@@ -1013,8 +1012,7 @@ static int ll_ioc_copy_end(struct super_block *sb, struct hsm_copy *copy)
1013 copy->hc_hai.hai_action == HSMA_ARCHIVE); 1012 copy->hc_hai.hai_action == HSMA_ARCHIVE);
1014 iput(inode); 1013 iput(inode);
1015 if (rc) { 1014 if (rc) {
1016 CDEBUG(D_HSM, "Could not read file data version. " 1015 CDEBUG(D_HSM, "Could not read file data version. Request could not be confirmed.\n");
1017 "Request could not be confirmed.\n");
1018 if (hpk.hpk_errval == 0) 1016 if (hpk.hpk_errval == 0)
1019 hpk.hpk_errval = -rc; 1017 hpk.hpk_errval = -rc;
1020 goto progress; 1018 goto progress;
@@ -1028,8 +1026,7 @@ static int ll_ioc_copy_end(struct super_block *sb, struct hsm_copy *copy)
1028 * to check anyway. */ 1026 * to check anyway. */
1029 if ((copy->hc_hai.hai_action == HSMA_ARCHIVE) && 1027 if ((copy->hc_hai.hai_action == HSMA_ARCHIVE) &&
1030 (copy->hc_data_version != data_version)) { 1028 (copy->hc_data_version != data_version)) {
1031 CDEBUG(D_HSM, "File data version mismatched. " 1029 CDEBUG(D_HSM, "File data version mismatched. File content was changed during archiving. "
1032 "File content was changed during archiving. "
1033 DFID", start:%#llx current:%#llx\n", 1030 DFID", start:%#llx current:%#llx\n",
1034 PFID(&copy->hc_hai.hai_fid), 1031 PFID(&copy->hc_hai.hai_fid),
1035 copy->hc_data_version, data_version); 1032 copy->hc_data_version, data_version);
@@ -1384,7 +1381,7 @@ lmv_out_free:
1384 if (copy_from_user(lumv1, lumv1p, sizeof(*lumv1))) 1381 if (copy_from_user(lumv1, lumv1p, sizeof(*lumv1)))
1385 return -EFAULT; 1382 return -EFAULT;
1386 1383
1387 if ((lumv1->lmm_magic == LOV_USER_MAGIC_V3) ) { 1384 if (lumv1->lmm_magic == LOV_USER_MAGIC_V3) {
1388 if (copy_from_user(&lumv3, lumv3p, sizeof(lumv3))) 1385 if (copy_from_user(&lumv3, lumv3p, sizeof(lumv3)))
1389 return -EFAULT; 1386 return -EFAULT;
1390 } 1387 }
@@ -1509,8 +1506,7 @@ out_rmdir:
1509 cmd == LL_IOC_MDC_GETINFO)) { 1506 cmd == LL_IOC_MDC_GETINFO)) {
1510 rc = 0; 1507 rc = 0;
1511 goto skip_lmm; 1508 goto skip_lmm;
1512 } 1509 } else
1513 else
1514 goto out_req; 1510 goto out_req;
1515 } 1511 }
1516 1512
@@ -1694,64 +1690,6 @@ out_poll:
1694 OBD_FREE_PTR(check); 1690 OBD_FREE_PTR(check);
1695 return rc; 1691 return rc;
1696 } 1692 }
1697#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 50, 0)
1698 case LL_IOC_QUOTACTL_18: {
1699 /* copy the old 1.x quota struct for internal use, then copy
1700 * back into old format struct. For 1.8 compatibility. */
1701 struct if_quotactl_18 *qctl_18;
1702 struct if_quotactl *qctl_20;
1703
1704 qctl_18 = kzalloc(sizeof(*qctl_18), GFP_NOFS);
1705 if (!qctl_18)
1706 return -ENOMEM;
1707
1708 qctl_20 = kzalloc(sizeof(*qctl_20), GFP_NOFS);
1709 if (!qctl_20) {
1710 rc = -ENOMEM;
1711 goto out_quotactl_18;
1712 }
1713
1714 if (copy_from_user(qctl_18, (void *)arg, sizeof(*qctl_18))) {
1715 rc = -ENOMEM;
1716 goto out_quotactl_20;
1717 }
1718
1719 QCTL_COPY(qctl_20, qctl_18);
1720 qctl_20->qc_idx = 0;
1721
1722 /* XXX: dqb_valid was borrowed as a flag to mark that
1723 * only mds quota is wanted */
1724 if (qctl_18->qc_cmd == Q_GETQUOTA &&
1725 qctl_18->qc_dqblk.dqb_valid) {
1726 qctl_20->qc_valid = QC_MDTIDX;
1727 qctl_20->qc_dqblk.dqb_valid = 0;
1728 } else if (qctl_18->obd_uuid.uuid[0] != '\0') {
1729 qctl_20->qc_valid = QC_UUID;
1730 qctl_20->obd_uuid = qctl_18->obd_uuid;
1731 } else {
1732 qctl_20->qc_valid = QC_GENERAL;
1733 }
1734
1735 rc = quotactl_ioctl(sbi, qctl_20);
1736
1737 if (rc == 0) {
1738 QCTL_COPY(qctl_18, qctl_20);
1739 qctl_18->obd_uuid = qctl_20->obd_uuid;
1740
1741 if (copy_to_user((void *)arg, qctl_18,
1742 sizeof(*qctl_18)))
1743 rc = -EFAULT;
1744 }
1745
1746out_quotactl_20:
1747 OBD_FREE_PTR(qctl_20);
1748out_quotactl_18:
1749 OBD_FREE_PTR(qctl_18);
1750 return rc;
1751 }
1752#else
1753#warning "remove old LL_IOC_QUOTACTL_18 compatibility code"
1754#endif /* LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 50, 0) */
1755 case LL_IOC_QUOTACTL: { 1693 case LL_IOC_QUOTACTL: {
1756 struct if_quotactl *qctl; 1694 struct if_quotactl *qctl;
1757 1695
diff --git a/drivers/staging/lustre/lustre/llite/file.c b/drivers/staging/lustre/lustre/llite/file.c
index a2ae9a68a9a0..35a2df01528c 100644
--- a/drivers/staging/lustre/lustre/llite/file.c
+++ b/drivers/staging/lustre/lustre/llite/file.c
@@ -170,8 +170,8 @@ static int ll_close_inode_openhandle(struct obd_export *md_exp,
170 * OSTs and send setattr to back to MDS. */ 170 * OSTs and send setattr to back to MDS. */
171 rc = ll_som_update(inode, op_data); 171 rc = ll_som_update(inode, op_data);
172 if (rc) { 172 if (rc) {
173 CERROR("inode %lu mdc Size-on-MDS update failed: " 173 CERROR("inode %lu mdc Size-on-MDS update failed: rc = %d\n",
174 "rc = %d\n", inode->i_ino, rc); 174 inode->i_ino, rc);
175 rc = 0; 175 rc = 0;
176 } 176 }
177 } else if (rc) { 177 } else if (rc) {
@@ -247,7 +247,7 @@ int ll_md_real_close(struct inode *inode, fmode_t fmode)
247 return 0; 247 return 0;
248 } 248 }
249 249
250 och=*och_p; 250 och = *och_p;
251 *och_p = NULL; 251 *och_p = NULL;
252 mutex_unlock(&lli->lli_och_mutex); 252 mutex_unlock(&lli->lli_och_mutex);
253 253
@@ -358,7 +358,7 @@ int ll_file_release(struct inode *inode, struct file *file)
358 fd = LUSTRE_FPRIVATE(file); 358 fd = LUSTRE_FPRIVATE(file);
359 LASSERT(fd != NULL); 359 LASSERT(fd != NULL);
360 360
361 /* The last ref on @file, maybe not the the owner pid of statahead. 361 /* The last ref on @file, maybe not the owner pid of statahead.
362 * Different processes can open the same dir, "ll_opendir_key" means: 362 * Different processes can open the same dir, "ll_opendir_key" means:
363 * it is me that should stop the statahead thread. */ 363 * it is me that should stop the statahead thread. */
364 if (S_ISDIR(inode->i_mode) && lli->lli_opendir_key == fd && 364 if (S_ISDIR(inode->i_mode) && lli->lli_opendir_key == fd &&
@@ -975,8 +975,8 @@ int ll_inode_getattr(struct inode *inode, struct obdo *obdo,
975 struct ost_id *oi = lsm ? &lsm->lsm_oi : &obdo->o_oi; 975 struct ost_id *oi = lsm ? &lsm->lsm_oi : &obdo->o_oi;
976 976
977 obdo_refresh_inode(inode, obdo, obdo->o_valid); 977 obdo_refresh_inode(inode, obdo, obdo->o_valid);
978 CDEBUG(D_INODE, "objid "DOSTID" size %llu, blocks %llu," 978 CDEBUG(D_INODE, "objid " DOSTID " size %llu, blocks %llu, blksize %lu\n",
979 " blksize %lu\n", POSTID(oi), i_size_read(inode), 979 POSTID(oi), i_size_read(inode),
980 (unsigned long long)inode->i_blocks, 980 (unsigned long long)inode->i_blocks,
981 1UL << inode->i_blkbits); 981 1UL << inode->i_blkbits);
982 } 982 }
@@ -1403,8 +1403,8 @@ int ll_lov_getstripe_ea_info(struct inode *inode, const char *filename,
1403 rc = md_getattr_name(sbi->ll_md_exp, op_data, &req); 1403 rc = md_getattr_name(sbi->ll_md_exp, op_data, &req);
1404 ll_finish_md_op_data(op_data); 1404 ll_finish_md_op_data(op_data);
1405 if (rc < 0) { 1405 if (rc < 0) {
1406 CDEBUG(D_INFO, "md_getattr_name failed " 1406 CDEBUG(D_INFO, "md_getattr_name failed on %s: rc %d\n",
1407 "on %s: rc %d\n", filename, rc); 1407 filename, rc);
1408 goto out; 1408 goto out;
1409 } 1409 }
1410 1410
@@ -2221,8 +2221,8 @@ ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2221 if (cmd == LL_IOC_SETFLAGS) { 2221 if (cmd == LL_IOC_SETFLAGS) {
2222 if ((flags & LL_FILE_IGNORE_LOCK) && 2222 if ((flags & LL_FILE_IGNORE_LOCK) &&
2223 !(file->f_flags & O_DIRECT)) { 2223 !(file->f_flags & O_DIRECT)) {
2224 CERROR("%s: unable to disable locking on " 2224 CERROR("%s: unable to disable locking on non-O_DIRECT file\n",
2225 "non-O_DIRECT file\n", current->comm); 2225 current->comm);
2226 return -EINVAL; 2226 return -EINVAL;
2227 } 2227 }
2228 2228
@@ -2848,7 +2848,7 @@ ldlm_mode_t ll_take_md_lock(struct inode *inode, __u64 bits,
2848 struct lustre_handle *lockh, __u64 flags, 2848 struct lustre_handle *lockh, __u64 flags,
2849 ldlm_mode_t mode) 2849 ldlm_mode_t mode)
2850{ 2850{
2851 ldlm_policy_data_t policy = { .l_inodebits = {bits}}; 2851 ldlm_policy_data_t policy = { .l_inodebits = {bits} };
2852 struct lu_fid *fid; 2852 struct lu_fid *fid;
2853 ldlm_mode_t rc; 2853 ldlm_mode_t rc;
2854 2854
diff --git a/drivers/staging/lustre/lustre/llite/llite_capa.c b/drivers/staging/lustre/lustre/llite/llite_capa.c
index b1e39ee412cd..aec9a44120c0 100644
--- a/drivers/staging/lustre/lustre/llite/llite_capa.c
+++ b/drivers/staging/lustre/lustre/llite/llite_capa.c
@@ -540,8 +540,7 @@ static int ll_update_capa(struct obd_capa *ocapa, struct lustre_capa *capa)
540 if (rc == -EIO && !capa_is_expired(ocapa)) { 540 if (rc == -EIO && !capa_is_expired(ocapa)) {
541 delay_capa_renew(ocapa, 120); 541 delay_capa_renew(ocapa, 120);
542 DEBUG_CAPA(D_ERROR, &ocapa->c_capa, 542 DEBUG_CAPA(D_ERROR, &ocapa->c_capa,
543 "renewal failed: -EIO, " 543 "renewal failed: -EIO, retry in 2 mins");
544 "retry in 2 mins");
545 ll_capa_renewal_retries++; 544 ll_capa_renewal_retries++;
546 goto retry; 545 goto retry;
547 } else { 546 } else {
diff --git a/drivers/staging/lustre/lustre/llite/llite_close.c b/drivers/staging/lustre/lustre/llite/llite_close.c
index 84e0003f2daf..21b4a5026776 100644
--- a/drivers/staging/lustre/lustre/llite/llite_close.c
+++ b/drivers/staging/lustre/lustre/llite/llite_close.c
@@ -90,8 +90,7 @@ void ll_queue_done_writing(struct inode *inode, unsigned long flags)
90 struct ll_close_queue *lcq = ll_i2sbi(inode)->ll_lcq; 90 struct ll_close_queue *lcq = ll_i2sbi(inode)->ll_lcq;
91 91
92 if (lli->lli_flags & LLIF_MDS_SIZE_LOCK) 92 if (lli->lli_flags & LLIF_MDS_SIZE_LOCK)
93 CWARN("ino %lu/%u(flags %u) som valid it just after " 93 CWARN("ino %lu/%u(flags %u) som valid it just after recovery\n",
94 "recovery\n",
95 inode->i_ino, inode->i_generation, 94 inode->i_ino, inode->i_generation,
96 lli->lli_flags); 95 lli->lli_flags);
97 /* DONE_WRITING is allowed and inode has no dirty page. */ 96 /* DONE_WRITING is allowed and inode has no dirty page. */
@@ -124,8 +123,8 @@ void ll_done_writing_attr(struct inode *inode, struct md_op_data *op_data)
124 op_data->op_flags |= MF_SOM_CHANGE; 123 op_data->op_flags |= MF_SOM_CHANGE;
125 /* Check if Size-on-MDS attributes are valid. */ 124 /* Check if Size-on-MDS attributes are valid. */
126 if (lli->lli_flags & LLIF_MDS_SIZE_LOCK) 125 if (lli->lli_flags & LLIF_MDS_SIZE_LOCK)
127 CERROR("ino %lu/%u(flags %u) som valid it just after " 126 CERROR("ino %lu/%u(flags %u) som valid it just after recovery\n",
128 "recovery\n", inode->i_ino, inode->i_generation, 127 inode->i_ino, inode->i_generation,
129 lli->lli_flags); 128 lli->lli_flags);
130 129
131 if (!cl_local_size(inode)) { 130 if (!cl_local_size(inode)) {
@@ -218,8 +217,8 @@ int ll_som_update(struct inode *inode, struct md_op_data *op_data)
218 217
219 LASSERT(op_data != NULL); 218 LASSERT(op_data != NULL);
220 if (lli->lli_flags & LLIF_MDS_SIZE_LOCK) 219 if (lli->lli_flags & LLIF_MDS_SIZE_LOCK)
221 CERROR("ino %lu/%u(flags %u) som valid it just after " 220 CERROR("ino %lu/%u(flags %u) som valid it just after recovery\n",
222 "recovery\n", inode->i_ino, inode->i_generation, 221 inode->i_ino, inode->i_generation,
223 lli->lli_flags); 222 lli->lli_flags);
224 223
225 OBDO_ALLOC(oa); 224 OBDO_ALLOC(oa);
@@ -238,9 +237,8 @@ int ll_som_update(struct inode *inode, struct md_op_data *op_data)
238 if (rc) { 237 if (rc) {
239 oa->o_valid = 0; 238 oa->o_valid = 0;
240 if (rc != -ENOENT) 239 if (rc != -ENOENT)
241 CERROR("inode_getattr failed (%d): unable to " 240 CERROR("inode_getattr failed (%d): unable to send a Size-on-MDS attribute update for inode %lu/%u\n",
242 "send a Size-on-MDS attribute update " 241 rc, inode->i_ino,
243 "for inode %lu/%u\n", rc, inode->i_ino,
244 inode->i_generation); 242 inode->i_generation);
245 } else { 243 } else {
246 CDEBUG(D_INODE, "Size-on-MDS update on "DFID"\n", 244 CDEBUG(D_INODE, "Size-on-MDS update on "DFID"\n",
diff --git a/drivers/staging/lustre/lustre/llite/llite_internal.h b/drivers/staging/lustre/lustre/llite/llite_internal.h
index 77d1c12704b4..37306e0c7aad 100644
--- a/drivers/staging/lustre/lustre/llite/llite_internal.h
+++ b/drivers/staging/lustre/lustre/llite/llite_internal.h
@@ -1435,8 +1435,8 @@ static inline void ll_set_lock_data(struct obd_export *exp, struct inode *inode,
1435 * case the dcache being cleared */ 1435 * case the dcache being cleared */
1436 if (it->d.lustre.it_remote_lock_mode) { 1436 if (it->d.lustre.it_remote_lock_mode) {
1437 handle.cookie = it->d.lustre.it_remote_lock_handle; 1437 handle.cookie = it->d.lustre.it_remote_lock_handle;
1438 CDEBUG(D_DLMTRACE, "setting l_data to inode %p" 1438 CDEBUG(D_DLMTRACE, "setting l_data to inode %p(%lu/%u) for remote lock %#llx\n",
1439 "(%lu/%u) for remote lock %#llx\n", inode, 1439 inode,
1440 inode->i_ino, inode->i_generation, 1440 inode->i_ino, inode->i_generation,
1441 handle.cookie); 1441 handle.cookie);
1442 md_set_lock_data(exp, &handle.cookie, inode, NULL); 1442 md_set_lock_data(exp, &handle.cookie, inode, NULL);
@@ -1444,8 +1444,8 @@ static inline void ll_set_lock_data(struct obd_export *exp, struct inode *inode,
1444 1444
1445 handle.cookie = it->d.lustre.it_lock_handle; 1445 handle.cookie = it->d.lustre.it_lock_handle;
1446 1446
1447 CDEBUG(D_DLMTRACE, "setting l_data to inode %p (%lu/%u)" 1447 CDEBUG(D_DLMTRACE, "setting l_data to inode %p (%lu/%u) for lock %#llx\n",
1448 " for lock %#llx\n", inode, inode->i_ino, 1448 inode, inode->i_ino,
1449 inode->i_generation, handle.cookie); 1449 inode->i_generation, handle.cookie);
1450 1450
1451 md_set_lock_data(exp, &handle.cookie, inode, 1451 md_set_lock_data(exp, &handle.cookie, inode,
@@ -1489,8 +1489,8 @@ static inline void __d_lustre_invalidate(struct dentry *dentry)
1489 */ 1489 */
1490static inline void d_lustre_invalidate(struct dentry *dentry, int nested) 1490static inline void d_lustre_invalidate(struct dentry *dentry, int nested)
1491{ 1491{
1492 CDEBUG(D_DENTRY, "invalidate dentry %pd (%p) parent %p inode %p " 1492 CDEBUG(D_DENTRY, "invalidate dentry %pd (%p) parent %p inode %p refc %d\n",
1493 "refc %d\n", dentry, dentry, 1493 dentry, dentry,
1494 dentry->d_parent, dentry->d_inode, d_count(dentry)); 1494 dentry->d_parent, dentry->d_inode, d_count(dentry));
1495 1495
1496 spin_lock_nested(&dentry->d_lock, 1496 spin_lock_nested(&dentry->d_lock,
@@ -1509,24 +1509,6 @@ static inline void d_lustre_revalidate(struct dentry *dentry)
1509 spin_unlock(&dentry->d_lock); 1509 spin_unlock(&dentry->d_lock);
1510} 1510}
1511 1511
1512#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 50, 0)
1513/* Compatibility for old (1.8) compiled userspace quota code */
1514struct if_quotactl_18 {
1515 __u32 qc_cmd;
1516 __u32 qc_type;
1517 __u32 qc_id;
1518 __u32 qc_stat;
1519 struct obd_dqinfo qc_dqinfo;
1520 struct obd_dqblk qc_dqblk;
1521 char obd_type[16];
1522 struct obd_uuid obd_uuid;
1523};
1524#define LL_IOC_QUOTACTL_18 _IOWR('f', 162, struct if_quotactl_18 *)
1525/* End compatibility for old (1.8) compiled userspace quota code */
1526#else
1527#warning "remove old LL_IOC_QUOTACTL_18 compatibility code"
1528#endif /* LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 50, 0) */
1529
1530enum { 1512enum {
1531 LL_LAYOUT_GEN_NONE = ((__u32)-2), /* layout lock was cancelled */ 1513 LL_LAYOUT_GEN_NONE = ((__u32)-2), /* layout lock was cancelled */
1532 LL_LAYOUT_GEN_EMPTY = ((__u32)-1) /* for empty layout */ 1514 LL_LAYOUT_GEN_EMPTY = ((__u32)-1) /* for empty layout */
diff --git a/drivers/staging/lustre/lustre/llite/llite_lib.c b/drivers/staging/lustre/lustre/llite/llite_lib.c
index 7b6b9e2e0102..6e423aa6a6e4 100644
--- a/drivers/staging/lustre/lustre/llite/llite_lib.c
+++ b/drivers/staging/lustre/lustre/llite/llite_lib.c
@@ -250,12 +250,11 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
250 250
251 data->ocd_brw_size = MD_MAX_BRW_SIZE; 251 data->ocd_brw_size = MD_MAX_BRW_SIZE;
252 252
253 err = obd_connect(NULL, &sbi->ll_md_exp, obd, &sbi->ll_sb_uuid, data, NULL); 253 err = obd_connect(NULL, &sbi->ll_md_exp, obd, &sbi->ll_sb_uuid,
254 data, NULL);
254 if (err == -EBUSY) { 255 if (err == -EBUSY) {
255 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing " 256 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing recovery, of which this client is not a part. Please wait for recovery to complete, abort, or time out.\n",
256 "recovery, of which this client is not a " 257 md);
257 "part. Please wait for recovery to complete,"
258 " abort, or time out.\n", md);
259 goto out; 258 goto out;
260 } else if (err) { 259 } else if (err) {
261 CERROR("cannot connect to %s: rc = %d\n", md, err); 260 CERROR("cannot connect to %s: rc = %d\n", md, err);
@@ -267,8 +266,8 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
267 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp, 266 err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
268 LUSTRE_SEQ_METADATA); 267 LUSTRE_SEQ_METADATA);
269 if (err) { 268 if (err) {
270 CERROR("%s: Can't init metadata layer FID infrastructure, " 269 CERROR("%s: Can't init metadata layer FID infrastructure, rc = %d\n",
271 "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err); 270 sbi->ll_md_exp->exp_obd->obd_name, err);
272 goto out_md; 271 goto out_md;
273 } 272 }
274 273
@@ -296,10 +295,7 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
296 buf = kzalloc(PAGE_CACHE_SIZE, GFP_KERNEL); 295 buf = kzalloc(PAGE_CACHE_SIZE, GFP_KERNEL);
297 obd_connect_flags2str(buf, PAGE_CACHE_SIZE, 296 obd_connect_flags2str(buf, PAGE_CACHE_SIZE,
298 valid ^ CLIENT_CONNECT_MDT_REQD, ","); 297 valid ^ CLIENT_CONNECT_MDT_REQD, ",");
299 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support " 298 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support feature(s) needed for correct operation of this client (%s). Please upgrade server or downgrade client.\n",
300 "feature(s) needed for correct operation "
301 "of this client (%s). Please upgrade "
302 "server or downgrade client.\n",
303 sbi->ll_md_exp->exp_obd->obd_name, buf); 299 sbi->ll_md_exp->exp_obd->obd_name, buf);
304 OBD_FREE(buf, PAGE_CACHE_SIZE); 300 OBD_FREE(buf, PAGE_CACHE_SIZE);
305 err = -EPROTO; 301 err = -EPROTO;
@@ -325,8 +321,7 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
325 321
326 if ((sbi->ll_flags & LL_SBI_USER_XATTR) && 322 if ((sbi->ll_flags & LL_SBI_USER_XATTR) &&
327 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) { 323 !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
328 LCONSOLE_INFO("Disabling user_xattr feature because " 324 LCONSOLE_INFO("Disabling user_xattr feature because it is not supported on the server\n");
329 "it is not supported on the server\n");
330 sbi->ll_flags &= ~LL_SBI_USER_XATTR; 325 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
331 } 326 }
332 327
@@ -351,8 +346,7 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
351 } else { 346 } else {
352 if (sbi->ll_flags & LL_SBI_RMT_CLIENT) { 347 if (sbi->ll_flags & LL_SBI_RMT_CLIENT) {
353 sbi->ll_flags &= ~LL_SBI_RMT_CLIENT; 348 sbi->ll_flags &= ~LL_SBI_RMT_CLIENT;
354 LCONSOLE_INFO("client claims to be remote, but server " 349 LCONSOLE_INFO("client claims to be remote, but server rejected, forced to be local.\n");
355 "rejected, forced to be local.\n");
356 } 350 }
357 } 351 }
358 352
@@ -429,8 +423,8 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
429 if (sbi->ll_flags & LL_SBI_RMT_CLIENT) 423 if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
430 data->ocd_connect_flags |= OBD_CONNECT_RMT_CLIENT_FORCE; 424 data->ocd_connect_flags |= OBD_CONNECT_RMT_CLIENT_FORCE;
431 425
432 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d " 426 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d ocd_grant: %d\n",
433 "ocd_grant: %d\n", data->ocd_connect_flags, 427 data->ocd_connect_flags,
434 data->ocd_version, data->ocd_grant); 428 data->ocd_version, data->ocd_grant);
435 429
436 obd->obd_upcall.onu_owner = &sbi->ll_lco; 430 obd->obd_upcall.onu_owner = &sbi->ll_lco;
@@ -441,10 +435,8 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
441 err = obd_connect(NULL, &sbi->ll_dt_exp, obd, &sbi->ll_sb_uuid, data, 435 err = obd_connect(NULL, &sbi->ll_dt_exp, obd, &sbi->ll_sb_uuid, data,
442 NULL); 436 NULL);
443 if (err == -EBUSY) { 437 if (err == -EBUSY) {
444 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing " 438 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing recovery, of which this client is not a part. Please wait for recovery to complete, abort, or time out.\n",
445 "recovery, of which this client is not a " 439 dt);
446 "part. Please wait for recovery to "
447 "complete, abort, or time out.\n", dt);
448 goto out_md; 440 goto out_md;
449 } else if (err) { 441 } else if (err) {
450 CERROR("%s: Cannot connect to %s: rc = %d\n", 442 CERROR("%s: Cannot connect to %s: rc = %d\n",
@@ -457,8 +449,8 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
457 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp, 449 err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
458 LUSTRE_SEQ_METADATA); 450 LUSTRE_SEQ_METADATA);
459 if (err) { 451 if (err) {
460 CERROR("%s: Can't init data layer FID infrastructure, " 452 CERROR("%s: Can't init data layer FID infrastructure, rc = %d\n",
461 "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err); 453 sbi->ll_dt_exp->exp_obd->obd_name, err);
462 goto out_dt; 454 goto out_dt;
463 } 455 }
464 456
@@ -698,9 +690,9 @@ void lustre_dump_dentry(struct dentry *dentry, int recur)
698 list_for_each(tmp, &dentry->d_subdirs) 690 list_for_each(tmp, &dentry->d_subdirs)
699 subdirs++; 691 subdirs++;
700 692
701 CERROR("dentry %p dump: name=%pd parent=%p, inode=%p, count=%u," 693 CERROR("dentry %p dump: name=%pd parent=%pd (%p), inode=%p, count=%u, flags=0x%x, fsdata=%p, %d subdirs\n",
702 " flags=0x%x, fsdata=%p, %d subdirs\n", dentry, dentry, 694 dentry, dentry, dentry->d_parent, dentry->d_parent,
703 dentry->d_parent, dentry->d_inode, d_count(dentry), 695 dentry->d_inode, d_count(dentry),
704 dentry->d_flags, dentry->d_fsdata, subdirs); 696 dentry->d_flags, dentry->d_fsdata, subdirs);
705 if (dentry->d_inode != NULL) 697 if (dentry->d_inode != NULL)
706 ll_dump_inode(dentry->d_inode); 698 ll_dump_inode(dentry->d_inode);
@@ -710,6 +702,7 @@ void lustre_dump_dentry(struct dentry *dentry, int recur)
710 702
711 list_for_each(tmp, &dentry->d_subdirs) { 703 list_for_each(tmp, &dentry->d_subdirs) {
712 struct dentry *d = list_entry(tmp, struct dentry, d_child); 704 struct dentry *d = list_entry(tmp, struct dentry, d_child);
705
713 lustre_dump_dentry(d, recur - 1); 706 lustre_dump_dentry(d, recur - 1);
714 } 707 }
715} 708}
@@ -754,9 +747,9 @@ void ll_kill_super(struct super_block *sb)
754 return; 747 return;
755 748
756 sbi = ll_s2sbi(sb); 749 sbi = ll_s2sbi(sb);
757 /* we need to restore s_dev from changed for clustered NFS before put_super 750 /* we need to restore s_dev from changed for clustered NFS before
758 * because new kernels have cached s_dev and change sb->s_dev in 751 * put_super because new kernels have cached s_dev and change sb->s_dev
759 * put_super not affected real removing devices */ 752 * in put_super not affected real removing devices */
760 if (sbi) { 753 if (sbi) {
761 sb->s_dev = sbi->ll_sdev_orig; 754 sb->s_dev = sbi->ll_sdev_orig;
762 sbi->ll_umounting = 1; 755 sbi->ll_umounting = 1;
@@ -814,25 +807,6 @@ static int ll_options(char *options, int *flags)
814 *flags &= ~tmp; 807 *flags &= ~tmp;
815 goto next; 808 goto next;
816 } 809 }
817#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 5, 50, 0)
818 tmp = ll_set_opt("acl", s1, LL_SBI_ACL);
819 if (tmp) {
820 /* Ignore deprecated mount option. The client will
821 * always try to mount with ACL support, whether this
822 * is used depends on whether server supports it. */
823 LCONSOLE_ERROR_MSG(0x152, "Ignoring deprecated "
824 "mount option 'acl'.\n");
825 goto next;
826 }
827 tmp = ll_set_opt("noacl", s1, LL_SBI_ACL);
828 if (tmp) {
829 LCONSOLE_ERROR_MSG(0x152, "Ignoring deprecated "
830 "mount option 'noacl'.\n");
831 goto next;
832 }
833#else
834#warning "{no}acl options have been deprecated since 1.8, please remove them"
835#endif
836 tmp = ll_set_opt("remote_client", s1, LL_SBI_RMT_CLIENT); 810 tmp = ll_set_opt("remote_client", s1, LL_SBI_RMT_CLIENT);
837 if (tmp) { 811 if (tmp) {
838 *flags |= tmp; 812 *flags |= tmp;
@@ -1038,9 +1012,8 @@ int ll_fill_super(struct super_block *sb, struct vfsmount *mnt)
1038 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */ 1012 /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1039 lprof = class_get_profile(profilenm); 1013 lprof = class_get_profile(profilenm);
1040 if (lprof == NULL) { 1014 if (lprof == NULL) {
1041 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be" 1015 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be read from the MGS. Does that filesystem exist?\n",
1042 " read from the MGS. Does that filesystem " 1016 profilenm);
1043 "exist?\n", profilenm);
1044 err = -EINVAL; 1017 err = -EINVAL;
1045 goto out_free; 1018 goto out_free;
1046 } 1019 }
@@ -1119,9 +1092,8 @@ void ll_put_super(struct super_block *sb)
1119 } 1092 }
1120 1093
1121 next = 0; 1094 next = 0;
1122 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)) !=NULL) { 1095 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
1123 class_manual_cleanup(obd); 1096 class_manual_cleanup(obd);
1124 }
1125 1097
1126 if (sbi->ll_flags & LL_SBI_VERBOSE) 1098 if (sbi->ll_flags & LL_SBI_VERBOSE)
1127 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : ""); 1099 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
@@ -1150,14 +1122,14 @@ struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1150 lock_res_and_lock(lock); 1122 lock_res_and_lock(lock);
1151 if (lock->l_resource->lr_lvb_inode) { 1123 if (lock->l_resource->lr_lvb_inode) {
1152 struct ll_inode_info *lli; 1124 struct ll_inode_info *lli;
1125
1153 lli = ll_i2info(lock->l_resource->lr_lvb_inode); 1126 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1154 if (lli->lli_inode_magic == LLI_INODE_MAGIC) { 1127 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1155 inode = igrab(lock->l_resource->lr_lvb_inode); 1128 inode = igrab(lock->l_resource->lr_lvb_inode);
1156 } else { 1129 } else {
1157 inode = lock->l_resource->lr_lvb_inode; 1130 inode = lock->l_resource->lr_lvb_inode;
1158 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO : 1131 LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ? D_INFO :
1159 D_WARNING, lock, "lr_lvb_inode %p is " 1132 D_WARNING, lock, "lr_lvb_inode %p is bogus: magic %08x",
1160 "bogus: magic %08x",
1161 lock->l_resource->lr_lvb_inode, 1133 lock->l_resource->lr_lvb_inode,
1162 lli->lli_inode_magic); 1134 lli->lli_inode_magic);
1163 inode = NULL; 1135 inode = NULL;
@@ -1730,11 +1702,11 @@ void ll_update_inode(struct inode *inode, struct lustre_md *md)
1730 if (body->valid & OBD_MD_FLTYPE) 1702 if (body->valid & OBD_MD_FLTYPE)
1731 inode->i_mode = (inode->i_mode & ~S_IFMT)|(body->mode & S_IFMT); 1703 inode->i_mode = (inode->i_mode & ~S_IFMT)|(body->mode & S_IFMT);
1732 LASSERT(inode->i_mode != 0); 1704 LASSERT(inode->i_mode != 0);
1733 if (S_ISREG(inode->i_mode)) { 1705 if (S_ISREG(inode->i_mode))
1734 inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS + 1, LL_MAX_BLKSIZE_BITS); 1706 inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS + 1,
1735 } else { 1707 LL_MAX_BLKSIZE_BITS);
1708 else
1736 inode->i_blkbits = inode->i_sb->s_blocksize_bits; 1709 inode->i_blkbits = inode->i_sb->s_blocksize_bits;
1737 }
1738 if (body->valid & OBD_MD_FLUID) 1710 if (body->valid & OBD_MD_FLUID)
1739 inode->i_uid = make_kuid(&init_user_ns, body->uid); 1711 inode->i_uid = make_kuid(&init_user_ns, body->uid);
1740 if (body->valid & OBD_MD_FLGID) 1712 if (body->valid & OBD_MD_FLGID)
@@ -1778,9 +1750,7 @@ void ll_update_inode(struct inode *inode, struct lustre_md *md)
1778 if (lli->lli_flags & (LLIF_DONE_WRITING | 1750 if (lli->lli_flags & (LLIF_DONE_WRITING |
1779 LLIF_EPOCH_PENDING | 1751 LLIF_EPOCH_PENDING |
1780 LLIF_SOM_DIRTY)) { 1752 LLIF_SOM_DIRTY)) {
1781 CERROR("ino %lu flags %u still has " 1753 CERROR("ino %lu flags %u still has size authority! do not trust the size got from MDS\n",
1782 "size authority! do not trust "
1783 "the size got from MDS\n",
1784 inode->i_ino, lli->lli_flags); 1754 inode->i_ino, lli->lli_flags);
1785 } else { 1755 } else {
1786 /* Use old size assignment to avoid 1756 /* Use old size assignment to avoid
@@ -1848,6 +1818,7 @@ void ll_read_inode2(struct inode *inode, void *opaque)
1848 1818
1849 if (S_ISREG(inode->i_mode)) { 1819 if (S_ISREG(inode->i_mode)) {
1850 struct ll_sb_info *sbi = ll_i2sbi(inode); 1820 struct ll_sb_info *sbi = ll_i2sbi(inode);
1821
1851 inode->i_op = &ll_file_inode_operations; 1822 inode->i_op = &ll_file_inode_operations;
1852 inode->i_fop = sbi->ll_fop; 1823 inode->i_fop = sbi->ll_fop;
1853 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops; 1824 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
@@ -1878,11 +1849,10 @@ void ll_delete_inode(struct inode *inode)
1878 1849
1879 /* Workaround for LU-118 */ 1850 /* Workaround for LU-118 */
1880 if (inode->i_data.nrpages) { 1851 if (inode->i_data.nrpages) {
1881 TREE_READ_LOCK_IRQ(&inode->i_data); 1852 spin_lock_irq(&inode->i_data.tree_lock);
1882 TREE_READ_UNLOCK_IRQ(&inode->i_data); 1853 spin_unlock_irq(&inode->i_data.tree_lock);
1883 LASSERTF(inode->i_data.nrpages == 0, 1854 LASSERTF(inode->i_data.nrpages == 0,
1884 "inode=%lu/%u(%p) nrpages=%lu, see " 1855 "inode=%lu/%u(%p) nrpages=%lu, see http://jira.whamcloud.com/browse/LU-118\n",
1885 "http://jira.whamcloud.com/browse/LU-118\n",
1886 inode->i_ino, inode->i_generation, inode, 1856 inode->i_ino, inode->i_generation, inode,
1887 inode->i_data.nrpages); 1857 inode->i_data.nrpages);
1888 } 1858 }
@@ -2164,7 +2134,13 @@ int ll_obd_statfs(struct inode *inode, void *arg)
2164 __u32 flags; 2134 __u32 flags;
2165 int len = 0, rc; 2135 int len = 0, rc;
2166 2136
2167 if (!inode || !(sbi = ll_i2sbi(inode))) { 2137 if (!inode) {
2138 rc = -EINVAL;
2139 goto out_statfs;
2140 }
2141
2142 sbi = ll_i2sbi(inode);
2143 if (!sbi) {
2168 rc = -EINVAL; 2144 rc = -EINVAL;
2169 goto out_statfs; 2145 goto out_statfs;
2170 } 2146 }
@@ -2396,7 +2372,7 @@ char *ll_get_fsname(struct super_block *sb, char *buf, int buflen)
2396 return buf; 2372 return buf;
2397} 2373}
2398 2374
2399static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize) 2375static char *ll_d_path(struct dentry *dentry, char *buf, int bufsize)
2400{ 2376{
2401 char *path = NULL; 2377 char *path = NULL;
2402 2378
@@ -2426,8 +2402,8 @@ void ll_dirty_page_discard_warn(struct page *page, int ioret)
2426 } 2402 }
2427 2403
2428 CDEBUG(D_WARNING, 2404 CDEBUG(D_WARNING,
2429 "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted " 2405 "%s: dirty page discard: %s/fid: " DFID "/%s may get corrupted (rc %d)\n",
2430 "(rc %d)\n", ll_get_fsname(page->mapping->host->i_sb, NULL, 0), 2406 ll_get_fsname(page->mapping->host->i_sb, NULL, 0),
2431 s2lsi(page->mapping->host->i_sb)->lsi_lmd->lmd_dev, 2407 s2lsi(page->mapping->host->i_sb)->lsi_lmd->lmd_dev,
2432 PFID(&obj->cob_header.coh_lu.loh_fid), 2408 PFID(&obj->cob_header.coh_lu.loh_fid),
2433 (path && !IS_ERR(path)) ? path : "", ioret); 2409 (path && !IS_ERR(path)) ? path : "", ioret);
diff --git a/drivers/staging/lustre/lustre/llite/llite_mmap.c b/drivers/staging/lustre/lustre/llite/llite_mmap.c
index ba1c047ae927..479bf428780c 100644
--- a/drivers/staging/lustre/lustre/llite/llite_mmap.c
+++ b/drivers/staging/lustre/lustre/llite/llite_mmap.c
@@ -234,8 +234,7 @@ static int ll_page_mkwrite0(struct vm_area_struct *vma, struct page *vmpage,
234 */ 234 */
235 unlock_page(vmpage); 235 unlock_page(vmpage);
236 236
237 CDEBUG(D_MMAP, "Race on page_mkwrite %p/%lu, page has " 237 CDEBUG(D_MMAP, "Race on page_mkwrite %p/%lu, page has been written out, retry.\n",
238 "been written out, retry.\n",
239 vmpage, vmpage->index); 238 vmpage, vmpage->index);
240 239
241 *retry = true; 240 *retry = true;
@@ -366,8 +365,7 @@ restart:
366 vmf->page = NULL; 365 vmf->page = NULL;
367 366
368 if (!printed && ++count > 16) { 367 if (!printed && ++count > 16) {
369 CWARN("the page is under heavy contention," 368 CWARN("the page is under heavy contention, maybe your app(%s) needs revising :-)\n",
370 "maybe your app(%s) needs revising :-)\n",
371 current->comm); 369 current->comm);
372 printed = true; 370 printed = true;
373 } 371 }
@@ -393,8 +391,7 @@ static int ll_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
393 result = ll_page_mkwrite0(vma, vmf->page, &retry); 391 result = ll_page_mkwrite0(vma, vmf->page, &retry);
394 392
395 if (!printed && ++count > 16) { 393 if (!printed && ++count > 16) {
396 CWARN("app(%s): the page %lu of file %lu is under heavy" 394 CWARN("app(%s): the page %lu of file %lu is under heavy contention.\n",
397 " contention.\n",
398 current->comm, vmf->pgoff, 395 current->comm, vmf->pgoff,
399 file_inode(vma->vm_file)->i_ino); 396 file_inode(vma->vm_file)->i_ino);
400 printed = true; 397 printed = true;
diff --git a/drivers/staging/lustre/lustre/llite/llite_rmtacl.c b/drivers/staging/lustre/lustre/llite/llite_rmtacl.c
index 586f49a374ec..f4da156f3874 100644
--- a/drivers/staging/lustre/lustre/llite/llite_rmtacl.c
+++ b/drivers/staging/lustre/lustre/llite/llite_rmtacl.c
@@ -131,8 +131,8 @@ int rct_add(struct rmtacl_ctl_table *rct, pid_t key, int ops)
131 spin_lock(&rct->rct_lock); 131 spin_lock(&rct->rct_lock);
132 e = __rct_search(rct, key); 132 e = __rct_search(rct, key);
133 if (unlikely(e != NULL)) { 133 if (unlikely(e != NULL)) {
134 CWARN("Unexpected stale rmtacl_entry found: " 134 CWARN("Unexpected stale rmtacl_entry found: [key: %d] [ops: %d]\n",
135 "[key: %d] [ops: %d]\n", (int)key, ops); 135 (int)key, ops);
136 rce_free(e); 136 rce_free(e);
137 } 137 }
138 list_add_tail(&rce->rce_list, &rct->rct_entries[rce_hashfunc(key)]); 138 list_add_tail(&rce->rce_list, &rct->rct_entries[rce_hashfunc(key)]);
@@ -263,8 +263,7 @@ int ee_add(struct eacl_table *et, pid_t key, struct lu_fid *fid, int type,
263 spin_lock(&et->et_lock); 263 spin_lock(&et->et_lock);
264 e = __et_search_del(et, key, fid, type); 264 e = __et_search_del(et, key, fid, type);
265 if (unlikely(e != NULL)) { 265 if (unlikely(e != NULL)) {
266 CWARN("Unexpected stale eacl_entry found: " 266 CWARN("Unexpected stale eacl_entry found: [key: %d] [fid: " DFID "] [type: %d]\n",
267 "[key: %d] [fid: "DFID"] [type: %d]\n",
268 (int)key, PFID(fid), type); 267 (int)key, PFID(fid), type);
269 ee_free(e); 268 ee_free(e);
270 } 269 }
diff --git a/drivers/staging/lustre/lustre/llite/lloop.c b/drivers/staging/lustre/lustre/llite/lloop.c
index 9e31b789b790..031248840642 100644
--- a/drivers/staging/lustre/lustre/llite/lloop.c
+++ b/drivers/staging/lustre/lustre/llite/lloop.c
@@ -777,8 +777,8 @@ static int __init lloop_init(void)
777 777
778 if (max_loop < 1 || max_loop > 256) { 778 if (max_loop < 1 || max_loop > 256) {
779 max_loop = MAX_LOOP_DEFAULT; 779 max_loop = MAX_LOOP_DEFAULT;
780 CWARN("lloop: invalid max_loop (must be between" 780 CWARN("lloop: invalid max_loop (must be between 1 and 256), using default (%u)\n",
781 " 1 and 256), using default (%u)\n", max_loop); 781 max_loop);
782 } 782 }
783 783
784 lloop_major = register_blkdev(0, "lloop"); 784 lloop_major = register_blkdev(0, "lloop");
@@ -792,11 +792,11 @@ static int __init lloop_init(void)
792 if (ll_iocontrol_magic == NULL) 792 if (ll_iocontrol_magic == NULL)
793 goto out_mem1; 793 goto out_mem1;
794 794
795 loop_dev = kzalloc(max_loop * sizeof(*loop_dev), GFP_KERNEL); 795 loop_dev = kcalloc(max_loop, sizeof(*loop_dev), GFP_KERNEL);
796 if (!loop_dev) 796 if (!loop_dev)
797 goto out_mem1; 797 goto out_mem1;
798 798
799 disks = kzalloc(max_loop * sizeof(*disks), GFP_KERNEL); 799 disks = kcalloc(max_loop, sizeof(*disks), GFP_KERNEL);
800 if (!disks) 800 if (!disks)
801 goto out_mem2; 801 goto out_mem2;
802 802
diff --git a/drivers/staging/lustre/lustre/llite/lproc_llite.c b/drivers/staging/lustre/lustre/llite/lproc_llite.c
index 3b3df9f03422..e6a909e6faf0 100644
--- a/drivers/staging/lustre/lustre/llite/lproc_llite.c
+++ b/drivers/staging/lustre/lustre/llite/lproc_llite.c
@@ -227,8 +227,9 @@ static int ll_max_readahead_mb_seq_show(struct seq_file *m, void *v)
227 return lprocfs_seq_read_frac_helper(m, pages_number, mult); 227 return lprocfs_seq_read_frac_helper(m, pages_number, mult);
228} 228}
229 229
230static ssize_t ll_max_readahead_mb_seq_write(struct file *file, const char *buffer, 230static ssize_t ll_max_readahead_mb_seq_write(struct file *file,
231 size_t count, loff_t *off) 231 const char __user *buffer,
232 size_t count, loff_t *off)
232{ 233{
233 struct super_block *sb = ((struct seq_file *)file->private_data)->private; 234 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
234 struct ll_sb_info *sbi = ll_s2sbi(sb); 235 struct ll_sb_info *sbi = ll_s2sbi(sb);
@@ -269,7 +270,7 @@ static int ll_max_readahead_per_file_mb_seq_show(struct seq_file *m, void *v)
269} 270}
270 271
271static ssize_t ll_max_readahead_per_file_mb_seq_write(struct file *file, 272static ssize_t ll_max_readahead_per_file_mb_seq_write(struct file *file,
272 const char *buffer, 273 const char __user *buffer,
273 size_t count, loff_t *off) 274 size_t count, loff_t *off)
274{ 275{
275 struct super_block *sb = ((struct seq_file *)file->private_data)->private; 276 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
@@ -283,8 +284,7 @@ static ssize_t ll_max_readahead_per_file_mb_seq_write(struct file *file,
283 284
284 if (pages_number < 0 || 285 if (pages_number < 0 ||
285 pages_number > sbi->ll_ra_info.ra_max_pages) { 286 pages_number > sbi->ll_ra_info.ra_max_pages) {
286 CERROR("can't set file readahead more than" 287 CERROR("can't set file readahead more than max_read_ahead_mb %lu MB\n",
287 "max_read_ahead_mb %lu MB\n",
288 sbi->ll_ra_info.ra_max_pages); 288 sbi->ll_ra_info.ra_max_pages);
289 return -ERANGE; 289 return -ERANGE;
290 } 290 }
@@ -313,7 +313,7 @@ static int ll_max_read_ahead_whole_mb_seq_show(struct seq_file *m, void *unused)
313} 313}
314 314
315static ssize_t ll_max_read_ahead_whole_mb_seq_write(struct file *file, 315static ssize_t ll_max_read_ahead_whole_mb_seq_write(struct file *file,
316 const char *buffer, 316 const char __user *buffer,
317 size_t count, loff_t *off) 317 size_t count, loff_t *off)
318{ 318{
319 struct super_block *sb = ((struct seq_file *)file->private_data)->private; 319 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
@@ -329,9 +329,8 @@ static ssize_t ll_max_read_ahead_whole_mb_seq_write(struct file *file,
329 * algorithm does this anyway so it's pointless to set it larger. */ 329 * algorithm does this anyway so it's pointless to set it larger. */
330 if (pages_number < 0 || 330 if (pages_number < 0 ||
331 pages_number > sbi->ll_ra_info.ra_max_pages_per_file) { 331 pages_number > sbi->ll_ra_info.ra_max_pages_per_file) {
332 CERROR("can't set max_read_ahead_whole_mb more than " 332 CERROR("can't set max_read_ahead_whole_mb more than max_read_ahead_per_file_mb: %lu\n",
333 "max_read_ahead_per_file_mb: %lu\n", 333 sbi->ll_ra_info.ra_max_pages_per_file >> (20 - PAGE_CACHE_SHIFT));
334 sbi->ll_ra_info.ra_max_pages_per_file >> (20 - PAGE_CACHE_SHIFT));
335 return -ERANGE; 334 return -ERANGE;
336 } 335 }
337 336
@@ -469,8 +468,9 @@ static int ll_checksum_seq_show(struct seq_file *m, void *v)
469 return seq_printf(m, "%u\n", (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0); 468 return seq_printf(m, "%u\n", (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
470} 469}
471 470
472static ssize_t ll_checksum_seq_write(struct file *file, const char *buffer, 471static ssize_t ll_checksum_seq_write(struct file *file,
473 size_t count, loff_t *off) 472 const char __user *buffer,
473 size_t count, loff_t *off)
474{ 474{
475 struct super_block *sb = ((struct seq_file *)file->private_data)->private; 475 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
476 struct ll_sb_info *sbi = ll_s2sbi(sb); 476 struct ll_sb_info *sbi = ll_s2sbi(sb);
@@ -504,8 +504,9 @@ static int ll_max_rw_chunk_seq_show(struct seq_file *m, void *v)
504 return seq_printf(m, "%lu\n", ll_s2sbi(sb)->ll_max_rw_chunk); 504 return seq_printf(m, "%lu\n", ll_s2sbi(sb)->ll_max_rw_chunk);
505} 505}
506 506
507static ssize_t ll_max_rw_chunk_seq_write(struct file *file, const char *buffer, 507static ssize_t ll_max_rw_chunk_seq_write(struct file *file,
508 size_t count, loff_t *off) 508 const char __user *buffer,
509 size_t count, loff_t *off)
509{ 510{
510 struct super_block *sb = ((struct seq_file *)file->private_data)->private; 511 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
511 int rc, val; 512 int rc, val;
@@ -533,8 +534,8 @@ static int ll_rd_track_id(struct seq_file *m, enum stats_track_type type)
533 } 534 }
534} 535}
535 536
536static int ll_wr_track_id(const char *buffer, unsigned long count, void *data, 537static int ll_wr_track_id(const char __user *buffer, unsigned long count,
537 enum stats_track_type type) 538 void *data, enum stats_track_type type)
538{ 539{
539 struct super_block *sb = data; 540 struct super_block *sb = data;
540 int rc, pid; 541 int rc, pid;
@@ -556,8 +557,9 @@ static int ll_track_pid_seq_show(struct seq_file *m, void *v)
556 return ll_rd_track_id(m, STATS_TRACK_PID); 557 return ll_rd_track_id(m, STATS_TRACK_PID);
557} 558}
558 559
559static ssize_t ll_track_pid_seq_write(struct file *file, const char *buffer, 560static ssize_t ll_track_pid_seq_write(struct file *file,
560 size_t count, loff_t *off) 561 const char __user *buffer,
562 size_t count, loff_t *off)
561{ 563{
562 struct seq_file *seq = file->private_data; 564 struct seq_file *seq = file->private_data;
563 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PID); 565 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PID);
@@ -569,8 +571,9 @@ static int ll_track_ppid_seq_show(struct seq_file *m, void *v)
569 return ll_rd_track_id(m, STATS_TRACK_PPID); 571 return ll_rd_track_id(m, STATS_TRACK_PPID);
570} 572}
571 573
572static ssize_t ll_track_ppid_seq_write(struct file *file, const char *buffer, 574static ssize_t ll_track_ppid_seq_write(struct file *file,
573 size_t count, loff_t *off) 575 const char __user *buffer,
576 size_t count, loff_t *off)
574{ 577{
575 struct seq_file *seq = file->private_data; 578 struct seq_file *seq = file->private_data;
576 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PPID); 579 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_PPID);
@@ -582,8 +585,9 @@ static int ll_track_gid_seq_show(struct seq_file *m, void *v)
582 return ll_rd_track_id(m, STATS_TRACK_GID); 585 return ll_rd_track_id(m, STATS_TRACK_GID);
583} 586}
584 587
585static ssize_t ll_track_gid_seq_write(struct file *file, const char *buffer, 588static ssize_t ll_track_gid_seq_write(struct file *file,
586 size_t count, loff_t *off) 589 const char __user *buffer,
590 size_t count, loff_t *off)
587{ 591{
588 struct seq_file *seq = file->private_data; 592 struct seq_file *seq = file->private_data;
589 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_GID); 593 return ll_wr_track_id(buffer, count, seq->private, STATS_TRACK_GID);
@@ -598,8 +602,9 @@ static int ll_statahead_max_seq_show(struct seq_file *m, void *v)
598 return seq_printf(m, "%u\n", sbi->ll_sa_max); 602 return seq_printf(m, "%u\n", sbi->ll_sa_max);
599} 603}
600 604
601static ssize_t ll_statahead_max_seq_write(struct file *file, const char *buffer, 605static ssize_t ll_statahead_max_seq_write(struct file *file,
602 size_t count, loff_t *off) 606 const char __user *buffer,
607 size_t count, loff_t *off)
603{ 608{
604 struct super_block *sb = ((struct seq_file *)file->private_data)->private; 609 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
605 struct ll_sb_info *sbi = ll_s2sbi(sb); 610 struct ll_sb_info *sbi = ll_s2sbi(sb);
@@ -612,8 +617,8 @@ static ssize_t ll_statahead_max_seq_write(struct file *file, const char *buffer,
612 if (val >= 0 && val <= LL_SA_RPC_MAX) 617 if (val >= 0 && val <= LL_SA_RPC_MAX)
613 sbi->ll_sa_max = val; 618 sbi->ll_sa_max = val;
614 else 619 else
615 CERROR("Bad statahead_max value %d. Valid values are in the " 620 CERROR("Bad statahead_max value %d. Valid values are in the range [0, %d]\n",
616 "range [0, %d]\n", val, LL_SA_RPC_MAX); 621 val, LL_SA_RPC_MAX);
617 622
618 return count; 623 return count;
619} 624}
@@ -628,8 +633,9 @@ static int ll_statahead_agl_seq_show(struct seq_file *m, void *v)
628 sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0); 633 sbi->ll_flags & LL_SBI_AGL_ENABLED ? 1 : 0);
629} 634}
630 635
631static ssize_t ll_statahead_agl_seq_write(struct file *file, const char *buffer, 636static ssize_t ll_statahead_agl_seq_write(struct file *file,
632 size_t count, loff_t *off) 637 const char __user *buffer,
638 size_t count, loff_t *off)
633{ 639{
634 struct super_block *sb = ((struct seq_file *)file->private_data)->private; 640 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
635 struct ll_sb_info *sbi = ll_s2sbi(sb); 641 struct ll_sb_info *sbi = ll_s2sbi(sb);
@@ -672,8 +678,9 @@ static int ll_lazystatfs_seq_show(struct seq_file *m, void *v)
672 (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0); 678 (sbi->ll_flags & LL_SBI_LAZYSTATFS) ? 1 : 0);
673} 679}
674 680
675static ssize_t ll_lazystatfs_seq_write(struct file *file, const char *buffer, 681static ssize_t ll_lazystatfs_seq_write(struct file *file,
676 size_t count, loff_t *off) 682 const char __user *buffer,
683 size_t count, loff_t *off)
677{ 684{
678 struct super_block *sb = ((struct seq_file *)file->private_data)->private; 685 struct super_block *sb = ((struct seq_file *)file->private_data)->private;
679 struct ll_sb_info *sbi = ll_s2sbi(sb); 686 struct ll_sb_info *sbi = ll_s2sbi(sb);
@@ -761,8 +768,8 @@ static int ll_sbi_flags_seq_show(struct seq_file *m, void *v)
761 768
762 while (flags != 0) { 769 while (flags != 0) {
763 if (ARRAY_SIZE(str) <= i) { 770 if (ARRAY_SIZE(str) <= i) {
764 CERROR("%s: Revise array LL_SBI_FLAGS to match sbi " 771 CERROR("%s: Revise array LL_SBI_FLAGS to match sbi flags please.\n",
765 "flags please.\n", ll_get_fsname(sb, NULL, 0)); 772 ll_get_fsname(sb, NULL, 0));
766 return -EINVAL; 773 return -EINVAL;
767 } 774 }
768 775
@@ -787,7 +794,8 @@ static int ll_xattr_cache_seq_show(struct seq_file *m, void *v)
787 return rc; 794 return rc;
788} 795}
789 796
790static ssize_t ll_xattr_cache_seq_write(struct file *file, const char *buffer, 797static ssize_t ll_xattr_cache_seq_write(struct file *file,
798 const char __user *buffer,
791 size_t count, loff_t *off) 799 size_t count, loff_t *off)
792{ 800{
793 struct seq_file *seq = file->private_data; 801 struct seq_file *seq = file->private_data;
@@ -813,7 +821,7 @@ LPROC_SEQ_FOPS(ll_xattr_cache);
813 821
814static struct lprocfs_vars lprocfs_llite_obd_vars[] = { 822static struct lprocfs_vars lprocfs_llite_obd_vars[] = {
815 { "uuid", &ll_sb_uuid_fops, NULL, 0 }, 823 { "uuid", &ll_sb_uuid_fops, NULL, 0 },
816 //{ "mntpt_path", ll_rd_path, 0, 0 }, 824 /* { "mntpt_path", ll_rd_path, 0, 0 }, */
817 { "fstype", &ll_fstype_fops, NULL, 0 }, 825 { "fstype", &ll_fstype_fops, NULL, 0 },
818 { "site", &ll_site_stats_fops, NULL, 0 }, 826 { "site", &ll_site_stats_fops, NULL, 0 },
819 { "blocksize", &ll_blksize_fops, NULL, 0 }, 827 { "blocksize", &ll_blksize_fops, NULL, 0 },
@@ -823,7 +831,7 @@ static struct lprocfs_vars lprocfs_llite_obd_vars[] = {
823 { "filestotal", &ll_filestotal_fops, NULL, 0 }, 831 { "filestotal", &ll_filestotal_fops, NULL, 0 },
824 { "filesfree", &ll_filesfree_fops, NULL, 0 }, 832 { "filesfree", &ll_filesfree_fops, NULL, 0 },
825 { "client_type", &ll_client_type_fops, NULL, 0 }, 833 { "client_type", &ll_client_type_fops, NULL, 0 },
826 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 }, 834 /* { "filegroups", lprocfs_rd_filegroups, 0, 0 }, */
827 { "max_read_ahead_mb", &ll_max_readahead_mb_fops, NULL }, 835 { "max_read_ahead_mb", &ll_max_readahead_mb_fops, NULL },
828 { "max_read_ahead_per_file_mb", &ll_max_readahead_per_file_mb_fops, 836 { "max_read_ahead_per_file_mb", &ll_max_readahead_per_file_mb_fops,
829 NULL }, 837 NULL },
@@ -1133,8 +1141,8 @@ static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
1133 read_cum += r; 1141 read_cum += r;
1134 write_cum += w; 1142 write_cum += w;
1135 end = 1 << (i + LL_HIST_START - units); 1143 end = 1 << (i + LL_HIST_START - units);
1136 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | " 1144 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu | %14lu %4lu %4lu\n",
1137 "%14lu %4lu %4lu\n", start, *unitp, end, *unitp, 1145 start, *unitp, end, *unitp,
1138 (i == LL_HIST_MAX - 1) ? '+' : ' ', 1146 (i == LL_HIST_MAX - 1) ? '+' : ' ',
1139 r, pct(r, read_tot), pct(read_cum, read_tot), 1147 r, pct(r, read_tot), pct(read_cum, read_tot),
1140 w, pct(w, write_tot), pct(write_cum, write_tot)); 1148 w, pct(w, write_tot), pct(write_cum, write_tot));
@@ -1160,8 +1168,7 @@ static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
1160 1168
1161 if (!sbi->ll_rw_stats_on) { 1169 if (!sbi->ll_rw_stats_on) {
1162 seq_printf(seq, "disabled\n" 1170 seq_printf(seq, "disabled\n"
1163 "write anything in this file to activate, " 1171 "write anything in this file to activate, then 0 or \"[D/d]isabled\" to deactivate\n");
1164 "then 0 or \"[D/d]isabled\" to deactivate\n");
1165 return 0; 1172 return 0;
1166 } 1173 }
1167 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n", 1174 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
@@ -1239,8 +1246,7 @@ static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1239 1246
1240 if (!sbi->ll_rw_stats_on) { 1247 if (!sbi->ll_rw_stats_on) {
1241 seq_printf(seq, "disabled\n" 1248 seq_printf(seq, "disabled\n"
1242 "write anything in this file to activate, " 1249 "write anything in this file to activate, then 0 or \"[D/d]isabled\" to deactivate\n");
1243 "then 0 or \"[D/d]isabled\" to deactivate\n");
1244 return 0; 1250 return 0;
1245 } 1251 }
1246 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n", 1252 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
@@ -1418,8 +1424,7 @@ static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1418 1424
1419 if (!sbi->ll_rw_stats_on) { 1425 if (!sbi->ll_rw_stats_on) {
1420 seq_printf(seq, "disabled\n" 1426 seq_printf(seq, "disabled\n"
1421 "write anything in this file to activate, " 1427 "write anything in this file to activate, then 0 or \"[D/d]isabled\" to deactivate\n");
1422 "then 0 or \"[D/d]isabled\" to deactivate\n");
1423 return 0; 1428 return 0;
1424 } 1429 }
1425 spin_lock(&sbi->ll_process_lock); 1430 spin_lock(&sbi->ll_process_lock);
diff --git a/drivers/staging/lustre/lustre/llite/namei.c b/drivers/staging/lustre/lustre/llite/namei.c
index 8e926b385a60..1bf891bd321a 100644
--- a/drivers/staging/lustre/lustre/llite/namei.c
+++ b/drivers/staging/lustre/lustre/llite/namei.c
@@ -83,8 +83,8 @@ static int ll_set_inode(struct inode *inode, void *opaque)
83 83
84 lli->lli_fid = body->fid1; 84 lli->lli_fid = body->fid1;
85 if (unlikely(!(body->valid & OBD_MD_FLTYPE))) { 85 if (unlikely(!(body->valid & OBD_MD_FLTYPE))) {
86 CERROR("Can not initialize inode "DFID" without object type: " 86 CERROR("Can not initialize inode " DFID " without object type: valid = %#llx\n",
87 "valid = %#llx\n", PFID(&lli->lli_fid), body->valid); 87 PFID(&lli->lli_fid), body->valid);
88 return -EINVAL; 88 return -EINVAL;
89 } 89 }
90 90
@@ -598,8 +598,7 @@ static int ll_atomic_open(struct inode *dir, struct dentry *dentry,
598 long long lookup_flags = LOOKUP_OPEN; 598 long long lookup_flags = LOOKUP_OPEN;
599 int rc = 0; 599 int rc = 0;
600 600
601 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p),file %p," 601 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p),file %p,open_flags %x,mode %x opened %d\n",
602 "open_flags %x,mode %x opened %d\n",
603 dentry, dir->i_ino, 602 dentry, dir->i_ino,
604 dir->i_generation, dir, file, open_flags, mode, *opened); 603 dir->i_generation, dir, file, open_flags, mode, *opened);
605 604
@@ -843,8 +842,7 @@ static int ll_create_nd(struct inode *dir, struct dentry *dentry,
843{ 842{
844 int rc; 843 int rc;
845 844
846 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p)," 845 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p),flags=%u, excl=%d\n",
847 "flags=%u, excl=%d\n",
848 dentry, dir->i_ino, 846 dentry, dir->i_ino,
849 dir->i_generation, dir, mode, want_excl); 847 dir->i_generation, dir, mode, want_excl);
850 848
diff --git a/drivers/staging/lustre/lustre/llite/remote_perm.c b/drivers/staging/lustre/lustre/llite/remote_perm.c
index c05a9126cfe3..a58182600dae 100644
--- a/drivers/staging/lustre/lustre/llite/remote_perm.c
+++ b/drivers/staging/lustre/lustre/llite/remote_perm.c
@@ -194,7 +194,7 @@ int ll_update_remote_perm(struct inode *inode, struct mdt_remote_perm *perm)
194 194
195 if (!lli->lli_remote_perms) 195 if (!lli->lli_remote_perms)
196 lli->lli_remote_perms = perm_hash; 196 lli->lli_remote_perms = perm_hash;
197 else if (perm_hash) 197 else
198 free_rmtperm_hash(perm_hash); 198 free_rmtperm_hash(perm_hash);
199 199
200 head = lli->lli_remote_perms + remote_perm_hashfunc(perm->rp_uid); 200 head = lli->lli_remote_perms + remote_perm_hashfunc(perm->rp_uid);
@@ -209,8 +209,7 @@ again:
209 continue; 209 continue;
210 if (tmp->lrp_fsgid != perm->rp_fsgid) 210 if (tmp->lrp_fsgid != perm->rp_fsgid)
211 continue; 211 continue;
212 if (lrp) 212 free_ll_remote_perm(lrp);
213 free_ll_remote_perm(lrp);
214 lrp = tmp; 213 lrp = tmp;
215 break; 214 break;
216 } 215 }
diff --git a/drivers/staging/lustre/lustre/llite/rw.c b/drivers/staging/lustre/lustre/llite/rw.c
index 1f53b9863385..10a0421366d0 100644
--- a/drivers/staging/lustre/lustre/llite/rw.c
+++ b/drivers/staging/lustre/lustre/llite/rw.c
@@ -121,8 +121,8 @@ static struct ll_cl_context *ll_cl_init(struct file *file,
121 /* this is too bad. Someone is trying to write the 121 /* this is too bad. Someone is trying to write the
122 * page w/o holding inode mutex. This means we can 122 * page w/o holding inode mutex. This means we can
123 * add dirty pages into cache during truncate */ 123 * add dirty pages into cache during truncate */
124 CERROR("Proc %s is dirting page w/o inode lock, this" 124 CERROR("Proc %s is dirtying page w/o inode lock, this will break truncate\n",
125 "will break truncate.\n", current->comm); 125 current->comm);
126 dump_stack(); 126 dump_stack();
127 LBUG(); 127 LBUG();
128 return ERR_PTR(-EIO); 128 return ERR_PTR(-EIO);
@@ -145,7 +145,7 @@ static struct ll_cl_context *ll_cl_init(struct file *file,
145 */ 145 */
146 io->ci_lockreq = CILR_NEVER; 146 io->ci_lockreq = CILR_NEVER;
147 147
148 pos = (vmpage->index << PAGE_CACHE_SHIFT); 148 pos = vmpage->index << PAGE_CACHE_SHIFT;
149 149
150 /* Create a temp IO to serve write. */ 150 /* Create a temp IO to serve write. */
151 result = cl_io_rw_init(env, io, CIT_WRITE, pos, PAGE_CACHE_SIZE); 151 result = cl_io_rw_init(env, io, CIT_WRITE, pos, PAGE_CACHE_SIZE);
@@ -606,8 +606,8 @@ stride_pg_count(pgoff_t st_off, unsigned long st_len, unsigned long st_pgs,
606 else 606 else
607 pg_count = start_left + st_pgs * (end - start - 1) + end_left; 607 pg_count = start_left + st_pgs * (end - start - 1) + end_left;
608 608
609 CDEBUG(D_READA, "st_off %lu, st_len %lu st_pgs %lu off %lu length %lu" 609 CDEBUG(D_READA, "st_off %lu, st_len %lu st_pgs %lu off %lu length %lu pgcount %lu\n",
610 "pgcount %lu\n", st_off, st_len, st_pgs, off, length, pg_count); 610 st_off, st_len, st_pgs, off, length, pg_count);
611 611
612 return pg_count; 612 return pg_count;
613} 613}
@@ -667,10 +667,10 @@ static int ll_read_ahead_pages(const struct lu_env *env,
667 /* FIXME: This assertion only is valid when it is for 667 /* FIXME: This assertion only is valid when it is for
668 * forward read-ahead, it will be fixed when backward 668 * forward read-ahead, it will be fixed when backward
669 * read-ahead is implemented */ 669 * read-ahead is implemented */
670 LASSERTF(page_idx > ria->ria_stoff, "Invalid page_idx %lu" 670 LASSERTF(page_idx > ria->ria_stoff, "Invalid page_idx %lu rs %lu re %lu ro %lu rl %lu rp %lu\n",
671 "rs %lu re %lu ro %lu rl %lu rp %lu\n", page_idx, 671 page_idx,
672 ria->ria_start, ria->ria_end, ria->ria_stoff, 672 ria->ria_start, ria->ria_end, ria->ria_stoff,
673 ria->ria_length, ria->ria_pages); 673 ria->ria_length, ria->ria_pages);
674 offset = page_idx - ria->ria_stoff; 674 offset = page_idx - ria->ria_stoff;
675 offset = offset % (ria->ria_length); 675 offset = offset % (ria->ria_length);
676 if (offset > ria->ria_pages) { 676 if (offset > ria->ria_pages) {
@@ -927,8 +927,8 @@ static void ras_stride_increase_window(struct ll_readahead_state *ras,
927 927
928 LASSERT(ras->ras_stride_length > 0); 928 LASSERT(ras->ras_stride_length > 0);
929 LASSERTF(ras->ras_window_start + ras->ras_window_len 929 LASSERTF(ras->ras_window_start + ras->ras_window_len
930 >= ras->ras_stride_offset, "window_start %lu, window_len %lu" 930 >= ras->ras_stride_offset, "window_start %lu, window_len %lu stride_offset %lu\n",
931 " stride_offset %lu\n", ras->ras_window_start, 931 ras->ras_window_start,
932 ras->ras_window_len, ras->ras_stride_offset); 932 ras->ras_window_len, ras->ras_stride_offset);
933 933
934 stride_len = ras->ras_window_start + ras->ras_window_len - 934 stride_len = ras->ras_window_start + ras->ras_window_len -
diff --git a/drivers/staging/lustre/lustre/llite/rw26.c b/drivers/staging/lustre/lustre/llite/rw26.c
index 4c77ae8b9350..2f21304046aa 100644
--- a/drivers/staging/lustre/lustre/llite/rw26.c
+++ b/drivers/staging/lustre/lustre/llite/rw26.c
@@ -183,7 +183,7 @@ static int ll_set_page_dirty(struct page *vmpage)
183 return __set_page_dirty_nobuffers(vmpage); 183 return __set_page_dirty_nobuffers(vmpage);
184} 184}
185 185
186#define MAX_DIRECTIO_SIZE 2*1024*1024*1024UL 186#define MAX_DIRECTIO_SIZE (2*1024*1024*1024UL)
187 187
188static inline int ll_get_user_pages(int rw, unsigned long user_addr, 188static inline int ll_get_user_pages(int rw, unsigned long user_addr,
189 size_t size, struct page ***pages, 189 size_t size, struct page ***pages,
@@ -417,7 +417,7 @@ static ssize_t ll_direct_IO_26(int rw, struct kiocb *iocb,
417 417
418 result = iov_iter_get_pages_alloc(iter, &pages, count, &offs); 418 result = iov_iter_get_pages_alloc(iter, &pages, count, &offs);
419 if (likely(result > 0)) { 419 if (likely(result > 0)) {
420 int n = (result + offs + PAGE_SIZE - 1) / PAGE_SIZE; 420 int n = DIV_ROUND_UP(result + offs, PAGE_SIZE);
421 result = ll_direct_IO_26_seg(env, io, rw, inode, 421 result = ll_direct_IO_26_seg(env, io, rw, inode,
422 file->f_mapping, 422 file->f_mapping,
423 result, file_offset, 423 result, file_offset,
@@ -535,7 +535,7 @@ const struct address_space_operations ll_aops = {
535#else 535#else
536const struct address_space_operations_ext ll_aops = { 536const struct address_space_operations_ext ll_aops = {
537 .orig_aops.readpage = ll_readpage, 537 .orig_aops.readpage = ll_readpage,
538// .orig_aops.readpages = ll_readpages, 538/* .orig_aops.readpages = ll_readpages, */
539 .orig_aops.direct_IO = ll_direct_IO_26, 539 .orig_aops.direct_IO = ll_direct_IO_26,
540 .orig_aops.writepage = ll_writepage, 540 .orig_aops.writepage = ll_writepage,
541 .orig_aops.writepages = ll_writepages, 541 .orig_aops.writepages = ll_writepages,
diff --git a/drivers/staging/lustre/lustre/llite/statahead.c b/drivers/staging/lustre/lustre/llite/statahead.c
index 09d965e76842..6ad9dd0fe2b3 100644
--- a/drivers/staging/lustre/lustre/llite/statahead.c
+++ b/drivers/staging/lustre/lustre/llite/statahead.c
@@ -334,8 +334,7 @@ static void ll_sa_entry_put(struct ll_statahead_info *sai,
334 LASSERT(ll_sa_entry_unhashed(entry)); 334 LASSERT(ll_sa_entry_unhashed(entry));
335 335
336 ll_sa_entry_cleanup(sai, entry); 336 ll_sa_entry_cleanup(sai, entry);
337 if (entry->se_inode) 337 iput(entry->se_inode);
338 iput(entry->se_inode);
339 338
340 OBD_FREE(entry, entry->se_size); 339 OBD_FREE(entry, entry->se_size);
341 atomic_dec(&sai->sai_cache_count); 340 atomic_dec(&sai->sai_cache_count);
@@ -915,7 +914,7 @@ static int do_sa_revalidate(struct inode *dir, struct ll_sa_entry *entry,
915 return rc; 914 return rc;
916} 915}
917 916
918static void ll_statahead_one(struct dentry *parent, const char* entry_name, 917static void ll_statahead_one(struct dentry *parent, const char *entry_name,
919 int entry_name_len) 918 int entry_name_len)
920{ 919{
921 struct inode *dir = parent->d_inode; 920 struct inode *dir = parent->d_inode;
@@ -1491,10 +1490,7 @@ ll_sai_unplug(struct ll_statahead_info *sai, struct ll_sa_entry *entry)
1491 sai->sai_consecutive_miss++; 1490 sai->sai_consecutive_miss++;
1492 if (sa_low_hit(sai) && thread_is_running(thread)) { 1491 if (sa_low_hit(sai) && thread_is_running(thread)) {
1493 atomic_inc(&sbi->ll_sa_wrong); 1492 atomic_inc(&sbi->ll_sa_wrong);
1494 CDEBUG(D_READA, "Statahead for dir "DFID" hit " 1493 CDEBUG(D_READA, "Statahead for dir " DFID " hit ratio too low: hit/miss %llu/%llu, sent/replied %llu/%llu, stopping statahead thread\n",
1495 "ratio too low: hit/miss %llu/%llu"
1496 ", sent/replied %llu/%llu, stopping "
1497 "statahead thread\n",
1498 PFID(&lli->lli_fid), sai->sai_hit, 1494 PFID(&lli->lli_fid), sai->sai_hit,
1499 sai->sai_miss, sai->sai_sent, 1495 sai->sai_miss, sai->sai_sent,
1500 sai->sai_replied); 1496 sai->sai_replied);
@@ -1612,8 +1608,7 @@ int do_statahead_enter(struct inode *dir, struct dentry **dentryp,
1612 } else if ((*dentryp)->d_inode != inode) { 1608 } else if ((*dentryp)->d_inode != inode) {
1613 /* revalidate, but inode is recreated */ 1609 /* revalidate, but inode is recreated */
1614 CDEBUG(D_READA, 1610 CDEBUG(D_READA,
1615 "stale dentry %pd inode %lu/%u, " 1611 "stale dentry %pd inode %lu/%u, statahead inode %lu/%u\n",
1616 "statahead inode %lu/%u\n",
1617 *dentryp, 1612 *dentryp,
1618 (*dentryp)->d_inode->i_ino, 1613 (*dentryp)->d_inode->i_ino,
1619 (*dentryp)->d_inode->i_generation, 1614 (*dentryp)->d_inode->i_generation,
@@ -1665,8 +1660,7 @@ int do_statahead_enter(struct inode *dir, struct dentry **dentryp,
1665 if (unlikely(sai->sai_inode != parent->d_inode)) { 1660 if (unlikely(sai->sai_inode != parent->d_inode)) {
1666 struct ll_inode_info *nlli = ll_i2info(parent->d_inode); 1661 struct ll_inode_info *nlli = ll_i2info(parent->d_inode);
1667 1662
1668 CWARN("Race condition, someone changed %pd just now: " 1663 CWARN("Race condition, someone changed %pd just now: old parent "DFID", new parent "DFID"\n",
1669 "old parent "DFID", new parent "DFID"\n",
1670 *dentryp, 1664 *dentryp,
1671 PFID(&lli->lli_fid), PFID(&nlli->lli_fid)); 1665 PFID(&lli->lli_fid), PFID(&nlli->lli_fid));
1672 dput(parent); 1666 dput(parent);
diff --git a/drivers/staging/lustre/lustre/llite/super25.c b/drivers/staging/lustre/lustre/llite/super25.c
index e61dbed120a3..6aff155651cc 100644
--- a/drivers/staging/lustre/lustre/llite/super25.c
+++ b/drivers/staging/lustre/lustre/llite/super25.c
@@ -162,7 +162,7 @@ static int __init init_lustre_lite(void)
162 162
163 /* Nodes with small feet have little entropy 163 /* Nodes with small feet have little entropy
164 * the NID for this node gives the most entropy in the low bits */ 164 * the NID for this node gives the most entropy in the low bits */
165 for (i=0; ; i++) { 165 for (i = 0; ; i++) {
166 if (LNetGetId(i, &lnet_id) == -ENOENT) { 166 if (LNetGetId(i, &lnet_id) == -ENOENT) {
167 break; 167 break;
168 } 168 }
diff --git a/drivers/staging/lustre/lustre/llite/symlink.c b/drivers/staging/lustre/lustre/llite/symlink.c
index eccd3a717a4d..686b6a574cc5 100644
--- a/drivers/staging/lustre/lustre/llite/symlink.c
+++ b/drivers/staging/lustre/lustre/llite/symlink.c
@@ -100,8 +100,8 @@ static int ll_readlink_internal(struct inode *inode,
100 if (*symname == NULL || 100 if (*symname == NULL ||
101 strnlen(*symname, symlen) != symlen - 1) { 101 strnlen(*symname, symlen) != symlen - 1) {
102 /* not full/NULL terminated */ 102 /* not full/NULL terminated */
103 CERROR("inode %lu: symlink not NULL terminated string" 103 CERROR("inode %lu: symlink not NULL terminated string of length %d\n",
104 "of length %d\n", inode->i_ino, symlen - 1); 104 inode->i_ino, symlen - 1);
105 rc = -EPROTO; 105 rc = -EPROTO;
106 goto failed; 106 goto failed;
107 } 107 }
diff --git a/drivers/staging/lustre/lustre/llite/vvp_io.c b/drivers/staging/lustre/lustre/llite/vvp_io.c
index e540a6d286f8..930f6010203e 100644
--- a/drivers/staging/lustre/lustre/llite/vvp_io.c
+++ b/drivers/staging/lustre/lustre/llite/vvp_io.c
@@ -709,7 +709,7 @@ static int vvp_io_fault_start(const struct lu_env *env,
709 } 709 }
710 710
711 711
712 if (fio->ft_mkwrite ) { 712 if (fio->ft_mkwrite) {
713 pgoff_t last_index; 713 pgoff_t last_index;
714 /* 714 /*
715 * Capture the size while holding the lli_trunc_sem from above 715 * Capture the size while holding the lli_trunc_sem from above
@@ -720,9 +720,8 @@ static int vvp_io_fault_start(const struct lu_env *env,
720 last_index = cl_index(obj, size - 1); 720 last_index = cl_index(obj, size - 1);
721 if (last_index < fio->ft_index) { 721 if (last_index < fio->ft_index) {
722 CDEBUG(D_PAGE, 722 CDEBUG(D_PAGE,
723 "llite: mkwrite and truncate race happened: " 723 "llite: mkwrite and truncate race happened: %p: 0x%lx 0x%lx\n",
724 "%p: 0x%lx 0x%lx\n", 724 vmpage->mapping, fio->ft_index, last_index);
725 vmpage->mapping, fio->ft_index, last_index);
726 /* 725 /*
727 * We need to return if we are 726 * We need to return if we are
728 * passed the end of the file. This will propagate 727 * passed the end of the file. This will propagate
diff --git a/drivers/staging/lustre/lustre/llite/vvp_page.c b/drivers/staging/lustre/lustre/llite/vvp_page.c
index 4626346f6ee1..954ed08c6af2 100644
--- a/drivers/staging/lustre/lustre/llite/vvp_page.c
+++ b/drivers/staging/lustre/lustre/llite/vvp_page.c
@@ -376,8 +376,7 @@ static int vvp_page_print(const struct lu_env *env,
376 struct ccc_page *vp = cl2ccc_page(slice); 376 struct ccc_page *vp = cl2ccc_page(slice);
377 struct page *vmpage = vp->cpg_page; 377 struct page *vmpage = vp->cpg_page;
378 378
379 (*printer)(env, cookie, LUSTRE_VVP_NAME"-page@%p(%d:%d:%d) " 379 (*printer)(env, cookie, LUSTRE_VVP_NAME "-page@%p(%d:%d:%d) vm@%p ",
380 "vm@%p ",
381 vp, vp->cpg_defer_uptodate, vp->cpg_ra_used, 380 vp, vp->cpg_defer_uptodate, vp->cpg_ra_used,
382 vp->cpg_write_queued, vmpage); 381 vp->cpg_write_queued, vmpage);
383 if (vmpage != NULL) { 382 if (vmpage != NULL) {
diff --git a/drivers/staging/lustre/lustre/llite/xattr.c b/drivers/staging/lustre/lustre/llite/xattr.c
index 3151baf5585c..b439936b4524 100644
--- a/drivers/staging/lustre/lustre/llite/xattr.c
+++ b/drivers/staging/lustre/lustre/llite/xattr.c
@@ -201,8 +201,7 @@ int ll_setxattr_common(struct inode *inode, const char *name,
201#endif 201#endif
202 if (rc) { 202 if (rc) {
203 if (rc == -EOPNOTSUPP && xattr_type == XATTR_USER_T) { 203 if (rc == -EOPNOTSUPP && xattr_type == XATTR_USER_T) {
204 LCONSOLE_INFO("Disabling user_xattr feature because " 204 LCONSOLE_INFO("Disabling user_xattr feature because it is not supported on the server\n");
205 "it is not supported on the server\n");
206 sbi->ll_flags &= ~LL_SBI_USER_XATTR; 205 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
207 } 206 }
208 return rc; 207 return rc;
@@ -234,6 +233,9 @@ int ll_setxattr(struct dentry *dentry, const char *name,
234 struct lov_user_md *lump = (struct lov_user_md *)value; 233 struct lov_user_md *lump = (struct lov_user_md *)value;
235 int rc = 0; 234 int rc = 0;
236 235
236 if (size != 0 && size < sizeof(struct lov_user_md))
237 return -EINVAL;
238
237 /* Attributes that are saved via getxattr will always have 239 /* Attributes that are saved via getxattr will always have
238 * the stripe_offset as 0. Instead, the MDS should be 240 * the stripe_offset as 0. Instead, the MDS should be
239 * allowed to pick the starting OST index. b=17846 */ 241 * allowed to pick the starting OST index. b=17846 */
diff --git a/drivers/staging/lustre/lustre/llite/xattr_cache.c b/drivers/staging/lustre/lustre/llite/xattr_cache.c
index 627cbe242f22..e2badf17d95e 100644
--- a/drivers/staging/lustre/lustre/llite/xattr_cache.c
+++ b/drivers/staging/lustre/lustre/llite/xattr_cache.c
@@ -126,9 +126,7 @@ static int ll_xattr_cache_add(struct list_head *cache,
126 return -ENOMEM; 126 return -ENOMEM;
127 } 127 }
128 128
129 xattr->xe_namelen = strlen(xattr_name) + 1; 129 xattr->xe_name = kstrdup(xattr_name, GFP_NOFS);
130
131 xattr->xe_name = kzalloc(xattr->xe_namelen, GFP_NOFS);
132 if (!xattr->xe_name) { 130 if (!xattr->xe_name) {
133 CDEBUG(D_CACHE, "failed to alloc xattr name %u\n", 131 CDEBUG(D_CACHE, "failed to alloc xattr name %u\n",
134 xattr->xe_namelen); 132 xattr->xe_namelen);
@@ -141,7 +139,6 @@ static int ll_xattr_cache_add(struct list_head *cache,
141 goto err_value; 139 goto err_value;
142 } 140 }
143 141
144 memcpy(xattr->xe_name, xattr_name, xattr->xe_namelen);
145 memcpy(xattr->xe_value, xattr_val, xattr_val_len); 142 memcpy(xattr->xe_value, xattr_val, xattr_val_len);
146 xattr->xe_vallen = xattr_val_len; 143 xattr->xe_vallen = xattr_val_len;
147 list_add(&xattr->xe_list, cache); 144 list_add(&xattr->xe_list, cache);
diff --git a/drivers/staging/lustre/lustre/lmv/lmv_fld.c b/drivers/staging/lustre/lustre/lmv/lmv_fld.c
index e8421f04beda..ee235926f52b 100644
--- a/drivers/staging/lustre/lustre/lmv/lmv_fld.c
+++ b/drivers/staging/lustre/lustre/lmv/lmv_fld.c
@@ -75,8 +75,7 @@ int lmv_fld_lookup(struct lmv_obd *lmv,
75 *mds, PFID(fid)); 75 *mds, PFID(fid));
76 76
77 if (*mds >= lmv->desc.ld_tgt_count) { 77 if (*mds >= lmv->desc.ld_tgt_count) {
78 CERROR("FLD lookup got invalid mds #%x (max: %x) " 78 CERROR("FLD lookup got invalid mds #%x (max: %x) for fid=" DFID "\n", *mds, lmv->desc.ld_tgt_count,
79 "for fid="DFID"\n", *mds, lmv->desc.ld_tgt_count,
80 PFID(fid)); 79 PFID(fid));
81 rc = -EINVAL; 80 rc = -EINVAL;
82 } 81 }
diff --git a/drivers/staging/lustre/lustre/lmv/lmv_intent.c b/drivers/staging/lustre/lustre/lmv/lmv_intent.c
index 5106124b7d92..d22d57b4ff38 100644
--- a/drivers/staging/lustre/lustre/lmv/lmv_intent.c
+++ b/drivers/staging/lustre/lustre/lmv/lmv_intent.c
@@ -186,8 +186,8 @@ int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data,
186 return rc; 186 return rc;
187 } 187 }
188 188
189 CDEBUG(D_INODE, "OPEN_INTENT with fid1="DFID", fid2="DFID"," 189 CDEBUG(D_INODE, "OPEN_INTENT with fid1=" DFID ", fid2=" DFID ", name='%s' -> mds #%d\n",
190 " name='%s' -> mds #%d\n", PFID(&op_data->op_fid1), 190 PFID(&op_data->op_fid1),
191 PFID(&op_data->op_fid2), op_data->op_name, tgt->ltd_idx); 191 PFID(&op_data->op_fid2), op_data->op_name, tgt->ltd_idx);
192 192
193 rc = md_intent_lock(tgt->ltd_exp, op_data, lmm, lmmsize, it, flags, 193 rc = md_intent_lock(tgt->ltd_exp, op_data, lmm, lmmsize, it, flags,
@@ -226,8 +226,8 @@ int lmv_intent_open(struct obd_export *exp, struct md_op_data *op_data,
226 * this is normal situation, we should not print error here, 226 * this is normal situation, we should not print error here,
227 * only debug info. 227 * only debug info.
228 */ 228 */
229 CDEBUG(D_INODE, "Can't handle remote %s: dir "DFID"("DFID"):" 229 CDEBUG(D_INODE, "Can't handle remote %s: dir " DFID "(" DFID "):%*s: %d\n",
230 "%*s: %d\n", LL_IT2STR(it), PFID(&op_data->op_fid2), 230 LL_IT2STR(it), PFID(&op_data->op_fid2),
231 PFID(&op_data->op_fid1), op_data->op_namelen, 231 PFID(&op_data->op_fid1), op_data->op_namelen,
232 op_data->op_name, rc); 232 op_data->op_name, rc);
233 return rc; 233 return rc;
diff --git a/drivers/staging/lustre/lustre/lmv/lmv_internal.h b/drivers/staging/lustre/lustre/lmv/lmv_internal.h
index b911e7643874..852d78721ca9 100644
--- a/drivers/staging/lustre/lustre/lmv/lmv_internal.h
+++ b/drivers/staging/lustre/lustre/lmv/lmv_internal.h
@@ -42,8 +42,8 @@
42 42
43#define LMV_MAX_TGT_COUNT 128 43#define LMV_MAX_TGT_COUNT 128
44 44
45#define lmv_init_lock(lmv) mutex_lock(&lmv->init_mutex); 45#define lmv_init_lock(lmv) mutex_lock(&lmv->init_mutex)
46#define lmv_init_unlock(lmv) mutex_unlock(&lmv->init_mutex); 46#define lmv_init_unlock(lmv) mutex_unlock(&lmv->init_mutex)
47 47
48#define LL_IT2STR(it) \ 48#define LL_IT2STR(it) \
49 ((it) ? ldlm_it2str((it)->it_op) : "0") 49 ((it) ? ldlm_it2str((it)->it_op) : "0")
diff --git a/drivers/staging/lustre/lustre/lmv/lmv_obd.c b/drivers/staging/lustre/lustre/lmv/lmv_obd.c
index 1a5821289c39..9f3837412cdf 100644
--- a/drivers/staging/lustre/lustre/lmv/lmv_obd.c
+++ b/drivers/staging/lustre/lustre/lmv/lmv_obd.c
@@ -325,8 +325,8 @@ static int lmv_init_ea_size(struct obd_export *exp, int easize,
325 rc = md_init_ea_size(lmv->tgts[i]->ltd_exp, easize, def_easize, 325 rc = md_init_ea_size(lmv->tgts[i]->ltd_exp, easize, def_easize,
326 cookiesize, def_cookiesize); 326 cookiesize, def_cookiesize);
327 if (rc) { 327 if (rc) {
328 CERROR("%s: obd_init_ea_size() failed on MDT target %d:" 328 CERROR("%s: obd_init_ea_size() failed on MDT target %d: rc = %d.\n",
329 " rc = %d.\n", obd->obd_name, i, rc); 329 obd->obd_name, i, rc);
330 break; 330 break;
331 } 331 }
332 } 332 }
@@ -427,8 +427,7 @@ int lmv_connect_mdc(struct obd_device *obd, struct lmv_tgt_desc *tgt)
427 mdc_obd->obd_type->typ_name, 427 mdc_obd->obd_type->typ_name,
428 mdc_obd->obd_name); 428 mdc_obd->obd_name);
429 if (mdc_symlink == NULL) { 429 if (mdc_symlink == NULL) {
430 CERROR("Could not register LMV target " 430 CERROR("Could not register LMV target /proc/fs/lustre/%s/%s/target_obds/%s.",
431 "/proc/fs/lustre/%s/%s/target_obds/%s.",
432 obd->obd_type->typ_name, obd->obd_name, 431 obd->obd_type->typ_name, obd->obd_name,
433 mdc_obd->obd_name); 432 mdc_obd->obd_name);
434 lprocfs_remove(&lmv_proc_dir); 433 lprocfs_remove(&lmv_proc_dir);
@@ -474,8 +473,8 @@ static int lmv_add_target(struct obd_device *obd, struct obd_uuid *uuidp,
474 473
475 if ((index < lmv->tgts_size) && (lmv->tgts[index] != NULL)) { 474 if ((index < lmv->tgts_size) && (lmv->tgts[index] != NULL)) {
476 tgt = lmv->tgts[index]; 475 tgt = lmv->tgts[index];
477 CERROR("%s: UUID %s already assigned at LOV target index %d:" 476 CERROR("%s: UUID %s already assigned at LOV target index %d: rc = %d\n",
478 " rc = %d\n", obd->obd_name, 477 obd->obd_name,
479 obd_uuid2str(&tgt->ltd_uuid), index, -EEXIST); 478 obd_uuid2str(&tgt->ltd_uuid), index, -EEXIST);
480 lmv_init_unlock(lmv); 479 lmv_init_unlock(lmv);
481 return -EEXIST; 480 return -EEXIST;
@@ -600,8 +599,7 @@ int lmv_check_connect(struct obd_device *obd)
600 --lmv->desc.ld_active_tgt_count; 599 --lmv->desc.ld_active_tgt_count;
601 rc2 = obd_disconnect(tgt->ltd_exp); 600 rc2 = obd_disconnect(tgt->ltd_exp);
602 if (rc2) { 601 if (rc2) {
603 CERROR("LMV target %s disconnect on " 602 CERROR("LMV target %s disconnect on MDC idx %d: error %d\n",
604 "MDC idx %d: error %d\n",
605 tgt->ltd_uuid.uuid, i, rc2); 603 tgt->ltd_uuid.uuid, i, rc2);
606 } 604 }
607 } 605 }
@@ -865,10 +863,9 @@ static int lmv_hsm_ct_register(struct lmv_obd *lmv, unsigned int cmd, int len,
865 if (err) { 863 if (err) {
866 if (lmv->tgts[i]->ltd_active) { 864 if (lmv->tgts[i]->ltd_active) {
867 /* permanent error */ 865 /* permanent error */
868 CERROR("error: iocontrol MDC %s on MDT" 866 CERROR("error: iocontrol MDC %s on MDTidx %d cmd %x: err = %d\n",
869 "idx %d cmd %x: err = %d\n", 867 lmv->tgts[i]->ltd_uuid.uuid,
870 lmv->tgts[i]->ltd_uuid.uuid, 868 i, cmd, err);
871 i, cmd, err);
872 rc = err; 869 rc = err;
873 lk->lk_flags |= LK_FLG_STOP; 870 lk->lk_flags |= LK_FLG_STOP;
874 /* unregister from previous MDS */ 871 /* unregister from previous MDS */
@@ -925,7 +922,7 @@ static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
925 __u32 index; 922 __u32 index;
926 923
927 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32)); 924 memcpy(&index, data->ioc_inlbuf2, sizeof(__u32));
928 if ((index >= count)) 925 if (index >= count)
929 return -ENODEV; 926 return -ENODEV;
930 927
931 if (lmv->tgts[index] == NULL || 928 if (lmv->tgts[index] == NULL ||
@@ -1147,10 +1144,9 @@ static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
1147 return err; 1144 return err;
1148 } else if (err) { 1145 } else if (err) {
1149 if (lmv->tgts[i]->ltd_active) { 1146 if (lmv->tgts[i]->ltd_active) {
1150 CERROR("error: iocontrol MDC %s on MDT" 1147 CERROR("error: iocontrol MDC %s on MDTidx %d cmd %x: err = %d\n",
1151 "idx %d cmd %x: err = %d\n", 1148 lmv->tgts[i]->ltd_uuid.uuid,
1152 lmv->tgts[i]->ltd_uuid.uuid, 1149 i, cmd, err);
1153 i, cmd, err);
1154 if (!rc) 1150 if (!rc)
1155 rc = err; 1151 rc = err;
1156 } 1152 }
@@ -1234,8 +1230,8 @@ static int lmv_placement_policy(struct obd_device *obd,
1234 if (lum->lum_type == LMV_STRIPE_TYPE && 1230 if (lum->lum_type == LMV_STRIPE_TYPE &&
1235 lum->lum_stripe_offset != -1) { 1231 lum->lum_stripe_offset != -1) {
1236 if (lum->lum_stripe_offset >= lmv->desc.ld_tgt_count) { 1232 if (lum->lum_stripe_offset >= lmv->desc.ld_tgt_count) {
1237 CERROR("%s: Stripe_offset %d > MDT count %d:" 1233 CERROR("%s: Stripe_offset %d > MDT count %d: rc = %d\n",
1238 " rc = %d\n", obd->obd_name, 1234 obd->obd_name,
1239 lum->lum_stripe_offset, 1235 lum->lum_stripe_offset,
1240 lmv->desc.ld_tgt_count, -ERANGE); 1236 lmv->desc.ld_tgt_count, -ERANGE);
1241 return -ERANGE; 1237 return -ERANGE;
@@ -1298,8 +1294,8 @@ int lmv_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
1298 1294
1299 rc = lmv_placement_policy(obd, op_data, &mds); 1295 rc = lmv_placement_policy(obd, op_data, &mds);
1300 if (rc) { 1296 if (rc) {
1301 CERROR("Can't get target for allocating fid, " 1297 CERROR("Can't get target for allocating fid, rc %d\n",
1302 "rc %d\n", rc); 1298 rc);
1303 return rc; 1299 return rc;
1304 } 1300 }
1305 1301
@@ -2310,7 +2306,6 @@ retry:
2310static int lmv_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage) 2306static int lmv_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2311{ 2307{
2312 struct lmv_obd *lmv = &obd->u.lmv; 2308 struct lmv_obd *lmv = &obd->u.lmv;
2313 int rc = 0;
2314 2309
2315 switch (stage) { 2310 switch (stage) {
2316 case OBD_CLEANUP_EARLY: 2311 case OBD_CLEANUP_EARLY:
@@ -2324,7 +2319,7 @@ static int lmv_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2324 default: 2319 default:
2325 break; 2320 break;
2326 } 2321 }
2327 return rc; 2322 return 0;
2328} 2323}
2329 2324
2330static int lmv_get_info(const struct lu_env *env, struct obd_export *exp, 2325static int lmv_get_info(const struct lu_env *env, struct obd_export *exp,
diff --git a/drivers/staging/lustre/lustre/lov/lov_ea.c b/drivers/staging/lustre/lustre/lov/lov_ea.c
index 9e21e5efcdb6..e9ec39c5a6c2 100644
--- a/drivers/staging/lustre/lustre/lov/lov_ea.c
+++ b/drivers/staging/lustre/lustre/lov/lov_ea.c
@@ -348,9 +348,8 @@ const struct lsm_operations lsm_v3_ops = {
348 348
349void dump_lsm(unsigned int level, const struct lov_stripe_md *lsm) 349void dump_lsm(unsigned int level, const struct lov_stripe_md *lsm)
350{ 350{
351 CDEBUG(level, "lsm %p, objid "DOSTID", maxbytes %#llx, magic 0x%08X," 351 CDEBUG(level, "lsm %p, objid " DOSTID ", maxbytes %#llx, magic 0x%08X, stripe_size %u, stripe_count %u, refc: %d, layout_gen %u, pool [" LOV_POOLNAMEF "]\n",
352 " stripe_size %u, stripe_count %u, refc: %d," 352 lsm,
353 " layout_gen %u, pool ["LOV_POOLNAMEF"]\n", lsm,
354 POSTID(&lsm->lsm_oi), lsm->lsm_maxbytes, lsm->lsm_magic, 353 POSTID(&lsm->lsm_oi), lsm->lsm_maxbytes, lsm->lsm_magic,
355 lsm->lsm_stripe_size, lsm->lsm_stripe_count, 354 lsm->lsm_stripe_size, lsm->lsm_stripe_count,
356 atomic_read(&lsm->lsm_refc), lsm->lsm_layout_gen, 355 atomic_read(&lsm->lsm_refc), lsm->lsm_layout_gen,
diff --git a/drivers/staging/lustre/lustre/lov/lov_obd.c b/drivers/staging/lustre/lustre/lov/lov_obd.c
index 94dfd64bd283..ea503d2a19f8 100644
--- a/drivers/staging/lustre/lustre/lov/lov_obd.c
+++ b/drivers/staging/lustre/lustre/lov/lov_obd.c
@@ -168,8 +168,8 @@ int lov_connect_obd(struct obd_device *obd, __u32 index, int activate,
168 168
169 169
170 if (imp->imp_invalid) { 170 if (imp->imp_invalid) {
171 CDEBUG(D_CONFIG, "not connecting OSC %s; administratively " 171 CDEBUG(D_CONFIG, "not connecting OSC %s; administratively disabled\n",
172 "disabled\n", obd_uuid2str(tgt_uuid)); 172 obd_uuid2str(tgt_uuid));
173 return 0; 173 return 0;
174 } 174 }
175 175
@@ -201,10 +201,9 @@ int lov_connect_obd(struct obd_device *obd, __u32 index, int activate,
201 osc_obd->obd_type->typ_name, 201 osc_obd->obd_type->typ_name,
202 osc_obd->obd_name); 202 osc_obd->obd_name);
203 if (osc_symlink == NULL) { 203 if (osc_symlink == NULL) {
204 CERROR("could not register LOV target " 204 CERROR("could not register LOV target /proc/fs/lustre/%s/%s/target_obds/%s.",
205 "/proc/fs/lustre/%s/%s/target_obds/%s.", 205 obd->obd_type->typ_name, obd->obd_name,
206 obd->obd_type->typ_name, obd->obd_name, 206 osc_obd->obd_name);
207 osc_obd->obd_name);
208 lprocfs_remove(&lov_proc_dir); 207 lprocfs_remove(&lov_proc_dir);
209 obd->obd_proc_private = NULL; 208 obd->obd_proc_private = NULL;
210 } 209 }
@@ -726,8 +725,7 @@ void lov_fix_desc_stripe_size(__u64 *val)
726{ 725{
727 if (*val < LOV_MIN_STRIPE_SIZE) { 726 if (*val < LOV_MIN_STRIPE_SIZE) {
728 if (*val != 0) 727 if (*val != 0)
729 LCONSOLE_INFO("Increasing default stripe size to " 728 LCONSOLE_INFO("Increasing default stripe size to minimum %u\n",
730 "minimum %u\n",
731 LOV_DESC_STRIPE_SIZE_DEFAULT); 729 LOV_DESC_STRIPE_SIZE_DEFAULT);
732 *val = LOV_DESC_STRIPE_SIZE_DEFAULT; 730 *val = LOV_DESC_STRIPE_SIZE_DEFAULT;
733 } else if (*val & (LOV_MIN_STRIPE_SIZE - 1)) { 731 } else if (*val & (LOV_MIN_STRIPE_SIZE - 1)) {
@@ -847,7 +845,6 @@ out:
847 845
848static int lov_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage) 846static int lov_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
849{ 847{
850 int rc = 0;
851 struct lov_obd *lov = &obd->u.lov; 848 struct lov_obd *lov = &obd->u.lov;
852 849
853 switch (stage) { 850 switch (stage) {
@@ -865,7 +862,7 @@ static int lov_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
865 break; 862 break;
866 } 863 }
867 864
868 return rc; 865 return 0;
869} 866}
870 867
871static int lov_cleanup(struct obd_device *obd) 868static int lov_cleanup(struct obd_device *obd)
@@ -900,8 +897,7 @@ static int lov_cleanup(struct obd_device *obd)
900 /* We should never get here - these 897 /* We should never get here - these
901 should have been removed in the 898 should have been removed in the
902 disconnect. */ 899 disconnect. */
903 CERROR("lov tgt %d not cleaned!" 900 CERROR("lov tgt %d not cleaned! deathrow=%d, lovrc=%d\n",
904 " deathrow=%d, lovrc=%d\n",
905 i, lov->lov_death_row, 901 i, lov->lov_death_row,
906 atomic_read(&lov->lov_refcount)); 902 atomic_read(&lov->lov_refcount));
907 lov_del_target(obd, i, NULL, 0); 903 lov_del_target(obd, i, NULL, 0);
@@ -1176,8 +1172,8 @@ static int lov_getattr_async(struct obd_export *exp, struct obd_info *oinfo,
1176 list_for_each(pos, &lovset->set_list) { 1172 list_for_each(pos, &lovset->set_list) {
1177 req = list_entry(pos, struct lov_request, rq_link); 1173 req = list_entry(pos, struct lov_request, rq_link);
1178 1174
1179 CDEBUG(D_INFO, "objid "DOSTID"[%d] has subobj "DOSTID" at idx" 1175 CDEBUG(D_INFO, "objid " DOSTID "[%d] has subobj " DOSTID " at idx%u\n",
1180 "%u\n", POSTID(&oinfo->oi_oa->o_oi), req->rq_stripe, 1176 POSTID(&oinfo->oi_oa->o_oi), req->rq_stripe,
1181 POSTID(&req->rq_oi.oi_oa->o_oi), req->rq_idx); 1177 POSTID(&req->rq_oi.oi_oa->o_oi), req->rq_idx);
1182 rc = obd_getattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp, 1178 rc = obd_getattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
1183 &req->rq_oi, rqset); 1179 &req->rq_oi, rqset);
@@ -1256,8 +1252,8 @@ static int lov_setattr_async(struct obd_export *exp, struct obd_info *oinfo,
1256 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE) 1252 if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE)
1257 oti->oti_logcookies = set->set_cookies + req->rq_stripe; 1253 oti->oti_logcookies = set->set_cookies + req->rq_stripe;
1258 1254
1259 CDEBUG(D_INFO, "objid "DOSTID"[%d] has subobj "DOSTID" at idx" 1255 CDEBUG(D_INFO, "objid " DOSTID "[%d] has subobj " DOSTID " at idx%u\n",
1260 "%u\n", POSTID(&oinfo->oi_oa->o_oi), req->rq_stripe, 1256 POSTID(&oinfo->oi_oa->o_oi), req->rq_stripe,
1261 POSTID(&req->rq_oi.oi_oa->o_oi), req->rq_idx); 1257 POSTID(&req->rq_oi.oi_oa->o_oi), req->rq_idx);
1262 1258
1263 rc = obd_setattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp, 1259 rc = obd_setattr_async(lov->lov_tgts[req->rq_idx]->ltd_exp,
@@ -1568,8 +1564,7 @@ static int lov_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1568 if (lov->lov_tgts[i]->ltd_active) { 1564 if (lov->lov_tgts[i]->ltd_active) {
1569 CDEBUG(err == -ENOTTY ? 1565 CDEBUG(err == -ENOTTY ?
1570 D_IOCTL : D_WARNING, 1566 D_IOCTL : D_WARNING,
1571 "iocontrol OSC %s on OST " 1567 "iocontrol OSC %s on OST idx %d cmd %x: err = %d\n",
1572 "idx %d cmd %x: err = %d\n",
1573 lov_uuid2str(lov, i), 1568 lov_uuid2str(lov, i),
1574 i, cmd, err); 1569 i, cmd, err);
1575 if (!rc) 1570 if (!rc)
@@ -2266,8 +2261,8 @@ static int lov_quotacheck(struct obd_device *obd, struct obd_export *exp,
2266 2261
2267 /* Skip quota check on the administratively disabled OSTs. */ 2262 /* Skip quota check on the administratively disabled OSTs. */
2268 if (!lov->lov_tgts[i]->ltd_activate) { 2263 if (!lov->lov_tgts[i]->ltd_activate) {
2269 CWARN("lov idx %d was administratively disabled, " 2264 CWARN("lov idx %d was administratively disabled, skip quotacheck on it.\n",
2270 "skip quotacheck on it.\n", i); 2265 i);
2271 continue; 2266 continue;
2272 } 2267 }
2273 2268
diff --git a/drivers/staging/lustre/lustre/lov/lov_pack.c b/drivers/staging/lustre/lustre/lov/lov_pack.c
index 5edd6a3a9c54..5356d5324176 100644
--- a/drivers/staging/lustre/lustre/lov/lov_pack.c
+++ b/drivers/staging/lustre/lustre/lov/lov_pack.c
@@ -438,8 +438,7 @@ int lov_getstripe(struct obd_export *exp, struct lov_stripe_md *lsm,
438 if (copy_from_user(&lum, lump, lum_size)) { 438 if (copy_from_user(&lum, lump, lum_size)) {
439 rc = -EFAULT; 439 rc = -EFAULT;
440 goto out_set; 440 goto out_set;
441 } 441 } else if ((lum.lmm_magic != LOV_USER_MAGIC) &&
442 else if ((lum.lmm_magic != LOV_USER_MAGIC) &&
443 (lum.lmm_magic != LOV_USER_MAGIC_V3)) { 442 (lum.lmm_magic != LOV_USER_MAGIC_V3)) {
444 rc = -EINVAL; 443 rc = -EINVAL;
445 goto out_set; 444 goto out_set;
diff --git a/drivers/staging/lustre/lustre/mdc/mdc_lib.c b/drivers/staging/lustre/lustre/mdc/mdc_lib.c
index e8732cc30ce2..4e59995e0042 100644
--- a/drivers/staging/lustre/lustre/mdc/mdc_lib.c
+++ b/drivers/staging/lustre/lustre/mdc/mdc_lib.c
@@ -194,10 +194,8 @@ static __u64 mds_pack_open_flags(__u64 flags, __u32 mode)
194 cr_flags |= MDS_OPEN_SYNC; 194 cr_flags |= MDS_OPEN_SYNC;
195 if (flags & O_DIRECTORY) 195 if (flags & O_DIRECTORY)
196 cr_flags |= MDS_OPEN_DIRECTORY; 196 cr_flags |= MDS_OPEN_DIRECTORY;
197#ifdef FMODE_EXEC 197 if (flags & __FMODE_EXEC)
198 if (flags & FMODE_EXEC)
199 cr_flags |= MDS_FMODE_EXEC; 198 cr_flags |= MDS_FMODE_EXEC;
200#endif
201 if (cl_is_lov_delay_create(flags)) 199 if (cl_is_lov_delay_create(flags))
202 cr_flags |= MDS_OPEN_DELAY_CREATE; 200 cr_flags |= MDS_OPEN_DELAY_CREATE;
203 201
diff --git a/drivers/staging/lustre/lustre/mdc/mdc_locks.c b/drivers/staging/lustre/lustre/mdc/mdc_locks.c
index b58147ee62b6..8c9b4f5494e9 100644
--- a/drivers/staging/lustre/lustre/mdc/mdc_locks.c
+++ b/drivers/staging/lustre/lustre/mdc/mdc_locks.c
@@ -296,10 +296,8 @@ static struct ptlrpc_request *mdc_intent_open_pack(struct obd_export *exp,
296 } else { 296 } else {
297 if (it->it_flags & (FMODE_WRITE|MDS_OPEN_TRUNC)) 297 if (it->it_flags & (FMODE_WRITE|MDS_OPEN_TRUNC))
298 mode = LCK_CW; 298 mode = LCK_CW;
299#ifdef FMODE_EXEC 299 else if (it->it_flags & __FMODE_EXEC)
300 else if (it->it_flags & FMODE_EXEC)
301 mode = LCK_PR; 300 mode = LCK_PR;
302#endif
303 else 301 else
304 mode = LCK_CR; 302 mode = LCK_CR;
305 } 303 }
diff --git a/drivers/staging/lustre/lustre/mdc/mdc_request.c b/drivers/staging/lustre/lustre/mdc/mdc_request.c
index 14e1ba1675f6..3b0f245a8780 100644
--- a/drivers/staging/lustre/lustre/mdc/mdc_request.c
+++ b/drivers/staging/lustre/lustre/mdc/mdc_request.c
@@ -60,7 +60,7 @@ struct mdc_renew_capa_args {
60 60
61static int mdc_cleanup(struct obd_device *obd); 61static int mdc_cleanup(struct obd_device *obd);
62 62
63int mdc_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req, 63static int mdc_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req,
64 const struct req_msg_field *field, struct obd_capa **oc) 64 const struct req_msg_field *field, struct obd_capa **oc)
65{ 65{
66 struct lustre_capa *capa; 66 struct lustre_capa *capa;
@@ -147,7 +147,7 @@ out:
147} 147}
148 148
149/* This should be mdc_get_info("rootfid") */ 149/* This should be mdc_get_info("rootfid") */
150int mdc_getstatus(struct obd_export *exp, struct lu_fid *rootfid, 150static int mdc_getstatus(struct obd_export *exp, struct lu_fid *rootfid,
151 struct obd_capa **pc) 151 struct obd_capa **pc)
152{ 152{
153 return send_getstatus(class_exp2cliimp(exp), rootfid, pc, 153 return send_getstatus(class_exp2cliimp(exp), rootfid, pc,
@@ -214,7 +214,7 @@ static int mdc_getattr_common(struct obd_export *exp,
214 return 0; 214 return 0;
215} 215}
216 216
217int mdc_getattr(struct obd_export *exp, struct md_op_data *op_data, 217static int mdc_getattr(struct obd_export *exp, struct md_op_data *op_data,
218 struct ptlrpc_request **request) 218 struct ptlrpc_request **request)
219{ 219{
220 struct ptlrpc_request *req; 220 struct ptlrpc_request *req;
@@ -258,7 +258,7 @@ int mdc_getattr(struct obd_export *exp, struct md_op_data *op_data,
258 return rc; 258 return rc;
259} 259}
260 260
261int mdc_getattr_name(struct obd_export *exp, struct md_op_data *op_data, 261static int mdc_getattr_name(struct obd_export *exp, struct md_op_data *op_data,
262 struct ptlrpc_request **request) 262 struct ptlrpc_request **request)
263{ 263{
264 struct ptlrpc_request *req; 264 struct ptlrpc_request *req;
@@ -441,7 +441,7 @@ static int mdc_xattr_common(struct obd_export *exp,
441 return rc; 441 return rc;
442} 442}
443 443
444int mdc_setxattr(struct obd_export *exp, const struct lu_fid *fid, 444static int mdc_setxattr(struct obd_export *exp, const struct lu_fid *fid,
445 struct obd_capa *oc, u64 valid, const char *xattr_name, 445 struct obd_capa *oc, u64 valid, const char *xattr_name,
446 const char *input, int input_size, int output_size, 446 const char *input, int input_size, int output_size,
447 int flags, __u32 suppgid, struct ptlrpc_request **request) 447 int flags, __u32 suppgid, struct ptlrpc_request **request)
@@ -452,7 +452,7 @@ int mdc_setxattr(struct obd_export *exp, const struct lu_fid *fid,
452 suppgid, request); 452 suppgid, request);
453} 453}
454 454
455int mdc_getxattr(struct obd_export *exp, const struct lu_fid *fid, 455static int mdc_getxattr(struct obd_export *exp, const struct lu_fid *fid,
456 struct obd_capa *oc, u64 valid, const char *xattr_name, 456 struct obd_capa *oc, u64 valid, const char *xattr_name,
457 const char *input, int input_size, int output_size, 457 const char *input, int input_size, int output_size,
458 int flags, struct ptlrpc_request **request) 458 int flags, struct ptlrpc_request **request)
diff --git a/drivers/staging/lustre/lustre/mgc/mgc_request.c b/drivers/staging/lustre/lustre/mgc/mgc_request.c
index bc263adf09d4..60d2b0f12693 100644
--- a/drivers/staging/lustre/lustre/mgc/mgc_request.c
+++ b/drivers/staging/lustre/lustre/mgc/mgc_request.c
@@ -510,8 +510,6 @@ static void do_requeue(struct config_llog_data *cld)
510 510
511static int mgc_requeue_thread(void *data) 511static int mgc_requeue_thread(void *data)
512{ 512{
513 int rc = 0;
514
515 CDEBUG(D_MGC, "Starting requeue thread\n"); 513 CDEBUG(D_MGC, "Starting requeue thread\n");
516 514
517 /* Keep trying failed locks periodically */ 515 /* Keep trying failed locks periodically */
@@ -592,7 +590,7 @@ static int mgc_requeue_thread(void *data)
592 complete(&rq_exit); 590 complete(&rq_exit);
593 591
594 CDEBUG(D_MGC, "Ending requeue thread\n"); 592 CDEBUG(D_MGC, "Ending requeue thread\n");
595 return rc; 593 return 0;
596} 594}
597 595
598/* Add a cld to the list to requeue. Start the requeue thread if needed. 596/* Add a cld to the list to requeue. Start the requeue thread if needed.
@@ -736,8 +734,7 @@ static int mgc_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
736 rc = PTR_ERR(kthread_run(mgc_requeue_thread, NULL, 734 rc = PTR_ERR(kthread_run(mgc_requeue_thread, NULL,
737 "ll_cfg_requeue")); 735 "ll_cfg_requeue"));
738 if (IS_ERR_VALUE(rc)) { 736 if (IS_ERR_VALUE(rc)) {
739 CERROR("%s: Cannot start requeue thread (%d)," 737 CERROR("%s: Cannot start requeue thread (%d),no more log updates!\n",
740 "no more log updates!\n",
741 obd->obd_name, rc); 738 obd->obd_name, rc);
742 goto err_cleanup; 739 goto err_cleanup;
743 } 740 }
@@ -1021,8 +1018,7 @@ int mgc_set_info_async(const struct lu_env *env, struct obd_export *exp,
1021 1018
1022 sptlrpc_flavor2name(&cli->cl_flvr_mgc, 1019 sptlrpc_flavor2name(&cli->cl_flvr_mgc,
1023 str, sizeof(str)); 1020 str, sizeof(str));
1024 LCONSOLE_ERROR("asking sptlrpc flavor %s to MGS but " 1021 LCONSOLE_ERROR("asking sptlrpc flavor %s to MGS but currently %s is in use\n",
1025 "currently %s is in use\n",
1026 (char *) val, str); 1022 (char *) val, str);
1027 rc = -EPERM; 1023 rc = -EPERM;
1028 } 1024 }
@@ -1055,8 +1051,6 @@ static int mgc_import_event(struct obd_device *obd,
1055 struct obd_import *imp, 1051 struct obd_import *imp,
1056 enum obd_import_event event) 1052 enum obd_import_event event)
1057{ 1053{
1058 int rc = 0;
1059
1060 LASSERT(imp->imp_obd == obd); 1054 LASSERT(imp->imp_obd == obd);
1061 CDEBUG(D_MGC, "import event %#x\n", event); 1055 CDEBUG(D_MGC, "import event %#x\n", event);
1062 1056
@@ -1090,7 +1084,7 @@ static int mgc_import_event(struct obd_device *obd,
1090 CERROR("Unknown import event %#x\n", event); 1084 CERROR("Unknown import event %#x\n", event);
1091 LBUG(); 1085 LBUG();
1092 } 1086 }
1093 return rc; 1087 return 0;
1094} 1088}
1095 1089
1096enum { 1090enum {
diff --git a/drivers/staging/lustre/lustre/obdclass/acl.c b/drivers/staging/lustre/lustre/obdclass/acl.c
index 2619bfeceb8b..9a69f6b35a0e 100644
--- a/drivers/staging/lustre/lustre/obdclass/acl.c
+++ b/drivers/staging/lustre/lustre/obdclass/acl.c
@@ -171,17 +171,17 @@ EXPORT_SYMBOL(lustre_posix_acl_xattr_2ext);
171/* 171/*
172 * Filter out the "nobody" entries in the posix ACL. 172 * Filter out the "nobody" entries in the posix ACL.
173 */ 173 */
174int lustre_posix_acl_xattr_filter(posix_acl_xattr_header *header, int size, 174int lustre_posix_acl_xattr_filter(posix_acl_xattr_header *header, size_t size,
175 posix_acl_xattr_header **out) 175 posix_acl_xattr_header **out)
176{ 176{
177 int count, i, j, rc = 0; 177 int count, i, j, rc = 0;
178 __u32 id; 178 __u32 id;
179 posix_acl_xattr_header *new; 179 posix_acl_xattr_header *new;
180 180
181 if (unlikely(size < 0)) 181 if (!size)
182 return -EINVAL;
183 else if (!size)
184 return 0; 182 return 0;
183 if (size < sizeof(*new))
184 return -EINVAL;
185 185
186 OBD_ALLOC(new, size); 186 OBD_ALLOC(new, size);
187 if (unlikely(new == NULL)) 187 if (unlikely(new == NULL))
diff --git a/drivers/staging/lustre/lustre/obdclass/capa.c b/drivers/staging/lustre/lustre/obdclass/capa.c
index cd1abce378ea..d206b1046a18 100644
--- a/drivers/staging/lustre/lustre/obdclass/capa.c
+++ b/drivers/staging/lustre/lustre/obdclass/capa.c
@@ -272,8 +272,7 @@ int capa_hmac(__u8 *hmac, struct lustre_capa *capa, __u8 *key)
272 272
273 tfm = crypto_alloc_hash(alg->ha_name, 0, 0); 273 tfm = crypto_alloc_hash(alg->ha_name, 0, 0);
274 if (IS_ERR(tfm)) { 274 if (IS_ERR(tfm)) {
275 CERROR("crypto_alloc_tfm failed, check whether your kernel" 275 CERROR("crypto_alloc_tfm failed, check whether your kernel has crypto support!\n");
276 "has crypto support!\n");
277 return PTR_ERR(tfm); 276 return PTR_ERR(tfm);
278 } 277 }
279 keylen = alg->ha_keylen; 278 keylen = alg->ha_keylen;
@@ -302,7 +301,7 @@ int capa_encrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen)
302 301
303 /* passing "aes" in a variable instead of a constant string keeps gcc 302 /* passing "aes" in a variable instead of a constant string keeps gcc
304 * 4.3.2 happy */ 303 * 4.3.2 happy */
305 tfm = crypto_alloc_blkcipher(alg, 0, 0 ); 304 tfm = crypto_alloc_blkcipher(alg, 0, 0);
306 if (IS_ERR(tfm)) { 305 if (IS_ERR(tfm)) {
307 CERROR("failed to load transform for aes\n"); 306 CERROR("failed to load transform for aes\n");
308 return PTR_ERR(tfm); 307 return PTR_ERR(tfm);
@@ -355,7 +354,7 @@ int capa_decrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen)
355 354
356 /* passing "aes" in a variable instead of a constant string keeps gcc 355 /* passing "aes" in a variable instead of a constant string keeps gcc
357 * 4.3.2 happy */ 356 * 4.3.2 happy */
358 tfm = crypto_alloc_blkcipher(alg, 0, 0 ); 357 tfm = crypto_alloc_blkcipher(alg, 0, 0);
359 if (IS_ERR(tfm)) { 358 if (IS_ERR(tfm)) {
360 CERROR("failed to load transform for aes\n"); 359 CERROR("failed to load transform for aes\n");
361 return PTR_ERR(tfm); 360 return PTR_ERR(tfm);
@@ -407,14 +406,13 @@ EXPORT_SYMBOL(capa_cpy);
407 406
408void _debug_capa(struct lustre_capa *c, 407void _debug_capa(struct lustre_capa *c,
409 struct libcfs_debug_msg_data *msgdata, 408 struct libcfs_debug_msg_data *msgdata,
410 const char *fmt, ... ) 409 const char *fmt, ...)
411{ 410{
412 va_list args; 411 va_list args;
413 va_start(args, fmt); 412 va_start(args, fmt);
414 libcfs_debug_vmsg2(msgdata, fmt, args, 413 libcfs_debug_vmsg2(msgdata, fmt, args,
415 " capability@%p fid "DFID" opc %#llx uid %llu" 414 " capability@%p fid " DFID " opc %#llx uid %llu gid %llu flags %u alg %d keyid %u timeout %u expiry %u\n",
416 " gid %llu flags %u alg %d keyid %u timeout %u " 415 c, PFID(capa_fid(c)), capa_opc(c),
417 "expiry %u\n", c, PFID(capa_fid(c)), capa_opc(c),
418 capa_uid(c), capa_gid(c), capa_flags(c), 416 capa_uid(c), capa_gid(c), capa_flags(c),
419 capa_alg(c), capa_keyid(c), capa_timeout(c), 417 capa_alg(c), capa_keyid(c), capa_timeout(c),
420 capa_expiry(c)); 418 capa_expiry(c));
diff --git a/drivers/staging/lustre/lustre/obdclass/cl_io.c b/drivers/staging/lustre/lustre/obdclass/cl_io.c
index f2383a497cbe..3141b6043708 100644
--- a/drivers/staging/lustre/lustre/obdclass/cl_io.c
+++ b/drivers/staging/lustre/lustre/obdclass/cl_io.c
@@ -1622,8 +1622,7 @@ int cl_sync_io_wait(const struct lu_env *env, struct cl_io *io,
1622 atomic_read(&anchor->csi_sync_nr) == 0, 1622 atomic_read(&anchor->csi_sync_nr) == 0,
1623 &lwi); 1623 &lwi);
1624 if (rc < 0) { 1624 if (rc < 0) {
1625 CERROR("SYNC IO failed with error: %d, try to cancel " 1625 CERROR("SYNC IO failed with error: %d, try to cancel %d remaining pages\n",
1626 "%d remaining pages\n",
1627 rc, atomic_read(&anchor->csi_sync_nr)); 1626 rc, atomic_read(&anchor->csi_sync_nr));
1628 1627
1629 (void)cl_io_cancel(env, io, queue); 1628 (void)cl_io_cancel(env, io, queue);
diff --git a/drivers/staging/lustre/lustre/obdclass/cl_lock.c b/drivers/staging/lustre/lustre/obdclass/cl_lock.c
index b204531ef710..b081167f9767 100644
--- a/drivers/staging/lustre/lustre/obdclass/cl_lock.c
+++ b/drivers/staging/lustre/lustre/obdclass/cl_lock.c
@@ -129,8 +129,7 @@ static void cl_lock_trace0(int level, const struct lu_env *env,
129 const char *func, const int line) 129 const char *func, const int line)
130{ 130{
131 struct cl_object_header *h = cl_object_header(lock->cll_descr.cld_obj); 131 struct cl_object_header *h = cl_object_header(lock->cll_descr.cld_obj);
132 CDEBUG(level, "%s: %p@(%d %p %d %d %d %d %d %lx)" 132 CDEBUG(level, "%s: %p@(%d %p %d %d %d %d %d %lx)(%p/%d/%d) at %s():%d\n",
133 "(%p/%d/%d) at %s():%d\n",
134 prefix, lock, atomic_read(&lock->cll_ref), 133 prefix, lock, atomic_read(&lock->cll_ref),
135 lock->cll_guarder, lock->cll_depth, 134 lock->cll_guarder, lock->cll_depth,
136 lock->cll_state, lock->cll_error, lock->cll_holds, 135 lock->cll_state, lock->cll_error, lock->cll_holds,
diff --git a/drivers/staging/lustre/lustre/obdclass/class_obd.c b/drivers/staging/lustre/lustre/obdclass/class_obd.c
index 7265ecbc6f9d..89a3fb2e56b2 100644
--- a/drivers/staging/lustre/lustre/obdclass/class_obd.c
+++ b/drivers/staging/lustre/lustre/obdclass/class_obd.c
@@ -144,13 +144,11 @@ int obd_alloc_fail(const void *ptr, const char *name, const char *type,
144 CERROR("%s%salloc of %s (%llu bytes) failed at %s:%d\n", 144 CERROR("%s%salloc of %s (%llu bytes) failed at %s:%d\n",
145 ptr ? "force " :"", type, name, (__u64)size, file, 145 ptr ? "force " :"", type, name, (__u64)size, file,
146 line); 146 line);
147 CERROR("%llu total bytes and %llu total pages " 147 CERROR("%llu total bytes and %llu total pages (%llu bytes) allocated by Lustre, %d total bytes by LNET\n",
148 "(%llu bytes) allocated by Lustre, "
149 "%d total bytes by LNET\n",
150 obd_memory_sum(), 148 obd_memory_sum(),
151 obd_pages_sum() << PAGE_CACHE_SHIFT, 149 obd_pages_sum() << PAGE_CACHE_SHIFT,
152 obd_pages_sum(), 150 obd_pages_sum(),
153 atomic_read(&libcfs_kmemory)); 151 atomic_read(&libcfs_kmemory));
154 return 1; 152 return 1;
155 } 153 }
156 return 0; 154 return 0;
diff --git a/drivers/staging/lustre/lustre/obdclass/debug.c b/drivers/staging/lustre/lustre/obdclass/debug.c
index d0f8f875ddd6..9c934e6d2ea1 100644
--- a/drivers/staging/lustre/lustre/obdclass/debug.c
+++ b/drivers/staging/lustre/lustre/obdclass/debug.c
@@ -40,6 +40,7 @@
40 40
41#define DEBUG_SUBSYSTEM D_OTHER 41#define DEBUG_SUBSYSTEM D_OTHER
42 42
43#include <linux/unaligned/access_ok.h>
43 44
44#include "../include/obd_support.h" 45#include "../include/obd_support.h"
45#include "../include/lustre_debug.h" 46#include "../include/lustre_debug.h"
@@ -60,14 +61,11 @@ int block_debug_setup(void *addr, int len, __u64 off, __u64 id)
60{ 61{
61 LASSERT(addr); 62 LASSERT(addr);
62 63
63 off = cpu_to_le64 (off); 64 put_unaligned_le64(off, addr);
64 id = cpu_to_le64 (id); 65 put_unaligned_le64(id, addr+LPDS);
65 memcpy(addr, (char *)&off, LPDS);
66 memcpy(addr + LPDS, (char *)&id, LPDS);
67
68 addr += len - LPDS - LPDS; 66 addr += len - LPDS - LPDS;
69 memcpy(addr, (char *)&off, LPDS); 67 put_unaligned_le64(off, addr);
70 memcpy(addr + LPDS, (char *)&id, LPDS); 68 put_unaligned_le64(id, addr+LPDS);
71 69
72 return 0; 70 return 0;
73} 71}
diff --git a/drivers/staging/lustre/lustre/obdclass/dt_object.c b/drivers/staging/lustre/lustre/obdclass/dt_object.c
index 52256c26bf07..e7be26ec7521 100644
--- a/drivers/staging/lustre/lustre/obdclass/dt_object.c
+++ b/drivers/staging/lustre/lustre/obdclass/dt_object.c
@@ -332,8 +332,7 @@ static struct dt_object *dt_reg_open(const struct lu_env *env,
332 result = dt_lookup_dir(env, p, name, fid); 332 result = dt_lookup_dir(env, p, name, fid);
333 if (result == 0){ 333 if (result == 0){
334 o = dt_locate(env, dt, fid); 334 o = dt_locate(env, dt, fid);
335 } 335 } else
336 else
337 o = ERR_PTR(result); 336 o = ERR_PTR(result);
338 337
339 return o; 338 return o;
@@ -950,8 +949,8 @@ int lprocfs_dt_rd_blksize(char *page, char **start, off_t off,
950{ 949{
951 struct dt_device *dt = data; 950 struct dt_device *dt = data;
952 struct obd_statfs osfs; 951 struct obd_statfs osfs;
953
954 int rc = dt_statfs(NULL, dt, &osfs); 952 int rc = dt_statfs(NULL, dt, &osfs);
953
955 if (rc == 0) { 954 if (rc == 0) {
956 *eof = 1; 955 *eof = 1;
957 rc = snprintf(page, count, "%u\n", 956 rc = snprintf(page, count, "%u\n",
@@ -967,8 +966,8 @@ int lprocfs_dt_rd_kbytestotal(char *page, char **start, off_t off,
967{ 966{
968 struct dt_device *dt = data; 967 struct dt_device *dt = data;
969 struct obd_statfs osfs; 968 struct obd_statfs osfs;
970
971 int rc = dt_statfs(NULL, dt, &osfs); 969 int rc = dt_statfs(NULL, dt, &osfs);
970
972 if (rc == 0) { 971 if (rc == 0) {
973 __u32 blk_size = osfs.os_bsize >> 10; 972 __u32 blk_size = osfs.os_bsize >> 10;
974 __u64 result = osfs.os_blocks; 973 __u64 result = osfs.os_blocks;
@@ -989,8 +988,8 @@ int lprocfs_dt_rd_kbytesfree(char *page, char **start, off_t off,
989{ 988{
990 struct dt_device *dt = data; 989 struct dt_device *dt = data;
991 struct obd_statfs osfs; 990 struct obd_statfs osfs;
992
993 int rc = dt_statfs(NULL, dt, &osfs); 991 int rc = dt_statfs(NULL, dt, &osfs);
992
994 if (rc == 0) { 993 if (rc == 0) {
995 __u32 blk_size = osfs.os_bsize >> 10; 994 __u32 blk_size = osfs.os_bsize >> 10;
996 __u64 result = osfs.os_bfree; 995 __u64 result = osfs.os_bfree;
@@ -1011,8 +1010,8 @@ int lprocfs_dt_rd_kbytesavail(char *page, char **start, off_t off,
1011{ 1010{
1012 struct dt_device *dt = data; 1011 struct dt_device *dt = data;
1013 struct obd_statfs osfs; 1012 struct obd_statfs osfs;
1014
1015 int rc = dt_statfs(NULL, dt, &osfs); 1013 int rc = dt_statfs(NULL, dt, &osfs);
1014
1016 if (rc == 0) { 1015 if (rc == 0) {
1017 __u32 blk_size = osfs.os_bsize >> 10; 1016 __u32 blk_size = osfs.os_bsize >> 10;
1018 __u64 result = osfs.os_bavail; 1017 __u64 result = osfs.os_bavail;
@@ -1033,8 +1032,8 @@ int lprocfs_dt_rd_filestotal(char *page, char **start, off_t off,
1033{ 1032{
1034 struct dt_device *dt = data; 1033 struct dt_device *dt = data;
1035 struct obd_statfs osfs; 1034 struct obd_statfs osfs;
1036
1037 int rc = dt_statfs(NULL, dt, &osfs); 1035 int rc = dt_statfs(NULL, dt, &osfs);
1036
1038 if (rc == 0) { 1037 if (rc == 0) {
1039 *eof = 1; 1038 *eof = 1;
1040 rc = snprintf(page, count, "%llu\n", osfs.os_files); 1039 rc = snprintf(page, count, "%llu\n", osfs.os_files);
@@ -1049,8 +1048,8 @@ int lprocfs_dt_rd_filesfree(char *page, char **start, off_t off,
1049{ 1048{
1050 struct dt_device *dt = data; 1049 struct dt_device *dt = data;
1051 struct obd_statfs osfs; 1050 struct obd_statfs osfs;
1052
1053 int rc = dt_statfs(NULL, dt, &osfs); 1051 int rc = dt_statfs(NULL, dt, &osfs);
1052
1054 if (rc == 0) { 1053 if (rc == 0) {
1055 *eof = 1; 1054 *eof = 1;
1056 rc = snprintf(page, count, "%llu\n", osfs.os_ffree); 1055 rc = snprintf(page, count, "%llu\n", osfs.os_ffree);
diff --git a/drivers/staging/lustre/lustre/obdclass/genops.c b/drivers/staging/lustre/lustre/obdclass/genops.c
index c314e9c2343e..736ca410aca3 100644
--- a/drivers/staging/lustre/lustre/obdclass/genops.c
+++ b/drivers/staging/lustre/lustre/obdclass/genops.c
@@ -317,7 +317,7 @@ struct obd_device *class_newdev(const char *type_name, const char *name)
317 result->obd_minor, new_obd_minor); 317 result->obd_minor, new_obd_minor);
318 318
319 obd_devs[result->obd_minor] = NULL; 319 obd_devs[result->obd_minor] = NULL;
320 result->obd_name[0]='\0'; 320 result->obd_name[0] = '\0';
321 } 321 }
322 result = ERR_PTR(-EEXIST); 322 result = ERR_PTR(-EEXIST);
323 break; 323 break;
@@ -524,8 +524,8 @@ void class_obd_list(void)
524/* Search for a client OBD connected to tgt_uuid. If grp_uuid is 524/* Search for a client OBD connected to tgt_uuid. If grp_uuid is
525 specified, then only the client with that uuid is returned, 525 specified, then only the client with that uuid is returned,
526 otherwise any client connected to the tgt is returned. */ 526 otherwise any client connected to the tgt is returned. */
527struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid, 527struct obd_device *class_find_client_obd(struct obd_uuid *tgt_uuid,
528 const char * typ_name, 528 const char *typ_name,
529 struct obd_uuid *grp_uuid) 529 struct obd_uuid *grp_uuid)
530{ 530{
531 int i; 531 int i;
@@ -557,7 +557,7 @@ EXPORT_SYMBOL(class_find_client_obd);
557 searching at *next, and if a device is found, the next index to look 557 searching at *next, and if a device is found, the next index to look
558 at is saved in *next. If next is NULL, then the first matching device 558 at is saved in *next. If next is NULL, then the first matching device
559 will always be returned. */ 559 will always be returned. */
560struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid, int *next) 560struct obd_device *class_devices_in_group(struct obd_uuid *grp_uuid, int *next)
561{ 561{
562 int i; 562 int i;
563 563
@@ -1087,8 +1087,7 @@ void __class_export_del_lock_ref(struct obd_export *exp, struct ldlm_lock *lock)
1087 spin_lock(&exp->exp_locks_list_guard); 1087 spin_lock(&exp->exp_locks_list_guard);
1088 LASSERT(lock->l_exp_refs_nr > 0); 1088 LASSERT(lock->l_exp_refs_nr > 0);
1089 if (lock->l_exp_refs_target != exp) { 1089 if (lock->l_exp_refs_target != exp) {
1090 LCONSOLE_WARN("lock %p, " 1090 LCONSOLE_WARN("lock %p, mismatching export pointers: %p, %p\n",
1091 "mismatching export pointers: %p, %p\n",
1092 lock, lock->l_exp_refs_target, exp); 1091 lock, lock->l_exp_refs_target, exp);
1093 } 1092 }
1094 if (-- lock->l_exp_refs_nr == 0) { 1093 if (-- lock->l_exp_refs_nr == 0) {
@@ -1259,8 +1258,7 @@ static void class_disconnect_export_list(struct list_head *list,
1259 } 1258 }
1260 1259
1261 class_export_get(exp); 1260 class_export_get(exp);
1262 CDEBUG(D_HA, "%s: disconnecting export at %s (%p), " 1261 CDEBUG(D_HA, "%s: disconnecting export at %s (%p), last request at " CFS_TIME_T "\n",
1263 "last request at "CFS_TIME_T"\n",
1264 exp->exp_obd->obd_name, obd_export_nid2str(exp), 1262 exp->exp_obd->obd_name, obd_export_nid2str(exp),
1265 exp, exp->exp_last_request_time); 1263 exp, exp->exp_last_request_time);
1266 /* release one export reference anyway */ 1264 /* release one export reference anyway */
@@ -1284,8 +1282,8 @@ void class_disconnect_exports(struct obd_device *obd)
1284 spin_unlock(&obd->obd_dev_lock); 1282 spin_unlock(&obd->obd_dev_lock);
1285 1283
1286 if (!list_empty(&work_list)) { 1284 if (!list_empty(&work_list)) {
1287 CDEBUG(D_HA, "OBD device %d (%p) has exports, " 1285 CDEBUG(D_HA, "OBD device %d (%p) has exports, disconnecting them\n",
1288 "disconnecting them\n", obd->obd_minor, obd); 1286 obd->obd_minor, obd);
1289 class_disconnect_export_list(&work_list, 1287 class_disconnect_export_list(&work_list,
1290 exp_flags_from_obd(obd)); 1288 exp_flags_from_obd(obd));
1291 } else 1289 } else
@@ -1422,8 +1420,8 @@ int obd_export_evict_by_nid(struct obd_device *obd, const char *nid)
1422 LASSERTF(doomed_exp != obd->obd_self_export, 1420 LASSERTF(doomed_exp != obd->obd_self_export,
1423 "self-export is hashed by NID?\n"); 1421 "self-export is hashed by NID?\n");
1424 exports_evicted++; 1422 exports_evicted++;
1425 LCONSOLE_WARN("%s: evicting %s (at %s) by administrative " 1423 LCONSOLE_WARN("%s: evicting %s (at %s) by administrative request\n",
1426 "request\n", obd->obd_name, 1424 obd->obd_name,
1427 obd_uuid2str(&doomed_exp->exp_client_uuid), 1425 obd_uuid2str(&doomed_exp->exp_client_uuid),
1428 obd_export_nid2str(doomed_exp)); 1426 obd_export_nid2str(doomed_exp));
1429 class_fail_export(doomed_exp); 1427 class_fail_export(doomed_exp);
@@ -1546,9 +1544,7 @@ void obd_exports_barrier(struct obd_device *obd)
1546 set_current_state(TASK_UNINTERRUPTIBLE); 1544 set_current_state(TASK_UNINTERRUPTIBLE);
1547 schedule_timeout(cfs_time_seconds(waited)); 1545 schedule_timeout(cfs_time_seconds(waited));
1548 if (waited > 5 && IS_PO2(waited)) { 1546 if (waited > 5 && IS_PO2(waited)) {
1549 LCONSOLE_WARN("%s is waiting for obd_unlinked_exports " 1547 LCONSOLE_WARN("%s is waiting for obd_unlinked_exports more than %d seconds. The obd refcount = %d. Is it stuck?\n",
1550 "more than %d seconds. "
1551 "The obd refcount = %d. Is it stuck?\n",
1552 obd->obd_name, waited, 1548 obd->obd_name, waited,
1553 atomic_read(&obd->obd_refcount)); 1549 atomic_read(&obd->obd_refcount));
1554 dump_exports(obd, 1); 1550 dump_exports(obd, 1);
@@ -1783,7 +1779,7 @@ EXPORT_SYMBOL(kuc_len);
1783 * @param p Pointer to payload area 1779 * @param p Pointer to payload area
1784 * @returns Pointer to kuc header 1780 * @returns Pointer to kuc header
1785 */ 1781 */
1786struct kuc_hdr * kuc_ptr(void *p) 1782struct kuc_hdr *kuc_ptr(void *p)
1787{ 1783{
1788 struct kuc_hdr *lh = ((struct kuc_hdr *)p) - 1; 1784 struct kuc_hdr *lh = ((struct kuc_hdr *)p) - 1;
1789 LASSERT(lh->kuc_magic == KUC_MAGIC); 1785 LASSERT(lh->kuc_magic == KUC_MAGIC);
diff --git a/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c b/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
index 7eaaaa648dfb..66ceab20c743 100644
--- a/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
+++ b/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
@@ -166,14 +166,14 @@ int obd_ioctl_popdata(void *arg, void *data, int len)
166EXPORT_SYMBOL(obd_ioctl_popdata); 166EXPORT_SYMBOL(obd_ioctl_popdata);
167 167
168/* opening /dev/obd */ 168/* opening /dev/obd */
169static int obd_class_open(struct inode * inode, struct file * file) 169static int obd_class_open(struct inode *inode, struct file *file)
170{ 170{
171 try_module_get(THIS_MODULE); 171 try_module_get(THIS_MODULE);
172 return 0; 172 return 0;
173} 173}
174 174
175/* closing /dev/obd */ 175/* closing /dev/obd */
176static int obd_class_release(struct inode * inode, struct file * file) 176static int obd_class_release(struct inode *inode, struct file *file)
177{ 177{
178 module_put(THIS_MODULE); 178 module_put(THIS_MODULE);
179 return 0; 179 return 0;
diff --git a/drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c b/drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c
index 38a9b319355e..dd46e7358160 100644
--- a/drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c
+++ b/drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c
@@ -202,9 +202,8 @@ static int proc_max_dirty_pages_in_mb(struct ctl_table *table, int write,
202 /* Don't allow them to let dirty pages exceed 90% of system 202 /* Don't allow them to let dirty pages exceed 90% of system
203 * memory and set a hard minimum of 4MB. */ 203 * memory and set a hard minimum of 4MB. */
204 if (obd_max_dirty_pages > ((totalram_pages / 10) * 9)) { 204 if (obd_max_dirty_pages > ((totalram_pages / 10) * 9)) {
205 CERROR("Refusing to set max dirty pages to %u, which " 205 CERROR("Refusing to set max dirty pages to %u, which is more than 90%% of available RAM; setting to %lu\n",
206 "is more than 90%% of available RAM; setting " 206 obd_max_dirty_pages,
207 "to %lu\n", obd_max_dirty_pages,
208 ((totalram_pages / 10) * 9)); 207 ((totalram_pages / 10) * 9));
209 obd_max_dirty_pages = ((totalram_pages / 10) * 9); 208 obd_max_dirty_pages = ((totalram_pages / 10) * 9);
210 } else if (obd_max_dirty_pages < 4 << (20 - PAGE_CACHE_SHIFT)) { 209 } else if (obd_max_dirty_pages < 4 << (20 - PAGE_CACHE_SHIFT)) {
diff --git a/drivers/staging/lustre/lustre/obdclass/llog.c b/drivers/staging/lustre/lustre/obdclass/llog.c
index 3ab05292152c..114be4a78ccf 100644
--- a/drivers/staging/lustre/lustre/obdclass/llog.c
+++ b/drivers/staging/lustre/lustre/obdclass/llog.c
@@ -346,8 +346,8 @@ repeat:
346 } 346 }
347 if (rec->lrh_len == 0 || 347 if (rec->lrh_len == 0 ||
348 rec->lrh_len > LLOG_CHUNK_SIZE) { 348 rec->lrh_len > LLOG_CHUNK_SIZE) {
349 CWARN("invalid length %d in llog record for " 349 CWARN("invalid length %d in llog record for index %d/%d\n",
350 "index %d/%d\n", rec->lrh_len, 350 rec->lrh_len,
351 rec->lrh_index, index); 351 rec->lrh_index, index);
352 rc = -EINVAL; 352 rc = -EINVAL;
353 goto out; 353 goto out;
diff --git a/drivers/staging/lustre/lustre/obdclass/llog_cat.c b/drivers/staging/lustre/lustre/obdclass/llog_cat.c
index 6e139cf372c4..4b850fc5f5d9 100644
--- a/drivers/staging/lustre/lustre/obdclass/llog_cat.c
+++ b/drivers/staging/lustre/lustre/obdclass/llog_cat.c
@@ -228,8 +228,7 @@ int llog_cat_close(const struct lu_env *env, struct llog_handle *cathandle)
228 (llh->llh_count == 1)) { 228 (llh->llh_count == 1)) {
229 rc = llog_destroy(env, loghandle); 229 rc = llog_destroy(env, loghandle);
230 if (rc) 230 if (rc)
231 CERROR("%s: failure destroying log during " 231 CERROR("%s: failure destroying log during cleanup: rc = %d\n",
232 "cleanup: rc = %d\n",
233 loghandle->lgh_ctxt->loc_obd->obd_name, 232 loghandle->lgh_ctxt->loc_obd->obd_name,
234 rc); 233 rc);
235 234
@@ -746,8 +745,7 @@ int llog_cat_cleanup(const struct lu_env *env, struct llog_handle *cathandle,
746 llog_cat_set_first_idx(cathandle, index); 745 llog_cat_set_first_idx(cathandle, index);
747 rc = llog_cancel_rec(env, cathandle, index); 746 rc = llog_cancel_rec(env, cathandle, index);
748 if (rc == 0) 747 if (rc == 0)
749 CDEBUG(D_HA, "cancel plain log at index" 748 CDEBUG(D_HA, "cancel plain log at index %u of catalog " DOSTID "\n",
750 " %u of catalog "DOSTID"\n",
751 index, POSTID(&cathandle->lgh_id.lgl_oi)); 749 index, POSTID(&cathandle->lgh_id.lgl_oi));
752 return rc; 750 return rc;
753} 751}
@@ -810,8 +808,8 @@ int llog_cat_init_and_process(const struct lu_env *env,
810 808
811 rc = llog_process_or_fork(env, llh, cat_cancel_cb, NULL, NULL, false); 809 rc = llog_process_or_fork(env, llh, cat_cancel_cb, NULL, NULL, false);
812 if (rc) 810 if (rc)
813 CERROR("%s: llog_process() with cat_cancel_cb failed: rc = " 811 CERROR("%s: llog_process() with cat_cancel_cb failed: rc = %d\n",
814 "%d\n", llh->lgh_ctxt->loc_obd->obd_name, rc); 812 llh->lgh_ctxt->loc_obd->obd_name, rc);
815 return 0; 813 return 0;
816} 814}
817EXPORT_SYMBOL(llog_cat_init_and_process); 815EXPORT_SYMBOL(llog_cat_init_and_process);
diff --git a/drivers/staging/lustre/lustre/obdclass/llog_obd.c b/drivers/staging/lustre/lustre/obdclass/llog_obd.c
index da769db0af77..978d886a1103 100644
--- a/drivers/staging/lustre/lustre/obdclass/llog_obd.c
+++ b/drivers/staging/lustre/lustre/obdclass/llog_obd.c
@@ -42,7 +42,7 @@
42#include "llog_internal.h" 42#include "llog_internal.h"
43 43
44/* helper functions for calling the llog obd methods */ 44/* helper functions for calling the llog obd methods */
45static struct llog_ctxt* llog_new_ctxt(struct obd_device *obd) 45static struct llog_ctxt *llog_new_ctxt(struct obd_device *obd)
46{ 46{
47 struct llog_ctxt *ctxt; 47 struct llog_ctxt *ctxt;
48 48
diff --git a/drivers/staging/lustre/lustre/obdclass/llog_swab.c b/drivers/staging/lustre/lustre/obdclass/llog_swab.c
index bfac8387021e..d3ec90e85eb9 100644
--- a/drivers/staging/lustre/lustre/obdclass/llog_swab.c
+++ b/drivers/staging/lustre/lustre/obdclass/llog_swab.c
@@ -400,8 +400,7 @@ void lustre_swab_cfg_marker(struct cfg_marker *marker, int swab, int size)
400 } 400 }
401 marker->cm_createtime = createtime; 401 marker->cm_createtime = createtime;
402 marker->cm_canceltime = canceltime; 402 marker->cm_canceltime = canceltime;
403 CDEBUG(D_CONFIG, "Find old cfg_marker(Srv32b,Clt64b) " 403 CDEBUG(D_CONFIG, "Find old cfg_marker(Srv32b,Clt64b) for target %s, converting\n",
404 "for target %s, converting\n",
405 marker->cm_tgtname); 404 marker->cm_tgtname);
406 } else if (swab) { 405 } else if (swab) {
407 __swab64s(&marker->cm_createtime); 406 __swab64s(&marker->cm_createtime);
diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
index 61e04af2464f..3b7dfc367722 100644
--- a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
+++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
@@ -177,7 +177,7 @@ int lprocfs_read_frac_helper(char *buffer, unsigned long count, long val,
177} 177}
178EXPORT_SYMBOL(lprocfs_read_frac_helper); 178EXPORT_SYMBOL(lprocfs_read_frac_helper);
179 179
180int lprocfs_write_frac_helper(const char *buffer, unsigned long count, 180int lprocfs_write_frac_helper(const char __user *buffer, unsigned long count,
181 int *val, int mult) 181 int *val, int mult)
182{ 182{
183 char kernbuf[20], *end, *pbuf; 183 char kernbuf[20], *end, *pbuf;
@@ -1400,8 +1400,8 @@ int lprocfs_alloc_obd_stats(struct obd_device *obd, unsigned num_private_stats)
1400 * LPROCFS_OBD_OP_INIT(.., .., opname) 1400 * LPROCFS_OBD_OP_INIT(.., .., opname)
1401 * is missing from the list above. */ 1401 * is missing from the list above. */
1402 LASSERTF(stats->ls_cnt_header[i].lc_name != NULL, 1402 LASSERTF(stats->ls_cnt_header[i].lc_name != NULL,
1403 "Missing obd_stat initializer obd_op " 1403 "Missing obd_stat initializer obd_op operation at offset %d.\n",
1404 "operation at offset %d.\n", i - num_private_stats); 1404 i - num_private_stats);
1405 } 1405 }
1406 rc = lprocfs_register_stats(obd->obd_proc_entry, "stats", stats); 1406 rc = lprocfs_register_stats(obd->obd_proc_entry, "stats", stats);
1407 if (rc < 0) { 1407 if (rc < 0) {
@@ -1486,8 +1486,7 @@ int lprocfs_alloc_md_stats(struct obd_device *obd,
1486 1486
1487 for (i = num_private_stats; i < num_stats; i++) { 1487 for (i = num_private_stats; i < num_stats; i++) {
1488 if (stats->ls_cnt_header[i].lc_name == NULL) { 1488 if (stats->ls_cnt_header[i].lc_name == NULL) {
1489 CERROR("Missing md_stat initializer md_op " 1489 CERROR("Missing md_stat initializer md_op operation at offset %d. Aborting.\n",
1490 "operation at offset %d. Aborting.\n",
1491 i - num_private_stats); 1490 i - num_private_stats);
1492 LBUG(); 1491 LBUG();
1493 } 1492 }
@@ -1607,8 +1606,7 @@ LPROC_SEQ_FOPS_RO(lproc_exp_hash);
1607int lprocfs_nid_stats_clear_read(struct seq_file *m, void *data) 1606int lprocfs_nid_stats_clear_read(struct seq_file *m, void *data)
1608{ 1607{
1609 return seq_printf(m, "%s\n", 1608 return seq_printf(m, "%s\n",
1610 "Write into this file to clear all nid stats and " 1609 "Write into this file to clear all nid stats and stale nid entries");
1611 "stale nid entries");
1612} 1610}
1613EXPORT_SYMBOL(lprocfs_nid_stats_clear_read); 1611EXPORT_SYMBOL(lprocfs_nid_stats_clear_read);
1614 1612
@@ -1819,7 +1817,7 @@ __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
1819} 1817}
1820EXPORT_SYMBOL(lprocfs_read_helper); 1818EXPORT_SYMBOL(lprocfs_read_helper);
1821 1819
1822int lprocfs_write_helper(const char *buffer, unsigned long count, 1820int lprocfs_write_helper(const char __user *buffer, unsigned long count,
1823 int *val) 1821 int *val)
1824{ 1822{
1825 return lprocfs_write_frac_helper(buffer, count, val, 1); 1823 return lprocfs_write_frac_helper(buffer, count, val, 1);
diff --git a/drivers/staging/lustre/lustre/obdclass/lu_object.c b/drivers/staging/lustre/lustre/obdclass/lu_object.c
index 2fc037cfb62f..83bf168c2939 100644
--- a/drivers/staging/lustre/lustre/obdclass/lu_object.c
+++ b/drivers/staging/lustre/lustre/obdclass/lu_object.c
@@ -866,8 +866,7 @@ static int lu_htable_order(void)
866 866
867 /* clear off unreasonable cache setting. */ 867 /* clear off unreasonable cache setting. */
868 if (lu_cache_percent == 0 || lu_cache_percent > LU_CACHE_PERCENT_MAX) { 868 if (lu_cache_percent == 0 || lu_cache_percent > LU_CACHE_PERCENT_MAX) {
869 CWARN("obdclass: invalid lu_cache_percent: %u, it must be in" 869 CWARN("obdclass: invalid lu_cache_percent: %u, it must be in the range of (0, %u]. Will use default value: %u.\n",
870 " the range of (0, %u]. Will use default value: %u.\n",
871 lu_cache_percent, LU_CACHE_PERCENT_MAX, 870 lu_cache_percent, LU_CACHE_PERCENT_MAX,
872 LU_CACHE_PERCENT_DEFAULT); 871 LU_CACHE_PERCENT_DEFAULT);
873 872
diff --git a/drivers/staging/lustre/lustre/obdclass/obd_config.c b/drivers/staging/lustre/lustre/obdclass/obd_config.c
index 5e7b3d7cc984..6ce9adc2f11c 100644
--- a/drivers/staging/lustre/lustre/obdclass/obd_config.c
+++ b/drivers/staging/lustre/lustre/obdclass/obd_config.c
@@ -835,7 +835,7 @@ int class_del_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
835 835
836LIST_HEAD(lustre_profile_list); 836LIST_HEAD(lustre_profile_list);
837 837
838struct lustre_profile *class_get_profile(const char * prof) 838struct lustre_profile *class_get_profile(const char *prof)
839{ 839{
840 struct lustre_profile *lprof; 840 struct lustre_profile *lprof;
841 841
@@ -1443,8 +1443,7 @@ int class_config_llog_handler(const struct lu_env *env,
1443 if (!(clli->cfg_flags & CFG_F_COMPAT146) && 1443 if (!(clli->cfg_flags & CFG_F_COMPAT146) &&
1444 !(clli->cfg_flags & CFG_F_MARKER) && 1444 !(clli->cfg_flags & CFG_F_MARKER) &&
1445 (lcfg->lcfg_command != LCFG_MARKER)) { 1445 (lcfg->lcfg_command != LCFG_MARKER)) {
1446 CWARN("Config not inside markers, ignoring! " 1446 CWARN("Config not inside markers, ignoring! (inst: %p, uuid: %s, flags: %#x)\n",
1447 "(inst: %p, uuid: %s, flags: %#x)\n",
1448 clli->cfg_instance, 1447 clli->cfg_instance,
1449 clli->cfg_uuid.uuid, clli->cfg_flags); 1448 clli->cfg_uuid.uuid, clli->cfg_flags);
1450 clli->cfg_flags |= CFG_F_SKIP; 1449 clli->cfg_flags |= CFG_F_SKIP;
@@ -1467,14 +1466,12 @@ int class_config_llog_handler(const struct lu_env *env,
1467 1466
1468 if ((lcfg->lcfg_command == LCFG_ATTACH && typename && 1467 if ((lcfg->lcfg_command == LCFG_ATTACH && typename &&
1469 strcmp(typename, "mds") == 0)) { 1468 strcmp(typename, "mds") == 0)) {
1470 CWARN("For 1.8 interoperability, rename obd " 1469 CWARN("For 1.8 interoperability, rename obd type from mds to mdt\n");
1471 "type from mds to mdt\n");
1472 typename[2] = 't'; 1470 typename[2] = 't';
1473 } 1471 }
1474 if ((lcfg->lcfg_command == LCFG_SETUP && index && 1472 if ((lcfg->lcfg_command == LCFG_SETUP && index &&
1475 strcmp(index, "type") == 0)) { 1473 strcmp(index, "type") == 0)) {
1476 CDEBUG(D_INFO, "For 1.8 interoperability, " 1474 CDEBUG(D_INFO, "For 1.8 interoperability, set this index to '0'\n");
1477 "set this index to '0'\n");
1478 index[0] = '0'; 1475 index[0] = '0';
1479 index[1] = 0; 1476 index[1] = 0;
1480 } 1477 }
diff --git a/drivers/staging/lustre/lustre/obdclass/obd_mount.c b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
index 1260c8713bc6..4f39cdee1b5c 100644
--- a/drivers/staging/lustre/lustre/obdclass/obd_mount.c
+++ b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
@@ -100,19 +100,12 @@ int lustre_process_log(struct super_block *sb, char *logname,
100 OBD_FREE_PTR(bufs); 100 OBD_FREE_PTR(bufs);
101 101
102 if (rc == -EINVAL) 102 if (rc == -EINVAL)
103 LCONSOLE_ERROR_MSG(0x15b, "%s: The configuration from log '%s'" 103 LCONSOLE_ERROR_MSG(0x15b, "%s: The configuration from log '%s' failed from the MGS (%d). Make sure this client and the MGS are running compatible versions of Lustre.\n",
104 "failed from the MGS (%d). Make sure this "
105 "client and the MGS are running compatible "
106 "versions of Lustre.\n",
107 mgc->obd_name, logname, rc); 104 mgc->obd_name, logname, rc);
108 105
109 if (rc) 106 if (rc)
110 LCONSOLE_ERROR_MSG(0x15c, "%s: The configuration from log '%s' " 107 LCONSOLE_ERROR_MSG(0x15c, "%s: The configuration from log '%s' failed (%d). This may be the result of communication errors between this node and the MGS, a bad configuration, or other errors. See the syslog for more information.\n",
111 "failed (%d). This may be the result of " 108 mgc->obd_name, logname,
112 "communication errors between this node and "
113 "the MGS, a bad configuration, or other "
114 "errors. See the syslog for more "
115 "information.\n", mgc->obd_name, logname,
116 rc); 109 rc);
117 110
118 /* class_obd_list(); */ 111 /* class_obd_list(); */
@@ -297,11 +290,8 @@ int lustre_start_mgc(struct super_block *sb)
297 if (has_ir ^ !(*flags & LMD_FLG_NOIR)) { 290 if (has_ir ^ !(*flags & LMD_FLG_NOIR)) {
298 /* LMD_FLG_NOIR is for test purpose only */ 291 /* LMD_FLG_NOIR is for test purpose only */
299 LCONSOLE_WARN( 292 LCONSOLE_WARN(
300 "Trying to mount a client with IR setting " 293 "Trying to mount a client with IR setting not compatible with current mgc. Force to use current mgc setting that is IR %s.\n",
301 "not compatible with current mgc. " 294 has_ir ? "enabled" : "disabled");
302 "Force to use current mgc setting that is "
303 "IR %s.\n",
304 has_ir ? "enabled" : "disabled");
305 if (has_ir) 295 if (has_ir)
306 *flags &= ~LMD_FLG_NOIR; 296 *flags &= ~LMD_FLG_NOIR;
307 else 297 else
@@ -998,16 +988,14 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd)
998 988
999 LASSERT(lmd); 989 LASSERT(lmd);
1000 if (!options) { 990 if (!options) {
1001 LCONSOLE_ERROR_MSG(0x162, "Missing mount data: check that " 991 LCONSOLE_ERROR_MSG(0x162, "Missing mount data: check that /sbin/mount.lustre is installed.\n");
1002 "/sbin/mount.lustre is installed.\n");
1003 return -EINVAL; 992 return -EINVAL;
1004 } 993 }
1005 994
1006 /* Options should be a string - try to detect old lmd data */ 995 /* Options should be a string - try to detect old lmd data */
1007 if ((raw->lmd_magic & 0xffffff00) == (LMD_MAGIC & 0xffffff00)) { 996 if ((raw->lmd_magic & 0xffffff00) == (LMD_MAGIC & 0xffffff00)) {
1008 LCONSOLE_ERROR_MSG(0x163, "You're using an old version of " 997 LCONSOLE_ERROR_MSG(0x163, "You're using an old version of /sbin/mount.lustre. Please install version %s\n",
1009 "/sbin/mount.lustre. Please install " 998 LUSTRE_VERSION_STRING);
1010 "version %s\n", LUSTRE_VERSION_STRING);
1011 return -EINVAL; 999 return -EINVAL;
1012 } 1000 }
1013 lmd->lmd_magic = LMD_MAGIC; 1001 lmd->lmd_magic = LMD_MAGIC;
@@ -1139,8 +1127,7 @@ static int lmd_parse(char *options, struct lustre_mount_data *lmd)
1139 } 1127 }
1140 1128
1141 if (!devname) { 1129 if (!devname) {
1142 LCONSOLE_ERROR_MSG(0x164, "Can't find the device name " 1130 LCONSOLE_ERROR_MSG(0x164, "Can't find the device name (need mount option 'device=...')\n");
1143 "(need mount option 'device=...')\n");
1144 goto invalid; 1131 goto invalid;
1145 } 1132 }
1146 1133
@@ -1232,9 +1219,7 @@ int lustre_fill_super(struct super_block *sb, void *data, int silent)
1232 if (client_fill_super == NULL) 1219 if (client_fill_super == NULL)
1233 request_module("lustre"); 1220 request_module("lustre");
1234 if (client_fill_super == NULL) { 1221 if (client_fill_super == NULL) {
1235 LCONSOLE_ERROR_MSG(0x165, "Nothing registered for " 1222 LCONSOLE_ERROR_MSG(0x165, "Nothing registered for client mount! Is the 'lustre' module loaded?\n");
1236 "client mount! Is the 'lustre' "
1237 "module loaded?\n");
1238 lustre_put_lsi(sb); 1223 lustre_put_lsi(sb);
1239 rc = -ENODEV; 1224 rc = -ENODEV;
1240 } else { 1225 } else {
@@ -1249,8 +1234,7 @@ int lustre_fill_super(struct super_block *sb, void *data, int silent)
1249 /* c_f_s will call lustre_common_put_super on failure */ 1234 /* c_f_s will call lustre_common_put_super on failure */
1250 } 1235 }
1251 } else { 1236 } else {
1252 CERROR("This is client-side-only module, " 1237 CERROR("This is client-side-only module, cannot handle server mount.\n");
1253 "cannot handle server mount.\n");
1254 rc = -EINVAL; 1238 rc = -EINVAL;
1255 } 1239 }
1256 1240
diff --git a/drivers/staging/lustre/lustre/obdecho/echo_client.c b/drivers/staging/lustre/lustre/obdecho/echo_client.c
index 98e4290919d0..5f6d9441bc44 100644
--- a/drivers/staging/lustre/lustre/obdecho/echo_client.c
+++ b/drivers/staging/lustre/lustre/obdecho/echo_client.c
@@ -698,14 +698,16 @@ static struct lu_device *echo_device_alloc(const struct lu_env *env,
698 int cleanup = 0; 698 int cleanup = 0;
699 699
700 OBD_ALLOC_PTR(ed); 700 OBD_ALLOC_PTR(ed);
701 if (ed == NULL) 701 if (ed == NULL) {
702 GOTO(out, rc = -ENOMEM); 702 rc = -ENOMEM;
703 goto out;
704 }
703 705
704 cleanup = 1; 706 cleanup = 1;
705 cd = &ed->ed_cl; 707 cd = &ed->ed_cl;
706 rc = cl_device_init(cd, t); 708 rc = cl_device_init(cd, t);
707 if (rc) 709 if (rc)
708 GOTO(out, rc); 710 goto out;
709 711
710 cd->cd_lu_dev.ld_ops = &echo_device_lu_ops; 712 cd->cd_lu_dev.ld_ops = &echo_device_lu_ops;
711 cd->cd_ops = &echo_device_cl_ops; 713 cd->cd_ops = &echo_device_cl_ops;
@@ -719,24 +721,26 @@ static struct lu_device *echo_device_alloc(const struct lu_env *env,
719 if (tgt == NULL) { 721 if (tgt == NULL) {
720 CERROR("Can not find tgt device %s\n", 722 CERROR("Can not find tgt device %s\n",
721 lustre_cfg_string(cfg, 1)); 723 lustre_cfg_string(cfg, 1));
722 GOTO(out, rc = -ENODEV); 724 rc = -ENODEV;
725 goto out;
723 } 726 }
724 727
725 next = tgt->obd_lu_dev; 728 next = tgt->obd_lu_dev;
726 if (!strcmp(tgt->obd_type->typ_name, LUSTRE_MDT_NAME)) { 729 if (!strcmp(tgt->obd_type->typ_name, LUSTRE_MDT_NAME)) {
727 CERROR("echo MDT client must be run on server\n"); 730 CERROR("echo MDT client must be run on server\n");
728 GOTO(out, rc = -EOPNOTSUPP); 731 rc = -EOPNOTSUPP;
732 goto out;
729 } 733 }
730 734
731 rc = echo_site_init(env, ed); 735 rc = echo_site_init(env, ed);
732 if (rc) 736 if (rc)
733 GOTO(out, rc); 737 goto out;
734 738
735 cleanup = 3; 739 cleanup = 3;
736 740
737 rc = echo_client_setup(env, obd, cfg); 741 rc = echo_client_setup(env, obd, cfg);
738 if (rc) 742 if (rc)
739 GOTO(out, rc); 743 goto out;
740 744
741 ed->ed_ec = &obd->u.echo_client; 745 ed->ed_ec = &obd->u.echo_client;
742 cleanup = 4; 746 cleanup = 4;
@@ -749,15 +753,17 @@ static struct lu_device *echo_device_alloc(const struct lu_env *env,
749 tgt_type_name = tgt->obd_type->typ_name; 753 tgt_type_name = tgt->obd_type->typ_name;
750 if (next != NULL) { 754 if (next != NULL) {
751 LASSERT(next != NULL); 755 LASSERT(next != NULL);
752 if (next->ld_site != NULL) 756 if (next->ld_site != NULL) {
753 GOTO(out, rc = -EBUSY); 757 rc = -EBUSY;
758 goto out;
759 }
754 760
755 next->ld_site = &ed->ed_site->cs_lu; 761 next->ld_site = &ed->ed_site->cs_lu;
756 rc = next->ld_type->ldt_ops->ldto_device_init(env, next, 762 rc = next->ld_type->ldt_ops->ldto_device_init(env, next,
757 next->ld_type->ldt_name, 763 next->ld_type->ldt_name,
758 NULL); 764 NULL);
759 if (rc) 765 if (rc)
760 GOTO(out, rc); 766 goto out;
761 767
762 /* Tricky case, I have to determine the obd type since 768 /* Tricky case, I have to determine the obd type since
763 * CLIO uses the different parameters to initialize 769 * CLIO uses the different parameters to initialize
@@ -865,8 +871,7 @@ static struct lu_device *echo_device_free(const struct lu_env *env,
865 spin_lock(&ec->ec_lock); 871 spin_lock(&ec->ec_lock);
866 while (!list_empty(&ec->ec_objects)) { 872 while (!list_empty(&ec->ec_objects)) {
867 spin_unlock(&ec->ec_lock); 873 spin_unlock(&ec->ec_lock);
868 CERROR("echo_client still has objects at cleanup time, " 874 CERROR("echo_client still has objects at cleanup time, wait for 1 second\n");
869 "wait for 1 second\n");
870 set_current_state(TASK_UNINTERRUPTIBLE); 875 set_current_state(TASK_UNINTERRUPTIBLE);
871 schedule_timeout(cfs_time_seconds(1)); 876 schedule_timeout(cfs_time_seconds(1));
872 lu_site_purge(env, &ed->ed_site->cs_lu, -1); 877 lu_site_purge(env, &ed->ed_site->cs_lu, -1);
@@ -968,15 +973,19 @@ static struct echo_object *cl_echo_object_find(struct echo_device *d,
968 973
969 fid = &info->eti_fid; 974 fid = &info->eti_fid;
970 rc = ostid_to_fid(fid, &lsm->lsm_oi, 0); 975 rc = ostid_to_fid(fid, &lsm->lsm_oi, 0);
971 if (rc != 0) 976 if (rc != 0) {
972 GOTO(out, eco = ERR_PTR(rc)); 977 eco = ERR_PTR(rc);
978 goto out;
979 }
973 980
974 /* In the function below, .hs_keycmp resolves to 981 /* In the function below, .hs_keycmp resolves to
975 * lu_obj_hop_keycmp() */ 982 * lu_obj_hop_keycmp() */
976 /* coverity[overrun-buffer-val] */ 983 /* coverity[overrun-buffer-val] */
977 obj = cl_object_find(env, echo_dev2cl(d), fid, &conf->eoc_cl); 984 obj = cl_object_find(env, echo_dev2cl(d), fid, &conf->eoc_cl);
978 if (IS_ERR(obj)) 985 if (IS_ERR(obj)) {
979 GOTO(out, eco = (void *)obj); 986 eco = (void *)obj;
987 goto out;
988 }
980 989
981 eco = cl2echo_obj(obj); 990 eco = cl2echo_obj(obj);
982 if (eco->eo_deleted) { 991 if (eco->eo_deleted) {
@@ -1076,7 +1085,7 @@ static int cl_echo_enqueue(struct echo_object *eco, u64 start, u64 end,
1076 io->ci_ignore_layout = 1; 1085 io->ci_ignore_layout = 1;
1077 result = cl_io_init(env, io, CIT_MISC, echo_obj2cl(eco)); 1086 result = cl_io_init(env, io, CIT_MISC, echo_obj2cl(eco));
1078 if (result < 0) 1087 if (result < 0)
1079 GOTO(out, result); 1088 goto out;
1080 LASSERT(result == 0); 1089 LASSERT(result == 0);
1081 1090
1082 result = cl_echo_enqueue0(env, eco, start, end, mode, cookie, 0); 1091 result = cl_echo_enqueue0(env, eco, start, end, mode, cookie, 0);
@@ -1182,7 +1191,7 @@ static int cl_echo_object_brw(struct echo_object *eco, int rw, u64 offset,
1182 io->ci_ignore_layout = 1; 1191 io->ci_ignore_layout = 1;
1183 rc = cl_io_init(env, io, CIT_MISC, obj); 1192 rc = cl_io_init(env, io, CIT_MISC, obj);
1184 if (rc < 0) 1193 if (rc < 0)
1185 GOTO(out, rc); 1194 goto out;
1186 LASSERT(rc == 0); 1195 LASSERT(rc == 0);
1187 1196
1188 1197
@@ -1191,7 +1200,7 @@ static int cl_echo_object_brw(struct echo_object *eco, int rw, u64 offset,
1191 rw == READ ? LCK_PR : LCK_PW, &lh.cookie, 1200 rw == READ ? LCK_PR : LCK_PW, &lh.cookie,
1192 CEF_NEVER); 1201 CEF_NEVER);
1193 if (rc < 0) 1202 if (rc < 0)
1194 GOTO(error_lock, rc); 1203 goto error_lock;
1195 1204
1196 for (i = 0; i < npages; i++) { 1205 for (i = 0; i < npages; i++) {
1197 LASSERT(pages[i]); 1206 LASSERT(pages[i]);
@@ -1318,7 +1327,7 @@ static int echo_create_object(const struct lu_env *env, struct echo_device *ed,
1318 rc = echo_alloc_memmd(ed, &lsm); 1327 rc = echo_alloc_memmd(ed, &lsm);
1319 if (rc < 0) { 1328 if (rc < 0) {
1320 CERROR("Cannot allocate md: rc = %d\n", rc); 1329 CERROR("Cannot allocate md: rc = %d\n", rc);
1321 GOTO(failed, rc); 1330 goto failed;
1322 } 1331 }
1323 1332
1324 if (ulsm != NULL) { 1333 if (ulsm != NULL) {
@@ -1326,7 +1335,7 @@ static int echo_create_object(const struct lu_env *env, struct echo_device *ed,
1326 1335
1327 rc = echo_copyin_lsm (ed, lsm, ulsm, ulsm_nob); 1336 rc = echo_copyin_lsm (ed, lsm, ulsm, ulsm_nob);
1328 if (rc != 0) 1337 if (rc != 0)
1329 GOTO(failed, rc); 1338 goto failed;
1330 1339
1331 if (lsm->lsm_stripe_count == 0) 1340 if (lsm->lsm_stripe_count == 0)
1332 lsm->lsm_stripe_count = ec->ec_nstripes; 1341 lsm->lsm_stripe_count = ec->ec_nstripes;
@@ -1363,7 +1372,7 @@ static int echo_create_object(const struct lu_env *env, struct echo_device *ed,
1363 rc = obd_create(env, ec->ec_exp, oa, &lsm, oti); 1372 rc = obd_create(env, ec->ec_exp, oa, &lsm, oti);
1364 if (rc != 0) { 1373 if (rc != 0) {
1365 CERROR("Cannot create objects: rc = %d\n", rc); 1374 CERROR("Cannot create objects: rc = %d\n", rc);
1366 GOTO(failed, rc); 1375 goto failed;
1367 } 1376 }
1368 created = 1; 1377 created = 1;
1369 } 1378 }
@@ -1373,8 +1382,10 @@ static int echo_create_object(const struct lu_env *env, struct echo_device *ed,
1373 oa->o_valid |= OBD_MD_FLID; 1382 oa->o_valid |= OBD_MD_FLID;
1374 1383
1375 eco = cl_echo_object_find(ed, &lsm); 1384 eco = cl_echo_object_find(ed, &lsm);
1376 if (IS_ERR(eco)) 1385 if (IS_ERR(eco)) {
1377 GOTO(failed, rc = PTR_ERR(eco)); 1386 rc = PTR_ERR(eco);
1387 goto failed;
1388 }
1378 cl_echo_object_put(eco); 1389 cl_echo_object_put(eco);
1379 1390
1380 CDEBUG(D_INFO, "oa oid "DOSTID"\n", POSTID(&oa->o_oi)); 1391 CDEBUG(D_INFO, "oa oid "DOSTID"\n", POSTID(&oa->o_oi));
@@ -1642,8 +1653,10 @@ static int echo_client_prep_commit(const struct lu_env *env,
1642 OBD_ALLOC(lnb, npages * sizeof(struct niobuf_local)); 1653 OBD_ALLOC(lnb, npages * sizeof(struct niobuf_local));
1643 OBD_ALLOC(rnb, npages * sizeof(struct niobuf_remote)); 1654 OBD_ALLOC(rnb, npages * sizeof(struct niobuf_remote));
1644 1655
1645 if (lnb == NULL || rnb == NULL) 1656 if (lnb == NULL || rnb == NULL) {
1646 GOTO(out, ret = -ENOMEM); 1657 ret = -ENOMEM;
1658 goto out;
1659 }
1647 1660
1648 if (rw == OBD_BRW_WRITE && async) 1661 if (rw == OBD_BRW_WRITE && async)
1649 brw_flags |= OBD_BRW_ASYNC; 1662 brw_flags |= OBD_BRW_ASYNC;
@@ -1671,7 +1684,7 @@ static int echo_client_prep_commit(const struct lu_env *env,
1671 ret = obd_preprw(env, rw, exp, oa, 1, &ioo, rnb, &lpages, 1684 ret = obd_preprw(env, rw, exp, oa, 1, &ioo, rnb, &lpages,
1672 lnb, oti, NULL); 1685 lnb, oti, NULL);
1673 if (ret != 0) 1686 if (ret != 0)
1674 GOTO(out, ret); 1687 goto out;
1675 LASSERT(lpages == npages); 1688 LASSERT(lpages == npages);
1676 1689
1677 for (i = 0; i < lpages; i++) { 1690 for (i = 0; i < lpages; i++) {
@@ -1704,7 +1717,7 @@ static int echo_client_prep_commit(const struct lu_env *env,
1704 ret = obd_commitrw(env, rw, exp, oa, 1, &ioo, 1717 ret = obd_commitrw(env, rw, exp, oa, 1, &ioo,
1705 rnb, npages, lnb, oti, ret); 1718 rnb, npages, lnb, oti, ret);
1706 if (ret != 0) 1719 if (ret != 0)
1707 GOTO(out, ret); 1720 goto out;
1708 1721
1709 /* Reset oti otherwise it would confuse ldiskfs. */ 1722 /* Reset oti otherwise it would confuse ldiskfs. */
1710 memset(oti, 0, sizeof(*oti)); 1723 memset(oti, 0, sizeof(*oti));
@@ -1862,21 +1875,27 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1862 return -ENOMEM; 1875 return -ENOMEM;
1863 1876
1864 rc = lu_env_init(env, LCT_DT_THREAD); 1877 rc = lu_env_init(env, LCT_DT_THREAD);
1865 if (rc) 1878 if (rc) {
1866 GOTO(out, rc = -ENOMEM); 1879 rc = -ENOMEM;
1880 goto out;
1881 }
1867 1882
1868 switch (cmd) { 1883 switch (cmd) {
1869 case OBD_IOC_CREATE: /* may create echo object */ 1884 case OBD_IOC_CREATE: /* may create echo object */
1870 if (!capable(CFS_CAP_SYS_ADMIN)) 1885 if (!capable(CFS_CAP_SYS_ADMIN)) {
1871 GOTO (out, rc = -EPERM); 1886 rc = -EPERM;
1887 goto out;
1888 }
1872 1889
1873 rc = echo_create_object(env, ed, 1, oa, data->ioc_pbuf1, 1890 rc = echo_create_object(env, ed, 1, oa, data->ioc_pbuf1,
1874 data->ioc_plen1, &dummy_oti); 1891 data->ioc_plen1, &dummy_oti);
1875 GOTO(out, rc); 1892 goto out;
1876 1893
1877 case OBD_IOC_DESTROY: 1894 case OBD_IOC_DESTROY:
1878 if (!capable(CFS_CAP_SYS_ADMIN)) 1895 if (!capable(CFS_CAP_SYS_ADMIN)) {
1879 GOTO (out, rc = -EPERM); 1896 rc = -EPERM;
1897 goto out;
1898 }
1880 1899
1881 rc = echo_get_object(&eco, ed, oa); 1900 rc = echo_get_object(&eco, ed, oa);
1882 if (rc == 0) { 1901 if (rc == 0) {
@@ -1886,7 +1905,7 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1886 eco->eo_deleted = 1; 1905 eco->eo_deleted = 1;
1887 echo_put_object(eco); 1906 echo_put_object(eco);
1888 } 1907 }
1889 GOTO(out, rc); 1908 goto out;
1890 1909
1891 case OBD_IOC_GETATTR: 1910 case OBD_IOC_GETATTR:
1892 rc = echo_get_object(&eco, ed, oa); 1911 rc = echo_get_object(&eco, ed, oa);
@@ -1897,11 +1916,13 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1897 rc = obd_getattr(env, ec->ec_exp, &oinfo); 1916 rc = obd_getattr(env, ec->ec_exp, &oinfo);
1898 echo_put_object(eco); 1917 echo_put_object(eco);
1899 } 1918 }
1900 GOTO(out, rc); 1919 goto out;
1901 1920
1902 case OBD_IOC_SETATTR: 1921 case OBD_IOC_SETATTR:
1903 if (!capable(CFS_CAP_SYS_ADMIN)) 1922 if (!capable(CFS_CAP_SYS_ADMIN)) {
1904 GOTO (out, rc = -EPERM); 1923 rc = -EPERM;
1924 goto out;
1925 }
1905 1926
1906 rc = echo_get_object(&eco, ed, oa); 1927 rc = echo_get_object(&eco, ed, oa);
1907 if (rc == 0) { 1928 if (rc == 0) {
@@ -1912,17 +1933,19 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1912 rc = obd_setattr(env, ec->ec_exp, &oinfo, NULL); 1933 rc = obd_setattr(env, ec->ec_exp, &oinfo, NULL);
1913 echo_put_object(eco); 1934 echo_put_object(eco);
1914 } 1935 }
1915 GOTO(out, rc); 1936 goto out;
1916 1937
1917 case OBD_IOC_BRW_WRITE: 1938 case OBD_IOC_BRW_WRITE:
1918 if (!capable(CFS_CAP_SYS_ADMIN)) 1939 if (!capable(CFS_CAP_SYS_ADMIN)) {
1919 GOTO (out, rc = -EPERM); 1940 rc = -EPERM;
1941 goto out;
1942 }
1920 1943
1921 rw = OBD_BRW_WRITE; 1944 rw = OBD_BRW_WRITE;
1922 /* fall through */ 1945 /* fall through */
1923 case OBD_IOC_BRW_READ: 1946 case OBD_IOC_BRW_READ:
1924 rc = echo_client_brw_ioctl(env, rw, exp, data, &dummy_oti); 1947 rc = echo_client_brw_ioctl(env, rw, exp, data, &dummy_oti);
1925 GOTO(out, rc); 1948 goto out;
1926 1949
1927 case ECHO_IOC_GET_STRIPE: 1950 case ECHO_IOC_GET_STRIPE:
1928 rc = echo_get_object(&eco, ed, oa); 1951 rc = echo_get_object(&eco, ed, oa);
@@ -1931,11 +1954,13 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1931 data->ioc_plen1); 1954 data->ioc_plen1);
1932 echo_put_object(eco); 1955 echo_put_object(eco);
1933 } 1956 }
1934 GOTO(out, rc); 1957 goto out;
1935 1958
1936 case ECHO_IOC_SET_STRIPE: 1959 case ECHO_IOC_SET_STRIPE:
1937 if (!capable(CFS_CAP_SYS_ADMIN)) 1960 if (!capable(CFS_CAP_SYS_ADMIN)) {
1938 GOTO (out, rc = -EPERM); 1961 rc = -EPERM;
1962 goto out;
1963 }
1939 1964
1940 if (data->ioc_pbuf1 == NULL) { /* unset */ 1965 if (data->ioc_pbuf1 == NULL) { /* unset */
1941 rc = echo_get_object(&eco, ed, oa); 1966 rc = echo_get_object(&eco, ed, oa);
@@ -1948,25 +1973,28 @@ echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1948 data->ioc_pbuf1, 1973 data->ioc_pbuf1,
1949 data->ioc_plen1, &dummy_oti); 1974 data->ioc_plen1, &dummy_oti);
1950 } 1975 }
1951 GOTO (out, rc); 1976 goto out;
1952 1977
1953 case ECHO_IOC_ENQUEUE: 1978 case ECHO_IOC_ENQUEUE:
1954 if (!capable(CFS_CAP_SYS_ADMIN)) 1979 if (!capable(CFS_CAP_SYS_ADMIN)) {
1955 GOTO (out, rc = -EPERM); 1980 rc = -EPERM;
1981 goto out;
1982 }
1956 1983
1957 rc = echo_client_enqueue(exp, oa, 1984 rc = echo_client_enqueue(exp, oa,
1958 data->ioc_conn1, /* lock mode */ 1985 data->ioc_conn1, /* lock mode */
1959 data->ioc_offset, 1986 data->ioc_offset,
1960 data->ioc_count);/*extent*/ 1987 data->ioc_count);/*extent*/
1961 GOTO (out, rc); 1988 goto out;
1962 1989
1963 case ECHO_IOC_CANCEL: 1990 case ECHO_IOC_CANCEL:
1964 rc = echo_client_cancel(exp, oa); 1991 rc = echo_client_cancel(exp, oa);
1965 GOTO (out, rc); 1992 goto out;
1966 1993
1967 default: 1994 default:
1968 CERROR ("echo_ioctl(): unrecognised ioctl %#x\n", cmd); 1995 CERROR ("echo_ioctl(): unrecognised ioctl %#x\n", cmd);
1969 GOTO (out, rc = -ENOTTY); 1996 rc = -ENOTTY;
1997 goto out;
1970 } 1998 }
1971 1999
1972out: 2000out:
@@ -2084,11 +2112,13 @@ static int echo_client_disconnect(struct obd_export *exp)
2084{ 2112{
2085 int rc; 2113 int rc;
2086 2114
2087 if (exp == NULL) 2115 if (exp == NULL) {
2088 GOTO(out, rc = -EINVAL); 2116 rc = -EINVAL;
2117 goto out;
2118 }
2089 2119
2090 rc = class_disconnect(exp); 2120 rc = class_disconnect(exp);
2091 GOTO(out, rc); 2121 goto out;
2092 out: 2122 out:
2093 return rc; 2123 return rc;
2094} 2124}
diff --git a/drivers/staging/lustre/lustre/osc/osc_cache.c b/drivers/staging/lustre/lustre/osc/osc_cache.c
index 7734d666b7a1..370e6d4896c6 100644
--- a/drivers/staging/lustre/lustre/osc/osc_cache.c
+++ b/drivers/staging/lustre/lustre/osc/osc_cache.c
@@ -178,76 +178,113 @@ static int osc_extent_sanity_check0(struct osc_extent *ext,
178 int page_count; 178 int page_count;
179 int rc = 0; 179 int rc = 0;
180 180
181 if (!osc_object_is_locked(obj)) 181 if (!osc_object_is_locked(obj)) {
182 GOTO(out, rc = 9); 182 rc = 9;
183 goto out;
184 }
183 185
184 if (ext->oe_state >= OES_STATE_MAX) 186 if (ext->oe_state >= OES_STATE_MAX) {
185 GOTO(out, rc = 10); 187 rc = 10;
188 goto out;
189 }
186 190
187 if (atomic_read(&ext->oe_refc) <= 0) 191 if (atomic_read(&ext->oe_refc) <= 0) {
188 GOTO(out, rc = 20); 192 rc = 20;
193 goto out;
194 }
189 195
190 if (atomic_read(&ext->oe_refc) < atomic_read(&ext->oe_users)) 196 if (atomic_read(&ext->oe_refc) < atomic_read(&ext->oe_users)) {
191 GOTO(out, rc = 30); 197 rc = 30;
198 goto out;
199 }
192 200
193 switch (ext->oe_state) { 201 switch (ext->oe_state) {
194 case OES_INV: 202 case OES_INV:
195 if (ext->oe_nr_pages > 0 || !list_empty(&ext->oe_pages)) 203 if (ext->oe_nr_pages > 0 || !list_empty(&ext->oe_pages))
196 GOTO(out, rc = 35); 204 rc = 35;
197 GOTO(out, rc = 0); 205 else
198 break; 206 rc = 0;
207 goto out;
199 case OES_ACTIVE: 208 case OES_ACTIVE:
200 if (atomic_read(&ext->oe_users) == 0) 209 if (atomic_read(&ext->oe_users) == 0) {
201 GOTO(out, rc = 40); 210 rc = 40;
202 if (ext->oe_hp) 211 goto out;
203 GOTO(out, rc = 50); 212 }
204 if (ext->oe_fsync_wait && !ext->oe_urgent) 213 if (ext->oe_hp) {
205 GOTO(out, rc = 55); 214 rc = 50;
215 goto out;
216 }
217 if (ext->oe_fsync_wait && !ext->oe_urgent) {
218 rc = 55;
219 goto out;
220 }
206 break; 221 break;
207 case OES_CACHE: 222 case OES_CACHE:
208 if (ext->oe_grants == 0) 223 if (ext->oe_grants == 0) {
209 GOTO(out, rc = 60); 224 rc = 60;
210 if (ext->oe_fsync_wait && !ext->oe_urgent && !ext->oe_hp) 225 goto out;
211 GOTO(out, rc = 65); 226 }
227 if (ext->oe_fsync_wait && !ext->oe_urgent && !ext->oe_hp) {
228 rc = 65;
229 goto out;
230 }
212 default: 231 default:
213 if (atomic_read(&ext->oe_users) > 0) 232 if (atomic_read(&ext->oe_users) > 0) {
214 GOTO(out, rc = 70); 233 rc = 70;
234 goto out;
235 }
215 } 236 }
216 237
217 if (ext->oe_max_end < ext->oe_end || ext->oe_end < ext->oe_start) 238 if (ext->oe_max_end < ext->oe_end || ext->oe_end < ext->oe_start) {
218 GOTO(out, rc = 80); 239 rc = 80;
240 goto out;
241 }
219 242
220 if (ext->oe_osclock == NULL && ext->oe_grants > 0) 243 if (ext->oe_osclock == NULL && ext->oe_grants > 0) {
221 GOTO(out, rc = 90); 244 rc = 90;
245 goto out;
246 }
222 247
223 if (ext->oe_osclock) { 248 if (ext->oe_osclock) {
224 struct cl_lock_descr *descr; 249 struct cl_lock_descr *descr;
225 descr = &ext->oe_osclock->cll_descr; 250 descr = &ext->oe_osclock->cll_descr;
226 if (!(descr->cld_start <= ext->oe_start && 251 if (!(descr->cld_start <= ext->oe_start &&
227 descr->cld_end >= ext->oe_max_end)) 252 descr->cld_end >= ext->oe_max_end)) {
228 GOTO(out, rc = 100); 253 rc = 100;
254 goto out;
255 }
229 } 256 }
230 257
231 if (ext->oe_nr_pages > ext->oe_mppr) 258 if (ext->oe_nr_pages > ext->oe_mppr) {
232 GOTO(out, rc = 105); 259 rc = 105;
260 goto out;
261 }
233 262
234 /* Do not verify page list if extent is in RPC. This is because an 263 /* Do not verify page list if extent is in RPC. This is because an
235 * in-RPC extent is supposed to be exclusively accessible w/o lock. */ 264 * in-RPC extent is supposed to be exclusively accessible w/o lock. */
236 if (ext->oe_state > OES_CACHE) 265 if (ext->oe_state > OES_CACHE) {
237 GOTO(out, rc = 0); 266 rc = 0;
267 goto out;
268 }
238 269
239 if (!extent_debug) 270 if (!extent_debug) {
240 GOTO(out, rc = 0); 271 rc = 0;
272 goto out;
273 }
241 274
242 page_count = 0; 275 page_count = 0;
243 list_for_each_entry(oap, &ext->oe_pages, oap_pending_item) { 276 list_for_each_entry(oap, &ext->oe_pages, oap_pending_item) {
244 pgoff_t index = oap2cl_page(oap)->cp_index; 277 pgoff_t index = oap2cl_page(oap)->cp_index;
245 ++page_count; 278 ++page_count;
246 if (index > ext->oe_end || index < ext->oe_start) 279 if (index > ext->oe_end || index < ext->oe_start) {
247 GOTO(out, rc = 110); 280 rc = 110;
281 goto out;
282 }
283 }
284 if (page_count != ext->oe_nr_pages) {
285 rc = 120;
286 goto out;
248 } 287 }
249 if (page_count != ext->oe_nr_pages)
250 GOTO(out, rc = 120);
251 288
252out: 289out:
253 if (rc != 0) 290 if (rc != 0)
@@ -536,10 +573,9 @@ static int osc_extent_merge(const struct lu_env *env, struct osc_extent *cur,
536/** 573/**
537 * Drop user count of osc_extent, and unplug IO asynchronously. 574 * Drop user count of osc_extent, and unplug IO asynchronously.
538 */ 575 */
539int osc_extent_release(const struct lu_env *env, struct osc_extent *ext) 576void osc_extent_release(const struct lu_env *env, struct osc_extent *ext)
540{ 577{
541 struct osc_object *obj = ext->oe_obj; 578 struct osc_object *obj = ext->oe_obj;
542 int rc = 0;
543 579
544 LASSERT(atomic_read(&ext->oe_users) > 0); 580 LASSERT(atomic_read(&ext->oe_users) > 0);
545 LASSERT(sanity_check(ext) == 0); 581 LASSERT(sanity_check(ext) == 0);
@@ -571,7 +607,6 @@ int osc_extent_release(const struct lu_env *env, struct osc_extent *ext)
571 osc_io_unplug_async(env, osc_cli(obj), obj); 607 osc_io_unplug_async(env, osc_cli(obj), obj);
572 } 608 }
573 osc_extent_put(env, ext); 609 osc_extent_put(env, ext);
574 return rc;
575} 610}
576 611
577static inline int overlapped(struct osc_extent *ex1, struct osc_extent *ex2) 612static inline int overlapped(struct osc_extent *ex1, struct osc_extent *ex2)
@@ -776,8 +811,10 @@ restart:
776 rc = osc_extent_wait(env, conflict, OES_INV); 811 rc = osc_extent_wait(env, conflict, OES_INV);
777 osc_extent_put(env, conflict); 812 osc_extent_put(env, conflict);
778 conflict = NULL; 813 conflict = NULL;
779 if (rc < 0) 814 if (rc < 0) {
780 GOTO(out, found = ERR_PTR(rc)); 815 found = ERR_PTR(rc);
816 goto out;
817 }
781 818
782 goto restart; 819 goto restart;
783 } 820 }
@@ -934,7 +971,7 @@ static int osc_extent_truncate(struct osc_extent *ext, pgoff_t trunc_index,
934 io->ci_obj = cl_object_top(osc2cl(obj)); 971 io->ci_obj = cl_object_top(osc2cl(obj));
935 rc = cl_io_init(env, io, CIT_MISC, io->ci_obj); 972 rc = cl_io_init(env, io, CIT_MISC, io->ci_obj);
936 if (rc < 0) 973 if (rc < 0)
937 GOTO(out, rc); 974 goto out;
938 975
939 /* discard all pages with index greater then trunc_index */ 976 /* discard all pages with index greater then trunc_index */
940 list_for_each_entry_safe(oap, tmp, &ext->oe_pages, 977 list_for_each_entry_safe(oap, tmp, &ext->oe_pages,
@@ -1114,21 +1151,27 @@ static int osc_extent_expand(struct osc_extent *ext, pgoff_t index, int *grants)
1114 osc_object_lock(obj); 1151 osc_object_lock(obj);
1115 LASSERT(sanity_check_nolock(ext) == 0); 1152 LASSERT(sanity_check_nolock(ext) == 0);
1116 end_chunk = ext->oe_end >> ppc_bits; 1153 end_chunk = ext->oe_end >> ppc_bits;
1117 if (chunk > end_chunk + 1) 1154 if (chunk > end_chunk + 1) {
1118 GOTO(out, rc = -ERANGE); 1155 rc = -ERANGE;
1156 goto out;
1157 }
1119 1158
1120 if (end_chunk >= chunk) 1159 if (end_chunk >= chunk) {
1121 GOTO(out, rc = 0); 1160 rc = 0;
1161 goto out;
1162 }
1122 1163
1123 LASSERT(end_chunk + 1 == chunk); 1164 LASSERT(end_chunk + 1 == chunk);
1124 /* try to expand this extent to cover @index */ 1165 /* try to expand this extent to cover @index */
1125 end_index = min(ext->oe_max_end, ((chunk + 1) << ppc_bits) - 1); 1166 end_index = min(ext->oe_max_end, ((chunk + 1) << ppc_bits) - 1);
1126 1167
1127 next = next_extent(ext); 1168 next = next_extent(ext);
1128 if (next != NULL && next->oe_start <= end_index) 1169 if (next != NULL && next->oe_start <= end_index) {
1129 /* complex mode - overlapped with the next extent, 1170 /* complex mode - overlapped with the next extent,
1130 * this case will be handled by osc_extent_find() */ 1171 * this case will be handled by osc_extent_find() */
1131 GOTO(out, rc = -EAGAIN); 1172 rc = -EAGAIN;
1173 goto out;
1174 }
1132 1175
1133 ext->oe_end = end_index; 1176 ext->oe_end = end_index;
1134 ext->oe_grants += chunksize; 1177 ext->oe_grants += chunksize;
@@ -1497,12 +1540,16 @@ static int osc_enter_cache(const struct lu_env *env, struct client_obd *cli,
1497 * of queued writes and create a discontiguous rpc stream */ 1540 * of queued writes and create a discontiguous rpc stream */
1498 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_NO_GRANT) || 1541 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_NO_GRANT) ||
1499 cli->cl_dirty_max < PAGE_CACHE_SIZE || 1542 cli->cl_dirty_max < PAGE_CACHE_SIZE ||
1500 cli->cl_ar.ar_force_sync || loi->loi_ar.ar_force_sync) 1543 cli->cl_ar.ar_force_sync || loi->loi_ar.ar_force_sync) {
1501 GOTO(out, rc = -EDQUOT); 1544 rc = -EDQUOT;
1545 goto out;
1546 }
1502 1547
1503 /* Hopefully normal case - cache space and write credits available */ 1548 /* Hopefully normal case - cache space and write credits available */
1504 if (osc_enter_cache_try(cli, oap, bytes, 0)) 1549 if (osc_enter_cache_try(cli, oap, bytes, 0)) {
1505 GOTO(out, rc = 0); 1550 rc = 0;
1551 goto out;
1552 }
1506 1553
1507 /* We can get here for two reasons: too many dirty pages in cache, or 1554 /* We can get here for two reasons: too many dirty pages in cache, or
1508 * run out of grants. In both cases we should write dirty pages out. 1555 * run out of grants. In both cases we should write dirty pages out.
@@ -1530,16 +1577,18 @@ static int osc_enter_cache(const struct lu_env *env, struct client_obd *cli,
1530 /* l_wait_event is interrupted by signal */ 1577 /* l_wait_event is interrupted by signal */
1531 if (rc < 0) { 1578 if (rc < 0) {
1532 list_del_init(&ocw.ocw_entry); 1579 list_del_init(&ocw.ocw_entry);
1533 GOTO(out, rc); 1580 goto out;
1534 } 1581 }
1535 1582
1536 LASSERT(list_empty(&ocw.ocw_entry)); 1583 LASSERT(list_empty(&ocw.ocw_entry));
1537 rc = ocw.ocw_rc; 1584 rc = ocw.ocw_rc;
1538 1585
1539 if (rc != -EDQUOT) 1586 if (rc != -EDQUOT)
1540 GOTO(out, rc); 1587 goto out;
1541 if (osc_enter_cache_try(cli, oap, bytes, 0)) 1588 if (osc_enter_cache_try(cli, oap, bytes, 0)) {
1542 GOTO(out, rc = 0); 1589 rc = 0;
1590 goto out;
1591 }
1543 } 1592 }
1544out: 1593out:
1545 client_obd_list_unlock(&cli->cl_loi_list_lock); 1594 client_obd_list_unlock(&cli->cl_loi_list_lock);
@@ -1562,8 +1611,8 @@ void osc_wake_cache_waiters(struct client_obd *cli)
1562 if ((cli->cl_dirty + PAGE_CACHE_SIZE > cli->cl_dirty_max) || 1611 if ((cli->cl_dirty + PAGE_CACHE_SIZE > cli->cl_dirty_max) ||
1563 (atomic_read(&obd_dirty_pages) + 1 > 1612 (atomic_read(&obd_dirty_pages) + 1 >
1564 obd_max_dirty_pages)) { 1613 obd_max_dirty_pages)) {
1565 CDEBUG(D_CACHE, "no dirty room: dirty: %ld " 1614 CDEBUG(D_CACHE, "no dirty room: dirty: %ld osc max %ld, sys max %d\n",
1566 "osc max %ld, sys max %d\n", cli->cl_dirty, 1615 cli->cl_dirty,
1567 cli->cl_dirty_max, obd_max_dirty_pages); 1616 cli->cl_dirty_max, obd_max_dirty_pages);
1568 goto wakeup; 1617 goto wakeup;
1569 } 1618 }
@@ -2401,14 +2450,15 @@ int osc_flush_async_page(const struct lu_env *env, struct cl_io *io,
2401 * one making the extent active, we could deadlock waiting for 2450 * one making the extent active, we could deadlock waiting for
2402 * the page writeback to clear but it won't because the extent 2451 * the page writeback to clear but it won't because the extent
2403 * is active and won't be written out. */ 2452 * is active and won't be written out. */
2404 GOTO(out, rc = -EAGAIN); 2453 rc = -EAGAIN;
2454 goto out;
2405 default: 2455 default:
2406 break; 2456 break;
2407 } 2457 }
2408 2458
2409 rc = cl_page_prep(env, io, cl_page_top(cp), CRT_WRITE); 2459 rc = cl_page_prep(env, io, cl_page_top(cp), CRT_WRITE);
2410 if (rc) 2460 if (rc)
2411 GOTO(out, rc); 2461 goto out;
2412 2462
2413 spin_lock(&oap->oap_lock); 2463 spin_lock(&oap->oap_lock);
2414 oap->oap_async_flags |= ASYNC_READY|ASYNC_URGENT; 2464 oap->oap_async_flags |= ASYNC_READY|ASYNC_URGENT;
diff --git a/drivers/staging/lustre/lustre/osc/osc_cl_internal.h b/drivers/staging/lustre/lustre/osc/osc_cl_internal.h
index ebbd95c0cea8..365b2787b3c8 100644
--- a/drivers/staging/lustre/lustre/osc/osc_cl_internal.h
+++ b/drivers/staging/lustre/lustre/osc/osc_cl_internal.h
@@ -678,7 +678,7 @@ struct osc_extent {
678 678
679int osc_extent_finish(const struct lu_env *env, struct osc_extent *ext, 679int osc_extent_finish(const struct lu_env *env, struct osc_extent *ext,
680 int sent, int rc); 680 int sent, int rc);
681int osc_extent_release(const struct lu_env *env, struct osc_extent *ext); 681void osc_extent_release(const struct lu_env *env, struct osc_extent *ext);
682 682
683/** @} osc */ 683/** @} osc */
684 684
diff --git a/drivers/staging/lustre/lustre/osc/osc_lock.c b/drivers/staging/lustre/lustre/osc/osc_lock.c
index 8138856fda8c..a7f08bc48166 100644
--- a/drivers/staging/lustre/lustre/osc/osc_lock.c
+++ b/drivers/staging/lustre/lustre/osc/osc_lock.c
@@ -1067,14 +1067,12 @@ static int osc_lock_enqueue_wait(const struct lu_env *env,
1067 * conflicts, we do not wait but return 0 so the 1067 * conflicts, we do not wait but return 0 so the
1068 * request is send to the server 1068 * request is send to the server
1069 */ 1069 */
1070 CDEBUG(D_DLMTRACE, "group lock %p is conflicted " 1070 CDEBUG(D_DLMTRACE, "group lock %p is conflicted with %p, no wait, send to server\n",
1071 "with %p, no wait, send to server\n",
1072 lock, conflict); 1071 lock, conflict);
1073 cl_lock_put(env, conflict); 1072 cl_lock_put(env, conflict);
1074 rc = 0; 1073 rc = 0;
1075 } else { 1074 } else {
1076 CDEBUG(D_DLMTRACE, "lock %p is conflicted with %p, " 1075 CDEBUG(D_DLMTRACE, "lock %p is conflicted with %p, will wait\n",
1077 "will wait\n",
1078 lock, conflict); 1076 lock, conflict);
1079 LASSERT(lock->cll_conflict == NULL); 1077 LASSERT(lock->cll_conflict == NULL);
1080 lu_ref_add(&conflict->cll_reference, "cancel-wait", 1078 lu_ref_add(&conflict->cll_reference, "cancel-wait",
diff --git a/drivers/staging/lustre/lustre/osc/osc_object.c b/drivers/staging/lustre/lustre/osc/osc_object.c
index 69000584619d..92c202f70395 100644
--- a/drivers/staging/lustre/lustre/osc/osc_object.c
+++ b/drivers/staging/lustre/lustre/osc/osc_object.c
@@ -140,8 +140,7 @@ static int osc_object_print(const struct lu_env *env, void *cookie,
140 struct lov_oinfo *oinfo = osc->oo_oinfo; 140 struct lov_oinfo *oinfo = osc->oo_oinfo;
141 struct osc_async_rc *ar = &oinfo->loi_ar; 141 struct osc_async_rc *ar = &oinfo->loi_ar;
142 142
143 (*p)(env, cookie, "id: "DOSTID" " 143 (*p)(env, cookie, "id: " DOSTID " idx: %d gen: %d kms_valid: %u kms %llu rc: %d force_sync: %d min_xid: %llu ",
144 "idx: %d gen: %d kms_valid: %u kms %llu rc: %d force_sync: %d min_xid: %llu ",
145 POSTID(&oinfo->loi_oi), oinfo->loi_ost_idx, 144 POSTID(&oinfo->loi_oi), oinfo->loi_ost_idx,
146 oinfo->loi_ost_gen, oinfo->loi_kms_valid, oinfo->loi_kms, 145 oinfo->loi_ost_gen, oinfo->loi_kms_valid, oinfo->loi_kms,
147 ar->ar_rc, ar->ar_force_sync, ar->ar_min_xid); 146 ar->ar_rc, ar->ar_force_sync, ar->ar_min_xid);
diff --git a/drivers/staging/lustre/lustre/osc/osc_page.c b/drivers/staging/lustre/lustre/osc/osc_page.c
index fcd079b1af01..76ba58b09c5d 100644
--- a/drivers/staging/lustre/lustre/osc/osc_page.c
+++ b/drivers/staging/lustre/lustre/osc/osc_page.c
@@ -369,12 +369,7 @@ static int osc_page_print(const struct lu_env *env,
369 struct osc_object *obj = cl2osc(slice->cpl_obj); 369 struct osc_object *obj = cl2osc(slice->cpl_obj);
370 struct client_obd *cli = &osc_export(obj)->exp_obd->u.cli; 370 struct client_obd *cli = &osc_export(obj)->exp_obd->u.cli;
371 371
372 return (*printer)(env, cookie, LUSTRE_OSC_NAME"-page@%p: " 372 return (*printer)(env, cookie, LUSTRE_OSC_NAME "-page@%p: 1< %#x %d %u %s %s > 2< %llu %u %u %#x %#x | %p %p %p > 3< %s %p %d %lu %d > 4< %d %d %d %lu %s | %s %s %s %s > 5< %s %s %s %s | %d %s | %d %s %s>\n",
373 "1< %#x %d %u %s %s > "
374 "2< %llu %u %u %#x %#x | %p %p %p > "
375 "3< %s %p %d %lu %d > "
376 "4< %d %d %d %lu %s | %s %s %s %s > "
377 "5< %s %s %s %s | %d %s | %d %s %s>\n",
378 opg, 373 opg,
379 /* 1 */ 374 /* 1 */
380 oap->oap_magic, oap->oap_cmd, 375 oap->oap_magic, oap->oap_cmd,
@@ -550,8 +545,8 @@ void osc_page_submit(const struct lu_env *env, struct osc_page *opg,
550 LINVRNT(osc_page_protected(env, opg, 545 LINVRNT(osc_page_protected(env, opg,
551 crt == CRT_WRITE ? CLM_WRITE : CLM_READ, 1)); 546 crt == CRT_WRITE ? CLM_WRITE : CLM_READ, 1));
552 547
553 LASSERTF(oap->oap_magic == OAP_MAGIC, "Bad oap magic: oap %p, " 548 LASSERTF(oap->oap_magic == OAP_MAGIC, "Bad oap magic: oap %p, magic 0x%x\n",
554 "magic 0x%x\n", oap, oap->oap_magic); 549 oap, oap->oap_magic);
555 LASSERT(oap->oap_async_flags & ASYNC_READY); 550 LASSERT(oap->oap_async_flags & ASYNC_READY);
556 LASSERT(oap->oap_async_flags & ASYNC_COUNT_STABLE); 551 LASSERT(oap->oap_async_flags & ASYNC_COUNT_STABLE);
557 552
diff --git a/drivers/staging/lustre/lustre/osc/osc_request.c b/drivers/staging/lustre/lustre/osc/osc_request.c
index 44657a06b8a5..b9450b95f1c5 100644
--- a/drivers/staging/lustre/lustre/osc/osc_request.c
+++ b/drivers/staging/lustre/lustre/osc/osc_request.c
@@ -1078,9 +1078,9 @@ static void osc_init_grant(struct client_obd *cli, struct obd_connect_data *ocd)
1078 cli->cl_chunkbits = max_t(int, PAGE_CACHE_SHIFT, ocd->ocd_blocksize); 1078 cli->cl_chunkbits = max_t(int, PAGE_CACHE_SHIFT, ocd->ocd_blocksize);
1079 client_obd_list_unlock(&cli->cl_loi_list_lock); 1079 client_obd_list_unlock(&cli->cl_loi_list_lock);
1080 1080
1081 CDEBUG(D_CACHE, "%s, setting cl_avail_grant: %ld cl_lost_grant: %ld." 1081 CDEBUG(D_CACHE, "%s, setting cl_avail_grant: %ld cl_lost_grant: %ld chunk bits: %d\n",
1082 "chunk bits: %d.\n", cli->cl_import->imp_obd->obd_name, 1082 cli->cl_import->imp_obd->obd_name,
1083 cli->cl_avail_grant, cli->cl_lost_grant, cli->cl_chunkbits); 1083 cli->cl_avail_grant, cli->cl_lost_grant, cli->cl_chunkbits);
1084 1084
1085 if (ocd->ocd_connect_flags & OBD_CONNECT_GRANT_SHRINK && 1085 if (ocd->ocd_connect_flags & OBD_CONNECT_GRANT_SHRINK &&
1086 list_empty(&cli->cl_grant_shrink_list)) 1086 list_empty(&cli->cl_grant_shrink_list))
@@ -1171,8 +1171,7 @@ static inline int can_merge_pages(struct brw_page *p1, struct brw_page *p2)
1171 /* warn if we try to combine flags that we don't know to be 1171 /* warn if we try to combine flags that we don't know to be
1172 * safe to combine */ 1172 * safe to combine */
1173 if (unlikely((p1->flag & mask) != (p2->flag & mask))) { 1173 if (unlikely((p1->flag & mask) != (p2->flag & mask))) {
1174 CWARN("Saw flags 0x%x and 0x%x in the same brw, please " 1174 CWARN("Saw flags 0x%x and 0x%x in the same brw, please report this at http://bugs.whamcloud.com/\n",
1175 "report this at http://bugs.whamcloud.com/\n",
1176 p1->flag, p2->flag); 1175 p1->flag, p2->flag);
1177 } 1176 }
1178 return 0; 1177 return 0;
@@ -1343,8 +1342,7 @@ static int osc_brw_prep_request(int cmd, struct client_obd *cli,
1343 "i: %d/%d pg: %p off: %llu, count: %u\n", 1342 "i: %d/%d pg: %p off: %llu, count: %u\n",
1344 i, page_count, pg, pg->off, pg->count); 1343 i, page_count, pg, pg->off, pg->count);
1345 LASSERTF(i == 0 || pg->off > pg_prev->off, 1344 LASSERTF(i == 0 || pg->off > pg_prev->off,
1346 "i %d p_c %u pg %p [pri %lu ind %lu] off %llu" 1345 "i %d p_c %u pg %p [pri %lu ind %lu] off %llu prev_pg %p [pri %lu ind %lu] off %llu\n",
1347 " prev_pg %p [pri %lu ind %lu] off %llu\n",
1348 i, page_count, 1346 i, page_count,
1349 pg->pg, page_private(pg->pg), pg->pg->index, pg->off, 1347 pg->pg, page_private(pg->pg), pg->pg->index, pg->off,
1350 pg_prev->pg, page_private(pg_prev->pg), 1348 pg_prev->pg, page_private(pg_prev->pg),
@@ -1467,16 +1465,16 @@ static int check_write_checksum(struct obdo *oa, const lnet_process_id_t *peer,
1467 cksum_type); 1465 cksum_type);
1468 1466
1469 if (cksum_type != client_cksum_type) 1467 if (cksum_type != client_cksum_type)
1470 msg = "the server did not use the checksum type specified in " 1468 msg = "the server did not use the checksum type specified in the original request - likely a protocol problem"
1471 "the original request - likely a protocol problem"; 1469 ;
1472 else if (new_cksum == server_cksum) 1470 else if (new_cksum == server_cksum)
1473 msg = "changed on the client after we checksummed it - " 1471 msg = "changed on the client after we checksummed it - likely false positive due to mmap IO (bug 11742)"
1474 "likely false positive due to mmap IO (bug 11742)"; 1472 ;
1475 else if (new_cksum == client_cksum) 1473 else if (new_cksum == client_cksum)
1476 msg = "changed in transit before arrival at OST"; 1474 msg = "changed in transit before arrival at OST";
1477 else 1475 else
1478 msg = "changed in transit AND doesn't match the original - " 1476 msg = "changed in transit AND doesn't match the original - likely false positive due to mmap IO (bug 11742)"
1479 "likely false positive due to mmap IO (bug 11742)"; 1477 ;
1480 1478
1481 LCONSOLE_ERROR_MSG(0x132, "BAD WRITE CHECKSUM: %s: from %s inode "DFID 1479 LCONSOLE_ERROR_MSG(0x132, "BAD WRITE CHECKSUM: %s: from %s inode "DFID
1482 " object "DOSTID" extent [%llu-%llu]\n", 1480 " object "DOSTID" extent [%llu-%llu]\n",
@@ -1486,8 +1484,8 @@ static int check_write_checksum(struct obdo *oa, const lnet_process_id_t *peer,
1486 oa->o_valid & OBD_MD_FLFID ? oa->o_parent_ver : 0, 1484 oa->o_valid & OBD_MD_FLFID ? oa->o_parent_ver : 0,
1487 POSTID(&oa->o_oi), pga[0]->off, 1485 POSTID(&oa->o_oi), pga[0]->off,
1488 pga[page_count-1]->off + pga[page_count-1]->count - 1); 1486 pga[page_count-1]->off + pga[page_count-1]->count - 1);
1489 CERROR("original client csum %x (type %x), server csum %x (type %x), " 1487 CERROR("original client csum %x (type %x), server csum %x (type %x), client csum now %x\n",
1490 "client csum now %x\n", client_cksum, client_cksum_type, 1488 client_cksum, client_cksum_type,
1491 server_cksum, cksum_type, new_cksum); 1489 server_cksum, cksum_type, new_cksum);
1492 return 1; 1490 return 1;
1493} 1491}
@@ -1601,23 +1599,21 @@ static int osc_brw_fini_request(struct ptlrpc_request *req, int rc)
1601 } 1599 }
1602 1600
1603 if (server_cksum != client_cksum) { 1601 if (server_cksum != client_cksum) {
1604 LCONSOLE_ERROR_MSG(0x133, "%s: BAD READ CHECKSUM: from " 1602 LCONSOLE_ERROR_MSG(0x133, "%s: BAD READ CHECKSUM: from %s%s%s inode " DFID " object " DOSTID " extent [%llu-%llu]\n",
1605 "%s%s%s inode "DFID" object "DOSTID
1606 " extent [%llu-%llu]\n",
1607 req->rq_import->imp_obd->obd_name, 1603 req->rq_import->imp_obd->obd_name,
1608 libcfs_nid2str(peer->nid), 1604 libcfs_nid2str(peer->nid),
1609 via, router, 1605 via, router,
1610 body->oa.o_valid & OBD_MD_FLFID ? 1606 body->oa.o_valid & OBD_MD_FLFID ?
1611 body->oa.o_parent_seq : (__u64)0, 1607 body->oa.o_parent_seq : (__u64)0,
1612 body->oa.o_valid & OBD_MD_FLFID ? 1608 body->oa.o_valid & OBD_MD_FLFID ?
1613 body->oa.o_parent_oid : 0, 1609 body->oa.o_parent_oid : 0,
1614 body->oa.o_valid & OBD_MD_FLFID ? 1610 body->oa.o_valid & OBD_MD_FLFID ?
1615 body->oa.o_parent_ver : 0, 1611 body->oa.o_parent_ver : 0,
1616 POSTID(&body->oa.o_oi), 1612 POSTID(&body->oa.o_oi),
1617 aa->aa_ppga[0]->off, 1613 aa->aa_ppga[0]->off,
1618 aa->aa_ppga[aa->aa_page_count-1]->off + 1614 aa->aa_ppga[aa->aa_page_count-1]->off +
1619 aa->aa_ppga[aa->aa_page_count-1]->count - 1615 aa->aa_ppga[aa->aa_page_count-1]->count -
1620 1); 1616 1);
1621 CERROR("client %x, server %x, cksum_type %x\n", 1617 CERROR("client %x, server %x, cksum_type %x\n",
1622 client_cksum, server_cksum, cksum_type); 1618 client_cksum, server_cksum, cksum_type);
1623 cksum_counter = 0; 1619 cksum_counter = 0;
@@ -1771,8 +1767,7 @@ static int brw_interpret(const struct lu_env *env,
1771 if (osc_recoverable_error(rc)) { 1767 if (osc_recoverable_error(rc)) {
1772 if (req->rq_import_generation != 1768 if (req->rq_import_generation !=
1773 req->rq_import->imp_generation) { 1769 req->rq_import->imp_generation) {
1774 CDEBUG(D_HA, "%s: resend cross eviction for object: " 1770 CDEBUG(D_HA, "%s: resend cross eviction for object: " DOSTID ", rc = %d.\n",
1775 ""DOSTID", rc = %d.\n",
1776 req->rq_import->imp_obd->obd_name, 1771 req->rq_import->imp_obd->obd_name,
1777 POSTID(&aa->aa_oa->o_oi), rc); 1772 POSTID(&aa->aa_oa->o_oi), rc);
1778 } else if (rc == -EINPROGRESS || 1773 } else if (rc == -EINPROGRESS ||
@@ -3013,8 +3008,8 @@ static int osc_reconnect(const struct lu_env *env,
3013 cli->cl_lost_grant = 0; 3008 cli->cl_lost_grant = 0;
3014 client_obd_list_unlock(&cli->cl_loi_list_lock); 3009 client_obd_list_unlock(&cli->cl_loi_list_lock);
3015 3010
3016 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d" 3011 CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d ocd_grant: %d, lost: %ld.\n",
3017 " ocd_grant: %d, lost: %ld.\n", data->ocd_connect_flags, 3012 data->ocd_connect_flags,
3018 data->ocd_version, data->ocd_grant, lost_grant); 3013 data->ocd_version, data->ocd_grant, lost_grant);
3019 } 3014 }
3020 3015
@@ -3217,8 +3212,6 @@ out_ptlrpcd:
3217 3212
3218static int osc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage) 3213static int osc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
3219{ 3214{
3220 int rc = 0;
3221
3222 switch (stage) { 3215 switch (stage) {
3223 case OBD_CLEANUP_EARLY: { 3216 case OBD_CLEANUP_EARLY: {
3224 struct obd_import *imp; 3217 struct obd_import *imp;
@@ -3253,7 +3246,7 @@ static int osc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
3253 break; 3246 break;
3254 } 3247 }
3255 } 3248 }
3256 return rc; 3249 return 0;
3257} 3250}
3258 3251
3259int osc_cleanup(struct obd_device *obd) 3252int osc_cleanup(struct obd_device *obd)
diff --git a/drivers/staging/lustre/lustre/ptlrpc/client.c b/drivers/staging/lustre/lustre/ptlrpc/client.c
index 38cc931a189c..dc9e406f3212 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/client.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/client.c
@@ -265,8 +265,7 @@ static void ptlrpc_at_adj_service(struct ptlrpc_request *req,
265 so just keep minimal history here */ 265 so just keep minimal history here */
266 oldse = at_measured(&at->iat_service_estimate[idx], serv_est); 266 oldse = at_measured(&at->iat_service_estimate[idx], serv_est);
267 if (oldse != 0) 267 if (oldse != 0)
268 CDEBUG(D_ADAPTTO, "The RPC service estimate for %s ptl %d " 268 CDEBUG(D_ADAPTTO, "The RPC service estimate for %s ptl %d has changed from %d to %d\n",
269 "has changed from %d to %d\n",
270 req->rq_import->imp_obd->obd_name, req->rq_request_portal, 269 req->rq_import->imp_obd->obd_name, req->rq_request_portal,
271 oldse, at_get(&at->iat_service_estimate[idx])); 270 oldse, at_get(&at->iat_service_estimate[idx]));
272} 271}
@@ -297,8 +296,7 @@ static void ptlrpc_at_adj_net_latency(struct ptlrpc_request *req,
297 296
298 oldnl = at_measured(&at->iat_net_latency, nl); 297 oldnl = at_measured(&at->iat_net_latency, nl);
299 if (oldnl != 0) 298 if (oldnl != 0)
300 CDEBUG(D_ADAPTTO, "The network latency for %s (nid %s) " 299 CDEBUG(D_ADAPTTO, "The network latency for %s (nid %s) has changed from %d to %d\n",
301 "has changed from %d to %d\n",
302 req->rq_import->imp_obd->obd_name, 300 req->rq_import->imp_obd->obd_name,
303 obd_uuid2str( 301 obd_uuid2str(
304 &req->rq_import->imp_connection->c_remote_uuid), 302 &req->rq_import->imp_connection->c_remote_uuid),
@@ -371,8 +369,8 @@ static int ptlrpc_at_recv_early_reply(struct ptlrpc_request *req)
371 ptlrpc_at_get_net_latency(req); 369 ptlrpc_at_get_net_latency(req);
372 370
373 DEBUG_REQ(D_ADAPTTO, req, 371 DEBUG_REQ(D_ADAPTTO, req,
374 "Early reply #%d, new deadline in "CFS_DURATION_T"s " 372 "Early reply #%d, new deadline in " CFS_DURATION_T "s (" CFS_DURATION_T "s)",
375 "("CFS_DURATION_T"s)", req->rq_early_count, 373 req->rq_early_count,
376 cfs_time_sub(req->rq_deadline, get_seconds()), 374 cfs_time_sub(req->rq_deadline, get_seconds()),
377 cfs_time_sub(req->rq_deadline, olddl)); 375 cfs_time_sub(req->rq_deadline, olddl));
378 376
@@ -445,8 +443,8 @@ void ptlrpc_add_rqs_to_pool(struct ptlrpc_request_pool *pool, int num_rq)
445 443
446 LASSERTF(list_empty(&pool->prp_req_list) || 444 LASSERTF(list_empty(&pool->prp_req_list) ||
447 size == pool->prp_rq_size, 445 size == pool->prp_rq_size,
448 "Trying to change pool size with nonempty pool " 446 "Trying to change pool size with nonempty pool from %d to %d bytes\n",
449 "from %d to %d bytes\n", pool->prp_rq_size, size); 447 pool->prp_rq_size, size);
450 448
451 spin_lock(&pool->prp_lock); 449 spin_lock(&pool->prp_lock);
452 pool->prp_rq_size = size; 450 pool->prp_rq_size = size;
@@ -1146,11 +1144,10 @@ static int ptlrpc_check_status(struct ptlrpc_request *req)
1146 struct obd_import *imp = req->rq_import; 1144 struct obd_import *imp = req->rq_import;
1147 __u32 opc = lustre_msg_get_opc(req->rq_reqmsg); 1145 __u32 opc = lustre_msg_get_opc(req->rq_reqmsg);
1148 if (ptlrpc_console_allow(req)) 1146 if (ptlrpc_console_allow(req))
1149 LCONSOLE_ERROR_MSG(0x011, "%s: Communicating with %s," 1147 LCONSOLE_ERROR_MSG(0x011, "%s: Communicating with %s, operation %s failed with %d.\n",
1150 " operation %s failed with %d.\n",
1151 imp->imp_obd->obd_name, 1148 imp->imp_obd->obd_name,
1152 libcfs_nid2str( 1149 libcfs_nid2str(
1153 imp->imp_connection->c_peer.nid), 1150 imp->imp_connection->c_peer.nid),
1154 ll_opcode2str(opc), err); 1151 ll_opcode2str(opc), err);
1155 return err < 0 ? err : -EINVAL; 1152 return err < 0 ? err : -EINVAL;
1156 } 1153 }
@@ -1206,8 +1203,7 @@ static int after_reply(struct ptlrpc_request *req)
1206 1203
1207 if (req->rq_reply_truncate) { 1204 if (req->rq_reply_truncate) {
1208 if (ptlrpc_no_resend(req)) { 1205 if (ptlrpc_no_resend(req)) {
1209 DEBUG_REQ(D_ERROR, req, "reply buffer overflow," 1206 DEBUG_REQ(D_ERROR, req, "reply buffer overflow, expected: %d, actual size: %d",
1210 " expected: %d, actual size: %d",
1211 req->rq_nob_received, req->rq_repbuf_len); 1207 req->rq_nob_received, req->rq_repbuf_len);
1212 return -EOVERFLOW; 1208 return -EOVERFLOW;
1213 } 1209 }
@@ -1259,8 +1255,7 @@ static int after_reply(struct ptlrpc_request *req)
1259 /* new xid is already allocated for bulk in 1255 /* new xid is already allocated for bulk in
1260 * ptlrpc_check_set() */ 1256 * ptlrpc_check_set() */
1261 req->rq_xid = ptlrpc_next_xid(); 1257 req->rq_xid = ptlrpc_next_xid();
1262 DEBUG_REQ(D_RPCTRACE, req, "Allocating new xid for " 1258 DEBUG_REQ(D_RPCTRACE, req, "Allocating new xid for resend on EINPROGRESS");
1263 "resend on EINPROGRESS");
1264 } 1259 }
1265 1260
1266 /* Readjust the timeout for current conditions */ 1261 /* Readjust the timeout for current conditions */
@@ -1412,8 +1407,8 @@ static int ptlrpc_send_new_req(struct ptlrpc_request *req)
1412 req->rq_waiting = 1; 1407 req->rq_waiting = 1;
1413 spin_unlock(&req->rq_lock); 1408 spin_unlock(&req->rq_lock);
1414 1409
1415 DEBUG_REQ(D_HA, req, "req from PID %d waiting for recovery: " 1410 DEBUG_REQ(D_HA, req, "req from PID %d waiting for recovery: (%s != %s)",
1416 "(%s != %s)", lustre_msg_get_status(req->rq_reqmsg), 1411 lustre_msg_get_status(req->rq_reqmsg),
1417 ptlrpc_import_state_name(req->rq_send_state), 1412 ptlrpc_import_state_name(req->rq_send_state),
1418 ptlrpc_import_state_name(imp->imp_state)); 1413 ptlrpc_import_state_name(imp->imp_state));
1419 LASSERT(list_empty(&req->rq_list)); 1414 LASSERT(list_empty(&req->rq_list));
@@ -1450,8 +1445,8 @@ static int ptlrpc_send_new_req(struct ptlrpc_request *req)
1450 } 1445 }
1451 } 1446 }
1452 1447
1453 CDEBUG(D_RPCTRACE, "Sending RPC pname:cluuid:pid:xid:nid:opc" 1448 CDEBUG(D_RPCTRACE, "Sending RPC pname:cluuid:pid:xid:nid:opc %s:%s:%d:%llu:%s:%d\n",
1454 " %s:%s:%d:%llu:%s:%d\n", current_comm(), 1449 current_comm(),
1455 imp->imp_obd->obd_uuid.uuid, 1450 imp->imp_obd->obd_uuid.uuid,
1456 lustre_msg_get_status(req->rq_reqmsg), req->rq_xid, 1451 lustre_msg_get_status(req->rq_reqmsg), req->rq_xid,
1457 libcfs_nid2str(imp->imp_connection->c_peer.nid), 1452 libcfs_nid2str(imp->imp_connection->c_peer.nid),
@@ -1828,12 +1823,11 @@ interpret:
1828 ptlrpc_rqphase_move(req, RQ_PHASE_COMPLETE); 1823 ptlrpc_rqphase_move(req, RQ_PHASE_COMPLETE);
1829 1824
1830 CDEBUG(req->rq_reqmsg != NULL ? D_RPCTRACE : 0, 1825 CDEBUG(req->rq_reqmsg != NULL ? D_RPCTRACE : 0,
1831 "Completed RPC pname:cluuid:pid:xid:nid:" 1826 "Completed RPC pname:cluuid:pid:xid:nid:opc %s:%s:%d:%llu:%s:%d\n",
1832 "opc %s:%s:%d:%llu:%s:%d\n", 1827 current_comm(), imp->imp_obd->obd_uuid.uuid,
1833 current_comm(), imp->imp_obd->obd_uuid.uuid, 1828 lustre_msg_get_status(req->rq_reqmsg), req->rq_xid,
1834 lustre_msg_get_status(req->rq_reqmsg), req->rq_xid, 1829 libcfs_nid2str(imp->imp_connection->c_peer.nid),
1835 libcfs_nid2str(imp->imp_connection->c_peer.nid), 1830 lustre_msg_get_opc(req->rq_reqmsg));
1836 lustre_msg_get_opc(req->rq_reqmsg));
1837 1831
1838 spin_lock(&imp->imp_lock); 1832 spin_lock(&imp->imp_lock);
1839 /* Request already may be not on sending or delaying list. This 1833 /* Request already may be not on sending or delaying list. This
@@ -2215,10 +2209,8 @@ EXPORT_SYMBOL(ptlrpc_set_wait);
2215 */ 2209 */
2216static void __ptlrpc_free_req(struct ptlrpc_request *request, int locked) 2210static void __ptlrpc_free_req(struct ptlrpc_request *request, int locked)
2217{ 2211{
2218 if (request == NULL) { 2212 if (request == NULL)
2219 return; 2213 return;
2220 }
2221
2222 LASSERTF(!request->rq_receiving_reply, "req %p\n", request); 2214 LASSERTF(!request->rq_receiving_reply, "req %p\n", request);
2223 LASSERTF(request->rq_rqbd == NULL, "req %p\n", request);/* client-side */ 2215 LASSERTF(request->rq_rqbd == NULL, "req %p\n", request);/* client-side */
2224 LASSERTF(list_empty(&request->rq_list), "req %p\n", request); 2216 LASSERTF(list_empty(&request->rq_list), "req %p\n", request);
diff --git a/drivers/staging/lustre/lustre/ptlrpc/events.c b/drivers/staging/lustre/lustre/ptlrpc/events.c
index 32dfffa76a5e..7f8644e01112 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/events.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/events.c
@@ -128,8 +128,8 @@ void reply_in_callback(lnet_event_t *ev)
128 ((lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT))) { 128 ((lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT))) {
129 /* Early reply */ 129 /* Early reply */
130 DEBUG_REQ(D_ADAPTTO, req, 130 DEBUG_REQ(D_ADAPTTO, req,
131 "Early reply received: mlen=%u offset=%d replen=%d " 131 "Early reply received: mlen=%u offset=%d replen=%d replied=%d unlinked=%d",
132 "replied=%d unlinked=%d", ev->mlength, ev->offset, 132 ev->mlength, ev->offset,
133 req->rq_replen, req->rq_replied, ev->unlinked); 133 req->rq_replen, req->rq_replied, ev->unlinked);
134 134
135 req->rq_early_count++; /* number received, client side */ 135 req->rq_early_count++; /* number received, client side */
@@ -313,8 +313,7 @@ void request_in_callback(lnet_event_t *ev)
313 } 313 }
314 req = ptlrpc_request_cache_alloc(GFP_ATOMIC); 314 req = ptlrpc_request_cache_alloc(GFP_ATOMIC);
315 if (req == NULL) { 315 if (req == NULL) {
316 CERROR("Can't allocate incoming request descriptor: " 316 CERROR("Can't allocate incoming request descriptor: Dropping %s RPC from %s\n",
317 "Dropping %s RPC from %s\n",
318 service->srv_name, 317 service->srv_name,
319 libcfs_id2str(ev->initiator)); 318 libcfs_id2str(ev->initiator));
320 return; 319 return;
diff --git a/drivers/staging/lustre/lustre/ptlrpc/import.c b/drivers/staging/lustre/lustre/ptlrpc/import.c
index 2e7e7171ca63..4ceb90db02a3 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/import.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/import.c
@@ -157,18 +157,14 @@ int ptlrpc_set_import_discon(struct obd_import *imp, __u32 conn_cnt)
157 &target_start, &target_len); 157 &target_start, &target_len);
158 158
159 if (imp->imp_replayable) { 159 if (imp->imp_replayable) {
160 LCONSOLE_WARN("%s: Connection to %.*s (at %s) was " 160 LCONSOLE_WARN("%s: Connection to %.*s (at %s) was lost; in progress operations using this service will wait for recovery to complete\n",
161 "lost; in progress operations using this " 161 imp->imp_obd->obd_name, target_len, target_start,
162 "service will wait for recovery to complete\n", 162 libcfs_nid2str(imp->imp_connection->c_peer.nid));
163 imp->imp_obd->obd_name, target_len, target_start,
164 libcfs_nid2str(imp->imp_connection->c_peer.nid));
165 } else { 163 } else {
166 LCONSOLE_ERROR_MSG(0x166, "%s: Connection to " 164 LCONSOLE_ERROR_MSG(0x166, "%s: Connection to %.*s (at %s) was lost; in progress operations using this service will fail\n",
167 "%.*s (at %s) was lost; in progress " 165 imp->imp_obd->obd_name,
168 "operations using this service will fail\n", 166 target_len, target_start,
169 imp->imp_obd->obd_name, 167 libcfs_nid2str(imp->imp_connection->c_peer.nid));
170 target_len, target_start,
171 libcfs_nid2str(imp->imp_connection->c_peer.nid));
172 } 168 }
173 IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_DISCON); 169 IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_DISCON);
174 spin_unlock(&imp->imp_lock); 170 spin_unlock(&imp->imp_lock);
@@ -328,8 +324,8 @@ void ptlrpc_invalidate_import(struct obd_import *imp)
328 * sluggish nets). Let's check this. If there 324 * sluggish nets). Let's check this. If there
329 * is no inflight and unregistering != 0, this 325 * is no inflight and unregistering != 0, this
330 * is bug. */ 326 * is bug. */
331 LASSERTF(count == 0, "Some RPCs are still " 327 LASSERTF(count == 0, "Some RPCs are still unregistering: %d\n",
332 "unregistering: %d\n", count); 328 count);
333 329
334 /* Let's save one loop as soon as inflight have 330 /* Let's save one loop as soon as inflight have
335 * dropped to zero. No new inflights possible at 331 * dropped to zero. No new inflights possible at
@@ -353,12 +349,11 @@ void ptlrpc_invalidate_import(struct obd_import *imp)
353 "still on delayed list"); 349 "still on delayed list");
354 } 350 }
355 351
356 CERROR("%s: RPCs in \"%s\" phase found (%d). " 352 CERROR("%s: RPCs in \"%s\" phase found (%d). Network is sluggish? Waiting them to error out.\n",
357 "Network is sluggish? Waiting them " 353 cli_tgt,
358 "to error out.\n", cli_tgt,
359 ptlrpc_phase2str(RQ_PHASE_UNREGISTERING), 354 ptlrpc_phase2str(RQ_PHASE_UNREGISTERING),
360 atomic_read(&imp-> 355 atomic_read(&imp->
361 imp_unregistering)); 356 imp_unregistering));
362 } 357 }
363 spin_unlock(&imp->imp_lock); 358 spin_unlock(&imp->imp_lock);
364 } 359 }
@@ -413,8 +408,7 @@ void ptlrpc_fail_import(struct obd_import *imp, __u32 conn_cnt)
413 408
414 if (ptlrpc_set_import_discon(imp, conn_cnt)) { 409 if (ptlrpc_set_import_discon(imp, conn_cnt)) {
415 if (!imp->imp_replayable) { 410 if (!imp->imp_replayable) {
416 CDEBUG(D_HA, "import %s@%s for %s not replayable, " 411 CDEBUG(D_HA, "import %s@%s for %s not replayable, auto-deactivating\n",
417 "auto-deactivating\n",
418 obd2cli_tgt(imp->imp_obd), 412 obd2cli_tgt(imp->imp_obd),
419 imp->imp_connection->c_remote_uuid.uuid, 413 imp->imp_connection->c_remote_uuid.uuid,
420 imp->imp_obd->obd_name); 414 imp->imp_obd->obd_name);
@@ -541,8 +535,8 @@ static int import_select_connection(struct obd_import *imp)
541 at_reset(at, CONNECTION_SWITCH_MAX); 535 at_reset(at, CONNECTION_SWITCH_MAX);
542 } 536 }
543 LASSERT(imp_conn->oic_last_attempt); 537 LASSERT(imp_conn->oic_last_attempt);
544 CDEBUG(D_HA, "%s: tried all connections, increasing latency " 538 CDEBUG(D_HA, "%s: tried all connections, increasing latency to %ds\n",
545 "to %ds\n", imp->imp_obd->obd_name, at_get(at)); 539 imp->imp_obd->obd_name, at_get(at));
546 } 540 }
547 541
548 imp_conn->oic_last_attempt = cfs_time_current_64(); 542 imp_conn->oic_last_attempt = cfs_time_current_64();
@@ -564,8 +558,7 @@ static int import_select_connection(struct obd_import *imp)
564 deuuidify(obd2cli_tgt(imp->imp_obd), NULL, 558 deuuidify(obd2cli_tgt(imp->imp_obd), NULL,
565 &target_start, &target_len); 559 &target_start, &target_len);
566 560
567 CDEBUG(D_HA, "%s: Connection changing to" 561 CDEBUG(D_HA, "%s: Connection changing to %.*s (at %s)\n",
568 " %.*s (at %s)\n",
569 imp->imp_obd->obd_name, 562 imp->imp_obd->obd_name,
570 target_len, target_start, 563 target_len, target_start,
571 libcfs_nid2str(imp_conn->oic_conn->c_peer.nid)); 564 libcfs_nid2str(imp_conn->oic_conn->c_peer.nid));
@@ -935,14 +928,13 @@ static int ptlrpc_connect_interpret(const struct lu_env *env,
935 lustre_msg_get_handle( 928 lustre_msg_get_handle(
936 request->rq_repmsg)->cookie); 929 request->rq_repmsg)->cookie);
937 } else { 930 } else {
938 LCONSOLE_WARN("Evicted from %s (at %s) " 931 LCONSOLE_WARN("Evicted from %s (at %s) after server handle changed from %#llx to %#llx\n",
939 "after server handle changed from %#llx to %#llx\n",
940 obd2cli_tgt(imp->imp_obd), 932 obd2cli_tgt(imp->imp_obd),
941 imp->imp_connection-> \ 933 imp->imp_connection-> \
942 c_remote_uuid.uuid, 934 c_remote_uuid.uuid,
943 imp->imp_remote_handle.cookie, 935 imp->imp_remote_handle.cookie,
944 lustre_msg_get_handle( 936 lustre_msg_get_handle(
945 request->rq_repmsg)->cookie); 937 request->rq_repmsg)->cookie);
946 } 938 }
947 939
948 940
@@ -962,8 +954,8 @@ static int ptlrpc_connect_interpret(const struct lu_env *env,
962 } 954 }
963 955
964 if (imp->imp_invalid) { 956 if (imp->imp_invalid) {
965 CDEBUG(D_HA, "%s: reconnected but import is invalid; " 957 CDEBUG(D_HA, "%s: reconnected but import is invalid; marking evicted\n",
966 "marking evicted\n", imp->imp_obd->obd_name); 958 imp->imp_obd->obd_name);
967 IMPORT_SET_STATE(imp, LUSTRE_IMP_EVICTED); 959 IMPORT_SET_STATE(imp, LUSTRE_IMP_EVICTED);
968 } else if (MSG_CONNECT_RECOVERING & msg_flags) { 960 } else if (MSG_CONNECT_RECOVERING & msg_flags) {
969 CDEBUG(D_HA, "%s: reconnected to %s during replay\n", 961 CDEBUG(D_HA, "%s: reconnected to %s during replay\n",
@@ -985,8 +977,8 @@ static int ptlrpc_connect_interpret(const struct lu_env *env,
985 imp->imp_last_replay_transno = 0; 977 imp->imp_last_replay_transno = 0;
986 IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY); 978 IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY);
987 } else { 979 } else {
988 DEBUG_REQ(D_HA, request, "%s: evicting (reconnect/recover flags" 980 DEBUG_REQ(D_HA, request, "%s: evicting (reconnect/recover flags not set: %x)",
989 " not set: %x)", imp->imp_obd->obd_name, msg_flags); 981 imp->imp_obd->obd_name, msg_flags);
990 imp->imp_remote_handle = 982 imp->imp_remote_handle =
991 *lustre_msg_get_handle(request->rq_repmsg); 983 *lustre_msg_get_handle(request->rq_repmsg);
992 IMPORT_SET_STATE(imp, LUSTRE_IMP_EVICTED); 984 IMPORT_SET_STATE(imp, LUSTRE_IMP_EVICTED);
@@ -994,17 +986,13 @@ static int ptlrpc_connect_interpret(const struct lu_env *env,
994 986
995 /* Sanity checks for a reconnected import. */ 987 /* Sanity checks for a reconnected import. */
996 if (!(imp->imp_replayable) != !(msg_flags & MSG_CONNECT_REPLAYABLE)) { 988 if (!(imp->imp_replayable) != !(msg_flags & MSG_CONNECT_REPLAYABLE)) {
997 CERROR("imp_replayable flag does not match server " 989 CERROR("imp_replayable flag does not match server after reconnect. We should LBUG right here.\n");
998 "after reconnect. We should LBUG right here.\n");
999 } 990 }
1000 991
1001 if (lustre_msg_get_last_committed(request->rq_repmsg) > 0 && 992 if (lustre_msg_get_last_committed(request->rq_repmsg) > 0 &&
1002 lustre_msg_get_last_committed(request->rq_repmsg) < 993 lustre_msg_get_last_committed(request->rq_repmsg) <
1003 aa->pcaa_peer_committed) { 994 aa->pcaa_peer_committed) {
1004 CERROR("%s went back in time (transno %lld" 995 CERROR("%s went back in time (transno %lld was previously committed, server now claims %lld)! See https://bugzilla.lustre.org/show_bug.cgi?id=9646\n",
1005 " was previously committed, server now claims %lld"
1006 ")! See https://bugzilla.lustre.org/show_bug.cgi?"
1007 "id=9646\n",
1008 obd2cli_tgt(imp->imp_obd), aa->pcaa_peer_committed, 996 obd2cli_tgt(imp->imp_obd), aa->pcaa_peer_committed,
1009 lustre_msg_get_last_committed(request->rq_repmsg)); 997 lustre_msg_get_last_committed(request->rq_repmsg));
1010 } 998 }
@@ -1013,8 +1001,7 @@ finish:
1013 rc = ptlrpc_import_recovery_state_machine(imp); 1001 rc = ptlrpc_import_recovery_state_machine(imp);
1014 if (rc != 0) { 1002 if (rc != 0) {
1015 if (rc == -ENOTCONN) { 1003 if (rc == -ENOTCONN) {
1016 CDEBUG(D_HA, "evicted/aborted by %s@%s during recovery;" 1004 CDEBUG(D_HA, "evicted/aborted by %s@%s during recovery; invalidating and reconnecting\n",
1017 "invalidating and reconnecting\n",
1018 obd2cli_tgt(imp->imp_obd), 1005 obd2cli_tgt(imp->imp_obd),
1019 imp->imp_connection->c_remote_uuid.uuid); 1006 imp->imp_connection->c_remote_uuid.uuid);
1020 ptlrpc_connect_import(imp); 1007 ptlrpc_connect_import(imp);
@@ -1034,9 +1021,7 @@ finish:
1034 1021
1035 if ((imp->imp_connect_flags_orig & OBD_CONNECT_IBITS) && 1022 if ((imp->imp_connect_flags_orig & OBD_CONNECT_IBITS) &&
1036 !(ocd->ocd_connect_flags & OBD_CONNECT_IBITS)) { 1023 !(ocd->ocd_connect_flags & OBD_CONNECT_IBITS)) {
1037 LCONSOLE_WARN("%s: MDS %s does not support ibits " 1024 LCONSOLE_WARN("%s: MDS %s does not support ibits lock, either very old or invalid: requested %llx, replied %llx\n",
1038 "lock, either very old or invalid: "
1039 "requested %llx, replied %llx\n",
1040 imp->imp_obd->obd_name, 1025 imp->imp_obd->obd_name,
1041 imp->imp_connection->c_remote_uuid.uuid, 1026 imp->imp_connection->c_remote_uuid.uuid,
1042 imp->imp_connect_flags_orig, 1027 imp->imp_connect_flags_orig,
@@ -1052,13 +1037,12 @@ finish:
1052 LUSTRE_VERSION_OFFSET_WARN)) { 1037 LUSTRE_VERSION_OFFSET_WARN)) {
1053 /* Sigh, some compilers do not like #ifdef in the middle 1038 /* Sigh, some compilers do not like #ifdef in the middle
1054 of macro arguments */ 1039 of macro arguments */
1055 const char *older = "older. Consider upgrading server " 1040 const char *older = "older. Consider upgrading server or downgrading client"
1056 "or downgrading client"; 1041 ;
1057 const char *newer = "newer than client version. " 1042 const char *newer = "newer than client version. Consider upgrading client"
1058 "Consider upgrading client"; 1043 ;
1059 1044
1060 LCONSOLE_WARN("Server %s version (%d.%d.%d.%d) " 1045 LCONSOLE_WARN("Server %s version (%d.%d.%d.%d) is much %s (%s)\n",
1061 "is much %s (%s)\n",
1062 obd2cli_tgt(imp->imp_obd), 1046 obd2cli_tgt(imp->imp_obd),
1063 OBD_OCD_VERSION_MAJOR(ocd->ocd_version), 1047 OBD_OCD_VERSION_MAJOR(ocd->ocd_version),
1064 OBD_OCD_VERSION_MINOR(ocd->ocd_version), 1048 OBD_OCD_VERSION_MINOR(ocd->ocd_version),
@@ -1095,10 +1079,7 @@ finish:
1095 * the checksum types it doesn't support */ 1079 * the checksum types it doesn't support */
1096 if ((ocd->ocd_cksum_types & 1080 if ((ocd->ocd_cksum_types &
1097 cksum_types_supported_client()) == 0) { 1081 cksum_types_supported_client()) == 0) {
1098 LCONSOLE_WARN("The negotiation of the checksum " 1082 LCONSOLE_WARN("The negotiation of the checksum algorithm to use with server %s failed (%x/%x), disabling checksums\n",
1099 "algorithm to use with server %s "
1100 "failed (%x/%x), disabling "
1101 "checksums\n",
1102 obd2cli_tgt(imp->imp_obd), 1083 obd2cli_tgt(imp->imp_obd),
1103 ocd->ocd_cksum_types, 1084 ocd->ocd_cksum_types,
1104 cksum_types_supported_client()); 1085 cksum_types_supported_client());
@@ -1191,17 +1172,13 @@ out:
1191 * connection from liblustre clients, so we 1172 * connection from liblustre clients, so we
1192 * should never see this from VFS context 1173 * should never see this from VFS context
1193 */ 1174 */
1194 LCONSOLE_ERROR_MSG(0x16a, "Server %s version " 1175 LCONSOLE_ERROR_MSG(0x16a, "Server %s version (%d.%d.%d.%d) refused connection from this client with an incompatible version (%s). Client must be recompiled\n",
1195 "(%d.%d.%d.%d)" 1176 obd2cli_tgt(imp->imp_obd),
1196 " refused connection from this client " 1177 OBD_OCD_VERSION_MAJOR(ocd->ocd_version),
1197 "with an incompatible version (%s). " 1178 OBD_OCD_VERSION_MINOR(ocd->ocd_version),
1198 "Client must be recompiled\n", 1179 OBD_OCD_VERSION_PATCH(ocd->ocd_version),
1199 obd2cli_tgt(imp->imp_obd), 1180 OBD_OCD_VERSION_FIX(ocd->ocd_version),
1200 OBD_OCD_VERSION_MAJOR(ocd->ocd_version), 1181 LUSTRE_VERSION_STRING);
1201 OBD_OCD_VERSION_MINOR(ocd->ocd_version),
1202 OBD_OCD_VERSION_PATCH(ocd->ocd_version),
1203 OBD_OCD_VERSION_FIX(ocd->ocd_version),
1204 LUSTRE_VERSION_STRING);
1205 ptlrpc_deactivate_import(imp); 1182 ptlrpc_deactivate_import(imp);
1206 IMPORT_SET_STATE(imp, LUSTRE_IMP_CLOSED); 1183 IMPORT_SET_STATE(imp, LUSTRE_IMP_CLOSED);
1207 } 1184 }
@@ -1237,8 +1214,7 @@ static int completed_replay_interpret(const struct lu_env *env,
1237 "%s: version recovery fails, reconnecting\n", 1214 "%s: version recovery fails, reconnecting\n",
1238 req->rq_import->imp_obd->obd_name); 1215 req->rq_import->imp_obd->obd_name);
1239 } else { 1216 } else {
1240 CDEBUG(D_HA, "%s: LAST_REPLAY message error: %d, " 1217 CDEBUG(D_HA, "%s: LAST_REPLAY message error: %d, reconnecting\n",
1241 "reconnecting\n",
1242 req->rq_import->imp_obd->obd_name, 1218 req->rq_import->imp_obd->obd_name,
1243 req->rq_status); 1219 req->rq_status);
1244 } 1220 }
@@ -1343,9 +1319,7 @@ int ptlrpc_import_recovery_state_machine(struct obd_import *imp)
1343 /* Don't care about MGC eviction */ 1319 /* Don't care about MGC eviction */
1344 if (strcmp(imp->imp_obd->obd_type->typ_name, 1320 if (strcmp(imp->imp_obd->obd_type->typ_name,
1345 LUSTRE_MGC_NAME) != 0) { 1321 LUSTRE_MGC_NAME) != 0) {
1346 LCONSOLE_ERROR_MSG(0x167, "%s: This client was evicted " 1322 LCONSOLE_ERROR_MSG(0x167, "%s: This client was evicted by %.*s; in progress operations using this service will fail.\n",
1347 "by %.*s; in progress operations "
1348 "using this service will fail.\n",
1349 imp->imp_obd->obd_name, target_len, 1323 imp->imp_obd->obd_name, target_len,
1350 target_start); 1324 target_start);
1351 } 1325 }
@@ -1455,8 +1429,7 @@ int ptlrpc_disconnect_import(struct obd_import *imp, int noclose)
1455 break; 1429 break;
1456 default: 1430 default:
1457 rc = -EINVAL; 1431 rc = -EINVAL;
1458 CERROR("%s: don't know how to disconnect from %s " 1432 CERROR("%s: don't know how to disconnect from %s (connect_op %d): rc = %d\n",
1459 "(connect_op %d): rc = %d\n",
1460 imp->imp_obd->obd_name, obd2cli_tgt(imp->imp_obd), 1433 imp->imp_obd->obd_name, obd2cli_tgt(imp->imp_obd),
1461 imp->imp_connect_op, rc); 1434 imp->imp_connect_op, rc);
1462 return rc; 1435 return rc;
@@ -1607,8 +1580,8 @@ int at_measured(struct adaptive_timeout *at, unsigned int val)
1607 at->at_current = max(at->at_current, at_min); 1580 at->at_current = max(at->at_current, at_min);
1608 1581
1609 if (at->at_current != old) 1582 if (at->at_current != old)
1610 CDEBUG(D_OTHER, "AT %p change: old=%u new=%u delta=%d " 1583 CDEBUG(D_OTHER, "AT %p change: old=%u new=%u delta=%d (val=%u) hist %u %u %u %u\n",
1611 "(val=%u) hist %u %u %u %u\n", at, 1584 at,
1612 old, at->at_current, at->at_current - old, val, 1585 old, at->at_current, at->at_current - old, val,
1613 at->at_hist[0], at->at_hist[1], at->at_hist[2], 1586 at->at_hist[0], at->at_hist[1], at->at_hist[2],
1614 at->at_hist[3]); 1587 at->at_hist[3]);
diff --git a/drivers/staging/lustre/lustre/ptlrpc/layout.c b/drivers/staging/lustre/lustre/ptlrpc/layout.c
index 5b8337187b59..dc5ceb55d001 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/layout.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/layout.c
@@ -980,18 +980,7 @@ EXPORT_SYMBOL(RMF_CONN);
980struct req_msg_field RMF_CONNECT_DATA = 980struct req_msg_field RMF_CONNECT_DATA =
981 DEFINE_MSGF("cdata", 981 DEFINE_MSGF("cdata",
982 RMF_F_NO_SIZE_CHECK /* we allow extra space for interop */, 982 RMF_F_NO_SIZE_CHECK /* we allow extra space for interop */,
983#if LUSTRE_VERSION_CODE > OBD_OCD_VERSION(2, 7, 50, 0)
984 sizeof(struct obd_connect_data), 983 sizeof(struct obd_connect_data),
985#else
986/* For interoperability with 1.8 and 2.0 clients/servers.
987 * The RPC verification code allows larger RPC buffers, but not
988 * smaller buffers. Until we no longer need to keep compatibility
989 * with older servers/clients we can only check that the buffer
990 * size is at least as large as obd_connect_data_v1. That is not
991 * not in itself harmful, since the chance of just corrupting this
992 * field is low. See JIRA LU-16 for details. */
993 sizeof(struct obd_connect_data_v1),
994#endif
995 lustre_swab_connect, NULL); 984 lustre_swab_connect, NULL);
996EXPORT_SYMBOL(RMF_CONNECT_DATA); 985EXPORT_SYMBOL(RMF_CONNECT_DATA);
997 986
@@ -1897,8 +1886,8 @@ swabber_dumper_helper(struct req_capsule *pill,
1897 swabber(value); 1886 swabber(value);
1898 ptlrpc_buf_set_swabbed(pill->rc_req, inout, offset); 1887 ptlrpc_buf_set_swabbed(pill->rc_req, inout, offset);
1899 if (dump) { 1888 if (dump) {
1900 CDEBUG(D_RPCTRACE, "Dump of swabbed field %s " 1889 CDEBUG(D_RPCTRACE, "Dump of swabbed field %s follows\n",
1901 "follows\n", field->rmf_name); 1890 field->rmf_name);
1902 field->rmf_dumper(value); 1891 field->rmf_dumper(value);
1903 } 1892 }
1904 1893
@@ -1914,8 +1903,7 @@ swabber_dumper_helper(struct req_capsule *pill,
1914 i < n; 1903 i < n;
1915 i++, p += field->rmf_size) { 1904 i++, p += field->rmf_size) {
1916 if (dump) { 1905 if (dump) {
1917 CDEBUG(D_RPCTRACE, "Dump of %sarray field %s, " 1906 CDEBUG(D_RPCTRACE, "Dump of %sarray field %s, element %d follows\n",
1918 "element %d follows\n",
1919 do_swab ? "unswabbed " : "", field->rmf_name, i); 1907 do_swab ? "unswabbed " : "", field->rmf_name, i);
1920 field->rmf_dumper(p); 1908 field->rmf_dumper(p);
1921 } 1909 }
@@ -1923,8 +1911,8 @@ swabber_dumper_helper(struct req_capsule *pill,
1923 continue; 1911 continue;
1924 swabber(p); 1912 swabber(p);
1925 if (dump) { 1913 if (dump) {
1926 CDEBUG(D_RPCTRACE, "Dump of swabbed array field %s, " 1914 CDEBUG(D_RPCTRACE, "Dump of swabbed array field %s, element %d follows\n",
1927 "element %d follows\n", field->rmf_name, i); 1915 field->rmf_name, i);
1928 field->rmf_dumper(value); 1916 field->rmf_dumper(value);
1929 } 1917 }
1930 } 1918 }
@@ -1983,8 +1971,7 @@ static void *__req_capsule_get(struct req_capsule *pill,
1983 */ 1971 */
1984 len = lustre_msg_buflen(msg, offset); 1972 len = lustre_msg_buflen(msg, offset);
1985 if ((len % field->rmf_size) != 0) { 1973 if ((len % field->rmf_size) != 0) {
1986 CERROR("%s: array field size mismatch " 1974 CERROR("%s: array field size mismatch %d modulo %d != 0 (%d)\n",
1987 "%d modulo %d != 0 (%d)\n",
1988 field->rmf_name, len, field->rmf_size, loc); 1975 field->rmf_name, len, field->rmf_size, loc);
1989 return NULL; 1976 return NULL;
1990 } 1977 }
@@ -1997,8 +1984,7 @@ static void *__req_capsule_get(struct req_capsule *pill,
1997 1984
1998 if (value == NULL) { 1985 if (value == NULL) {
1999 DEBUG_REQ(D_ERROR, pill->rc_req, 1986 DEBUG_REQ(D_ERROR, pill->rc_req,
2000 "Wrong buffer for field `%s' (%d of %d) " 1987 "Wrong buffer for field `%s' (%d of %d) in format `%s': %d vs. %d (%s)\n",
2001 "in format `%s': %d vs. %d (%s)\n",
2002 field->rmf_name, offset, lustre_msg_bufcount(msg), 1988 field->rmf_name, offset, lustre_msg_bufcount(msg),
2003 fmt->rf_name, lustre_msg_buflen(msg, offset), len, 1989 fmt->rf_name, lustre_msg_buflen(msg, offset), len,
2004 rcl_names[loc]); 1990 rcl_names[loc]);
@@ -2013,7 +1999,7 @@ static void *__req_capsule_get(struct req_capsule *pill,
2013/** 1999/**
2014 * Dump a request and/or reply 2000 * Dump a request and/or reply
2015 */ 2001 */
2016void __req_capsule_dump(struct req_capsule *pill, enum req_location loc) 2002static void __req_capsule_dump(struct req_capsule *pill, enum req_location loc)
2017{ 2003{
2018 const struct req_format *fmt; 2004 const struct req_format *fmt;
2019 const struct req_msg_field *field; 2005 const struct req_msg_field *field;
@@ -2031,8 +2017,8 @@ void __req_capsule_dump(struct req_capsule *pill, enum req_location loc)
2031 * have a specific dumper 2017 * have a specific dumper
2032 */ 2018 */
2033 len = req_capsule_get_size(pill, field, loc); 2019 len = req_capsule_get_size(pill, field, loc);
2034 CDEBUG(D_RPCTRACE, "Field %s has no dumper function;" 2020 CDEBUG(D_RPCTRACE, "Field %s has no dumper function; field size is %d\n",
2035 "field size is %d\n", field->rmf_name, len); 2021 field->rmf_name, len);
2036 } else { 2022 } else {
2037 /* It's the dumping side-effect that we're interested in */ 2023 /* It's the dumping side-effect that we're interested in */
2038 (void) __req_capsule_get(pill, field, loc, NULL, 1); 2024 (void) __req_capsule_get(pill, field, loc, NULL, 1);
@@ -2184,8 +2170,7 @@ void req_capsule_set_size(struct req_capsule *pill,
2184 (size > 0)) { 2170 (size > 0)) {
2185 if ((field->rmf_flags & RMF_F_STRUCT_ARRAY) && 2171 if ((field->rmf_flags & RMF_F_STRUCT_ARRAY) &&
2186 (size % field->rmf_size != 0)) { 2172 (size % field->rmf_size != 0)) {
2187 CERROR("%s: array field size mismatch " 2173 CERROR("%s: array field size mismatch %d %% %d != 0 (%d)\n",
2188 "%d %% %d != 0 (%d)\n",
2189 field->rmf_name, size, field->rmf_size, loc); 2174 field->rmf_name, size, field->rmf_size, loc);
2190 LBUG(); 2175 LBUG();
2191 } else if (!(field->rmf_flags & RMF_F_STRUCT_ARRAY) && 2176 } else if (!(field->rmf_flags & RMF_F_STRUCT_ARRAY) &&
diff --git a/drivers/staging/lustre/lustre/ptlrpc/llog_client.c b/drivers/staging/lustre/lustre/ptlrpc/llog_client.c
index 56f825fbb17c..e9baf5bbee3a 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/llog_client.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/llog_client.c
@@ -334,8 +334,7 @@ static int llog_client_read_header(const struct lu_env *env,
334 llh_hdr->lrh_type, LLOG_HDR_MAGIC); 334 llh_hdr->lrh_type, LLOG_HDR_MAGIC);
335 rc = -EIO; 335 rc = -EIO;
336 } else if (llh_hdr->lrh_len != LLOG_CHUNK_SIZE) { 336 } else if (llh_hdr->lrh_len != LLOG_CHUNK_SIZE) {
337 CERROR("incorrectly sized log header: %#x " 337 CERROR("incorrectly sized log header: %#x (expecting %#x)\n",
338 "(expecting %#x)\n",
339 llh_hdr->lrh_len, LLOG_CHUNK_SIZE); 338 llh_hdr->lrh_len, LLOG_CHUNK_SIZE);
340 CERROR("you may need to re-run lconf --write_conf.\n"); 339 CERROR("you may need to re-run lconf --write_conf.\n");
341 rc = -EIO; 340 rc = -EIO;
diff --git a/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c b/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c
index 87b9764a4f19..4011e0050fcb 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c
@@ -175,7 +175,7 @@ const char *ll_opcode2str(__u32 opcode)
175 return ll_rpc_opcode_table[offset].opname; 175 return ll_rpc_opcode_table[offset].opname;
176} 176}
177 177
178const char* ll_eopcode2str(__u32 opcode) 178const char *ll_eopcode2str(__u32 opcode)
179{ 179{
180 LASSERT(ll_eopcode_table[opcode].opcode == opcode); 180 LASSERT(ll_eopcode_table[opcode].opcode == opcode);
181 return ll_eopcode_table[opcode].opname; 181 return ll_eopcode_table[opcode].opname;
@@ -694,8 +694,7 @@ default_queue:
694 if (queue == PTLRPC_NRS_QUEUE_HP && !nrs_svc_has_hp(svc)) { 694 if (queue == PTLRPC_NRS_QUEUE_HP && !nrs_svc_has_hp(svc)) {
695 rc = -ENODEV; 695 rc = -ENODEV;
696 goto out; 696 goto out;
697 } 697 } else if (queue == PTLRPC_NRS_QUEUE_BOTH && !nrs_svc_has_hp(svc))
698 else if (queue == PTLRPC_NRS_QUEUE_BOTH && !nrs_svc_has_hp(svc))
699 queue = PTLRPC_NRS_QUEUE_REG; 698 queue = PTLRPC_NRS_QUEUE_REG;
700 699
701 /** 700 /**
@@ -746,8 +745,7 @@ ptlrpc_lprocfs_svc_req_history_seek(struct ptlrpc_service_part *svcpt,
746 svcpt->scp_service->srv_name, svcpt->scp_cpt, 745 svcpt->scp_service->srv_name, svcpt->scp_cpt,
747 srhi->srhi_seq, srhi->srhi_req->rq_history_seq); 746 srhi->srhi_seq, srhi->srhi_req->rq_history_seq);
748 LASSERTF(!list_empty(&svcpt->scp_hist_reqs), 747 LASSERTF(!list_empty(&svcpt->scp_hist_reqs),
749 "%s:%d: seek offset %llu, request seq %llu, " 748 "%s:%d: seek offset %llu, request seq %llu, last culled %llu\n",
750 "last culled %llu\n",
751 svcpt->scp_service->srv_name, svcpt->scp_cpt, 749 svcpt->scp_service->srv_name, svcpt->scp_cpt,
752 seq, srhi->srhi_seq, svcpt->scp_hist_seq_culled); 750 seq, srhi->srhi_seq, svcpt->scp_hist_seq_culled);
753 e = &srhi->srhi_req->rq_history_list; 751 e = &srhi->srhi_req->rq_history_list;
@@ -814,8 +812,8 @@ ptlrpc_lprocfs_svc_req_history_start(struct seq_file *s, loff_t *pos)
814 int i; 812 int i;
815 813
816 if (sizeof(loff_t) != sizeof(__u64)) { /* can't support */ 814 if (sizeof(loff_t) != sizeof(__u64)) { /* can't support */
817 CWARN("Failed to read request history because size of loff_t " 815 CWARN("Failed to read request history because size of loff_t %d can't match size of u64\n",
818 "%d can't match size of u64\n", (int)sizeof(loff_t)); 816 (int)sizeof(loff_t));
819 return NULL; 817 return NULL;
820 } 818 }
821 819
@@ -1298,14 +1296,12 @@ int lprocfs_wr_import(struct file *file, const char *buffer,
1298 if (*endptr) { 1296 if (*endptr) {
1299 CERROR("config: wrong instance # %s\n", ptr); 1297 CERROR("config: wrong instance # %s\n", ptr);
1300 } else if (inst != imp->imp_connect_data.ocd_instance) { 1298 } else if (inst != imp->imp_connect_data.ocd_instance) {
1301 CDEBUG(D_INFO, "IR: %s is connecting to an obsoleted " 1299 CDEBUG(D_INFO, "IR: %s is connecting to an obsoleted target(%u/%u), reconnecting...\n",
1302 "target(%u/%u), reconnecting...\n",
1303 imp->imp_obd->obd_name, 1300 imp->imp_obd->obd_name,
1304 imp->imp_connect_data.ocd_instance, inst); 1301 imp->imp_connect_data.ocd_instance, inst);
1305 do_reconn = 1; 1302 do_reconn = 1;
1306 } else { 1303 } else {
1307 CDEBUG(D_INFO, "IR: %s has already been connecting to " 1304 CDEBUG(D_INFO, "IR: %s has already been connecting to new target(%u)\n",
1308 "new target(%u)\n",
1309 imp->imp_obd->obd_name, inst); 1305 imp->imp_obd->obd_name, inst);
1310 } 1306 }
1311 } 1307 }
diff --git a/drivers/staging/lustre/lustre/ptlrpc/niobuf.c b/drivers/staging/lustre/lustre/ptlrpc/niobuf.c
index c1e8aa4d5ec4..f715e9a8b996 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/niobuf.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/niobuf.c
@@ -224,8 +224,8 @@ int ptlrpc_register_bulk(struct ptlrpc_request *req)
224 total_md - desc->bd_md_count); 224 total_md - desc->bd_md_count);
225 spin_unlock(&desc->bd_lock); 225 spin_unlock(&desc->bd_lock);
226 226
227 CDEBUG(D_NET, "Setup %u bulk %s buffers: %u pages %u bytes, " 227 CDEBUG(D_NET, "Setup %u bulk %s buffers: %u pages %u bytes, xid x%#llx-%#llx, portal %u\n",
228 "xid x%#llx-%#llx, portal %u\n", desc->bd_md_count, 228 desc->bd_md_count,
229 desc->bd_type == BULK_GET_SOURCE ? "get-source" : "put-sink", 229 desc->bd_type == BULK_GET_SOURCE ? "get-source" : "put-sink",
230 desc->bd_iov_count, desc->bd_nob, 230 desc->bd_iov_count, desc->bd_nob,
231 desc->bd_last_xid, req->rq_xid, desc->bd_portal); 231 desc->bd_last_xid, req->rq_xid, desc->bd_portal);
@@ -337,8 +337,7 @@ static void ptlrpc_at_set_reply(struct ptlrpc_request *req, int flags)
337 337
338 if (req->rq_reqmsg && 338 if (req->rq_reqmsg &&
339 !(lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT)) { 339 !(lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT)) {
340 CDEBUG(D_ADAPTTO, "No early reply support: flags=%#x " 340 CDEBUG(D_ADAPTTO, "No early reply support: flags=%#x req_flags=%#x magic=%d:%x/%x len=%d\n",
341 "req_flags=%#x magic=%d:%x/%x len=%d\n",
342 flags, lustre_msg_get_flags(req->rq_reqmsg), 341 flags, lustre_msg_get_flags(req->rq_reqmsg),
343 lustre_msg_is_v1(req->rq_reqmsg), 342 lustre_msg_is_v1(req->rq_reqmsg),
344 lustre_msg_get_magic(req->rq_reqmsg), 343 lustre_msg_get_magic(req->rq_reqmsg),
diff --git a/drivers/staging/lustre/lustre/ptlrpc/nrs.c b/drivers/staging/lustre/lustre/ptlrpc/nrs.c
index 181301bd2083..d5fd7215c72f 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/nrs.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/nrs.c
@@ -770,8 +770,8 @@ static int nrs_policy_register(struct ptlrpc_nrs *nrs,
770 770
771 tmp = nrs_policy_find_locked(nrs, policy->pol_desc->pd_name); 771 tmp = nrs_policy_find_locked(nrs, policy->pol_desc->pd_name);
772 if (tmp != NULL) { 772 if (tmp != NULL) {
773 CERROR("NRS policy %s has been registered, can't register it " 773 CERROR("NRS policy %s has been registered, can't register it for %s\n",
774 "for %s\n", policy->pol_desc->pd_name, 774 policy->pol_desc->pd_name,
775 svcpt->scp_service->srv_name); 775 svcpt->scp_service->srv_name);
776 nrs_policy_put_locked(tmp); 776 nrs_policy_put_locked(tmp);
777 777
@@ -882,8 +882,7 @@ static int nrs_register_policies_locked(struct ptlrpc_nrs *nrs)
882 if (nrs_policy_compatible(svc, desc)) { 882 if (nrs_policy_compatible(svc, desc)) {
883 rc = nrs_policy_register(nrs, desc); 883 rc = nrs_policy_register(nrs, desc);
884 if (rc != 0) { 884 if (rc != 0) {
885 CERROR("Failed to register NRS policy %s for " 885 CERROR("Failed to register NRS policy %s for partition %d of service %s: %d\n",
886 "partition %d of service %s: %d\n",
887 desc->pd_name, svcpt->scp_cpt, 886 desc->pd_name, svcpt->scp_cpt,
888 svc->srv_name, rc); 887 svc->srv_name, rc);
889 /** 888 /**
@@ -1082,8 +1081,7 @@ again:
1082 if (rc == -ENOENT) { 1081 if (rc == -ENOENT) {
1083 rc = 0; 1082 rc = 0;
1084 } else if (rc != 0) { 1083 } else if (rc != 0) {
1085 CERROR("Failed to unregister NRS policy %s for " 1084 CERROR("Failed to unregister NRS policy %s for partition %d of service %s: %d\n",
1086 "partition %d of service %s: %d\n",
1087 desc->pd_name, svcpt->scp_cpt, 1085 desc->pd_name, svcpt->scp_cpt,
1088 svcpt->scp_service->srv_name, rc); 1086 svcpt->scp_service->srv_name, rc);
1089 return rc; 1087 return rc;
@@ -1145,18 +1143,15 @@ int ptlrpc_nrs_policy_register(struct ptlrpc_nrs_pol_conf *conf)
1145 if ((conf->nc_flags & PTLRPC_NRS_FL_REG_EXTERN) && 1143 if ((conf->nc_flags & PTLRPC_NRS_FL_REG_EXTERN) &&
1146 (conf->nc_flags & (PTLRPC_NRS_FL_FALLBACK | 1144 (conf->nc_flags & (PTLRPC_NRS_FL_FALLBACK |
1147 PTLRPC_NRS_FL_REG_START))) { 1145 PTLRPC_NRS_FL_REG_START))) {
1148 CERROR("NRS: failing to register policy %s. Please check " 1146 CERROR("NRS: failing to register policy %s. Please check policy flags; external policies cannot act as fallback policies, or be started immediately upon registration without interaction with lprocfs\n",
1149 "policy flags; external policies cannot act as fallback " 1147 conf->nc_name);
1150 "policies, or be started immediately upon registration "
1151 "without interaction with lprocfs\n", conf->nc_name);
1152 return -EINVAL; 1148 return -EINVAL;
1153 } 1149 }
1154 1150
1155 mutex_lock(&nrs_core.nrs_mutex); 1151 mutex_lock(&nrs_core.nrs_mutex);
1156 1152
1157 if (nrs_policy_find_desc_locked(conf->nc_name) != NULL) { 1153 if (nrs_policy_find_desc_locked(conf->nc_name) != NULL) {
1158 CERROR("NRS: failing to register policy %s which has already " 1154 CERROR("NRS: failing to register policy %s which has already been registered with NRS core!\n",
1159 "been registered with NRS core!\n",
1160 conf->nc_name); 1155 conf->nc_name);
1161 rc = -EEXIST; 1156 rc = -EEXIST;
1162 goto fail; 1157 goto fail;
@@ -1209,8 +1204,7 @@ again:
1209 nrs = nrs_svcpt2nrs(svcpt, hp); 1204 nrs = nrs_svcpt2nrs(svcpt, hp);
1210 rc = nrs_policy_register(nrs, desc); 1205 rc = nrs_policy_register(nrs, desc);
1211 if (rc != 0) { 1206 if (rc != 0) {
1212 CERROR("Failed to register NRS policy %s for " 1207 CERROR("Failed to register NRS policy %s for partition %d of service %s: %d\n",
1213 "partition %d of service %s: %d\n",
1214 desc->pd_name, svcpt->scp_cpt, 1208 desc->pd_name, svcpt->scp_cpt,
1215 svcpt->scp_service->srv_name, rc); 1209 svcpt->scp_service->srv_name, rc);
1216 1210
@@ -1281,8 +1275,7 @@ int ptlrpc_nrs_policy_unregister(struct ptlrpc_nrs_pol_conf *conf)
1281 LASSERT(conf != NULL); 1275 LASSERT(conf != NULL);
1282 1276
1283 if (conf->nc_flags & PTLRPC_NRS_FL_FALLBACK) { 1277 if (conf->nc_flags & PTLRPC_NRS_FL_FALLBACK) {
1284 CERROR("Unable to unregister a fallback policy, unless the " 1278 CERROR("Unable to unregister a fallback policy, unless the PTLRPC service is stopping.\n");
1285 "PTLRPC service is stopping.\n");
1286 return -EPERM; 1279 return -EPERM;
1287 } 1280 }
1288 1281
@@ -1292,8 +1285,7 @@ int ptlrpc_nrs_policy_unregister(struct ptlrpc_nrs_pol_conf *conf)
1292 1285
1293 desc = nrs_policy_find_desc_locked(conf->nc_name); 1286 desc = nrs_policy_find_desc_locked(conf->nc_name);
1294 if (desc == NULL) { 1287 if (desc == NULL) {
1295 CERROR("Failing to unregister NRS policy %s which has " 1288 CERROR("Failing to unregister NRS policy %s which has not been registered with NRS core!\n",
1296 "not been registered with NRS core!\n",
1297 conf->nc_name); 1289 conf->nc_name);
1298 rc = -ENOENT; 1290 rc = -ENOENT;
1299 goto not_exist; 1291 goto not_exist;
@@ -1304,9 +1296,8 @@ int ptlrpc_nrs_policy_unregister(struct ptlrpc_nrs_pol_conf *conf)
1304 rc = nrs_policy_unregister_locked(desc); 1296 rc = nrs_policy_unregister_locked(desc);
1305 if (rc < 0) { 1297 if (rc < 0) {
1306 if (rc == -EBUSY) 1298 if (rc == -EBUSY)
1307 CERROR("Please first stop policy %s on all service " 1299 CERROR("Please first stop policy %s on all service partitions and then retry to unregister the policy.\n",
1308 "partitions and then retry to unregister the " 1300 conf->nc_name);
1309 "policy.\n", conf->nc_name);
1310 goto fail; 1301 goto fail;
1311 } 1302 }
1312 1303
diff --git a/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c b/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c
index 50556db15f79..2f45f7657830 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/pack_generic.c
@@ -412,8 +412,8 @@ void *lustre_msg_buf_v2(struct lustre_msg_v2 *m, int n, int min_size)
412 412
413 buflen = m->lm_buflens[n]; 413 buflen = m->lm_buflens[n];
414 if (unlikely(buflen < min_size)) { 414 if (unlikely(buflen < min_size)) {
415 CERROR("msg %p buffer[%d] size %d too small " 415 CERROR("msg %p buffer[%d] size %d too small (required %d, opc=%d)\n",
416 "(required %d, opc=%d)\n", m, n, buflen, min_size, 416 m, n, buflen, min_size,
417 n == MSG_PTLRPC_BODY_OFF ? -1 : lustre_msg_get_opc(m)); 417 n == MSG_PTLRPC_BODY_OFF ? -1 : lustre_msg_get_opc(m));
418 return NULL; 418 return NULL;
419 } 419 }
@@ -749,21 +749,19 @@ char *lustre_msg_string(struct lustre_msg *m, int index, int max_len)
749 slen = strnlen(str, blen); 749 slen = strnlen(str, blen);
750 750
751 if (slen == blen) { /* not NULL terminated */ 751 if (slen == blen) { /* not NULL terminated */
752 CERROR("can't unpack non-NULL terminated string in " 752 CERROR("can't unpack non-NULL terminated string in msg %p buffer[%d] len %d\n",
753 "msg %p buffer[%d] len %d\n", m, index, blen); 753 m, index, blen);
754 return NULL; 754 return NULL;
755 } 755 }
756 756
757 if (max_len == 0) { 757 if (max_len == 0) {
758 if (slen != blen - 1) { 758 if (slen != blen - 1) {
759 CERROR("can't unpack short string in msg %p " 759 CERROR("can't unpack short string in msg %p buffer[%d] len %d: strlen %d\n",
760 "buffer[%d] len %d: strlen %d\n",
761 m, index, blen, slen); 760 m, index, blen, slen);
762 return NULL; 761 return NULL;
763 } 762 }
764 } else if (slen > max_len) { 763 } else if (slen > max_len) {
765 CERROR("can't unpack oversized string in msg %p " 764 CERROR("can't unpack oversized string in msg %p buffer[%d] len %d strlen %d: max %d expected\n",
766 "buffer[%d] len %d strlen %d: max %d expected\n",
767 m, index, blen, slen, max_len); 765 m, index, blen, slen, max_len);
768 return NULL; 766 return NULL;
769 } 767 }
@@ -1313,43 +1311,17 @@ __u32 lustre_msg_get_cksum(struct lustre_msg *msg)
1313 } 1311 }
1314} 1312}
1315 1313
1316#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 50, 0)
1317/*
1318 * In 1.6 and 1.8 the checksum was computed only on struct ptlrpc_body as
1319 * it was in 1.6 (88 bytes, smaller than the full size in 1.8). It makes
1320 * more sense to compute the checksum on the full ptlrpc_body, regardless
1321 * of what size it is, but in order to keep interoperability with 1.8 we
1322 * can optionally also checksum only the first 88 bytes (caller decides). */
1323# define ptlrpc_body_cksum_size_compat18 88
1324
1325__u32 lustre_msg_calc_cksum(struct lustre_msg *msg, int compat18)
1326#else
1327# warning "remove checksum compatibility support for b1_8"
1328__u32 lustre_msg_calc_cksum(struct lustre_msg *msg) 1314__u32 lustre_msg_calc_cksum(struct lustre_msg *msg)
1329#endif
1330{ 1315{
1331 switch (msg->lm_magic) { 1316 switch (msg->lm_magic) {
1332 case LUSTRE_MSG_MAGIC_V2: { 1317 case LUSTRE_MSG_MAGIC_V2: {
1333 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg); 1318 struct ptlrpc_body *pb = lustre_msg_ptlrpc_body(msg);
1334#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 50, 0)
1335 __u32 crc;
1336 unsigned int hsize = 4;
1337 __u32 len = compat18 ? ptlrpc_body_cksum_size_compat18 :
1338 lustre_msg_buflen(msg, MSG_PTLRPC_BODY_OFF);
1339 LASSERTF(pb, "invalid msg %p: no ptlrpc body!\n", msg);
1340 cfs_crypto_hash_digest(CFS_HASH_ALG_CRC32, (unsigned char *)pb,
1341 len, NULL, 0, (unsigned char *)&crc,
1342 &hsize);
1343 return crc;
1344#else
1345# warning "remove checksum compatibility support for b1_8"
1346 __u32 crc; 1319 __u32 crc;
1347 unsigned int hsize = 4; 1320 unsigned int hsize = 4;
1348 cfs_crypto_hash_digest(CFS_HASH_ALG_CRC32, (unsigned char *)pb, 1321 cfs_crypto_hash_digest(CFS_HASH_ALG_CRC32, (unsigned char *)pb,
1349 lustre_msg_buflen(msg, MSG_PTLRPC_BODY_OFF), 1322 lustre_msg_buflen(msg, MSG_PTLRPC_BODY_OFF),
1350 NULL, 0, (unsigned char *)&crc, &hsize); 1323 NULL, 0, (unsigned char *)&crc, &hsize);
1351 return crc; 1324 return crc;
1352#endif
1353 } 1325 }
1354 default: 1326 default:
1355 CERROR("incorrect message magic: %08x\n", msg->lm_magic); 1327 CERROR("incorrect message magic: %08x\n", msg->lm_magic);
@@ -2284,8 +2256,8 @@ void lustre_swab_quota_body(struct quota_body *b)
2284void dump_ioo(struct obd_ioobj *ioo) 2256void dump_ioo(struct obd_ioobj *ioo)
2285{ 2257{
2286 CDEBUG(D_RPCTRACE, 2258 CDEBUG(D_RPCTRACE,
2287 "obd_ioobj: ioo_oid="DOSTID", ioo_max_brw=%#x, " 2259 "obd_ioobj: ioo_oid=" DOSTID ", ioo_max_brw=%#x, ioo_bufct=%d\n",
2288 "ioo_bufct=%d\n", POSTID(&ioo->ioo_oid), ioo->ioo_max_brw, 2260 POSTID(&ioo->ioo_oid), ioo->ioo_max_brw,
2289 ioo->ioo_bufcnt); 2261 ioo->ioo_bufcnt);
2290} 2262}
2291EXPORT_SYMBOL(dump_ioo); 2263EXPORT_SYMBOL(dump_ioo);
@@ -2356,8 +2328,7 @@ void dump_obdo(struct obdo *oa)
2356 CDEBUG(D_RPCTRACE, "obdo: o_handle = %lld\n", 2328 CDEBUG(D_RPCTRACE, "obdo: o_handle = %lld\n",
2357 oa->o_handle.cookie); 2329 oa->o_handle.cookie);
2358 if (valid & OBD_MD_FLCOOKIE) 2330 if (valid & OBD_MD_FLCOOKIE)
2359 CDEBUG(D_RPCTRACE, "obdo: o_lcookie = " 2331 CDEBUG(D_RPCTRACE, "obdo: o_lcookie = (llog_cookie dumping not yet implemented)\n");
2360 "(llog_cookie dumping not yet implemented)\n");
2361} 2332}
2362EXPORT_SYMBOL(dump_obdo); 2333EXPORT_SYMBOL(dump_obdo);
2363 2334
@@ -2421,17 +2392,15 @@ void _debug_req(struct ptlrpc_request *req,
2421 2392
2422 va_start(args, fmt); 2393 va_start(args, fmt);
2423 libcfs_debug_vmsg2(msgdata, fmt, args, 2394 libcfs_debug_vmsg2(msgdata, fmt, args,
2424 " req@%p x%llu/t%lld(%lld) o%d->%s@%s:%d/%d" 2395 " req@%p x%llu/t%lld(%lld) o%d->%s@%s:%d/%d lens %d/%d e %d to %d dl " CFS_TIME_T " ref %d fl " REQ_FLAGS_FMT "/%x/%x rc %d/%d\n",
2425 " lens %d/%d e %d to %d dl "CFS_TIME_T" ref %d "
2426 "fl "REQ_FLAGS_FMT"/%x/%x rc %d/%d\n",
2427 req, req->rq_xid, req->rq_transno, 2396 req, req->rq_xid, req->rq_transno,
2428 req_ok ? lustre_msg_get_transno(req->rq_reqmsg) : 0, 2397 req_ok ? lustre_msg_get_transno(req->rq_reqmsg) : 0,
2429 req_ok ? lustre_msg_get_opc(req->rq_reqmsg) : -1, 2398 req_ok ? lustre_msg_get_opc(req->rq_reqmsg) : -1,
2430 req->rq_import ? 2399 req->rq_import ?
2431 req->rq_import->imp_obd->obd_name : 2400 req->rq_import->imp_obd->obd_name :
2432 req->rq_export ? 2401 req->rq_export ?
2433 req->rq_export->exp_client_uuid.uuid : 2402 req->rq_export->exp_client_uuid.uuid :
2434 "<?>", 2403 "<?>",
2435 libcfs_nid2str(nid), 2404 libcfs_nid2str(nid),
2436 req->rq_request_portal, req->rq_reply_portal, 2405 req->rq_request_portal, req->rq_reply_portal,
2437 req->rq_reqlen, req->rq_replen, 2406 req->rq_reqlen, req->rq_replen,
diff --git a/drivers/staging/lustre/lustre/ptlrpc/pinger.c b/drivers/staging/lustre/lustre/ptlrpc/pinger.c
index 20341b27a06a..340d98a64137 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/pinger.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/pinger.c
@@ -206,8 +206,7 @@ static void ptlrpc_pinger_process_import(struct obd_import *imp,
206 206
207 spin_unlock(&imp->imp_lock); 207 spin_unlock(&imp->imp_lock);
208 208
209 CDEBUG(level == LUSTRE_IMP_FULL ? D_INFO : D_HA, "%s->%s: level %s/%u " 209 CDEBUG(level == LUSTRE_IMP_FULL ? D_INFO : D_HA, "%s->%s: level %s/%u force %u force_next %u deactive %u pingable %u suppress %u\n",
210 "force %u force_next %u deactive %u pingable %u suppress %u\n",
211 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd), 210 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd),
212 ptlrpc_import_state_name(level), level, force, force_next, 211 ptlrpc_import_state_name(level), level, force, force_next,
213 imp->imp_deactive, imp->imp_pingable, suppress); 212 imp->imp_deactive, imp->imp_pingable, suppress);
@@ -220,8 +219,7 @@ static void ptlrpc_pinger_process_import(struct obd_import *imp,
220 } else if (level != LUSTRE_IMP_FULL || 219 } else if (level != LUSTRE_IMP_FULL ||
221 imp->imp_obd->obd_no_recov || 220 imp->imp_obd->obd_no_recov ||
222 imp_is_deactive(imp)) { 221 imp_is_deactive(imp)) {
223 CDEBUG(D_HA, "%s->%s: not pinging (in recovery " 222 CDEBUG(D_HA, "%s->%s: not pinging (in recovery or recovery disabled: %s)\n",
224 "or recovery disabled: %s)\n",
225 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd), 223 imp->imp_obd->obd_uuid.uuid, obd2cli_tgt(imp->imp_obd),
226 ptlrpc_import_state_name(level)); 224 ptlrpc_import_state_name(level));
227 if (force) { 225 if (force) {
@@ -334,11 +332,7 @@ int ptlrpc_start_pinger(void)
334 thread_is_running(&pinger_thread), &lwi); 332 thread_is_running(&pinger_thread), &lwi);
335 333
336 if (suppress_pings) 334 if (suppress_pings)
337 CWARN("Pings will be suppressed at the request of the " 335 CWARN("Pings will be suppressed at the request of the administrator. The configuration shall meet the additional requirements described in the manual. (Search for the \"suppress_pings\" kernel module parameter.)\n");
338 "administrator. The configuration shall meet the "
339 "additional requirements described in the manual. "
340 "(Search for the \"suppress_pings\" kernel module "
341 "parameter.)\n");
342 336
343 return 0; 337 return 0;
344} 338}
@@ -428,7 +422,7 @@ EXPORT_SYMBOL(ptlrpc_pinger_del_import);
428 * Register a timeout callback to the pinger list, and the callback will 422 * Register a timeout callback to the pinger list, and the callback will
429 * be called when timeout happens. 423 * be called when timeout happens.
430 */ 424 */
431struct timeout_item* ptlrpc_new_timeout(int time, enum timeout_event event, 425struct timeout_item *ptlrpc_new_timeout(int time, enum timeout_event event,
432 timeout_cb_t cb, void *data) 426 timeout_cb_t cb, void *data)
433{ 427{
434 struct timeout_item *ti; 428 struct timeout_item *ti;
@@ -448,7 +442,7 @@ struct timeout_item* ptlrpc_new_timeout(int time, enum timeout_event event,
448} 442}
449 443
450/** 444/**
451 * Register timeout event on the the pinger thread. 445 * Register timeout event on the pinger thread.
452 * Note: the timeout list is an sorted list with increased timeout value. 446 * Note: the timeout list is an sorted list with increased timeout value.
453 */ 447 */
454static struct timeout_item* 448static struct timeout_item*
@@ -623,11 +617,7 @@ static int ping_evictor_main(void *arg)
623 if (expire_time > exp->exp_last_request_time) { 617 if (expire_time > exp->exp_last_request_time) {
624 class_export_get(exp); 618 class_export_get(exp);
625 spin_unlock(&obd->obd_dev_lock); 619 spin_unlock(&obd->obd_dev_lock);
626 LCONSOLE_WARN("%s: haven't heard from client %s" 620 LCONSOLE_WARN("%s: haven't heard from client %s (at %s) in %ld seconds. I think it's dead, and I am evicting it. exp %p, cur %ld expire %ld last %ld\n",
627 " (at %s) in %ld seconds. I think"
628 " it's dead, and I am evicting"
629 " it. exp %p, cur %ld expire %ld"
630 " last %ld\n",
631 obd->obd_name, 621 obd->obd_name,
632 obd_uuid2str(&exp->exp_client_uuid), 622 obd_uuid2str(&exp->exp_client_uuid),
633 obd_export_nid2str(exp), 623 obd_export_nid2str(exp),
diff --git a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c
index 357ea9f8bd57..cbcc541cac43 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/ptlrpcd.c
@@ -356,10 +356,9 @@ static int ptlrpcd_check(struct lu_env *env, struct ptlrpcd_ctl *pc)
356 if (atomic_read(&ps->set_new_count)) { 356 if (atomic_read(&ps->set_new_count)) {
357 rc = ptlrpcd_steal_rqset(set, ps); 357 rc = ptlrpcd_steal_rqset(set, ps);
358 if (rc > 0) 358 if (rc > 0)
359 CDEBUG(D_RPCTRACE, "transfer %d" 359 CDEBUG(D_RPCTRACE, "transfer %d async RPCs [%d->%d]\n",
360 " async RPCs [%d->%d]\n", 360 rc, partner->pc_index,
361 rc, partner->pc_index, 361 pc->pc_index);
362 pc->pc_index);
363 } 362 }
364 ptlrpc_reqset_put(ps); 363 ptlrpc_reqset_put(ps);
365 } while (rc == 0 && pc->pc_cursor != first); 364 } while (rc == 0 && pc->pc_cursor != first);
diff --git a/drivers/staging/lustre/lustre/ptlrpc/recover.c b/drivers/staging/lustre/lustre/ptlrpc/recover.c
index e1bc77b83ffb..7b1d72947330 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/recover.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/recover.c
@@ -237,8 +237,7 @@ void ptlrpc_request_handle_notconn(struct ptlrpc_request *failed_req)
237 if (ptlrpc_set_import_discon(imp, 237 if (ptlrpc_set_import_discon(imp,
238 lustre_msg_get_conn_cnt(failed_req->rq_reqmsg))) { 238 lustre_msg_get_conn_cnt(failed_req->rq_reqmsg))) {
239 if (!imp->imp_replayable) { 239 if (!imp->imp_replayable) {
240 CDEBUG(D_HA, "import %s@%s for %s not replayable, " 240 CDEBUG(D_HA, "import %s@%s for %s not replayable, auto-deactivating\n",
241 "auto-deactivating\n",
242 obd2cli_tgt(imp->imp_obd), 241 obd2cli_tgt(imp->imp_obd),
243 imp->imp_connection->c_remote_uuid.uuid, 242 imp->imp_connection->c_remote_uuid.uuid,
244 imp->imp_obd->obd_name); 243 imp->imp_obd->obd_name);
@@ -274,8 +273,8 @@ int ptlrpc_set_import_active(struct obd_import *imp, int active)
274 /* When deactivating, mark import invalid, and abort in-flight 273 /* When deactivating, mark import invalid, and abort in-flight
275 * requests. */ 274 * requests. */
276 if (!active) { 275 if (!active) {
277 LCONSOLE_WARN("setting import %s INACTIVE by administrator " 276 LCONSOLE_WARN("setting import %s INACTIVE by administrator request\n",
278 "request\n", obd2cli_tgt(imp->imp_obd)); 277 obd2cli_tgt(imp->imp_obd));
279 278
280 /* set before invalidate to avoid messages about imp_inval 279 /* set before invalidate to avoid messages about imp_inval
281 * set without imp_deactive in ptlrpc_import_delay_req */ 280 * set without imp_deactive in ptlrpc_import_delay_req */
diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec.c b/drivers/staging/lustre/lustre/ptlrpc/sec.c
index 4ce76852e6ee..21e9dc9d5580 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/sec.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/sec.c
@@ -209,7 +209,7 @@ EXPORT_SYMBOL(sptlrpc_flavor2name_bulk);
209 209
210char *sptlrpc_flavor2name(struct sptlrpc_flavor *sf, char *buf, int bufsize) 210char *sptlrpc_flavor2name(struct sptlrpc_flavor *sf, char *buf, int bufsize)
211{ 211{
212 snprintf(buf, bufsize, "%s", sptlrpc_flavor2name_base(sf->sf_rpc)); 212 strlcpy(buf, sptlrpc_flavor2name_base(sf->sf_rpc), bufsize);
213 213
214 /* 214 /*
215 * currently we don't support customized bulk specification for 215 * currently we don't support customized bulk specification for
@@ -220,10 +220,9 @@ char *sptlrpc_flavor2name(struct sptlrpc_flavor *sf, char *buf, int bufsize)
220 220
221 bspec[0] = '-'; 221 bspec[0] = '-';
222 sptlrpc_flavor2name_bulk(sf, &bspec[1], sizeof(bspec) - 1); 222 sptlrpc_flavor2name_bulk(sf, &bspec[1], sizeof(bspec) - 1);
223 strncat(buf, bspec, bufsize); 223 strlcat(buf, bspec, bufsize);
224 } 224 }
225 225
226 buf[bufsize - 1] = '\0';
227 return buf; 226 return buf;
228} 227}
229EXPORT_SYMBOL(sptlrpc_flavor2name); 228EXPORT_SYMBOL(sptlrpc_flavor2name);
@@ -457,8 +456,8 @@ int sptlrpc_req_ctx_switch(struct ptlrpc_request *req,
457 LASSERT(req->rq_reqlen); 456 LASSERT(req->rq_reqlen);
458 LASSERT(req->rq_replen); 457 LASSERT(req->rq_replen);
459 458
460 CDEBUG(D_SEC, "req %p: switch ctx %p(%u->%s) -> %p(%u->%s), " 459 CDEBUG(D_SEC, "req %p: switch ctx %p(%u->%s) -> %p(%u->%s), switch sec %p(%s) -> %p(%s)\n",
461 "switch sec %p(%s) -> %p(%s)\n", req, 460 req,
462 oldctx, oldctx->cc_vcred.vc_uid, sec2target_str(oldctx->cc_sec), 461 oldctx, oldctx->cc_vcred.vc_uid, sec2target_str(oldctx->cc_sec),
463 newctx, newctx->cc_vcred.vc_uid, sec2target_str(newctx->cc_sec), 462 newctx, newctx->cc_vcred.vc_uid, sec2target_str(newctx->cc_sec),
464 oldctx->cc_sec, oldctx->cc_sec->ps_policy->sp_name, 463 oldctx->cc_sec, oldctx->cc_sec->ps_policy->sp_name,
@@ -1842,8 +1841,8 @@ int sptlrpc_target_export_check(struct obd_export *exp,
1842 req->rq_svc_ctx, 1841 req->rq_svc_ctx,
1843 &flavor); 1842 &flavor);
1844 } else { 1843 } else {
1845 CDEBUG(D_SEC, "exp %p (%x|%x|%x): is current flavor, " 1844 CDEBUG(D_SEC, "exp %p (%x|%x|%x): is current flavor, install rvs ctx\n",
1846 "install rvs ctx\n", exp, exp->exp_flvr.sf_rpc, 1845 exp, exp->exp_flvr.sf_rpc,
1847 exp->exp_flvr_old[0].sf_rpc, 1846 exp->exp_flvr_old[0].sf_rpc,
1848 exp->exp_flvr_old[1].sf_rpc); 1847 exp->exp_flvr_old[1].sf_rpc);
1849 spin_unlock(&exp->exp_lock); 1848 spin_unlock(&exp->exp_lock);
@@ -1856,13 +1855,12 @@ int sptlrpc_target_export_check(struct obd_export *exp,
1856 if (exp->exp_flvr_expire[0]) { 1855 if (exp->exp_flvr_expire[0]) {
1857 if (exp->exp_flvr_expire[0] >= get_seconds()) { 1856 if (exp->exp_flvr_expire[0] >= get_seconds()) {
1858 if (flavor_allowed(&exp->exp_flvr_old[0], req)) { 1857 if (flavor_allowed(&exp->exp_flvr_old[0], req)) {
1859 CDEBUG(D_SEC, "exp %p (%x|%x|%x): match the " 1858 CDEBUG(D_SEC, "exp %p (%x|%x|%x): match the middle one (" CFS_DURATION_T ")\n", exp,
1860 "middle one ("CFS_DURATION_T")\n", exp,
1861 exp->exp_flvr.sf_rpc, 1859 exp->exp_flvr.sf_rpc,
1862 exp->exp_flvr_old[0].sf_rpc, 1860 exp->exp_flvr_old[0].sf_rpc,
1863 exp->exp_flvr_old[1].sf_rpc, 1861 exp->exp_flvr_old[1].sf_rpc,
1864 exp->exp_flvr_expire[0] - 1862 exp->exp_flvr_expire[0] -
1865 get_seconds()); 1863 get_seconds());
1866 spin_unlock(&exp->exp_lock); 1864 spin_unlock(&exp->exp_lock);
1867 return 0; 1865 return 0;
1868 } 1866 }
@@ -1881,13 +1879,13 @@ int sptlrpc_target_export_check(struct obd_export *exp,
1881 if (exp->exp_flvr_changed == 0 && exp->exp_flvr_expire[1]) { 1879 if (exp->exp_flvr_changed == 0 && exp->exp_flvr_expire[1]) {
1882 if (exp->exp_flvr_expire[1] >= get_seconds()) { 1880 if (exp->exp_flvr_expire[1] >= get_seconds()) {
1883 if (flavor_allowed(&exp->exp_flvr_old[1], req)) { 1881 if (flavor_allowed(&exp->exp_flvr_old[1], req)) {
1884 CDEBUG(D_SEC, "exp %p (%x|%x|%x): match the " 1882 CDEBUG(D_SEC, "exp %p (%x|%x|%x): match the oldest one (" CFS_DURATION_T ")\n",
1885 "oldest one ("CFS_DURATION_T")\n", exp, 1883 exp,
1886 exp->exp_flvr.sf_rpc, 1884 exp->exp_flvr.sf_rpc,
1887 exp->exp_flvr_old[0].sf_rpc, 1885 exp->exp_flvr_old[0].sf_rpc,
1888 exp->exp_flvr_old[1].sf_rpc, 1886 exp->exp_flvr_old[1].sf_rpc,
1889 exp->exp_flvr_expire[1] - 1887 exp->exp_flvr_expire[1] -
1890 get_seconds()); 1888 get_seconds());
1891 spin_unlock(&exp->exp_lock); 1889 spin_unlock(&exp->exp_lock);
1892 return 0; 1890 return 0;
1893 } 1891 }
@@ -1907,8 +1905,7 @@ int sptlrpc_target_export_check(struct obd_export *exp,
1907 1905
1908 spin_unlock(&exp->exp_lock); 1906 spin_unlock(&exp->exp_lock);
1909 1907
1910 CWARN("exp %p(%s): req %p (%u|%u|%u|%u|%u|%u) with " 1908 CWARN("exp %p(%s): req %p (%u|%u|%u|%u|%u|%u) with unauthorized flavor %x, expect %x|%x(%+ld)|%x(%+ld)\n",
1911 "unauthorized flavor %x, expect %x|%x(%+ld)|%x(%+ld)\n",
1912 exp, exp->exp_obd->obd_name, 1909 exp, exp->exp_obd->obd_name,
1913 req, req->rq_auth_gss, req->rq_ctx_init, req->rq_ctx_fini, 1910 req, req->rq_auth_gss, req->rq_ctx_init, req->rq_ctx_fini,
1914 req->rq_auth_usr_root, req->rq_auth_usr_mdt, req->rq_auth_usr_ost, 1911 req->rq_auth_usr_root, req->rq_auth_usr_mdt, req->rq_auth_usr_ost,
diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c b/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c
index cc68a1cf24e3..0dabd83fd46f 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/sec_bulk.c
@@ -772,8 +772,7 @@ void sptlrpc_enc_pool_fini(void)
772 772
773 if (page_pools.epp_st_access > 0) { 773 if (page_pools.epp_st_access > 0) {
774 CDEBUG(D_SEC, 774 CDEBUG(D_SEC,
775 "max pages %lu, grows %u, grow fails %u, shrinks %u, " 775 "max pages %lu, grows %u, grow fails %u, shrinks %u, access %lu, missing %lu, max qlen %u, max wait "
776 "access %lu, missing %lu, max qlen %u, max wait "
777 CFS_TIME_T"/%d\n", 776 CFS_TIME_T"/%d\n",
778 page_pools.epp_st_max_pages, page_pools.epp_st_grows, 777 page_pools.epp_st_max_pages, page_pools.epp_st_grows,
779 page_pools.epp_st_grow_fails, 778 page_pools.epp_st_grow_fails,
diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_null.c b/drivers/staging/lustre/lustre/ptlrpc/sec_null.c
index 099cec3b669f..4e132435b450 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/sec_null.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/sec_null.c
@@ -101,16 +101,7 @@ int null_ctx_verify(struct ptlrpc_cli_ctx *ctx, struct ptlrpc_request *req)
101 101
102 if (req->rq_early) { 102 if (req->rq_early) {
103 cksums = lustre_msg_get_cksum(req->rq_repdata); 103 cksums = lustre_msg_get_cksum(req->rq_repdata);
104#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 50, 0)
105 if (lustre_msghdr_get_flags(req->rq_reqmsg) &
106 MSGHDR_CKSUM_INCOMPAT18)
107 cksumc = lustre_msg_calc_cksum(req->rq_repmsg, 0);
108 else
109 cksumc = lustre_msg_calc_cksum(req->rq_repmsg, 1);
110#else
111# warning "remove checksum compatibility support for b1_8"
112 cksumc = lustre_msg_calc_cksum(req->rq_repmsg); 104 cksumc = lustre_msg_calc_cksum(req->rq_repmsg);
113#endif
114 if (cksumc != cksums) { 105 if (cksumc != cksums) {
115 CDEBUG(D_SEC, 106 CDEBUG(D_SEC,
116 "early reply checksum mismatch: %08x != %08x\n", 107 "early reply checksum mismatch: %08x != %08x\n",
@@ -371,16 +362,7 @@ int null_authorize(struct ptlrpc_request *req)
371 } else { 362 } else {
372 __u32 cksum; 363 __u32 cksum;
373 364
374#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 50, 0)
375 if (lustre_msghdr_get_flags(req->rq_reqmsg) &
376 MSGHDR_CKSUM_INCOMPAT18)
377 cksum = lustre_msg_calc_cksum(rs->rs_repbuf, 0);
378 else
379 cksum = lustre_msg_calc_cksum(rs->rs_repbuf, 1);
380#else
381# warning "remove checksum compatibility support for b1_8"
382 cksum = lustre_msg_calc_cksum(rs->rs_repbuf); 365 cksum = lustre_msg_calc_cksum(rs->rs_repbuf);
383#endif
384 lustre_msg_set_cksum(rs->rs_repbuf, cksum); 366 lustre_msg_set_cksum(rs->rs_repbuf, cksum);
385 req->rq_reply_off = 0; 367 req->rq_reply_off = 0;
386 } 368 }
diff --git a/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c b/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c
index 3d72b810c45c..a79cd53010a4 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/sec_plain.c
@@ -938,8 +938,8 @@ int plain_svc_wrap_bulk(struct ptlrpc_request *req,
938 rc = plain_generate_bulk_csum(desc, req->rq_flvr.u_bulk.hash.hash_alg, 938 rc = plain_generate_bulk_csum(desc, req->rq_flvr.u_bulk.hash.hash_alg,
939 tokenv); 939 tokenv);
940 if (rc) { 940 if (rc) {
941 CERROR("bulk read: server failed to compute " 941 CERROR("bulk read: server failed to compute checksum: %d\n",
942 "checksum: %d\n", rc); 942 rc);
943 } else { 943 } else {
944 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CHECKSUM_RECEIVE)) 944 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CHECKSUM_RECEIVE))
945 corrupt_bulk_data(desc); 945 corrupt_bulk_data(desc);
diff --git a/drivers/staging/lustre/lustre/ptlrpc/service.c b/drivers/staging/lustre/lustre/ptlrpc/service.c
index a8df8a792333..635b12b22cef 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/service.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/service.c
@@ -580,8 +580,7 @@ ptlrpc_server_nthreads_check(struct ptlrpc_service *svc,
580 svc->srv_nthrs_cpt_init = init; 580 svc->srv_nthrs_cpt_init = init;
581 581
582 if (nthrs * svc->srv_ncpts > tc->tc_nthrs_max) { 582 if (nthrs * svc->srv_ncpts > tc->tc_nthrs_max) {
583 CDEBUG(D_OTHER, "%s: This service may have more threads (%d) " 583 CDEBUG(D_OTHER, "%s: This service may have more threads (%d) than the given soft limit (%d)\n",
584 "than the given soft limit (%d)\n",
585 svc->srv_name, nthrs * svc->srv_ncpts, 584 svc->srv_name, nthrs * svc->srv_ncpts,
586 tc->tc_nthrs_max); 585 tc->tc_nthrs_max);
587 } 586 }
@@ -1251,8 +1250,8 @@ static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req)
1251 /* deadline is when the client expects us to reply, margin is the 1250 /* deadline is when the client expects us to reply, margin is the
1252 difference between clients' and servers' expectations */ 1251 difference between clients' and servers' expectations */
1253 DEBUG_REQ(D_ADAPTTO, req, 1252 DEBUG_REQ(D_ADAPTTO, req,
1254 "%ssending early reply (deadline %+lds, margin %+lds) for " 1253 "%ssending early reply (deadline %+lds, margin %+lds) for %d+%d",
1255 "%d+%d", AT_OFF ? "AT off - not " : "", 1254 AT_OFF ? "AT off - not " : "",
1256 olddl, olddl - at_get(&svcpt->scp_at_estimate), 1255 olddl, olddl - at_get(&svcpt->scp_at_estimate),
1257 at_get(&svcpt->scp_at_estimate), at_extra); 1256 at_get(&svcpt->scp_at_estimate), at_extra);
1258 1257
@@ -1260,17 +1259,15 @@ static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req)
1260 return 0; 1259 return 0;
1261 1260
1262 if (olddl < 0) { 1261 if (olddl < 0) {
1263 DEBUG_REQ(D_WARNING, req, "Already past deadline (%+lds), " 1262 DEBUG_REQ(D_WARNING, req, "Already past deadline (%+lds), not sending early reply. Consider increasing at_early_margin (%d)?",
1264 "not sending early reply. Consider increasing " 1263 olddl, at_early_margin);
1265 "at_early_margin (%d)?", olddl, at_early_margin);
1266 1264
1267 /* Return an error so we're not re-added to the timed list. */ 1265 /* Return an error so we're not re-added to the timed list. */
1268 return -ETIMEDOUT; 1266 return -ETIMEDOUT;
1269 } 1267 }
1270 1268
1271 if (!(lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT)) { 1269 if (!(lustre_msghdr_get_flags(req->rq_reqmsg) & MSGHDR_AT_SUPPORT)) {
1272 DEBUG_REQ(D_INFO, req, "Wanted to ask client for more time, " 1270 DEBUG_REQ(D_INFO, req, "Wanted to ask client for more time, but no AT support");
1273 "but no AT support");
1274 return -ENOSYS; 1271 return -ENOSYS;
1275 } 1272 }
1276 1273
@@ -1296,8 +1293,7 @@ static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req)
1296 * we may be past adaptive_max */ 1293 * we may be past adaptive_max */
1297 if (req->rq_deadline >= req->rq_arrival_time.tv_sec + 1294 if (req->rq_deadline >= req->rq_arrival_time.tv_sec +
1298 at_get(&svcpt->scp_at_estimate)) { 1295 at_get(&svcpt->scp_at_estimate)) {
1299 DEBUG_REQ(D_WARNING, req, "Couldn't add any time " 1296 DEBUG_REQ(D_WARNING, req, "Couldn't add any time (%ld/%ld), not sending early reply\n",
1300 "(%ld/%ld), not sending early reply\n",
1301 olddl, req->rq_arrival_time.tv_sec + 1297 olddl, req->rq_arrival_time.tv_sec +
1302 at_get(&svcpt->scp_at_estimate) - 1298 at_get(&svcpt->scp_at_estimate) -
1303 get_seconds()); 1299 get_seconds());
@@ -1329,8 +1325,7 @@ static int ptlrpc_at_send_early_reply(struct ptlrpc_request *req)
1329 LASSERT(atomic_read(&req->rq_refcount)); 1325 LASSERT(atomic_read(&req->rq_refcount));
1330 /** if it is last refcount then early reply isn't needed */ 1326 /** if it is last refcount then early reply isn't needed */
1331 if (atomic_read(&req->rq_refcount) == 1) { 1327 if (atomic_read(&req->rq_refcount) == 1) {
1332 DEBUG_REQ(D_ADAPTTO, reqcopy, "Normal reply already sent out, " 1328 DEBUG_REQ(D_ADAPTTO, reqcopy, "Normal reply already sent out, abort sending early reply\n");
1333 "abort sending early reply\n");
1334 rc = -EINVAL; 1329 rc = -EINVAL;
1335 goto out; 1330 goto out;
1336 } 1331 }
@@ -1454,16 +1449,14 @@ static int ptlrpc_at_check_timed(struct ptlrpc_service_part *svcpt)
1454 1449
1455 spin_unlock(&svcpt->scp_at_lock); 1450 spin_unlock(&svcpt->scp_at_lock);
1456 1451
1457 CDEBUG(D_ADAPTTO, "timeout in %+ds, asking for %d secs on %d early " 1452 CDEBUG(D_ADAPTTO, "timeout in %+ds, asking for %d secs on %d early replies\n",
1458 "replies\n", first, at_extra, counter); 1453 first, at_extra, counter);
1459 if (first < 0) { 1454 if (first < 0) {
1460 /* We're already past request deadlines before we even get a 1455 /* We're already past request deadlines before we even get a
1461 chance to send early replies */ 1456 chance to send early replies */
1462 LCONSOLE_WARN("%s: This server is not able to keep up with " 1457 LCONSOLE_WARN("%s: This server is not able to keep up with request traffic (cpu-bound).\n",
1463 "request traffic (cpu-bound).\n",
1464 svcpt->scp_service->srv_name); 1458 svcpt->scp_service->srv_name);
1465 CWARN("earlyQ=%d reqQ=%d recA=%d, svcEst=%d, " 1459 CWARN("earlyQ=%d reqQ=%d recA=%d, svcEst=%d, delay=" CFS_DURATION_T "(jiff)\n",
1466 "delay="CFS_DURATION_T"(jiff)\n",
1467 counter, svcpt->scp_nreqs_incoming, 1460 counter, svcpt->scp_nreqs_incoming,
1468 svcpt->scp_nreqs_active, 1461 svcpt->scp_nreqs_active,
1469 at_get(&svcpt->scp_at_estimate), delay); 1462 at_get(&svcpt->scp_at_estimate), delay);
@@ -1825,8 +1818,7 @@ ptlrpc_server_handle_req_in(struct ptlrpc_service_part *svcpt,
1825 if (rc == 0) { 1818 if (rc == 0) {
1826 rc = sptlrpc_target_export_check(req->rq_export, req); 1819 rc = sptlrpc_target_export_check(req->rq_export, req);
1827 if (rc) 1820 if (rc)
1828 DEBUG_REQ(D_ERROR, req, "DROPPING req with " 1821 DEBUG_REQ(D_ERROR, req, "DROPPING req with illegal security flavor,");
1829 "illegal security flavor,");
1830 } 1822 }
1831 1823
1832 if (rc) 1824 if (rc)
@@ -1942,18 +1934,17 @@ ptlrpc_server_handle_request(struct ptlrpc_service_part *svcpt,
1942 /* Discard requests queued for longer than the deadline. 1934 /* Discard requests queued for longer than the deadline.
1943 The deadline is increased if we send an early reply. */ 1935 The deadline is increased if we send an early reply. */
1944 if (get_seconds() > request->rq_deadline) { 1936 if (get_seconds() > request->rq_deadline) {
1945 DEBUG_REQ(D_ERROR, request, "Dropping timed-out request from %s" 1937 DEBUG_REQ(D_ERROR, request, "Dropping timed-out request from %s: deadline " CFS_DURATION_T ":" CFS_DURATION_T "s ago\n",
1946 ": deadline "CFS_DURATION_T":"CFS_DURATION_T"s ago\n",
1947 libcfs_id2str(request->rq_peer), 1938 libcfs_id2str(request->rq_peer),
1948 cfs_time_sub(request->rq_deadline, 1939 cfs_time_sub(request->rq_deadline,
1949 request->rq_arrival_time.tv_sec), 1940 request->rq_arrival_time.tv_sec),
1950 cfs_time_sub(get_seconds(), 1941 cfs_time_sub(get_seconds(),
1951 request->rq_deadline)); 1942 request->rq_deadline));
1952 goto put_conn; 1943 goto put_conn;
1953 } 1944 }
1954 1945
1955 CDEBUG(D_RPCTRACE, "Handling RPC pname:cluuid+ref:pid:xid:nid:opc " 1946 CDEBUG(D_RPCTRACE, "Handling RPC pname:cluuid+ref:pid:xid:nid:opc %s:%s+%d:%d:x%llu:%s:%d\n",
1956 "%s:%s+%d:%d:x%llu:%s:%d\n", current_comm(), 1947 current_comm(),
1957 (request->rq_export ? 1948 (request->rq_export ?
1958 (char *)request->rq_export->exp_client_uuid.uuid : "0"), 1949 (char *)request->rq_export->exp_client_uuid.uuid : "0"),
1959 (request->rq_export ? 1950 (request->rq_export ?
@@ -1986,26 +1977,24 @@ put_conn:
1986 1977
1987 do_gettimeofday(&work_end); 1978 do_gettimeofday(&work_end);
1988 timediff = cfs_timeval_sub(&work_end, &work_start, NULL); 1979 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
1989 CDEBUG(D_RPCTRACE, "Handled RPC pname:cluuid+ref:pid:xid:nid:opc " 1980 CDEBUG(D_RPCTRACE, "Handled RPC pname:cluuid+ref:pid:xid:nid:opc %s:%s+%d:%d:x%llu:%s:%d Request processed in %ldus (%ldus total) trans %llu rc %d/%d\n",
1990 "%s:%s+%d:%d:x%llu:%s:%d Request processed in " 1981 current_comm(),
1991 "%ldus (%ldus total) trans %llu rc %d/%d\n", 1982 (request->rq_export ?
1992 current_comm(), 1983 (char *)request->rq_export->exp_client_uuid.uuid : "0"),
1993 (request->rq_export ? 1984 (request->rq_export ?
1994 (char *)request->rq_export->exp_client_uuid.uuid : "0"), 1985 atomic_read(&request->rq_export->exp_refcount) : -99),
1995 (request->rq_export ? 1986 lustre_msg_get_status(request->rq_reqmsg),
1996 atomic_read(&request->rq_export->exp_refcount) : -99), 1987 request->rq_xid,
1997 lustre_msg_get_status(request->rq_reqmsg), 1988 libcfs_id2str(request->rq_peer),
1998 request->rq_xid, 1989 lustre_msg_get_opc(request->rq_reqmsg),
1999 libcfs_id2str(request->rq_peer), 1990 timediff,
2000 lustre_msg_get_opc(request->rq_reqmsg), 1991 cfs_timeval_sub(&work_end, &request->rq_arrival_time, NULL),
2001 timediff, 1992 (request->rq_repmsg ?
2002 cfs_timeval_sub(&work_end, &request->rq_arrival_time, NULL), 1993 lustre_msg_get_transno(request->rq_repmsg) :
2003 (request->rq_repmsg ? 1994 request->rq_transno),
2004 lustre_msg_get_transno(request->rq_repmsg) : 1995 request->rq_status,
2005 request->rq_transno), 1996 (request->rq_repmsg ?
2006 request->rq_status, 1997 lustre_msg_get_status(request->rq_repmsg) : -999));
2007 (request->rq_repmsg ?
2008 lustre_msg_get_status(request->rq_repmsg) : -999));
2009 if (likely(svc->srv_stats != NULL && request->rq_reqmsg != NULL)) { 1998 if (likely(svc->srv_stats != NULL && request->rq_reqmsg != NULL)) {
2010 __u32 op = lustre_msg_get_opc(request->rq_reqmsg); 1999 __u32 op = lustre_msg_get_opc(request->rq_reqmsg);
2011 int opc = opcode_offset(op); 2000 int opc = opcode_offset(op);
@@ -2557,8 +2546,8 @@ static int ptlrpc_start_hr_threads(void)
2557 if (!IS_ERR_VALUE(rc)) 2546 if (!IS_ERR_VALUE(rc))
2558 continue; 2547 continue;
2559 2548
2560 CERROR("Reply handling thread %d:%d Failed on starting: " 2549 CERROR("Reply handling thread %d:%d Failed on starting: rc = %d\n",
2561 "rc = %d\n", i, j, rc); 2550 i, j, rc);
2562 ptlrpc_stop_hr_threads(); 2551 ptlrpc_stop_hr_threads();
2563 return rc; 2552 return rc;
2564 } 2553 }
@@ -2920,8 +2909,7 @@ ptlrpc_service_unlink_rqbd(struct ptlrpc_service *svc)
2920 rc = l_wait_event(svcpt->scp_waitq, 2909 rc = l_wait_event(svcpt->scp_waitq,
2921 svcpt->scp_nrqbds_posted == 0, &lwi); 2910 svcpt->scp_nrqbds_posted == 0, &lwi);
2922 if (rc == -ETIMEDOUT) { 2911 if (rc == -ETIMEDOUT) {
2923 CWARN("Service %s waiting for " 2912 CWARN("Service %s waiting for request buffers\n",
2924 "request buffers\n",
2925 svcpt->scp_service->srv_name); 2913 svcpt->scp_service->srv_name);
2926 } 2914 }
2927 spin_lock(&svcpt->scp_lock); 2915 spin_lock(&svcpt->scp_lock);
diff --git a/drivers/staging/media/cxd2099/cxd2099.c b/drivers/staging/media/cxd2099/cxd2099.c
index 73e7b2c9e4a7..657ea480c6e7 100644
--- a/drivers/staging/media/cxd2099/cxd2099.c
+++ b/drivers/staging/media/cxd2099/cxd2099.c
@@ -527,7 +527,7 @@ static int slot_reset(struct dvb_ca_en50221 *ca, int slot)
527 u8 val; 527 u8 val;
528#endif 528#endif
529 for (i = 0; i < 100; i++) { 529 for (i = 0; i < 100; i++) {
530 msleep(10); 530 usleep_range(10000, 11000);
531#if 0 531#if 0
532 read_reg(ci, 0x06, &val); 532 read_reg(ci, 0x06, &val);
533 dev_info(&ci->i2c->dev, "%d:%02x\n", i, val); 533 dev_info(&ci->i2c->dev, "%d:%02x\n", i, val);
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipe.h b/drivers/staging/media/davinci_vpfe/dm365_ipipe.h
index cf4204603eb8..d81b29e19309 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_ipipe.h
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipe.h
@@ -120,8 +120,8 @@ struct vpfe_ipipe_device {
120 enum ipipe_input_entity input; 120 enum ipipe_input_entity input;
121 unsigned int output; 121 unsigned int output;
122 struct v4l2_ctrl_handler ctrls; 122 struct v4l2_ctrl_handler ctrls;
123 void *__iomem base_addr; 123 void __iomem *base_addr;
124 void *__iomem isp5_base_addr; 124 void __iomem *isp5_base_addr;
125 struct ipipe_module_params config; 125 struct ipipe_module_params config;
126}; 126};
127 127
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipe_hw.c b/drivers/staging/media/davinci_vpfe/dm365_ipipe_hw.c
index 6461de1a61fd..2a3a56b88de1 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_ipipe_hw.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipe_hw.c
@@ -24,7 +24,7 @@
24#define IPIPE_MODE_CONTINUOUS 0 24#define IPIPE_MODE_CONTINUOUS 0
25#define IPIPE_MODE_SINGLE_SHOT 1 25#define IPIPE_MODE_SINGLE_SHOT 1
26 26
27static void ipipe_clock_enable(void *__iomem base_addr) 27static void ipipe_clock_enable(void __iomem *base_addr)
28{ 28{
29 /* enable IPIPE MMR for register write access */ 29 /* enable IPIPE MMR for register write access */
30 regw_ip(base_addr, IPIPE_GCK_MMR_DEFAULT, IPIPE_GCK_MMR); 30 regw_ip(base_addr, IPIPE_GCK_MMR_DEFAULT, IPIPE_GCK_MMR);
@@ -34,7 +34,7 @@ static void ipipe_clock_enable(void *__iomem base_addr)
34} 34}
35 35
36static void 36static void
37rsz_set_common_params(void *__iomem rsz_base, struct resizer_params *params) 37rsz_set_common_params(void __iomem *rsz_base, struct resizer_params *params)
38{ 38{
39 struct rsz_common_params *rsz_common = &params->rsz_common; 39 struct rsz_common_params *rsz_common = &params->rsz_common;
40 u32 val; 40 u32 val;
@@ -66,7 +66,7 @@ rsz_set_common_params(void *__iomem rsz_base, struct resizer_params *params)
66} 66}
67 67
68static void 68static void
69rsz_set_rsz_regs(void *__iomem rsz_base, unsigned int rsz_id, 69rsz_set_rsz_regs(void __iomem *rsz_base, unsigned int rsz_id,
70 struct resizer_params *params) 70 struct resizer_params *params)
71{ 71{
72 struct resizer_scale_param *rsc_params; 72 struct resizer_scale_param *rsc_params;
@@ -171,7 +171,7 @@ rsz_set_rsz_regs(void *__iomem rsz_base, unsigned int rsz_id,
171 171
172/*set the registers of either RSZ0 or RSZ1 */ 172/*set the registers of either RSZ0 or RSZ1 */
173static void 173static void
174ipipe_setup_resizer(void *__iomem rsz_base, struct resizer_params *params) 174ipipe_setup_resizer(void __iomem *rsz_base, struct resizer_params *params)
175{ 175{
176 /* enable MMR gate to write to Resizer */ 176 /* enable MMR gate to write to Resizer */
177 regw_rsz(rsz_base, 1, RSZ_GCK_MMR); 177 regw_rsz(rsz_base, 1, RSZ_GCK_MMR);
@@ -302,8 +302,8 @@ int config_rsz_hw(struct vpfe_resizer_device *resizer,
302 struct resizer_params *config) 302 struct resizer_params *config)
303{ 303{
304 struct vpfe_device *vpfe_dev = to_vpfe_device(resizer); 304 struct vpfe_device *vpfe_dev = to_vpfe_device(resizer);
305 void *__iomem ipipe_base = vpfe_dev->vpfe_ipipe.base_addr; 305 void __iomem *ipipe_base = vpfe_dev->vpfe_ipipe.base_addr;
306 void *__iomem rsz_base = vpfe_dev->vpfe_resizer.base_addr; 306 void __iomem *rsz_base = vpfe_dev->vpfe_resizer.base_addr;
307 307
308 /* enable VPSS clock */ 308 /* enable VPSS clock */
309 vpss_enable_clock(VPSS_IPIPE_CLOCK, 1); 309 vpss_enable_clock(VPSS_IPIPE_CLOCK, 1);
@@ -315,7 +315,7 @@ int config_rsz_hw(struct vpfe_resizer_device *resizer,
315} 315}
316 316
317static void 317static void
318rsz_set_y_address(void *__iomem rsz_base, unsigned int address, 318rsz_set_y_address(void __iomem *rsz_base, unsigned int address,
319 unsigned int offset) 319 unsigned int offset)
320{ 320{
321 u32 val; 321 u32 val;
@@ -330,7 +330,7 @@ rsz_set_y_address(void *__iomem rsz_base, unsigned int address,
330} 330}
331 331
332static void 332static void
333rsz_set_c_address(void *__iomem rsz_base, unsigned int address, 333rsz_set_c_address(void __iomem *rsz_base, unsigned int address,
334 unsigned int offset) 334 unsigned int offset)
335{ 335{
336 u32 val; 336 u32 val;
@@ -352,7 +352,7 @@ rsz_set_c_address(void *__iomem rsz_base, unsigned int address,
352 * @address: the address to set 352 * @address: the address to set
353 */ 353 */
354int 354int
355resizer_set_outaddr(void *__iomem rsz_base, struct resizer_params *params, 355resizer_set_outaddr(void __iomem *rsz_base, struct resizer_params *params,
356 int resize_no, unsigned int address) 356 int resize_no, unsigned int address)
357{ 357{
358 struct resizer_scale_param *rsc_param; 358 struct resizer_scale_param *rsc_param;
@@ -411,7 +411,7 @@ resizer_set_outaddr(void *__iomem rsz_base, struct resizer_params *params,
411} 411}
412 412
413void 413void
414ipipe_set_lutdpc_regs(void *__iomem base_addr, void *__iomem isp5_base_addr, 414ipipe_set_lutdpc_regs(void __iomem *base_addr, void __iomem *isp5_base_addr,
415 struct vpfe_ipipe_lutdpc *dpc) 415 struct vpfe_ipipe_lutdpc *dpc)
416{ 416{
417 u32 max_tbl_size = LUT_DPC_MAX_SIZE >> 1; 417 u32 max_tbl_size = LUT_DPC_MAX_SIZE >> 1;
@@ -446,7 +446,7 @@ ipipe_set_lutdpc_regs(void *__iomem base_addr, void *__iomem isp5_base_addr,
446} 446}
447 447
448static void 448static void
449set_dpc_thresholds(void *__iomem base_addr, 449set_dpc_thresholds(void __iomem *base_addr,
450 struct vpfe_ipipe_otfdpc_2_0_cfg *dpc_thr) 450 struct vpfe_ipipe_otfdpc_2_0_cfg *dpc_thr)
451{ 451{
452 regw_ip(base_addr, dpc_thr->corr_thr.r & OTFDPC_DPC2_THR_MASK, 452 regw_ip(base_addr, dpc_thr->corr_thr.r & OTFDPC_DPC2_THR_MASK,
@@ -467,7 +467,7 @@ set_dpc_thresholds(void *__iomem base_addr,
467 DPC_OTF_2D_THR_B); 467 DPC_OTF_2D_THR_B);
468} 468}
469 469
470void ipipe_set_otfdpc_regs(void *__iomem base_addr, 470void ipipe_set_otfdpc_regs(void __iomem *base_addr,
471 struct vpfe_ipipe_otfdpc *otfdpc) 471 struct vpfe_ipipe_otfdpc *otfdpc)
472{ 472{
473 struct vpfe_ipipe_otfdpc_2_0_cfg *dpc_2_0 = &otfdpc->alg_cfg.dpc_2_0; 473 struct vpfe_ipipe_otfdpc_2_0_cfg *dpc_2_0 = &otfdpc->alg_cfg.dpc_2_0;
@@ -523,7 +523,7 @@ void ipipe_set_otfdpc_regs(void *__iomem base_addr,
523 523
524/* 2D Noise filter */ 524/* 2D Noise filter */
525void 525void
526ipipe_set_d2f_regs(void *__iomem base_addr, unsigned int id, 526ipipe_set_d2f_regs(void __iomem *base_addr, unsigned int id,
527 struct vpfe_ipipe_nf *noise_filter) 527 struct vpfe_ipipe_nf *noise_filter)
528{ 528{
529 529
@@ -571,7 +571,7 @@ ipipe_set_d2f_regs(void *__iomem base_addr, unsigned int id,
571 (((decimal & 0x1f) | ((integer & 0x7) << 5))) 571 (((decimal & 0x1f) | ((integer & 0x7) << 5)))
572 572
573/* Green Imbalance Correction */ 573/* Green Imbalance Correction */
574void ipipe_set_gic_regs(void *__iomem base_addr, struct vpfe_ipipe_gic *gic) 574void ipipe_set_gic_regs(void __iomem *base_addr, struct vpfe_ipipe_gic *gic)
575{ 575{
576 u32 val; 576 u32 val;
577 577
@@ -609,7 +609,7 @@ void ipipe_set_gic_regs(void *__iomem base_addr, struct vpfe_ipipe_gic *gic)
609#define IPIPE_U13Q9(decimal, integer) \ 609#define IPIPE_U13Q9(decimal, integer) \
610 (((decimal & 0x1ff) | ((integer & 0xf) << 9))) 610 (((decimal & 0x1ff) | ((integer & 0xf) << 9)))
611/* White balance */ 611/* White balance */
612void ipipe_set_wb_regs(void *__iomem base_addr, struct vpfe_ipipe_wb *wb) 612void ipipe_set_wb_regs(void __iomem *base_addr, struct vpfe_ipipe_wb *wb)
613{ 613{
614 u32 val; 614 u32 val;
615 615
@@ -635,7 +635,7 @@ void ipipe_set_wb_regs(void *__iomem base_addr, struct vpfe_ipipe_wb *wb)
635} 635}
636 636
637/* CFA */ 637/* CFA */
638void ipipe_set_cfa_regs(void *__iomem base_addr, struct vpfe_ipipe_cfa *cfa) 638void ipipe_set_cfa_regs(void __iomem *base_addr, struct vpfe_ipipe_cfa *cfa)
639{ 639{
640 ipipe_clock_enable(base_addr); 640 ipipe_clock_enable(base_addr);
641 641
@@ -671,7 +671,7 @@ void ipipe_set_cfa_regs(void *__iomem base_addr, struct vpfe_ipipe_cfa *cfa)
671} 671}
672 672
673void 673void
674ipipe_set_rgb2rgb_regs(void *__iomem base_addr, unsigned int id, 674ipipe_set_rgb2rgb_regs(void __iomem *base_addr, unsigned int id,
675 struct vpfe_ipipe_rgb2rgb *rgb) 675 struct vpfe_ipipe_rgb2rgb *rgb)
676{ 676{
677 u32 offset_mask = RGB2RGB_1_OFST_MASK; 677 u32 offset_mask = RGB2RGB_1_OFST_MASK;
@@ -724,7 +724,7 @@ ipipe_set_rgb2rgb_regs(void *__iomem base_addr, unsigned int id,
724} 724}
725 725
726static void 726static void
727ipipe_update_gamma_tbl(void *__iomem isp5_base_addr, 727ipipe_update_gamma_tbl(void __iomem *isp5_base_addr,
728 struct vpfe_ipipe_gamma_entry *table, int size, u32 addr) 728 struct vpfe_ipipe_gamma_entry *table, int size, u32 addr)
729{ 729{
730 int count; 730 int count;
@@ -738,7 +738,7 @@ ipipe_update_gamma_tbl(void *__iomem isp5_base_addr,
738} 738}
739 739
740void 740void
741ipipe_set_gamma_regs(void *__iomem base_addr, void *__iomem isp5_base_addr, 741ipipe_set_gamma_regs(void __iomem *base_addr, void __iomem *isp5_base_addr,
742 struct vpfe_ipipe_gamma *gamma) 742 struct vpfe_ipipe_gamma *gamma)
743{ 743{
744 int table_size; 744 int table_size;
@@ -770,7 +770,7 @@ ipipe_set_gamma_regs(void *__iomem base_addr, void *__iomem isp5_base_addr,
770} 770}
771 771
772void 772void
773ipipe_set_3d_lut_regs(void *__iomem base_addr, void *__iomem isp5_base_addr, 773ipipe_set_3d_lut_regs(void __iomem *base_addr, void __iomem *isp5_base_addr,
774 struct vpfe_ipipe_3d_lut *lut_3d) 774 struct vpfe_ipipe_3d_lut *lut_3d)
775{ 775{
776 struct vpfe_ipipe_3d_lut_entry *tbl; 776 struct vpfe_ipipe_3d_lut_entry *tbl;
@@ -819,7 +819,7 @@ ipipe_set_3d_lut_regs(void *__iomem base_addr, void *__iomem isp5_base_addr,
819 819
820/* Lumina adjustments */ 820/* Lumina adjustments */
821void 821void
822ipipe_set_lum_adj_regs(void *__iomem base_addr, struct ipipe_lum_adj *lum_adj) 822ipipe_set_lum_adj_regs(void __iomem *base_addr, struct ipipe_lum_adj *lum_adj)
823{ 823{
824 u32 val; 824 u32 val;
825 825
@@ -834,7 +834,7 @@ ipipe_set_lum_adj_regs(void *__iomem base_addr, struct ipipe_lum_adj *lum_adj)
834#define IPIPE_S12Q8(decimal, integer) \ 834#define IPIPE_S12Q8(decimal, integer) \
835 (((decimal & 0xff) | ((integer & 0xf) << 8))) 835 (((decimal & 0xff) | ((integer & 0xf) << 8)))
836 836
837void ipipe_set_rgb2ycbcr_regs(void *__iomem base_addr, 837void ipipe_set_rgb2ycbcr_regs(void __iomem *base_addr,
838 struct vpfe_ipipe_rgb2yuv *yuv) 838 struct vpfe_ipipe_rgb2yuv *yuv)
839{ 839{
840 u32 val; 840 u32 val;
@@ -866,7 +866,7 @@ void ipipe_set_rgb2ycbcr_regs(void *__iomem base_addr,
866 866
867/* YUV 422 conversion */ 867/* YUV 422 conversion */
868void 868void
869ipipe_set_yuv422_conv_regs(void *__iomem base_addr, 869ipipe_set_yuv422_conv_regs(void __iomem *base_addr,
870 struct vpfe_ipipe_yuv422_conv *conv) 870 struct vpfe_ipipe_yuv422_conv *conv)
871{ 871{
872 u32 val; 872 u32 val;
@@ -879,7 +879,7 @@ ipipe_set_yuv422_conv_regs(void *__iomem base_addr,
879} 879}
880 880
881void 881void
882ipipe_set_gbce_regs(void *__iomem base_addr, void *__iomem isp5_base_addr, 882ipipe_set_gbce_regs(void __iomem *base_addr, void __iomem *isp5_base_addr,
883 struct vpfe_ipipe_gbce *gbce) 883 struct vpfe_ipipe_gbce *gbce)
884{ 884{
885 unsigned int count; 885 unsigned int count;
@@ -906,7 +906,7 @@ ipipe_set_gbce_regs(void *__iomem base_addr, void *__iomem isp5_base_addr,
906} 906}
907 907
908void 908void
909ipipe_set_ee_regs(void *__iomem base_addr, void *__iomem isp5_base_addr, 909ipipe_set_ee_regs(void __iomem *base_addr, void __iomem *isp5_base_addr,
910 struct vpfe_ipipe_yee *ee) 910 struct vpfe_ipipe_yee *ee)
911{ 911{
912 unsigned int count; 912 unsigned int count;
@@ -950,7 +950,7 @@ ipipe_set_ee_regs(void *__iomem base_addr, void *__iomem isp5_base_addr,
950} 950}
951 951
952/* Chromatic Artifact Correction. CAR */ 952/* Chromatic Artifact Correction. CAR */
953static void ipipe_set_mf(void *__iomem base_addr) 953static void ipipe_set_mf(void __iomem *base_addr)
954{ 954{
955 /* typ to dynamic switch */ 955 /* typ to dynamic switch */
956 regw_ip(base_addr, VPFE_IPIPE_CAR_DYN_SWITCH, CAR_TYP); 956 regw_ip(base_addr, VPFE_IPIPE_CAR_DYN_SWITCH, CAR_TYP);
@@ -959,7 +959,7 @@ static void ipipe_set_mf(void *__iomem base_addr)
959} 959}
960 960
961static void 961static void
962ipipe_set_gain_ctrl(void *__iomem base_addr, struct vpfe_ipipe_car *car) 962ipipe_set_gain_ctrl(void __iomem *base_addr, struct vpfe_ipipe_car *car)
963{ 963{
964 regw_ip(base_addr, VPFE_IPIPE_CAR_CHR_GAIN_CTRL, CAR_TYP); 964 regw_ip(base_addr, VPFE_IPIPE_CAR_CHR_GAIN_CTRL, CAR_TYP);
965 regw_ip(base_addr, car->hpf, CAR_HPF_TYP); 965 regw_ip(base_addr, car->hpf, CAR_HPF_TYP);
@@ -975,7 +975,7 @@ ipipe_set_gain_ctrl(void *__iomem base_addr, struct vpfe_ipipe_car *car)
975 CAR_GN2_MIN); 975 CAR_GN2_MIN);
976} 976}
977 977
978void ipipe_set_car_regs(void *__iomem base_addr, struct vpfe_ipipe_car *car) 978void ipipe_set_car_regs(void __iomem *base_addr, struct vpfe_ipipe_car *car)
979{ 979{
980 u32 val; 980 u32 val;
981 981
@@ -1010,7 +1010,7 @@ void ipipe_set_car_regs(void *__iomem base_addr, struct vpfe_ipipe_car *car)
1010} 1010}
1011 1011
1012/* Chromatic Gain Suppression */ 1012/* Chromatic Gain Suppression */
1013void ipipe_set_cgs_regs(void *__iomem base_addr, struct vpfe_ipipe_cgs *cgs) 1013void ipipe_set_cgs_regs(void __iomem *base_addr, struct vpfe_ipipe_cgs *cgs)
1014{ 1014{
1015 ipipe_clock_enable(base_addr); 1015 ipipe_clock_enable(base_addr);
1016 regw_ip(base_addr, cgs->en, CGS_EN); 1016 regw_ip(base_addr, cgs->en, CGS_EN);
@@ -1025,12 +1025,12 @@ void ipipe_set_cgs_regs(void *__iomem base_addr, struct vpfe_ipipe_cgs *cgs)
1025 regw_ip(base_addr, cgs->h_min, CGS_GN1_H_MIN); 1025 regw_ip(base_addr, cgs->h_min, CGS_GN1_H_MIN);
1026} 1026}
1027 1027
1028void rsz_src_enable(void *__iomem rsz_base, int enable) 1028void rsz_src_enable(void __iomem *rsz_base, int enable)
1029{ 1029{
1030 regw_rsz(rsz_base, enable, RSZ_SRC_EN); 1030 regw_rsz(rsz_base, enable, RSZ_SRC_EN);
1031} 1031}
1032 1032
1033int rsz_enable(void *__iomem rsz_base, int rsz_id, int enable) 1033int rsz_enable(void __iomem *rsz_base, int rsz_id, int enable)
1034{ 1034{
1035 if (rsz_id == RSZ_A) { 1035 if (rsz_id == RSZ_A) {
1036 regw_rsz(rsz_base, enable, RSZ_EN_A); 1036 regw_rsz(rsz_base, enable, RSZ_EN_A);
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipe_hw.h b/drivers/staging/media/davinci_vpfe/dm365_ipipe_hw.h
index 81176fb9d164..2bf2f7a69173 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_ipipe_hw.h
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipe_hw.h
@@ -490,29 +490,29 @@
490#define RSZ_RGB_TYP_SHIFT 0 490#define RSZ_RGB_TYP_SHIFT 0
491#define RSZ_RGB_ALPHA_MASK 0xff 491#define RSZ_RGB_ALPHA_MASK 0xff
492 492
493static inline u32 regr_ip(void *__iomem addr, u32 offset) 493static inline u32 regr_ip(void __iomem *addr, u32 offset)
494{ 494{
495 return readl(addr + offset); 495 return readl(addr + offset);
496} 496}
497 497
498static inline void regw_ip(void *__iomem addr, u32 val, u32 offset) 498static inline void regw_ip(void __iomem *addr, u32 val, u32 offset)
499{ 499{
500 writel(val, addr + offset); 500 writel(val, addr + offset);
501} 501}
502 502
503static inline u32 w_ip_table(void *__iomem addr, u32 val, u32 offset) 503static inline u32 w_ip_table(void __iomem *addr, u32 val, u32 offset)
504{ 504{
505 writel(val, addr + offset); 505 writel(val, addr + offset);
506 506
507 return val; 507 return val;
508} 508}
509 509
510static inline u32 regr_rsz(void *__iomem addr, u32 offset) 510static inline u32 regr_rsz(void __iomem *addr, u32 offset)
511{ 511{
512 return readl(addr + offset); 512 return readl(addr + offset);
513} 513}
514 514
515static inline u32 regw_rsz(void *__iomem addr, u32 val, u32 offset) 515static inline u32 regw_rsz(void __iomem *addr, u32 val, u32 offset)
516{ 516{
517 writel(val, addr + offset); 517 writel(val, addr + offset);
518 518
@@ -520,39 +520,39 @@ static inline u32 regw_rsz(void *__iomem addr, u32 val, u32 offset)
520} 520}
521 521
522int config_ipipe_hw(struct vpfe_ipipe_device *ipipe); 522int config_ipipe_hw(struct vpfe_ipipe_device *ipipe);
523int resizer_set_outaddr(void *__iomem rsz_base, struct resizer_params *params, 523int resizer_set_outaddr(void __iomem *rsz_base, struct resizer_params *params,
524 int resize_no, unsigned int address); 524 int resize_no, unsigned int address);
525int rsz_enable(void *__iomem rsz_base, int rsz_id, int enable); 525int rsz_enable(void __iomem *rsz_base, int rsz_id, int enable);
526void rsz_src_enable(void *__iomem rsz_base, int enable); 526void rsz_src_enable(void __iomem *rsz_base, int enable);
527void rsz_set_in_pix_format(unsigned char y_c); 527void rsz_set_in_pix_format(unsigned char y_c);
528int config_rsz_hw(struct vpfe_resizer_device *resizer, 528int config_rsz_hw(struct vpfe_resizer_device *resizer,
529 struct resizer_params *config); 529 struct resizer_params *config);
530void ipipe_set_d2f_regs(void *__iomem base_addr, unsigned int id, 530void ipipe_set_d2f_regs(void __iomem *base_addr, unsigned int id,
531 struct vpfe_ipipe_nf *noise_filter); 531 struct vpfe_ipipe_nf *noise_filter);
532void ipipe_set_rgb2rgb_regs(void *__iomem base_addr, unsigned int id, 532void ipipe_set_rgb2rgb_regs(void __iomem *base_addr, unsigned int id,
533 struct vpfe_ipipe_rgb2rgb *rgb); 533 struct vpfe_ipipe_rgb2rgb *rgb);
534void ipipe_set_yuv422_conv_regs(void *__iomem base_addr, 534void ipipe_set_yuv422_conv_regs(void __iomem *base_addr,
535 struct vpfe_ipipe_yuv422_conv *conv); 535 struct vpfe_ipipe_yuv422_conv *conv);
536void ipipe_set_lum_adj_regs(void *__iomem base_addr, 536void ipipe_set_lum_adj_regs(void __iomem *base_addr,
537 struct ipipe_lum_adj *lum_adj); 537 struct ipipe_lum_adj *lum_adj);
538void ipipe_set_rgb2ycbcr_regs(void *__iomem base_addr, 538void ipipe_set_rgb2ycbcr_regs(void __iomem *base_addr,
539 struct vpfe_ipipe_rgb2yuv *yuv); 539 struct vpfe_ipipe_rgb2yuv *yuv);
540void ipipe_set_lutdpc_regs(void *__iomem base_addr, 540void ipipe_set_lutdpc_regs(void __iomem *base_addr,
541 void *__iomem isp5_base_addr, struct vpfe_ipipe_lutdpc *lutdpc); 541 void __iomem *isp5_base_addr, struct vpfe_ipipe_lutdpc *lutdpc);
542void ipipe_set_otfdpc_regs(void *__iomem base_addr, 542void ipipe_set_otfdpc_regs(void __iomem *base_addr,
543 struct vpfe_ipipe_otfdpc *otfdpc); 543 struct vpfe_ipipe_otfdpc *otfdpc);
544void ipipe_set_3d_lut_regs(void *__iomem base_addr, 544void ipipe_set_3d_lut_regs(void __iomem *base_addr,
545 void *__iomem isp5_base_addr, struct vpfe_ipipe_3d_lut *lut_3d); 545 void __iomem *isp5_base_addr, struct vpfe_ipipe_3d_lut *lut_3d);
546void ipipe_set_gamma_regs(void *__iomem base_addr, 546void ipipe_set_gamma_regs(void __iomem *base_addr,
547 void *__iomem isp5_base_addr, struct vpfe_ipipe_gamma *gamma); 547 void __iomem *isp5_base_addr, struct vpfe_ipipe_gamma *gamma);
548void ipipe_set_ee_regs(void *__iomem base_addr, 548void ipipe_set_ee_regs(void __iomem *base_addr,
549 void *__iomem isp5_base_addr, struct vpfe_ipipe_yee *ee); 549 void __iomem *isp5_base_addr, struct vpfe_ipipe_yee *ee);
550void ipipe_set_gbce_regs(void *__iomem base_addr, 550void ipipe_set_gbce_regs(void __iomem *base_addr,
551 void *__iomem isp5_base_addr, struct vpfe_ipipe_gbce *gbce); 551 void __iomem *isp5_base_addr, struct vpfe_ipipe_gbce *gbce);
552void ipipe_set_gic_regs(void *__iomem base_addr, struct vpfe_ipipe_gic *gic); 552void ipipe_set_gic_regs(void __iomem *base_addr, struct vpfe_ipipe_gic *gic);
553void ipipe_set_cfa_regs(void *__iomem base_addr, struct vpfe_ipipe_cfa *cfa); 553void ipipe_set_cfa_regs(void __iomem *base_addr, struct vpfe_ipipe_cfa *cfa);
554void ipipe_set_car_regs(void *__iomem base_addr, struct vpfe_ipipe_car *car); 554void ipipe_set_car_regs(void __iomem *base_addr, struct vpfe_ipipe_car *car);
555void ipipe_set_cgs_regs(void *__iomem base_addr, struct vpfe_ipipe_cgs *cgs); 555void ipipe_set_cgs_regs(void __iomem *base_addr, struct vpfe_ipipe_cgs *cgs);
556void ipipe_set_wb_regs(void *__iomem base_addr, struct vpfe_ipipe_wb *wb); 556void ipipe_set_wb_regs(void __iomem *base_addr, struct vpfe_ipipe_wb *wb);
557 557
558#endif /* _DAVINCI_VPFE_DM365_IPIPE_HW_H */ 558#endif /* _DAVINCI_VPFE_DM365_IPIPE_HW_H */
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
index a86f16ff5818..87d42e18377d 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c
@@ -421,7 +421,7 @@ static int
421ipipeif_get_config(struct v4l2_subdev *sd, void __user *arg) 421ipipeif_get_config(struct v4l2_subdev *sd, void __user *arg)
422{ 422{
423 struct vpfe_ipipeif_device *ipipeif = v4l2_get_subdevdata(sd); 423 struct vpfe_ipipeif_device *ipipeif = v4l2_get_subdevdata(sd);
424 struct ipipeif_params *config = (struct ipipeif_params *)arg; 424 struct ipipeif_params *config = arg;
425 struct device *dev = ipipeif->subdev.v4l2_dev->dev; 425 struct device *dev = ipipeif->subdev.v4l2_dev->dev;
426 426
427 if (!arg) { 427 if (!arg) {
@@ -462,7 +462,7 @@ ipipeif_get_config(struct v4l2_subdev *sd, void __user *arg)
462static long ipipeif_ioctl(struct v4l2_subdev *sd, 462static long ipipeif_ioctl(struct v4l2_subdev *sd,
463 unsigned int cmd, void *arg) 463 unsigned int cmd, void *arg)
464{ 464{
465 struct ipipeif_params *config = (struct ipipeif_params *)arg; 465 struct ipipeif_params *config = arg;
466 int ret = -ENOIOCTLCMD; 466 int ret = -ENOIOCTLCMD;
467 467
468 switch (cmd) { 468 switch (cmd) {
diff --git a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.h b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.h
index 608701fc5fed..cea3d61335af 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_ipipeif.h
+++ b/drivers/staging/media/davinci_vpfe/dm365_ipipeif.h
@@ -134,7 +134,7 @@ struct vpfe_ipipeif_device {
134 unsigned int output; 134 unsigned int output;
135 struct vpfe_video_device video_in; 135 struct vpfe_video_device video_in;
136 struct v4l2_ctrl_handler ctrls; 136 struct v4l2_ctrl_handler ctrls;
137 void *__iomem ipipeif_base_addr; 137 void __iomem *ipipeif_base_addr;
138 struct ipipeif_params config; 138 struct ipipeif_params config;
139 int dpcm_predictor; 139 int dpcm_predictor;
140 int gain; 140 int gain;
diff --git a/drivers/staging/media/davinci_vpfe/dm365_isif.c b/drivers/staging/media/davinci_vpfe/dm365_isif.c
index fa26f63831b7..0ba0bf2c1cff 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_isif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_isif.c
@@ -70,17 +70,17 @@ static const u32 isif_srggb_pattern =
70 ISIF_COLPTN_Gb_G << ISIF_CCOLP_CP15_4 | 70 ISIF_COLPTN_Gb_G << ISIF_CCOLP_CP15_4 |
71 ISIF_COLPTN_B_Mg << ISIF_CCOLP_CP17_6; 71 ISIF_COLPTN_B_Mg << ISIF_CCOLP_CP17_6;
72 72
73static inline u32 isif_read(void *__iomem base_addr, u32 offset) 73static inline u32 isif_read(void __iomem *base_addr, u32 offset)
74{ 74{
75 return readl(base_addr + offset); 75 return readl(base_addr + offset);
76} 76}
77 77
78static inline void isif_write(void *__iomem base_addr, u32 val, u32 offset) 78static inline void isif_write(void __iomem *base_addr, u32 val, u32 offset)
79{ 79{
80 writel(val, base_addr + offset); 80 writel(val, base_addr + offset);
81} 81}
82 82
83static inline u32 isif_merge(void *__iomem base_addr, u32 mask, u32 val, 83static inline u32 isif_merge(void __iomem *base_addr, u32 mask, u32 val,
84 u32 offset) 84 u32 offset)
85{ 85{
86 u32 new_val = (isif_read(base_addr, offset) & ~mask) | (val & mask); 86 u32 new_val = (isif_read(base_addr, offset) & ~mask) | (val & mask);
@@ -646,7 +646,7 @@ static void isif_config_gain_offset(struct vpfe_isif_device *isif)
646{ 646{
647 struct vpfe_isif_gain_offsets_adj *gain_off_ptr = 647 struct vpfe_isif_gain_offsets_adj *gain_off_ptr =
648 &isif->isif_cfg.bayer.config_params.gain_offset; 648 &isif->isif_cfg.bayer.config_params.gain_offset;
649 void *__iomem base = isif->isif_cfg.base_addr; 649 void __iomem *base = isif->isif_cfg.base_addr;
650 u32 val; 650 u32 val;
651 651
652 val = ((gain_off_ptr->gain_sdram_en & 1) << GAIN_SDRAM_EN_SHIFT) | 652 val = ((gain_off_ptr->gain_sdram_en & 1) << GAIN_SDRAM_EN_SHIFT) |
@@ -1602,6 +1602,7 @@ isif_pad_get_crop(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1602 1602
1603 if (crop->which == V4L2_SUBDEV_FORMAT_TRY) { 1603 if (crop->which == V4L2_SUBDEV_FORMAT_TRY) {
1604 struct v4l2_rect *rect; 1604 struct v4l2_rect *rect;
1605
1605 rect = v4l2_subdev_get_try_crop(fh, ISIF_PAD_SINK); 1606 rect = v4l2_subdev_get_try_crop(fh, ISIF_PAD_SINK);
1606 memcpy(&crop->rect, rect, sizeof(*rect)); 1607 memcpy(&crop->rect, rect, sizeof(*rect));
1607 } else { 1608 } else {
@@ -1991,7 +1992,7 @@ int vpfe_isif_init(struct vpfe_isif_device *isif, struct platform_device *pdev)
1991 struct media_entity *me = &sd->entity; 1992 struct media_entity *me = &sd->entity;
1992 static resource_size_t res_len; 1993 static resource_size_t res_len;
1993 struct resource *res; 1994 struct resource *res;
1994 void *__iomem addr; 1995 void __iomem *addr;
1995 int status; 1996 int status;
1996 int i = 0; 1997 int i = 0;
1997 1998
diff --git a/drivers/staging/media/davinci_vpfe/dm365_isif.h b/drivers/staging/media/davinci_vpfe/dm365_isif.h
index 473fd2cfe350..89e814e9c0d7 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_isif.h
+++ b/drivers/staging/media/davinci_vpfe/dm365_isif.h
@@ -159,9 +159,9 @@ struct isif_oper_config {
159 struct isif_params_raw bayer; 159 struct isif_params_raw bayer;
160 enum isif_data_pack data_pack; 160 enum isif_data_pack data_pack;
161 struct isif_gain_values isif_gain_params; 161 struct isif_gain_values isif_gain_params;
162 void *__iomem base_addr; 162 void __iomem *base_addr;
163 void *__iomem linear_tbl0_addr; 163 void __iomem *linear_tbl0_addr;
164 void *__iomem linear_tbl1_addr; 164 void __iomem *linear_tbl1_addr;
165}; 165};
166 166
167#define ISIF_PAD_SINK 0 167#define ISIF_PAD_SINK 0
diff --git a/drivers/staging/media/davinci_vpfe/dm365_resizer.c b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
index e0b29c8ca221..75e70e14b724 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_resizer.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_resizer.c
@@ -149,7 +149,7 @@ configure_resizer_out_params(struct vpfe_resizer_device *resizer, int index,
149 param->rsz_en[index] = DISABLE; 149 param->rsz_en[index] = DISABLE;
150 return; 150 return;
151 } 151 }
152 output = (struct vpfe_rsz_output_spec *)output_spec; 152 output = output_spec;
153 param->rsz_en[index] = ENABLE; 153 param->rsz_en[index] = ENABLE;
154 if (partial) { 154 if (partial) {
155 param->rsz_rsc_param[index].h_flip = output->h_flip; 155 param->rsz_rsc_param[index].h_flip = output->h_flip;
@@ -633,7 +633,7 @@ resizer_calculate_normal_f_div_param(struct device *dev, int input_width,
633 if (!(val % 2)) { 633 if (!(val % 2)) {
634 h1 = val; 634 h1 = val;
635 } else { 635 } else {
636 val = (input_width << 7); 636 val = input_width << 7;
637 val -= rsz >> 1; 637 val -= rsz >> 1;
638 val /= rsz << 1; 638 val /= rsz << 1;
639 val <<= 1; 639 val <<= 1;
@@ -1218,12 +1218,12 @@ static long resizer_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
1218 1218
1219 switch (cmd) { 1219 switch (cmd) {
1220 case VIDIOC_VPFE_RSZ_S_CONFIG: 1220 case VIDIOC_VPFE_RSZ_S_CONFIG:
1221 user_config = (struct vpfe_rsz_config *)arg; 1221 user_config = arg;
1222 ret = resizer_set_configuration(resizer, user_config); 1222 ret = resizer_set_configuration(resizer, user_config);
1223 break; 1223 break;
1224 1224
1225 case VIDIOC_VPFE_RSZ_G_CONFIG: 1225 case VIDIOC_VPFE_RSZ_G_CONFIG:
1226 user_config = (struct vpfe_rsz_config *)arg; 1226 user_config = arg;
1227 if (!user_config->config) { 1227 if (!user_config->config) {
1228 dev_err(dev, "error in VIDIOC_VPFE_RSZ_G_CONFIG\n"); 1228 dev_err(dev, "error in VIDIOC_VPFE_RSZ_G_CONFIG\n");
1229 return -EINVAL; 1229 return -EINVAL;
diff --git a/drivers/staging/media/davinci_vpfe/dm365_resizer.h b/drivers/staging/media/davinci_vpfe/dm365_resizer.h
index 59a79422b914..93b0f44030aa 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_resizer.h
+++ b/drivers/staging/media/davinci_vpfe/dm365_resizer.h
@@ -228,7 +228,7 @@ struct vpfe_resizer_device {
228 struct dm365_resizer_device resizer_a; 228 struct dm365_resizer_device resizer_a;
229 struct dm365_resizer_device resizer_b; 229 struct dm365_resizer_device resizer_b;
230 struct resizer_params config; 230 struct resizer_params config;
231 void *__iomem base_addr; 231 void __iomem *base_addr;
232}; 232};
233 233
234int vpfe_resizer_init(struct vpfe_resizer_device *vpfe_rsz, 234int vpfe_resizer_init(struct vpfe_resizer_device *vpfe_rsz,
diff --git a/drivers/staging/media/lirc/lirc_bt829.c b/drivers/staging/media/lirc/lirc_bt829.c
index 4c806ba41323..44f565547179 100644
--- a/drivers/staging/media/lirc/lirc_bt829.c
+++ b/drivers/staging/media/lirc/lirc_bt829.c
@@ -56,11 +56,6 @@ static unsigned char do_get_bits(void);
56#define DRIVER_NAME "lirc_bt829" 56#define DRIVER_NAME "lirc_bt829"
57 57
58static bool debug; 58static bool debug;
59#define dprintk(fmt, args...) \
60 do { \
61 if (debug) \
62 printk(KERN_DEBUG DRIVER_NAME ": "fmt, ## args); \
63 } while (0)
64 59
65static int atir_minor; 60static int atir_minor;
66static phys_addr_t pci_addr_phys; 61static phys_addr_t pci_addr_phys;
@@ -101,7 +96,7 @@ static int atir_add_to_buf(void *data, struct lirc_buffer *buf)
101 status = poll_main(); 96 status = poll_main();
102 key = (status >> 8) & 0xFF; 97 key = (status >> 8) & 0xFF;
103 if (status & 0xFF) { 98 if (status & 0xFF) {
104 dprintk("reading key %02X\n", key); 99 dev_dbg(atir_driver.dev, "reading key %02X\n", key);
105 lirc_buffer_write(buf, &key); 100 lirc_buffer_write(buf, &key);
106 return 0; 101 return 0;
107 } 102 }
@@ -110,13 +105,13 @@ static int atir_add_to_buf(void *data, struct lirc_buffer *buf)
110 105
111static int atir_set_use_inc(void *data) 106static int atir_set_use_inc(void *data)
112{ 107{
113 dprintk("driver is opened\n"); 108 dev_dbg(atir_driver.dev, "driver is opened\n");
114 return 0; 109 return 0;
115} 110}
116 111
117static void atir_set_use_dec(void *data) 112static void atir_set_use_dec(void *data)
118{ 113{
119 dprintk("driver is closed\n"); 114 dev_dbg(atir_driver.dev, "driver is closed\n");
120} 115}
121 116
122int init_module(void) 117int init_module(void)
@@ -154,7 +149,8 @@ int init_module(void)
154 rc = atir_minor; 149 rc = atir_minor;
155 goto err_unmap; 150 goto err_unmap;
156 } 151 }
157 dprintk("driver is registered on minor %d\n", atir_minor); 152 dev_dbg(atir_driver.dev, "driver is registered on minor %d\n",
153 atir_minor);
158 154
159 return 0; 155 return 0;
160 156
diff --git a/drivers/staging/media/lirc/lirc_imon.c b/drivers/staging/media/lirc/lirc_imon.c
index 232edd5b1742..9ce7d9990e3e 100644
--- a/drivers/staging/media/lirc/lirc_imon.c
+++ b/drivers/staging/media/lirc/lirc_imon.c
@@ -495,7 +495,7 @@ static int ir_open(void *data)
495 /* prevent races with disconnect */ 495 /* prevent races with disconnect */
496 mutex_lock(&driver_lock); 496 mutex_lock(&driver_lock);
497 497
498 context = (struct imon_context *)data; 498 context = data;
499 499
500 /* initial IR protocol decode variables */ 500 /* initial IR protocol decode variables */
501 context->rx.count = 0; 501 context->rx.count = 0;
@@ -516,7 +516,7 @@ static void ir_close(void *data)
516{ 516{
517 struct imon_context *context; 517 struct imon_context *context;
518 518
519 context = (struct imon_context *)data; 519 context = data;
520 if (!context) { 520 if (!context) {
521 pr_err("%s: no context for device\n", __func__); 521 pr_err("%s: no context for device\n", __func__);
522 return; 522 return;
@@ -572,29 +572,6 @@ static void submit_data(struct imon_context *context)
572 wake_up(&context->driver->rbuf->wait_poll); 572 wake_up(&context->driver->rbuf->wait_poll);
573} 573}
574 574
575static inline int tv2int(const struct timeval *a, const struct timeval *b)
576{
577 int usecs = 0;
578 int sec = 0;
579
580 if (b->tv_usec > a->tv_usec) {
581 usecs = 1000000;
582 sec--;
583 }
584
585 usecs += a->tv_usec - b->tv_usec;
586
587 sec += a->tv_sec - b->tv_sec;
588 sec *= 1000;
589 usecs /= 1000;
590 sec += usecs;
591
592 if (sec < 0)
593 sec = 1000;
594
595 return sec;
596}
597
598/** 575/**
599 * Process the incoming packet 576 * Process the incoming packet
600 */ 577 */
diff --git a/drivers/staging/media/lirc/lirc_sasem.c b/drivers/staging/media/lirc/lirc_sasem.c
index 2f0463eb9887..4a268200cbf5 100644
--- a/drivers/staging/media/lirc/lirc_sasem.c
+++ b/drivers/staging/media/lirc/lirc_sasem.c
@@ -488,7 +488,7 @@ static int ir_open(void *data)
488 /* prevent races with disconnect */ 488 /* prevent races with disconnect */
489 mutex_lock(&disconnect_lock); 489 mutex_lock(&disconnect_lock);
490 490
491 context = (struct sasem_context *) data; 491 context = data;
492 492
493 mutex_lock(&context->ctx_lock); 493 mutex_lock(&context->ctx_lock);
494 494
@@ -530,7 +530,7 @@ static void ir_close(void *data)
530{ 530{
531 struct sasem_context *context; 531 struct sasem_context *context;
532 532
533 context = (struct sasem_context *)data; 533 context = data;
534 if (!context) { 534 if (!context) {
535 pr_err("%s: no context for device\n", __func__); 535 pr_err("%s: no context for device\n", __func__);
536 return; 536 return;
diff --git a/drivers/staging/media/lirc/lirc_sir.c b/drivers/staging/media/lirc/lirc_sir.c
index e961b5218215..39f4733fb1ee 100644
--- a/drivers/staging/media/lirc/lirc_sir.c
+++ b/drivers/staging/media/lirc/lirc_sir.c
@@ -140,12 +140,6 @@ static int rx_buf[RBUF_LEN];
140static unsigned int rx_tail, rx_head; 140static unsigned int rx_tail, rx_head;
141 141
142static bool debug; 142static bool debug;
143#define dprintk(fmt, args...) \
144 do { \
145 if (debug) \
146 printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \
147 fmt, ## args); \
148 } while (0)
149 143
150/* SECTION: Prototypes */ 144/* SECTION: Prototypes */
151 145
@@ -322,7 +316,7 @@ static void add_read_queue(int flag, unsigned long val)
322 unsigned int new_rx_tail; 316 unsigned int new_rx_tail;
323 int newval; 317 int newval;
324 318
325 dprintk("add flag %d with val %lu\n", flag, val); 319 pr_debug("add flag %d with val %lu\n", flag, val);
326 320
327 newval = val & PULSE_MASK; 321 newval = val & PULSE_MASK;
328 322
@@ -342,7 +336,7 @@ static void add_read_queue(int flag, unsigned long val)
342 } 336 }
343 new_rx_tail = (rx_tail + 1) & (RBUF_LEN - 1); 337 new_rx_tail = (rx_tail + 1) & (RBUF_LEN - 1);
344 if (new_rx_tail == rx_head) { 338 if (new_rx_tail == rx_head) {
345 dprintk("Buffer overrun.\n"); 339 pr_debug("Buffer overrun.\n");
346 return; 340 return;
347 } 341 }
348 rx_buf[rx_tail] = newval; 342 rx_buf[rx_tail] = newval;
@@ -439,7 +433,8 @@ static void sir_timeout(unsigned long data)
439 outb(UART_FCR_CLEAR_RCVR, io + UART_FCR); 433 outb(UART_FCR_CLEAR_RCVR, io + UART_FCR);
440 /* determine 'virtual' pulse end: */ 434 /* determine 'virtual' pulse end: */
441 pulse_end = delta(&last_tv, &last_intr_tv); 435 pulse_end = delta(&last_tv, &last_intr_tv);
442 dprintk("timeout add %d for %lu usec\n", last_value, pulse_end); 436 dev_dbg(driver.dev, "timeout add %d for %lu usec\n",
437 last_value, pulse_end);
443 add_read_queue(last_value, pulse_end); 438 add_read_queue(last_value, pulse_end);
444 last_value = 0; 439 last_value = 0;
445 last_tv = last_intr_tv; 440 last_tv = last_intr_tv;
@@ -479,14 +474,15 @@ static irqreturn_t sir_interrupt(int irq, void *dev_id)
479 do_gettimeofday(&curr_tv); 474 do_gettimeofday(&curr_tv);
480 deltv = delta(&last_tv, &curr_tv); 475 deltv = delta(&last_tv, &curr_tv);
481 deltintrtv = delta(&last_intr_tv, &curr_tv); 476 deltintrtv = delta(&last_intr_tv, &curr_tv);
482 dprintk("t %lu, d %d\n", deltintrtv, (int)data); 477 dev_dbg(driver.dev, "t %lu, d %d\n",
478 deltintrtv, (int)data);
483 /* 479 /*
484 * if nothing came in last X cycles, 480 * if nothing came in last X cycles,
485 * it was gap 481 * it was gap
486 */ 482 */
487 if (deltintrtv > TIME_CONST * threshold) { 483 if (deltintrtv > TIME_CONST * threshold) {
488 if (last_value) { 484 if (last_value) {
489 dprintk("GAP\n"); 485 dev_dbg(driver.dev, "GAP\n");
490 /* simulate signal change */ 486 /* simulate signal change */
491 add_read_queue(last_value, 487 add_read_queue(last_value,
492 deltv - 488 deltv -
diff --git a/drivers/staging/media/lirc/lirc_zilog.c b/drivers/staging/media/lirc/lirc_zilog.c
index 1e15d2cab727..cc872fb4ca68 100644
--- a/drivers/staging/media/lirc/lirc_zilog.c
+++ b/drivers/staging/media/lirc/lirc_zilog.c
@@ -152,23 +152,12 @@ struct tx_data_struct {
152static struct tx_data_struct *tx_data; 152static struct tx_data_struct *tx_data;
153static struct mutex tx_data_lock; 153static struct mutex tx_data_lock;
154 154
155#define zilog_notify(s, args...) printk(KERN_NOTICE KBUILD_MODNAME ": " s, \
156 ## args)
157#define zilog_error(s, args...) printk(KERN_ERR KBUILD_MODNAME ": " s, ## args)
158#define zilog_info(s, args...) printk(KERN_INFO KBUILD_MODNAME ": " s, ## args)
159 155
160/* module parameters */ 156/* module parameters */
161static bool debug; /* debug output */ 157static bool debug; /* debug output */
162static bool tx_only; /* only handle the IR Tx function */ 158static bool tx_only; /* only handle the IR Tx function */
163static int minor = -1; /* minor number */ 159static int minor = -1; /* minor number */
164 160
165#define dprintk(fmt, args...) \
166 do { \
167 if (debug) \
168 printk(KERN_DEBUG KBUILD_MODNAME ": " fmt, \
169 ## args); \
170 } while (0)
171
172 161
173/* struct IR reference counting */ 162/* struct IR reference counting */
174static struct IR *get_ir_device(struct IR *ir, bool ir_devices_lock_held) 163static struct IR *get_ir_device(struct IR *ir, bool ir_devices_lock_held)
@@ -333,7 +322,7 @@ static int add_to_buf(struct IR *ir)
333 struct IR_tx *tx; 322 struct IR_tx *tx;
334 323
335 if (lirc_buffer_full(rbuf)) { 324 if (lirc_buffer_full(rbuf)) {
336 dprintk("buffer overflow\n"); 325 dev_dbg(ir->l.dev, "buffer overflow\n");
337 return -EOVERFLOW; 326 return -EOVERFLOW;
338 } 327 }
339 328
@@ -379,16 +368,17 @@ static int add_to_buf(struct IR *ir)
379 */ 368 */
380 ret = i2c_master_send(rx->c, sendbuf, 1); 369 ret = i2c_master_send(rx->c, sendbuf, 1);
381 if (ret != 1) { 370 if (ret != 1) {
382 zilog_error("i2c_master_send failed with %d\n", ret); 371 dev_err(ir->l.dev, "i2c_master_send failed with %d\n",
372 ret);
383 if (failures >= 3) { 373 if (failures >= 3) {
384 mutex_unlock(&ir->ir_lock); 374 mutex_unlock(&ir->ir_lock);
385 zilog_error("unable to read from the IR chip " 375 dev_err(ir->l.dev, "unable to read from the IR chip "
386 "after 3 resets, giving up\n"); 376 "after 3 resets, giving up\n");
387 break; 377 break;
388 } 378 }
389 379
390 /* Looks like the chip crashed, reset it */ 380 /* Looks like the chip crashed, reset it */
391 zilog_error("polling the IR receiver chip failed, " 381 dev_err(ir->l.dev, "polling the IR receiver chip failed, "
392 "trying reset\n"); 382 "trying reset\n");
393 383
394 set_current_state(TASK_UNINTERRUPTIBLE); 384 set_current_state(TASK_UNINTERRUPTIBLE);
@@ -415,13 +405,14 @@ static int add_to_buf(struct IR *ir)
415 ret = i2c_master_recv(rx->c, keybuf, sizeof(keybuf)); 405 ret = i2c_master_recv(rx->c, keybuf, sizeof(keybuf));
416 mutex_unlock(&ir->ir_lock); 406 mutex_unlock(&ir->ir_lock);
417 if (ret != sizeof(keybuf)) { 407 if (ret != sizeof(keybuf)) {
418 zilog_error("i2c_master_recv failed with %d -- " 408 dev_err(ir->l.dev, "i2c_master_recv failed with %d -- "
419 "keeping last read buffer\n", ret); 409 "keeping last read buffer\n", ret);
420 } else { 410 } else {
421 rx->b[0] = keybuf[3]; 411 rx->b[0] = keybuf[3];
422 rx->b[1] = keybuf[4]; 412 rx->b[1] = keybuf[4];
423 rx->b[2] = keybuf[5]; 413 rx->b[2] = keybuf[5];
424 dprintk("key (0x%02x/0x%02x)\n", rx->b[0], rx->b[1]); 414 dev_dbg(ir->l.dev, "key (0x%02x/0x%02x)\n",
415 rx->b[0], rx->b[1]);
425 } 416 }
426 417
427 /* key pressed ? */ 418 /* key pressed ? */
@@ -472,7 +463,7 @@ static int lirc_thread(void *arg)
472 struct IR *ir = arg; 463 struct IR *ir = arg;
473 struct lirc_buffer *rbuf = ir->l.rbuf; 464 struct lirc_buffer *rbuf = ir->l.rbuf;
474 465
475 dprintk("poll thread started\n"); 466 dev_dbg(ir->l.dev, "poll thread started\n");
476 467
477 while (!kthread_should_stop()) { 468 while (!kthread_should_stop()) {
478 set_current_state(TASK_INTERRUPTIBLE); 469 set_current_state(TASK_INTERRUPTIBLE);
@@ -500,7 +491,7 @@ static int lirc_thread(void *arg)
500 wake_up_interruptible(&rbuf->wait_poll); 491 wake_up_interruptible(&rbuf->wait_poll);
501 } 492 }
502 493
503 dprintk("poll thread ended\n"); 494 dev_dbg(ir->l.dev, "poll thread ended\n");
504 return 0; 495 return 0;
505} 496}
506 497
@@ -644,7 +635,7 @@ static int get_key_data(unsigned char *buf,
644 return -EPROTO; 635 return -EPROTO;
645 636
646corrupt: 637corrupt:
647 zilog_error("firmware is corrupt\n"); 638 pr_err("firmware is corrupt\n");
648 return -EFAULT; 639 return -EFAULT;
649} 640}
650 641
@@ -662,10 +653,11 @@ static int send_data_block(struct IR_tx *tx, unsigned char *data_block)
662 buf[0] = (unsigned char)(i + 1); 653 buf[0] = (unsigned char)(i + 1);
663 for (j = 0; j < tosend; ++j) 654 for (j = 0; j < tosend; ++j)
664 buf[1 + j] = data_block[i + j]; 655 buf[1 + j] = data_block[i + j];
665 dprintk("%*ph", 5, buf); 656 dev_dbg(tx->ir->l.dev, "%*ph", 5, buf);
666 ret = i2c_master_send(tx->c, buf, tosend + 1); 657 ret = i2c_master_send(tx->c, buf, tosend + 1);
667 if (ret != tosend + 1) { 658 if (ret != tosend + 1) {
668 zilog_error("i2c_master_send failed with %d\n", ret); 659 dev_err(tx->ir->l.dev, "i2c_master_send failed with %d\n",
660 ret);
669 return ret < 0 ? ret : -EFAULT; 661 return ret < 0 ? ret : -EFAULT;
670 } 662 }
671 i += tosend; 663 i += tosend;
@@ -689,7 +681,7 @@ static int send_boot_data(struct IR_tx *tx)
689 buf[1] = 0x20; 681 buf[1] = 0x20;
690 ret = i2c_master_send(tx->c, buf, 2); 682 ret = i2c_master_send(tx->c, buf, 2);
691 if (ret != 2) { 683 if (ret != 2) {
692 zilog_error("i2c_master_send failed with %d\n", ret); 684 dev_err(tx->ir->l.dev, "i2c_master_send failed with %d\n", ret);
693 return ret < 0 ? ret : -EFAULT; 685 return ret < 0 ? ret : -EFAULT;
694 } 686 }
695 687
@@ -706,21 +698,22 @@ static int send_boot_data(struct IR_tx *tx)
706 } 698 }
707 699
708 if (ret != 1) { 700 if (ret != 1) {
709 zilog_error("i2c_master_send failed with %d\n", ret); 701 dev_err(tx->ir->l.dev, "i2c_master_send failed with %d\n", ret);
710 return ret < 0 ? ret : -EFAULT; 702 return ret < 0 ? ret : -EFAULT;
711 } 703 }
712 704
713 /* Here comes the firmware version... (hopefully) */ 705 /* Here comes the firmware version... (hopefully) */
714 ret = i2c_master_recv(tx->c, buf, 4); 706 ret = i2c_master_recv(tx->c, buf, 4);
715 if (ret != 4) { 707 if (ret != 4) {
716 zilog_error("i2c_master_recv failed with %d\n", ret); 708 dev_err(tx->ir->l.dev, "i2c_master_recv failed with %d\n", ret);
717 return 0; 709 return 0;
718 } 710 }
719 if ((buf[0] != 0x80) && (buf[0] != 0xa0)) { 711 if ((buf[0] != 0x80) && (buf[0] != 0xa0)) {
720 zilog_error("unexpected IR TX init response: %02x\n", buf[0]); 712 dev_err(tx->ir->l.dev, "unexpected IR TX init response: %02x\n",
713 buf[0]);
721 return 0; 714 return 0;
722 } 715 }
723 zilog_notify("Zilog/Hauppauge IR blaster firmware version " 716 dev_notice(tx->ir->l.dev, "Zilog/Hauppauge IR blaster firmware version "
724 "%d.%d.%d loaded\n", buf[1], buf[2], buf[3]); 717 "%d.%d.%d loaded\n", buf[1], buf[2], buf[3]);
725 718
726 return 0; 719 return 0;
@@ -736,7 +729,7 @@ static void fw_unload_locked(void)
736 729
737 vfree(tx_data); 730 vfree(tx_data);
738 tx_data = NULL; 731 tx_data = NULL;
739 dprintk("successfully unloaded IR blaster firmware\n"); 732 pr_debug("successfully unloaded IR blaster firmware\n");
740 } 733 }
741} 734}
742 735
@@ -766,17 +759,16 @@ static int fw_load(struct IR_tx *tx)
766 /* Request codeset data file */ 759 /* Request codeset data file */
767 ret = request_firmware(&fw_entry, "haup-ir-blaster.bin", tx->ir->l.dev); 760 ret = request_firmware(&fw_entry, "haup-ir-blaster.bin", tx->ir->l.dev);
768 if (ret != 0) { 761 if (ret != 0) {
769 zilog_error("firmware haup-ir-blaster.bin not available (%d)\n", 762 dev_err(tx->ir->l.dev, "firmware haup-ir-blaster.bin not available (%d)\n",
770 ret); 763 ret);
771 ret = ret < 0 ? ret : -EFAULT; 764 ret = ret < 0 ? ret : -EFAULT;
772 goto out; 765 goto out;
773 } 766 }
774 dprintk("firmware of size %zu loaded\n", fw_entry->size); 767 dev_dbg(tx->ir->l.dev, "firmware of size %zu loaded\n", fw_entry->size);
775 768
776 /* Parse the file */ 769 /* Parse the file */
777 tx_data = vmalloc(sizeof(*tx_data)); 770 tx_data = vmalloc(sizeof(*tx_data));
778 if (tx_data == NULL) { 771 if (tx_data == NULL) {
779 zilog_error("out of memory\n");
780 release_firmware(fw_entry); 772 release_firmware(fw_entry);
781 ret = -ENOMEM; 773 ret = -ENOMEM;
782 goto out; 774 goto out;
@@ -786,7 +778,6 @@ static int fw_load(struct IR_tx *tx)
786 /* Copy the data so hotplug doesn't get confused and timeout */ 778 /* Copy the data so hotplug doesn't get confused and timeout */
787 tx_data->datap = vmalloc(fw_entry->size); 779 tx_data->datap = vmalloc(fw_entry->size);
788 if (tx_data->datap == NULL) { 780 if (tx_data->datap == NULL) {
789 zilog_error("out of memory\n");
790 release_firmware(fw_entry); 781 release_firmware(fw_entry);
791 vfree(tx_data); 782 vfree(tx_data);
792 ret = -ENOMEM; 783 ret = -ENOMEM;
@@ -801,7 +792,7 @@ static int fw_load(struct IR_tx *tx)
801 if (!read_uint8(&data, tx_data->endp, &version)) 792 if (!read_uint8(&data, tx_data->endp, &version))
802 goto corrupt; 793 goto corrupt;
803 if (version != 1) { 794 if (version != 1) {
804 zilog_error("unsupported code set file version (%u, expected" 795 dev_err(tx->ir->l.dev, "unsupported code set file version (%u, expected"
805 "1) -- please upgrade to a newer driver", 796 "1) -- please upgrade to a newer driver",
806 version); 797 version);
807 fw_unload_locked(); 798 fw_unload_locked();
@@ -818,7 +809,8 @@ static int fw_load(struct IR_tx *tx)
818 &tx_data->num_code_sets)) 809 &tx_data->num_code_sets))
819 goto corrupt; 810 goto corrupt;
820 811
821 dprintk("%u IR blaster codesets loaded\n", tx_data->num_code_sets); 812 dev_dbg(tx->ir->l.dev, "%u IR blaster codesets loaded\n",
813 tx_data->num_code_sets);
822 814
823 tx_data->code_sets = vmalloc( 815 tx_data->code_sets = vmalloc(
824 tx_data->num_code_sets * sizeof(char *)); 816 tx_data->num_code_sets * sizeof(char *));
@@ -882,7 +874,7 @@ static int fw_load(struct IR_tx *tx)
882 goto out; 874 goto out;
883 875
884corrupt: 876corrupt:
885 zilog_error("firmware is corrupt\n"); 877 dev_err(tx->ir->l.dev, "firmware is corrupt\n");
886 fw_unload_locked(); 878 fw_unload_locked();
887 ret = -EFAULT; 879 ret = -EFAULT;
888 880
@@ -902,9 +894,9 @@ static ssize_t read(struct file *filep, char __user *outbuf, size_t n,
902 unsigned int m; 894 unsigned int m;
903 DECLARE_WAITQUEUE(wait, current); 895 DECLARE_WAITQUEUE(wait, current);
904 896
905 dprintk("read called\n"); 897 dev_dbg(ir->l.dev, "read called\n");
906 if (n % rbuf->chunk_size) { 898 if (n % rbuf->chunk_size) {
907 dprintk("read result = -EINVAL\n"); 899 dev_dbg(ir->l.dev, "read result = -EINVAL\n");
908 return -EINVAL; 900 return -EINVAL;
909 } 901 }
910 902
@@ -948,7 +940,7 @@ static ssize_t read(struct file *filep, char __user *outbuf, size_t n,
948 unsigned char buf[MAX_XFER_SIZE]; 940 unsigned char buf[MAX_XFER_SIZE];
949 941
950 if (rbuf->chunk_size > sizeof(buf)) { 942 if (rbuf->chunk_size > sizeof(buf)) {
951 zilog_error("chunk_size is too big (%d)!\n", 943 dev_err(ir->l.dev, "chunk_size is too big (%d)!\n",
952 rbuf->chunk_size); 944 rbuf->chunk_size);
953 ret = -EINVAL; 945 ret = -EINVAL;
954 break; 946 break;
@@ -962,7 +954,7 @@ static ssize_t read(struct file *filep, char __user *outbuf, size_t n,
962 retries++; 954 retries++;
963 } 955 }
964 if (retries >= 5) { 956 if (retries >= 5) {
965 zilog_error("Buffer read failed!\n"); 957 dev_err(ir->l.dev, "Buffer read failed!\n");
966 ret = -EIO; 958 ret = -EIO;
967 } 959 }
968 } 960 }
@@ -972,7 +964,8 @@ static ssize_t read(struct file *filep, char __user *outbuf, size_t n,
972 put_ir_rx(rx, false); 964 put_ir_rx(rx, false);
973 set_current_state(TASK_RUNNING); 965 set_current_state(TASK_RUNNING);
974 966
975 dprintk("read result = %d (%s)\n", ret, ret ? "Error" : "OK"); 967 dev_dbg(ir->l.dev, "read result = %d (%s)\n",
968 ret, ret ? "Error" : "OK");
976 969
977 return ret ? ret : written; 970 return ret ? ret : written;
978} 971}
@@ -988,7 +981,7 @@ static int send_code(struct IR_tx *tx, unsigned int code, unsigned int key)
988 ret = get_key_data(data_block, code, key); 981 ret = get_key_data(data_block, code, key);
989 982
990 if (ret == -EPROTO) { 983 if (ret == -EPROTO) {
991 zilog_error("failed to get data for code %u, key %u -- check " 984 dev_err(tx->ir->l.dev, "failed to get data for code %u, key %u -- check "
992 "lircd.conf entries\n", code, key); 985 "lircd.conf entries\n", code, key);
993 return ret; 986 return ret;
994 } else if (ret != 0) 987 } else if (ret != 0)
@@ -1004,7 +997,7 @@ static int send_code(struct IR_tx *tx, unsigned int code, unsigned int key)
1004 buf[1] = 0x40; 997 buf[1] = 0x40;
1005 ret = i2c_master_send(tx->c, buf, 2); 998 ret = i2c_master_send(tx->c, buf, 2);
1006 if (ret != 2) { 999 if (ret != 2) {
1007 zilog_error("i2c_master_send failed with %d\n", ret); 1000 dev_err(tx->ir->l.dev, "i2c_master_send failed with %d\n", ret);
1008 return ret < 0 ? ret : -EFAULT; 1001 return ret < 0 ? ret : -EFAULT;
1009 } 1002 }
1010 1003
@@ -1017,18 +1010,18 @@ static int send_code(struct IR_tx *tx, unsigned int code, unsigned int key)
1017 } 1010 }
1018 1011
1019 if (ret != 1) { 1012 if (ret != 1) {
1020 zilog_error("i2c_master_send failed with %d\n", ret); 1013 dev_err(tx->ir->l.dev, "i2c_master_send failed with %d\n", ret);
1021 return ret < 0 ? ret : -EFAULT; 1014 return ret < 0 ? ret : -EFAULT;
1022 } 1015 }
1023 1016
1024 /* Send finished download? */ 1017 /* Send finished download? */
1025 ret = i2c_master_recv(tx->c, buf, 1); 1018 ret = i2c_master_recv(tx->c, buf, 1);
1026 if (ret != 1) { 1019 if (ret != 1) {
1027 zilog_error("i2c_master_recv failed with %d\n", ret); 1020 dev_err(tx->ir->l.dev, "i2c_master_recv failed with %d\n", ret);
1028 return ret < 0 ? ret : -EFAULT; 1021 return ret < 0 ? ret : -EFAULT;
1029 } 1022 }
1030 if (buf[0] != 0xA0) { 1023 if (buf[0] != 0xA0) {
1031 zilog_error("unexpected IR TX response #1: %02x\n", 1024 dev_err(tx->ir->l.dev, "unexpected IR TX response #1: %02x\n",
1032 buf[0]); 1025 buf[0]);
1033 return -EFAULT; 1026 return -EFAULT;
1034 } 1027 }
@@ -1038,7 +1031,7 @@ static int send_code(struct IR_tx *tx, unsigned int code, unsigned int key)
1038 buf[1] = 0x80; 1031 buf[1] = 0x80;
1039 ret = i2c_master_send(tx->c, buf, 2); 1032 ret = i2c_master_send(tx->c, buf, 2);
1040 if (ret != 2) { 1033 if (ret != 2) {
1041 zilog_error("i2c_master_send failed with %d\n", ret); 1034 dev_err(tx->ir->l.dev, "i2c_master_send failed with %d\n", ret);
1042 return ret < 0 ? ret : -EFAULT; 1035 return ret < 0 ? ret : -EFAULT;
1043 } 1036 }
1044 1037
@@ -1048,7 +1041,7 @@ static int send_code(struct IR_tx *tx, unsigned int code, unsigned int key)
1048 * going to skip this whole mess and say we're done on the HD PVR 1041 * going to skip this whole mess and say we're done on the HD PVR
1049 */ 1042 */
1050 if (!tx->post_tx_ready_poll) { 1043 if (!tx->post_tx_ready_poll) {
1051 dprintk("sent code %u, key %u\n", code, key); 1044 dev_dbg(tx->ir->l.dev, "sent code %u, key %u\n", code, key);
1052 return 0; 1045 return 0;
1053 } 1046 }
1054 1047
@@ -1064,11 +1057,11 @@ static int send_code(struct IR_tx *tx, unsigned int code, unsigned int key)
1064 ret = i2c_master_send(tx->c, buf, 1); 1057 ret = i2c_master_send(tx->c, buf, 1);
1065 if (ret == 1) 1058 if (ret == 1)
1066 break; 1059 break;
1067 dprintk("NAK expected: i2c_master_send " 1060 dev_dbg(tx->ir->l.dev, "NAK expected: i2c_master_send "
1068 "failed with %d (try %d)\n", ret, i+1); 1061 "failed with %d (try %d)\n", ret, i+1);
1069 } 1062 }
1070 if (ret != 1) { 1063 if (ret != 1) {
1071 zilog_error("IR TX chip never got ready: last i2c_master_send " 1064 dev_err(tx->ir->l.dev, "IR TX chip never got ready: last i2c_master_send "
1072 "failed with %d\n", ret); 1065 "failed with %d\n", ret);
1073 return ret < 0 ? ret : -EFAULT; 1066 return ret < 0 ? ret : -EFAULT;
1074 } 1067 }
@@ -1076,16 +1069,17 @@ static int send_code(struct IR_tx *tx, unsigned int code, unsigned int key)
1076 /* Seems to be an 'ok' response */ 1069 /* Seems to be an 'ok' response */
1077 i = i2c_master_recv(tx->c, buf, 1); 1070 i = i2c_master_recv(tx->c, buf, 1);
1078 if (i != 1) { 1071 if (i != 1) {
1079 zilog_error("i2c_master_recv failed with %d\n", ret); 1072 dev_err(tx->ir->l.dev, "i2c_master_recv failed with %d\n", ret);
1080 return -EFAULT; 1073 return -EFAULT;
1081 } 1074 }
1082 if (buf[0] != 0x80) { 1075 if (buf[0] != 0x80) {
1083 zilog_error("unexpected IR TX response #2: %02x\n", buf[0]); 1076 dev_err(tx->ir->l.dev, "unexpected IR TX response #2: %02x\n",
1077 buf[0]);
1084 return -EFAULT; 1078 return -EFAULT;
1085 } 1079 }
1086 1080
1087 /* Oh good, it worked */ 1081 /* Oh good, it worked */
1088 dprintk("sent code %u, key %u\n", code, key); 1082 dev_dbg(tx->ir->l.dev, "sent code %u, key %u\n", code, key);
1089 return 0; 1083 return 0;
1090} 1084}
1091 1085
@@ -1171,11 +1165,11 @@ static ssize_t write(struct file *filep, const char __user *buf, size_t n,
1171 */ 1165 */
1172 if (ret != 0) { 1166 if (ret != 0) {
1173 /* Looks like the chip crashed, reset it */ 1167 /* Looks like the chip crashed, reset it */
1174 zilog_error("sending to the IR transmitter chip " 1168 dev_err(tx->ir->l.dev, "sending to the IR transmitter chip "
1175 "failed, trying reset\n"); 1169 "failed, trying reset\n");
1176 1170
1177 if (failures >= 3) { 1171 if (failures >= 3) {
1178 zilog_error("unable to send to the IR chip " 1172 dev_err(tx->ir->l.dev, "unable to send to the IR chip "
1179 "after 3 resets, giving up\n"); 1173 "after 3 resets, giving up\n");
1180 mutex_unlock(&ir->ir_lock); 1174 mutex_unlock(&ir->ir_lock);
1181 mutex_unlock(&tx->client_lock); 1175 mutex_unlock(&tx->client_lock);
@@ -1210,7 +1204,7 @@ static unsigned int poll(struct file *filep, poll_table *wait)
1210 struct lirc_buffer *rbuf = ir->l.rbuf; 1204 struct lirc_buffer *rbuf = ir->l.rbuf;
1211 unsigned int ret; 1205 unsigned int ret;
1212 1206
1213 dprintk("poll called\n"); 1207 dev_dbg(ir->l.dev, "poll called\n");
1214 1208
1215 rx = get_ir_rx(ir); 1209 rx = get_ir_rx(ir);
1216 if (rx == NULL) { 1210 if (rx == NULL) {
@@ -1218,7 +1212,7 @@ static unsigned int poll(struct file *filep, poll_table *wait)
1218 * Revisit this, if our poll function ever reports writeable 1212 * Revisit this, if our poll function ever reports writeable
1219 * status for Tx 1213 * status for Tx
1220 */ 1214 */
1221 dprintk("poll result = POLLERR\n"); 1215 dev_dbg(ir->l.dev, "poll result = POLLERR\n");
1222 return POLLERR; 1216 return POLLERR;
1223 } 1217 }
1224 1218
@@ -1231,7 +1225,8 @@ static unsigned int poll(struct file *filep, poll_table *wait)
1231 /* Indicate what ops could happen immediately without blocking */ 1225 /* Indicate what ops could happen immediately without blocking */
1232 ret = lirc_buffer_empty(rbuf) ? 0 : (POLLIN|POLLRDNORM); 1226 ret = lirc_buffer_empty(rbuf) ? 0 : (POLLIN|POLLRDNORM);
1233 1227
1234 dprintk("poll result = %s\n", ret ? "POLLIN|POLLRDNORM" : "none"); 1228 dev_dbg(ir->l.dev, "poll result = %s\n",
1229 ret ? "POLLIN|POLLRDNORM" : "none");
1235 return ret; 1230 return ret;
1236} 1231}
1237 1232
@@ -1338,7 +1333,7 @@ static int close(struct inode *node, struct file *filep)
1338 struct IR *ir = filep->private_data; 1333 struct IR *ir = filep->private_data;
1339 1334
1340 if (ir == NULL) { 1335 if (ir == NULL) {
1341 zilog_error("close: no private_data attached to the file!\n"); 1336 dev_err(ir->l.dev, "close: no private_data attached to the file!\n");
1342 return -ENODEV; 1337 return -ENODEV;
1343 } 1338 }
1344 1339
@@ -1450,7 +1445,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
1450 int ret; 1445 int ret;
1451 bool tx_probe = false; 1446 bool tx_probe = false;
1452 1447
1453 dprintk("%s: %s on i2c-%d (%s), client addr=0x%02x\n", 1448 dev_dbg(&client->dev, "%s: %s on i2c-%d (%s), client addr=0x%02x\n",
1454 __func__, id->name, adap->nr, adap->name, client->addr); 1449 __func__, id->name, adap->nr, adap->name, client->addr);
1455 1450
1456 /* 1451 /*
@@ -1463,7 +1458,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
1463 else if (tx_only) /* module option */ 1458 else if (tx_only) /* module option */
1464 return -ENXIO; 1459 return -ENXIO;
1465 1460
1466 zilog_info("probing IR %s on %s (i2c-%d)\n", 1461 pr_info("probing IR %s on %s (i2c-%d)\n",
1467 tx_probe ? "Tx" : "Rx", adap->name, adap->nr); 1462 tx_probe ? "Tx" : "Rx", adap->name, adap->nr);
1468 1463
1469 mutex_lock(&ir_devices_lock); 1464 mutex_lock(&ir_devices_lock);
@@ -1545,7 +1540,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
1545 1540
1546 /* Proceed only if the Rx client is also ready or not needed */ 1541 /* Proceed only if the Rx client is also ready or not needed */
1547 if (rx == NULL && !tx_only) { 1542 if (rx == NULL && !tx_only) {
1548 zilog_info("probe of IR Tx on %s (i2c-%d) done. Waiting" 1543 dev_info(tx->ir->l.dev, "probe of IR Tx on %s (i2c-%d) done. Waiting"
1549 " on IR Rx.\n", adap->name, adap->nr); 1544 " on IR Rx.\n", adap->name, adap->nr);
1550 goto out_ok; 1545 goto out_ok;
1551 } 1546 }
@@ -1584,7 +1579,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
1584 "zilog-rx-i2c-%d", adap->nr); 1579 "zilog-rx-i2c-%d", adap->nr);
1585 if (IS_ERR(rx->task)) { 1580 if (IS_ERR(rx->task)) {
1586 ret = PTR_ERR(rx->task); 1581 ret = PTR_ERR(rx->task);
1587 zilog_error("%s: could not start IR Rx polling thread" 1582 dev_err(tx->ir->l.dev, "%s: could not start IR Rx polling thread"
1588 "\n", __func__); 1583 "\n", __func__);
1589 /* Failed kthread, so put back the ir ref */ 1584 /* Failed kthread, so put back the ir ref */
1590 put_ir_device(ir, true); 1585 put_ir_device(ir, true);
@@ -1597,7 +1592,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
1597 1592
1598 /* Proceed only if the Tx client is also ready */ 1593 /* Proceed only if the Tx client is also ready */
1599 if (tx == NULL) { 1594 if (tx == NULL) {
1600 zilog_info("probe of IR Rx on %s (i2c-%d) done. Waiting" 1595 pr_info("probe of IR Rx on %s (i2c-%d) done. Waiting"
1601 " on IR Tx.\n", adap->name, adap->nr); 1596 " on IR Tx.\n", adap->name, adap->nr);
1602 goto out_ok; 1597 goto out_ok;
1603 } 1598 }
@@ -1607,12 +1602,12 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
1607 ir->l.minor = minor; /* module option: user requested minor number */ 1602 ir->l.minor = minor; /* module option: user requested minor number */
1608 ir->l.minor = lirc_register_driver(&ir->l); 1603 ir->l.minor = lirc_register_driver(&ir->l);
1609 if (ir->l.minor < 0 || ir->l.minor >= MAX_IRCTL_DEVICES) { 1604 if (ir->l.minor < 0 || ir->l.minor >= MAX_IRCTL_DEVICES) {
1610 zilog_error("%s: \"minor\" must be between 0 and %d (%d)!\n", 1605 dev_err(tx->ir->l.dev, "%s: \"minor\" must be between 0 and %d (%d)!\n",
1611 __func__, MAX_IRCTL_DEVICES-1, ir->l.minor); 1606 __func__, MAX_IRCTL_DEVICES-1, ir->l.minor);
1612 ret = -EBADRQC; 1607 ret = -EBADRQC;
1613 goto out_put_xx; 1608 goto out_put_xx;
1614 } 1609 }
1615 zilog_info("IR unit on %s (i2c-%d) registered as lirc%d and ready\n", 1610 dev_info(ir->l.dev, "IR unit on %s (i2c-%d) registered as lirc%d and ready\n",
1616 adap->name, adap->nr, ir->l.minor); 1611 adap->name, adap->nr, ir->l.minor);
1617 1612
1618out_ok: 1613out_ok:
@@ -1621,7 +1616,7 @@ out_ok:
1621 if (tx != NULL) 1616 if (tx != NULL)
1622 put_ir_tx(tx, true); 1617 put_ir_tx(tx, true);
1623 put_ir_device(ir, true); 1618 put_ir_device(ir, true);
1624 zilog_info("probe of IR %s on %s (i2c-%d) done\n", 1619 dev_info(ir->l.dev, "probe of IR %s on %s (i2c-%d) done\n",
1625 tx_probe ? "Tx" : "Rx", adap->name, adap->nr); 1620 tx_probe ? "Tx" : "Rx", adap->name, adap->nr);
1626 mutex_unlock(&ir_devices_lock); 1621 mutex_unlock(&ir_devices_lock);
1627 return 0; 1622 return 0;
@@ -1634,7 +1629,7 @@ out_put_xx:
1634out_put_ir: 1629out_put_ir:
1635 put_ir_device(ir, true); 1630 put_ir_device(ir, true);
1636out_no_ir: 1631out_no_ir:
1637 zilog_error("%s: probing IR %s on %s (i2c-%d) failed with %d\n", 1632 dev_err(&client->dev, "%s: probing IR %s on %s (i2c-%d) failed with %d\n",
1638 __func__, tx_probe ? "Tx" : "Rx", adap->name, adap->nr, 1633 __func__, tx_probe ? "Tx" : "Rx", adap->name, adap->nr,
1639 ret); 1634 ret);
1640 mutex_unlock(&ir_devices_lock); 1635 mutex_unlock(&ir_devices_lock);
@@ -1645,7 +1640,7 @@ static int __init zilog_init(void)
1645{ 1640{
1646 int ret; 1641 int ret;
1647 1642
1648 zilog_notify("Zilog/Hauppauge IR driver initializing\n"); 1643 pr_notice("Zilog/Hauppauge IR driver initializing\n");
1649 1644
1650 mutex_init(&tx_data_lock); 1645 mutex_init(&tx_data_lock);
1651 1646
@@ -1653,9 +1648,9 @@ static int __init zilog_init(void)
1653 1648
1654 ret = i2c_add_driver(&driver); 1649 ret = i2c_add_driver(&driver);
1655 if (ret) 1650 if (ret)
1656 zilog_error("initialization failed\n"); 1651 pr_err("initialization failed\n");
1657 else 1652 else
1658 zilog_notify("initialization complete\n"); 1653 pr_notice("initialization complete\n");
1659 1654
1660 return ret; 1655 return ret;
1661} 1656}
@@ -1665,7 +1660,7 @@ static void __exit zilog_exit(void)
1665 i2c_del_driver(&driver); 1660 i2c_del_driver(&driver);
1666 /* if loaded */ 1661 /* if loaded */
1667 fw_unload(); 1662 fw_unload();
1668 zilog_notify("Zilog/Hauppauge IR driver unloaded\n"); 1663 pr_notice("Zilog/Hauppauge IR driver unloaded\n");
1669} 1664}
1670 1665
1671module_init(zilog_init); 1666module_init(zilog_init);
diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
index 96b14b326e09..cc1dfadd91eb 100644
--- a/drivers/staging/media/omap4iss/iss.c
+++ b/drivers/staging/media/omap4iss/iss.c
@@ -1357,10 +1357,8 @@ static int iss_probe(struct platform_device *pdev)
1357 return -EINVAL; 1357 return -EINVAL;
1358 1358
1359 iss = devm_kzalloc(&pdev->dev, sizeof(*iss), GFP_KERNEL); 1359 iss = devm_kzalloc(&pdev->dev, sizeof(*iss), GFP_KERNEL);
1360 if (!iss) { 1360 if (!iss)
1361 dev_err(&pdev->dev, "Could not allocate memory\n");
1362 return -ENOMEM; 1361 return -ENOMEM;
1363 }
1364 1362
1365 mutex_init(&iss->iss_mutex); 1363 mutex_init(&iss->iss_mutex);
1366 1364
diff --git a/drivers/staging/media/omap4iss/iss_csi2.c b/drivers/staging/media/omap4iss/iss_csi2.c
index 7dbf68cd3566..21971c675b8c 100644
--- a/drivers/staging/media/omap4iss/iss_csi2.c
+++ b/drivers/staging/media/omap4iss/iss_csi2.c
@@ -1231,7 +1231,7 @@ static int csi2_init_entities(struct iss_csi2_device *csi2, const char *subname)
1231 1231
1232 v4l2_subdev_init(sd, &csi2_ops); 1232 v4l2_subdev_init(sd, &csi2_ops);
1233 sd->internal_ops = &csi2_internal_ops; 1233 sd->internal_ops = &csi2_internal_ops;
1234 sprintf(name, "CSI2%s", subname); 1234 snprintf(name, sizeof(name), "CSI2%s", subname);
1235 snprintf(sd->name, sizeof(sd->name), "OMAP4 ISS %s", name); 1235 snprintf(sd->name, sizeof(sd->name), "OMAP4 ISS %s", name);
1236 1236
1237 sd->grp_id = 1 << 16; /* group ID for iss subdevs */ 1237 sd->grp_id = 1 << 16; /* group ID for iss subdevs */
diff --git a/drivers/staging/octeon-usb/octeon-hcd.c b/drivers/staging/octeon-usb/octeon-hcd.c
index 2f8eaf768bf3..6b8b108c4e6d 100644
--- a/drivers/staging/octeon-usb/octeon-hcd.c
+++ b/drivers/staging/octeon-usb/octeon-hcd.c
@@ -456,6 +456,16 @@ struct octeon_temp_buffer {
456 u8 data[0]; 456 u8 data[0];
457}; 457};
458 458
459static inline struct octeon_hcd *cvmx_usb_to_octeon(struct cvmx_usb_state *p)
460{
461 return container_of(p, struct octeon_hcd, usb);
462}
463
464static inline struct usb_hcd *octeon_to_hcd(struct octeon_hcd *p)
465{
466 return container_of((void *)p, struct usb_hcd, hcd_priv);
467}
468
459/** 469/**
460 * octeon_alloc_temp_buffer - allocate a temporary buffer for USB transfer 470 * octeon_alloc_temp_buffer - allocate a temporary buffer for USB transfer
461 * (if needed) 471 * (if needed)
@@ -640,8 +650,7 @@ static inline int __cvmx_usb_get_data_pid(struct cvmx_usb_pipe *pipe)
640{ 650{
641 if (pipe->pid_toggle) 651 if (pipe->pid_toggle)
642 return 2; /* Data1 */ 652 return 2; /* Data1 */
643 else 653 return 0; /* Data0 */
644 return 0; /* Data0 */
645} 654}
646 655
647/** 656/**
@@ -744,7 +753,7 @@ static int cvmx_usb_initialize(struct cvmx_usb_state *usb,
744 * such that USB is as close as possible to 125Mhz 753 * such that USB is as close as possible to 125Mhz
745 */ 754 */
746 { 755 {
747 int divisor = (octeon_get_clock_rate()+125000000-1)/125000000; 756 int divisor = DIV_ROUND_UP(octeon_get_clock_rate(), 125000000);
748 /* Lower than 4 doesn't seem to work properly */ 757 /* Lower than 4 doesn't seem to work properly */
749 if (divisor < 4) 758 if (divisor < 4)
750 divisor = 4; 759 divisor = 4;
@@ -1328,7 +1337,8 @@ static void __cvmx_usb_poll_rx_fifo(struct cvmx_usb_state *usb)
1328 1337
1329 /* Loop writing the FIFO data for this packet into memory */ 1338 /* Loop writing the FIFO data for this packet into memory */
1330 while (bytes > 0) { 1339 while (bytes > 0) {
1331 *ptr++ = __cvmx_usb_read_csr32(usb, USB_FIFO_ADDRESS(channel, usb->index)); 1340 *ptr++ = __cvmx_usb_read_csr32(usb,
1341 USB_FIFO_ADDRESS(channel, usb->index));
1332 bytes -= 4; 1342 bytes -= 4;
1333 } 1343 }
1334 CVMX_SYNCW; 1344 CVMX_SYNCW;
@@ -1479,7 +1489,8 @@ static void __cvmx_usb_fill_tx_fifo(struct cvmx_usb_state *usb, int channel)
1479 fifo = &usb->nonperiodic; 1489 fifo = &usb->nonperiodic;
1480 1490
1481 fifo->entry[fifo->head].channel = channel; 1491 fifo->entry[fifo->head].channel = channel;
1482 fifo->entry[fifo->head].address = __cvmx_usb_read_csr64(usb, CVMX_USBNX_DMA0_OUTB_CHN0(usb->index) + channel*8); 1492 fifo->entry[fifo->head].address = __cvmx_usb_read_csr64(usb,
1493 CVMX_USBNX_DMA0_OUTB_CHN0(usb->index) + channel*8);
1483 fifo->entry[fifo->head].size = (usbc_hctsiz.s.xfersize+3)>>2; 1494 fifo->entry[fifo->head].size = (usbc_hctsiz.s.xfersize+3)>>2;
1484 fifo->head++; 1495 fifo->head++;
1485 if (fifo->head > MAX_CHANNELS) 1496 if (fifo->head > MAX_CHANNELS)
@@ -1501,6 +1512,9 @@ static void __cvmx_usb_start_channel_control(struct cvmx_usb_state *usb,
1501 int channel, 1512 int channel,
1502 struct cvmx_usb_pipe *pipe) 1513 struct cvmx_usb_pipe *pipe)
1503{ 1514{
1515 struct octeon_hcd *priv = cvmx_usb_to_octeon(usb);
1516 struct usb_hcd *hcd = octeon_to_hcd(priv);
1517 struct device *dev = hcd->self.controller;
1504 struct cvmx_usb_transaction *transaction = 1518 struct cvmx_usb_transaction *transaction =
1505 list_first_entry(&pipe->transactions, typeof(*transaction), 1519 list_first_entry(&pipe->transactions, typeof(*transaction),
1506 node); 1520 node);
@@ -1517,7 +1531,7 @@ static void __cvmx_usb_start_channel_control(struct cvmx_usb_state *usb,
1517 switch (transaction->stage) { 1531 switch (transaction->stage) {
1518 case CVMX_USB_STAGE_NON_CONTROL: 1532 case CVMX_USB_STAGE_NON_CONTROL:
1519 case CVMX_USB_STAGE_NON_CONTROL_SPLIT_COMPLETE: 1533 case CVMX_USB_STAGE_NON_CONTROL_SPLIT_COMPLETE:
1520 cvmx_dprintf("%s: ERROR - Non control stage\n", __func__); 1534 dev_err(dev, "%s: ERROR - Non control stage\n", __func__);
1521 break; 1535 break;
1522 case CVMX_USB_STAGE_SETUP: 1536 case CVMX_USB_STAGE_SETUP:
1523 usbc_hctsiz.s.pid = 3; /* Setup */ 1537 usbc_hctsiz.s.pid = 3; /* Setup */
@@ -1607,8 +1621,8 @@ static void __cvmx_usb_start_channel_control(struct cvmx_usb_state *usb,
1607 * Calculate the number of packets to transfer. If the length is zero 1621 * Calculate the number of packets to transfer. If the length is zero
1608 * we still need to transfer one packet 1622 * we still need to transfer one packet
1609 */ 1623 */
1610 packets_to_transfer = (bytes_to_transfer + pipe->max_packet - 1) / 1624 packets_to_transfer = DIV_ROUND_UP(bytes_to_transfer,
1611 pipe->max_packet; 1625 pipe->max_packet);
1612 if (packets_to_transfer == 0) 1626 if (packets_to_transfer == 0)
1613 packets_to_transfer = 1; 1627 packets_to_transfer = 1;
1614 else if ((packets_to_transfer > 1) && 1628 else if ((packets_to_transfer > 1) &&
@@ -1700,7 +1714,9 @@ static void __cvmx_usb_start_channel(struct cvmx_usb_state *usb,
1700 usbc_hcintmsk.s.stallmsk = 1; 1714 usbc_hcintmsk.s.stallmsk = 1;
1701 usbc_hcintmsk.s.xfercomplmsk = 1; 1715 usbc_hcintmsk.s.xfercomplmsk = 1;
1702 } 1716 }
1703 __cvmx_usb_write_csr32(usb, CVMX_USBCX_HCINTMSKX(channel, usb->index), usbc_hcintmsk.u32); 1717 __cvmx_usb_write_csr32(usb,
1718 CVMX_USBCX_HCINTMSKX(channel, usb->index),
1719 usbc_hcintmsk.u32);
1704 1720
1705 /* Enable the channel interrupt to propagate */ 1721 /* Enable the channel interrupt to propagate */
1706 usbc_haintmsk.u32 = __cvmx_usb_read_csr32(usb, 1722 usbc_haintmsk.u32 = __cvmx_usb_read_csr32(usb,
@@ -1853,8 +1869,7 @@ static void __cvmx_usb_start_channel(struct cvmx_usb_state *usb,
1853 * zero we still need to transfer one packet 1869 * zero we still need to transfer one packet
1854 */ 1870 */
1855 packets_to_transfer = 1871 packets_to_transfer =
1856 (bytes_to_transfer + pipe->max_packet - 1) / 1872 DIV_ROUND_UP(bytes_to_transfer, pipe->max_packet);
1857 pipe->max_packet;
1858 if (packets_to_transfer == 0) 1873 if (packets_to_transfer == 0)
1859 packets_to_transfer = 1; 1874 packets_to_transfer = 1;
1860 else if ((packets_to_transfer > 1) && 1875 else if ((packets_to_transfer > 1) &&
@@ -2110,16 +2125,6 @@ done:
2110 union cvmx_usbcx_gintmsk, sofmsk, need_sof); 2125 union cvmx_usbcx_gintmsk, sofmsk, need_sof);
2111} 2126}
2112 2127
2113static inline struct octeon_hcd *cvmx_usb_to_octeon(struct cvmx_usb_state *p)
2114{
2115 return container_of(p, struct octeon_hcd, usb);
2116}
2117
2118static inline struct usb_hcd *octeon_to_hcd(struct octeon_hcd *p)
2119{
2120 return container_of((void *)p, struct usb_hcd, hcd_priv);
2121}
2122
2123static void octeon_usb_urb_complete_callback(struct cvmx_usb_state *usb, 2128static void octeon_usb_urb_complete_callback(struct cvmx_usb_state *usb,
2124 enum cvmx_usb_complete status, 2129 enum cvmx_usb_complete status,
2125 struct cvmx_usb_pipe *pipe, 2130 struct cvmx_usb_pipe *pipe,
@@ -2583,6 +2588,9 @@ static int cvmx_usb_get_frame_number(struct cvmx_usb_state *usb)
2583 */ 2588 */
2584static int __cvmx_usb_poll_channel(struct cvmx_usb_state *usb, int channel) 2589static int __cvmx_usb_poll_channel(struct cvmx_usb_state *usb, int channel)
2585{ 2590{
2591 struct octeon_hcd *priv = cvmx_usb_to_octeon(usb);
2592 struct usb_hcd *hcd = octeon_to_hcd(priv);
2593 struct device *dev = hcd->self.controller;
2586 union cvmx_usbcx_hcintx usbc_hcint; 2594 union cvmx_usbcx_hcintx usbc_hcint;
2587 union cvmx_usbcx_hctsizx usbc_hctsiz; 2595 union cvmx_usbcx_hctsizx usbc_hctsiz;
2588 union cvmx_usbcx_hccharx usbc_hcchar; 2596 union cvmx_usbcx_hccharx usbc_hcchar;
@@ -2640,8 +2648,8 @@ static int __cvmx_usb_poll_channel(struct cvmx_usb_state *usb, int channel)
2640 * Channel halt isn't needed. 2648 * Channel halt isn't needed.
2641 */ 2649 */
2642 } else { 2650 } else {
2643 cvmx_dprintf("USB%d: Channel %d interrupt without halt\n", 2651 dev_err(dev, "USB%d: Channel %d interrupt without halt\n",
2644 usb->index, channel); 2652 usb->index, channel);
2645 return 0; 2653 return 0;
2646 } 2654 }
2647 } 2655 }
@@ -2881,9 +2889,11 @@ static int __cvmx_usb_poll_channel(struct cvmx_usb_state *usb, int channel)
2881 struct usb_ctrlrequest *header = 2889 struct usb_ctrlrequest *header =
2882 cvmx_phys_to_ptr(transaction->control_header); 2890 cvmx_phys_to_ptr(transaction->control_header);
2883 if (header->wLength) 2891 if (header->wLength)
2884 transaction->stage = CVMX_USB_STAGE_DATA; 2892 transaction->stage =
2893 CVMX_USB_STAGE_DATA;
2885 else 2894 else
2886 transaction->stage = CVMX_USB_STAGE_STATUS; 2895 transaction->stage =
2896 CVMX_USB_STAGE_STATUS;
2887 } 2897 }
2888 break; 2898 break;
2889 case CVMX_USB_STAGE_SETUP_SPLIT_COMPLETE: 2899 case CVMX_USB_STAGE_SETUP_SPLIT_COMPLETE:
@@ -2891,9 +2901,11 @@ static int __cvmx_usb_poll_channel(struct cvmx_usb_state *usb, int channel)
2891 struct usb_ctrlrequest *header = 2901 struct usb_ctrlrequest *header =
2892 cvmx_phys_to_ptr(transaction->control_header); 2902 cvmx_phys_to_ptr(transaction->control_header);
2893 if (header->wLength) 2903 if (header->wLength)
2894 transaction->stage = CVMX_USB_STAGE_DATA; 2904 transaction->stage =
2905 CVMX_USB_STAGE_DATA;
2895 else 2906 else
2896 transaction->stage = CVMX_USB_STAGE_STATUS; 2907 transaction->stage =
2908 CVMX_USB_STAGE_STATUS;
2897 } 2909 }
2898 break; 2910 break;
2899 case CVMX_USB_STAGE_DATA: 2911 case CVMX_USB_STAGE_DATA:
@@ -3015,7 +3027,8 @@ static int __cvmx_usb_poll_channel(struct cvmx_usb_state *usb, int channel)
3015 * is complete, the pipe sleeps until the next 3027 * is complete, the pipe sleeps until the next
3016 * schedule interval 3028 * schedule interval
3017 */ 3029 */
3018 if (pipe->transfer_dir == CVMX_USB_DIRECTION_OUT) { 3030 if (pipe->transfer_dir ==
3031 CVMX_USB_DIRECTION_OUT) {
3019 /* 3032 /*
3020 * If no space left or this wasn't a max 3033 * If no space left or this wasn't a max
3021 * size packet then this transfer is 3034 * size packet then this transfer is
diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
index b2b6c3cd2bed..fcbe836aa997 100644
--- a/drivers/staging/octeon/ethernet-rx.c
+++ b/drivers/staging/octeon/ethernet-rx.c
@@ -61,66 +61,7 @@
61 61
62#include <asm/octeon/cvmx-gmxx-defs.h> 62#include <asm/octeon/cvmx-gmxx-defs.h>
63 63
64struct cvm_napi_wrapper { 64static struct napi_struct cvm_oct_napi;
65 struct napi_struct napi;
66} ____cacheline_aligned_in_smp;
67
68static struct cvm_napi_wrapper cvm_oct_napi[NR_CPUS] __cacheline_aligned_in_smp;
69
70struct cvm_oct_core_state {
71 int baseline_cores;
72 /*
73 * The number of additional cores that could be processing
74 * input packets.
75 */
76 atomic_t available_cores;
77 cpumask_t cpu_state;
78} ____cacheline_aligned_in_smp;
79
80static struct cvm_oct_core_state core_state __cacheline_aligned_in_smp;
81
82static int cvm_irq_cpu;
83
84static void cvm_oct_enable_napi(void *_)
85{
86 int cpu = smp_processor_id();
87 napi_schedule(&cvm_oct_napi[cpu].napi);
88}
89
90static void cvm_oct_enable_one_cpu(void)
91{
92 int v;
93 int cpu;
94
95 /* Check to see if more CPUs are available for receive processing... */
96 v = atomic_sub_if_positive(1, &core_state.available_cores);
97 if (v < 0)
98 return;
99
100 /* ... if a CPU is available, Turn on NAPI polling for that CPU. */
101 for_each_online_cpu(cpu) {
102 if (!cpu_test_and_set(cpu, core_state.cpu_state)) {
103 v = smp_call_function_single(cpu, cvm_oct_enable_napi,
104 NULL, 0);
105 if (v)
106 panic("Can't enable NAPI.");
107 break;
108 }
109 }
110}
111
112static void cvm_oct_no_more_work(void)
113{
114 int cpu = smp_processor_id();
115
116 if (cpu == cvm_irq_cpu) {
117 enable_irq(OCTEON_IRQ_WORKQ0 + pow_receive_group);
118 return;
119 }
120
121 cpu_clear(cpu, core_state.cpu_state);
122 atomic_add(1, &core_state.available_cores);
123}
124 65
125/** 66/**
126 * cvm_oct_do_interrupt - interrupt handler. 67 * cvm_oct_do_interrupt - interrupt handler.
@@ -132,8 +73,7 @@ static irqreturn_t cvm_oct_do_interrupt(int cpl, void *dev_id)
132{ 73{
133 /* Disable the IRQ and start napi_poll. */ 74 /* Disable the IRQ and start napi_poll. */
134 disable_irq_nosync(OCTEON_IRQ_WORKQ0 + pow_receive_group); 75 disable_irq_nosync(OCTEON_IRQ_WORKQ0 + pow_receive_group);
135 cvm_irq_cpu = smp_processor_id(); 76 napi_schedule(&cvm_oct_napi);
136 cvm_oct_enable_napi(NULL);
137 77
138 return IRQ_HANDLED; 78 return IRQ_HANDLED;
139} 79}
@@ -186,13 +126,15 @@ static inline int cvm_oct_check_rcv_error(cvmx_wqe_t *work)
186 126
187 if (*ptr == 0xd5) { 127 if (*ptr == 0xd5) {
188 /* 128 /*
189 printk_ratelimited("Port %d received 0xd5 preamble\n", work->ipprt); 129 printk_ratelimited("Port %d received 0xd5 preamble\n",
130 work->ipprt);
190 */ 131 */
191 work->packet_ptr.s.addr += i + 1; 132 work->packet_ptr.s.addr += i + 1;
192 work->len -= i + 5; 133 work->len -= i + 5;
193 } else if ((*ptr & 0xf) == 0xd) { 134 } else if ((*ptr & 0xf) == 0xd) {
194 /* 135 /*
195 printk_ratelimited("Port %d received 0x?d preamble\n", work->ipprt); 136 printk_ratelimited("Port %d received 0x?d preamble\n",
137 work->ipprt);
196 */ 138 */
197 work->packet_ptr.s.addr += i; 139 work->packet_ptr.s.addr += i;
198 work->len -= i + 4; 140 work->len -= i + 4;
@@ -278,28 +220,15 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
278 cvmx_write_csr(CVMX_POW_WQ_INT, wq_int.u64); 220 cvmx_write_csr(CVMX_POW_WQ_INT, wq_int.u64);
279 break; 221 break;
280 } 222 }
281 pskb = (struct sk_buff **)(cvm_oct_get_buffer_ptr(work->packet_ptr) - sizeof(void *)); 223 pskb = (struct sk_buff **)(cvm_oct_get_buffer_ptr(work->packet_ptr) -
224 sizeof(void *));
282 prefetch(pskb); 225 prefetch(pskb);
283 226
284 if (USE_ASYNC_IOBDMA && rx_count < (budget - 1)) { 227 if (USE_ASYNC_IOBDMA && rx_count < (budget - 1)) {
285 cvmx_pow_work_request_async_nocheck(CVMX_SCR_SCRATCH, CVMX_POW_NO_WAIT); 228 cvmx_pow_work_request_async_nocheck(CVMX_SCR_SCRATCH,
229 CVMX_POW_NO_WAIT);
286 did_work_request = 1; 230 did_work_request = 1;
287 } 231 }
288
289 if (rx_count == 0) {
290 /*
291 * First time through, see if there is enough
292 * work waiting to merit waking another
293 * CPU.
294 */
295 union cvmx_pow_wq_int_cntx counts;
296 int backlog;
297 int cores_in_use = core_state.baseline_cores - atomic_read(&core_state.available_cores);
298 counts.u64 = cvmx_read_csr(CVMX_POW_WQ_INT_CNTX(pow_receive_group));
299 backlog = counts.s.iq_cnt + counts.s.ds_cnt;
300 if (backlog > budget * cores_in_use && napi != NULL)
301 cvm_oct_enable_one_cpu();
302 }
303 rx_count++; 232 rx_count++;
304 233
305 skb_in_hw = USE_SKBUFFS_IN_HW && work->word2.s.bufs == 1; 234 skb_in_hw = USE_SKBUFFS_IN_HW && work->word2.s.bufs == 1;
@@ -322,7 +251,8 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
322 * buffer. 251 * buffer.
323 */ 252 */
324 if (likely(skb_in_hw)) { 253 if (likely(skb_in_hw)) {
325 skb->data = skb->head + work->packet_ptr.s.addr - cvmx_ptr_to_phys(skb->head); 254 skb->data = skb->head + work->packet_ptr.s.addr -
255 cvmx_ptr_to_phys(skb->head);
326 prefetch(skb->data); 256 prefetch(skb->data);
327 skb->len = work->len; 257 skb->len = work->len;
328 skb_set_tail_pointer(skb, skb->len); 258 skb_set_tail_pointer(skb, skb->len);
@@ -359,7 +289,8 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
359 /* No packet buffers to free */ 289 /* No packet buffers to free */
360 } else { 290 } else {
361 int segments = work->word2.s.bufs; 291 int segments = work->word2.s.bufs;
362 union cvmx_buf_ptr segment_ptr = work->packet_ptr; 292 union cvmx_buf_ptr segment_ptr =
293 work->packet_ptr;
363 int len = work->len; 294 int len = work->len;
364 295
365 while (segments--) { 296 while (segments--) {
@@ -375,8 +306,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
375 * one: int segment_size = 306 * one: int segment_size =
376 * segment_ptr.s.size; 307 * segment_ptr.s.size;
377 */ 308 */
378 int segment_size = CVMX_FPA_PACKET_POOL_SIZE - 309 int segment_size =
379 (segment_ptr.s.addr - (((segment_ptr.s.addr >> 7) - segment_ptr.s.back) << 7)); 310 CVMX_FPA_PACKET_POOL_SIZE -
311 (segment_ptr.s.addr -
312 (((segment_ptr.s.addr >> 7) -
313 segment_ptr.s.back) << 7));
380 /* 314 /*
381 * Don't copy more than what 315 * Don't copy more than what
382 * is left in the packet. 316 * is left in the packet.
@@ -407,8 +341,10 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
407 skb->protocol = eth_type_trans(skb, dev); 341 skb->protocol = eth_type_trans(skb, dev);
408 skb->dev = dev; 342 skb->dev = dev;
409 343
410 if (unlikely(work->word2.s.not_IP || work->word2.s.IP_exc || 344 if (unlikely(work->word2.s.not_IP ||
411 work->word2.s.L4_error || !work->word2.s.tcp_or_udp)) 345 work->word2.s.IP_exc ||
346 work->word2.s.L4_error ||
347 !work->word2.s.tcp_or_udp))
412 skb->ip_summed = CHECKSUM_NONE; 348 skb->ip_summed = CHECKSUM_NONE;
413 else 349 else
414 skb->ip_summed = CHECKSUM_UNNECESSARY; 350 skb->ip_summed = CHECKSUM_UNNECESSARY;
@@ -416,11 +352,15 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
416 /* Increment RX stats for virtual ports */ 352 /* Increment RX stats for virtual ports */
417 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) { 353 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
418#ifdef CONFIG_64BIT 354#ifdef CONFIG_64BIT
419 atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets); 355 atomic64_add(1,
420 atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes); 356 (atomic64_t *)&priv->stats.rx_packets);
357 atomic64_add(skb->len,
358 (atomic64_t *)&priv->stats.rx_bytes);
421#else 359#else
422 atomic_add(1, (atomic_t *)&priv->stats.rx_packets); 360 atomic_add(1,
423 atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes); 361 (atomic_t *)&priv->stats.rx_packets);
362 atomic_add(skb->len,
363 (atomic_t *)&priv->stats.rx_bytes);
424#endif 364#endif
425 } 365 }
426 netif_receive_skb(skb); 366 netif_receive_skb(skb);
@@ -431,9 +371,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
431 dev->name); 371 dev->name);
432 */ 372 */
433#ifdef CONFIG_64BIT 373#ifdef CONFIG_64BIT
434 atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped); 374 atomic64_add(1,
375 (atomic64_t *)&priv->stats.rx_dropped);
435#else 376#else
436 atomic_add(1, (atomic_t *)&priv->stats.rx_dropped); 377 atomic_add(1,
378 (atomic_t *)&priv->stats.rx_dropped);
437#endif 379#endif
438 dev_kfree_skb_irq(skb); 380 dev_kfree_skb_irq(skb);
439 } 381 }
@@ -476,7 +418,7 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
476 if (rx_count < budget && napi != NULL) { 418 if (rx_count < budget && napi != NULL) {
477 /* No more work */ 419 /* No more work */
478 napi_complete(napi); 420 napi_complete(napi);
479 cvm_oct_no_more_work(); 421 enable_irq(OCTEON_IRQ_WORKQ0 + pow_receive_group);
480 } 422 }
481 return rx_count; 423 return rx_count;
482} 424}
@@ -511,18 +453,10 @@ void cvm_oct_rx_initialize(void)
511 if (NULL == dev_for_napi) 453 if (NULL == dev_for_napi)
512 panic("No net_devices were allocated."); 454 panic("No net_devices were allocated.");
513 455
514 if (max_rx_cpus >= 1 && max_rx_cpus < num_online_cpus()) 456 netif_napi_add(dev_for_napi, &cvm_oct_napi, cvm_oct_napi_poll,
515 atomic_set(&core_state.available_cores, max_rx_cpus); 457 rx_napi_weight);
516 else 458 napi_enable(&cvm_oct_napi);
517 atomic_set(&core_state.available_cores, num_online_cpus()); 459
518 core_state.baseline_cores = atomic_read(&core_state.available_cores);
519
520 core_state.cpu_state = CPU_MASK_NONE;
521 for_each_possible_cpu(i) {
522 netif_napi_add(dev_for_napi, &cvm_oct_napi[i].napi,
523 cvm_oct_napi_poll, rx_napi_weight);
524 napi_enable(&cvm_oct_napi[i].napi);
525 }
526 /* Register an IRQ handler to receive POW interrupts */ 460 /* Register an IRQ handler to receive POW interrupts */
527 i = request_irq(OCTEON_IRQ_WORKQ0 + pow_receive_group, 461 i = request_irq(OCTEON_IRQ_WORKQ0 + pow_receive_group,
528 cvm_oct_do_interrupt, 0, "Ethernet", cvm_oct_device); 462 cvm_oct_do_interrupt, 0, "Ethernet", cvm_oct_device);
@@ -543,15 +477,11 @@ void cvm_oct_rx_initialize(void)
543 int_pc.s.pc_thr = 5; 477 int_pc.s.pc_thr = 5;
544 cvmx_write_csr(CVMX_POW_WQ_INT_PC, int_pc.u64); 478 cvmx_write_csr(CVMX_POW_WQ_INT_PC, int_pc.u64);
545 479
546 480 /* Schedule NAPI now. This will indirectly enable the interrupt. */
547 /* Scheduld NAPI now. This will indirectly enable interrupts. */ 481 napi_schedule(&cvm_oct_napi);
548 cvm_oct_enable_one_cpu();
549} 482}
550 483
551void cvm_oct_rx_shutdown(void) 484void cvm_oct_rx_shutdown(void)
552{ 485{
553 int i; 486 netif_napi_del(&cvm_oct_napi);
554 /* Shutdown all of the NAPIs */
555 for_each_possible_cpu(i)
556 netif_napi_del(&cvm_oct_napi[i].napi);
557} 487}
diff --git a/drivers/staging/octeon/ethernet-tx.c b/drivers/staging/octeon/ethernet-tx.c
index 4e54d8540219..b7a7854d3f7e 100644
--- a/drivers/staging/octeon/ethernet-tx.c
+++ b/drivers/staging/octeon/ethernet-tx.c
@@ -77,6 +77,7 @@ static DECLARE_TASKLET(cvm_oct_tx_cleanup_tasklet, cvm_oct_tx_do_cleanup, 0);
77static inline int32_t cvm_oct_adjust_skb_to_free(int32_t skb_to_free, int fau) 77static inline int32_t cvm_oct_adjust_skb_to_free(int32_t skb_to_free, int fau)
78{ 78{
79 int32_t undo; 79 int32_t undo;
80
80 undo = skb_to_free > 0 ? MAX_SKB_TO_FREE : skb_to_free + 81 undo = skb_to_free > 0 ? MAX_SKB_TO_FREE : skb_to_free +
81 MAX_SKB_TO_FREE; 82 MAX_SKB_TO_FREE;
82 if (undo > 0) 83 if (undo > 0)
@@ -89,6 +90,7 @@ static inline int32_t cvm_oct_adjust_skb_to_free(int32_t skb_to_free, int fau)
89static void cvm_oct_kick_tx_poll_watchdog(void) 90static void cvm_oct_kick_tx_poll_watchdog(void)
90{ 91{
91 union cvmx_ciu_timx ciu_timx; 92 union cvmx_ciu_timx ciu_timx;
93
92 ciu_timx.u64 = 0; 94 ciu_timx.u64 = 0;
93 ciu_timx.s.one_shot = 1; 95 ciu_timx.s.one_shot = 1;
94 ciu_timx.s.len = cvm_oct_tx_poll_interval; 96 ciu_timx.s.len = cvm_oct_tx_poll_interval;
@@ -118,9 +120,11 @@ static void cvm_oct_free_tx_skbs(struct net_device *dev)
118 total_freed += skb_to_free; 120 total_freed += skb_to_free;
119 if (skb_to_free > 0) { 121 if (skb_to_free > 0) {
120 struct sk_buff *to_free_list = NULL; 122 struct sk_buff *to_free_list = NULL;
123
121 spin_lock_irqsave(&priv->tx_free_list[qos].lock, flags); 124 spin_lock_irqsave(&priv->tx_free_list[qos].lock, flags);
122 while (skb_to_free > 0) { 125 while (skb_to_free > 0) {
123 struct sk_buff *t; 126 struct sk_buff *t;
127
124 t = __skb_dequeue(&priv->tx_free_list[qos]); 128 t = __skb_dequeue(&priv->tx_free_list[qos]);
125 t->next = to_free_list; 129 t->next = to_free_list;
126 to_free_list = t; 130 to_free_list = t;
@@ -131,6 +135,7 @@ static void cvm_oct_free_tx_skbs(struct net_device *dev)
131 /* Do the actual freeing outside of the lock. */ 135 /* Do the actual freeing outside of the lock. */
132 while (to_free_list) { 136 while (to_free_list) {
133 struct sk_buff *t = to_free_list; 137 struct sk_buff *t = to_free_list;
138
134 to_free_list = to_free_list->next; 139 to_free_list = to_free_list->next;
135 dev_kfree_skb_any(t); 140 dev_kfree_skb_any(t);
136 } 141 }
@@ -258,6 +263,7 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
258 cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface)); 263 cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
259 if (gmx_prt_cfg.s.duplex == 0) { 264 if (gmx_prt_cfg.s.duplex == 0) {
260 int add_bytes = 64 - skb->len; 265 int add_bytes = 64 - skb->len;
266
261 if ((skb_tail_pointer(skb) + add_bytes) <= 267 if ((skb_tail_pointer(skb) + add_bytes) <=
262 skb_end_pointer(skb)) 268 skb_end_pointer(skb))
263 memset(__skb_put(skb, add_bytes), 0, 269 memset(__skb_put(skb, add_bytes), 0,
@@ -289,6 +295,7 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
289 CVM_OCT_SKB_CB(skb)[0] = hw_buffer.u64; 295 CVM_OCT_SKB_CB(skb)[0] = hw_buffer.u64;
290 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { 296 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
291 struct skb_frag_struct *fs = skb_shinfo(skb)->frags + i; 297 struct skb_frag_struct *fs = skb_shinfo(skb)->frags + i;
298
292 hw_buffer.s.addr = XKPHYS_TO_PHYS( 299 hw_buffer.s.addr = XKPHYS_TO_PHYS(
293 (u64)(page_address(fs->page.p) + 300 (u64)(page_address(fs->page.p) +
294 fs->page_offset)); 301 fs->page_offset));
@@ -495,6 +502,7 @@ skip_xmit:
495 502
496 while (skb_to_free > 0) { 503 while (skb_to_free > 0) {
497 struct sk_buff *t = __skb_dequeue(&priv->tx_free_list[qos]); 504 struct sk_buff *t = __skb_dequeue(&priv->tx_free_list[qos]);
505
498 t->next = to_free_list; 506 t->next = to_free_list;
499 to_free_list = t; 507 to_free_list = t;
500 skb_to_free--; 508 skb_to_free--;
@@ -505,6 +513,7 @@ skip_xmit:
505 /* Do the actual freeing outside of the lock. */ 513 /* Do the actual freeing outside of the lock. */
506 while (to_free_list) { 514 while (to_free_list) {
507 struct sk_buff *t = to_free_list; 515 struct sk_buff *t = to_free_list;
516
508 to_free_list = to_free_list->next; 517 to_free_list = to_free_list->next;
509 dev_kfree_skb_any(t); 518 dev_kfree_skb_any(t);
510 } 519 }
@@ -550,6 +559,7 @@ int cvm_oct_xmit_pow(struct sk_buff *skb, struct net_device *dev)
550 559
551 /* Get a work queue entry */ 560 /* Get a work queue entry */
552 cvmx_wqe_t *work = cvmx_fpa_alloc(CVMX_FPA_WQE_POOL); 561 cvmx_wqe_t *work = cvmx_fpa_alloc(CVMX_FPA_WQE_POOL);
562
553 if (unlikely(work == NULL)) { 563 if (unlikely(work == NULL)) {
554 printk_ratelimited("%s: Failed to allocate a work queue entry\n", 564 printk_ratelimited("%s: Failed to allocate a work queue entry\n",
555 dev->name); 565 dev->name);
@@ -713,6 +723,7 @@ static void cvm_oct_tx_do_cleanup(unsigned long arg)
713 for (port = 0; port < TOTAL_NUMBER_OF_PORTS; port++) { 723 for (port = 0; port < TOTAL_NUMBER_OF_PORTS; port++) {
714 if (cvm_oct_device[port]) { 724 if (cvm_oct_device[port]) {
715 struct net_device *dev = cvm_oct_device[port]; 725 struct net_device *dev = cvm_oct_device[port];
726
716 cvm_oct_free_tx_skbs(dev); 727 cvm_oct_free_tx_skbs(dev);
717 } 728 }
718 } 729 }
diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
index af24294d9466..ee321496dcdd 100644
--- a/drivers/staging/octeon/ethernet.c
+++ b/drivers/staging/octeon/ethernet.c
@@ -98,12 +98,6 @@ MODULE_PARM_DESC(pow_send_list, "\n"
98 "\t\"eth2,spi3,spi7\" would cause these three devices to transmit\n" 98 "\t\"eth2,spi3,spi7\" would cause these three devices to transmit\n"
99 "\tusing the pow_send_group."); 99 "\tusing the pow_send_group.");
100 100
101int max_rx_cpus = -1;
102module_param(max_rx_cpus, int, 0444);
103MODULE_PARM_DESC(max_rx_cpus, "\n"
104 "\t\tThe maximum number of CPUs to use for packet reception.\n"
105 "\t\tUse -1 to use all available CPUs.");
106
107int rx_napi_weight = 32; 101int rx_napi_weight = 32;
108module_param(rx_napi_weight, int, 0444); 102module_param(rx_napi_weight, int, 0444);
109MODULE_PARM_DESC(rx_napi_weight, "The NAPI WEIGHT parameter."); 103MODULE_PARM_DESC(rx_napi_weight, "The NAPI WEIGHT parameter.");
@@ -452,7 +446,7 @@ int cvm_oct_common_init(struct net_device *dev)
452 mac = of_get_mac_address(priv->of_node); 446 mac = of_get_mac_address(priv->of_node);
453 447
454 if (mac) 448 if (mac)
455 memcpy(dev->dev_addr, mac, ETH_ALEN); 449 ether_addr_copy(dev->dev_addr, mac);
456 else 450 else
457 eth_hw_addr_random(dev); 451 eth_hw_addr_random(dev);
458 452
diff --git a/drivers/staging/octeon/octeon-ethernet.h b/drivers/staging/octeon/octeon-ethernet.h
index d0e321119914..f48dc766fada 100644
--- a/drivers/staging/octeon/octeon-ethernet.h
+++ b/drivers/staging/octeon/octeon-ethernet.h
@@ -99,7 +99,6 @@ extern struct workqueue_struct *cvm_oct_poll_queue;
99extern atomic_t cvm_oct_poll_queue_stopping; 99extern atomic_t cvm_oct_poll_queue_stopping;
100extern u64 cvm_oct_tx_poll_interval; 100extern u64 cvm_oct_tx_poll_interval;
101 101
102extern int max_rx_cpus;
103extern int rx_napi_weight; 102extern int rx_napi_weight;
104 103
105#endif 104#endif
diff --git a/drivers/staging/olpc_dcon/olpc_dcon.c b/drivers/staging/olpc_dcon/olpc_dcon.c
index eb83b28b8cd1..6a9a8815477c 100644
--- a/drivers/staging/olpc_dcon/olpc_dcon.c
+++ b/drivers/staging/olpc_dcon/olpc_dcon.c
@@ -682,8 +682,7 @@ static int dcon_remove(struct i2c_client *client)
682 682
683 free_irq(DCON_IRQ, dcon); 683 free_irq(DCON_IRQ, dcon);
684 684
685 if (dcon->bl_dev) 685 backlight_device_unregister(dcon->bl_dev);
686 backlight_device_unregister(dcon->bl_dev);
687 686
688 if (dcon_device != NULL) 687 if (dcon_device != NULL)
689 platform_device_unregister(dcon_device); 688 platform_device_unregister(dcon_device);
diff --git a/drivers/staging/ozwpan/ozhcd.c b/drivers/staging/ozwpan/ozhcd.c
index 347b8b1ffa29..8543bb29a138 100644
--- a/drivers/staging/ozwpan/ozhcd.c
+++ b/drivers/staging/ozwpan/ozhcd.c
@@ -353,8 +353,7 @@ static void oz_complete_urb(struct usb_hcd *hcd, struct urb *urb,
353 } 353 }
354 spin_lock(&g_tasklet_lock); 354 spin_lock(&g_tasklet_lock);
355 spin_unlock_irqrestore(&g_tasklet_lock, irq_state); 355 spin_unlock_irqrestore(&g_tasklet_lock, irq_state);
356 if (cancel_urbl) 356 oz_free_urb_link(cancel_urbl);
357 oz_free_urb_link(cancel_urbl);
358} 357}
359 358
360/* 359/*
@@ -522,8 +521,7 @@ static int oz_dequeue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir,
522 } 521 }
523 } 522 }
524 spin_unlock_bh(&port->ozhcd->hcd_lock); 523 spin_unlock_bh(&port->ozhcd->hcd_lock);
525 if (urbl) 524 oz_free_urb_link(urbl);
526 oz_free_urb_link(urbl);
527 return urbl ? 0 : -EIDRM; 525 return urbl ? 0 : -EIDRM;
528} 526}
529 527
@@ -729,7 +727,7 @@ void oz_hcd_pd_reset(void *hpd, void *hport)
729{ 727{
730 /* Cleanup the current configuration and report reset to the core. 728 /* Cleanup the current configuration and report reset to the core.
731 */ 729 */
732 struct oz_port *port = (struct oz_port *)hport; 730 struct oz_port *port = hport;
733 struct oz_hcd *ozhcd = port->ozhcd; 731 struct oz_hcd *ozhcd = port->ozhcd;
734 732
735 oz_dbg(ON, "PD Reset\n"); 733 oz_dbg(ON, "PD Reset\n");
@@ -748,7 +746,7 @@ void oz_hcd_pd_reset(void *hpd, void *hport)
748void oz_hcd_get_desc_cnf(void *hport, u8 req_id, int status, const u8 *desc, 746void oz_hcd_get_desc_cnf(void *hport, u8 req_id, int status, const u8 *desc,
749 int length, int offset, int total_size) 747 int length, int offset, int total_size)
750{ 748{
751 struct oz_port *port = (struct oz_port *)hport; 749 struct oz_port *port = hport;
752 struct urb *urb; 750 struct urb *urb;
753 int err = 0; 751 int err = 0;
754 752
@@ -888,7 +886,7 @@ static void oz_hcd_complete_set_interface(struct oz_port *port, struct urb *urb,
888void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode, const u8 *data, 886void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode, const u8 *data,
889 int data_len) 887 int data_len)
890{ 888{
891 struct oz_port *port = (struct oz_port *)hport; 889 struct oz_port *port = hport;
892 struct urb *urb; 890 struct urb *urb;
893 struct usb_ctrlrequest *setup; 891 struct usb_ctrlrequest *setup;
894 struct usb_hcd *hcd = port->ozhcd->hcd; 892 struct usb_hcd *hcd = port->ozhcd->hcd;
@@ -1035,7 +1033,7 @@ static inline int oz_usb_get_frame_number(void)
1035int oz_hcd_heartbeat(void *hport) 1033int oz_hcd_heartbeat(void *hport)
1036{ 1034{
1037 int rc = 0; 1035 int rc = 0;
1038 struct oz_port *port = (struct oz_port *)hport; 1036 struct oz_port *port = hport;
1039 struct oz_hcd *ozhcd = port->ozhcd; 1037 struct oz_hcd *ozhcd = port->ozhcd;
1040 struct oz_urb_link *urbl, *n; 1038 struct oz_urb_link *urbl, *n;
1041 LIST_HEAD(xfr_list); 1039 LIST_HEAD(xfr_list);
@@ -1913,7 +1911,7 @@ static void oz_get_hub_descriptor(struct usb_hcd *hcd,
1913 memset(desc, 0, sizeof(*desc)); 1911 memset(desc, 0, sizeof(*desc));
1914 desc->bDescriptorType = 0x29; 1912 desc->bDescriptorType = 0x29;
1915 desc->bDescLength = 9; 1913 desc->bDescLength = 9;
1916 desc->wHubCharacteristics = (__force __u16)cpu_to_le16(0x0001); 1914 desc->wHubCharacteristics = cpu_to_le16(0x0001);
1917 desc->bNbrPorts = OZ_NB_PORTS; 1915 desc->bNbrPorts = OZ_NB_PORTS;
1918} 1916}
1919 1917
@@ -2031,11 +2029,11 @@ static int oz_clear_port_feature(struct usb_hcd *hcd, u16 wvalue, u16 windex)
2031 break; 2029 break;
2032 case USB_PORT_FEAT_C_CONNECTION: 2030 case USB_PORT_FEAT_C_CONNECTION:
2033 oz_dbg(HUB, "USB_PORT_FEAT_C_CONNECTION\n"); 2031 oz_dbg(HUB, "USB_PORT_FEAT_C_CONNECTION\n");
2034 clear_bits = (USB_PORT_STAT_C_CONNECTION << 16); 2032 clear_bits = USB_PORT_STAT_C_CONNECTION << 16;
2035 break; 2033 break;
2036 case USB_PORT_FEAT_C_ENABLE: 2034 case USB_PORT_FEAT_C_ENABLE:
2037 oz_dbg(HUB, "USB_PORT_FEAT_C_ENABLE\n"); 2035 oz_dbg(HUB, "USB_PORT_FEAT_C_ENABLE\n");
2038 clear_bits = (USB_PORT_STAT_C_ENABLE << 16); 2036 clear_bits = USB_PORT_STAT_C_ENABLE << 16;
2039 break; 2037 break;
2040 case USB_PORT_FEAT_C_SUSPEND: 2038 case USB_PORT_FEAT_C_SUSPEND:
2041 oz_dbg(HUB, "USB_PORT_FEAT_C_SUSPEND\n"); 2039 oz_dbg(HUB, "USB_PORT_FEAT_C_SUSPEND\n");
@@ -2045,7 +2043,7 @@ static int oz_clear_port_feature(struct usb_hcd *hcd, u16 wvalue, u16 windex)
2045 break; 2043 break;
2046 case USB_PORT_FEAT_C_RESET: 2044 case USB_PORT_FEAT_C_RESET:
2047 oz_dbg(HUB, "USB_PORT_FEAT_C_RESET\n"); 2045 oz_dbg(HUB, "USB_PORT_FEAT_C_RESET\n");
2048 clear_bits = (USB_PORT_FEAT_C_RESET << 16); 2046 clear_bits = USB_PORT_FEAT_C_RESET << 16;
2049 break; 2047 break;
2050 case USB_PORT_FEAT_TEST: 2048 case USB_PORT_FEAT_TEST:
2051 oz_dbg(HUB, "USB_PORT_FEAT_TEST\n"); 2049 oz_dbg(HUB, "USB_PORT_FEAT_TEST\n");
diff --git a/drivers/staging/ozwpan/ozusbsvc1.c b/drivers/staging/ozwpan/ozusbsvc1.c
index be7ee01c50ab..d434d8c6fff6 100644
--- a/drivers/staging/ozwpan/ozusbsvc1.c
+++ b/drivers/staging/ozwpan/ozusbsvc1.c
@@ -56,7 +56,7 @@ static int oz_usb_submit_elt(struct oz_elt_buf *eb, struct oz_elt_info *ei,
56int oz_usb_get_desc_req(void *hpd, u8 req_id, u8 req_type, u8 desc_type, 56int oz_usb_get_desc_req(void *hpd, u8 req_id, u8 req_type, u8 desc_type,
57 u8 index, __le16 windex, int offset, int len) 57 u8 index, __le16 windex, int offset, int len)
58{ 58{
59 struct oz_usb_ctx *usb_ctx = (struct oz_usb_ctx *)hpd; 59 struct oz_usb_ctx *usb_ctx = hpd;
60 struct oz_pd *pd = usb_ctx->pd; 60 struct oz_pd *pd = usb_ctx->pd;
61 struct oz_elt *elt; 61 struct oz_elt *elt;
62 struct oz_get_desc_req *body; 62 struct oz_get_desc_req *body;
@@ -92,7 +92,7 @@ int oz_usb_get_desc_req(void *hpd, u8 req_id, u8 req_type, u8 desc_type,
92 */ 92 */
93static int oz_usb_set_config_req(void *hpd, u8 req_id, u8 index) 93static int oz_usb_set_config_req(void *hpd, u8 req_id, u8 index)
94{ 94{
95 struct oz_usb_ctx *usb_ctx = (struct oz_usb_ctx *)hpd; 95 struct oz_usb_ctx *usb_ctx = hpd;
96 struct oz_pd *pd = usb_ctx->pd; 96 struct oz_pd *pd = usb_ctx->pd;
97 struct oz_elt *elt; 97 struct oz_elt *elt;
98 struct oz_elt_buf *eb = &pd->elt_buff; 98 struct oz_elt_buf *eb = &pd->elt_buff;
@@ -115,7 +115,7 @@ static int oz_usb_set_config_req(void *hpd, u8 req_id, u8 index)
115 */ 115 */
116static int oz_usb_set_interface_req(void *hpd, u8 req_id, u8 index, u8 alt) 116static int oz_usb_set_interface_req(void *hpd, u8 req_id, u8 index, u8 alt)
117{ 117{
118 struct oz_usb_ctx *usb_ctx = (struct oz_usb_ctx *)hpd; 118 struct oz_usb_ctx *usb_ctx = hpd;
119 struct oz_pd *pd = usb_ctx->pd; 119 struct oz_pd *pd = usb_ctx->pd;
120 struct oz_elt *elt; 120 struct oz_elt *elt;
121 struct oz_elt_buf *eb = &pd->elt_buff; 121 struct oz_elt_buf *eb = &pd->elt_buff;
@@ -140,7 +140,7 @@ static int oz_usb_set_interface_req(void *hpd, u8 req_id, u8 index, u8 alt)
140static int oz_usb_set_clear_feature_req(void *hpd, u8 req_id, u8 type, 140static int oz_usb_set_clear_feature_req(void *hpd, u8 req_id, u8 type,
141 u8 recipient, u8 index, __le16 feature) 141 u8 recipient, u8 index, __le16 feature)
142{ 142{
143 struct oz_usb_ctx *usb_ctx = (struct oz_usb_ctx *)hpd; 143 struct oz_usb_ctx *usb_ctx = hpd;
144 struct oz_pd *pd = usb_ctx->pd; 144 struct oz_pd *pd = usb_ctx->pd;
145 struct oz_elt *elt; 145 struct oz_elt *elt;
146 struct oz_elt_buf *eb = &pd->elt_buff; 146 struct oz_elt_buf *eb = &pd->elt_buff;
@@ -166,7 +166,7 @@ static int oz_usb_set_clear_feature_req(void *hpd, u8 req_id, u8 type,
166static int oz_usb_vendor_class_req(void *hpd, u8 req_id, u8 req_type, 166static int oz_usb_vendor_class_req(void *hpd, u8 req_id, u8 req_type,
167 u8 request, __le16 value, __le16 index, const u8 *data, int data_len) 167 u8 request, __le16 value, __le16 index, const u8 *data, int data_len)
168{ 168{
169 struct oz_usb_ctx *usb_ctx = (struct oz_usb_ctx *)hpd; 169 struct oz_usb_ctx *usb_ctx = hpd;
170 struct oz_pd *pd = usb_ctx->pd; 170 struct oz_pd *pd = usb_ctx->pd;
171 struct oz_elt *elt; 171 struct oz_elt *elt;
172 struct oz_elt_buf *eb = &pd->elt_buff; 172 struct oz_elt_buf *eb = &pd->elt_buff;
@@ -244,7 +244,7 @@ int oz_usb_control_req(void *hpd, u8 req_id, struct usb_ctrlrequest *setup,
244 */ 244 */
245int oz_usb_send_isoc(void *hpd, u8 ep_num, struct urb *urb) 245int oz_usb_send_isoc(void *hpd, u8 ep_num, struct urb *urb)
246{ 246{
247 struct oz_usb_ctx *usb_ctx = (struct oz_usb_ctx *)hpd; 247 struct oz_usb_ctx *usb_ctx = hpd;
248 struct oz_pd *pd = usb_ctx->pd; 248 struct oz_pd *pd = usb_ctx->pd;
249 struct oz_elt_buf *eb; 249 struct oz_elt_buf *eb;
250 int i; 250 int i;
diff --git a/drivers/staging/panel/TODO b/drivers/staging/panel/TODO
index a4be749bcdfc..2db3f994b632 100644
--- a/drivers/staging/panel/TODO
+++ b/drivers/staging/panel/TODO
@@ -1,6 +1,5 @@
1TODO: 1TODO:
2 - checkpatch.pl cleanups 2 - checkpatch.pl cleanups
3 - Lindent
4 - review major/minor usages 3 - review major/minor usages
5 - review userspace api 4 - review userspace api
6 - see if all of this could be easier done in userspace instead. 5 - see if all of this could be easier done in userspace instead.
diff --git a/drivers/staging/panel/panel.c b/drivers/staging/panel/panel.c
index 6d1a32097d3c..98325b7b4462 100644
--- a/drivers/staging/panel/panel.c
+++ b/drivers/staging/panel/panel.c
@@ -133,6 +133,8 @@
133#define LCD_ESCAPE_LEN 24 /* max chars for LCD escape command */ 133#define LCD_ESCAPE_LEN 24 /* max chars for LCD escape command */
134#define LCD_ESCAPE_CHAR 27 /* use char 27 for escape command */ 134#define LCD_ESCAPE_CHAR 27 /* use char 27 for escape command */
135 135
136#define NOT_SET -1
137
136/* macros to simplify use of the parallel port */ 138/* macros to simplify use of the parallel port */
137#define r_ctr(x) (parport_read_control((x)->port)) 139#define r_ctr(x) (parport_read_control((x)->port))
138#define r_dtr(x) (parport_read_data((x)->port)) 140#define r_dtr(x) (parport_read_data((x)->port))
@@ -210,6 +212,10 @@ static pmask_t phys_prev;
210static char inputs_stable; 212static char inputs_stable;
211 213
212/* these variables are specific to the keypad */ 214/* these variables are specific to the keypad */
215static struct {
216 bool enabled;
217} keypad;
218
213static char keypad_buffer[KEYPAD_BUFFER]; 219static char keypad_buffer[KEYPAD_BUFFER];
214static int keypad_buflen; 220static int keypad_buflen;
215static int keypad_start; 221static int keypad_start;
@@ -217,17 +223,50 @@ static char keypressed;
217static wait_queue_head_t keypad_read_wait; 223static wait_queue_head_t keypad_read_wait;
218 224
219/* lcd-specific variables */ 225/* lcd-specific variables */
220 226static struct {
221/* contains the LCD config state */ 227 bool enabled;
222static unsigned long int lcd_flags; 228 bool initialized;
223/* contains the LCD X offset */ 229 bool must_clear;
224static unsigned long int lcd_addr_x; 230
225/* contains the LCD Y offset */ 231 /* TODO: use bool here? */
226static unsigned long int lcd_addr_y; 232 char left_shift;
227/* current escape sequence, 0 terminated */ 233
228static char lcd_escape[LCD_ESCAPE_LEN + 1]; 234 int height;
229/* not in escape state. >=0 = escape cmd len */ 235 int width;
230static int lcd_escape_len = -1; 236 int bwidth;
237 int hwidth;
238 int charset;
239 int proto;
240 int light_tempo;
241
242 /* TODO: use union here? */
243 struct {
244 int e;
245 int rs;
246 int rw;
247 int cl;
248 int da;
249 int bl;
250 } pins;
251
252 /* contains the LCD config state */
253 unsigned long int flags;
254
255 /* Contains the LCD X and Y offset */
256 struct {
257 unsigned long int x;
258 unsigned long int y;
259 } addr;
260
261 /* Current escape sequence and it's length or -1 if outside */
262 struct {
263 char buf[LCD_ESCAPE_LEN + 1];
264 int len;
265 } esc_seq;
266} lcd;
267
268/* Needed only for init */
269static int selected_lcd_type = NOT_SET;
231 270
232/* 271/*
233 * Bit masks to convert LCD signals to parallel port outputs. 272 * Bit masks to convert LCD signals to parallel port outputs.
@@ -302,14 +341,15 @@ static unsigned char lcd_bits[LCD_PORTS][LCD_BITS][BIT_STATES];
302/* 341/*
303 * Construct custom config from the kernel's configuration 342 * Construct custom config from the kernel's configuration
304 */ 343 */
305#define DEFAULT_PROFILE PANEL_PROFILE_LARGE
306#define DEFAULT_PARPORT 0 344#define DEFAULT_PARPORT 0
307#define DEFAULT_LCD LCD_TYPE_OLD 345#define DEFAULT_PROFILE PANEL_PROFILE_LARGE
308#define DEFAULT_KEYPAD KEYPAD_TYPE_OLD 346#define DEFAULT_KEYPAD_TYPE KEYPAD_TYPE_OLD
347#define DEFAULT_LCD_TYPE LCD_TYPE_OLD
348#define DEFAULT_LCD_HEIGHT 2
309#define DEFAULT_LCD_WIDTH 40 349#define DEFAULT_LCD_WIDTH 40
310#define DEFAULT_LCD_BWIDTH 40 350#define DEFAULT_LCD_BWIDTH 40
311#define DEFAULT_LCD_HWIDTH 64 351#define DEFAULT_LCD_HWIDTH 64
312#define DEFAULT_LCD_HEIGHT 2 352#define DEFAULT_LCD_CHARSET LCD_CHARSET_NORMAL
313#define DEFAULT_LCD_PROTO LCD_PROTO_PARALLEL 353#define DEFAULT_LCD_PROTO LCD_PROTO_PARALLEL
314 354
315#define DEFAULT_LCD_PIN_E PIN_AUTOLF 355#define DEFAULT_LCD_PIN_E PIN_AUTOLF
@@ -318,27 +358,31 @@ static unsigned char lcd_bits[LCD_PORTS][LCD_BITS][BIT_STATES];
318#define DEFAULT_LCD_PIN_SCL PIN_STROBE 358#define DEFAULT_LCD_PIN_SCL PIN_STROBE
319#define DEFAULT_LCD_PIN_SDA PIN_D0 359#define DEFAULT_LCD_PIN_SDA PIN_D0
320#define DEFAULT_LCD_PIN_BL PIN_NOT_SET 360#define DEFAULT_LCD_PIN_BL PIN_NOT_SET
321#define DEFAULT_LCD_CHARSET LCD_CHARSET_NORMAL
322
323#ifdef CONFIG_PANEL_PROFILE
324#undef DEFAULT_PROFILE
325#define DEFAULT_PROFILE CONFIG_PANEL_PROFILE
326#endif
327 361
328#ifdef CONFIG_PANEL_PARPORT 362#ifdef CONFIG_PANEL_PARPORT
329#undef DEFAULT_PARPORT 363#undef DEFAULT_PARPORT
330#define DEFAULT_PARPORT CONFIG_PANEL_PARPORT 364#define DEFAULT_PARPORT CONFIG_PANEL_PARPORT
331#endif 365#endif
332 366
367#ifdef CONFIG_PANEL_PROFILE
368#undef DEFAULT_PROFILE
369#define DEFAULT_PROFILE CONFIG_PANEL_PROFILE
370#endif
371
333#if DEFAULT_PROFILE == 0 /* custom */ 372#if DEFAULT_PROFILE == 0 /* custom */
334#ifdef CONFIG_PANEL_KEYPAD 373#ifdef CONFIG_PANEL_KEYPAD
335#undef DEFAULT_KEYPAD 374#undef DEFAULT_KEYPAD_TYPE
336#define DEFAULT_KEYPAD CONFIG_PANEL_KEYPAD 375#define DEFAULT_KEYPAD_TYPE CONFIG_PANEL_KEYPAD
337#endif 376#endif
338 377
339#ifdef CONFIG_PANEL_LCD 378#ifdef CONFIG_PANEL_LCD
340#undef DEFAULT_LCD 379#undef DEFAULT_LCD_TYPE
341#define DEFAULT_LCD CONFIG_PANEL_LCD 380#define DEFAULT_LCD_TYPE CONFIG_PANEL_LCD
381#endif
382
383#ifdef CONFIG_PANEL_LCD_HEIGHT
384#undef DEFAULT_LCD_HEIGHT
385#define DEFAULT_LCD_HEIGHT CONFIG_PANEL_LCD_HEIGHT
342#endif 386#endif
343 387
344#ifdef CONFIG_PANEL_LCD_WIDTH 388#ifdef CONFIG_PANEL_LCD_WIDTH
@@ -356,9 +400,9 @@ static unsigned char lcd_bits[LCD_PORTS][LCD_BITS][BIT_STATES];
356#define DEFAULT_LCD_HWIDTH CONFIG_PANEL_LCD_HWIDTH 400#define DEFAULT_LCD_HWIDTH CONFIG_PANEL_LCD_HWIDTH
357#endif 401#endif
358 402
359#ifdef CONFIG_PANEL_LCD_HEIGHT 403#ifdef CONFIG_PANEL_LCD_CHARSET
360#undef DEFAULT_LCD_HEIGHT 404#undef DEFAULT_LCD_CHARSET
361#define DEFAULT_LCD_HEIGHT CONFIG_PANEL_LCD_HEIGHT 405#define DEFAULT_LCD_CHARSET CONFIG_PANEL_LCD_CHARSET
362#endif 406#endif
363 407
364#ifdef CONFIG_PANEL_LCD_PROTO 408#ifdef CONFIG_PANEL_LCD_PROTO
@@ -396,25 +440,18 @@ static unsigned char lcd_bits[LCD_PORTS][LCD_BITS][BIT_STATES];
396#define DEFAULT_LCD_PIN_BL CONFIG_PANEL_LCD_PIN_BL 440#define DEFAULT_LCD_PIN_BL CONFIG_PANEL_LCD_PIN_BL
397#endif 441#endif
398 442
399#ifdef CONFIG_PANEL_LCD_CHARSET
400#undef DEFAULT_LCD_CHARSET
401#define DEFAULT_LCD_CHARSET CONFIG_PANEL_LCD_CHARSET
402#endif
403
404#endif /* DEFAULT_PROFILE == 0 */ 443#endif /* DEFAULT_PROFILE == 0 */
405 444
406/* global variables */ 445/* global variables */
407static int keypad_open_cnt; /* #times opened */ 446
408static int lcd_open_cnt; /* #times opened */ 447/* Device single-open policy control */
448static atomic_t lcd_available = ATOMIC_INIT(1);
449static atomic_t keypad_available = ATOMIC_INIT(1);
450
409static struct pardevice *pprt; 451static struct pardevice *pprt;
410 452
411static int lcd_initialized;
412static int keypad_initialized; 453static int keypad_initialized;
413 454
414static int light_tempo;
415
416static char lcd_must_clear;
417static char lcd_left_shift;
418static char init_in_progress; 455static char init_in_progress;
419 456
420static void (*lcd_write_cmd)(int); 457static void (*lcd_write_cmd)(int);
@@ -426,59 +463,51 @@ static struct timer_list scan_timer;
426 463
427MODULE_DESCRIPTION("Generic parallel port LCD/Keypad driver"); 464MODULE_DESCRIPTION("Generic parallel port LCD/Keypad driver");
428 465
429static int parport = -1; 466static int parport = DEFAULT_PARPORT;
430module_param(parport, int, 0000); 467module_param(parport, int, 0000);
431MODULE_PARM_DESC(parport, "Parallel port index (0=lpt1, 1=lpt2, ...)"); 468MODULE_PARM_DESC(parport, "Parallel port index (0=lpt1, 1=lpt2, ...)");
432 469
433static int lcd_height = -1; 470static int profile = DEFAULT_PROFILE;
471module_param(profile, int, 0000);
472MODULE_PARM_DESC(profile,
473 "1=16x2 old kp; 2=serial 16x2, new kp; 3=16x2 hantronix; "
474 "4=16x2 nexcom; default=40x2, old kp");
475
476static int keypad_type = NOT_SET;
477module_param(keypad_type, int, 0000);
478MODULE_PARM_DESC(keypad_type,
479 "Keypad type: 0=none, 1=old 6 keys, 2=new 6+1 keys, 3=nexcom 4 keys");
480
481static int lcd_type = NOT_SET;
482module_param(lcd_type, int, 0000);
483MODULE_PARM_DESC(lcd_type,
484 "LCD type: 0=none, 1=old //, 2=serial ks0074, 3=hantronix //, 4=nexcom //, 5=compiled-in");
485
486static int lcd_height = NOT_SET;
434module_param(lcd_height, int, 0000); 487module_param(lcd_height, int, 0000);
435MODULE_PARM_DESC(lcd_height, "Number of lines on the LCD"); 488MODULE_PARM_DESC(lcd_height, "Number of lines on the LCD");
436 489
437static int lcd_width = -1; 490static int lcd_width = NOT_SET;
438module_param(lcd_width, int, 0000); 491module_param(lcd_width, int, 0000);
439MODULE_PARM_DESC(lcd_width, "Number of columns on the LCD"); 492MODULE_PARM_DESC(lcd_width, "Number of columns on the LCD");
440 493
441static int lcd_bwidth = -1; /* internal buffer width (usually 40) */ 494static int lcd_bwidth = NOT_SET; /* internal buffer width (usually 40) */
442module_param(lcd_bwidth, int, 0000); 495module_param(lcd_bwidth, int, 0000);
443MODULE_PARM_DESC(lcd_bwidth, "Internal LCD line width (40)"); 496MODULE_PARM_DESC(lcd_bwidth, "Internal LCD line width (40)");
444 497
445static int lcd_hwidth = -1; /* hardware buffer width (usually 64) */ 498static int lcd_hwidth = NOT_SET; /* hardware buffer width (usually 64) */
446module_param(lcd_hwidth, int, 0000); 499module_param(lcd_hwidth, int, 0000);
447MODULE_PARM_DESC(lcd_hwidth, "LCD line hardware address (64)"); 500MODULE_PARM_DESC(lcd_hwidth, "LCD line hardware address (64)");
448 501
449static int lcd_enabled = -1; 502static int lcd_charset = NOT_SET;
450module_param(lcd_enabled, int, 0000); 503module_param(lcd_charset, int, 0000);
451MODULE_PARM_DESC(lcd_enabled, "Deprecated option, use lcd_type instead"); 504MODULE_PARM_DESC(lcd_charset, "LCD character set: 0=standard, 1=KS0074");
452
453static int keypad_enabled = -1;
454module_param(keypad_enabled, int, 0000);
455MODULE_PARM_DESC(keypad_enabled, "Deprecated option, use keypad_type instead");
456
457static int lcd_type = -1;
458module_param(lcd_type, int, 0000);
459MODULE_PARM_DESC(lcd_type,
460 "LCD type: 0=none, 1=old //, 2=serial ks0074, 3=hantronix //, 4=nexcom //, 5=compiled-in");
461 505
462static int lcd_proto = -1; 506static int lcd_proto = NOT_SET;
463module_param(lcd_proto, int, 0000); 507module_param(lcd_proto, int, 0000);
464MODULE_PARM_DESC(lcd_proto, 508MODULE_PARM_DESC(lcd_proto,
465 "LCD communication: 0=parallel (//), 1=serial, 2=TI LCD Interface"); 509 "LCD communication: 0=parallel (//), 1=serial, 2=TI LCD Interface");
466 510
467static int lcd_charset = -1;
468module_param(lcd_charset, int, 0000);
469MODULE_PARM_DESC(lcd_charset, "LCD character set: 0=standard, 1=KS0074");
470
471static int keypad_type = -1;
472module_param(keypad_type, int, 0000);
473MODULE_PARM_DESC(keypad_type,
474 "Keypad type: 0=none, 1=old 6 keys, 2=new 6+1 keys, 3=nexcom 4 keys");
475
476static int profile = DEFAULT_PROFILE;
477module_param(profile, int, 0000);
478MODULE_PARM_DESC(profile,
479 "1=16x2 old kp; 2=serial 16x2, new kp; 3=16x2 hantronix; "
480 "4=16x2 nexcom; default=40x2, old kp");
481
482/* 511/*
483 * These are the parallel port pins the LCD control signals are connected to. 512 * These are the parallel port pins the LCD control signals are connected to.
484 * Set this to 0 if the signal is not used. Set it to its opposite value 513 * Set this to 0 if the signal is not used. Set it to its opposite value
@@ -503,20 +532,31 @@ module_param(lcd_rw_pin, int, 0000);
503MODULE_PARM_DESC(lcd_rw_pin, 532MODULE_PARM_DESC(lcd_rw_pin,
504 "# of the // port pin connected to LCD 'RW' signal, with polarity (-17..17)"); 533 "# of the // port pin connected to LCD 'RW' signal, with polarity (-17..17)");
505 534
506static int lcd_bl_pin = PIN_NOT_SET; 535static int lcd_cl_pin = PIN_NOT_SET;
507module_param(lcd_bl_pin, int, 0000); 536module_param(lcd_cl_pin, int, 0000);
508MODULE_PARM_DESC(lcd_bl_pin, 537MODULE_PARM_DESC(lcd_cl_pin,
509 "# of the // port pin connected to LCD backlight, with polarity (-17..17)"); 538 "# of the // port pin connected to serial LCD 'SCL' signal, with polarity (-17..17)");
510 539
511static int lcd_da_pin = PIN_NOT_SET; 540static int lcd_da_pin = PIN_NOT_SET;
512module_param(lcd_da_pin, int, 0000); 541module_param(lcd_da_pin, int, 0000);
513MODULE_PARM_DESC(lcd_da_pin, 542MODULE_PARM_DESC(lcd_da_pin,
514 "# of the // port pin connected to serial LCD 'SDA' signal, with polarity (-17..17)"); 543 "# of the // port pin connected to serial LCD 'SDA' signal, with polarity (-17..17)");
515 544
516static int lcd_cl_pin = PIN_NOT_SET; 545static int lcd_bl_pin = PIN_NOT_SET;
517module_param(lcd_cl_pin, int, 0000); 546module_param(lcd_bl_pin, int, 0000);
518MODULE_PARM_DESC(lcd_cl_pin, 547MODULE_PARM_DESC(lcd_bl_pin,
519 "# of the // port pin connected to serial LCD 'SCL' signal, with polarity (-17..17)"); 548 "# of the // port pin connected to LCD backlight, with polarity (-17..17)");
549
550/* Deprecated module parameters - consider not using them anymore */
551
552static int lcd_enabled = NOT_SET;
553module_param(lcd_enabled, int, 0000);
554MODULE_PARM_DESC(lcd_enabled, "Deprecated option, use lcd_type instead");
555
556static int keypad_enabled = NOT_SET;
557module_param(keypad_enabled, int, 0000);
558MODULE_PARM_DESC(keypad_enabled, "Deprecated option, use keypad_type instead");
559
520 560
521static const unsigned char *lcd_char_conv; 561static const unsigned char *lcd_char_conv;
522 562
@@ -748,7 +788,7 @@ static void lcd_send_serial(int byte)
748/* turn the backlight on or off */ 788/* turn the backlight on or off */
749static void lcd_backlight(int on) 789static void lcd_backlight(int on)
750{ 790{
751 if (lcd_bl_pin == PIN_NONE) 791 if (lcd.pins.bl == PIN_NONE)
752 return; 792 return;
753 793
754 /* The backlight is activated by setting the AUTOFEED line to +5V */ 794 /* The backlight is activated by setting the AUTOFEED line to +5V */
@@ -847,23 +887,23 @@ static void lcd_write_data_tilcd(int data)
847static void lcd_gotoxy(void) 887static void lcd_gotoxy(void)
848{ 888{
849 lcd_write_cmd(0x80 /* set DDRAM address */ 889 lcd_write_cmd(0x80 /* set DDRAM address */
850 | (lcd_addr_y ? lcd_hwidth : 0) 890 | (lcd.addr.y ? lcd.hwidth : 0)
851 /* we force the cursor to stay at the end of the 891 /* we force the cursor to stay at the end of the
852 line if it wants to go farther */ 892 line if it wants to go farther */
853 | ((lcd_addr_x < lcd_bwidth) ? lcd_addr_x & 893 | ((lcd.addr.x < lcd.bwidth) ? lcd.addr.x &
854 (lcd_hwidth - 1) : lcd_bwidth - 1)); 894 (lcd.hwidth - 1) : lcd.bwidth - 1));
855} 895}
856 896
857static void lcd_print(char c) 897static void lcd_print(char c)
858{ 898{
859 if (lcd_addr_x < lcd_bwidth) { 899 if (lcd.addr.x < lcd.bwidth) {
860 if (lcd_char_conv != NULL) 900 if (lcd_char_conv != NULL)
861 c = lcd_char_conv[(unsigned char)c]; 901 c = lcd_char_conv[(unsigned char)c];
862 lcd_write_data(c); 902 lcd_write_data(c);
863 lcd_addr_x++; 903 lcd.addr.x++;
864 } 904 }
865 /* prevents the cursor from wrapping onto the next line */ 905 /* prevents the cursor from wrapping onto the next line */
866 if (lcd_addr_x == lcd_bwidth) 906 if (lcd.addr.x == lcd.bwidth)
867 lcd_gotoxy(); 907 lcd_gotoxy();
868} 908}
869 909
@@ -872,12 +912,12 @@ static void lcd_clear_fast_s(void)
872{ 912{
873 int pos; 913 int pos;
874 914
875 lcd_addr_x = 0; 915 lcd.addr.x = 0;
876 lcd_addr_y = 0; 916 lcd.addr.y = 0;
877 lcd_gotoxy(); 917 lcd_gotoxy();
878 918
879 spin_lock_irq(&pprt_lock); 919 spin_lock_irq(&pprt_lock);
880 for (pos = 0; pos < lcd_height * lcd_hwidth; pos++) { 920 for (pos = 0; pos < lcd.height * lcd.hwidth; pos++) {
881 lcd_send_serial(0x5F); /* R/W=W, RS=1 */ 921 lcd_send_serial(0x5F); /* R/W=W, RS=1 */
882 lcd_send_serial(' ' & 0x0F); 922 lcd_send_serial(' ' & 0x0F);
883 lcd_send_serial((' ' >> 4) & 0x0F); 923 lcd_send_serial((' ' >> 4) & 0x0F);
@@ -885,8 +925,8 @@ static void lcd_clear_fast_s(void)
885 } 925 }
886 spin_unlock_irq(&pprt_lock); 926 spin_unlock_irq(&pprt_lock);
887 927
888 lcd_addr_x = 0; 928 lcd.addr.x = 0;
889 lcd_addr_y = 0; 929 lcd.addr.y = 0;
890 lcd_gotoxy(); 930 lcd_gotoxy();
891} 931}
892 932
@@ -895,12 +935,12 @@ static void lcd_clear_fast_p8(void)
895{ 935{
896 int pos; 936 int pos;
897 937
898 lcd_addr_x = 0; 938 lcd.addr.x = 0;
899 lcd_addr_y = 0; 939 lcd.addr.y = 0;
900 lcd_gotoxy(); 940 lcd_gotoxy();
901 941
902 spin_lock_irq(&pprt_lock); 942 spin_lock_irq(&pprt_lock);
903 for (pos = 0; pos < lcd_height * lcd_hwidth; pos++) { 943 for (pos = 0; pos < lcd.height * lcd.hwidth; pos++) {
904 /* present the data to the data port */ 944 /* present the data to the data port */
905 w_dtr(pprt, ' '); 945 w_dtr(pprt, ' ');
906 946
@@ -923,8 +963,8 @@ static void lcd_clear_fast_p8(void)
923 } 963 }
924 spin_unlock_irq(&pprt_lock); 964 spin_unlock_irq(&pprt_lock);
925 965
926 lcd_addr_x = 0; 966 lcd.addr.x = 0;
927 lcd_addr_y = 0; 967 lcd.addr.y = 0;
928 lcd_gotoxy(); 968 lcd_gotoxy();
929} 969}
930 970
@@ -933,12 +973,12 @@ static void lcd_clear_fast_tilcd(void)
933{ 973{
934 int pos; 974 int pos;
935 975
936 lcd_addr_x = 0; 976 lcd.addr.x = 0;
937 lcd_addr_y = 0; 977 lcd.addr.y = 0;
938 lcd_gotoxy(); 978 lcd_gotoxy();
939 979
940 spin_lock_irq(&pprt_lock); 980 spin_lock_irq(&pprt_lock);
941 for (pos = 0; pos < lcd_height * lcd_hwidth; pos++) { 981 for (pos = 0; pos < lcd.height * lcd.hwidth; pos++) {
942 /* present the data to the data port */ 982 /* present the data to the data port */
943 w_dtr(pprt, ' '); 983 w_dtr(pprt, ' ');
944 udelay(60); 984 udelay(60);
@@ -946,8 +986,8 @@ static void lcd_clear_fast_tilcd(void)
946 986
947 spin_unlock_irq(&pprt_lock); 987 spin_unlock_irq(&pprt_lock);
948 988
949 lcd_addr_x = 0; 989 lcd.addr.x = 0;
950 lcd_addr_y = 0; 990 lcd.addr.y = 0;
951 lcd_gotoxy(); 991 lcd_gotoxy();
952} 992}
953 993
@@ -955,15 +995,15 @@ static void lcd_clear_fast_tilcd(void)
955static void lcd_clear_display(void) 995static void lcd_clear_display(void)
956{ 996{
957 lcd_write_cmd(0x01); /* clear display */ 997 lcd_write_cmd(0x01); /* clear display */
958 lcd_addr_x = 0; 998 lcd.addr.x = 0;
959 lcd_addr_y = 0; 999 lcd.addr.y = 0;
960 /* we must wait a few milliseconds (15) */ 1000 /* we must wait a few milliseconds (15) */
961 long_sleep(15); 1001 long_sleep(15);
962} 1002}
963 1003
964static void lcd_init_display(void) 1004static void lcd_init_display(void)
965{ 1005{
966 lcd_flags = ((lcd_height > 1) ? LCD_FLAG_N : 0) 1006 lcd.flags = ((lcd.height > 1) ? LCD_FLAG_N : 0)
967 | LCD_FLAG_D | LCD_FLAG_C | LCD_FLAG_B; 1007 | LCD_FLAG_D | LCD_FLAG_C | LCD_FLAG_B;
968 1008
969 long_sleep(20); /* wait 20 ms after power-up for the paranoid */ 1009 long_sleep(20); /* wait 20 ms after power-up for the paranoid */
@@ -976,8 +1016,8 @@ static void lcd_init_display(void)
976 long_sleep(10); 1016 long_sleep(10);
977 1017
978 lcd_write_cmd(0x30 /* set font height and lines number */ 1018 lcd_write_cmd(0x30 /* set font height and lines number */
979 | ((lcd_flags & LCD_FLAG_F) ? 4 : 0) 1019 | ((lcd.flags & LCD_FLAG_F) ? 4 : 0)
980 | ((lcd_flags & LCD_FLAG_N) ? 8 : 0) 1020 | ((lcd.flags & LCD_FLAG_N) ? 8 : 0)
981 ); 1021 );
982 long_sleep(10); 1022 long_sleep(10);
983 1023
@@ -985,12 +1025,12 @@ static void lcd_init_display(void)
985 long_sleep(10); 1025 long_sleep(10);
986 1026
987 lcd_write_cmd(0x08 /* set display mode */ 1027 lcd_write_cmd(0x08 /* set display mode */
988 | ((lcd_flags & LCD_FLAG_D) ? 4 : 0) 1028 | ((lcd.flags & LCD_FLAG_D) ? 4 : 0)
989 | ((lcd_flags & LCD_FLAG_C) ? 2 : 0) 1029 | ((lcd.flags & LCD_FLAG_C) ? 2 : 0)
990 | ((lcd_flags & LCD_FLAG_B) ? 1 : 0) 1030 | ((lcd.flags & LCD_FLAG_B) ? 1 : 0)
991 ); 1031 );
992 1032
993 lcd_backlight((lcd_flags & LCD_FLAG_L) ? 1 : 0); 1033 lcd_backlight((lcd.flags & LCD_FLAG_L) ? 1 : 0);
994 1034
995 long_sleep(10); 1035 long_sleep(10);
996 1036
@@ -1013,100 +1053,101 @@ static inline int handle_lcd_special_code(void)
1013 1053
1014 int processed = 0; 1054 int processed = 0;
1015 1055
1016 char *esc = lcd_escape + 2; 1056 char *esc = lcd.esc_seq.buf + 2;
1017 int oldflags = lcd_flags; 1057 int oldflags = lcd.flags;
1018 1058
1019 /* check for display mode flags */ 1059 /* check for display mode flags */
1020 switch (*esc) { 1060 switch (*esc) {
1021 case 'D': /* Display ON */ 1061 case 'D': /* Display ON */
1022 lcd_flags |= LCD_FLAG_D; 1062 lcd.flags |= LCD_FLAG_D;
1023 processed = 1; 1063 processed = 1;
1024 break; 1064 break;
1025 case 'd': /* Display OFF */ 1065 case 'd': /* Display OFF */
1026 lcd_flags &= ~LCD_FLAG_D; 1066 lcd.flags &= ~LCD_FLAG_D;
1027 processed = 1; 1067 processed = 1;
1028 break; 1068 break;
1029 case 'C': /* Cursor ON */ 1069 case 'C': /* Cursor ON */
1030 lcd_flags |= LCD_FLAG_C; 1070 lcd.flags |= LCD_FLAG_C;
1031 processed = 1; 1071 processed = 1;
1032 break; 1072 break;
1033 case 'c': /* Cursor OFF */ 1073 case 'c': /* Cursor OFF */
1034 lcd_flags &= ~LCD_FLAG_C; 1074 lcd.flags &= ~LCD_FLAG_C;
1035 processed = 1; 1075 processed = 1;
1036 break; 1076 break;
1037 case 'B': /* Blink ON */ 1077 case 'B': /* Blink ON */
1038 lcd_flags |= LCD_FLAG_B; 1078 lcd.flags |= LCD_FLAG_B;
1039 processed = 1; 1079 processed = 1;
1040 break; 1080 break;
1041 case 'b': /* Blink OFF */ 1081 case 'b': /* Blink OFF */
1042 lcd_flags &= ~LCD_FLAG_B; 1082 lcd.flags &= ~LCD_FLAG_B;
1043 processed = 1; 1083 processed = 1;
1044 break; 1084 break;
1045 case '+': /* Back light ON */ 1085 case '+': /* Back light ON */
1046 lcd_flags |= LCD_FLAG_L; 1086 lcd.flags |= LCD_FLAG_L;
1047 processed = 1; 1087 processed = 1;
1048 break; 1088 break;
1049 case '-': /* Back light OFF */ 1089 case '-': /* Back light OFF */
1050 lcd_flags &= ~LCD_FLAG_L; 1090 lcd.flags &= ~LCD_FLAG_L;
1051 processed = 1; 1091 processed = 1;
1052 break; 1092 break;
1053 case '*': 1093 case '*':
1054 /* flash back light using the keypad timer */ 1094 /* flash back light using the keypad timer */
1055 if (scan_timer.function != NULL) { 1095 if (scan_timer.function != NULL) {
1056 if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0)) 1096 if (lcd.light_tempo == 0
1097 && ((lcd.flags & LCD_FLAG_L) == 0))
1057 lcd_backlight(1); 1098 lcd_backlight(1);
1058 light_tempo = FLASH_LIGHT_TEMPO; 1099 lcd.light_tempo = FLASH_LIGHT_TEMPO;
1059 } 1100 }
1060 processed = 1; 1101 processed = 1;
1061 break; 1102 break;
1062 case 'f': /* Small Font */ 1103 case 'f': /* Small Font */
1063 lcd_flags &= ~LCD_FLAG_F; 1104 lcd.flags &= ~LCD_FLAG_F;
1064 processed = 1; 1105 processed = 1;
1065 break; 1106 break;
1066 case 'F': /* Large Font */ 1107 case 'F': /* Large Font */
1067 lcd_flags |= LCD_FLAG_F; 1108 lcd.flags |= LCD_FLAG_F;
1068 processed = 1; 1109 processed = 1;
1069 break; 1110 break;
1070 case 'n': /* One Line */ 1111 case 'n': /* One Line */
1071 lcd_flags &= ~LCD_FLAG_N; 1112 lcd.flags &= ~LCD_FLAG_N;
1072 processed = 1; 1113 processed = 1;
1073 break; 1114 break;
1074 case 'N': /* Two Lines */ 1115 case 'N': /* Two Lines */
1075 lcd_flags |= LCD_FLAG_N; 1116 lcd.flags |= LCD_FLAG_N;
1076 break; 1117 break;
1077 case 'l': /* Shift Cursor Left */ 1118 case 'l': /* Shift Cursor Left */
1078 if (lcd_addr_x > 0) { 1119 if (lcd.addr.x > 0) {
1079 /* back one char if not at end of line */ 1120 /* back one char if not at end of line */
1080 if (lcd_addr_x < lcd_bwidth) 1121 if (lcd.addr.x < lcd.bwidth)
1081 lcd_write_cmd(0x10); 1122 lcd_write_cmd(0x10);
1082 lcd_addr_x--; 1123 lcd.addr.x--;
1083 } 1124 }
1084 processed = 1; 1125 processed = 1;
1085 break; 1126 break;
1086 case 'r': /* shift cursor right */ 1127 case 'r': /* shift cursor right */
1087 if (lcd_addr_x < lcd_width) { 1128 if (lcd.addr.x < lcd.width) {
1088 /* allow the cursor to pass the end of the line */ 1129 /* allow the cursor to pass the end of the line */
1089 if (lcd_addr_x < 1130 if (lcd.addr.x <
1090 (lcd_bwidth - 1)) 1131 (lcd.bwidth - 1))
1091 lcd_write_cmd(0x14); 1132 lcd_write_cmd(0x14);
1092 lcd_addr_x++; 1133 lcd.addr.x++;
1093 } 1134 }
1094 processed = 1; 1135 processed = 1;
1095 break; 1136 break;
1096 case 'L': /* shift display left */ 1137 case 'L': /* shift display left */
1097 lcd_left_shift++; 1138 lcd.left_shift++;
1098 lcd_write_cmd(0x18); 1139 lcd_write_cmd(0x18);
1099 processed = 1; 1140 processed = 1;
1100 break; 1141 break;
1101 case 'R': /* shift display right */ 1142 case 'R': /* shift display right */
1102 lcd_left_shift--; 1143 lcd.left_shift--;
1103 lcd_write_cmd(0x1C); 1144 lcd_write_cmd(0x1C);
1104 processed = 1; 1145 processed = 1;
1105 break; 1146 break;
1106 case 'k': { /* kill end of line */ 1147 case 'k': { /* kill end of line */
1107 int x; 1148 int x;
1108 1149
1109 for (x = lcd_addr_x; x < lcd_bwidth; x++) 1150 for (x = lcd.addr.x; x < lcd.bwidth; x++)
1110 lcd_write_data(' '); 1151 lcd_write_data(' ');
1111 1152
1112 /* restore cursor position */ 1153 /* restore cursor position */
@@ -1116,7 +1157,7 @@ static inline int handle_lcd_special_code(void)
1116 } 1157 }
1117 case 'I': /* reinitialize display */ 1158 case 'I': /* reinitialize display */
1118 lcd_init_display(); 1159 lcd_init_display();
1119 lcd_left_shift = 0; 1160 lcd.left_shift = 0;
1120 processed = 1; 1161 processed = 1;
1121 break; 1162 break;
1122 case 'G': { 1163 case 'G': {
@@ -1187,11 +1228,11 @@ static inline int handle_lcd_special_code(void)
1187 while (*esc) { 1228 while (*esc) {
1188 if (*esc == 'x') { 1229 if (*esc == 'x') {
1189 esc++; 1230 esc++;
1190 if (kstrtoul(esc, 10, &lcd_addr_x) < 0) 1231 if (kstrtoul(esc, 10, &lcd.addr.x) < 0)
1191 break; 1232 break;
1192 } else if (*esc == 'y') { 1233 } else if (*esc == 'y') {
1193 esc++; 1234 esc++;
1194 if (kstrtoul(esc, 10, &lcd_addr_y) < 0) 1235 if (kstrtoul(esc, 10, &lcd.addr.y) < 0)
1195 break; 1236 break;
1196 } else { 1237 } else {
1197 break; 1238 break;
@@ -1204,25 +1245,25 @@ static inline int handle_lcd_special_code(void)
1204 } 1245 }
1205 1246
1206 /* Check whether one flag was changed */ 1247 /* Check whether one flag was changed */
1207 if (oldflags != lcd_flags) { 1248 if (oldflags != lcd.flags) {
1208 /* check whether one of B,C,D flags were changed */ 1249 /* check whether one of B,C,D flags were changed */
1209 if ((oldflags ^ lcd_flags) & 1250 if ((oldflags ^ lcd.flags) &
1210 (LCD_FLAG_B | LCD_FLAG_C | LCD_FLAG_D)) 1251 (LCD_FLAG_B | LCD_FLAG_C | LCD_FLAG_D))
1211 /* set display mode */ 1252 /* set display mode */
1212 lcd_write_cmd(0x08 1253 lcd_write_cmd(0x08
1213 | ((lcd_flags & LCD_FLAG_D) ? 4 : 0) 1254 | ((lcd.flags & LCD_FLAG_D) ? 4 : 0)
1214 | ((lcd_flags & LCD_FLAG_C) ? 2 : 0) 1255 | ((lcd.flags & LCD_FLAG_C) ? 2 : 0)
1215 | ((lcd_flags & LCD_FLAG_B) ? 1 : 0)); 1256 | ((lcd.flags & LCD_FLAG_B) ? 1 : 0));
1216 /* check whether one of F,N flags was changed */ 1257 /* check whether one of F,N flags was changed */
1217 else if ((oldflags ^ lcd_flags) & (LCD_FLAG_F | LCD_FLAG_N)) 1258 else if ((oldflags ^ lcd.flags) & (LCD_FLAG_F | LCD_FLAG_N))
1218 lcd_write_cmd(0x30 1259 lcd_write_cmd(0x30
1219 | ((lcd_flags & LCD_FLAG_F) ? 4 : 0) 1260 | ((lcd.flags & LCD_FLAG_F) ? 4 : 0)
1220 | ((lcd_flags & LCD_FLAG_N) ? 8 : 0)); 1261 | ((lcd.flags & LCD_FLAG_N) ? 8 : 0));
1221 /* check whether L flag was changed */ 1262 /* check whether L flag was changed */
1222 else if ((oldflags ^ lcd_flags) & (LCD_FLAG_L)) { 1263 else if ((oldflags ^ lcd.flags) & (LCD_FLAG_L)) {
1223 if (lcd_flags & (LCD_FLAG_L)) 1264 if (lcd.flags & (LCD_FLAG_L))
1224 lcd_backlight(1); 1265 lcd_backlight(1);
1225 else if (light_tempo == 0) 1266 else if (lcd.light_tempo == 0)
1226 /* switch off the light only when the tempo 1267 /* switch off the light only when the tempo
1227 lighting is gone */ 1268 lighting is gone */
1228 lcd_backlight(0); 1269 lcd_backlight(0);
@@ -1235,29 +1276,29 @@ static inline int handle_lcd_special_code(void)
1235static void lcd_write_char(char c) 1276static void lcd_write_char(char c)
1236{ 1277{
1237 /* first, we'll test if we're in escape mode */ 1278 /* first, we'll test if we're in escape mode */
1238 if ((c != '\n') && lcd_escape_len >= 0) { 1279 if ((c != '\n') && lcd.esc_seq.len >= 0) {
1239 /* yes, let's add this char to the buffer */ 1280 /* yes, let's add this char to the buffer */
1240 lcd_escape[lcd_escape_len++] = c; 1281 lcd.esc_seq.buf[lcd.esc_seq.len++] = c;
1241 lcd_escape[lcd_escape_len] = 0; 1282 lcd.esc_seq.buf[lcd.esc_seq.len] = 0;
1242 } else { 1283 } else {
1243 /* aborts any previous escape sequence */ 1284 /* aborts any previous escape sequence */
1244 lcd_escape_len = -1; 1285 lcd.esc_seq.len = -1;
1245 1286
1246 switch (c) { 1287 switch (c) {
1247 case LCD_ESCAPE_CHAR: 1288 case LCD_ESCAPE_CHAR:
1248 /* start of an escape sequence */ 1289 /* start of an escape sequence */
1249 lcd_escape_len = 0; 1290 lcd.esc_seq.len = 0;
1250 lcd_escape[lcd_escape_len] = 0; 1291 lcd.esc_seq.buf[lcd.esc_seq.len] = 0;
1251 break; 1292 break;
1252 case '\b': 1293 case '\b':
1253 /* go back one char and clear it */ 1294 /* go back one char and clear it */
1254 if (lcd_addr_x > 0) { 1295 if (lcd.addr.x > 0) {
1255 /* check if we're not at the 1296 /* check if we're not at the
1256 end of the line */ 1297 end of the line */
1257 if (lcd_addr_x < lcd_bwidth) 1298 if (lcd.addr.x < lcd.bwidth)
1258 /* back one char */ 1299 /* back one char */
1259 lcd_write_cmd(0x10); 1300 lcd_write_cmd(0x10);
1260 lcd_addr_x--; 1301 lcd.addr.x--;
1261 } 1302 }
1262 /* replace with a space */ 1303 /* replace with a space */
1263 lcd_write_data(' '); 1304 lcd_write_data(' ');
@@ -1271,15 +1312,15 @@ static void lcd_write_char(char c)
1271 case '\n': 1312 case '\n':
1272 /* flush the remainder of the current line and 1313 /* flush the remainder of the current line and
1273 go to the beginning of the next line */ 1314 go to the beginning of the next line */
1274 for (; lcd_addr_x < lcd_bwidth; lcd_addr_x++) 1315 for (; lcd.addr.x < lcd.bwidth; lcd.addr.x++)
1275 lcd_write_data(' '); 1316 lcd_write_data(' ');
1276 lcd_addr_x = 0; 1317 lcd.addr.x = 0;
1277 lcd_addr_y = (lcd_addr_y + 1) % lcd_height; 1318 lcd.addr.y = (lcd.addr.y + 1) % lcd.height;
1278 lcd_gotoxy(); 1319 lcd_gotoxy();
1279 break; 1320 break;
1280 case '\r': 1321 case '\r':
1281 /* go to the beginning of the same line */ 1322 /* go to the beginning of the same line */
1282 lcd_addr_x = 0; 1323 lcd.addr.x = 0;
1283 lcd_gotoxy(); 1324 lcd_gotoxy();
1284 break; 1325 break;
1285 case '\t': 1326 case '\t':
@@ -1295,32 +1336,32 @@ static void lcd_write_char(char c)
1295 1336
1296 /* now we'll see if we're in an escape mode and if the current 1337 /* now we'll see if we're in an escape mode and if the current
1297 escape sequence can be understood. */ 1338 escape sequence can be understood. */
1298 if (lcd_escape_len >= 2) { 1339 if (lcd.esc_seq.len >= 2) {
1299 int processed = 0; 1340 int processed = 0;
1300 1341
1301 if (!strcmp(lcd_escape, "[2J")) { 1342 if (!strcmp(lcd.esc_seq.buf, "[2J")) {
1302 /* clear the display */ 1343 /* clear the display */
1303 lcd_clear_fast(); 1344 lcd_clear_fast();
1304 processed = 1; 1345 processed = 1;
1305 } else if (!strcmp(lcd_escape, "[H")) { 1346 } else if (!strcmp(lcd.esc_seq.buf, "[H")) {
1306 /* cursor to home */ 1347 /* cursor to home */
1307 lcd_addr_x = 0; 1348 lcd.addr.x = 0;
1308 lcd_addr_y = 0; 1349 lcd.addr.y = 0;
1309 lcd_gotoxy(); 1350 lcd_gotoxy();
1310 processed = 1; 1351 processed = 1;
1311 } 1352 }
1312 /* codes starting with ^[[L */ 1353 /* codes starting with ^[[L */
1313 else if ((lcd_escape_len >= 3) && 1354 else if ((lcd.esc_seq.len >= 3) &&
1314 (lcd_escape[0] == '[') && 1355 (lcd.esc_seq.buf[0] == '[') &&
1315 (lcd_escape[1] == 'L')) { 1356 (lcd.esc_seq.buf[1] == 'L')) {
1316 processed = handle_lcd_special_code(); 1357 processed = handle_lcd_special_code();
1317 } 1358 }
1318 1359
1319 /* LCD special escape codes */ 1360 /* LCD special escape codes */
1320 /* flush the escape sequence if it's been processed 1361 /* flush the escape sequence if it's been processed
1321 or if it is getting too long. */ 1362 or if it is getting too long. */
1322 if (processed || (lcd_escape_len >= LCD_ESCAPE_LEN)) 1363 if (processed || (lcd.esc_seq.len >= LCD_ESCAPE_LEN))
1323 lcd_escape_len = -1; 1364 lcd.esc_seq.len = -1;
1324 } /* escape codes */ 1365 } /* escape codes */
1325} 1366}
1326 1367
@@ -1347,23 +1388,22 @@ static ssize_t lcd_write(struct file *file,
1347 1388
1348static int lcd_open(struct inode *inode, struct file *file) 1389static int lcd_open(struct inode *inode, struct file *file)
1349{ 1390{
1350 if (lcd_open_cnt) 1391 if (!atomic_dec_and_test(&lcd_available))
1351 return -EBUSY; /* open only once at a time */ 1392 return -EBUSY; /* open only once at a time */
1352 1393
1353 if (file->f_mode & FMODE_READ) /* device is write-only */ 1394 if (file->f_mode & FMODE_READ) /* device is write-only */
1354 return -EPERM; 1395 return -EPERM;
1355 1396
1356 if (lcd_must_clear) { 1397 if (lcd.must_clear) {
1357 lcd_clear_display(); 1398 lcd_clear_display();
1358 lcd_must_clear = 0; 1399 lcd.must_clear = false;
1359 } 1400 }
1360 lcd_open_cnt++;
1361 return nonseekable_open(inode, file); 1401 return nonseekable_open(inode, file);
1362} 1402}
1363 1403
1364static int lcd_release(struct inode *inode, struct file *file) 1404static int lcd_release(struct inode *inode, struct file *file)
1365{ 1405{
1366 lcd_open_cnt--; 1406 atomic_inc(&lcd_available);
1367 return 0; 1407 return 0;
1368} 1408}
1369 1409
@@ -1375,9 +1415,9 @@ static const struct file_operations lcd_fops = {
1375}; 1415};
1376 1416
1377static struct miscdevice lcd_dev = { 1417static struct miscdevice lcd_dev = {
1378 LCD_MINOR, 1418 .minor = LCD_MINOR,
1379 "lcd", 1419 .name = "lcd",
1380 &lcd_fops 1420 .fops = &lcd_fops,
1381}; 1421};
1382 1422
1383/* public function usable from the kernel for any purpose */ 1423/* public function usable from the kernel for any purpose */
@@ -1386,7 +1426,7 @@ static void panel_lcd_print(const char *s)
1386 const char *tmp = s; 1426 const char *tmp = s;
1387 int count = strlen(s); 1427 int count = strlen(s);
1388 1428
1389 if (lcd_enabled && lcd_initialized) { 1429 if (lcd.enabled && lcd.initialized) {
1390 for (; count-- > 0; tmp++) { 1430 for (; count-- > 0; tmp++) {
1391 if (!in_interrupt() && (((count + 1) & 0x1f) == 0)) 1431 if (!in_interrupt() && (((count + 1) & 0x1f) == 0))
1392 /* let's be a little nice with other processes 1432 /* let's be a little nice with other processes
@@ -1401,183 +1441,173 @@ static void panel_lcd_print(const char *s)
1401/* initialize the LCD driver */ 1441/* initialize the LCD driver */
1402static void lcd_init(void) 1442static void lcd_init(void)
1403{ 1443{
1404 switch (lcd_type) { 1444 switch (selected_lcd_type) {
1405 case LCD_TYPE_OLD: 1445 case LCD_TYPE_OLD:
1406 /* parallel mode, 8 bits */ 1446 /* parallel mode, 8 bits */
1407 if (lcd_proto < 0) 1447 lcd.proto = LCD_PROTO_PARALLEL;
1408 lcd_proto = LCD_PROTO_PARALLEL; 1448 lcd.charset = LCD_CHARSET_NORMAL;
1409 if (lcd_charset < 0) 1449 lcd.pins.e = PIN_STROBE;
1410 lcd_charset = LCD_CHARSET_NORMAL; 1450 lcd.pins.rs = PIN_AUTOLF;
1411 if (lcd_e_pin == PIN_NOT_SET) 1451
1412 lcd_e_pin = PIN_STROBE; 1452 lcd.width = 40;
1413 if (lcd_rs_pin == PIN_NOT_SET) 1453 lcd.bwidth = 40;
1414 lcd_rs_pin = PIN_AUTOLF; 1454 lcd.hwidth = 64;
1415 1455 lcd.height = 2;
1416 if (lcd_width < 0)
1417 lcd_width = 40;
1418 if (lcd_bwidth < 0)
1419 lcd_bwidth = 40;
1420 if (lcd_hwidth < 0)
1421 lcd_hwidth = 64;
1422 if (lcd_height < 0)
1423 lcd_height = 2;
1424 break; 1456 break;
1425 case LCD_TYPE_KS0074: 1457 case LCD_TYPE_KS0074:
1426 /* serial mode, ks0074 */ 1458 /* serial mode, ks0074 */
1427 if (lcd_proto < 0) 1459 lcd.proto = LCD_PROTO_SERIAL;
1428 lcd_proto = LCD_PROTO_SERIAL; 1460 lcd.charset = LCD_CHARSET_KS0074;
1429 if (lcd_charset < 0) 1461 lcd.pins.bl = PIN_AUTOLF;
1430 lcd_charset = LCD_CHARSET_KS0074; 1462 lcd.pins.cl = PIN_STROBE;
1431 if (lcd_bl_pin == PIN_NOT_SET) 1463 lcd.pins.da = PIN_D0;
1432 lcd_bl_pin = PIN_AUTOLF; 1464
1433 if (lcd_cl_pin == PIN_NOT_SET) 1465 lcd.width = 16;
1434 lcd_cl_pin = PIN_STROBE; 1466 lcd.bwidth = 40;
1435 if (lcd_da_pin == PIN_NOT_SET) 1467 lcd.hwidth = 16;
1436 lcd_da_pin = PIN_D0; 1468 lcd.height = 2;
1437
1438 if (lcd_width < 0)
1439 lcd_width = 16;
1440 if (lcd_bwidth < 0)
1441 lcd_bwidth = 40;
1442 if (lcd_hwidth < 0)
1443 lcd_hwidth = 16;
1444 if (lcd_height < 0)
1445 lcd_height = 2;
1446 break; 1469 break;
1447 case LCD_TYPE_NEXCOM: 1470 case LCD_TYPE_NEXCOM:
1448 /* parallel mode, 8 bits, generic */ 1471 /* parallel mode, 8 bits, generic */
1449 if (lcd_proto < 0) 1472 lcd.proto = LCD_PROTO_PARALLEL;
1450 lcd_proto = LCD_PROTO_PARALLEL; 1473 lcd.charset = LCD_CHARSET_NORMAL;
1451 if (lcd_charset < 0) 1474 lcd.pins.e = PIN_AUTOLF;
1452 lcd_charset = LCD_CHARSET_NORMAL; 1475 lcd.pins.rs = PIN_SELECP;
1453 if (lcd_e_pin == PIN_NOT_SET) 1476 lcd.pins.rw = PIN_INITP;
1454 lcd_e_pin = PIN_AUTOLF; 1477
1455 if (lcd_rs_pin == PIN_NOT_SET) 1478 lcd.width = 16;
1456 lcd_rs_pin = PIN_SELECP; 1479 lcd.bwidth = 40;
1457 if (lcd_rw_pin == PIN_NOT_SET) 1480 lcd.hwidth = 64;
1458 lcd_rw_pin = PIN_INITP; 1481 lcd.height = 2;
1459
1460 if (lcd_width < 0)
1461 lcd_width = 16;
1462 if (lcd_bwidth < 0)
1463 lcd_bwidth = 40;
1464 if (lcd_hwidth < 0)
1465 lcd_hwidth = 64;
1466 if (lcd_height < 0)
1467 lcd_height = 2;
1468 break; 1482 break;
1469 case LCD_TYPE_CUSTOM: 1483 case LCD_TYPE_CUSTOM:
1470 /* customer-defined */ 1484 /* customer-defined */
1471 if (lcd_proto < 0) 1485 lcd.proto = DEFAULT_LCD_PROTO;
1472 lcd_proto = DEFAULT_LCD_PROTO; 1486 lcd.charset = DEFAULT_LCD_CHARSET;
1473 if (lcd_charset < 0)
1474 lcd_charset = DEFAULT_LCD_CHARSET;
1475 /* default geometry will be set later */ 1487 /* default geometry will be set later */
1476 break; 1488 break;
1477 case LCD_TYPE_HANTRONIX: 1489 case LCD_TYPE_HANTRONIX:
1478 /* parallel mode, 8 bits, hantronix-like */ 1490 /* parallel mode, 8 bits, hantronix-like */
1479 default: 1491 default:
1480 if (lcd_proto < 0) 1492 lcd.proto = LCD_PROTO_PARALLEL;
1481 lcd_proto = LCD_PROTO_PARALLEL; 1493 lcd.charset = LCD_CHARSET_NORMAL;
1482 if (lcd_charset < 0) 1494 lcd.pins.e = PIN_STROBE;
1483 lcd_charset = LCD_CHARSET_NORMAL; 1495 lcd.pins.rs = PIN_SELECP;
1484 if (lcd_e_pin == PIN_NOT_SET) 1496
1485 lcd_e_pin = PIN_STROBE; 1497 lcd.width = 16;
1486 if (lcd_rs_pin == PIN_NOT_SET) 1498 lcd.bwidth = 40;
1487 lcd_rs_pin = PIN_SELECP; 1499 lcd.hwidth = 64;
1488 1500 lcd.height = 2;
1489 if (lcd_width < 0)
1490 lcd_width = 16;
1491 if (lcd_bwidth < 0)
1492 lcd_bwidth = 40;
1493 if (lcd_hwidth < 0)
1494 lcd_hwidth = 64;
1495 if (lcd_height < 0)
1496 lcd_height = 2;
1497 break; 1501 break;
1498 } 1502 }
1499 1503
1504 /* Overwrite with module params set on loading */
1505 if (lcd_height != NOT_SET)
1506 lcd.height = lcd_height;
1507 if (lcd_width != NOT_SET)
1508 lcd.width = lcd_width;
1509 if (lcd_bwidth != NOT_SET)
1510 lcd.bwidth = lcd_bwidth;
1511 if (lcd_hwidth != NOT_SET)
1512 lcd.hwidth = lcd_hwidth;
1513 if (lcd_charset != NOT_SET)
1514 lcd.charset = lcd_charset;
1515 if (lcd_proto != NOT_SET)
1516 lcd.proto = lcd_proto;
1517 if (lcd_e_pin != PIN_NOT_SET)
1518 lcd.pins.e = lcd_e_pin;
1519 if (lcd_rs_pin != PIN_NOT_SET)
1520 lcd.pins.rs = lcd_rs_pin;
1521 if (lcd_rw_pin != PIN_NOT_SET)
1522 lcd.pins.rw = lcd_rw_pin;
1523 if (lcd_cl_pin != PIN_NOT_SET)
1524 lcd.pins.cl = lcd_cl_pin;
1525 if (lcd_da_pin != PIN_NOT_SET)
1526 lcd.pins.da = lcd_da_pin;
1527 if (lcd_bl_pin != PIN_NOT_SET)
1528 lcd.pins.bl = lcd_bl_pin;
1529
1500 /* this is used to catch wrong and default values */ 1530 /* this is used to catch wrong and default values */
1501 if (lcd_width <= 0) 1531 if (lcd.width <= 0)
1502 lcd_width = DEFAULT_LCD_WIDTH; 1532 lcd.width = DEFAULT_LCD_WIDTH;
1503 if (lcd_bwidth <= 0) 1533 if (lcd.bwidth <= 0)
1504 lcd_bwidth = DEFAULT_LCD_BWIDTH; 1534 lcd.bwidth = DEFAULT_LCD_BWIDTH;
1505 if (lcd_hwidth <= 0) 1535 if (lcd.hwidth <= 0)
1506 lcd_hwidth = DEFAULT_LCD_HWIDTH; 1536 lcd.hwidth = DEFAULT_LCD_HWIDTH;
1507 if (lcd_height <= 0) 1537 if (lcd.height <= 0)
1508 lcd_height = DEFAULT_LCD_HEIGHT; 1538 lcd.height = DEFAULT_LCD_HEIGHT;
1509 1539
1510 if (lcd_proto == LCD_PROTO_SERIAL) { /* SERIAL */ 1540 if (lcd.proto == LCD_PROTO_SERIAL) { /* SERIAL */
1511 lcd_write_cmd = lcd_write_cmd_s; 1541 lcd_write_cmd = lcd_write_cmd_s;
1512 lcd_write_data = lcd_write_data_s; 1542 lcd_write_data = lcd_write_data_s;
1513 lcd_clear_fast = lcd_clear_fast_s; 1543 lcd_clear_fast = lcd_clear_fast_s;
1514 1544
1515 if (lcd_cl_pin == PIN_NOT_SET) 1545 if (lcd.pins.cl == PIN_NOT_SET)
1516 lcd_cl_pin = DEFAULT_LCD_PIN_SCL; 1546 lcd.pins.cl = DEFAULT_LCD_PIN_SCL;
1517 if (lcd_da_pin == PIN_NOT_SET) 1547 if (lcd.pins.da == PIN_NOT_SET)
1518 lcd_da_pin = DEFAULT_LCD_PIN_SDA; 1548 lcd.pins.da = DEFAULT_LCD_PIN_SDA;
1519 1549
1520 } else if (lcd_proto == LCD_PROTO_PARALLEL) { /* PARALLEL */ 1550 } else if (lcd.proto == LCD_PROTO_PARALLEL) { /* PARALLEL */
1521 lcd_write_cmd = lcd_write_cmd_p8; 1551 lcd_write_cmd = lcd_write_cmd_p8;
1522 lcd_write_data = lcd_write_data_p8; 1552 lcd_write_data = lcd_write_data_p8;
1523 lcd_clear_fast = lcd_clear_fast_p8; 1553 lcd_clear_fast = lcd_clear_fast_p8;
1524 1554
1525 if (lcd_e_pin == PIN_NOT_SET) 1555 if (lcd.pins.e == PIN_NOT_SET)
1526 lcd_e_pin = DEFAULT_LCD_PIN_E; 1556 lcd.pins.e = DEFAULT_LCD_PIN_E;
1527 if (lcd_rs_pin == PIN_NOT_SET) 1557 if (lcd.pins.rs == PIN_NOT_SET)
1528 lcd_rs_pin = DEFAULT_LCD_PIN_RS; 1558 lcd.pins.rs = DEFAULT_LCD_PIN_RS;
1529 if (lcd_rw_pin == PIN_NOT_SET) 1559 if (lcd.pins.rw == PIN_NOT_SET)
1530 lcd_rw_pin = DEFAULT_LCD_PIN_RW; 1560 lcd.pins.rw = DEFAULT_LCD_PIN_RW;
1531 } else { 1561 } else {
1532 lcd_write_cmd = lcd_write_cmd_tilcd; 1562 lcd_write_cmd = lcd_write_cmd_tilcd;
1533 lcd_write_data = lcd_write_data_tilcd; 1563 lcd_write_data = lcd_write_data_tilcd;
1534 lcd_clear_fast = lcd_clear_fast_tilcd; 1564 lcd_clear_fast = lcd_clear_fast_tilcd;
1535 } 1565 }
1536 1566
1537 if (lcd_bl_pin == PIN_NOT_SET) 1567 if (lcd.pins.bl == PIN_NOT_SET)
1538 lcd_bl_pin = DEFAULT_LCD_PIN_BL; 1568 lcd.pins.bl = DEFAULT_LCD_PIN_BL;
1539 1569
1540 if (lcd_e_pin == PIN_NOT_SET) 1570 if (lcd.pins.e == PIN_NOT_SET)
1541 lcd_e_pin = PIN_NONE; 1571 lcd.pins.e = PIN_NONE;
1542 if (lcd_rs_pin == PIN_NOT_SET) 1572 if (lcd.pins.rs == PIN_NOT_SET)
1543 lcd_rs_pin = PIN_NONE; 1573 lcd.pins.rs = PIN_NONE;
1544 if (lcd_rw_pin == PIN_NOT_SET) 1574 if (lcd.pins.rw == PIN_NOT_SET)
1545 lcd_rw_pin = PIN_NONE; 1575 lcd.pins.rw = PIN_NONE;
1546 if (lcd_bl_pin == PIN_NOT_SET) 1576 if (lcd.pins.bl == PIN_NOT_SET)
1547 lcd_bl_pin = PIN_NONE; 1577 lcd.pins.bl = PIN_NONE;
1548 if (lcd_cl_pin == PIN_NOT_SET) 1578 if (lcd.pins.cl == PIN_NOT_SET)
1549 lcd_cl_pin = PIN_NONE; 1579 lcd.pins.cl = PIN_NONE;
1550 if (lcd_da_pin == PIN_NOT_SET) 1580 if (lcd.pins.da == PIN_NOT_SET)
1551 lcd_da_pin = PIN_NONE; 1581 lcd.pins.da = PIN_NONE;
1552 1582
1553 if (lcd_charset < 0) 1583 if (lcd.charset == NOT_SET)
1554 lcd_charset = DEFAULT_LCD_CHARSET; 1584 lcd.charset = DEFAULT_LCD_CHARSET;
1555 1585
1556 if (lcd_charset == LCD_CHARSET_KS0074) 1586 if (lcd.charset == LCD_CHARSET_KS0074)
1557 lcd_char_conv = lcd_char_conv_ks0074; 1587 lcd_char_conv = lcd_char_conv_ks0074;
1558 else 1588 else
1559 lcd_char_conv = NULL; 1589 lcd_char_conv = NULL;
1560 1590
1561 if (lcd_bl_pin != PIN_NONE) 1591 if (lcd.pins.bl != PIN_NONE)
1562 init_scan_timer(); 1592 init_scan_timer();
1563 1593
1564 pin_to_bits(lcd_e_pin, lcd_bits[LCD_PORT_D][LCD_BIT_E], 1594 pin_to_bits(lcd.pins.e, lcd_bits[LCD_PORT_D][LCD_BIT_E],
1565 lcd_bits[LCD_PORT_C][LCD_BIT_E]); 1595 lcd_bits[LCD_PORT_C][LCD_BIT_E]);
1566 pin_to_bits(lcd_rs_pin, lcd_bits[LCD_PORT_D][LCD_BIT_RS], 1596 pin_to_bits(lcd.pins.rs, lcd_bits[LCD_PORT_D][LCD_BIT_RS],
1567 lcd_bits[LCD_PORT_C][LCD_BIT_RS]); 1597 lcd_bits[LCD_PORT_C][LCD_BIT_RS]);
1568 pin_to_bits(lcd_rw_pin, lcd_bits[LCD_PORT_D][LCD_BIT_RW], 1598 pin_to_bits(lcd.pins.rw, lcd_bits[LCD_PORT_D][LCD_BIT_RW],
1569 lcd_bits[LCD_PORT_C][LCD_BIT_RW]); 1599 lcd_bits[LCD_PORT_C][LCD_BIT_RW]);
1570 pin_to_bits(lcd_bl_pin, lcd_bits[LCD_PORT_D][LCD_BIT_BL], 1600 pin_to_bits(lcd.pins.bl, lcd_bits[LCD_PORT_D][LCD_BIT_BL],
1571 lcd_bits[LCD_PORT_C][LCD_BIT_BL]); 1601 lcd_bits[LCD_PORT_C][LCD_BIT_BL]);
1572 pin_to_bits(lcd_cl_pin, lcd_bits[LCD_PORT_D][LCD_BIT_CL], 1602 pin_to_bits(lcd.pins.cl, lcd_bits[LCD_PORT_D][LCD_BIT_CL],
1573 lcd_bits[LCD_PORT_C][LCD_BIT_CL]); 1603 lcd_bits[LCD_PORT_C][LCD_BIT_CL]);
1574 pin_to_bits(lcd_da_pin, lcd_bits[LCD_PORT_D][LCD_BIT_DA], 1604 pin_to_bits(lcd.pins.da, lcd_bits[LCD_PORT_D][LCD_BIT_DA],
1575 lcd_bits[LCD_PORT_C][LCD_BIT_DA]); 1605 lcd_bits[LCD_PORT_C][LCD_BIT_DA]);
1576 1606
1577 /* before this line, we must NOT send anything to the display. 1607 /* before this line, we must NOT send anything to the display.
1578 * Since lcd_init_display() needs to write data, we have to 1608 * Since lcd_init_display() needs to write data, we have to
1579 * enable mark the LCD initialized just before. */ 1609 * enable mark the LCD initialized just before. */
1580 lcd_initialized = 1; 1610 lcd.initialized = true;
1581 lcd_init_display(); 1611 lcd_init_display();
1582 1612
1583 /* display a short message */ 1613 /* display a short message */
@@ -1589,10 +1619,10 @@ static void lcd_init(void)
1589 panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*Linux-" UTS_RELEASE "\nPanel-" 1619 panel_lcd_print("\x1b[Lc\x1b[Lb\x1b[L*Linux-" UTS_RELEASE "\nPanel-"
1590 PANEL_VERSION); 1620 PANEL_VERSION);
1591#endif 1621#endif
1592 lcd_addr_x = 0; 1622 lcd.addr.x = 0;
1593 lcd_addr_y = 0; 1623 lcd.addr.y = 0;
1594 /* clear the display on the next device opening */ 1624 /* clear the display on the next device opening */
1595 lcd_must_clear = 1; 1625 lcd.must_clear = true;
1596 lcd_gotoxy(); 1626 lcd_gotoxy();
1597} 1627}
1598 1628
@@ -1627,20 +1657,19 @@ static ssize_t keypad_read(struct file *file,
1627 1657
1628static int keypad_open(struct inode *inode, struct file *file) 1658static int keypad_open(struct inode *inode, struct file *file)
1629{ 1659{
1630 if (keypad_open_cnt) 1660 if (!atomic_dec_and_test(&keypad_available))
1631 return -EBUSY; /* open only once at a time */ 1661 return -EBUSY; /* open only once at a time */
1632 1662
1633 if (file->f_mode & FMODE_WRITE) /* device is read-only */ 1663 if (file->f_mode & FMODE_WRITE) /* device is read-only */
1634 return -EPERM; 1664 return -EPERM;
1635 1665
1636 keypad_buflen = 0; /* flush the buffer on opening */ 1666 keypad_buflen = 0; /* flush the buffer on opening */
1637 keypad_open_cnt++;
1638 return 0; 1667 return 0;
1639} 1668}
1640 1669
1641static int keypad_release(struct inode *inode, struct file *file) 1670static int keypad_release(struct inode *inode, struct file *file)
1642{ 1671{
1643 keypad_open_cnt--; 1672 atomic_inc(&keypad_available);
1644 return 0; 1673 return 0;
1645} 1674}
1646 1675
@@ -1652,9 +1681,9 @@ static const struct file_operations keypad_fops = {
1652}; 1681};
1653 1682
1654static struct miscdevice keypad_dev = { 1683static struct miscdevice keypad_dev = {
1655 KEYPAD_MINOR, 1684 .minor = KEYPAD_MINOR,
1656 "keypad", 1685 .name = "keypad",
1657 &keypad_fops 1686 .fops = &keypad_fops,
1658}; 1687};
1659 1688
1660static void keypad_send_key(const char *string, int max_len) 1689static void keypad_send_key(const char *string, int max_len)
@@ -1663,7 +1692,7 @@ static void keypad_send_key(const char *string, int max_len)
1663 return; 1692 return;
1664 1693
1665 /* send the key to the device only if a process is attached to it. */ 1694 /* send the key to the device only if a process is attached to it. */
1666 if (keypad_open_cnt > 0) { 1695 if (!atomic_read(&keypad_available)) {
1667 while (max_len-- && keypad_buflen < KEYPAD_BUFFER && *string) { 1696 while (max_len-- && keypad_buflen < KEYPAD_BUFFER && *string) {
1668 keypad_buffer[(keypad_start + keypad_buflen++) % 1697 keypad_buffer[(keypad_start + keypad_buflen++) %
1669 KEYPAD_BUFFER] = *string++; 1698 KEYPAD_BUFFER] = *string++;
@@ -1917,7 +1946,7 @@ static void panel_process_inputs(void)
1917 1946
1918static void panel_scan_timer(void) 1947static void panel_scan_timer(void)
1919{ 1948{
1920 if (keypad_enabled && keypad_initialized) { 1949 if (keypad.enabled && keypad_initialized) {
1921 if (spin_trylock_irq(&pprt_lock)) { 1950 if (spin_trylock_irq(&pprt_lock)) {
1922 phys_scan_contacts(); 1951 phys_scan_contacts();
1923 1952
@@ -1929,14 +1958,16 @@ static void panel_scan_timer(void)
1929 panel_process_inputs(); 1958 panel_process_inputs();
1930 } 1959 }
1931 1960
1932 if (lcd_enabled && lcd_initialized) { 1961 if (lcd.enabled && lcd.initialized) {
1933 if (keypressed) { 1962 if (keypressed) {
1934 if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0)) 1963 if (lcd.light_tempo == 0
1964 && ((lcd.flags & LCD_FLAG_L) == 0))
1935 lcd_backlight(1); 1965 lcd_backlight(1);
1936 light_tempo = FLASH_LIGHT_TEMPO; 1966 lcd.light_tempo = FLASH_LIGHT_TEMPO;
1937 } else if (light_tempo > 0) { 1967 } else if (lcd.light_tempo > 0) {
1938 light_tempo--; 1968 lcd.light_tempo--;
1939 if (light_tempo == 0 && ((lcd_flags & LCD_FLAG_L) == 0)) 1969 if (lcd.light_tempo == 0
1970 && ((lcd.flags & LCD_FLAG_L) == 0))
1940 lcd_backlight(0); 1971 lcd_backlight(0);
1941 } 1972 }
1942 } 1973 }
@@ -2108,7 +2139,7 @@ static void keypad_init(void)
2108static int panel_notify_sys(struct notifier_block *this, unsigned long code, 2139static int panel_notify_sys(struct notifier_block *this, unsigned long code,
2109 void *unused) 2140 void *unused)
2110{ 2141{
2111 if (lcd_enabled && lcd_initialized) { 2142 if (lcd.enabled && lcd.initialized) {
2112 switch (code) { 2143 switch (code) {
2113 case SYS_DOWN: 2144 case SYS_DOWN:
2114 panel_lcd_print 2145 panel_lcd_print
@@ -2164,13 +2195,13 @@ static void panel_attach(struct parport *port)
2164 /* must init LCD first, just in case an IRQ from the keypad is 2195 /* must init LCD first, just in case an IRQ from the keypad is
2165 * generated at keypad init 2196 * generated at keypad init
2166 */ 2197 */
2167 if (lcd_enabled) { 2198 if (lcd.enabled) {
2168 lcd_init(); 2199 lcd_init();
2169 if (misc_register(&lcd_dev)) 2200 if (misc_register(&lcd_dev))
2170 goto err_unreg_device; 2201 goto err_unreg_device;
2171 } 2202 }
2172 2203
2173 if (keypad_enabled) { 2204 if (keypad.enabled) {
2174 keypad_init(); 2205 keypad_init();
2175 if (misc_register(&keypad_dev)) 2206 if (misc_register(&keypad_dev))
2176 goto err_lcd_unreg; 2207 goto err_lcd_unreg;
@@ -2178,7 +2209,7 @@ static void panel_attach(struct parport *port)
2178 return; 2209 return;
2179 2210
2180err_lcd_unreg: 2211err_lcd_unreg:
2181 if (lcd_enabled) 2212 if (lcd.enabled)
2182 misc_deregister(&lcd_dev); 2213 misc_deregister(&lcd_dev);
2183err_unreg_device: 2214err_unreg_device:
2184 parport_unregister_device(pprt); 2215 parport_unregister_device(pprt);
@@ -2196,14 +2227,14 @@ static void panel_detach(struct parport *port)
2196 return; 2227 return;
2197 } 2228 }
2198 2229
2199 if (keypad_enabled && keypad_initialized) { 2230 if (keypad.enabled && keypad_initialized) {
2200 misc_deregister(&keypad_dev); 2231 misc_deregister(&keypad_dev);
2201 keypad_initialized = 0; 2232 keypad_initialized = 0;
2202 } 2233 }
2203 2234
2204 if (lcd_enabled && lcd_initialized) { 2235 if (lcd.enabled && lcd.initialized) {
2205 misc_deregister(&lcd_dev); 2236 misc_deregister(&lcd_dev);
2206 lcd_initialized = 0; 2237 lcd.initialized = false;
2207 } 2238 }
2208 2239
2209 parport_release(pprt); 2240 parport_release(pprt);
@@ -2218,72 +2249,89 @@ static struct parport_driver panel_driver = {
2218}; 2249};
2219 2250
2220/* init function */ 2251/* init function */
2221static int panel_init(void) 2252static int __init panel_init_module(void)
2222{ 2253{
2223 /* for backwards compatibility */ 2254 int selected_keypad_type = NOT_SET;
2224 if (keypad_type < 0)
2225 keypad_type = keypad_enabled;
2226
2227 if (lcd_type < 0)
2228 lcd_type = lcd_enabled;
2229
2230 if (parport < 0)
2231 parport = DEFAULT_PARPORT;
2232 2255
2233 /* take care of an eventual profile */ 2256 /* take care of an eventual profile */
2234 switch (profile) { 2257 switch (profile) {
2235 case PANEL_PROFILE_CUSTOM: 2258 case PANEL_PROFILE_CUSTOM:
2236 /* custom profile */ 2259 /* custom profile */
2237 if (keypad_type < 0) 2260 selected_keypad_type = DEFAULT_KEYPAD_TYPE;
2238 keypad_type = DEFAULT_KEYPAD; 2261 selected_lcd_type = DEFAULT_LCD_TYPE;
2239 if (lcd_type < 0)
2240 lcd_type = DEFAULT_LCD;
2241 break; 2262 break;
2242 case PANEL_PROFILE_OLD: 2263 case PANEL_PROFILE_OLD:
2243 /* 8 bits, 2*16, old keypad */ 2264 /* 8 bits, 2*16, old keypad */
2244 if (keypad_type < 0) 2265 selected_keypad_type = KEYPAD_TYPE_OLD;
2245 keypad_type = KEYPAD_TYPE_OLD; 2266 selected_lcd_type = LCD_TYPE_OLD;
2246 if (lcd_type < 0) 2267
2247 lcd_type = LCD_TYPE_OLD; 2268 /* TODO: This two are a little hacky, sort it out later */
2248 if (lcd_width < 0) 2269 if (lcd_width == NOT_SET)
2249 lcd_width = 16; 2270 lcd_width = 16;
2250 if (lcd_hwidth < 0) 2271 if (lcd_hwidth == NOT_SET)
2251 lcd_hwidth = 16; 2272 lcd_hwidth = 16;
2252 break; 2273 break;
2253 case PANEL_PROFILE_NEW: 2274 case PANEL_PROFILE_NEW:
2254 /* serial, 2*16, new keypad */ 2275 /* serial, 2*16, new keypad */
2255 if (keypad_type < 0) 2276 selected_keypad_type = KEYPAD_TYPE_NEW;
2256 keypad_type = KEYPAD_TYPE_NEW; 2277 selected_lcd_type = LCD_TYPE_KS0074;
2257 if (lcd_type < 0)
2258 lcd_type = LCD_TYPE_KS0074;
2259 break; 2278 break;
2260 case PANEL_PROFILE_HANTRONIX: 2279 case PANEL_PROFILE_HANTRONIX:
2261 /* 8 bits, 2*16 hantronix-like, no keypad */ 2280 /* 8 bits, 2*16 hantronix-like, no keypad */
2262 if (keypad_type < 0) 2281 selected_keypad_type = KEYPAD_TYPE_NONE;
2263 keypad_type = KEYPAD_TYPE_NONE; 2282 selected_lcd_type = LCD_TYPE_HANTRONIX;
2264 if (lcd_type < 0)
2265 lcd_type = LCD_TYPE_HANTRONIX;
2266 break; 2283 break;
2267 case PANEL_PROFILE_NEXCOM: 2284 case PANEL_PROFILE_NEXCOM:
2268 /* generic 8 bits, 2*16, nexcom keypad, eg. Nexcom. */ 2285 /* generic 8 bits, 2*16, nexcom keypad, eg. Nexcom. */
2269 if (keypad_type < 0) 2286 selected_keypad_type = KEYPAD_TYPE_NEXCOM;
2270 keypad_type = KEYPAD_TYPE_NEXCOM; 2287 selected_lcd_type = LCD_TYPE_NEXCOM;
2271 if (lcd_type < 0)
2272 lcd_type = LCD_TYPE_NEXCOM;
2273 break; 2288 break;
2274 case PANEL_PROFILE_LARGE: 2289 case PANEL_PROFILE_LARGE:
2275 /* 8 bits, 2*40, old keypad */ 2290 /* 8 bits, 2*40, old keypad */
2276 if (keypad_type < 0) 2291 selected_keypad_type = KEYPAD_TYPE_OLD;
2277 keypad_type = KEYPAD_TYPE_OLD; 2292 selected_lcd_type = LCD_TYPE_OLD;
2278 if (lcd_type < 0)
2279 lcd_type = LCD_TYPE_OLD;
2280 break; 2293 break;
2281 } 2294 }
2282 2295
2283 lcd_enabled = (lcd_type > 0); 2296 /*
2284 keypad_enabled = (keypad_type > 0); 2297 * Init lcd struct with load-time values to preserve exact current
2298 * functionality (at least for now).
2299 */
2300 lcd.height = lcd_height;
2301 lcd.width = lcd_width;
2302 lcd.bwidth = lcd_bwidth;
2303 lcd.hwidth = lcd_hwidth;
2304 lcd.charset = lcd_charset;
2305 lcd.proto = lcd_proto;
2306 lcd.pins.e = lcd_e_pin;
2307 lcd.pins.rs = lcd_rs_pin;
2308 lcd.pins.rw = lcd_rw_pin;
2309 lcd.pins.cl = lcd_cl_pin;
2310 lcd.pins.da = lcd_da_pin;
2311 lcd.pins.bl = lcd_bl_pin;
2312
2313 /* Leave it for now, just in case */
2314 lcd.esc_seq.len = -1;
2315
2316 /*
2317 * Overwrite selection with module param values (both keypad and lcd),
2318 * where the deprecated params have lower prio.
2319 */
2320 if (keypad_enabled != NOT_SET)
2321 selected_keypad_type = keypad_enabled;
2322 if (keypad_type != NOT_SET)
2323 selected_keypad_type = keypad_type;
2285 2324
2286 switch (keypad_type) { 2325 keypad.enabled = (selected_keypad_type > 0);
2326
2327 if (lcd_enabled != NOT_SET)
2328 selected_lcd_type = lcd_enabled;
2329 if (lcd_type != NOT_SET)
2330 selected_lcd_type = lcd_type;
2331
2332 lcd.enabled = (selected_lcd_type > 0);
2333
2334 switch (selected_keypad_type) {
2287 case KEYPAD_TYPE_OLD: 2335 case KEYPAD_TYPE_OLD:
2288 keypad_profile = old_keypad_profile; 2336 keypad_profile = old_keypad_profile;
2289 break; 2337 break;
@@ -2306,7 +2354,7 @@ static int panel_init(void)
2306 return -EIO; 2354 return -EIO;
2307 } 2355 }
2308 2356
2309 if (!lcd_enabled && !keypad_enabled) { 2357 if (!lcd.enabled && !keypad.enabled) {
2310 /* no device enabled, let's release the parport */ 2358 /* no device enabled, let's release the parport */
2311 if (pprt) { 2359 if (pprt) {
2312 parport_release(pprt); 2360 parport_release(pprt);
@@ -2333,11 +2381,6 @@ static int panel_init(void)
2333 return 0; 2381 return 0;
2334} 2382}
2335 2383
2336static int __init panel_init_module(void)
2337{
2338 return panel_init();
2339}
2340
2341static void __exit panel_cleanup_module(void) 2384static void __exit panel_cleanup_module(void)
2342{ 2385{
2343 unregister_reboot_notifier(&panel_notifier); 2386 unregister_reboot_notifier(&panel_notifier);
@@ -2346,16 +2389,16 @@ static void __exit panel_cleanup_module(void)
2346 del_timer_sync(&scan_timer); 2389 del_timer_sync(&scan_timer);
2347 2390
2348 if (pprt != NULL) { 2391 if (pprt != NULL) {
2349 if (keypad_enabled) { 2392 if (keypad.enabled) {
2350 misc_deregister(&keypad_dev); 2393 misc_deregister(&keypad_dev);
2351 keypad_initialized = 0; 2394 keypad_initialized = 0;
2352 } 2395 }
2353 2396
2354 if (lcd_enabled) { 2397 if (lcd.enabled) {
2355 panel_lcd_print("\x0cLCD driver " PANEL_VERSION 2398 panel_lcd_print("\x0cLCD driver " PANEL_VERSION
2356 "\nunloaded.\x1b[Lc\x1b[Lb\x1b[L-"); 2399 "\nunloaded.\x1b[Lc\x1b[Lb\x1b[L-");
2357 misc_deregister(&lcd_dev); 2400 misc_deregister(&lcd_dev);
2358 lcd_initialized = 0; 2401 lcd.initialized = false;
2359 } 2402 }
2360 2403
2361 /* TODO: free all input signals */ 2404 /* TODO: free all input signals */
diff --git a/drivers/staging/rtl8188eu/core/rtw_ap.c b/drivers/staging/rtl8188eu/core/rtw_ap.c
index 9224e029ef2b..d61842ed673e 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ap.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ap.c
@@ -888,7 +888,7 @@ int rtw_check_beacon_data(struct adapter *padapter, u8 *pbuf, int len)
888 888
889 pbss_network->Rssi = 0; 889 pbss_network->Rssi = 0;
890 890
891 memcpy(pbss_network->MacAddress, myid(&(padapter->eeprompriv)), ETH_ALEN); 891 ether_addr_copy(pbss_network->MacAddress, myid(&(padapter->eeprompriv)));
892 892
893 /* beacon interval */ 893 /* beacon interval */
894 p = rtw_get_beacon_interval_from_ie(ie);/* 8: TimeStamp, 2: Beacon Interval 2:Capability */ 894 p = rtw_get_beacon_interval_from_ie(ie);/* 8: TimeStamp, 2: Beacon Interval 2:Capability */
@@ -1164,7 +1164,7 @@ int rtw_acl_add_sta(struct adapter *padapter, u8 *addr)
1164 if (!paclnode->valid) { 1164 if (!paclnode->valid) {
1165 INIT_LIST_HEAD(&paclnode->list); 1165 INIT_LIST_HEAD(&paclnode->list);
1166 1166
1167 memcpy(paclnode->addr, addr, ETH_ALEN); 1167 ether_addr_copy(paclnode->addr, addr);
1168 1168
1169 paclnode->valid = true; 1169 paclnode->valid = true;
1170 1170
@@ -1186,7 +1186,6 @@ int rtw_acl_add_sta(struct adapter *padapter, u8 *addr)
1186int rtw_acl_remove_sta(struct adapter *padapter, u8 *addr) 1186int rtw_acl_remove_sta(struct adapter *padapter, u8 *addr)
1187{ 1187{
1188 struct list_head *plist, *phead; 1188 struct list_head *plist, *phead;
1189 int ret = 0;
1190 struct rtw_wlan_acl_node *paclnode; 1189 struct rtw_wlan_acl_node *paclnode;
1191 struct sta_priv *pstapriv = &padapter->stapriv; 1190 struct sta_priv *pstapriv = &padapter->stapriv;
1192 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list; 1191 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
@@ -1217,7 +1216,7 @@ int rtw_acl_remove_sta(struct adapter *padapter, u8 *addr)
1217 spin_unlock_bh(&(pacl_node_q->lock)); 1216 spin_unlock_bh(&(pacl_node_q->lock));
1218 1217
1219 DBG_88E("%s, acl_num =%d\n", __func__, pacl_list->num); 1218 DBG_88E("%s, acl_num =%d\n", __func__, pacl_list->num);
1220 return ret; 1219 return 0;
1221} 1220}
1222 1221
1223static void update_bcn_fixed_ie(struct adapter *padapter) 1222static void update_bcn_fixed_ie(struct adapter *padapter)
@@ -1753,7 +1752,6 @@ u8 ap_free_sta(struct adapter *padapter, struct sta_info *psta,
1753int rtw_ap_inform_ch_switch(struct adapter *padapter, u8 new_ch, u8 ch_offset) 1752int rtw_ap_inform_ch_switch(struct adapter *padapter, u8 new_ch, u8 ch_offset)
1754{ 1753{
1755 struct list_head *phead, *plist; 1754 struct list_head *phead, *plist;
1756 int ret = 0;
1757 struct sta_info *psta = NULL; 1755 struct sta_info *psta = NULL;
1758 struct sta_priv *pstapriv = &padapter->stapriv; 1756 struct sta_priv *pstapriv = &padapter->stapriv;
1759 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 1757 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
@@ -1761,7 +1759,7 @@ int rtw_ap_inform_ch_switch(struct adapter *padapter, u8 new_ch, u8 ch_offset)
1761 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 1759 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1762 1760
1763 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE) 1761 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
1764 return ret; 1762 return 0;
1765 1763
1766 DBG_88E(FUNC_NDEV_FMT" with ch:%u, offset:%u\n", 1764 DBG_88E(FUNC_NDEV_FMT" with ch:%u, offset:%u\n",
1767 FUNC_NDEV_ARG(padapter->pnetdev), new_ch, ch_offset); 1765 FUNC_NDEV_ARG(padapter->pnetdev), new_ch, ch_offset);
@@ -1782,13 +1780,12 @@ int rtw_ap_inform_ch_switch(struct adapter *padapter, u8 new_ch, u8 ch_offset)
1782 1780
1783 issue_action_spct_ch_switch(padapter, bc_addr, new_ch, ch_offset); 1781 issue_action_spct_ch_switch(padapter, bc_addr, new_ch, ch_offset);
1784 1782
1785 return ret; 1783 return 0;
1786} 1784}
1787 1785
1788int rtw_sta_flush(struct adapter *padapter) 1786int rtw_sta_flush(struct adapter *padapter)
1789{ 1787{
1790 struct list_head *phead, *plist; 1788 struct list_head *phead, *plist;
1791 int ret = 0;
1792 struct sta_info *psta = NULL; 1789 struct sta_info *psta = NULL;
1793 struct sta_priv *pstapriv = &padapter->stapriv; 1790 struct sta_priv *pstapriv = &padapter->stapriv;
1794 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 1791 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
@@ -1798,7 +1795,7 @@ int rtw_sta_flush(struct adapter *padapter)
1798 DBG_88E(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(padapter->pnetdev)); 1795 DBG_88E(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(padapter->pnetdev));
1799 1796
1800 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE) 1797 if ((pmlmeinfo->state&0x03) != WIFI_FW_AP_STATE)
1801 return ret; 1798 return 0;
1802 1799
1803 spin_lock_bh(&pstapriv->asoc_list_lock); 1800 spin_lock_bh(&pstapriv->asoc_list_lock);
1804 phead = &pstapriv->asoc_list; 1801 phead = &pstapriv->asoc_list;
@@ -1822,7 +1819,7 @@ int rtw_sta_flush(struct adapter *padapter)
1822 1819
1823 associated_clients_update(padapter, true); 1820 associated_clients_update(padapter, true);
1824 1821
1825 return ret; 1822 return 0;
1826} 1823}
1827 1824
1828/* called > TSR LEVEL for USB or SDIO Interface*/ 1825/* called > TSR LEVEL for USB or SDIO Interface*/
diff --git a/drivers/staging/rtl8188eu/core/rtw_cmd.c b/drivers/staging/rtl8188eu/core/rtw_cmd.c
index eddef9cd2e16..4b4346244953 100644
--- a/drivers/staging/rtl8188eu/core/rtw_cmd.c
+++ b/drivers/staging/rtl8188eu/core/rtw_cmd.c
@@ -167,7 +167,7 @@ int rtw_cmd_thread(void *context)
167 struct cmd_obj *pcmd; 167 struct cmd_obj *pcmd;
168 u8 (*cmd_hdl)(struct adapter *padapter, u8 *pbuf); 168 u8 (*cmd_hdl)(struct adapter *padapter, u8 *pbuf);
169 void (*pcmd_callback)(struct adapter *dev, struct cmd_obj *pcmd); 169 void (*pcmd_callback)(struct adapter *dev, struct cmd_obj *pcmd);
170 struct adapter *padapter = (struct adapter *)context; 170 struct adapter *padapter = context;
171 struct cmd_priv *pcmdpriv = &(padapter->cmdpriv); 171 struct cmd_priv *pcmdpriv = &(padapter->cmdpriv);
172 172
173 allow_signal(SIGTERM); 173 allow_signal(SIGTERM);
@@ -433,8 +433,7 @@ u8 rtw_joinbss_cmd(struct adapter *padapter, struct wlan_network *pnetwork)
433 433
434 psecnetwork = (struct wlan_bssid_ex *)&psecuritypriv->sec_bss; 434 psecnetwork = (struct wlan_bssid_ex *)&psecuritypriv->sec_bss;
435 if (psecnetwork == NULL) { 435 if (psecnetwork == NULL) {
436 if (pcmd != NULL) 436 kfree(pcmd);
437 kfree(pcmd);
438 437
439 res = _FAIL; 438 res = _FAIL;
440 439
@@ -456,7 +455,7 @@ u8 rtw_joinbss_cmd(struct adapter *padapter, struct wlan_network *pnetwork)
456 455
457 psecnetwork->IELength = 0; 456 psecnetwork->IELength = 0;
458 /* Added by Albert 2009/02/18 */ 457 /* Added by Albert 2009/02/18 */
459 /* If the the driver wants to use the bssid to create the connection. */ 458 /* If the driver wants to use the bssid to create the connection. */
460 /* If not, we have to copy the connecting AP's MAC address to it so that */ 459 /* If not, we have to copy the connecting AP's MAC address to it so that */
461 /* the driver just has the bssid information for PMKIDList searching. */ 460 /* the driver just has the bssid information for PMKIDList searching. */
462 461
@@ -638,7 +637,7 @@ u8 rtw_setstakey_cmd(struct adapter *padapter, u8 *psta, u8 unicast_key)
638 ether_addr_copy(psetstakey_para->addr, sta->hwaddr); 637 ether_addr_copy(psetstakey_para->addr, sta->hwaddr);
639 638
640 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) 639 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE))
641 psetstakey_para->algorithm = (unsigned char) psecuritypriv->dot11PrivacyAlgrthm; 640 psetstakey_para->algorithm = (unsigned char)psecuritypriv->dot11PrivacyAlgrthm;
642 else 641 else
643 GET_ENCRY_ALGO(psecuritypriv, sta, psetstakey_para->algorithm, false); 642 GET_ENCRY_ALGO(psecuritypriv, sta, psetstakey_para->algorithm, false);
644 643
diff --git a/drivers/staging/rtl8188eu/core/rtw_debug.c b/drivers/staging/rtl8188eu/core/rtw_debug.c
index 1f72f7d8097e..bc3fe10ff247 100644
--- a/drivers/staging/rtl8188eu/core/rtw_debug.c
+++ b/drivers/staging/rtl8188eu/core/rtw_debug.c
@@ -45,7 +45,7 @@ int proc_get_write_reg(char *page, char **start,
45int proc_set_write_reg(struct file *file, const char __user *buffer, 45int proc_set_write_reg(struct file *file, const char __user *buffer,
46 unsigned long count, void *data) 46 unsigned long count, void *data)
47{ 47{
48 struct net_device *dev = (struct net_device *)data; 48 struct net_device *dev = data;
49 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); 49 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
50 char tmp[32]; 50 char tmp[32];
51 u32 addr, val, len; 51 u32 addr, val, len;
@@ -577,7 +577,7 @@ int proc_get_rx_signal(char *page, char **start,
577int proc_set_rx_signal(struct file *file, const char __user *buffer, 577int proc_set_rx_signal(struct file *file, const char __user *buffer,
578 unsigned long count, void *data) 578 unsigned long count, void *data)
579{ 579{
580 struct net_device *dev = (struct net_device *)data; 580 struct net_device *dev = data;
581 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); 581 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
582 char tmp[32]; 582 char tmp[32];
583 u32 is_signal_dbg; 583 u32 is_signal_dbg;
@@ -627,7 +627,7 @@ int proc_get_ht_enable(char *page, char **start,
627int proc_set_ht_enable(struct file *file, const char __user *buffer, 627int proc_set_ht_enable(struct file *file, const char __user *buffer,
628 unsigned long count, void *data) 628 unsigned long count, void *data)
629{ 629{
630 struct net_device *dev = (struct net_device *)data; 630 struct net_device *dev = data;
631 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); 631 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
632 struct registry_priv *pregpriv = &padapter->registrypriv; 632 struct registry_priv *pregpriv = &padapter->registrypriv;
633 char tmp[32]; 633 char tmp[32];
@@ -669,7 +669,7 @@ int proc_get_cbw40_enable(char *page, char **start,
669int proc_set_cbw40_enable(struct file *file, const char __user *buffer, 669int proc_set_cbw40_enable(struct file *file, const char __user *buffer,
670 unsigned long count, void *data) 670 unsigned long count, void *data)
671{ 671{
672 struct net_device *dev = (struct net_device *)data; 672 struct net_device *dev = data;
673 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); 673 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
674 struct registry_priv *pregpriv = &padapter->registrypriv; 674 struct registry_priv *pregpriv = &padapter->registrypriv;
675 char tmp[32]; 675 char tmp[32];
@@ -710,7 +710,7 @@ int proc_get_ampdu_enable(char *page, char **start,
710int proc_set_ampdu_enable(struct file *file, const char __user *buffer, 710int proc_set_ampdu_enable(struct file *file, const char __user *buffer,
711 unsigned long count, void *data) 711 unsigned long count, void *data)
712{ 712{
713 struct net_device *dev = (struct net_device *)data; 713 struct net_device *dev = data;
714 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); 714 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
715 struct registry_priv *pregpriv = &padapter->registrypriv; 715 struct registry_priv *pregpriv = &padapter->registrypriv;
716 char tmp[32]; 716 char tmp[32];
@@ -771,7 +771,7 @@ int proc_get_rx_stbc(char *page, char **start,
771int proc_set_rx_stbc(struct file *file, const char __user *buffer, 771int proc_set_rx_stbc(struct file *file, const char __user *buffer,
772 unsigned long count, void *data) 772 unsigned long count, void *data)
773{ 773{
774 struct net_device *dev = (struct net_device *)data; 774 struct net_device *dev = data;
775 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); 775 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
776 struct registry_priv *pregpriv = &padapter->registrypriv; 776 struct registry_priv *pregpriv = &padapter->registrypriv;
777 char tmp[32]; 777 char tmp[32];
@@ -800,7 +800,7 @@ int proc_get_rssi_disp(char *page, char **start,
800int proc_set_rssi_disp(struct file *file, const char __user *buffer, 800int proc_set_rssi_disp(struct file *file, const char __user *buffer,
801 unsigned long count, void *data) 801 unsigned long count, void *data)
802{ 802{
803 struct net_device *dev = (struct net_device *)data; 803 struct net_device *dev = data;
804 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev); 804 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
805 char tmp[32]; 805 char tmp[32];
806 u32 enable = 0; 806 u32 enable = 0;
diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c b/drivers/staging/rtl8188eu/core/rtw_efuse.c
index 7006088d1ad0..8816d116a8b8 100644
--- a/drivers/staging/rtl8188eu/core/rtw_efuse.c
+++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c
@@ -106,13 +106,13 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf)
106 efuseTbl = kzalloc(EFUSE_MAP_LEN_88E, GFP_KERNEL); 106 efuseTbl = kzalloc(EFUSE_MAP_LEN_88E, GFP_KERNEL);
107 if (efuseTbl == NULL) { 107 if (efuseTbl == NULL) {
108 DBG_88E("%s: alloc efuseTbl fail!\n", __func__); 108 DBG_88E("%s: alloc efuseTbl fail!\n", __func__);
109 goto exit; 109 return;
110 } 110 }
111 111
112 eFuseWord = (u16 **)rtw_malloc2d(EFUSE_MAX_SECTION_88E, EFUSE_MAX_WORD_UNIT, sizeof(u16)); 112 eFuseWord = (u16 **)rtw_malloc2d(EFUSE_MAX_SECTION_88E, EFUSE_MAX_WORD_UNIT, sizeof(u16));
113 if (eFuseWord == NULL) { 113 if (eFuseWord == NULL) {
114 DBG_88E("%s: alloc eFuseWord fail!\n", __func__); 114 DBG_88E("%s: alloc eFuseWord fail!\n", __func__);
115 goto exit; 115 goto eFuseWord_failed;
116 } 116 }
117 117
118 /* 0. Refresh efuse init map as all oxFF. */ 118 /* 0. Refresh efuse init map as all oxFF. */
@@ -210,10 +210,10 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16 _size_byte, u8 *pbuf)
210 /* */ 210 /* */
211 211
212exit: 212exit:
213 kfree(efuseTbl); 213 kfree(eFuseWord);
214 214
215 if (eFuseWord) 215eFuseWord_failed:
216 kfree(eFuseWord); 216 kfree(efuseTbl);
217} 217}
218 218
219static void efuse_read_phymap_from_txpktbuf( 219static void efuse_read_phymap_from_txpktbuf(
@@ -250,7 +250,7 @@ static void efuse_read_phymap_from_txpktbuf(
250 while (!(reg_0x143 = usb_read8(adapter, REG_TXPKTBUF_DBG)) && 250 while (!(reg_0x143 = usb_read8(adapter, REG_TXPKTBUF_DBG)) &&
251 (passing_time = rtw_get_passing_time_ms(start)) < 1000) { 251 (passing_time = rtw_get_passing_time_ms(start)) < 1000) {
252 DBG_88E("%s polling reg_0x143:0x%02x, reg_0x106:0x%02x\n", __func__, reg_0x143, usb_read8(adapter, 0x106)); 252 DBG_88E("%s polling reg_0x143:0x%02x, reg_0x106:0x%02x\n", __func__, reg_0x143, usb_read8(adapter, 0x106));
253 msleep(1); 253 usleep_range(1000, 2000);
254 } 254 }
255 255
256 lo32 = usb_read32(adapter, REG_PKTBUF_DBG_DATA_L); 256 lo32 = usb_read32(adapter, REG_PKTBUF_DBG_DATA_L);
@@ -322,7 +322,6 @@ void efuse_ReadEFuse(struct adapter *Adapter, u8 efuseType, u16 _offset, u16 _si
322 iol_read_efuse(Adapter, 0, _offset, _size_byte, pbuf); 322 iol_read_efuse(Adapter, 0, _offset, _size_byte, pbuf);
323 iol_mode_enable(Adapter, 0); 323 iol_mode_enable(Adapter, 0);
324 } 324 }
325 return;
326} 325}
327 326
328/* Do not support BT */ 327/* Do not support BT */
@@ -332,56 +331,56 @@ void EFUSE_GetEfuseDefinition(struct adapter *pAdapter, u8 efuseType, u8 type, v
332 case TYPE_EFUSE_MAX_SECTION: 331 case TYPE_EFUSE_MAX_SECTION:
333 { 332 {
334 u8 *pMax_section; 333 u8 *pMax_section;
335 pMax_section = (u8 *)pOut; 334 pMax_section = pOut;
336 *pMax_section = EFUSE_MAX_SECTION_88E; 335 *pMax_section = EFUSE_MAX_SECTION_88E;
337 } 336 }
338 break; 337 break;
339 case TYPE_EFUSE_REAL_CONTENT_LEN: 338 case TYPE_EFUSE_REAL_CONTENT_LEN:
340 { 339 {
341 u16 *pu2Tmp; 340 u16 *pu2Tmp;
342 pu2Tmp = (u16 *)pOut; 341 pu2Tmp = pOut;
343 *pu2Tmp = EFUSE_REAL_CONTENT_LEN_88E; 342 *pu2Tmp = EFUSE_REAL_CONTENT_LEN_88E;
344 } 343 }
345 break; 344 break;
346 case TYPE_EFUSE_CONTENT_LEN_BANK: 345 case TYPE_EFUSE_CONTENT_LEN_BANK:
347 { 346 {
348 u16 *pu2Tmp; 347 u16 *pu2Tmp;
349 pu2Tmp = (u16 *)pOut; 348 pu2Tmp = pOut;
350 *pu2Tmp = EFUSE_REAL_CONTENT_LEN_88E; 349 *pu2Tmp = EFUSE_REAL_CONTENT_LEN_88E;
351 } 350 }
352 break; 351 break;
353 case TYPE_AVAILABLE_EFUSE_BYTES_BANK: 352 case TYPE_AVAILABLE_EFUSE_BYTES_BANK:
354 { 353 {
355 u16 *pu2Tmp; 354 u16 *pu2Tmp;
356 pu2Tmp = (u16 *)pOut; 355 pu2Tmp = pOut;
357 *pu2Tmp = (u16)(EFUSE_REAL_CONTENT_LEN_88E-EFUSE_OOB_PROTECT_BYTES_88E); 356 *pu2Tmp = (u16)(EFUSE_REAL_CONTENT_LEN_88E-EFUSE_OOB_PROTECT_BYTES_88E);
358 } 357 }
359 break; 358 break;
360 case TYPE_AVAILABLE_EFUSE_BYTES_TOTAL: 359 case TYPE_AVAILABLE_EFUSE_BYTES_TOTAL:
361 { 360 {
362 u16 *pu2Tmp; 361 u16 *pu2Tmp;
363 pu2Tmp = (u16 *)pOut; 362 pu2Tmp = pOut;
364 *pu2Tmp = (u16)(EFUSE_REAL_CONTENT_LEN_88E-EFUSE_OOB_PROTECT_BYTES_88E); 363 *pu2Tmp = (u16)(EFUSE_REAL_CONTENT_LEN_88E-EFUSE_OOB_PROTECT_BYTES_88E);
365 } 364 }
366 break; 365 break;
367 case TYPE_EFUSE_MAP_LEN: 366 case TYPE_EFUSE_MAP_LEN:
368 { 367 {
369 u16 *pu2Tmp; 368 u16 *pu2Tmp;
370 pu2Tmp = (u16 *)pOut; 369 pu2Tmp = pOut;
371 *pu2Tmp = (u16)EFUSE_MAP_LEN_88E; 370 *pu2Tmp = (u16)EFUSE_MAP_LEN_88E;
372 } 371 }
373 break; 372 break;
374 case TYPE_EFUSE_PROTECT_BYTES_BANK: 373 case TYPE_EFUSE_PROTECT_BYTES_BANK:
375 { 374 {
376 u8 *pu1Tmp; 375 u8 *pu1Tmp;
377 pu1Tmp = (u8 *)pOut; 376 pu1Tmp = pOut;
378 *pu1Tmp = (u8)(EFUSE_OOB_PROTECT_BYTES_88E); 377 *pu1Tmp = (u8)(EFUSE_OOB_PROTECT_BYTES_88E);
379 } 378 }
380 break; 379 break;
381 default: 380 default:
382 { 381 {
383 u8 *pu1Tmp; 382 u8 *pu1Tmp;
384 pu1Tmp = (u8 *)pOut; 383 pu1Tmp = pOut;
385 *pu1Tmp = 0; 384 *pu1Tmp = 0;
386 } 385 }
387 break; 386 break;
@@ -638,10 +637,9 @@ static bool hal_EfusePgPacketWrite2ByteHeader(struct adapter *pAdapter, u8 efuse
638 if ((tmp_header & 0x0F) == 0x0F) { /* word_en PG fail */ 637 if ((tmp_header & 0x0F) == 0x0F) { /* word_en PG fail */
639 if (repeatcnt++ > EFUSE_REPEAT_THRESHOLD_) { 638 if (repeatcnt++ > EFUSE_REPEAT_THRESHOLD_) {
640 return false; 639 return false;
641 } else {
642 efuse_addr++;
643 continue;
644 } 640 }
641 efuse_addr++;
642 continue;
645 } else if (pg_header != tmp_header) { /* offset PG fail */ 643 } else if (pg_header != tmp_header) { /* offset PG fail */
646 struct pgpkt fixPkt; 644 struct pgpkt fixPkt;
647 fixPkt.offset = ((pg_header_temp & 0xE0) >> 5) | ((tmp_header & 0xF0) >> 1); 645 fixPkt.offset = ((pg_header_temp & 0xE0) >> 5) | ((tmp_header & 0xF0) >> 1);
@@ -708,14 +706,13 @@ static bool hal_EfusePgPacketWriteData(struct adapter *pAdapter, u8 efuseType, u
708 if (badworden == 0x0F) { 706 if (badworden == 0x0F) {
709 /* write ok */ 707 /* write ok */
710 return true; 708 return true;
711 } else {
712 /* reorganize other pg packet */
713 PgWriteSuccess = Efuse_PgPacketWrite(pAdapter, pTargetPkt->offset, badworden, pTargetPkt->data);
714 if (!PgWriteSuccess)
715 return false;
716 else
717 return true;
718 } 709 }
710 /* reorganize other pg packet */
711 PgWriteSuccess = Efuse_PgPacketWrite(pAdapter, pTargetPkt->offset, badworden, pTargetPkt->data);
712 if (!PgWriteSuccess)
713 return false;
714 else
715 return true;
719} 716}
720 717
721static bool 718static bool
diff --git a/drivers/staging/rtl8188eu/core/rtw_ieee80211.c b/drivers/staging/rtl8188eu/core/rtw_ieee80211.c
index 755d3effd0a7..f2c3ca79c0c9 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ieee80211.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ieee80211.c
@@ -159,7 +159,7 @@ u8 *rtw_set_ie
159 return pbuf + len + 2; 159 return pbuf + len + 2;
160} 160}
161 161
162inline u8 *rtw_set_ie_ch_switch (u8 *buf, u32 *buf_len, u8 ch_switch_mode, 162inline u8 *rtw_set_ie_ch_switch(u8 *buf, u32 *buf_len, u8 ch_switch_mode,
163 u8 new_ch, u8 ch_switch_cnt) 163 u8 new_ch, u8 ch_switch_cnt)
164{ 164{
165 u8 ie_data[3]; 165 u8 ie_data[3];
@@ -870,7 +870,7 @@ static int rtw_ieee802_11_parse_vendor_specific(u8 *pos, uint elen,
870 if (elen < 4) { 870 if (elen < 4) {
871 if (show_errors) { 871 if (show_errors) {
872 DBG_88E("short vendor specific information element ignored (len=%lu)\n", 872 DBG_88E("short vendor specific information element ignored (len=%lu)\n",
873 (unsigned long) elen); 873 (unsigned long)elen);
874 } 874 }
875 return -1; 875 return -1;
876 } 876 }
@@ -890,7 +890,7 @@ static int rtw_ieee802_11_parse_vendor_specific(u8 *pos, uint elen,
890 case WME_OUI_TYPE: /* this is a Wi-Fi WME info. element */ 890 case WME_OUI_TYPE: /* this is a Wi-Fi WME info. element */
891 if (elen < 5) { 891 if (elen < 5) {
892 DBG_88E("short WME information element ignored (len=%lu)\n", 892 DBG_88E("short WME information element ignored (len=%lu)\n",
893 (unsigned long) elen); 893 (unsigned long)elen);
894 return -1; 894 return -1;
895 } 895 }
896 switch (pos[4]) { 896 switch (pos[4]) {
@@ -905,7 +905,7 @@ static int rtw_ieee802_11_parse_vendor_specific(u8 *pos, uint elen,
905 break; 905 break;
906 default: 906 default:
907 DBG_88E("unknown WME information element ignored (subtype=%d len=%lu)\n", 907 DBG_88E("unknown WME information element ignored (subtype=%d len=%lu)\n",
908 pos[4], (unsigned long) elen); 908 pos[4], (unsigned long)elen);
909 return -1; 909 return -1;
910 } 910 }
911 break; 911 break;
@@ -916,7 +916,7 @@ static int rtw_ieee802_11_parse_vendor_specific(u8 *pos, uint elen,
916 break; 916 break;
917 default: 917 default:
918 DBG_88E("Unknown Microsoft information element ignored (type=%d len=%lu)\n", 918 DBG_88E("Unknown Microsoft information element ignored (type=%d len=%lu)\n",
919 pos[3], (unsigned long) elen); 919 pos[3], (unsigned long)elen);
920 return -1; 920 return -1;
921 } 921 }
922 break; 922 break;
@@ -929,13 +929,13 @@ static int rtw_ieee802_11_parse_vendor_specific(u8 *pos, uint elen,
929 break; 929 break;
930 default: 930 default:
931 DBG_88E("Unknown Broadcom information element ignored (type=%d len=%lu)\n", 931 DBG_88E("Unknown Broadcom information element ignored (type=%d len=%lu)\n",
932 pos[3], (unsigned long) elen); 932 pos[3], (unsigned long)elen);
933 return -1; 933 return -1;
934 } 934 }
935 break; 935 break;
936 default: 936 default:
937 DBG_88E("unknown vendor specific information element ignored (vendor OUI %02x:%02x:%02x len=%lu)\n", 937 DBG_88E("unknown vendor specific information element ignored (vendor OUI %02x:%02x:%02x len=%lu)\n",
938 pos[0], pos[1], pos[2], (unsigned long) elen); 938 pos[0], pos[1], pos[2], (unsigned long)elen);
939 return -1; 939 return -1;
940 } 940 }
941 return 0; 941 return 0;
@@ -969,7 +969,7 @@ enum parse_res rtw_ieee802_11_parse_elems(u8 *start, uint len,
969 if (elen > left) { 969 if (elen > left) {
970 if (show_errors) { 970 if (show_errors) {
971 DBG_88E("IEEE 802.11 element parse failed (id=%d elen=%d left=%lu)\n", 971 DBG_88E("IEEE 802.11 element parse failed (id=%d elen=%d left=%lu)\n",
972 id, elen, (unsigned long) left); 972 id, elen, (unsigned long)left);
973 } 973 }
974 return ParseFailed; 974 return ParseFailed;
975 } 975 }
diff --git a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
index fc280ce57d2c..2faf6b2e8129 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ioctl_set.c
@@ -98,7 +98,6 @@ u8 rtw_do_join(struct adapter *padapter)
98 98
99 pibss = padapter->registrypriv.dev_network.MacAddress; 99 pibss = padapter->registrypriv.dev_network.MacAddress;
100 100
101 memset(&pdev_network->Ssid, 0, sizeof(struct ndis_802_11_ssid));
102 memcpy(&pdev_network->Ssid, &pmlmepriv->assoc_ssid, sizeof(struct ndis_802_11_ssid)); 101 memcpy(&pdev_network->Ssid, &pmlmepriv->assoc_ssid, sizeof(struct ndis_802_11_ssid));
103 102
104 rtw_update_registrypriv_dev_network(padapter); 103 rtw_update_registrypriv_dev_network(padapter);
diff --git a/drivers/staging/rtl8188eu/core/rtw_led.c b/drivers/staging/rtl8188eu/core/rtw_led.c
index 384be22052e5..1b8264b978da 100644
--- a/drivers/staging/rtl8188eu/core/rtw_led.c
+++ b/drivers/staging/rtl8188eu/core/rtw_led.c
@@ -11,10 +11,6 @@
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details. 12 * more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * 14 *
19 ******************************************************************************/ 15 ******************************************************************************/
20 16
@@ -28,7 +24,7 @@
28/* */ 24/* */
29void BlinkTimerCallback(void *data) 25void BlinkTimerCallback(void *data)
30{ 26{
31 struct LED_871x *pLed = (struct LED_871x *)data; 27 struct LED_871x *pLed = data;
32 struct adapter *padapter = pLed->padapter; 28 struct adapter *padapter = pLed->padapter;
33 29
34 if ((padapter->bSurpriseRemoved) || (padapter->bDriverStopped)) 30 if ((padapter->bSurpriseRemoved) || (padapter->bDriverStopped))
@@ -228,7 +224,8 @@ static void SwLedBlink1(struct LED_871x *pLed)
228 pLed->bLedWPSBlinkInProgress = false; 224 pLed->bLedWPSBlinkInProgress = false;
229 } else { 225 } else {
230 pLed->BlinkingLedState = RTW_LED_OFF; 226 pLed->BlinkingLedState = RTW_LED_OFF;
231 _set_timer(&(pLed->BlinkTimer), LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA); 227 _set_timer(&(pLed->BlinkTimer),
228 LED_BLINK_WPS_SUCCESS_INTERVAL_ALPHA);
232 } 229 }
233 break; 230 break;
234 default: 231 default:
@@ -392,7 +389,8 @@ static void SwLedControlMode1(struct adapter *padapter, enum LED_CTL_MODE LedAct
392 pLed->CurrLedState = LED_BLINK_WPS_STOP; 389 pLed->CurrLedState = LED_BLINK_WPS_STOP;
393 if (pLed->bLedOn) { 390 if (pLed->bLedOn) {
394 pLed->BlinkingLedState = RTW_LED_OFF; 391 pLed->BlinkingLedState = RTW_LED_OFF;
395 _set_timer(&(pLed->BlinkTimer), LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA); 392 _set_timer(&(pLed->BlinkTimer),
393 LED_BLINK_WPS_SUCCESS_INTERVAL_ALPHA);
396 } else { 394 } else {
397 pLed->BlinkingLedState = RTW_LED_ON; 395 pLed->BlinkingLedState = RTW_LED_ON;
398 _set_timer(&(pLed->BlinkTimer), 0); 396 _set_timer(&(pLed->BlinkTimer), 0);
diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme.c b/drivers/staging/rtl8188eu/core/rtw_mlme.c
index 149c271e966d..d4632da50c1d 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme.c
@@ -674,7 +674,6 @@ void rtw_surveydone_event_callback(struct adapter *adapter, u8 *pbuf)
674 674
675 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("switching to adhoc master\n")); 675 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, ("switching to adhoc master\n"));
676 676
677 memset(&pdev_network->Ssid, 0, sizeof(struct ndis_802_11_ssid));
678 memcpy(&pdev_network->Ssid, &pmlmepriv->assoc_ssid, sizeof(struct ndis_802_11_ssid)); 677 memcpy(&pdev_network->Ssid, &pmlmepriv->assoc_ssid, sizeof(struct ndis_802_11_ssid));
679 678
680 rtw_update_registrypriv_dev_network(adapter); 679 rtw_update_registrypriv_dev_network(adapter);
@@ -1334,7 +1333,6 @@ void rtw_stadel_event_callback(struct adapter *adapter, u8 *pbuf)
1334 1333
1335 memcpy(pdev_network, &tgt_network->network, get_wlan_bssid_ex_sz(&tgt_network->network)); 1334 memcpy(pdev_network, &tgt_network->network, get_wlan_bssid_ex_sz(&tgt_network->network));
1336 1335
1337 memset(&pdev_network->Ssid, 0, sizeof(struct ndis_802_11_ssid));
1338 memcpy(&pdev_network->Ssid, &pmlmepriv->assoc_ssid, sizeof(struct ndis_802_11_ssid)); 1336 memcpy(&pdev_network->Ssid, &pmlmepriv->assoc_ssid, sizeof(struct ndis_802_11_ssid));
1339 1337
1340 rtw_update_registrypriv_dev_network(adapter); 1338 rtw_update_registrypriv_dev_network(adapter);
@@ -1364,7 +1362,7 @@ void rtw_cpwm_event_callback(struct adapter *padapter, u8 *pbuf)
1364*/ 1362*/
1365void _rtw_join_timeout_handler (void *function_context) 1363void _rtw_join_timeout_handler (void *function_context)
1366{ 1364{
1367 struct adapter *adapter = (struct adapter *)function_context; 1365 struct adapter *adapter = function_context;
1368 struct mlme_priv *pmlmepriv = &adapter->mlmepriv; 1366 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
1369 int do_join_r; 1367 int do_join_r;
1370 1368
@@ -1406,7 +1404,7 @@ void _rtw_join_timeout_handler (void *function_context)
1406*/ 1404*/
1407void rtw_scan_timeout_handler (void *function_context) 1405void rtw_scan_timeout_handler (void *function_context)
1408{ 1406{
1409 struct adapter *adapter = (struct adapter *)function_context; 1407 struct adapter *adapter = function_context;
1410 struct mlme_priv *pmlmepriv = &adapter->mlmepriv; 1408 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
1411 1409
1412 DBG_88E(FUNC_ADPT_FMT" fw_state=%x\n", FUNC_ADPT_ARG(adapter), get_fwstate(pmlmepriv)); 1410 DBG_88E(FUNC_ADPT_FMT" fw_state=%x\n", FUNC_ADPT_ARG(adapter), get_fwstate(pmlmepriv));
@@ -1437,7 +1435,7 @@ void rtw_dynamic_check_timer_handlder(void *function_context)
1437 struct registry_priv *pregistrypriv = &adapter->registrypriv; 1435 struct registry_priv *pregistrypriv = &adapter->registrypriv;
1438 1436
1439 if (!adapter) 1437 if (!adapter)
1440 goto exit; 1438 return;
1441 if (!adapter->hw_init_completed) 1439 if (!adapter->hw_init_completed)
1442 goto exit; 1440 goto exit;
1443 if ((adapter->bDriverStopped) || (adapter->bSurpriseRemoved)) 1441 if ((adapter->bDriverStopped) || (adapter->bSurpriseRemoved))
@@ -2117,7 +2115,7 @@ void rtw_issue_addbareq_cmd(struct adapter *padapter, struct xmit_frame *pxmitfr
2117 if (0 == issued) { 2115 if (0 == issued) {
2118 DBG_88E("rtw_issue_addbareq_cmd, p=%d\n", priority); 2116 DBG_88E("rtw_issue_addbareq_cmd, p=%d\n", priority);
2119 psta->htpriv.candidate_tid_bitmap |= BIT((u8)priority); 2117 psta->htpriv.candidate_tid_bitmap |= BIT((u8)priority);
2120 rtw_addbareq_cmd(padapter, (u8) priority, pattrib->ra); 2118 rtw_addbareq_cmd(padapter, (u8)priority, pattrib->ra);
2121 } 2119 }
2122 } 2120 }
2123} 2121}
diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
index 70b1bc3e0e63..e4b7ee4c99d5 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
@@ -227,7 +227,7 @@ static void init_mlme_ext_priv_value(struct adapter *padapter)
227 pmlmeext->cur_channel = padapter->registrypriv.channel; 227 pmlmeext->cur_channel = padapter->registrypriv.channel;
228 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_20; 228 pmlmeext->cur_bwmode = HT_CHANNEL_WIDTH_20;
229 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE; 229 pmlmeext->cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
230 pmlmeext->oper_channel = pmlmeext->cur_channel ; 230 pmlmeext->oper_channel = pmlmeext->cur_channel;
231 pmlmeext->oper_bwmode = pmlmeext->cur_bwmode; 231 pmlmeext->oper_bwmode = pmlmeext->cur_bwmode;
232 pmlmeext->oper_ch_offset = pmlmeext->cur_ch_offset; 232 pmlmeext->oper_ch_offset = pmlmeext->cur_ch_offset;
233 pmlmeext->retry = 0; 233 pmlmeext->retry = 0;
@@ -371,7 +371,6 @@ static u8 init_channel_set(struct adapter *padapter, u8 ChannelPlan, struct rt_c
371 371
372int init_mlme_ext_priv(struct adapter *padapter) 372int init_mlme_ext_priv(struct adapter *padapter)
373{ 373{
374 int res = _SUCCESS;
375 struct registry_priv *pregistrypriv = &padapter->registrypriv; 374 struct registry_priv *pregistrypriv = &padapter->registrypriv;
376 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 375 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
377 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv); 376 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
@@ -397,7 +396,7 @@ int init_mlme_ext_priv(struct adapter *padapter)
397 396
398 pmlmeext->active_keep_alive_check = true; 397 pmlmeext->active_keep_alive_check = true;
399 398
400 return res; 399 return _SUCCESS;
401} 400}
402 401
403void free_mlme_ext_priv(struct mlme_ext_priv *pmlmeext) 402void free_mlme_ext_priv(struct mlme_ext_priv *pmlmeext)
@@ -945,7 +944,7 @@ unsigned int OnAssocReq(struct adapter *padapter, struct recv_frame *precv_frame
945 } 944 }
946 945
947 pstat = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe)); 946 pstat = rtw_get_stainfo(pstapriv, GetAddr2Ptr(pframe));
948 if (pstat == (struct sta_info *)NULL) { 947 if (pstat == NULL) {
949 status = _RSON_CLS2_; 948 status = _RSON_CLS2_;
950 goto asoc_class2_error; 949 goto asoc_class2_error;
951 } 950 }
@@ -1554,7 +1553,6 @@ unsigned int OnAtim(struct adapter *padapter, struct recv_frame *precv_frame)
1554 1553
1555unsigned int on_action_spct(struct adapter *padapter, struct recv_frame *precv_frame) 1554unsigned int on_action_spct(struct adapter *padapter, struct recv_frame *precv_frame)
1556{ 1555{
1557 unsigned int ret = _FAIL;
1558 struct sta_info *psta = NULL; 1556 struct sta_info *psta = NULL;
1559 struct sta_priv *pstapriv = &padapter->stapriv; 1557 struct sta_priv *pstapriv = &padapter->stapriv;
1560 u8 *pframe = precv_frame->rx_data; 1558 u8 *pframe = precv_frame->rx_data;
@@ -1587,7 +1585,7 @@ unsigned int on_action_spct(struct adapter *padapter, struct recv_frame *precv_f
1587 } 1585 }
1588 1586
1589exit: 1587exit:
1590 return ret; 1588 return _FAIL;
1591} 1589}
1592 1590
1593unsigned int OnAction_qos(struct adapter *padapter, struct recv_frame *precv_frame) 1591unsigned int OnAction_qos(struct adapter *padapter, struct recv_frame *precv_frame)
@@ -2000,7 +1998,7 @@ void issue_beacon(struct adapter *padapter, int timeout_ms)
2000 DBG_88E("%s, alloc mgnt frame fail\n", __func__); 1998 DBG_88E("%s, alloc mgnt frame fail\n", __func__);
2001 return; 1999 return;
2002 } 2000 }
2003#if defined (CONFIG_88EU_AP_MODE) 2001#if defined(CONFIG_88EU_AP_MODE)
2004 spin_lock_bh(&pmlmepriv->bcn_update_lock); 2002 spin_lock_bh(&pmlmepriv->bcn_update_lock);
2005#endif /* if defined (CONFIG_88EU_AP_MODE) */ 2003#endif /* if defined (CONFIG_88EU_AP_MODE) */
2006 2004
@@ -2027,7 +2025,7 @@ void issue_beacon(struct adapter *padapter, int timeout_ms)
2027 SetFrameSubType(pframe, WIFI_BEACON); 2025 SetFrameSubType(pframe, WIFI_BEACON);
2028 2026
2029 pframe += sizeof(struct rtw_ieee80211_hdr_3addr); 2027 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
2030 pattrib->pktlen = sizeof (struct rtw_ieee80211_hdr_3addr); 2028 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
2031 2029
2032 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) { 2030 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) {
2033 int len_diff; 2031 int len_diff;
@@ -2042,8 +2040,8 @@ void issue_beacon(struct adapter *padapter, int timeout_ms)
2042 ); 2040 );
2043 pframe += (cur_network->IELength+len_diff); 2041 pframe += (cur_network->IELength+len_diff);
2044 pattrib->pktlen += (cur_network->IELength+len_diff); 2042 pattrib->pktlen += (cur_network->IELength+len_diff);
2045 wps_ie = rtw_get_wps_ie(pmgntframe->buf_addr+TXDESC_OFFSET+sizeof (struct rtw_ieee80211_hdr_3addr)+_BEACON_IE_OFFSET_, 2043 wps_ie = rtw_get_wps_ie(pmgntframe->buf_addr+TXDESC_OFFSET+sizeof(struct rtw_ieee80211_hdr_3addr)+_BEACON_IE_OFFSET_,
2046 pattrib->pktlen-sizeof (struct rtw_ieee80211_hdr_3addr)-_BEACON_IE_OFFSET_, NULL, &wps_ielen); 2044 pattrib->pktlen-sizeof(struct rtw_ieee80211_hdr_3addr)-_BEACON_IE_OFFSET_, NULL, &wps_ielen);
2047 if (wps_ie && wps_ielen > 0) 2045 if (wps_ie && wps_ielen > 0)
2048 rtw_get_wps_attr_content(wps_ie, wps_ielen, WPS_ATTR_SELECTED_REGISTRAR, (u8 *)(&sr), NULL); 2046 rtw_get_wps_attr_content(wps_ie, wps_ielen, WPS_ATTR_SELECTED_REGISTRAR, (u8 *)(&sr), NULL);
2049 if (sr != 0) 2047 if (sr != 0)
@@ -2101,7 +2099,7 @@ void issue_beacon(struct adapter *padapter, int timeout_ms)
2101 /* todo:HT for adhoc */ 2099 /* todo:HT for adhoc */
2102_issue_bcn: 2100_issue_bcn:
2103 2101
2104#if defined (CONFIG_88EU_AP_MODE) 2102#if defined(CONFIG_88EU_AP_MODE)
2105 pmlmepriv->update_bcn = false; 2103 pmlmepriv->update_bcn = false;
2106 2104
2107 spin_unlock_bh(&pmlmepriv->bcn_update_lock); 2105 spin_unlock_bh(&pmlmepriv->bcn_update_lock);
@@ -2130,7 +2128,7 @@ void issue_probersp(struct adapter *padapter, unsigned char *da, u8 is_valid_p2p
2130 __le16 *fctrl; 2128 __le16 *fctrl;
2131 unsigned char *mac, *bssid; 2129 unsigned char *mac, *bssid;
2132 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv); 2130 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
2133#if defined (CONFIG_88EU_AP_MODE) 2131#if defined(CONFIG_88EU_AP_MODE)
2134 u8 *pwps_ie; 2132 u8 *pwps_ie;
2135 uint wps_ielen; 2133 uint wps_ielen;
2136 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 2134 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
@@ -2323,8 +2321,8 @@ static int _issue_probereq(struct adapter *padapter, struct ndis_802_11_ssid *ps
2323 pmlmeext->mgnt_seq++; 2321 pmlmeext->mgnt_seq++;
2324 SetFrameSubType(pframe, WIFI_PROBEREQ); 2322 SetFrameSubType(pframe, WIFI_PROBEREQ);
2325 2323
2326 pframe += sizeof (struct rtw_ieee80211_hdr_3addr); 2324 pframe += sizeof(struct rtw_ieee80211_hdr_3addr);
2327 pattrib->pktlen = sizeof (struct rtw_ieee80211_hdr_3addr); 2325 pattrib->pktlen = sizeof(struct rtw_ieee80211_hdr_3addr);
2328 2326
2329 if (pssid) 2327 if (pssid)
2330 pframe = rtw_set_ie(pframe, _SSID_IE_, pssid->SsidLength, pssid->Ssid, &(pattrib->pktlen)); 2328 pframe = rtw_set_ie(pframe, _SSID_IE_, pssid->SsidLength, pssid->Ssid, &(pattrib->pktlen));
@@ -3209,7 +3207,7 @@ exit:
3209 return ret; 3207 return ret;
3210} 3208}
3211 3209
3212void issue_action_spct_ch_switch (struct adapter *padapter, u8 *ra, u8 new_ch, u8 ch_offset) 3210void issue_action_spct_ch_switch(struct adapter *padapter, u8 *ra, u8 new_ch, u8 ch_offset)
3213{ 3211{
3214 struct xmit_frame *pmgntframe; 3212 struct xmit_frame *pmgntframe;
3215 struct pkt_attrib *pattrib; 3213 struct pkt_attrib *pattrib;
@@ -3260,7 +3258,7 @@ void issue_action_spct_ch_switch (struct adapter *padapter, u8 *ra, u8 new_ch, u
3260 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen)); 3258 pframe = rtw_set_fixed_ie(pframe, 1, &(action), &(pattrib->pktlen));
3261 } 3259 }
3262 3260
3263 pframe = rtw_set_ie_ch_switch (pframe, &(pattrib->pktlen), 0, new_ch, 0); 3261 pframe = rtw_set_ie_ch_switch(pframe, &(pattrib->pktlen), 0, new_ch, 0);
3264 pframe = rtw_set_ie_secondary_ch_offset(pframe, &(pattrib->pktlen), 3262 pframe = rtw_set_ie_secondary_ch_offset(pframe, &(pattrib->pktlen),
3265 hal_ch_offset_to_secondary_ch_offset(ch_offset)); 3263 hal_ch_offset_to_secondary_ch_offset(ch_offset));
3266 3264
@@ -4835,7 +4833,7 @@ void linked_status_chk(struct adapter *padapter)
4835 4833
4836void survey_timer_hdl(void *function_context) 4834void survey_timer_hdl(void *function_context)
4837{ 4835{
4838 struct adapter *padapter = (struct adapter *)function_context; 4836 struct adapter *padapter = function_context;
4839 struct cmd_obj *ph2c; 4837 struct cmd_obj *ph2c;
4840 struct sitesurvey_parm *psurveyPara; 4838 struct sitesurvey_parm *psurveyPara;
4841 struct cmd_priv *pcmdpriv = &padapter->cmdpriv; 4839 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
@@ -4912,7 +4910,7 @@ void link_timer_hdl(void *function_context)
4912 4910
4913void addba_timer_hdl(void *function_context) 4911void addba_timer_hdl(void *function_context)
4914{ 4912{
4915 struct sta_info *psta = (struct sta_info *)function_context; 4913 struct sta_info *psta = function_context;
4916 struct ht_priv *phtpriv; 4914 struct ht_priv *phtpriv;
4917 4915
4918 if (!psta) 4916 if (!psta)
diff --git a/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c b/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
index 27ed83cca193..df463a29b641 100644
--- a/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
+++ b/drivers/staging/rtl8188eu/core/rtw_pwrctrl.c
@@ -279,12 +279,11 @@ void rtw_ps_processor(struct adapter *padapter)
279exit: 279exit:
280 rtw_set_pwr_state_check_timer(&padapter->pwrctrlpriv); 280 rtw_set_pwr_state_check_timer(&padapter->pwrctrlpriv);
281 pwrpriv->ps_processing = false; 281 pwrpriv->ps_processing = false;
282 return;
283} 282}
284 283
285static void pwr_state_check_handler(void *FunctionContext) 284static void pwr_state_check_handler(void *FunctionContext)
286{ 285{
287 struct adapter *padapter = (struct adapter *)FunctionContext; 286 struct adapter *padapter = FunctionContext;
288 rtw_ps_cmd(padapter); 287 rtw_ps_cmd(padapter);
289} 288}
290 289
@@ -527,7 +526,7 @@ void rtw_init_pwrctrl_priv(struct adapter *padapter)
527 526
528 pwrctrlpriv->LpsIdleCount = 0; 527 pwrctrlpriv->LpsIdleCount = 0;
529 if (padapter->registrypriv.mp_mode == 1) 528 if (padapter->registrypriv.mp_mode == 1)
530 pwrctrlpriv->power_mgnt = PS_MODE_ACTIVE ; 529 pwrctrlpriv->power_mgnt = PS_MODE_ACTIVE;
531 else 530 else
532 pwrctrlpriv->power_mgnt = padapter->registrypriv.power_mgnt;/* PS_MODE_MIN; */ 531 pwrctrlpriv->power_mgnt = padapter->registrypriv.power_mgnt;/* PS_MODE_MIN; */
533 pwrctrlpriv->bLeisurePs = (PS_MODE_ACTIVE != pwrctrlpriv->power_mgnt) ? true : false; 532 pwrctrlpriv->bLeisurePs = (PS_MODE_ACTIVE != pwrctrlpriv->power_mgnt) ? true : false;
@@ -577,7 +576,7 @@ int _rtw_pwr_wakeup(struct adapter *padapter, u32 ips_deffer_ms, const char *cal
577 if (pwrpriv->ps_processing) { 576 if (pwrpriv->ps_processing) {
578 DBG_88E("%s wait ps_processing...\n", __func__); 577 DBG_88E("%s wait ps_processing...\n", __func__);
579 while (pwrpriv->ps_processing && rtw_get_passing_time_ms(start) <= 3000) 578 while (pwrpriv->ps_processing && rtw_get_passing_time_ms(start) <= 3000)
580 msleep(10); 579 usleep_range(1000, 3000);
581 if (pwrpriv->ps_processing) 580 if (pwrpriv->ps_processing)
582 DBG_88E("%s wait ps_processing timeout\n", __func__); 581 DBG_88E("%s wait ps_processing timeout\n", __func__);
583 else 582 else
diff --git a/drivers/staging/rtl8188eu/core/rtw_recv.c b/drivers/staging/rtl8188eu/core/rtw_recv.c
index 4d56dbad2a7d..bd79e9e7105a 100644
--- a/drivers/staging/rtl8188eu/core/rtw_recv.c
+++ b/drivers/staging/rtl8188eu/core/rtw_recv.c
@@ -46,7 +46,7 @@ void rtw_signal_stat_timer_hdl(RTW_TIMER_HDL_ARGS);
46void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv) 46void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv)
47{ 47{
48 48
49 memset((u8 *)psta_recvpriv, 0, sizeof (struct sta_recv_priv)); 49 memset((u8 *)psta_recvpriv, 0, sizeof(struct sta_recv_priv));
50 50
51 spin_lock_init(&psta_recvpriv->lock); 51 spin_lock_init(&psta_recvpriv->lock);
52 52
@@ -109,7 +109,7 @@ exit:
109 return res; 109 return res;
110} 110}
111 111
112void _rtw_free_recv_priv (struct recv_priv *precvpriv) 112void _rtw_free_recv_priv(struct recv_priv *precvpriv)
113{ 113{
114 struct adapter *padapter = precvpriv->adapter; 114 struct adapter *padapter = precvpriv->adapter;
115 115
@@ -124,7 +124,7 @@ void _rtw_free_recv_priv (struct recv_priv *precvpriv)
124 124
125} 125}
126 126
127struct recv_frame *_rtw_alloc_recvframe (struct __queue *pfree_recv_queue) 127struct recv_frame *_rtw_alloc_recvframe(struct __queue *pfree_recv_queue)
128{ 128{
129 struct recv_frame *hdr; 129 struct recv_frame *hdr;
130 struct list_head *plist, *phead; 130 struct list_head *plist, *phead;
@@ -797,7 +797,7 @@ exit:
797 return ret; 797 return ret;
798} 798}
799 799
800static int ap2sta_data_frame ( 800static int ap2sta_data_frame(
801 struct adapter *adapter, 801 struct adapter *adapter,
802 struct recv_frame *precv_frame, 802 struct recv_frame *precv_frame,
803 struct sta_info **psta) 803 struct sta_info **psta)
@@ -1266,7 +1266,7 @@ static int validate_recv_frame(struct adapter *adapter,
1266 u8 bDumpRxPkt; 1266 u8 bDumpRxPkt;
1267 struct rx_pkt_attrib *pattrib = &precv_frame->attrib; 1267 struct rx_pkt_attrib *pattrib = &precv_frame->attrib;
1268 u8 *ptr = precv_frame->rx_data; 1268 u8 *ptr = precv_frame->rx_data;
1269 u8 ver = (unsigned char) (*ptr)&0x3; 1269 u8 ver = (unsigned char)(*ptr)&0x3;
1270 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv; 1270 struct mlme_ext_priv *pmlmeext = &adapter->mlmeextpriv;
1271 1271
1272 1272
@@ -1373,7 +1373,6 @@ static int wlanhdr_to_ethhdr(struct recv_frame *precvframe)
1373 u8 *psnap_type; 1373 u8 *psnap_type;
1374 struct ieee80211_snap_hdr *psnap; 1374 struct ieee80211_snap_hdr *psnap;
1375 1375
1376 int ret = _SUCCESS;
1377 struct adapter *adapter = precvframe->adapter; 1376 struct adapter *adapter = precvframe->adapter;
1378 struct mlme_priv *pmlmepriv = &adapter->mlmepriv; 1377 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
1379 u8 *ptr = precvframe->rx_data; 1378 u8 *ptr = precvframe->rx_data;
@@ -1428,7 +1427,7 @@ static int wlanhdr_to_ethhdr(struct recv_frame *precvframe)
1428 memcpy(ptr+12, &be_tmp, 2); 1427 memcpy(ptr+12, &be_tmp, 2);
1429 } 1428 }
1430 1429
1431 return ret; 1430 return _SUCCESS;
1432} 1431}
1433 1432
1434/* perform defrag */ 1433/* perform defrag */
@@ -1624,7 +1623,6 @@ static int amsdu_to_msdu(struct adapter *padapter, struct recv_frame *prframe)
1624 struct sk_buff *sub_skb, *subframes[MAX_SUBFRAME_COUNT]; 1623 struct sk_buff *sub_skb, *subframes[MAX_SUBFRAME_COUNT];
1625 struct recv_priv *precvpriv = &padapter->recvpriv; 1624 struct recv_priv *precvpriv = &padapter->recvpriv;
1626 struct __queue *pfree_recv_queue = &(precvpriv->free_recv_queue); 1625 struct __queue *pfree_recv_queue = &(precvpriv->free_recv_queue);
1627 int ret = _SUCCESS;
1628 nr_subframes = 0; 1626 nr_subframes = 0;
1629 1627
1630 pattrib = &prframe->attrib; 1628 pattrib = &prframe->attrib;
@@ -1728,7 +1726,7 @@ exit:
1728 prframe->len = 0; 1726 prframe->len = 0;
1729 rtw_free_recvframe(prframe, pfree_recv_queue);/* free this recv_frame */ 1727 rtw_free_recvframe(prframe, pfree_recv_queue);/* free this recv_frame */
1730 1728
1731 return ret; 1729 return _SUCCESS;
1732} 1730}
1733 1731
1734static int check_indicate_seq(struct recv_reorder_ctrl *preorder_ctrl, u16 seq_num) 1732static int check_indicate_seq(struct recv_reorder_ctrl *preorder_ctrl, u16 seq_num)
@@ -1949,7 +1947,7 @@ _err_exit:
1949 1947
1950void rtw_reordering_ctrl_timeout_handler(void *pcontext) 1948void rtw_reordering_ctrl_timeout_handler(void *pcontext)
1951{ 1949{
1952 struct recv_reorder_ctrl *preorder_ctrl = (struct recv_reorder_ctrl *)pcontext; 1950 struct recv_reorder_ctrl *preorder_ctrl = pcontext;
1953 struct adapter *padapter = preorder_ctrl->padapter; 1951 struct adapter *padapter = preorder_ctrl->padapter;
1954 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue; 1952 struct __queue *ppending_recvframe_queue = &preorder_ctrl->pending_recvframe_queue;
1955 1953
@@ -1981,7 +1979,7 @@ static int process_recv_indicatepkts(struct adapter *padapter,
1981 } 1979 }
1982 } 1980 }
1983 } else { /* B/G mode */ 1981 } else { /* B/G mode */
1984 retval = wlanhdr_to_ethhdr (prframe); 1982 retval = wlanhdr_to_ethhdr(prframe);
1985 if (retval != _SUCCESS) { 1983 if (retval != _SUCCESS) {
1986 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("wlanhdr_to_ethhdr: drop pkt\n")); 1984 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, ("wlanhdr_to_ethhdr: drop pkt\n"));
1987 return retval; 1985 return retval;
diff --git a/drivers/staging/rtl8188eu/core/rtw_security.c b/drivers/staging/rtl8188eu/core/rtw_security.c
index f9096a512da5..bd8d60a230e9 100644
--- a/drivers/staging/rtl8188eu/core/rtw_security.c
+++ b/drivers/staging/rtl8188eu/core/rtw_security.c
@@ -189,7 +189,7 @@ void rtw_wep_encrypt(struct adapter *padapter, u8 *pxmitframe)
189 arcfour_encrypt(&mycontext, payload+length, crc, 4); 189 arcfour_encrypt(&mycontext, payload+length, crc, 4);
190 190
191 pframe += pxmitpriv->frag_len; 191 pframe += pxmitpriv->frag_len;
192 pframe = (u8 *) round_up((size_t)(pframe), 4); 192 pframe = (u8 *)round_up((size_t)(pframe), 4);
193 } 193 }
194 } 194 }
195 } 195 }
@@ -258,7 +258,7 @@ static void secmicputuint32(u8 *p, u32 val)
258{ 258{
259 long i; 259 long i;
260 for (i = 0; i < 4; i++) { 260 for (i = 0; i < 4; i++) {
261 *p++ = (u8) (val & 0xff); 261 *p++ = (u8)(val & 0xff);
262 val >>= 8; 262 val >>= 8;
263 } 263 }
264} 264}
@@ -621,14 +621,14 @@ u32 rtw_tkip_encrypt(struct adapter *padapter, u8 *pxmitframe)
621 arcfour_encrypt(&mycontext, payload, payload, length); 621 arcfour_encrypt(&mycontext, payload, payload, length);
622 arcfour_encrypt(&mycontext, payload+length, crc, 4); 622 arcfour_encrypt(&mycontext, payload+length, crc, 4);
623 } else { 623 } else {
624 length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len ; 624 length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
625 *((__le32 *)crc) = getcrc32(payload, length);/* modified by Amy*/ 625 *((__le32 *)crc) = getcrc32(payload, length);/* modified by Amy*/
626 arcfour_init(&mycontext, rc4key, 16); 626 arcfour_init(&mycontext, rc4key, 16);
627 arcfour_encrypt(&mycontext, payload, payload, length); 627 arcfour_encrypt(&mycontext, payload, payload, length);
628 arcfour_encrypt(&mycontext, payload+length, crc, 4); 628 arcfour_encrypt(&mycontext, payload+length, crc, 4);
629 629
630 pframe += pxmitpriv->frag_len; 630 pframe += pxmitpriv->frag_len;
631 pframe = (u8 *) round_up((size_t)(pframe), 4); 631 pframe = (u8 *)round_up((size_t)(pframe), 4);
632 } 632 }
633 } 633 }
634 } else { 634 } else {
@@ -953,8 +953,8 @@ static void construct_mic_iv(u8 *mic_iv, int qc_exists, int a4_exists, u8 *mpdu,
953 mic_iv[i] = mpdu[i + 8]; /* mic_iv[2:7] = A2[0:5] = mpdu[10:15] */ 953 mic_iv[i] = mpdu[i + 8]; /* mic_iv[2:7] = A2[0:5] = mpdu[10:15] */
954 for (i = 8; i < 14; i++) 954 for (i = 8; i < 14; i++)
955 mic_iv[i] = pn_vector[13 - i]; /* mic_iv[8:13] = PN[5:0] */ 955 mic_iv[i] = pn_vector[13 - i]; /* mic_iv[8:13] = PN[5:0] */
956 mic_iv[14] = (unsigned char) (payload_length / 256); 956 mic_iv[14] = (unsigned char)(payload_length / 256);
957 mic_iv[15] = (unsigned char) (payload_length % 256); 957 mic_iv[15] = (unsigned char)(payload_length % 256);
958} 958}
959 959
960/************************************************/ 960/************************************************/
@@ -1045,8 +1045,8 @@ static void construct_ctr_preload(u8 *ctr_preload, int a4_exists, int qc_exists,
1045 ctr_preload[i] = mpdu[i + 8]; /* ctr_preload[2:7] = A2[0:5] = mpdu[10:15] */ 1045 ctr_preload[i] = mpdu[i + 8]; /* ctr_preload[2:7] = A2[0:5] = mpdu[10:15] */
1046 for (i = 8; i < 14; i++) 1046 for (i = 8; i < 14; i++)
1047 ctr_preload[i] = pn_vector[13 - i]; /* ctr_preload[8:13] = PN[5:0] */ 1047 ctr_preload[i] = pn_vector[13 - i]; /* ctr_preload[8:13] = PN[5:0] */
1048 ctr_preload[14] = (unsigned char) (c / 256); /* Ctr */ 1048 ctr_preload[14] = (unsigned char)(c / 256); /* Ctr */
1049 ctr_preload[15] = (unsigned char) (c % 256); 1049 ctr_preload[15] = (unsigned char)(c % 256);
1050} 1050}
1051 1051
1052/************************************/ 1052/************************************/
@@ -1219,7 +1219,7 @@ u32 rtw_aes_encrypt(struct adapter *padapter, u8 *pxmitframe)
1219 pframe = ((struct xmit_frame *)pxmitframe)->buf_addr + hw_hdr_offset; 1219 pframe = ((struct xmit_frame *)pxmitframe)->buf_addr + hw_hdr_offset;
1220 1220
1221 /* 4 start to encrypt each fragment */ 1221 /* 4 start to encrypt each fragment */
1222 if ((pattrib->encrypt == _AES_)) { 1222 if (pattrib->encrypt == _AES_) {
1223 if (pattrib->psta) 1223 if (pattrib->psta)
1224 stainfo = pattrib->psta; 1224 stainfo = pattrib->psta;
1225 else 1225 else
@@ -1238,11 +1238,11 @@ u32 rtw_aes_encrypt(struct adapter *padapter, u8 *pxmitframe)
1238 1238
1239 aes_cipher(prwskey, pattrib->hdrlen, pframe, length); 1239 aes_cipher(prwskey, pattrib->hdrlen, pframe, length);
1240 } else{ 1240 } else{
1241 length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len ; 1241 length = pxmitpriv->frag_len-pattrib->hdrlen-pattrib->iv_len-pattrib->icv_len;
1242 1242
1243 aes_cipher(prwskey, pattrib->hdrlen, pframe, length); 1243 aes_cipher(prwskey, pattrib->hdrlen, pframe, length);
1244 pframe += pxmitpriv->frag_len; 1244 pframe += pxmitpriv->frag_len;
1245 pframe = (u8 *) round_up((size_t)(pframe), 8); 1245 pframe = (u8 *)round_up((size_t)(pframe), 8);
1246 } 1246 }
1247 } 1247 }
1248 } else{ 1248 } else{
@@ -1460,7 +1460,7 @@ u32 rtw_aes_decrypt(struct adapter *padapter, u8 *precvframe)
1460 u32 res = _SUCCESS; 1460 u32 res = _SUCCESS;
1461 pframe = (unsigned char *)((struct recv_frame *)precvframe)->rx_data; 1461 pframe = (unsigned char *)((struct recv_frame *)precvframe)->rx_data;
1462 /* 4 start to encrypt each fragment */ 1462 /* 4 start to encrypt each fragment */
1463 if ((prxattrib->encrypt == _AES_)) { 1463 if (prxattrib->encrypt == _AES_) {
1464 stainfo = rtw_get_stainfo(&padapter->stapriv, &prxattrib->ta[0]); 1464 stainfo = rtw_get_stainfo(&padapter->stapriv, &prxattrib->ta[0]);
1465 if (stainfo != NULL) { 1465 if (stainfo != NULL) {
1466 RT_TRACE(_module_rtl871x_security_c_, _drv_err_, ("rtw_aes_decrypt: stainfo!= NULL!!!\n")); 1466 RT_TRACE(_module_rtl871x_security_c_, _drv_err_, ("rtw_aes_decrypt: stainfo!= NULL!!!\n"));
diff --git a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
index e1dc8fa82d38..dc9d0ddf6b3a 100644
--- a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
+++ b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
@@ -29,7 +29,7 @@
29 29
30static void _rtw_init_stainfo(struct sta_info *psta) 30static void _rtw_init_stainfo(struct sta_info *psta)
31{ 31{
32 memset((u8 *)psta, 0, sizeof (struct sta_info)); 32 memset((u8 *)psta, 0, sizeof(struct sta_info));
33 33
34 spin_lock_init(&psta->lock); 34 spin_lock_init(&psta->lock);
35 INIT_LIST_HEAD(&psta->list); 35 INIT_LIST_HEAD(&psta->list);
diff --git a/drivers/staging/rtl8188eu/core/rtw_wlan_util.c b/drivers/staging/rtl8188eu/core/rtw_wlan_util.c
index d300369977fa..324c1a7fd0bc 100644
--- a/drivers/staging/rtl8188eu/core/rtw_wlan_util.c
+++ b/drivers/staging/rtl8188eu/core/rtw_wlan_util.c
@@ -1394,7 +1394,6 @@ unsigned char check_assoc_AP(u8 *pframe, uint len)
1394 DBG_88E("link to Artheros AP\n"); 1394 DBG_88E("link to Artheros AP\n");
1395 return HT_IOT_PEER_ATHEROS; 1395 return HT_IOT_PEER_ATHEROS;
1396 } else if ((!memcmp(pIE->data, BROADCOM_OUI1, 3)) || 1396 } else if ((!memcmp(pIE->data, BROADCOM_OUI1, 3)) ||
1397 (!memcmp(pIE->data, BROADCOM_OUI2, 3)) ||
1398 (!memcmp(pIE->data, BROADCOM_OUI2, 3))) { 1397 (!memcmp(pIE->data, BROADCOM_OUI2, 3))) {
1399 DBG_88E("link to Broadcom AP\n"); 1398 DBG_88E("link to Broadcom AP\n");
1400 return HT_IOT_PEER_BROADCOM; 1399 return HT_IOT_PEER_BROADCOM;
diff --git a/drivers/staging/rtl8188eu/core/rtw_xmit.c b/drivers/staging/rtl8188eu/core/rtw_xmit.c
index 639ace06a3d6..7a71df167464 100644
--- a/drivers/staging/rtl8188eu/core/rtw_xmit.c
+++ b/drivers/staging/rtl8188eu/core/rtw_xmit.c
@@ -37,7 +37,7 @@ static void _init_txservq(struct tx_servq *ptxservq)
37 37
38void _rtw_init_sta_xmit_priv(struct sta_xmit_priv *psta_xmitpriv) 38void _rtw_init_sta_xmit_priv(struct sta_xmit_priv *psta_xmitpriv)
39{ 39{
40 memset((unsigned char *)psta_xmitpriv, 0, sizeof (struct sta_xmit_priv)); 40 memset((unsigned char *)psta_xmitpriv, 0, sizeof(struct sta_xmit_priv));
41 spin_lock_init(&psta_xmitpriv->lock); 41 spin_lock_init(&psta_xmitpriv->lock);
42 _init_txservq(&psta_xmitpriv->be_q); 42 _init_txservq(&psta_xmitpriv->be_q);
43 _init_txservq(&psta_xmitpriv->bk_q); 43 _init_txservq(&psta_xmitpriv->bk_q);
@@ -223,7 +223,7 @@ exit:
223 return res; 223 return res;
224} 224}
225 225
226void _rtw_free_xmit_priv (struct xmit_priv *pxmitpriv) 226void _rtw_free_xmit_priv(struct xmit_priv *pxmitpriv)
227{ 227{
228 int i; 228 int i;
229 struct adapter *padapter = pxmitpriv->adapter; 229 struct adapter *padapter = pxmitpriv->adapter;
@@ -691,7 +691,7 @@ static s32 xmitframe_addmic(struct adapter *padapter, struct xmit_frame *pxmitfr
691 payload = pframe; 691 payload = pframe;
692 692
693 for (curfragnum = 0; curfragnum < pattrib->nr_frags; curfragnum++) { 693 for (curfragnum = 0; curfragnum < pattrib->nr_frags; curfragnum++) {
694 payload = (u8 *) round_up((size_t)(payload), 4); 694 payload = (u8 *)round_up((size_t)(payload), 4);
695 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_, 695 RT_TRACE(_module_rtl871x_xmit_c_, _drv_err_,
696 ("=== curfragnum=%d, pframe = 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x,!!!\n", 696 ("=== curfragnum=%d, pframe = 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x,!!!\n",
697 curfragnum, *payload, *(payload+1), 697 curfragnum, *payload, *(payload+1),
@@ -772,7 +772,7 @@ static s32 xmitframe_swencrypt(struct adapter *padapter, struct xmit_frame *pxmi
772 return _SUCCESS; 772 return _SUCCESS;
773} 773}
774 774
775s32 rtw_make_wlanhdr (struct adapter *padapter , u8 *hdr, struct pkt_attrib *pattrib) 775s32 rtw_make_wlanhdr(struct adapter *padapter, u8 *hdr, struct pkt_attrib *pattrib)
776{ 776{
777 u16 *qc; 777 u16 *qc;
778 778
@@ -1025,8 +1025,7 @@ s32 rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct
1025 1025
1026 /* adding icv, if necessary... */ 1026 /* adding icv, if necessary... */
1027 if (pattrib->iv_len) { 1027 if (pattrib->iv_len) {
1028 if (psta != NULL) { 1028 switch (pattrib->encrypt) {
1029 switch (pattrib->encrypt) {
1030 case _WEP40_: 1029 case _WEP40_:
1031 case _WEP104_: 1030 case _WEP104_:
1032 WEP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx); 1031 WEP_IV(pattrib->iv, psta->dot11txpn, pattrib->key_idx);
@@ -1043,7 +1042,6 @@ s32 rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct
1043 else 1042 else
1044 AES_IV(pattrib->iv, psta->dot11txpn, 0); 1043 AES_IV(pattrib->iv, psta->dot11txpn, 0);
1045 break; 1044 break;
1046 }
1047 } 1045 }
1048 1046
1049 memcpy(pframe, pattrib->iv, pattrib->iv_len); 1047 memcpy(pframe, pattrib->iv, pattrib->iv_len);
@@ -1098,7 +1096,7 @@ s32 rtw_xmitframe_coalesce(struct adapter *padapter, struct sk_buff *pkt, struct
1098 1096
1099 addr = (size_t)(pframe); 1097 addr = (size_t)(pframe);
1100 1098
1101 mem_start = (unsigned char *) round_up(addr, 4) + hw_hdr_offset; 1099 mem_start = (unsigned char *)round_up(addr, 4) + hw_hdr_offset;
1102 memcpy(mem_start, pbuf_start + hw_hdr_offset, pattrib->hdrlen); 1100 memcpy(mem_start, pbuf_start + hw_hdr_offset, pattrib->hdrlen);
1103 } 1101 }
1104 1102
diff --git a/drivers/staging/rtl8188eu/hal/bb_cfg.c b/drivers/staging/rtl8188eu/hal/bb_cfg.c
index 80e8cc92c10a..1e963bf9e48b 100644
--- a/drivers/staging/rtl8188eu/hal/bb_cfg.c
+++ b/drivers/staging/rtl8188eu/hal/bb_cfg.c
@@ -173,7 +173,7 @@ static bool set_baseband_agc_config(struct adapter *adapt)
173 u32 v1 = array[i]; 173 u32 v1 = array[i];
174 u32 v2 = array[i+1]; 174 u32 v2 = array[i+1];
175 175
176 if (v1 < 0xCDCDCDCD){ 176 if (v1 < 0xCDCDCDCD) {
177 phy_set_bb_reg(adapt, v1, bMaskDWord, v2); 177 phy_set_bb_reg(adapt, v1, bMaskDWord, v2);
178 udelay(1); 178 udelay(1);
179 } 179 }
@@ -552,7 +552,7 @@ static void store_pwrindex_offset(struct adapter *Adapter, u32 regaddr, u32 bitm
552 } 552 }
553} 553}
554 554
555static void rtl_addr_delay(struct adapter *adapt, u32 addr, u32 bit_mask ,u32 data) 555static void rtl_addr_delay(struct adapter *adapt, u32 addr, u32 bit_mask, u32 data)
556{ 556{
557 if (addr == 0xfe) { 557 if (addr == 0xfe) {
558 msleep(50); 558 msleep(50);
diff --git a/drivers/staging/rtl8188eu/hal/fw.c b/drivers/staging/rtl8188eu/hal/fw.c
index 17b7f3750547..3b2875481fc5 100644
--- a/drivers/staging/rtl8188eu/hal/fw.c
+++ b/drivers/staging/rtl8188eu/hal/fw.c
@@ -84,7 +84,7 @@ static void _rtl88e_fw_block_write(struct adapter *adapt,
84static void _rtl88e_fill_dummy(u8 *pfwbuf, u32 *pfwlen) 84static void _rtl88e_fill_dummy(u8 *pfwbuf, u32 *pfwlen)
85{ 85{
86 u32 fwlen = *pfwlen; 86 u32 fwlen = *pfwlen;
87 u8 remain = (u8) (fwlen % 4); 87 u8 remain = (u8)(fwlen % 4);
88 88
89 remain = (remain == 0) ? 0 : (4 - remain); 89 remain = (remain == 0) ? 0 : (4 - remain);
90 90
@@ -101,7 +101,7 @@ static void _rtl88e_fw_page_write(struct adapter *adapt,
101 u32 page, const u8 *buffer, u32 size) 101 u32 page, const u8 *buffer, u32 size)
102{ 102{
103 u8 value8; 103 u8 value8;
104 u8 u8page = (u8) (page & 0x07); 104 u8 u8page = (u8)(page & 0x07);
105 105
106 value8 = (usb_read8(adapt, REG_MCUFWDL + 2) & 0xF8) | u8page; 106 value8 = (usb_read8(adapt, REG_MCUFWDL + 2) & 0xF8) | u8page;
107 107
@@ -193,13 +193,13 @@ int rtl88eu_download_fw(struct adapter *adapt)
193 u32 fwsize; 193 u32 fwsize;
194 int err; 194 int err;
195 195
196 if (request_firmware(&fw, fw_name, device)){ 196 if (request_firmware(&fw, fw_name, device)) {
197 dev_err(device, "Firmware %s not available\n", fw_name); 197 dev_err(device, "Firmware %s not available\n", fw_name);
198 return -ENOENT; 198 return -ENOENT;
199 } 199 }
200 200
201 if (fw->size > FW_8188E_SIZE) { 201 if (fw->size > FW_8188E_SIZE) {
202 dev_err(device,"Firmware size exceed 0x%X. Check it.\n", 202 dev_err(device, "Firmware size exceed 0x%X. Check it.\n",
203 FW_8188E_SIZE); 203 FW_8188E_SIZE);
204 return -1; 204 return -1;
205 } 205 }
diff --git a/drivers/staging/rtl8188eu/hal/hal_intf.c b/drivers/staging/rtl8188eu/hal/hal_intf.c
index 538a0f65d09c..4bdbed28774e 100644
--- a/drivers/staging/rtl8188eu/hal/hal_intf.c
+++ b/drivers/staging/rtl8188eu/hal/hal_intf.c
@@ -275,13 +275,6 @@ void rtw_hal_write_rfreg(struct adapter *adapt, enum rf_radio_path rfpath,
275 bitmask, data); 275 bitmask, data);
276} 276}
277 277
278s32 rtw_hal_interrupt_handler(struct adapter *adapt)
279{
280 if (adapt->HalFunc.interrupt_handler)
281 return adapt->HalFunc.interrupt_handler(adapt);
282 return _FAIL;
283}
284
285void rtw_hal_set_bwmode(struct adapter *adapt, 278void rtw_hal_set_bwmode(struct adapter *adapt,
286 enum ht_channel_width bandwidth, u8 offset) 279 enum ht_channel_width bandwidth, u8 offset)
287{ 280{
@@ -329,15 +322,6 @@ void rtw_hal_sreset_init(struct adapter *adapt)
329 adapt->HalFunc.sreset_init_value(adapt); 322 adapt->HalFunc.sreset_init_value(adapt);
330} 323}
331 324
332u8 rtw_hal_sreset_get_wifi_status(struct adapter *adapt)
333{
334 u8 status = 0;
335
336 if (adapt->HalFunc.sreset_get_wifi_status)
337 status = adapt->HalFunc.sreset_get_wifi_status(adapt);
338 return status;
339}
340
341void rtw_hal_notch_filter(struct adapter *adapter, bool enable) 325void rtw_hal_notch_filter(struct adapter *adapter, bool enable)
342{ 326{
343 if (adapter->HalFunc.hal_notch_filter) 327 if (adapter->HalFunc.hal_notch_filter)
diff --git a/drivers/staging/rtl8188eu/hal/mac_cfg.c b/drivers/staging/rtl8188eu/hal/mac_cfg.c
index c0e7fa938059..febc83a5adb8 100644
--- a/drivers/staging/rtl8188eu/hal/mac_cfg.c
+++ b/drivers/staging/rtl8188eu/hal/mac_cfg.c
@@ -127,7 +127,7 @@ bool rtl88eu_phy_mac_config(struct adapter *adapt)
127 ptrarray = array_MAC_REG_8188E; 127 ptrarray = array_MAC_REG_8188E;
128 128
129 for (i = 0; i < arraylength; i = i + 2) 129 for (i = 0; i < arraylength; i = i + 2)
130 usb_write8(adapt, ptrarray[i], (u8) ptrarray[i + 1]); 130 usb_write8(adapt, ptrarray[i], (u8)ptrarray[i + 1]);
131 131
132 usb_write8(adapt, REG_MAX_AGGR_NUM, MAX_AGGR_NUM); 132 usb_write8(adapt, REG_MAX_AGGR_NUM, MAX_AGGR_NUM);
133 return true; 133 return true;
diff --git a/drivers/staging/rtl8188eu/hal/odm.c b/drivers/staging/rtl8188eu/hal/odm.c
index e4df83710ca6..9873998011d2 100644
--- a/drivers/staging/rtl8188eu/hal/odm.c
+++ b/drivers/staging/rtl8188eu/hal/odm.c
@@ -437,8 +437,8 @@ void odm_CommonInfoSelfInit(struct odm_dm_struct *pDM_Odm)
437{ 437{
438 struct adapter *adapter = pDM_Odm->Adapter; 438 struct adapter *adapter = pDM_Odm->Adapter;
439 439
440 pDM_Odm->bCckHighPower = (bool) phy_query_bb_reg(adapter, 0x824, BIT9); 440 pDM_Odm->bCckHighPower = (bool)phy_query_bb_reg(adapter, 0x824, BIT9);
441 pDM_Odm->RFPathRxEnable = (u8) phy_query_bb_reg(adapter, 0xc04, 0x0F); 441 pDM_Odm->RFPathRxEnable = (u8)phy_query_bb_reg(adapter, 0xc04, 0x0F);
442 442
443 ODM_InitDebugSetting(pDM_Odm); 443 ODM_InitDebugSetting(pDM_Odm);
444} 444}
@@ -529,7 +529,7 @@ void odm_DIGInit(struct odm_dm_struct *pDM_Odm)
529 struct adapter *adapter = pDM_Odm->Adapter; 529 struct adapter *adapter = pDM_Odm->Adapter;
530 struct rtw_dig *pDM_DigTable = &pDM_Odm->DM_DigTable; 530 struct rtw_dig *pDM_DigTable = &pDM_Odm->DM_DigTable;
531 531
532 pDM_DigTable->CurIGValue = (u8) phy_query_bb_reg(adapter, ODM_REG_IGI_A_11N, ODM_BIT_IGI_11N); 532 pDM_DigTable->CurIGValue = (u8)phy_query_bb_reg(adapter, ODM_REG_IGI_A_11N, ODM_BIT_IGI_11N);
533 pDM_DigTable->RssiLowThresh = DM_DIG_THRESH_LOW; 533 pDM_DigTable->RssiLowThresh = DM_DIG_THRESH_LOW;
534 pDM_DigTable->RssiHighThresh = DM_DIG_THRESH_HIGH; 534 pDM_DigTable->RssiHighThresh = DM_DIG_THRESH_HIGH;
535 pDM_DigTable->FALowThresh = DM_false_ALARM_THRESH_LOW; 535 pDM_DigTable->FALowThresh = DM_false_ALARM_THRESH_LOW;
@@ -620,7 +620,7 @@ void odm_DIG(struct odm_dm_struct *pDM_Odm)
620 } else if (pDM_Odm->SupportAbility & ODM_BB_ANT_DIV) { 620 } else if (pDM_Odm->SupportAbility & ODM_BB_ANT_DIV) {
621 /* 1 Lower Bound for 88E AntDiv */ 621 /* 1 Lower Bound for 88E AntDiv */
622 if (pDM_Odm->AntDivType == CG_TRX_HW_ANTDIV) { 622 if (pDM_Odm->AntDivType == CG_TRX_HW_ANTDIV) {
623 DIG_Dynamic_MIN = (u8) pDM_DigTable->AntDiv_RSSI_max; 623 DIG_Dynamic_MIN = (u8)pDM_DigTable->AntDiv_RSSI_max;
624 ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD, 624 ODM_RT_TRACE(pDM_Odm, ODM_COMP_ANT_DIV, ODM_DBG_LOUD,
625 ("odm_DIG(): pDM_DigTable->AntDiv_RSSI_max=%d\n", 625 ("odm_DIG(): pDM_DigTable->AntDiv_RSSI_max=%d\n",
626 pDM_DigTable->AntDiv_RSSI_max)); 626 pDM_DigTable->AntDiv_RSSI_max));
diff --git a/drivers/staging/rtl8188eu/hal/odm_HWConfig.c b/drivers/staging/rtl8188eu/hal/odm_HWConfig.c
index 4e4e21936e7c..29f87dffbad3 100644
--- a/drivers/staging/rtl8188eu/hal/odm_HWConfig.c
+++ b/drivers/staging/rtl8188eu/hal/odm_HWConfig.c
@@ -118,7 +118,7 @@ static void odm_RxPhyStatus92CSeries_Parsing(struct odm_dm_struct *dm_odm,
118 118
119 cck_highpwr = dm_odm->bCckHighPower; 119 cck_highpwr = dm_odm->bCckHighPower;
120 120
121 cck_agc_rpt = pPhyStaRpt->cck_agc_rpt_ofdm_cfosho_a ; 121 cck_agc_rpt = pPhyStaRpt->cck_agc_rpt_ofdm_cfosho_a;
122 122
123 /* 2011.11.28 LukeLee: 88E use different LNA & VGA gain table */ 123 /* 2011.11.28 LukeLee: 88E use different LNA & VGA gain table */
124 /* The RSSI formula should be modified according to the gain table */ 124 /* The RSSI formula should be modified according to the gain table */
diff --git a/drivers/staging/rtl8188eu/hal/odm_RTL8188E.c b/drivers/staging/rtl8188eu/hal/odm_RTL8188E.c
index 5342af778eb0..d3c6873925ba 100644
--- a/drivers/staging/rtl8188eu/hal/odm_RTL8188E.c
+++ b/drivers/staging/rtl8188eu/hal/odm_RTL8188E.c
@@ -278,7 +278,7 @@ static void rtl88eu_dm_hw_ant_div(struct odm_dm_struct *dm_odm)
278 struct rtw_dig *dig_table = &dm_odm->DM_DigTable; 278 struct rtw_dig *dig_table = &dm_odm->DM_DigTable;
279 struct sta_info *entry; 279 struct sta_info *entry;
280 u32 i, min_rssi = 0xFF, ant_div_max_rssi = 0, max_rssi = 0; 280 u32 i, min_rssi = 0xFF, ant_div_max_rssi = 0, max_rssi = 0;
281 u32 local_min_rssi,local_max_rssi; 281 u32 local_min_rssi, local_max_rssi;
282 u32 main_rssi, aux_rssi; 282 u32 main_rssi, aux_rssi;
283 u8 RxIdleAnt = 0, target_ant = 7; 283 u8 RxIdleAnt = 0, target_ant = 7;
284 284
diff --git a/drivers/staging/rtl8188eu/hal/phy.c b/drivers/staging/rtl8188eu/hal/phy.c
index c4f7f358a81c..3f663fe151ba 100644
--- a/drivers/staging/rtl8188eu/hal/phy.c
+++ b/drivers/staging/rtl8188eu/hal/phy.c
@@ -478,7 +478,7 @@ void rtl88eu_dm_txpower_tracking_callback_thermalmeter(struct adapter *adapt)
478 /* 2.4G, decrease power */ 478 /* 2.4G, decrease power */
479 {0, 0, 2, 3, 4, 4, 5, 6, 7, 7, 8, 9, 10, 10, 11}, 479 {0, 0, 2, 3, 4, 4, 5, 6, 7, 7, 8, 9, 10, 10, 11},
480 /* 2.4G, increase power */ 480 /* 2.4G, increase power */
481 {0, 0, -1, -2, -3, -4,-4, -4, -4, -5, -7, -8,-9, -9, -10}, 481 {0, 0, -1, -2, -3, -4, -4, -4, -4, -5, -7, -8, -9, -9, -10},
482 }; 482 };
483 u8 thermal_mapping[2][index_mapping_NUM_88E] = { 483 u8 thermal_mapping[2][index_mapping_NUM_88E] = {
484 /* 2.4G, decrease power */ 484 /* 2.4G, decrease power */
diff --git a/drivers/staging/rtl8188eu/hal/rf.c b/drivers/staging/rtl8188eu/hal/rf.c
index c2fac34c8132..eea4c8a6022b 100644
--- a/drivers/staging/rtl8188eu/hal/rf.c
+++ b/drivers/staging/rtl8188eu/hal/rf.c
@@ -131,7 +131,7 @@ void rtl88eu_phy_rf6052_set_cck_txpower(struct adapter *adapt, u8 *powerlevel)
131/* powerbase1 for HT MCS rates */ 131/* powerbase1 for HT MCS rates */
132static void getpowerbase88e(struct adapter *adapt, u8 *pwr_level_ofdm, 132static void getpowerbase88e(struct adapter *adapt, u8 *pwr_level_ofdm,
133 u8 *pwr_level_bw20, u8 *pwr_level_bw40, 133 u8 *pwr_level_bw20, u8 *pwr_level_bw40,
134 u8 channel,u32 *ofdmbase, u32 *mcs_base) 134 u8 channel, u32 *ofdmbase, u32 *mcs_base)
135{ 135{
136 struct hal_data_8188e *hal_data = GET_HAL_DATA(adapt); 136 struct hal_data_8188e *hal_data = GET_HAL_DATA(adapt);
137 u32 powerbase0, powerbase1; 137 u32 powerbase0, powerbase1;
diff --git a/drivers/staging/rtl8188eu/hal/rf_cfg.c b/drivers/staging/rtl8188eu/hal/rf_cfg.c
index ddc2f55fe13f..5dc11cae2ef9 100644
--- a/drivers/staging/rtl8188eu/hal/rf_cfg.c
+++ b/drivers/staging/rtl8188eu/hal/rf_cfg.c
@@ -164,7 +164,7 @@ do { \
164#define B3WIREDATALENGTH 0x800 164#define B3WIREDATALENGTH 0x800
165#define BRFSI_RFENV 0x10 165#define BRFSI_RFENV 0x10
166 166
167static void rtl_rfreg_delay(struct adapter *adapt, enum rf_radio_path rfpath,u32 addr, u32 mask, u32 data) 167static void rtl_rfreg_delay(struct adapter *adapt, enum rf_radio_path rfpath, u32 addr, u32 mask, u32 data)
168{ 168{
169 if (addr == 0xfe) { 169 if (addr == 0xfe) {
170 mdelay(50); 170 mdelay(50);
@@ -190,7 +190,7 @@ static void rtl8188e_config_rf_reg(struct adapter *adapt,
190 u32 content = 0x1000; /*RF Content: radio_a_txt*/ 190 u32 content = 0x1000; /*RF Content: radio_a_txt*/
191 u32 maskforphyset = (u32)(content & 0xE000); 191 u32 maskforphyset = (u32)(content & 0xE000);
192 192
193 rtl_rfreg_delay(adapt, RF90_PATH_A, addr| maskforphyset, 193 rtl_rfreg_delay(adapt, RF90_PATH_A, addr | maskforphyset,
194 RFREG_OFFSET_MASK, 194 RFREG_OFFSET_MASK,
195 data); 195 data);
196} 196}
diff --git a/drivers/staging/rtl8188eu/hal/rtl8188e_cmd.c b/drivers/staging/rtl8188eu/hal/rtl8188e_cmd.c
index 023a3d84ee8b..7f30dea1b53b 100644
--- a/drivers/staging/rtl8188eu/hal/rtl8188e_cmd.c
+++ b/drivers/staging/rtl8188eu/hal/rtl8188e_cmd.c
@@ -150,11 +150,9 @@ u8 rtl8188e_set_raid_cmd(struct adapter *adapt, u32 mask)
150 struct hal_data_8188e *haldata = GET_HAL_DATA(adapt); 150 struct hal_data_8188e *haldata = GET_HAL_DATA(adapt);
151 151
152 if (haldata->fw_ractrl) { 152 if (haldata->fw_ractrl) {
153 __le32 lmask;
154 153
155 memset(buf, 0, 3); 154 memset(buf, 0, 3);
156 lmask = cpu_to_le32(mask); 155 put_unaligned_le32(mask, buf);
157 memcpy(buf, &lmask, 3);
158 156
159 FillH2CCmd_88E(adapt, H2C_DM_MACID_CFG, 3, buf); 157 FillH2CCmd_88E(adapt, H2C_DM_MACID_CFG, 3, buf);
160 } else { 158 } else {
@@ -254,7 +252,7 @@ void rtl8188e_set_FwMediaStatus_cmd(struct adapter *adapt, __le16 mstatus_rpt)
254{ 252{
255 u8 opmode, macid; 253 u8 opmode, macid;
256 u16 mst_rpt = le16_to_cpu(mstatus_rpt); 254 u16 mst_rpt = le16_to_cpu(mstatus_rpt);
257 opmode = (u8) mst_rpt; 255 opmode = (u8)mst_rpt;
258 macid = (u8)(mst_rpt >> 8); 256 macid = (u8)(mst_rpt >> 8);
259 257
260 DBG_88E("### %s: MStatus=%x MACID=%d\n", __func__, opmode, macid); 258 DBG_88E("### %s: MStatus=%x MACID=%d\n", __func__, opmode, macid);
diff --git a/drivers/staging/rtl8188eu/hal/rtl8188e_dm.c b/drivers/staging/rtl8188eu/hal/rtl8188e_dm.c
index dab4c337a863..01566210bbd2 100644
--- a/drivers/staging/rtl8188eu/hal/rtl8188e_dm.c
+++ b/drivers/staging/rtl8188eu/hal/rtl8188e_dm.c
@@ -155,6 +155,8 @@ void rtl8188e_HalDmWatchDog(struct adapter *Adapter)
155 bool fw_ps_awake = true; 155 bool fw_ps_awake = true;
156 u8 hw_init_completed = false; 156 u8 hw_init_completed = false;
157 struct hal_data_8188e *hal_data = GET_HAL_DATA(Adapter); 157 struct hal_data_8188e *hal_data = GET_HAL_DATA(Adapter);
158 struct mlme_priv *pmlmepriv = NULL;
159 u8 bLinked = false;
158 160
159 hw_init_completed = Adapter->hw_init_completed; 161 hw_init_completed = Adapter->hw_init_completed;
160 162
@@ -170,22 +172,20 @@ void rtl8188e_HalDmWatchDog(struct adapter *Adapter)
170 fw_ps_awake = false; 172 fw_ps_awake = false;
171 173
172 /* ODM */ 174 /* ODM */
173 if (hw_init_completed) { 175 pmlmepriv = &Adapter->mlmepriv;
174 struct mlme_priv *pmlmepriv = &Adapter->mlmepriv; 176
175 u8 bLinked = false; 177 if ((check_fwstate(pmlmepriv, WIFI_AP_STATE)) ||
176 178 (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE |
177 if ((check_fwstate(pmlmepriv, WIFI_AP_STATE)) || 179 WIFI_ADHOC_MASTER_STATE))) {
178 (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE | WIFI_ADHOC_MASTER_STATE))) { 180 if (Adapter->stapriv.asoc_sta_count > 2)
179 if (Adapter->stapriv.asoc_sta_count > 2) 181 bLinked = true;
180 bLinked = true; 182 } else {/* Station mode */
181 } else {/* Station mode */ 183 if (check_fwstate(pmlmepriv, _FW_LINKED))
182 if (check_fwstate(pmlmepriv, _FW_LINKED)) 184 bLinked = true;
183 bLinked = true;
184 }
185
186 ODM_CmnInfoUpdate(&hal_data->odmpriv, ODM_CMNINFO_LINK, bLinked);
187 ODM_DMWatchdog(&hal_data->odmpriv);
188 } 185 }
186
187 ODM_CmnInfoUpdate(&hal_data->odmpriv, ODM_CMNINFO_LINK, bLinked);
188 ODM_DMWatchdog(&hal_data->odmpriv);
189skip_dm: 189skip_dm:
190 /* Check GPIO to determine current RF on/off and Pbc status. */ 190 /* Check GPIO to determine current RF on/off and Pbc status. */
191 /* Check Hardware Radio ON/OFF or not */ 191 /* Check Hardware Radio ON/OFF or not */
diff --git a/drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c b/drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c
index d6fe5e6aa4f4..7d460eaafa35 100644
--- a/drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c
+++ b/drivers/staging/rtl8188eu/hal/rtl8188e_hal_init.c
@@ -181,7 +181,8 @@ static void rtl8188e_SetHalODMVar(struct adapter *Adapter, enum hal_odm_variable
181 switch (eVariable) { 181 switch (eVariable) {
182 case HAL_ODM_STA_INFO: 182 case HAL_ODM_STA_INFO:
183 { 183 {
184 struct sta_info *psta = (struct sta_info *)pValue1; 184 struct sta_info *psta = pValue1;
185
185 if (bSet) { 186 if (bSet) {
186 DBG_88E("### Set STA_(%d) info\n", psta->mac_id); 187 DBG_88E("### Set STA_(%d) info\n", psta->mac_id);
187 ODM_CmnInfoPtrArrayHook(podmpriv, ODM_CMNINFO_STA_STATUS, psta->mac_id, psta); 188 ODM_CmnInfoPtrArrayHook(podmpriv, ODM_CMNINFO_STA_STATUS, psta->mac_id, psta);
diff --git a/drivers/staging/rtl8188eu/hal/rtl8188e_xmit.c b/drivers/staging/rtl8188eu/hal/rtl8188e_xmit.c
index 7a4f754d86df..a6ba53b488e3 100644
--- a/drivers/staging/rtl8188eu/hal/rtl8188e_xmit.c
+++ b/drivers/staging/rtl8188eu/hal/rtl8188e_xmit.c
@@ -25,7 +25,7 @@
25 25
26void dump_txrpt_ccx_88e(void *buf) 26void dump_txrpt_ccx_88e(void *buf)
27{ 27{
28 struct txrpt_ccx_88e *txrpt_ccx = (struct txrpt_ccx_88e *)buf; 28 struct txrpt_ccx_88e *txrpt_ccx = buf;
29 29
30 DBG_88E("%s:\n" 30 DBG_88E("%s:\n"
31 "tag1:%u, pkt_num:%u, txdma_underflow:%u, int_bt:%u, int_tri:%u, int_ccx:%u\n" 31 "tag1:%u, pkt_num:%u, txdma_underflow:%u, int_bt:%u, int_tri:%u, int_ccx:%u\n"
diff --git a/drivers/staging/rtl8188eu/hal/rtl8188eu_xmit.c b/drivers/staging/rtl8188eu/hal/rtl8188eu_xmit.c
index be9eede6931d..594c1da9db23 100644
--- a/drivers/staging/rtl8188eu/hal/rtl8188eu_xmit.c
+++ b/drivers/staging/rtl8188eu/hal/rtl8188eu_xmit.c
@@ -399,7 +399,7 @@ static s32 rtw_dump_xframe(struct adapter *adapt, struct xmit_frame *pxmitframe)
399 399
400 mem_addr += w_sz; 400 mem_addr += w_sz;
401 401
402 mem_addr = (u8 *) round_up((size_t)mem_addr, 4); 402 mem_addr = (u8 *)round_up((size_t)mem_addr, 4);
403 } 403 }
404 404
405 rtw_free_xmitframe(pxmitpriv, pxmitframe); 405 rtw_free_xmitframe(pxmitpriv, pxmitframe);
diff --git a/drivers/staging/rtl8188eu/hal/usb_halinit.c b/drivers/staging/rtl8188eu/hal/usb_halinit.c
index caf2ca3a47e7..14650e91c78a 100644
--- a/drivers/staging/rtl8188eu/hal/usb_halinit.c
+++ b/drivers/staging/rtl8188eu/hal/usb_halinit.c
@@ -1673,7 +1673,7 @@ static void SetHwReg8188EU(struct adapter *Adapter, u8 variable, u8 *val)
1673 pRegToSet = RegToSet_Normal; /* 0xb972a841; */ 1673 pRegToSet = RegToSet_Normal; /* 0xb972a841; */
1674 FactorToSet = *((u8 *)val); 1674 FactorToSet = *((u8 *)val);
1675 if (FactorToSet <= 3) { 1675 if (FactorToSet <= 3) {
1676 FactorToSet = (1<<(FactorToSet + 2)); 1676 FactorToSet = 1 << (FactorToSet + 2);
1677 if (FactorToSet > 0xf) 1677 if (FactorToSet > 0xf)
1678 FactorToSet = 0xf; 1678 FactorToSet = 0xf;
1679 1679
@@ -2012,7 +2012,7 @@ static u8 SetHalDefVar8188EUsb(struct adapter *Adapter, enum hal_def_variable eV
2012 u8 bRSSIDump = *((u8 *)pValue); 2012 u8 bRSSIDump = *((u8 *)pValue);
2013 struct odm_dm_struct *dm_ocm = &(haldata->odmpriv); 2013 struct odm_dm_struct *dm_ocm = &(haldata->odmpriv);
2014 if (bRSSIDump) 2014 if (bRSSIDump)
2015 dm_ocm->DebugComponents = ODM_COMP_DIG|ODM_COMP_FA_CNT ; 2015 dm_ocm->DebugComponents = ODM_COMP_DIG|ODM_COMP_FA_CNT;
2016 else 2016 else
2017 dm_ocm->DebugComponents = 0; 2017 dm_ocm->DebugComponents = 0;
2018 } 2018 }
diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
index 9191993dd3f5..3b476d80f64d 100644
--- a/drivers/staging/rtl8188eu/include/hal_intf.h
+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
@@ -304,8 +304,6 @@ void rtw_hal_write_rfreg(struct adapter *padapter,
304 enum rf_radio_path eRFPath, u32 RegAddr, 304 enum rf_radio_path eRFPath, u32 RegAddr,
305 u32 BitMask, u32 Data); 305 u32 BitMask, u32 Data);
306 306
307s32 rtw_hal_interrupt_handler(struct adapter *padapter);
308
309void rtw_hal_set_bwmode(struct adapter *padapter, 307void rtw_hal_set_bwmode(struct adapter *padapter,
310 enum ht_channel_width Bandwidth, u8 Offset); 308 enum ht_channel_width Bandwidth, u8 Offset);
311void rtw_hal_set_chan(struct adapter *padapter, u8 channel); 309void rtw_hal_set_chan(struct adapter *padapter, u8 channel);
@@ -317,7 +315,6 @@ void rtw_hal_antdiv_rssi_compared(struct adapter *padapter,
317 struct wlan_bssid_ex *src); 315 struct wlan_bssid_ex *src);
318 316
319void rtw_hal_sreset_init(struct adapter *padapter); 317void rtw_hal_sreset_init(struct adapter *padapter);
320u8 rtw_hal_sreset_get_wifi_status(struct adapter *padapter);
321 318
322void rtw_hal_notch_filter(struct adapter *adapter, bool enable); 319void rtw_hal_notch_filter(struct adapter *adapter, bool enable);
323void rtw_hal_reset_security_engine(struct adapter *adapter); 320void rtw_hal_reset_security_engine(struct adapter *adapter);
diff --git a/drivers/staging/rtl8188eu/include/ieee80211_ext.h b/drivers/staging/rtl8188eu/include/ieee80211_ext.h
index 1052d1817a97..15e53d380ad0 100644
--- a/drivers/staging/rtl8188eu/include/ieee80211_ext.h
+++ b/drivers/staging/rtl8188eu/include/ieee80211_ext.h
@@ -103,24 +103,24 @@ struct wme_parameter_element {
103 103
104#define WPA_PUT_LE16(a, val) \ 104#define WPA_PUT_LE16(a, val) \
105 do { \ 105 do { \
106 (a)[1] = ((u16) (val)) >> 8; \ 106 (a)[1] = ((u16)(val)) >> 8; \
107 (a)[0] = ((u16) (val)) & 0xff; \ 107 (a)[0] = ((u16)(val)) & 0xff; \
108 } while (0) 108 } while (0)
109 109
110#define WPA_PUT_BE32(a, val) \ 110#define WPA_PUT_BE32(a, val) \
111 do { \ 111 do { \
112 (a)[0] = (u8) ((((u32) (val)) >> 24) & 0xff); \ 112 (a)[0] = (u8)((((u32) (val)) >> 24) & 0xff); \
113 (a)[1] = (u8) ((((u32) (val)) >> 16) & 0xff); \ 113 (a)[1] = (u8)((((u32) (val)) >> 16) & 0xff); \
114 (a)[2] = (u8) ((((u32) (val)) >> 8) & 0xff); \ 114 (a)[2] = (u8)((((u32) (val)) >> 8) & 0xff); \
115 (a)[3] = (u8) (((u32) (val)) & 0xff); \ 115 (a)[3] = (u8)(((u32) (val)) & 0xff); \
116 } while (0) 116 } while (0)
117 117
118#define WPA_PUT_LE32(a, val) \ 118#define WPA_PUT_LE32(a, val) \
119 do { \ 119 do { \
120 (a)[3] = (u8) ((((u32) (val)) >> 24) & 0xff); \ 120 (a)[3] = (u8)((((u32) (val)) >> 24) & 0xff); \
121 (a)[2] = (u8) ((((u32) (val)) >> 16) & 0xff); \ 121 (a)[2] = (u8)((((u32) (val)) >> 16) & 0xff); \
122 (a)[1] = (u8) ((((u32) (val)) >> 8) & 0xff); \ 122 (a)[1] = (u8)((((u32) (val)) >> 8) & 0xff); \
123 (a)[0] = (u8) (((u32) (val)) & 0xff); \ 123 (a)[0] = (u8)(((u32) (val)) & 0xff); \
124 } while (0) 124 } while (0)
125 125
126#define RSN_SELECTOR_PUT(a, val) WPA_PUT_BE32((u8 *)(a), (val)) 126#define RSN_SELECTOR_PUT(a, val) WPA_PUT_BE32((u8 *)(a), (val))
diff --git a/drivers/staging/rtl8188eu/include/odm_debug.h b/drivers/staging/rtl8188eu/include/odm_debug.h
index db7b44e16c48..914f831a5b77 100644
--- a/drivers/staging/rtl8188eu/include/odm_debug.h
+++ b/drivers/staging/rtl8188eu/include/odm_debug.h
@@ -83,9 +83,8 @@
83#define ODM_COMP_INIT BIT31 83#define ODM_COMP_INIT BIT31
84 84
85/*------------------------Export Marco Definition---------------------------*/ 85/*------------------------Export Marco Definition---------------------------*/
86#define DbgPrint pr_info
87#define RT_PRINTK(fmt, args...) \ 86#define RT_PRINTK(fmt, args...) \
88 DbgPrint("%s(): " fmt, __func__, ## args); 87 pr_info("%s(): " fmt, __func__, ## args);
89 88
90#ifndef ASSERT 89#ifndef ASSERT
91 #define ASSERT(expr) 90 #define ASSERT(expr)
@@ -94,40 +93,18 @@
94#define ODM_RT_TRACE(pDM_Odm, comp, level, fmt) \ 93#define ODM_RT_TRACE(pDM_Odm, comp, level, fmt) \
95 if (((comp) & pDM_Odm->DebugComponents) && \ 94 if (((comp) & pDM_Odm->DebugComponents) && \
96 (level <= pDM_Odm->DebugLevel)) { \ 95 (level <= pDM_Odm->DebugLevel)) { \
97 DbgPrint("[ODM-8188E] "); \ 96 pr_info("[ODM-8188E] "); \
98 RT_PRINTK fmt; \
99 }
100
101#define ODM_RT_TRACE_F(pDM_Odm, comp, level, fmt) \
102 if (((comp) & pDM_Odm->DebugComponents) && \
103 (level <= pDM_Odm->DebugLevel)) { \
104 RT_PRINTK fmt; \ 97 RT_PRINTK fmt; \
105 } 98 }
106 99
107#define ODM_RT_ASSERT(pDM_Odm, expr, fmt) \ 100#define ODM_RT_ASSERT(pDM_Odm, expr, fmt) \
108 if (!(expr)) { \ 101 if (!(expr)) { \
109 DbgPrint("Assertion failed! %s at ......\n", #expr); \ 102 pr_info("Assertion failed! %s at ......\n", #expr); \
110 DbgPrint(" ......%s,%s,line=%d\n", __FILE__, \ 103 pr_info(" ......%s,%s,line=%d\n", __FILE__, \
111 __func__, __LINE__); \ 104 __func__, __LINE__); \
112 RT_PRINTK fmt; \ 105 RT_PRINTK fmt; \
113 ASSERT(false); \ 106 ASSERT(false); \
114 } 107 }
115#define ODM_dbg_enter() { DbgPrint("==> %s\n", __func__); }
116#define ODM_dbg_exit() { DbgPrint("<== %s\n", __func__); }
117#define ODM_dbg_trace(str) { DbgPrint("%s:%s\n", __func__, str); }
118
119#define ODM_PRINT_ADDR(pDM_Odm, comp, level, title_str, ptr) \
120 if (((comp) & pDM_Odm->DebugComponents) && \
121 (level <= pDM_Odm->DebugLevel)) { \
122 int __i; \
123 u8 *__ptr = (u8 *)ptr; \
124 DbgPrint("[ODM] "); \
125 DbgPrint(title_str); \
126 DbgPrint(" "); \
127 for (__i = 0; __i < 6; __i++) \
128 DbgPrint("%02X%s", __ptr[__i], (__i == 5)?"":"-");\
129 DbgPrint("\n"); \
130 }
131 108
132void ODM_InitDebugSetting(struct odm_dm_struct *pDM_Odm); 109void ODM_InitDebugSetting(struct odm_dm_struct *pDM_Odm);
133 110
diff --git a/drivers/staging/rtl8188eu/include/osdep_service.h b/drivers/staging/rtl8188eu/include/osdep_service.h
index fed9c86890b4..82f58f87656a 100644
--- a/drivers/staging/rtl8188eu/include/osdep_service.h
+++ b/drivers/staging/rtl8188eu/include/osdep_service.h
@@ -182,8 +182,8 @@ u64 rtw_modular64(u64 x, u64 y);
182 182
183/* Macros for handling unaligned memory accesses */ 183/* Macros for handling unaligned memory accesses */
184 184
185#define RTW_GET_BE24(a) ((((u32) (a)[0]) << 16) | (((u32) (a)[1]) << 8) | \ 185#define RTW_GET_BE24(a) ((((u32)(a)[0]) << 16) | (((u32) (a)[1]) << 8) | \
186 ((u32) (a)[2])) 186 ((u32)(a)[2]))
187 187
188void rtw_buf_free(u8 **buf, u32 *buf_len); 188void rtw_buf_free(u8 **buf, u32 *buf_len);
189void rtw_buf_update(u8 **buf, u32 *buf_len, u8 *src, u32 src_len); 189void rtw_buf_update(u8 **buf, u32 *buf_len, u8 *src, u32 src_len);
diff --git a/drivers/staging/rtl8188eu/include/rtw_debug.h b/drivers/staging/rtl8188eu/include/rtw_debug.h
index a38616e3cad2..971bf457f32d 100644
--- a/drivers/staging/rtl8188eu/include/rtw_debug.h
+++ b/drivers/staging/rtl8188eu/include/rtw_debug.h
@@ -106,7 +106,7 @@ extern u32 GlobalDebugLevel;
106 u8 *ptr = (u8 *)_hexdata; \ 106 u8 *ptr = (u8 *)_hexdata; \
107 pr_info("%s", DRIVER_PREFIX); \ 107 pr_info("%s", DRIVER_PREFIX); \
108 pr_info(_titlestring); \ 108 pr_info(_titlestring); \
109 for (__i = 0; __i < (int)_hexdatalen; __i++ ) { \ 109 for (__i = 0; __i < (int)_hexdatalen; __i++) { \
110 pr_info("%02X%s", ptr[__i], \ 110 pr_info("%02X%s", ptr[__i], \
111 (((__i + 1) % 4) == 0) ? \ 111 (((__i + 1) % 4) == 0) ? \
112 " " : " "); \ 112 " " : " "); \
diff --git a/drivers/staging/rtl8188eu/include/rtw_led.h b/drivers/staging/rtl8188eu/include/rtw_led.h
index c5194b620da4..23f0cfe312f3 100644
--- a/drivers/staging/rtl8188eu/include/rtw_led.h
+++ b/drivers/staging/rtl8188eu/include/rtw_led.h
@@ -11,10 +11,6 @@
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details. 12 * more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * 14 *
19 ******************************************************************************/ 15 ******************************************************************************/
20#ifndef __RTW_LED_H_ 16#ifndef __RTW_LED_H_
@@ -27,7 +23,7 @@
27#define LED_BLINK_LINK_INTERVAL_ALPHA 500 /* 500 */ 23#define LED_BLINK_LINK_INTERVAL_ALPHA 500 /* 500 */
28#define LED_BLINK_SCAN_INTERVAL_ALPHA 180 /* 150 */ 24#define LED_BLINK_SCAN_INTERVAL_ALPHA 180 /* 150 */
29#define LED_BLINK_FASTER_INTERVAL_ALPHA 50 25#define LED_BLINK_FASTER_INTERVAL_ALPHA 50
30#define LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA 5000 26#define LED_BLINK_WPS_SUCCESS_INTERVAL_ALPHA 5000
31 27
32enum LED_CTL_MODE { 28enum LED_CTL_MODE {
33 LED_CTL_POWER_ON, 29 LED_CTL_POWER_ON,
@@ -92,7 +88,7 @@ struct LED_871x {
92 88
93void LedControl8188eu(struct adapter *padapter, enum LED_CTL_MODE LedAction); 89void LedControl8188eu(struct adapter *padapter, enum LED_CTL_MODE LedAction);
94 90
95struct led_priv{ 91struct led_priv {
96 /* add for led control */ 92 /* add for led control */
97 struct LED_871x SwLed0; 93 struct LED_871x SwLed0;
98 u8 bRegUseLed; 94 u8 bRegUseLed;
diff --git a/drivers/staging/rtl8188eu/include/rtw_mlme_ext.h b/drivers/staging/rtl8188eu/include/rtw_mlme_ext.h
index d699ca19ef16..8d72ccf5f2a0 100644
--- a/drivers/staging/rtl8188eu/include/rtw_mlme_ext.h
+++ b/drivers/staging/rtl8188eu/include/rtw_mlme_ext.h
@@ -448,7 +448,7 @@ struct mlme_ext_priv {
448 448
449int init_mlme_ext_priv(struct adapter *adapter); 449int init_mlme_ext_priv(struct adapter *adapter);
450int init_hw_mlme_ext(struct adapter *padapter); 450int init_hw_mlme_ext(struct adapter *padapter);
451void free_mlme_ext_priv (struct mlme_ext_priv *pmlmeext); 451void free_mlme_ext_priv(struct mlme_ext_priv *pmlmeext);
452extern void init_mlme_ext_timer(struct adapter *padapter); 452extern void init_mlme_ext_timer(struct adapter *padapter);
453extern void init_addba_retry_timer(struct adapter *adapt, struct sta_info *sta); 453extern void init_addba_retry_timer(struct adapter *adapt, struct sta_info *sta);
454extern struct xmit_frame *alloc_mgtxmitframe(struct xmit_priv *pxmitpriv); 454extern struct xmit_frame *alloc_mgtxmitframe(struct xmit_priv *pxmitpriv);
@@ -646,8 +646,8 @@ void mlmeext_sta_add_event_callback(struct adapter *padapter,
646 646
647void linked_status_chk(struct adapter *padapter); 647void linked_status_chk(struct adapter *padapter);
648 648
649void survey_timer_hdl (void *function_context); 649void survey_timer_hdl(void *function_context);
650void link_timer_hdl (void *funtion_context); 650void link_timer_hdl(void *funtion_context);
651void addba_timer_hdl(void *function_context); 651void addba_timer_hdl(void *function_context);
652 652
653#define set_survey_timer(mlmeext, ms) \ 653#define set_survey_timer(mlmeext, ms) \
@@ -708,15 +708,15 @@ u8 tdls_hdl(struct adapter *padapter, unsigned char *pbuf);
708#ifdef _RTW_CMD_C_ 708#ifdef _RTW_CMD_C_
709 709
710static struct cmd_hdl wlancmds[] = { 710static struct cmd_hdl wlancmds[] = {
711 GEN_MLME_EXT_HANDLER(sizeof (struct wlan_bssid_ex), join_cmd_hdl) 711 GEN_MLME_EXT_HANDLER(sizeof(struct wlan_bssid_ex), join_cmd_hdl)
712 GEN_MLME_EXT_HANDLER(sizeof (struct disconnect_parm), disconnect_hdl) 712 GEN_MLME_EXT_HANDLER(sizeof(struct disconnect_parm), disconnect_hdl)
713 GEN_MLME_EXT_HANDLER(sizeof (struct wlan_bssid_ex), createbss_hdl) 713 GEN_MLME_EXT_HANDLER(sizeof(struct wlan_bssid_ex), createbss_hdl)
714 GEN_MLME_EXT_HANDLER(sizeof (struct setopmode_parm), setopmode_hdl) 714 GEN_MLME_EXT_HANDLER(sizeof(struct setopmode_parm), setopmode_hdl)
715 GEN_MLME_EXT_HANDLER(sizeof (struct sitesurvey_parm), sitesurvey_cmd_hdl) 715 GEN_MLME_EXT_HANDLER(sizeof(struct sitesurvey_parm), sitesurvey_cmd_hdl)
716 GEN_MLME_EXT_HANDLER(sizeof (struct setauth_parm), setauth_hdl) 716 GEN_MLME_EXT_HANDLER(sizeof(struct setauth_parm), setauth_hdl)
717 GEN_MLME_EXT_HANDLER(sizeof (struct setkey_parm), setkey_hdl) 717 GEN_MLME_EXT_HANDLER(sizeof(struct setkey_parm), setkey_hdl)
718 GEN_MLME_EXT_HANDLER(sizeof (struct set_stakey_parm), set_stakey_hdl) 718 GEN_MLME_EXT_HANDLER(sizeof(struct set_stakey_parm), set_stakey_hdl)
719 GEN_MLME_EXT_HANDLER(sizeof (struct set_assocsta_parm), NULL) 719 GEN_MLME_EXT_HANDLER(sizeof(struct set_assocsta_parm), NULL)
720 GEN_MLME_EXT_HANDLER(sizeof(struct addBaReq_parm), add_ba_hdl) 720 GEN_MLME_EXT_HANDLER(sizeof(struct addBaReq_parm), add_ba_hdl)
721 GEN_MLME_EXT_HANDLER(sizeof(struct set_ch_parm), set_ch_hdl) 721 GEN_MLME_EXT_HANDLER(sizeof(struct set_ch_parm), set_ch_hdl)
722 GEN_MLME_EXT_HANDLER(sizeof(struct wlan_bssid_ex), tx_beacon_hdl) 722 GEN_MLME_EXT_HANDLER(sizeof(struct wlan_bssid_ex), tx_beacon_hdl)
@@ -787,7 +787,7 @@ static struct fwevent wlanevents[] = {
787 {0, NULL}, 787 {0, NULL},
788 {0, NULL}, 788 {0, NULL},
789 {0, &rtw_survey_event_callback}, /*8*/ 789 {0, &rtw_survey_event_callback}, /*8*/
790 {sizeof (struct surveydone_event), &rtw_surveydone_event_callback},/*9*/ 790 {sizeof(struct surveydone_event), &rtw_surveydone_event_callback},/*9*/
791 {0, &rtw_joinbss_event_callback}, /*10*/ 791 {0, &rtw_joinbss_event_callback}, /*10*/
792 {sizeof(struct stassoc_event), &rtw_stassoc_event_callback}, 792 {sizeof(struct stassoc_event), &rtw_stassoc_event_callback},
793 {sizeof(struct stadel_event), &rtw_stadel_event_callback}, 793 {sizeof(struct stadel_event), &rtw_stadel_event_callback},
diff --git a/drivers/staging/rtl8188eu/include/wifi.h b/drivers/staging/rtl8188eu/include/wifi.h
index a88ebf41bba1..8dbdfafd52b5 100644
--- a/drivers/staging/rtl8188eu/include/wifi.h
+++ b/drivers/staging/rtl8188eu/include/wifi.h
@@ -766,27 +766,27 @@ enum ht_cap_ampdu_factor {
766#define OP_MODE_20MHZ_HT_STA_ASSOCED 2 766#define OP_MODE_20MHZ_HT_STA_ASSOCED 2
767#define OP_MODE_MIXED 3 767#define OP_MODE_MIXED 3
768 768
769#define HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK ((u8) BIT(0) | BIT(1)) 769#define HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK ((u8)BIT(0) | BIT(1))
770#define HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE ((u8) BIT(0)) 770#define HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE ((u8)BIT(0))
771#define HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW ((u8) BIT(0) | BIT(1)) 771#define HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW ((u8)BIT(0) | BIT(1))
772#define HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH ((u8) BIT(2)) 772#define HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH ((u8)BIT(2))
773#define HT_INFO_HT_PARAM_RIFS_MODE ((u8) BIT(3)) 773#define HT_INFO_HT_PARAM_RIFS_MODE ((u8)BIT(3))
774#define HT_INFO_HT_PARAM_CTRL_ACCESS_ONLY ((u8) BIT(4)) 774#define HT_INFO_HT_PARAM_CTRL_ACCESS_ONLY ((u8)BIT(4))
775#define HT_INFO_HT_PARAM_SRV_INTERVAL_GRANULARITY ((u8) BIT(5)) 775#define HT_INFO_HT_PARAM_SRV_INTERVAL_GRANULARITY ((u8)BIT(5))
776 776
777#define HT_INFO_OPERATION_MODE_OP_MODE_MASK \ 777#define HT_INFO_OPERATION_MODE_OP_MODE_MASK \
778 ((u16) (0x0001 | 0x0002)) 778 ((u16)(0x0001 | 0x0002))
779#define HT_INFO_OPERATION_MODE_OP_MODE_OFFSET 0 779#define HT_INFO_OPERATION_MODE_OP_MODE_OFFSET 0
780#define HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT ((u8) BIT(2)) 780#define HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT ((u8)BIT(2))
781#define HT_INFO_OPERATION_MODE_TRANSMIT_BURST_LIMIT ((u8) BIT(3)) 781#define HT_INFO_OPERATION_MODE_TRANSMIT_BURST_LIMIT ((u8)BIT(3))
782#define HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT ((u8) BIT(4)) 782#define HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT ((u8)BIT(4))
783 783
784#define HT_INFO_STBC_PARAM_DUAL_BEACON ((u16) BIT(6)) 784#define HT_INFO_STBC_PARAM_DUAL_BEACON ((u16)BIT(6))
785#define HT_INFO_STBC_PARAM_DUAL_STBC_PROTECT ((u16) BIT(7)) 785#define HT_INFO_STBC_PARAM_DUAL_STBC_PROTECT ((u16)BIT(7))
786#define HT_INFO_STBC_PARAM_SECONDARY_BC ((u16) BIT(8)) 786#define HT_INFO_STBC_PARAM_SECONDARY_BC ((u16)BIT(8))
787#define HT_INFO_STBC_PARAM_LSIG_TXOP_PROTECT_ALLOWED ((u16) BIT(9)) 787#define HT_INFO_STBC_PARAM_LSIG_TXOP_PROTECT_ALLOWED ((u16)BIT(9))
788#define HT_INFO_STBC_PARAM_PCO_ACTIVE ((u16) BIT(10)) 788#define HT_INFO_STBC_PARAM_PCO_ACTIVE ((u16)BIT(10))
789#define HT_INFO_STBC_PARAM_PCO_PHASE ((u16) BIT(11)) 789#define HT_INFO_STBC_PARAM_PCO_PHASE ((u16)BIT(11))
790 790
791/* ===============WPS Section=============== */ 791/* ===============WPS Section=============== */
792/* For WPSv1.0 */ 792/* For WPSv1.0 */
diff --git a/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c b/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c
index d598fec4abbf..24a8f5ac96e5 100644
--- a/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/ioctl_linux.c
@@ -361,7 +361,7 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
361 param->u.crypt.err = 0; 361 param->u.crypt.err = 0;
362 param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0'; 362 param->u.crypt.alg[IEEE_CRYPT_ALG_NAME_LEN - 1] = '\0';
363 363
364 if (param_len < (u32) ((u8 *)param->u.crypt.key - (u8 *)param) + param->u.crypt.key_len) { 364 if (param_len < (u32)((u8 *)param->u.crypt.key - (u8 *)param) + param->u.crypt.key_len) {
365 ret = -EINVAL; 365 ret = -EINVAL;
366 goto exit; 366 goto exit;
367 } 367 }
@@ -512,14 +512,12 @@ static int rtw_set_wpa_ie(struct adapter *padapter, char *pie, unsigned short ie
512 } 512 }
513 513
514 if (ielen) { 514 if (ielen) {
515 buf = kzalloc(ielen, GFP_KERNEL); 515 buf = kmemdup(pie, ielen, GFP_KERNEL);
516 if (buf == NULL) { 516 if (buf == NULL) {
517 ret = -ENOMEM; 517 ret = -ENOMEM;
518 goto exit; 518 goto exit;
519 } 519 }
520 520
521 memcpy(buf, pie, ielen);
522
523 /* dump */ 521 /* dump */
524 { 522 {
525 int i; 523 int i;
@@ -1136,7 +1134,8 @@ static int rtw_wx_set_scan(struct net_device *dev, struct iw_request_info *a,
1136 struct iw_scan_req *req = (struct iw_scan_req *)extra; 1134 struct iw_scan_req *req = (struct iw_scan_req *)extra;
1137 1135
1138 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { 1136 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1139 int len = min((int)req->essid_len, IW_ESSID_MAX_SIZE); 1137 int len = min_t(int, req->essid_len,
1138 IW_ESSID_MAX_SIZE);
1140 1139
1141 memcpy(ssid[0].Ssid, req->essid, len); 1140 memcpy(ssid[0].Ssid, req->essid, len);
1142 ssid[0].SsidLength = len; 1141 ssid[0].SsidLength = len;
@@ -1417,7 +1416,7 @@ static int rtw_wx_set_rate(struct net_device *dev,
1417 struct iw_request_info *a, 1416 struct iw_request_info *a,
1418 union iwreq_data *wrqu, char *extra) 1417 union iwreq_data *wrqu, char *extra)
1419{ 1418{
1420 int i, ret = 0; 1419 int i;
1421 u8 datarates[NumRates]; 1420 u8 datarates[NumRates];
1422 u32 target_rate = wrqu->bitrate.value; 1421 u32 target_rate = wrqu->bitrate.value;
1423 u32 fixed = wrqu->bitrate.fixed; 1422 u32 fixed = wrqu->bitrate.fixed;
@@ -1490,7 +1489,7 @@ set_rate:
1490 RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_, ("datarate_inx =%d\n", datarates[i])); 1489 RT_TRACE(_module_rtl871x_ioctl_os_c, _drv_info_, ("datarate_inx =%d\n", datarates[i]));
1491 } 1490 }
1492 1491
1493 return ret; 1492 return 0;
1494} 1493}
1495 1494
1496static int rtw_wx_get_rate(struct net_device *dev, 1495static int rtw_wx_get_rate(struct net_device *dev,
@@ -2699,10 +2698,8 @@ static int rtw_set_wps_beacon(struct net_device *dev, struct ieee_param *param,
2699 2698
2700 ie_len = len-12-2;/* 12 = param header, 2:no packed */ 2699 ie_len = len-12-2;/* 12 = param header, 2:no packed */
2701 2700
2702 if (pmlmepriv->wps_beacon_ie) { 2701 kfree(pmlmepriv->wps_beacon_ie);
2703 kfree(pmlmepriv->wps_beacon_ie); 2702 pmlmepriv->wps_beacon_ie = NULL;
2704 pmlmepriv->wps_beacon_ie = NULL;
2705 }
2706 2703
2707 if (ie_len > 0) { 2704 if (ie_len > 0) {
2708 pmlmepriv->wps_beacon_ie = rtw_malloc(ie_len); 2705 pmlmepriv->wps_beacon_ie = rtw_malloc(ie_len);
@@ -2736,10 +2733,8 @@ static int rtw_set_wps_probe_resp(struct net_device *dev, struct ieee_param *par
2736 2733
2737 ie_len = len-12-2;/* 12 = param header, 2:no packed */ 2734 ie_len = len-12-2;/* 12 = param header, 2:no packed */
2738 2735
2739 if (pmlmepriv->wps_probe_resp_ie) { 2736 kfree(pmlmepriv->wps_probe_resp_ie);
2740 kfree(pmlmepriv->wps_probe_resp_ie); 2737 pmlmepriv->wps_probe_resp_ie = NULL;
2741 pmlmepriv->wps_probe_resp_ie = NULL;
2742 }
2743 2738
2744 if (ie_len > 0) { 2739 if (ie_len > 0) {
2745 pmlmepriv->wps_probe_resp_ie = rtw_malloc(ie_len); 2740 pmlmepriv->wps_probe_resp_ie = rtw_malloc(ie_len);
@@ -2768,10 +2763,8 @@ static int rtw_set_wps_assoc_resp(struct net_device *dev, struct ieee_param *par
2768 2763
2769 ie_len = len-12-2;/* 12 = param header, 2:no packed */ 2764 ie_len = len-12-2;/* 12 = param header, 2:no packed */
2770 2765
2771 if (pmlmepriv->wps_assoc_resp_ie) { 2766 kfree(pmlmepriv->wps_assoc_resp_ie);
2772 kfree(pmlmepriv->wps_assoc_resp_ie); 2767 pmlmepriv->wps_assoc_resp_ie = NULL;
2773 pmlmepriv->wps_assoc_resp_ie = NULL;
2774 }
2775 2768
2776 if (ie_len > 0) { 2769 if (ie_len > 0) {
2777 pmlmepriv->wps_assoc_resp_ie = rtw_malloc(ie_len); 2770 pmlmepriv->wps_assoc_resp_ie = rtw_malloc(ie_len);
diff --git a/drivers/staging/rtl8188eu/os_dep/os_intfs.c b/drivers/staging/rtl8188eu/os_dep/os_intfs.c
index 08a80f759b8d..88a909c9e457 100644
--- a/drivers/staging/rtl8188eu/os_dep/os_intfs.c
+++ b/drivers/staging/rtl8188eu/os_dep/os_intfs.c
@@ -512,7 +512,6 @@ void rtw_proc_remove_one(struct net_device *dev)
512 512
513static uint loadparam(struct adapter *padapter, struct net_device *pnetdev) 513static uint loadparam(struct adapter *padapter, struct net_device *pnetdev)
514{ 514{
515 uint status = _SUCCESS;
516 struct registry_priv *registry_par = &padapter->registrypriv; 515 struct registry_priv *registry_par = &padapter->registrypriv;
517 516
518 517
@@ -527,7 +526,7 @@ static uint loadparam(struct adapter *padapter, struct net_device *pnetdev)
527 526
528 registry_par->channel = (u8)rtw_channel; 527 registry_par->channel = (u8)rtw_channel;
529 registry_par->wireless_mode = (u8)rtw_wireless_mode; 528 registry_par->wireless_mode = (u8)rtw_wireless_mode;
530 registry_par->vrtl_carrier_sense = (u8)rtw_vrtl_carrier_sense ; 529 registry_par->vrtl_carrier_sense = (u8)rtw_vrtl_carrier_sense;
531 registry_par->vcs_type = (u8)rtw_vcs_type; 530 registry_par->vcs_type = (u8)rtw_vcs_type;
532 registry_par->rts_thresh = (u16)rtw_rts_thresh; 531 registry_par->rts_thresh = (u16)rtw_rts_thresh;
533 registry_par->frag_thresh = (u16)rtw_frag_thresh; 532 registry_par->frag_thresh = (u16)rtw_frag_thresh;
@@ -582,7 +581,7 @@ static uint loadparam(struct adapter *padapter, struct net_device *pnetdev)
582 snprintf(registry_par->ifname, 16, "%s", ifname); 581 snprintf(registry_par->ifname, 16, "%s", ifname);
583 snprintf(registry_par->if2name, 16, "%s", if2name); 582 snprintf(registry_par->if2name, 16, "%s", if2name);
584 registry_par->notch_filter = (u8)rtw_notch_filter; 583 registry_par->notch_filter = (u8)rtw_notch_filter;
585 return status; 584 return _SUCCESS;
586} 585}
587 586
588static int rtw_net_set_mac_address(struct net_device *pnetdev, void *p) 587static int rtw_net_set_mac_address(struct net_device *pnetdev, void *p)
@@ -760,7 +759,6 @@ void rtw_stop_drv_threads(struct adapter *padapter)
760 759
761static u8 rtw_init_default_value(struct adapter *padapter) 760static u8 rtw_init_default_value(struct adapter *padapter)
762{ 761{
763 u8 ret = _SUCCESS;
764 struct registry_priv *pregistrypriv = &padapter->registrypriv; 762 struct registry_priv *pregistrypriv = &padapter->registrypriv;
765 struct xmit_priv *pxmitpriv = &padapter->xmitpriv; 763 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
766 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 764 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
@@ -803,12 +801,11 @@ static u8 rtw_init_default_value(struct adapter *padapter)
803 padapter->bWritePortCancel = false; 801 padapter->bWritePortCancel = false;
804 padapter->bRxRSSIDisplay = 0; 802 padapter->bRxRSSIDisplay = 0;
805 padapter->bNotifyChannelChange = 0; 803 padapter->bNotifyChannelChange = 0;
806 return ret; 804 return _SUCCESS;
807} 805}
808 806
809u8 rtw_reset_drv_sw(struct adapter *padapter) 807u8 rtw_reset_drv_sw(struct adapter *padapter)
810{ 808{
811 u8 ret8 = _SUCCESS;
812 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 809 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
813 struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv; 810 struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
814 811
@@ -833,7 +830,7 @@ u8 rtw_reset_drv_sw(struct adapter *padapter)
833 830
834 rtw_set_signal_stat_timer(&padapter->recvpriv); 831 rtw_set_signal_stat_timer(&padapter->recvpriv);
835 832
836 return ret8; 833 return _SUCCESS;
837} 834}
838 835
839u8 rtw_init_drv_sw(struct adapter *padapter) 836u8 rtw_init_drv_sw(struct adapter *padapter)
diff --git a/drivers/staging/rtl8188eu/os_dep/osdep_service.c b/drivers/staging/rtl8188eu/os_dep/osdep_service.c
index 8af4a8d24cce..abcb3a8589ef 100644
--- a/drivers/staging/rtl8188eu/os_dep/osdep_service.c
+++ b/drivers/staging/rtl8188eu/os_dep/osdep_service.c
@@ -51,7 +51,7 @@ void *rtw_malloc2d(int h, int w, int size)
51{ 51{
52 int j; 52 int j;
53 53
54 void **a = (void **)kzalloc(h*sizeof(void *) + h*w*size, GFP_KERNEL); 54 void **a = kzalloc(h*sizeof(void *) + h*w*size, GFP_KERNEL);
55 if (a == NULL) { 55 if (a == NULL) {
56 pr_info("%s: alloc memory fail!\n", __func__); 56 pr_info("%s: alloc memory fail!\n", __func__);
57 return NULL; 57 return NULL;
diff --git a/drivers/staging/rtl8188eu/os_dep/rtw_android.c b/drivers/staging/rtl8188eu/os_dep/rtw_android.c
index d9d55d12fd5f..99ce077007f4 100644
--- a/drivers/staging/rtl8188eu/os_dep/rtw_android.c
+++ b/drivers/staging/rtl8188eu/os_dep/rtw_android.c
@@ -148,36 +148,21 @@ static int rtw_android_set_block(struct net_device *net, char *command,
148int rtw_android_priv_cmd(struct net_device *net, struct ifreq *ifr, int cmd) 148int rtw_android_priv_cmd(struct net_device *net, struct ifreq *ifr, int cmd)
149{ 149{
150 int ret = 0; 150 int ret = 0;
151 char *command = NULL; 151 char *command;
152 int cmd_num; 152 int cmd_num;
153 int bytes_written = 0; 153 int bytes_written = 0;
154 struct android_wifi_priv_cmd priv_cmd; 154 struct android_wifi_priv_cmd priv_cmd;
155 155
156 if (!ifr->ifr_data) { 156 if (!ifr->ifr_data)
157 ret = -EINVAL; 157 return -EINVAL;
158 goto exit; 158 if (copy_from_user(&priv_cmd, ifr->ifr_data, sizeof(priv_cmd)))
159 } 159 return -EFAULT;
160 if (copy_from_user(&priv_cmd, ifr->ifr_data, 160 if (priv_cmd.total_len < 1)
161 sizeof(struct android_wifi_priv_cmd))) { 161 return -EINVAL;
162 ret = -EFAULT; 162 command = memdup_user(priv_cmd.buf, priv_cmd.total_len);
163 goto exit; 163 if (IS_ERR(command))
164 } 164 return PTR_ERR(command);
165 command = kmalloc(priv_cmd.total_len, GFP_KERNEL); 165 command[priv_cmd.total_len - 1] = 0;
166 if (!command) {
167 DBG_88E("%s: failed to allocate memory\n", __func__);
168 ret = -ENOMEM;
169 goto exit;
170 }
171 if (!access_ok(VERIFY_READ, priv_cmd.buf, priv_cmd.total_len)) {
172 DBG_88E("%s: failed to access memory\n", __func__);
173 ret = -EFAULT;
174 goto exit;
175 }
176 if (copy_from_user(command, (char __user *)priv_cmd.buf,
177 priv_cmd.total_len)) {
178 ret = -EFAULT;
179 goto exit;
180 }
181 DBG_88E("%s: Android private cmd \"%s\" on %s\n", 166 DBG_88E("%s: Android private cmd \"%s\" on %s\n",
182 __func__, command, ifr->ifr_name); 167 __func__, command, ifr->ifr_name);
183 cmd_num = rtw_android_cmdstr_to_num(command); 168 cmd_num = rtw_android_cmdstr_to_num(command);
@@ -191,7 +176,7 @@ int rtw_android_priv_cmd(struct net_device *net, struct ifreq *ifr, int cmd)
191 DBG_88E("%s: Ignore private cmd \"%s\" - iface %s is down\n", 176 DBG_88E("%s: Ignore private cmd \"%s\" - iface %s is down\n",
192 __func__, command, ifr->ifr_name); 177 __func__, command, ifr->ifr_name);
193 ret = 0; 178 ret = 0;
194 goto exit; 179 goto free;
195 } 180 }
196 switch (cmd_num) { 181 switch (cmd_num) {
197 case ANDROID_WIFI_CMD_STOP: 182 case ANDROID_WIFI_CMD_STOP:
@@ -279,7 +264,7 @@ response:
279 } else { 264 } else {
280 ret = bytes_written; 265 ret = bytes_written;
281 } 266 }
282exit: 267free:
283 kfree(command); 268 kfree(command);
284 return ret; 269 return ret;
285} 270}
diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
index 2f87150a21b7..bee39c2278f1 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
@@ -63,7 +63,6 @@ static struct dvobj_priv *usb_dvobj_init(struct usb_interface *usb_intf)
63 struct usb_config_descriptor *pconf_desc; 63 struct usb_config_descriptor *pconf_desc;
64 struct usb_host_interface *phost_iface; 64 struct usb_host_interface *phost_iface;
65 struct usb_interface_descriptor *piface_desc; 65 struct usb_interface_descriptor *piface_desc;
66 struct usb_host_endpoint *phost_endp;
67 struct usb_endpoint_descriptor *pendp_desc; 66 struct usb_endpoint_descriptor *pendp_desc;
68 struct usb_device *pusbd; 67 struct usb_device *pusbd;
69 68
@@ -92,24 +91,22 @@ static struct dvobj_priv *usb_dvobj_init(struct usb_interface *usb_intf)
92 91
93 for (i = 0; i < pdvobjpriv->nr_endpoint; i++) { 92 for (i = 0; i < pdvobjpriv->nr_endpoint; i++) {
94 int ep_num; 93 int ep_num;
95 phost_endp = phost_iface->endpoint + i; 94 pendp_desc = &phost_iface->endpoint[i].desc;
96 95
97 if (phost_endp) { 96 ep_num = usb_endpoint_num(pendp_desc);
98 pendp_desc = &phost_endp->desc; 97
99 ep_num = usb_endpoint_num(pendp_desc); 98 if (usb_endpoint_is_bulk_in(pendp_desc)) {
100 99 pdvobjpriv->RtInPipe[pdvobjpriv->RtNumInPipes] = ep_num;
101 if (usb_endpoint_is_bulk_in(pendp_desc)) { 100 pdvobjpriv->RtNumInPipes++;
102 pdvobjpriv->RtInPipe[pdvobjpriv->RtNumInPipes] = ep_num; 101 } else if (usb_endpoint_is_int_in(pendp_desc)) {
103 pdvobjpriv->RtNumInPipes++; 102 pdvobjpriv->RtInPipe[pdvobjpriv->RtNumInPipes] = ep_num;
104 } else if (usb_endpoint_is_int_in(pendp_desc)) { 103 pdvobjpriv->RtNumInPipes++;
105 pdvobjpriv->RtInPipe[pdvobjpriv->RtNumInPipes] = ep_num; 104 } else if (usb_endpoint_is_bulk_out(pendp_desc)) {
106 pdvobjpriv->RtNumInPipes++; 105 pdvobjpriv->RtOutPipe[pdvobjpriv->RtNumOutPipes] =
107 } else if (usb_endpoint_is_bulk_out(pendp_desc)) { 106 ep_num;
108 pdvobjpriv->RtOutPipe[pdvobjpriv->RtNumOutPipes] = ep_num; 107 pdvobjpriv->RtNumOutPipes++;
109 pdvobjpriv->RtNumOutPipes++;
110 }
111 pdvobjpriv->ep_num[i] = ep_num;
112 } 108 }
109 pdvobjpriv->ep_num[i] = ep_num;
113 } 110 }
114 111
115 if (pusbd->speed == USB_SPEED_HIGH) 112 if (pusbd->speed == USB_SPEED_HIGH)
@@ -557,8 +554,6 @@ static void rtw_dev_remove(struct usb_interface *pusb_intf)
557 554
558 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("-dev_remove()\n")); 555 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("-dev_remove()\n"));
559 DBG_88E("-r871xu_dev_remove, done\n"); 556 DBG_88E("-r871xu_dev_remove, done\n");
560
561 return;
562} 557}
563 558
564static struct usb_driver rtl8188e_usb_drv = { 559static struct usb_driver rtl8188e_usb_drv = {
diff --git a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
index ba1e178fb510..d2efa9dfc8c0 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_ops_linux.c
@@ -160,10 +160,10 @@ static int recvbuf2recvframe(struct adapter *adapt, struct sk_buff *pskb)
160 switch (haldata->UsbRxAggMode) { 160 switch (haldata->UsbRxAggMode) {
161 case USB_RX_AGG_DMA: 161 case USB_RX_AGG_DMA:
162 case USB_RX_AGG_MIX: 162 case USB_RX_AGG_MIX:
163 pkt_offset = (u16) round_up(pkt_offset, 128); 163 pkt_offset = (u16)round_up(pkt_offset, 128);
164 break; 164 break;
165 case USB_RX_AGG_USB: 165 case USB_RX_AGG_USB:
166 pkt_offset = (u16) round_up(pkt_offset, 4); 166 pkt_offset = (u16)round_up(pkt_offset, 4);
167 break; 167 break;
168 case USB_RX_AGG_DISABLE: 168 case USB_RX_AGG_DISABLE:
169 default: 169 default:
@@ -843,7 +843,7 @@ void usb_write_port_cancel(struct adapter *padapter)
843void rtl8188eu_recv_tasklet(void *priv) 843void rtl8188eu_recv_tasklet(void *priv)
844{ 844{
845 struct sk_buff *pskb; 845 struct sk_buff *pskb;
846 struct adapter *adapt = (struct adapter *)priv; 846 struct adapter *adapt = priv;
847 struct recv_priv *precvpriv = &adapt->recvpriv; 847 struct recv_priv *precvpriv = &adapt->recvpriv;
848 848
849 while (NULL != (pskb = skb_dequeue(&precvpriv->rx_skb_queue))) { 849 while (NULL != (pskb = skb_dequeue(&precvpriv->rx_skb_queue))) {
@@ -862,7 +862,7 @@ void rtl8188eu_recv_tasklet(void *priv)
862void rtl8188eu_xmit_tasklet(void *priv) 862void rtl8188eu_xmit_tasklet(void *priv)
863{ 863{
864 int ret = false; 864 int ret = false;
865 struct adapter *adapt = (struct adapter *)priv; 865 struct adapter *adapt = priv;
866 struct xmit_priv *pxmitpriv = &adapt->xmitpriv; 866 struct xmit_priv *pxmitpriv = &adapt->xmitpriv;
867 867
868 if (check_fwstate(&adapt->mlmepriv, _FW_UNDER_SURVEY)) 868 if (check_fwstate(&adapt->mlmepriv, _FW_UNDER_SURVEY))
diff --git a/drivers/staging/rtl8188eu/os_dep/xmit_linux.c b/drivers/staging/rtl8188eu/os_dep/xmit_linux.c
index 0ce47b07ef86..5acf9a9dddeb 100644
--- a/drivers/staging/rtl8188eu/os_dep/xmit_linux.c
+++ b/drivers/staging/rtl8188eu/os_dep/xmit_linux.c
@@ -46,7 +46,7 @@ void _rtw_open_pktfile(struct sk_buff *pktptr, struct pkt_file *pfile)
46 46
47} 47}
48 48
49uint _rtw_pktfile_read (struct pkt_file *pfile, u8 *rmem, uint rlen) 49uint _rtw_pktfile_read(struct pkt_file *pfile, u8 *rmem, uint rlen)
50{ 50{
51 uint len = 0; 51 uint len = 0;
52 52
@@ -66,13 +66,7 @@ uint _rtw_pktfile_read (struct pkt_file *pfile, u8 *rmem, uint rlen)
66 66
67int rtw_endofpktfile(struct pkt_file *pfile) 67int rtw_endofpktfile(struct pkt_file *pfile)
68{ 68{
69 69 return pfile->pkt_len == 0;
70 if (pfile->pkt_len == 0) {
71 return true;
72 }
73
74
75 return false;
76} 70}
77 71
78int rtw_os_xmit_resource_alloc(struct adapter *padapter, struct xmit_buf *pxmitbuf, u32 alloc_sz) 72int rtw_os_xmit_resource_alloc(struct adapter *padapter, struct xmit_buf *pxmitbuf, u32 alloc_sz)
diff --git a/drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c b/drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c
index 0ffed2d06b58..552d943b1761 100644
--- a/drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c
+++ b/drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c
@@ -1287,7 +1287,7 @@ void rtl8192_tx_fill_desc(struct net_device *dev, struct tx_desc *pdesc,
1287 1287
1288void rtl8192_tx_fill_cmd_desc(struct net_device *dev, 1288void rtl8192_tx_fill_cmd_desc(struct net_device *dev,
1289 struct tx_desc_cmd *entry, 1289 struct tx_desc_cmd *entry,
1290 struct cb_desc *cb_desc, struct sk_buff* skb) 1290 struct cb_desc *cb_desc, struct sk_buff *skb)
1291{ 1291{
1292 struct r8192_priv *priv = rtllib_priv(dev); 1292 struct r8192_priv *priv = rtllib_priv(dev);
1293 dma_addr_t mapping = pci_map_single(priv->pdev, skb->data, skb->len, 1293 dma_addr_t mapping = pci_map_single(priv->pdev, skb->data, skb->len,
@@ -1302,7 +1302,7 @@ void rtl8192_tx_fill_cmd_desc(struct net_device *dev,
1302 if (cb_desc->bCmdOrInit == DESC_PACKET_TYPE_INIT) { 1302 if (cb_desc->bCmdOrInit == DESC_PACKET_TYPE_INIT) {
1303 entry->CmdInit = DESC_PACKET_TYPE_INIT; 1303 entry->CmdInit = DESC_PACKET_TYPE_INIT;
1304 } else { 1304 } else {
1305 struct tx_desc * entry_tmp = (struct tx_desc *)entry; 1305 struct tx_desc *entry_tmp = (struct tx_desc *)entry;
1306 1306
1307 entry_tmp->CmdInit = DESC_PACKET_TYPE_NORMAL; 1307 entry_tmp->CmdInit = DESC_PACKET_TYPE_NORMAL;
1308 entry_tmp->Offset = sizeof(struct tx_fwinfo_8190pci) + 8; 1308 entry_tmp->Offset = sizeof(struct tx_fwinfo_8190pci) + 8;
diff --git a/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c b/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c
index b6ce8c3b2f8c..885315cac3a4 100644
--- a/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c
+++ b/drivers/staging/rtl8192e/rtl8192e/rtl_dm.c
@@ -1449,13 +1449,11 @@ static void dm_CCKTxPowerAdjust_TSSI(struct net_device *dev, bool bInCH14)
1449 (priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[1]<<8)) ; 1449 (priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[1]<<8)) ;
1450 1450
1451 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal); 1451 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
1452 TempVal = 0;
1453 TempVal = (u32)(priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[2] + 1452 TempVal = (u32)(priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[2] +
1454 (priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[3]<<8) + 1453 (priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[3]<<8) +
1455 (priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[4]<<16)+ 1454 (priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[4]<<16)+
1456 (priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[5]<<24)); 1455 (priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[5]<<24));
1457 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal); 1456 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal);
1458 TempVal = 0;
1459 TempVal = (u32)(priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[6] + 1457 TempVal = (u32)(priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[6] +
1460 (priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[7]<<8)) ; 1458 (priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[7]<<8)) ;
1461 1459
@@ -1465,13 +1463,11 @@ static void dm_CCKTxPowerAdjust_TSSI(struct net_device *dev, bool bInCH14)
1465 (priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[1]<<8)) ; 1463 (priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[1]<<8)) ;
1466 1464
1467 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal); 1465 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
1468 TempVal = 0;
1469 TempVal = (u32)(priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[2] + 1466 TempVal = (u32)(priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[2] +
1470 (priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[3]<<8) + 1467 (priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[3]<<8) +
1471 (priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[4]<<16)+ 1468 (priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[4]<<16)+
1472 (priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[5]<<24)); 1469 (priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[5]<<24));
1473 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal); 1470 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal);
1474 TempVal = 0;
1475 TempVal = (u32)(priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[6] + 1471 TempVal = (u32)(priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[6] +
1476 (priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[7]<<8)) ; 1472 (priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[7]<<8)) ;
1477 1473
@@ -1493,7 +1489,6 @@ static void dm_CCKTxPowerAdjust_ThermalMeter(struct net_device *dev, bool bInCH
1493 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal); 1489 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
1494 RT_TRACE(COMP_POWER_TRACKING, "CCK not chnl 14, reg 0x%x = 0x%x\n", 1490 RT_TRACE(COMP_POWER_TRACKING, "CCK not chnl 14, reg 0x%x = 0x%x\n",
1495 rCCK0_TxFilter1, TempVal); 1491 rCCK0_TxFilter1, TempVal);
1496 TempVal = 0;
1497 TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][2] + 1492 TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][2] +
1498 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][3]<<8) + 1493 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][3]<<8) +
1499 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][4]<<16)+ 1494 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][4]<<16)+
@@ -1501,7 +1496,6 @@ static void dm_CCKTxPowerAdjust_ThermalMeter(struct net_device *dev, bool bInCH
1501 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal); 1496 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal);
1502 RT_TRACE(COMP_POWER_TRACKING, "CCK not chnl 14, reg 0x%x = 0x%x\n", 1497 RT_TRACE(COMP_POWER_TRACKING, "CCK not chnl 14, reg 0x%x = 0x%x\n",
1503 rCCK0_TxFilter2, TempVal); 1498 rCCK0_TxFilter2, TempVal);
1504 TempVal = 0;
1505 TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][6] + 1499 TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][6] +
1506 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][7]<<8) ; 1500 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][7]<<8) ;
1507 1501
@@ -1515,7 +1509,6 @@ static void dm_CCKTxPowerAdjust_ThermalMeter(struct net_device *dev, bool bInCH
1515 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal); 1509 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
1516 RT_TRACE(COMP_POWER_TRACKING, "CCK chnl 14, reg 0x%x = 0x%x\n", 1510 RT_TRACE(COMP_POWER_TRACKING, "CCK chnl 14, reg 0x%x = 0x%x\n",
1517 rCCK0_TxFilter1, TempVal); 1511 rCCK0_TxFilter1, TempVal);
1518 TempVal = 0;
1519 TempVal = CCKSwingTable_Ch14[priv->CCK_index][2] + 1512 TempVal = CCKSwingTable_Ch14[priv->CCK_index][2] +
1520 (CCKSwingTable_Ch14[priv->CCK_index][3]<<8) + 1513 (CCKSwingTable_Ch14[priv->CCK_index][3]<<8) +
1521 (CCKSwingTable_Ch14[priv->CCK_index][4]<<16)+ 1514 (CCKSwingTable_Ch14[priv->CCK_index][4]<<16)+
@@ -1523,7 +1516,6 @@ static void dm_CCKTxPowerAdjust_ThermalMeter(struct net_device *dev, bool bInCH
1523 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal); 1516 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal);
1524 RT_TRACE(COMP_POWER_TRACKING, "CCK chnl 14, reg 0x%x = 0x%x\n", 1517 RT_TRACE(COMP_POWER_TRACKING, "CCK chnl 14, reg 0x%x = 0x%x\n",
1525 rCCK0_TxFilter2, TempVal); 1518 rCCK0_TxFilter2, TempVal);
1526 TempVal = 0;
1527 TempVal = CCKSwingTable_Ch14[priv->CCK_index][6] + 1519 TempVal = CCKSwingTable_Ch14[priv->CCK_index][6] +
1528 (CCKSwingTable_Ch14[priv->CCK_index][7]<<8) ; 1520 (CCKSwingTable_Ch14[priv->CCK_index][7]<<8) ;
1529 1521
diff --git a/drivers/staging/rtl8192e/rtl819x_BAProc.c b/drivers/staging/rtl8192e/rtl819x_BAProc.c
index 6da57847a533..0415e02b4eff 100644
--- a/drivers/staging/rtl8192e/rtl819x_BAProc.c
+++ b/drivers/staging/rtl8192e/rtl819x_BAProc.c
@@ -16,6 +16,8 @@
16 * Contact Information: 16 * Contact Information:
17 * wlanfae <wlanfae@realtek.com> 17 * wlanfae <wlanfae@realtek.com>
18******************************************************************************/ 18******************************************************************************/
19#include <asm/byteorder.h>
20#include <asm/unaligned.h>
19#include "rtllib.h" 21#include "rtllib.h"
20#include "rtl819x_BA.h" 22#include "rtl819x_BA.h"
21 23
@@ -79,7 +81,6 @@ static struct sk_buff *rtllib_ADDBA(struct rtllib_device *ieee, u8 *Dst,
79 struct sk_buff *skb = NULL; 81 struct sk_buff *skb = NULL;
80 struct rtllib_hdr_3addr *BAReq = NULL; 82 struct rtllib_hdr_3addr *BAReq = NULL;
81 u8 *tag = NULL; 83 u8 *tag = NULL;
82 u16 tmp = 0;
83 u16 len = ieee->tx_headroom + 9; 84 u16 len = ieee->tx_headroom + 9;
84 85
85 RTLLIB_DEBUG(RTLLIB_DL_TRACE | RTLLIB_DL_BA, "========>%s(), frame(%d)" 86 RTLLIB_DEBUG(RTLLIB_DL_TRACE | RTLLIB_DL_BA, "========>%s(), frame(%d)"
@@ -115,15 +116,15 @@ static struct sk_buff *rtllib_ADDBA(struct rtllib_device *ieee, u8 *Dst,
115 116
116 if (ACT_ADDBARSP == type) { 117 if (ACT_ADDBARSP == type) {
117 RT_TRACE(COMP_DBG, "====>to send ADDBARSP\n"); 118 RT_TRACE(COMP_DBG, "====>to send ADDBARSP\n");
118 tmp = StatusCode; 119
119 memcpy(tag, (u8 *)&tmp, 2); 120 put_unaligned_le16(StatusCode, tag);
120 tag += 2; 121 tag += 2;
121 } 122 }
122 tmp = pBA->BaParamSet.shortData; 123
123 memcpy(tag, (u8 *)&tmp, 2); 124 put_unaligned_le16(pBA->BaParamSet.shortData, tag);
124 tag += 2; 125 tag += 2;
125 tmp = pBA->BaTimeoutValue; 126
126 memcpy(tag, (u8 *)&tmp, 2); 127 put_unaligned_le16(pBA->BaTimeoutValue, tag);
127 tag += 2; 128 tag += 2;
128 129
129 if (ACT_ADDBAREQ == type) { 130 if (ACT_ADDBAREQ == type) {
@@ -143,7 +144,6 @@ static struct sk_buff *rtllib_DELBA(struct rtllib_device *ieee, u8 *dst,
143 struct sk_buff *skb = NULL; 144 struct sk_buff *skb = NULL;
144 struct rtllib_hdr_3addr *Delba = NULL; 145 struct rtllib_hdr_3addr *Delba = NULL;
145 u8 *tag = NULL; 146 u8 *tag = NULL;
146 u16 tmp = 0;
147 u16 len = 6 + ieee->tx_headroom; 147 u16 len = 6 + ieee->tx_headroom;
148 148
149 if (net_ratelimit()) 149 if (net_ratelimit())
@@ -178,11 +178,11 @@ static struct sk_buff *rtllib_DELBA(struct rtllib_device *ieee, u8 *dst,
178 *tag++ = ACT_CAT_BA; 178 *tag++ = ACT_CAT_BA;
179 *tag++ = ACT_DELBA; 179 *tag++ = ACT_DELBA;
180 180
181 tmp = DelbaParamSet.shortData; 181
182 memcpy(tag, (u8 *)&tmp, 2); 182 put_unaligned_le16(DelbaParamSet.shortData, tag);
183 tag += 2; 183 tag += 2;
184 tmp = ReasonCode; 184
185 memcpy(tag, (u8 *)&tmp, 2); 185 put_unaligned_le16(ReasonCode, tag);
186 tag += 2; 186 tag += 2;
187 187
188 RTLLIB_DEBUG_DATA(RTLLIB_DL_DATA|RTLLIB_DL_BA, skb->data, skb->len); 188 RTLLIB_DEBUG_DATA(RTLLIB_DL_DATA|RTLLIB_DL_BA, skb->data, skb->len);
diff --git a/drivers/staging/rtl8192e/rtllib.h b/drivers/staging/rtl8192e/rtllib.h
index 2d82f8993ea1..cef2dc27103f 100644
--- a/drivers/staging/rtl8192e/rtllib.h
+++ b/drivers/staging/rtl8192e/rtllib.h
@@ -2762,8 +2762,6 @@ extern void rtllib_stop_scan(struct rtllib_device *ieee);
2762extern bool rtllib_act_scanning(struct rtllib_device *ieee, bool sync_scan); 2762extern bool rtllib_act_scanning(struct rtllib_device *ieee, bool sync_scan);
2763extern void rtllib_stop_scan_syncro(struct rtllib_device *ieee); 2763extern void rtllib_stop_scan_syncro(struct rtllib_device *ieee);
2764extern void rtllib_start_scan_syncro(struct rtllib_device *ieee, u8 is_mesh); 2764extern void rtllib_start_scan_syncro(struct rtllib_device *ieee, u8 is_mesh);
2765extern inline struct sk_buff *rtllib_probe_req(struct rtllib_device *ieee);
2766extern u8 MgntQuery_MgntFrameTxRate(struct rtllib_device *ieee);
2767extern void rtllib_sta_ps_send_null_frame(struct rtllib_device *ieee, 2765extern void rtllib_sta_ps_send_null_frame(struct rtllib_device *ieee,
2768 short pwr); 2766 short pwr);
2769extern void rtllib_sta_wakeup(struct rtllib_device *ieee, short nl); 2767extern void rtllib_sta_wakeup(struct rtllib_device *ieee, short nl);
@@ -2944,12 +2942,12 @@ void rtllib_softmac_scan_syncro(struct rtllib_device *ieee, u8 is_mesh);
2944 2942
2945extern const long rtllib_wlan_frequencies[]; 2943extern const long rtllib_wlan_frequencies[];
2946 2944
2947extern inline void rtllib_increment_scans(struct rtllib_device *ieee) 2945static inline void rtllib_increment_scans(struct rtllib_device *ieee)
2948{ 2946{
2949 ieee->scans++; 2947 ieee->scans++;
2950} 2948}
2951 2949
2952extern inline int rtllib_get_scans(struct rtllib_device *ieee) 2950static inline int rtllib_get_scans(struct rtllib_device *ieee)
2953{ 2951{
2954 return ieee->scans; 2952 return ieee->scans;
2955} 2953}
diff --git a/drivers/staging/rtl8192e/rtllib_rx.c b/drivers/staging/rtl8192e/rtllib_rx.c
index 1c2014fd8d81..cf11b042b93a 100644
--- a/drivers/staging/rtl8192e/rtllib_rx.c
+++ b/drivers/staging/rtl8192e/rtllib_rx.c
@@ -1415,10 +1415,6 @@ static int rtllib_rx_InfraAdhoc(struct rtllib_device *ieee, struct sk_buff *skb,
1415 return 1; 1415 return 1;
1416 1416
1417 rx_dropped: 1417 rx_dropped:
1418 if (rxb != NULL) {
1419 kfree(rxb);
1420 rxb = NULL;
1421 }
1422 ieee->stats.rx_dropped++; 1418 ieee->stats.rx_dropped++;
1423 1419
1424 /* Returning 0 indicates to caller that we have not handled the SKB-- 1420 /* Returning 0 indicates to caller that we have not handled the SKB--
@@ -2691,7 +2687,7 @@ void rtllib_rx_mgt(struct rtllib_device *ieee,
2691 struct sk_buff *skb, 2687 struct sk_buff *skb,
2692 struct rtllib_rx_stats *stats) 2688 struct rtllib_rx_stats *stats)
2693{ 2689{
2694 struct rtllib_hdr_4addr *header = (struct rtllib_hdr_4addr *)skb->data ; 2690 struct rtllib_hdr_4addr *header = (struct rtllib_hdr_4addr *)skb->data;
2695 2691
2696 if ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) != 2692 if ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) !=
2697 RTLLIB_STYPE_PROBE_RESP) && 2693 RTLLIB_STYPE_PROBE_RESP) &&
diff --git a/drivers/staging/rtl8192e/rtllib_softmac.c b/drivers/staging/rtl8192e/rtllib_softmac.c
index abb6729ae279..d992a754e72d 100644
--- a/drivers/staging/rtl8192e/rtllib_softmac.c
+++ b/drivers/staging/rtl8192e/rtllib_softmac.c
@@ -193,7 +193,7 @@ MgntQuery_TxRateExcludeCCKRates(struct rtllib_device *ieee)
193 return QueryRate; 193 return QueryRate;
194} 194}
195 195
196u8 MgntQuery_MgntFrameTxRate(struct rtllib_device *ieee) 196static u8 MgntQuery_MgntFrameTxRate(struct rtllib_device *ieee)
197{ 197{
198 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo; 198 struct rt_hi_throughput *pHTInfo = ieee->pHTInfo;
199 u8 rate; 199 u8 rate;
@@ -343,7 +343,7 @@ inline void softmac_ps_mgmt_xmit(struct sk_buff *skb,
343 } 343 }
344} 344}
345 345
346inline struct sk_buff *rtllib_probe_req(struct rtllib_device *ieee) 346static inline struct sk_buff *rtllib_probe_req(struct rtllib_device *ieee)
347{ 347{
348 unsigned int len, rate_len; 348 unsigned int len, rate_len;
349 u8 *tag; 349 u8 *tag;
@@ -1311,7 +1311,7 @@ inline struct sk_buff *rtllib_association_req(struct rtllib_network *beacon,
1311 } 1311 }
1312 1312
1313 if (beacon->bCkipSupported) { 1313 if (beacon->bCkipSupported) {
1314 static u8 AironetIeOui[] = {0x00, 0x01, 0x66}; 1314 static const u8 AironetIeOui[] = {0x00, 0x01, 0x66};
1315 u8 CcxAironetBuf[30]; 1315 u8 CcxAironetBuf[30];
1316 struct octet_string osCcxAironetIE; 1316 struct octet_string osCcxAironetIE;
1317 1317
@@ -1331,10 +1331,11 @@ inline struct sk_buff *rtllib_association_req(struct rtllib_network *beacon,
1331 } 1331 }
1332 1332
1333 if (beacon->bCcxRmEnable) { 1333 if (beacon->bCcxRmEnable) {
1334 static u8 CcxRmCapBuf[] = {0x00, 0x40, 0x96, 0x01, 0x01, 0x00}; 1334 static const u8 CcxRmCapBuf[] = {0x00, 0x40, 0x96, 0x01, 0x01,
1335 0x00};
1335 struct octet_string osCcxRmCap; 1336 struct octet_string osCcxRmCap;
1336 1337
1337 osCcxRmCap.Octet = CcxRmCapBuf; 1338 osCcxRmCap.Octet = (u8 *) CcxRmCapBuf;
1338 osCcxRmCap.Length = sizeof(CcxRmCapBuf); 1339 osCcxRmCap.Length = sizeof(CcxRmCapBuf);
1339 tag = skb_put(skb, ccxrm_ie_len); 1340 tag = skb_put(skb, ccxrm_ie_len);
1340 *tag++ = MFIE_TYPE_GENERIC; 1341 *tag++ = MFIE_TYPE_GENERIC;
@@ -3167,6 +3168,7 @@ void rtllib_softmac_free(struct rtllib_device *ieee)
3167 cancel_delayed_work(&ieee->associate_retry_wq); 3168 cancel_delayed_work(&ieee->associate_retry_wq);
3168 destroy_workqueue(ieee->wq); 3169 destroy_workqueue(ieee->wq);
3169 up(&ieee->wx_sem); 3170 up(&ieee->wx_sem);
3171 tasklet_kill(&ieee->ps_task);
3170} 3172}
3171 3173
3172/******************************************************** 3174/********************************************************
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
index 73de9e9669f6..d401dbf4c7c6 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c
@@ -713,8 +713,8 @@ static void RxReorderIndicatePacket(struct ieee80211_device *ieee,
713 while(!list_empty(&pTS->RxPendingPktList)) { 713 while(!list_empty(&pTS->RxPendingPktList)) {
714 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): start RREORDER indicate\n",__func__); 714 IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): start RREORDER indicate\n",__func__);
715 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(pTS->RxPendingPktList.prev,RX_REORDER_ENTRY,List); 715 pReorderEntry = (PRX_REORDER_ENTRY)list_entry(pTS->RxPendingPktList.prev,RX_REORDER_ENTRY,List);
716 if( SN_LESS(pReorderEntry->SeqNum, pTS->RxIndicateSeq) || 716 if (SN_LESS(pReorderEntry->SeqNum, pTS->RxIndicateSeq) ||
717 SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq)) 717 SN_EQUAL(pReorderEntry->SeqNum, pTS->RxIndicateSeq))
718 { 718 {
719 /* This protect buffer from overflow. */ 719 /* This protect buffer from overflow. */
720 if(index >= REORDER_WIN_SIZE) { 720 if(index >= REORDER_WIN_SIZE) {
@@ -800,9 +800,8 @@ static u8 parse_subframe(struct sk_buff *skb,
800 // Null packet, don't indicate it to upper layer 800 // Null packet, don't indicate it to upper layer
801 ChkLength = LLCOffset;/* + (Frame_WEP(frame)!=0 ?Adapter->MgntInfo.SecurityInfo.EncryptionHeadOverhead:0);*/ 801 ChkLength = LLCOffset;/* + (Frame_WEP(frame)!=0 ?Adapter->MgntInfo.SecurityInfo.EncryptionHeadOverhead:0);*/
802 802
803 if( skb->len <= ChkLength ) { 803 if (skb->len <= ChkLength)
804 return 0; 804 return 0;
805 }
806 805
807 skb_pull(skb, LLCOffset); 806 skb_pull(skb, LLCOffset);
808 807
@@ -1035,10 +1034,9 @@ int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
1035 { 1034 {
1036 1035
1037 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pRxTS->RxLastFragNum is %d,frag is %d,pRxTS->RxLastSeqNum is %d,seq is %d\n",__func__,pRxTS->RxLastFragNum,frag,pRxTS->RxLastSeqNum,WLAN_GET_SEQ_SEQ(sc)); 1036 // IEEE80211_DEBUG(IEEE80211_DL_REORDER,"%s(): pRxTS->RxLastFragNum is %d,frag is %d,pRxTS->RxLastSeqNum is %d,seq is %d\n",__func__,pRxTS->RxLastFragNum,frag,pRxTS->RxLastSeqNum,WLAN_GET_SEQ_SEQ(sc));
1038 if( (fc & (1<<11)) && 1037 if ((fc & (1<<11)) &&
1039 (frag == pRxTS->RxLastFragNum) && 1038 (frag == pRxTS->RxLastFragNum) &&
1040 (WLAN_GET_SEQ_SEQ(sc) == pRxTS->RxLastSeqNum) ) 1039 (WLAN_GET_SEQ_SEQ(sc) == pRxTS->RxLastSeqNum)) {
1041 {
1042 goto rx_dropped; 1040 goto rx_dropped;
1043 } 1041 }
1044 else 1042 else
@@ -2456,7 +2454,7 @@ static inline void ieee80211_process_probe_response(
2456 // then wireless adapter should do active scan from ch1~11 and 2454 // then wireless adapter should do active scan from ch1~11 and
2457 // passive scan from ch12~14 2455 // passive scan from ch12~14
2458 2456
2459 if( !IsLegalChannel(ieee, network.channel) ) 2457 if (!IsLegalChannel(ieee, network.channel))
2460 return; 2458 return;
2461 if(ieee->bGlobalDomain) 2459 if(ieee->bGlobalDomain)
2462 { 2460 {
@@ -2465,8 +2463,7 @@ static inline void ieee80211_process_probe_response(
2465 // Case 1: Country code 2463 // Case 1: Country code
2466 if(IS_COUNTRY_IE_VALID(ieee) ) 2464 if(IS_COUNTRY_IE_VALID(ieee) )
2467 { 2465 {
2468 if( !IsLegalChannel(ieee, network.channel) ) 2466 if (!IsLegalChannel(ieee, network.channel)) {
2469 {
2470 printk("GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network.channel); 2467 printk("GetScanInfo(): For Country code, filter probe response at channel(%d).\n", network.channel);
2471 return; 2468 return;
2472 } 2469 }
@@ -2487,8 +2484,7 @@ static inline void ieee80211_process_probe_response(
2487 // Case 1: Country code 2484 // Case 1: Country code
2488 if(IS_COUNTRY_IE_VALID(ieee) ) 2485 if(IS_COUNTRY_IE_VALID(ieee) )
2489 { 2486 {
2490 if( !IsLegalChannel(ieee, network.channel) ) 2487 if (!IsLegalChannel(ieee, network.channel)) {
2491 {
2492 printk("GetScanInfo(): For Country code, filter beacon at channel(%d).\n",network.channel); 2488 printk("GetScanInfo(): For Country code, filter beacon at channel(%d).\n",network.channel);
2493 return; 2489 return;
2494 } 2490 }
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
index a85bb232be97..d1471877e19d 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac.c
@@ -411,7 +411,7 @@ static void ieee80211_send_probe(struct ieee80211_device *ieee)
411 } 411 }
412} 412}
413 413
414void ieee80211_send_probe_requests(struct ieee80211_device *ieee) 414static void ieee80211_send_probe_requests(struct ieee80211_device *ieee)
415{ 415{
416 if (ieee->active_scan && (ieee->softmac_features & IEEE_SOFTMAC_PROBERQ)){ 416 if (ieee->active_scan && (ieee->softmac_features & IEEE_SOFTMAC_PROBERQ)){
417 ieee80211_send_probe(ieee); 417 ieee80211_send_probe(ieee);
@@ -517,7 +517,7 @@ static void ieee80211_softmac_scan_wq(struct work_struct *work)
517 goto out; 517 goto out;
518 ieee->set_chan(ieee->dev, ieee->current_network.channel); 518 ieee->set_chan(ieee->dev, ieee->current_network.channel);
519 if(channel_map[ieee->current_network.channel] == 1) 519 if(channel_map[ieee->current_network.channel] == 1)
520 ieee80211_send_probe_requests(ieee); 520 ieee80211_send_probe_requests(ieee);
521 521
522 522
523 queue_delayed_work(ieee->wq, &ieee->softmac_scan_wq, IEEE80211_SOFTMAC_SCAN_TIME); 523 queue_delayed_work(ieee->wq, &ieee->softmac_scan_wq, IEEE80211_SOFTMAC_SCAN_TIME);
@@ -804,12 +804,11 @@ static struct sk_buff *ieee80211_probe_resp(struct ieee80211_device *ieee, u8 *d
804 *(tag++) = ieee->current_network.channel; 804 *(tag++) = ieee->current_network.channel;
805 805
806 if(atim_len){ 806 if(atim_len){
807 u16 val16;
808 *(tag++) = MFIE_TYPE_IBSS_SET; 807 *(tag++) = MFIE_TYPE_IBSS_SET;
809 *(tag++) = 2; 808 *(tag++) = 2;
810 //*((u16*)(tag)) = cpu_to_le16(ieee->current_network.atim_window); 809
811 val16 = cpu_to_le16(ieee->current_network.atim_window); 810 put_unaligned_le16(ieee->current_network.atim_window,
812 memcpy((u8 *)tag, (u8 *)&val16, 2); 811 (u8 *)tag);
813 tag+=2; 812 tag+=2;
814 } 813 }
815 814
@@ -1043,10 +1042,9 @@ inline struct sk_buff *ieee80211_association_req(struct ieee80211_network *beaco
1043 { 1042 {
1044 ccxrm_ie_len = 6+2; 1043 ccxrm_ie_len = 6+2;
1045 } 1044 }
1046 if( beacon->BssCcxVerNumber >= 2 ) 1045 if (beacon->BssCcxVerNumber >= 2)
1047 {
1048 cxvernum_ie_len = 5+2; 1046 cxvernum_ie_len = 5+2;
1049 } 1047
1050#ifdef THOMAS_TURBO 1048#ifdef THOMAS_TURBO
1051 len = sizeof(struct ieee80211_assoc_request_frame)+ 2 1049 len = sizeof(struct ieee80211_assoc_request_frame)+ 2
1052 + beacon->ssid_len//essid tagged val 1050 + beacon->ssid_len//essid tagged val
@@ -1103,7 +1101,7 @@ inline struct sk_buff *ieee80211_association_req(struct ieee80211_network *beaco
1103 if(ieee->short_slot) 1101 if(ieee->short_slot)
1104 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT); 1102 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_SHORT_SLOT);
1105 if (wmm_info_len) //QOS 1103 if (wmm_info_len) //QOS
1106 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_QOS); 1104 hdr->capability |= cpu_to_le16(WLAN_CAPABILITY_QOS);
1107 1105
1108 hdr->listen_interval = 0xa; //FIXME 1106 hdr->listen_interval = 0xa; //FIXME
1109 1107
@@ -1118,8 +1116,7 @@ inline struct sk_buff *ieee80211_association_req(struct ieee80211_network *beaco
1118 ieee80211_MFIE_Brate(ieee, &tag); 1116 ieee80211_MFIE_Brate(ieee, &tag);
1119 ieee80211_MFIE_Grate(ieee, &tag); 1117 ieee80211_MFIE_Grate(ieee, &tag);
1120 // For CCX 1 S13, CKIP. Added by Annie, 2006-08-14. 1118 // For CCX 1 S13, CKIP. Added by Annie, 2006-08-14.
1121 if( beacon->bCkipSupported ) 1119 if (beacon->bCkipSupported) {
1122 {
1123 static u8 AironetIeOui[] = {0x00, 0x01, 0x66}; // "4500-client" 1120 static u8 AironetIeOui[] = {0x00, 0x01, 0x66}; // "4500-client"
1124 u8 CcxAironetBuf[30]; 1121 u8 CcxAironetBuf[30];
1125 OCTET_STRING osCcxAironetIE; 1122 OCTET_STRING osCcxAironetIE;
@@ -1158,8 +1155,7 @@ inline struct sk_buff *ieee80211_association_req(struct ieee80211_network *beaco
1158 tag += osCcxRmCap.Length; 1155 tag += osCcxRmCap.Length;
1159 } 1156 }
1160 1157
1161 if( beacon->BssCcxVerNumber >= 2 ) 1158 if (beacon->BssCcxVerNumber >= 2) {
1162 {
1163 u8 CcxVerNumBuf[] = {0x00, 0x40, 0x96, 0x03, 0x00}; 1159 u8 CcxVerNumBuf[] = {0x00, 0x40, 0x96, 0x03, 0x00};
1164 OCTET_STRING osCcxVerNum; 1160 OCTET_STRING osCcxVerNum;
1165 CcxVerNumBuf[4] = beacon->BssCcxVerNumber; 1161 CcxVerNumBuf[4] = beacon->BssCcxVerNumber;
@@ -1533,7 +1529,7 @@ void ieee80211_softmac_check_all_nets(struct ieee80211_device *ieee)
1533 break; 1529 break;
1534 1530
1535 if (ieee->scan_age == 0 || time_after(target->last_scanned + ieee->scan_age, jiffies)) 1531 if (ieee->scan_age == 0 || time_after(target->last_scanned + ieee->scan_age, jiffies))
1536 ieee80211_softmac_new_net(ieee, target); 1532 ieee80211_softmac_new_net(ieee, target);
1537 } 1533 }
1538 1534
1539 spin_unlock_irqrestore(&ieee->lock, flags); 1535 spin_unlock_irqrestore(&ieee->lock, flags);
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c
index 82ea533a0cf4..644368df6342 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_softmac_wx.c
@@ -374,7 +374,7 @@ int ieee80211_wx_set_scan(struct ieee80211_device *ieee, struct iw_request_info
374 goto out; 374 goto out;
375 } 375 }
376 376
377 if ( ieee->state == IEEE80211_LINKED){ 377 if (ieee->state == IEEE80211_LINKED) {
378 queue_work(ieee->wq, &ieee->wx_sync_scan_wq); 378 queue_work(ieee->wq, &ieee->wx_sync_scan_wq);
379 /* intentionally forget to up sem */ 379 /* intentionally forget to up sem */
380 return 0; 380 return 0;
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
index 57bef219687b..fca73c7c9fbe 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_tx.c
@@ -529,8 +529,7 @@ static void ieee80211_query_protectionmode(struct ieee80211_device *ieee,
529 } 529 }
530 } 530 }
531 // For test , CTS replace with RTS 531 // For test , CTS replace with RTS
532 if( 0 ) 532 if (0) {
533 {
534 tcb_desc->bCTSEnable = true; 533 tcb_desc->bCTSEnable = true;
535 tcb_desc->rts_rate = MGN_24M; 534 tcb_desc->rts_rate = MGN_24M;
536 tcb_desc->bRTSEnable = true; 535 tcb_desc->bRTSEnable = true;
diff --git a/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c b/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c
index 68f5ede86633..ae1b3cf2866c 100644
--- a/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c
+++ b/drivers/staging/rtl8192u/ieee80211/ieee80211_wx.c
@@ -172,7 +172,7 @@ static inline char *rtl819x_translate_scan(struct ieee80211_device *ieee,
172 iwe.cmd = IWEVCUSTOM; 172 iwe.cmd = IWEVCUSTOM;
173 iwe.u.data.length = p - custom; 173 iwe.u.data.length = p - custom;
174 if (iwe.u.data.length) 174 if (iwe.u.data.length)
175 start = iwe_stream_add_point(info, start, stop, &iwe, custom); 175 start = iwe_stream_add_point(info, start, stop, &iwe, custom);
176 /* Add quality statistics */ 176 /* Add quality statistics */
177 /* TODO: Fix these values... */ 177 /* TODO: Fix these values... */
178 iwe.cmd = IWEVQUAL; 178 iwe.cmd = IWEVQUAL;
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c b/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c
index 51552d42d66c..cd196cec0dd9 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_BAProc.c
@@ -110,7 +110,7 @@ static struct sk_buff *ieee80211_ADDBA(struct ieee80211_device *ieee, u8 *Dst, P
110 struct sk_buff *skb = NULL; 110 struct sk_buff *skb = NULL;
111 struct ieee80211_hdr_3addr *BAReq = NULL; 111 struct ieee80211_hdr_3addr *BAReq = NULL;
112 u8 *tag = NULL; 112 u8 *tag = NULL;
113 u16 tmp = 0; 113 __le16 tmp = 0;
114 u16 len = ieee->tx_headroom + 9; 114 u16 len = ieee->tx_headroom + 9;
115 //category(1) + action field(1) + Dialog Token(1) + BA Parameter Set(2) + BA Timeout Value(2) + BA Start SeqCtrl(2)(or StatusCode(2)) 115 //category(1) + action field(1) + Dialog Token(1) + BA Parameter Set(2) + BA Timeout Value(2) + BA Start SeqCtrl(2)(or StatusCode(2))
116 IEEE80211_DEBUG(IEEE80211_DL_TRACE | IEEE80211_DL_BA, "========>%s(), frame(%d) sentd to:%pM, ieee->dev:%p\n", __func__, type, Dst, ieee->dev); 116 IEEE80211_DEBUG(IEEE80211_DL_TRACE | IEEE80211_DL_BA, "========>%s(), frame(%d) sentd to:%pM, ieee->dev:%p\n", __func__, type, Dst, ieee->dev);
@@ -196,7 +196,7 @@ static struct sk_buff *ieee80211_DELBA(
196 struct sk_buff *skb = NULL; 196 struct sk_buff *skb = NULL;
197 struct ieee80211_hdr_3addr *Delba = NULL; 197 struct ieee80211_hdr_3addr *Delba = NULL;
198 u8 *tag = NULL; 198 u8 *tag = NULL;
199 u16 tmp = 0; 199 __le16 tmp = 0;
200 //len = head len + DELBA Parameter Set(2) + Reason Code(2) 200 //len = head len + DELBA Parameter Set(2) + Reason Code(2)
201 u16 len = 6 + ieee->tx_headroom; 201 u16 len = 6 + ieee->tx_headroom;
202 202
@@ -342,8 +342,7 @@ int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, struct sk_buff *skb)
342 PSEQUENCE_CONTROL pBaStartSeqCtrl = NULL; 342 PSEQUENCE_CONTROL pBaStartSeqCtrl = NULL;
343 PRX_TS_RECORD pTS = NULL; 343 PRX_TS_RECORD pTS = NULL;
344 344
345 if (skb->len < sizeof( struct ieee80211_hdr_3addr) + 9) 345 if (skb->len < sizeof(struct ieee80211_hdr_3addr) + 9) {
346 {
347 IEEE80211_DEBUG(IEEE80211_DL_ERR, 346 IEEE80211_DEBUG(IEEE80211_DL_ERR,
348 " Invalid skb len in BAREQ(%d / %zu)\n", 347 " Invalid skb len in BAREQ(%d / %zu)\n",
349 skb->len, 348 skb->len,
@@ -444,8 +443,7 @@ int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb)
444 PBA_PARAM_SET pBaParamSet = NULL; 443 PBA_PARAM_SET pBaParamSet = NULL;
445 u16 ReasonCode; 444 u16 ReasonCode;
446 445
447 if (skb->len < sizeof( struct ieee80211_hdr_3addr) + 9) 446 if (skb->len < sizeof(struct ieee80211_hdr_3addr) + 9) {
448 {
449 IEEE80211_DEBUG(IEEE80211_DL_ERR, 447 IEEE80211_DEBUG(IEEE80211_DL_ERR,
450 " Invalid skb len in BARSP(%d / %zu)\n", 448 " Invalid skb len in BARSP(%d / %zu)\n",
451 skb->len, 449 skb->len,
@@ -463,10 +461,9 @@ int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb)
463 461
464 // Check the capability 462 // Check the capability
465 // Since we can always receive A-MPDU, we just check if it is under HT mode. 463 // Since we can always receive A-MPDU, we just check if it is under HT mode.
466 if( ieee->current_network.qos_data.active == 0 || 464 if (ieee->current_network.qos_data.active == 0 ||
467 ieee->pHTInfo->bCurrentHTSupport == false || 465 ieee->pHTInfo->bCurrentHTSupport == false ||
468 ieee->pHTInfo->bCurrentAMPDUEnable == false ) 466 ieee->pHTInfo->bCurrentAMPDUEnable == false) {
469 {
470 IEEE80211_DEBUG(IEEE80211_DL_ERR, "reject to ADDBA_RSP as some capability is not ready(%d, %d, %d)\n",ieee->current_network.qos_data.active, ieee->pHTInfo->bCurrentHTSupport, ieee->pHTInfo->bCurrentAMPDUEnable); 467 IEEE80211_DEBUG(IEEE80211_DL_ERR, "reject to ADDBA_RSP as some capability is not ready(%d, %d, %d)\n",ieee->current_network.qos_data.active, ieee->pHTInfo->bCurrentHTSupport, ieee->pHTInfo->bCurrentAMPDUEnable);
471 ReasonCode = DELBA_REASON_UNKNOWN_BA; 468 ReasonCode = DELBA_REASON_UNKNOWN_BA;
472 goto OnADDBARsp_Reject; 469 goto OnADDBARsp_Reject;
@@ -577,8 +574,7 @@ int ieee80211_rx_DELBA(struct ieee80211_device *ieee, struct sk_buff *skb)
577 u16 *pReasonCode = NULL; 574 u16 *pReasonCode = NULL;
578 u8 *dst = NULL; 575 u8 *dst = NULL;
579 576
580 if (skb->len < sizeof( struct ieee80211_hdr_3addr) + 6) 577 if (skb->len < sizeof(struct ieee80211_hdr_3addr) + 6) {
581 {
582 IEEE80211_DEBUG(IEEE80211_DL_ERR, 578 IEEE80211_DEBUG(IEEE80211_DL_ERR,
583 " Invalid skb len in DELBA(%d / %zu)\n", 579 " Invalid skb len in DELBA(%d / %zu)\n",
584 skb->len, 580 skb->len,
diff --git a/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c b/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c
index 1ea2cd392670..e60d926a3973 100644
--- a/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c
+++ b/drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c
@@ -602,8 +602,7 @@ void HTConstructCapabilityElement(struct ieee80211_device *ieee, u8 *posHTCap, u
602 // TODO: Nedd to take care of this part 602 // TODO: Nedd to take care of this part
603 IEEE80211_DEBUG(IEEE80211_DL_HT, "TX HT cap/info ele BW=%d MaxAMSDUSize:%d DssCCk:%d\n", pCapELE->ChlWidth, pCapELE->MaxAMSDUSize, pCapELE->DssCCk); 603 IEEE80211_DEBUG(IEEE80211_DL_HT, "TX HT cap/info ele BW=%d MaxAMSDUSize:%d DssCCk:%d\n", pCapELE->ChlWidth, pCapELE->MaxAMSDUSize, pCapELE->DssCCk);
604 604
605 if( IsEncrypt) 605 if (IsEncrypt) {
606 {
607 pCapELE->MPDUDensity = 7; // 8us 606 pCapELE->MPDUDensity = 7; // 8us
608 pCapELE->MaxRxAMPDUFactor = 2; // 2 is for 32 K and 3 is 64K 607 pCapELE->MaxRxAMPDUFactor = 2; // 2 is for 32 K and 3 is 64K
609 } 608 }
@@ -951,8 +950,7 @@ void HTOnAssocRsp(struct ieee80211_device *ieee)
951 static u8 EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33}; // For 11n EWC definition, 2007.07.17, by Emily 950 static u8 EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33}; // For 11n EWC definition, 2007.07.17, by Emily
952 static u8 EWC11NHTInfo[] = {0x00, 0x90, 0x4c, 0x34}; // For 11n EWC definition, 2007.07.17, by Emily 951 static u8 EWC11NHTInfo[] = {0x00, 0x90, 0x4c, 0x34}; // For 11n EWC definition, 2007.07.17, by Emily
953 952
954 if( pHTInfo->bCurrentHTSupport == false ) 953 if (pHTInfo->bCurrentHTSupport == false) {
955 {
956 IEEE80211_DEBUG(IEEE80211_DL_ERR, "<=== HTOnAssocRsp(): HT_DISABLE\n"); 954 IEEE80211_DEBUG(IEEE80211_DL_ERR, "<=== HTOnAssocRsp(): HT_DISABLE\n");
957 return; 955 return;
958 } 956 }
@@ -1043,7 +1041,7 @@ void HTOnAssocRsp(struct ieee80211_device *ieee)
1043 // Replace MPDU factor declared in original association response frame format. 2007.08.20 by Emily 1041 // Replace MPDU factor declared in original association response frame format. 2007.08.20 by Emily
1044 if (ieee->current_network.bssht.bdRT2RTAggregation) 1042 if (ieee->current_network.bssht.bdRT2RTAggregation)
1045 { 1043 {
1046 if( ieee->pairwise_key_type != KEY_TYPE_NA) 1044 if (ieee->pairwise_key_type != KEY_TYPE_NA)
1047 // Realtek may set 32k in security mode and 64k for others 1045 // Realtek may set 32k in security mode and 64k for others
1048 pHTInfo->CurrentAMPDUFactor = pPeerHTCap->MaxRxAMPDUFactor; 1046 pHTInfo->CurrentAMPDUFactor = pPeerHTCap->MaxRxAMPDUFactor;
1049 else 1047 else
@@ -1332,8 +1330,7 @@ u8 HTCCheck(struct ieee80211_device *ieee, u8 *pFrame)
1332{ 1330{
1333 if(ieee->pHTInfo->bCurrentHTSupport) 1331 if(ieee->pHTInfo->bCurrentHTSupport)
1334 { 1332 {
1335 if( (IsQoSDataFrame(pFrame) && Frame_Order(pFrame)) == 1) 1333 if ((IsQoSDataFrame(pFrame) && Frame_Order(pFrame)) == 1) {
1336 {
1337 IEEE80211_DEBUG(IEEE80211_DL_HT, "HT CONTROL FILED EXIST!!\n"); 1334 IEEE80211_DEBUG(IEEE80211_DL_HT, "HT CONTROL FILED EXIST!!\n");
1338 return true; 1335 return true;
1339 } 1336 }
diff --git a/drivers/staging/rtl8192u/r8192U_core.c b/drivers/staging/rtl8192u/r8192U_core.c
index 929ac29197cc..e031a253e2ae 100644
--- a/drivers/staging/rtl8192u/r8192U_core.c
+++ b/drivers/staging/rtl8192u/r8192U_core.c
@@ -1791,8 +1791,8 @@ static void rtl8192_link_change(struct net_device *dev)
1791} 1791}
1792 1792
1793static struct ieee80211_qos_parameters def_qos_parameters = { 1793static struct ieee80211_qos_parameters def_qos_parameters = {
1794 {3, 3, 3, 3},/* cw_min */ 1794 {cpu_to_le16(3), cpu_to_le16(3), cpu_to_le16(3), cpu_to_le16(3)},
1795 {7, 7, 7, 7},/* cw_max */ 1795 {cpu_to_le16(7), cpu_to_le16(7), cpu_to_le16(7), cpu_to_le16(7)},
1796 {2, 2, 2, 2},/* aifs */ 1796 {2, 2, 2, 2},/* aifs */
1797 {0, 0, 0, 0},/* flags */ 1797 {0, 0, 0, 0},/* flags */
1798 {0, 0, 0, 0} /* tx_op_limit */ 1798 {0, 0, 0, 0} /* tx_op_limit */
@@ -1821,8 +1821,11 @@ static void rtl8192_qos_activate(struct work_struct *work)
1821 struct net_device *dev = priv->ieee80211->dev; 1821 struct net_device *dev = priv->ieee80211->dev;
1822 struct ieee80211_qos_parameters *qos_parameters = &priv->ieee80211->current_network.qos_data.parameters; 1822 struct ieee80211_qos_parameters *qos_parameters = &priv->ieee80211->current_network.qos_data.parameters;
1823 u8 mode = priv->ieee80211->current_network.mode; 1823 u8 mode = priv->ieee80211->current_network.mode;
1824 u8 u1bAIFS; 1824 u32 u1bAIFS;
1825 u32 u4bAcParam; 1825 u32 u4bAcParam;
1826 u32 op_limit;
1827 u32 cw_max;
1828 u32 cw_min;
1826 int i; 1829 int i;
1827 1830
1828 mutex_lock(&priv->mutex); 1831 mutex_lock(&priv->mutex);
@@ -1835,11 +1838,14 @@ static void rtl8192_qos_activate(struct work_struct *work)
1835 for (i = 0; i < QOS_QUEUE_NUM; i++) { 1838 for (i = 0; i < QOS_QUEUE_NUM; i++) {
1836 //Mode G/A: slotTimeTimer = 9; Mode B: 20 1839 //Mode G/A: slotTimeTimer = 9; Mode B: 20
1837 u1bAIFS = qos_parameters->aifs[i] * ((mode&(IEEE_G|IEEE_N_24G)) ? 9 : 20) + aSifsTime; 1840 u1bAIFS = qos_parameters->aifs[i] * ((mode&(IEEE_G|IEEE_N_24G)) ? 9 : 20) + aSifsTime;
1838 u4bAcParam = ((((u32)(qos_parameters->tx_op_limit[i]))<< AC_PARAM_TXOP_LIMIT_OFFSET)| 1841 u1bAIFS <<= AC_PARAM_AIFS_OFFSET;
1839 (((u32)(qos_parameters->cw_max[i]))<< AC_PARAM_ECW_MAX_OFFSET)| 1842 op_limit = (u32)le16_to_cpu(qos_parameters->tx_op_limit[i]);
1840 (((u32)(qos_parameters->cw_min[i]))<< AC_PARAM_ECW_MIN_OFFSET)| 1843 op_limit <<= AC_PARAM_TXOP_LIMIT_OFFSET;
1841 ((u32)u1bAIFS << AC_PARAM_AIFS_OFFSET)); 1844 cw_max = (u32)le16_to_cpu(qos_parameters->cw_max[i]);
1842 1845 cw_max <<= AC_PARAM_ECW_MAX_OFFSET;
1846 cw_min = (u32)le16_to_cpu(qos_parameters->cw_min[i]);
1847 cw_min <<= AC_PARAM_ECW_MIN_OFFSET;
1848 u4bAcParam = op_limit | cw_max | cw_min | u1bAIFS;
1843 write_nic_dword(dev, WDCAPARA_ADD[i], u4bAcParam); 1849 write_nic_dword(dev, WDCAPARA_ADD[i], u4bAcParam);
1844 } 1850 }
1845 1851
diff --git a/drivers/staging/rtl8192u/r8192U_dm.c b/drivers/staging/rtl8192u/r8192U_dm.c
index b0b66fba563b..936565d46014 100644
--- a/drivers/staging/rtl8192u/r8192U_dm.c
+++ b/drivers/staging/rtl8192u/r8192U_dm.c
@@ -1476,14 +1476,12 @@ static void dm_CCKTxPowerAdjust_TSSI(struct net_device *dev, bool bInCH14)
1476 1476
1477 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal); 1477 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
1478 //Write 0xa24 ~ 0xa27 1478 //Write 0xa24 ~ 0xa27
1479 TempVal = 0;
1480 TempVal = priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[2] + 1479 TempVal = priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[2] +
1481 (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[3]<<8) + 1480 (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[3]<<8) +
1482 (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[4]<<16)+ 1481 (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[4]<<16)+
1483 (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[5]<<24); 1482 (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[5]<<24);
1484 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal); 1483 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal);
1485 //Write 0xa28 0xa29 1484 //Write 0xa28 0xa29
1486 TempVal = 0;
1487 TempVal = priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[6] + 1485 TempVal = priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[6] +
1488 (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[7]<<8) ; 1486 (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[7]<<8) ;
1489 1487
@@ -1496,14 +1494,12 @@ static void dm_CCKTxPowerAdjust_TSSI(struct net_device *dev, bool bInCH14)
1496 1494
1497 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal); 1495 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
1498 //Write 0xa24 ~ 0xa27 1496 //Write 0xa24 ~ 0xa27
1499 TempVal = 0;
1500 TempVal = priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[2] + 1497 TempVal = priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[2] +
1501 (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[3]<<8) + 1498 (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[3]<<8) +
1502 (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[4]<<16)+ 1499 (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[4]<<16)+
1503 (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[5]<<24); 1500 (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[5]<<24);
1504 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal); 1501 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal);
1505 //Write 0xa28 0xa29 1502 //Write 0xa28 0xa29
1506 TempVal = 0;
1507 TempVal = priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[6] + 1503 TempVal = priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[6] +
1508 (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[7]<<8) ; 1504 (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[7]<<8) ;
1509 1505
@@ -1528,7 +1524,6 @@ static void dm_CCKTxPowerAdjust_ThermalMeter(struct net_device *dev, bool bInCH
1528 RT_TRACE(COMP_POWER_TRACKING, "CCK not chnl 14, reg 0x%x = 0x%x\n", 1524 RT_TRACE(COMP_POWER_TRACKING, "CCK not chnl 14, reg 0x%x = 0x%x\n",
1529 rCCK0_TxFilter1, TempVal); 1525 rCCK0_TxFilter1, TempVal);
1530 //Write 0xa24 ~ 0xa27 1526 //Write 0xa24 ~ 0xa27
1531 TempVal = 0;
1532 TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][2] + 1527 TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][2] +
1533 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][3]<<8) + 1528 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][3]<<8) +
1534 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][4]<<16)+ 1529 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][4]<<16)+
@@ -1537,7 +1532,6 @@ static void dm_CCKTxPowerAdjust_ThermalMeter(struct net_device *dev, bool bInCH
1537 RT_TRACE(COMP_POWER_TRACKING, "CCK not chnl 14, reg 0x%x = 0x%x\n", 1532 RT_TRACE(COMP_POWER_TRACKING, "CCK not chnl 14, reg 0x%x = 0x%x\n",
1538 rCCK0_TxFilter2, TempVal); 1533 rCCK0_TxFilter2, TempVal);
1539 //Write 0xa28 0xa29 1534 //Write 0xa28 0xa29
1540 TempVal = 0;
1541 TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][6] + 1535 TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][6] +
1542 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][7]<<8) ; 1536 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][7]<<8) ;
1543 1537
@@ -1556,7 +1550,6 @@ static void dm_CCKTxPowerAdjust_ThermalMeter(struct net_device *dev, bool bInCH
1556 RT_TRACE(COMP_POWER_TRACKING, "CCK chnl 14, reg 0x%x = 0x%x\n", 1550 RT_TRACE(COMP_POWER_TRACKING, "CCK chnl 14, reg 0x%x = 0x%x\n",
1557 rCCK0_TxFilter1, TempVal); 1551 rCCK0_TxFilter1, TempVal);
1558 //Write 0xa24 ~ 0xa27 1552 //Write 0xa24 ~ 0xa27
1559 TempVal = 0;
1560 TempVal = CCKSwingTable_Ch14[priv->CCK_index][2] + 1553 TempVal = CCKSwingTable_Ch14[priv->CCK_index][2] +
1561 (CCKSwingTable_Ch14[priv->CCK_index][3]<<8) + 1554 (CCKSwingTable_Ch14[priv->CCK_index][3]<<8) +
1562 (CCKSwingTable_Ch14[priv->CCK_index][4]<<16)+ 1555 (CCKSwingTable_Ch14[priv->CCK_index][4]<<16)+
@@ -1565,7 +1558,6 @@ static void dm_CCKTxPowerAdjust_ThermalMeter(struct net_device *dev, bool bInCH
1565 RT_TRACE(COMP_POWER_TRACKING, "CCK chnl 14, reg 0x%x = 0x%x\n", 1558 RT_TRACE(COMP_POWER_TRACKING, "CCK chnl 14, reg 0x%x = 0x%x\n",
1566 rCCK0_TxFilter2, TempVal); 1559 rCCK0_TxFilter2, TempVal);
1567 //Write 0xa28 0xa29 1560 //Write 0xa28 0xa29
1568 TempVal = 0;
1569 TempVal = CCKSwingTable_Ch14[priv->CCK_index][6] + 1561 TempVal = CCKSwingTable_Ch14[priv->CCK_index][6] +
1570 (CCKSwingTable_Ch14[priv->CCK_index][7]<<8) ; 1562 (CCKSwingTable_Ch14[priv->CCK_index][7]<<8) ;
1571 1563
@@ -1810,85 +1802,6 @@ void dm_change_dynamic_initgain_thresh(struct net_device *dev, u32 dm_type,
1810 } 1802 }
1811} /* DM_ChangeDynamicInitGainThresh */ 1803} /* DM_ChangeDynamicInitGainThresh */
1812 1804
1813void
1814dm_change_rxpath_selection_setting(
1815 struct net_device *dev,
1816 s32 DM_Type,
1817 s32 DM_Value)
1818{
1819 struct r8192_priv *priv = ieee80211_priv(dev);
1820 prate_adaptive pRA = (prate_adaptive)&(priv->rate_adaptive);
1821
1822
1823 if(DM_Type == 0)
1824 {
1825 if(DM_Value > 1)
1826 DM_Value = 1;
1827 DM_RxPathSelTable.Enable = (u8)DM_Value;
1828 }
1829 else if(DM_Type == 1)
1830 {
1831 if(DM_Value > 1)
1832 DM_Value = 1;
1833 DM_RxPathSelTable.DbgMode = (u8)DM_Value;
1834 }
1835 else if(DM_Type == 2)
1836 {
1837 if(DM_Value > 40)
1838 DM_Value = 40;
1839 DM_RxPathSelTable.SS_TH_low = (u8)DM_Value;
1840 }
1841 else if(DM_Type == 3)
1842 {
1843 if(DM_Value > 25)
1844 DM_Value = 25;
1845 DM_RxPathSelTable.diff_TH = (u8)DM_Value;
1846 }
1847 else if(DM_Type == 4)
1848 {
1849 if(DM_Value >= CCK_Rx_Version_MAX)
1850 DM_Value = CCK_Rx_Version_1;
1851 DM_RxPathSelTable.cck_method= (u8)DM_Value;
1852 }
1853 else if(DM_Type == 10)
1854 {
1855 if(DM_Value > 100)
1856 DM_Value = 50;
1857 DM_RxPathSelTable.rf_rssi[0] = (u8)DM_Value;
1858 }
1859 else if(DM_Type == 11)
1860 {
1861 if(DM_Value > 100)
1862 DM_Value = 50;
1863 DM_RxPathSelTable.rf_rssi[1] = (u8)DM_Value;
1864 }
1865 else if(DM_Type == 12)
1866 {
1867 if(DM_Value > 100)
1868 DM_Value = 50;
1869 DM_RxPathSelTable.rf_rssi[2] = (u8)DM_Value;
1870 }
1871 else if(DM_Type == 13)
1872 {
1873 if(DM_Value > 100)
1874 DM_Value = 50;
1875 DM_RxPathSelTable.rf_rssi[3] = (u8)DM_Value;
1876 }
1877 else if(DM_Type == 20)
1878 {
1879 if(DM_Value > 1)
1880 DM_Value = 1;
1881 pRA->ping_rssi_enable = (u8)DM_Value;
1882 }
1883 else if(DM_Type == 21)
1884 {
1885 if(DM_Value > 30)
1886 DM_Value = 30;
1887 pRA->ping_rssi_thresh_for_ra = DM_Value;
1888 }
1889}
1890
1891
1892/*----------------------------------------------------------------------------- 1805/*-----------------------------------------------------------------------------
1893 * Function: dm_dig_init() 1806 * Function: dm_dig_init()
1894 * 1807 *
@@ -3554,7 +3467,6 @@ static void dm_check_txrateandretrycount(struct net_device *dev)
3554 3467
3555static void dm_send_rssi_tofw(struct net_device *dev) 3468static void dm_send_rssi_tofw(struct net_device *dev)
3556{ 3469{
3557 DCMD_TXCMD_T tx_cmd;
3558 struct r8192_priv *priv = ieee80211_priv(dev); 3470 struct r8192_priv *priv = ieee80211_priv(dev);
3559 3471
3560 // If we test chariot, we should stop the TX command ? 3472 // If we test chariot, we should stop the TX command ?
@@ -3562,9 +3474,6 @@ static void dm_send_rssi_tofw(struct net_device *dev)
3562 // 0x1e0(byte) to notify driver. 3474 // 0x1e0(byte) to notify driver.
3563 write_nic_byte(dev, DRIVER_RSSI, (u8)priv->undecorated_smoothed_pwdb); 3475 write_nic_byte(dev, DRIVER_RSSI, (u8)priv->undecorated_smoothed_pwdb);
3564 return; 3476 return;
3565 tx_cmd.Op = TXCMD_SET_RX_RSSI;
3566 tx_cmd.Length = 4;
3567 tx_cmd.Value = priv->undecorated_smoothed_pwdb;
3568} 3477}
3569 3478
3570/*---------------------------Define function prototype------------------------*/ 3479/*---------------------------Define function prototype------------------------*/
diff --git a/drivers/staging/rtl8192u/r8192U_wx.c b/drivers/staging/rtl8192u/r8192U_wx.c
index 28f60d2dbe5b..361d2d0c3df1 100644
--- a/drivers/staging/rtl8192u/r8192U_wx.c
+++ b/drivers/staging/rtl8192u/r8192U_wx.c
@@ -171,7 +171,6 @@ static int r8192_wx_set_crcmon(struct net_device *dev,
171 struct r8192_priv *priv = ieee80211_priv(dev); 171 struct r8192_priv *priv = ieee80211_priv(dev);
172 int *parms = (int *)extra; 172 int *parms = (int *)extra;
173 int enable = (parms[0] > 0); 173 int enable = (parms[0] > 0);
174 short prev = priv->crcmon;
175 174
176 down(&priv->wx_sem); 175 down(&priv->wx_sem);
177 176
@@ -183,11 +182,6 @@ static int r8192_wx_set_crcmon(struct net_device *dev,
183 DMESG("bad CRC in monitor mode are %s", 182 DMESG("bad CRC in monitor mode are %s",
184 priv->crcmon ? "accepted" : "rejected"); 183 priv->crcmon ? "accepted" : "rejected");
185 184
186 if (prev != priv->crcmon && priv->up) {
187 /* rtl8180_down(dev); */
188 /* rtl8180_up(dev); */
189 }
190
191 up(&priv->wx_sem); 185 up(&priv->wx_sem);
192 186
193 return 0; 187 return 0;
diff --git a/drivers/staging/rtl8192u/r819xU_firmware.c b/drivers/staging/rtl8192u/r819xU_firmware.c
index f66ad8a0dfe0..c230be290ab6 100644
--- a/drivers/staging/rtl8192u/r819xU_firmware.c
+++ b/drivers/staging/rtl8192u/r819xU_firmware.c
@@ -45,6 +45,7 @@ static bool fw_download_code(struct net_device *dev, u8 *code_virtual_address,
45 unsigned char *seg_ptr; 45 unsigned char *seg_ptr;
46 cb_desc *tcb_desc; 46 cb_desc *tcb_desc;
47 u8 bLastIniPkt; 47 u8 bLastIniPkt;
48 u8 index;
48 49
49 firmware_init_param(dev); 50 firmware_init_param(dev);
50 //Fragmentation might be required 51 //Fragmentation might be required
@@ -78,18 +79,19 @@ static bool fw_download_code(struct net_device *dev, u8 *code_virtual_address,
78 * Transform from little endian to big endian 79 * Transform from little endian to big endian
79 * and pending zero 80 * and pending zero
80 */ 81 */
81 for (i=0; i < frag_length; i+=4) { 82 for (i = 0; i < frag_length; i += 4) {
82 *seg_ptr++ = ((i+0)<frag_length)?code_virtual_address[i+3]:0; 83 *seg_ptr++ = ((i+0) < frag_length)?code_virtual_address[i+3] : 0;
83 *seg_ptr++ = ((i+1)<frag_length)?code_virtual_address[i+2]:0; 84 *seg_ptr++ = ((i+1) < frag_length)?code_virtual_address[i+2] : 0;
84 *seg_ptr++ = ((i+2)<frag_length)?code_virtual_address[i+1]:0; 85 *seg_ptr++ = ((i+2) < frag_length)?code_virtual_address[i+1] : 0;
85 *seg_ptr++ = ((i+3)<frag_length)?code_virtual_address[i+0]:0; 86 *seg_ptr++ = ((i+3) < frag_length)?code_virtual_address[i+0] : 0;
86 } 87 }
87 tcb_desc->txbuf_size= (u16)i; 88 tcb_desc->txbuf_size = (u16)i;
88 skb_put(skb, i); 89 skb_put(skb, i);
89 90
90 if (!priv->ieee80211->check_nic_enough_desc(dev,tcb_desc->queue_index)|| 91 index = tcb_desc->queue_index;
91 (!skb_queue_empty(&priv->ieee80211->skb_waitQ[tcb_desc->queue_index]))||\ 92 if (!priv->ieee80211->check_nic_enough_desc(dev, index) ||
92 (priv->ieee80211->queue_stop)) { 93 (!skb_queue_empty(&priv->ieee80211->skb_waitQ[index])) ||
94 (priv->ieee80211->queue_stop)) {
93 RT_TRACE(COMP_FIRMWARE,"=====================================================> tx full!\n"); 95 RT_TRACE(COMP_FIRMWARE,"=====================================================> tx full!\n");
94 skb_queue_tail(&priv->ieee80211->skb_waitQ[tcb_desc->queue_index], skb); 96 skb_queue_tail(&priv->ieee80211->skb_waitQ[tcb_desc->queue_index], skb);
95 } else { 97 } else {
diff --git a/drivers/staging/rtl8192u/r819xU_firmware.h b/drivers/staging/rtl8192u/r819xU_firmware.h
index c48c884aa1af..cfa222350a9a 100644
--- a/drivers/staging/rtl8192u/r819xU_firmware.h
+++ b/drivers/staging/rtl8192u/r819xU_firmware.h
@@ -12,15 +12,15 @@
12#define GET_COMMAND_PACKET_FRAG_THRESHOLD(v) (4*(v/4) - 8 - USB_HWDESC_HEADER_LEN) 12#define GET_COMMAND_PACKET_FRAG_THRESHOLD(v) (4*(v/4) - 8 - USB_HWDESC_HEADER_LEN)
13//#endif 13//#endif
14 14
15typedef enum _firmware_init_step{ 15typedef enum _firmware_init_step {
16 FW_INIT_STEP0_BOOT = 0, 16 FW_INIT_STEP0_BOOT = 0,
17 FW_INIT_STEP1_MAIN = 1, 17 FW_INIT_STEP1_MAIN = 1,
18 FW_INIT_STEP2_DATA = 2, 18 FW_INIT_STEP2_DATA = 2,
19}firmware_init_step_e; 19} firmware_init_step_e;
20 20
21typedef enum _opt_rst_type{ 21typedef enum _opt_rst_type {
22 OPT_SYSTEM_RESET = 0, 22 OPT_SYSTEM_RESET = 0,
23 OPT_FIRMWARE_RESET = 1, 23 OPT_FIRMWARE_RESET = 1,
24}opt_rst_type_e; 24} opt_rst_type_e;
25 25
26#endif 26#endif
diff --git a/drivers/staging/rtl8192u/r819xU_phy.c b/drivers/staging/rtl8192u/r819xU_phy.c
index e9c15fe8ded5..058960251bac 100644
--- a/drivers/staging/rtl8192u/r819xU_phy.c
+++ b/drivers/staging/rtl8192u/r819xU_phy.c
@@ -1463,6 +1463,7 @@ void rtl8192_SwChnl_WorkItem(struct net_device *dev)
1463u8 rtl8192_phy_SwChnl(struct net_device *dev, u8 channel) 1463u8 rtl8192_phy_SwChnl(struct net_device *dev, u8 channel)
1464{ 1464{
1465 struct r8192_priv *priv = ieee80211_priv(dev); 1465 struct r8192_priv *priv = ieee80211_priv(dev);
1466
1466 RT_TRACE(COMP_CH, "%s(), SwChnlInProgress: %d\n", __func__, 1467 RT_TRACE(COMP_CH, "%s(), SwChnlInProgress: %d\n", __func__,
1467 priv->SwChnlInProgress); 1468 priv->SwChnlInProgress);
1468 if (!priv->up) 1469 if (!priv->up)
diff --git a/drivers/staging/rtl8712/hal_init.c b/drivers/staging/rtl8712/hal_init.c
index 1d6ade05fa18..324da34383ea 100644
--- a/drivers/staging/rtl8712/hal_init.c
+++ b/drivers/staging/rtl8712/hal_init.c
@@ -86,7 +86,7 @@ static u32 rtl871x_open_fw(struct _adapter *padapter, const u8 **ppmappedfw)
86 (int)padapter->fw->size); 86 (int)padapter->fw->size);
87 return 0; 87 return 0;
88 } 88 }
89 *ppmappedfw = (u8 *)((*praw)->data); 89 *ppmappedfw = (*praw)->data;
90 return (*praw)->size; 90 return (*praw)->size;
91} 91}
92 92
@@ -136,15 +136,10 @@ static void update_fwhdr(struct fw_hdr *pfwhdr, const u8 *pmappedfw)
136static u8 chk_fwhdr(struct fw_hdr *pfwhdr, u32 ulfilelength) 136static u8 chk_fwhdr(struct fw_hdr *pfwhdr, u32 ulfilelength)
137{ 137{
138 u32 fwhdrsz, fw_sz; 138 u32 fwhdrsz, fw_sz;
139 u8 intf, rfconf;
140 139
141 /* check signature */ 140 /* check signature */
142 if ((pfwhdr->signature != 0x8712) && (pfwhdr->signature != 0x8192)) 141 if ((pfwhdr->signature != 0x8712) && (pfwhdr->signature != 0x8192))
143 return _FAIL; 142 return _FAIL;
144 /* check interface */
145 intf = (u8)((pfwhdr->version&0x3000) >> 12);
146 /* check rf_conf */
147 rfconf = (u8)((pfwhdr->version&0xC000) >> 14);
148 /* check fw_priv_sze & sizeof(struct fw_priv) */ 143 /* check fw_priv_sze & sizeof(struct fw_priv) */
149 if (pfwhdr->fw_priv_sz != sizeof(struct fw_priv)) 144 if (pfwhdr->fw_priv_sz != sizeof(struct fw_priv))
150 return _FAIL; 145 return _FAIL;
@@ -162,7 +157,7 @@ static u8 rtl8712_dl_fw(struct _adapter *padapter)
162 sint i; 157 sint i;
163 u8 tmp8, tmp8_a; 158 u8 tmp8, tmp8_a;
164 u16 tmp16; 159 u16 tmp16;
165 u32 maxlen = 0, tmp32; /* for compare usage */ 160 u32 maxlen = 0; /* for compare usage */
166 uint dump_imem_sz, imem_sz, dump_emem_sz, emem_sz; /* max = 49152; */ 161 uint dump_imem_sz, imem_sz, dump_emem_sz, emem_sz; /* max = 49152; */
167 struct fw_hdr fwhdr; 162 struct fw_hdr fwhdr;
168 u32 ulfilelength; /* FW file size */ 163 u32 ulfilelength; /* FW file size */
@@ -262,7 +257,7 @@ static u8 rtl8712_dl_fw(struct _adapter *padapter)
262 if (tmp8_a != (tmp8|BIT(2))) 257 if (tmp8_a != (tmp8|BIT(2)))
263 goto exit_fail; 258 goto exit_fail;
264 259
265 tmp32 = r8712_read32(padapter, TCR); 260 r8712_read32(padapter, TCR);
266 261
267 /* 4.polling IMEM Ready */ 262 /* 4.polling IMEM Ready */
268 i = 100; 263 i = 100;
diff --git a/drivers/staging/rtl8712/ieee80211.c b/drivers/staging/rtl8712/ieee80211.c
index fe9459e483c5..57868085ce58 100644
--- a/drivers/staging/rtl8712/ieee80211.c
+++ b/drivers/staging/rtl8712/ieee80211.c
@@ -124,11 +124,10 @@ u8 *r8712_get_ie(u8 *pbuf, sint index, sint *len, sint limit)
124 if (*p == index) { 124 if (*p == index) {
125 *len = *(p + 1); 125 *len = *(p + 1);
126 return p; 126 return p;
127 } else {
128 tmp = *(p + 1);
129 p += (tmp + 2);
130 i += (tmp + 2);
131 } 127 }
128 tmp = *(p + 1);
129 p += (tmp + 2);
130 i += (tmp + 2);
132 if (i >= limit) 131 if (i >= limit)
133 break; 132 break;
134 } 133 }
@@ -237,10 +236,9 @@ unsigned char *r8712_get_wpa_ie(unsigned char *pie, int *wpa_ie_len, int limit)
237 goto check_next_ie; 236 goto check_next_ie;
238 *wpa_ie_len = *(pbuf + 1); 237 *wpa_ie_len = *(pbuf + 1);
239 return pbuf; 238 return pbuf;
240 } else {
241 *wpa_ie_len = 0;
242 return NULL;
243 } 239 }
240 *wpa_ie_len = 0;
241 return NULL;
244check_next_ie: 242check_next_ie:
245 limit = limit - (pbuf - pie) - 2 - len; 243 limit = limit - (pbuf - pie) - 2 - len;
246 if (limit <= 0) 244 if (limit <= 0)
@@ -370,13 +368,12 @@ int r8712_parse_wpa2_ie(u8 *rsn_ie, int rsn_ie_len, int *group_cipher,
370int r8712_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, 368int r8712_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len,
371 u8 *wpa_ie, u16 *wpa_len) 369 u8 *wpa_ie, u16 *wpa_len)
372{ 370{
373 u8 authmode, sec_idx; 371 u8 authmode;
374 u8 wpa_oui[4] = {0x0, 0x50, 0xf2, 0x01}; 372 u8 wpa_oui[4] = {0x0, 0x50, 0xf2, 0x01};
375 uint cnt; 373 uint cnt;
376 374
377 /*Search required WPA or WPA2 IE and copy to sec_ie[ ]*/ 375 /*Search required WPA or WPA2 IE and copy to sec_ie[ ]*/
378 cnt = (_TIMESTAMP_ + _BEACON_ITERVAL_ + _CAPABILITY_); 376 cnt = (_TIMESTAMP_ + _BEACON_ITERVAL_ + _CAPABILITY_);
379 sec_idx = 0;
380 while (cnt < in_len) { 377 while (cnt < in_len) {
381 authmode = in_ie[cnt]; 378 authmode = in_ie[cnt];
382 if ((authmode == _WPA_IE_ID_) && 379 if ((authmode == _WPA_IE_ID_) &&
@@ -414,7 +411,7 @@ int r8712_get_wps_ie(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen)
414 cnt += in_ie[cnt+1]+2; 411 cnt += in_ie[cnt+1]+2;
415 match = true; 412 match = true;
416 break; 413 break;
417 } else 414 }
418 cnt += in_ie[cnt+1]+2; /* goto next */ 415 cnt += in_ie[cnt+1]+2; /* goto next */
419 } 416 }
420 return match; 417 return match;
diff --git a/drivers/staging/rtl8712/osdep_service.h b/drivers/staging/rtl8712/osdep_service.h
index d7a357b8d2d1..5153ad9c2c75 100644
--- a/drivers/staging/rtl8712/osdep_service.h
+++ b/drivers/staging/rtl8712/osdep_service.h
@@ -88,17 +88,13 @@ static inline u32 _down_sema(struct semaphore *sema)
88{ 88{
89 if (down_interruptible(sema)) 89 if (down_interruptible(sema))
90 return _FAIL; 90 return _FAIL;
91 else 91 return _SUCCESS;
92 return _SUCCESS;
93} 92}
94 93
95static inline u32 end_of_queue_search(struct list_head *head, 94static inline u32 end_of_queue_search(struct list_head *head,
96 struct list_head *plist) 95 struct list_head *plist)
97{ 96{
98 if (head == plist) 97 return (head == plist);
99 return true;
100 else
101 return false;
102} 98}
103 99
104static inline void sleep_schedulable(int ms) 100static inline void sleep_schedulable(int ms)
diff --git a/drivers/staging/rtl8712/recv_linux.c b/drivers/staging/rtl8712/recv_linux.c
index 495ee1205e02..0631f3638257 100644
--- a/drivers/staging/rtl8712/recv_linux.c
+++ b/drivers/staging/rtl8712/recv_linux.c
@@ -146,7 +146,7 @@ void r8712_os_read_port(struct _adapter *padapter, struct recv_buf *precvbuf)
146 dev_kfree_skb_any(precvbuf->pskb); 146 dev_kfree_skb_any(precvbuf->pskb);
147 precvbuf->pskb = NULL; 147 precvbuf->pskb = NULL;
148 precvbuf->reuse = false; 148 precvbuf->reuse = false;
149 if (precvbuf->irp_pending == false) 149 if (!precvbuf->irp_pending)
150 r8712_read_port(padapter, precvpriv->ff_hwaddr, 0, 150 r8712_read_port(padapter, precvpriv->ff_hwaddr, 0,
151 (unsigned char *)precvbuf); 151 (unsigned char *)precvbuf);
152} 152}
diff --git a/drivers/staging/rtl8712/rtl8712_cmd.c b/drivers/staging/rtl8712/rtl8712_cmd.c
index 720e8a15db96..62e53cc1d8b9 100644
--- a/drivers/staging/rtl8712/rtl8712_cmd.c
+++ b/drivers/staging/rtl8712/rtl8712_cmd.c
@@ -157,10 +157,8 @@ static u8 read_bbreg_hdl(struct _adapter *padapter, u8 *pbuf)
157{ 157{
158 u32 val; 158 u32 val;
159 void (*pcmd_callback)(struct _adapter *dev, struct cmd_obj *pcmd); 159 void (*pcmd_callback)(struct _adapter *dev, struct cmd_obj *pcmd);
160 struct readBB_parm *prdbbparm;
161 struct cmd_obj *pcmd = (struct cmd_obj *)pbuf; 160 struct cmd_obj *pcmd = (struct cmd_obj *)pbuf;
162 161
163 prdbbparm = (struct readBB_parm *)pcmd->parmbuf;
164 if (pcmd->rsp && pcmd->rspsz > 0) 162 if (pcmd->rsp && pcmd->rspsz > 0)
165 memcpy(pcmd->rsp, (u8 *)&val, pcmd->rspsz); 163 memcpy(pcmd->rsp, (u8 *)&val, pcmd->rspsz);
166 pcmd_callback = cmd_callback[pcmd->cmdcode].callback; 164 pcmd_callback = cmd_callback[pcmd->cmdcode].callback;
@@ -174,10 +172,8 @@ static u8 read_bbreg_hdl(struct _adapter *padapter, u8 *pbuf)
174static u8 write_bbreg_hdl(struct _adapter *padapter, u8 *pbuf) 172static u8 write_bbreg_hdl(struct _adapter *padapter, u8 *pbuf)
175{ 173{
176 void (*pcmd_callback)(struct _adapter *dev, struct cmd_obj *pcmd); 174 void (*pcmd_callback)(struct _adapter *dev, struct cmd_obj *pcmd);
177 struct writeBB_parm *pwritebbparm;
178 struct cmd_obj *pcmd = (struct cmd_obj *)pbuf; 175 struct cmd_obj *pcmd = (struct cmd_obj *)pbuf;
179 176
180 pwritebbparm = (struct writeBB_parm *)pcmd->parmbuf;
181 pcmd_callback = cmd_callback[pcmd->cmdcode].callback; 177 pcmd_callback = cmd_callback[pcmd->cmdcode].callback;
182 if (pcmd_callback == NULL) 178 if (pcmd_callback == NULL)
183 r8712_free_cmd_obj(pcmd); 179 r8712_free_cmd_obj(pcmd);
@@ -190,10 +186,8 @@ static u8 read_rfreg_hdl(struct _adapter *padapter, u8 *pbuf)
190{ 186{
191 u32 val; 187 u32 val;
192 void (*pcmd_callback)(struct _adapter *dev, struct cmd_obj *pcmd); 188 void (*pcmd_callback)(struct _adapter *dev, struct cmd_obj *pcmd);
193 struct readRF_parm *prdrfparm;
194 struct cmd_obj *pcmd = (struct cmd_obj *)pbuf; 189 struct cmd_obj *pcmd = (struct cmd_obj *)pbuf;
195 190
196 prdrfparm = (struct readRF_parm *)pcmd->parmbuf;
197 if (pcmd->rsp && pcmd->rspsz > 0) 191 if (pcmd->rsp && pcmd->rspsz > 0)
198 memcpy(pcmd->rsp, (u8 *)&val, pcmd->rspsz); 192 memcpy(pcmd->rsp, (u8 *)&val, pcmd->rspsz);
199 pcmd_callback = cmd_callback[pcmd->cmdcode].callback; 193 pcmd_callback = cmd_callback[pcmd->cmdcode].callback;
@@ -207,10 +201,8 @@ static u8 read_rfreg_hdl(struct _adapter *padapter, u8 *pbuf)
207static u8 write_rfreg_hdl(struct _adapter *padapter, u8 *pbuf) 201static u8 write_rfreg_hdl(struct _adapter *padapter, u8 *pbuf)
208{ 202{
209 void (*pcmd_callback)(struct _adapter *dev, struct cmd_obj *pcmd); 203 void (*pcmd_callback)(struct _adapter *dev, struct cmd_obj *pcmd);
210 struct writeRF_parm *pwriterfparm;
211 struct cmd_obj *pcmd = (struct cmd_obj *)pbuf; 204 struct cmd_obj *pcmd = (struct cmd_obj *)pbuf;
212 205
213 pwriterfparm = (struct writeRF_parm *)pcmd->parmbuf;
214 pcmd_callback = cmd_callback[pcmd->cmdcode].callback; 206 pcmd_callback = cmd_callback[pcmd->cmdcode].callback;
215 if (pcmd_callback == NULL) 207 if (pcmd_callback == NULL)
216 r8712_free_cmd_obj(pcmd); 208 r8712_free_cmd_obj(pcmd);
@@ -222,9 +214,7 @@ static u8 write_rfreg_hdl(struct _adapter *padapter, u8 *pbuf)
222static u8 sys_suspend_hdl(struct _adapter *padapter, u8 *pbuf) 214static u8 sys_suspend_hdl(struct _adapter *padapter, u8 *pbuf)
223{ 215{
224 struct cmd_obj *pcmd = (struct cmd_obj *)pbuf; 216 struct cmd_obj *pcmd = (struct cmd_obj *)pbuf;
225 struct usb_suspend_parm *psetusbsuspend;
226 217
227 psetusbsuspend = (struct usb_suspend_parm *)pcmd->parmbuf;
228 r8712_free_cmd_obj(pcmd); 218 r8712_free_cmd_obj(pcmd);
229 return H2C_SUCCESS; 219 return H2C_SUCCESS;
230} 220}
@@ -320,7 +310,7 @@ void r8712_fw_cmd_data(struct _adapter *pAdapter, u32 *value, u8 flag)
320int r8712_cmd_thread(void *context) 310int r8712_cmd_thread(void *context)
321{ 311{
322 struct cmd_obj *pcmd; 312 struct cmd_obj *pcmd;
323 unsigned int cmdsz, wr_sz, *pcmdbuf, *prspbuf; 313 unsigned int cmdsz, wr_sz, *pcmdbuf;
324 struct tx_desc *pdesc; 314 struct tx_desc *pdesc;
325 void (*pcmd_callback)(struct _adapter *dev, struct cmd_obj *pcmd); 315 void (*pcmd_callback)(struct _adapter *dev, struct cmd_obj *pcmd);
326 struct _adapter *padapter = (struct _adapter *)context; 316 struct _adapter *padapter = (struct _adapter *)context;
@@ -342,7 +332,6 @@ _next:
342 continue; 332 continue;
343 } 333 }
344 pcmdbuf = (unsigned int *)pcmdpriv->cmd_buf; 334 pcmdbuf = (unsigned int *)pcmdpriv->cmd_buf;
345 prspbuf = (unsigned int *)pcmdpriv->rsp_buf;
346 pdesc = (struct tx_desc *)pcmdbuf; 335 pdesc = (struct tx_desc *)pcmdbuf;
347 memset(pdesc, 0, TXDESC_SIZE); 336 memset(pdesc, 0, TXDESC_SIZE);
348 pcmd = cmd_hdl_filter(padapter, pcmd); 337 pcmd = cmd_hdl_filter(padapter, pcmd);
diff --git a/drivers/staging/rtl8712/rtl8712_efuse.c b/drivers/staging/rtl8712/rtl8712_efuse.c
index c9eeb4270ab9..d95716999498 100644
--- a/drivers/staging/rtl8712/rtl8712_efuse.c
+++ b/drivers/staging/rtl8712/rtl8712_efuse.c
@@ -219,13 +219,12 @@ u16 r8712_efuse_get_current_size(struct _adapter *padapter)
219{ 219{
220 int bContinual = true; 220 int bContinual = true;
221 u16 efuse_addr = 0; 221 u16 efuse_addr = 0;
222 u8 hoffset = 0, hworden = 0; 222 u8 hworden = 0;
223 u8 efuse_data, word_cnts = 0; 223 u8 efuse_data, word_cnts = 0;
224 224
225 while (bContinual && efuse_one_byte_read(padapter, efuse_addr, 225 while (bContinual && efuse_one_byte_read(padapter, efuse_addr,
226 &efuse_data) && (efuse_addr < efuse_available_max_size)) { 226 &efuse_data) && (efuse_addr < efuse_available_max_size)) {
227 if (efuse_data != 0xFF) { 227 if (efuse_data != 0xFF) {
228 hoffset = (efuse_data >> 4) & 0x0F;
229 hworden = efuse_data & 0x0F; 228 hworden = efuse_data & 0x0F;
230 word_cnts = calculate_word_cnts(hworden); 229 word_cnts = calculate_word_cnts(hworden);
231 /* read next header */ 230 /* read next header */
@@ -414,19 +413,18 @@ u8 r8712_efuse_pg_packet_write(struct _adapter *padapter, const u8 offset,
414 bResult = false; 413 bResult = false;
415 } 414 }
416 break; 415 break;
417 } else { /* write header fail */
418 bResult = false;
419 if (0xFF == efuse_data)
420 return bResult; /* nothing damaged. */
421 /* call rescue procedure */
422 if (fix_header(padapter, efuse_data, efuse_addr) ==
423 false)
424 return false; /* rescue fail */
425
426 if (++repeat_times > _REPEAT_THRESHOLD_) /* fail */
427 break;
428 /* otherwise, take another risk... */
429 } 416 }
417 /* write header fail */
418 bResult = false;
419 if (0xFF == efuse_data)
420 return bResult; /* nothing damaged. */
421 /* call rescue procedure */
422 if (!fix_header(padapter, efuse_data, efuse_addr))
423 return false; /* rescue fail */
424
425 if (++repeat_times > _REPEAT_THRESHOLD_) /* fail */
426 break;
427 /* otherwise, take another risk... */
430 } 428 }
431 return bResult; 429 return bResult;
432} 430}
@@ -541,15 +539,16 @@ u8 r8712_efuse_map_write(struct _adapter *padapter, u16 addr, u16 cnts,
541 } 539 }
542 idx++; 540 idx++;
543 break; 541 break;
544 } else {
545 if ((data[idx] != pktdata[i]) || (data[idx+1] !=
546 pktdata[i+1])) {
547 word_en &= ~BIT(i >> 1);
548 newdata[j++] = data[idx];
549 newdata[j++] = data[idx + 1];
550 }
551 idx += 2;
552 } 542 }
543
544 if ((data[idx] != pktdata[i]) || (data[idx+1] !=
545 pktdata[i+1])) {
546 word_en &= ~BIT(i >> 1);
547 newdata[j++] = data[idx];
548 newdata[j++] = data[idx + 1];
549 }
550 idx += 2;
551
553 if (idx == cnts) 552 if (idx == cnts)
554 break; 553 break;
555 } 554 }
diff --git a/drivers/staging/rtl8712/rtl8712_recv.c b/drivers/staging/rtl8712/rtl8712_recv.c
index b27806209268..cd8b444b255b 100644
--- a/drivers/staging/rtl8712/rtl8712_recv.c
+++ b/drivers/staging/rtl8712/rtl8712_recv.c
@@ -158,8 +158,6 @@ int r8712_free_recvframe(union recv_frame *precvframe,
158static void update_recvframe_attrib_from_recvstat(struct rx_pkt_attrib *pattrib, 158static void update_recvframe_attrib_from_recvstat(struct rx_pkt_attrib *pattrib,
159 struct recv_stat *prxstat) 159 struct recv_stat *prxstat)
160{ 160{
161 u32 *pphy_info;
162 struct phy_stat *pphy_stat;
163 u16 drvinfo_sz = 0; 161 u16 drvinfo_sz = 0;
164 162
165 drvinfo_sz = (le32_to_cpu(prxstat->rxdw0)&0x000f0000)>>16; 163 drvinfo_sz = (le32_to_cpu(prxstat->rxdw0)&0x000f0000)>>16;
@@ -189,10 +187,6 @@ static void update_recvframe_attrib_from_recvstat(struct rx_pkt_attrib *pattrib,
189 /*Offset 16*/ 187 /*Offset 16*/
190 /*Offset 20*/ 188 /*Offset 20*/
191 /*phy_info*/ 189 /*phy_info*/
192 if (drvinfo_sz) {
193 pphy_stat = (struct phy_stat *)(prxstat+1);
194 pphy_info = (u32 *)prxstat+1;
195 }
196} 190}
197 191
198/*perform defrag*/ 192/*perform defrag*/
@@ -200,7 +194,7 @@ static union recv_frame *recvframe_defrag(struct _adapter *adapter,
200 struct __queue *defrag_q) 194 struct __queue *defrag_q)
201{ 195{
202 struct list_head *plist, *phead; 196 struct list_head *plist, *phead;
203 u8 *data, wlanhdr_offset; 197 u8 wlanhdr_offset;
204 u8 curfragnum; 198 u8 curfragnum;
205 struct recv_frame_hdr *pfhdr, *pnfhdr; 199 struct recv_frame_hdr *pfhdr, *pnfhdr;
206 union recv_frame *prframe, *pnextrframe; 200 union recv_frame *prframe, *pnextrframe;
@@ -223,7 +217,6 @@ static union recv_frame *recvframe_defrag(struct _adapter *adapter,
223 curfragnum++; 217 curfragnum++;
224 plist = &defrag_q->queue; 218 plist = &defrag_q->queue;
225 plist = plist->next; 219 plist = plist->next;
226 data = get_recvframe_data(prframe);
227 while (end_of_queue_search(phead, plist) == false) { 220 while (end_of_queue_search(phead, plist) == false) {
228 pnextrframe = LIST_CONTAINOR(plist, union recv_frame, u); 221 pnextrframe = LIST_CONTAINOR(plist, union recv_frame, u);
229 pnfhdr = &pnextrframe->u.hdr; 222 pnfhdr = &pnextrframe->u.hdr;
@@ -436,13 +429,11 @@ void r8712_rxcmd_event_hdl(struct _adapter *padapter, void *prxcmdbuf)
436{ 429{
437 uint voffset; 430 uint voffset;
438 u8 *poffset; 431 u8 *poffset;
439 u16 pkt_len, cmd_len, drvinfo_sz; 432 u16 cmd_len, drvinfo_sz;
440 u8 eid, cmd_seq;
441 struct recv_stat *prxstat; 433 struct recv_stat *prxstat;
442 434
443 poffset = (u8 *)prxcmdbuf; 435 poffset = (u8 *)prxcmdbuf;
444 voffset = *(uint *)poffset; 436 voffset = *(uint *)poffset;
445 pkt_len = le32_to_cpu(voffset) & 0x00003fff;
446 prxstat = (struct recv_stat *)prxcmdbuf; 437 prxstat = (struct recv_stat *)prxcmdbuf;
447 drvinfo_sz = ((le32_to_cpu(prxstat->rxdw0) & 0x000f0000) >> 16); 438 drvinfo_sz = ((le32_to_cpu(prxstat->rxdw0) & 0x000f0000) >> 16);
448 drvinfo_sz = drvinfo_sz << 3; 439 drvinfo_sz = drvinfo_sz << 3;
@@ -450,8 +441,6 @@ void r8712_rxcmd_event_hdl(struct _adapter *padapter, void *prxcmdbuf)
450 do { 441 do {
451 voffset = *(uint *)poffset; 442 voffset = *(uint *)poffset;
452 cmd_len = (u16)(le32_to_cpu(voffset) & 0xffff); 443 cmd_len = (u16)(le32_to_cpu(voffset) & 0xffff);
453 cmd_seq = (u8)((le32_to_cpu(voffset) >> 24) & 0x7f);
454 eid = (u8)((le32_to_cpu(voffset) >> 16) & 0xff);
455 r8712_event_handle(padapter, (uint *)poffset); 444 r8712_event_handle(padapter, (uint *)poffset);
456 poffset += (cmd_len + 8);/*8 bytes alignment*/ 445 poffset += (cmd_len + 8);/*8 bytes alignment*/
457 } while (le32_to_cpu(voffset) & BIT(31)); 446 } while (le32_to_cpu(voffset) & BIT(31));
@@ -533,11 +522,10 @@ int r8712_recv_indicatepkts_in_order(struct _adapter *padapter,
533 if (bforced == true) { 522 if (bforced == true) {
534 if (list_empty(phead)) 523 if (list_empty(phead))
535 return true; 524 return true;
536 else { 525
537 prframe = LIST_CONTAINOR(plist, union recv_frame, u); 526 prframe = LIST_CONTAINOR(plist, union recv_frame, u);
538 pattrib = &prframe->u.hdr.attrib; 527 pattrib = &prframe->u.hdr.attrib;
539 preorder_ctrl->indicate_seq = pattrib->seq_num; 528 preorder_ctrl->indicate_seq = pattrib->seq_num;
540 }
541 } 529 }
542 /* Prepare indication list and indication. 530 /* Prepare indication list and indication.
543 * Check if there is any packet need indicate. */ 531 * Check if there is any packet need indicate. */
diff --git a/drivers/staging/rtl8712/rtl871x_cmd.c b/drivers/staging/rtl8712/rtl871x_cmd.c
index d9c1561e3272..fe5e315319f7 100644
--- a/drivers/staging/rtl8712/rtl871x_cmd.c
+++ b/drivers/staging/rtl8712/rtl871x_cmd.c
@@ -205,12 +205,12 @@ void r8712_free_cmd_obj(struct cmd_obj *pcmd)
205{ 205{
206 if ((pcmd->cmdcode != _JoinBss_CMD_) && 206 if ((pcmd->cmdcode != _JoinBss_CMD_) &&
207 (pcmd->cmdcode != _CreateBss_CMD_)) 207 (pcmd->cmdcode != _CreateBss_CMD_))
208 kfree((unsigned char *)pcmd->parmbuf); 208 kfree(pcmd->parmbuf);
209 if (pcmd->rsp != NULL) { 209 if (pcmd->rsp != NULL) {
210 if (pcmd->rspsz != 0) 210 if (pcmd->rspsz != 0)
211 kfree((unsigned char *)pcmd->rsp); 211 kfree(pcmd->rsp);
212 } 212 }
213 kfree((unsigned char *)pcmd); 213 kfree(pcmd);
214} 214}
215 215
216/* 216/*
@@ -232,7 +232,7 @@ u8 r8712_sitesurvey_cmd(struct _adapter *padapter,
232 return _FAIL; 232 return _FAIL;
233 psurveyPara = kmalloc(sizeof(*psurveyPara), GFP_ATOMIC); 233 psurveyPara = kmalloc(sizeof(*psurveyPara), GFP_ATOMIC);
234 if (psurveyPara == NULL) { 234 if (psurveyPara == NULL) {
235 kfree((unsigned char *) ph2c); 235 kfree(ph2c);
236 return _FAIL; 236 return _FAIL;
237 } 237 }
238 init_h2fwcmd_w_parm_no_rsp(ph2c, psurveyPara, 238 init_h2fwcmd_w_parm_no_rsp(ph2c, psurveyPara,
@@ -264,7 +264,7 @@ u8 r8712_setdatarate_cmd(struct _adapter *padapter, u8 *rateset)
264 return _FAIL; 264 return _FAIL;
265 pbsetdataratepara = kmalloc(sizeof(*pbsetdataratepara), GFP_ATOMIC); 265 pbsetdataratepara = kmalloc(sizeof(*pbsetdataratepara), GFP_ATOMIC);
266 if (pbsetdataratepara == NULL) { 266 if (pbsetdataratepara == NULL) {
267 kfree((u8 *) ph2c); 267 kfree(ph2c);
268 return _FAIL; 268 return _FAIL;
269 } 269 }
270 init_h2fwcmd_w_parm_no_rsp(ph2c, pbsetdataratepara, 270 init_h2fwcmd_w_parm_no_rsp(ph2c, pbsetdataratepara,
@@ -286,7 +286,7 @@ u8 r8712_set_chplan_cmd(struct _adapter *padapter, int chplan)
286 return _FAIL; 286 return _FAIL;
287 psetchplanpara = kmalloc(sizeof(*psetchplanpara), GFP_ATOMIC); 287 psetchplanpara = kmalloc(sizeof(*psetchplanpara), GFP_ATOMIC);
288 if (psetchplanpara == NULL) { 288 if (psetchplanpara == NULL) {
289 kfree((u8 *) ph2c); 289 kfree(ph2c);
290 return _FAIL; 290 return _FAIL;
291 } 291 }
292 init_h2fwcmd_w_parm_no_rsp(ph2c, psetchplanpara, 292 init_h2fwcmd_w_parm_no_rsp(ph2c, psetchplanpara,
@@ -307,7 +307,7 @@ u8 r8712_setbasicrate_cmd(struct _adapter *padapter, u8 *rateset)
307 return _FAIL; 307 return _FAIL;
308 pssetbasicratepara = kmalloc(sizeof(*pssetbasicratepara), GFP_ATOMIC); 308 pssetbasicratepara = kmalloc(sizeof(*pssetbasicratepara), GFP_ATOMIC);
309 if (pssetbasicratepara == NULL) { 309 if (pssetbasicratepara == NULL) {
310 kfree((u8 *) ph2c); 310 kfree(ph2c);
311 return _FAIL; 311 return _FAIL;
312 } 312 }
313 init_h2fwcmd_w_parm_no_rsp(ph2c, pssetbasicratepara, 313 init_h2fwcmd_w_parm_no_rsp(ph2c, pssetbasicratepara,
@@ -329,7 +329,7 @@ u8 r8712_setptm_cmd(struct _adapter *padapter, u8 type)
329 return _FAIL; 329 return _FAIL;
330 pwriteptmparm = kmalloc(sizeof(*pwriteptmparm), GFP_ATOMIC); 330 pwriteptmparm = kmalloc(sizeof(*pwriteptmparm), GFP_ATOMIC);
331 if (pwriteptmparm == NULL) { 331 if (pwriteptmparm == NULL) {
332 kfree((u8 *) ph2c); 332 kfree(ph2c);
333 return _FAIL; 333 return _FAIL;
334 } 334 }
335 init_h2fwcmd_w_parm_no_rsp(ph2c, pwriteptmparm, GEN_CMD_CODE(_SetPT)); 335 init_h2fwcmd_w_parm_no_rsp(ph2c, pwriteptmparm, GEN_CMD_CODE(_SetPT));
@@ -349,7 +349,7 @@ u8 r8712_setfwdig_cmd(struct _adapter *padapter, u8 type)
349 return _FAIL; 349 return _FAIL;
350 pwriteptmparm = kmalloc(sizeof(*pwriteptmparm), GFP_ATOMIC); 350 pwriteptmparm = kmalloc(sizeof(*pwriteptmparm), GFP_ATOMIC);
351 if (pwriteptmparm == NULL) { 351 if (pwriteptmparm == NULL) {
352 kfree((u8 *) ph2c); 352 kfree(ph2c);
353 return _FAIL; 353 return _FAIL;
354 } 354 }
355 init_h2fwcmd_w_parm_no_rsp(ph2c, pwriteptmparm, GEN_CMD_CODE(_SetDIG)); 355 init_h2fwcmd_w_parm_no_rsp(ph2c, pwriteptmparm, GEN_CMD_CODE(_SetDIG));
@@ -369,7 +369,7 @@ u8 r8712_setfwra_cmd(struct _adapter *padapter, u8 type)
369 return _FAIL; 369 return _FAIL;
370 pwriteptmparm = kmalloc(sizeof(*pwriteptmparm), GFP_ATOMIC); 370 pwriteptmparm = kmalloc(sizeof(*pwriteptmparm), GFP_ATOMIC);
371 if (pwriteptmparm == NULL) { 371 if (pwriteptmparm == NULL) {
372 kfree((u8 *) ph2c); 372 kfree(ph2c);
373 return _FAIL; 373 return _FAIL;
374 } 374 }
375 init_h2fwcmd_w_parm_no_rsp(ph2c, pwriteptmparm, GEN_CMD_CODE(_SetRA)); 375 init_h2fwcmd_w_parm_no_rsp(ph2c, pwriteptmparm, GEN_CMD_CODE(_SetRA));
@@ -389,7 +389,7 @@ u8 r8712_setrfreg_cmd(struct _adapter *padapter, u8 offset, u32 val)
389 return _FAIL; 389 return _FAIL;
390 pwriterfparm = kmalloc(sizeof(*pwriterfparm), GFP_ATOMIC); 390 pwriterfparm = kmalloc(sizeof(*pwriterfparm), GFP_ATOMIC);
391 if (pwriterfparm == NULL) { 391 if (pwriterfparm == NULL) {
392 kfree((u8 *) ph2c); 392 kfree(ph2c);
393 return _FAIL; 393 return _FAIL;
394 } 394 }
395 init_h2fwcmd_w_parm_no_rsp(ph2c, pwriterfparm, GEN_CMD_CODE(_SetRFReg)); 395 init_h2fwcmd_w_parm_no_rsp(ph2c, pwriterfparm, GEN_CMD_CODE(_SetRFReg));
@@ -410,7 +410,7 @@ u8 r8712_getrfreg_cmd(struct _adapter *padapter, u8 offset, u8 *pval)
410 return _FAIL; 410 return _FAIL;
411 prdrfparm = kmalloc(sizeof(*prdrfparm), GFP_ATOMIC); 411 prdrfparm = kmalloc(sizeof(*prdrfparm), GFP_ATOMIC);
412 if (prdrfparm == NULL) { 412 if (prdrfparm == NULL) {
413 kfree((u8 *) ph2c); 413 kfree(ph2c);
414 return _FAIL; 414 return _FAIL;
415 } 415 }
416 INIT_LIST_HEAD(&ph2c->list); 416 INIT_LIST_HEAD(&ph2c->list);
@@ -470,7 +470,6 @@ u8 r8712_createbss_cmd(struct _adapter *padapter)
470 470
471u8 r8712_joinbss_cmd(struct _adapter *padapter, struct wlan_network *pnetwork) 471u8 r8712_joinbss_cmd(struct _adapter *padapter, struct wlan_network *pnetwork)
472{ 472{
473 u8 *auth;
474 uint t_len = 0; 473 uint t_len = 0;
475 struct ndis_wlan_bssid_ex *psecnetwork; 474 struct ndis_wlan_bssid_ex *psecnetwork;
476 struct cmd_obj *pcmd; 475 struct cmd_obj *pcmd;
@@ -517,7 +516,6 @@ u8 r8712_joinbss_cmd(struct _adapter *padapter, struct wlan_network *pnetwork)
517 return _FAIL; 516 return _FAIL;
518 } 517 }
519 memcpy(psecnetwork, &pnetwork->network, t_len); 518 memcpy(psecnetwork, &pnetwork->network, t_len);
520 auth = &psecuritypriv->authenticator_ie[0];
521 psecuritypriv->authenticator_ie[0] = (unsigned char) 519 psecuritypriv->authenticator_ie[0] = (unsigned char)
522 psecnetwork->IELength; 520 psecnetwork->IELength;
523 if ((psecnetwork->IELength-12) < (256 - 1)) 521 if ((psecnetwork->IELength-12) < (256 - 1))
@@ -527,7 +525,7 @@ u8 r8712_joinbss_cmd(struct _adapter *padapter, struct wlan_network *pnetwork)
527 memcpy(&psecuritypriv->authenticator_ie[1], 525 memcpy(&psecuritypriv->authenticator_ie[1],
528 &psecnetwork->IEs[12], (256-1)); 526 &psecnetwork->IEs[12], (256-1));
529 psecnetwork->IELength = 0; 527 psecnetwork->IELength = 0;
530 /* If the the driver wants to use the bssid to create the connection. 528 /* If the driver wants to use the bssid to create the connection.
531 * If not, we copy the connecting AP's MAC address to it so that 529 * If not, we copy the connecting AP's MAC address to it so that
532 * the driver just has the bssid information for PMKIDList searching. 530 * the driver just has the bssid information for PMKIDList searching.
533 */ 531 */
@@ -626,7 +624,7 @@ u8 r8712_disassoc_cmd(struct _adapter *padapter) /* for sta_mode */
626 return _FAIL; 624 return _FAIL;
627 pdisconnect = kmalloc(sizeof(*pdisconnect), GFP_ATOMIC); 625 pdisconnect = kmalloc(sizeof(*pdisconnect), GFP_ATOMIC);
628 if (pdisconnect == NULL) { 626 if (pdisconnect == NULL) {
629 kfree((u8 *)pdisconnect_cmd); 627 kfree(pdisconnect_cmd);
630 return _FAIL; 628 return _FAIL;
631 } 629 }
632 init_h2fwcmd_w_parm_no_rsp(pdisconnect_cmd, pdisconnect, 630 init_h2fwcmd_w_parm_no_rsp(pdisconnect_cmd, pdisconnect,
@@ -648,7 +646,7 @@ u8 r8712_setopmode_cmd(struct _adapter *padapter,
648 return _FAIL; 646 return _FAIL;
649 psetop = kmalloc(sizeof(*psetop), GFP_ATOMIC); 647 psetop = kmalloc(sizeof(*psetop), GFP_ATOMIC);
650 if (psetop == NULL) { 648 if (psetop == NULL) {
651 kfree((u8 *) ph2c); 649 kfree(ph2c);
652 return _FAIL; 650 return _FAIL;
653 } 651 }
654 init_h2fwcmd_w_parm_no_rsp(ph2c, psetop, _SetOpMode_CMD_); 652 init_h2fwcmd_w_parm_no_rsp(ph2c, psetop, _SetOpMode_CMD_);
@@ -672,13 +670,13 @@ u8 r8712_setstakey_cmd(struct _adapter *padapter, u8 *psta, u8 unicast_key)
672 return _FAIL; 670 return _FAIL;
673 psetstakey_para = kmalloc(sizeof(*psetstakey_para), GFP_ATOMIC); 671 psetstakey_para = kmalloc(sizeof(*psetstakey_para), GFP_ATOMIC);
674 if (psetstakey_para == NULL) { 672 if (psetstakey_para == NULL) {
675 kfree((u8 *) ph2c); 673 kfree(ph2c);
676 return _FAIL; 674 return _FAIL;
677 } 675 }
678 psetstakey_rsp = kmalloc(sizeof(*psetstakey_rsp), GFP_ATOMIC); 676 psetstakey_rsp = kmalloc(sizeof(*psetstakey_rsp), GFP_ATOMIC);
679 if (psetstakey_rsp == NULL) { 677 if (psetstakey_rsp == NULL) {
680 kfree((u8 *) ph2c); 678 kfree(ph2c);
681 kfree((u8 *) psetstakey_para); 679 kfree(psetstakey_para);
682 return _FAIL; 680 return _FAIL;
683 } 681 }
684 init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_); 682 init_h2fwcmd_w_parm_no_rsp(ph2c, psetstakey_para, _SetStaKey_CMD_);
@@ -712,7 +710,7 @@ u8 r8712_setrfintfs_cmd(struct _adapter *padapter, u8 mode)
712 return _FAIL; 710 return _FAIL;
713 psetrfintfsparm = kmalloc(sizeof(*psetrfintfsparm), GFP_ATOMIC); 711 psetrfintfsparm = kmalloc(sizeof(*psetrfintfsparm), GFP_ATOMIC);
714 if (psetrfintfsparm == NULL) { 712 if (psetrfintfsparm == NULL) {
715 kfree((unsigned char *) ph2c); 713 kfree(ph2c);
716 return _FAIL; 714 return _FAIL;
717 } 715 }
718 init_h2fwcmd_w_parm_no_rsp(ph2c, psetrfintfsparm, 716 init_h2fwcmd_w_parm_no_rsp(ph2c, psetrfintfsparm,
@@ -734,7 +732,7 @@ u8 r8712_setrttbl_cmd(struct _adapter *padapter,
734 return _FAIL; 732 return _FAIL;
735 psetrttblparm = kmalloc(sizeof(*psetrttblparm), GFP_ATOMIC); 733 psetrttblparm = kmalloc(sizeof(*psetrttblparm), GFP_ATOMIC);
736 if (psetrttblparm == NULL) { 734 if (psetrttblparm == NULL) {
737 kfree((unsigned char *)ph2c); 735 kfree(ph2c);
738 return _FAIL; 736 return _FAIL;
739 } 737 }
740 init_h2fwcmd_w_parm_no_rsp(ph2c, psetrttblparm, 738 init_h2fwcmd_w_parm_no_rsp(ph2c, psetrttblparm,
@@ -755,7 +753,7 @@ u8 r8712_gettssi_cmd(struct _adapter *padapter, u8 offset, u8 *pval)
755 return _FAIL; 753 return _FAIL;
756 prdtssiparm = kmalloc(sizeof(*prdtssiparm), GFP_ATOMIC); 754 prdtssiparm = kmalloc(sizeof(*prdtssiparm), GFP_ATOMIC);
757 if (prdtssiparm == NULL) { 755 if (prdtssiparm == NULL) {
758 kfree((unsigned char *) ph2c); 756 kfree(ph2c);
759 return _FAIL; 757 return _FAIL;
760 } 758 }
761 INIT_LIST_HEAD(&ph2c->list); 759 INIT_LIST_HEAD(&ph2c->list);
@@ -781,7 +779,7 @@ u8 r8712_setMacAddr_cmd(struct _adapter *padapter, u8 *mac_addr)
781 return _FAIL; 779 return _FAIL;
782 psetMacAddr_para = kmalloc(sizeof(*psetMacAddr_para), GFP_ATOMIC); 780 psetMacAddr_para = kmalloc(sizeof(*psetMacAddr_para), GFP_ATOMIC);
783 if (psetMacAddr_para == NULL) { 781 if (psetMacAddr_para == NULL) {
784 kfree((u8 *) ph2c); 782 kfree(ph2c);
785 return _FAIL; 783 return _FAIL;
786 } 784 }
787 init_h2fwcmd_w_parm_no_rsp(ph2c, psetMacAddr_para, 785 init_h2fwcmd_w_parm_no_rsp(ph2c, psetMacAddr_para,
@@ -803,13 +801,13 @@ u8 r8712_setassocsta_cmd(struct _adapter *padapter, u8 *mac_addr)
803 return _FAIL; 801 return _FAIL;
804 psetassocsta_para = kmalloc(sizeof(*psetassocsta_para), GFP_ATOMIC); 802 psetassocsta_para = kmalloc(sizeof(*psetassocsta_para), GFP_ATOMIC);
805 if (psetassocsta_para == NULL) { 803 if (psetassocsta_para == NULL) {
806 kfree((u8 *) ph2c); 804 kfree(ph2c);
807 return _FAIL; 805 return _FAIL;
808 } 806 }
809 psetassocsta_rsp = kmalloc(sizeof(*psetassocsta_rsp), GFP_ATOMIC); 807 psetassocsta_rsp = kmalloc(sizeof(*psetassocsta_rsp), GFP_ATOMIC);
810 if (psetassocsta_rsp == NULL) { 808 if (psetassocsta_rsp == NULL) {
811 kfree((u8 *)ph2c); 809 kfree(ph2c);
812 kfree((u8 *)psetassocsta_para); 810 kfree(psetassocsta_para);
813 return _FAIL; 811 return _FAIL;
814 } 812 }
815 init_h2fwcmd_w_parm_no_rsp(ph2c, psetassocsta_para, _SetAssocSta_CMD_); 813 init_h2fwcmd_w_parm_no_rsp(ph2c, psetassocsta_para, _SetAssocSta_CMD_);
@@ -831,7 +829,7 @@ u8 r8712_addbareq_cmd(struct _adapter *padapter, u8 tid)
831 return _FAIL; 829 return _FAIL;
832 paddbareq_parm = kmalloc(sizeof(*paddbareq_parm), GFP_ATOMIC); 830 paddbareq_parm = kmalloc(sizeof(*paddbareq_parm), GFP_ATOMIC);
833 if (paddbareq_parm == NULL) { 831 if (paddbareq_parm == NULL) {
834 kfree((unsigned char *)ph2c); 832 kfree(ph2c);
835 return _FAIL; 833 return _FAIL;
836 } 834 }
837 paddbareq_parm->tid = tid; 835 paddbareq_parm->tid = tid;
@@ -852,7 +850,7 @@ u8 r8712_wdg_wk_cmd(struct _adapter *padapter)
852 return _FAIL; 850 return _FAIL;
853 pdrvintcmd_param = kmalloc(sizeof(*pdrvintcmd_param), GFP_ATOMIC); 851 pdrvintcmd_param = kmalloc(sizeof(*pdrvintcmd_param), GFP_ATOMIC);
854 if (pdrvintcmd_param == NULL) { 852 if (pdrvintcmd_param == NULL) {
855 kfree((unsigned char *)ph2c); 853 kfree(ph2c);
856 return _FAIL; 854 return _FAIL;
857 } 855 }
858 pdrvintcmd_param->i_cid = WDG_WK_CID; 856 pdrvintcmd_param->i_cid = WDG_WK_CID;
@@ -1026,7 +1024,7 @@ u8 r8712_disconnectCtrlEx_cmd(struct _adapter *adapter, u32 enableDrvCtrl,
1026 return _FAIL; 1024 return _FAIL;
1027 param = kzalloc(sizeof(*param), GFP_ATOMIC); 1025 param = kzalloc(sizeof(*param), GFP_ATOMIC);
1028 if (param == NULL) { 1026 if (param == NULL) {
1029 kfree((unsigned char *) ph2c); 1027 kfree(ph2c);
1030 return _FAIL; 1028 return _FAIL;
1031 } 1029 }
1032 1030
diff --git a/drivers/staging/rtl8712/rtl871x_io.c b/drivers/staging/rtl8712/rtl871x_io.c
index d7b63aedead7..e4e5b13cb927 100644
--- a/drivers/staging/rtl8712/rtl871x_io.c
+++ b/drivers/staging/rtl8712/rtl871x_io.c
@@ -93,7 +93,7 @@ static uint register_intf_hdl(u8 *dev, struct intf_hdl *pintfhdl)
93 pintfhdl->intf_option = 0; 93 pintfhdl->intf_option = 0;
94 pintfhdl->adapter = dev; 94 pintfhdl->adapter = dev;
95 pintfhdl->intf_dev = (u8 *)&(adapter->dvobjpriv); 95 pintfhdl->intf_dev = (u8 *)&(adapter->dvobjpriv);
96 if (_init_intf_hdl(adapter, pintfhdl) == false) 96 if (!_init_intf_hdl(adapter, pintfhdl))
97 goto register_intf_hdl_fail; 97 goto register_intf_hdl_fail;
98 return _SUCCESS; 98 return _SUCCESS;
99register_intf_hdl_fail: 99register_intf_hdl_fail:
@@ -142,7 +142,7 @@ uint r8712_alloc_io_queue(struct _adapter *adapter)
142alloc_io_queue_fail: 142alloc_io_queue_fail:
143 if (pio_queue) { 143 if (pio_queue) {
144 kfree(pio_queue->pallocated_free_ioreqs_buf); 144 kfree(pio_queue->pallocated_free_ioreqs_buf);
145 kfree((u8 *)pio_queue); 145 kfree(pio_queue);
146 } 146 }
147 adapter->pio_queue = NULL; 147 adapter->pio_queue = NULL;
148 return _FAIL; 148 return _FAIL;
@@ -156,6 +156,6 @@ void r8712_free_io_queue(struct _adapter *adapter)
156 kfree(pio_queue->pallocated_free_ioreqs_buf); 156 kfree(pio_queue->pallocated_free_ioreqs_buf);
157 adapter->pio_queue = NULL; 157 adapter->pio_queue = NULL;
158 unregister_intf_hdl(&pio_queue->intf); 158 unregister_intf_hdl(&pio_queue->intf);
159 kfree((u8 *)pio_queue); 159 kfree(pio_queue);
160 } 160 }
161} 161}
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
index 8e42ce06e5d7..73b7d864ccbd 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_linux.c
@@ -170,7 +170,7 @@ static inline char *translate_scan(struct _adapter *padapter,
170 s8 *p; 170 s8 *p;
171 u32 i = 0, ht_ielen = 0; 171 u32 i = 0, ht_ielen = 0;
172 u16 cap, ht_cap = false, mcs_rate; 172 u16 cap, ht_cap = false, mcs_rate;
173 u8 rssi, bw_40MHz = 0, short_GI = 0; 173 u8 rssi;
174 174
175 if ((pnetwork->network.Configuration.DSConfig < 1) || 175 if ((pnetwork->network.Configuration.DSConfig < 1) ||
176 (pnetwork->network.Configuration.DSConfig > 14)) { 176 (pnetwork->network.Configuration.DSConfig > 14)) {
@@ -197,10 +197,6 @@ static inline char *translate_scan(struct _adapter *padapter,
197 ht_cap = true; 197 ht_cap = true;
198 pht_capie = (struct ieee80211_ht_cap *)(p + 2); 198 pht_capie = (struct ieee80211_ht_cap *)(p + 2);
199 memcpy(&mcs_rate , pht_capie->supp_mcs_set, 2); 199 memcpy(&mcs_rate , pht_capie->supp_mcs_set, 2);
200 bw_40MHz = (pht_capie->cap_info&IEEE80211_HT_CAP_SUP_WIDTH)
201 ? 1 : 0;
202 short_GI = (pht_capie->cap_info&(IEEE80211_HT_CAP_SGI_20 |
203 IEEE80211_HT_CAP_SGI_40)) ? 1 : 0;
204 } 200 }
205 /* Add the protocol name */ 201 /* Add the protocol name */
206 iwe.cmd = SIOCGIWNAME; 202 iwe.cmd = SIOCGIWNAME;
@@ -287,12 +283,10 @@ static inline char *translate_scan(struct _adapter *padapter,
287 u8 wpa_ie[255], rsn_ie[255]; 283 u8 wpa_ie[255], rsn_ie[255];
288 u16 wpa_len = 0, rsn_len = 0; 284 u16 wpa_len = 0, rsn_len = 0;
289 int n; 285 int n;
290 sint out_len = 0;
291 286
292 out_len = r8712_get_sec_ie(pnetwork->network.IEs, 287 r8712_get_sec_ie(pnetwork->network.IEs,
293 pnetwork->network. 288 pnetwork->network.IELength, rsn_ie, &rsn_len,
294 IELength, rsn_ie, &rsn_len, 289 wpa_ie, &wpa_len);
295 wpa_ie, &wpa_len);
296 if (wpa_len > 0) { 290 if (wpa_len > 0) {
297 memset(buf, 0, MAX_WPA_IE_LEN); 291 memset(buf, 0, MAX_WPA_IE_LEN);
298 n = sprintf(buf, "wpa_ie="); 292 n = sprintf(buf, "wpa_ie=");
@@ -505,14 +499,14 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param,
505 } 499 }
506 } 500 }
507exit: 501exit:
508 kfree((u8 *)pwep); 502 kfree(pwep);
509 return ret; 503 return ret;
510} 504}
511 505
512static int r871x_set_wpa_ie(struct _adapter *padapter, char *pie, 506static int r871x_set_wpa_ie(struct _adapter *padapter, char *pie,
513 unsigned short ielen) 507 unsigned short ielen)
514{ 508{
515 u8 *buf = NULL, *pos = NULL; 509 u8 *buf = NULL;
516 int group_cipher = 0, pairwise_cipher = 0; 510 int group_cipher = 0, pairwise_cipher = 0;
517 int ret = 0; 511 int ret = 0;
518 512
@@ -522,7 +516,6 @@ static int r871x_set_wpa_ie(struct _adapter *padapter, char *pie,
522 buf = kmemdup(pie, ielen, GFP_ATOMIC); 516 buf = kmemdup(pie, ielen, GFP_ATOMIC);
523 if (buf == NULL) 517 if (buf == NULL)
524 return -ENOMEM; 518 return -ENOMEM;
525 pos = buf;
526 if (ielen < RSN_HEADER_LEN) { 519 if (ielen < RSN_HEADER_LEN) {
527 ret = -EINVAL; 520 ret = -EINVAL;
528 goto exit; 521 goto exit;
@@ -1133,13 +1126,11 @@ static int r871x_wx_set_mlme(struct net_device *dev,
1133 union iwreq_data *wrqu, char *extra) 1126 union iwreq_data *wrqu, char *extra)
1134{ 1127{
1135 int ret = 0; 1128 int ret = 0;
1136 u16 reason;
1137 struct _adapter *padapter = (struct _adapter *)netdev_priv(dev); 1129 struct _adapter *padapter = (struct _adapter *)netdev_priv(dev);
1138 struct iw_mlme *mlme = (struct iw_mlme *) extra; 1130 struct iw_mlme *mlme = (struct iw_mlme *) extra;
1139 1131
1140 if (mlme == NULL) 1132 if (mlme == NULL)
1141 return -1; 1133 return -1;
1142 reason = cpu_to_le16(mlme->reason_code);
1143 switch (mlme->cmd) { 1134 switch (mlme->cmd) {
1144 case IW_MLME_DEAUTH: 1135 case IW_MLME_DEAUTH:
1145 if (!r8712_set_802_11_disassociate(padapter)) 1136 if (!r8712_set_802_11_disassociate(padapter))
@@ -2216,7 +2207,7 @@ static int wpa_supplicant_ioctl(struct net_device *dev, struct iw_point *p)
2216 } 2207 }
2217 if (ret == 0 && copy_to_user(p->pointer, param, p->length)) 2208 if (ret == 0 && copy_to_user(p->pointer, param, p->length))
2218 ret = -EFAULT; 2209 ret = -EFAULT;
2219 kfree((u8 *)param); 2210 kfree(param);
2220 return ret; 2211 return ret;
2221} 2212}
2222 2213
diff --git a/drivers/staging/rtl8712/rtl871x_ioctl_set.c b/drivers/staging/rtl8712/rtl871x_ioctl_set.c
index 9d47eb472837..6318a0e65e6e 100644
--- a/drivers/staging/rtl8712/rtl871x_ioctl_set.c
+++ b/drivers/staging/rtl8712/rtl871x_ioctl_set.c
@@ -77,7 +77,7 @@ static u8 do_join(struct _adapter *padapter)
77 /* when set_ssid/set_bssid for do_join(), but scanning queue 77 /* when set_ssid/set_bssid for do_join(), but scanning queue
78 * is empty we try to issue sitesurvey firstly 78 * is empty we try to issue sitesurvey firstly
79 */ 79 */
80 if (pmlmepriv->sitesurveyctrl.traffic_busy == false) 80 if (!pmlmepriv->sitesurveyctrl.traffic_busy)
81 r8712_sitesurvey_cmd(padapter, &pmlmepriv->assoc_ssid); 81 r8712_sitesurvey_cmd(padapter, &pmlmepriv->assoc_ssid);
82 return true; 82 return true;
83 } else { 83 } else {
@@ -143,8 +143,7 @@ u8 r8712_set_802_11_bssid(struct _adapter *padapter, u8 *bssid)
143 _FW_LINKED|WIFI_ADHOC_MASTER_STATE) == true) { 143 _FW_LINKED|WIFI_ADHOC_MASTER_STATE) == true) {
144 if (!memcmp(&pmlmepriv->cur_network.network.MacAddress, bssid, 144 if (!memcmp(&pmlmepriv->cur_network.network.MacAddress, bssid,
145 ETH_ALEN)) { 145 ETH_ALEN)) {
146 if (check_fwstate(pmlmepriv, 146 if (!check_fwstate(pmlmepriv, WIFI_STATION_STATE))
147 WIFI_STATION_STATE) == false)
148 goto _Abort_Set_BSSID; /* driver is in 147 goto _Abort_Set_BSSID; /* driver is in
149 * WIFI_ADHOC_MASTER_STATE */ 148 * WIFI_ADHOC_MASTER_STATE */
150 } else { 149 } else {
@@ -177,7 +176,7 @@ void r8712_set_802_11_ssid(struct _adapter *padapter,
177 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 176 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
178 struct wlan_network *pnetwork = &pmlmepriv->cur_network; 177 struct wlan_network *pnetwork = &pmlmepriv->cur_network;
179 178
180 if (padapter->hw_init_completed == false) 179 if (!padapter->hw_init_completed)
181 return; 180 return;
182 spin_lock_irqsave(&pmlmepriv->lock, irqL); 181 spin_lock_irqsave(&pmlmepriv->lock, irqL);
183 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING)) { 182 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING)) {
@@ -188,10 +187,9 @@ void r8712_set_802_11_ssid(struct _adapter *padapter,
188 if ((pmlmepriv->assoc_ssid.SsidLength == ssid->SsidLength) && 187 if ((pmlmepriv->assoc_ssid.SsidLength == ssid->SsidLength) &&
189 (!memcmp(&pmlmepriv->assoc_ssid.Ssid, ssid->Ssid, 188 (!memcmp(&pmlmepriv->assoc_ssid.Ssid, ssid->Ssid,
190 ssid->SsidLength))) { 189 ssid->SsidLength))) {
191 if ((check_fwstate(pmlmepriv, 190 if (!check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
192 WIFI_STATION_STATE) == false)) { 191 if (!r8712_is_same_ibss(padapter,
193 if (r8712_is_same_ibss(padapter, 192 pnetwork)) {
194 pnetwork) == false) {
195 /* if in WIFI_ADHOC_MASTER_STATE or 193 /* if in WIFI_ADHOC_MASTER_STATE or
196 * WIFI_ADHOC_STATE, create bss or 194 * WIFI_ADHOC_STATE, create bss or
197 * rejoin again 195 * rejoin again
@@ -227,7 +225,7 @@ void r8712_set_802_11_ssid(struct _adapter *padapter,
227 } 225 }
228 if (padapter->securitypriv.btkip_countermeasure == true) 226 if (padapter->securitypriv.btkip_countermeasure == true)
229 goto _Abort_Set_SSID; 227 goto _Abort_Set_SSID;
230 if (validate_ssid(ssid) == false) 228 if (!validate_ssid(ssid))
231 goto _Abort_Set_SSID; 229 goto _Abort_Set_SSID;
232 memcpy(&pmlmepriv->assoc_ssid, ssid, sizeof(struct ndis_802_11_ssid)); 230 memcpy(&pmlmepriv->assoc_ssid, ssid, sizeof(struct ndis_802_11_ssid));
233 pmlmepriv->assoc_by_bssid = false; 231 pmlmepriv->assoc_by_bssid = false;
@@ -308,10 +306,10 @@ u8 r8712_set_802_11_bssid_list_scan(struct _adapter *padapter)
308 unsigned long irqL; 306 unsigned long irqL;
309 u8 ret = true; 307 u8 ret = true;
310 308
311 if (padapter == NULL) 309 if (!padapter)
312 return false; 310 return false;
313 pmlmepriv = &padapter->mlmepriv; 311 pmlmepriv = &padapter->mlmepriv;
314 if (padapter->hw_init_completed == false) 312 if (!padapter->hw_init_completed)
315 return false; 313 return false;
316 spin_lock_irqsave(&pmlmepriv->lock, irqL); 314 spin_lock_irqsave(&pmlmepriv->lock, irqL);
317 if ((check_fwstate(pmlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING)) || 315 if ((check_fwstate(pmlmepriv, _FW_UNDER_SURVEY|_FW_UNDER_LINKING)) ||
@@ -345,13 +343,9 @@ u8 r8712_set_802_11_authentication_mode(struct _adapter *padapter,
345u8 r8712_set_802_11_add_wep(struct _adapter *padapter, 343u8 r8712_set_802_11_add_wep(struct _adapter *padapter,
346 struct NDIS_802_11_WEP *wep) 344 struct NDIS_802_11_WEP *wep)
347{ 345{
348 u8 bdefaultkey;
349 u8 btransmitkey;
350 sint keyid; 346 sint keyid;
351 struct security_priv *psecuritypriv = &padapter->securitypriv; 347 struct security_priv *psecuritypriv = &padapter->securitypriv;
352 348
353 bdefaultkey = (wep->KeyIndex & 0x40000000) > 0 ? false : true;
354 btransmitkey = (wep->KeyIndex & 0x80000000) > 0 ? true : false;
355 keyid = wep->KeyIndex & 0x3fffffff; 349 keyid = wep->KeyIndex & 0x3fffffff;
356 if (keyid >= WEP_KEYS) 350 if (keyid >= WEP_KEYS)
357 return false; 351 return false;
diff --git a/drivers/staging/rtl8712/rtl871x_mlme.c b/drivers/staging/rtl8712/rtl871x_mlme.c
index 00f2e0fc4ac5..b7462e8145d6 100644
--- a/drivers/staging/rtl8712/rtl871x_mlme.c
+++ b/drivers/staging/rtl8712/rtl871x_mlme.c
@@ -923,7 +923,7 @@ void r8712_joinbss_event_callback(struct _adapter *adapter, u8 *pbuf)
923ignore_joinbss_callback: 923ignore_joinbss_callback:
924 spin_unlock_irqrestore(&pmlmepriv->lock, irqL); 924 spin_unlock_irqrestore(&pmlmepriv->lock, irqL);
925 if (sizeof(struct list_head) == 4 * sizeof(u32)) 925 if (sizeof(struct list_head) == 4 * sizeof(u32))
926 kfree((u8 *)pnetwork); 926 kfree(pnetwork);
927} 927}
928 928
929void r8712_stassoc_event_callback(struct _adapter *adapter, u8 *pbuf) 929void r8712_stassoc_event_callback(struct _adapter *adapter, u8 *pbuf)
@@ -1218,7 +1218,7 @@ sint r8712_set_auth(struct _adapter *adapter,
1218 1218
1219 psetauthparm = kzalloc(sizeof(*psetauthparm), GFP_ATOMIC); 1219 psetauthparm = kzalloc(sizeof(*psetauthparm), GFP_ATOMIC);
1220 if (psetauthparm == NULL) { 1220 if (psetauthparm == NULL) {
1221 kfree((unsigned char *)pcmd); 1221 kfree(pcmd);
1222 return _FAIL; 1222 return _FAIL;
1223 } 1223 }
1224 psetauthparm->mode = (u8)psecuritypriv->AuthAlgrthm; 1224 psetauthparm->mode = (u8)psecuritypriv->AuthAlgrthm;
@@ -1372,7 +1372,7 @@ static int SecIsInPMKIDList(struct _adapter *Adapter, u8 *bssid)
1372sint r8712_restruct_sec_ie(struct _adapter *adapter, u8 *in_ie, 1372sint r8712_restruct_sec_ie(struct _adapter *adapter, u8 *in_ie,
1373 u8 *out_ie, uint in_len) 1373 u8 *out_ie, uint in_len)
1374{ 1374{
1375 u8 authmode = 0, securitytype, match; 1375 u8 authmode = 0, match;
1376 u8 sec_ie[255], uncst_oui[4], bkup_ie[255]; 1376 u8 sec_ie[255], uncst_oui[4], bkup_ie[255];
1377 u8 wpa_oui[4] = {0x0, 0x50, 0xf2, 0x01}; 1377 u8 wpa_oui[4] = {0x0, 0x50, 0xf2, 0x01};
1378 uint ielength, cnt, remove_cnt; 1378 uint ielength, cnt, remove_cnt;
@@ -1399,21 +1399,17 @@ sint r8712_restruct_sec_ie(struct _adapter *adapter, u8 *in_ie,
1399 switch (ndissecuritytype) { 1399 switch (ndissecuritytype) {
1400 case Ndis802_11Encryption1Enabled: 1400 case Ndis802_11Encryption1Enabled:
1401 case Ndis802_11Encryption1KeyAbsent: 1401 case Ndis802_11Encryption1KeyAbsent:
1402 securitytype = _WEP40_;
1403 uncst_oui[3] = 0x1; 1402 uncst_oui[3] = 0x1;
1404 break; 1403 break;
1405 case Ndis802_11Encryption2Enabled: 1404 case Ndis802_11Encryption2Enabled:
1406 case Ndis802_11Encryption2KeyAbsent: 1405 case Ndis802_11Encryption2KeyAbsent:
1407 securitytype = _TKIP_;
1408 uncst_oui[3] = 0x2; 1406 uncst_oui[3] = 0x2;
1409 break; 1407 break;
1410 case Ndis802_11Encryption3Enabled: 1408 case Ndis802_11Encryption3Enabled:
1411 case Ndis802_11Encryption3KeyAbsent: 1409 case Ndis802_11Encryption3KeyAbsent:
1412 securitytype = _AES_;
1413 uncst_oui[3] = 0x4; 1410 uncst_oui[3] = 0x4;
1414 break; 1411 break;
1415 default: 1412 default:
1416 securitytype = _NO_PRIVACY_;
1417 break; 1413 break;
1418 } 1414 }
1419 /*Search required WPA or WPA2 IE and copy to sec_ie[] */ 1415 /*Search required WPA or WPA2 IE and copy to sec_ie[] */
@@ -1705,7 +1701,7 @@ unsigned int r8712_restructure_ht_ie(struct _adapter *padapter, u8 *in_ie,
1705 u8 *out_ie, uint in_len, uint *pout_len) 1701 u8 *out_ie, uint in_len, uint *pout_len)
1706{ 1702{
1707 u32 ielen, out_len; 1703 u32 ielen, out_len;
1708 unsigned char *p, *pframe; 1704 unsigned char *p;
1709 struct ieee80211_ht_cap ht_capie; 1705 struct ieee80211_ht_cap ht_capie;
1710 unsigned char WMM_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01, 0x00}; 1706 unsigned char WMM_IE[] = {0x00, 0x50, 0xf2, 0x02, 0x00, 0x01, 0x00};
1711 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 1707 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
@@ -1717,10 +1713,8 @@ unsigned int r8712_restructure_ht_ie(struct _adapter *padapter, u8 *in_ie,
1717 if (p && (ielen > 0)) { 1713 if (p && (ielen > 0)) {
1718 if (pqospriv->qos_option == 0) { 1714 if (pqospriv->qos_option == 0) {
1719 out_len = *pout_len; 1715 out_len = *pout_len;
1720 pframe = r8712_set_ie(out_ie+out_len, 1716 r8712_set_ie(out_ie+out_len, _VENDOR_SPECIFIC_IE_,
1721 _VENDOR_SPECIFIC_IE_, 1717 _WMM_IE_Length_, WMM_IE, pout_len);
1722 _WMM_IE_Length_,
1723 WMM_IE, pout_len);
1724 pqospriv->qos_option = 1; 1718 pqospriv->qos_option = 1;
1725 } 1719 }
1726 out_len = *pout_len; 1720 out_len = *pout_len;
@@ -1733,9 +1727,9 @@ unsigned int r8712_restructure_ht_ie(struct _adapter *padapter, u8 *in_ie,
1733 IEEE80211_HT_CAP_DSSSCCK40; 1727 IEEE80211_HT_CAP_DSSSCCK40;
1734 ht_capie.ampdu_params_info = (IEEE80211_HT_CAP_AMPDU_FACTOR & 1728 ht_capie.ampdu_params_info = (IEEE80211_HT_CAP_AMPDU_FACTOR &
1735 0x03) | (IEEE80211_HT_CAP_AMPDU_DENSITY & 0x00); 1729 0x03) | (IEEE80211_HT_CAP_AMPDU_DENSITY & 0x00);
1736 pframe = r8712_set_ie(out_ie+out_len, _HT_CAPABILITY_IE_, 1730 r8712_set_ie(out_ie+out_len, _HT_CAPABILITY_IE_,
1737 sizeof(struct ieee80211_ht_cap), 1731 sizeof(struct ieee80211_ht_cap),
1738 (unsigned char *)&ht_capie, pout_len); 1732 (unsigned char *)&ht_capie, pout_len);
1739 phtpriv->ht_option = 1; 1733 phtpriv->ht_option = 1;
1740 } 1734 }
1741 return phtpriv->ht_option; 1735 return phtpriv->ht_option;
@@ -1748,7 +1742,6 @@ static void update_ht_cap(struct _adapter *padapter, u8 *pie, uint ie_len)
1748 int i, len; 1742 int i, len;
1749 struct sta_info *bmc_sta, *psta; 1743 struct sta_info *bmc_sta, *psta;
1750 struct ieee80211_ht_cap *pht_capie; 1744 struct ieee80211_ht_cap *pht_capie;
1751 struct ieee80211_ht_addt_info *pht_addtinfo;
1752 struct recv_reorder_ctrl *preorder_ctrl; 1745 struct recv_reorder_ctrl *preorder_ctrl;
1753 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 1746 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1754 struct ht_priv *phtpriv = &pmlmepriv->htpriv; 1747 struct ht_priv *phtpriv = &pmlmepriv->htpriv;
@@ -1801,8 +1794,6 @@ static void update_ht_cap(struct _adapter *padapter, u8 *pie, uint ie_len)
1801 p = r8712_get_ie(pie + sizeof(struct NDIS_802_11_FIXED_IEs), 1794 p = r8712_get_ie(pie + sizeof(struct NDIS_802_11_FIXED_IEs),
1802 _HT_ADD_INFO_IE_, &len, 1795 _HT_ADD_INFO_IE_, &len,
1803 ie_len-sizeof(struct NDIS_802_11_FIXED_IEs)); 1796 ie_len-sizeof(struct NDIS_802_11_FIXED_IEs));
1804 if (p && len > 0)
1805 pht_addtinfo = (struct ieee80211_ht_addt_info *)(p + 2);
1806} 1797}
1807 1798
1808void r8712_issue_addbareq_cmd(struct _adapter *padapter, int priority) 1799void r8712_issue_addbareq_cmd(struct _adapter *padapter, int priority)
diff --git a/drivers/staging/rtl8712/rtl871x_mp.c b/drivers/staging/rtl8712/rtl871x_mp.c
index 2ec660ad78af..3d913b9701bb 100644
--- a/drivers/staging/rtl8712/rtl871x_mp.c
+++ b/drivers/staging/rtl8712/rtl871x_mp.c
@@ -56,7 +56,7 @@ static int init_mp_priv(struct mp_priv *pmp_priv)
56 pmp_priv->pallocated_mp_xmitframe_buf = kmalloc(NR_MP_XMITFRAME * 56 pmp_priv->pallocated_mp_xmitframe_buf = kmalloc(NR_MP_XMITFRAME *
57 sizeof(struct mp_xmit_frame) + 4, 57 sizeof(struct mp_xmit_frame) + 4,
58 GFP_ATOMIC); 58 GFP_ATOMIC);
59 if (pmp_priv->pallocated_mp_xmitframe_buf == NULL) { 59 if (!pmp_priv->pallocated_mp_xmitframe_buf) {
60 res = _FAIL; 60 res = _FAIL;
61 goto _exit_init_mp_priv; 61 goto _exit_init_mp_priv;
62 } 62 }
@@ -173,7 +173,7 @@ u8 r8712_bb_reg_write(struct _adapter *pAdapter, u16 offset, u32 value)
173 oldValue = r8712_bb_reg_read(pAdapter, iocmd.value); 173 oldValue = r8712_bb_reg_read(pAdapter, iocmd.value);
174 oldValue &= (0xFFFFFFFF >> ((4 - shift) * 8)); 174 oldValue &= (0xFFFFFFFF >> ((4 - shift) * 8));
175 value = oldValue | (newValue << (shift * 8)); 175 value = oldValue | (newValue << (shift * 8));
176 if (fw_iocmd_write(pAdapter, iocmd, value) == false) 176 if (!fw_iocmd_write(pAdapter, iocmd, value))
177 return false; 177 return false;
178 iocmd.value += 4; 178 iocmd.value += 4;
179 oldValue = r8712_bb_reg_read(pAdapter, iocmd.value); 179 oldValue = r8712_bb_reg_read(pAdapter, iocmd.value);
diff --git a/drivers/staging/rtl8712/rtl871x_mp_ioctl.c b/drivers/staging/rtl8712/rtl871x_mp_ioctl.c
index 9827ff8143b2..a16f15e91992 100644
--- a/drivers/staging/rtl8712/rtl871x_mp_ioctl.c
+++ b/drivers/staging/rtl8712/rtl871x_mp_ioctl.c
@@ -1431,11 +1431,8 @@ unsigned int mp_ioctl_xmit_packet_hdl(struct oid_par_priv *poid_par_priv)
1431/*-------------------------------------------------------------------------*/ 1431/*-------------------------------------------------------------------------*/
1432uint oid_rt_set_power_down_hdl(struct oid_par_priv *poid_par_priv) 1432uint oid_rt_set_power_down_hdl(struct oid_par_priv *poid_par_priv)
1433{ 1433{
1434 u8 bpwrup;
1435
1436 if (poid_par_priv->type_of_oid != SET_OID) 1434 if (poid_par_priv->type_of_oid != SET_OID)
1437 return RNDIS_STATUS_NOT_ACCEPTED; 1435 return RNDIS_STATUS_NOT_ACCEPTED;
1438 bpwrup = *(u8 *)poid_par_priv->information_buf;
1439 /*CALL the power_down function*/ 1436 /*CALL the power_down function*/
1440 return RNDIS_STATUS_SUCCESS; 1437 return RNDIS_STATUS_SUCCESS;
1441} 1438}
diff --git a/drivers/staging/rtl8712/rtl871x_pwrctrl.c b/drivers/staging/rtl8712/rtl871x_pwrctrl.c
index 51dcf5555b62..ed2844d2b02a 100644
--- a/drivers/staging/rtl8712/rtl871x_pwrctrl.c
+++ b/drivers/staging/rtl8712/rtl871x_pwrctrl.c
@@ -156,11 +156,9 @@ static void rpwm_workitem_callback(struct work_struct *work)
156 struct pwrctrl_priv, rpwm_workitem); 156 struct pwrctrl_priv, rpwm_workitem);
157 struct _adapter *padapter = container_of(pwrpriv, 157 struct _adapter *padapter = container_of(pwrpriv,
158 struct _adapter, pwrctrlpriv); 158 struct _adapter, pwrctrlpriv);
159 u8 cpwm = pwrpriv->cpwm;
160
161 if (pwrpriv->cpwm != pwrpriv->rpwm) { 159 if (pwrpriv->cpwm != pwrpriv->rpwm) {
162 _enter_pwrlock(&pwrpriv->lock); 160 _enter_pwrlock(&pwrpriv->lock);
163 cpwm = r8712_read8(padapter, SDIO_HCPWM); 161 r8712_read8(padapter, SDIO_HCPWM);
164 pwrpriv->rpwm_retry = 1; 162 pwrpriv->rpwm_retry = 1;
165 r8712_set_rpwm(padapter, pwrpriv->rpwm); 163 r8712_set_rpwm(padapter, pwrpriv->rpwm);
166 up(&pwrpriv->lock); 164 up(&pwrpriv->lock);
diff --git a/drivers/staging/rtl8712/rtl871x_recv.c b/drivers/staging/rtl8712/rtl871x_recv.c
index 9b99a71670f3..06f15f81c4d8 100644
--- a/drivers/staging/rtl8712/rtl871x_recv.c
+++ b/drivers/staging/rtl8712/rtl871x_recv.c
@@ -601,7 +601,7 @@ sint r8712_wlanhdr_to_ethhdr(union recv_frame *precvframe)
601{ 601{
602 /*remove the wlanhdr and add the eth_hdr*/ 602 /*remove the wlanhdr and add the eth_hdr*/
603 sint rmv_len; 603 sint rmv_len;
604 u16 eth_type, len; 604 u16 len;
605 u8 bsnaphdr; 605 u8 bsnaphdr;
606 u8 *psnap_type; 606 u8 *psnap_type;
607 struct ieee80211_snap_hdr *psnap; 607 struct ieee80211_snap_hdr *psnap;
@@ -635,7 +635,6 @@ sint r8712_wlanhdr_to_ethhdr(union recv_frame *precvframe)
635 ptr += rmv_len; 635 ptr += rmv_len;
636 *ptr = 0x87; 636 *ptr = 0x87;
637 *(ptr+1) = 0x12; 637 *(ptr+1) = 0x12;
638 eth_type = 0x8712;
639 /* append rx status for mp test packets */ 638 /* append rx status for mp test packets */
640 ptr = recvframe_pull(precvframe, (rmv_len - 639 ptr = recvframe_pull(precvframe, (rmv_len -
641 sizeof(struct ethhdr) + 2) - 24); 640 sizeof(struct ethhdr) + 2) - 24);
@@ -658,27 +657,11 @@ s32 r8712_recv_entry(union recv_frame *precvframe)
658{ 657{
659 struct _adapter *padapter; 658 struct _adapter *padapter;
660 struct recv_priv *precvpriv; 659 struct recv_priv *precvpriv;
661 struct mlme_priv *pmlmepriv;
662 struct recv_stat *prxstat;
663 struct dvobj_priv *pdev;
664 u8 *phead, *pdata, *ptail, *pend;
665 660
666 struct __queue *pfree_recv_queue, *ppending_recv_queue;
667 s32 ret = _SUCCESS; 661 s32 ret = _SUCCESS;
668 struct intf_hdl *pintfhdl;
669 662
670 padapter = precvframe->u.hdr.adapter; 663 padapter = precvframe->u.hdr.adapter;
671 pintfhdl = &padapter->pio_queue->intf;
672 pmlmepriv = &padapter->mlmepriv;
673 precvpriv = &(padapter->recvpriv); 664 precvpriv = &(padapter->recvpriv);
674 pdev = &padapter->dvobjpriv;
675 pfree_recv_queue = &(precvpriv->free_recv_queue);
676 ppending_recv_queue = &(precvpriv->recv_pending_queue);
677 phead = precvframe->u.hdr.rx_head;
678 pdata = precvframe->u.hdr.rx_data;
679 ptail = precvframe->u.hdr.rx_tail;
680 pend = precvframe->u.hdr.rx_end;
681 prxstat = (struct recv_stat *)phead;
682 665
683 padapter->ledpriv.LedControlHandler(padapter, LED_CTL_RX); 666 padapter->ledpriv.LedControlHandler(padapter, LED_CTL_RX);
684 667
diff --git a/drivers/staging/rtl8712/rtl871x_recv.h b/drivers/staging/rtl8712/rtl871x_recv.h
index 92ca8997e5bc..77487bb9d3c0 100644
--- a/drivers/staging/rtl8712/rtl871x_recv.h
+++ b/drivers/staging/rtl8712/rtl871x_recv.h
@@ -170,11 +170,8 @@ static inline u8 *recvframe_put(union recv_frame *precvframe, sint sz)
170 /* used for append sz bytes from ptr to rx_tail, update rx_tail and 170 /* used for append sz bytes from ptr to rx_tail, update rx_tail and
171 * return the updated rx_tail to the caller 171 * return the updated rx_tail to the caller
172 * after putting, rx_tail must be still larger than rx_end. */ 172 * after putting, rx_tail must be still larger than rx_end. */
173 unsigned char *prev_rx_tail;
174
175 if (precvframe == NULL) 173 if (precvframe == NULL)
176 return NULL; 174 return NULL;
177 prev_rx_tail = precvframe->u.hdr.rx_tail;
178 precvframe->u.hdr.rx_tail += sz; 175 precvframe->u.hdr.rx_tail += sz;
179 if (precvframe->u.hdr.rx_tail > precvframe->u.hdr.rx_end) { 176 if (precvframe->u.hdr.rx_tail > precvframe->u.hdr.rx_end) {
180 precvframe->u.hdr.rx_tail -= sz; 177 precvframe->u.hdr.rx_tail -= sz;
diff --git a/drivers/staging/rtl8712/rtl871x_security.c b/drivers/staging/rtl8712/rtl871x_security.c
index 8faf22bb7c90..c653ad6854b4 100644
--- a/drivers/staging/rtl8712/rtl871x_security.c
+++ b/drivers/staging/rtl8712/rtl871x_security.c
@@ -578,7 +578,7 @@ u32 r8712_tkip_encrypt(struct _adapter *padapter, u8 *pxmitframe)
578 u8 ttkey[16]; 578 u8 ttkey[16];
579 u8 crc[4]; 579 u8 crc[4];
580 struct arc4context mycontext; 580 struct arc4context mycontext;
581 u32 curfragnum, length, prwskeylen; 581 u32 curfragnum, length;
582 582
583 u8 *pframe, *payload, *iv, *prwskey; 583 u8 *pframe, *payload, *iv, *prwskey;
584 union pn48 txpn; 584 union pn48 txpn;
@@ -600,7 +600,6 @@ u32 r8712_tkip_encrypt(struct _adapter *padapter, u8 *pxmitframe)
600 &pattrib->ra[0]); 600 &pattrib->ra[0]);
601 if (stainfo != NULL) { 601 if (stainfo != NULL) {
602 prwskey = &stainfo->x_UncstKey.skey[0]; 602 prwskey = &stainfo->x_UncstKey.skey[0];
603 prwskeylen = 16;
604 for (curfragnum = 0; curfragnum < pattrib->nr_frags; 603 for (curfragnum = 0; curfragnum < pattrib->nr_frags;
605 curfragnum++) { 604 curfragnum++) {
606 iv = pframe + pattrib->hdrlen; 605 iv = pframe + pattrib->hdrlen;
@@ -655,7 +654,7 @@ u32 r8712_tkip_decrypt(struct _adapter *padapter, u8 *precvframe)
655 u8 ttkey[16]; 654 u8 ttkey[16];
656 u8 crc[4]; 655 u8 crc[4];
657 struct arc4context mycontext; 656 struct arc4context mycontext;
658 u32 length, prwskeylen; 657 u32 length;
659 u8 *pframe, *payload, *iv, *prwskey, idx = 0; 658 u8 *pframe, *payload, *iv, *prwskey, idx = 0;
660 union pn48 txpn; 659 union pn48 txpn;
661 struct sta_info *stainfo; 660 struct sta_info *stainfo;
@@ -683,7 +682,6 @@ u32 r8712_tkip_decrypt(struct _adapter *padapter, u8 *precvframe)
683 return _FAIL; 682 return _FAIL;
684 } else 683 } else
685 prwskey = &stainfo->x_UncstKey.skey[0]; 684 prwskey = &stainfo->x_UncstKey.skey[0];
686 prwskeylen = 16;
687 GET_TKIP_PN(iv, txpn); 685 GET_TKIP_PN(iv, txpn);
688 pnl = (u16)(txpn.val); 686 pnl = (u16)(txpn.val);
689 pnh = (u32)(txpn.val >> 16); 687 pnh = (u32)(txpn.val >> 16);
@@ -1154,7 +1152,6 @@ u32 r8712_aes_encrypt(struct _adapter *padapter, u8 *pxmitframe)
1154{ /* exclude ICV */ 1152{ /* exclude ICV */
1155 /* Intermediate Buffers */ 1153 /* Intermediate Buffers */
1156 sint curfragnum, length; 1154 sint curfragnum, length;
1157 u32 prwskeylen;
1158 u8 *pframe, *prwskey; 1155 u8 *pframe, *prwskey;
1159 struct sta_info *stainfo; 1156 struct sta_info *stainfo;
1160 struct pkt_attrib *pattrib = &((struct xmit_frame *) 1157 struct pkt_attrib *pattrib = &((struct xmit_frame *)
@@ -1174,7 +1171,6 @@ u32 r8712_aes_encrypt(struct _adapter *padapter, u8 *pxmitframe)
1174 &pattrib->ra[0]); 1171 &pattrib->ra[0]);
1175 if (stainfo != NULL) { 1172 if (stainfo != NULL) {
1176 prwskey = &stainfo->x_UncstKey.skey[0]; 1173 prwskey = &stainfo->x_UncstKey.skey[0];
1177 prwskeylen = 16;
1178 for (curfragnum = 0; curfragnum < pattrib->nr_frags; 1174 for (curfragnum = 0; curfragnum < pattrib->nr_frags;
1179 curfragnum++) { 1175 curfragnum++) {
1180 if ((curfragnum + 1) == pattrib->nr_frags) { 1176 if ((curfragnum + 1) == pattrib->nr_frags) {
@@ -1363,7 +1359,6 @@ u32 r8712_aes_decrypt(struct _adapter *padapter, u8 *precvframe)
1363{ /* exclude ICV */ 1359{ /* exclude ICV */
1364 /* Intermediate Buffers */ 1360 /* Intermediate Buffers */
1365 sint length; 1361 sint length;
1366 u32 prwskeylen;
1367 u8 *pframe, *prwskey, *iv, idx; 1362 u8 *pframe, *prwskey, *iv, idx;
1368 struct sta_info *stainfo; 1363 struct sta_info *stainfo;
1369 struct rx_pkt_attrib *prxattrib = &((union recv_frame *) 1364 struct rx_pkt_attrib *prxattrib = &((union recv_frame *)
@@ -1387,7 +1382,6 @@ u32 r8712_aes_decrypt(struct _adapter *padapter, u8 *precvframe)
1387 1382
1388 } else 1383 } else
1389 prwskey = &stainfo->x_UncstKey.skey[0]; 1384 prwskey = &stainfo->x_UncstKey.skey[0];
1390 prwskeylen = 16;
1391 length = ((union recv_frame *)precvframe)-> 1385 length = ((union recv_frame *)precvframe)->
1392 u.hdr.len-prxattrib->hdrlen-prxattrib->iv_len; 1386 u.hdr.len-prxattrib->hdrlen-prxattrib->iv_len;
1393 aes_decipher(prwskey, prxattrib->hdrlen, pframe, 1387 aes_decipher(prwskey, prxattrib->hdrlen, pframe,
diff --git a/drivers/staging/rtl8712/rtl871x_sta_mgt.c b/drivers/staging/rtl8712/rtl871x_sta_mgt.c
index e769bb5c5fb8..4c9b98e8210e 100644
--- a/drivers/staging/rtl8712/rtl871x_sta_mgt.c
+++ b/drivers/staging/rtl8712/rtl871x_sta_mgt.c
@@ -79,13 +79,11 @@ static void mfree_all_stainfo(struct sta_priv *pstapriv)
79{ 79{
80 unsigned long irqL; 80 unsigned long irqL;
81 struct list_head *plist, *phead; 81 struct list_head *plist, *phead;
82 struct sta_info *psta = NULL;
83 82
84 spin_lock_irqsave(&pstapriv->sta_hash_lock, irqL); 83 spin_lock_irqsave(&pstapriv->sta_hash_lock, irqL);
85 phead = &pstapriv->free_sta_queue.queue; 84 phead = &pstapriv->free_sta_queue.queue;
86 plist = phead->next; 85 plist = phead->next;
87 while ((end_of_queue_search(phead, plist)) == false) { 86 while ((end_of_queue_search(phead, plist)) == false) {
88 psta = LIST_CONTAINOR(plist, struct sta_info, list);
89 plist = plist->next; 87 plist = plist->next;
90 } 88 }
91 89
@@ -109,7 +107,6 @@ u32 _r8712_free_sta_priv(struct sta_priv *pstapriv)
109 107
110struct sta_info *r8712_alloc_stainfo(struct sta_priv *pstapriv, u8 *hwaddr) 108struct sta_info *r8712_alloc_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
111{ 109{
112 uint tmp_aid;
113 s32 index; 110 s32 index;
114 struct list_head *phash_list; 111 struct list_head *phash_list;
115 struct sta_info *psta; 112 struct sta_info *psta;
@@ -127,7 +124,6 @@ struct sta_info *r8712_alloc_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
127 psta = LIST_CONTAINOR(pfree_sta_queue->queue.next, 124 psta = LIST_CONTAINOR(pfree_sta_queue->queue.next,
128 struct sta_info, list); 125 struct sta_info, list);
129 list_del_init(&(psta->list)); 126 list_del_init(&(psta->list));
130 tmp_aid = psta->aid;
131 _init_stainfo(psta); 127 _init_stainfo(psta);
132 memcpy(psta->hwaddr, hwaddr, ETH_ALEN); 128 memcpy(psta->hwaddr, hwaddr, ETH_ALEN);
133 index = wifi_mac_hash(hwaddr); 129 index = wifi_mac_hash(hwaddr);
@@ -267,15 +263,10 @@ struct sta_info *r8712_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
267 263
268void r8712_init_bcmc_stainfo(struct _adapter *padapter) 264void r8712_init_bcmc_stainfo(struct _adapter *padapter)
269{ 265{
270 struct sta_info *psta;
271 struct tx_servq *ptxservq;
272 unsigned char bcast_addr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 266 unsigned char bcast_addr[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
273 struct sta_priv *pstapriv = &padapter->stapriv; 267 struct sta_priv *pstapriv = &padapter->stapriv;
274 268
275 psta = r8712_alloc_stainfo(pstapriv, bcast_addr); 269 r8712_alloc_stainfo(pstapriv, bcast_addr);
276 if (psta == NULL)
277 return;
278 ptxservq = &(psta->sta_xmitpriv.be_q);
279} 270}
280 271
281struct sta_info *r8712_get_bcmc_stainfo(struct _adapter *padapter) 272struct sta_info *r8712_get_bcmc_stainfo(struct _adapter *padapter)
diff --git a/drivers/staging/rtl8712/rtl871x_xmit.c b/drivers/staging/rtl8712/rtl871x_xmit.c
index f49acaf04076..62a377e7fdc7 100644
--- a/drivers/staging/rtl8712/rtl871x_xmit.c
+++ b/drivers/staging/rtl8712/rtl871x_xmit.c
@@ -184,7 +184,6 @@ void _free_xmit_priv(struct xmit_priv *pxmitpriv)
184sint r8712_update_attrib(struct _adapter *padapter, _pkt *pkt, 184sint r8712_update_attrib(struct _adapter *padapter, _pkt *pkt,
185 struct pkt_attrib *pattrib) 185 struct pkt_attrib *pattrib)
186{ 186{
187 uint i;
188 struct pkt_file pktfile; 187 struct pkt_file pktfile;
189 struct sta_info *psta = NULL; 188 struct sta_info *psta = NULL;
190 struct ethhdr etherhdr; 189 struct ethhdr etherhdr;
@@ -199,7 +198,7 @@ sint r8712_update_attrib(struct _adapter *padapter, _pkt *pkt,
199 198
200 _r8712_open_pktfile(pkt, &pktfile); 199 _r8712_open_pktfile(pkt, &pktfile);
201 200
202 i = _r8712_pktfile_read(&pktfile, (unsigned char *)&etherhdr, ETH_HLEN); 201 _r8712_pktfile_read(&pktfile, (unsigned char *)&etherhdr, ETH_HLEN);
203 202
204 pattrib->ether_type = ntohs(etherhdr.h_proto); 203 pattrib->ether_type = ntohs(etherhdr.h_proto);
205 204
@@ -236,7 +235,7 @@ sint r8712_update_attrib(struct _adapter *padapter, _pkt *pkt,
236 /* for mp storing the txcmd per packet, 235 /* for mp storing the txcmd per packet,
237 * according to the info of txcmd to update pattrib */ 236 * according to the info of txcmd to update pattrib */
238 /*get MP_TXDESC_SIZE bytes txcmd per packet*/ 237 /*get MP_TXDESC_SIZE bytes txcmd per packet*/
239 i = _r8712_pktfile_read(&pktfile, (u8 *)&txdesc, TXDESC_SIZE); 238 _r8712_pktfile_read(&pktfile, (u8 *)&txdesc, TXDESC_SIZE);
240 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN); 239 memcpy(pattrib->ra, pattrib->dst, ETH_ALEN);
241 memcpy(pattrib->ta, pattrib->src, ETH_ALEN); 240 memcpy(pattrib->ta, pattrib->src, ETH_ALEN);
242 pattrib->pctrl = 1; 241 pattrib->pctrl = 1;
@@ -347,7 +346,7 @@ sint r8712_update_attrib(struct _adapter *padapter, _pkt *pkt,
347static sint xmitframe_addmic(struct _adapter *padapter, 346static sint xmitframe_addmic(struct _adapter *padapter,
348 struct xmit_frame *pxmitframe) 347 struct xmit_frame *pxmitframe)
349{ 348{
350 u32 curfragnum, length, datalen; 349 u32 curfragnum, length;
351 u8 *pframe, *payload, mic[8]; 350 u8 *pframe, *payload, mic[8];
352 struct mic_data micdata; 351 struct mic_data micdata;
353 struct sta_info *stainfo; 352 struct sta_info *stainfo;
@@ -369,7 +368,6 @@ static sint xmitframe_addmic(struct _adapter *padapter,
369 u8 null_key[16] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 368 u8 null_key[16] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
370 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 369 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
371 0x0, 0x0}; 370 0x0, 0x0};
372 datalen = pattrib->pktlen - pattrib->hdrlen;
373 pframe = pxmitframe->buf_addr + TXDESC_OFFSET; 371 pframe = pxmitframe->buf_addr + TXDESC_OFFSET;
374 if (bmcst) { 372 if (bmcst) {
375 if (!memcmp(psecuritypriv->XGrptxmickey 373 if (!memcmp(psecuritypriv->XGrptxmickey
@@ -486,7 +484,7 @@ static sint make_wlanhdr(struct _adapter *padapter , u8 *hdr,
486 memset(hdr, 0, WLANHDR_OFFSET); 484 memset(hdr, 0, WLANHDR_OFFSET);
487 SetFrameSubType(fctrl, pattrib->subtype); 485 SetFrameSubType(fctrl, pattrib->subtype);
488 if (pattrib->subtype & WIFI_DATA_TYPE) { 486 if (pattrib->subtype & WIFI_DATA_TYPE) {
489 if ((check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true)) { 487 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true) {
490 /* to_ds = 1, fr_ds = 0; */ 488 /* to_ds = 1, fr_ds = 0; */
491 SetToDs(fctrl); 489 SetToDs(fctrl);
492 memcpy(pwlanhdr->addr1, get_bssid(pmlmepriv), 490 memcpy(pwlanhdr->addr1, get_bssid(pmlmepriv),
@@ -825,16 +823,13 @@ void r8712_free_xmitframe(struct xmit_priv *pxmitpriv,
825 unsigned long irqL; 823 unsigned long irqL;
826 struct __queue *pfree_xmit_queue = &pxmitpriv->free_xmit_queue; 824 struct __queue *pfree_xmit_queue = &pxmitpriv->free_xmit_queue;
827 struct _adapter *padapter = pxmitpriv->adapter; 825 struct _adapter *padapter = pxmitpriv->adapter;
828 struct sk_buff *pndis_pkt = NULL;
829 826
830 if (pxmitframe == NULL) 827 if (pxmitframe == NULL)
831 return; 828 return;
832 spin_lock_irqsave(&pfree_xmit_queue->lock, irqL); 829 spin_lock_irqsave(&pfree_xmit_queue->lock, irqL);
833 list_del_init(&pxmitframe->list); 830 list_del_init(&pxmitframe->list);
834 if (pxmitframe->pkt) { 831 if (pxmitframe->pkt)
835 pndis_pkt = pxmitframe->pkt;
836 pxmitframe->pkt = NULL; 832 pxmitframe->pkt = NULL;
837 }
838 list_add_tail(&pxmitframe->list, &pfree_xmit_queue->queue); 833 list_add_tail(&pxmitframe->list, &pfree_xmit_queue->queue);
839 pxmitpriv->free_xmitframe_cnt++; 834 pxmitpriv->free_xmitframe_cnt++;
840 spin_unlock_irqrestore(&pfree_xmit_queue->lock, irqL); 835 spin_unlock_irqrestore(&pfree_xmit_queue->lock, irqL);
diff --git a/drivers/staging/rtl8712/usb_intf.c b/drivers/staging/rtl8712/usb_intf.c
index a3d733b145eb..7d0d1719b136 100644
--- a/drivers/staging/rtl8712/usb_intf.c
+++ b/drivers/staging/rtl8712/usb_intf.c
@@ -255,9 +255,6 @@ static struct drv_priv drvpriv = {
255static uint r8712_usb_dvobj_init(struct _adapter *padapter) 255static uint r8712_usb_dvobj_init(struct _adapter *padapter)
256{ 256{
257 uint status = _SUCCESS; 257 uint status = _SUCCESS;
258 struct usb_device_descriptor *pdev_desc;
259 struct usb_host_config *phost_conf;
260 struct usb_config_descriptor *pconf_desc;
261 struct usb_host_interface *phost_iface; 258 struct usb_host_interface *phost_iface;
262 struct usb_interface_descriptor *piface_desc; 259 struct usb_interface_descriptor *piface_desc;
263 struct dvobj_priv *pdvobjpriv = &padapter->dvobjpriv; 260 struct dvobj_priv *pdvobjpriv = &padapter->dvobjpriv;
@@ -265,9 +262,6 @@ static uint r8712_usb_dvobj_init(struct _adapter *padapter)
265 262
266 pdvobjpriv->padapter = padapter; 263 pdvobjpriv->padapter = padapter;
267 padapter->EepromAddressSize = 6; 264 padapter->EepromAddressSize = 6;
268 pdev_desc = &pusbd->descriptor;
269 phost_conf = pusbd->actconfig;
270 pconf_desc = &phost_conf->desc;
271 phost_iface = &pintf->altsetting[0]; 265 phost_iface = &pintf->altsetting[0];
272 piface_desc = &phost_iface->desc; 266 piface_desc = &phost_iface->desc;
273 pdvobjpriv->nr_endpoint = piface_desc->bNumEndpoints; 267 pdvobjpriv->nr_endpoint = piface_desc->bNumEndpoints;
@@ -292,13 +286,13 @@ static void r8712_usb_dvobj_deinit(struct _adapter *padapter)
292void rtl871x_intf_stop(struct _adapter *padapter) 286void rtl871x_intf_stop(struct _adapter *padapter)
293{ 287{
294 /*disable_hw_interrupt*/ 288 /*disable_hw_interrupt*/
295 if (padapter->bSurpriseRemoved == false) { 289 if (!padapter->bSurpriseRemoved) {
296 /*device still exists, so driver can do i/o operation 290 /*device still exists, so driver can do i/o operation
297 * TODO: */ 291 * TODO: */
298 } 292 }
299 293
300 /* cancel in irp */ 294 /* cancel in irp */
301 if (padapter->dvobjpriv.inirp_deinit != NULL) 295 if (padapter->dvobjpriv.inirp_deinit)
302 padapter->dvobjpriv.inirp_deinit(padapter); 296 padapter->dvobjpriv.inirp_deinit(padapter);
303 /* cancel out irp */ 297 /* cancel out irp */
304 r8712_usb_write_port_cancel(padapter); 298 r8712_usb_write_port_cancel(padapter);
@@ -318,7 +312,7 @@ void r871x_dev_unload(struct _adapter *padapter)
318 r8712_stop_drv_threads(padapter); 312 r8712_stop_drv_threads(padapter);
319 313
320 /*s5.*/ 314 /*s5.*/
321 if (padapter->bSurpriseRemoved == false) { 315 if (!padapter->bSurpriseRemoved) {
322 padapter->hw_init_completed = false; 316 padapter->hw_init_completed = false;
323 rtl8712_hal_deinit(padapter); 317 rtl8712_hal_deinit(padapter);
324 } 318 }
@@ -402,7 +396,7 @@ static int r871xu_drv_init(struct usb_interface *pusb_intf,
402 /* step 3. 396 /* step 3.
403 * initialize the dvobj_priv 397 * initialize the dvobj_priv
404 */ 398 */
405 if (padapter->dvobj_init == NULL) 399 if (!padapter->dvobj_init)
406 goto error; 400 goto error;
407 else { 401 else {
408 status = padapter->dvobj_init(padapter); 402 status = padapter->dvobj_init(padapter);
@@ -568,7 +562,7 @@ static int r871xu_drv_init(struct usb_interface *pusb_intf,
568 ((mac[0] == 0x00) && (mac[1] == 0x00) && 562 ((mac[0] == 0x00) && (mac[1] == 0x00) &&
569 (mac[2] == 0x00) && (mac[3] == 0x00) && 563 (mac[2] == 0x00) && (mac[3] == 0x00) &&
570 (mac[4] == 0x00) && (mac[5] == 0x00)) || 564 (mac[4] == 0x00) && (mac[5] == 0x00)) ||
571 (AutoloadFail == false)) { 565 (!AutoloadFail)) {
572 mac[0] = 0x00; 566 mac[0] = 0x00;
573 mac[1] = 0xe0; 567 mac[1] = 0xe0;
574 mac[2] = 0x4c; 568 mac[2] = 0x4c;
diff --git a/drivers/staging/rtl8712/usb_ops_linux.c b/drivers/staging/rtl8712/usb_ops_linux.c
index e89d2b07fcb9..c3a4e3f26b40 100644
--- a/drivers/staging/rtl8712/usb_ops_linux.c
+++ b/drivers/staging/rtl8712/usb_ops_linux.c
@@ -168,7 +168,6 @@ static void usb_write_mem_complete(struct urb *purb)
168void r8712_usb_write_mem(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *wmem) 168void r8712_usb_write_mem(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *wmem)
169{ 169{
170 unsigned int pipe; 170 unsigned int pipe;
171 int status;
172 struct _adapter *padapter = (struct _adapter *)pintfhdl->adapter; 171 struct _adapter *padapter = (struct _adapter *)pintfhdl->adapter;
173 struct intf_priv *pintfpriv = pintfhdl->pintfpriv; 172 struct intf_priv *pintfpriv = pintfhdl->pintfpriv;
174 struct io_queue *pio_queue = (struct io_queue *)padapter->pio_queue; 173 struct io_queue *pio_queue = (struct io_queue *)padapter->pio_queue;
@@ -186,7 +185,7 @@ void r8712_usb_write_mem(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *wmem)
186 usb_fill_bulk_urb(piorw_urb, pusbd, pipe, 185 usb_fill_bulk_urb(piorw_urb, pusbd, pipe,
187 wmem, cnt, usb_write_mem_complete, 186 wmem, cnt, usb_write_mem_complete,
188 pio_queue); 187 pio_queue);
189 status = usb_submit_urb(piorw_urb, GFP_ATOMIC); 188 usb_submit_urb(piorw_urb, GFP_ATOMIC);
190 _down_sema(&pintfpriv->io_retevt); 189 _down_sema(&pintfpriv->io_retevt);
191} 190}
192 191
@@ -267,7 +266,7 @@ u32 r8712_usb_read_port(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *rmem)
267 if (adapter->bDriverStopped || adapter->bSurpriseRemoved || 266 if (adapter->bDriverStopped || adapter->bSurpriseRemoved ||
268 adapter->pwrctrlpriv.pnp_bstop_trx) 267 adapter->pwrctrlpriv.pnp_bstop_trx)
269 return _FAIL; 268 return _FAIL;
270 if ((precvbuf->reuse == false) || (precvbuf->pskb == NULL)) { 269 if (!precvbuf->reuse == false || !precvbuf->pskb) {
271 precvbuf->pskb = skb_dequeue(&precvpriv->free_recv_skb_queue); 270 precvbuf->pskb = skb_dequeue(&precvpriv->free_recv_skb_queue);
272 if (NULL != precvbuf->pskb) 271 if (NULL != precvbuf->pskb)
273 precvbuf->reuse = true; 272 precvbuf->reuse = true;
@@ -275,10 +274,10 @@ u32 r8712_usb_read_port(struct intf_hdl *pintfhdl, u32 addr, u32 cnt, u8 *rmem)
275 if (precvbuf != NULL) { 274 if (precvbuf != NULL) {
276 r8712_init_recvbuf(adapter, precvbuf); 275 r8712_init_recvbuf(adapter, precvbuf);
277 /* re-assign for linux based on skb */ 276 /* re-assign for linux based on skb */
278 if ((precvbuf->reuse == false) || (precvbuf->pskb == NULL)) { 277 if (!precvbuf->reuse || !precvbuf->pskb) {
279 precvbuf->pskb = netdev_alloc_skb(adapter->pnetdev, 278 precvbuf->pskb = netdev_alloc_skb(adapter->pnetdev,
280 MAX_RECVBUF_SZ + RECVBUFF_ALIGN_SZ); 279 MAX_RECVBUF_SZ + RECVBUFF_ALIGN_SZ);
281 if (precvbuf->pskb == NULL) 280 if (!precvbuf->pskb)
282 return _FAIL; 281 return _FAIL;
283 tmpaddr = (addr_t)precvbuf->pskb->data; 282 tmpaddr = (addr_t)precvbuf->pskb->data;
284 alignment = tmpaddr & (RECVBUFF_ALIGN_SZ-1); 283 alignment = tmpaddr & (RECVBUFF_ALIGN_SZ-1);
diff --git a/drivers/staging/rtl8712/xmit_linux.c b/drivers/staging/rtl8712/xmit_linux.c
index 0ac9130faf6c..039b598152bc 100644
--- a/drivers/staging/rtl8712/xmit_linux.c
+++ b/drivers/staging/rtl8712/xmit_linux.c
@@ -79,7 +79,6 @@ sint r8712_endofpktfile(struct pkt_file *pfile)
79 79
80void r8712_set_qos(struct pkt_file *ppktfile, struct pkt_attrib *pattrib) 80void r8712_set_qos(struct pkt_file *ppktfile, struct pkt_attrib *pattrib)
81{ 81{
82 int i;
83 struct ethhdr etherhdr; 82 struct ethhdr etherhdr;
84 struct iphdr ip_hdr; 83 struct iphdr ip_hdr;
85 u16 UserPriority = 0; 84 u16 UserPriority = 0;
@@ -89,8 +88,7 @@ void r8712_set_qos(struct pkt_file *ppktfile, struct pkt_attrib *pattrib)
89 88
90 /* get UserPriority from IP hdr*/ 89 /* get UserPriority from IP hdr*/
91 if (pattrib->ether_type == 0x0800) { 90 if (pattrib->ether_type == 0x0800) {
92 i = _r8712_pktfile_read(ppktfile, (u8 *)&ip_hdr, 91 _r8712_pktfile_read(ppktfile, (u8 *)&ip_hdr, sizeof(ip_hdr));
93 sizeof(ip_hdr));
94 /*UserPriority = (ntohs(ip_hdr.tos) >> 5) & 0x3 ;*/ 92 /*UserPriority = (ntohs(ip_hdr.tos) >> 5) & 0x3 ;*/
95 UserPriority = ip_hdr.tos >> 5; 93 UserPriority = ip_hdr.tos >> 5;
96 } else { 94 } else {
diff --git a/drivers/staging/rtl8723au/Makefile b/drivers/staging/rtl8723au/Makefile
index a9aae2163639..3e8989018a88 100644
--- a/drivers/staging/rtl8723au/Makefile
+++ b/drivers/staging/rtl8723au/Makefile
@@ -2,7 +2,6 @@ r8723au-y := \
2 core/rtw_cmd.o \ 2 core/rtw_cmd.o \
3 core/rtw_efuse.o \ 3 core/rtw_efuse.o \
4 core/rtw_ieee80211.o \ 4 core/rtw_ieee80211.o \
5 core/rtw_led.o \
6 core/rtw_mlme.o \ 5 core/rtw_mlme.o \
7 core/rtw_mlme_ext.o \ 6 core/rtw_mlme_ext.o \
8 core/rtw_pwrctrl.o \ 7 core/rtw_pwrctrl.o \
@@ -33,8 +32,6 @@ r8723au-y := \
33 hal/rtl8723a_rf6052.o \ 32 hal/rtl8723a_rf6052.o \
34 hal/rtl8723a_rxdesc.o \ 33 hal/rtl8723a_rxdesc.o \
35 hal/rtl8723a_sreset.o \ 34 hal/rtl8723a_sreset.o \
36 hal/rtl8723a_xmit.o \
37 hal/rtl8723au_led.o \
38 hal/rtl8723au_recv.o \ 35 hal/rtl8723au_recv.o \
39 hal/rtl8723au_xmit.o \ 36 hal/rtl8723au_xmit.o \
40 hal/usb_halinit.o \ 37 hal/usb_halinit.o \
diff --git a/drivers/staging/rtl8723au/core/rtw_ap.c b/drivers/staging/rtl8723au/core/rtw_ap.c
index 6b4092f05da5..e394d12c36b0 100644
--- a/drivers/staging/rtl8723au/core/rtw_ap.c
+++ b/drivers/staging/rtl8723au/core/rtw_ap.c
@@ -231,12 +231,10 @@ void expire_timeout_chk23a(struct rtw_adapter *padapter)
231 psta->expire_to--; 231 psta->expire_to--;
232 } 232 }
233 233
234 if (psta->expire_to <= 0) 234 if (psta->expire_to <= 0) {
235 {
236 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 235 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
237 236
238 if (padapter->registrypriv.wifi_spec == 1) 237 if (padapter->registrypriv.wifi_spec == 1) {
239 {
240 psta->expire_to = pstapriv->expire_to; 238 psta->expire_to = pstapriv->expire_to;
241 continue; 239 continue;
242 } 240 }
@@ -308,15 +306,12 @@ void expire_timeout_chk23a(struct rtw_adapter *padapter)
308 ret = issue_nulldata23a(padapter, psta->hwaddr, 0, 3, 50); 306 ret = issue_nulldata23a(padapter, psta->hwaddr, 0, 3, 50);
309 307
310 psta->keep_alive_trycnt++; 308 psta->keep_alive_trycnt++;
311 if (ret == _SUCCESS) 309 if (ret == _SUCCESS) {
312 {
313 DBG_8723A("asoc check, sta(" MAC_FMT ") is alive\n", MAC_ARG(psta->hwaddr)); 310 DBG_8723A("asoc check, sta(" MAC_FMT ") is alive\n", MAC_ARG(psta->hwaddr));
314 psta->expire_to = pstapriv->expire_to; 311 psta->expire_to = pstapriv->expire_to;
315 psta->keep_alive_trycnt = 0; 312 psta->keep_alive_trycnt = 0;
316 continue; 313 continue;
317 } 314 } else if (psta->keep_alive_trycnt <= 3) {
318 else if (psta->keep_alive_trycnt <= 3)
319 {
320 DBG_8723A("ack check for asoc expire, keep_alive_trycnt =%d\n", psta->keep_alive_trycnt); 315 DBG_8723A("ack check for asoc expire, keep_alive_trycnt =%d\n", psta->keep_alive_trycnt);
321 psta->expire_to = 1; 316 psta->expire_to = 1;
322 continue; 317 continue;
@@ -363,8 +358,7 @@ void add_RATid23a(struct rtw_adapter *padapter, struct sta_info *psta, u8 rssi_l
363 return; 358 return;
364 359
365 /* b/g mode ra_bitmap */ 360 /* b/g mode ra_bitmap */
366 for (i = 0; i < sizeof(psta->bssrateset); i++) 361 for (i = 0; i < sizeof(psta->bssrateset); i++) {
367 {
368 if (psta->bssrateset[i]) 362 if (psta->bssrateset[i])
369 tx_ra_bitmap |= rtw_get_bit_value_from_ieee_value23a(psta->bssrateset[i]&0x7f); 363 tx_ra_bitmap |= rtw_get_bit_value_from_ieee_value23a(psta->bssrateset[i]&0x7f);
370 } 364 }
@@ -406,8 +400,7 @@ void add_RATid23a(struct rtw_adapter *padapter, struct sta_info *psta, u8 rssi_l
406 raid = networktype_to_raid23a(sta_band); 400 raid = networktype_to_raid23a(sta_band);
407 init_rate = get_highest_rate_idx23a(tx_ra_bitmap&0x0fffffff)&0x3f; 401 init_rate = get_highest_rate_idx23a(tx_ra_bitmap&0x0fffffff)&0x3f;
408 402
409 if (psta->aid < NUM_STA) 403 if (psta->aid < NUM_STA) {
410 {
411 u8 arg = 0; 404 u8 arg = 0;
412 405
413 arg = psta->mac_id&0x1f; 406 arg = psta->mac_id&0x1f;
@@ -436,11 +429,8 @@ void add_RATid23a(struct rtw_adapter *padapter, struct sta_info *psta, u8 rssi_l
436 psta->raid = raid; 429 psta->raid = raid;
437 psta->init_rate = init_rate; 430 psta->init_rate = init_rate;
438 431
439 } 432 } else
440 else
441 {
442 DBG_8723A("station aid %d exceed the max number\n", psta->aid); 433 DBG_8723A("station aid %d exceed the max number\n", psta->aid);
443 }
444} 434}
445 435
446static void update_bmc_sta(struct rtw_adapter *padapter) 436static void update_bmc_sta(struct rtw_adapter *padapter)
@@ -453,8 +443,7 @@ static void update_bmc_sta(struct rtw_adapter *padapter)
453 struct wlan_bssid_ex *pcur_network = &pmlmepriv->cur_network.network; 443 struct wlan_bssid_ex *pcur_network = &pmlmepriv->cur_network.network;
454 struct sta_info *psta = rtw_get_bcmc_stainfo23a(padapter); 444 struct sta_info *psta = rtw_get_bcmc_stainfo23a(padapter);
455 445
456 if (psta) 446 if (psta) {
457 {
458 psta->aid = 0;/* default set to 0 */ 447 psta->aid = 0;/* default set to 0 */
459 psta->mac_id = psta->aid + 1; 448 psta->mac_id = psta->aid + 1;
460 449
@@ -474,8 +463,7 @@ static void update_bmc_sta(struct rtw_adapter *padapter)
474 psta->bssratelen = supportRateNum; 463 psta->bssratelen = supportRateNum;
475 464
476 /* b/g mode ra_bitmap */ 465 /* b/g mode ra_bitmap */
477 for (i = 0; i < supportRateNum; i++) 466 for (i = 0; i < supportRateNum; i++) {
478 {
479 if (psta->bssrateset[i]) 467 if (psta->bssrateset[i])
480 tx_ra_bitmap |= rtw_get_bit_value_from_ieee_value23a(psta->bssrateset[i]&0x7f); 468 tx_ra_bitmap |= rtw_get_bit_value_from_ieee_value23a(psta->bssrateset[i]&0x7f);
481 } 469 }
@@ -522,11 +510,8 @@ static void update_bmc_sta(struct rtw_adapter *padapter)
522 psta->state = _FW_LINKED; 510 psta->state = _FW_LINKED;
523 spin_unlock_bh(&psta->lock); 511 spin_unlock_bh(&psta->lock);
524 512
525 } 513 } else
526 else
527 {
528 DBG_8723A("add_RATid23a_bmc_sta error!\n"); 514 DBG_8723A("add_RATid23a_bmc_sta error!\n");
529 }
530} 515}
531 516
532/* notes: */ 517/* notes: */
@@ -561,8 +546,7 @@ void update_sta_info23a_apmode23a(struct rtw_adapter *padapter, struct sta_info
561 /* ERP */ 546 /* ERP */
562 VCS_update23a(padapter, psta); 547 VCS_update23a(padapter, psta);
563 /* HT related cap */ 548 /* HT related cap */
564 if (phtpriv_sta->ht_option) 549 if (phtpriv_sta->ht_option) {
565 {
566 /* check if sta supports rx ampdu */ 550 /* check if sta supports rx ampdu */
567 phtpriv_sta->ampdu_enable = phtpriv_ap->ampdu_enable; 551 phtpriv_sta->ampdu_enable = phtpriv_ap->ampdu_enable;
568 552
@@ -580,9 +564,7 @@ void update_sta_info23a_apmode23a(struct rtw_adapter *padapter, struct sta_info
580 564
581 psta->qos_option = true; 565 psta->qos_option = true;
582 566
583 } 567 } else {
584 else
585 {
586 phtpriv_sta->ampdu_enable = false; 568 phtpriv_sta->ampdu_enable = false;
587 569
588 phtpriv_sta->sgi = false; 570 phtpriv_sta->sgi = false;
@@ -654,7 +636,7 @@ static void start_bss_network(struct rtw_adapter *padapter, u8 *pbuf)
654 636
655 bcn_interval = (u16)pnetwork->beacon_interval; 637 bcn_interval = (u16)pnetwork->beacon_interval;
656 cur_channel = pnetwork->DSConfig; 638 cur_channel = pnetwork->DSConfig;
657 cur_bwmode = HT_CHANNEL_WIDTH_20;; 639 cur_bwmode = HT_CHANNEL_WIDTH_20;
658 cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE; 640 cur_ch_offset = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
659 641
660 /* check if there is wps ie, */ 642 /* check if there is wps ie, */
@@ -1122,7 +1104,6 @@ int rtw_acl_remove_sta23a(struct rtw_adapter *padapter, u8 *addr)
1122 struct sta_priv *pstapriv = &padapter->stapriv; 1104 struct sta_priv *pstapriv = &padapter->stapriv;
1123 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list; 1105 struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;
1124 struct rtw_queue *pacl_node_q = &pacl_list->acl_node_q; 1106 struct rtw_queue *pacl_node_q = &pacl_list->acl_node_q;
1125 int ret = 0;
1126 1107
1127 DBG_8723A("%s(acl_num =%d) = %pM\n", __func__, pacl_list->num, addr); 1108 DBG_8723A("%s(acl_num =%d) = %pM\n", __func__, pacl_list->num, addr);
1128 1109
@@ -1148,7 +1129,7 @@ int rtw_acl_remove_sta23a(struct rtw_adapter *padapter, u8 *addr)
1148 1129
1149 DBG_8723A("%s, acl_num =%d\n", __func__, pacl_list->num); 1130 DBG_8723A("%s, acl_num =%d\n", __func__, pacl_list->num);
1150 1131
1151 return ret; 1132 return 0;
1152} 1133}
1153 1134
1154static void update_bcn_fixed_ie(struct rtw_adapter *padapter) 1135static void update_bcn_fixed_ie(struct rtw_adapter *padapter)
@@ -1217,8 +1198,6 @@ static void update_bcn_wmm_ie(struct rtw_adapter *padapter)
1217static void update_bcn_wps_ie(struct rtw_adapter *padapter) 1198static void update_bcn_wps_ie(struct rtw_adapter *padapter)
1218{ 1199{
1219 DBG_8723A("%s\n", __func__); 1200 DBG_8723A("%s\n", __func__);
1220
1221 return;
1222} 1201}
1223 1202
1224static void update_bcn_p2p_ie(struct rtw_adapter *padapter) 1203static void update_bcn_p2p_ie(struct rtw_adapter *padapter)
@@ -1261,8 +1240,7 @@ void update_beacon23a(struct rtw_adapter *padapter, u8 ie_id, u8 *oui, u8 tx)
1261 1240
1262 spin_lock_bh(&pmlmepriv->bcn_update_lock); 1241 spin_lock_bh(&pmlmepriv->bcn_update_lock);
1263 1242
1264 switch (ie_id) 1243 switch (ie_id) {
1265 {
1266 case 0xFF: 1244 case 0xFF:
1267 /* 8: TimeStamp, 2: Beacon Interval 2:Capability */ 1245 /* 8: TimeStamp, 2: Beacon Interval 2:Capability */
1268 update_bcn_fixed_ie(padapter); 1246 update_bcn_fixed_ie(padapter);
@@ -1389,8 +1367,7 @@ static int rtw_ht_operation_update(struct rtw_adapter *padapter)
1389void associated_clients_update23a(struct rtw_adapter *padapter, u8 updated) 1367void associated_clients_update23a(struct rtw_adapter *padapter, u8 updated)
1390{ 1368{
1391 /* update associated stations cap. */ 1369 /* update associated stations cap. */
1392 if (updated == true) 1370 if (updated == true) {
1393 {
1394 struct list_head *phead, *plist, *ptmp; 1371 struct list_head *phead, *plist, *ptmp;
1395 struct sta_info *psta; 1372 struct sta_info *psta;
1396 struct sta_priv *pstapriv = &padapter->stapriv; 1373 struct sta_priv *pstapriv = &padapter->stapriv;
@@ -1416,34 +1393,27 @@ void bss_cap_update_on_sta_join23a(struct rtw_adapter *padapter, struct sta_info
1416 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 1393 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1417 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 1394 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1418 1395
1419 if (!(psta->flags & WLAN_STA_SHORT_PREAMBLE)) 1396 if (!(psta->flags & WLAN_STA_SHORT_PREAMBLE)) {
1420 { 1397 if (!psta->no_short_preamble_set) {
1421 if (!psta->no_short_preamble_set)
1422 {
1423 psta->no_short_preamble_set = 1; 1398 psta->no_short_preamble_set = 1;
1424 1399
1425 pmlmepriv->num_sta_no_short_preamble++; 1400 pmlmepriv->num_sta_no_short_preamble++;
1426 1401
1427 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) && 1402 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
1428 (pmlmepriv->num_sta_no_short_preamble == 1)) 1403 (pmlmepriv->num_sta_no_short_preamble == 1)) {
1429 {
1430 beacon_updated = true; 1404 beacon_updated = true;
1431 update_beacon23a(padapter, 0xFF, NULL, true); 1405 update_beacon23a(padapter, 0xFF, NULL, true);
1432 } 1406 }
1433 1407
1434 } 1408 }
1435 } 1409 } else {
1436 else 1410 if (psta->no_short_preamble_set) {
1437 {
1438 if (psta->no_short_preamble_set)
1439 {
1440 psta->no_short_preamble_set = 0; 1411 psta->no_short_preamble_set = 0;
1441 1412
1442 pmlmepriv->num_sta_no_short_preamble--; 1413 pmlmepriv->num_sta_no_short_preamble--;
1443 1414
1444 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) && 1415 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
1445 (pmlmepriv->num_sta_no_short_preamble == 0)) 1416 (pmlmepriv->num_sta_no_short_preamble == 0)) {
1446 {
1447 beacon_updated = true; 1417 beacon_updated = true;
1448 update_beacon23a(padapter, 0xFF, NULL, true); 1418 update_beacon23a(padapter, 0xFF, NULL, true);
1449 } 1419 }
@@ -1451,32 +1421,25 @@ void bss_cap_update_on_sta_join23a(struct rtw_adapter *padapter, struct sta_info
1451 } 1421 }
1452 } 1422 }
1453 1423
1454 if (psta->flags & WLAN_STA_NONERP) 1424 if (psta->flags & WLAN_STA_NONERP) {
1455 { 1425 if (!psta->nonerp_set) {
1456 if (!psta->nonerp_set)
1457 {
1458 psta->nonerp_set = 1; 1426 psta->nonerp_set = 1;
1459 1427
1460 pmlmepriv->num_sta_non_erp++; 1428 pmlmepriv->num_sta_non_erp++;
1461 1429
1462 if (pmlmepriv->num_sta_non_erp == 1) 1430 if (pmlmepriv->num_sta_non_erp == 1) {
1463 {
1464 beacon_updated = true; 1431 beacon_updated = true;
1465 update_beacon23a(padapter, WLAN_EID_ERP_INFO, NULL, true); 1432 update_beacon23a(padapter, WLAN_EID_ERP_INFO, NULL, true);
1466 } 1433 }
1467 } 1434 }
1468 1435
1469 } 1436 } else {
1470 else 1437 if (psta->nonerp_set) {
1471 {
1472 if (psta->nonerp_set)
1473 {
1474 psta->nonerp_set = 0; 1438 psta->nonerp_set = 0;
1475 1439
1476 pmlmepriv->num_sta_non_erp--; 1440 pmlmepriv->num_sta_non_erp--;
1477 1441
1478 if (pmlmepriv->num_sta_non_erp == 0) 1442 if (pmlmepriv->num_sta_non_erp == 0) {
1479 {
1480 beacon_updated = true; 1443 beacon_updated = true;
1481 update_beacon23a(padapter, WLAN_EID_ERP_INFO, NULL, true); 1444 update_beacon23a(padapter, WLAN_EID_ERP_INFO, NULL, true);
1482 } 1445 }
@@ -1484,42 +1447,34 @@ void bss_cap_update_on_sta_join23a(struct rtw_adapter *padapter, struct sta_info
1484 1447
1485 } 1448 }
1486 1449
1487 if (!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)) 1450 if (!(psta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)) {
1488 { 1451 if (!psta->no_short_slot_time_set) {
1489 if (!psta->no_short_slot_time_set)
1490 {
1491 psta->no_short_slot_time_set = 1; 1452 psta->no_short_slot_time_set = 1;
1492 1453
1493 pmlmepriv->num_sta_no_short_slot_time++; 1454 pmlmepriv->num_sta_no_short_slot_time++;
1494 1455
1495 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) && 1456 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
1496 (pmlmepriv->num_sta_no_short_slot_time == 1)) 1457 (pmlmepriv->num_sta_no_short_slot_time == 1)) {
1497 {
1498 beacon_updated = true; 1458 beacon_updated = true;
1499 update_beacon23a(padapter, 0xFF, NULL, true); 1459 update_beacon23a(padapter, 0xFF, NULL, true);
1500 } 1460 }
1501 1461
1502 } 1462 }
1503 } 1463 } else {
1504 else 1464 if (psta->no_short_slot_time_set) {
1505 {
1506 if (psta->no_short_slot_time_set)
1507 {
1508 psta->no_short_slot_time_set = 0; 1465 psta->no_short_slot_time_set = 0;
1509 1466
1510 pmlmepriv->num_sta_no_short_slot_time--; 1467 pmlmepriv->num_sta_no_short_slot_time--;
1511 1468
1512 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) && 1469 if ((pmlmeext->cur_wireless_mode > WIRELESS_11B) &&
1513 (pmlmepriv->num_sta_no_short_slot_time == 0)) 1470 (pmlmepriv->num_sta_no_short_slot_time == 0)) {
1514 {
1515 beacon_updated = true; 1471 beacon_updated = true;
1516 update_beacon23a(padapter, 0xFF, NULL, true); 1472 update_beacon23a(padapter, 0xFF, NULL, true);
1517 } 1473 }
1518 } 1474 }
1519 } 1475 }
1520 1476
1521 if (psta->flags & WLAN_STA_HT) 1477 if (psta->flags & WLAN_STA_HT) {
1522 {
1523 u16 ht_capab = le16_to_cpu(psta->htpriv.ht_cap.cap_info); 1478 u16 ht_capab = le16_to_cpu(psta->htpriv.ht_cap.cap_info);
1524 1479
1525 DBG_8723A("HT: STA " MAC_FMT " HT Capabilities " 1480 DBG_8723A("HT: STA " MAC_FMT " HT Capabilities "
@@ -1552,9 +1507,7 @@ void bss_cap_update_on_sta_join23a(struct rtw_adapter *padapter, struct sta_info
1552 pmlmepriv->num_sta_ht_20mhz); 1507 pmlmepriv->num_sta_ht_20mhz);
1553 } 1508 }
1554 1509
1555 } 1510 } else {
1556 else
1557 {
1558 if (!psta->no_ht_set) { 1511 if (!psta->no_ht_set) {
1559 psta->no_ht_set = 1; 1512 psta->no_ht_set = 1;
1560 pmlmepriv->num_sta_no_ht++; 1513 pmlmepriv->num_sta_no_ht++;
@@ -1567,8 +1520,7 @@ void bss_cap_update_on_sta_join23a(struct rtw_adapter *padapter, struct sta_info
1567 } 1520 }
1568 } 1521 }
1569 1522
1570 if (rtw_ht_operation_update(padapter) > 0) 1523 if (rtw_ht_operation_update(padapter) > 0) {
1571 {
1572 update_beacon23a(padapter, WLAN_EID_HT_CAPABILITY, NULL, false); 1524 update_beacon23a(padapter, WLAN_EID_HT_CAPABILITY, NULL, false);
1573 update_beacon23a(padapter, WLAN_EID_HT_OPERATION, NULL, true); 1525 update_beacon23a(padapter, WLAN_EID_HT_OPERATION, NULL, true);
1574 } 1526 }
@@ -1592,8 +1544,7 @@ u8 bss_cap_update_on_sta_leave23a(struct rtw_adapter *padapter, struct sta_info
1592 psta->no_short_preamble_set = 0; 1544 psta->no_short_preamble_set = 0;
1593 pmlmepriv->num_sta_no_short_preamble--; 1545 pmlmepriv->num_sta_no_short_preamble--;
1594 if (pmlmeext->cur_wireless_mode > WIRELESS_11B 1546 if (pmlmeext->cur_wireless_mode > WIRELESS_11B
1595 && pmlmepriv->num_sta_no_short_preamble == 0) 1547 && pmlmepriv->num_sta_no_short_preamble == 0) {
1596 {
1597 beacon_updated = true; 1548 beacon_updated = true;
1598 update_beacon23a(padapter, 0xFF, NULL, true); 1549 update_beacon23a(padapter, 0xFF, NULL, true);
1599 } 1550 }
@@ -1602,8 +1553,7 @@ u8 bss_cap_update_on_sta_leave23a(struct rtw_adapter *padapter, struct sta_info
1602 if (psta->nonerp_set) { 1553 if (psta->nonerp_set) {
1603 psta->nonerp_set = 0; 1554 psta->nonerp_set = 0;
1604 pmlmepriv->num_sta_non_erp--; 1555 pmlmepriv->num_sta_non_erp--;
1605 if (pmlmepriv->num_sta_non_erp == 0) 1556 if (pmlmepriv->num_sta_non_erp == 0) {
1606 {
1607 beacon_updated = true; 1557 beacon_updated = true;
1608 update_beacon23a(padapter, WLAN_EID_ERP_INFO, 1558 update_beacon23a(padapter, WLAN_EID_ERP_INFO,
1609 NULL, true); 1559 NULL, true);
@@ -1614,8 +1564,7 @@ u8 bss_cap_update_on_sta_leave23a(struct rtw_adapter *padapter, struct sta_info
1614 psta->no_short_slot_time_set = 0; 1564 psta->no_short_slot_time_set = 0;
1615 pmlmepriv->num_sta_no_short_slot_time--; 1565 pmlmepriv->num_sta_no_short_slot_time--;
1616 if (pmlmeext->cur_wireless_mode > WIRELESS_11B 1566 if (pmlmeext->cur_wireless_mode > WIRELESS_11B
1617 && pmlmepriv->num_sta_no_short_slot_time == 0) 1567 && pmlmepriv->num_sta_no_short_slot_time == 0) {
1618 {
1619 beacon_updated = true; 1568 beacon_updated = true;
1620 update_beacon23a(padapter, 0xFF, NULL, true); 1569 update_beacon23a(padapter, 0xFF, NULL, true);
1621 } 1570 }
@@ -1636,8 +1585,7 @@ u8 bss_cap_update_on_sta_leave23a(struct rtw_adapter *padapter, struct sta_info
1636 pmlmepriv->num_sta_ht_20mhz--; 1585 pmlmepriv->num_sta_ht_20mhz--;
1637 } 1586 }
1638 1587
1639 if (rtw_ht_operation_update(padapter) > 0) 1588 if (rtw_ht_operation_update(padapter) > 0) {
1640 {
1641 update_beacon23a(padapter, WLAN_EID_HT_CAPABILITY, NULL, false); 1589 update_beacon23a(padapter, WLAN_EID_HT_CAPABILITY, NULL, false);
1642 update_beacon23a(padapter, WLAN_EID_HT_OPERATION, NULL, true); 1590 update_beacon23a(padapter, WLAN_EID_HT_OPERATION, NULL, true);
1643 } 1591 }
@@ -1657,8 +1605,7 @@ u8 ap_free_sta23a(struct rtw_adapter *padapter, struct sta_info *psta, bool acti
1657 if (!psta) 1605 if (!psta)
1658 return beacon_updated; 1606 return beacon_updated;
1659 1607
1660 if (active == true) 1608 if (active) {
1661 {
1662 /* tear down Rx AMPDU */ 1609 /* tear down Rx AMPDU */
1663 send_delba23a(padapter, 0, psta->hwaddr);/* recipient */ 1610 send_delba23a(padapter, 0, psta->hwaddr);/* recipient */
1664 1611
@@ -1698,7 +1645,6 @@ u8 ap_free_sta23a(struct rtw_adapter *padapter, struct sta_info *psta, bool acti
1698int rtw_ap_inform_ch_switch23a (struct rtw_adapter *padapter, u8 new_ch, u8 ch_offset) 1645int rtw_ap_inform_ch_switch23a (struct rtw_adapter *padapter, u8 new_ch, u8 ch_offset)
1699{ 1646{
1700 struct list_head *phead, *plist; 1647 struct list_head *phead, *plist;
1701 int ret = 0;
1702 struct sta_info *psta = NULL; 1648 struct sta_info *psta = NULL;
1703 struct sta_priv *pstapriv = &padapter->stapriv; 1649 struct sta_priv *pstapriv = &padapter->stapriv;
1704 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 1650 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
@@ -1706,7 +1652,7 @@ int rtw_ap_inform_ch_switch23a (struct rtw_adapter *padapter, u8 new_ch, u8 ch_o
1706 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 1652 u8 bc_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1707 1653
1708 if ((pmlmeinfo->state&0x03) != MSR_AP) 1654 if ((pmlmeinfo->state&0x03) != MSR_AP)
1709 return ret; 1655 return 0;
1710 1656
1711 DBG_8723A("%s(%s): with ch:%u, offset:%u\n", __func__, 1657 DBG_8723A("%s(%s): with ch:%u, offset:%u\n", __func__,
1712 padapter->pnetdev->name, new_ch, ch_offset); 1658 padapter->pnetdev->name, new_ch, ch_offset);
@@ -1724,13 +1670,12 @@ int rtw_ap_inform_ch_switch23a (struct rtw_adapter *padapter, u8 new_ch, u8 ch_o
1724 1670
1725 issue_action_spct_ch_switch23a (padapter, bc_addr, new_ch, ch_offset); 1671 issue_action_spct_ch_switch23a (padapter, bc_addr, new_ch, ch_offset);
1726 1672
1727 return ret; 1673 return 0;
1728} 1674}
1729 1675
1730int rtw_sta_flush23a(struct rtw_adapter *padapter) 1676int rtw_sta_flush23a(struct rtw_adapter *padapter)
1731{ 1677{
1732 struct list_head *phead, *plist, *ptmp; 1678 struct list_head *phead, *plist, *ptmp;
1733 int ret = 0;
1734 struct sta_info *psta; 1679 struct sta_info *psta;
1735 struct sta_priv *pstapriv = &padapter->stapriv; 1680 struct sta_priv *pstapriv = &padapter->stapriv;
1736 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 1681 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
@@ -1743,7 +1688,7 @@ int rtw_sta_flush23a(struct rtw_adapter *padapter)
1743 DBG_8723A("%s(%s)\n", __func__, padapter->pnetdev->name); 1688 DBG_8723A("%s(%s)\n", __func__, padapter->pnetdev->name);
1744 1689
1745 if ((pmlmeinfo->state&0x03) != MSR_AP) 1690 if ((pmlmeinfo->state&0x03) != MSR_AP)
1746 return ret; 1691 return 0;
1747 1692
1748 spin_lock_bh(&pstapriv->asoc_list_lock); 1693 spin_lock_bh(&pstapriv->asoc_list_lock);
1749 phead = &pstapriv->asoc_list; 1694 phead = &pstapriv->asoc_list;
@@ -1769,7 +1714,7 @@ int rtw_sta_flush23a(struct rtw_adapter *padapter)
1769 1714
1770 associated_clients_update23a(padapter, true); 1715 associated_clients_update23a(padapter, true);
1771 1716
1772 return ret; 1717 return 0;
1773} 1718}
1774 1719
1775/* called > TSR LEVEL for USB or SDIO Interface*/ 1720/* called > TSR LEVEL for USB or SDIO Interface*/
@@ -1788,13 +1733,10 @@ void sta_info_update23a(struct rtw_adapter *padapter, struct sta_info *psta)
1788 psta->qos_option = 0; 1733 psta->qos_option = 0;
1789 1734
1790 /* update 802.11n ht cap. */ 1735 /* update 802.11n ht cap. */
1791 if (WLAN_STA_HT&flags) 1736 if (WLAN_STA_HT&flags) {
1792 {
1793 psta->htpriv.ht_option = true; 1737 psta->htpriv.ht_option = true;
1794 psta->qos_option = 1; 1738 psta->qos_option = 1;
1795 } 1739 } else {
1796 else
1797 {
1798 psta->htpriv.ht_option = false; 1740 psta->htpriv.ht_option = false;
1799 } 1741 }
1800 1742
@@ -1807,8 +1749,7 @@ void sta_info_update23a(struct rtw_adapter *padapter, struct sta_info *psta)
1807/* called >= TSR LEVEL for USB or SDIO Interface*/ 1749/* called >= TSR LEVEL for USB or SDIO Interface*/
1808void ap_sta_info_defer_update23a(struct rtw_adapter *padapter, struct sta_info *psta) 1750void ap_sta_info_defer_update23a(struct rtw_adapter *padapter, struct sta_info *psta)
1809{ 1751{
1810 if (psta->state & _FW_LINKED) 1752 if (psta->state & _FW_LINKED) {
1811 {
1812 /* add ratid */ 1753 /* add ratid */
1813 add_RATid23a(padapter, psta, 0);/* DM_RATR_STA_INIT */ 1754 add_RATid23a(padapter, psta, 0);/* DM_RATR_STA_INIT */
1814 } 1755 }
@@ -1819,7 +1760,7 @@ void rtw_ap_restore_network(struct rtw_adapter *padapter)
1819{ 1760{
1820 struct mlme_priv *mlmepriv = &padapter->mlmepriv; 1761 struct mlme_priv *mlmepriv = &padapter->mlmepriv;
1821 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 1762 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1822 struct sta_priv * pstapriv = &padapter->stapriv; 1763 struct sta_priv *pstapriv = &padapter->stapriv;
1823 struct sta_info *psta; 1764 struct sta_info *psta;
1824 struct security_priv *psecuritypriv = &padapter->securitypriv; 1765 struct security_priv *psecuritypriv = &padapter->securitypriv;
1825 struct list_head *phead, *plist, *ptmp; 1766 struct list_head *phead, *plist, *ptmp;
diff --git a/drivers/staging/rtl8723au/core/rtw_cmd.c b/drivers/staging/rtl8723au/core/rtw_cmd.c
index 4eaa50297b95..60e0ded8ae02 100644
--- a/drivers/staging/rtl8723au/core/rtw_cmd.c
+++ b/drivers/staging/rtl8723au/core/rtw_cmd.c
@@ -36,25 +36,25 @@ static struct cmd_hdl wlancmds[] = {
36 GEN_MLME_EXT_HANDLER(0, NULL) 36 GEN_MLME_EXT_HANDLER(0, NULL)
37 GEN_MLME_EXT_HANDLER(0, NULL) 37 GEN_MLME_EXT_HANDLER(0, NULL)
38 GEN_MLME_EXT_HANDLER(0, NULL) 38 GEN_MLME_EXT_HANDLER(0, NULL)
39 GEN_MLME_EXT_HANDLER(sizeof (struct wlan_bssid_ex), join_cmd_hdl23a) /*14*/ 39 GEN_MLME_EXT_HANDLER(sizeof(struct wlan_bssid_ex), join_cmd_hdl23a) /*14*/
40 GEN_MLME_EXT_HANDLER(sizeof (struct disconnect_parm), disconnect_hdl23a) 40 GEN_MLME_EXT_HANDLER(sizeof(struct disconnect_parm), disconnect_hdl23a)
41 GEN_MLME_EXT_HANDLER(sizeof (struct wlan_bssid_ex), createbss_hdl23a) 41 GEN_MLME_EXT_HANDLER(sizeof(struct wlan_bssid_ex), createbss_hdl23a)
42 GEN_MLME_EXT_HANDLER(sizeof (struct setopmode_parm), setopmode_hdl23a) 42 GEN_MLME_EXT_HANDLER(sizeof(struct setopmode_parm), setopmode_hdl23a)
43 GEN_MLME_EXT_HANDLER(sizeof (struct sitesurvey_parm), sitesurvey_cmd_hdl23a) /*18*/ 43 GEN_MLME_EXT_HANDLER(sizeof(struct sitesurvey_parm), sitesurvey_cmd_hdl23a) /*18*/
44 GEN_MLME_EXT_HANDLER(sizeof (struct setauth_parm), setauth_hdl23a) 44 GEN_MLME_EXT_HANDLER(sizeof(struct setauth_parm), setauth_hdl23a)
45 GEN_MLME_EXT_HANDLER(sizeof (struct setkey_parm), setkey_hdl23a) /*20*/ 45 GEN_MLME_EXT_HANDLER(sizeof(struct setkey_parm), setkey_hdl23a) /*20*/
46 GEN_MLME_EXT_HANDLER(sizeof (struct set_stakey_parm), set_stakey_hdl23a) 46 GEN_MLME_EXT_HANDLER(sizeof(struct set_stakey_parm), set_stakey_hdl23a)
47 GEN_MLME_EXT_HANDLER(sizeof (struct set_assocsta_parm), NULL) 47 GEN_MLME_EXT_HANDLER(sizeof(struct set_assocsta_parm), NULL)
48 GEN_MLME_EXT_HANDLER(sizeof (struct del_assocsta_parm), NULL) 48 GEN_MLME_EXT_HANDLER(sizeof(struct del_assocsta_parm), NULL)
49 GEN_MLME_EXT_HANDLER(sizeof (struct setstapwrstate_parm), NULL) 49 GEN_MLME_EXT_HANDLER(sizeof(struct setstapwrstate_parm), NULL)
50 GEN_MLME_EXT_HANDLER(sizeof (struct setbasicrate_parm), NULL) 50 GEN_MLME_EXT_HANDLER(sizeof(struct setbasicrate_parm), NULL)
51 GEN_MLME_EXT_HANDLER(sizeof (struct getbasicrate_parm), NULL) 51 GEN_MLME_EXT_HANDLER(sizeof(struct getbasicrate_parm), NULL)
52 GEN_MLME_EXT_HANDLER(sizeof (struct setdatarate_parm), NULL) 52 GEN_MLME_EXT_HANDLER(sizeof(struct setdatarate_parm), NULL)
53 GEN_MLME_EXT_HANDLER(sizeof (struct getdatarate_parm), NULL) 53 GEN_MLME_EXT_HANDLER(sizeof(struct getdatarate_parm), NULL)
54 GEN_MLME_EXT_HANDLER(sizeof (struct setphyinfo_parm), NULL) 54 GEN_MLME_EXT_HANDLER(sizeof(struct setphyinfo_parm), NULL)
55 GEN_MLME_EXT_HANDLER(sizeof (struct getphyinfo_parm), NULL) /*30*/ 55 GEN_MLME_EXT_HANDLER(sizeof(struct getphyinfo_parm), NULL) /*30*/
56 GEN_MLME_EXT_HANDLER(sizeof (struct setphy_parm), NULL) 56 GEN_MLME_EXT_HANDLER(sizeof(struct setphy_parm), NULL)
57 GEN_MLME_EXT_HANDLER(sizeof (struct getphy_parm), NULL) 57 GEN_MLME_EXT_HANDLER(sizeof(struct getphy_parm), NULL)
58 GEN_MLME_EXT_HANDLER(0, NULL) 58 GEN_MLME_EXT_HANDLER(0, NULL)
59 GEN_MLME_EXT_HANDLER(0, NULL) 59 GEN_MLME_EXT_HANDLER(0, NULL)
60 GEN_MLME_EXT_HANDLER(0, NULL) 60 GEN_MLME_EXT_HANDLER(0, NULL)
@@ -359,6 +359,7 @@ int rtw_sitesurvey_cmd23a(struct rtw_adapter *padapter,
359 /* prepare ssid list */ 359 /* prepare ssid list */
360 if (ssid) { 360 if (ssid) {
361 int i; 361 int i;
362
362 for (i = 0; i < ssid_num && i < RTW_SSID_SCAN_AMOUNT; i++) { 363 for (i = 0; i < ssid_num && i < RTW_SSID_SCAN_AMOUNT; i++) {
363 if (ssid[i].ssid_len) { 364 if (ssid[i].ssid_len) {
364 memcpy(&psurveyPara->ssid[i], &ssid[i], 365 memcpy(&psurveyPara->ssid[i], &ssid[i],
@@ -371,6 +372,7 @@ int rtw_sitesurvey_cmd23a(struct rtw_adapter *padapter,
371 /* prepare channel list */ 372 /* prepare channel list */
372 if (ch) { 373 if (ch) {
373 int i; 374 int i;
375
374 for (i = 0; i < ch_num && i < RTW_CHANNEL_SCAN_AMOUNT; i++) { 376 for (i = 0; i < ch_num && i < RTW_CHANNEL_SCAN_AMOUNT; i++) {
375 if (ch[i].hw_value && 377 if (ch[i].hw_value &&
376 !(ch[i].flags & IEEE80211_CHAN_DISABLED)) { 378 !(ch[i].flags & IEEE80211_CHAN_DISABLED)) {
@@ -389,8 +391,6 @@ int rtw_sitesurvey_cmd23a(struct rtw_adapter *padapter,
389 mod_timer(&pmlmepriv->scan_to_timer, jiffies + 391 mod_timer(&pmlmepriv->scan_to_timer, jiffies +
390 msecs_to_jiffies(SCANNING_TIMEOUT)); 392 msecs_to_jiffies(SCANNING_TIMEOUT));
391 393
392 rtw_led_control(padapter, LED_CTL_SITE_SURVEY);
393
394 pmlmepriv->scan_interval = SCAN_INTERVAL;/* 30*2 sec = 60sec */ 394 pmlmepriv->scan_interval = SCAN_INTERVAL;/* 30*2 sec = 60sec */
395 } else 395 } else
396 _clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY); 396 _clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY);
@@ -415,8 +415,6 @@ int rtw_createbss_cmd23a(struct rtw_adapter *padapter)
415 415
416 pdev_network = &padapter->registrypriv.dev_network; 416 pdev_network = &padapter->registrypriv.dev_network;
417 417
418 rtw_led_control(padapter, LED_CTL_START_TO_LINK);
419
420 if (pmlmepriv->assoc_ssid.ssid_len == 0) { 418 if (pmlmepriv->assoc_ssid.ssid_len == 0) {
421 RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_, 419 RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_,
422 (" createbss for Any SSid:%s\n", 420 (" createbss for Any SSid:%s\n",
@@ -465,8 +463,6 @@ int rtw_joinbss_cmd23a(struct rtw_adapter *padapter,
465 463
466 ifmode = pnetwork->network.ifmode; 464 ifmode = pnetwork->network.ifmode;
467 465
468 rtw_led_control(padapter, LED_CTL_START_TO_LINK);
469
470 if (pmlmepriv->assoc_ssid.ssid_len == 0) { 466 if (pmlmepriv->assoc_ssid.ssid_len == 0) {
471 RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_, 467 RT_TRACE(_module_rtl871x_cmd_c_, _drv_info_,
472 ("+Join cmd: Any SSid\n")); 468 ("+Join cmd: Any SSid\n"));
@@ -599,7 +595,7 @@ exit:
599 return res; 595 return res;
600} 596}
601 597
602int rtw_disassoc_cmd23a(struct rtw_adapter*padapter, u32 deauth_timeout_ms, 598int rtw_disassoc_cmd23a(struct rtw_adapter *padapter, u32 deauth_timeout_ms,
603 bool enqueue) 599 bool enqueue)
604{ 600{
605 struct cmd_obj *cmdobj = NULL; 601 struct cmd_obj *cmdobj = NULL;
@@ -719,6 +715,7 @@ int rtw_setstakey_cmd23a(struct rtw_adapter *padapter, u8 *psta, u8 unicast_key)
719 memcpy(&psetstakey_para->key, &sta->dot118021x_UncstKey, 16); 715 memcpy(&psetstakey_para->key, &sta->dot118021x_UncstKey, 16);
720 } else { 716 } else {
721 int idx = psecuritypriv->dot118021XGrpKeyid; 717 int idx = psecuritypriv->dot118021XGrpKeyid;
718
722 memcpy(&psetstakey_para->key, 719 memcpy(&psetstakey_para->key,
723 &psecuritypriv->dot118021XGrpKey[idx].skey, 16); 720 &psecuritypriv->dot118021XGrpKey[idx].skey, 16);
724 } 721 }
@@ -786,7 +783,7 @@ exit:
786 return res; 783 return res;
787} 784}
788 785
789int rtw_addbareq_cmd23a(struct rtw_adapter*padapter, u8 tid, u8 *addr) 786int rtw_addbareq_cmd23a(struct rtw_adapter *padapter, u8 tid, u8 *addr)
790{ 787{
791 struct cmd_priv *pcmdpriv = &padapter->cmdpriv; 788 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
792 struct cmd_obj *ph2c; 789 struct cmd_obj *ph2c;
@@ -822,7 +819,7 @@ exit:
822 return res; 819 return res;
823} 820}
824 821
825int rtw_dynamic_chk_wk_cmd23a(struct rtw_adapter*padapter) 822int rtw_dynamic_chk_wk_cmd23a(struct rtw_adapter *padapter)
826{ 823{
827 struct cmd_obj *ph2c; 824 struct cmd_obj *ph2c;
828 struct drvextra_cmd_parm *pdrvextra_cmd_parm; 825 struct drvextra_cmd_parm *pdrvextra_cmd_parm;
@@ -859,7 +856,7 @@ exit:
859 * This is only ever called from on_action_spct23a_ch_switch () which isn't 856 * This is only ever called from on_action_spct23a_ch_switch () which isn't
860 * called from anywhere itself 857 * called from anywhere itself
861 */ 858 */
862int rtw_set_ch_cmd23a(struct rtw_adapter*padapter, u8 ch, u8 bw, u8 ch_offset, 859int rtw_set_ch_cmd23a(struct rtw_adapter *padapter, u8 ch, u8 bw, u8 ch_offset,
863 u8 enqueue) 860 u8 enqueue)
864{ 861{
865 struct cmd_obj *pcmdobj; 862 struct cmd_obj *pcmdobj;
@@ -919,34 +916,34 @@ static void traffic_status_watchdog(struct rtw_adapter *padapter)
919 u8 bHigherBusyTxTraffic = false; 916 u8 bHigherBusyTxTraffic = false;
920 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 917 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
921 int BusyThreshold = 100; 918 int BusyThreshold = 100;
919 struct rt_link_detect *ldi = &pmlmepriv->LinkDetectInfo;
920
922 /* */ 921 /* */
923 /* Determine if our traffic is busy now */ 922 /* Determine if our traffic is busy now */
924 /* */ 923 /* */
925 if (check_fwstate(pmlmepriv, _FW_LINKED)) { 924 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
926 if (rtl8723a_BT_coexist(padapter)) 925 if (rtl8723a_BT_coexist(padapter))
927 BusyThreshold = 50; 926 BusyThreshold = 50;
928 else if (pmlmepriv->LinkDetectInfo.bBusyTraffic) 927 else if (ldi->bBusyTraffic)
929 BusyThreshold = 75; 928 BusyThreshold = 75;
930 /* if we raise bBusyTraffic in last watchdog, using 929 /* if we raise bBusyTraffic in last watchdog, using
931 lower threshold. */ 930 lower threshold. */
932 if (pmlmepriv->LinkDetectInfo.NumRxOkInPeriod > BusyThreshold || 931 if (ldi->NumRxOkInPeriod > BusyThreshold ||
933 pmlmepriv->LinkDetectInfo.NumTxOkInPeriod > BusyThreshold) { 932 ldi->NumTxOkInPeriod > BusyThreshold) {
934 bBusyTraffic = true; 933 bBusyTraffic = true;
935 934
936 if (pmlmepriv->LinkDetectInfo.NumRxOkInPeriod > 935 if (ldi->NumRxOkInPeriod > ldi->NumTxOkInPeriod)
937 pmlmepriv->LinkDetectInfo.NumTxOkInPeriod)
938 bRxBusyTraffic = true; 936 bRxBusyTraffic = true;
939 else 937 else
940 bTxBusyTraffic = true; 938 bTxBusyTraffic = true;
941 } 939 }
942 940
943 /* Higher Tx/Rx data. */ 941 /* Higher Tx/Rx data. */
944 if (pmlmepriv->LinkDetectInfo.NumRxOkInPeriod > 4000 || 942 if (ldi->NumRxOkInPeriod > 4000 ||
945 pmlmepriv->LinkDetectInfo.NumTxOkInPeriod > 4000) { 943 ldi->NumTxOkInPeriod > 4000) {
946 bHigherBusyTraffic = true; 944 bHigherBusyTraffic = true;
947 945
948 if (pmlmepriv->LinkDetectInfo.NumRxOkInPeriod > 946 if (ldi->NumRxOkInPeriod > ldi->NumTxOkInPeriod)
949 pmlmepriv->LinkDetectInfo.NumTxOkInPeriod)
950 bHigherBusyRxTraffic = true; 947 bHigherBusyRxTraffic = true;
951 else 948 else
952 bHigherBusyTxTraffic = true; 949 bHigherBusyTxTraffic = true;
@@ -955,9 +952,9 @@ static void traffic_status_watchdog(struct rtw_adapter *padapter)
955 if (!rtl8723a_BT_coexist(padapter) || 952 if (!rtl8723a_BT_coexist(padapter) ||
956 !rtl8723a_BT_using_antenna_1(padapter)) { 953 !rtl8723a_BT_using_antenna_1(padapter)) {
957 /* check traffic for powersaving. */ 954 /* check traffic for powersaving. */
958 if (((pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod + 955 if (((ldi->NumRxUnicastOkInPeriod +
959 pmlmepriv->LinkDetectInfo.NumTxOkInPeriod) > 8) || 956 ldi->NumTxOkInPeriod) > 8) ||
960 pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod >2) 957 ldi->NumRxUnicastOkInPeriod > 2)
961 bEnterPS = false; 958 bEnterPS = false;
962 else 959 else
963 bEnterPS = true; 960 bEnterPS = true;
@@ -971,15 +968,15 @@ static void traffic_status_watchdog(struct rtw_adapter *padapter)
971 } else 968 } else
972 LPS_Leave23a(padapter); 969 LPS_Leave23a(padapter);
973 970
974 pmlmepriv->LinkDetectInfo.NumRxOkInPeriod = 0; 971 ldi->NumRxOkInPeriod = 0;
975 pmlmepriv->LinkDetectInfo.NumTxOkInPeriod = 0; 972 ldi->NumTxOkInPeriod = 0;
976 pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod = 0; 973 ldi->NumRxUnicastOkInPeriod = 0;
977 pmlmepriv->LinkDetectInfo.bBusyTraffic = bBusyTraffic; 974 ldi->bBusyTraffic = bBusyTraffic;
978 pmlmepriv->LinkDetectInfo.bTxBusyTraffic = bTxBusyTraffic; 975 ldi->bTxBusyTraffic = bTxBusyTraffic;
979 pmlmepriv->LinkDetectInfo.bRxBusyTraffic = bRxBusyTraffic; 976 ldi->bRxBusyTraffic = bRxBusyTraffic;
980 pmlmepriv->LinkDetectInfo.bHigherBusyTraffic = bHigherBusyTraffic; 977 ldi->bHigherBusyTraffic = bHigherBusyTraffic;
981 pmlmepriv->LinkDetectInfo.bHigherBusyRxTraffic = bHigherBusyRxTraffic; 978 ldi->bHigherBusyRxTraffic = bHigherBusyRxTraffic;
982 pmlmepriv->LinkDetectInfo.bHigherBusyTxTraffic = bHigherBusyTxTraffic; 979 ldi->bHigherBusyTxTraffic = bHigherBusyTxTraffic;
983} 980}
984 981
985static void dynamic_chk_wk_hdl(struct rtw_adapter *padapter, u8 *pbuf, int sz) 982static void dynamic_chk_wk_hdl(struct rtw_adapter *padapter, u8 *pbuf, int sz)
@@ -1017,46 +1014,45 @@ static void lps_ctrl_wk_hdl(struct rtw_adapter *padapter, u8 lps_ctrl_type)
1017 check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) 1014 check_fwstate(pmlmepriv, WIFI_ADHOC_STATE))
1018 return; 1015 return;
1019 1016
1020 switch (lps_ctrl_type) 1017 switch (lps_ctrl_type) {
1021 { 1018 case LPS_CTRL_SCAN:
1022 case LPS_CTRL_SCAN: 1019 rtl8723a_BT_wifiscan_notify(padapter, true);
1023 rtl8723a_BT_wifiscan_notify(padapter, true); 1020 if (!rtl8723a_BT_using_antenna_1(padapter)) {
1024 if (!rtl8723a_BT_using_antenna_1(padapter)) { 1021 if (check_fwstate(pmlmepriv, _FW_LINKED))
1025 if (check_fwstate(pmlmepriv, _FW_LINKED)) 1022 LPS_Leave23a(padapter);
1026 LPS_Leave23a(padapter);
1027 } 1023 }
1028 break; 1024 break;
1029 case LPS_CTRL_JOINBSS: 1025 case LPS_CTRL_JOINBSS:
1026 LPS_Leave23a(padapter);
1027 break;
1028 case LPS_CTRL_CONNECT:
1029 mstatus = 1;/* connect */
1030 /* Reset LPS Setting */
1031 padapter->pwrctrlpriv.LpsIdleCount = 0;
1032 rtl8723a_set_FwJoinBssReport_cmd(padapter, 1);
1033 rtl8723a_BT_mediastatus_notify(padapter, mstatus);
1034 break;
1035 case LPS_CTRL_DISCONNECT:
1036 mstatus = 0;/* disconnect */
1037 rtl8723a_BT_mediastatus_notify(padapter, mstatus);
1038 if (!rtl8723a_BT_using_antenna_1(padapter))
1030 LPS_Leave23a(padapter); 1039 LPS_Leave23a(padapter);
1031 break; 1040 rtl8723a_set_FwJoinBssReport_cmd(padapter, 0);
1032 case LPS_CTRL_CONNECT: 1041 break;
1033 mstatus = 1;/* connect */ 1042 case LPS_CTRL_SPECIAL_PACKET:
1034 /* Reset LPS Setting */ 1043 pwrpriv->DelayLPSLastTimeStamp = jiffies;
1035 padapter->pwrctrlpriv.LpsIdleCount = 0; 1044 rtl8723a_BT_specialpacket_notify(padapter);
1036 rtl8723a_set_FwJoinBssReport_cmd(padapter, 1); 1045 if (!rtl8723a_BT_using_antenna_1(padapter))
1037 rtl8723a_BT_mediastatus_notify(padapter, mstatus); 1046 LPS_Leave23a(padapter);
1038 break; 1047 break;
1039 case LPS_CTRL_DISCONNECT: 1048 case LPS_CTRL_LEAVE:
1040 mstatus = 0;/* disconnect */ 1049 rtl8723a_BT_lps_leave(padapter);
1041 rtl8723a_BT_mediastatus_notify(padapter, mstatus); 1050 if (!rtl8723a_BT_using_antenna_1(padapter))
1042 if (!rtl8723a_BT_using_antenna_1(padapter)) 1051 LPS_Leave23a(padapter);
1043 LPS_Leave23a(padapter); 1052 break;
1044 rtl8723a_set_FwJoinBssReport_cmd(padapter, 0);
1045 break;
1046 case LPS_CTRL_SPECIAL_PACKET:
1047 pwrpriv->DelayLPSLastTimeStamp = jiffies;
1048 rtl8723a_BT_specialpacket_notify(padapter);
1049 if (!rtl8723a_BT_using_antenna_1(padapter))
1050 LPS_Leave23a(padapter);
1051 break;
1052 case LPS_CTRL_LEAVE:
1053 rtl8723a_BT_lps_leave(padapter);
1054 if (!rtl8723a_BT_using_antenna_1(padapter))
1055 LPS_Leave23a(padapter);
1056 break;
1057 1053
1058 default: 1054 default:
1059 break; 1055 break;
1060 } 1056 }
1061} 1057}
1062 1058
@@ -1098,7 +1094,7 @@ exit:
1098 return res; 1094 return res;
1099} 1095}
1100 1096
1101int rtw_ps_cmd23a(struct rtw_adapter*padapter) 1097int rtw_ps_cmd23a(struct rtw_adapter *padapter)
1102{ 1098{
1103 struct cmd_obj *ppscmd; 1099 struct cmd_obj *ppscmd;
1104 struct drvextra_cmd_parm *pdrvextra_cmd_parm; 1100 struct drvextra_cmd_parm *pdrvextra_cmd_parm;
@@ -1147,12 +1143,12 @@ static void rtw_chk_hi_queue_hdl(struct rtw_adapter *padapter)
1147 1143
1148 val = rtl8723a_chk_hi_queue_empty(padapter); 1144 val = rtl8723a_chk_hi_queue_empty(padapter);
1149 1145
1150 while (val == false) { 1146 while (!val) {
1151 msleep(100); 1147 msleep(100);
1152 1148
1153 cnt++; 1149 cnt++;
1154 1150
1155 if (cnt>10) 1151 if (cnt > 10)
1156 break; 1152 break;
1157 1153
1158 val = rtl8723a_chk_hi_queue_empty(padapter); 1154 val = rtl8723a_chk_hi_queue_empty(padapter);
@@ -1168,7 +1164,7 @@ static void rtw_chk_hi_queue_hdl(struct rtw_adapter *padapter)
1168 } 1164 }
1169} 1165}
1170 1166
1171int rtw_chk_hi_queue_cmd23a(struct rtw_adapter*padapter) 1167int rtw_chk_hi_queue_cmd23a(struct rtw_adapter *padapter)
1172{ 1168{
1173 struct cmd_obj *ph2c; 1169 struct cmd_obj *ph2c;
1174 struct drvextra_cmd_parm *pdrvextra_cmd_parm; 1170 struct drvextra_cmd_parm *pdrvextra_cmd_parm;
@@ -1305,8 +1301,7 @@ int rtw_drvextra_cmd_hdl23a(struct rtw_adapter *padapter, const u8 *pbuf)
1305 1301
1306 pdrvextra_cmd = (struct drvextra_cmd_parm *)pbuf; 1302 pdrvextra_cmd = (struct drvextra_cmd_parm *)pbuf;
1307 1303
1308 switch (pdrvextra_cmd->ec_id) 1304 switch (pdrvextra_cmd->ec_id) {
1309 {
1310 case DYNAMIC_CHK_WK_CID: 1305 case DYNAMIC_CHK_WK_CID:
1311 dynamic_chk_wk_hdl(padapter, pdrvextra_cmd->pbuf, 1306 dynamic_chk_wk_hdl(padapter, pdrvextra_cmd->pbuf,
1312 pdrvextra_cmd->type_size); 1307 pdrvextra_cmd->type_size);
diff --git a/drivers/staging/rtl8723au/core/rtw_efuse.c b/drivers/staging/rtl8723au/core/rtw_efuse.c
index 9f6ce7d071cd..81960e788f89 100644
--- a/drivers/staging/rtl8723au/core/rtw_efuse.c
+++ b/drivers/staging/rtl8723au/core/rtw_efuse.c
@@ -117,12 +117,7 @@ Efuse_GetCurrentSize23a(struct rtw_adapter *pAdapter, u8 efuseType)
117u8 117u8
118Efuse_CalculateWordCnts23a(u8 word_en) 118Efuse_CalculateWordCnts23a(u8 word_en)
119{ 119{
120 u8 word_cnts = 0; 120 return hweight8((~word_en) & 0xf);
121 if (!(word_en & BIT(0))) word_cnts++; /* 0 : write enable */
122 if (!(word_en & BIT(1))) word_cnts++;
123 if (!(word_en & BIT(2))) word_cnts++;
124 if (!(word_en & BIT(3))) word_cnts++;
125 return word_cnts;
126} 121}
127 122
128/* */ 123/* */
@@ -181,7 +176,7 @@ EFUSE_GetEfuseDefinition23a(struct rtw_adapter *pAdapter, u8 efuseType,
181 176
182 switch (type) { 177 switch (type) {
183 case TYPE_EFUSE_MAX_SECTION: 178 case TYPE_EFUSE_MAX_SECTION:
184 pMax_section = (u8 *) pOut; 179 pMax_section = pOut;
185 180
186 if (efuseType == EFUSE_WIFI) 181 if (efuseType == EFUSE_WIFI)
187 *pMax_section = EFUSE_MAX_SECTION_8723A; 182 *pMax_section = EFUSE_MAX_SECTION_8723A;
@@ -190,7 +185,7 @@ EFUSE_GetEfuseDefinition23a(struct rtw_adapter *pAdapter, u8 efuseType,
190 break; 185 break;
191 186
192 case TYPE_EFUSE_REAL_CONTENT_LEN: 187 case TYPE_EFUSE_REAL_CONTENT_LEN:
193 pu2Tmp = (u16 *) pOut; 188 pu2Tmp = pOut;
194 189
195 if (efuseType == EFUSE_WIFI) 190 if (efuseType == EFUSE_WIFI)
196 *pu2Tmp = EFUSE_REAL_CONTENT_LEN_8723A; 191 *pu2Tmp = EFUSE_REAL_CONTENT_LEN_8723A;
@@ -199,7 +194,7 @@ EFUSE_GetEfuseDefinition23a(struct rtw_adapter *pAdapter, u8 efuseType,
199 break; 194 break;
200 195
201 case TYPE_AVAILABLE_EFUSE_BYTES_BANK: 196 case TYPE_AVAILABLE_EFUSE_BYTES_BANK:
202 pu2Tmp = (u16 *) pOut; 197 pu2Tmp = pOut;
203 198
204 if (efuseType == EFUSE_WIFI) 199 if (efuseType == EFUSE_WIFI)
205 *pu2Tmp = (EFUSE_REAL_CONTENT_LEN_8723A - 200 *pu2Tmp = (EFUSE_REAL_CONTENT_LEN_8723A -
@@ -210,7 +205,7 @@ EFUSE_GetEfuseDefinition23a(struct rtw_adapter *pAdapter, u8 efuseType,
210 break; 205 break;
211 206
212 case TYPE_AVAILABLE_EFUSE_BYTES_TOTAL: 207 case TYPE_AVAILABLE_EFUSE_BYTES_TOTAL:
213 pu2Tmp = (u16 *) pOut; 208 pu2Tmp = pOut;
214 209
215 if (efuseType == EFUSE_WIFI) 210 if (efuseType == EFUSE_WIFI)
216 *pu2Tmp = (EFUSE_REAL_CONTENT_LEN_8723A - 211 *pu2Tmp = (EFUSE_REAL_CONTENT_LEN_8723A -
@@ -221,7 +216,7 @@ EFUSE_GetEfuseDefinition23a(struct rtw_adapter *pAdapter, u8 efuseType,
221 break; 216 break;
222 217
223 case TYPE_EFUSE_MAP_LEN: 218 case TYPE_EFUSE_MAP_LEN:
224 pu2Tmp = (u16 *) pOut; 219 pu2Tmp = pOut;
225 220
226 if (efuseType == EFUSE_WIFI) 221 if (efuseType == EFUSE_WIFI)
227 *pu2Tmp = EFUSE_MAP_LEN_8723A; 222 *pu2Tmp = EFUSE_MAP_LEN_8723A;
@@ -230,7 +225,7 @@ EFUSE_GetEfuseDefinition23a(struct rtw_adapter *pAdapter, u8 efuseType,
230 break; 225 break;
231 226
232 case TYPE_EFUSE_PROTECT_BYTES_BANK: 227 case TYPE_EFUSE_PROTECT_BYTES_BANK:
233 pu1Tmp = (u8 *) pOut; 228 pu1Tmp = pOut;
234 229
235 if (efuseType == EFUSE_WIFI) 230 if (efuseType == EFUSE_WIFI)
236 *pu1Tmp = EFUSE_OOB_PROTECT_BYTES; 231 *pu1Tmp = EFUSE_OOB_PROTECT_BYTES;
@@ -239,7 +234,7 @@ EFUSE_GetEfuseDefinition23a(struct rtw_adapter *pAdapter, u8 efuseType,
239 break; 234 break;
240 235
241 case TYPE_EFUSE_CONTENT_LEN_BANK: 236 case TYPE_EFUSE_CONTENT_LEN_BANK:
242 pu2Tmp = (u16 *) pOut; 237 pu2Tmp = pOut;
243 238
244 if (efuseType == EFUSE_WIFI) 239 if (efuseType == EFUSE_WIFI)
245 *pu2Tmp = EFUSE_REAL_CONTENT_LEN_8723A; 240 *pu2Tmp = EFUSE_REAL_CONTENT_LEN_8723A;
@@ -248,7 +243,7 @@ EFUSE_GetEfuseDefinition23a(struct rtw_adapter *pAdapter, u8 efuseType,
248 break; 243 break;
249 244
250 default: 245 default:
251 pu1Tmp = (u8 *) pOut; 246 pu1Tmp = pOut;
252 *pu1Tmp = 0; 247 *pu1Tmp = 0;
253 break; 248 break;
254 } 249 }
diff --git a/drivers/staging/rtl8723au/core/rtw_ieee80211.c b/drivers/staging/rtl8723au/core/rtw_ieee80211.c
index 6274cb397c92..bbbcfc8257da 100644
--- a/drivers/staging/rtl8723au/core/rtw_ieee80211.c
+++ b/drivers/staging/rtl8723au/core/rtw_ieee80211.c
@@ -69,6 +69,7 @@ int rtw_get_bit_value_from_ieee_value23a(u8 val)
69 {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108, 0}; 69 {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108, 0};
70 70
71 int i = 0; 71 int i = 0;
72
72 while (dot11_rate_table[i] != 0) { 73 while (dot11_rate_table[i] != 0) {
73 if (dot11_rate_table[i] == val) 74 if (dot11_rate_table[i] == val)
74 return BIT(i); 75 return BIT(i);
@@ -301,8 +302,7 @@ void rtw_set_supported_rate23a(u8 *SupportedRates, uint mode)
301 302
302 memset(SupportedRates, 0, NDIS_802_11_LENGTH_RATES_EX); 303 memset(SupportedRates, 0, NDIS_802_11_LENGTH_RATES_EX);
303 304
304 switch (mode) 305 switch (mode) {
305 {
306 case WIRELESS_11B: 306 case WIRELESS_11B:
307 memcpy(SupportedRates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN); 307 memcpy(SupportedRates, WIFI_CCKRATES, IEEE80211_CCK_RATE_LEN);
308 break; 308 break;
diff --git a/drivers/staging/rtl8723au/core/rtw_led.c b/drivers/staging/rtl8723au/core/rtw_led.c
deleted file mode 100644
index 989cda29a57e..000000000000
--- a/drivers/staging/rtl8723au/core/rtw_led.c
+++ /dev/null
@@ -1,1893 +0,0 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 ******************************************************************************/
15
16#include <drv_types.h>
17#include <rtl8723a_led.h>
18
19/* */
20/* Description: */
21/* Callback function of LED BlinkTimer, */
22/* it just schedules to corresponding BlinkWorkItem/led_blink_hdl23a */
23/* */
24static void BlinkTimerCallback(unsigned long data)
25{
26 struct led_8723a *pLed = (struct led_8723a *)data;
27 struct rtw_adapter *padapter = pLed->padapter;
28
29 /* DBG_8723A("%s\n", __func__); */
30
31 if ((padapter->bSurpriseRemoved == true) || (padapter->bDriverStopped == true))
32 {
33 /* DBG_8723A("%s bSurpriseRemoved:%d, bDriverStopped:%d\n", __func__, padapter->bSurpriseRemoved, padapter->bDriverStopped); */
34 return;
35 }
36 schedule_work(&pLed->BlinkWorkItem);
37}
38
39/* */
40/* Description: */
41/* Callback function of LED BlinkWorkItem. */
42/* We dispatch acture LED blink action according to LedStrategy. */
43/* */
44void BlinkWorkItemCallback23a(struct work_struct *work)
45{
46 struct led_8723a *pLed = container_of(work, struct led_8723a, BlinkWorkItem);
47 BlinkHandler23a(pLed);
48}
49
50/* */
51/* Description: */
52/* Reset status of led_8723a object. */
53/* */
54void ResetLedStatus23a(struct led_8723a * pLed) {
55
56 pLed->CurrLedState = RTW_LED_OFF; /* Current LED state. */
57 pLed->bLedOn = false; /* true if LED is ON, false if LED is OFF. */
58
59 pLed->bLedBlinkInProgress = false; /* true if it is blinking, false o.w.. */
60 pLed->bLedWPSBlinkInProgress = false;
61
62 pLed->BlinkTimes = 0; /* Number of times to toggle led state for blinking. */
63 pLed->BlinkingLedState = LED_UNKNOWN; /* Next state for blinking, either RTW_LED_ON or RTW_LED_OFF are. */
64
65 pLed->bLedNoLinkBlinkInProgress = false;
66 pLed->bLedLinkBlinkInProgress = false;
67 pLed->bLedStartToLinkBlinkInProgress = false;
68 pLed->bLedScanBlinkInProgress = false;
69}
70
71 /* */
72/* Description: */
73/* Initialize an led_8723a object. */
74/* */
75void
76InitLed871x23a(struct rtw_adapter *padapter, struct led_8723a *pLed, enum led_pin_8723a LedPin)
77{
78 pLed->padapter = padapter;
79 pLed->LedPin = LedPin;
80
81 ResetLedStatus23a(pLed);
82
83 setup_timer(&pLed->BlinkTimer, BlinkTimerCallback, (unsigned long)pLed);
84
85 INIT_WORK(&pLed->BlinkWorkItem, BlinkWorkItemCallback23a);
86}
87
88/* */
89/* Description: */
90/* DeInitialize an led_8723a object. */
91/* */
92void
93DeInitLed871x23a(struct led_8723a *pLed)
94{
95 cancel_work_sync(&pLed->BlinkWorkItem);
96 del_timer_sync(&pLed->BlinkTimer);
97 ResetLedStatus23a(pLed);
98}
99
100/* Description: */
101/* Implementation of LED blinking behavior. */
102/* It toggle off LED and schedule corresponding timer if necessary. */
103
104static void SwLedBlink(struct led_8723a *pLed)
105{
106 struct rtw_adapter *padapter = pLed->padapter;
107 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
108 u8 bStopBlinking = false;
109
110 /* Change LED according to BlinkingLedState specified. */
111 if (pLed->BlinkingLedState == RTW_LED_ON) {
112 SwLedOn23a(padapter, pLed);
113 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn on\n", pLed->BlinkTimes));
114 } else {
115 SwLedOff23a(padapter, pLed);
116 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn off\n", pLed->BlinkTimes));
117 }
118
119 /* Determine if we shall change LED state again. */
120 pLed->BlinkTimes--;
121 switch (pLed->CurrLedState) {
122
123 case LED_BLINK_NORMAL:
124 if (pLed->BlinkTimes == 0)
125 bStopBlinking = true;
126 break;
127 case LED_BLINK_StartToBlink:
128 if (check_fwstate(pmlmepriv, _FW_LINKED) &&
129 check_fwstate(pmlmepriv, WIFI_STATION_STATE))
130 bStopBlinking = true;
131 if (check_fwstate(pmlmepriv, _FW_LINKED) &&
132 (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE) ||
133 check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE)))
134 bStopBlinking = true;
135 else if (pLed->BlinkTimes == 0)
136 bStopBlinking = true;
137 break;
138 case LED_BLINK_WPS:
139 if (pLed->BlinkTimes == 0)
140 bStopBlinking = true;
141 break;
142 default:
143 bStopBlinking = true;
144 break;
145 }
146
147 if (bStopBlinking) {
148 if ((check_fwstate(pmlmepriv, _FW_LINKED)) && !pLed->bLedOn)
149 SwLedOn23a(padapter, pLed);
150 else if ((check_fwstate(pmlmepriv, _FW_LINKED)) && pLed->bLedOn)
151 SwLedOff23a(padapter, pLed);
152
153 pLed->BlinkTimes = 0;
154 pLed->bLedBlinkInProgress = false;
155 } else {
156 /* Assign LED state to toggle. */
157 if (pLed->BlinkingLedState == RTW_LED_ON)
158 pLed->BlinkingLedState = RTW_LED_OFF;
159 else
160 pLed->BlinkingLedState = RTW_LED_ON;
161
162 /* Schedule a timer to toggle LED state. */
163 switch (pLed->CurrLedState) {
164 case LED_BLINK_NORMAL:
165 mod_timer(&pLed->BlinkTimer, jiffies +
166 msecs_to_jiffies(LED_BLINK_NORMAL_INTERVAL));
167 break;
168 case LED_BLINK_SLOWLY:
169 case LED_BLINK_StartToBlink:
170 mod_timer(&pLed->BlinkTimer, jiffies +
171 msecs_to_jiffies(LED_BLINK_SLOWLY_INTERVAL));
172 break;
173 case LED_BLINK_WPS:
174 mod_timer(&pLed->BlinkTimer, jiffies +
175 msecs_to_jiffies(LED_BLINK_LONG_INTERVAL));
176 break;
177 default:
178 mod_timer(&pLed->BlinkTimer, jiffies +
179 msecs_to_jiffies(LED_BLINK_SLOWLY_INTERVAL));
180 break;
181 }
182 }
183}
184
185static void SwLedBlink1(struct led_8723a *pLed)
186{
187 struct rtw_adapter *padapter = pLed->padapter;
188 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
189 unsigned long delay = 0;
190 u8 bStopBlinking = false;
191
192 /* Change LED according to BlinkingLedState specified. */
193 if (pLed->BlinkingLedState == RTW_LED_ON) {
194 SwLedOn23a(padapter, pLed);
195 RT_TRACE(_module_rtl8712_led_c_, _drv_info_,
196 ("Blinktimes (%d): turn on\n", pLed->BlinkTimes));
197 } else {
198 SwLedOff23a(padapter, pLed);
199 RT_TRACE(_module_rtl8712_led_c_, _drv_info_,
200 ("Blinktimes (%d): turn off\n", pLed->BlinkTimes));
201 }
202
203 if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
204 SwLedOff23a(padapter, pLed);
205 ResetLedStatus23a(pLed);
206 return;
207 }
208 switch (pLed->CurrLedState) {
209 case LED_BLINK_SLOWLY:
210 if (pLed->bLedOn)
211 pLed->BlinkingLedState = RTW_LED_OFF;
212 else
213 pLed->BlinkingLedState = RTW_LED_ON;
214 delay = LED_BLINK_NO_LINK_INTERVAL_ALPHA;
215 break;
216 case LED_BLINK_NORMAL:
217 if (pLed->bLedOn)
218 pLed->BlinkingLedState = RTW_LED_OFF;
219 else
220 pLed->BlinkingLedState = RTW_LED_ON;
221 delay = LED_BLINK_LINK_INTERVAL_ALPHA;
222 break;
223 case LED_BLINK_SCAN:
224 pLed->BlinkTimes--;
225 if (pLed->BlinkTimes == 0)
226 bStopBlinking = true;
227 if (bStopBlinking) {
228 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
229 pLed->bLedLinkBlinkInProgress = true;
230 pLed->CurrLedState = LED_BLINK_NORMAL;
231 if (pLed->bLedOn)
232 pLed->BlinkingLedState = RTW_LED_OFF;
233 else
234 pLed->BlinkingLedState = RTW_LED_ON;
235 delay = LED_BLINK_LINK_INTERVAL_ALPHA;
236 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
237 } else {
238 pLed->bLedNoLinkBlinkInProgress = true;
239 pLed->CurrLedState = LED_BLINK_SLOWLY;
240 if (pLed->bLedOn)
241 pLed->BlinkingLedState = RTW_LED_OFF;
242 else
243 pLed->BlinkingLedState = RTW_LED_ON;
244 delay = LED_BLINK_NO_LINK_INTERVAL_ALPHA;
245 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
246 }
247 pLed->bLedScanBlinkInProgress = false;
248 } else {
249 if (pLed->bLedOn)
250 pLed->BlinkingLedState = RTW_LED_OFF;
251 else
252 pLed->BlinkingLedState = RTW_LED_ON;
253 delay = LED_BLINK_SCAN_INTERVAL_ALPHA;
254 }
255 break;
256 case LED_BLINK_TXRX:
257 pLed->BlinkTimes--;
258 if (pLed->BlinkTimes == 0)
259 bStopBlinking = true;
260 if (bStopBlinking) {
261 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
262 pLed->bLedLinkBlinkInProgress = true;
263 pLed->CurrLedState = LED_BLINK_NORMAL;
264 if (pLed->bLedOn)
265 pLed->BlinkingLedState = RTW_LED_OFF;
266 else
267 pLed->BlinkingLedState = RTW_LED_ON;
268 delay = LED_BLINK_LINK_INTERVAL_ALPHA;
269 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
270 } else {
271 pLed->bLedNoLinkBlinkInProgress = true;
272 pLed->CurrLedState = LED_BLINK_SLOWLY;
273 if (pLed->bLedOn)
274 pLed->BlinkingLedState = RTW_LED_OFF;
275 else
276 pLed->BlinkingLedState = RTW_LED_ON;
277 delay = LED_BLINK_NO_LINK_INTERVAL_ALPHA;
278 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
279 }
280 pLed->BlinkTimes = 0;
281 pLed->bLedBlinkInProgress = false;
282 } else {
283 if (pLed->bLedOn)
284 pLed->BlinkingLedState = RTW_LED_OFF;
285 else
286 pLed->BlinkingLedState = RTW_LED_ON;
287 delay = LED_BLINK_FASTER_INTERVAL_ALPHA;
288 }
289 break;
290 case LED_BLINK_WPS:
291 if (pLed->bLedOn)
292 pLed->BlinkingLedState = RTW_LED_OFF;
293 else
294 pLed->BlinkingLedState = RTW_LED_ON;
295 delay = LED_BLINK_SCAN_INTERVAL_ALPHA;
296 break;
297 case LED_BLINK_WPS_STOP: /* WPS success */
298 if (pLed->BlinkingLedState == RTW_LED_ON)
299 bStopBlinking = false;
300 else
301 bStopBlinking = true;
302 if (bStopBlinking) {
303 pLed->bLedLinkBlinkInProgress = true;
304 pLed->CurrLedState = LED_BLINK_NORMAL;
305 if (pLed->bLedOn)
306 pLed->BlinkingLedState = RTW_LED_OFF;
307 else
308 pLed->BlinkingLedState = RTW_LED_ON;
309 delay = LED_BLINK_LINK_INTERVAL_ALPHA;
310 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
311
312 pLed->bLedWPSBlinkInProgress = false;
313 } else {
314 pLed->BlinkingLedState = RTW_LED_OFF;
315 delay = LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA;
316 }
317 break;
318 default:
319 break;
320 }
321 if (delay)
322 mod_timer(&pLed->BlinkTimer, jiffies + msecs_to_jiffies(delay));
323}
324
325static void SwLedBlink2(struct led_8723a *pLed)
326{
327 struct rtw_adapter *padapter = pLed->padapter;
328 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
329 u8 bStopBlinking = false;
330
331 /* Change LED according to BlinkingLedState specified. */
332 if (pLed->BlinkingLedState == RTW_LED_ON) {
333 SwLedOn23a(padapter, pLed);
334 RT_TRACE(_module_rtl8712_led_c_, _drv_info_,
335 ("Blinktimes (%d): turn on\n", pLed->BlinkTimes));
336 } else {
337 SwLedOff23a(padapter, pLed);
338 RT_TRACE(_module_rtl8712_led_c_, _drv_info_,
339 ("Blinktimes (%d): turn off\n", pLed->BlinkTimes));
340 }
341 switch (pLed->CurrLedState) {
342 case LED_BLINK_SCAN:
343 pLed->BlinkTimes--;
344 if (pLed->BlinkTimes == 0)
345 bStopBlinking = true;
346 if (bStopBlinking) {
347 if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
348 SwLedOff23a(padapter, pLed);
349 } else if (check_fwstate(pmlmepriv, _FW_LINKED)) {
350 pLed->CurrLedState = RTW_LED_ON;
351 pLed->BlinkingLedState = RTW_LED_ON;
352 SwLedOn23a(padapter, pLed);
353 RT_TRACE(_module_rtl8712_led_c_, _drv_info_,
354 ("stop scan blink CurrLedState %d\n",
355 pLed->CurrLedState));
356 } else {
357 pLed->CurrLedState = RTW_LED_OFF;
358 pLed->BlinkingLedState = RTW_LED_OFF;
359 SwLedOff23a(padapter, pLed);
360 RT_TRACE(_module_rtl8712_led_c_, _drv_info_,
361 ("stop scan blink CurrLedState %d\n",
362 pLed->CurrLedState));
363 }
364 pLed->bLedScanBlinkInProgress = false;
365 } else {
366 if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
367 SwLedOff23a(padapter, pLed);
368 } else {
369 if (pLed->bLedOn)
370 pLed->BlinkingLedState = RTW_LED_OFF;
371 else
372 pLed->BlinkingLedState = RTW_LED_ON;
373 mod_timer(&pLed->BlinkTimer,
374 jiffies + msecs_to_jiffies(LED_BLINK_SCAN_INTERVAL_ALPHA));
375 }
376 }
377 break;
378 case LED_BLINK_TXRX:
379 pLed->BlinkTimes--;
380 if (pLed->BlinkTimes == 0)
381 bStopBlinking = true;
382 if (bStopBlinking) {
383 if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
384 SwLedOff23a(padapter, pLed);
385 } else if (check_fwstate(pmlmepriv, _FW_LINKED)) {
386 pLed->CurrLedState = RTW_LED_ON;
387 pLed->BlinkingLedState = RTW_LED_ON;
388 SwLedOn23a(padapter, pLed);
389 RT_TRACE(_module_rtl8712_led_c_, _drv_info_,
390 ("stop CurrLedState %d\n", pLed->CurrLedState));
391
392 } else {
393 pLed->CurrLedState = RTW_LED_OFF;
394 pLed->BlinkingLedState = RTW_LED_OFF;
395 SwLedOff23a(padapter, pLed);
396 RT_TRACE(_module_rtl8712_led_c_, _drv_info_,
397 ("stop CurrLedState %d\n", pLed->CurrLedState));
398 }
399 pLed->bLedBlinkInProgress = false;
400 } else {
401 if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
402 SwLedOff23a(padapter, pLed);
403 } else {
404 if (pLed->bLedOn)
405 pLed->BlinkingLedState = RTW_LED_OFF;
406 else
407 pLed->BlinkingLedState = RTW_LED_ON;
408 mod_timer(&pLed->BlinkTimer,
409 jiffies + msecs_to_jiffies(LED_BLINK_FASTER_INTERVAL_ALPHA));
410 }
411 }
412 break;
413 default:
414 break;
415 }
416}
417
418static void SwLedBlink3(struct led_8723a *pLed)
419{
420 struct rtw_adapter *padapter = pLed->padapter;
421 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
422 u8 bStopBlinking = false;
423
424 /* Change LED according to BlinkingLedState specified. */
425 if (pLed->BlinkingLedState == RTW_LED_ON)
426 {
427 SwLedOn23a(padapter, pLed);
428 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn on\n", pLed->BlinkTimes));
429 }
430 else
431 {
432 if (pLed->CurrLedState != LED_BLINK_WPS_STOP)
433 SwLedOff23a(padapter, pLed);
434 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn off\n", pLed->BlinkTimes));
435 }
436
437 switch (pLed->CurrLedState)
438 {
439 case LED_BLINK_SCAN:
440 pLed->BlinkTimes--;
441 if (pLed->BlinkTimes == 0)
442 {
443 bStopBlinking = true;
444 }
445
446 if (bStopBlinking)
447 {
448 if (padapter->pwrctrlpriv.rf_pwrstate != rf_on)
449 {
450 SwLedOff23a(padapter, pLed);
451 }
452 else if (check_fwstate(pmlmepriv, _FW_LINKED)) {
453 pLed->CurrLedState = RTW_LED_ON;
454 pLed->BlinkingLedState = RTW_LED_ON;
455 if (!pLed->bLedOn)
456 SwLedOn23a(padapter, pLed);
457
458 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
459 } else {
460 pLed->CurrLedState = RTW_LED_OFF;
461 pLed->BlinkingLedState = RTW_LED_OFF;
462 if (pLed->bLedOn)
463 SwLedOff23a(padapter, pLed);
464
465 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
466 }
467 pLed->bLedScanBlinkInProgress = false;
468 }
469 else
470 {
471 if (padapter->pwrctrlpriv.rf_pwrstate != rf_on)
472 {
473 SwLedOff23a(padapter, pLed);
474 }
475 else
476 {
477 if (pLed->bLedOn)
478 pLed->BlinkingLedState = RTW_LED_OFF;
479 else
480 pLed->BlinkingLedState = RTW_LED_ON;
481 mod_timer(&pLed->BlinkTimer,
482 jiffies + msecs_to_jiffies(LED_BLINK_SCAN_INTERVAL_ALPHA));
483 }
484 }
485 break;
486
487 case LED_BLINK_TXRX:
488 pLed->BlinkTimes--;
489 if (pLed->BlinkTimes == 0)
490 {
491 bStopBlinking = true;
492 }
493 if (bStopBlinking)
494 {
495 if (padapter->pwrctrlpriv.rf_pwrstate != rf_on)
496 {
497 SwLedOff23a(padapter, pLed);
498 } else if (check_fwstate(pmlmepriv,
499 _FW_LINKED)) {
500 pLed->CurrLedState = RTW_LED_ON;
501 pLed->BlinkingLedState = RTW_LED_ON;
502
503 if (!pLed->bLedOn)
504 SwLedOn23a(padapter, pLed);
505
506 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
507 } else {
508 pLed->CurrLedState = RTW_LED_OFF;
509 pLed->BlinkingLedState = RTW_LED_OFF;
510
511 if (pLed->bLedOn)
512 SwLedOff23a(padapter, pLed);
513
514 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
515 }
516 pLed->bLedBlinkInProgress = false;
517 }
518 else
519 {
520 if (padapter->pwrctrlpriv.rf_pwrstate != rf_on)
521 {
522 SwLedOff23a(padapter, pLed);
523 }
524 else
525 {
526 if (pLed->bLedOn)
527 pLed->BlinkingLedState = RTW_LED_OFF;
528 else
529 pLed->BlinkingLedState = RTW_LED_ON;
530 mod_timer(&pLed->BlinkTimer,
531 jiffies + msecs_to_jiffies(LED_BLINK_FASTER_INTERVAL_ALPHA));
532 }
533 }
534 break;
535
536 case LED_BLINK_WPS:
537 if (pLed->bLedOn)
538 pLed->BlinkingLedState = RTW_LED_OFF;
539 else
540 pLed->BlinkingLedState = RTW_LED_ON;
541 mod_timer(&pLed->BlinkTimer, jiffies +
542 msecs_to_jiffies(LED_BLINK_SCAN_INTERVAL_ALPHA));
543 break;
544
545 case LED_BLINK_WPS_STOP: /* WPS success */
546 if (pLed->BlinkingLedState == RTW_LED_ON)
547 {
548 pLed->BlinkingLedState = RTW_LED_OFF;
549 mod_timer(&pLed->BlinkTimer, jiffies +
550 msecs_to_jiffies(LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA));
551 bStopBlinking = false;
552 } else {
553 bStopBlinking = true;
554 }
555
556 if (bStopBlinking)
557 {
558 if (padapter->pwrctrlpriv.rf_pwrstate != rf_on)
559 {
560 SwLedOff23a(padapter, pLed);
561 }
562 else
563 {
564 pLed->CurrLedState = RTW_LED_ON;
565 pLed->BlinkingLedState = RTW_LED_ON;
566 SwLedOn23a(padapter, pLed);
567 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
568 }
569 pLed->bLedWPSBlinkInProgress = false;
570 }
571 break;
572
573 default:
574 break;
575 }
576}
577
578static void SwLedBlink4(struct led_8723a *pLed)
579{
580 struct rtw_adapter *padapter = pLed->padapter;
581 struct led_priv *ledpriv = &padapter->ledpriv;
582 struct led_8723a *pLed1 = &ledpriv->SwLed1;
583 u8 bStopBlinking = false;
584 unsigned long delay = 0;
585
586 /* Change LED according to BlinkingLedState specified. */
587 if (pLed->BlinkingLedState == RTW_LED_ON)
588 {
589 SwLedOn23a(padapter, pLed);
590 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn on\n", pLed->BlinkTimes));
591 } else {
592 SwLedOff23a(padapter, pLed);
593 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn off\n", pLed->BlinkTimes));
594 }
595
596 if (!pLed1->bLedWPSBlinkInProgress && pLed1->BlinkingLedState == LED_UNKNOWN)
597 {
598 pLed1->BlinkingLedState = RTW_LED_OFF;
599 pLed1->CurrLedState = RTW_LED_OFF;
600 SwLedOff23a(padapter, pLed1);
601 }
602
603 switch (pLed->CurrLedState)
604 {
605 case LED_BLINK_SLOWLY:
606 if (pLed->bLedOn)
607 pLed->BlinkingLedState = RTW_LED_OFF;
608 else
609 pLed->BlinkingLedState = RTW_LED_ON;
610 delay = LED_BLINK_NO_LINK_INTERVAL_ALPHA;
611 break;
612
613 case LED_BLINK_StartToBlink:
614 if (pLed->bLedOn) {
615 pLed->BlinkingLedState = RTW_LED_OFF;
616 delay = LED_BLINK_SLOWLY_INTERVAL;
617 } else {
618 pLed->BlinkingLedState = RTW_LED_ON;
619 delay = LED_BLINK_NORMAL_INTERVAL;
620 }
621 break;
622
623 case LED_BLINK_SCAN:
624 pLed->BlinkTimes--;
625 if (pLed->BlinkTimes == 0) {
626 bStopBlinking = false;
627 }
628
629 if (bStopBlinking) {
630 if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
631 SwLedOff23a(padapter, pLed);
632 } else {
633 pLed->bLedNoLinkBlinkInProgress = false;
634 pLed->CurrLedState = LED_BLINK_SLOWLY;
635 if (pLed->bLedOn)
636 pLed->BlinkingLedState = RTW_LED_OFF;
637 else
638 pLed->BlinkingLedState = RTW_LED_ON;
639 delay = LED_BLINK_NO_LINK_INTERVAL_ALPHA;
640 }
641 pLed->bLedScanBlinkInProgress = false;
642 } else {
643 if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
644 SwLedOff23a(padapter, pLed);
645 } else {
646 if (pLed->bLedOn)
647 pLed->BlinkingLedState = RTW_LED_OFF;
648 else
649 pLed->BlinkingLedState = RTW_LED_ON;
650 delay = LED_BLINK_SCAN_INTERVAL_ALPHA;
651 }
652 }
653 break;
654
655 case LED_BLINK_TXRX:
656 pLed->BlinkTimes--;
657 if (pLed->BlinkTimes == 0) {
658 bStopBlinking = true;
659 }
660 if (bStopBlinking) {
661 if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
662 SwLedOff23a(padapter, pLed);
663 } else {
664 pLed->bLedNoLinkBlinkInProgress = true;
665 pLed->CurrLedState = LED_BLINK_SLOWLY;
666 if (pLed->bLedOn)
667 pLed->BlinkingLedState = RTW_LED_OFF;
668 else
669 pLed->BlinkingLedState = RTW_LED_ON;
670 delay = LED_BLINK_NO_LINK_INTERVAL_ALPHA;
671 }
672 pLed->bLedBlinkInProgress = false;
673 } else {
674 if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
675 SwLedOff23a(padapter, pLed);
676 } else {
677 if (pLed->bLedOn)
678 pLed->BlinkingLedState = RTW_LED_OFF;
679 else
680 pLed->BlinkingLedState = RTW_LED_ON;
681 delay = LED_BLINK_FASTER_INTERVAL_ALPHA;
682 }
683 }
684 break;
685
686 case LED_BLINK_WPS:
687 if (pLed->bLedOn) {
688 pLed->BlinkingLedState = RTW_LED_OFF;
689 delay = LED_BLINK_SLOWLY_INTERVAL;
690 } else {
691 pLed->BlinkingLedState = RTW_LED_ON;
692 delay = LED_BLINK_NORMAL_INTERVAL;
693 }
694 break;
695
696 case LED_BLINK_WPS_STOP: /* WPS authentication fail */
697 if (pLed->bLedOn)
698 pLed->BlinkingLedState = RTW_LED_OFF;
699 else
700 pLed->BlinkingLedState = RTW_LED_ON;
701
702 delay = LED_BLINK_NORMAL_INTERVAL;
703 break;
704
705 case LED_BLINK_WPS_STOP_OVERLAP: /* WPS session overlap */
706 pLed->BlinkTimes--;
707 if (pLed->BlinkTimes == 0) {
708 if (pLed->bLedOn) {
709 pLed->BlinkTimes = 1;
710 } else {
711 bStopBlinking = true;
712 }
713 }
714
715 if (bStopBlinking) {
716 pLed->BlinkTimes = 10;
717 pLed->BlinkingLedState = RTW_LED_ON;
718 delay = LED_BLINK_LINK_INTERVAL_ALPHA;
719 } else {
720 if (pLed->bLedOn)
721 pLed->BlinkingLedState = RTW_LED_OFF;
722 else
723 pLed->BlinkingLedState = RTW_LED_ON;
724
725 delay = LED_BLINK_NORMAL_INTERVAL;
726 }
727 break;
728
729 default:
730 break;
731 }
732 if (delay)
733 mod_timer(&pLed->BlinkTimer, jiffies + msecs_to_jiffies(delay));
734
735 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("SwLedBlink4 CurrLedState %d\n", pLed->CurrLedState));
736}
737
738static void SwLedBlink5(struct led_8723a *pLed)
739{
740 struct rtw_adapter *padapter = pLed->padapter;
741 u8 bStopBlinking = false;
742 unsigned long delay = 0;
743
744 /* Change LED according to BlinkingLedState specified. */
745 if (pLed->BlinkingLedState == RTW_LED_ON) {
746 SwLedOn23a(padapter, pLed);
747 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn on\n", pLed->BlinkTimes));
748 } else {
749 SwLedOff23a(padapter, pLed);
750 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn off\n", pLed->BlinkTimes));
751 }
752
753 switch (pLed->CurrLedState)
754 {
755 case LED_BLINK_SCAN:
756 pLed->BlinkTimes--;
757 if (pLed->BlinkTimes == 0) {
758 bStopBlinking = true;
759 }
760
761 if (bStopBlinking) {
762 if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
763 pLed->CurrLedState = RTW_LED_OFF;
764 pLed->BlinkingLedState = RTW_LED_OFF;
765 if (pLed->bLedOn)
766 SwLedOff23a(padapter, pLed);
767 } else {
768 pLed->CurrLedState = RTW_LED_ON;
769 pLed->BlinkingLedState = RTW_LED_ON;
770 if (!pLed->bLedOn)
771 delay = LED_BLINK_FASTER_INTERVAL_ALPHA;
772 }
773
774 pLed->bLedScanBlinkInProgress = false;
775 } else {
776 if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
777 SwLedOff23a(padapter, pLed);
778 } else {
779 if (pLed->bLedOn)
780 pLed->BlinkingLedState = RTW_LED_OFF;
781 else
782 pLed->BlinkingLedState = RTW_LED_ON;
783 delay = LED_BLINK_SCAN_INTERVAL_ALPHA;
784 }
785 }
786 break;
787
788 case LED_BLINK_TXRX:
789 pLed->BlinkTimes--;
790 if (pLed->BlinkTimes == 0) {
791 bStopBlinking = true;
792 }
793
794 if (bStopBlinking) {
795 if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
796 pLed->CurrLedState = RTW_LED_OFF;
797 pLed->BlinkingLedState = RTW_LED_OFF;
798 if (pLed->bLedOn)
799 SwLedOff23a(padapter, pLed);
800 } else {
801 pLed->CurrLedState = RTW_LED_ON;
802 pLed->BlinkingLedState = RTW_LED_ON;
803 if (!pLed->bLedOn)
804 delay = LED_BLINK_FASTER_INTERVAL_ALPHA;
805 }
806
807 pLed->bLedBlinkInProgress = false;
808 } else {
809 if (padapter->pwrctrlpriv.rf_pwrstate != rf_on && padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) {
810 SwLedOff23a(padapter, pLed);
811 } else {
812 if (pLed->bLedOn)
813 pLed->BlinkingLedState = RTW_LED_OFF;
814 else
815 pLed->BlinkingLedState = RTW_LED_ON;
816 delay = LED_BLINK_FASTER_INTERVAL_ALPHA;
817 }
818 }
819 break;
820
821 default:
822 break;
823 }
824
825 if (delay)
826 mod_timer(&pLed->BlinkTimer, jiffies + msecs_to_jiffies(delay));
827
828 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("SwLedBlink5 CurrLedState %d\n", pLed->CurrLedState));
829}
830
831static void SwLedBlink6(struct led_8723a *pLed)
832{
833 struct rtw_adapter *padapter = pLed->padapter;
834
835 /* Change LED according to BlinkingLedState specified. */
836 if (pLed->BlinkingLedState == RTW_LED_ON) {
837 SwLedOn23a(padapter, pLed);
838 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn on\n", pLed->BlinkTimes));
839 } else {
840 SwLedOff23a(padapter, pLed);
841 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Blinktimes (%d): turn off\n", pLed->BlinkTimes));
842 }
843 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("<==== blink6\n"));
844}
845
846/* ALPHA, added by chiyoko, 20090106 */
847static void
848SwLedControlMode1(struct rtw_adapter *padapter, enum led_ctl_mode LedAction)
849{
850 struct led_priv *ledpriv = &padapter->ledpriv;
851 struct led_8723a *pLed = &ledpriv->SwLed0;
852 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
853
854 long delay = -1;
855
856 switch (LedAction)
857 {
858 case LED_CTL_POWER_ON:
859 case LED_CTL_START_TO_LINK:
860 case LED_CTL_NO_LINK:
861 if (pLed->bLedNoLinkBlinkInProgress == false) {
862 if (pLed->CurrLedState == LED_BLINK_SCAN ||
863 IS_LED_WPS_BLINKING(pLed)) {
864 return;
865 }
866 if (pLed->bLedLinkBlinkInProgress == true) {
867 del_timer_sync(&pLed->BlinkTimer);
868 pLed->bLedLinkBlinkInProgress = false;
869 }
870 if (pLed->bLedBlinkInProgress == true) {
871 del_timer_sync(&pLed->BlinkTimer);
872 pLed->bLedBlinkInProgress = false;
873 }
874
875 pLed->bLedNoLinkBlinkInProgress = true;
876 pLed->CurrLedState = LED_BLINK_SLOWLY;
877 if (pLed->bLedOn)
878 pLed->BlinkingLedState = RTW_LED_OFF;
879 else
880 pLed->BlinkingLedState = RTW_LED_ON;
881 delay = LED_BLINK_NO_LINK_INTERVAL_ALPHA;
882 }
883 break;
884
885 case LED_CTL_LINK:
886 if (pLed->bLedLinkBlinkInProgress == false) {
887 if (pLed->CurrLedState == LED_BLINK_SCAN ||
888 IS_LED_WPS_BLINKING(pLed)) {
889 return;
890 }
891 if (pLed->bLedNoLinkBlinkInProgress == true) {
892 del_timer_sync(&pLed->BlinkTimer);
893 pLed->bLedNoLinkBlinkInProgress = false;
894 }
895 if (pLed->bLedBlinkInProgress == true) {
896 del_timer_sync(&pLed->BlinkTimer);
897 pLed->bLedBlinkInProgress = false;
898 }
899 pLed->bLedLinkBlinkInProgress = true;
900 pLed->CurrLedState = LED_BLINK_NORMAL;
901 if (pLed->bLedOn)
902 pLed->BlinkingLedState = RTW_LED_OFF;
903 else
904 pLed->BlinkingLedState = RTW_LED_ON;
905 delay = LED_BLINK_LINK_INTERVAL_ALPHA;
906 }
907 break;
908
909 case LED_CTL_SITE_SURVEY:
910 if (pmlmepriv->LinkDetectInfo.bBusyTraffic &&
911 check_fwstate(pmlmepriv, _FW_LINKED))
912 ;
913 else if (pLed->bLedScanBlinkInProgress == false) {
914 if (IS_LED_WPS_BLINKING(pLed))
915 return;
916
917 if (pLed->bLedNoLinkBlinkInProgress == true) {
918 del_timer_sync(&pLed->BlinkTimer);
919 pLed->bLedNoLinkBlinkInProgress = false;
920 }
921 if (pLed->bLedLinkBlinkInProgress == true) {
922 del_timer_sync(&pLed->BlinkTimer);
923 pLed->bLedLinkBlinkInProgress = false;
924 }
925 if (pLed->bLedBlinkInProgress == true) {
926 del_timer_sync(&pLed->BlinkTimer);
927 pLed->bLedBlinkInProgress = false;
928 }
929 pLed->bLedScanBlinkInProgress = true;
930 pLed->CurrLedState = LED_BLINK_SCAN;
931 pLed->BlinkTimes = 24;
932 if (pLed->bLedOn)
933 pLed->BlinkingLedState = RTW_LED_OFF;
934 else
935 pLed->BlinkingLedState = RTW_LED_ON;
936 delay = LED_BLINK_SCAN_INTERVAL_ALPHA;
937 }
938 break;
939
940 case LED_CTL_TX:
941 case LED_CTL_RX:
942 if (pLed->bLedBlinkInProgress == false) {
943 if (pLed->CurrLedState == LED_BLINK_SCAN ||
944 IS_LED_WPS_BLINKING(pLed)) {
945 return;
946 }
947 if (pLed->bLedNoLinkBlinkInProgress == true) {
948 del_timer_sync(&pLed->BlinkTimer);
949 pLed->bLedNoLinkBlinkInProgress = false;
950 }
951 if (pLed->bLedLinkBlinkInProgress == true) {
952 del_timer_sync(&pLed->BlinkTimer);
953 pLed->bLedLinkBlinkInProgress = false;
954 }
955 pLed->bLedBlinkInProgress = true;
956 pLed->CurrLedState = LED_BLINK_TXRX;
957 pLed->BlinkTimes = 2;
958 if (pLed->bLedOn)
959 pLed->BlinkingLedState = RTW_LED_OFF;
960 else
961 pLed->BlinkingLedState = RTW_LED_ON;
962 delay = LED_BLINK_FASTER_INTERVAL_ALPHA;
963 }
964 break;
965
966 case LED_CTL_START_WPS: /* wait until xinpin finish */
967 case LED_CTL_START_WPS_BOTTON:
968 if (pLed->bLedWPSBlinkInProgress == false) {
969 if (pLed->bLedNoLinkBlinkInProgress == true) {
970 del_timer_sync(&pLed->BlinkTimer);
971 pLed->bLedNoLinkBlinkInProgress = false;
972 }
973 if (pLed->bLedLinkBlinkInProgress == true) {
974 del_timer_sync(&pLed->BlinkTimer);
975 pLed->bLedLinkBlinkInProgress = false;
976 }
977 if (pLed->bLedBlinkInProgress == true) {
978 del_timer_sync(&pLed->BlinkTimer);
979 pLed->bLedBlinkInProgress = false;
980 }
981 if (pLed->bLedScanBlinkInProgress == true) {
982 del_timer_sync(&pLed->BlinkTimer);
983 pLed->bLedScanBlinkInProgress = false;
984 }
985 pLed->bLedWPSBlinkInProgress = true;
986 pLed->CurrLedState = LED_BLINK_WPS;
987 if (pLed->bLedOn)
988 pLed->BlinkingLedState = RTW_LED_OFF;
989 else
990 pLed->BlinkingLedState = RTW_LED_ON;
991 delay = LED_BLINK_SCAN_INTERVAL_ALPHA;
992 }
993 break;
994
995 case LED_CTL_STOP_WPS:
996 if (pLed->bLedNoLinkBlinkInProgress == true) {
997 del_timer_sync(&pLed->BlinkTimer);
998 pLed->bLedNoLinkBlinkInProgress = false;
999 }
1000 if (pLed->bLedLinkBlinkInProgress == true) {
1001 del_timer_sync(&pLed->BlinkTimer);
1002 pLed->bLedLinkBlinkInProgress = false;
1003 }
1004 if (pLed->bLedBlinkInProgress == true) {
1005 del_timer_sync(&pLed->BlinkTimer);
1006 pLed->bLedBlinkInProgress = false;
1007 }
1008 if (pLed->bLedScanBlinkInProgress == true) {
1009 del_timer_sync(&pLed->BlinkTimer);
1010 pLed->bLedScanBlinkInProgress = false;
1011 }
1012 if (pLed->bLedWPSBlinkInProgress) {
1013 del_timer_sync(&pLed->BlinkTimer);
1014 } else {
1015 pLed->bLedWPSBlinkInProgress = true;
1016 }
1017
1018 pLed->CurrLedState = LED_BLINK_WPS_STOP;
1019 if (pLed->bLedOn) {
1020 pLed->BlinkingLedState = RTW_LED_OFF;
1021 delay = LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA;
1022 } else {
1023 pLed->BlinkingLedState = RTW_LED_ON;
1024 delay = 0;
1025 }
1026 break;
1027
1028 case LED_CTL_STOP_WPS_FAIL:
1029 if (pLed->bLedWPSBlinkInProgress) {
1030 del_timer_sync(&pLed->BlinkTimer);
1031 pLed->bLedWPSBlinkInProgress = false;
1032 }
1033
1034 pLed->bLedNoLinkBlinkInProgress = true;
1035 pLed->CurrLedState = LED_BLINK_SLOWLY;
1036 if (pLed->bLedOn)
1037 pLed->BlinkingLedState = RTW_LED_OFF;
1038 else
1039 pLed->BlinkingLedState = RTW_LED_ON;
1040 delay = LED_BLINK_NO_LINK_INTERVAL_ALPHA;
1041 break;
1042
1043 case LED_CTL_POWER_OFF:
1044 pLed->CurrLedState = RTW_LED_OFF;
1045 pLed->BlinkingLedState = RTW_LED_OFF;
1046 if (pLed->bLedNoLinkBlinkInProgress) {
1047 del_timer_sync(&pLed->BlinkTimer);
1048 pLed->bLedNoLinkBlinkInProgress = false;
1049 }
1050 if (pLed->bLedLinkBlinkInProgress) {
1051 del_timer_sync(&pLed->BlinkTimer);
1052 pLed->bLedLinkBlinkInProgress = false;
1053 }
1054 if (pLed->bLedBlinkInProgress) {
1055 del_timer_sync(&pLed->BlinkTimer);
1056 pLed->bLedBlinkInProgress = false;
1057 }
1058 if (pLed->bLedWPSBlinkInProgress) {
1059 del_timer_sync(&pLed->BlinkTimer);
1060 pLed->bLedWPSBlinkInProgress = false;
1061 }
1062 if (pLed->bLedScanBlinkInProgress) {
1063 del_timer_sync(&pLed->BlinkTimer);
1064 pLed->bLedScanBlinkInProgress = false;
1065 }
1066
1067 SwLedOff23a(padapter, pLed);
1068 break;
1069
1070 default:
1071 break;
1072
1073 }
1074
1075 if (delay != -1)
1076 mod_timer(&pLed->BlinkTimer, jiffies + msecs_to_jiffies(delay));
1077
1078 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Led %d\n", pLed->CurrLedState));
1079}
1080
1081 /* Arcadyan/Sitecom , added by chiyoko, 20090216 */
1082static void
1083SwLedControlMode2(struct rtw_adapter *padapter, enum led_ctl_mode LedAction)
1084{
1085 struct led_priv *ledpriv = &padapter->ledpriv;
1086 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1087 struct led_8723a *pLed = &ledpriv->SwLed0;
1088 long delay = -1;
1089
1090 switch (LedAction) {
1091 case LED_CTL_SITE_SURVEY:
1092 if (pmlmepriv->LinkDetectInfo.bBusyTraffic)
1093 ;
1094 else if (pLed->bLedScanBlinkInProgress == false) {
1095 if (IS_LED_WPS_BLINKING(pLed))
1096 return;
1097
1098 if (pLed->bLedBlinkInProgress == true) {
1099 del_timer_sync(&pLed->BlinkTimer);
1100 pLed->bLedBlinkInProgress = false;
1101 }
1102 pLed->bLedScanBlinkInProgress = true;
1103 pLed->CurrLedState = LED_BLINK_SCAN;
1104 pLed->BlinkTimes = 24;
1105 if (pLed->bLedOn)
1106 pLed->BlinkingLedState = RTW_LED_OFF;
1107 else
1108 pLed->BlinkingLedState = RTW_LED_ON;
1109 delay = LED_BLINK_SCAN_INTERVAL_ALPHA;
1110 }
1111 break;
1112 case LED_CTL_TX:
1113 case LED_CTL_RX:
1114 if (pLed->bLedBlinkInProgress == false &&
1115 check_fwstate(pmlmepriv, _FW_LINKED)) {
1116 if (pLed->CurrLedState == LED_BLINK_SCAN ||
1117 IS_LED_WPS_BLINKING(pLed)) {
1118 return;
1119 }
1120
1121 pLed->bLedBlinkInProgress = true;
1122 pLed->CurrLedState = LED_BLINK_TXRX;
1123 pLed->BlinkTimes = 2;
1124 if (pLed->bLedOn)
1125 pLed->BlinkingLedState = RTW_LED_OFF;
1126 else
1127 pLed->BlinkingLedState = RTW_LED_ON;
1128 delay = LED_BLINK_FASTER_INTERVAL_ALPHA;
1129 }
1130 break;
1131 case LED_CTL_LINK:
1132 pLed->CurrLedState = RTW_LED_ON;
1133 pLed->BlinkingLedState = RTW_LED_ON;
1134 if (pLed->bLedBlinkInProgress) {
1135 del_timer_sync(&pLed->BlinkTimer);
1136 pLed->bLedBlinkInProgress = false;
1137 }
1138 if (pLed->bLedScanBlinkInProgress) {
1139 del_timer_sync(&pLed->BlinkTimer);
1140 pLed->bLedScanBlinkInProgress = false;
1141 }
1142
1143 delay = 0;
1144 break;
1145 case LED_CTL_START_WPS: /* wait until xinpin finish */
1146 case LED_CTL_START_WPS_BOTTON:
1147 if (pLed->bLedWPSBlinkInProgress == false) {
1148 if (pLed->bLedBlinkInProgress == true) {
1149 del_timer_sync(&pLed->BlinkTimer);
1150 pLed->bLedBlinkInProgress = false;
1151 }
1152 if (pLed->bLedScanBlinkInProgress == true) {
1153 del_timer_sync(&pLed->BlinkTimer);
1154 pLed->bLedScanBlinkInProgress = false;
1155 }
1156 pLed->bLedWPSBlinkInProgress = true;
1157 pLed->CurrLedState = RTW_LED_ON;
1158 pLed->BlinkingLedState = RTW_LED_ON;
1159 delay = 0;
1160 }
1161 break;
1162 case LED_CTL_STOP_WPS:
1163 pLed->bLedWPSBlinkInProgress = false;
1164 if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
1165 SwLedOff23a(padapter, pLed);
1166 } else {
1167 pLed->CurrLedState = RTW_LED_ON;
1168 pLed->BlinkingLedState = RTW_LED_ON;
1169 delay = 0;
1170 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
1171 }
1172 break;
1173 case LED_CTL_STOP_WPS_FAIL:
1174 pLed->bLedWPSBlinkInProgress = false;
1175 if (padapter->pwrctrlpriv.rf_pwrstate != rf_on) {
1176 SwLedOff23a(padapter, pLed);
1177 } else {
1178 pLed->CurrLedState = RTW_LED_OFF;
1179 pLed->BlinkingLedState = RTW_LED_OFF;
1180 delay = 0;
1181 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
1182 }
1183 break;
1184 case LED_CTL_START_TO_LINK:
1185 case LED_CTL_NO_LINK:
1186 if (!IS_LED_BLINKING(pLed))
1187 {
1188 pLed->CurrLedState = RTW_LED_OFF;
1189 pLed->BlinkingLedState = RTW_LED_OFF;
1190 delay = 0;
1191 }
1192 break;
1193 case LED_CTL_POWER_OFF:
1194 pLed->CurrLedState = RTW_LED_OFF;
1195 pLed->BlinkingLedState = RTW_LED_OFF;
1196 if (pLed->bLedBlinkInProgress) {
1197 del_timer_sync(&pLed->BlinkTimer);
1198 pLed->bLedBlinkInProgress = false;
1199 }
1200 if (pLed->bLedScanBlinkInProgress) {
1201 del_timer_sync(&pLed->BlinkTimer);
1202 pLed->bLedScanBlinkInProgress = false;
1203 }
1204 if (pLed->bLedWPSBlinkInProgress) {
1205 del_timer_sync(&pLed->BlinkTimer);
1206 pLed->bLedWPSBlinkInProgress = false;
1207 }
1208
1209 delay = 0;
1210 break;
1211 default:
1212 break;
1213
1214 }
1215
1216 if (delay != -1)
1217 mod_timer(&pLed->BlinkTimer, jiffies + msecs_to_jiffies(delay));
1218
1219 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
1220}
1221
1222 /* COREGA, added by chiyoko, 20090316 */
1223static void
1224SwLedControlMode3(struct rtw_adapter *padapter, enum led_ctl_mode LedAction)
1225{
1226 struct led_priv *ledpriv = &padapter->ledpriv;
1227 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1228 struct led_8723a *pLed = &ledpriv->SwLed0;
1229 long delay = -1;
1230
1231 switch (LedAction)
1232 {
1233 case LED_CTL_SITE_SURVEY:
1234 if (pmlmepriv->LinkDetectInfo.bBusyTraffic)
1235 ;
1236 else if (pLed->bLedScanBlinkInProgress == false) {
1237 if (IS_LED_WPS_BLINKING(pLed))
1238 return;
1239
1240 if (pLed->bLedBlinkInProgress == true) {
1241 del_timer_sync(&pLed->BlinkTimer);
1242 pLed->bLedBlinkInProgress = false;
1243 }
1244 pLed->bLedScanBlinkInProgress = true;
1245 pLed->CurrLedState = LED_BLINK_SCAN;
1246 pLed->BlinkTimes = 24;
1247 if (pLed->bLedOn)
1248 pLed->BlinkingLedState = RTW_LED_OFF;
1249 else
1250 pLed->BlinkingLedState = RTW_LED_ON;
1251 delay = LED_BLINK_SCAN_INTERVAL_ALPHA;
1252 }
1253 break;
1254
1255 case LED_CTL_TX:
1256 case LED_CTL_RX:
1257 if (pLed->bLedBlinkInProgress == false &&
1258 check_fwstate(pmlmepriv, _FW_LINKED)) {
1259 if (pLed->CurrLedState == LED_BLINK_SCAN ||
1260 IS_LED_WPS_BLINKING(pLed)) {
1261 return;
1262 }
1263
1264 pLed->bLedBlinkInProgress = true;
1265 pLed->CurrLedState = LED_BLINK_TXRX;
1266 pLed->BlinkTimes = 2;
1267 if (pLed->bLedOn)
1268 pLed->BlinkingLedState = RTW_LED_OFF;
1269 else
1270 pLed->BlinkingLedState = RTW_LED_ON;
1271 delay = LED_BLINK_FASTER_INTERVAL_ALPHA;
1272 }
1273 break;
1274
1275 case LED_CTL_LINK:
1276 if (IS_LED_WPS_BLINKING(pLed))
1277 return;
1278
1279 pLed->CurrLedState = RTW_LED_ON;
1280 pLed->BlinkingLedState = RTW_LED_ON;
1281 if (pLed->bLedBlinkInProgress) {
1282 del_timer_sync(&pLed->BlinkTimer);
1283 pLed->bLedBlinkInProgress = false;
1284 }
1285 if (pLed->bLedScanBlinkInProgress) {
1286 del_timer_sync(&pLed->BlinkTimer);
1287 pLed->bLedScanBlinkInProgress = false;
1288 }
1289
1290 delay = 0;
1291 break;
1292
1293 case LED_CTL_START_WPS: /* wait until xinpin finish */
1294 case LED_CTL_START_WPS_BOTTON:
1295 if (pLed->bLedWPSBlinkInProgress == false) {
1296 if (pLed->bLedBlinkInProgress == true) {
1297 del_timer_sync(&pLed->BlinkTimer);
1298 pLed->bLedBlinkInProgress = false;
1299 }
1300 if (pLed->bLedScanBlinkInProgress == true) {
1301 del_timer_sync(&pLed->BlinkTimer);
1302 pLed->bLedScanBlinkInProgress = false;
1303 }
1304 pLed->bLedWPSBlinkInProgress = true;
1305 pLed->CurrLedState = LED_BLINK_WPS;
1306 if (pLed->bLedOn)
1307 pLed->BlinkingLedState = RTW_LED_OFF;
1308 else
1309 pLed->BlinkingLedState = RTW_LED_ON;
1310 delay = LED_BLINK_SCAN_INTERVAL_ALPHA;
1311 }
1312 break;
1313
1314 case LED_CTL_STOP_WPS:
1315 if (pLed->bLedWPSBlinkInProgress) {
1316 del_timer_sync(&pLed->BlinkTimer);
1317 pLed->bLedWPSBlinkInProgress = false;
1318 } else {
1319 pLed->bLedWPSBlinkInProgress = true;
1320 }
1321
1322 pLed->CurrLedState = LED_BLINK_WPS_STOP;
1323 if (pLed->bLedOn) {
1324 pLed->BlinkingLedState = RTW_LED_OFF;
1325 delay = LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA;
1326 } else {
1327 pLed->BlinkingLedState = RTW_LED_ON;
1328 delay = 0;
1329 }
1330
1331 break;
1332
1333 case LED_CTL_STOP_WPS_FAIL:
1334 if (pLed->bLedWPSBlinkInProgress) {
1335 del_timer_sync(&pLed->BlinkTimer);
1336 pLed->bLedWPSBlinkInProgress = false;
1337 }
1338
1339 pLed->CurrLedState = RTW_LED_OFF;
1340 pLed->BlinkingLedState = RTW_LED_OFF;
1341 delay = 0;
1342 break;
1343
1344 case LED_CTL_START_TO_LINK:
1345 case LED_CTL_NO_LINK:
1346 if (!IS_LED_BLINKING(pLed))
1347 {
1348 pLed->CurrLedState = RTW_LED_OFF;
1349 pLed->BlinkingLedState = RTW_LED_OFF;
1350 delay = 0;
1351 }
1352 break;
1353
1354 case LED_CTL_POWER_OFF:
1355 pLed->CurrLedState = RTW_LED_OFF;
1356 pLed->BlinkingLedState = RTW_LED_OFF;
1357 if (pLed->bLedBlinkInProgress) {
1358 del_timer_sync(&pLed->BlinkTimer);
1359 pLed->bLedBlinkInProgress = false;
1360 }
1361 if (pLed->bLedScanBlinkInProgress) {
1362 del_timer_sync(&pLed->BlinkTimer);
1363 pLed->bLedScanBlinkInProgress = false;
1364 }
1365 if (pLed->bLedWPSBlinkInProgress) {
1366 del_timer_sync(&pLed->BlinkTimer);
1367 pLed->bLedWPSBlinkInProgress = false;
1368 }
1369
1370 delay = 0;
1371 break;
1372
1373 default:
1374 break;
1375
1376 }
1377
1378 if (delay != -1)
1379 mod_timer(&pLed->BlinkTimer, jiffies + msecs_to_jiffies(delay));
1380
1381 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("CurrLedState %d\n", pLed->CurrLedState));
1382}
1383
1384 /* Edimax-Belkin, added by chiyoko, 20090413 */
1385static void
1386SwLedControlMode4(struct rtw_adapter *padapter, enum led_ctl_mode LedAction)
1387{
1388 struct led_priv *ledpriv = &padapter->ledpriv;
1389 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1390 struct led_8723a *pLed = &ledpriv->SwLed0;
1391 struct led_8723a *pLed1 = &ledpriv->SwLed1;
1392
1393 switch (LedAction)
1394 {
1395 case LED_CTL_START_TO_LINK:
1396 if (pLed1->bLedWPSBlinkInProgress) {
1397 pLed1->bLedWPSBlinkInProgress = false;
1398 del_timer_sync(&pLed1->BlinkTimer);
1399
1400 pLed1->BlinkingLedState = RTW_LED_OFF;
1401 pLed1->CurrLedState = RTW_LED_OFF;
1402
1403 if (pLed1->bLedOn)
1404 mod_timer(&pLed->BlinkTimer, jiffies);
1405 }
1406
1407 if (pLed->bLedStartToLinkBlinkInProgress == false) {
1408 if (pLed->CurrLedState == LED_BLINK_SCAN ||
1409 IS_LED_WPS_BLINKING(pLed)) {
1410 return;
1411 }
1412 if (pLed->bLedBlinkInProgress == true) {
1413 del_timer_sync(&pLed->BlinkTimer);
1414 pLed->bLedBlinkInProgress = false;
1415 }
1416 if (pLed->bLedNoLinkBlinkInProgress == true) {
1417 del_timer_sync(&pLed->BlinkTimer);
1418 pLed->bLedNoLinkBlinkInProgress = false;
1419 }
1420
1421 pLed->bLedStartToLinkBlinkInProgress = true;
1422 pLed->CurrLedState = LED_BLINK_StartToBlink;
1423 if (pLed->bLedOn) {
1424 pLed->BlinkingLedState = RTW_LED_OFF;
1425 mod_timer(&pLed->BlinkTimer,
1426 jiffies + msecs_to_jiffies(LED_BLINK_SLOWLY_INTERVAL));
1427 } else {
1428 pLed->BlinkingLedState = RTW_LED_ON;
1429 mod_timer(&pLed->BlinkTimer,
1430 jiffies + msecs_to_jiffies(LED_BLINK_NORMAL_INTERVAL));
1431 }
1432 }
1433 break;
1434
1435 case LED_CTL_LINK:
1436 case LED_CTL_NO_LINK:
1437 /* LED1 settings */
1438 if (LedAction == LED_CTL_LINK) {
1439 if (pLed1->bLedWPSBlinkInProgress) {
1440 pLed1->bLedWPSBlinkInProgress = false;
1441 del_timer_sync(&pLed1->BlinkTimer);
1442
1443 pLed1->BlinkingLedState = RTW_LED_OFF;
1444 pLed1->CurrLedState = RTW_LED_OFF;
1445
1446 if (pLed1->bLedOn)
1447 mod_timer(&pLed->BlinkTimer, jiffies);
1448 }
1449 }
1450
1451 if (pLed->bLedNoLinkBlinkInProgress == false) {
1452 if (pLed->CurrLedState == LED_BLINK_SCAN ||
1453 IS_LED_WPS_BLINKING(pLed)) {
1454 return;
1455 }
1456 if (pLed->bLedBlinkInProgress == true) {
1457 del_timer_sync(&pLed->BlinkTimer);
1458 pLed->bLedBlinkInProgress = false;
1459 }
1460
1461 pLed->bLedNoLinkBlinkInProgress = true;
1462 pLed->CurrLedState = LED_BLINK_SLOWLY;
1463 if (pLed->bLedOn)
1464 pLed->BlinkingLedState = RTW_LED_OFF;
1465 else
1466 pLed->BlinkingLedState = RTW_LED_ON;
1467 mod_timer(&pLed->BlinkTimer, jiffies +
1468 msecs_to_jiffies(LED_BLINK_NO_LINK_INTERVAL_ALPHA));
1469 }
1470 break;
1471
1472 case LED_CTL_SITE_SURVEY:
1473 if (pmlmepriv->LinkDetectInfo.bBusyTraffic &&
1474 check_fwstate(pmlmepriv, _FW_LINKED))
1475 ;
1476 else if (pLed->bLedScanBlinkInProgress == false) {
1477 if (IS_LED_WPS_BLINKING(pLed))
1478 return;
1479
1480 if (pLed->bLedNoLinkBlinkInProgress == true) {
1481 del_timer_sync(&pLed->BlinkTimer);
1482 pLed->bLedNoLinkBlinkInProgress = false;
1483 }
1484 if (pLed->bLedBlinkInProgress == true) {
1485 del_timer_sync(&pLed->BlinkTimer);
1486 pLed->bLedBlinkInProgress = false;
1487 }
1488 pLed->bLedScanBlinkInProgress = true;
1489 pLed->CurrLedState = LED_BLINK_SCAN;
1490 pLed->BlinkTimes = 24;
1491 if (pLed->bLedOn)
1492 pLed->BlinkingLedState = RTW_LED_OFF;
1493 else
1494 pLed->BlinkingLedState = RTW_LED_ON;
1495 mod_timer(&pLed->BlinkTimer, jiffies +
1496 msecs_to_jiffies(LED_BLINK_SCAN_INTERVAL_ALPHA));
1497 }
1498 break;
1499
1500 case LED_CTL_TX:
1501 case LED_CTL_RX:
1502 if (pLed->bLedBlinkInProgress == false) {
1503 if (pLed->CurrLedState == LED_BLINK_SCAN ||
1504 IS_LED_WPS_BLINKING(pLed)) {
1505 return;
1506 }
1507 if (pLed->bLedNoLinkBlinkInProgress == true) {
1508 del_timer_sync(&pLed->BlinkTimer);
1509 pLed->bLedNoLinkBlinkInProgress = false;
1510 }
1511 pLed->bLedBlinkInProgress = true;
1512 pLed->CurrLedState = LED_BLINK_TXRX;
1513 pLed->BlinkTimes = 2;
1514 if (pLed->bLedOn)
1515 pLed->BlinkingLedState = RTW_LED_OFF;
1516 else
1517 pLed->BlinkingLedState = RTW_LED_ON;
1518 mod_timer(&pLed->BlinkTimer, jiffies +
1519 msecs_to_jiffies(LED_BLINK_FASTER_INTERVAL_ALPHA));
1520 }
1521 break;
1522
1523 case LED_CTL_START_WPS: /* wait until xinpin finish */
1524 case LED_CTL_START_WPS_BOTTON:
1525 if (pLed1->bLedWPSBlinkInProgress) {
1526 pLed1->bLedWPSBlinkInProgress = false;
1527 del_timer_sync(&pLed1->BlinkTimer);
1528
1529 pLed1->BlinkingLedState = RTW_LED_OFF;
1530 pLed1->CurrLedState = RTW_LED_OFF;
1531
1532 if (pLed1->bLedOn)
1533 mod_timer(&pLed->BlinkTimer, jiffies);
1534 }
1535
1536 if (pLed->bLedWPSBlinkInProgress == false) {
1537 if (pLed->bLedNoLinkBlinkInProgress == true) {
1538 del_timer_sync(&pLed->BlinkTimer);
1539 pLed->bLedNoLinkBlinkInProgress = false;
1540 }
1541 if (pLed->bLedBlinkInProgress == true) {
1542 del_timer_sync(&pLed->BlinkTimer);
1543 pLed->bLedBlinkInProgress = false;
1544 }
1545 if (pLed->bLedScanBlinkInProgress == true) {
1546 del_timer_sync(&pLed->BlinkTimer);
1547 pLed->bLedScanBlinkInProgress = false;
1548 }
1549 pLed->bLedWPSBlinkInProgress = true;
1550 pLed->CurrLedState = LED_BLINK_WPS;
1551 if (pLed->bLedOn)
1552 {
1553 pLed->BlinkingLedState = RTW_LED_OFF;
1554 mod_timer(&pLed->BlinkTimer, jiffies +
1555 msecs_to_jiffies(LED_BLINK_SLOWLY_INTERVAL));
1556 } else {
1557 pLed->BlinkingLedState = RTW_LED_ON;
1558 mod_timer(&pLed->BlinkTimer, jiffies +
1559 msecs_to_jiffies(LED_BLINK_NORMAL_INTERVAL));
1560 }
1561 }
1562 break;
1563
1564 case LED_CTL_STOP_WPS: /* WPS connect success */
1565 if (pLed->bLedWPSBlinkInProgress) {
1566 del_timer_sync(&pLed->BlinkTimer);
1567 pLed->bLedWPSBlinkInProgress = false;
1568 }
1569
1570 pLed->bLedNoLinkBlinkInProgress = true;
1571 pLed->CurrLedState = LED_BLINK_SLOWLY;
1572 if (pLed->bLedOn)
1573 pLed->BlinkingLedState = RTW_LED_OFF;
1574 else
1575 pLed->BlinkingLedState = RTW_LED_ON;
1576 mod_timer(&pLed->BlinkTimer, jiffies +
1577 msecs_to_jiffies(LED_BLINK_NO_LINK_INTERVAL_ALPHA));
1578 break;
1579
1580 case LED_CTL_STOP_WPS_FAIL: /* WPS authentication fail */
1581 if (pLed->bLedWPSBlinkInProgress) {
1582 del_timer_sync(&pLed->BlinkTimer);
1583 pLed->bLedWPSBlinkInProgress = false;
1584 }
1585
1586 pLed->bLedNoLinkBlinkInProgress = true;
1587 pLed->CurrLedState = LED_BLINK_SLOWLY;
1588 if (pLed->bLedOn)
1589 pLed->BlinkingLedState = RTW_LED_OFF;
1590 else
1591 pLed->BlinkingLedState = RTW_LED_ON;
1592 mod_timer(&pLed->BlinkTimer, jiffies +
1593 msecs_to_jiffies(LED_BLINK_NO_LINK_INTERVAL_ALPHA));
1594
1595 /* LED1 settings */
1596 if (pLed1->bLedWPSBlinkInProgress)
1597 del_timer_sync(&pLed1->BlinkTimer);
1598 else
1599 pLed1->bLedWPSBlinkInProgress = true;
1600
1601 pLed1->CurrLedState = LED_BLINK_WPS_STOP;
1602 if (pLed1->bLedOn)
1603 pLed1->BlinkingLedState = RTW_LED_OFF;
1604 else
1605 pLed1->BlinkingLedState = RTW_LED_ON;
1606 mod_timer(&pLed->BlinkTimer, jiffies +
1607 msecs_to_jiffies(LED_BLINK_NORMAL_INTERVAL));
1608
1609 break;
1610
1611 case LED_CTL_STOP_WPS_FAIL_OVERLAP: /* WPS session overlap */
1612 if (pLed->bLedWPSBlinkInProgress) {
1613 del_timer_sync(&pLed->BlinkTimer);
1614 pLed->bLedWPSBlinkInProgress = false;
1615 }
1616
1617 pLed->bLedNoLinkBlinkInProgress = true;
1618 pLed->CurrLedState = LED_BLINK_SLOWLY;
1619 if (pLed->bLedOn)
1620 pLed->BlinkingLedState = RTW_LED_OFF;
1621 else
1622 pLed->BlinkingLedState = RTW_LED_ON;
1623 mod_timer(&pLed->BlinkTimer, jiffies +
1624 msecs_to_jiffies(LED_BLINK_NO_LINK_INTERVAL_ALPHA));
1625
1626 /* LED1 settings */
1627 if (pLed1->bLedWPSBlinkInProgress)
1628 del_timer_sync(&pLed1->BlinkTimer);
1629 else
1630 pLed1->bLedWPSBlinkInProgress = true;
1631
1632 pLed1->CurrLedState = LED_BLINK_WPS_STOP_OVERLAP;
1633 pLed1->BlinkTimes = 10;
1634 if (pLed1->bLedOn)
1635 pLed1->BlinkingLedState = RTW_LED_OFF;
1636 else
1637 pLed1->BlinkingLedState = RTW_LED_ON;
1638 mod_timer(&pLed->BlinkTimer, jiffies +
1639 msecs_to_jiffies(LED_BLINK_NORMAL_INTERVAL));
1640
1641 break;
1642
1643 case LED_CTL_POWER_OFF:
1644 pLed->CurrLedState = RTW_LED_OFF;
1645 pLed->BlinkingLedState = RTW_LED_OFF;
1646
1647 if (pLed->bLedNoLinkBlinkInProgress) {
1648 del_timer_sync(&pLed->BlinkTimer);
1649 pLed->bLedNoLinkBlinkInProgress = false;
1650 }
1651 if (pLed->bLedLinkBlinkInProgress) {
1652 del_timer_sync(&pLed->BlinkTimer);
1653 pLed->bLedLinkBlinkInProgress = false;
1654 }
1655 if (pLed->bLedBlinkInProgress) {
1656 del_timer_sync(&pLed->BlinkTimer);
1657 pLed->bLedBlinkInProgress = false;
1658 }
1659 if (pLed->bLedWPSBlinkInProgress) {
1660 del_timer_sync(&pLed->BlinkTimer);
1661 pLed->bLedWPSBlinkInProgress = false;
1662 }
1663 if (pLed->bLedScanBlinkInProgress) {
1664 del_timer_sync(&pLed->BlinkTimer);
1665 pLed->bLedScanBlinkInProgress = false;
1666 }
1667 if (pLed->bLedStartToLinkBlinkInProgress) {
1668 del_timer_sync(&pLed->BlinkTimer);
1669 pLed->bLedStartToLinkBlinkInProgress = false;
1670 }
1671
1672 if (pLed1->bLedWPSBlinkInProgress) {
1673 del_timer_sync(&pLed1->BlinkTimer);
1674 pLed1->bLedWPSBlinkInProgress = false;
1675 }
1676
1677 pLed1->BlinkingLedState = LED_UNKNOWN;
1678 SwLedOff23a(padapter, pLed);
1679 SwLedOff23a(padapter, pLed1);
1680 break;
1681
1682 default:
1683 break;
1684
1685 }
1686
1687 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Led %d\n", pLed->CurrLedState));
1688}
1689
1690 /* Sercomm-Belkin, added by chiyoko, 20090415 */
1691static void
1692SwLedControlMode5(struct rtw_adapter *padapter, enum led_ctl_mode LedAction)
1693{
1694 struct led_priv *ledpriv = &padapter->ledpriv;
1695 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1696 struct led_8723a *pLed = &ledpriv->SwLed0;
1697
1698 switch (LedAction)
1699 {
1700 case LED_CTL_POWER_ON:
1701 case LED_CTL_NO_LINK:
1702 case LED_CTL_LINK: /* solid blue */
1703 pLed->CurrLedState = RTW_LED_ON;
1704 pLed->BlinkingLedState = RTW_LED_ON;
1705
1706 mod_timer(&pLed->BlinkTimer, jiffies);
1707 break;
1708
1709 case LED_CTL_SITE_SURVEY:
1710 if (pmlmepriv->LinkDetectInfo.bBusyTraffic &&
1711 check_fwstate(pmlmepriv, _FW_LINKED))
1712 ;
1713 else if (pLed->bLedScanBlinkInProgress == false)
1714 {
1715 if (pLed->bLedBlinkInProgress == true)
1716 {
1717 del_timer_sync(&pLed->BlinkTimer);
1718 pLed->bLedBlinkInProgress = false;
1719 }
1720 pLed->bLedScanBlinkInProgress = true;
1721 pLed->CurrLedState = LED_BLINK_SCAN;
1722 pLed->BlinkTimes = 24;
1723 if (pLed->bLedOn)
1724 pLed->BlinkingLedState = RTW_LED_OFF;
1725 else
1726 pLed->BlinkingLedState = RTW_LED_ON;
1727 mod_timer(&pLed->BlinkTimer, jiffies +
1728 msecs_to_jiffies(LED_BLINK_SCAN_INTERVAL_ALPHA));
1729 }
1730 break;
1731
1732 case LED_CTL_TX:
1733 case LED_CTL_RX:
1734 if (pLed->bLedBlinkInProgress == false) {
1735 if (pLed->CurrLedState == LED_BLINK_SCAN) {
1736 return;
1737 }
1738 pLed->bLedBlinkInProgress = true;
1739 pLed->CurrLedState = LED_BLINK_TXRX;
1740 pLed->BlinkTimes = 2;
1741 if (pLed->bLedOn)
1742 pLed->BlinkingLedState = RTW_LED_OFF;
1743 else
1744 pLed->BlinkingLedState = RTW_LED_ON;
1745 mod_timer(&pLed->BlinkTimer, jiffies +
1746 msecs_to_jiffies(LED_BLINK_FASTER_INTERVAL_ALPHA));
1747 }
1748 break;
1749
1750 case LED_CTL_POWER_OFF:
1751 pLed->CurrLedState = RTW_LED_OFF;
1752 pLed->BlinkingLedState = RTW_LED_OFF;
1753
1754 if (pLed->bLedBlinkInProgress) {
1755 del_timer_sync(&pLed->BlinkTimer);
1756 pLed->bLedBlinkInProgress = false;
1757 }
1758
1759 SwLedOff23a(padapter, pLed);
1760 break;
1761
1762 default:
1763 break;
1764
1765 }
1766
1767 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("Led %d\n", pLed->CurrLedState));
1768}
1769
1770 /* WNC-Corega, added by chiyoko, 20090902 */
1771static void SwLedControlMode6(struct rtw_adapter *padapter,
1772 enum led_ctl_mode LedAction)
1773{
1774 struct led_priv *ledpriv = &padapter->ledpriv;
1775 struct led_8723a *pLed0 = &ledpriv->SwLed0;
1776
1777 switch (LedAction) {
1778 case LED_CTL_POWER_ON:
1779 case LED_CTL_LINK:
1780 case LED_CTL_NO_LINK:
1781 del_timer_sync(&pLed0->BlinkTimer);
1782 pLed0->CurrLedState = RTW_LED_ON;
1783 pLed0->BlinkingLedState = RTW_LED_ON;
1784 mod_timer(&pLed0->BlinkTimer, jiffies);
1785 break;
1786 case LED_CTL_POWER_OFF:
1787 SwLedOff23a(padapter, pLed0);
1788 break;
1789 default:
1790 break;
1791 }
1792
1793 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("ledcontrol 6 Led %d\n", pLed0->CurrLedState));
1794}
1795
1796/* */
1797/* Description: */
1798/* Handler function of LED Blinking. */
1799/* We dispatch acture LED blink action according to LedStrategy. */
1800/* */
1801void BlinkHandler23a(struct led_8723a *pLed)
1802{
1803 struct rtw_adapter *padapter = pLed->padapter;
1804 struct led_priv *ledpriv = &padapter->ledpriv;
1805
1806 /* DBG_8723A("%s (%s:%d)\n", __func__, current->comm, current->pid); */
1807
1808 if ((padapter->bSurpriseRemoved) || (padapter->bDriverStopped))
1809 return;
1810
1811 switch (ledpriv->LedStrategy) {
1812 case SW_LED_MODE0:
1813 SwLedBlink(pLed);
1814 break;
1815 case SW_LED_MODE1:
1816 SwLedBlink1(pLed);
1817 break;
1818 case SW_LED_MODE2:
1819 SwLedBlink2(pLed);
1820 break;
1821 case SW_LED_MODE3:
1822 SwLedBlink3(pLed);
1823 break;
1824 case SW_LED_MODE4:
1825 SwLedBlink4(pLed);
1826 break;
1827 case SW_LED_MODE5:
1828 SwLedBlink5(pLed);
1829 break;
1830 case SW_LED_MODE6:
1831 SwLedBlink6(pLed);
1832 break;
1833 default:
1834 break;
1835 }
1836}
1837
1838void
1839LedControl871x23a(struct rtw_adapter *padapter, enum led_ctl_mode LedAction) {
1840 struct led_priv *ledpriv = &padapter->ledpriv;
1841
1842 if ((padapter->bSurpriseRemoved == true) ||
1843 (padapter->bDriverStopped == true) ||
1844 (padapter->hw_init_completed == false)) {
1845 return;
1846 }
1847
1848 if (ledpriv->bRegUseLed == false)
1849 return;
1850
1851 /* if (!priv->up) */
1852 /* return; */
1853
1854 /* if (priv->bInHctTest) */
1855 /* return; */
1856
1857 if ((padapter->pwrctrlpriv.rf_pwrstate != rf_on &&
1858 padapter->pwrctrlpriv.rfoff_reason > RF_CHANGE_BY_PS) &&
1859 (LedAction == LED_CTL_TX || LedAction == LED_CTL_RX ||
1860 LedAction == LED_CTL_SITE_SURVEY ||
1861 LedAction == LED_CTL_LINK ||
1862 LedAction == LED_CTL_NO_LINK ||
1863 LedAction == LED_CTL_POWER_ON)) {
1864 return;
1865 }
1866
1867 switch (ledpriv->LedStrategy) {
1868 case SW_LED_MODE0:
1869 break;
1870 case SW_LED_MODE1:
1871 SwLedControlMode1(padapter, LedAction);
1872 break;
1873 case SW_LED_MODE2:
1874 SwLedControlMode2(padapter, LedAction);
1875 break;
1876 case SW_LED_MODE3:
1877 SwLedControlMode3(padapter, LedAction);
1878 break;
1879 case SW_LED_MODE4:
1880 SwLedControlMode4(padapter, LedAction);
1881 break;
1882 case SW_LED_MODE5:
1883 SwLedControlMode5(padapter, LedAction);
1884 break;
1885 case SW_LED_MODE6:
1886 SwLedControlMode6(padapter, LedAction);
1887 break;
1888 default:
1889 break;
1890 }
1891
1892 RT_TRACE(_module_rtl8712_led_c_, _drv_info_, ("LedStrategy:%d, LedAction %d\n", ledpriv->LedStrategy, LedAction));
1893}
diff --git a/drivers/staging/rtl8723au/core/rtw_mlme.c b/drivers/staging/rtl8723au/core/rtw_mlme.c
index 1f6006439bbb..7299ef0a2e54 100644
--- a/drivers/staging/rtl8723au/core/rtw_mlme.c
+++ b/drivers/staging/rtl8723au/core/rtw_mlme.c
@@ -50,7 +50,6 @@ static void rtw_init_mlme_timer(struct rtw_adapter *padapter)
50int rtw_init_mlme_priv23a(struct rtw_adapter *padapter) 50int rtw_init_mlme_priv23a(struct rtw_adapter *padapter)
51{ 51{
52 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 52 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
53 int res = _SUCCESS;
54 53
55 pmlmepriv->nic_hdl = padapter; 54 pmlmepriv->nic_hdl = padapter;
56 55
@@ -68,7 +67,7 @@ int rtw_init_mlme_priv23a(struct rtw_adapter *padapter)
68 rtw_clear_scan_deny(padapter); 67 rtw_clear_scan_deny(padapter);
69 68
70 rtw_init_mlme_timer(padapter); 69 rtw_init_mlme_timer(padapter);
71 return res; 70 return _SUCCESS;
72} 71}
73 72
74#ifdef CONFIG_8723AU_AP_MODE 73#ifdef CONFIG_8723AU_AP_MODE
@@ -110,7 +109,6 @@ struct wlan_network *rtw_alloc_network(struct mlme_priv *pmlmepriv, gfp_t gfp)
110 pnetwork->network_type = 0; 109 pnetwork->network_type = 0;
111 pnetwork->fixed = false; 110 pnetwork->fixed = false;
112 pnetwork->last_scanned = jiffies; 111 pnetwork->last_scanned = jiffies;
113 pnetwork->aid = 0;
114 pnetwork->join_res = 0; 112 pnetwork->join_res = 0;
115 } 113 }
116 114
@@ -218,8 +216,6 @@ void rtw_generate_random_ibss23a(u8 *pibss)
218 pibss[3] = curtime & 0xff;/* p[0]; */ 216 pibss[3] = curtime & 0xff;/* p[0]; */
219 pibss[4] = (curtime >> 8) & 0xff;/* p[1]; */ 217 pibss[4] = (curtime >> 8) & 0xff;/* p[1]; */
220 pibss[5] = (curtime >> 16) & 0xff;/* p[2]; */ 218 pibss[5] = (curtime >> 16) & 0xff;/* p[2]; */
221
222 return;
223} 219}
224 220
225void rtw_set_roaming(struct rtw_adapter *adapter, u8 to_roaming) 221void rtw_set_roaming(struct rtw_adapter *adapter, u8 to_roaming)
@@ -356,12 +352,12 @@ rtw_get_oldest_wlan_network23a(struct rtw_queue *scanned_queue)
356void update_network23a(struct wlan_bssid_ex *dst, struct wlan_bssid_ex *src, 352void update_network23a(struct wlan_bssid_ex *dst, struct wlan_bssid_ex *src,
357 struct rtw_adapter *padapter, bool update_ie) 353 struct rtw_adapter *padapter, bool update_ie)
358{ 354{
359 u8 ss_ori = dst->PhyInfo.SignalStrength; 355 u8 ss_ori = dst->SignalStrength;
360 u8 sq_ori = dst->PhyInfo.SignalQuality; 356 u8 sq_ori = dst->SignalQuality;
361 long rssi_ori = dst->Rssi; 357 long rssi_ori = dst->Rssi;
362 358
363 u8 ss_smp = src->PhyInfo.SignalStrength; 359 u8 ss_smp = src->SignalStrength;
364 u8 sq_smp = src->PhyInfo.SignalQuality; 360 u8 sq_smp = src->SignalQuality;
365 long rssi_smp = src->Rssi; 361 long rssi_smp = src->Rssi;
366 362
367 u8 ss_final; 363 u8 ss_final;
@@ -389,16 +385,16 @@ void update_network23a(struct wlan_bssid_ex *dst, struct wlan_bssid_ex *src,
389 rssi_final = rssi_ori; 385 rssi_final = rssi_ori;
390 } else { 386 } else {
391 if (sq_smp != 101) { /* from the right channel */ 387 if (sq_smp != 101) { /* from the right channel */
392 ss_final = ((u32)src->PhyInfo.SignalStrength + 388 ss_final = ((u32)src->SignalStrength +
393 (u32)dst->PhyInfo.SignalStrength * 4) / 5; 389 (u32)dst->SignalStrength * 4) / 5;
394 sq_final = ((u32)src->PhyInfo.SignalQuality + 390 sq_final = ((u32)src->SignalQuality +
395 (u32)dst->PhyInfo.SignalQuality * 4) / 5; 391 (u32)dst->SignalQuality * 4) / 5;
396 rssi_final = src->Rssi+dst->Rssi * 4 / 5; 392 rssi_final = src->Rssi+dst->Rssi * 4 / 5;
397 } else { 393 } else {
398 /* bss info not receiving from the right channel, use 394 /* bss info not receiving from the right channel, use
399 the original RX signal infos */ 395 the original RX signal infos */
400 ss_final = dst->PhyInfo.SignalStrength; 396 ss_final = dst->SignalStrength;
401 sq_final = dst->PhyInfo.SignalQuality; 397 sq_final = dst->SignalQuality;
402 rssi_final = dst->Rssi; 398 rssi_final = dst->Rssi;
403 } 399 }
404 400
@@ -407,14 +403,13 @@ void update_network23a(struct wlan_bssid_ex *dst, struct wlan_bssid_ex *src,
407 if (update_ie) 403 if (update_ie)
408 memcpy(dst, src, get_wlan_bssid_ex_sz(src)); 404 memcpy(dst, src, get_wlan_bssid_ex_sz(src));
409 405
410 dst->PhyInfo.SignalStrength = ss_final; 406 dst->SignalStrength = ss_final;
411 dst->PhyInfo.SignalQuality = sq_final; 407 dst->SignalQuality = sq_final;
412 dst->Rssi = rssi_final; 408 dst->Rssi = rssi_final;
413 409
414 DBG_8723A("%s %s(%pM), SignalStrength:%u, SignalQuality:%u, " 410 DBG_8723A("%s %s(%pM), SignalStrength:%u, SignalQuality:%u, "
415 "RawRSSI:%ld\n", __func__, dst->Ssid.ssid, dst->MacAddress, 411 "RawRSSI:%ld\n", __func__, dst->Ssid.ssid, dst->MacAddress,
416 dst->PhyInfo.SignalStrength, 412 dst->SignalStrength, dst->SignalQuality, dst->Rssi);
417 dst->PhyInfo.SignalQuality, dst->Rssi);
418} 413}
419 414
420static void update_current_network(struct rtw_adapter *adapter, 415static void update_current_network(struct rtw_adapter *adapter,
@@ -487,12 +482,11 @@ static void rtw_update_scanned_network(struct rtw_adapter *adapter,
487 pnetwork->last_scanned = jiffies; 482 pnetwork->last_scanned = jiffies;
488 483
489 pnetwork->network_type = 0; 484 pnetwork->network_type = 0;
490 pnetwork->aid = 0;
491 pnetwork->join_res = 0; 485 pnetwork->join_res = 0;
492 486
493 /* bss info not receiving from the right channel */ 487 /* bss info not receiving from the right channel */
494 if (pnetwork->network.PhyInfo.SignalQuality == 101) 488 if (pnetwork->network.SignalQuality == 101)
495 pnetwork->network.PhyInfo.SignalQuality = 0; 489 pnetwork->network.SignalQuality = 0;
496 } else { 490 } else {
497 /* 491 /*
498 * we have an entry and we are going to update it. But 492 * we have an entry and we are going to update it. But
@@ -579,8 +573,6 @@ void rtw_atimdone_event_callback23a(struct rtw_adapter *adapter, const u8 *pbuf)
579{ 573{
580 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_, 574 RT_TRACE(_module_rtl871x_mlme_c_, _drv_err_,
581 ("receive atimdone_evet\n")); 575 ("receive atimdone_evet\n"));
582
583 return;
584} 576}
585 577
586void rtw_survey_event_cb23a(struct rtw_adapter *adapter, const u8 *pbuf) 578void rtw_survey_event_cb23a(struct rtw_adapter *adapter, const u8 *pbuf)
@@ -650,8 +642,6 @@ exit:
650 642
651 kfree(survey->bss); 643 kfree(survey->bss);
652 survey->bss = NULL; 644 survey->bss = NULL;
653
654 return;
655} 645}
656 646
657void 647void
@@ -825,8 +815,6 @@ void rtw_indicate_connect23a(struct rtw_adapter *padapter)
825 if (!check_fwstate(&padapter->mlmepriv, _FW_LINKED)) { 815 if (!check_fwstate(&padapter->mlmepriv, _FW_LINKED)) {
826 set_fwstate(pmlmepriv, _FW_LINKED); 816 set_fwstate(pmlmepriv, _FW_LINKED);
827 817
828 rtw_led_control(padapter, LED_CTL_LINK);
829
830 rtw_cfg80211_indicate_connect(padapter); 818 rtw_cfg80211_indicate_connect(padapter);
831 819
832 netif_carrier_on(padapter->pnetdev); 820 netif_carrier_on(padapter->pnetdev);
@@ -871,10 +859,7 @@ void rtw_indicate_disconnect23a(struct rtw_adapter *padapter)
871 859
872 _clr_fwstate_(pmlmepriv, _FW_LINKED); 860 _clr_fwstate_(pmlmepriv, _FW_LINKED);
873 861
874 rtw_led_control(padapter, LED_CTL_NO_LINK);
875
876 rtw_clear_scan_deny(padapter); 862 rtw_clear_scan_deny(padapter);
877
878 } 863 }
879 864
880 rtw_lps_ctrl_wk_cmd23a(padapter, LPS_CTRL_DISCONNECT, 1); 865 rtw_lps_ctrl_wk_cmd23a(padapter, LPS_CTRL_DISCONNECT, 1);
@@ -1028,22 +1013,18 @@ rtw_joinbss_update_network23a(struct rtw_adapter *padapter,
1028 cur_network->network.beacon_interval = 1013 cur_network->network.beacon_interval =
1029 ptarget_wlan->network.beacon_interval; 1014 ptarget_wlan->network.beacon_interval;
1030 cur_network->network.tsf = ptarget_wlan->network.tsf; 1015 cur_network->network.tsf = ptarget_wlan->network.tsf;
1031 cur_network->aid = pnetwork->join_res;
1032 1016
1033 rtw_set_signal_stat_timer(&padapter->recvpriv); 1017 rtw_set_signal_stat_timer(&padapter->recvpriv);
1034 padapter->recvpriv.signal_strength = 1018 padapter->recvpriv.signal_strength =
1035 ptarget_wlan->network.PhyInfo.SignalStrength; 1019 ptarget_wlan->network.SignalStrength;
1036 padapter->recvpriv.signal_qual = 1020 padapter->recvpriv.signal_qual = ptarget_wlan->network.SignalQuality;
1037 ptarget_wlan->network.PhyInfo.SignalQuality;
1038 /* 1021 /*
1039 * the ptarget_wlan->network.Rssi is raw data, we use 1022 * the ptarget_wlan->network.Rssi is raw data, we use
1040 * ptarget_wlan->network.PhyInfo.SignalStrength instead (has scaled) 1023 * ptarget_wlan->network.SignalStrength instead (has scaled)
1041 */ 1024 */
1042 padapter->recvpriv.rssi = translate_percentage_to_dbm( 1025 DBG_8723A("%s signal_strength:%3u, signal_qual:%3u\n",
1043 ptarget_wlan->network.PhyInfo.SignalStrength);
1044 DBG_8723A("%s signal_strength:%3u, rssi:%3d, signal_qual:%3u\n",
1045 __func__, padapter->recvpriv.signal_strength, 1026 __func__, padapter->recvpriv.signal_strength,
1046 padapter->recvpriv.rssi, padapter->recvpriv.signal_qual); 1027 padapter->recvpriv.signal_qual);
1047 rtw_set_signal_stat_timer(&padapter->recvpriv); 1028 rtw_set_signal_stat_timer(&padapter->recvpriv);
1048 1029
1049 /* update fw_state will clr _FW_UNDER_LINKING here indirectly */ 1030 /* update fw_state will clr _FW_UNDER_LINKING here indirectly */
@@ -1132,7 +1113,7 @@ void rtw_joinbss_event_prehandle23a(struct rtw_adapter *adapter, u8 *pbuf)
1132 if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) { 1113 if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) {
1133 /* s1. find ptarget_wlan */ 1114 /* s1. find ptarget_wlan */
1134 if (check_fwstate(pmlmepriv, _FW_LINKED)) { 1115 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
1135 if (the_same_macaddr == true) { 1116 if (the_same_macaddr) {
1136 ptarget_wlan = rtw_find_network23a(&pmlmepriv->scanned_queue, cur_network->network.MacAddress); 1117 ptarget_wlan = rtw_find_network23a(&pmlmepriv->scanned_queue, cur_network->network.MacAddress);
1137 } else { 1118 } else {
1138 pcur_wlan = rtw_find_network23a(&pmlmepriv->scanned_queue, cur_network->network.MacAddress); 1119 pcur_wlan = rtw_find_network23a(&pmlmepriv->scanned_queue, cur_network->network.MacAddress);
@@ -1515,18 +1496,21 @@ out:
1515inline bool rtw_is_scan_deny(struct rtw_adapter *adapter) 1496inline bool rtw_is_scan_deny(struct rtw_adapter *adapter)
1516{ 1497{
1517 struct mlme_priv *mlmepriv = &adapter->mlmepriv; 1498 struct mlme_priv *mlmepriv = &adapter->mlmepriv;
1499
1518 return (atomic_read(&mlmepriv->set_scan_deny) != 0) ? true : false; 1500 return (atomic_read(&mlmepriv->set_scan_deny) != 0) ? true : false;
1519} 1501}
1520 1502
1521void rtw_clear_scan_deny(struct rtw_adapter *adapter) 1503void rtw_clear_scan_deny(struct rtw_adapter *adapter)
1522{ 1504{
1523 struct mlme_priv *mlmepriv = &adapter->mlmepriv; 1505 struct mlme_priv *mlmepriv = &adapter->mlmepriv;
1506
1524 atomic_set(&mlmepriv->set_scan_deny, 0); 1507 atomic_set(&mlmepriv->set_scan_deny, 0);
1525} 1508}
1526 1509
1527void rtw_set_scan_deny_timer_hdl(unsigned long data) 1510void rtw_set_scan_deny_timer_hdl(unsigned long data)
1528{ 1511{
1529 struct rtw_adapter *adapter = (struct rtw_adapter *)data; 1512 struct rtw_adapter *adapter = (struct rtw_adapter *)data;
1513
1530 rtw_clear_scan_deny(adapter); 1514 rtw_clear_scan_deny(adapter);
1531} 1515}
1532 1516
@@ -1540,7 +1524,8 @@ void rtw_set_scan_deny(struct rtw_adapter *adapter, u32 ms)
1540} 1524}
1541 1525
1542#if defined(IEEE80211_SCAN_RESULT_EXPIRE) 1526#if defined(IEEE80211_SCAN_RESULT_EXPIRE)
1543#define RTW_SCAN_RESULT_EXPIRE IEEE80211_SCAN_RESULT_EXPIRE/HZ*1000 -1000 /* 3000 -1000 */ 1527#define RTW_SCAN_RESULT_EXPIRE \
1528 ((IEEE80211_SCAN_RESULT_EXPIRE / (HZ*1000)) - 1000) /* 3000 -1000 */
1544#else 1529#else
1545#define RTW_SCAN_RESULT_EXPIRE 2000 1530#define RTW_SCAN_RESULT_EXPIRE 2000
1546#endif 1531#endif
@@ -1766,7 +1751,7 @@ exit:
1766 return ret; 1751 return ret;
1767} 1752}
1768 1753
1769int rtw_set_auth23a(struct rtw_adapter * adapter, 1754int rtw_set_auth23a(struct rtw_adapter *adapter,
1770 struct security_priv *psecuritypriv) 1755 struct security_priv *psecuritypriv)
1771{ 1756{
1772 struct cmd_obj *pcmd; 1757 struct cmd_obj *pcmd;
@@ -2151,6 +2136,7 @@ bool rtw_restructure_ht_ie23a(struct rtw_adapter *padapter, u8 *in_ie,
2151 2136
2152 if (p && p[1] > 0) { 2137 if (p && p[1] > 0) {
2153 u32 rx_packet_offset, max_recvbuf_sz; 2138 u32 rx_packet_offset, max_recvbuf_sz;
2139
2154 if (pmlmepriv->qos_option == 0) { 2140 if (pmlmepriv->qos_option == 0) {
2155 out_len = *pout_len; 2141 out_len = *pout_len;
2156 pframe = rtw_set_ie23a(out_ie + out_len, 2142 pframe = rtw_set_ie23a(out_ie + out_len,
@@ -2165,9 +2151,9 @@ bool rtw_restructure_ht_ie23a(struct rtw_adapter *padapter, u8 *in_ie,
2165 2151
2166 memset(&ht_capie, 0, sizeof(struct ieee80211_ht_cap)); 2152 memset(&ht_capie, 0, sizeof(struct ieee80211_ht_cap));
2167 2153
2168 ht_capie.cap_info = IEEE80211_HT_CAP_SUP_WIDTH_20_40 | 2154 ht_capie.cap_info = cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
2169 IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40 | 2155 IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40 |
2170 IEEE80211_HT_CAP_TX_STBC | IEEE80211_HT_CAP_DSSSCCK40; 2156 IEEE80211_HT_CAP_TX_STBC | IEEE80211_HT_CAP_DSSSCCK40);
2171 2157
2172 GetHalDefVar8192CUsb(padapter, HAL_DEF_RX_PACKET_OFFSET, 2158 GetHalDefVar8192CUsb(padapter, HAL_DEF_RX_PACKET_OFFSET,
2173 &rx_packet_offset); 2159 &rx_packet_offset);
diff --git a/drivers/staging/rtl8723au/core/rtw_mlme_ext.c b/drivers/staging/rtl8723au/core/rtw_mlme_ext.c
index 3eb77de17e3a..0e0f73c86e53 100644
--- a/drivers/staging/rtl8723au/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8723au/core/rtw_mlme_ext.c
@@ -331,6 +331,7 @@ rtw_update_TSF(struct mlme_ext_priv *pmlmeext, struct ieee80211_mgmt *mgmt)
331int rtw_ch_set_search_ch23a(struct rt_channel_info *ch_set, const u32 ch) 331int rtw_ch_set_search_ch23a(struct rt_channel_info *ch_set, const u32 ch)
332{ 332{
333 int i; 333 int i;
334
334 for (i = 0; ch_set[i]. ChannelNum != 0; i++) { 335 for (i = 0; ch_set[i]. ChannelNum != 0; i++) {
335 if (ch == ch_set[i].ChannelNum) 336 if (ch == ch_set[i].ChannelNum)
336 break; 337 break;
@@ -566,7 +567,6 @@ static u8 init_channel_set(struct rtw_adapter *padapter, u8 cplan,
566 567
567int init_mlme_ext_priv23a(struct rtw_adapter *padapter) 568int init_mlme_ext_priv23a(struct rtw_adapter *padapter)
568{ 569{
569 int res = _SUCCESS;
570 struct registry_priv *pregistrypriv = &padapter->registrypriv; 570 struct registry_priv *pregistrypriv = &padapter->registrypriv;
571 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 571 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
572 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 572 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
@@ -593,7 +593,7 @@ int init_mlme_ext_priv23a(struct rtw_adapter *padapter)
593 pmlmeext->mlmeext_init = true; 593 pmlmeext->mlmeext_init = true;
594 594
595 pmlmeext->active_keep_alive_check = true; 595 pmlmeext->active_keep_alive_check = true;
596 return res; 596 return _SUCCESS;
597} 597}
598 598
599void free_mlme_ext_priv23a (struct mlme_ext_priv *pmlmeext) 599void free_mlme_ext_priv23a (struct mlme_ext_priv *pmlmeext)
@@ -680,8 +680,7 @@ void mgt_dispatcher23a(struct rtw_adapter *padapter,
680 } 680 }
681 681
682#ifdef CONFIG_8723AU_AP_MODE 682#ifdef CONFIG_8723AU_AP_MODE
683 switch (stype) 683 switch (stype) {
684 {
685 case IEEE80211_STYPE_AUTH: 684 case IEEE80211_STYPE_AUTH:
686 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) 685 if (check_fwstate(pmlmepriv, WIFI_AP_STATE))
687 ptable->func = &OnAuth23a; 686 ptable->func = &OnAuth23a;
@@ -1572,6 +1571,7 @@ OnAssocReq23a(struct rtw_adapter *padapter, struct recv_frame *precv_frame)
1572 pstat->uapsd_bk = 0; 1571 pstat->uapsd_bk = 0;
1573 if (pmlmepriv->qos_option) { 1572 if (pmlmepriv->qos_option) {
1574 const u8 *end = pos + left; 1573 const u8 *end = pos + left;
1574
1575 p = pos; 1575 p = pos;
1576 1576
1577 for (;;) { 1577 for (;;) {
@@ -2335,12 +2335,9 @@ static int update_hidden_ssid(u8 *ies, u32 ies_len, u8 hidden_ssid_mode)
2335 __func__, hidden_ssid_mode, ssid_ie, ssid_len_ori); */ 2335 __func__, hidden_ssid_mode, ssid_ie, ssid_len_ori); */
2336 2336
2337 if (ssid_ie && ssid_len_ori > 0) { 2337 if (ssid_ie && ssid_len_ori > 0) {
2338 switch (hidden_ssid_mode) 2338 switch (hidden_ssid_mode) {
2339 {
2340 case 1: 2339 case 1:
2341 next_ie = ssid_ie + 2 + ssid_len_ori; 2340 next_ie = ssid_ie + 2 + ssid_len_ori;
2342 remain_len = 0;
2343
2344 remain_len = ies_len -(next_ie-ies); 2341 remain_len = ies_len -(next_ie-ies);
2345 2342
2346 ssid_ie[1] = 0; 2343 ssid_ie[1] = 0;
@@ -2599,7 +2596,9 @@ static void issue_probersp(struct rtw_adapter *padapter, unsigned char *da,
2599 if (ssid_ie && cur_network->Ssid.ssid_len) { 2596 if (ssid_ie && cur_network->Ssid.ssid_len) {
2600 uint remainder_ielen; 2597 uint remainder_ielen;
2601 u8 *remainder_ie; 2598 u8 *remainder_ie;
2599
2602 remainder_ie = ssid_ie + 2; 2600 remainder_ie = ssid_ie + 2;
2601
2603 remainder_ielen = pframe - remainder_ie; 2602 remainder_ielen = pframe - remainder_ie;
2604 2603
2605 DBG_8723A_LEVEL(_drv_warning_, "%s(%s): " 2604 DBG_8723A_LEVEL(_drv_warning_, "%s(%s): "
@@ -2862,6 +2861,7 @@ static void issue_auth(struct rtw_adapter *padapter, struct sta_info *psta,
2862 if (psta) { /* for AP mode */ 2861 if (psta) { /* for AP mode */
2863#ifdef CONFIG_8723AU_AP_MODE 2862#ifdef CONFIG_8723AU_AP_MODE
2864 unsigned short val16; 2863 unsigned short val16;
2864
2865 ether_addr_copy(mgmt->da, psta->hwaddr); 2865 ether_addr_copy(mgmt->da, psta->hwaddr);
2866 ether_addr_copy(mgmt->sa, myid(&padapter->eeprompriv)); 2866 ether_addr_copy(mgmt->sa, myid(&padapter->eeprompriv));
2867 ether_addr_copy(mgmt->bssid, myid(&padapter->eeprompriv)); 2867 ether_addr_copy(mgmt->bssid, myid(&padapter->eeprompriv));
@@ -3306,6 +3306,7 @@ static void issue_assocreq(struct rtw_adapter *padapter)
3306 !memcmp(p + 2, WMM_OUI23A, 4) || 3306 !memcmp(p + 2, WMM_OUI23A, 4) ||
3307 !memcmp(p + 2, WPS_OUI23A, 4)) { 3307 !memcmp(p + 2, WPS_OUI23A, 4)) {
3308 u8 plen = p[1]; 3308 u8 plen = p[1];
3309
3309 if (!padapter->registrypriv.wifi_spec) { 3310 if (!padapter->registrypriv.wifi_spec) {
3310 /* Commented by Kurt 20110629 */ 3311 /* Commented by Kurt 20110629 */
3311 /* In some older APs, WPS handshake */ 3312 /* In some older APs, WPS handshake */
@@ -3997,7 +3998,7 @@ int send_beacon23a(struct rtw_adapter *padapter)
3997 yield(); 3998 yield();
3998 bxmitok = rtl8723a_get_bcn_valid(padapter); 3999 bxmitok = rtl8723a_get_bcn_valid(padapter);
3999 poll++; 4000 poll++;
4000 } while ((poll % 10) != 0 && bxmitok == false && 4001 } while ((poll % 10) != 0 && !bxmitok &&
4001 !padapter->bSurpriseRemoved && 4002 !padapter->bSurpriseRemoved &&
4002 !padapter->bDriverStopped); 4003 !padapter->bDriverStopped);
4003 4004
@@ -4070,6 +4071,7 @@ static void rtw_site_survey(struct rtw_adapter *padapter)
4070 if (ScanType == SCAN_ACTIVE) /* obey the channel plan setting... */ 4071 if (ScanType == SCAN_ACTIVE) /* obey the channel plan setting... */
4071 { 4072 {
4072 int i; 4073 int i;
4074
4073 for (i = 0;i<RTW_SSID_SCAN_AMOUNT;i++) { 4075 for (i = 0;i<RTW_SSID_SCAN_AMOUNT;i++) {
4074 if (pmlmeext->sitesurvey_res.ssid[i].ssid_len) { 4076 if (pmlmeext->sitesurvey_res.ssid[i].ssid_len) {
4075 /* todo: to issue two probe req??? */ 4077 /* todo: to issue two probe req??? */
@@ -4197,9 +4199,9 @@ static struct wlan_bssid_ex *collect_bss_info(struct rtw_adapter *padapter,
4197 /* get the signal strength */ 4199 /* get the signal strength */
4198 /* in dBM.raw data */ 4200 /* in dBM.raw data */
4199 bssid->Rssi = precv_frame->attrib.phy_info.RecvSignalPower; 4201 bssid->Rssi = precv_frame->attrib.phy_info.RecvSignalPower;
4200 bssid->PhyInfo.SignalQuality = 4202 bssid->SignalQuality =
4201 precv_frame->attrib.phy_info.SignalQuality;/* in percentage */ 4203 precv_frame->attrib.phy_info.SignalQuality;/* in percentage */
4202 bssid->PhyInfo.SignalStrength = 4204 bssid->SignalStrength =
4203 precv_frame->attrib.phy_info.SignalStrength;/* in percentage */ 4205 precv_frame->attrib.phy_info.SignalStrength;/* in percentage */
4204 4206
4205 /* checking SSID */ 4207 /* checking SSID */
@@ -4293,6 +4295,7 @@ static struct wlan_bssid_ex *collect_bss_info(struct rtw_adapter *padapter,
4293 bssid->IELength); 4295 bssid->IELength);
4294 if (p && p[1] > 0) { 4296 if (p && p[1] > 0) {
4295 struct ieee80211_ht_cap *pHT_caps; 4297 struct ieee80211_ht_cap *pHT_caps;
4298
4296 pHT_caps = (struct ieee80211_ht_cap *)(p + 2); 4299 pHT_caps = (struct ieee80211_ht_cap *)(p + 2);
4297 4300
4298 if (pHT_caps->cap_info & 4301 if (pHT_caps->cap_info &
@@ -4305,7 +4308,7 @@ static struct wlan_bssid_ex *collect_bss_info(struct rtw_adapter *padapter,
4305 4308
4306 /* mark bss info receiving from nearby channel as SignalQuality 101 */ 4309 /* mark bss info receiving from nearby channel as SignalQuality 101 */
4307 if (bssid->DSConfig != rtw_get_oper_ch23a(padapter)) 4310 if (bssid->DSConfig != rtw_get_oper_ch23a(padapter))
4308 bssid->PhyInfo.SignalQuality = 101; 4311 bssid->SignalQuality = 101;
4309 4312
4310 return bssid; 4313 return bssid;
4311fail: 4314fail:
@@ -4319,6 +4322,7 @@ static void start_create_ibss(struct rtw_adapter *padapter)
4319 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 4322 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
4320 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; 4323 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
4321 struct wlan_bssid_ex *pnetwork = &pmlmeinfo->network; 4324 struct wlan_bssid_ex *pnetwork = &pmlmeinfo->network;
4325
4322 pmlmeext->cur_channel = (u8)pnetwork->DSConfig; 4326 pmlmeext->cur_channel = (u8)pnetwork->DSConfig;
4323 pmlmeinfo->bcn_interval = pnetwork->beacon_interval; 4327 pmlmeinfo->bcn_interval = pnetwork->beacon_interval;
4324 4328
@@ -4354,9 +4358,7 @@ static void start_create_ibss(struct rtw_adapter *padapter)
4354 report_join_res23a(padapter, 1); 4358 report_join_res23a(padapter, 1);
4355 pmlmeinfo->state |= WIFI_FW_ASSOC_SUCCESS; 4359 pmlmeinfo->state |= WIFI_FW_ASSOC_SUCCESS;
4356 } 4360 }
4357 } 4361 } else {
4358 else
4359 {
4360 DBG_8723A("%s: invalid cap:%x\n", __func__, caps); 4362 DBG_8723A("%s: invalid cap:%x\n", __func__, caps);
4361 return; 4363 return;
4362 } 4364 }
@@ -4414,9 +4416,7 @@ static void start_clnt_join(struct rtw_adapter *padapter)
4414 pmlmeinfo->state = MSR_ADHOC; 4416 pmlmeinfo->state = MSR_ADHOC;
4415 4417
4416 report_join_res23a(padapter, 1); 4418 report_join_res23a(padapter, 1);
4417 } 4419 } else {
4418 else
4419 {
4420 /* DBG_8723A("marc: invalid cap:%x\n", caps); */ 4420 /* DBG_8723A("marc: invalid cap:%x\n", caps); */
4421 return; 4421 return;
4422 } 4422 }
@@ -4480,16 +4480,12 @@ int receive_disconnect23a(struct rtw_adapter *padapter,
4480 4480
4481 DBG_8723A("%s\n", __func__); 4481 DBG_8723A("%s\n", __func__);
4482 4482
4483 if ((pmlmeinfo->state&0x03) == MSR_INFRA) 4483 if ((pmlmeinfo->state&0x03) == MSR_INFRA) {
4484 { 4484 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) {
4485 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS)
4486 {
4487 pmlmeinfo->state = MSR_NOLINK; 4485 pmlmeinfo->state = MSR_NOLINK;
4488 report_del_sta_event23a(padapter, MacAddr, reason); 4486 report_del_sta_event23a(padapter, MacAddr, reason);
4489 4487
4490 } 4488 } else if (pmlmeinfo->state & WIFI_FW_LINKING_STATE) {
4491 else if (pmlmeinfo->state & WIFI_FW_LINKING_STATE)
4492 {
4493 pmlmeinfo->state = MSR_NOLINK; 4489 pmlmeinfo->state = MSR_NOLINK;
4494 report_join_res23a(padapter, -2); 4490 report_join_res23a(padapter, -2);
4495 } 4491 }
@@ -4866,7 +4862,7 @@ void report_join_res23a(struct rtw_adapter *padapter, int res)
4866 pjoinbss_evt = (struct joinbss_event*)(pevtcmd + sizeof(struct C2HEvent_Header)); 4862 pjoinbss_evt = (struct joinbss_event*)(pevtcmd + sizeof(struct C2HEvent_Header));
4867 memcpy((unsigned char *)&pjoinbss_evt->network.network, 4863 memcpy((unsigned char *)&pjoinbss_evt->network.network,
4868 &pmlmeinfo->network, sizeof(struct wlan_bssid_ex)); 4864 &pmlmeinfo->network, sizeof(struct wlan_bssid_ex));
4869 pjoinbss_evt->network.join_res = pjoinbss_evt->network.aid = res; 4865 pjoinbss_evt->network.join_res = res;
4870 4866
4871 DBG_8723A("report_join_res23a(%d)\n", res); 4867 DBG_8723A("report_join_res23a(%d)\n", res);
4872 4868
@@ -4995,8 +4991,7 @@ void update_sta_info23a(struct rtw_adapter *padapter, struct sta_info *psta)
4995 VCS_update23a(padapter, psta); 4991 VCS_update23a(padapter, psta);
4996 4992
4997 /* HT */ 4993 /* HT */
4998 if (pmlmepriv->htpriv.ht_option) 4994 if (pmlmepriv->htpriv.ht_option) {
4999 {
5000 psta->htpriv.ht_option = true; 4995 psta->htpriv.ht_option = true;
5001 4996
5002 psta->htpriv.ampdu_enable = pmlmepriv->htpriv.ampdu_enable; 4997 psta->htpriv.ampdu_enable = pmlmepriv->htpriv.ampdu_enable;
@@ -5006,9 +5001,7 @@ void update_sta_info23a(struct rtw_adapter *padapter, struct sta_info *psta)
5006 5001
5007 psta->qos_option = true; 5002 psta->qos_option = true;
5008 5003
5009 } 5004 } else {
5010 else
5011 {
5012 psta->htpriv.ht_option = false; 5005 psta->htpriv.ht_option = false;
5013 5006
5014 psta->htpriv.ampdu_enable = false; 5007 psta->htpriv.ampdu_enable = false;
@@ -5050,12 +5043,10 @@ void mlmeext_joinbss_event_callback23a(struct rtw_adapter *padapter,
5050 goto exit_mlmeext_joinbss_event_callback23a; 5043 goto exit_mlmeext_joinbss_event_callback23a;
5051 } 5044 }
5052 5045
5053 if ((pmlmeinfo->state&0x03) == MSR_ADHOC) 5046 if ((pmlmeinfo->state&0x03) == MSR_ADHOC) {
5054 {
5055 /* for bc/mc */ 5047 /* for bc/mc */
5056 psta_bmc = rtw_get_bcmc_stainfo23a(padapter); 5048 psta_bmc = rtw_get_bcmc_stainfo23a(padapter);
5057 if (psta_bmc) 5049 if (psta_bmc) {
5058 {
5059 pmlmeinfo->FW_sta_info[psta_bmc->mac_id].psta = psta_bmc; 5050 pmlmeinfo->FW_sta_info[psta_bmc->mac_id].psta = psta_bmc;
5060 update_bmc_sta_support_rate23a(padapter, psta_bmc->mac_id); 5051 update_bmc_sta_support_rate23a(padapter, psta_bmc->mac_id);
5061 Update_RA_Entry23a(padapter, psta_bmc); 5052 Update_RA_Entry23a(padapter, psta_bmc);
@@ -5086,8 +5077,7 @@ void mlmeext_joinbss_event_callback23a(struct rtw_adapter *padapter,
5086 set_channel_bwmode23a(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode); 5077 set_channel_bwmode23a(padapter, pmlmeext->cur_channel, pmlmeext->cur_ch_offset, pmlmeext->cur_bwmode);
5087 5078
5088 psta = rtw_get_stainfo23a(pstapriv, cur_network->MacAddress); 5079 psta = rtw_get_stainfo23a(pstapriv, cur_network->MacAddress);
5089 if (psta) /* only for infra. mode */ 5080 if (psta) { /* only for infra. mode */
5090 {
5091 pmlmeinfo->FW_sta_info[psta->mac_id].psta = psta; 5081 pmlmeinfo->FW_sta_info[psta->mac_id].psta = psta;
5092 5082
5093 /* DBG_8723A("set_sta_rate23a\n"); */ 5083 /* DBG_8723A("set_sta_rate23a\n"); */
@@ -5123,8 +5113,7 @@ void mlmeext_sta_add_event_callback23a(struct rtw_adapter *padapter,
5123 5113
5124 if ((pmlmeinfo->state & 0x03) == MSR_ADHOC) { 5114 if ((pmlmeinfo->state & 0x03) == MSR_ADHOC) {
5125 /* adhoc master or sta_count>1 */ 5115 /* adhoc master or sta_count>1 */
5126 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) 5116 if (pmlmeinfo->state & WIFI_FW_ASSOC_SUCCESS) {
5127 {
5128 /* nothing to do */ 5117 /* nothing to do */
5129 } else { /* adhoc client */ 5118 } else { /* adhoc client */
5130 /* correcting TSF */ 5119 /* correcting TSF */
diff --git a/drivers/staging/rtl8723au/core/rtw_pwrctrl.c b/drivers/staging/rtl8723au/core/rtw_pwrctrl.c
index 1b2af7381d82..e2d51afe522c 100644
--- a/drivers/staging/rtl8723au/core/rtw_pwrctrl.c
+++ b/drivers/staging/rtl8723au/core/rtw_pwrctrl.c
@@ -159,7 +159,7 @@ void rtw_ps_processor23a(struct rtw_adapter *padapter)
159 if (pwrpriv->ips_mode_req == IPS_NONE) 159 if (pwrpriv->ips_mode_req == IPS_NONE)
160 goto exit; 160 goto exit;
161 161
162 if (rtw_pwr_unassociated_idle(padapter) == false) 162 if (!rtw_pwr_unassociated_idle(padapter))
163 goto exit; 163 goto exit;
164 164
165 if (pwrpriv->rf_pwrstate == rf_on && 165 if (pwrpriv->rf_pwrstate == rf_on &&
@@ -172,12 +172,12 @@ void rtw_ps_processor23a(struct rtw_adapter *padapter)
172exit: 172exit:
173 rtw_set_pwr_state_check_timer(&padapter->pwrctrlpriv); 173 rtw_set_pwr_state_check_timer(&padapter->pwrctrlpriv);
174 pwrpriv->ps_processing = false; 174 pwrpriv->ps_processing = false;
175 return;
176} 175}
177 176
178static void pwr_state_check_handler(unsigned long data) 177static void pwr_state_check_handler(unsigned long data)
179{ 178{
180 struct rtw_adapter *padapter = (struct rtw_adapter *)data; 179 struct rtw_adapter *padapter = (struct rtw_adapter *)data;
180
181 rtw_ps_cmd23a(padapter); 181 rtw_ps_cmd23a(padapter);
182} 182}
183 183
@@ -338,8 +338,7 @@ s32 LPS_RF_ON_check23a(struct rtw_adapter *padapter, u32 delay_ms)
338 start_time = jiffies; 338 start_time = jiffies;
339 end_time = start_time + msecs_to_jiffies(delay_ms); 339 end_time = start_time + msecs_to_jiffies(delay_ms);
340 340
341 while (1) 341 while (1) {
342 {
343 bAwake = rtl8723a_get_fwlps_rf_on(padapter); 342 bAwake = rtl8723a_get_fwlps_rf_on(padapter);
344 if (bAwake == true) 343 if (bAwake == true)
345 break; 344 break;
@@ -470,6 +469,7 @@ void rtw_free_pwrctrl_priv(struct rtw_adapter *adapter)
470inline void rtw_set_ips_deny23a(struct rtw_adapter *padapter, u32 ms) 469inline void rtw_set_ips_deny23a(struct rtw_adapter *padapter, u32 ms)
471{ 470{
472 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv; 471 struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
472
473 pwrpriv->ips_deny_time = jiffies + msecs_to_jiffies(ms); 473 pwrpriv->ips_deny_time = jiffies + msecs_to_jiffies(ms);
474} 474}
475 475
diff --git a/drivers/staging/rtl8723au/core/rtw_recv.c b/drivers/staging/rtl8723au/core/rtw_recv.c
index 5bc7734d9a72..559dddee2648 100644
--- a/drivers/staging/rtl8723au/core/rtw_recv.c
+++ b/drivers/staging/rtl8723au/core/rtw_recv.c
@@ -215,6 +215,7 @@ u32 rtw_free_uc_swdec_pending_queue23a(struct rtw_adapter *adapter)
215{ 215{
216 u32 cnt = 0; 216 u32 cnt = 0;
217 struct recv_frame *pending_frame; 217 struct recv_frame *pending_frame;
218
218 while ((pending_frame = rtw_alloc_recvframe23a(&adapter->recvpriv.uc_swdec_pending_queue))) { 219 while ((pending_frame = rtw_alloc_recvframe23a(&adapter->recvpriv.uc_swdec_pending_queue))) {
219 rtw_free_recvframe23a(pending_frame); 220 rtw_free_recvframe23a(pending_frame);
220 DBG_8723A("%s: dequeue uc_swdec_pending_queue\n", __func__); 221 DBG_8723A("%s: dequeue uc_swdec_pending_queue\n", __func__);
@@ -239,6 +240,7 @@ int rtw_enqueue_recvbuf23a_to_head(struct recv_buf *precvbuf, struct rtw_queue *
239int rtw_enqueue_recvbuf23a(struct recv_buf *precvbuf, struct rtw_queue *queue) 240int rtw_enqueue_recvbuf23a(struct recv_buf *precvbuf, struct rtw_queue *queue)
240{ 241{
241 unsigned long irqL; 242 unsigned long irqL;
243
242 spin_lock_irqsave(&queue->lock, irqL); 244 spin_lock_irqsave(&queue->lock, irqL);
243 245
244 list_del_init(&precvbuf->list); 246 list_del_init(&precvbuf->list);
@@ -364,6 +366,7 @@ int recvframe_chkmic(struct rtw_adapter *adapter,
364 366
365 if (bmic_err == true) { 367 if (bmic_err == true) {
366 int i; 368 int i;
369
367 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, 370 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
368 ("\n *(pframemic-8)-*(pframemic-1) =" 371 ("\n *(pframemic-8)-*(pframemic-1) ="
369 "0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:" 372 "0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:"
@@ -483,6 +486,7 @@ struct recv_frame *decryptor(struct rtw_adapter *padapter,
483 486
484 if (prxattrib->encrypt > 0) { 487 if (prxattrib->encrypt > 0) {
485 u8 *iv = precv_frame->pkt->data + prxattrib->hdrlen; 488 u8 *iv = precv_frame->pkt->data + prxattrib->hdrlen;
489
486 prxattrib->key_index = (((iv[3]) >> 6) & 0x3); 490 prxattrib->key_index = (((iv[3]) >> 6) & 0x3);
487 491
488 if (prxattrib->key_index > WEP_KEYS) { 492 if (prxattrib->key_index > WEP_KEYS) {
@@ -564,59 +568,27 @@ static struct recv_frame *portctrl(struct rtw_adapter *adapter,
564 ("########portctrl:adapter->securitypriv.dot11AuthAlgrthm =" 568 ("########portctrl:adapter->securitypriv.dot11AuthAlgrthm ="
565 "%d\n", adapter->securitypriv.dot11AuthAlgrthm)); 569 "%d\n", adapter->securitypriv.dot11AuthAlgrthm));
566 570
571 prtnframe = precv_frame;
572
567 if (auth_alg == dot11AuthAlgrthm_8021X) { 573 if (auth_alg == dot11AuthAlgrthm_8021X) {
568 /* get ether_type */ 574 /* get ether_type */
569 ptr = pfhdr->pkt->data + pfhdr->attrib.hdrlen; 575 ptr = pfhdr->pkt->data + pfhdr->attrib.hdrlen;
570 576
571 ether_type = (ptr[6] << 8) | ptr[7]; 577 ether_type = (ptr[6] << 8) | ptr[7];
572 578
573 if ((psta != NULL) && (psta->ieee8021x_blocked)) { 579 if (psta && psta->ieee8021x_blocked) {
574 /* blocked */ 580 /* blocked */
575 /* only accept EAPOL frame */ 581 /* only accept EAPOL frame */
576 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, 582 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
577 ("########portctrl:psta->ieee8021x_blocked ==" 583 ("########portctrl:psta->ieee8021x_blocked =="
578 "1\n")); 584 "1\n"));
579 585
580 if (ether_type == eapol_type) { 586 if (ether_type != eapol_type) {
581 prtnframe = precv_frame;
582 } else {
583 /* free this frame */ 587 /* free this frame */
584 rtw_free_recvframe23a(precv_frame); 588 rtw_free_recvframe23a(precv_frame);
585 prtnframe = NULL; 589 prtnframe = NULL;
586 } 590 }
587 } else {
588 /* allowed */
589 /* check decryption status, and decrypt the frame if needed */
590 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
591 ("########portctrl:psta->ieee8021x_blocked =="
592 "0\n"));
593 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
594 ("portctrl:precv_frame->hdr.attrib.privacy ="
595 "%x\n", precv_frame->attrib.privacy));
596
597 if (pattrib->bdecrypted == 0) {
598 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
599 ("portctrl:prxstat->decrypted =%x\n",
600 pattrib->bdecrypted));
601 }
602
603 prtnframe = precv_frame;
604 /* check is the EAPOL frame or not (Rekey) */
605 if (ether_type == eapol_type) {
606 RT_TRACE(_module_rtl871x_recv_c_, _drv_notice_,
607 ("########portctrl:ether_type == "
608 "0x888e\n"));
609 /* check Rekey */
610
611 prtnframe = precv_frame;
612 } else {
613 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
614 ("########portctrl:ether_type = 0x%04x"
615 "\n", ether_type));
616 }
617 } 591 }
618 } else {
619 prtnframe = precv_frame;
620 } 592 }
621 593
622 return prtnframe; 594 return prtnframe;
@@ -1066,6 +1038,7 @@ int sta2ap_data_frame(struct rtw_adapter *adapter,
1066 } 1038 }
1067 } else { 1039 } else {
1068 u8 *myhwaddr = myid(&adapter->eeprompriv); 1040 u8 *myhwaddr = myid(&adapter->eeprompriv);
1041
1069 if (!ether_addr_equal(pattrib->ra, myhwaddr)) { 1042 if (!ether_addr_equal(pattrib->ra, myhwaddr)) {
1070 ret = RTW_RX_HANDLED; 1043 ret = RTW_RX_HANDLED;
1071 goto exit; 1044 goto exit;
@@ -1405,8 +1378,7 @@ static int validate_recv_data_frame(struct rtw_adapter *adapter,
1405 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_, 1378 RT_TRACE(_module_rtl871x_recv_c_, _drv_info_,
1406 ("\n pattrib->encrypt =%d\n", pattrib->encrypt)); 1379 ("\n pattrib->encrypt =%d\n", pattrib->encrypt));
1407 1380
1408 switch (pattrib->encrypt) 1381 switch (pattrib->encrypt) {
1409 {
1410 case WLAN_CIPHER_SUITE_WEP40: 1382 case WLAN_CIPHER_SUITE_WEP40:
1411 case WLAN_CIPHER_SUITE_WEP104: 1383 case WLAN_CIPHER_SUITE_WEP104:
1412 pattrib->iv_len = IEEE80211_WEP_IV_LEN; 1384 pattrib->iv_len = IEEE80211_WEP_IV_LEN;
@@ -1505,8 +1477,7 @@ static int validate_recv_frame(struct rtw_adapter *adapter,
1505 if (unlikely(bDumpRxPkt == 1)) 1477 if (unlikely(bDumpRxPkt == 1))
1506 dump_rx_pkt(skb, type, bDumpRxPkt); 1478 dump_rx_pkt(skb, type, bDumpRxPkt);
1507 1479
1508 switch (type) 1480 switch (type) {
1509 {
1510 case IEEE80211_FTYPE_MGMT: 1481 case IEEE80211_FTYPE_MGMT:
1511 retval = validate_recv_mgnt_frame(adapter, precv_frame); 1482 retval = validate_recv_mgnt_frame(adapter, precv_frame);
1512 if (retval == _FAIL) { 1483 if (retval == _FAIL) {
@@ -1524,7 +1495,6 @@ static int validate_recv_frame(struct rtw_adapter *adapter,
1524 retval = _FAIL; /* only data frame return _SUCCESS */ 1495 retval = _FAIL; /* only data frame return _SUCCESS */
1525 break; 1496 break;
1526 case IEEE80211_FTYPE_DATA: 1497 case IEEE80211_FTYPE_DATA:
1527 rtw_led_control(adapter, LED_CTL_RX);
1528 pattrib->qos = (subtype & IEEE80211_STYPE_QOS_DATA) ? 1 : 0; 1498 pattrib->qos = (subtype & IEEE80211_STYPE_QOS_DATA) ? 1 : 0;
1529 retval = validate_recv_data_frame(adapter, precv_frame); 1499 retval = validate_recv_data_frame(adapter, precv_frame);
1530 if (retval == _FAIL) { 1500 if (retval == _FAIL) {
@@ -1551,8 +1521,6 @@ static int wlanhdr_to_ethhdr (struct recv_frame *precvframe)
1551 u16 eth_type, len, hdrlen; 1521 u16 eth_type, len, hdrlen;
1552 u8 bsnaphdr; 1522 u8 bsnaphdr;
1553 u8 *psnap; 1523 u8 *psnap;
1554
1555 int ret = _SUCCESS;
1556 struct rtw_adapter *adapter = precvframe->adapter; 1524 struct rtw_adapter *adapter = precvframe->adapter;
1557 struct mlme_priv *pmlmepriv = &adapter->mlmepriv; 1525 struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
1558 1526
@@ -1613,7 +1581,7 @@ static int wlanhdr_to_ethhdr (struct recv_frame *precvframe)
1613 } 1581 }
1614 1582
1615 1583
1616 return ret; 1584 return _SUCCESS;
1617} 1585}
1618 1586
1619/* perform defrag */ 1587/* perform defrag */
@@ -1691,7 +1659,7 @@ struct recv_frame *recvframe_defrag(struct rtw_adapter *adapter,
1691 skb_put(skb, pnfhdr->pkt->len); 1659 skb_put(skb, pnfhdr->pkt->len);
1692 1660
1693 prframe->attrib.icv_len = pnfhdr->attrib.icv_len; 1661 prframe->attrib.icv_len = pnfhdr->attrib.icv_len;
1694 }; 1662 }
1695 1663
1696 /* free the defrag_q queue and return the prframe */ 1664 /* free the defrag_q queue and return the prframe */
1697 rtw_free_recvframe23a_queue(defrag_q); 1665 rtw_free_recvframe23a_queue(defrag_q);
@@ -2177,8 +2145,7 @@ int process_recv_indicatepkts(struct rtw_adapter *padapter,
2177 return retval; 2145 return retval;
2178 } 2146 }
2179 } 2147 }
2180 } else /* B/G mode */ 2148 } else { /* B/G mode */
2181 {
2182 retval = wlanhdr_to_ethhdr(prframe); 2149 retval = wlanhdr_to_ethhdr(prframe);
2183 if (retval != _SUCCESS) { 2150 if (retval != _SUCCESS) {
2184 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, 2151 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
@@ -2238,8 +2205,6 @@ static int recv_func_posthandle(struct rtw_adapter *padapter,
2238 struct recv_priv *precvpriv = &padapter->recvpriv; 2205 struct recv_priv *precvpriv = &padapter->recvpriv;
2239 2206
2240 /* DATA FRAME */ 2207 /* DATA FRAME */
2241 rtw_led_control(padapter, LED_CTL_RX);
2242
2243 prframe = decryptor(padapter, prframe); 2208 prframe = decryptor(padapter, prframe);
2244 if (prframe == NULL) { 2209 if (prframe == NULL) {
2245 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_, 2210 RT_TRACE(_module_rtl871x_recv_c_, _drv_err_,
@@ -2349,66 +2314,52 @@ void rtw_signal_stat_timer_hdl23a(unsigned long data)
2349 u8 _alpha = 3; /* this value is based on converging_constant = 5000 */ 2314 u8 _alpha = 3; /* this value is based on converging_constant = 5000 */
2350 /* and sampling_interval = 1000 */ 2315 /* and sampling_interval = 1000 */
2351 2316
2352 if (adapter->recvpriv.is_signal_dbg) { 2317 if (recvpriv->signal_strength_data.update_req == 0) {
2353 /* update the user specific value, signal_strength_dbg, */ 2318 /* update_req is clear, means we got rx */
2354 /* to signal_strength, rssi */ 2319 avg_signal_strength = recvpriv->signal_strength_data.avg_val;
2355 adapter->recvpriv.signal_strength = 2320 num_signal_strength = recvpriv->signal_strength_data.total_num;
2356 adapter->recvpriv.signal_strength_dbg; 2321 /* after avg_vals are acquired, we can re-stat */
2357 adapter->recvpriv.rssi = 2322 /* the signal values */
2358 (s8)translate_percentage_to_dbm((u8)adapter->recvpriv.signal_strength_dbg); 2323 recvpriv->signal_strength_data.update_req = 1;
2359 } else { 2324 }
2360 if (recvpriv->signal_strength_data.update_req == 0) { 2325
2361 /* update_req is clear, means we got rx */ 2326 if (recvpriv->signal_qual_data.update_req == 0) {
2362 avg_signal_strength = 2327 /* update_req is clear, means we got rx */
2363 recvpriv->signal_strength_data.avg_val; 2328 avg_signal_qual = recvpriv->signal_qual_data.avg_val;
2364 num_signal_strength = 2329 num_signal_qual = recvpriv->signal_qual_data.total_num;
2365 recvpriv->signal_strength_data.total_num; 2330 /* after avg_vals are acquired, we can re-stat */
2366 /* after avg_vals are acquired, we can re-stat */ 2331 /*the signal values */
2367 /* the signal values */ 2332 recvpriv->signal_qual_data.update_req = 1;
2368 recvpriv->signal_strength_data.update_req = 1; 2333 }
2369 } 2334
2335 /* update value of signal_strength, rssi, signal_qual */
2336 if (!check_fwstate(&adapter->mlmepriv, _FW_UNDER_SURVEY)) {
2337 tmp_s = (avg_signal_strength + (_alpha - 1) *
2338 recvpriv->signal_strength);
2339 if (tmp_s %_alpha)
2340 tmp_s = tmp_s / _alpha + 1;
2341 else
2342 tmp_s = tmp_s / _alpha;
2343 if (tmp_s > 100)
2344 tmp_s = 100;
2370 2345
2371 if (recvpriv->signal_qual_data.update_req == 0) { 2346 tmp_q = avg_signal_qual + (_alpha - 1) * recvpriv->signal_qual;
2372 /* update_req is clear, means we got rx */ 2347 if (tmp_q %_alpha)
2373 avg_signal_qual = recvpriv->signal_qual_data.avg_val; 2348 tmp_q = tmp_q / _alpha + 1;
2374 num_signal_qual = recvpriv->signal_qual_data.total_num; 2349 else
2375 /* after avg_vals are acquired, we can re-stat */ 2350 tmp_q = tmp_q / _alpha;
2376 /*the signal values */ 2351 if (tmp_q > 100)
2377 recvpriv->signal_qual_data.update_req = 1; 2352 tmp_q = 100;
2378 }
2379 2353
2380 /* update value of signal_strength, rssi, signal_qual */ 2354 recvpriv->signal_strength = tmp_s;
2381 if (!check_fwstate(&adapter->mlmepriv, _FW_UNDER_SURVEY)) { 2355 recvpriv->signal_qual = tmp_q;
2382 tmp_s = (avg_signal_strength + (_alpha - 1) * 2356
2383 recvpriv->signal_strength); 2357 DBG_8723A("%s signal_strength:%3u, signal_qual:%3u, "
2384 if (tmp_s %_alpha) 2358 "num_signal_strength:%u, num_signal_qual:%u\n",
2385 tmp_s = tmp_s / _alpha + 1; 2359 __func__, recvpriv->signal_strength,
2386 else 2360 recvpriv->signal_qual, num_signal_strength,
2387 tmp_s = tmp_s / _alpha; 2361 num_signal_qual);
2388 if (tmp_s > 100)
2389 tmp_s = 100;
2390
2391 tmp_q = (avg_signal_qual + (_alpha - 1) *
2392 recvpriv->signal_qual);
2393 if (tmp_q %_alpha)
2394 tmp_q = tmp_q / _alpha + 1;
2395 else
2396 tmp_q = tmp_q / _alpha;
2397 if (tmp_q > 100)
2398 tmp_q = 100;
2399
2400 recvpriv->signal_strength = tmp_s;
2401 recvpriv->rssi = (s8)translate_percentage_to_dbm(tmp_s);
2402 recvpriv->signal_qual = tmp_q;
2403
2404 DBG_8723A("%s signal_strength:%3u, rssi:%3d, "
2405 "signal_qual:%3u, num_signal_strength:%u, "
2406 "num_signal_qual:%u\n",
2407 __func__, recvpriv->signal_strength,
2408 recvpriv->rssi, recvpriv->signal_qual,
2409 num_signal_strength, num_signal_qual
2410 );
2411 }
2412 } 2362 }
2363
2413 rtw_set_signal_stat_timer(recvpriv); 2364 rtw_set_signal_stat_timer(recvpriv);
2414} 2365}
diff --git a/drivers/staging/rtl8723au/core/rtw_security.c b/drivers/staging/rtl8723au/core/rtw_security.c
index 76371ae69377..715a47414bdd 100644
--- a/drivers/staging/rtl8723au/core/rtw_security.c
+++ b/drivers/staging/rtl8723au/core/rtw_security.c
@@ -23,19 +23,18 @@
23 23
24#define CRC32_POLY 0x04c11db7 24#define CRC32_POLY 0x04c11db7
25 25
26struct arc4context 26struct arc4context {
27{
28 u32 x; 27 u32 x;
29 u32 y; 28 u32 y;
30 u8 state[256]; 29 u8 state[256];
31}; 30};
32 31
33static void arcfour_init(struct arc4context *parc4ctx, u8 * key, u32 key_len) 32static void arcfour_init(struct arc4context *parc4ctx, u8 *key, u32 key_len)
34{ 33{
35 u32 t, u; 34 u32 t, u;
36 u32 keyindex; 35 u32 keyindex;
37 u32 stateindex; 36 u32 stateindex;
38 u8 * state; 37 u8 *state;
39 u32 counter; 38 u32 counter;
40 39
41 state = parc4ctx->state; 40 state = parc4ctx->state;
@@ -45,8 +44,7 @@ static void arcfour_init(struct arc4context *parc4ctx, u8 * key, u32 key_len)
45 state[counter] = (u8)counter; 44 state[counter] = (u8)counter;
46 keyindex = 0; 45 keyindex = 0;
47 stateindex = 0; 46 stateindex = 0;
48 for (counter = 0; counter < 256; counter++) 47 for (counter = 0; counter < 256; counter++) {
49 {
50 t = state[counter]; 48 t = state[counter];
51 stateindex = (stateindex + key[keyindex] + t) & 0xff; 49 stateindex = (stateindex + key[keyindex] + t) & 0xff;
52 u = state[stateindex]; 50 u = state[stateindex];
@@ -62,7 +60,7 @@ static u32 arcfour_byte( struct arc4context *parc4ctx)
62 u32 x; 60 u32 x;
63 u32 y; 61 u32 y;
64 u32 sx, sy; 62 u32 sx, sy;
65 u8 * state; 63 u8 *state;
66 64
67 state = parc4ctx->state; 65 state = parc4ctx->state;
68 x = (parc4ctx->x + 1) & 0xff; 66 x = (parc4ctx->x + 1) & 0xff;
@@ -78,8 +76,8 @@ static u32 arcfour_byte( struct arc4context *parc4ctx)
78} 76}
79 77
80static void arcfour_encrypt( struct arc4context *parc4ctx, 78static void arcfour_encrypt( struct arc4context *parc4ctx,
81 u8 * dest, 79 u8 *dest,
82 u8 * src, 80 u8 *src,
83 u32 len) 81 u32 len)
84{ 82{
85 u32 i; 83 u32 i;
@@ -114,8 +112,7 @@ static void crc32_init(void)
114 112
115 c = 0x12340000; 113 c = 0x12340000;
116 114
117 for (i = 0; i < 256; ++i) 115 for (i = 0; i < 256; ++i) {
118 {
119 k = crc32_reverseBit((u8)i); 116 k = crc32_reverseBit((u8)i);
120 for (c = ((u32)k) << 24, j = 8; j > 0; --j) { 117 for (c = ((u32)k) << 24, j = 8; j > 0; --j) {
121 c = c & 0x80000000 ? (c << 1) ^ CRC32_POLY : (c << 1); 118 c = c & 0x80000000 ? (c << 1) ^ CRC32_POLY : (c << 1);
@@ -221,7 +218,7 @@ void rtw_wep_decrypt23a(struct rtw_adapter *padapter,
221 u8 keyindex; 218 u8 keyindex;
222 struct rx_pkt_attrib *prxattrib = &precvframe->attrib; 219 struct rx_pkt_attrib *prxattrib = &precvframe->attrib;
223 struct security_priv *psecuritypriv = &padapter->securitypriv; 220 struct security_priv *psecuritypriv = &padapter->securitypriv;
224 struct sk_buff * skb = precvframe->pkt; 221 struct sk_buff *skb = precvframe->pkt;
225 222
226 pframe = skb->data; 223 pframe = skb->data;
227 224
@@ -260,33 +257,29 @@ void rtw_wep_decrypt23a(struct rtw_adapter *padapter,
260 crc[1], payload[length - 3], 257 crc[1], payload[length - 3],
261 crc[0], payload[length - 4])); 258 crc[0], payload[length - 4]));
262 } 259 }
263
264 return;
265} 260}
266 261
267/* 3 ===== TKIP related ===== */ 262/* 3 ===== TKIP related ===== */
268 263
269static u32 secmicgetuint32(u8 * p) 264static u32 secmicgetuint32(u8 *p)
270/* Convert from Byte[] to u32 in a portable way */ 265/* Convert from Byte[] to u32 in a portable way */
271{ 266{
272 s32 i; 267 s32 i;
273 u32 res = 0; 268 u32 res = 0;
274 269
275 for (i = 0; i<4; i++) 270 for (i = 0; i<4; i++) {
276 {
277 res |= ((u32)(*p++)) << (8*i); 271 res |= ((u32)(*p++)) << (8*i);
278 } 272 }
279 273
280 return res; 274 return res;
281} 275}
282 276
283static void secmicputuint32(u8 * p, u32 val) 277static void secmicputuint32(u8 *p, u32 val)
284/* Convert from long to Byte[] in a portable way */ 278/* Convert from long to Byte[] in a portable way */
285{ 279{
286 long i; 280 long i;
287 281
288 for (i = 0; i<4; i++) 282 for (i = 0; i<4; i++) {
289 {
290 *p++ = (u8) (val & 0xff); 283 *p++ = (u8) (val & 0xff);
291 val >>= 8; 284 val >>= 8;
292 } 285 }
@@ -304,7 +297,7 @@ static void secmicclear(struct mic_data *pmicdata)
304 297
305} 298}
306 299
307void rtw_secmicsetkey23a(struct mic_data *pmicdata, u8 * key) 300void rtw_secmicsetkey23a(struct mic_data *pmicdata, u8 *key)
308{ 301{
309 /* Set the key */ 302 /* Set the key */
310 303
@@ -322,8 +315,7 @@ void rtw_secmicappend23abyte23a(struct mic_data *pmicdata, u8 b)
322 pmicdata->M |= ((unsigned long)b) << (8*pmicdata->nBytesInM); 315 pmicdata->M |= ((unsigned long)b) << (8*pmicdata->nBytesInM);
323 pmicdata->nBytesInM++; 316 pmicdata->nBytesInM++;
324 /* Process the word if it is full. */ 317 /* Process the word if it is full. */
325 if (pmicdata->nBytesInM >= 4) 318 if (pmicdata->nBytesInM >= 4) {
326 {
327 pmicdata->L ^= pmicdata->M; 319 pmicdata->L ^= pmicdata->M;
328 pmicdata->R ^= ROL32(pmicdata->L, 17); 320 pmicdata->R ^= ROL32(pmicdata->L, 17);
329 pmicdata->L += pmicdata->R; 321 pmicdata->L += pmicdata->R;
@@ -340,19 +332,18 @@ void rtw_secmicappend23abyte23a(struct mic_data *pmicdata, u8 b)
340 332
341} 333}
342 334
343void rtw_secmicappend23a(struct mic_data *pmicdata, u8 * src, u32 nbytes) 335void rtw_secmicappend23a(struct mic_data *pmicdata, u8 *src, u32 nbytes)
344{ 336{
345 337
346 /* This is simple */ 338 /* This is simple */
347 while(nbytes > 0) 339 while(nbytes > 0) {
348 {
349 rtw_secmicappend23abyte23a(pmicdata, *src++); 340 rtw_secmicappend23abyte23a(pmicdata, *src++);
350 nbytes--; 341 nbytes--;
351 } 342 }
352 343
353} 344}
354 345
355void rtw_secgetmic23a(struct mic_data *pmicdata, u8 * dst) 346void rtw_secgetmic23a(struct mic_data *pmicdata, u8 *dst)
356{ 347{
357 348
358 /* Append the minimum padding */ 349 /* Append the minimum padding */
@@ -362,8 +353,7 @@ void rtw_secgetmic23a(struct mic_data *pmicdata, u8 * dst)
362 rtw_secmicappend23abyte23a(pmicdata, 0); 353 rtw_secmicappend23abyte23a(pmicdata, 0);
363 rtw_secmicappend23abyte23a(pmicdata, 0); 354 rtw_secmicappend23abyte23a(pmicdata, 0);
364 /* and then zeroes until the length is a multiple of 4 */ 355 /* and then zeroes until the length is a multiple of 4 */
365 while(pmicdata->nBytesInM != 0) 356 while(pmicdata->nBytesInM != 0) {
366 {
367 rtw_secmicappend23abyte23a(pmicdata, 0); 357 rtw_secmicappend23abyte23a(pmicdata, 0);
368 } 358 }
369 /* The appendByte function has already computed the result. */ 359 /* The appendByte function has already computed the result. */
@@ -374,7 +364,8 @@ void rtw_secgetmic23a(struct mic_data *pmicdata, u8 * dst)
374 364
375} 365}
376 366
377void rtw_seccalctkipmic23a(u8 * key, u8 *header, u8 *data, u32 data_len, u8 *mic_code, u8 pri) 367void rtw_seccalctkipmic23a(u8 *key, u8 *header, u8 *data, u32 data_len,
368 u8 *mic_code, u8 pri)
378{ 369{
379 370
380 struct mic_data micdata; 371 struct mic_data micdata;
@@ -531,8 +522,8 @@ static void phase1(u16 *p1k, const u8 *tk, const u8 *ta, u32 iv32)
531 522
532 /* Now compute an unbalanced Feistel cipher with 80-bit block */ 523 /* Now compute an unbalanced Feistel cipher with 80-bit block */
533 /* size on the 80-bit block P1K[], using the 128-bit key TK[] */ 524 /* size on the 80-bit block P1K[], using the 128-bit key TK[] */
534 for (i = 0; i < PHASE1_LOOP_CNT ;i++) 525 for (i = 0; i < PHASE1_LOOP_CNT ;i++) {
535 { /* Each add operation here is mod 2**16 */ 526 /* Each add operation here is mod 2**16 */
536 p1k[0] += _S_(p1k[4] ^ TK16((i&1)+0)); 527 p1k[0] += _S_(p1k[4] ^ TK16((i&1)+0));
537 p1k[1] += _S_(p1k[0] ^ TK16((i&1)+2)); 528 p1k[1] += _S_(p1k[0] ^ TK16((i&1)+2));
538 p1k[2] += _S_(p1k[1] ^ TK16((i&1)+4)); 529 p1k[2] += _S_(p1k[1] ^ TK16((i&1)+4));
@@ -602,8 +593,7 @@ static void phase2(u8 *rc4key, const u8 *tk, const u16 *p1k, u16 iv16)
602 rc4key[3] = Lo8((PPK[5] ^ TK16(0)) >> 1); 593 rc4key[3] = Lo8((PPK[5] ^ TK16(0)) >> 1);
603 594
604 /* Copy 96 bits of PPK[0..5] to RC4KEY[4..15] (little-endian) */ 595 /* Copy 96 bits of PPK[0..5] to RC4KEY[4..15] (little-endian) */
605 for (i = 0;i<6;i++) 596 for (i = 0;i<6;i++) {
606 {
607 rc4key[4+2*i] = Lo8(PPK[i]); 597 rc4key[4+2*i] = Lo8(PPK[i]);
608 rc4key[5+2*i] = Hi8(PPK[i]); 598 rc4key[5+2*i] = Hi8(PPK[i]);
609 } 599 }
@@ -649,8 +639,7 @@ int rtw_tkip_encrypt23a(struct rtw_adapter *padapter,
649 639
650 if (stainfo!= NULL) { 640 if (stainfo!= NULL) {
651 641
652 if (!(stainfo->state &_FW_LINKED)) 642 if (!(stainfo->state &_FW_LINKED)) {
653 {
654 DBG_8723A("%s, psta->state(0x%x) != _FW_LINKED\n", __func__, stainfo->state); 643 DBG_8723A("%s, psta->state(0x%x) != _FW_LINKED\n", __func__, stainfo->state);
655 return _FAIL; 644 return _FAIL;
656 } 645 }
@@ -728,7 +717,7 @@ int rtw_tkip_decrypt23a(struct rtw_adapter *padapter,
728 struct sta_info *stainfo; 717 struct sta_info *stainfo;
729 struct rx_pkt_attrib *prxattrib = &precvframe->attrib; 718 struct rx_pkt_attrib *prxattrib = &precvframe->attrib;
730 struct security_priv *psecuritypriv = &padapter->securitypriv; 719 struct security_priv *psecuritypriv = &padapter->securitypriv;
731 struct sk_buff * skb = precvframe->pkt; 720 struct sk_buff *skb = precvframe->pkt;
732 int res = _SUCCESS; 721 int res = _SUCCESS;
733 722
734 pframe = skb->data; 723 pframe = skb->data;
@@ -887,8 +876,7 @@ static void byte_sub(u8 *in, u8 *out)
887{ 876{
888 int i; 877 int i;
889 878
890 for (i = 0; i< 16; i++) 879 for (i = 0; i< 16; i++) {
891 {
892 out[i] = sbox(in[i]); 880 out[i] = sbox(in[i]);
893 } 881 }
894 882
@@ -928,8 +916,7 @@ static void mix_column(u8 *in, u8 *out)
928 u8 temp[4]; 916 u8 temp[4];
929 u8 tempb[4]; 917 u8 tempb[4];
930 918
931 for (i = 0 ; i<4; i++) 919 for (i = 0 ; i<4; i++) {
932 {
933 if ((in[i] & 0x80) == 0x80) 920 if ((in[i] & 0x80) == 0x80)
934 add1b[i] = 0x1b; 921 add1b[i] = 0x1b;
935 else 922 else
@@ -951,11 +938,9 @@ static void mix_column(u8 *in, u8 *out)
951 andf7[2] = in[2] & 0x7f; 938 andf7[2] = in[2] & 0x7f;
952 andf7[3] = in[3] & 0x7f; 939 andf7[3] = in[3] & 0x7f;
953 940
954 for (i = 3; i>0; i--) /* logical shift left 1 bit */ 941 for (i = 3; i>0; i--) { /* logical shift left 1 bit */
955 {
956 andf7[i] = andf7[i] << 1; 942 andf7[i] = andf7[i] << 1;
957 if ((andf7[i-1] & 0x80) == 0x80) 943 if ((andf7[i-1] & 0x80) == 0x80) {
958 {
959 andf7[i] = (andf7[i] | 0x01); 944 andf7[i] = (andf7[i] | 0x01);
960 } 945 }
961 } 946 }
@@ -988,21 +973,15 @@ static void aes128k128d(u8 *key, u8 *data, u8 *ciphertext)
988 973
989 for (i = 0; i<16; i++) round_key[i] = key[i]; 974 for (i = 0; i<16; i++) round_key[i] = key[i];
990 975
991 for (round = 0; round < 11; round++) 976 for (round = 0; round < 11; round++) {
992 { 977 if (round == 0) {
993 if (round == 0)
994 {
995 xor_128(round_key, data, ciphertext); 978 xor_128(round_key, data, ciphertext);
996 next_key(round_key, round); 979 next_key(round_key, round);
997 } 980 } else if (round == 10) {
998 else if (round == 10)
999 {
1000 byte_sub(ciphertext, intermediatea); 981 byte_sub(ciphertext, intermediatea);
1001 shift_row(intermediatea, intermediateb); 982 shift_row(intermediatea, intermediateb);
1002 xor_128(intermediateb, round_key, ciphertext); 983 xor_128(intermediateb, round_key, ciphertext);
1003 } 984 } else { /* 1 - 9 */
1004 else /* 1 - 9 */
1005 {
1006 byte_sub(ciphertext, intermediatea); 985 byte_sub(ciphertext, intermediatea);
1007 shift_row(intermediatea, intermediateb); 986 shift_row(intermediatea, intermediateb);
1008 mix_column(&intermediateb[0], &intermediatea[0]); 987 mix_column(&intermediateb[0], &intermediatea[0]);
@@ -1088,20 +1067,17 @@ static void construct_mic_header2(u8 *mic_header2, u8 *mpdu, int a4_exists,
1088 mic_header2[6] = 0x00; 1067 mic_header2[6] = 0x00;
1089 mic_header2[7] = 0x00; /* mpdu[23]; */ 1068 mic_header2[7] = 0x00; /* mpdu[23]; */
1090 1069
1091 if (!qc_exists && a4_exists) 1070 if (!qc_exists && a4_exists) {
1092 {
1093 for (i = 0;i<6;i++) mic_header2[8+i] = mpdu[24+i]; /* A4 */ 1071 for (i = 0;i<6;i++) mic_header2[8+i] = mpdu[24+i]; /* A4 */
1094 1072
1095 } 1073 }
1096 1074
1097 if (qc_exists && !a4_exists) 1075 if (qc_exists && !a4_exists) {
1098 {
1099 mic_header2[8] = mpdu[24] & 0x0f; /* mute bits 15 - 4 */ 1076 mic_header2[8] = mpdu[24] & 0x0f; /* mute bits 15 - 4 */
1100 mic_header2[9] = mpdu[25] & 0x00; 1077 mic_header2[9] = mpdu[25] & 0x00;
1101 } 1078 }
1102 1079
1103 if (qc_exists && a4_exists) 1080 if (qc_exists && a4_exists) {
1104 {
1105 for (i = 0;i<6;i++) mic_header2[8+i] = mpdu[24+i]; /* A4 */ 1081 for (i = 0;i<6;i++) mic_header2[8+i] = mpdu[24+i]; /* A4 */
1106 1082
1107 mic_header2[14] = mpdu[30] & 0x0f; 1083 mic_header2[14] = mpdu[30] & 0x0f;
diff --git a/drivers/staging/rtl8723au/core/rtw_sreset.c b/drivers/staging/rtl8723au/core/rtw_sreset.c
index 58ed980795a6..29a29d92a6ac 100644
--- a/drivers/staging/rtl8723au/core/rtw_sreset.c
+++ b/drivers/staging/rtl8723au/core/rtw_sreset.c
@@ -107,7 +107,7 @@ static void sreset_restore_network_station(struct rtw_adapter *padapter)
107 107
108 mlmeext_joinbss_event_callback23a(padapter, 1); 108 mlmeext_joinbss_event_callback23a(padapter, 1);
109 /* restore Sequence No. */ 109 /* restore Sequence No. */
110 rtl8723au_write8(padapter, 0x4dc, padapter->xmitpriv.nqos_ssn); 110 rtl8723au_write8(padapter, REG_NQOS_SEQ, padapter->xmitpriv.nqos_ssn);
111 111
112 sreset_restore_security_station(padapter); 112 sreset_restore_security_station(padapter);
113} 113}
diff --git a/drivers/staging/rtl8723au/core/rtw_wlan_util.c b/drivers/staging/rtl8723au/core/rtw_wlan_util.c
index 09c44a55d4a6..69d9e0f17fd8 100644
--- a/drivers/staging/rtl8723au/core/rtw_wlan_util.c
+++ b/drivers/staging/rtl8723au/core/rtw_wlan_util.c
@@ -608,8 +608,6 @@ void WMMOnAssocRsp23a(struct rtw_adapter *padapter)
608 DBG_8723A("wmm_para_seq(%d): %d\n", i, 608 DBG_8723A("wmm_para_seq(%d): %d\n", i,
609 pxmitpriv->wmm_para_seq[i]); 609 pxmitpriv->wmm_para_seq[i]);
610 } 610 }
611
612 return;
613} 611}
614 612
615static void bwmode_update_check(struct rtw_adapter *padapter, const u8 *p) 613static void bwmode_update_check(struct rtw_adapter *padapter, const u8 *p)
@@ -750,7 +748,6 @@ void HT_caps_handler23a(struct rtw_adapter *padapter, const u8 *p)
750 else 748 else
751 cap->mcs.rx_mask[i] &= MCS_rate_2R23A[i]; 749 cap->mcs.rx_mask[i] &= MCS_rate_2R23A[i];
752 } 750 }
753 return;
754} 751}
755 752
756void HT_info_handler23a(struct rtw_adapter *padapter, const u8 *p) 753void HT_info_handler23a(struct rtw_adapter *padapter, const u8 *p)
@@ -771,7 +768,6 @@ void HT_info_handler23a(struct rtw_adapter *padapter, const u8 *p)
771 768
772 pmlmeinfo->HT_info_enable = 1; 769 pmlmeinfo->HT_info_enable = 1;
773 memcpy(&pmlmeinfo->HT_info, p + 2, p[1]); 770 memcpy(&pmlmeinfo->HT_info, p + 2, p[1]);
774 return;
775} 771}
776 772
777void HTOnAssocRsp23a(struct rtw_adapter *padapter) 773void HTOnAssocRsp23a(struct rtw_adapter *padapter)
@@ -833,7 +829,7 @@ void VCS_update23a(struct rtw_adapter *padapter, struct sta_info *psta)
833 psta->cts2self = 0; 829 psta->cts2self = 0;
834 break; 830 break;
835 case 1: /* on */ 831 case 1: /* on */
836 if (pregpriv->vcs_type == 1) { /* 1:RTS/CTS 2:CTS to self */ 832 if (pregpriv->vcs_type == RTS_CTS) {
837 psta->rtsen = 1; 833 psta->rtsen = 1;
838 psta->cts2self = 0; 834 psta->cts2self = 0;
839 } else { 835 } else {
@@ -844,7 +840,7 @@ void VCS_update23a(struct rtw_adapter *padapter, struct sta_info *psta)
844 case 2: /* auto */ 840 case 2: /* auto */
845 default: 841 default:
846 if (pmlmeinfo->ERP_enable && pmlmeinfo->ERP_IE & BIT(1)) { 842 if (pmlmeinfo->ERP_enable && pmlmeinfo->ERP_IE & BIT(1)) {
847 if (pregpriv->vcs_type == 1) { 843 if (pregpriv->vcs_type == RTS_CTS) {
848 psta->rtsen = 1; 844 psta->rtsen = 1;
849 psta->cts2self = 0; 845 psta->cts2self = 0;
850 } else { 846 } else {
@@ -870,7 +866,7 @@ int rtw_check_bcn_info23a(struct rtw_adapter *Adapter,
870 int pie_len, ssid_len, privacy; 866 int pie_len, ssid_len, privacy;
871 const u8 *p, *ssid; 867 const u8 *p, *ssid;
872 868
873 if (is_client_associated_to_ap23a(Adapter) == false) 869 if (!is_client_associated_to_ap23a(Adapter))
874 return _SUCCESS; 870 return _SUCCESS;
875 871
876 if (unlikely(!ieee80211_is_beacon(mgmt->frame_control))) { 872 if (unlikely(!ieee80211_is_beacon(mgmt->frame_control))) {
@@ -1080,7 +1076,7 @@ bool is_ap_in_tkip23a(struct rtw_adapter *padapter)
1080 return false; 1076 return false;
1081} 1077}
1082 1078
1083bool should_forbid_n_rate23a(struct rtw_adapter * padapter) 1079bool should_forbid_n_rate23a(struct rtw_adapter *padapter)
1084{ 1080{
1085 u32 i; 1081 u32 i;
1086 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 1082 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
@@ -1153,6 +1149,7 @@ bool is_ap_in_wep23a(struct rtw_adapter *padapter)
1153static int wifirate2_ratetbl_inx23a(unsigned char rate) 1149static int wifirate2_ratetbl_inx23a(unsigned char rate)
1154{ 1150{
1155 int inx = 0; 1151 int inx = 0;
1152
1156 rate = rate & 0x7f; 1153 rate = rate & 0x7f;
1157 1154
1158 switch (rate) { 1155 switch (rate) {
@@ -1311,6 +1308,7 @@ unsigned char check_assoc_AP23a(u8 *pframe, uint len)
1311 u8 epigram_vendor_flag; 1308 u8 epigram_vendor_flag;
1312 u8 ralink_vendor_flag; 1309 u8 ralink_vendor_flag;
1313 const u8 *p; 1310 const u8 *p;
1311
1314 epigram_vendor_flag = 0; 1312 epigram_vendor_flag = 0;
1315 ralink_vendor_flag = 0; 1313 ralink_vendor_flag = 0;
1316 1314
@@ -1324,7 +1322,6 @@ unsigned char check_assoc_AP23a(u8 *pframe, uint len)
1324 DBG_8723A("link to Artheros AP\n"); 1322 DBG_8723A("link to Artheros AP\n");
1325 return HT_IOT_PEER_ATHEROS; 1323 return HT_IOT_PEER_ATHEROS;
1326 } else if (!memcmp(p + 2, BROADCOM_OUI1, 3) || 1324 } else if (!memcmp(p + 2, BROADCOM_OUI1, 3) ||
1327 !memcmp(p + 2, BROADCOM_OUI2, 3) ||
1328 !memcmp(p + 2, BROADCOM_OUI2, 3)) { 1325 !memcmp(p + 2, BROADCOM_OUI2, 3)) {
1329 DBG_8723A("link to Broadcom AP\n"); 1326 DBG_8723A("link to Broadcom AP\n");
1330 return HT_IOT_PEER_BROADCOM; 1327 return HT_IOT_PEER_BROADCOM;
diff --git a/drivers/staging/rtl8723au/core/rtw_xmit.c b/drivers/staging/rtl8723au/core/rtw_xmit.c
index 7a8038156cea..7a5e6bf0d1ae 100644
--- a/drivers/staging/rtl8723au/core/rtw_xmit.c
+++ b/drivers/staging/rtl8723au/core/rtw_xmit.c
@@ -22,9 +22,6 @@
22#include <usb_ops.h> 22#include <usb_ops.h>
23#include <rtl8723a_xmit.h> 23#include <rtl8723a_xmit.h>
24 24
25static u8 P802_1H_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0xf8 };
26static u8 RFC1042_OUI[P80211_OUI_LEN] = { 0x00, 0x00, 0x00 };
27
28static void _init_txservq(struct tx_servq *ptxservq) 25static void _init_txservq(struct tx_servq *ptxservq)
29{ 26{
30 27
@@ -180,16 +177,8 @@ int _rtw_init_xmit_priv23a(struct xmit_priv *pxmitpriv,
180 for (i = 0; i < 4; i ++) 177 for (i = 0; i < 4; i ++)
181 pxmitpriv->wmm_para_seq[i] = i; 178 pxmitpriv->wmm_para_seq[i] = i;
182 179
183 pxmitpriv->txirp_cnt = 1;
184
185 sema_init(&pxmitpriv->tx_retevt, 0); 180 sema_init(&pxmitpriv->tx_retevt, 0);
186 181
187 /* per AC pending irp */
188 pxmitpriv->beq_cnt = 0;
189 pxmitpriv->bkq_cnt = 0;
190 pxmitpriv->viq_cnt = 0;
191 pxmitpriv->voq_cnt = 0;
192
193 pxmitpriv->ack_tx = false; 182 pxmitpriv->ack_tx = false;
194 mutex_init(&pxmitpriv->ack_tx_mutex); 183 mutex_init(&pxmitpriv->ack_tx_mutex);
195 rtw_sctx_init23a(&pxmitpriv->ack_tx_ops, 0); 184 rtw_sctx_init23a(&pxmitpriv->ack_tx_ops, 0);
@@ -315,6 +304,7 @@ static void update_attrib_vcs_info(struct rtw_adapter *padapter, struct xmit_fra
315 /* check HT op mode */ 304 /* check HT op mode */
316 if (pattrib->ht_en) { 305 if (pattrib->ht_en) {
317 u8 HTOpMode = pmlmeinfo->HT_protection; 306 u8 HTOpMode = pmlmeinfo->HT_protection;
307
318 if ((pmlmeext->cur_bwmode && (HTOpMode == 2 || HTOpMode == 3)) || 308 if ((pmlmeext->cur_bwmode && (HTOpMode == 2 || HTOpMode == 3)) ||
319 (!pmlmeext->cur_bwmode && HTOpMode == 3)) { 309 (!pmlmeext->cur_bwmode && HTOpMode == 3)) {
320 pattrib->vcs_mode = RTS_CTS; 310 pattrib->vcs_mode = RTS_CTS;
@@ -464,6 +454,7 @@ static int update_attrib(struct rtw_adapter *padapter,
464 if (pattrib->pktlen > 282 + 24) { 454 if (pattrib->pktlen > 282 + 24) {
465 if (pattrib->ether_type == ETH_P_IP) {/* IP header */ 455 if (pattrib->ether_type == ETH_P_IP) {/* IP header */
466 u8 *pframe = skb->data; 456 u8 *pframe = skb->data;
457
467 pframe += ETH_HLEN; 458 pframe += ETH_HLEN;
468 459
469 if ((pframe[21] == 68 && pframe[23] == 67) || 460 if ((pframe[21] == 68 && pframe[23] == 67) ||
@@ -1048,21 +1039,23 @@ s32 rtw_txframes_sta_ac_pending23a(struct rtw_adapter *padapter,
1048 return ptxservq->qcnt; 1039 return ptxservq->qcnt;
1049} 1040}
1050 1041
1051/* 1042/* Logical Link Control(LLC) SubNetwork Attachment Point(SNAP) header
1052 * Calculate wlan 802.11 packet MAX size from pkt_attrib 1043 * IEEE LLC/SNAP header contains 8 octets
1053 * This function doesn't consider fragment case 1044 * First 3 octets comprise the LLC portion
1045 * SNAP portion, 5 octets, is divided into two fields:
1046 * Organizationally Unique Identifier(OUI), 3 octets,
1047 * type, defined by that organization, 2 octets.
1054 */ 1048 */
1055u32 rtw_calculate_wlan_pkt_size_by_attribue23a(struct pkt_attrib *pattrib) 1049static int rtw_put_snap(u8 *data, u16 h_proto)
1056{ 1050{
1057 u32 len = 0; 1051 if (h_proto == ETH_P_IPX || h_proto == ETH_P_AARP)
1058 1052 ether_addr_copy(data, bridge_tunnel_header);
1059 len = pattrib->hdrlen + pattrib->iv_len; /* WLAN Header and IV */ 1053 else
1060 len += SNAP_SIZE + sizeof(u16); /* LLC */ 1054 ether_addr_copy(data, rfc1042_header);
1061 len += pattrib->pktlen;
1062 if (pattrib->encrypt == WLAN_CIPHER_SUITE_TKIP) len += 8; /* MIC */
1063 len += ((pattrib->bswenc) ? pattrib->icv_len : 0); /* ICV */
1064 1055
1065 return len; 1056 data += ETH_ALEN;
1057 put_unaligned_be16(h_proto, data);
1058 return ETH_ALEN + sizeof(u16);
1066} 1059}
1067 1060
1068/* 1061/*
@@ -1188,7 +1181,7 @@ int rtw_xmitframe_coalesce23a(struct rtw_adapter *padapter, struct sk_buff *skb,
1188 mpdu_len -= pattrib->iv_len; 1181 mpdu_len -= pattrib->iv_len;
1189 } 1182 }
1190 if (frg_inx == 0) { 1183 if (frg_inx == 0) {
1191 llc_sz = rtw_put_snap23a(pframe, pattrib->ether_type); 1184 llc_sz = rtw_put_snap(pframe, pattrib->ether_type);
1192 pframe += llc_sz; 1185 pframe += llc_sz;
1193 mpdu_len -= llc_sz; 1186 mpdu_len -= llc_sz;
1194 } 1187 }
@@ -1258,34 +1251,6 @@ exit:
1258 return res; 1251 return res;
1259} 1252}
1260 1253
1261/* Logical Link Control(LLC) SubNetwork Attachment Point(SNAP) header
1262 * IEEE LLC/SNAP header contains 8 octets
1263 * First 3 octets comprise the LLC portion
1264 * SNAP portion, 5 octets, is divided into two fields:
1265 * Organizationally Unique Identifier(OUI), 3 octets,
1266 * type, defined by that organization, 2 octets.
1267 */
1268s32 rtw_put_snap23a(u8 *data, u16 h_proto)
1269{
1270 struct ieee80211_snap_hdr *snap;
1271 u8 *oui;
1272
1273 snap = (struct ieee80211_snap_hdr *)data;
1274 snap->dsap = 0xaa;
1275 snap->ssap = 0xaa;
1276 snap->ctrl = 0x03;
1277
1278 if (h_proto == 0x8137 || h_proto == 0x80f3)
1279 oui = P802_1H_OUI;
1280 else
1281 oui = RFC1042_OUI;
1282 snap->oui[0] = oui[0];
1283 snap->oui[1] = oui[1];
1284 snap->oui[2] = oui[2];
1285 *(u16 *)(data + SNAP_SIZE) = htons(h_proto);
1286 return SNAP_SIZE + sizeof(u16);
1287}
1288
1289void rtw_update_protection23a(struct rtw_adapter *padapter, u8 *ie, uint ie_len) 1254void rtw_update_protection23a(struct rtw_adapter *padapter, u8 *ie, uint ie_len)
1290{ 1255{
1291 struct xmit_priv *pxmitpriv = &padapter->xmitpriv; 1256 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
@@ -1293,7 +1258,7 @@ void rtw_update_protection23a(struct rtw_adapter *padapter, u8 *ie, uint ie_len)
1293 uint protection; 1258 uint protection;
1294 const u8 *p; 1259 const u8 *p;
1295 1260
1296 switch (pxmitpriv->vcs_setting) { 1261 switch (pregistrypriv->vrtl_carrier_sense) {
1297 case DISABLE_VCS: 1262 case DISABLE_VCS:
1298 pxmitpriv->vcs = NONE_VCS; 1263 pxmitpriv->vcs = NONE_VCS;
1299 break; 1264 break;
@@ -1326,7 +1291,7 @@ void rtw_count_tx_stats23a(struct rtw_adapter *padapter, struct xmit_frame *pxmi
1326 struct xmit_priv *pxmitpriv = &padapter->xmitpriv; 1291 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
1327 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 1292 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1328 1293
1329 if ((pxmitframe->frame_tag&0x0f) == DATA_FRAMETAG) { 1294 if (pxmitframe->frame_tag == DATA_FRAMETAG) {
1330 pxmitpriv->tx_bytes += sz; 1295 pxmitpriv->tx_bytes += sz;
1331 pmlmepriv->LinkDetectInfo.NumTxOkInPeriod++; 1296 pmlmepriv->LinkDetectInfo.NumTxOkInPeriod++;
1332 1297
@@ -1893,18 +1858,6 @@ u32 rtw_get_ff_hwaddr23a(struct xmit_frame *pxmitframe)
1893 return addr; 1858 return addr;
1894} 1859}
1895 1860
1896static void do_queue_select(struct rtw_adapter *padapter, struct pkt_attrib *pattrib)
1897{
1898 u8 qsel;
1899
1900 qsel = pattrib->priority;
1901 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
1902 ("### do_queue_select priority =%d , qsel = %d\n",
1903 pattrib->priority, qsel));
1904
1905 pattrib->qsel = qsel;
1906}
1907
1908/* 1861/*
1909 * The main transmit(tx) entry 1862 * The main transmit(tx) entry
1910 * 1863 *
@@ -1936,9 +1889,7 @@ int rtw_xmit23a(struct rtw_adapter *padapter, struct sk_buff *skb)
1936 } 1889 }
1937 pxmitframe->pkt = skb; 1890 pxmitframe->pkt = skb;
1938 1891
1939 rtw_led_control(padapter, LED_CTL_TX); 1892 pxmitframe->attrib.qsel = pxmitframe->attrib.priority;
1940
1941 do_queue_select(padapter, &pxmitframe->attrib);
1942 1893
1943#ifdef CONFIG_8723AU_AP_MODE 1894#ifdef CONFIG_8723AU_AP_MODE
1944 spin_lock_bh(&pxmitpriv->lock); 1895 spin_lock_bh(&pxmitpriv->lock);
@@ -2411,11 +2362,6 @@ void rtw23a_sctx_done_err(struct submit_ctx **sctx, int status)
2411 } 2362 }
2412} 2363}
2413 2364
2414void rtw_sctx_done23a(struct submit_ctx **sctx)
2415{
2416 rtw23a_sctx_done_err(sctx, RTW_SCTX_DONE_SUCCESS);
2417}
2418
2419int rtw_ack_tx_wait23a(struct xmit_priv *pxmitpriv, u32 timeout_ms) 2365int rtw_ack_tx_wait23a(struct xmit_priv *pxmitpriv, u32 timeout_ms)
2420{ 2366{
2421 struct submit_ctx *pack_tx_ops = &pxmitpriv->ack_tx_ops; 2367 struct submit_ctx *pack_tx_ops = &pxmitpriv->ack_tx_ops;
diff --git a/drivers/staging/rtl8723au/hal/HalDMOutSrc8723A_CE.c b/drivers/staging/rtl8723au/hal/HalDMOutSrc8723A_CE.c
index 4b41bc4ce1e6..179a1ba03029 100644
--- a/drivers/staging/rtl8723au/hal/HalDMOutSrc8723A_CE.c
+++ b/drivers/staging/rtl8723au/hal/HalDMOutSrc8723A_CE.c
@@ -612,7 +612,7 @@ static void _PHY_PathADDAOn(struct rtw_adapter *pAdapter, u32 *ADDAReg, bool isP
612 u32 i; 612 u32 i;
613 613
614 pathOn = isPathAOn ? 0x04db25a4 : 0x0b1b25a4; 614 pathOn = isPathAOn ? 0x04db25a4 : 0x0b1b25a4;
615 if (false == is2T) { 615 if (!is2T) {
616 pathOn = 0x0bdb25a0; 616 pathOn = 0x0bdb25a0;
617 PHY_SetBBReg(pAdapter, ADDAReg[0], bMaskDWord, 0x0b1b25a0); 617 PHY_SetBBReg(pAdapter, ADDAReg[0], bMaskDWord, 0x0b1b25a0);
618 } else { 618 } else {
diff --git a/drivers/staging/rtl8723au/hal/hal_com.c b/drivers/staging/rtl8723au/hal/hal_com.c
index bf919f6e4128..bf4cae20bd12 100644
--- a/drivers/staging/rtl8723au/hal/hal_com.c
+++ b/drivers/staging/rtl8723au/hal/hal_com.c
@@ -463,7 +463,7 @@ void rtl8723a_set_ampdu_factor(struct rtw_adapter *padapter, u8 FactorToSet)
463 MaxAggNum = 0xF; 463 MaxAggNum = 0xF;
464 464
465 if (FactorToSet <= 3) { 465 if (FactorToSet <= 3) {
466 FactorToSet = (1 << (FactorToSet + 2)); 466 FactorToSet = 1 << (FactorToSet + 2);
467 if (FactorToSet > MaxAggNum) 467 if (FactorToSet > MaxAggNum)
468 FactorToSet = MaxAggNum; 468 FactorToSet = MaxAggNum;
469 469
@@ -727,7 +727,7 @@ void rtl8723a_fifo_cleanup(struct rtw_adapter *padapter)
727 rtl8723au_write8(padapter, REG_TXPAUSE, 0xff); 727 rtl8723au_write8(padapter, REG_TXPAUSE, 0xff);
728 728
729 /* keep sn */ 729 /* keep sn */
730 padapter->xmitpriv.nqos_ssn = rtl8723au_read16(padapter, REG_NQOS_SEQ); 730 padapter->xmitpriv.nqos_ssn = rtl8723au_read8(padapter, REG_NQOS_SEQ);
731 731
732 if (pwrpriv->bkeepfwalive != true) { 732 if (pwrpriv->bkeepfwalive != true) {
733 u32 v32; 733 u32 v32;
diff --git a/drivers/staging/rtl8723au/hal/odm_HWConfig.c b/drivers/staging/rtl8723au/hal/odm_HWConfig.c
index 29d844d66cae..fb3cc872f205 100644
--- a/drivers/staging/rtl8723au/hal/odm_HWConfig.c
+++ b/drivers/staging/rtl8723au/hal/odm_HWConfig.c
@@ -391,20 +391,11 @@ static void odm_Process_RSSIForDM(struct dm_odm_t *pDM_Odm,
391 } 391 }
392} 392}
393 393
394/* Endianness before calling this API */ 394void ODM_PhyStatusQuery23a(struct dm_odm_t *pDM_Odm, struct phy_info *pPhyInfo,
395static void ODM_PhyStatusQuery23a_92CSeries(struct dm_odm_t *pDM_Odm, 395 u8 *pPhyStatus, struct odm_packet_info *pPktinfo)
396 struct phy_info *pPhyInfo,
397 u8 *pPhyStatus,
398 struct odm_packet_info *pPktinfo)
399{ 396{
400 odm_RxPhyStatus92CSeries_Parsing(pDM_Odm, pPhyInfo, 397 odm_RxPhyStatus92CSeries_Parsing(pDM_Odm, pPhyInfo,
401 pPhyStatus, pPktinfo); 398 pPhyStatus, pPktinfo);
402 399
403 odm_Process_RSSIForDM(pDM_Odm, pPhyInfo, pPktinfo); 400 odm_Process_RSSIForDM(pDM_Odm, pPhyInfo, pPktinfo);
404} 401}
405
406void ODM_PhyStatusQuery23a(struct dm_odm_t *pDM_Odm, struct phy_info *pPhyInfo,
407 u8 *pPhyStatus, struct odm_packet_info *pPktinfo)
408{
409 ODM_PhyStatusQuery23a_92CSeries(pDM_Odm, pPhyInfo, pPhyStatus, pPktinfo);
410}
diff --git a/drivers/staging/rtl8723au/hal/rtl8723a_bt-coexist.c b/drivers/staging/rtl8723au/hal/rtl8723a_bt-coexist.c
index 9054a987f06b..86a83975f4f0 100644
--- a/drivers/staging/rtl8723au/hal/rtl8723a_bt-coexist.c
+++ b/drivers/staging/rtl8723au/hal/rtl8723a_bt-coexist.c
@@ -340,7 +340,7 @@ static u8 bthci_GetAssocInfo(struct rtw_adapter *padapter, u8 EntryNum)
340 tempBuf, TotalLen-BaseMemoryShift); 340 tempBuf, TotalLen-BaseMemoryShift);
341 341
342 pAmpAsoc = (struct amp_assoc_structure *)tempBuf; 342 pAmpAsoc = (struct amp_assoc_structure *)tempBuf;
343 pAmpAsoc->Length = le16_to_cpu(pAmpAsoc->Length); 343 le16_to_cpus(&pAmpAsoc->Length);
344 BaseMemoryShift += 3 + pAmpAsoc->Length; 344 BaseMemoryShift += 3 + pAmpAsoc->Length;
345 345
346 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("TypeID = 0x%x, ", pAmpAsoc->TypeID)); 346 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("TypeID = 0x%x, ", pAmpAsoc->TypeID));
@@ -1759,18 +1759,6 @@ static enum hci_status bthci_CmdReadConnectionAcceptTimeout(struct rtw_adapter *
1759 return status; 1759 return status;
1760} 1760}
1761 1761
1762/* 7.3.3 */
1763static enum hci_status
1764bthci_CmdSetEventFilter(
1765 struct rtw_adapter *padapter,
1766 struct packet_irp_hcicmd_data *pHciCmd
1767 )
1768{
1769 enum hci_status status = HCI_STATUS_SUCCESS;
1770
1771 return status;
1772}
1773
1774/* 7.3.14 */ 1762/* 7.3.14 */
1775static enum hci_status 1763static enum hci_status
1776bthci_CmdWriteConnectionAcceptTimeout( 1764bthci_CmdWriteConnectionAcceptTimeout(
@@ -2982,19 +2970,12 @@ bthci_CmdReadLinkQuality(
2982 return status; 2970 return status;
2983} 2971}
2984 2972
2985static enum hci_status bthci_CmdReadRSSI(struct rtw_adapter *padapter)
2986{
2987 enum hci_status status = HCI_STATUS_SUCCESS;
2988 return status;
2989}
2990
2991static enum hci_status 2973static enum hci_status
2992bthci_CmdCreateLogicalLink( 2974bthci_CmdCreateLogicalLink(
2993 struct rtw_adapter *padapter, 2975 struct rtw_adapter *padapter,
2994 struct packet_irp_hcicmd_data *pHciCmd 2976 struct packet_irp_hcicmd_data *pHciCmd
2995 ) 2977 )
2996{ 2978{
2997 enum hci_status status = HCI_STATUS_SUCCESS;
2998 struct bt_30info *pBTInfo = GET_BT_INFO(padapter); 2979 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
2999 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg; 2980 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3000 2981
@@ -3003,7 +2984,7 @@ bthci_CmdCreateLogicalLink(
3003 bthci_BuildLogicalLink(padapter, pHciCmd, 2984 bthci_BuildLogicalLink(padapter, pHciCmd,
3004 HCI_CREATE_LOGICAL_LINK); 2985 HCI_CREATE_LOGICAL_LINK);
3005 2986
3006 return status; 2987 return HCI_STATUS_SUCCESS;
3007} 2988}
3008 2989
3009static enum hci_status 2990static enum hci_status
@@ -3012,7 +2993,6 @@ bthci_CmdAcceptLogicalLink(
3012 struct packet_irp_hcicmd_data *pHciCmd 2993 struct packet_irp_hcicmd_data *pHciCmd
3013 ) 2994 )
3014{ 2995{
3015 enum hci_status status = HCI_STATUS_SUCCESS;
3016 struct bt_30info *pBTInfo = GET_BT_INFO(padapter); 2996 struct bt_30info *pBTInfo = GET_BT_INFO(padapter);
3017 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg; 2997 struct bt_dgb *pBtDbg = &pBTInfo->BtDbg;
3018 2998
@@ -3021,7 +3001,7 @@ bthci_CmdAcceptLogicalLink(
3021 bthci_BuildLogicalLink(padapter, pHciCmd, 3001 bthci_BuildLogicalLink(padapter, pHciCmd,
3022 HCI_ACCEPT_LOGICAL_LINK); 3002 HCI_ACCEPT_LOGICAL_LINK);
3023 3003
3024 return status; 3004 return HCI_STATUS_SUCCESS;
3025} 3005}
3026 3006
3027static enum hci_status 3007static enum hci_status
@@ -4138,15 +4118,6 @@ bthci_CmdHostBufferSize(struct rtw_adapter *padapter,
4138} 4118}
4139 4119
4140static enum hci_status 4120static enum hci_status
4141bthci_CmdHostNumberOfCompletedPackets(struct rtw_adapter *padapter,
4142 struct packet_irp_hcicmd_data *pHciCmd)
4143{
4144 enum hci_status status = HCI_STATUS_SUCCESS;
4145
4146 return status;
4147}
4148
4149static enum hci_status
4150bthci_UnknownCMD(struct rtw_adapter *padapter, struct packet_irp_hcicmd_data *pHciCmd) 4121bthci_UnknownCMD(struct rtw_adapter *padapter, struct packet_irp_hcicmd_data *pHciCmd)
4151{ 4122{
4152 enum hci_status status = HCI_STATUS_UNKNOW_HCI_CMD; 4123 enum hci_status status = HCI_STATUS_UNKNOW_HCI_CMD;
@@ -4219,7 +4190,6 @@ bthci_HandleOGFSetEventMaskCMD(struct rtw_adapter *padapter,
4219 break; 4190 break;
4220 case HCI_SET_EVENT_FILTER: 4191 case HCI_SET_EVENT_FILTER:
4221 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SET_EVENT_FILTER\n")); 4192 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_SET_EVENT_FILTER\n"));
4222 status = bthci_CmdSetEventFilter(padapter, pHciCmd);
4223 break; 4193 break;
4224 case HCI_WRITE_CONNECTION_ACCEPT_TIMEOUT: 4194 case HCI_WRITE_CONNECTION_ACCEPT_TIMEOUT:
4225 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_CONNECTION_ACCEPT_TIMEOUT\n")); 4195 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_WRITE_CONNECTION_ACCEPT_TIMEOUT\n"));
@@ -4235,7 +4205,6 @@ bthci_HandleOGFSetEventMaskCMD(struct rtw_adapter *padapter,
4235 break; 4205 break;
4236 case HCI_HOST_NUMBER_OF_COMPLETED_PACKETS: 4206 case HCI_HOST_NUMBER_OF_COMPLETED_PACKETS:
4237 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_HOST_NUMBER_OF_COMPLETED_PACKETS\n")); 4207 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_HOST_NUMBER_OF_COMPLETED_PACKETS\n"));
4238 status = bthci_CmdHostNumberOfCompletedPackets(padapter, pHciCmd);
4239 break; 4208 break;
4240 case HCI_READ_LINK_SUPERVISION_TIMEOUT: 4209 case HCI_READ_LINK_SUPERVISION_TIMEOUT:
4241 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LINK_SUPERVISION_TIMEOUT\n")); 4210 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LINK_SUPERVISION_TIMEOUT\n"));
@@ -4323,7 +4292,6 @@ bthci_HandleOGFStatusParameters(struct rtw_adapter *padapter,
4323 break; 4292 break;
4324 case HCI_READ_RSSI: 4293 case HCI_READ_RSSI:
4325 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_RSSI\n")); 4294 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_RSSI\n"));
4326 status = bthci_CmdReadRSSI(padapter);
4327 break; 4295 break;
4328 case HCI_READ_LOCAL_AMP_INFO: 4296 case HCI_READ_LOCAL_AMP_INFO:
4329 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_AMP_INFO\n")); 4297 RTPRINT(FIOCTL, IOCTL_BT_HCICMD, ("HCI_READ_LOCAL_AMP_INFO\n"));
@@ -10671,7 +10639,7 @@ void BTDM_BBBackOffLevel(struct rtw_adapter *padapter, u8 type)
10671 10639
10672void BTDM_FWCoexAllOff(struct rtw_adapter *padapter) 10640void BTDM_FWCoexAllOff(struct rtw_adapter *padapter)
10673{ 10641{
10674 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);; 10642 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10675 10643
10676 RTPRINT(FBT, BT_TRACE, ("BTDM_FWCoexAllOff()\n")); 10644 RTPRINT(FBT, BT_TRACE, ("BTDM_FWCoexAllOff()\n"));
10677 if (pHalData->bt_coexist.bFWCoexistAllOff) 10645 if (pHalData->bt_coexist.bFWCoexistAllOff)
@@ -10685,7 +10653,7 @@ void BTDM_FWCoexAllOff(struct rtw_adapter *padapter)
10685 10653
10686void BTDM_SWCoexAllOff(struct rtw_adapter *padapter) 10654void BTDM_SWCoexAllOff(struct rtw_adapter *padapter)
10687{ 10655{
10688 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);; 10656 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10689 10657
10690 RTPRINT(FBT, BT_TRACE, ("BTDM_SWCoexAllOff()\n")); 10658 RTPRINT(FBT, BT_TRACE, ("BTDM_SWCoexAllOff()\n"));
10691 if (pHalData->bt_coexist.bSWCoexistAllOff) 10659 if (pHalData->bt_coexist.bSWCoexistAllOff)
@@ -10698,7 +10666,7 @@ void BTDM_SWCoexAllOff(struct rtw_adapter *padapter)
10698 10666
10699void BTDM_HWCoexAllOff(struct rtw_adapter *padapter) 10667void BTDM_HWCoexAllOff(struct rtw_adapter *padapter)
10700{ 10668{
10701 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);; 10669 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
10702 10670
10703 RTPRINT(FBT, BT_TRACE, ("BTDM_HWCoexAllOff()\n")); 10671 RTPRINT(FBT, BT_TRACE, ("BTDM_HWCoexAllOff()\n"));
10704 if (pHalData->bt_coexist.bHWCoexistAllOff) 10672 if (pHalData->bt_coexist.bHWCoexistAllOff)
diff --git a/drivers/staging/rtl8723au/hal/rtl8723a_cmd.c b/drivers/staging/rtl8723au/hal/rtl8723a_cmd.c
index 271c33d6ca5a..7b56411cc3c8 100644
--- a/drivers/staging/rtl8723au/hal/rtl8723a_cmd.c
+++ b/drivers/staging/rtl8723au/hal/rtl8723a_cmd.c
@@ -115,19 +115,16 @@ exit:
115 115
116int rtl8723a_set_rssi_cmd(struct rtw_adapter *padapter, u8 *param) 116int rtl8723a_set_rssi_cmd(struct rtw_adapter *padapter, u8 *param)
117{ 117{
118 int res = _SUCCESS;
119
120 *((u32 *)param) = cpu_to_le32(*((u32 *)param)); 118 *((u32 *)param) = cpu_to_le32(*((u32 *)param));
121 119
122 FillH2CCmd(padapter, RSSI_SETTING_EID, 3, param); 120 FillH2CCmd(padapter, RSSI_SETTING_EID, 3, param);
123 121
124 return res; 122 return _SUCCESS;
125} 123}
126 124
127int rtl8723a_set_raid_cmd(struct rtw_adapter *padapter, u32 mask, u8 arg) 125int rtl8723a_set_raid_cmd(struct rtw_adapter *padapter, u32 mask, u8 arg)
128{ 126{
129 u8 buf[5]; 127 u8 buf[5];
130 int res = _SUCCESS;
131 128
132 memset(buf, 0, 5); 129 memset(buf, 0, 5);
133 mask = cpu_to_le32(mask); 130 mask = cpu_to_le32(mask);
@@ -136,7 +133,7 @@ int rtl8723a_set_raid_cmd(struct rtw_adapter *padapter, u32 mask, u8 arg)
136 133
137 FillH2CCmd(padapter, MACID_CONFIG_EID, 5, buf); 134 FillH2CCmd(padapter, MACID_CONFIG_EID, 5, buf);
138 135
139 return res; 136 return _SUCCESS;
140} 137}
141 138
142/* bitmap[0:27] = tx_rate_bitmap */ 139/* bitmap[0:27] = tx_rate_bitmap */
diff --git a/drivers/staging/rtl8723au/hal/rtl8723a_hal_init.c b/drivers/staging/rtl8723au/hal/rtl8723a_hal_init.c
index 8523908d5e5f..a5eadd4e2580 100644
--- a/drivers/staging/rtl8723au/hal/rtl8723a_hal_init.c
+++ b/drivers/staging/rtl8723au/hal/rtl8723a_hal_init.c
@@ -47,29 +47,19 @@ static void _FWDownloadEnable(struct rtw_adapter *padapter, bool enable)
47 } 47 }
48} 48}
49 49
50static int _BlockWrite(struct rtw_adapter *padapter, void *buffer, u32 buffSize)
51{
52 int ret;
53
54 if (buffSize > MAX_PAGE_SIZE)
55 return _FAIL;
56
57 ret = rtl8723au_writeN(padapter, FW_8723A_START_ADDRESS,
58 buffSize, buffer);
59
60 return ret;
61}
62
63static int 50static int
64_PageWrite(struct rtw_adapter *padapter, u32 page, void *buffer, u32 size) 51_PageWrite(struct rtw_adapter *padapter, u32 page, void *buffer, u32 size)
65{ 52{
66 u8 value8; 53 u8 value8;
67 u8 u8Page = (u8) (page & 0x07); 54 u8 u8Page = (u8) (page & 0x07);
68 55
56 if (size > MAX_PAGE_SIZE)
57 return _FAIL;
58
69 value8 = (rtl8723au_read8(padapter, REG_MCUFWDL + 2) & 0xF8) | u8Page; 59 value8 = (rtl8723au_read8(padapter, REG_MCUFWDL + 2) & 0xF8) | u8Page;
70 rtl8723au_write8(padapter, REG_MCUFWDL + 2, value8); 60 rtl8723au_write8(padapter, REG_MCUFWDL + 2, value8);
71 61
72 return _BlockWrite(padapter, buffer, size); 62 return rtl8723au_writeN(padapter, FW_8723A_START_ADDRESS, size, buffer);
73} 63}
74 64
75static int _WriteFW(struct rtw_adapter *padapter, void *buffer, u32 size) 65static int _WriteFW(struct rtw_adapter *padapter, void *buffer, u32 size)
@@ -743,84 +733,6 @@ u16 rtl8723a_EfuseGetCurrentSize_BT(struct rtw_adapter *padapter)
743 return retU2; 733 return retU2;
744} 734}
745 735
746bool
747rtl8723a_EfusePgPacketRead(struct rtw_adapter *padapter, u8 offset, u8 *data)
748{
749 u8 efuse_data, word_cnts = 0;
750 u16 efuse_addr = 0;
751 u8 hoffset = 0, hworden = 0;
752 u8 i;
753 u8 max_section = 0;
754 s32 ret;
755
756 if (data == NULL)
757 return false;
758
759 EFUSE_GetEfuseDefinition23a(padapter, EFUSE_WIFI, TYPE_EFUSE_MAX_SECTION,
760 &max_section);
761 if (offset > max_section) {
762 DBG_8723A("%s: Packet offset(%d) is illegal(>%d)!\n",
763 __func__, offset, max_section);
764 return false;
765 }
766
767 memset(data, 0xFF, PGPKT_DATA_SIZE);
768 ret = true;
769
770 /* */
771 /* <Roger_TODO> Efuse has been pre-programmed dummy 5Bytes at the
772 end of Efuse by CP. */
773 /* Skip dummy parts to prevent unexpected data read from Efuse. */
774 /* By pass right now. 2009.02.19. */
775 /* */
776 while (AVAILABLE_EFUSE_ADDR(efuse_addr)) {
777 if (efuse_OneByteRead23a(padapter, efuse_addr++, &efuse_data) ==
778 _FAIL) {
779 ret = false;
780 break;
781 }
782
783 if (efuse_data == 0xFF)
784 break;
785
786 if (EXT_HEADER(efuse_data)) {
787 hoffset = GET_HDR_OFFSET_2_0(efuse_data);
788 efuse_OneByteRead23a(padapter, efuse_addr++, &efuse_data);
789 if (ALL_WORDS_DISABLED(efuse_data)) {
790 DBG_8723A("%s: Error!! All words disabled!\n",
791 __func__);
792 continue;
793 }
794
795 hoffset |= ((efuse_data & 0xF0) >> 1);
796 hworden = efuse_data & 0x0F;
797 } else {
798 hoffset = (efuse_data >> 4) & 0x0F;
799 hworden = efuse_data & 0x0F;
800 }
801
802 if (hoffset == offset) {
803 for (i = 0; i < EFUSE_MAX_WORD_UNIT; i++) {
804 /* Check word enable condition in the section */
805 if (!(hworden & (0x01 << i))) {
806 ReadEFuseByte23a(padapter, efuse_addr++,
807 &efuse_data);
808 data[i * 2] = efuse_data;
809
810 ReadEFuseByte23a(padapter, efuse_addr++,
811 &efuse_data);
812 data[(i * 2) + 1] = efuse_data;
813 }
814 }
815 } else {
816 word_cnts = Efuse_CalculateWordCnts23a(hworden);
817 efuse_addr += word_cnts * 2;
818 }
819 }
820
821 return ret;
822}
823
824void rtl8723a_read_chip_version(struct rtw_adapter *padapter) 736void rtl8723a_read_chip_version(struct rtw_adapter *padapter)
825{ 737{
826 u32 value32; 738 u32 value32;
@@ -1126,6 +1038,21 @@ exit:
1126 return ret; 1038 return ret;
1127} 1039}
1128 1040
1041void handle_txrpt_ccx_8723a(struct rtw_adapter *adapter, void *buf)
1042{
1043 struct txrpt_ccx_8723a *txrpt_ccx = buf;
1044 struct submit_ctx *pack_tx_ops = &adapter->xmitpriv.ack_tx_ops;
1045
1046 if (txrpt_ccx->int_ccx && adapter->xmitpriv.ack_tx) {
1047 if (txrpt_ccx->pkt_ok)
1048 rtw23a_sctx_done_err(&pack_tx_ops,
1049 RTW_SCTX_DONE_SUCCESS);
1050 else
1051 rtw23a_sctx_done_err(&pack_tx_ops,
1052 RTW_SCTX_DONE_CCX_PKT_FAIL);
1053 }
1054}
1055
1129void rtl8723a_InitAntenna_Selection(struct rtw_adapter *padapter) 1056void rtl8723a_InitAntenna_Selection(struct rtw_adapter *padapter)
1130{ 1057{
1131 u8 val; 1058 u8 val;
@@ -1326,18 +1253,17 @@ c. APSD_CTRL 0x600[7:0] = 0x40
1326d. SYS_FUNC_EN 0x02[7:0] = 0x16 reset BB state machine 1253d. SYS_FUNC_EN 0x02[7:0] = 0x16 reset BB state machine
1327e. SYS_FUNC_EN 0x02[7:0] = 0x14 reset BB state machine 1254e. SYS_FUNC_EN 0x02[7:0] = 0x14 reset BB state machine
1328***************************************/ 1255***************************************/
1329 u8 eRFPath = 0, value8 = 0; 1256 u8 value8;
1330 1257
1331 rtl8723au_write8(padapter, REG_TXPAUSE, 0xFF); 1258 rtl8723au_write8(padapter, REG_TXPAUSE, 0xFF);
1332 1259
1333 PHY_SetRFReg(padapter, (enum RF_RADIO_PATH) eRFPath, 0x0, bMaskByte0, 0x0); 1260 PHY_SetRFReg(padapter, RF_PATH_A, 0x0, bMaskByte0, 0x0);
1334 1261
1335 value8 |= APSDOFF; 1262 value8 = APSDOFF;
1336 rtl8723au_write8(padapter, REG_APSD_CTRL, value8); /* 0x40 */ 1263 rtl8723au_write8(padapter, REG_APSD_CTRL, value8); /* 0x40 */
1337 1264
1338 /* Set BB reset at first */ 1265 /* Set BB reset at first */
1339 value8 = 0; 1266 value8 = FEN_USBD | FEN_USBA | FEN_BB_GLB_RSTn;
1340 value8 |= (FEN_USBD | FEN_USBA | FEN_BB_GLB_RSTn);
1341 rtl8723au_write8(padapter, REG_SYS_FUNC_EN, value8); /* 0x16 */ 1267 rtl8723au_write8(padapter, REG_SYS_FUNC_EN, value8); /* 0x16 */
1342 1268
1343 /* Set global reset. */ 1269 /* Set global reset. */
@@ -1350,11 +1276,6 @@ e. SYS_FUNC_EN 0x02[7:0] = 0x14 reset BB state machine
1350/* RT_TRACE(COMP_INIT, DBG_LOUD, ("======> RF off and reset BB.\n")); */ 1276/* RT_TRACE(COMP_INIT, DBG_LOUD, ("======> RF off and reset BB.\n")); */
1351} 1277}
1352 1278
1353static void _DisableRFAFEAndResetBB(struct rtw_adapter *padapter)
1354{
1355 _DisableRFAFEAndResetBB8192C(padapter);
1356}
1357
1358static void _ResetDigitalProcedure1_92C(struct rtw_adapter *padapter, 1279static void _ResetDigitalProcedure1_92C(struct rtw_adapter *padapter,
1359 bool bWithoutHWSM) 1280 bool bWithoutHWSM)
1360{ 1281{
@@ -1368,18 +1289,18 @@ static void _ResetDigitalProcedure1_92C(struct rtw_adapter *padapter,
1368 i. SYS_FUNC_EN 0x02[10]= 1 enable MCU register, 1289 i. SYS_FUNC_EN 0x02[10]= 1 enable MCU register,
1369 (8051 enable) 1290 (8051 enable)
1370 ******************************/ 1291 ******************************/
1371 u16 valu16 = 0; 1292 u16 valu16;
1372 rtl8723au_write8(padapter, REG_MCUFWDL, 0); 1293 rtl8723au_write8(padapter, REG_MCUFWDL, 0);
1373 1294
1374 valu16 = rtl8723au_read16(padapter, REG_SYS_FUNC_EN); 1295 valu16 = rtl8723au_read16(padapter, REG_SYS_FUNC_EN);
1375 /* reset MCU , 8051 */ 1296 /* reset MCU , 8051 */
1376 rtl8723au_write16(padapter, REG_SYS_FUNC_EN, 1297 rtl8723au_write16(padapter, REG_SYS_FUNC_EN,
1377 valu16 & (~FEN_CPUEN)); 1298 valu16 & ~FEN_CPUEN);
1378 1299
1379 valu16 = rtl8723au_read16(padapter, REG_SYS_FUNC_EN) & 0x0FFF; 1300 valu16 = rtl8723au_read16(padapter, REG_SYS_FUNC_EN) & 0x0FFF;
1380 /* reset MAC */ 1301 /* reset MAC */
1381 rtl8723au_write16(padapter, REG_SYS_FUNC_EN, 1302 rtl8723au_write16(padapter, REG_SYS_FUNC_EN,
1382 valu16 | (FEN_HWPDN | FEN_ELDR)); 1303 valu16 | FEN_HWPDN | FEN_ELDR);
1383 1304
1384 valu16 = rtl8723au_read16(padapter, REG_SYS_FUNC_EN); 1305 valu16 = rtl8723au_read16(padapter, REG_SYS_FUNC_EN);
1385 /* enable MCU , 8051 */ 1306 /* enable MCU , 8051 */
@@ -1387,43 +1308,41 @@ static void _ResetDigitalProcedure1_92C(struct rtw_adapter *padapter,
1387 valu16 | FEN_CPUEN); 1308 valu16 | FEN_CPUEN);
1388 } else { 1309 } else {
1389 u8 retry_cnts = 0; 1310 u8 retry_cnts = 0;
1311 u8 val8;
1312
1313 val8 = rtl8723au_read8(padapter, REG_MCUFWDL);
1390 1314
1391 /* 2010/08/12 MH For USB SS, we can not stop 8051 when we 1315 /* 2010/08/12 MH For USB SS, we can not stop 8051 when we
1392 are trying to enter IPS/HW&SW radio off. For 1316 are trying to enter IPS/HW&SW radio off. For
1393 S3/S4/S5/Disable, we can stop 8051 because */ 1317 S3/S4/S5/Disable, we can stop 8051 because */
1394 /* we will init FW when power on again. */ 1318 /* we will init FW when power on again. */
1395 /* If we want to SS mode, we can not reset 8051. */ 1319 /* If we want to SS mode, we can not reset 8051. */
1396 if (rtl8723au_read8(padapter, REG_MCUFWDL) & BIT(1)) { 1320 if ((val8 & BIT(1)) && padapter->bFWReady) {
1397 /* IF fw in RAM code, do reset */ 1321 /* IF fw in RAM code, do reset */
1398 if (padapter->bFWReady) { 1322 /* 2010/08/25 MH Accordign to RD alfred's
1399 /* 2010/08/25 MH Accordign to RD alfred's 1323 suggestion, we need to disable other */
1400 suggestion, we need to disable other */ 1324 /* HRCV INT to influence 8051 reset. */
1401 /* HRCV INT to influence 8051 reset. */ 1325 rtl8723au_write8(padapter, REG_FWIMR, 0x20);
1402 rtl8723au_write8(padapter, REG_FWIMR, 0x20); 1326 /* 2011/02/15 MH According to Alex's
1403 /* 2011/02/15 MH According to Alex's 1327 suggestion, close mask to prevent
1404 suggestion, close mask to prevent 1328 incorrect FW write operation. */
1405 incorrect FW write operation. */ 1329 rtl8723au_write8(padapter, REG_FTIMR, 0x00);
1406 rtl8723au_write8(padapter, REG_FTIMR, 0x00); 1330 rtl8723au_write8(padapter, REG_FSIMR, 0x00);
1407 rtl8723au_write8(padapter, REG_FSIMR, 0x00); 1331
1408 1332 /* 8051 reset by self */
1409 /* 8051 reset by self */ 1333 rtl8723au_write8(padapter, REG_HMETFR + 3, 0x20);
1410 rtl8723au_write8(padapter, REG_HMETFR + 3, 1334
1411 0x20); 1335 while ((retry_cnts++ < 100) &&
1412 1336 (rtl8723au_read16(padapter, REG_SYS_FUNC_EN) &
1413 while ((retry_cnts++ < 100) && 1337 FEN_CPUEN)) {
1414 (FEN_CPUEN & 1338 udelay(50); /* us */
1415 rtl8723au_read16(padapter, 1339 }
1416 REG_SYS_FUNC_EN))) {
1417 udelay(50); /* us */
1418 }
1419 1340
1420 if (retry_cnts >= 100) { 1341 if (retry_cnts >= 100) {
1421 /* Reset MAC and Enable 8051 */ 1342 /* Reset MAC and Enable 8051 */
1422 rtl8723au_write8(padapter, 1343 rtl8723au_write8(padapter,
1423 REG_SYS_FUNC_EN + 1, 1344 REG_SYS_FUNC_EN + 1, 0x50);
1424 0x50); 1345 mdelay(10);
1425 mdelay(10);
1426 }
1427 } 1346 }
1428 } 1347 }
1429 /* Reset MAC and Enable 8051 */ 1348 /* Reset MAC and Enable 8051 */
@@ -1450,12 +1369,6 @@ static void _ResetDigitalProcedure1_92C(struct rtw_adapter *padapter,
1450 } 1369 }
1451} 1370}
1452 1371
1453static void _ResetDigitalProcedure1(struct rtw_adapter *padapter,
1454 bool bWithoutHWSM)
1455{
1456 _ResetDigitalProcedure1_92C(padapter, bWithoutHWSM);
1457}
1458
1459static void _ResetDigitalProcedure2(struct rtw_adapter *padapter) 1372static void _ResetDigitalProcedure2(struct rtw_adapter *padapter)
1460{ 1373{
1461/***************************** 1374/*****************************
@@ -1472,8 +1385,8 @@ m. SYS_ISO_CTRL 0x01[7:0] = 0x83 isolated ELDR to PON
1472static void _DisableAnalog(struct rtw_adapter *padapter, bool bWithoutHWSM) 1385static void _DisableAnalog(struct rtw_adapter *padapter, bool bWithoutHWSM)
1473{ 1386{
1474 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter); 1387 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
1475 u16 value16 = 0; 1388 u16 value16;
1476 u8 value8 = 0; 1389 u8 value8;
1477 1390
1478 if (bWithoutHWSM) { 1391 if (bWithoutHWSM) {
1479 /***************************** 1392 /*****************************
@@ -1487,7 +1400,7 @@ static void _DisableAnalog(struct rtw_adapter *padapter, bool bWithoutHWSM)
1487 /* rtl8723au_write8(padapter, REG_LDOV12D_CTRL, 0x54); */ 1400 /* rtl8723au_write8(padapter, REG_LDOV12D_CTRL, 0x54); */
1488 1401
1489 value8 = rtl8723au_read8(padapter, REG_LDOV12D_CTRL); 1402 value8 = rtl8723au_read8(padapter, REG_LDOV12D_CTRL);
1490 value8 &= (~LDV12_EN); 1403 value8 &= ~LDV12_EN;
1491 rtl8723au_write8(padapter, REG_LDOV12D_CTRL, value8); 1404 rtl8723au_write8(padapter, REG_LDOV12D_CTRL, value8);
1492/* RT_TRACE(COMP_INIT, DBG_LOUD, 1405/* RT_TRACE(COMP_INIT, DBG_LOUD,
1493 (" REG_LDOV12D_CTRL Reg0x21:0x%02x.\n", value8)); */ 1406 (" REG_LDOV12D_CTRL Reg0x21:0x%02x.\n", value8)); */
@@ -1509,9 +1422,9 @@ static void _DisableAnalog(struct rtw_adapter *padapter, bool bWithoutHWSM)
1509 use HW to shut down 8051 automatically. */ 1422 use HW to shut down 8051 automatically. */
1510 /* Becasue suspend operatione need the asistance of 8051 1423 /* Becasue suspend operatione need the asistance of 8051
1511 to wait for 3ms. */ 1424 to wait for 3ms. */
1512 value16 |= (APDM_HOST | AFSM_HSUS | PFM_ALDN); 1425 value16 = APDM_HOST | AFSM_HSUS | PFM_ALDN;
1513 } else { 1426 } else {
1514 value16 |= (APDM_HOST | AFSM_HSUS | PFM_ALDN); 1427 value16 = APDM_HOST | AFSM_HSUS | PFM_ALDN;
1515 } 1428 }
1516 1429
1517 rtl8723au_write16(padapter, REG_APS_FSMCO, value16); /* 0x4802 */ 1430 rtl8723au_write16(padapter, REG_APS_FSMCO, value16); /* 0x4802 */
@@ -1522,16 +1435,14 @@ static void _DisableAnalog(struct rtw_adapter *padapter, bool bWithoutHWSM)
1522/* HW Auto state machine */ 1435/* HW Auto state machine */
1523int CardDisableHWSM(struct rtw_adapter *padapter, u8 resetMCU) 1436int CardDisableHWSM(struct rtw_adapter *padapter, u8 resetMCU)
1524{ 1437{
1525 int rtStatus = _SUCCESS;
1526
1527 if (padapter->bSurpriseRemoved) { 1438 if (padapter->bSurpriseRemoved) {
1528 return rtStatus; 1439 return _SUCCESS;
1529 } 1440 }
1530 /* RF Off Sequence ==== */ 1441 /* RF Off Sequence ==== */
1531 _DisableRFAFEAndResetBB(padapter); 1442 _DisableRFAFEAndResetBB8192C(padapter);
1532 1443
1533 /* ==== Reset digital sequence ====== */ 1444 /* ==== Reset digital sequence ====== */
1534 _ResetDigitalProcedure1(padapter, false); 1445 _ResetDigitalProcedure1_92C(padapter, false);
1535 1446
1536 /* ==== Pull GPIO PIN to balance level and LED control ====== */ 1447 /* ==== Pull GPIO PIN to balance level and LED control ====== */
1537 _DisableGPIO(padapter); 1448 _DisableGPIO(padapter);
@@ -1542,25 +1453,21 @@ int CardDisableHWSM(struct rtw_adapter *padapter, u8 resetMCU)
1542 RT_TRACE(_module_hci_hal_init_c_, _drv_info_, 1453 RT_TRACE(_module_hci_hal_init_c_, _drv_info_,
1543 ("======> Card disable finished.\n")); 1454 ("======> Card disable finished.\n"));
1544 1455
1545 return rtStatus; 1456 return _SUCCESS;
1546} 1457}
1547 1458
1548/* without HW Auto state machine */ 1459/* without HW Auto state machine */
1549int CardDisableWithoutHWSM(struct rtw_adapter *padapter) 1460int CardDisableWithoutHWSM(struct rtw_adapter *padapter)
1550{ 1461{
1551 int rtStatus = _SUCCESS;
1552
1553 /* RT_TRACE(COMP_INIT, DBG_LOUD,
1554 ("======> Card Disable Without HWSM .\n")); */
1555 if (padapter->bSurpriseRemoved) { 1462 if (padapter->bSurpriseRemoved) {
1556 return rtStatus; 1463 return _SUCCESS;
1557 } 1464 }
1558 1465
1559 /* RF Off Sequence ==== */ 1466 /* RF Off Sequence ==== */
1560 _DisableRFAFEAndResetBB(padapter); 1467 _DisableRFAFEAndResetBB8192C(padapter);
1561 1468
1562 /* ==== Reset digital sequence ====== */ 1469 /* ==== Reset digital sequence ====== */
1563 _ResetDigitalProcedure1(padapter, true); 1470 _ResetDigitalProcedure1_92C(padapter, true);
1564 1471
1565 /* ==== Pull GPIO PIN to balance level and LED control ====== */ 1472 /* ==== Pull GPIO PIN to balance level and LED control ====== */
1566 _DisableGPIO(padapter); 1473 _DisableGPIO(padapter);
@@ -1573,29 +1480,27 @@ int CardDisableWithoutHWSM(struct rtw_adapter *padapter)
1573 1480
1574 /* RT_TRACE(COMP_INIT, DBG_LOUD, 1481 /* RT_TRACE(COMP_INIT, DBG_LOUD,
1575 ("<====== Card Disable Without HWSM .\n")); */ 1482 ("<====== Card Disable Without HWSM .\n")); */
1576 return rtStatus; 1483 return _SUCCESS;
1577} 1484}
1578 1485
1579void Hal_InitPGData(struct rtw_adapter *padapter, u8 *PROMContent) 1486void Hal_InitPGData(struct rtw_adapter *padapter, u8 *PROMContent)
1580{ 1487{
1581 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter); 1488 struct eeprom_priv *pEEPROM = GET_EEPROM_EFUSE_PRIV(padapter);
1582 1489
1583 if (false == pEEPROM->bautoload_fail_flag) { /* autoload OK. */ 1490 if (!pEEPROM->bautoload_fail_flag) { /* autoload OK. */
1584 if (!pEEPROM->EepromOrEfuse) { 1491 if (!pEEPROM->EepromOrEfuse) {
1585 /* Read EFUSE real map to shadow. */ 1492 /* Read EFUSE real map to shadow. */
1586 EFUSE_ShadowMapUpdate23a(padapter, EFUSE_WIFI); 1493 EFUSE_ShadowMapUpdate23a(padapter, EFUSE_WIFI);
1587 memcpy((void *)PROMContent, 1494 memcpy(PROMContent, pEEPROM->efuse_eeprom_data,
1588 (void *)pEEPROM->efuse_eeprom_data,
1589 HWSET_MAX_SIZE); 1495 HWSET_MAX_SIZE);
1590 } 1496 }
1591 } else { /* autoload fail */ 1497 } else {
1592 RT_TRACE(_module_hci_hal_init_c_, _drv_notice_, 1498 RT_TRACE(_module_hci_hal_init_c_, _drv_notice_,
1593 ("AutoLoad Fail reported from CR9346!!\n")); 1499 ("AutoLoad Fail reported from CR9346!!\n"));
1594/* pHalData->AutoloadFailFlag = true; */
1595 /* update to default value 0xFF */ 1500 /* update to default value 0xFF */
1596 if (false == pEEPROM->EepromOrEfuse) 1501 if (!pEEPROM->EepromOrEfuse)
1597 EFUSE_ShadowMapUpdate23a(padapter, EFUSE_WIFI); 1502 EFUSE_ShadowMapUpdate23a(padapter, EFUSE_WIFI);
1598 memcpy((void *)PROMContent, (void *)pEEPROM->efuse_eeprom_data, 1503 memcpy(PROMContent, pEEPROM->efuse_eeprom_data,
1599 HWSET_MAX_SIZE); 1504 HWSET_MAX_SIZE);
1600 } 1505 }
1601} 1506}
@@ -1945,13 +1850,13 @@ Hal_EfuseParseThermalMeter_8723A(struct rtw_adapter *padapter,
1945 /* */ 1850 /* */
1946 /* ThermalMeter from EEPROM */ 1851 /* ThermalMeter from EEPROM */
1947 /* */ 1852 /* */
1948 if (AutoloadFail == false) 1853 if (!AutoloadFail)
1949 pHalData->EEPROMThermalMeter = 1854 pHalData->EEPROMThermalMeter =
1950 PROMContent[EEPROM_THERMAL_METER_8723A]; 1855 PROMContent[EEPROM_THERMAL_METER_8723A];
1951 else 1856 else
1952 pHalData->EEPROMThermalMeter = EEPROM_Default_ThermalMeter; 1857 pHalData->EEPROMThermalMeter = EEPROM_Default_ThermalMeter;
1953 1858
1954 if ((pHalData->EEPROMThermalMeter == 0xff) || (AutoloadFail == true)) { 1859 if ((pHalData->EEPROMThermalMeter == 0xff) || AutoloadFail) {
1955 pHalData->bAPKThermalMeterIgnore = true; 1860 pHalData->bAPKThermalMeterIgnore = true;
1956 pHalData->EEPROMThermalMeter = EEPROM_Default_ThermalMeter; 1861 pHalData->EEPROMThermalMeter = EEPROM_Default_ThermalMeter;
1957 } 1862 }
@@ -1960,10 +1865,6 @@ Hal_EfuseParseThermalMeter_8723A(struct rtw_adapter *padapter,
1960 pHalData->EEPROMThermalMeter); 1865 pHalData->EEPROMThermalMeter);
1961} 1866}
1962 1867
1963void Hal_InitChannelPlan23a(struct rtw_adapter *padapter)
1964{
1965}
1966
1967static void rtl8723a_cal_txdesc_chksum(struct tx_desc *ptxdesc) 1868static void rtl8723a_cal_txdesc_chksum(struct tx_desc *ptxdesc)
1968{ 1869{
1969 u16 *usPtr = (u16 *) ptxdesc; 1870 u16 *usPtr = (u16 *) ptxdesc;
@@ -1981,254 +1882,6 @@ static void rtl8723a_cal_txdesc_chksum(struct tx_desc *ptxdesc)
1981 ptxdesc->txdw7 |= cpu_to_le32(checksum & 0x0000ffff); 1882 ptxdesc->txdw7 |= cpu_to_le32(checksum & 0x0000ffff);
1982} 1883}
1983 1884
1984static void fill_txdesc_sectype(struct pkt_attrib *pattrib,
1985 struct txdesc_8723a *ptxdesc)
1986{
1987 if ((pattrib->encrypt > 0) && !pattrib->bswenc) {
1988 switch (pattrib->encrypt) {
1989 /* SEC_TYPE */
1990 case WLAN_CIPHER_SUITE_WEP40:
1991 case WLAN_CIPHER_SUITE_WEP104:
1992 case WLAN_CIPHER_SUITE_TKIP:
1993 ptxdesc->sectype = 1;
1994 break;
1995
1996 case WLAN_CIPHER_SUITE_CCMP:
1997 ptxdesc->sectype = 3;
1998 break;
1999
2000 case 0:
2001 default:
2002 break;
2003 }
2004 }
2005}
2006
2007static void fill_txdesc_vcs(struct pkt_attrib *pattrib,
2008 struct txdesc_8723a *ptxdesc)
2009{
2010 /* DBG_8723A("cvs_mode =%d\n", pattrib->vcs_mode); */
2011
2012 switch (pattrib->vcs_mode) {
2013 case RTS_CTS:
2014 ptxdesc->rtsen = 1;
2015 break;
2016
2017 case CTS_TO_SELF:
2018 ptxdesc->cts2self = 1;
2019 break;
2020
2021 case NONE_VCS:
2022 default:
2023 break;
2024 }
2025
2026 if (pattrib->vcs_mode) {
2027 ptxdesc->hw_rts_en = 1; /* ENABLE HW RTS */
2028
2029 /* Set RTS BW */
2030 if (pattrib->ht_en) {
2031 if (pattrib->bwmode & HT_CHANNEL_WIDTH_40)
2032 ptxdesc->rts_bw = 1;
2033
2034 switch (pattrib->ch_offset) {
2035 case HAL_PRIME_CHNL_OFFSET_DONT_CARE:
2036 ptxdesc->rts_sc = 0;
2037 break;
2038
2039 case HAL_PRIME_CHNL_OFFSET_LOWER:
2040 ptxdesc->rts_sc = 1;
2041 break;
2042
2043 case HAL_PRIME_CHNL_OFFSET_UPPER:
2044 ptxdesc->rts_sc = 2;
2045 break;
2046
2047 default:
2048 ptxdesc->rts_sc = 3; /* Duplicate */
2049 break;
2050 }
2051 }
2052 }
2053}
2054
2055static void fill_txdesc_phy(struct pkt_attrib *pattrib,
2056 struct txdesc_8723a *ptxdesc)
2057{
2058 if (pattrib->ht_en) {
2059 if (pattrib->bwmode & HT_CHANNEL_WIDTH_40)
2060 ptxdesc->data_bw = 1;
2061
2062 switch (pattrib->ch_offset) {
2063 case HAL_PRIME_CHNL_OFFSET_DONT_CARE:
2064 ptxdesc->data_sc = 0;
2065 break;
2066
2067 case HAL_PRIME_CHNL_OFFSET_LOWER:
2068 ptxdesc->data_sc = 1;
2069 break;
2070
2071 case HAL_PRIME_CHNL_OFFSET_UPPER:
2072 ptxdesc->data_sc = 2;
2073 break;
2074
2075 default:
2076 ptxdesc->data_sc = 3; /* Duplicate */
2077 break;
2078 }
2079 }
2080}
2081
2082static void rtl8723a_fill_default_txdesc(struct xmit_frame *pxmitframe,
2083 u8 *pbuf)
2084{
2085 struct rtw_adapter *padapter;
2086 struct hal_data_8723a *pHalData;
2087 struct dm_priv *pdmpriv;
2088 struct mlme_ext_priv *pmlmeext;
2089 struct mlme_ext_info *pmlmeinfo;
2090 struct pkt_attrib *pattrib;
2091 struct txdesc_8723a *ptxdesc;
2092 s32 bmcst;
2093
2094 padapter = pxmitframe->padapter;
2095 pHalData = GET_HAL_DATA(padapter);
2096 pdmpriv = &pHalData->dmpriv;
2097 pmlmeext = &padapter->mlmeextpriv;
2098 pmlmeinfo = &pmlmeext->mlmext_info;
2099
2100 pattrib = &pxmitframe->attrib;
2101 bmcst = is_multicast_ether_addr(pattrib->ra);
2102
2103 ptxdesc = (struct txdesc_8723a *)pbuf;
2104
2105 if (pxmitframe->frame_tag == DATA_FRAMETAG) {
2106 ptxdesc->macid = pattrib->mac_id; /* CAM_ID(MAC_ID) */
2107
2108 if (pattrib->ampdu_en == true)
2109 ptxdesc->agg_en = 1; /* AGG EN */
2110 else
2111 ptxdesc->bk = 1; /* AGG BK */
2112
2113 ptxdesc->qsel = pattrib->qsel;
2114 ptxdesc->rate_id = pattrib->raid;
2115
2116 fill_txdesc_sectype(pattrib, ptxdesc);
2117
2118 ptxdesc->seq = pattrib->seqnum;
2119
2120 if ((pattrib->ether_type != 0x888e) &&
2121 (pattrib->ether_type != 0x0806) &&
2122 (pattrib->dhcp_pkt != 1)) {
2123 /* Non EAP & ARP & DHCP type data packet */
2124
2125 fill_txdesc_vcs(pattrib, ptxdesc);
2126 fill_txdesc_phy(pattrib, ptxdesc);
2127
2128 ptxdesc->rtsrate = 8; /* RTS Rate = 24M */
2129 ptxdesc->data_ratefb_lmt = 0x1F;
2130 ptxdesc->rts_ratefb_lmt = 0xF;
2131
2132 /* use REG_INIDATA_RATE_SEL value */
2133 ptxdesc->datarate =
2134 pdmpriv->INIDATA_RATE[pattrib->mac_id];
2135
2136 } else {
2137 /* EAP data packet and ARP packet. */
2138 /* Use the 1M data rate to send the EAP/ARP packet. */
2139 /* This will maybe make the handshake smooth. */
2140
2141 ptxdesc->bk = 1; /* AGG BK */
2142 ptxdesc->userate = 1; /* driver uses rate */
2143 if (pmlmeinfo->preamble_mode == PREAMBLE_SHORT)
2144 ptxdesc->data_short = 1;
2145 ptxdesc->datarate = MRateToHwRate23a(pmlmeext->tx_rate);
2146 }
2147 } else if (pxmitframe->frame_tag == MGNT_FRAMETAG) {
2148/* RT_TRACE(_module_hal_xmit_c_, _drv_notice_,
2149 ("%s: MGNT_FRAMETAG\n", __func__)); */
2150
2151 ptxdesc->macid = pattrib->mac_id; /* CAM_ID(MAC_ID) */
2152 ptxdesc->qsel = pattrib->qsel;
2153 ptxdesc->rate_id = pattrib->raid; /* Rate ID */
2154 ptxdesc->seq = pattrib->seqnum;
2155 ptxdesc->userate = 1; /* driver uses rate, 1M */
2156 ptxdesc->rty_lmt_en = 1; /* retry limit enable */
2157 ptxdesc->data_rt_lmt = 6; /* retry limit = 6 */
2158
2159 /* CCX-TXRPT ack for xmit mgmt frames. */
2160 if (pxmitframe->ack_report)
2161 ptxdesc->ccx = 1;
2162
2163 ptxdesc->datarate = MRateToHwRate23a(pmlmeext->tx_rate);
2164 } else if (pxmitframe->frame_tag == TXAGG_FRAMETAG) {
2165 RT_TRACE(_module_hal_xmit_c_, _drv_warning_,
2166 ("%s: TXAGG_FRAMETAG\n", __func__));
2167 } else {
2168 RT_TRACE(_module_hal_xmit_c_, _drv_warning_,
2169 ("%s: frame_tag = 0x%x\n", __func__,
2170 pxmitframe->frame_tag));
2171
2172 ptxdesc->macid = 4; /* CAM_ID(MAC_ID) */
2173 ptxdesc->rate_id = 6; /* Rate ID */
2174 ptxdesc->seq = pattrib->seqnum;
2175 ptxdesc->userate = 1; /* driver uses rate */
2176 ptxdesc->datarate = MRateToHwRate23a(pmlmeext->tx_rate);
2177 }
2178
2179 ptxdesc->pktlen = pattrib->last_txcmdsz;
2180 ptxdesc->offset = TXDESC_SIZE + OFFSET_SZ;
2181 if (bmcst)
2182 ptxdesc->bmc = 1;
2183 ptxdesc->ls = 1;
2184 ptxdesc->fs = 1;
2185 ptxdesc->own = 1;
2186
2187 /* 2009.11.05. tynli_test. Suggested by SD4 Filen for FW LPS. */
2188 /* (1) The sequence number of each non-Qos frame / broadcast /
2189 * multicast / mgnt frame should be controled by Hw because Fw
2190 * will also send null data which we cannot control when Fw LPS enable.
2191 * --> default enable non-Qos data sequense number.
2192 2010.06.23. by tynli. */
2193 /* (2) Enable HW SEQ control for beacon packet,
2194 * because we use Hw beacon. */
2195 /* (3) Use HW Qos SEQ to control the seq num of Ext port
2196 * non-Qos packets. */
2197 /* 2010.06.23. Added by tynli. */
2198 if (!pattrib->qos_en) {
2199 /* Hw set sequence number */
2200 ptxdesc->hwseq_en = 1; /* HWSEQ_EN */
2201 ptxdesc->hwseq_sel = 0; /* HWSEQ_SEL */
2202 }
2203}
2204
2205/*
2206 * Description:
2207 *
2208 * Parameters:
2209 * pxmitframe xmitframe
2210 * pbuf where to fill tx desc
2211 */
2212void rtl8723a_update_txdesc(struct xmit_frame *pxmitframe, u8 *pbuf)
2213{
2214 struct tx_desc *pdesc;
2215
2216 pdesc = (struct tx_desc *)pbuf;
2217 memset(pdesc, 0, sizeof(struct tx_desc));
2218
2219 rtl8723a_fill_default_txdesc(pxmitframe, pbuf);
2220
2221 pdesc->txdw0 = cpu_to_le32(pdesc->txdw0);
2222 pdesc->txdw1 = cpu_to_le32(pdesc->txdw1);
2223 pdesc->txdw2 = cpu_to_le32(pdesc->txdw2);
2224 pdesc->txdw3 = cpu_to_le32(pdesc->txdw3);
2225 pdesc->txdw4 = cpu_to_le32(pdesc->txdw4);
2226 pdesc->txdw5 = cpu_to_le32(pdesc->txdw5);
2227 pdesc->txdw6 = cpu_to_le32(pdesc->txdw6);
2228 pdesc->txdw7 = cpu_to_le32(pdesc->txdw7);
2229 rtl8723a_cal_txdesc_chksum(pdesc);
2230}
2231
2232/* 1885/*
2233 * Description: In normal chip, we should send some packet to Hw which 1886 * Description: In normal chip, we should send some packet to Hw which
2234 * will be used by Fw in FW LPS mode. The function is to fill the Tx 1887 * will be used by Fw in FW LPS mode. The function is to fill the Tx
diff --git a/drivers/staging/rtl8723au/hal/rtl8723a_phycfg.c b/drivers/staging/rtl8723au/hal/rtl8723a_phycfg.c
index 3d4d7ec27509..88e91cd8ebb9 100644
--- a/drivers/staging/rtl8723au/hal/rtl8723a_phycfg.c
+++ b/drivers/staging/rtl8723au/hal/rtl8723a_phycfg.c
@@ -418,7 +418,6 @@ PHY_SetRFReg(struct rtw_adapter *Adapter, enum RF_RADIO_PATH eRFPath,
418 *---------------------------------------------------------------------------*/ 418 *---------------------------------------------------------------------------*/
419int PHY_MACConfig8723A(struct rtw_adapter *Adapter) 419int PHY_MACConfig8723A(struct rtw_adapter *Adapter)
420{ 420{
421 int rtStatus = _SUCCESS;
422 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter); 421 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
423 bool is92C = IS_92C_SERIAL(pHalData->VersionID); 422 bool is92C = IS_92C_SERIAL(pHalData->VersionID);
424 423
@@ -433,7 +432,7 @@ int PHY_MACConfig8723A(struct rtw_adapter *Adapter)
433 if (is92C && (BOARD_USB_DONGLE == pHalData->BoardType)) 432 if (is92C && (BOARD_USB_DONGLE == pHalData->BoardType))
434 rtl8723au_write8(Adapter, 0x40, 0x04); 433 rtl8723au_write8(Adapter, 0x40, 0x04);
435 434
436 return rtStatus; 435 return _SUCCESS;
437} 436}
438 437
439/** 438/**
diff --git a/drivers/staging/rtl8723au/hal/rtl8723a_rf6052.c b/drivers/staging/rtl8723au/hal/rtl8723a_rf6052.c
index 2dc0886e5f90..1aad4384471c 100644
--- a/drivers/staging/rtl8723au/hal/rtl8723a_rf6052.c
+++ b/drivers/staging/rtl8723au/hal/rtl8723a_rf6052.c
@@ -42,21 +42,6 @@
42#include <rtl8723a_hal.h> 42#include <rtl8723a_hal.h>
43#include <usb_ops_linux.h> 43#include <usb_ops_linux.h>
44 44
45/*---------------------------Define Local Constant---------------------------*/
46/* Define local structure for debug!!!!! */
47struct rf_shadow_compare_map {
48 /* Shadow register value */
49 u32 Value;
50 /* Compare or not flag */
51 u8 Compare;
52 /* Record If it had ever modified unpredicted */
53 u8 ErrorOrNot;
54 /* Recorver Flag */
55 u8 Recorver;
56 /* */
57 u8 Driver_Write;
58};
59
60/*----------------------------------------------------------------------------- 45/*-----------------------------------------------------------------------------
61 * Function: PHY_RF6052SetBandwidth() 46 * Function: PHY_RF6052SetBandwidth()
62 * 47 *
@@ -71,20 +56,23 @@ struct rf_shadow_compare_map {
71 * 56 *
72 * Note: For RF type 0222D 57 * Note: For RF type 0222D
73 *---------------------------------------------------------------------------*/ 58 *---------------------------------------------------------------------------*/
74void rtl8723a_phy_rf6052set_bw( 59void rtl8723a_phy_rf6052set_bw(struct rtw_adapter *Adapter,
75 struct rtw_adapter *Adapter, 60 enum ht_channel_width Bandwidth) /* 20M or 40M */
76 enum ht_channel_width Bandwidth) /* 20M or 40M */
77{ 61{
78 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter); 62 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
79 63
80 switch (Bandwidth) { 64 switch (Bandwidth) {
81 case HT_CHANNEL_WIDTH_20: 65 case HT_CHANNEL_WIDTH_20:
82 pHalData->RfRegChnlVal[0] = ((pHalData->RfRegChnlVal[0] & 0xfffff3ff) | 0x0400); 66 pHalData->RfRegChnlVal[0] =
83 PHY_SetRFReg(Adapter, RF_PATH_A, RF_CHNLBW, bRFRegOffsetMask, pHalData->RfRegChnlVal[0]); 67 (pHalData->RfRegChnlVal[0] & 0xfffff3ff) | 0x0400;
68 PHY_SetRFReg(Adapter, RF_PATH_A, RF_CHNLBW, bRFRegOffsetMask,
69 pHalData->RfRegChnlVal[0]);
84 break; 70 break;
85 case HT_CHANNEL_WIDTH_40: 71 case HT_CHANNEL_WIDTH_40:
86 pHalData->RfRegChnlVal[0] = ((pHalData->RfRegChnlVal[0] & 0xfffff3ff)); 72 pHalData->RfRegChnlVal[0] =
87 PHY_SetRFReg(Adapter, RF_PATH_A, RF_CHNLBW, bRFRegOffsetMask, pHalData->RfRegChnlVal[0]); 73 (pHalData->RfRegChnlVal[0] & 0xfffff3ff);
74 PHY_SetRFReg(Adapter, RF_PATH_A, RF_CHNLBW, bRFRegOffsetMask,
75 pHalData->RfRegChnlVal[0]);
88 break; 76 break;
89 default: 77 default:
90 break; 78 break;
@@ -108,7 +96,8 @@ void rtl8723a_phy_rf6052set_bw(
108 * 96 *
109 *---------------------------------------------------------------------------*/ 97 *---------------------------------------------------------------------------*/
110 98
111void rtl823a_phy_rf6052setccktxpower(struct rtw_adapter *Adapter, u8 *pPowerlevel) 99void rtl823a_phy_rf6052setccktxpower(struct rtw_adapter *Adapter,
100 u8 *pPowerlevel)
112{ 101{
113 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter); 102 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
114 struct dm_priv *pdmpriv = &pHalData->dmpriv; 103 struct dm_priv *pdmpriv = &pHalData->dmpriv;
@@ -118,7 +107,8 @@ void rtl823a_phy_rf6052setccktxpower(struct rtw_adapter *Adapter, u8 *pPowerleve
118 u8 idx1, idx2; 107 u8 idx1, idx2;
119 u8 *ptr; 108 u8 *ptr;
120 109
121 /* According to SD3 eechou's suggestion, we need to disable turbo scan for RU. */ 110 /* According to SD3 eechou's suggestion, we need to disable
111 turbo scan for RU. */
122 /* Otherwise, external PA will be broken if power index > 0x20. */ 112 /* Otherwise, external PA will be broken if power index > 0x20. */
123 if (pHalData->EEPROMRegulatory != 0 || pHalData->ExternalPA) 113 if (pHalData->EEPROMRegulatory != 0 || pHalData->ExternalPA)
124 TurboScanOff = true; 114 TurboScanOff = true;
@@ -131,29 +121,37 @@ void rtl823a_phy_rf6052setccktxpower(struct rtw_adapter *Adapter, u8 *pPowerleve
131 121
132 if (TurboScanOff) { 122 if (TurboScanOff) {
133 for (idx1 = RF_PATH_A; idx1 <= RF_PATH_B; idx1++) { 123 for (idx1 = RF_PATH_A; idx1 <= RF_PATH_B; idx1++) {
134 TxAGC[idx1] = 124 TxAGC[idx1] = pPowerlevel[idx1] |
135 pPowerlevel[idx1] | (pPowerlevel[idx1]<<8) | 125 (pPowerlevel[idx1] << 8) |
136 (pPowerlevel[idx1]<<16) | (pPowerlevel[idx1]<<24); 126 (pPowerlevel[idx1] << 16) |
137 /* 2010/10/18 MH For external PA module. We need to limit power index to be less than 0x20. */ 127 (pPowerlevel[idx1] << 24);
128 /* 2010/10/18 MH For external PA module.
129 We need to limit power index to be less
130 than 0x20. */
138 if (TxAGC[idx1] > 0x20 && pHalData->ExternalPA) 131 if (TxAGC[idx1] > 0x20 && pHalData->ExternalPA)
139 TxAGC[idx1] = 0x20; 132 TxAGC[idx1] = 0x20;
140 } 133 }
141 } 134 }
142 } else { 135 } else {
143/* 20100427 Joseph: Driver dynamic Tx power shall not affect Tx power. It shall be determined by power training mechanism. */ 136/* 20100427 Joseph: Driver dynamic Tx power shall not affect Tx
144/* Currently, we cannot fully disable driver dynamic tx power mechanism because it is referenced by BT coexist mechanism. */ 137 * power. It shall be determined by power training mechanism. */
145/* In the future, two mechanism shall be separated from each other and maintained independantly. Thanks for Lanhsin's reminder. */ 138/* Currently, we cannot fully disable driver dynamic tx power
139 * mechanism because it is referenced by BT coexist mechanism. */
140/* In the future, two mechanism shall be separated from each other
141 * and maintained independantly. Thanks for Lanhsin's reminder. */
146 if (pdmpriv->DynamicTxHighPowerLvl == TxHighPwrLevel_Level1) { 142 if (pdmpriv->DynamicTxHighPowerLvl == TxHighPwrLevel_Level1) {
147 TxAGC[RF_PATH_A] = 0x10101010; 143 TxAGC[RF_PATH_A] = 0x10101010;
148 TxAGC[RF_PATH_B] = 0x10101010; 144 TxAGC[RF_PATH_B] = 0x10101010;
149 } else if (pdmpriv->DynamicTxHighPowerLvl == TxHighPwrLevel_Level2) { 145 } else if (pdmpriv->DynamicTxHighPowerLvl ==
146 TxHighPwrLevel_Level2) {
150 TxAGC[RF_PATH_A] = 0x00000000; 147 TxAGC[RF_PATH_A] = 0x00000000;
151 TxAGC[RF_PATH_B] = 0x00000000; 148 TxAGC[RF_PATH_B] = 0x00000000;
152 } else { 149 } else {
153 for (idx1 = RF_PATH_A; idx1 <= RF_PATH_B; idx1++) { 150 for (idx1 = RF_PATH_A; idx1 <= RF_PATH_B; idx1++) {
154 TxAGC[idx1] = 151 TxAGC[idx1] = pPowerlevel[idx1] |
155 pPowerlevel[idx1] | (pPowerlevel[idx1]<<8) | 152 (pPowerlevel[idx1] << 8) |
156 (pPowerlevel[idx1]<<16) | (pPowerlevel[idx1]<<24); 153 (pPowerlevel[idx1] << 16) |
154 (pPowerlevel[idx1] << 24);
157 } 155 }
158 156
159 if (pHalData->EEPROMRegulatory == 0) { 157 if (pHalData->EEPROMRegulatory == 0) {
@@ -178,29 +176,24 @@ void rtl823a_phy_rf6052setccktxpower(struct rtw_adapter *Adapter, u8 *pPowerleve
178 } 176 }
179 177
180 /* rf-A cck tx power */ 178 /* rf-A cck tx power */
181 tmpval = TxAGC[RF_PATH_A]&0xff; 179 tmpval = TxAGC[RF_PATH_A] & 0xff;
182 PHY_SetBBReg(Adapter, rTxAGC_A_CCK1_Mcs32, bMaskByte1, tmpval); 180 PHY_SetBBReg(Adapter, rTxAGC_A_CCK1_Mcs32, bMaskByte1, tmpval);
183 tmpval = TxAGC[RF_PATH_A]>>8; 181 tmpval = TxAGC[RF_PATH_A] >> 8;
184 PHY_SetBBReg(Adapter, rTxAGC_B_CCK11_A_CCK2_11, 0xffffff00, tmpval); 182 PHY_SetBBReg(Adapter, rTxAGC_B_CCK11_A_CCK2_11, 0xffffff00, tmpval);
185 183
186 /* rf-B cck tx power */ 184 /* rf-B cck tx power */
187 tmpval = TxAGC[RF_PATH_B]>>24; 185 tmpval = TxAGC[RF_PATH_B] >> 24;
188 PHY_SetBBReg(Adapter, rTxAGC_B_CCK11_A_CCK2_11, bMaskByte0, tmpval); 186 PHY_SetBBReg(Adapter, rTxAGC_B_CCK11_A_CCK2_11, bMaskByte0, tmpval);
189 tmpval = TxAGC[RF_PATH_B]&0x00ffffff; 187 tmpval = TxAGC[RF_PATH_B] & 0x00ffffff;
190 PHY_SetBBReg(Adapter, rTxAGC_B_CCK1_55_Mcs32, 0xffffff00, tmpval); 188 PHY_SetBBReg(Adapter, rTxAGC_B_CCK1_55_Mcs32, 0xffffff00, tmpval);
191} /* PHY_RF6052SetCckTxPower */ 189} /* PHY_RF6052SetCckTxPower */
192 190
193/* powerbase0 for OFDM rates */ 191/* powerbase0 for OFDM rates */
194/* powerbase1 for HT MCS rates */ 192/* powerbase1 for HT MCS rates */
195static void getPowerBase( 193static void getPowerBase(struct rtw_adapter *Adapter, u8 *pPowerLevel,
196 struct rtw_adapter *Adapter, 194 u8 Channel, u32 *OfdmBase, u32 *MCSBase)
197 u8 *pPowerLevel,
198 u8 Channel,
199 u32 *OfdmBase,
200 u32 *MCSBase
201 )
202{ 195{
203 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter); 196 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
204 u32 powerBase0, powerBase1; 197 u32 powerBase0, powerBase1;
205 u8 Legacy_pwrdiff = 0; 198 u8 Legacy_pwrdiff = 0;
206 s8 HT20_pwrdiff = 0; 199 s8 HT20_pwrdiff = 0;
@@ -211,8 +204,9 @@ static void getPowerBase(
211 Legacy_pwrdiff = pHalData->TxPwrLegacyHtDiff[i][Channel-1]; 204 Legacy_pwrdiff = pHalData->TxPwrLegacyHtDiff[i][Channel-1];
212 powerBase0 = powerlevel[i] + Legacy_pwrdiff; 205 powerBase0 = powerlevel[i] + Legacy_pwrdiff;
213 206
214 powerBase0 = (powerBase0<<24) | (powerBase0<<16) | (powerBase0<<8) | powerBase0; 207 powerBase0 = powerBase0 << 24 | powerBase0 << 16 |
215 *(OfdmBase+i) = powerBase0; 208 powerBase0 << 8 | powerBase0;
209 *(OfdmBase + i) = powerBase0;
216 } 210 }
217 211
218 for (i = 0; i < 2; i++) { 212 for (i = 0; i < 2; i++) {
@@ -222,36 +216,35 @@ static void getPowerBase(
222 powerlevel[i] += HT20_pwrdiff; 216 powerlevel[i] += HT20_pwrdiff;
223 } 217 }
224 powerBase1 = powerlevel[i]; 218 powerBase1 = powerlevel[i];
225 powerBase1 = (powerBase1<<24) | (powerBase1<<16) | (powerBase1<<8) | powerBase1; 219 powerBase1 = powerBase1 << 24 | powerBase1 << 16 |
226 *(MCSBase+i) = powerBase1; 220 powerBase1 << 8 | powerBase1;
221 *(MCSBase + i) = powerBase1;
227 } 222 }
228} 223}
229 224
230static void getTxPowerWriteValByRegulatory( 225static void
231 struct rtw_adapter *Adapter, 226getTxPowerWriteValByRegulatory(struct rtw_adapter *Adapter, u8 Channel,
232 u8 Channel, 227 u8 index, u32 *powerBase0, u32 *powerBase1,
233 u8 index, 228 u32 *pOutWriteVal)
234 u32 *powerBase0,
235 u32 *powerBase1,
236 u32 *pOutWriteVal
237 )
238{ 229{
239 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter); 230 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
240 struct dm_priv *pdmpriv = &pHalData->dmpriv; 231 struct dm_priv *pdmpriv = &pHalData->dmpriv;
241 u8 i, chnlGroup = 0, pwr_diff_limit[4]; 232 u8 i, chnlGroup = 0, pwr_diff_limit[4];
242 u32 writeVal, customer_limit, rf; 233 u32 writeVal, customer_limit, rf;
243 234
244 /* Index 0 & 1 = legacy OFDM, 2-5 = HT_MCS rate */ 235 /* Index 0 & 1 = legacy OFDM, 2-5 = HT_MCS rate */
245 for (rf = 0; rf < 2; rf++) { 236 for (rf = 0; rf < 2; rf++) {
246 switch (pHalData->EEPROMRegulatory) { 237 switch (pHalData->EEPROMRegulatory) {
247 case 0: /* Realtek better performance */ 238 case 0: /* Realtek better performance */
248 /* increase power diff defined by Realtek for large power */ 239 /* increase power diff defined by Realtek for
240 * large power */
249 chnlGroup = 0; 241 chnlGroup = 0;
250 writeVal = pHalData->MCSTxPowerLevelOriginalOffset[chnlGroup][index+(rf?8:0)] + 242 writeVal = pHalData->MCSTxPowerLevelOriginalOffset[chnlGroup][index+(rf?8:0)] +
251 ((index < 2) ? powerBase0[rf] : powerBase1[rf]); 243 ((index < 2) ? powerBase0[rf] : powerBase1[rf]);
252 break; 244 break;
253 case 1: /* Realtek regulatory */ 245 case 1: /* Realtek regulatory */
254 /* increase power diff defined by Realtek for regulatory */ 246 /* increase power diff defined by Realtek for
247 * regulatory */
255 if (pHalData->pwrGroupCnt == 1) 248 if (pHalData->pwrGroupCnt == 1)
256 chnlGroup = 0; 249 chnlGroup = 0;
257 if (pHalData->pwrGroupCnt >= 3) { 250 if (pHalData->pwrGroupCnt >= 3) {
@@ -262,17 +255,20 @@ static void getTxPowerWriteValByRegulatory(
262 else if (Channel > 9) 255 else if (Channel > 9)
263 chnlGroup = 2; 256 chnlGroup = 2;
264 257
265 if (pHalData->CurrentChannelBW == HT_CHANNEL_WIDTH_20) 258 if (pHalData->CurrentChannelBW ==
259 HT_CHANNEL_WIDTH_20)
266 chnlGroup++; 260 chnlGroup++;
267 else 261 else
268 chnlGroup += 4; 262 chnlGroup += 4;
269 } 263 }
270 writeVal = pHalData->MCSTxPowerLevelOriginalOffset[chnlGroup][index+(rf?8:0)] + 264 writeVal = pHalData->MCSTxPowerLevelOriginalOffset[chnlGroup][index+(rf?8:0)] +
271 ((index < 2) ? powerBase0[rf] : powerBase1[rf]); 265 ((index < 2) ? powerBase0[rf] :
266 powerBase1[rf]);
272 break; 267 break;
273 case 2: /* Better regulatory */ 268 case 2: /* Better regulatory */
274 /* don't increase any power diff */ 269 /* don't increase any power diff */
275 writeVal = ((index < 2) ? powerBase0[rf] : powerBase1[rf]); 270 writeVal = ((index < 2) ? powerBase0[rf] :
271 powerBase1[rf]);
276 break; 272 break;
277 case 3: /* Customer defined power diff. */ 273 case 3: /* Customer defined power diff. */
278 chnlGroup = 0; 274 chnlGroup = 0;
@@ -299,28 +295,34 @@ static void getTxPowerWriteValByRegulatory(
299 break; 295 break;
300 } 296 }
301 297
302/* 20100427 Joseph: Driver dynamic Tx power shall not affect Tx power. It shall be determined by power training mechanism. */ 298/* 20100427 Joseph: Driver dynamic Tx power shall not affect Tx power.
303/* Currently, we cannot fully disable driver dynamic tx power mechanism because it is referenced by BT coexist mechanism. */ 299 It shall be determined by power training mechanism. */
304/* In the future, two mechanism shall be separated from each other and maintained independantly. Thanks for Lanhsin's reminder. */ 300/* Currently, we cannot fully disable driver dynamic tx power mechanism
301 because it is referenced by BT coexist mechanism. */
302/* In the future, two mechanism shall be separated from each other and
303 maintained independantly. Thanks for Lanhsin's reminder. */
305 304
306 if (pdmpriv->DynamicTxHighPowerLvl == TxHighPwrLevel_Level1) 305 if (pdmpriv->DynamicTxHighPowerLvl == TxHighPwrLevel_Level1)
307 writeVal = 0x14141414; 306 writeVal = 0x14141414;
308 else if (pdmpriv->DynamicTxHighPowerLvl == TxHighPwrLevel_Level2) 307 else if (pdmpriv->DynamicTxHighPowerLvl ==
308 TxHighPwrLevel_Level2)
309 writeVal = 0x00000000; 309 writeVal = 0x00000000;
310 310
311 /* 20100628 Joseph: High power mode for BT-Coexist mechanism. */ 311 /* 20100628 Joseph: High power mode for BT-Coexist mechanism. */
312 /* This mechanism is only applied when Driver-Highpower-Mechanism is OFF. */ 312 /* This mechanism is only applied when
313 Driver-Highpower-Mechanism is OFF. */
313 if (pdmpriv->DynamicTxHighPowerLvl == TxHighPwrLevel_BT1) 314 if (pdmpriv->DynamicTxHighPowerLvl == TxHighPwrLevel_BT1)
314 writeVal = writeVal - 0x06060606; 315 writeVal = writeVal - 0x06060606;
315 else if (pdmpriv->DynamicTxHighPowerLvl == TxHighPwrLevel_BT2) 316 else if (pdmpriv->DynamicTxHighPowerLvl == TxHighPwrLevel_BT2)
316 writeVal = writeVal; 317 writeVal = writeVal;
317 *(pOutWriteVal+rf) = writeVal; 318 *(pOutWriteVal + rf) = writeVal;
318 } 319 }
319} 320}
320 321
321static void writeOFDMPowerReg(struct rtw_adapter *Adapter, u8 index, u32 *pValue) 322static void writeOFDMPowerReg(struct rtw_adapter *Adapter, u8 index,
323 u32 *pValue)
322{ 324{
323 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter); 325 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
324 u16 RegOffset_A[6] = { 326 u16 RegOffset_A[6] = {
325 rTxAGC_A_Rate18_06, rTxAGC_A_Rate54_24, 327 rTxAGC_A_Rate18_06, rTxAGC_A_Rate54_24,
326 rTxAGC_A_Mcs03_Mcs00, rTxAGC_A_Mcs07_Mcs04, 328 rTxAGC_A_Mcs03_Mcs00, rTxAGC_A_Mcs07_Mcs04,
@@ -338,12 +340,13 @@ static void writeOFDMPowerReg(struct rtw_adapter *Adapter, u8 index, u32 *pValue
338 for (rf = 0; rf < 2; rf++) { 340 for (rf = 0; rf < 2; rf++) {
339 writeVal = pValue[rf]; 341 writeVal = pValue[rf];
340 for (i = 0; i < 4; i++) { 342 for (i = 0; i < 4; i++) {
341 pwr_val[i] = (u8)((writeVal & (0x7f<<(i*8)))>>(i*8)); 343 pwr_val[i] = (u8)((writeVal &
342 if (pwr_val[i] > RF6052_MAX_TX_PWR) 344 (0x7f << (i * 8))) >> (i * 8));
345 if (pwr_val[i] > RF6052_MAX_TX_PWR)
343 pwr_val[i] = RF6052_MAX_TX_PWR; 346 pwr_val[i] = RF6052_MAX_TX_PWR;
344 } 347 }
345 writeVal = (pwr_val[3]<<24) | (pwr_val[2]<<16) | 348 writeVal = pwr_val[3] << 24 | pwr_val[2] << 16 |
346 (pwr_val[1]<<8) | pwr_val[0]; 349 pwr_val[1] << 8 | pwr_val[0];
347 350
348 if (rf == 0) 351 if (rf == 0)
349 RegOffset = RegOffset_A[index]; 352 RegOffset = RegOffset_A[index];
@@ -352,7 +355,8 @@ static void writeOFDMPowerReg(struct rtw_adapter *Adapter, u8 index, u32 *pValue
352 355
353 PHY_SetBBReg(Adapter, RegOffset, bMaskDWord, writeVal); 356 PHY_SetBBReg(Adapter, RegOffset, bMaskDWord, writeVal);
354 357
355 /* 201005115 Joseph: Set Tx Power diff for Tx power training mechanism. */ 358 /* 201005115 Joseph: Set Tx Power diff for Tx power
359 training mechanism. */
356 if (((pHalData->rf_type == RF_2T2R) && 360 if (((pHalData->rf_type == RF_2T2R) &&
357 (RegOffset == rTxAGC_A_Mcs15_Mcs12 || 361 (RegOffset == rTxAGC_A_Mcs15_Mcs12 ||
358 RegOffset == rTxAGC_B_Mcs15_Mcs12)) || 362 RegOffset == rTxAGC_B_Mcs15_Mcs12)) ||
@@ -360,15 +364,19 @@ static void writeOFDMPowerReg(struct rtw_adapter *Adapter, u8 index, u32 *pValue
360 (RegOffset == rTxAGC_A_Mcs07_Mcs04 || 364 (RegOffset == rTxAGC_A_Mcs07_Mcs04 ||
361 RegOffset == rTxAGC_B_Mcs07_Mcs04))) { 365 RegOffset == rTxAGC_B_Mcs07_Mcs04))) {
362 writeVal = pwr_val[3]; 366 writeVal = pwr_val[3];
363 if (RegOffset == rTxAGC_A_Mcs15_Mcs12 || RegOffset == rTxAGC_A_Mcs07_Mcs04) 367 if (RegOffset == rTxAGC_A_Mcs15_Mcs12 ||
368 RegOffset == rTxAGC_A_Mcs07_Mcs04)
364 RegOffset = 0xc90; 369 RegOffset = 0xc90;
365 if (RegOffset == rTxAGC_B_Mcs15_Mcs12 || RegOffset == rTxAGC_B_Mcs07_Mcs04) 370 if (RegOffset == rTxAGC_B_Mcs15_Mcs12 ||
371 RegOffset == rTxAGC_B_Mcs07_Mcs04)
366 RegOffset = 0xc98; 372 RegOffset = 0xc98;
367 for (i = 0; i < 3; i++) { 373 for (i = 0; i < 3; i++) {
368 if (i != 2) 374 if (i != 2)
369 writeVal = (writeVal > 8) ? (writeVal-8) : 0; 375 writeVal = (writeVal > 8) ?
376 (writeVal - 8) : 0;
370 else 377 else
371 writeVal = (writeVal > 6) ? (writeVal-6) : 0; 378 writeVal = (writeVal > 6) ?
379 (writeVal - 6) : 0;
372 rtl8723au_write8(Adapter, RegOffset + i, 380 rtl8723au_write8(Adapter, RegOffset + i,
373 (u8)writeVal); 381 (u8)writeVal);
374 } 382 }
@@ -379,8 +387,9 @@ static void writeOFDMPowerReg(struct rtw_adapter *Adapter, u8 index, u32 *pValue
379 * Function: PHY_RF6052SetOFDMTxPower 387 * Function: PHY_RF6052SetOFDMTxPower
380 * 388 *
381 * Overview: For legacy and HY OFDM, we must read EEPROM TX power index for 389 * Overview: For legacy and HY OFDM, we must read EEPROM TX power index for
382 * different channel and read original value in TX power register area from 390 * different channel and read original value in TX power
383 * 0xe00. We increase offset and original value to be correct tx pwr. 391 * register area from 0xe00. We increase offset and
392 * original value to be correct tx pwr.
384 * 393 *
385 * Input: NONE 394 * Input: NONE
386 * 395 *
@@ -389,20 +398,23 @@ static void writeOFDMPowerReg(struct rtw_adapter *Adapter, u8 index, u32 *pValue
389 * Return: NONE 398 * Return: NONE
390 * 399 *
391 * Revised History: 400 * Revised History:
392 * When Who Remark 401 * When Remark
393 * 11/05/2008 MHC Simulate 8192 series method. 402 * 11/05/2008 MHC Simulate 8192 series method.
394 * 01/06/2009 MHC 1. Prevent Path B tx power overflow or underflow dure to 403 * 01/06/2009 MHC 1. Prevent Path B tx power overflow or
395 * A/B pwr difference or legacy/HT pwr diff. 404 * underflow dure to A/B pwr difference or
396 * 2. We concern with path B legacy/HT OFDM difference. 405 * legacy/HT pwr diff.
397 * 01/22/2009 MHC Support new EPRO format from SD3. 406 * 2. We concern with path B legacy/HT OFDM difference.
407 * 01/22/2009 MHC Support new EPRO format from SD3.
398 * 408 *
399 *---------------------------------------------------------------------------*/ 409 *---------------------------------------------------------------------------*/
400void rtl8723a_PHY_RF6052SetOFDMTxPower(struct rtw_adapter *Adapter, u8 *pPowerLevel, u8 Channel) 410void rtl8723a_PHY_RF6052SetOFDMTxPower(struct rtw_adapter *Adapter,
411 u8 *pPowerLevel, u8 Channel)
401{ 412{
402 u32 writeVal[2], powerBase0[2], powerBase1[2]; 413 u32 writeVal[2], powerBase0[2], powerBase1[2];
403 u8 index = 0; 414 u8 index = 0;
404 415
405 getPowerBase(Adapter, pPowerLevel, Channel, &powerBase0[0], &powerBase1[0]); 416 getPowerBase(Adapter, pPowerLevel, Channel,
417 &powerBase0[0], &powerBase1[0]);
406 418
407 for (index = 0; index < 6; index++) { 419 for (index = 0; index < 6; index++) {
408 getTxPowerWriteValByRegulatory(Adapter, Channel, index, 420 getTxPowerWriteValByRegulatory(Adapter, Channel, index,
@@ -416,7 +428,7 @@ static int phy_RF6052_Config_ParaFile(struct rtw_adapter *Adapter)
416{ 428{
417 u32 u4RegValue = 0; 429 u32 u4RegValue = 0;
418 u8 eRFPath; 430 u8 eRFPath;
419 struct bb_reg_define *pPhyReg; 431 struct bb_reg_define *pPhyReg;
420 int rtStatus = _SUCCESS; 432 int rtStatus = _SUCCESS;
421 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter); 433 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
422 434
@@ -430,15 +442,17 @@ static int phy_RF6052_Config_ParaFile(struct rtw_adapter *Adapter)
430 /*----Store original RFENV control type----*/ 442 /*----Store original RFENV control type----*/
431 switch (eRFPath) { 443 switch (eRFPath) {
432 case RF_PATH_A: 444 case RF_PATH_A:
433 u4RegValue = PHY_QueryBBReg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV); 445 u4RegValue = PHY_QueryBBReg(Adapter, pPhyReg->rfintfs,
446 bRFSI_RFENV);
434 break; 447 break;
435 case RF_PATH_B: 448 case RF_PATH_B:
436 u4RegValue = PHY_QueryBBReg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV<<16); 449 u4RegValue = PHY_QueryBBReg(Adapter, pPhyReg->rfintfs,
450 bRFSI_RFENV << 16);
437 break; 451 break;
438 } 452 }
439 453
440 /*----Set RF_ENV enable----*/ 454 /*----Set RF_ENV enable----*/
441 PHY_SetBBReg(Adapter, pPhyReg->rfintfe, bRFSI_RFENV<<16, 0x1); 455 PHY_SetBBReg(Adapter, pPhyReg->rfintfe, bRFSI_RFENV << 16, 0x1);
442 udelay(1);/* PlatformStallExecution(1); */ 456 udelay(1);/* PlatformStallExecution(1); */
443 457
444 /*----Set RF_ENV output high----*/ 458 /*----Set RF_ENV output high----*/
@@ -446,10 +460,12 @@ static int phy_RF6052_Config_ParaFile(struct rtw_adapter *Adapter)
446 udelay(1);/* PlatformStallExecution(1); */ 460 udelay(1);/* PlatformStallExecution(1); */
447 461
448 /* Set bit number of Address and Data for RF register */ 462 /* Set bit number of Address and Data for RF register */
449 PHY_SetBBReg(Adapter, pPhyReg->rfHSSIPara2, b3WireAddressLength, 0x0); /* Set 1 to 4 bits for 8255 */ 463 PHY_SetBBReg(Adapter, pPhyReg->rfHSSIPara2, b3WireAddressLength,
464 0x0); /* Set 1 to 4 bits for 8255 */
450 udelay(1);/* PlatformStallExecution(1); */ 465 udelay(1);/* PlatformStallExecution(1); */
451 466
452 PHY_SetBBReg(Adapter, pPhyReg->rfHSSIPara2, b3WireDataLength, 0x0); /* Set 0 to 12 bits for 8255 */ 467 PHY_SetBBReg(Adapter, pPhyReg->rfHSSIPara2, b3WireDataLength,
468 0x0); /* Set 0 to 12 bits for 8255 */
453 udelay(1);/* PlatformStallExecution(1); */ 469 udelay(1);/* PlatformStallExecution(1); */
454 470
455 /*----Initialize RF fom connfiguration file----*/ 471 /*----Initialize RF fom connfiguration file----*/
@@ -464,15 +480,16 @@ static int phy_RF6052_Config_ParaFile(struct rtw_adapter *Adapter)
464 /*----Restore RFENV control type----*/; 480 /*----Restore RFENV control type----*/;
465 switch (eRFPath) { 481 switch (eRFPath) {
466 case RF_PATH_A: 482 case RF_PATH_A:
467 PHY_SetBBReg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV, u4RegValue); 483 PHY_SetBBReg(Adapter, pPhyReg->rfintfs,
484 bRFSI_RFENV, u4RegValue);
468 break; 485 break;
469 case RF_PATH_B: 486 case RF_PATH_B:
470 PHY_SetBBReg(Adapter, pPhyReg->rfintfs, bRFSI_RFENV<<16, u4RegValue); 487 PHY_SetBBReg(Adapter, pPhyReg->rfintfs,
488 bRFSI_RFENV << 16, u4RegValue);
471 break; 489 break;
472 } 490 }
473 491
474 if (rtStatus != _SUCCESS) { 492 if (rtStatus != _SUCCESS) {
475 /* RT_TRACE(COMP_FPGA, DBG_LOUD, ("phy_RF6052_Config_ParaFile():Radio[%d] Fail!!", eRFPath)); */
476 goto phy_RF6052_Config_ParaFile_Fail; 493 goto phy_RF6052_Config_ParaFile_Fail;
477 } 494 }
478 } 495 }
diff --git a/drivers/staging/rtl8723au/hal/rtl8723a_xmit.c b/drivers/staging/rtl8723au/hal/rtl8723a_xmit.c
deleted file mode 100644
index 6ea2f9efef64..000000000000
--- a/drivers/staging/rtl8723au/hal/rtl8723a_xmit.c
+++ /dev/null
@@ -1,31 +0,0 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 ******************************************************************************/
15#define _RTL8723A_XMIT_C_
16
17#include <osdep_service.h>
18#include <drv_types.h>
19#include <rtl8723a_hal.h>
20
21void handle_txrpt_ccx_8723a(struct rtw_adapter *adapter, void *buf)
22{
23 struct txrpt_ccx_8723a *txrpt_ccx = buf;
24
25 if (txrpt_ccx->int_ccx) {
26 if (txrpt_ccx->pkt_ok)
27 rtw_ack_tx_done23a(&adapter->xmitpriv, RTW_SCTX_DONE_SUCCESS);
28 else
29 rtw_ack_tx_done23a(&adapter->xmitpriv, RTW_SCTX_DONE_CCX_PKT_FAIL);
30 }
31}
diff --git a/drivers/staging/rtl8723au/hal/rtl8723au_led.c b/drivers/staging/rtl8723au/hal/rtl8723au_led.c
deleted file mode 100644
index b946636af9b3..000000000000
--- a/drivers/staging/rtl8723au/hal/rtl8723au_led.c
+++ /dev/null
@@ -1,124 +0,0 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 ******************************************************************************/
15
16#include "drv_types.h"
17#include "rtl8723a_hal.h"
18#include "rtl8723a_led.h"
19#include "usb_ops_linux.h"
20
21/* */
22/* LED object. */
23/* */
24
25/* */
26/* Prototype of protected function. */
27/* */
28
29/* */
30/* LED_819xUsb routines. */
31/* */
32
33/* Description: */
34/* Turn on LED according to LedPin specified. */
35void SwLedOn23a(struct rtw_adapter *padapter, struct led_8723a *pLed)
36{
37 u8 LedCfg = 0;
38
39 if ((padapter->bSurpriseRemoved == true) || (padapter->bDriverStopped == true))
40 return;
41 switch (pLed->LedPin) {
42 case LED_PIN_GPIO0:
43 break;
44 case LED_PIN_LED0:
45 /* SW control led0 on. */
46 rtl8723au_write8(padapter, REG_LEDCFG0,
47 (LedCfg&0xf0)|BIT(5)|BIT(6));
48 break;
49 case LED_PIN_LED1:
50 /* SW control led1 on. */
51 rtl8723au_write8(padapter, REG_LEDCFG1, (LedCfg&0x00)|BIT(6));
52 break;
53 case LED_PIN_LED2:
54 LedCfg = rtl8723au_read8(padapter, REG_LEDCFG2);
55 /* SW control led1 on. */
56 rtl8723au_write8(padapter, REG_LEDCFG2, (LedCfg&0x80)|BIT(5));
57 break;
58 default:
59 break;
60 }
61 pLed->bLedOn = true;
62}
63
64/* Description: */
65/* Turn off LED according to LedPin specified. */
66void SwLedOff23a(struct rtw_adapter *padapter, struct led_8723a *pLed)
67{
68 u8 LedCfg = 0;
69 /* struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter); */
70
71 if ((padapter->bSurpriseRemoved) || (padapter->bDriverStopped))
72 goto exit;
73
74 switch (pLed->LedPin) {
75 case LED_PIN_GPIO0:
76 break;
77 case LED_PIN_LED0:
78 /* SW control led0 on. */
79 rtl8723au_write8(padapter, REG_LEDCFG0,
80 (LedCfg&0xf0)|BIT(5)|BIT(6));
81 break;
82 case LED_PIN_LED1:
83 /* SW control led1 on. */
84 rtl8723au_write8(padapter, REG_LEDCFG1,
85 (LedCfg&0x00)|BIT(5)|BIT(6));
86 break;
87 case LED_PIN_LED2:
88 LedCfg = rtl8723au_read8(padapter, REG_LEDCFG2);
89 /* SW control led1 on. */
90 rtl8723au_write8(padapter, REG_LEDCFG2,
91 (LedCfg&0x80)|BIT(3)|BIT(5));
92 break;
93 default:
94 break;
95 }
96exit:
97 pLed->bLedOn = false;
98}
99
100/* Interface to manipulate LED objects. */
101
102/* Description: */
103/* Initialize all LED_871x objects. */
104void
105rtl8723au_InitSwLeds(struct rtw_adapter *padapter)
106{
107 struct led_priv *pledpriv = &padapter->ledpriv;
108
109 pledpriv->LedControlHandler = LedControl871x23a;
110 /* 8723as-vau wifi used led2 */
111 InitLed871x23a(padapter, &pledpriv->SwLed0, LED_PIN_LED2);
112
113/* InitLed871x23a(padapter,&pledpriv->SwLed1, LED_PIN_LED2); */
114}
115
116/* Description: */
117/* DeInitialize all LED_819xUsb objects. */
118void
119rtl8723au_DeInitSwLeds(struct rtw_adapter *padapter)
120{
121 struct led_priv *ledpriv = &padapter->ledpriv;
122
123 DeInitLed871x23a(&ledpriv->SwLed0);
124}
diff --git a/drivers/staging/rtl8723au/hal/rtl8723au_xmit.c b/drivers/staging/rtl8723au/hal/rtl8723au_xmit.c
index a67850fe6e5d..6070510bb470 100644
--- a/drivers/staging/rtl8723au/hal/rtl8723au_xmit.c
+++ b/drivers/staging/rtl8723au/hal/rtl8723au_xmit.c
@@ -21,18 +21,6 @@
21/* include <rtl8192c_hal.h> */ 21/* include <rtl8192c_hal.h> */
22#include <rtl8723a_hal.h> 22#include <rtl8723a_hal.h>
23 23
24static void do_queue_select(struct rtw_adapter *padapter, struct pkt_attrib *pattrib)
25{
26 u8 qsel;
27
28 qsel = pattrib->priority;
29 RT_TRACE(_module_rtl871x_xmit_c_, _drv_info_,
30 ("### do_queue_select priority =%d , qsel = %d\n",
31 pattrib->priority, qsel));
32
33 pattrib->qsel = qsel;
34}
35
36static int urb_zero_packet_chk(struct rtw_adapter *padapter, int sz) 24static int urb_zero_packet_chk(struct rtw_adapter *padapter, int sz)
37{ 25{
38 int blnSetTxDescOffset; 26 int blnSetTxDescOffset;
@@ -163,7 +151,7 @@ static s32 update_txdesc(struct xmit_frame *pxmitframe, u8 *pmem, s32 sz, u8 bag
163 151
164 memset(ptxdesc, 0, sizeof(struct tx_desc)); 152 memset(ptxdesc, 0, sizeof(struct tx_desc));
165 153
166 if ((pxmitframe->frame_tag&0x0f) == DATA_FRAMETAG) { 154 if (pxmitframe->frame_tag == DATA_FRAMETAG) {
167 /* offset 4 */ 155 /* offset 4 */
168 ptxdesc->txdw1 |= cpu_to_le32(pattrib->mac_id&0x1f); 156 ptxdesc->txdw1 |= cpu_to_le32(pattrib->mac_id&0x1f);
169 157
@@ -215,7 +203,7 @@ static s32 update_txdesc(struct xmit_frame *pxmitframe, u8 *pmem, s32 sz, u8 bag
215 203
216 ptxdesc->txdw5 |= cpu_to_le32(MRateToHwRate23a(pmlmeext->tx_rate)); 204 ptxdesc->txdw5 |= cpu_to_le32(MRateToHwRate23a(pmlmeext->tx_rate));
217 } 205 }
218 } else if ((pxmitframe->frame_tag&0x0f) == MGNT_FRAMETAG) { 206 } else if (pxmitframe->frame_tag == MGNT_FRAMETAG) {
219 /* offset 4 */ 207 /* offset 4 */
220 ptxdesc->txdw1 |= cpu_to_le32(pattrib->mac_id&0x1f); 208 ptxdesc->txdw1 |= cpu_to_le32(pattrib->mac_id&0x1f);
221 209
@@ -240,10 +228,11 @@ static s32 update_txdesc(struct xmit_frame *pxmitframe, u8 *pmem, s32 sz, u8 bag
240 ptxdesc->txdw5 |= cpu_to_le32(0x00180000);/* retry limit = 6 */ 228 ptxdesc->txdw5 |= cpu_to_le32(0x00180000);/* retry limit = 6 */
241 229
242 ptxdesc->txdw5 |= cpu_to_le32(MRateToHwRate23a(pmlmeext->tx_rate)); 230 ptxdesc->txdw5 |= cpu_to_le32(MRateToHwRate23a(pmlmeext->tx_rate));
243 } else if ((pxmitframe->frame_tag&0x0f) == TXAGG_FRAMETAG) { 231 } else if (pxmitframe->frame_tag == TXAGG_FRAMETAG) {
244 DBG_8723A("pxmitframe->frame_tag == TXAGG_FRAMETAG\n"); 232 DBG_8723A("pxmitframe->frame_tag == TXAGG_FRAMETAG\n");
245 } else { 233 } else {
246 DBG_8723A("pxmitframe->frame_tag = %d\n", pxmitframe->frame_tag); 234 DBG_8723A("pxmitframe->frame_tag = %d\n",
235 pxmitframe->frame_tag);
247 236
248 /* offset 4 */ 237 /* offset 4 */
249 ptxdesc->txdw1 |= cpu_to_le32((4)&0x1f);/* CAM_ID(MAC_ID) */ 238 ptxdesc->txdw1 |= cpu_to_le32((4)&0x1f);/* CAM_ID(MAC_ID) */
@@ -306,10 +295,10 @@ static int rtw_dump_xframe(struct rtw_adapter *padapter,
306 struct pkt_attrib *pattrib = &pxmitframe->attrib; 295 struct pkt_attrib *pattrib = &pxmitframe->attrib;
307 struct xmit_priv *pxmitpriv = &padapter->xmitpriv; 296 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
308 297
309 if ((pxmitframe->frame_tag == DATA_FRAMETAG) && 298 if (pxmitframe->frame_tag == DATA_FRAMETAG &&
310 (pxmitframe->attrib.ether_type != 0x0806) && 299 pxmitframe->attrib.ether_type != ETH_P_ARP &&
311 (pxmitframe->attrib.ether_type != 0x888e) && 300 pxmitframe->attrib.ether_type != ETH_P_PAE &&
312 (pxmitframe->attrib.dhcp_pkt != 1)) 301 pxmitframe->attrib.dhcp_pkt != 1)
313 rtw_issue_addbareq_cmd23a(padapter, pxmitframe); 302 rtw_issue_addbareq_cmd23a(padapter, pxmitframe);
314 303
315 mem_addr = pxmitframe->buf_addr; 304 mem_addr = pxmitframe->buf_addr;
@@ -392,7 +381,7 @@ bool rtl8723au_xmitframe_complete(struct rtw_adapter *padapter,
392 381
393 pxmitbuf->priv_data = pxmitframe; 382 pxmitbuf->priv_data = pxmitframe;
394 383
395 if ((pxmitframe->frame_tag&0x0f) == DATA_FRAMETAG) { 384 if (pxmitframe->frame_tag == DATA_FRAMETAG) {
396 if (pxmitframe->attrib.priority <= 15)/* TID0~15 */ 385 if (pxmitframe->attrib.priority <= 15)/* TID0~15 */
397 res = rtw_xmitframe_coalesce23a(padapter, pxmitframe->pkt, pxmitframe); 386 res = rtw_xmitframe_coalesce23a(padapter, pxmitframe->pkt, pxmitframe);
398 387
@@ -440,7 +429,7 @@ bool rtl8723au_hal_xmit(struct rtw_adapter *padapter,
440 struct pkt_attrib *pattrib = &pxmitframe->attrib; 429 struct pkt_attrib *pattrib = &pxmitframe->attrib;
441 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 430 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
442 431
443 do_queue_select(padapter, pattrib); 432 pattrib->qsel = pattrib->priority;
444 spin_lock_bh(&pxmitpriv->lock); 433 spin_lock_bh(&pxmitpriv->lock);
445 434
446#ifdef CONFIG_8723AU_AP_MODE 435#ifdef CONFIG_8723AU_AP_MODE
diff --git a/drivers/staging/rtl8723au/hal/usb_halinit.c b/drivers/staging/rtl8723au/hal/usb_halinit.c
index a5de03d45aa9..febe5cedef8f 100644
--- a/drivers/staging/rtl8723au/hal/usb_halinit.c
+++ b/drivers/staging/rtl8723au/hal/usb_halinit.c
@@ -21,11 +21,13 @@
21#include <HalPwrSeqCmd.h> 21#include <HalPwrSeqCmd.h>
22#include <Hal8723PwrSeq.h> 22#include <Hal8723PwrSeq.h>
23#include <rtl8723a_hal.h> 23#include <rtl8723a_hal.h>
24#include <rtl8723a_led.h>
25#include <linux/ieee80211.h> 24#include <linux/ieee80211.h>
26 25
27#include <usb_ops.h> 26#include <usb_ops.h>
28 27
28static void phy_SsPwrSwitch92CU(struct rtw_adapter *Adapter,
29 enum rt_rf_power_state eRFPowerState);
30
29static void 31static void
30_ConfigChipOutEP(struct rtw_adapter *pAdapter, u8 NumOutPipe) 32_ConfigChipOutEP(struct rtw_adapter *pAdapter, u8 NumOutPipe)
31{ 33{
@@ -61,42 +63,28 @@ _ConfigChipOutEP(struct rtw_adapter *pAdapter, u8 NumOutPipe)
61 (u32)NumOutPipe, (u32)pHalData->OutEpNumber)); */ 63 (u32)NumOutPipe, (u32)pHalData->OutEpNumber)); */
62} 64}
63 65
64static bool rtl8723au_set_queue_pipe_mapping(struct rtw_adapter *pAdapter, 66bool rtl8723au_chip_configure(struct rtw_adapter *padapter)
65 u8 NumInPipe, u8 NumOutPipe)
66{ 67{
67 struct hal_data_8723a *pHalData = GET_HAL_DATA(pAdapter); 68 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
68 bool result = false; 69 struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
70 u8 NumInPipe = pdvobjpriv->RtNumInPipes;
71 u8 NumOutPipe = pdvobjpriv->RtNumOutPipes;
69 72
70 _ConfigChipOutEP(pAdapter, NumOutPipe); 73 _ConfigChipOutEP(padapter, NumOutPipe);
71 74
72 /* Normal chip with one IN and one OUT doesn't have interrupt IN EP. */ 75 /* Normal chip with one IN and one OUT doesn't have interrupt IN EP. */
73 if (pHalData->OutEpNumber == 1) { 76 if (pHalData->OutEpNumber == 1) {
74 if (NumInPipe != 1) 77 if (NumInPipe != 1)
75 return result; 78 return false;
76 } 79 }
77 80
78 result = Hal_MappingOutPipe23a(pAdapter, NumOutPipe); 81 return Hal_MappingOutPipe23a(padapter, NumOutPipe);
79
80 return result;
81}
82
83void rtl8723au_chip_configure(struct rtw_adapter *padapter)
84{
85 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
86 struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
87
88 pHalData->interfaceIndex = pdvobjpriv->InterfaceNumber;
89
90 rtl8723au_set_queue_pipe_mapping(padapter,
91 pdvobjpriv->RtNumInPipes,
92 pdvobjpriv->RtNumOutPipes);
93} 82}
94 83
95static int _InitPowerOn(struct rtw_adapter *padapter) 84static int _InitPowerOn(struct rtw_adapter *padapter)
96{ 85{
97 int status = _SUCCESS; 86 u16 value16;
98 u16 value16 = 0; 87 u8 value8;
99 u8 value8 = 0;
100 88
101 /* RSV_CTRL 0x1C[7:0] = 0x00 89 /* RSV_CTRL 0x1C[7:0] = 0x00
102 unlock ISO/CLK/Power control register */ 90 unlock ISO/CLK/Power control register */
@@ -123,7 +111,7 @@ static int _InitPowerOn(struct rtw_adapter *padapter)
123 /* for Efuse PG, suggest by Jackie 2011.11.23 */ 111 /* for Efuse PG, suggest by Jackie 2011.11.23 */
124 PHY_SetBBReg(padapter, REG_EFUSE_CTRL, BIT(28)|BIT(29)|BIT(30), 0x06); 112 PHY_SetBBReg(padapter, REG_EFUSE_CTRL, BIT(28)|BIT(29)|BIT(30), 0x06);
125 113
126 return status; 114 return _SUCCESS;
127} 115}
128 116
129/* Shall USB interface init this? */ 117/* Shall USB interface init this? */
@@ -313,7 +301,7 @@ static void _InitNormalChipThreeOutEpPriority(struct rtw_adapter *Adapter)
313 _InitNormalChipRegPriority(Adapter, beQ, bkQ, viQ, voQ, mgtQ, hiQ); 301 _InitNormalChipRegPriority(Adapter, beQ, bkQ, viQ, voQ, mgtQ, hiQ);
314} 302}
315 303
316static void _InitNormalChipQueuePriority(struct rtw_adapter *Adapter) 304static void _InitQueuePriority(struct rtw_adapter *Adapter)
317{ 305{
318 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter); 306 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
319 307
@@ -333,11 +321,6 @@ static void _InitNormalChipQueuePriority(struct rtw_adapter *Adapter)
333 } 321 }
334} 322}
335 323
336static void _InitQueuePriority(struct rtw_adapter *Adapter)
337{
338 _InitNormalChipQueuePriority(Adapter);
339}
340
341static void _InitTransferPageSize(struct rtw_adapter *Adapter) 324static void _InitTransferPageSize(struct rtw_adapter *Adapter)
342{ 325{
343 /* Tx page size is always 128. */ 326 /* Tx page size is always 128. */
@@ -442,18 +425,6 @@ static void _InitEDCA(struct rtw_adapter *Adapter)
442 rtl8723au_write32(Adapter, REG_EDCA_VO_PARAM, 0x002FA226); 425 rtl8723au_write32(Adapter, REG_EDCA_VO_PARAM, 0x002FA226);
443} 426}
444 427
445static void _InitHWLed(struct rtw_adapter *Adapter)
446{
447 struct led_priv *pledpriv = &Adapter->ledpriv;
448
449 if (pledpriv->LedStrategy != HW_LED)
450 return;
451
452/* HW led control */
453/* to do .... */
454/* must consider cases of antenna diversity/ commbo card/solo card/mini card */
455}
456
457static void _InitRDGSetting(struct rtw_adapter *Adapter) 428static void _InitRDGSetting(struct rtw_adapter *Adapter)
458{ 429{
459 rtl8723au_write8(Adapter, REG_RD_CTRL, 0xFF); 430 rtl8723au_write8(Adapter, REG_RD_CTRL, 0xFF);
@@ -480,7 +451,7 @@ static void _InitRFType(struct rtw_adapter *Adapter)
480 451
481 pHalData->rf_chip = RF_6052; 452 pHalData->rf_chip = RF_6052;
482 453
483 if (is92CU == false) { 454 if (!is92CU) {
484 pHalData->rf_type = RF_1T1R; 455 pHalData->rf_type = RF_1T1R;
485 DBG_8723A("Set RF Chip ID to RF_6052 and RF type to 1T1R.\n"); 456 DBG_8723A("Set RF Chip ID to RF_6052 and RF type to 1T1R.\n");
486 return; 457 return;
@@ -527,23 +498,22 @@ enum rt_rf_power_state RfOnOffDetect23a(struct rtw_adapter *pAdapter)
527 return rfpowerstate; 498 return rfpowerstate;
528} 499}
529 500
530void _ps_open_RF23a(struct rtw_adapter *padapter);
531
532int rtl8723au_hal_init(struct rtw_adapter *Adapter) 501int rtl8723au_hal_init(struct rtw_adapter *Adapter)
533{ 502{
534 u8 val8 = 0;
535 u32 boundary;
536 int status = _SUCCESS;
537 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter); 503 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
538 struct pwrctrl_priv *pwrctrlpriv = &Adapter->pwrctrlpriv; 504 struct pwrctrl_priv *pwrctrlpriv = &Adapter->pwrctrlpriv;
539 struct registry_priv *pregistrypriv = &Adapter->registrypriv; 505 struct registry_priv *pregistrypriv = &Adapter->registrypriv;
506 u8 val8 = 0;
507 u32 boundary;
508 int status = _SUCCESS;
509 bool mac_on;
540 510
541 unsigned long init_start_time = jiffies; 511 unsigned long init_start_time = jiffies;
542 512
543 Adapter->hw_init_completed = false; 513 Adapter->hw_init_completed = false;
544 514
545 if (Adapter->pwrctrlpriv.bkeepfwalive) { 515 if (Adapter->pwrctrlpriv.bkeepfwalive) {
546 _ps_open_RF23a(Adapter); 516 phy_SsPwrSwitch92CU(Adapter, rf_on);
547 517
548 if (pHalData->bIQKInitialized) { 518 if (pHalData->bIQKInitialized) {
549 rtl8723a_phy_iq_calibrate(Adapter, true); 519 rtl8723a_phy_iq_calibrate(Adapter, true);
@@ -566,9 +536,9 @@ int rtl8723au_hal_init(struct rtw_adapter *Adapter)
566 /* 0x100 value of first mac is 0xEA while 0x100 value of secondary 536 /* 0x100 value of first mac is 0xEA while 0x100 value of secondary
567 is 0x00 */ 537 is 0x00 */
568 if (val8 == 0xEA) { 538 if (val8 == 0xEA) {
569 pHalData->bMACFuncEnable = false; 539 mac_on = false;
570 } else { 540 } else {
571 pHalData->bMACFuncEnable = true; 541 mac_on = true;
572 RT_TRACE(_module_hci_hal_init_c_, _drv_info_, 542 RT_TRACE(_module_hci_hal_init_c_, _drv_info_,
573 ("%s: MAC has already power on\n", __func__)); 543 ("%s: MAC has already power on\n", __func__));
574 } 544 }
@@ -587,7 +557,7 @@ int rtl8723au_hal_init(struct rtw_adapter *Adapter)
587 boundary = WMM_NORMAL_TX_PAGE_BOUNDARY; 557 boundary = WMM_NORMAL_TX_PAGE_BOUNDARY;
588 } 558 }
589 559
590 if (!pHalData->bMACFuncEnable) { 560 if (!mac_on) {
591 status = InitLLTTable23a(Adapter, boundary); 561 status = InitLLTTable23a(Adapter, boundary);
592 if (status == _FAIL) { 562 if (status == _FAIL) {
593 RT_TRACE(_module_hci_hal_init_c_, _drv_err_, 563 RT_TRACE(_module_hci_hal_init_c_, _drv_err_,
@@ -673,7 +643,7 @@ int rtl8723au_hal_init(struct rtw_adapter *Adapter)
673 pHalData->RfRegChnlVal[0] = PHY_QueryRFReg(Adapter, (enum RF_RADIO_PATH)0, RF_CHNLBW, bRFRegOffsetMask); 643 pHalData->RfRegChnlVal[0] = PHY_QueryRFReg(Adapter, (enum RF_RADIO_PATH)0, RF_CHNLBW, bRFRegOffsetMask);
674 pHalData->RfRegChnlVal[1] = PHY_QueryRFReg(Adapter, (enum RF_RADIO_PATH)1, RF_CHNLBW, bRFRegOffsetMask); 644 pHalData->RfRegChnlVal[1] = PHY_QueryRFReg(Adapter, (enum RF_RADIO_PATH)1, RF_CHNLBW, bRFRegOffsetMask);
675 645
676 if (!pHalData->bMACFuncEnable) { 646 if (!mac_on) {
677 _InitQueueReservedPage(Adapter); 647 _InitQueueReservedPage(Adapter);
678 _InitTxBufferBoundary(Adapter); 648 _InitTxBufferBoundary(Adapter);
679 } 649 }
@@ -694,8 +664,6 @@ int rtl8723au_hal_init(struct rtw_adapter *Adapter)
694 _InitRetryFunction(Adapter); 664 _InitRetryFunction(Adapter);
695 rtl8723a_InitBeaconParameters(Adapter); 665 rtl8723a_InitBeaconParameters(Adapter);
696 666
697 _InitHWLed(Adapter);
698
699 _BBTurnOnBlock(Adapter); 667 _BBTurnOnBlock(Adapter);
700 /* NicIFSetMacAddress(padapter, padapter->PermanentAddress); */ 668 /* NicIFSetMacAddress(padapter, padapter->PermanentAddress); */
701 669
@@ -806,266 +774,108 @@ exit:
806} 774}
807 775
808static void phy_SsPwrSwitch92CU(struct rtw_adapter *Adapter, 776static void phy_SsPwrSwitch92CU(struct rtw_adapter *Adapter,
809 enum rt_rf_power_state eRFPowerState, 777 enum rt_rf_power_state eRFPowerState)
810 int bRegSSPwrLvl)
811{ 778{
812 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter); 779 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
813 u8 value8; 780 u8 sps0;
814 u8 bytetmp; 781
782 sps0 = rtl8723au_read8(Adapter, REG_SPS0_CTRL);
815 783
816 switch (eRFPowerState) { 784 switch (eRFPowerState) {
817 case rf_on: 785 case rf_on:
818 if (bRegSSPwrLvl == 1) { 786 /* 1. Enable MAC Clock. Can not be enabled now. */
819 /* 1. Enable MAC Clock. Can not be enabled now. */ 787 /* WriteXBYTE(REG_SYS_CLKR+1,
820 /* WriteXBYTE(REG_SYS_CLKR+1, 788 ReadXBYTE(REG_SYS_CLKR+1) | BIT(3)); */
821 ReadXBYTE(REG_SYS_CLKR+1) | BIT(3)); */ 789
822 790 /* 2. Force PWM, Enable SPS18_LDO_Marco_Block */
823 /* 2. Force PWM, Enable SPS18_LDO_Marco_Block */ 791 rtl8723au_write8(Adapter, REG_SPS0_CTRL,
824 rtl8723au_write8(Adapter, REG_SPS0_CTRL, 792 sps0 | BIT(0) | BIT(3));
825 rtl8723au_read8(Adapter, REG_SPS0_CTRL) | 793
826 BIT(0) | BIT(3)); 794 /* 3. restore BB, AFE control register. */
827 795 /* RF */
828 /* 3. restore BB, AFE control register. */ 796 if (pHalData->rf_type == RF_2T2R)
829 /* RF */ 797 PHY_SetBBReg(Adapter, rFPGA0_XAB_RFParameter,
830 if (pHalData->rf_type == RF_2T2R) 798 0x380038, 1);
831 PHY_SetBBReg(Adapter, rFPGA0_XAB_RFParameter, 799 else
832 0x380038, 1); 800 PHY_SetBBReg(Adapter, rFPGA0_XAB_RFParameter,
833 else 801 0x38, 1);
834 PHY_SetBBReg(Adapter, rFPGA0_XAB_RFParameter, 802 PHY_SetBBReg(Adapter, rOFDM0_TRxPathEnable, 0xf0, 1);
835 0x38, 1); 803 PHY_SetBBReg(Adapter, rFPGA0_RFMOD, BIT(1), 0);
836 PHY_SetBBReg(Adapter, rOFDM0_TRxPathEnable, 0xf0, 1); 804
837 PHY_SetBBReg(Adapter, rFPGA0_RFMOD, BIT(1), 0); 805 /* AFE */
838 806 if (pHalData->rf_type == RF_2T2R)
839 /* AFE */ 807 PHY_SetBBReg(Adapter, rRx_Wait_CCA, bMaskDWord,
840 if (pHalData->rf_type == RF_2T2R) 808 0x63DB25A0);
841 PHY_SetBBReg(Adapter, rRx_Wait_CCA, bMaskDWord, 809 else if (pHalData->rf_type == RF_1T1R)
842 0x63DB25A0); 810 PHY_SetBBReg(Adapter, rRx_Wait_CCA, bMaskDWord,
843 else if (pHalData->rf_type == RF_1T1R) 811 0x631B25A0);
844 PHY_SetBBReg(Adapter, rRx_Wait_CCA, bMaskDWord, 812
845 0x631B25A0); 813 /* 4. issue 3-wire command that RF set to Rx idle
846 814 mode. This is used to re-write the RX idle mode. */
847 /* 4. issue 3-wire command that RF set to Rx idle 815 /* We can only prvide a usual value instead and then
848 mode. This is used to re-write the RX idle mode. */ 816 HW will modify the value by itself. */
849 /* We can only prvide a usual value instead and then 817 PHY_SetRFReg(Adapter, RF_PATH_A, 0, bRFRegOffsetMask, 0x32D95);
850 HW will modify the value by itself. */ 818 if (pHalData->rf_type == RF_2T2R) {
851 PHY_SetRFReg(Adapter, RF_PATH_A, 0, 819 PHY_SetRFReg(Adapter, RF_PATH_B, 0,
852 bRFRegOffsetMask, 0x32D95);
853 if (pHalData->rf_type == RF_2T2R) {
854 PHY_SetRFReg(Adapter, RF_PATH_B, 0,
855 bRFRegOffsetMask, 0x32D95);
856 }
857 } else { /* Level 2 or others. */
858 /* h. AFE_PLL_CTRL 0x28[7:0] = 0x80
859 disable AFE PLL */
860 rtl8723au_write8(Adapter, REG_AFE_PLL_CTRL, 0x81);
861
862 /* i. AFE_XTAL_CTRL 0x24[15:0] = 0x880F
863 gated AFE DIG_CLOCK */
864 rtl8723au_write16(Adapter, REG_AFE_XTAL_CTRL, 0x800F);
865 mdelay(1);
866
867 /* 2. Force PWM, Enable SPS18_LDO_Marco_Block */
868 rtl8723au_write8(Adapter, REG_SPS0_CTRL,
869 rtl8723au_read8(Adapter, REG_SPS0_CTRL) |
870 BIT(0) | BIT(3));
871
872 /* 3. restore BB, AFE control register. */
873 /* RF */
874 if (pHalData->rf_type == RF_2T2R)
875 PHY_SetBBReg(Adapter, rFPGA0_XAB_RFParameter,
876 0x380038, 1);
877 else
878 PHY_SetBBReg(Adapter, rFPGA0_XAB_RFParameter,
879 0x38, 1);
880 PHY_SetBBReg(Adapter, rOFDM0_TRxPathEnable, 0xf0, 1);
881 PHY_SetBBReg(Adapter, rFPGA0_RFMOD, BIT(1), 0);
882
883 /* AFE */
884 if (pHalData->rf_type == RF_2T2R)
885 PHY_SetBBReg(Adapter, rRx_Wait_CCA,
886 bMaskDWord, 0x63DB25A0);
887 else if (pHalData->rf_type == RF_1T1R)
888 PHY_SetBBReg(Adapter, rRx_Wait_CCA,
889 bMaskDWord, 0x631B25A0);
890
891 /* 4. issue 3-wire command that RF set to Rx idle
892 mode. This is used to re-write the RX idle mode. */
893 /* We can only prvide a usual value instead and
894 then HW will modify the value by itself. */
895 PHY_SetRFReg(Adapter, RF_PATH_A, 0,
896 bRFRegOffsetMask, 0x32D95); 820 bRFRegOffsetMask, 0x32D95);
897 if (pHalData->rf_type == RF_2T2R) {
898 PHY_SetRFReg(Adapter, RF_PATH_B, 0,
899 bRFRegOffsetMask, 0x32D95);
900 }
901
902 /* 5. gated MAC Clock */
903 bytetmp = rtl8723au_read8(Adapter, REG_APSD_CTRL);
904 rtl8723au_write8(Adapter, REG_APSD_CTRL,
905 bytetmp & ~BIT(6));
906
907 mdelay(10);
908
909 /* Set BB reset at first */
910 /* 0x16 */
911 rtl8723au_write8(Adapter, REG_SYS_FUNC_EN, 0x17);
912
913 /* Enable TX */
914 rtl8723au_write8(Adapter, REG_TXPAUSE, 0x0);
915 } 821 }
916 break; 822 break;
917 case rf_sleep: 823 case rf_sleep:
918 case rf_off: 824 case rf_off:
919 value8 = rtl8723au_read8(Adapter, REG_SPS0_CTRL);
920 if (IS_81xxC_VENDOR_UMC_B_CUT(pHalData->VersionID)) 825 if (IS_81xxC_VENDOR_UMC_B_CUT(pHalData->VersionID))
921 value8 &= ~BIT(0); 826 sps0 &= ~BIT(0);
922 else 827 else
923 value8 &= ~(BIT(0) | BIT(3)); 828 sps0 &= ~(BIT(0) | BIT(3));
924 if (bRegSSPwrLvl == 1) { 829
925 RT_TRACE(_module_hal_init_c_, _drv_err_, ("SS LVL1\n")); 830 RT_TRACE(_module_hal_init_c_, _drv_err_, ("SS LVL1\n"));
926 /* Disable RF and BB only for SelectSuspend. */ 831 /* Disable RF and BB only for SelectSuspend. */
927 832
928 /* 1. Set BB/RF to shutdown. */ 833 /* 1. Set BB/RF to shutdown. */
929 /* (1) Reg878[5:3]= 0 RF rx_code for 834 /* (1) Reg878[5:3]= 0 RF rx_code for
930 preamble power saving */ 835 preamble power saving */
931 /* (2)Reg878[21:19]= 0 Turn off RF-B */ 836 /* (2)Reg878[21:19]= 0 Turn off RF-B */
932 /* (3) RegC04[7:4]= 0 Turn off all paths 837 /* (3) RegC04[7:4]= 0 Turn off all paths
933 for packet detection */ 838 for packet detection */
934 /* (4) Reg800[1] = 1 enable preamble power 839 /* (4) Reg800[1] = 1 enable preamble power saving */
935 saving */ 840 Adapter->pwrctrlpriv.PS_BBRegBackup[PSBBREG_RF0] =
936 Adapter->pwrctrlpriv.PS_BBRegBackup[PSBBREG_RF0] = 841 PHY_QueryBBReg(Adapter, rFPGA0_XAB_RFParameter,
937 PHY_QueryBBReg(Adapter, rFPGA0_XAB_RFParameter, 842 bMaskDWord);
938 bMaskDWord); 843 Adapter->pwrctrlpriv.PS_BBRegBackup[PSBBREG_RF1] =
939 Adapter->pwrctrlpriv.PS_BBRegBackup[PSBBREG_RF1] = 844 PHY_QueryBBReg(Adapter, rOFDM0_TRxPathEnable,
940 PHY_QueryBBReg(Adapter, rOFDM0_TRxPathEnable, 845 bMaskDWord);
941 bMaskDWord); 846 Adapter->pwrctrlpriv.PS_BBRegBackup[PSBBREG_RF2] =
942 Adapter->pwrctrlpriv.PS_BBRegBackup[PSBBREG_RF2] = 847 PHY_QueryBBReg(Adapter, rFPGA0_RFMOD, bMaskDWord);
943 PHY_QueryBBReg(Adapter, rFPGA0_RFMOD, 848 if (pHalData->rf_type == RF_2T2R) {
944 bMaskDWord); 849 PHY_SetBBReg(Adapter, rFPGA0_XAB_RFParameter,
945 if (pHalData->rf_type == RF_2T2R) { 850 0x380038, 0);
946 PHY_SetBBReg(Adapter, rFPGA0_XAB_RFParameter, 851 } else if (pHalData->rf_type == RF_1T1R) {
947 0x380038, 0); 852 PHY_SetBBReg(Adapter, rFPGA0_XAB_RFParameter, 0x38, 0);
948 } else if (pHalData->rf_type == RF_1T1R) {
949 PHY_SetBBReg(Adapter, rFPGA0_XAB_RFParameter,
950 0x38, 0);
951 }
952 PHY_SetBBReg(Adapter, rOFDM0_TRxPathEnable, 0xf0, 0);
953 PHY_SetBBReg(Adapter, rFPGA0_RFMOD, BIT(1), 1);
954
955 /* 2 .AFE control register to power down. bit[30:22] */
956 Adapter->pwrctrlpriv.PS_BBRegBackup[PSBBREG_AFE0] =
957 PHY_QueryBBReg(Adapter, rRx_Wait_CCA,
958 bMaskDWord);
959 if (pHalData->rf_type == RF_2T2R)
960 PHY_SetBBReg(Adapter, rRx_Wait_CCA, bMaskDWord,
961 0x00DB25A0);
962 else if (pHalData->rf_type == RF_1T1R)
963 PHY_SetBBReg(Adapter, rRx_Wait_CCA, bMaskDWord,
964 0x001B25A0);
965
966 /* 3. issue 3-wire command that RF set to power down.*/
967 PHY_SetRFReg(Adapter, RF_PATH_A, 0, bRFRegOffsetMask, 0);
968 if (pHalData->rf_type == RF_2T2R)
969 PHY_SetRFReg(Adapter, RF_PATH_B, 0,
970 bRFRegOffsetMask, 0);
971
972 /* 4. Force PFM , disable SPS18_LDO_Marco_Block */
973 rtl8723au_write8(Adapter, REG_SPS0_CTRL, value8);
974 } else { /* Level 2 or others. */
975 RT_TRACE(_module_hal_init_c_, _drv_err_, ("SS LVL2\n"));
976 {
977 u8 eRFPath = RF_PATH_A, value8 = 0;
978 rtl8723au_write8(Adapter, REG_TXPAUSE, 0xFF);
979 PHY_SetRFReg(Adapter,
980 (enum RF_RADIO_PATH)eRFPath,
981 0x0, bMaskByte0, 0x0);
982 value8 |= APSDOFF;
983 /* 0x40 */
984 rtl8723au_write8(Adapter, REG_APSD_CTRL,
985 value8);
986
987 /* After switch APSD, we need to delay
988 for stability */
989 mdelay(10);
990
991 /* Set BB reset at first */
992 value8 = 0;
993 value8 |= (FEN_USBD | FEN_USBA |
994 FEN_BB_GLB_RSTn);
995 /* 0x16 */
996 rtl8723au_write8(Adapter, REG_SYS_FUNC_EN,
997 value8);
998 }
999
1000 /* Disable RF and BB only for SelectSuspend. */
1001
1002 /* 1. Set BB/RF to shutdown. */
1003 /* (1) Reg878[5:3]= 0 RF rx_code for
1004 preamble power saving */
1005 /* (2)Reg878[21:19]= 0 Turn off RF-B */
1006 /* (3) RegC04[7:4]= 0 Turn off all paths for
1007 packet detection */
1008 /* (4) Reg800[1] = 1 enable preamble power
1009 saving */
1010 Adapter->pwrctrlpriv.PS_BBRegBackup[PSBBREG_RF0] =
1011 PHY_QueryBBReg(Adapter, rFPGA0_XAB_RFParameter,
1012 bMaskDWord);
1013 Adapter->pwrctrlpriv.PS_BBRegBackup[PSBBREG_RF1] =
1014 PHY_QueryBBReg(Adapter, rOFDM0_TRxPathEnable,
1015 bMaskDWord);
1016 Adapter->pwrctrlpriv.PS_BBRegBackup[PSBBREG_RF2] =
1017 PHY_QueryBBReg(Adapter, rFPGA0_RFMOD,
1018 bMaskDWord);
1019 if (pHalData->rf_type == RF_2T2R)
1020 PHY_SetBBReg(Adapter, rFPGA0_XAB_RFParameter,
1021 0x380038, 0);
1022 else if (pHalData->rf_type == RF_1T1R)
1023 PHY_SetBBReg(Adapter, rFPGA0_XAB_RFParameter,
1024 0x38, 0);
1025 PHY_SetBBReg(Adapter, rOFDM0_TRxPathEnable, 0xf0, 0);
1026 PHY_SetBBReg(Adapter, rFPGA0_RFMOD, BIT(1), 1);
1027
1028 /* 2 .AFE control register to power down. bit[30:22] */
1029 Adapter->pwrctrlpriv.PS_BBRegBackup[PSBBREG_AFE0] =
1030 PHY_QueryBBReg(Adapter, rRx_Wait_CCA,
1031 bMaskDWord);
1032 if (pHalData->rf_type == RF_2T2R)
1033 PHY_SetBBReg(Adapter, rRx_Wait_CCA, bMaskDWord,
1034 0x00DB25A0);
1035 else if (pHalData->rf_type == RF_1T1R)
1036 PHY_SetBBReg(Adapter, rRx_Wait_CCA, bMaskDWord,
1037 0x001B25A0);
1038
1039 /* 3. issue 3-wire command that RF set to power down. */
1040 PHY_SetRFReg(Adapter, RF_PATH_A, 0, bRFRegOffsetMask, 0);
1041 if (pHalData->rf_type == RF_2T2R)
1042 PHY_SetRFReg(Adapter, RF_PATH_B, 0,
1043 bRFRegOffsetMask, 0);
1044
1045 /* 4. Force PFM , disable SPS18_LDO_Marco_Block */
1046 rtl8723au_write8(Adapter, REG_SPS0_CTRL, value8);
1047
1048 /* 2010/10/13 MH/Isaachsu exchange sequence. */
1049 /* h. AFE_PLL_CTRL 0x28[7:0] = 0x80
1050 disable AFE PLL */
1051 rtl8723au_write8(Adapter, REG_AFE_PLL_CTRL, 0x80);
1052 mdelay(1);
1053
1054 /* i. AFE_XTAL_CTRL 0x24[15:0] = 0x880F
1055 gated AFE DIG_CLOCK */
1056 rtl8723au_write16(Adapter, REG_AFE_XTAL_CTRL, 0xA80F);
1057 } 853 }
854 PHY_SetBBReg(Adapter, rOFDM0_TRxPathEnable, 0xf0, 0);
855 PHY_SetBBReg(Adapter, rFPGA0_RFMOD, BIT(1), 1);
856
857 /* 2 .AFE control register to power down. bit[30:22] */
858 Adapter->pwrctrlpriv.PS_BBRegBackup[PSBBREG_AFE0] =
859 PHY_QueryBBReg(Adapter, rRx_Wait_CCA, bMaskDWord);
860 if (pHalData->rf_type == RF_2T2R)
861 PHY_SetBBReg(Adapter, rRx_Wait_CCA, bMaskDWord,
862 0x00DB25A0);
863 else if (pHalData->rf_type == RF_1T1R)
864 PHY_SetBBReg(Adapter, rRx_Wait_CCA, bMaskDWord,
865 0x001B25A0);
866
867 /* 3. issue 3-wire command that RF set to power down.*/
868 PHY_SetRFReg(Adapter, RF_PATH_A, 0, bRFRegOffsetMask, 0);
869 if (pHalData->rf_type == RF_2T2R)
870 PHY_SetRFReg(Adapter, RF_PATH_B, 0,
871 bRFRegOffsetMask, 0);
872
873 /* 4. Force PFM , disable SPS18_LDO_Marco_Block */
874 rtl8723au_write8(Adapter, REG_SPS0_CTRL, sps0);
1058 break; 875 break;
1059 default: 876 default:
1060 break; 877 break;
1061 } 878 }
1062
1063} /* phy_PowerSwitch92CU */
1064
1065void _ps_open_RF23a(struct rtw_adapter *padapter)
1066{
1067 /* here call with bRegSSPwrLvl 1, bRegSSPwrLvl 2 needs to be verified */
1068 phy_SsPwrSwitch92CU(padapter, rf_on, 1);
1069} 879}
1070 880
1071static void CardDisableRTL8723U(struct rtw_adapter *Adapter) 881static void CardDisableRTL8723U(struct rtw_adapter *Adapter)
@@ -1142,8 +952,7 @@ int rtl8723au_inirp_init(struct rtw_adapter *Adapter)
1142 /* issue Rx irp to receive data */ 952 /* issue Rx irp to receive data */
1143 precvbuf = (struct recv_buf *)precvpriv->precv_buf; 953 precvbuf = (struct recv_buf *)precvpriv->precv_buf;
1144 for (i = 0; i < NR_RECVBUFF; i++) { 954 for (i = 0; i < NR_RECVBUFF; i++) {
1145 if (rtl8723au_read_port(Adapter, RECV_BULK_IN_ADDR, 0, 955 if (rtl8723au_read_port(Adapter, 0, precvbuf) == _FAIL) {
1146 precvbuf) == _FAIL) {
1147 RT_TRACE(_module_hci_hal_init_c_, _drv_err_, 956 RT_TRACE(_module_hci_hal_init_c_, _drv_err_,
1148 ("usb_rx_init: usb_read_port error\n")); 957 ("usb_rx_init: usb_read_port error\n"));
1149 status = _FAIL; 958 status = _FAIL;
@@ -1151,9 +960,9 @@ int rtl8723au_inirp_init(struct rtw_adapter *Adapter)
1151 } 960 }
1152 precvbuf++; 961 precvbuf++;
1153 } 962 }
1154 if (rtl8723au_read_interrupt(Adapter, RECV_INT_IN_ADDR) == _FAIL) { 963 if (rtl8723au_read_interrupt(Adapter) == _FAIL) {
1155 RT_TRACE(_module_hci_hal_init_c_, _drv_err_, 964 RT_TRACE(_module_hci_hal_init_c_, _drv_err_,
1156 ("usb_rx_init: usb_read_interrupt error\n")); 965 ("%s: usb_read_interrupt error\n", __func__));
1157 status = _FAIL; 966 status = _FAIL;
1158 } 967 }
1159 pHalData->IntrMask[0] = rtl8723au_read32(Adapter, REG_USB_HIMR); 968 pHalData->IntrMask[0] = rtl8723au_read32(Adapter, REG_USB_HIMR);
@@ -1209,14 +1018,6 @@ static void _ReadBoardType(struct rtw_adapter *Adapter, u8 *PROMContent,
1209 pHalData->ExternalPA = 1; 1018 pHalData->ExternalPA = 1;
1210} 1019}
1211 1020
1212static void _ReadLEDSetting(struct rtw_adapter *Adapter, u8 *PROMContent,
1213 bool AutoloadFail)
1214{
1215 struct led_priv *pledpriv = &Adapter->ledpriv;
1216
1217 pledpriv->LedStrategy = HW_LED;
1218}
1219
1220static void Hal_EfuseParseMACAddr_8723AU(struct rtw_adapter *padapter, 1021static void Hal_EfuseParseMACAddr_8723AU(struct rtw_adapter *padapter,
1221 u8 *hwinfo, bool AutoLoadFail) 1022 u8 *hwinfo, bool AutoLoadFail)
1222{ 1023{
@@ -1263,7 +1064,6 @@ static void readAdapterInfo(struct rtw_adapter *padapter)
1263 pEEPROM->bautoload_fail_flag); 1064 pEEPROM->bautoload_fail_flag);
1264 Hal_EfuseParseThermalMeter_8723A(padapter, hwinfo, 1065 Hal_EfuseParseThermalMeter_8723A(padapter, hwinfo,
1265 pEEPROM->bautoload_fail_flag); 1066 pEEPROM->bautoload_fail_flag);
1266 _ReadLEDSetting(padapter, hwinfo, pEEPROM->bautoload_fail_flag);
1267/* _ReadRFSetting(Adapter, PROMContent, pEEPROM->bautoload_fail_flag); */ 1067/* _ReadRFSetting(Adapter, PROMContent, pEEPROM->bautoload_fail_flag); */
1268/* _ReadPSSetting(Adapter, PROMContent, pEEPROM->bautoload_fail_flag); */ 1068/* _ReadPSSetting(Adapter, PROMContent, pEEPROM->bautoload_fail_flag); */
1269 Hal_EfuseParseAntennaDiversity(padapter, hwinfo, 1069 Hal_EfuseParseAntennaDiversity(padapter, hwinfo,
@@ -1276,10 +1076,6 @@ static void readAdapterInfo(struct rtw_adapter *padapter)
1276 pEEPROM->bautoload_fail_flag); 1076 pEEPROM->bautoload_fail_flag);
1277 Hal_EfuseParseXtal_8723A(padapter, hwinfo, 1077 Hal_EfuseParseXtal_8723A(padapter, hwinfo,
1278 pEEPROM->bautoload_fail_flag); 1078 pEEPROM->bautoload_fail_flag);
1279 /* */
1280 /* The following part initialize some vars by PG info. */
1281 /* */
1282 Hal_InitChannelPlan23a(padapter);
1283 1079
1284 /* hal_CustomizedBehavior_8723U(Adapter); */ 1080 /* hal_CustomizedBehavior_8723U(Adapter); */
1285 1081
@@ -1311,13 +1107,6 @@ static void _ReadRFType(struct rtw_adapter *Adapter)
1311 pHalData->rf_chip = RF_6052; 1107 pHalData->rf_chip = RF_6052;
1312} 1108}
1313 1109
1314static void _ReadSilmComboMode(struct rtw_adapter *Adapter)
1315{
1316 struct hal_data_8723a *pHalData = GET_HAL_DATA(Adapter);
1317
1318 pHalData->SlimComboDbg = false; /* Default is not debug mode. */
1319}
1320
1321/* */ 1110/* */
1322/* Description: */ 1111/* Description: */
1323/* We should set Efuse cell selection to WiFi cell in default. */ 1112/* We should set Efuse cell selection to WiFi cell in default. */
@@ -1350,10 +1139,6 @@ void rtl8723a_read_adapter_info(struct rtw_adapter *Adapter)
1350 _ReadRFType(Adapter);/* rf_chip -> _InitRFType() */ 1139 _ReadRFType(Adapter);/* rf_chip -> _InitRFType() */
1351 _ReadPROMContent(Adapter); 1140 _ReadPROMContent(Adapter);
1352 1141
1353 /* 2010/10/25 MH THe function must be called after
1354 borad_type & IC-Version recognize. */
1355 _ReadSilmComboMode(Adapter);
1356
1357 /* MSG_8723A("%s()(done), rf_chip = 0x%x, rf_type = 0x%x\n", 1142 /* MSG_8723A("%s()(done), rf_chip = 0x%x, rf_type = 0x%x\n",
1358 __func__, pHalData->rf_chip, pHalData->rf_type); */ 1143 __func__, pHalData->rf_chip, pHalData->rf_type); */
1359 1144
@@ -1417,17 +1202,17 @@ int GetHalDefVar8192CUsb(struct rtw_adapter *Adapter,
1417void rtl8723a_update_ramask(struct rtw_adapter *padapter, 1202void rtl8723a_update_ramask(struct rtw_adapter *padapter,
1418 u32 mac_id, u8 rssi_level) 1203 u32 mac_id, u8 rssi_level)
1419{ 1204{
1420 u8 init_rate = 0;
1421 u8 networkType, raid;
1422 u32 mask, rate_bitmap;
1423 u8 shortGIrate = false;
1424 int supportRateNum = 0;
1425 struct sta_info *psta; 1205 struct sta_info *psta;
1426 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter); 1206 struct FW_Sta_Info *fw_sta;
1427 struct dm_priv *pdmpriv = &pHalData->dmpriv; 1207 struct hal_data_8723a *pHalData = GET_HAL_DATA(padapter);
1208 struct dm_priv *pdmpriv = &pHalData->dmpriv;
1428 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 1209 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1429 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info; 1210 struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
1430 struct wlan_bssid_ex *cur_network = &pmlmeinfo->network; 1211 struct wlan_bssid_ex *cur_network = &pmlmeinfo->network;
1212 u8 init_rate, networkType, raid;
1213 u32 mask, rate_bitmap;
1214 u8 shortGIrate = false;
1215 int supportRateNum;
1431 1216
1432 if (mac_id >= NUM_STA) /* CAM_SIZE */ 1217 if (mac_id >= NUM_STA) /* CAM_SIZE */
1433 return; 1218 return;
@@ -1456,8 +1241,8 @@ void rtl8723a_update_ramask(struct rtw_adapter *padapter,
1456 break; 1241 break;
1457 1242
1458 case 1:/* for broadcast/multicast */ 1243 case 1:/* for broadcast/multicast */
1459 supportRateNum = rtw_get_rateset_len23a( 1244 fw_sta = &pmlmeinfo->FW_sta_info[mac_id];
1460 pmlmeinfo->FW_sta_info[mac_id].SupportedRates); 1245 supportRateNum = rtw_get_rateset_len23a(fw_sta->SupportedRates);
1461 if (pmlmeext->cur_wireless_mode & WIRELESS_11B) 1246 if (pmlmeext->cur_wireless_mode & WIRELESS_11B)
1462 networkType = WIRELESS_11B; 1247 networkType = WIRELESS_11B;
1463 else 1248 else
@@ -1469,23 +1254,22 @@ void rtl8723a_update_ramask(struct rtw_adapter *padapter,
1469 break; 1254 break;
1470 1255
1471 default: /* for each sta in IBSS */ 1256 default: /* for each sta in IBSS */
1472 supportRateNum = rtw_get_rateset_len23a( 1257 fw_sta = &pmlmeinfo->FW_sta_info[mac_id];
1473 pmlmeinfo->FW_sta_info[mac_id].SupportedRates); 1258 supportRateNum = rtw_get_rateset_len23a(fw_sta->SupportedRates);
1474 networkType = judge_network_type23a(padapter, 1259 networkType = judge_network_type23a(padapter,
1475 pmlmeinfo->FW_sta_info[mac_id].SupportedRates, 1260 fw_sta->SupportedRates,
1476 supportRateNum) & 0xf; 1261 supportRateNum) & 0xf;
1477 /* pmlmeext->cur_wireless_mode = networkType; */ 1262 /* pmlmeext->cur_wireless_mode = networkType; */
1478 raid = networktype_to_raid23a(networkType); 1263 raid = networktype_to_raid23a(networkType);
1479 1264
1480 mask = update_supported_rate23a(cur_network->SupportedRates, 1265 mask = update_supported_rate23a(cur_network->SupportedRates,
1481 supportRateNum); 1266 supportRateNum);
1482 1267
1483 /* todo: support HT in IBSS */ 1268 /* todo: support HT in IBSS */
1484 break; 1269 break;
1485 } 1270 }
1486 1271
1487 /* mask &= 0x0fffffff; */ 1272 /* mask &= 0x0fffffff; */
1488 rate_bitmap = 0x0fffffff;
1489 rate_bitmap = ODM_Get_Rate_Bitmap23a(pHalData, mac_id, mask, 1273 rate_bitmap = ODM_Get_Rate_Bitmap23a(pHalData, mac_id, mask,
1490 rssi_level); 1274 rssi_level);
1491 DBG_8723A("%s => mac_id:%d, networkType:0x%02x, " 1275 DBG_8723A("%s => mac_id:%d, networkType:0x%02x, "
@@ -1493,15 +1277,14 @@ void rtl8723a_update_ramask(struct rtw_adapter *padapter,
1493 __func__, mac_id, networkType, mask, rssi_level, rate_bitmap); 1277 __func__, mac_id, networkType, mask, rssi_level, rate_bitmap);
1494 1278
1495 mask &= rate_bitmap; 1279 mask &= rate_bitmap;
1496 mask |= ((raid<<28)&0xf0000000); 1280 mask |= ((raid << 28) & 0xf0000000);
1497 1281
1498 init_rate = get_highest_rate_idx23a(mask)&0x3f; 1282 init_rate = get_highest_rate_idx23a(mask) & 0x3f;
1499 1283
1500 if (pHalData->fw_ractrl == true) { 1284 if (pHalData->fw_ractrl == true) {
1501 u8 arg = 0; 1285 u8 arg = 0;
1502 1286
1503 /* arg = (cam_idx-4)&0x1f;MACID */ 1287 arg = mac_id & 0x1f;/* MACID */
1504 arg = mac_id&0x1f;/* MACID */
1505 1288
1506 arg |= BIT(7); 1289 arg |= BIT(7);
1507 1290
@@ -1516,7 +1299,7 @@ void rtl8723a_update_ramask(struct rtw_adapter *padapter,
1516 if (shortGIrate == true) 1299 if (shortGIrate == true)
1517 init_rate |= BIT(6); 1300 init_rate |= BIT(6);
1518 1301
1519 rtl8723au_write8(padapter, (REG_INIDATA_RATE_SEL+mac_id), 1302 rtl8723au_write8(padapter, (REG_INIDATA_RATE_SEL + mac_id),
1520 init_rate); 1303 init_rate);
1521 } 1304 }
1522 1305
diff --git a/drivers/staging/rtl8723au/hal/usb_ops_linux.c b/drivers/staging/rtl8723au/hal/usb_ops_linux.c
index c1b04c13c392..a6d16adce107 100644
--- a/drivers/staging/rtl8723au/hal/usb_ops_linux.c
+++ b/drivers/staging/rtl8723au/hal/usb_ops_linux.c
@@ -317,7 +317,7 @@ urb_submit:
317 } 317 }
318} 318}
319 319
320int rtl8723au_read_interrupt(struct rtw_adapter *adapter, u32 addr) 320int rtl8723au_read_interrupt(struct rtw_adapter *adapter)
321{ 321{
322 int err; 322 int err;
323 unsigned int pipe; 323 unsigned int pipe;
@@ -545,8 +545,7 @@ static void usb_read_port_complete(struct urb *purb)
545 ("usb_read_port_complete: (purb->actual_" 545 ("usb_read_port_complete: (purb->actual_"
546 "length > MAX_RECVBUF_SZ) || (purb->actual_" 546 "length > MAX_RECVBUF_SZ) || (purb->actual_"
547 "length < RXDESC_SIZE)\n")); 547 "length < RXDESC_SIZE)\n"));
548 rtl8723au_read_port(padapter, RECV_BULK_IN_ADDR, 0, 548 rtl8723au_read_port(padapter, 0, precvbuf);
549 precvbuf);
550 DBG_8723A("%s()-%d: RX Warning!\n", 549 DBG_8723A("%s()-%d: RX Warning!\n",
551 __func__, __LINE__); 550 __func__, __LINE__);
552 } else { 551 } else {
@@ -561,8 +560,7 @@ static void usb_read_port_complete(struct urb *purb)
561 tasklet_schedule(&precvpriv->recv_tasklet); 560 tasklet_schedule(&precvpriv->recv_tasklet);
562 561
563 precvbuf->pskb = NULL; 562 precvbuf->pskb = NULL;
564 rtl8723au_read_port(padapter, RECV_BULK_IN_ADDR, 0, 563 rtl8723au_read_port(padapter, 0, precvbuf);
565 precvbuf);
566 } 564 }
567 } else { 565 } else {
568 RT_TRACE(_module_hci_ops_os_c_, _drv_err_, 566 RT_TRACE(_module_hci_ops_os_c_, _drv_err_,
@@ -596,8 +594,7 @@ static void usb_read_port_complete(struct urb *purb)
596 break; 594 break;
597 case -EPROTO: 595 case -EPROTO:
598 case -EOVERFLOW: 596 case -EOVERFLOW:
599 rtl8723au_read_port(padapter, RECV_BULK_IN_ADDR, 0, 597 rtl8723au_read_port(padapter, 0, precvbuf);
600 precvbuf);
601 break; 598 break;
602 case -EINPROGRESS: 599 case -EINPROGRESS:
603 DBG_8723A("ERROR: URB IS IN PROGRESS!\n"); 600 DBG_8723A("ERROR: URB IS IN PROGRESS!\n");
@@ -608,18 +605,18 @@ static void usb_read_port_complete(struct urb *purb)
608 } 605 }
609} 606}
610 607
611int rtl8723au_read_port(struct rtw_adapter *adapter, u32 addr, u32 cnt, 608int rtl8723au_read_port(struct rtw_adapter *adapter, u32 cnt,
612 struct recv_buf *precvbuf) 609 struct recv_buf *precvbuf)
613{ 610{
611 struct urb *purb;
612 struct dvobj_priv *pdvobj = adapter_to_dvobj(adapter);
613 struct recv_priv *precvpriv = &adapter->recvpriv;
614 struct usb_device *pusbd = pdvobj->pusbdev;
614 int err; 615 int err;
615 unsigned int pipe; 616 unsigned int pipe;
616 unsigned long tmpaddr; 617 unsigned long tmpaddr;
617 unsigned long alignment; 618 unsigned long alignment;
618 int ret = _SUCCESS; 619 int ret = _SUCCESS;
619 struct urb *purb;
620 struct dvobj_priv *pdvobj = adapter_to_dvobj(adapter);
621 struct recv_priv *precvpriv = &adapter->recvpriv;
622 struct usb_device *pusbd = pdvobj->pusbdev;
623 620
624 if (adapter->bDriverStopped || adapter->bSurpriseRemoved) { 621 if (adapter->bDriverStopped || adapter->bSurpriseRemoved) {
625 RT_TRACE(_module_hci_ops_os_c_, _drv_err_, 622 RT_TRACE(_module_hci_ops_os_c_, _drv_err_,
diff --git a/drivers/staging/rtl8723au/include/Hal8723UHWImg_CE.h b/drivers/staging/rtl8723au/include/Hal8723UHWImg_CE.h
index bbeaab48057a..c834b3a738d7 100644
--- a/drivers/staging/rtl8723au/include/Hal8723UHWImg_CE.h
+++ b/drivers/staging/rtl8723au/include/Hal8723UHWImg_CE.h
@@ -19,7 +19,7 @@ extern u8 Rtl8723UFwUMCBCutImgArrayWithoutBT[Rtl8723UUMCBCutImgArrayWithoutBTLen
19extern const u8 Rtl8723SFwUMCBCutMPImgArray[Rtl8723SUMCBCutMPImgArrayLength]; 19extern const u8 Rtl8723SFwUMCBCutMPImgArray[Rtl8723SUMCBCutMPImgArrayLength];
20 20
21#define Rtl8723EBTImgArrayLength 15276 21#define Rtl8723EBTImgArrayLength 15276
22extern u8 Rtl8723EFwBTImgArray[Rtl8723EBTImgArrayLength] ; 22extern u8 Rtl8723EFwBTImgArray[Rtl8723EBTImgArrayLength];
23 23
24#define Rtl8723UPHY_REG_Array_PGLength 336 24#define Rtl8723UPHY_REG_Array_PGLength 336
25extern u32 Rtl8723UPHY_REG_Array_PG[Rtl8723UPHY_REG_Array_PGLength]; 25extern u32 Rtl8723UPHY_REG_Array_PG[Rtl8723UPHY_REG_Array_PGLength];
diff --git a/drivers/staging/rtl8723au/include/drv_types.h b/drivers/staging/rtl8723au/include/drv_types.h
index 9870f87bdc70..e83463aeb9b1 100644
--- a/drivers/staging/rtl8723au/include/drv_types.h
+++ b/drivers/staging/rtl8723au/include/drv_types.h
@@ -51,7 +51,6 @@ enum _NIC_VERSION {
51#include <rtw_debug.h> 51#include <rtw_debug.h>
52#include <rtw_rf.h> 52#include <rtw_rf.h>
53#include <rtw_event.h> 53#include <rtw_event.h>
54#include <rtw_led.h>
55#include <rtw_mlme_ext.h> 54#include <rtw_mlme_ext.h>
56#include <rtw_ap.h> 55#include <rtw_ap.h>
57 56
@@ -228,7 +227,6 @@ struct rtw_adapter {
228 struct registry_priv registrypriv; 227 struct registry_priv registrypriv;
229 struct pwrctrl_priv pwrctrlpriv; 228 struct pwrctrl_priv pwrctrlpriv;
230 struct eeprom_priv eeprompriv; 229 struct eeprom_priv eeprompriv;
231 struct led_priv ledpriv;
232 230
233 u32 setband; 231 u32 setband;
234 232
diff --git a/drivers/staging/rtl8723au/include/odm_debug.h b/drivers/staging/rtl8723au/include/odm_debug.h
index 4d935a33ccb3..83be5bab9e09 100644
--- a/drivers/staging/rtl8723au/include/odm_debug.h
+++ b/drivers/staging/rtl8723au/include/odm_debug.h
@@ -91,8 +91,7 @@
91#define ODM_COMP_INIT BIT(31) 91#define ODM_COMP_INIT BIT(31)
92 92
93/*------------------------Export Macro Definition---------------------------*/ 93/*------------------------Export Macro Definition---------------------------*/
94 #define DbgPrint printk 94 #define RT_PRINTK(fmt, args...) printk("%s(): " fmt, __func__, ## args);
95 #define RT_PRINTK(fmt, args...) DbgPrint("%s(): " fmt, __func__, ## args);
96 95
97#ifndef ASSERT 96#ifndef ASSERT
98 #define ASSERT(expr) 97 #define ASSERT(expr)
@@ -101,38 +100,17 @@
101#define ODM_RT_TRACE(pDM_Odm, comp, level, fmt) \ 100#define ODM_RT_TRACE(pDM_Odm, comp, level, fmt) \
102 if(((comp) & pDM_Odm->DebugComponents) && (level <= pDM_Odm->DebugLevel)) \ 101 if(((comp) & pDM_Odm->DebugComponents) && (level <= pDM_Odm->DebugLevel)) \
103 { \ 102 { \
104 DbgPrint("[ODM-8723A] "); \ 103 printk("[ODM-8723A] "); \
105 RT_PRINTK fmt; \
106 }
107
108#define ODM_RT_TRACE_F(pDM_Odm, comp, level, fmt) \
109 if(((comp) & pDM_Odm->DebugComponents) && (level <= pDM_Odm->DebugLevel)) \
110 { \
111 RT_PRINTK fmt; \ 104 RT_PRINTK fmt; \
112 } 105 }
113 106
114#define ODM_RT_ASSERT(pDM_Odm, expr, fmt) \ 107#define ODM_RT_ASSERT(pDM_Odm, expr, fmt) \
115 if(!(expr)) { \ 108 if(!(expr)) { \
116 DbgPrint("Assertion failed! %s at ......\n", #expr); \ 109 printk("Assertion failed! %s at ......\n", #expr); \
117 DbgPrint(" ......%s,%s,line=%d\n", __FILE__, __func__, __LINE__);\ 110 printk(" ......%s,%s,line=%d\n", __FILE__, __func__, __LINE__);\
118 RT_PRINTK fmt; \ 111 RT_PRINTK fmt; \
119 ASSERT(false); \ 112 ASSERT(false); \
120 } 113 }
121#define ODM_dbg_enter() { DbgPrint("==> %s\n", __func__); }
122#define ODM_dbg_exit() { DbgPrint("<== %s\n", __func__); }
123#define ODM_dbg_trace(str) { DbgPrint("%s:%s\n", __func__, str); }
124
125#define ODM_PRINT_ADDR(pDM_Odm, comp, level, title_str, ptr) \
126 if(((comp) & pDM_Odm->DebugComponents) && (level <= pDM_Odm->DebugLevel){ \
127 int __i; \
128 u8 * __ptr = (u8 *)ptr; \
129 DbgPrint("[ODM] "); \
130 DbgPrint(title_str); \
131 DbgPrint(" "); \
132 for (__i=0; __i < 6; __i++) \
133 DbgPrint("%02X%s", __ptr[__i], (__i == 5) ? "" : "-"); \
134 DbgPrint("\n"); \
135 }
136 114
137void ODM_InitDebugSetting23a(struct dm_odm_t *pDM_Odm); 115void ODM_InitDebugSetting23a(struct dm_odm_t *pDM_Odm);
138 116
diff --git a/drivers/staging/rtl8723au/include/rtl8723a_dm.h b/drivers/staging/rtl8723au/include/rtl8723a_dm.h
index 18112225e53f..bf236e8e47a2 100644
--- a/drivers/staging/rtl8723au/include/rtl8723a_dm.h
+++ b/drivers/staging/rtl8723au/include/rtl8723a_dm.h
@@ -37,8 +37,7 @@ enum{
37#define IQK_BB_REG_NUM 9 37#define IQK_BB_REG_NUM 9
38#define HP_THERMAL_NUM 8 38#define HP_THERMAL_NUM 8
39/* duplicate code,will move to ODM ######### */ 39/* duplicate code,will move to ODM ######### */
40struct dm_priv 40struct dm_priv {
41{
42 u32 InitODMFlag; 41 u32 InitODMFlag;
43 42
44 /* Upper and Lower Signal threshold for Rate Adaptive*/ 43 /* Upper and Lower Signal threshold for Rate Adaptive*/
diff --git a/drivers/staging/rtl8723au/include/rtl8723a_hal.h b/drivers/staging/rtl8723au/include/rtl8723a_hal.h
index ee203a572cb7..e14633678b52 100644
--- a/drivers/staging/rtl8723au/include/rtl8723a_hal.h
+++ b/drivers/staging/rtl8723au/include/rtl8723a_hal.h
@@ -372,16 +372,9 @@ struct hal_data_8723a {
372 /* 2010/08/09 MH Add CU power down mode. */ 372 /* 2010/08/09 MH Add CU power down mode. */
373 u8 pwrdown; 373 u8 pwrdown;
374 374
375 /* Add for dual MAC 0--Mac0 1--Mac1 */
376 u32 interfaceIndex;
377
378 u8 OutEpQueueSel; 375 u8 OutEpQueueSel;
379 u8 OutEpNumber; 376 u8 OutEpNumber;
380 377
381 /* 2010/11/22 MH Add for slim combo debug mode selective. */
382 /* This is used for fix the drawback of CU TSMC-A/UMC-A cut. HW auto suspend ability. Close BT clock. */
383 bool SlimComboDbg;
384
385 /* */ 378 /* */
386 /* Add For EEPROM Efuse switch and Efuse Shadow map Setting */ 379 /* Add For EEPROM Efuse switch and Efuse Shadow map Setting */
387 /* */ 380 /* */
@@ -405,8 +398,6 @@ struct hal_data_8723a {
405 * 2011/02/23 MH Add for 8723 mylti function definition. The define should be moved to an */ 398 * 2011/02/23 MH Add for 8723 mylti function definition. The define should be moved to an */
406 /* independent file in the future. */ 399 /* independent file in the future. */
407 400
408 bool bMACFuncEnable;
409
410 /* Interrupt related register information. */ 401 /* Interrupt related register information. */
411 u32 IntArray[2]; 402 u32 IntArray[2];
412 u32 IntrMask[2]; 403 u32 IntrMask[2];
@@ -518,8 +509,6 @@ void Hal_EfuseParseRateIndicationOption(struct rtw_adapter *padapter, u8 *hwinfo
518void Hal_EfuseParseXtal_8723A(struct rtw_adapter *pAdapter, u8 *hwinfo, u8 AutoLoadFail); 509void Hal_EfuseParseXtal_8723A(struct rtw_adapter *pAdapter, u8 *hwinfo, u8 AutoLoadFail);
519void Hal_EfuseParseThermalMeter_8723A(struct rtw_adapter *padapter, u8 *hwinfo, bool AutoLoadFail); 510void Hal_EfuseParseThermalMeter_8723A(struct rtw_adapter *padapter, u8 *hwinfo, bool AutoLoadFail);
520 511
521void Hal_InitChannelPlan23a(struct rtw_adapter *padapter);
522
523/* register */ 512/* register */
524void SetBcnCtrlReg23a(struct rtw_adapter *padapter, u8 SetBits, u8 ClearBits); 513void SetBcnCtrlReg23a(struct rtw_adapter *padapter, u8 SetBits, u8 ClearBits);
525void rtl8723a_InitBeaconParameters(struct rtw_adapter *padapter); 514void rtl8723a_InitBeaconParameters(struct rtw_adapter *padapter);
diff --git a/drivers/staging/rtl8723au/include/rtl8723a_led.h b/drivers/staging/rtl8723au/include/rtl8723a_led.h
deleted file mode 100644
index 1623d186feb4..000000000000
--- a/drivers/staging/rtl8723au/include/rtl8723a_led.h
+++ /dev/null
@@ -1,30 +0,0 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 ******************************************************************************/
15#ifndef __RTL8723A_LED_H__
16#define __RTL8723A_LED_H__
17
18#include <osdep_service.h>
19#include <drv_types.h>
20
21
22/* */
23/* Interface to manipulate LED objects. */
24/* */
25void rtl8723au_InitSwLeds(struct rtw_adapter *padapter);
26void rtl8723au_DeInitSwLeds(struct rtw_adapter *padapter);
27void SwLedOn23a(struct rtw_adapter *padapter, struct led_8723a * pLed);
28void SwLedOff23a(struct rtw_adapter *padapter, struct led_8723a * pLed);
29
30#endif
diff --git a/drivers/staging/rtl8723au/include/rtl8723a_recv.h b/drivers/staging/rtl8723au/include/rtl8723a_recv.h
index 885d4d3859f8..0177bbc1c1cf 100644
--- a/drivers/staging/rtl8723au/include/rtl8723a_recv.h
+++ b/drivers/staging/rtl8723au/include/rtl8723a_recv.h
@@ -28,15 +28,11 @@
28 28
29#define MAX_RECVBUF_SZ 15360 /* 15k < 16k */ 29#define MAX_RECVBUF_SZ 15360 /* 15k < 16k */
30 30
31#define RECV_BULK_IN_ADDR 0x80
32#define RECV_INT_IN_ADDR 0x81
33
34#define PHY_RSSI_SLID_WIN_MAX 100 31#define PHY_RSSI_SLID_WIN_MAX 100
35#define PHY_LINKQUALITY_SLID_WIN_MAX 20 32#define PHY_LINKQUALITY_SLID_WIN_MAX 20
36 33
37 34
38struct phy_stat 35struct phy_stat {
39{
40 unsigned int phydw0; 36 unsigned int phydw0;
41 unsigned int phydw1; 37 unsigned int phydw1;
42 unsigned int phydw2; 38 unsigned int phydw2;
diff --git a/drivers/staging/rtl8723au/include/rtl8723a_xmit.h b/drivers/staging/rtl8723au/include/rtl8723a_xmit.h
index 815560c6e1d7..7db29f40ab70 100644
--- a/drivers/staging/rtl8723au/include/rtl8723a_xmit.h
+++ b/drivers/staging/rtl8723au/include/rtl8723a_xmit.h
@@ -212,7 +212,6 @@ struct txrpt_ccx_8723a {
212#define txrpt_ccx_qtime_8723a(txrpt_ccx) ((txrpt_ccx)->ccx_qtime0+((txrpt_ccx)->ccx_qtime1<<8)) 212#define txrpt_ccx_qtime_8723a(txrpt_ccx) ((txrpt_ccx)->ccx_qtime0+((txrpt_ccx)->ccx_qtime1<<8))
213 213
214void handle_txrpt_ccx_8723a(struct rtw_adapter *adapter, void *buf); 214void handle_txrpt_ccx_8723a(struct rtw_adapter *adapter, void *buf);
215void rtl8723a_update_txdesc(struct xmit_frame *pxmitframe, u8 *pmem);
216void rtl8723a_fill_fake_txdesc(struct rtw_adapter *padapter, u8 *pDesc, u32 BufferLen, u8 IsPsPoll, u8 IsBTQosNull); 215void rtl8723a_fill_fake_txdesc(struct rtw_adapter *padapter, u8 *pDesc, u32 BufferLen, u8 IsPsPoll, u8 IsBTQosNull);
217 216
218int rtl8723au_hal_xmitframe_enqueue(struct rtw_adapter *padapter, struct xmit_frame *pxmitframe); 217int rtl8723au_hal_xmitframe_enqueue(struct rtw_adapter *padapter, struct xmit_frame *pxmitframe);
diff --git a/drivers/staging/rtl8723au/include/rtw_cmd.h b/drivers/staging/rtl8723au/include/rtw_cmd.h
index ef67068a5fe3..71044107d13b 100644
--- a/drivers/staging/rtl8723au/include/rtw_cmd.h
+++ b/drivers/staging/rtl8723au/include/rtw_cmd.h
@@ -17,7 +17,6 @@
17 17
18#include <wlan_bssdef.h> 18#include <wlan_bssdef.h>
19#include <rtw_rf.h> 19#include <rtw_rf.h>
20#include <rtw_led.h>
21 20
22#define C2H_MEM_SZ (16*1024) 21#define C2H_MEM_SZ (16*1024)
23 22
@@ -450,8 +449,7 @@ struct getrfintfs_parm {
450 u8 rfintfs; 449 u8 rfintfs;
451}; 450};
452 451
453struct Tx_Beacon_param 452struct Tx_Beacon_param {
454{
455 struct wlan_bssid_ex network; 453 struct wlan_bssid_ex network;
456}; 454};
457 455
diff --git a/drivers/staging/rtl8723au/include/rtw_ht.h b/drivers/staging/rtl8723au/include/rtw_ht.h
index cfc947daf08b..780eb8944118 100644
--- a/drivers/staging/rtl8723au/include/rtw_ht.h
+++ b/drivers/staging/rtl8723au/include/rtw_ht.h
@@ -19,8 +19,7 @@
19#include "linux/ieee80211.h" 19#include "linux/ieee80211.h"
20#include "wifi.h" 20#include "wifi.h"
21 21
22struct ht_priv 22struct ht_priv {
23{
24 bool ht_option; 23 bool ht_option;
25 bool ampdu_enable;/* for enable Tx A-MPDU */ 24 bool ampdu_enable;/* for enable Tx A-MPDU */
26 /* u8 baddbareq_issued[16]; */ 25 /* u8 baddbareq_issued[16]; */
diff --git a/drivers/staging/rtl8723au/include/rtw_led.h b/drivers/staging/rtl8723au/include/rtw_led.h
deleted file mode 100644
index c071da587efd..000000000000
--- a/drivers/staging/rtl8723au/include/rtw_led.h
+++ /dev/null
@@ -1,181 +0,0 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 ******************************************************************************/
15#ifndef __RTW_LED_H_
16#define __RTW_LED_H_
17
18#include <osdep_service.h>
19#include <drv_types.h>
20
21#define MSECS(t) (HZ * ((t) / 1000) + (HZ * ((t) % 1000)) / 1000)
22
23#define LED_BLINK_NORMAL_INTERVAL 100
24#define LED_BLINK_SLOWLY_INTERVAL 200
25#define LED_BLINK_LONG_INTERVAL 400
26
27#define LED_BLINK_NO_LINK_INTERVAL_ALPHA 1000
28#define LED_BLINK_LINK_INTERVAL_ALPHA 500 /* 500 */
29#define LED_BLINK_SCAN_INTERVAL_ALPHA 180 /* 150 */
30#define LED_BLINK_FASTER_INTERVAL_ALPHA 50
31#define LED_BLINK_WPS_SUCESS_INTERVAL_ALPHA 5000
32
33#define LED_BLINK_NORMAL_INTERVAL_NETTRONIX 100
34#define LED_BLINK_SLOWLY_INTERVAL_NETTRONIX 2000
35
36#define LED_BLINK_SLOWLY_INTERVAL_PORNET 1000
37#define LED_BLINK_NORMAL_INTERVAL_PORNET 100
38
39#define LED_BLINK_FAST_INTERVAL_BITLAND 30
40
41/* 060403, rcnjko: Customized for AzWave. */
42#define LED_CM2_BLINK_ON_INTERVAL 250
43#define LED_CM2_BLINK_OFF_INTERVAL 4750
44
45#define LED_CM8_BLINK_INTERVAL 500 /* for QMI */
46#define LED_CM8_BLINK_OFF_INTERVAL 3750 /* for QMI */
47
48/* 080124, lanhsin: Customized for RunTop */
49#define LED_RunTop_BLINK_INTERVAL 300
50
51/* 060421, rcnjko: Customized for Sercomm Printer Server case. */
52#define LED_CM3_BLINK_INTERVAL 1500
53
54enum led_ctl_mode {
55 LED_CTL_POWER_ON = 1,
56 LED_CTL_LINK = 2,
57 LED_CTL_NO_LINK = 3,
58 LED_CTL_TX = 4,
59 LED_CTL_RX = 5,
60 LED_CTL_SITE_SURVEY = 6,
61 LED_CTL_POWER_OFF = 7,
62 LED_CTL_START_TO_LINK = 8,
63 LED_CTL_START_WPS = 9,
64 LED_CTL_STOP_WPS = 10,
65 LED_CTL_START_WPS_BOTTON = 11, /* added for runtop */
66 LED_CTL_STOP_WPS_FAIL = 12, /* added for ALPHA */
67 LED_CTL_STOP_WPS_FAIL_OVERLAP = 13, /* added for BELKIN */
68 LED_CTL_CONNECTION_NO_TRANSFER = 14,
69};
70
71enum led_state_872x {
72 LED_UNKNOWN = 0,
73 RTW_LED_ON = 1,
74 RTW_LED_OFF = 2,
75 LED_BLINK_NORMAL = 3,
76 LED_BLINK_SLOWLY = 4,
77 LED_BLINK_POWER_ON = 5,
78 LED_BLINK_SCAN = 6, /* LED is blinking during scanning period, the # of times to blink is depend on time for scanning. */
79 LED_BLINK_NO_LINK = 7, /* LED is blinking during no link state. */
80 LED_BLINK_StartToBlink = 8,/* Customzied for Sercomm Printer Server case */
81 LED_BLINK_TXRX = 9,
82 LED_BLINK_WPS = 10, /* LED is blinkg during WPS communication */
83 LED_BLINK_WPS_STOP = 11, /* for ALPHA */
84 LED_BLINK_WPS_STOP_OVERLAP = 12, /* for BELKIN */
85 LED_BLINK_RUNTOP = 13, /* Customized for RunTop */
86 LED_BLINK_CAMEO = 14,
87 LED_BLINK_XAVI = 15,
88 LED_BLINK_ALWAYS_ON = 16,
89};
90
91enum led_pin_8723a {
92 LED_PIN_NULL = 0,
93 LED_PIN_LED0 = 1,
94 LED_PIN_LED1 = 2,
95 LED_PIN_LED2 = 3,
96 LED_PIN_GPIO0 = 4,
97};
98
99struct led_8723a {
100 struct rtw_adapter *padapter;
101
102 enum led_pin_8723a LedPin; /* Identify how to implement this SW led. */
103 enum led_state_872x CurrLedState; /* Current LED state. */
104 enum led_state_872x BlinkingLedState; /* Next state for blinking, either RTW_LED_ON or RTW_LED_OFF are. */
105
106 u8 bLedOn; /* true if LED is ON, false if LED is OFF. */
107
108 u8 bLedBlinkInProgress; /* true if it is blinking, false o.w.. */
109
110 u8 bLedWPSBlinkInProgress;
111
112 u32 BlinkTimes; /* Number of times to toggle led state for blinking. */
113
114 struct timer_list BlinkTimer; /* Timer object for led blinking. */
115
116 u8 bSWLedCtrl;
117
118 /* ALPHA, added by chiyoko, 20090106 */
119 u8 bLedNoLinkBlinkInProgress;
120 u8 bLedLinkBlinkInProgress;
121 u8 bLedStartToLinkBlinkInProgress;
122 u8 bLedScanBlinkInProgress;
123
124 struct work_struct BlinkWorkItem; /* Workitem used by BlinkTimer to manipulate H/W to blink LED. */
125};
126
127#define IS_LED_WPS_BLINKING(_LED_871x) (((struct led_8723a *)_LED_871x)->CurrLedState==LED_BLINK_WPS \
128 || ((struct led_8723a *)_LED_871x)->CurrLedState==LED_BLINK_WPS_STOP \
129 || ((struct led_8723a *)_LED_871x)->bLedWPSBlinkInProgress)
130
131#define IS_LED_BLINKING(_LED_871x) (((struct led_8723a *)_LED_871x)->bLedWPSBlinkInProgress \
132 ||((struct led_8723a *)_LED_871x)->bLedScanBlinkInProgress)
133
134/* */
135/* LED customization. */
136/* */
137
138enum led_strategy_8723a {
139 SW_LED_MODE0 = 0, /* SW control 1 LED via GPIO0. It is default option. */
140 SW_LED_MODE1= 1, /* 2 LEDs, through LED0 and LED1. For ALPHA. */
141 SW_LED_MODE2 = 2, /* SW control 1 LED via GPIO0, customized for AzWave 8187 minicard. */
142 SW_LED_MODE3 = 3, /* SW control 1 LED via GPIO0, customized for Sercomm Printer Server case. */
143 SW_LED_MODE4 = 4, /* for Edimax / Belkin */
144 SW_LED_MODE5 = 5, /* for Sercomm / Belkin */
145 SW_LED_MODE6 = 6, /* for 88CU minicard, porting from ce SW_LED_MODE7 */
146 HW_LED = 50, /* HW control 2 LEDs, LED0 and LED1 (there are 4 different control modes, see MAC.CONFIG1 for details.) */
147 LED_ST_NONE = 99,
148};
149
150void LedControl871x23a(struct rtw_adapter *padapter, enum led_ctl_mode LedAction);
151
152struct led_priv{
153 /* add for led controll */
154 struct led_8723a SwLed0;
155 struct led_8723a SwLed1;
156 enum led_strategy_8723a LedStrategy;
157 u8 bRegUseLed;
158 void (*LedControlHandler)(struct rtw_adapter *padapter, enum led_ctl_mode LedAction);
159 /* add for led controll */
160};
161
162#define rtw_led_control(adapter, LedAction)
163
164void BlinkWorkItemCallback23a(struct work_struct *work);
165
166void ResetLedStatus23a(struct led_8723a *pLed);
167
168void
169InitLed871x23a(
170 struct rtw_adapter *padapter,
171 struct led_8723a *pLed,
172 enum led_pin_8723a LedPin
173);
174
175void
176DeInitLed871x23a(struct led_8723a *pLed);
177
178/* hal... */
179void BlinkHandler23a(struct led_8723a *pLed);
180
181#endif /* __RTW_LED_H_ */
diff --git a/drivers/staging/rtl8723au/include/rtw_mlme.h b/drivers/staging/rtl8723au/include/rtw_mlme.h
index 2ff01eb8fc0c..a6751f138336 100644
--- a/drivers/staging/rtl8723au/include/rtw_mlme.h
+++ b/drivers/staging/rtl8723au/include/rtw_mlme.h
@@ -270,7 +270,7 @@ static inline void _clr_fwstate_(struct mlme_priv *pmlmepriv, int state)
270static inline void clr_fwstate(struct mlme_priv *pmlmepriv, int state) 270static inline void clr_fwstate(struct mlme_priv *pmlmepriv, int state)
271{ 271{
272 spin_lock_bh(&pmlmepriv->lock); 272 spin_lock_bh(&pmlmepriv->lock);
273 if (check_fwstate(pmlmepriv, state) == true) 273 if (check_fwstate(pmlmepriv, state))
274 pmlmepriv->fw_state ^= state; 274 pmlmepriv->fw_state ^= state;
275 spin_unlock_bh(&pmlmepriv->lock); 275 spin_unlock_bh(&pmlmepriv->lock);
276} 276}
diff --git a/drivers/staging/rtl8723au/include/rtw_mlme_ext.h b/drivers/staging/rtl8723au/include/rtw_mlme_ext.h
index 97c3c4478f29..51dba1fa4c5d 100644
--- a/drivers/staging/rtl8723au/include/rtw_mlme_ext.h
+++ b/drivers/staging/rtl8723au/include/rtw_mlme_ext.h
@@ -270,8 +270,7 @@ struct action_handler {
270 int (*func)(struct rtw_adapter *padapter, struct recv_frame *precv_frame); 270 int (*func)(struct rtw_adapter *padapter, struct recv_frame *precv_frame);
271}; 271};
272 272
273struct ss_res 273struct ss_res {
274{
275 int state; 274 int state;
276 int bss_cnt; 275 int bss_cnt;
277 int channel_idx; 276 int channel_idx;
@@ -318,8 +317,7 @@ struct FW_Sta_Info {
318 * 5. ... and so on, till survey done. 317 * 5. ... and so on, till survey done.
319 */ 318 */
320 319
321struct mlme_ext_info 320struct mlme_ext_info {
322{
323 u32 state; 321 u32 state;
324 u32 reauth_count; 322 u32 reauth_count;
325 u32 reassoc_count; 323 u32 reassoc_count;
diff --git a/drivers/staging/rtl8723au/include/rtw_recv.h b/drivers/staging/rtl8723au/include/rtw_recv.h
index f846bb5e7ab7..dc784be3ddd9 100644
--- a/drivers/staging/rtl8723au/include/rtw_recv.h
+++ b/drivers/staging/rtl8723au/include/rtw_recv.h
@@ -200,9 +200,6 @@ struct recv_priv {
200 u8 *precv_buf; 200 u8 *precv_buf;
201 201
202 /* For display the phy informatiom */ 202 /* For display the phy informatiom */
203 u8 is_signal_dbg; /* for debug */
204 u8 signal_strength_dbg; /* for debug */
205 s8 rssi;
206 s8 rxpwdb; 203 s8 rxpwdb;
207 u8 signal_strength; 204 u8 signal_strength;
208 u8 signal_qual; 205 u8 signal_qual;
diff --git a/drivers/staging/rtl8723au/include/rtw_xmit.h b/drivers/staging/rtl8723au/include/rtw_xmit.h
index 32a844170327..2b7d6d08238b 100644
--- a/drivers/staging/rtl8723au/include/rtw_xmit.h
+++ b/drivers/staging/rtl8723au/include/rtw_xmit.h
@@ -196,7 +196,6 @@ enum {
196void rtw_sctx_init23a(struct submit_ctx *sctx, int timeout_ms); 196void rtw_sctx_init23a(struct submit_ctx *sctx, int timeout_ms);
197int rtw_sctx_wait23a(struct submit_ctx *sctx); 197int rtw_sctx_wait23a(struct submit_ctx *sctx);
198void rtw23a_sctx_done_err(struct submit_ctx **sctx, int status); 198void rtw23a_sctx_done_err(struct submit_ctx **sctx, int status);
199void rtw_sctx_done23a(struct submit_ctx **sctx);
200 199
201struct xmit_buf { 200struct xmit_buf {
202 struct list_head list, list2; 201 struct list_head list, list2;
@@ -295,10 +294,6 @@ struct xmit_priv {
295 294
296 struct rtw_adapter *adapter; 295 struct rtw_adapter *adapter;
297 296
298 u8 vcs_setting;
299 u8 vcs;
300 u8 vcs_type;
301
302 u64 tx_bytes; 297 u64 tx_bytes;
303 u64 tx_pkts; 298 u64 tx_pkts;
304 u64 tx_drop; 299 u64 tx_drop;
@@ -307,6 +302,8 @@ struct xmit_priv {
307 302
308 struct hw_xmit *hwxmits; 303 struct hw_xmit *hwxmits;
309 u8 hwxmit_entry; 304 u8 hwxmit_entry;
305 u8 vcs;
306 u8 nqos_ssn;
310 307
311 u8 wmm_para_seq[4];/* sequence for wmm ac parameter strength from 308 u8 wmm_para_seq[4];/* sequence for wmm ac parameter strength from
312 * large to small. it's value is 0->vo, 1->vi, 309 * large to small. it's value is 0->vo, 1->vi,
@@ -314,14 +311,8 @@ struct xmit_priv {
314 */ 311 */
315 312
316 struct semaphore tx_retevt;/* all tx return event; */ 313 struct semaphore tx_retevt;/* all tx return event; */
317 u8 txirp_cnt;/* */
318 314
319 struct tasklet_struct xmit_tasklet; 315 struct tasklet_struct xmit_tasklet;
320 /* per AC pending irp */
321 int beq_cnt;
322 int bkq_cnt;
323 int viq_cnt;
324 int voq_cnt;
325 316
326 struct rtw_queue free_xmitbuf_queue; 317 struct rtw_queue free_xmitbuf_queue;
327 struct list_head xmitbuf_list; /* track buffers for cleanup */ 318 struct list_head xmitbuf_list; /* track buffers for cleanup */
@@ -332,7 +323,6 @@ struct xmit_priv {
332 struct list_head xmitextbuf_list; /* track buffers for cleanup */ 323 struct list_head xmitextbuf_list; /* track buffers for cleanup */
333 uint free_xmit_extbuf_cnt; 324 uint free_xmit_extbuf_cnt;
334 325
335 u16 nqos_ssn;
336 int ack_tx; 326 int ack_tx;
337 struct mutex ack_tx_mutex; 327 struct mutex ack_tx_mutex;
338 struct submit_ctx ack_tx_ops; 328 struct submit_ctx ack_tx_ops;
@@ -349,7 +339,6 @@ s32 rtw_free_xmitbuf23a(struct xmit_priv *pxmitpriv, struct xmit_buf *pxmitbuf);
349void rtw_count_tx_stats23a(struct rtw_adapter *padapter, 339void rtw_count_tx_stats23a(struct rtw_adapter *padapter,
350 struct xmit_frame *pxmitframe, int sz); 340 struct xmit_frame *pxmitframe, int sz);
351void rtw_update_protection23a(struct rtw_adapter *padapter, u8 *ie, uint ie_len); 341void rtw_update_protection23a(struct rtw_adapter *padapter, u8 *ie, uint ie_len);
352s32 rtw_put_snap23a(u8 *data, u16 h_proto);
353struct xmit_frame *rtw_alloc_xmitframe23a_ext(struct xmit_priv *pxmitpriv); 342struct xmit_frame *rtw_alloc_xmitframe23a_ext(struct xmit_priv *pxmitpriv);
354struct xmit_frame *rtw_alloc_xmitframe23a_once(struct xmit_priv *pxmitpriv); 343struct xmit_frame *rtw_alloc_xmitframe23a_once(struct xmit_priv *pxmitpriv);
355s32 rtw_free_xmitframe23a(struct xmit_priv *pxmitpriv, 344s32 rtw_free_xmitframe23a(struct xmit_priv *pxmitpriv,
@@ -363,8 +352,6 @@ struct xmit_frame *rtw_dequeue_xframe23a(struct xmit_priv *pxmitpriv,
363 struct hw_xmit *phwxmit_i, int entry); 352 struct hw_xmit *phwxmit_i, int entry);
364s32 rtw_xmit23a_classifier(struct rtw_adapter *padapter, 353s32 rtw_xmit23a_classifier(struct rtw_adapter *padapter,
365 struct xmit_frame *pxmitframe); 354 struct xmit_frame *pxmitframe);
366u32 rtw_calculate_wlan_pkt_size_by_attribue23a(struct pkt_attrib *pattrib);
367#define rtw_wlan_pkt_size(f) rtw_calculate_wlan_pkt_size_by_attribue23a(&f->attrib)
368s32 rtw_xmitframe_coalesce23a(struct rtw_adapter *padapter, struct sk_buff *pkt, 355s32 rtw_xmitframe_coalesce23a(struct rtw_adapter *padapter, struct sk_buff *pkt,
369 struct xmit_frame *pxmitframe); 356 struct xmit_frame *pxmitframe);
370s32 _rtw_init_hw_txqueue(struct hw_txqueue *phw_txqueue, u8 ac_tag); 357s32 _rtw_init_hw_txqueue(struct hw_txqueue *phw_txqueue, u8 ac_tag);
@@ -391,7 +378,6 @@ void xmit_delivery_enabled_frames23a(struct rtw_adapter *padapter,
391u8 qos_acm23a(u8 acm_mask, u8 priority); 378u8 qos_acm23a(u8 acm_mask, u8 priority);
392u32 rtw_get_ff_hwaddr23a(struct xmit_frame *pxmitframe); 379u32 rtw_get_ff_hwaddr23a(struct xmit_frame *pxmitframe);
393int rtw_ack_tx_wait23a(struct xmit_priv *pxmitpriv, u32 timeout_ms); 380int rtw_ack_tx_wait23a(struct xmit_priv *pxmitpriv, u32 timeout_ms);
394void rtw_ack_tx_done23a(struct xmit_priv *pxmitpriv, int status);
395 381
396/* include after declaring struct xmit_buf, in order to avoid warning */ 382/* include after declaring struct xmit_buf, in order to avoid warning */
397#include <xmit_osdep.h> 383#include <xmit_osdep.h>
diff --git a/drivers/staging/rtl8723au/include/usb_ops.h b/drivers/staging/rtl8723au/include/usb_ops.h
index ade8bc71572a..ff11e13b24a8 100644
--- a/drivers/staging/rtl8723au/include/usb_ops.h
+++ b/drivers/staging/rtl8723au/include/usb_ops.h
@@ -63,6 +63,6 @@ static inline void rtw_reset_continual_urb_error(struct dvobj_priv *dvobj)
63 atomic_set(&dvobj->continual_urb_error, 0); 63 atomic_set(&dvobj->continual_urb_error, 0);
64} 64}
65 65
66void rtl8723au_chip_configure(struct rtw_adapter *padapter); 66bool rtl8723au_chip_configure(struct rtw_adapter *padapter);
67 67
68#endif /* __USB_OPS_H_ */ 68#endif /* __USB_OPS_H_ */
diff --git a/drivers/staging/rtl8723au/include/usb_ops_linux.h b/drivers/staging/rtl8723au/include/usb_ops_linux.h
index bf68bbb41f9c..af2f14b8b360 100644
--- a/drivers/staging/rtl8723au/include/usb_ops_linux.h
+++ b/drivers/staging/rtl8723au/include/usb_ops_linux.h
@@ -21,13 +21,13 @@
21 21
22#define MAX_USBCTRL_VENDORREQ_TIMES 10 22#define MAX_USBCTRL_VENDORREQ_TIMES 10
23 23
24int rtl8723au_read_port(struct rtw_adapter *adapter, u32 addr, u32 cnt, 24int rtl8723au_read_port(struct rtw_adapter *adapter, u32 cnt,
25 struct recv_buf *precvbuf); 25 struct recv_buf *precvbuf);
26void rtl8723au_read_port_cancel(struct rtw_adapter *padapter); 26void rtl8723au_read_port_cancel(struct rtw_adapter *padapter);
27int rtl8723au_write_port(struct rtw_adapter *padapter, u32 addr, u32 cnt, 27int rtl8723au_write_port(struct rtw_adapter *padapter, u32 addr, u32 cnt,
28 struct xmit_buf *pxmitbuf); 28 struct xmit_buf *pxmitbuf);
29void rtl8723au_write_port_cancel(struct rtw_adapter *padapter); 29void rtl8723au_write_port_cancel(struct rtw_adapter *padapter);
30int rtl8723au_read_interrupt(struct rtw_adapter *adapter, u32 addr); 30int rtl8723au_read_interrupt(struct rtw_adapter *adapter);
31 31
32u8 rtl8723au_read8(struct rtw_adapter *padapter, u16 addr); 32u8 rtl8723au_read8(struct rtw_adapter *padapter, u16 addr);
33u16 rtl8723au_read16(struct rtw_adapter *padapter, u16 addr); 33u16 rtl8723au_read16(struct rtw_adapter *padapter, u16 addr);
diff --git a/drivers/staging/rtl8723au/include/wlan_bssdef.h b/drivers/staging/rtl8723au/include/wlan_bssdef.h
index 96e8074a7c18..95b32e15a4d0 100644
--- a/drivers/staging/rtl8723au/include/wlan_bssdef.h
+++ b/drivers/staging/rtl8723au/include/wlan_bssdef.h
@@ -57,23 +57,6 @@ enum {
57 Ndis802_11Encryption3KeyAbsent, 57 Ndis802_11Encryption3KeyAbsent,
58}; 58};
59 59
60/* Key mapping keys require a BSSID */
61struct ndis_802_11_key {
62 u32 Length; /* Length of this structure */
63 u32 KeyIndex;
64 u32 KeyLength; /* length of key in bytes */
65 unsigned char BSSID[6];
66 unsigned long long KeyRSC;
67 u8 KeyMaterial[32]; /* variable length depending on above field */
68};
69
70struct wlan_phy_info {
71 u8 SignalStrength;/* in percentage) */
72 u8 SignalQuality;/* in percentage) */
73 u8 Optimum_antenna; /* for Antenna diversity */
74 u8 Reserved_0;
75};
76
77struct wlan_bcn_info { 60struct wlan_bcn_info {
78 /* these infor get from rtw_get_encrypt_info when 61 /* these infor get from rtw_get_encrypt_info when
79 * * translate scan to UI */ 62 * * translate scan to UI */
@@ -99,7 +82,8 @@ struct wlan_bssid_ex {
99 u32 DSConfig; /* Frequency, units are kHz */ 82 u32 DSConfig; /* Frequency, units are kHz */
100 enum nl80211_iftype ifmode; 83 enum nl80211_iftype ifmode;
101 unsigned char SupportedRates[NDIS_802_11_LENGTH_RATES_EX]; 84 unsigned char SupportedRates[NDIS_802_11_LENGTH_RATES_EX];
102 struct wlan_phy_info PhyInfo; 85 u8 SignalStrength;/* in percentage */
86 u8 SignalQuality;/* in percentage */
103 u32 IELength; 87 u32 IELength;
104 u8 IEs[MAX_IE_SZ]; /* timestamp, beacon interval, and capability info*/ 88 u8 IEs[MAX_IE_SZ]; /* timestamp, beacon interval, and capability info*/
105} __packed; 89} __packed;
@@ -115,7 +99,6 @@ struct wlan_network {
115 /* set to fixed when not to be removed as site-surveying */ 99 /* set to fixed when not to be removed as site-surveying */
116 int fixed; 100 int fixed;
117 unsigned long last_scanned; /* timestamp for the network */ 101 unsigned long last_scanned; /* timestamp for the network */
118 int aid; /* will only be valid when a BSS is joined. */
119 int join_res; 102 int join_res;
120 struct wlan_bssid_ex network; /* must be the last item */ 103 struct wlan_bssid_ex network; /* must be the last item */
121 struct wlan_bcn_info BcnInfo; 104 struct wlan_bcn_info BcnInfo;
diff --git a/drivers/staging/rtl8723au/os_dep/ioctl_cfg80211.c b/drivers/staging/rtl8723au/os_dep/ioctl_cfg80211.c
index 3d26955da724..82a8c06ab347 100644
--- a/drivers/staging/rtl8723au/os_dep/ioctl_cfg80211.c
+++ b/drivers/staging/rtl8723au/os_dep/ioctl_cfg80211.c
@@ -275,7 +275,8 @@ static int rtw_cfg80211_inform_bss(struct rtw_adapter *padapter,
275 &pnetwork->network)) { 275 &pnetwork->network)) {
276 notify_signal = 100 * translate_percentage_to_dbm(padapter->recvpriv.signal_strength); /* dbm */ 276 notify_signal = 100 * translate_percentage_to_dbm(padapter->recvpriv.signal_strength); /* dbm */
277 } else { 277 } else {
278 notify_signal = 100 * translate_percentage_to_dbm(pnetwork->network.PhyInfo.SignalStrength); /* dbm */ 278 notify_signal = 100 * translate_percentage_to_dbm(
279 pnetwork->network.SignalStrength); /* dbm */
279 } 280 }
280 281
281 bss = cfg80211_inform_bss(wiphy, notify_channel, 282 bss = cfg80211_inform_bss(wiphy, notify_channel,
@@ -471,7 +472,6 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, u8 key_index,
471 int set_tx, const u8 *sta_addr, 472 int set_tx, const u8 *sta_addr,
472 struct key_params *keyparms) 473 struct key_params *keyparms)
473{ 474{
474 int ret = 0;
475 int key_len; 475 int key_len;
476 struct sta_info *psta = NULL, *pbcmc_sta = NULL; 476 struct sta_info *psta = NULL, *pbcmc_sta = NULL;
477 struct rtw_adapter *padapter = netdev_priv(dev); 477 struct rtw_adapter *padapter = netdev_priv(dev);
@@ -708,7 +708,7 @@ static int rtw_cfg80211_ap_set_encryption(struct net_device *dev, u8 key_index,
708 708
709exit: 709exit:
710 710
711 return ret; 711 return 0;
712} 712}
713#endif 713#endif
714 714
@@ -850,7 +850,6 @@ static int rtw_cfg80211_set_encryption(struct net_device *dev, u8 key_index,
850 dot11PrivacyAlgrthm; 850 dot11PrivacyAlgrthm;
851 } 851 }
852 } 852 }
853 } else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) { /* adhoc mode */
854 } 853 }
855 } 854 }
856 855
@@ -2364,7 +2363,6 @@ void rtw_cfg80211_indicate_sta_assoc(struct rtw_adapter *padapter,
2364 ie_offset = offsetof(struct ieee80211_mgmt, 2363 ie_offset = offsetof(struct ieee80211_mgmt,
2365 u.reassoc_req.variable); 2364 u.reassoc_req.variable);
2366 2365
2367 sinfo.filled = 0;
2368 sinfo.filled = STATION_INFO_ASSOC_REQ_IES; 2366 sinfo.filled = STATION_INFO_ASSOC_REQ_IES;
2369 sinfo.assoc_req_ies = pmgmt_frame + ie_offset; 2367 sinfo.assoc_req_ies = pmgmt_frame + ie_offset;
2370 sinfo.assoc_req_ies_len = frame_len - ie_offset; 2368 sinfo.assoc_req_ies_len = frame_len - ie_offset;
@@ -2432,20 +2430,16 @@ void rtw_cfg80211_indicate_sta_disassoc(struct rtw_adapter *padapter,
2432 2430
2433static int rtw_cfg80211_monitor_if_open(struct net_device *ndev) 2431static int rtw_cfg80211_monitor_if_open(struct net_device *ndev)
2434{ 2432{
2435 int ret = 0;
2436
2437 DBG_8723A("%s\n", __func__); 2433 DBG_8723A("%s\n", __func__);
2438 2434
2439 return ret; 2435 return 0;
2440} 2436}
2441 2437
2442static int rtw_cfg80211_monitor_if_close(struct net_device *ndev) 2438static int rtw_cfg80211_monitor_if_close(struct net_device *ndev)
2443{ 2439{
2444 int ret = 0;
2445
2446 DBG_8723A("%s\n", __func__); 2440 DBG_8723A("%s\n", __func__);
2447 2441
2448 return ret; 2442 return 0;
2449} 2443}
2450 2444
2451static int rtw_cfg80211_monitor_if_xmit_entry(struct sk_buff *skb, 2445static int rtw_cfg80211_monitor_if_xmit_entry(struct sk_buff *skb,
@@ -2574,11 +2568,9 @@ fail:
2574static int 2568static int
2575rtw_cfg80211_monitor_if_set_mac_address(struct net_device *ndev, void *addr) 2569rtw_cfg80211_monitor_if_set_mac_address(struct net_device *ndev, void *addr)
2576{ 2570{
2577 int ret = 0;
2578
2579 DBG_8723A("%s\n", __func__); 2571 DBG_8723A("%s\n", __func__);
2580 2572
2581 return ret; 2573 return 0;
2582} 2574}
2583 2575
2584static const struct net_device_ops rtw_cfg80211_monitor_if_ops = { 2576static const struct net_device_ops rtw_cfg80211_monitor_if_ops = {
diff --git a/drivers/staging/rtl8723au/os_dep/os_intfs.c b/drivers/staging/rtl8723au/os_dep/os_intfs.c
index b34eaec9dd48..9966d16342b3 100644
--- a/drivers/staging/rtl8723au/os_dep/os_intfs.c
+++ b/drivers/staging/rtl8723au/os_dep/os_intfs.c
@@ -175,7 +175,6 @@ static int netdev_close(struct net_device *pnetdev);
175static int loadparam(struct rtw_adapter *padapter, struct net_device *pnetdev) 175static int loadparam(struct rtw_adapter *padapter, struct net_device *pnetdev)
176{ 176{
177 struct registry_priv *registry_par = &padapter->registrypriv; 177 struct registry_priv *registry_par = &padapter->registrypriv;
178 int status = _SUCCESS;
179 178
180 GlobalDebugLevel23A = rtw_debug; 179 GlobalDebugLevel23A = rtw_debug;
181 registry_par->chip_version = (u8)rtw_chip_version; 180 registry_par->chip_version = (u8)rtw_chip_version;
@@ -234,7 +233,7 @@ static int loadparam(struct rtw_adapter *padapter, struct net_device *pnetdev)
234 snprintf(registry_par->if2name, 16, "%s", if2name); 233 snprintf(registry_par->if2name, 16, "%s", if2name);
235 registry_par->notch_filter = (u8)rtw_notch_filter; 234 registry_par->notch_filter = (u8)rtw_notch_filter;
236 registry_par->regulatory_tid = (u8)rtw_regulatory_id; 235 registry_par->regulatory_tid = (u8)rtw_regulatory_id;
237 return status; 236 return _SUCCESS;
238} 237}
239 238
240static int rtw_net_set_mac_address(struct net_device *pnetdev, void *p) 239static int rtw_net_set_mac_address(struct net_device *pnetdev, void *p)
@@ -384,12 +383,9 @@ static int rtw_init_default_value(struct rtw_adapter *padapter)
384 struct xmit_priv *pxmitpriv = &padapter->xmitpriv; 383 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
385 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 384 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
386 struct security_priv *psecuritypriv = &padapter->securitypriv; 385 struct security_priv *psecuritypriv = &padapter->securitypriv;
387 int ret = _SUCCESS;
388 386
389 /* xmit_priv */ 387 /* xmit_priv */
390 pxmitpriv->vcs_setting = pregistrypriv->vrtl_carrier_sense;
391 pxmitpriv->vcs = pregistrypriv->vcs_type; 388 pxmitpriv->vcs = pregistrypriv->vcs_type;
392 pxmitpriv->vcs_type = pregistrypriv->vcs_type;
393 /* pxmitpriv->rts_thresh = pregistrypriv->rts_thresh; */ 389 /* pxmitpriv->rts_thresh = pregistrypriv->rts_thresh; */
394 pxmitpriv->frag_len = pregistrypriv->frag_thresh; 390 pxmitpriv->frag_len = pregistrypriv->frag_thresh;
395 391
@@ -425,7 +421,7 @@ static int rtw_init_default_value(struct rtw_adapter *padapter)
425 /* misc. */ 421 /* misc. */
426 padapter->bReadPortCancel = false; 422 padapter->bReadPortCancel = false;
427 padapter->bWritePortCancel = false; 423 padapter->bWritePortCancel = false;
428 return ret; 424 return _SUCCESS;
429} 425}
430 426
431int rtw_reset_drv_sw23a(struct rtw_adapter *padapter) 427int rtw_reset_drv_sw23a(struct rtw_adapter *padapter)
@@ -546,9 +542,6 @@ void rtw_cancel_all_timer23a(struct rtw_adapter *padapter)
546 RT_TRACE(_module_os_intfs_c_, _drv_info_, 542 RT_TRACE(_module_os_intfs_c_, _drv_info_,
547 ("%s:cancel dynamic_chk_timer!\n", __func__)); 543 ("%s:cancel dynamic_chk_timer!\n", __func__));
548 544
549 RT_TRACE(_module_os_intfs_c_, _drv_info_,
550 ("%s:cancel DeInitSwLeds!\n", __func__));
551
552 del_timer_sync(&padapter->pwrctrlpriv.pwr_state_check_timer); 545 del_timer_sync(&padapter->pwrctrlpriv.pwr_state_check_timer);
553 546
554 del_timer_sync(&padapter->mlmepriv.set_scan_deny_timer); 547 del_timer_sync(&padapter->mlmepriv.set_scan_deny_timer);
@@ -685,8 +678,6 @@ int netdev_open23a(struct net_device *pnetdev)
685 678
686 rtw_cfg80211_init_wiphy(padapter); 679 rtw_cfg80211_init_wiphy(padapter);
687 680
688 rtw_led_control(padapter, LED_CTL_NO_LINK);
689
690 padapter->bup = true; 681 padapter->bup = true;
691 } 682 }
692 padapter->net_closed = false; 683 padapter->net_closed = false;
@@ -768,8 +759,6 @@ int rtw_ips_pwr_up23a(struct rtw_adapter *padapter)
768 759
769 result = ips_netdrv_open(padapter); 760 result = ips_netdrv_open(padapter);
770 761
771 rtw_led_control(padapter, LED_CTL_NO_LINK);
772
773 DBG_8723A("<=== rtw_ips_pwr_up23a.............. in %dms\n", 762 DBG_8723A("<=== rtw_ips_pwr_up23a.............. in %dms\n",
774 jiffies_to_msecs(jiffies - start_time)); 763 jiffies_to_msecs(jiffies - start_time));
775 return result; 764 return result;
@@ -784,8 +773,6 @@ void rtw_ips_pwr_down23a(struct rtw_adapter *padapter)
784 padapter->bCardDisableWOHSM = true; 773 padapter->bCardDisableWOHSM = true;
785 padapter->net_closed = true; 774 padapter->net_closed = true;
786 775
787 rtw_led_control(padapter, LED_CTL_POWER_OFF);
788
789 rtw_ips_dev_unload23a(padapter); 776 rtw_ips_dev_unload23a(padapter);
790 padapter->bCardDisableWOHSM = false; 777 padapter->bCardDisableWOHSM = false;
791 DBG_8723A("<=== rtw_ips_pwr_down23a..................... in %dms\n", 778 DBG_8723A("<=== rtw_ips_pwr_down23a..................... in %dms\n",
@@ -844,8 +831,6 @@ static int netdev_close(struct net_device *pnetdev)
844 rtw_free_assoc_resources23a(padapter, 1); 831 rtw_free_assoc_resources23a(padapter, 1);
845 /* s2-4. */ 832 /* s2-4. */
846 rtw_free_network_queue23a(padapter); 833 rtw_free_network_queue23a(padapter);
847 /* Close LED */
848 rtw_led_control(padapter, LED_CTL_POWER_OFF);
849 } 834 }
850 835
851 rtw_scan_abort23a(padapter); 836 rtw_scan_abort23a(padapter);
diff --git a/drivers/staging/rtl8723au/os_dep/usb_intf.c b/drivers/staging/rtl8723au/os_dep/usb_intf.c
index 865743ecd855..373a617ace54 100644
--- a/drivers/staging/rtl8723au/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8723au/os_dep/usb_intf.c
@@ -59,21 +59,6 @@ static struct usb_driver rtl8723a_usb_drv = {
59 59
60static struct usb_driver *usb_drv = &rtl8723a_usb_drv; 60static struct usb_driver *usb_drv = &rtl8723a_usb_drv;
61 61
62static inline int RT_usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor *epd)
63{
64 return usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_in(epd);
65}
66
67static inline int RT_usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor *epd)
68{
69 return usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_out(epd);
70}
71
72static inline int RT_usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *epd)
73{
74 return usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd);
75}
76
77static int rtw_init_intf_priv(struct dvobj_priv *dvobj) 62static int rtw_init_intf_priv(struct dvobj_priv *dvobj)
78{ 63{
79 mutex_init(&dvobj->usb_vendor_req_mutex); 64 mutex_init(&dvobj->usb_vendor_req_mutex);
@@ -143,21 +128,21 @@ static struct dvobj_priv *usb_dvobj_init(struct usb_interface *usb_intf)
143 le16_to_cpu(pendp_desc->wMaxPacketSize)); 128 le16_to_cpu(pendp_desc->wMaxPacketSize));
144 DBG_8723A("bInterval =%x\n", pendp_desc->bInterval); 129 DBG_8723A("bInterval =%x\n", pendp_desc->bInterval);
145 130
146 if (RT_usb_endpoint_is_bulk_in(pendp_desc)) { 131 if (usb_endpoint_is_bulk_in(pendp_desc)) {
147 DBG_8723A("RT_usb_endpoint_is_bulk_in = %x\n", 132 DBG_8723A("usb_endpoint_is_bulk_in = %x\n",
148 usb_endpoint_num(pendp_desc)); 133 usb_endpoint_num(pendp_desc));
149 pdvobjpriv->RtInPipe[pdvobjpriv->RtNumInPipes] = 134 pdvobjpriv->RtInPipe[pdvobjpriv->RtNumInPipes] =
150 usb_endpoint_num(pendp_desc); 135 usb_endpoint_num(pendp_desc);
151 pdvobjpriv->RtNumInPipes++; 136 pdvobjpriv->RtNumInPipes++;
152 } else if (RT_usb_endpoint_is_int_in(pendp_desc)) { 137 } else if (usb_endpoint_is_int_in(pendp_desc)) {
153 DBG_8723A("RT_usb_endpoint_is_int_in = %x, Interval = %x\n", 138 DBG_8723A("usb_endpoint_is_int_in = %x, Interval = %x\n",
154 usb_endpoint_num(pendp_desc), 139 usb_endpoint_num(pendp_desc),
155 pendp_desc->bInterval); 140 pendp_desc->bInterval);
156 pdvobjpriv->RtInPipe[pdvobjpriv->RtNumInPipes] = 141 pdvobjpriv->RtInPipe[pdvobjpriv->RtNumInPipes] =
157 usb_endpoint_num(pendp_desc); 142 usb_endpoint_num(pendp_desc);
158 pdvobjpriv->RtNumInPipes++; 143 pdvobjpriv->RtNumInPipes++;
159 } else if (RT_usb_endpoint_is_bulk_out(pendp_desc)) { 144 } else if (usb_endpoint_is_bulk_out(pendp_desc)) {
160 DBG_8723A("RT_usb_endpoint_is_bulk_out = %x\n", 145 DBG_8723A("usb_endpoint_is_bulk_out = %x\n",
161 usb_endpoint_num(pendp_desc)); 146 usb_endpoint_num(pendp_desc));
162 pdvobjpriv->RtOutPipe[pdvobjpriv->RtNumOutPipes] = 147 pdvobjpriv->RtOutPipe[pdvobjpriv->RtNumOutPipes] =
163 usb_endpoint_num(pendp_desc); 148 usb_endpoint_num(pendp_desc);
@@ -257,6 +242,7 @@ void rtl8723a_usb_intf_stop(struct rtw_adapter *padapter)
257 242
258static void rtw_dev_unload(struct rtw_adapter *padapter) 243static void rtw_dev_unload(struct rtw_adapter *padapter)
259{ 244{
245 struct submit_ctx *pack_tx_ops = &padapter->xmitpriv.ack_tx_ops;
260 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+rtw_dev_unload\n")); 246 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+rtw_dev_unload\n"));
261 247
262 if (padapter->bup) { 248 if (padapter->bup) {
@@ -264,8 +250,8 @@ static void rtw_dev_unload(struct rtw_adapter *padapter)
264 250
265 padapter->bDriverStopped = true; 251 padapter->bDriverStopped = true;
266 if (padapter->xmitpriv.ack_tx) 252 if (padapter->xmitpriv.ack_tx)
267 rtw_ack_tx_done23a(&padapter->xmitpriv, 253 rtw23a_sctx_done_err(&pack_tx_ops,
268 RTW_SCTX_DONE_DRV_STOP); 254 RTW_SCTX_DONE_DRV_STOP);
269 255
270 /* s3. */ 256 /* s3. */
271 rtl8723a_usb_intf_stop(padapter); 257 rtl8723a_usb_intf_stop(padapter);
@@ -322,8 +308,6 @@ int rtw_hw_suspend23a(struct rtw_adapter *padapter)
322 if (check_fwstate(pmlmepriv, _FW_LINKED)) { 308 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
323 _clr_fwstate_(pmlmepriv, _FW_LINKED); 309 _clr_fwstate_(pmlmepriv, _FW_LINKED);
324 310
325 rtw_led_control(padapter, LED_CTL_NO_LINK);
326
327 rtw_os_indicate_disconnect23a(padapter); 311 rtw_os_indicate_disconnect23a(padapter);
328 312
329 /* donnot enqueue cmd */ 313 /* donnot enqueue cmd */
@@ -546,7 +530,8 @@ static struct rtw_adapter *rtw_usb_if1_init(struct dvobj_priv *dvobj,
546 rtl8723a_read_chip_version(padapter); 530 rtl8723a_read_chip_version(padapter);
547 531
548 /* step usb endpoint mapping */ 532 /* step usb endpoint mapping */
549 rtl8723au_chip_configure(padapter); 533 if (!rtl8723au_chip_configure(padapter))
534 goto free_hal_data;
550 535
551 /* step read efuse/eeprom data and get mac_addr */ 536 /* step read efuse/eeprom data and get mac_addr */
552 rtl8723a_read_adapter_info(padapter); 537 rtl8723a_read_adapter_info(padapter);
diff --git a/drivers/staging/rtl8723au/os_dep/usb_ops_linux.c b/drivers/staging/rtl8723au/os_dep/usb_ops_linux.c
index a3349ac57bae..3e19b3b2c1c2 100644
--- a/drivers/staging/rtl8723au/os_dep/usb_ops_linux.c
+++ b/drivers/staging/rtl8723au/os_dep/usb_ops_linux.c
@@ -18,13 +18,6 @@
18#include <usb_ops_linux.h> 18#include <usb_ops_linux.h>
19#include <rtw_sreset.h> 19#include <rtw_sreset.h>
20 20
21struct zero_bulkout_context {
22 void *pbuf;
23 void *purb;
24 void *pirp;
25 void *padapter;
26};
27
28void rtl8723au_read_port_cancel(struct rtw_adapter *padapter) 21void rtl8723au_read_port_cancel(struct rtw_adapter *padapter)
29{ 22{
30 struct recv_buf *precvbuf; 23 struct recv_buf *precvbuf;
@@ -53,18 +46,6 @@ static void usb_write_port23a_complete(struct urb *purb)
53 unsigned long irqL; 46 unsigned long irqL;
54 47
55 switch (pxmitbuf->flags) { 48 switch (pxmitbuf->flags) {
56 case VO_QUEUE_INX:
57 pxmitpriv->voq_cnt--;
58 break;
59 case VI_QUEUE_INX:
60 pxmitpriv->viq_cnt--;
61 break;
62 case BE_QUEUE_INX:
63 pxmitpriv->beq_cnt--;
64 break;
65 case BK_QUEUE_INX:
66 pxmitpriv->bkq_cnt--;
67 break;
68 case HIGH_QUEUE_INX: 49 case HIGH_QUEUE_INX:
69#ifdef CONFIG_8723AU_AP_MODE 50#ifdef CONFIG_8723AU_AP_MODE
70 rtw_chk_hi_queue_cmd23a(padapter); 51 rtw_chk_hi_queue_cmd23a(padapter);
@@ -166,19 +147,15 @@ int rtl8723au_write_port(struct rtw_adapter *padapter, u32 addr, u32 cnt,
166 147
167 switch (addr) { 148 switch (addr) {
168 case VO_QUEUE_INX: 149 case VO_QUEUE_INX:
169 pxmitpriv->voq_cnt++;
170 pxmitbuf->flags = VO_QUEUE_INX; 150 pxmitbuf->flags = VO_QUEUE_INX;
171 break; 151 break;
172 case VI_QUEUE_INX: 152 case VI_QUEUE_INX:
173 pxmitpriv->viq_cnt++;
174 pxmitbuf->flags = VI_QUEUE_INX; 153 pxmitbuf->flags = VI_QUEUE_INX;
175 break; 154 break;
176 case BE_QUEUE_INX: 155 case BE_QUEUE_INX:
177 pxmitpriv->beq_cnt++;
178 pxmitbuf->flags = BE_QUEUE_INX; 156 pxmitbuf->flags = BE_QUEUE_INX;
179 break; 157 break;
180 case BK_QUEUE_INX: 158 case BK_QUEUE_INX:
181 pxmitpriv->bkq_cnt++;
182 pxmitbuf->flags = BK_QUEUE_INX; 159 pxmitbuf->flags = BK_QUEUE_INX;
183 break; 160 break;
184 case HIGH_QUEUE_INX: 161 case HIGH_QUEUE_INX:
diff --git a/drivers/staging/rts5208/ms.c b/drivers/staging/rts5208/ms.c
index 228e48339b9e..b4612fb615f6 100644
--- a/drivers/staging/rts5208/ms.c
+++ b/drivers/staging/rts5208/ms.c
@@ -2599,9 +2599,9 @@ static int mspro_rw_multi_sector(struct scsi_cmnd *srb,
2599 2599
2600 if (count > sector_cnt) { 2600 if (count > sector_cnt) {
2601 if (mode_2k) 2601 if (mode_2k)
2602 ms_card->seq_mode |= MODE_2K_SEQ; 2602 ms_card->seq_mode = MODE_2K_SEQ;
2603 else 2603 else
2604 ms_card->seq_mode |= MODE_512_SEQ; 2604 ms_card->seq_mode = MODE_512_SEQ;
2605 } 2605 }
2606 } else { 2606 } else {
2607 count = sector_cnt; 2607 count = sector_cnt;
diff --git a/drivers/staging/rts5208/rtsx.c b/drivers/staging/rts5208/rtsx.c
index 2d2527c3aea2..c74f1b8108f6 100644
--- a/drivers/staging/rts5208/rtsx.c
+++ b/drivers/staging/rts5208/rtsx.c
@@ -418,7 +418,7 @@ static void rtsx_shutdown(struct pci_dev *pci)
418 418
419static int rtsx_control_thread(void *__dev) 419static int rtsx_control_thread(void *__dev)
420{ 420{
421 struct rtsx_dev *dev = (struct rtsx_dev *)__dev; 421 struct rtsx_dev *dev = __dev;
422 struct rtsx_chip *chip = dev->chip; 422 struct rtsx_chip *chip = dev->chip;
423 struct Scsi_Host *host = rtsx_to_host(dev); 423 struct Scsi_Host *host = rtsx_to_host(dev);
424 424
@@ -527,7 +527,7 @@ SkipForAbort:
527 527
528static int rtsx_polling_thread(void *__dev) 528static int rtsx_polling_thread(void *__dev)
529{ 529{
530 struct rtsx_dev *dev = (struct rtsx_dev *)__dev; 530 struct rtsx_dev *dev = __dev;
531 struct rtsx_chip *chip = dev->chip; 531 struct rtsx_chip *chip = dev->chip;
532 struct sd_info *sd_card = &(chip->sd_card); 532 struct sd_info *sd_card = &(chip->sd_card);
533 struct xd_info *xd_card = &(chip->xd_card); 533 struct xd_info *xd_card = &(chip->xd_card);
diff --git a/drivers/staging/rts5208/rtsx_chip.c b/drivers/staging/rts5208/rtsx_chip.c
index a7ade8b4e7f2..9593d8132938 100644
--- a/drivers/staging/rts5208/rtsx_chip.c
+++ b/drivers/staging/rts5208/rtsx_chip.c
@@ -126,10 +126,11 @@ static int rtsx_pre_handle_sdio_old(struct rtsx_chip *chip)
126 if (chip->ignore_sd && CHK_SDIO_EXIST(chip)) { 126 if (chip->ignore_sd && CHK_SDIO_EXIST(chip)) {
127 if (chip->asic_code) { 127 if (chip->asic_code) {
128 RTSX_WRITE_REG(chip, CARD_PULL_CTL5, 0xFF, 128 RTSX_WRITE_REG(chip, CARD_PULL_CTL5, 0xFF,
129 MS_INS_PU | SD_WP_PU | SD_CD_PU | SD_CMD_PU); 129 MS_INS_PU | SD_WP_PU |
130 SD_CD_PU | SD_CMD_PU);
130 } else { 131 } else {
131 RTSX_WRITE_REG(chip, FPGA_PULL_CTL, 0xFF, 132 RTSX_WRITE_REG(chip, FPGA_PULL_CTL, 0xFF,
132 FPGA_SD_PULL_CTL_EN); 133 FPGA_SD_PULL_CTL_EN);
133 } 134 }
134 RTSX_WRITE_REG(chip, CARD_SHARE_MODE, 0xFF, CARD_SHARE_48_SD); 135 RTSX_WRITE_REG(chip, CARD_SHARE_MODE, 0xFF, CARD_SHARE_48_SD);
135 136
@@ -137,7 +138,7 @@ static int rtsx_pre_handle_sdio_old(struct rtsx_chip *chip)
137 RTSX_WRITE_REG(chip, 0xFF2C, 0x01, 0x01); 138 RTSX_WRITE_REG(chip, 0xFF2C, 0x01, 0x01);
138 139
139 RTSX_WRITE_REG(chip, SDIO_CTRL, 0xFF, 140 RTSX_WRITE_REG(chip, SDIO_CTRL, 0xFF,
140 SDIO_BUS_CTRL | SDIO_CD_CTRL); 141 SDIO_BUS_CTRL | SDIO_CD_CTRL);
141 142
142 chip->sd_int = 1; 143 chip->sd_int = 1;
143 chip->sd_io = 1; 144 chip->sd_io = 1;
@@ -201,7 +202,7 @@ static int rtsx_pre_handle_sdio_new(struct rtsx_chip *chip)
201 TRACE_RET(chip, STATUS_FAIL); 202 TRACE_RET(chip, STATUS_FAIL);
202 } else { 203 } else {
203 RTSX_WRITE_REG(chip, FPGA_PULL_CTL, 204 RTSX_WRITE_REG(chip, FPGA_PULL_CTL,
204 FPGA_SD_PULL_CTL_BIT | 0x20, 0); 205 FPGA_SD_PULL_CTL_BIT | 0x20, 0);
205 } 206 }
206 retval = card_share_mode(chip, SD_CARD); 207 retval = card_share_mode(chip, SD_CARD);
207 if (retval != STATUS_SUCCESS) 208 if (retval != STATUS_SUCCESS)
@@ -226,6 +227,87 @@ static int rtsx_pre_handle_sdio_new(struct rtsx_chip *chip)
226} 227}
227#endif 228#endif
228 229
230static int rtsx_reset_aspm(struct rtsx_chip *chip)
231{
232 int ret;
233
234 if (chip->dynamic_aspm) {
235 if (!CHK_SDIO_EXIST(chip) || !CHECK_PID(chip, 0x5288))
236 return STATUS_SUCCESS;
237
238 ret = rtsx_write_cfg_dw(chip, 2, 0xC0, 0xFF,
239 chip->aspm_l0s_l1_en);
240 if (ret != STATUS_SUCCESS)
241 TRACE_RET(chip, STATUS_FAIL);
242
243 return STATUS_SUCCESS;
244 }
245
246 if (CHECK_PID(chip, 0x5208))
247 RTSX_WRITE_REG(chip, ASPM_FORCE_CTL, 0xFF, 0x3F);
248 ret = rtsx_write_config_byte(chip, LCTLR, chip->aspm_l0s_l1_en);
249 if (ret != STATUS_SUCCESS)
250 TRACE_RET(chip, STATUS_FAIL);
251
252 chip->aspm_level[0] = chip->aspm_l0s_l1_en;
253 if (CHK_SDIO_EXIST(chip)) {
254 chip->aspm_level[1] = chip->aspm_l0s_l1_en;
255 ret = rtsx_write_cfg_dw(chip, CHECK_PID(chip, 0x5288) ? 2 : 1,
256 0xC0, 0xFF, chip->aspm_l0s_l1_en);
257 if (ret != STATUS_SUCCESS)
258 TRACE_RET(chip, STATUS_FAIL);
259 }
260
261 chip->aspm_enabled = 1;
262
263 return STATUS_SUCCESS;
264}
265
266static int rtsx_enable_pcie_intr(struct rtsx_chip *chip)
267{
268 int ret;
269
270 if (!chip->asic_code || !CHECK_PID(chip, 0x5208)) {
271 rtsx_enable_bus_int(chip);
272 return STATUS_SUCCESS;
273 }
274
275 if (chip->phy_debug_mode) {
276 RTSX_WRITE_REG(chip, CDRESUMECTL, 0x77, 0);
277 rtsx_disable_bus_int(chip);
278 } else {
279 rtsx_enable_bus_int(chip);
280 }
281
282 if (chip->ic_version >= IC_VER_D) {
283 u16 reg;
284
285 ret = rtsx_read_phy_register(chip, 0x00, &reg);
286 if (ret != STATUS_SUCCESS)
287 TRACE_RET(chip, STATUS_FAIL);
288
289 reg &= 0xFE7F;
290 reg |= 0x80;
291 ret = rtsx_write_phy_register(chip, 0x00, reg);
292 if (ret != STATUS_SUCCESS)
293 TRACE_RET(chip, STATUS_FAIL);
294
295 ret = rtsx_read_phy_register(chip, 0x1C, &reg);
296 if (ret != STATUS_SUCCESS)
297 TRACE_RET(chip, STATUS_FAIL);
298
299 reg &= 0xFFF7;
300 ret = rtsx_write_phy_register(chip, 0x1C, reg);
301 if (ret != STATUS_SUCCESS)
302 TRACE_RET(chip, STATUS_FAIL);
303 }
304
305 if (chip->driver_first_load && (chip->ic_version < IC_VER_C))
306 rtsx_calibration(chip);
307
308 return STATUS_SUCCESS;
309}
310
229int rtsx_reset_chip(struct rtsx_chip *chip) 311int rtsx_reset_chip(struct rtsx_chip *chip)
230{ 312{
231 int retval; 313 int retval;
@@ -268,7 +350,7 @@ int rtsx_reset_chip(struct rtsx_chip *chip)
268 350
269#ifdef LED_AUTO_BLINK 351#ifdef LED_AUTO_BLINK
270 RTSX_WRITE_REG(chip, CARD_AUTO_BLINK, 0xFF, 352 RTSX_WRITE_REG(chip, CARD_AUTO_BLINK, 0xFF,
271 LED_BLINK_SPEED | BLINK_EN | LED_GPIO0); 353 LED_BLINK_SPEED | BLINK_EN | LED_GPIO0);
272#endif 354#endif
273 355
274 if (chip->asic_code) { 356 if (chip->asic_code) {
@@ -288,39 +370,9 @@ int rtsx_reset_chip(struct rtsx_chip *chip)
288 370
289 /* Enable ASPM */ 371 /* Enable ASPM */
290 if (chip->aspm_l0s_l1_en) { 372 if (chip->aspm_l0s_l1_en) {
291 if (chip->dynamic_aspm) { 373 retval = rtsx_reset_aspm(chip);
292 if (CHK_SDIO_EXIST(chip)) { 374 if (retval != STATUS_SUCCESS)
293 if (CHECK_PID(chip, 0x5288)) { 375 TRACE_RET(chip, STATUS_FAIL);
294 retval = rtsx_write_cfg_dw(chip, 2, 0xC0, 0xFF, chip->aspm_l0s_l1_en);
295 if (retval != STATUS_SUCCESS)
296 TRACE_RET(chip, STATUS_FAIL);
297 }
298 }
299 } else {
300 if (CHECK_PID(chip, 0x5208))
301 RTSX_WRITE_REG(chip, ASPM_FORCE_CTL,
302 0xFF, 0x3F);
303
304 retval = rtsx_write_config_byte(chip, LCTLR,
305 chip->aspm_l0s_l1_en);
306 if (retval != STATUS_SUCCESS)
307 TRACE_RET(chip, STATUS_FAIL);
308
309 chip->aspm_level[0] = chip->aspm_l0s_l1_en;
310 if (CHK_SDIO_EXIST(chip)) {
311 chip->aspm_level[1] = chip->aspm_l0s_l1_en;
312 if (CHECK_PID(chip, 0x5288))
313 retval = rtsx_write_cfg_dw(chip, 2, 0xC0, 0xFF, chip->aspm_l0s_l1_en);
314 else
315 retval = rtsx_write_cfg_dw(chip, 1, 0xC0, 0xFF, chip->aspm_l0s_l1_en);
316
317 if (retval != STATUS_SUCCESS)
318 TRACE_RET(chip, STATUS_FAIL);
319
320 }
321
322 chip->aspm_enabled = 1;
323 }
324 } else { 376 } else {
325 if (chip->asic_code && CHECK_PID(chip, 0x5208)) { 377 if (chip->asic_code && CHECK_PID(chip, 0x5208)) {
326 retval = rtsx_write_phy_register(chip, 0x07, 0x0129); 378 retval = rtsx_write_phy_register(chip, 0x07, 0x0129);
@@ -338,91 +390,38 @@ int rtsx_reset_chip(struct rtsx_chip *chip)
338 TRACE_RET(chip, STATUS_FAIL); 390 TRACE_RET(chip, STATUS_FAIL);
339 391
340 if (CHK_SDIO_EXIST(chip)) { 392 if (CHK_SDIO_EXIST(chip)) {
341 if (CHECK_PID(chip, 0x5288)) 393 retval = rtsx_write_cfg_dw(chip,
342 retval = rtsx_write_cfg_dw(chip, 2, 0xC0, 394 CHECK_PID(chip, 0x5288) ? 2 : 1,
343 0xFF00, 0x0100); 395 0xC0, 0xFF00, 0x0100);
344 else
345 retval = rtsx_write_cfg_dw(chip, 1, 0xC0,
346 0xFF00, 0x0100);
347 396
348 if (retval != STATUS_SUCCESS) 397 if (retval != STATUS_SUCCESS)
349 TRACE_RET(chip, STATUS_FAIL); 398 TRACE_RET(chip, STATUS_FAIL);
350
351 } 399 }
352 400
353 if (CHECK_PID(chip, 0x5288)) { 401 if (CHECK_PID(chip, 0x5288) && !CHK_SDIO_EXIST(chip)) {
354 if (!CHK_SDIO_EXIST(chip)) { 402 retval = rtsx_write_cfg_dw(chip, 2, 0xC0, 0xFFFF, 0x0103);
355 retval = rtsx_write_cfg_dw(chip, 2, 0xC0, 0xFFFF, 403 if (retval != STATUS_SUCCESS)
356 0x0103); 404 TRACE_RET(chip, STATUS_FAIL);
357 if (retval != STATUS_SUCCESS)
358 TRACE_RET(chip, STATUS_FAIL);
359
360 retval = rtsx_write_cfg_dw(chip, 2, 0x84, 0xFF, 0x03);
361 if (retval != STATUS_SUCCESS)
362 TRACE_RET(chip, STATUS_FAIL);
363 405
364 } 406 retval = rtsx_write_cfg_dw(chip, 2, 0x84, 0xFF, 0x03);
407 if (retval != STATUS_SUCCESS)
408 TRACE_RET(chip, STATUS_FAIL);
365 } 409 }
366 410
367 RTSX_WRITE_REG(chip, IRQSTAT0, LINK_RDY_INT, LINK_RDY_INT); 411 RTSX_WRITE_REG(chip, IRQSTAT0, LINK_RDY_INT, LINK_RDY_INT);
368 412
369 RTSX_WRITE_REG(chip, PERST_GLITCH_WIDTH, 0xFF, 0x80); 413 RTSX_WRITE_REG(chip, PERST_GLITCH_WIDTH, 0xFF, 0x80);
370 414
371 /* Enable PCIE interrupt */ 415 retval = rtsx_enable_pcie_intr(chip);
372 if (chip->asic_code) { 416 if (retval != STATUS_SUCCESS)
373 if (CHECK_PID(chip, 0x5208)) { 417 TRACE_RET(chip, STATUS_FAIL);
374 if (chip->phy_debug_mode) {
375 RTSX_WRITE_REG(chip, CDRESUMECTL, 0x77, 0);
376 rtsx_disable_bus_int(chip);
377 } else {
378 rtsx_enable_bus_int(chip);
379 }
380
381 if (chip->ic_version >= IC_VER_D) {
382 u16 reg;
383
384 retval = rtsx_read_phy_register(chip, 0x00,
385 &reg);
386 if (retval != STATUS_SUCCESS)
387 TRACE_RET(chip, STATUS_FAIL);
388
389 reg &= 0xFE7F;
390 reg |= 0x80;
391 retval = rtsx_write_phy_register(chip, 0x00,
392 reg);
393 if (retval != STATUS_SUCCESS)
394 TRACE_RET(chip, STATUS_FAIL);
395
396 retval = rtsx_read_phy_register(chip, 0x1C,
397 &reg);
398 if (retval != STATUS_SUCCESS)
399 TRACE_RET(chip, STATUS_FAIL);
400
401 reg &= 0xFFF7;
402 retval = rtsx_write_phy_register(chip, 0x1C,
403 reg);
404 if (retval != STATUS_SUCCESS)
405 TRACE_RET(chip, STATUS_FAIL);
406
407 }
408
409 if (chip->driver_first_load &&
410 (chip->ic_version < IC_VER_C))
411 rtsx_calibration(chip);
412
413 } else {
414 rtsx_enable_bus_int(chip);
415 }
416 } else {
417 rtsx_enable_bus_int(chip);
418 }
419 418
420 chip->need_reset = 0; 419 chip->need_reset = 0;
421 420
422 chip->int_reg = rtsx_readl(chip, RTSX_BIPR); 421 chip->int_reg = rtsx_readl(chip, RTSX_BIPR);
423 422
424 if (chip->hw_bypass_sd) 423 if (chip->hw_bypass_sd)
425 goto NextCard; 424 goto nextcard;
426 dev_dbg(rtsx_dev(chip), "In %s, chip->int_reg = 0x%x\n", __func__, 425 dev_dbg(rtsx_dev(chip), "In %s, chip->int_reg = 0x%x\n", __func__,
427 chip->int_reg); 426 chip->int_reg);
428 if (chip->int_reg & SD_EXIST) { 427 if (chip->int_reg & SD_EXIST) {
@@ -443,10 +442,10 @@ int rtsx_reset_chip(struct rtsx_chip *chip)
443 } else { 442 } else {
444 chip->sd_io = 0; 443 chip->sd_io = 0;
445 RTSX_WRITE_REG(chip, SDIO_CTRL, SDIO_BUS_CTRL | SDIO_CD_CTRL, 444 RTSX_WRITE_REG(chip, SDIO_CTRL, SDIO_BUS_CTRL | SDIO_CD_CTRL,
446 0); 445 0);
447 } 446 }
448 447
449NextCard: 448nextcard:
450 if (chip->int_reg & XD_EXIST) 449 if (chip->int_reg & XD_EXIST)
451 chip->need_reset |= XD_CARD; 450 chip->need_reset |= XD_CARD;
452 if (chip->int_reg & MS_EXIST) 451 if (chip->int_reg & MS_EXIST)
@@ -484,10 +483,10 @@ NextCard:
484 483
485 if (chip->ft2_fast_mode) { 484 if (chip->ft2_fast_mode) {
486 RTSX_WRITE_REG(chip, CARD_PWR_CTL, 0xFF, 485 RTSX_WRITE_REG(chip, CARD_PWR_CTL, 0xFF,
487 MS_PARTIAL_POWER_ON | SD_PARTIAL_POWER_ON); 486 MS_PARTIAL_POWER_ON | SD_PARTIAL_POWER_ON);
488 udelay(chip->pmos_pwr_on_interval); 487 udelay(chip->pmos_pwr_on_interval);
489 RTSX_WRITE_REG(chip, CARD_PWR_CTL, 0xFF, 488 RTSX_WRITE_REG(chip, CARD_PWR_CTL, 0xFF,
490 MS_POWER_ON | SD_POWER_ON); 489 MS_POWER_ON | SD_POWER_ON);
491 490
492 wait_timeout(200); 491 wait_timeout(200);
493 } 492 }
@@ -540,10 +539,7 @@ static int rts5208_init(struct rtsx_chip *chip)
540 539
541 RTSX_WRITE_REG(chip, CLK_SEL, 0x03, 0x03); 540 RTSX_WRITE_REG(chip, CLK_SEL, 0x03, 0x03);
542 RTSX_READ_REG(chip, CLK_SEL, &val); 541 RTSX_READ_REG(chip, CLK_SEL, &val);
543 if (val == 0) 542 chip->asic_code = val == 0 ? 1 : 0;
544 chip->asic_code = 1;
545 else
546 chip->asic_code = 0;
547 543
548 if (chip->asic_code) { 544 if (chip->asic_code) {
549 retval = rtsx_read_phy_register(chip, 0x1C, &reg); 545 retval = rtsx_read_phy_register(chip, 0x1C, &reg);
@@ -553,10 +549,7 @@ static int rts5208_init(struct rtsx_chip *chip)
553 dev_dbg(rtsx_dev(chip), "Value of phy register 0x1C is 0x%x\n", 549 dev_dbg(rtsx_dev(chip), "Value of phy register 0x1C is 0x%x\n",
554 reg); 550 reg);
555 chip->ic_version = (reg >> 4) & 0x07; 551 chip->ic_version = (reg >> 4) & 0x07;
556 if (reg & PHY_DEBUG_MODE) 552 chip->phy_debug_mode = reg & PHY_DEBUG_MODE ? 1 : 0;
557 chip->phy_debug_mode = 1;
558 else
559 chip->phy_debug_mode = 0;
560 553
561 } else { 554 } else {
562 RTSX_READ_REG(chip, 0xFE80, &val); 555 RTSX_READ_REG(chip, 0xFE80, &val);
@@ -566,16 +559,10 @@ static int rts5208_init(struct rtsx_chip *chip)
566 559
567 RTSX_READ_REG(chip, PDINFO, &val); 560 RTSX_READ_REG(chip, PDINFO, &val);
568 dev_dbg(rtsx_dev(chip), "PDINFO: 0x%x\n", val); 561 dev_dbg(rtsx_dev(chip), "PDINFO: 0x%x\n", val);
569 if (val & AUX_PWR_DETECTED) 562 chip->aux_pwr_exist = val & AUX_PWR_DETECTED ? 1 : 0;
570 chip->aux_pwr_exist = 1;
571 else
572 chip->aux_pwr_exist = 0;
573 563
574 RTSX_READ_REG(chip, 0xFE50, &val); 564 RTSX_READ_REG(chip, 0xFE50, &val);
575 if (val & 0x01) 565 chip->hw_bypass_sd = val & 0x01 ? 1 : 0;
576 chip->hw_bypass_sd = 1;
577 else
578 chip->hw_bypass_sd = 0;
579 566
580 rtsx_read_config_byte(chip, 0x0E, &val); 567 rtsx_read_config_byte(chip, 0x0E, &val);
581 if (val & 0x80) 568 if (val & 0x80)
@@ -585,10 +572,7 @@ static int rts5208_init(struct rtsx_chip *chip)
585 572
586 if (chip->use_hw_setting) { 573 if (chip->use_hw_setting) {
587 RTSX_READ_REG(chip, CHANGE_LINK_STATE, &val); 574 RTSX_READ_REG(chip, CHANGE_LINK_STATE, &val);
588 if (val & 0x80) 575 chip->auto_delink_en = val & 0x80 ? 1 : 0;
589 chip->auto_delink_en = 1;
590 else
591 chip->auto_delink_en = 0;
592 } 576 }
593 577
594 return STATUS_SUCCESS; 578 return STATUS_SUCCESS;
@@ -602,33 +586,21 @@ static int rts5288_init(struct rtsx_chip *chip)
602 586
603 RTSX_WRITE_REG(chip, CLK_SEL, 0x03, 0x03); 587 RTSX_WRITE_REG(chip, CLK_SEL, 0x03, 0x03);
604 RTSX_READ_REG(chip, CLK_SEL, &val); 588 RTSX_READ_REG(chip, CLK_SEL, &val);
605 if (val == 0) 589 chip->asic_code = val == 0 ? 1 : 0;
606 chip->asic_code = 1;
607 else
608 chip->asic_code = 0;
609 590
610 chip->ic_version = 0; 591 chip->ic_version = 0;
611 chip->phy_debug_mode = 0; 592 chip->phy_debug_mode = 0;
612 593
613 RTSX_READ_REG(chip, PDINFO, &val); 594 RTSX_READ_REG(chip, PDINFO, &val);
614 dev_dbg(rtsx_dev(chip), "PDINFO: 0x%x\n", val); 595 dev_dbg(rtsx_dev(chip), "PDINFO: 0x%x\n", val);
615 if (val & AUX_PWR_DETECTED) 596 chip->aux_pwr_exist = val & AUX_PWR_DETECTED ? 1 : 0;
616 chip->aux_pwr_exist = 1;
617 else
618 chip->aux_pwr_exist = 0;
619 597
620 RTSX_READ_REG(chip, CARD_SHARE_MODE, &val); 598 RTSX_READ_REG(chip, CARD_SHARE_MODE, &val);
621 dev_dbg(rtsx_dev(chip), "CARD_SHARE_MODE: 0x%x\n", val); 599 dev_dbg(rtsx_dev(chip), "CARD_SHARE_MODE: 0x%x\n", val);
622 if (val & 0x04) 600 chip->baro_pkg = val & 0x04 ? QFN : LQFP;
623 chip->baro_pkg = QFN;
624 else
625 chip->baro_pkg = LQFP;
626 601
627 RTSX_READ_REG(chip, 0xFE5A, &val); 602 RTSX_READ_REG(chip, 0xFE5A, &val);
628 if (val & 0x10) 603 chip->hw_bypass_sd = val & 0x10 ? 1 : 0;
629 chip->hw_bypass_sd = 1;
630 else
631 chip->hw_bypass_sd = 0;
632 604
633 retval = rtsx_read_cfg_dw(chip, 0, 0x718, &lval); 605 retval = rtsx_read_cfg_dw(chip, 0, 0x718, &lval);
634 if (retval != STATUS_SUCCESS) 606 if (retval != STATUS_SUCCESS)
@@ -643,16 +615,12 @@ static int rts5288_init(struct rtsx_chip *chip)
643 615
644 if (chip->use_hw_setting) { 616 if (chip->use_hw_setting) {
645 RTSX_READ_REG(chip, CHANGE_LINK_STATE, &val); 617 RTSX_READ_REG(chip, CHANGE_LINK_STATE, &val);
646 if (val & 0x80) 618 chip->auto_delink_en = val & 0x80 ? 1 : 0;
647 chip->auto_delink_en = 1;
648 else
649 chip->auto_delink_en = 0;
650 619
651 if (CHECK_BARO_PKG(chip, LQFP)) 620 if (CHECK_BARO_PKG(chip, LQFP))
652 chip->lun_mode = SD_MS_1LUN; 621 chip->lun_mode = SD_MS_1LUN;
653 else 622 else
654 chip->lun_mode = DEFAULT_SINGLE; 623 chip->lun_mode = DEFAULT_SINGLE;
655
656 } 624 }
657 625
658 return STATUS_SUCCESS; 626 return STATUS_SUCCESS;
@@ -660,9 +628,9 @@ static int rts5288_init(struct rtsx_chip *chip)
660 628
661int rtsx_init_chip(struct rtsx_chip *chip) 629int rtsx_init_chip(struct rtsx_chip *chip)
662{ 630{
663 struct sd_info *sd_card = &(chip->sd_card); 631 struct sd_info *sd_card = &chip->sd_card;
664 struct xd_info *xd_card = &(chip->xd_card); 632 struct xd_info *xd_card = &chip->xd_card;
665 struct ms_info *ms_card = &(chip->ms_card); 633 struct ms_info *ms_card = &chip->ms_card;
666 int retval; 634 int retval;
667 unsigned int i; 635 unsigned int i;
668 636
@@ -740,7 +708,6 @@ int rtsx_init_chip(struct rtsx_chip *chip)
740 retval = rts5288_init(chip); 708 retval = rts5288_init(chip);
741 if (retval != STATUS_SUCCESS) 709 if (retval != STATUS_SUCCESS)
742 TRACE_RET(chip, STATUS_FAIL); 710 TRACE_RET(chip, STATUS_FAIL);
743
744 } 711 }
745 712
746 if (chip->ss_en == 2) 713 if (chip->ss_en == 2)
@@ -842,7 +809,6 @@ static void rtsx_monitor_aspm_config(struct rtsx_chip *chip)
842 } else { 809 } else {
843 if (reg0 & 0x03) 810 if (reg0 & 0x03)
844 maybe_support_aspm = 1; 811 maybe_support_aspm = 1;
845
846 } 812 }
847 813
848 if (reg_changed) { 814 if (reg_changed) {
@@ -859,15 +825,15 @@ static void rtsx_monitor_aspm_config(struct rtsx_chip *chip)
859 chip->sdio_aspm = 0; 825 chip->sdio_aspm = 0;
860 } 826 }
861 rtsx_write_register(chip, ASPM_FORCE_CTL, 0xFF, 827 rtsx_write_register(chip, ASPM_FORCE_CTL, 0xFF,
862 0x30 | chip->aspm_level[0] | 828 0x30 | chip->aspm_level[0] |
863 (chip->aspm_level[1] << 2)); 829 (chip->aspm_level[1] << 2));
864 } 830 }
865} 831}
866 832
867void rtsx_polling_func(struct rtsx_chip *chip) 833void rtsx_polling_func(struct rtsx_chip *chip)
868{ 834{
869#ifdef SUPPORT_SD_LOCK 835#ifdef SUPPORT_SD_LOCK
870 struct sd_info *sd_card = &(chip->sd_card); 836 struct sd_info *sd_card = &chip->sd_card;
871#endif 837#endif
872 int ss_allowed; 838 int ss_allowed;
873 839
@@ -875,7 +841,7 @@ void rtsx_polling_func(struct rtsx_chip *chip)
875 return; 841 return;
876 842
877 if (rtsx_chk_stat(chip, RTSX_STAT_DELINK)) 843 if (rtsx_chk_stat(chip, RTSX_STAT_DELINK))
878 goto Delink_Stage; 844 goto delink_stage;
879 845
880 if (chip->polling_config) { 846 if (chip->polling_config) {
881 u8 val; 847 u8 val;
@@ -888,7 +854,7 @@ void rtsx_polling_func(struct rtsx_chip *chip)
888 854
889#ifdef SUPPORT_OCP 855#ifdef SUPPORT_OCP
890 if (chip->ocp_int) { 856 if (chip->ocp_int) {
891 rtsx_read_register(chip, OCPSTAT, &(chip->ocp_stat)); 857 rtsx_read_register(chip, OCPSTAT, &chip->ocp_stat);
892 858
893 if (chip->card_exist & SD_CARD) 859 if (chip->card_exist & SD_CARD)
894 sd_power_off_card3v3(chip); 860 sd_power_off_card3v3(chip);
@@ -932,7 +898,6 @@ void rtsx_polling_func(struct rtsx_chip *chip)
932 rtsx_read_cfg_dw(chip, 1, 0x04, &val); 898 rtsx_read_cfg_dw(chip, 1, 0x04, &val);
933 if (val & 0x07) 899 if (val & 0x07)
934 ss_allowed = 0; 900 ss_allowed = 0;
935
936 } 901 }
937 } 902 }
938 } else { 903 } else {
@@ -958,7 +923,7 @@ void rtsx_polling_func(struct rtsx_chip *chip)
958 923
959#ifdef SUPPORT_SDIO_ASPM 924#ifdef SUPPORT_SDIO_ASPM
960 if (CHK_SDIO_EXIST(chip) && !CHK_SDIO_IGNORED(chip) && 925 if (CHK_SDIO_EXIST(chip) && !CHK_SDIO_IGNORED(chip) &&
961 chip->aspm_l0s_l1_en && chip->dynamic_aspm) { 926 chip->aspm_l0s_l1_en && chip->dynamic_aspm) {
962 if (chip->sd_io) { 927 if (chip->sd_io) {
963 dynamic_configure_sdio_aspm(chip); 928 dynamic_configure_sdio_aspm(chip);
964 } else { 929 } else {
@@ -966,7 +931,8 @@ void rtsx_polling_func(struct rtsx_chip *chip)
966 dev_dbg(rtsx_dev(chip), "SDIO enter ASPM!\n"); 931 dev_dbg(rtsx_dev(chip), "SDIO enter ASPM!\n");
967 rtsx_write_register(chip, 932 rtsx_write_register(chip,
968 ASPM_FORCE_CTL, 0xFC, 933 ASPM_FORCE_CTL, 0xFC,
969 0x30 | (chip->aspm_level[1] << 2)); 934 0x30 |
935 (chip->aspm_level[1] << 2));
970 chip->sdio_aspm = 1; 936 chip->sdio_aspm = 1;
971 } 937 }
972 } 938 }
@@ -988,9 +954,10 @@ void rtsx_polling_func(struct rtsx_chip *chip)
988 954
989 turn_off_led(chip, LED_GPIO); 955 turn_off_led(chip, LED_GPIO);
990 956
991 if (chip->auto_power_down && !chip->card_ready && !chip->sd_io) 957 if (chip->auto_power_down && !chip->card_ready &&
992 rtsx_force_power_down(chip, SSC_PDCTL | OC_PDCTL); 958 !chip->sd_io)
993 959 rtsx_force_power_down(chip,
960 SSC_PDCTL | OC_PDCTL);
994 } 961 }
995 } 962 }
996 963
@@ -1013,7 +980,6 @@ void rtsx_polling_func(struct rtsx_chip *chip)
1013 break; 980 break;
1014 } 981 }
1015 982
1016
1017#ifdef SUPPORT_OCP 983#ifdef SUPPORT_OCP
1018 if (CHECK_LUN_MODE(chip, SD_MS_2LUN)) { 984 if (CHECK_LUN_MODE(chip, SD_MS_2LUN)) {
1019 if (chip->ocp_stat & 985 if (chip->ocp_stat &
@@ -1024,7 +990,7 @@ void rtsx_polling_func(struct rtsx_chip *chip)
1024 if (chip->ocp_stat & (SD_OC_NOW | SD_OC_EVER)) { 990 if (chip->ocp_stat & (SD_OC_NOW | SD_OC_EVER)) {
1025 if (chip->card_exist & SD_CARD) { 991 if (chip->card_exist & SD_CARD) {
1026 rtsx_write_register(chip, CARD_OE, SD_OUTPUT_EN, 992 rtsx_write_register(chip, CARD_OE, SD_OUTPUT_EN,
1027 0); 993 0);
1028 card_power_off(chip, SD_CARD); 994 card_power_off(chip, SD_CARD);
1029 chip->card_fail |= SD_CARD; 995 chip->card_fail |= SD_CARD;
1030 } 996 }
@@ -1032,7 +998,7 @@ void rtsx_polling_func(struct rtsx_chip *chip)
1032 if (chip->ocp_stat & (MS_OC_NOW | MS_OC_EVER)) { 998 if (chip->ocp_stat & (MS_OC_NOW | MS_OC_EVER)) {
1033 if (chip->card_exist & MS_CARD) { 999 if (chip->card_exist & MS_CARD) {
1034 rtsx_write_register(chip, CARD_OE, MS_OUTPUT_EN, 1000 rtsx_write_register(chip, CARD_OE, MS_OUTPUT_EN,
1035 0); 1001 0);
1036 card_power_off(chip, MS_CARD); 1002 card_power_off(chip, MS_CARD);
1037 chip->card_fail |= MS_CARD; 1003 chip->card_fail |= MS_CARD;
1038 } 1004 }
@@ -1043,15 +1009,15 @@ void rtsx_polling_func(struct rtsx_chip *chip)
1043 chip->ocp_stat); 1009 chip->ocp_stat);
1044 if (chip->card_exist & SD_CARD) { 1010 if (chip->card_exist & SD_CARD) {
1045 rtsx_write_register(chip, CARD_OE, SD_OUTPUT_EN, 1011 rtsx_write_register(chip, CARD_OE, SD_OUTPUT_EN,
1046 0); 1012 0);
1047 chip->card_fail |= SD_CARD; 1013 chip->card_fail |= SD_CARD;
1048 } else if (chip->card_exist & MS_CARD) { 1014 } else if (chip->card_exist & MS_CARD) {
1049 rtsx_write_register(chip, CARD_OE, MS_OUTPUT_EN, 1015 rtsx_write_register(chip, CARD_OE, MS_OUTPUT_EN,
1050 0); 1016 0);
1051 chip->card_fail |= MS_CARD; 1017 chip->card_fail |= MS_CARD;
1052 } else if (chip->card_exist & XD_CARD) { 1018 } else if (chip->card_exist & XD_CARD) {
1053 rtsx_write_register(chip, CARD_OE, XD_OUTPUT_EN, 1019 rtsx_write_register(chip, CARD_OE, XD_OUTPUT_EN,
1054 0); 1020 0);
1055 chip->card_fail |= XD_CARD; 1021 chip->card_fail |= XD_CARD;
1056 } 1022 }
1057 card_power_off(chip, SD_CARD); 1023 card_power_off(chip, SD_CARD);
@@ -1059,9 +1025,9 @@ void rtsx_polling_func(struct rtsx_chip *chip)
1059 } 1025 }
1060#endif 1026#endif
1061 1027
1062Delink_Stage: 1028delink_stage:
1063 if (chip->auto_delink_en && chip->auto_delink_allowed && 1029 if (chip->auto_delink_en && chip->auto_delink_allowed &&
1064 !chip->card_ready && !chip->card_ejected && !chip->sd_io) { 1030 !chip->card_ready && !chip->card_ejected && !chip->sd_io) {
1065 int enter_L1 = chip->auto_delink_in_L1 && ( 1031 int enter_L1 = chip->auto_delink_in_L1 && (
1066 chip->aspm_l0s_l1_en || chip->ss_en); 1032 chip->aspm_l0s_l1_en || chip->ss_en);
1067 int delink_stage1_cnt = chip->delink_stage1_step; 1033 int delink_stage1_cnt = chip->delink_stage1_step;
@@ -1081,27 +1047,33 @@ Delink_Stage:
1081 dev_dbg(rtsx_dev(chip), "False card inserted, do force delink\n"); 1047 dev_dbg(rtsx_dev(chip), "False card inserted, do force delink\n");
1082 1048
1083 if (enter_L1) 1049 if (enter_L1)
1084 rtsx_write_register(chip, HOST_SLEEP_STATE, 0x03, 1); 1050 rtsx_write_register(chip,
1051 HOST_SLEEP_STATE,
1052 0x03, 1);
1085 1053
1086 rtsx_write_register(chip, 1054 rtsx_write_register(chip,
1087 CHANGE_LINK_STATE, 0x0A, 1055 CHANGE_LINK_STATE,
1088 0x0A); 1056 0x0A, 0x0A);
1089 1057
1090 if (enter_L1) 1058 if (enter_L1)
1091 rtsx_enter_L1(chip); 1059 rtsx_enter_L1(chip);
1092 1060
1093 chip->auto_delink_cnt = delink_stage3_cnt + 1; 1061 chip->auto_delink_cnt =
1062 delink_stage3_cnt + 1;
1094 } else { 1063 } else {
1095 dev_dbg(rtsx_dev(chip), "No card inserted, do delink\n"); 1064 dev_dbg(rtsx_dev(chip), "No card inserted, do delink\n");
1096 1065
1097 if (enter_L1) 1066 if (enter_L1)
1098 rtsx_write_register(chip, HOST_SLEEP_STATE, 0x03, 1); 1067 rtsx_write_register(chip,
1068 HOST_SLEEP_STATE,
1069 0x03, 1);
1099 1070
1100 rtsx_write_register(chip, CHANGE_LINK_STATE, 0x02, 0x02); 1071 rtsx_write_register(chip,
1072 CHANGE_LINK_STATE,
1073 0x02, 0x02);
1101 1074
1102 if (enter_L1) 1075 if (enter_L1)
1103 rtsx_enter_L1(chip); 1076 rtsx_enter_L1(chip);
1104
1105 } 1077 }
1106 } 1078 }
1107 1079
@@ -1115,7 +1087,7 @@ Delink_Stage:
1115 rtsx_set_phy_reg_bit(chip, 0x1C, 2); 1087 rtsx_set_phy_reg_bit(chip, 0x1C, 2);
1116 1088
1117 rtsx_write_register(chip, CHANGE_LINK_STATE, 1089 rtsx_write_register(chip, CHANGE_LINK_STATE,
1118 0x0A, 0x0A); 1090 0x0A, 0x0A);
1119 } 1091 }
1120 1092
1121 chip->auto_delink_cnt++; 1093 chip->auto_delink_cnt++;
@@ -1219,7 +1191,7 @@ int rtsx_read_register(struct rtsx_chip *chip, u16 addr, u8 *data)
1219} 1191}
1220 1192
1221int rtsx_write_cfg_dw(struct rtsx_chip *chip, u8 func_no, u16 addr, u32 mask, 1193int rtsx_write_cfg_dw(struct rtsx_chip *chip, u8 func_no, u16 addr, u32 mask,
1222 u32 val) 1194 u32 val)
1223{ 1195{
1224 u8 mode = 0, tmp; 1196 u8 mode = 0, tmp;
1225 int i; 1197 int i;
@@ -1279,7 +1251,7 @@ int rtsx_read_cfg_dw(struct rtsx_chip *chip, u8 func_no, u16 addr, u32 *val)
1279} 1251}
1280 1252
1281int rtsx_write_cfg_seq(struct rtsx_chip *chip, u8 func, u16 addr, u8 *buf, 1253int rtsx_write_cfg_seq(struct rtsx_chip *chip, u8 func, u16 addr, u8 *buf,
1282 int len) 1254 int len)
1283{ 1255{
1284 u32 *data, *mask; 1256 u32 *data, *mask;
1285 u16 offset = addr % 4; 1257 u16 offset = addr % 4;
@@ -1324,7 +1296,7 @@ int rtsx_write_cfg_seq(struct rtsx_chip *chip, u8 func, u16 addr, u8 *buf,
1324 1296
1325 for (i = 0; i < dw_len; i++) { 1297 for (i = 0; i < dw_len; i++) {
1326 retval = rtsx_write_cfg_dw(chip, func, aligned_addr + i * 4, 1298 retval = rtsx_write_cfg_dw(chip, func, aligned_addr + i * 4,
1327 mask[i], data[i]); 1299 mask[i], data[i]);
1328 if (retval != STATUS_SUCCESS) { 1300 if (retval != STATUS_SUCCESS) {
1329 vfree(data); 1301 vfree(data);
1330 vfree(mask); 1302 vfree(mask);
@@ -1339,7 +1311,7 @@ int rtsx_write_cfg_seq(struct rtsx_chip *chip, u8 func, u16 addr, u8 *buf,
1339} 1311}
1340 1312
1341int rtsx_read_cfg_seq(struct rtsx_chip *chip, u8 func, u16 addr, u8 *buf, 1313int rtsx_read_cfg_seq(struct rtsx_chip *chip, u8 func, u16 addr, u8 *buf,
1342 int len) 1314 int len)
1343{ 1315{
1344 u32 *data; 1316 u32 *data;
1345 u16 offset = addr % 4; 1317 u16 offset = addr % 4;
@@ -1360,7 +1332,7 @@ int rtsx_read_cfg_seq(struct rtsx_chip *chip, u8 func, u16 addr, u8 *buf,
1360 1332
1361 for (i = 0; i < dw_len; i++) { 1333 for (i = 0; i < dw_len; i++) {
1362 retval = rtsx_read_cfg_dw(chip, func, aligned_addr + i * 4, 1334 retval = rtsx_read_cfg_dw(chip, func, aligned_addr + i * 4,
1363 data + i); 1335 data + i);
1364 if (retval != STATUS_SUCCESS) { 1336 if (retval != STATUS_SUCCESS) {
1365 vfree(data); 1337 vfree(data);
1366 TRACE_RET(chip, STATUS_FAIL); 1338 TRACE_RET(chip, STATUS_FAIL);
@@ -1522,7 +1494,7 @@ int rtsx_set_phy_reg_bit(struct rtsx_chip *chip, u8 reg, u8 bit)
1522 if (retval != STATUS_SUCCESS) 1494 if (retval != STATUS_SUCCESS)
1523 TRACE_RET(chip, STATUS_FAIL); 1495 TRACE_RET(chip, STATUS_FAIL);
1524 1496
1525 if (0 == (value & (1 << bit))) { 1497 if ((value & (1 << bit)) == 0) {
1526 value |= (1 << bit); 1498 value |= (1 << bit);
1527 retval = rtsx_write_phy_register(chip, reg, value); 1499 retval = rtsx_write_phy_register(chip, reg, value);
1528 if (retval != STATUS_SUCCESS) 1500 if (retval != STATUS_SUCCESS)
@@ -1595,12 +1567,9 @@ void rtsx_enter_ss(struct rtsx_chip *chip)
1595 rtsx_force_power_down(chip, SSC_PDCTL | OC_PDCTL); 1567 rtsx_force_power_down(chip, SSC_PDCTL | OC_PDCTL);
1596 } 1568 }
1597 1569
1598 if (CHK_SDIO_EXIST(chip)) { 1570 if (CHK_SDIO_EXIST(chip))
1599 if (CHECK_PID(chip, 0x5288)) 1571 rtsx_write_cfg_dw(chip, CHECK_PID(chip, 0x5288) ? 2 : 1,
1600 rtsx_write_cfg_dw(chip, 2, 0xC0, 0xFF00, 0x0100); 1572 0xC0, 0xFF00, 0x0100);
1601 else
1602 rtsx_write_cfg_dw(chip, 1, 0xC0, 0xFF00, 0x0100);
1603 }
1604 1573
1605 if (chip->auto_delink_en) { 1574 if (chip->auto_delink_en) {
1606 rtsx_write_register(chip, HOST_SLEEP_STATE, 0x01, 0x01); 1575 rtsx_write_register(chip, HOST_SLEEP_STATE, 0x01, 0x01);
@@ -1666,7 +1635,7 @@ int rtsx_pre_handle_interrupt(struct rtsx_chip *chip)
1666 chip->int_reg = rtsx_readl(chip, RTSX_BIPR); 1635 chip->int_reg = rtsx_readl(chip, RTSX_BIPR);
1667 1636
1668 if (((chip->int_reg & int_enable) == 0) || 1637 if (((chip->int_reg & int_enable) == 0) ||
1669 (chip->int_reg == 0xFFFFFFFF)) 1638 (chip->int_reg == 0xFFFFFFFF))
1670 return STATUS_FAIL; 1639 return STATUS_FAIL;
1671 1640
1672 status = chip->int_reg &= (int_enable | 0x7FFFFF); 1641 status = chip->int_reg &= (int_enable | 0x7FFFFF);
@@ -1676,12 +1645,12 @@ int rtsx_pre_handle_interrupt(struct rtsx_chip *chip)
1676 1645
1677 if (status & SD_INT) { 1646 if (status & SD_INT) {
1678 if (status & SD_EXIST) { 1647 if (status & SD_EXIST) {
1679 set_bit(SD_NR, &(chip->need_reset)); 1648 set_bit(SD_NR, &chip->need_reset);
1680 } else { 1649 } else {
1681 set_bit(SD_NR, &(chip->need_release)); 1650 set_bit(SD_NR, &chip->need_release);
1682 chip->sd_reset_counter = 0; 1651 chip->sd_reset_counter = 0;
1683 chip->sd_show_cnt = 0; 1652 chip->sd_show_cnt = 0;
1684 clear_bit(SD_NR, &(chip->need_reset)); 1653 clear_bit(SD_NR, &chip->need_reset);
1685 } 1654 }
1686 } else { 1655 } else {
1687 /* If multi-luns, it's possible that 1656 /* If multi-luns, it's possible that
@@ -1691,35 +1660,35 @@ int rtsx_pre_handle_interrupt(struct rtsx_chip *chip)
1691 all existed cards should be reset. 1660 all existed cards should be reset.
1692 */ 1661 */
1693 if (exit_ss && (status & SD_EXIST)) 1662 if (exit_ss && (status & SD_EXIST))
1694 set_bit(SD_NR, &(chip->need_reinit)); 1663 set_bit(SD_NR, &chip->need_reinit);
1695 } 1664 }
1696 if (!CHECK_PID(chip, 0x5288) || CHECK_BARO_PKG(chip, QFN)) { 1665 if (!CHECK_PID(chip, 0x5288) || CHECK_BARO_PKG(chip, QFN)) {
1697 if (status & XD_INT) { 1666 if (status & XD_INT) {
1698 if (status & XD_EXIST) { 1667 if (status & XD_EXIST) {
1699 set_bit(XD_NR, &(chip->need_reset)); 1668 set_bit(XD_NR, &chip->need_reset);
1700 } else { 1669 } else {
1701 set_bit(XD_NR, &(chip->need_release)); 1670 set_bit(XD_NR, &chip->need_release);
1702 chip->xd_reset_counter = 0; 1671 chip->xd_reset_counter = 0;
1703 chip->xd_show_cnt = 0; 1672 chip->xd_show_cnt = 0;
1704 clear_bit(XD_NR, &(chip->need_reset)); 1673 clear_bit(XD_NR, &chip->need_reset);
1705 } 1674 }
1706 } else { 1675 } else {
1707 if (exit_ss && (status & XD_EXIST)) 1676 if (exit_ss && (status & XD_EXIST))
1708 set_bit(XD_NR, &(chip->need_reinit)); 1677 set_bit(XD_NR, &chip->need_reinit);
1709 } 1678 }
1710 } 1679 }
1711 if (status & MS_INT) { 1680 if (status & MS_INT) {
1712 if (status & MS_EXIST) { 1681 if (status & MS_EXIST) {
1713 set_bit(MS_NR, &(chip->need_reset)); 1682 set_bit(MS_NR, &chip->need_reset);
1714 } else { 1683 } else {
1715 set_bit(MS_NR, &(chip->need_release)); 1684 set_bit(MS_NR, &chip->need_release);
1716 chip->ms_reset_counter = 0; 1685 chip->ms_reset_counter = 0;
1717 chip->ms_show_cnt = 0; 1686 chip->ms_show_cnt = 0;
1718 clear_bit(MS_NR, &(chip->need_reset)); 1687 clear_bit(MS_NR, &chip->need_reset);
1719 } 1688 }
1720 } else { 1689 } else {
1721 if (exit_ss && (status & MS_EXIST)) 1690 if (exit_ss && (status & MS_EXIST))
1722 set_bit(MS_NR, &(chip->need_reinit)); 1691 set_bit(MS_NR, &chip->need_reinit);
1723 } 1692 }
1724 } 1693 }
1725 1694
@@ -1727,10 +1696,8 @@ int rtsx_pre_handle_interrupt(struct rtsx_chip *chip)
1727 chip->ocp_int = ocp_int & status; 1696 chip->ocp_int = ocp_int & status;
1728#endif 1697#endif
1729 1698
1730 if (chip->sd_io) { 1699 if (chip->sd_io && (chip->int_reg & DATA_DONE_INT))
1731 if (chip->int_reg & DATA_DONE_INT) 1700 chip->int_reg &= ~(u32)DATA_DONE_INT;
1732 chip->int_reg &= ~(u32)DATA_DONE_INT;
1733 }
1734 1701
1735 return STATUS_SUCCESS; 1702 return STATUS_SUCCESS;
1736} 1703}
@@ -1774,14 +1741,14 @@ void rtsx_do_before_power_down(struct rtsx_chip *chip, int pm_stat)
1774 if (pm_stat == PM_S1) { 1741 if (pm_stat == PM_S1) {
1775 dev_dbg(rtsx_dev(chip), "Host enter S1\n"); 1742 dev_dbg(rtsx_dev(chip), "Host enter S1\n");
1776 rtsx_write_register(chip, HOST_SLEEP_STATE, 0x03, 1743 rtsx_write_register(chip, HOST_SLEEP_STATE, 0x03,
1777 HOST_ENTER_S1); 1744 HOST_ENTER_S1);
1778 } else if (pm_stat == PM_S3) { 1745 } else if (pm_stat == PM_S3) {
1779 if (chip->s3_pwr_off_delay > 0) 1746 if (chip->s3_pwr_off_delay > 0)
1780 wait_timeout(chip->s3_pwr_off_delay); 1747 wait_timeout(chip->s3_pwr_off_delay);
1781 1748
1782 dev_dbg(rtsx_dev(chip), "Host enter S3\n"); 1749 dev_dbg(rtsx_dev(chip), "Host enter S3\n");
1783 rtsx_write_register(chip, HOST_SLEEP_STATE, 0x03, 1750 rtsx_write_register(chip, HOST_SLEEP_STATE, 0x03,
1784 HOST_ENTER_S3); 1751 HOST_ENTER_S3);
1785 } 1752 }
1786 1753
1787 if (chip->do_delink_before_power_down && chip->auto_delink_en) 1754 if (chip->do_delink_before_power_down && chip->auto_delink_en)
@@ -1796,31 +1763,25 @@ void rtsx_do_before_power_down(struct rtsx_chip *chip, int pm_stat)
1796 1763
1797void rtsx_enable_aspm(struct rtsx_chip *chip) 1764void rtsx_enable_aspm(struct rtsx_chip *chip)
1798{ 1765{
1799 if (chip->aspm_l0s_l1_en && chip->dynamic_aspm) { 1766 if (chip->aspm_l0s_l1_en && chip->dynamic_aspm && !chip->aspm_enabled) {
1800 if (!chip->aspm_enabled) { 1767 dev_dbg(rtsx_dev(chip), "Try to enable ASPM\n");
1801 dev_dbg(rtsx_dev(chip), "Try to enable ASPM\n"); 1768 chip->aspm_enabled = 1;
1802 chip->aspm_enabled = 1;
1803 1769
1804 if (chip->asic_code && CHECK_PID(chip, 0x5208)) 1770 if (chip->asic_code && CHECK_PID(chip, 0x5208))
1805 rtsx_write_phy_register(chip, 0x07, 0); 1771 rtsx_write_phy_register(chip, 0x07, 0);
1806 if (CHECK_PID(chip, 0x5208)) { 1772 if (CHECK_PID(chip, 0x5208)) {
1807 rtsx_write_register(chip, ASPM_FORCE_CTL, 0xF3, 1773 rtsx_write_register(chip, ASPM_FORCE_CTL, 0xF3,
1808 0x30 | chip->aspm_level[0]); 1774 0x30 | chip->aspm_level[0]);
1809 } else { 1775 } else {
1810 rtsx_write_config_byte(chip, LCTLR, 1776 rtsx_write_config_byte(chip, LCTLR,
1811 chip->aspm_l0s_l1_en); 1777 chip->aspm_l0s_l1_en);
1812 } 1778 }
1813 1779
1814 if (CHK_SDIO_EXIST(chip)) { 1780 if (CHK_SDIO_EXIST(chip)) {
1815 u16 val = chip->aspm_l0s_l1_en | 0x0100; 1781 u16 val = chip->aspm_l0s_l1_en | 0x0100;
1816 1782
1817 if (CHECK_PID(chip, 0x5288)) 1783 rtsx_write_cfg_dw(chip, CHECK_PID(chip, 0x5288) ? 2 : 1,
1818 rtsx_write_cfg_dw(chip, 2, 0xC0, 1784 0xC0, 0xFFF, val);
1819 0xFFFF, val);
1820 else
1821 rtsx_write_cfg_dw(chip, 1, 0xC0,
1822 0xFFFF, val);
1823 }
1824 } 1785 }
1825 } 1786 }
1826} 1787}
@@ -1830,21 +1791,19 @@ void rtsx_disable_aspm(struct rtsx_chip *chip)
1830 if (CHECK_PID(chip, 0x5208)) 1791 if (CHECK_PID(chip, 0x5208))
1831 rtsx_monitor_aspm_config(chip); 1792 rtsx_monitor_aspm_config(chip);
1832 1793
1833 if (chip->aspm_l0s_l1_en && chip->dynamic_aspm) { 1794 if (chip->aspm_l0s_l1_en && chip->dynamic_aspm && chip->aspm_enabled) {
1834 if (chip->aspm_enabled) { 1795 dev_dbg(rtsx_dev(chip), "Try to disable ASPM\n");
1835 dev_dbg(rtsx_dev(chip), "Try to disable ASPM\n"); 1796 chip->aspm_enabled = 0;
1836 chip->aspm_enabled = 0;
1837 1797
1838 if (chip->asic_code && CHECK_PID(chip, 0x5208)) 1798 if (chip->asic_code && CHECK_PID(chip, 0x5208))
1839 rtsx_write_phy_register(chip, 0x07, 0x0129); 1799 rtsx_write_phy_register(chip, 0x07, 0x0129);
1840 if (CHECK_PID(chip, 0x5208)) 1800 if (CHECK_PID(chip, 0x5208))
1841 rtsx_write_register(chip, ASPM_FORCE_CTL, 1801 rtsx_write_register(chip, ASPM_FORCE_CTL,
1842 0xF3, 0x30); 1802 0xF3, 0x30);
1843 else 1803 else
1844 rtsx_write_config_byte(chip, LCTLR, 0x00); 1804 rtsx_write_config_byte(chip, LCTLR, 0x00);
1845 1805
1846 wait_timeout(1); 1806 wait_timeout(1);
1847 }
1848 } 1807 }
1849} 1808}
1850 1809
@@ -1907,7 +1866,7 @@ int rtsx_write_ppbuf(struct rtsx_chip *chip, u8 *buf, int buf_len)
1907 1866
1908 for (j = 0; j < 256; j++) { 1867 for (j = 0; j < 256; j++) {
1909 rtsx_add_cmd(chip, WRITE_REG_CMD, reg_addr++, 0xFF, 1868 rtsx_add_cmd(chip, WRITE_REG_CMD, reg_addr++, 0xFF,
1910 *ptr); 1869 *ptr);
1911 ptr++; 1870 ptr++;
1912 } 1871 }
1913 1872
@@ -1921,7 +1880,7 @@ int rtsx_write_ppbuf(struct rtsx_chip *chip, u8 *buf, int buf_len)
1921 1880
1922 for (j = 0; j < buf_len%256; j++) { 1881 for (j = 0; j < buf_len%256; j++) {
1923 rtsx_add_cmd(chip, WRITE_REG_CMD, reg_addr++, 0xFF, 1882 rtsx_add_cmd(chip, WRITE_REG_CMD, reg_addr++, 0xFF,
1924 *ptr); 1883 *ptr);
1925 ptr++; 1884 ptr++;
1926 } 1885 }
1927 1886
diff --git a/drivers/staging/rts5208/rtsx_scsi.c b/drivers/staging/rts5208/rtsx_scsi.c
index bbbf7968a0b6..11610826acf1 100644
--- a/drivers/staging/rts5208/rtsx_scsi.c
+++ b/drivers/staging/rts5208/rtsx_scsi.c
@@ -584,9 +584,8 @@ static int start_stop_unit(struct scsi_cmnd *srb, struct rtsx_chip *chip)
584 584
585 case MAKE_MEDIUM_READY: 585 case MAKE_MEDIUM_READY:
586 case LOAD_MEDIUM: 586 case LOAD_MEDIUM:
587 if (check_card_ready(chip, lun)) { 587 if (check_card_ready(chip, lun))
588 return TRANSPORT_GOOD; 588 return TRANSPORT_GOOD;
589 }
590 set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT); 589 set_sense_type(chip, lun, SENSE_TYPE_MEDIA_NOT_PRESENT);
591 TRACE_RET(chip, TRANSPORT_FAILED); 590 TRACE_RET(chip, TRANSPORT_FAILED);
592 591
diff --git a/drivers/staging/rts5208/rtsx_transport.c b/drivers/staging/rts5208/rtsx_transport.c
index 0a67dca72dff..756a9687c293 100644
--- a/drivers/staging/rts5208/rtsx_transport.c
+++ b/drivers/staging/rts5208/rtsx_transport.c
@@ -539,7 +539,7 @@ static int rtsx_transfer_sglist_adma(struct rtsx_chip *chip, u8 card,
539 if (i == buf_cnt / (HOST_SG_TBL_BUF_LEN / 8)) 539 if (i == buf_cnt / (HOST_SG_TBL_BUF_LEN / 8))
540 sg_cnt = buf_cnt % (HOST_SG_TBL_BUF_LEN / 8); 540 sg_cnt = buf_cnt % (HOST_SG_TBL_BUF_LEN / 8);
541 else 541 else
542 sg_cnt = (HOST_SG_TBL_BUF_LEN / 8); 542 sg_cnt = HOST_SG_TBL_BUF_LEN / 8;
543 543
544 chip->sgi = 0; 544 chip->sgi = 0;
545 for (j = 0; j < sg_cnt; j++) { 545 for (j = 0; j < sg_cnt; j++) {
@@ -728,15 +728,13 @@ int rtsx_transfer_data_partial(struct rtsx_chip *chip, u8 card,
728 if (rtsx_chk_stat(chip, RTSX_STAT_ABORT)) 728 if (rtsx_chk_stat(chip, RTSX_STAT_ABORT))
729 return -EIO; 729 return -EIO;
730 730
731 if (use_sg) { 731 if (use_sg)
732 err = rtsx_transfer_sglist_adma_partial(chip, card, 732 err = rtsx_transfer_sglist_adma_partial(chip, card,
733 (struct scatterlist *)buf, use_sg, 733 (struct scatterlist *)buf, use_sg,
734 index, offset, (int)len, dma_dir, timeout); 734 index, offset, (int)len, dma_dir, timeout);
735 } else { 735 else
736 err = rtsx_transfer_buf(chip, card, 736 err = rtsx_transfer_buf(chip, card,
737 buf, len, dma_dir, timeout); 737 buf, len, dma_dir, timeout);
738 }
739
740 if (err < 0) { 738 if (err < 0) {
741 if (RTSX_TST_DELINK(chip)) { 739 if (RTSX_TST_DELINK(chip)) {
742 RTSX_CLR_DELINK(chip); 740 RTSX_CLR_DELINK(chip);
diff --git a/drivers/staging/rts5208/rtsx_transport.h b/drivers/staging/rts5208/rtsx_transport.h
index b4b112372776..899bc2079dbe 100644
--- a/drivers/staging/rts5208/rtsx_transport.h
+++ b/drivers/staging/rts5208/rtsx_transport.h
@@ -46,7 +46,7 @@ void rtsx_add_cmd(struct rtsx_chip *chip,
46void rtsx_send_cmd_no_wait(struct rtsx_chip *chip); 46void rtsx_send_cmd_no_wait(struct rtsx_chip *chip);
47int rtsx_send_cmd(struct rtsx_chip *chip, u8 card, int timeout); 47int rtsx_send_cmd(struct rtsx_chip *chip, u8 card, int timeout);
48 48
49extern inline u8 *rtsx_get_cmd_data(struct rtsx_chip *chip) 49static inline u8 *rtsx_get_cmd_data(struct rtsx_chip *chip)
50{ 50{
51#ifdef CMD_USING_SG 51#ifdef CMD_USING_SG
52 return (u8 *)(chip->host_sg_tbl_ptr); 52 return (u8 *)(chip->host_sg_tbl_ptr);
diff --git a/drivers/staging/skein/Kconfig b/drivers/staging/skein/Kconfig
index b9172bfcdc1b..012a8233376e 100644
--- a/drivers/staging/skein/Kconfig
+++ b/drivers/staging/skein/Kconfig
@@ -1,8 +1,8 @@
1config CRYPTO_SKEIN 1config CRYPTO_SKEIN
2 bool "Skein digest algorithm" 2 tristate "Skein digest algorithm"
3 depends on (X86 || UML_X86) && 64BIT && CRYPTO 3 depends on (X86 || UML_X86) && 64BIT && CRYPTO
4 select CRYPTO_THREEFISH
5 select CRYPTO_HASH 4 select CRYPTO_HASH
5 select CRYPTO_ALGAPI
6 help 6 help
7 Skein secure hash algorithm is one of 5 finalists from the NIST SHA3 7 Skein secure hash algorithm is one of 5 finalists from the NIST SHA3
8 competition. 8 competition.
@@ -12,21 +12,5 @@ config CRYPTO_SKEIN
12 12
13 http://www.skein-hash.info/sites/default/files/skein1.3.pdf 13 http://www.skein-hash.info/sites/default/files/skein1.3.pdf
14 14
15 for more information. This module depends on the threefish block 15 for more information. This module also contains the threefish block
16 cipher module. 16 cipher algorithm.
17
18config CRYPTO_THREEFISH
19 bool "Threefish tweakable block cipher"
20 depends on (X86 || UML_X86) && 64BIT && CRYPTO
21 select CRYPTO_ALGAPI
22 help
23 Threefish cipher algorithm is the tweakable block cipher underneath
24 the Skein family of secure hash algorithms. Skein is one of 5
25 finalists from the NIST SHA3 competition.
26
27 Skein is optimized for modern, 64bit processors and is highly
28 customizable. See:
29
30 http://www.skein-hash.info/sites/default/files/skein1.3.pdf
31
32 for more information.
diff --git a/drivers/staging/skein/Makefile b/drivers/staging/skein/Makefile
index a14aaddd829c..b7f947fb98f0 100644
--- a/drivers/staging/skein/Makefile
+++ b/drivers/staging/skein/Makefile
@@ -1,9 +1,10 @@
1# 1#
2# Makefile for the skein secure hash algorithm 2# Makefile for the skein secure hash algorithm
3# 3#
4obj-$(CONFIG_CRYPTO_SKEIN) += skein.o \ 4obj-$(CONFIG_CRYPTO_SKEIN) += skein.o
5 skein_api.o \ 5skein-y := skein_base.o \
6 skein_block.o 6 skein_api.o \
7 7 skein_block.o \
8obj-$(CONFIG_CRYPTO_THREEFISH) += threefish_block.o \ 8 threefish_block.o \
9 threefish_api.o 9 threefish_api.o \
10 skein_generic.o
diff --git a/drivers/staging/skein/skein_api.c b/drivers/staging/skein/skein_api.c
index 6e700eefc00c..5bfce076f7c8 100644
--- a/drivers/staging/skein/skein_api.c
+++ b/drivers/staging/skein/skein_api.c
@@ -31,7 +31,7 @@ int skein_ctx_prepare(struct skein_ctx *ctx, enum skein_size size)
31{ 31{
32 skein_assert_ret(ctx && size, SKEIN_FAIL); 32 skein_assert_ret(ctx && size, SKEIN_FAIL);
33 33
34 memset(ctx , 0, sizeof(struct skein_ctx)); 34 memset(ctx, 0, sizeof(struct skein_ctx));
35 ctx->skein_size = size; 35 ctx->skein_size = size;
36 36
37 return SKEIN_SUCCESS; 37 return SKEIN_SUCCESS;
diff --git a/drivers/staging/skein/skein_api.h b/drivers/staging/skein/skein_api.h
index e02fa19d9458..171b87549548 100644
--- a/drivers/staging/skein/skein_api.h
+++ b/drivers/staging/skein/skein_api.h
@@ -79,7 +79,7 @@ OTHER DEALINGS IN THE SOFTWARE.
79 */ 79 */
80 80
81#include <linux/types.h> 81#include <linux/types.h>
82#include "skein.h" 82#include "skein_base.h"
83 83
84/** 84/**
85 * Which Skein size to use 85 * Which Skein size to use
diff --git a/drivers/staging/skein/skein.c b/drivers/staging/skein/skein_base.c
index 8cc83587b1f1..7e700a6b5788 100644
--- a/drivers/staging/skein/skein.c
+++ b/drivers/staging/skein/skein_base.c
@@ -8,10 +8,9 @@
8** 8**
9************************************************************************/ 9************************************************************************/
10 10
11#define SKEIN_PORT_CODE /* instantiate any code in skein_port.h */
12
13#include <linux/string.h> /* get the memcpy/memset functions */ 11#include <linux/string.h> /* get the memcpy/memset functions */
14#include "skein.h" /* get the Skein API definitions */ 12#include <linux/export.h>
13#include "skein_base.h" /* get the Skein API definitions */
15#include "skein_iv.h" /* get precomputed IVs */ 14#include "skein_iv.h" /* get precomputed IVs */
16#include "skein_block.h" 15#include "skein_block.h"
17 16
@@ -125,8 +124,6 @@ int skein_256_init_ext(struct skein_256_ctx *ctx, size_t hash_bit_len,
125 /* tree hash config info (or SKEIN_CFG_TREE_INFO_SEQUENTIAL) */ 124 /* tree hash config info (or SKEIN_CFG_TREE_INFO_SEQUENTIAL) */
126 cfg.w[2] = skein_swap64(tree_info); 125 cfg.w[2] = skein_swap64(tree_info);
127 126
128 skein_show_key(256, &ctx->h, key, key_bytes);
129
130 /* compute the initial chaining values from config block */ 127 /* compute the initial chaining values from config block */
131 skein_256_process_block(ctx, cfg.b, 1, SKEIN_CFG_STR_LEN); 128 skein_256_process_block(ctx, cfg.b, 1, SKEIN_CFG_STR_LEN);
132 129
@@ -233,8 +230,6 @@ int skein_256_final(struct skein_256_ctx *ctx, u8 *hash_val)
233 /* "output" the ctr mode bytes */ 230 /* "output" the ctr mode bytes */
234 skein_put64_lsb_first(hash_val+i*SKEIN_256_BLOCK_BYTES, ctx->x, 231 skein_put64_lsb_first(hash_val+i*SKEIN_256_BLOCK_BYTES, ctx->x,
235 n); 232 n);
236 skein_show_final(256, &ctx->h, n,
237 hash_val+i*SKEIN_256_BLOCK_BYTES);
238 /* restore the counter mode key for next time */ 233 /* restore the counter mode key for next time */
239 memcpy(ctx->x, x, sizeof(x)); 234 memcpy(ctx->x, x, sizeof(x));
240 } 235 }
@@ -354,8 +349,6 @@ int skein_512_init_ext(struct skein_512_ctx *ctx, size_t hash_bit_len,
354 /* tree hash config info (or SKEIN_CFG_TREE_INFO_SEQUENTIAL) */ 349 /* tree hash config info (or SKEIN_CFG_TREE_INFO_SEQUENTIAL) */
355 cfg.w[2] = skein_swap64(tree_info); 350 cfg.w[2] = skein_swap64(tree_info);
356 351
357 skein_show_key(512, &ctx->h, key, key_bytes);
358
359 /* compute the initial chaining values from config block */ 352 /* compute the initial chaining values from config block */
360 skein_512_process_block(ctx, cfg.b, 1, SKEIN_CFG_STR_LEN); 353 skein_512_process_block(ctx, cfg.b, 1, SKEIN_CFG_STR_LEN);
361 354
@@ -462,8 +455,6 @@ int skein_512_final(struct skein_512_ctx *ctx, u8 *hash_val)
462 /* "output" the ctr mode bytes */ 455 /* "output" the ctr mode bytes */
463 skein_put64_lsb_first(hash_val+i*SKEIN_512_BLOCK_BYTES, ctx->x, 456 skein_put64_lsb_first(hash_val+i*SKEIN_512_BLOCK_BYTES, ctx->x,
464 n); 457 n);
465 skein_show_final(512, &ctx->h, n,
466 hash_val+i*SKEIN_512_BLOCK_BYTES);
467 /* restore the counter mode key for next time */ 458 /* restore the counter mode key for next time */
468 memcpy(ctx->x, x, sizeof(x)); 459 memcpy(ctx->x, x, sizeof(x));
469 } 460 }
@@ -578,8 +569,6 @@ int skein_1024_init_ext(struct skein_1024_ctx *ctx, size_t hash_bit_len,
578 /* tree hash config info (or SKEIN_CFG_TREE_INFO_SEQUENTIAL) */ 569 /* tree hash config info (or SKEIN_CFG_TREE_INFO_SEQUENTIAL) */
579 cfg.w[2] = skein_swap64(tree_info); 570 cfg.w[2] = skein_swap64(tree_info);
580 571
581 skein_show_key(1024, &ctx->h, key, key_bytes);
582
583 /* compute the initial chaining values from config block */ 572 /* compute the initial chaining values from config block */
584 skein_1024_process_block(ctx, cfg.b, 1, SKEIN_CFG_STR_LEN); 573 skein_1024_process_block(ctx, cfg.b, 1, SKEIN_CFG_STR_LEN);
585 574
@@ -686,8 +675,6 @@ int skein_1024_final(struct skein_1024_ctx *ctx, u8 *hash_val)
686 /* "output" the ctr mode bytes */ 675 /* "output" the ctr mode bytes */
687 skein_put64_lsb_first(hash_val+i*SKEIN_1024_BLOCK_BYTES, ctx->x, 676 skein_put64_lsb_first(hash_val+i*SKEIN_1024_BLOCK_BYTES, ctx->x,
688 n); 677 n);
689 skein_show_final(1024, &ctx->h, n,
690 hash_val+i*SKEIN_1024_BLOCK_BYTES);
691 /* restore the counter mode key for next time */ 678 /* restore the counter mode key for next time */
692 memcpy(ctx->x, x, sizeof(x)); 679 memcpy(ctx->x, x, sizeof(x));
693 } 680 }
@@ -795,8 +782,6 @@ int skein_256_output(struct skein_256_ctx *ctx, u8 *hash_val)
795 /* "output" the ctr mode bytes */ 782 /* "output" the ctr mode bytes */
796 skein_put64_lsb_first(hash_val+i*SKEIN_256_BLOCK_BYTES, ctx->x, 783 skein_put64_lsb_first(hash_val+i*SKEIN_256_BLOCK_BYTES, ctx->x,
797 n); 784 n);
798 skein_show_final(256, &ctx->h, n,
799 hash_val+i*SKEIN_256_BLOCK_BYTES);
800 /* restore the counter mode key for next time */ 785 /* restore the counter mode key for next time */
801 memcpy(ctx->x, x, sizeof(x)); 786 memcpy(ctx->x, x, sizeof(x));
802 } 787 }
@@ -834,8 +819,6 @@ int skein_512_output(struct skein_512_ctx *ctx, u8 *hash_val)
834 /* "output" the ctr mode bytes */ 819 /* "output" the ctr mode bytes */
835 skein_put64_lsb_first(hash_val+i*SKEIN_512_BLOCK_BYTES, ctx->x, 820 skein_put64_lsb_first(hash_val+i*SKEIN_512_BLOCK_BYTES, ctx->x,
836 n); 821 n);
837 skein_show_final(256, &ctx->h, n,
838 hash_val+i*SKEIN_512_BLOCK_BYTES);
839 /* restore the counter mode key for next time */ 822 /* restore the counter mode key for next time */
840 memcpy(ctx->x, x, sizeof(x)); 823 memcpy(ctx->x, x, sizeof(x));
841 } 824 }
@@ -873,8 +856,6 @@ int skein_1024_output(struct skein_1024_ctx *ctx, u8 *hash_val)
873 /* "output" the ctr mode bytes */ 856 /* "output" the ctr mode bytes */
874 skein_put64_lsb_first(hash_val+i*SKEIN_1024_BLOCK_BYTES, ctx->x, 857 skein_put64_lsb_first(hash_val+i*SKEIN_1024_BLOCK_BYTES, ctx->x,
875 n); 858 n);
876 skein_show_final(256, &ctx->h, n,
877 hash_val+i*SKEIN_1024_BLOCK_BYTES);
878 /* restore the counter mode key for next time */ 859 /* restore the counter mode key for next time */
879 memcpy(ctx->x, x, sizeof(x)); 860 memcpy(ctx->x, x, sizeof(x));
880 } 861 }
diff --git a/drivers/staging/skein/skein.h b/drivers/staging/skein/skein_base.h
index e6669f196e5d..3c7f8ad3627d 100644
--- a/drivers/staging/skein/skein.h
+++ b/drivers/staging/skein/skein_base.h
@@ -15,10 +15,6 @@
15** 15**
16** The "default" note explains what happens when the switch is not defined. 16** The "default" note explains what happens when the switch is not defined.
17** 17**
18** SKEIN_DEBUG -- make callouts from inside Skein code
19** to examine/display intermediate values.
20** [default: no callouts (no overhead)]
21**
22** SKEIN_ERR_CHECK -- how error checking is handled inside Skein 18** SKEIN_ERR_CHECK -- how error checking is handled inside Skein
23** code. If not defined, most error checking 19** code. If not defined, most error checking
24** is disabled (for performance). Otherwise, 20** is disabled (for performance). Otherwise,
@@ -28,9 +24,10 @@
28** 24**
29***************************************************************************/ 25***************************************************************************/
30 26
31#ifndef rotl_64 27/*Skein digest sizes for crypto api*/
32#define rotl_64(x, N) (((x) << (N)) | ((x) >> (64-(N)))) 28#define SKEIN256_DIGEST_BIT_SIZE 256
33#endif 29#define SKEIN512_DIGEST_BIT_SIZE 512
30#define SKEIN1024_DIGEST_BIT_SIZE 1024
34 31
35/* below two prototype assume we are handed aligned data */ 32/* below two prototype assume we are handed aligned data */
36#define skein_put64_lsb_first(dst08, src64, b_cnt) memcpy(dst08, src64, b_cnt) 33#define skein_put64_lsb_first(dst08, src64, b_cnt) memcpy(dst08, src64, b_cnt)
@@ -44,12 +41,12 @@ enum {
44 SKEIN_BAD_HASHLEN = 2 41 SKEIN_BAD_HASHLEN = 2
45}; 42};
46 43
47#define SKEIN_MODIFIER_WORDS (2) /* number of modifier (tweak) words */ 44#define SKEIN_MODIFIER_WORDS 2 /* number of modifier (tweak) words */
48 45
49#define SKEIN_256_STATE_WORDS (4) 46#define SKEIN_256_STATE_WORDS 4
50#define SKEIN_512_STATE_WORDS (8) 47#define SKEIN_512_STATE_WORDS 8
51#define SKEIN_1024_STATE_WORDS (16) 48#define SKEIN_1024_STATE_WORDS 16
52#define SKEIN_MAX_STATE_WORDS (16) 49#define SKEIN_MAX_STATE_WORDS 16
53 50
54#define SKEIN_256_STATE_BYTES (8*SKEIN_256_STATE_WORDS) 51#define SKEIN_256_STATE_BYTES (8*SKEIN_256_STATE_WORDS)
55#define SKEIN_512_STATE_BYTES (8*SKEIN_512_STATE_WORDS) 52#define SKEIN_512_STATE_BYTES (8*SKEIN_512_STATE_WORDS)
@@ -87,6 +84,11 @@ struct skein_1024_ctx { /* 1024-bit Skein hash context structure */
87 u8 b[SKEIN_1024_BLOCK_BYTES]; /* partial block buf (8-byte aligned) */ 84 u8 b[SKEIN_1024_BLOCK_BYTES]; /* partial block buf (8-byte aligned) */
88}; 85};
89 86
87static inline u64 rotl_64(u64 x, u8 N)
88{
89 return (x << N) | (x >> (64 - N));
90}
91
90/* Skein APIs for (incremental) "straight hashing" */ 92/* Skein APIs for (incremental) "straight hashing" */
91int skein_256_init(struct skein_256_ctx *ctx, size_t hash_bit_len); 93int skein_256_init(struct skein_256_ctx *ctx, size_t hash_bit_len);
92int skein_512_init(struct skein_512_ctx *ctx, size_t hash_bit_len); 94int skein_512_init(struct skein_512_ctx *ctx, size_t hash_bit_len);
@@ -273,19 +275,6 @@ int skein_1024_output(struct skein_1024_ctx *ctx, u8 *hash_val);
273 (hdr).tweak[1] |= SKEIN_T1_TREE_LEVEL(height); \ 275 (hdr).tweak[1] |= SKEIN_T1_TREE_LEVEL(height); \
274 } 276 }
275 277
276/*****************************************************************
277** "Internal" Skein definitions for debugging and error checking
278******************************************************************/
279#ifdef SKEIN_DEBUG /* examine/display intermediate values? */
280#include "skein_debug.h"
281#else /* default is no callouts */
282#define skein_show_block(bits, ctx, x, blk_ptr, w_ptr, ks_event_ptr, ks_odd_ptr)
283#define skein_show_round(bits, ctx, r, x)
284#define skein_show_r_ptr(bits, ctx, r, x_ptr)
285#define skein_show_final(bits, ctx, cnt, out_ptr)
286#define skein_show_key(bits, ctx, key, key_bytes)
287#endif
288
289/* ignore all asserts, for performance */ 278/* ignore all asserts, for performance */
290#define skein_assert_ret(x, ret_code) 279#define skein_assert_ret(x, ret_code)
291#define skein_assert(x) 280#define skein_assert(x)
diff --git a/drivers/staging/skein/skein_block.c b/drivers/staging/skein/skein_block.c
index 616364faf92e..66261ab25c88 100644
--- a/drivers/staging/skein/skein_block.c
+++ b/drivers/staging/skein/skein_block.c
@@ -15,7 +15,7 @@
15************************************************************************/ 15************************************************************************/
16 16
17#include <linux/string.h> 17#include <linux/string.h>
18#include "skein.h" 18#include "skein_base.h"
19#include "skein_block.h" 19#include "skein_block.h"
20 20
21#ifndef SKEIN_USE_ASM 21#ifndef SKEIN_USE_ASM
@@ -26,32 +26,27 @@
26#define SKEIN_LOOP 001 /* default: unroll 256 and 512, but not 1024 */ 26#define SKEIN_LOOP 001 /* default: unroll 256 and 512, but not 1024 */
27#endif 27#endif
28 28
29#define BLK_BITS (WCNT*64) /* some useful definitions for code here */ 29#define BLK_BITS (WCNT * 64) /* some useful definitions for code here */
30#define KW_TWK_BASE (0) 30#define KW_TWK_BASE (0)
31#define KW_KEY_BASE (3) 31#define KW_KEY_BASE (3)
32#define ks (kw + KW_KEY_BASE) 32#define ks (kw + KW_KEY_BASE)
33#define ts (kw + KW_TWK_BASE) 33#define ts (kw + KW_TWK_BASE)
34 34
35#ifdef SKEIN_DEBUG 35#ifdef SKEIN_DEBUG
36#define debug_save_tweak(ctx) { \ 36#define debug_save_tweak(ctx) \
37 ctx->h.tweak[0] = ts[0]; ctx->h.tweak[1] = ts[1]; } 37{ \
38 ctx->h.tweak[0] = ts[0]; \
39 ctx->h.tweak[1] = ts[1]; \
40}
38#else 41#else
39#define debug_save_tweak(ctx) 42#define debug_save_tweak(ctx)
40#endif 43#endif
41 44
42/***************************** SKEIN_256 ******************************/
43#if !(SKEIN_USE_ASM & 256) 45#if !(SKEIN_USE_ASM & 256)
44void skein_256_process_block(struct skein_256_ctx *ctx, const u8 *blk_ptr,
45 size_t blk_cnt, size_t byte_cnt_add)
46 { /* do it in C */
47 enum {
48 WCNT = SKEIN_256_STATE_WORDS
49 };
50#undef RCNT 46#undef RCNT
51#define RCNT (SKEIN_256_ROUNDS_TOTAL/8) 47#define RCNT (SKEIN_256_ROUNDS_TOTAL / 8)
52
53#ifdef SKEIN_LOOP /* configure how much to unroll the loop */ 48#ifdef SKEIN_LOOP /* configure how much to unroll the loop */
54#define SKEIN_UNROLL_256 (((SKEIN_LOOP)/100)%10) 49#define SKEIN_UNROLL_256 (((SKEIN_LOOP) / 100) % 10)
55#else 50#else
56#define SKEIN_UNROLL_256 (0) 51#define SKEIN_UNROLL_256 (0)
57#endif 52#endif
@@ -60,17 +55,329 @@ void skein_256_process_block(struct skein_256_ctx *ctx, const u8 *blk_ptr,
60#if (RCNT % SKEIN_UNROLL_256) 55#if (RCNT % SKEIN_UNROLL_256)
61#error "Invalid SKEIN_UNROLL_256" /* sanity check on unroll count */ 56#error "Invalid SKEIN_UNROLL_256" /* sanity check on unroll count */
62#endif 57#endif
63 size_t r; 58#endif
64 u64 kw[WCNT+4+RCNT*2]; /* key schedule: chaining vars + tweak + "rot"*/ 59#define ROUND256(p0, p1, p2, p3, ROT, r_num) \
60do { \
61 X##p0 += X##p1; \
62 X##p1 = rotl_64(X##p1, ROT##_0); \
63 X##p1 ^= X##p0; \
64 X##p2 += X##p3; \
65 X##p3 = rotl_64(X##p3, ROT##_1); \
66 X##p3 ^= X##p2; \
67} while (0)
68
69#if SKEIN_UNROLL_256 == 0
70#define R256(p0, p1, p2, p3, ROT, r_num) /* fully unrolled */ \
71do { \
72 ROUND256(p0, p1, p2, p3, ROT, r_num); \
73} while (0)
74
75#define I256(R) \
76do { \
77 /* inject the key schedule value */ \
78 X0 += ks[((R) + 1) % 5]; \
79 X1 += ks[((R) + 2) % 5] + ts[((R) + 1) % 3]; \
80 X2 += ks[((R) + 3) % 5] + ts[((R) + 2) % 3]; \
81 X3 += ks[((R) + 4) % 5] + (R) + 1; \
82} while (0)
65#else 83#else
66 u64 kw[WCNT+4]; /* key schedule words : chaining vars + tweak */ 84/* looping version */
85#define R256(p0, p1, p2, p3, ROT, r_num) \
86do { \
87 ROUND256(p0, p1, p2, p3, ROT, r_num); \
88} while (0)
89
90#define I256(R) \
91do { \
92 /* inject the key schedule value */ \
93 X0 += ks[r + (R) + 0]; \
94 X1 += ks[r + (R) + 1] + ts[r + (R) + 0]; \
95 X2 += ks[r + (R) + 2] + ts[r + (R) + 1]; \
96 X3 += ks[r + (R) + 3] + r + (R); \
97 /* rotate key schedule */ \
98 ks[r + (R) + 4] = ks[r + (R) - 1]; \
99 ts[r + (R) + 2] = ts[r + (R) - 1]; \
100} while (0)
101#endif
102#define R256_8_ROUNDS(R) \
103do { \
104 R256(0, 1, 2, 3, R_256_0, 8 * (R) + 1); \
105 R256(0, 3, 2, 1, R_256_1, 8 * (R) + 2); \
106 R256(0, 1, 2, 3, R_256_2, 8 * (R) + 3); \
107 R256(0, 3, 2, 1, R_256_3, 8 * (R) + 4); \
108 I256(2 * (R)); \
109 R256(0, 1, 2, 3, R_256_4, 8 * (R) + 5); \
110 R256(0, 3, 2, 1, R_256_5, 8 * (R) + 6); \
111 R256(0, 1, 2, 3, R_256_6, 8 * (R) + 7); \
112 R256(0, 3, 2, 1, R_256_7, 8 * (R) + 8); \
113 I256(2 * (R) + 1); \
114} while (0)
115
116#define R256_UNROLL_R(NN) \
117 ((SKEIN_UNROLL_256 == 0 && \
118 SKEIN_256_ROUNDS_TOTAL / 8 > (NN)) || \
119 (SKEIN_UNROLL_256 > (NN)))
120
121#if (SKEIN_UNROLL_256 > 14)
122#error "need more unrolling in skein_256_process_block"
123#endif
124#endif
125
126#if !(SKEIN_USE_ASM & 512)
127#undef RCNT
128#define RCNT (SKEIN_512_ROUNDS_TOTAL/8)
129
130#ifdef SKEIN_LOOP /* configure how much to unroll the loop */
131#define SKEIN_UNROLL_512 (((SKEIN_LOOP)/10)%10)
132#else
133#define SKEIN_UNROLL_512 (0)
134#endif
135
136#if SKEIN_UNROLL_512
137#if (RCNT % SKEIN_UNROLL_512)
138#error "Invalid SKEIN_UNROLL_512" /* sanity check on unroll count */
139#endif
140#endif
141#define ROUND512(p0, p1, p2, p3, p4, p5, p6, p7, ROT, r_num) \
142do { \
143 X##p0 += X##p1; \
144 X##p1 = rotl_64(X##p1, ROT##_0); \
145 X##p1 ^= X##p0; \
146 X##p2 += X##p3; \
147 X##p3 = rotl_64(X##p3, ROT##_1); \
148 X##p3 ^= X##p2; \
149 X##p4 += X##p5; \
150 X##p5 = rotl_64(X##p5, ROT##_2); \
151 X##p5 ^= X##p4; \
152 X##p6 += X##p7; X##p7 = rotl_64(X##p7, ROT##_3); \
153 X##p7 ^= X##p6; \
154} while (0)
155
156#if SKEIN_UNROLL_512 == 0
157#define R512(p0, p1, p2, p3, p4, p5, p6, p7, ROT, r_num) /* unrolled */ \
158do { \
159 ROUND512(p0, p1, p2, p3, p4, p5, p6, p7, ROT, r_num); \
160} while (0)
161
162#define I512(R) \
163do { \
164 /* inject the key schedule value */ \
165 X0 += ks[((R) + 1) % 9]; \
166 X1 += ks[((R) + 2) % 9]; \
167 X2 += ks[((R) + 3) % 9]; \
168 X3 += ks[((R) + 4) % 9]; \
169 X4 += ks[((R) + 5) % 9]; \
170 X5 += ks[((R) + 6) % 9] + ts[((R) + 1) % 3]; \
171 X6 += ks[((R) + 7) % 9] + ts[((R) + 2) % 3]; \
172 X7 += ks[((R) + 8) % 9] + (R) + 1; \
173} while (0)
174
175#else /* looping version */
176#define R512(p0, p1, p2, p3, p4, p5, p6, p7, ROT, r_num) \
177do { \
178 ROUND512(p0, p1, p2, p3, p4, p5, p6, p7, ROT, r_num); \
179} while (0)
180
181#define I512(R) \
182do { \
183 /* inject the key schedule value */ \
184 X0 += ks[r + (R) + 0]; \
185 X1 += ks[r + (R) + 1]; \
186 X2 += ks[r + (R) + 2]; \
187 X3 += ks[r + (R) + 3]; \
188 X4 += ks[r + (R) + 4]; \
189 X5 += ks[r + (R) + 5] + ts[r + (R) + 0]; \
190 X6 += ks[r + (R) + 6] + ts[r + (R) + 1]; \
191 X7 += ks[r + (R) + 7] + r + (R); \
192 /* rotate key schedule */ \
193 ks[r + (R) + 8] = ks[r + (R) - 1]; \
194 ts[r + (R) + 2] = ts[r + (R) - 1]; \
195} while (0)
196#endif /* end of looped code definitions */
197#define R512_8_ROUNDS(R) /* do 8 full rounds */ \
198do { \
199 R512(0, 1, 2, 3, 4, 5, 6, 7, R_512_0, 8 * (R) + 1); \
200 R512(2, 1, 4, 7, 6, 5, 0, 3, R_512_1, 8 * (R) + 2); \
201 R512(4, 1, 6, 3, 0, 5, 2, 7, R_512_2, 8 * (R) + 3); \
202 R512(6, 1, 0, 7, 2, 5, 4, 3, R_512_3, 8 * (R) + 4); \
203 I512(2 * (R)); \
204 R512(0, 1, 2, 3, 4, 5, 6, 7, R_512_4, 8 * (R) + 5); \
205 R512(2, 1, 4, 7, 6, 5, 0, 3, R_512_5, 8 * (R) + 6); \
206 R512(4, 1, 6, 3, 0, 5, 2, 7, R_512_6, 8 * (R) + 7); \
207 R512(6, 1, 0, 7, 2, 5, 4, 3, R_512_7, 8 * (R) + 8); \
208 I512(2 * (R) + 1); /* and key injection */ \
209} while (0)
210#define R512_UNROLL_R(NN) \
211 ((SKEIN_UNROLL_512 == 0 && \
212 SKEIN_512_ROUNDS_TOTAL/8 > (NN)) || \
213 (SKEIN_UNROLL_512 > (NN)))
214
215#if (SKEIN_UNROLL_512 > 14)
216#error "need more unrolling in skein_512_process_block"
217#endif
218#endif
219
220#if !(SKEIN_USE_ASM & 1024)
221#undef RCNT
222#define RCNT (SKEIN_1024_ROUNDS_TOTAL/8)
223#ifdef SKEIN_LOOP /* configure how much to unroll the loop */
224#define SKEIN_UNROLL_1024 ((SKEIN_LOOP)%10)
225#else
226#define SKEIN_UNROLL_1024 (0)
227#endif
228
229#if (SKEIN_UNROLL_1024 != 0)
230#if (RCNT % SKEIN_UNROLL_1024)
231#error "Invalid SKEIN_UNROLL_1024" /* sanity check on unroll count */
232#endif
233#endif
234#define ROUND1024(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, pA, pB, pC, pD, pE, \
235 pF, ROT, r_num) \
236do { \
237 X##p0 += X##p1; \
238 X##p1 = rotl_64(X##p1, ROT##_0); \
239 X##p1 ^= X##p0; \
240 X##p2 += X##p3; \
241 X##p3 = rotl_64(X##p3, ROT##_1); \
242 X##p3 ^= X##p2; \
243 X##p4 += X##p5; \
244 X##p5 = rotl_64(X##p5, ROT##_2); \
245 X##p5 ^= X##p4; \
246 X##p6 += X##p7; \
247 X##p7 = rotl_64(X##p7, ROT##_3); \
248 X##p7 ^= X##p6; \
249 X##p8 += X##p9; \
250 X##p9 = rotl_64(X##p9, ROT##_4); \
251 X##p9 ^= X##p8; \
252 X##pA += X##pB; \
253 X##pB = rotl_64(X##pB, ROT##_5); \
254 X##pB ^= X##pA; \
255 X##pC += X##pD; \
256 X##pD = rotl_64(X##pD, ROT##_6); \
257 X##pD ^= X##pC; \
258 X##pE += X##pF; \
259 X##pF = rotl_64(X##pF, ROT##_7); \
260 X##pF ^= X##pE; \
261} while (0)
262
263#if SKEIN_UNROLL_1024 == 0
264#define R1024(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, pA, pB, pC, pD, pE, pF, \
265 ROT, rn) \
266do { \
267 ROUND1024(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, pA, pB, pC, pD, pE, \
268 pF, ROT, rn); \
269} while (0)
270
271#define I1024(R) \
272do { \
273 /* inject the key schedule value */ \
274 X00 += ks[((R) + 1) % 17]; \
275 X01 += ks[((R) + 2) % 17]; \
276 X02 += ks[((R) + 3) % 17]; \
277 X03 += ks[((R) + 4) % 17]; \
278 X04 += ks[((R) + 5) % 17]; \
279 X05 += ks[((R) + 6) % 17]; \
280 X06 += ks[((R) + 7) % 17]; \
281 X07 += ks[((R) + 8) % 17]; \
282 X08 += ks[((R) + 9) % 17]; \
283 X09 += ks[((R) + 10) % 17]; \
284 X10 += ks[((R) + 11) % 17]; \
285 X11 += ks[((R) + 12) % 17]; \
286 X12 += ks[((R) + 13) % 17]; \
287 X13 += ks[((R) + 14) % 17] + ts[((R) + 1) % 3]; \
288 X14 += ks[((R) + 15) % 17] + ts[((R) + 2) % 3]; \
289 X15 += ks[((R) + 16) % 17] + (R) + 1; \
290} while (0)
291#else /* looping version */
292#define R1024(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, pA, pB, pC, pD, pE, pF, \
293 ROT, rn) \
294do { \
295 ROUND1024(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, pA, pB, pC, pD, pE, \
296 pF, ROT, rn); \
297} while (0)
298
299#define I1024(R) \
300do { \
301 /* inject the key schedule value */ \
302 X00 += ks[r + (R) + 0]; \
303 X01 += ks[r + (R) + 1]; \
304 X02 += ks[r + (R) + 2]; \
305 X03 += ks[r + (R) + 3]; \
306 X04 += ks[r + (R) + 4]; \
307 X05 += ks[r + (R) + 5]; \
308 X06 += ks[r + (R) + 6]; \
309 X07 += ks[r + (R) + 7]; \
310 X08 += ks[r + (R) + 8]; \
311 X09 += ks[r + (R) + 9]; \
312 X10 += ks[r + (R) + 10]; \
313 X11 += ks[r + (R) + 11]; \
314 X12 += ks[r + (R) + 12]; \
315 X13 += ks[r + (R) + 13] + ts[r + (R) + 0]; \
316 X14 += ks[r + (R) + 14] + ts[r + (R) + 1]; \
317 X15 += ks[r + (R) + 15] + r + (R); \
318 /* rotate key schedule */ \
319 ks[r + (R) + 16] = ks[r + (R) - 1]; \
320 ts[r + (R) + 2] = ts[r + (R) - 1]; \
321} while (0)
322
323#endif
324#define R1024_8_ROUNDS(R) \
325do { \
326 R1024(00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, \
327 R1024_0, 8*(R) + 1); \
328 R1024(00, 09, 02, 13, 06, 11, 04, 15, 10, 07, 12, 03, 14, 05, 08, 01, \
329 R1024_1, 8*(R) + 2); \
330 R1024(00, 07, 02, 05, 04, 03, 06, 01, 12, 15, 14, 13, 08, 11, 10, 09, \
331 R1024_2, 8*(R) + 3); \
332 R1024(00, 15, 02, 11, 06, 13, 04, 09, 14, 01, 08, 05, 10, 03, 12, 07, \
333 R1024_3, 8*(R) + 4); \
334 I1024(2*(R)); \
335 R1024(00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, \
336 R1024_4, 8*(R) + 5); \
337 R1024(00, 09, 02, 13, 06, 11, 04, 15, 10, 07, 12, 03, 14, 05, 08, 01, \
338 R1024_5, 8*(R) + 6); \
339 R1024(00, 07, 02, 05, 04, 03, 06, 01, 12, 15, 14, 13, 08, 11, 10, 09, \
340 R1024_6, 8*(R) + 7); \
341 R1024(00, 15, 02, 11, 06, 13, 04, 09, 14, 01, 08, 05, 10, 03, 12, 07, \
342 R1024_7, 8*(R) + 8); \
343 I1024(2*(R)+1); \
344} while (0)
345
346#define R1024_UNROLL_R(NN) \
347 ((SKEIN_UNROLL_1024 == 0 && \
348 SKEIN_1024_ROUNDS_TOTAL/8 > (NN)) || \
349 (SKEIN_UNROLL_1024 > (NN)))
350
351#if (SKEIN_UNROLL_1024 > 14)
352#error "need more unrolling in Skein_1024_Process_Block"
353#endif
354#endif
355
356/***************************** SKEIN_256 ******************************/
357#if !(SKEIN_USE_ASM & 256)
358void skein_256_process_block(struct skein_256_ctx *ctx, const u8 *blk_ptr,
359 size_t blk_cnt, size_t byte_cnt_add)
360{ /* do it in C */
361 enum {
362 WCNT = SKEIN_256_STATE_WORDS
363 };
364 size_t r;
365#if SKEIN_UNROLL_256
366 /* key schedule: chaining vars + tweak + "rot"*/
367 u64 kw[WCNT+4+RCNT*2];
368#else
369 /* key schedule words : chaining vars + tweak */
370 u64 kw[WCNT+4];
67#endif 371#endif
68 u64 X0, X1, X2, X3; /* local copy of context vars, for speed */ 372 u64 X0, X1, X2, X3; /* local copy of context vars, for speed */
69 u64 w[WCNT]; /* local copy of input block */ 373 u64 w[WCNT]; /* local copy of input block */
70#ifdef SKEIN_DEBUG 374#ifdef SKEIN_DEBUG
71 const u64 *X_ptr[4]; /* use for debugging (help cc put Xn in regs) */ 375 const u64 *X_ptr[4]; /* use for debugging (help cc put Xn in regs) */
72 376
73 X_ptr[0] = &X0; X_ptr[1] = &X1; X_ptr[2] = &X2; X_ptr[3] = &X3; 377 X_ptr[0] = &X0;
378 X_ptr[1] = &X1;
379 X_ptr[2] = &X2;
380 X_ptr[3] = &X3;
74#endif 381#endif
75 skein_assert(blk_cnt != 0); /* never call with blk_cnt == 0! */ 382 skein_assert(blk_cnt != 0); /* never call with blk_cnt == 0! */
76 ts[0] = ctx->h.tweak[0]; 383 ts[0] = ctx->h.tweak[0];
@@ -94,132 +401,62 @@ void skein_256_process_block(struct skein_256_ctx *ctx, const u8 *blk_ptr,
94 /* get input block in little-endian format */ 401 /* get input block in little-endian format */
95 skein_get64_lsb_first(w, blk_ptr, WCNT); 402 skein_get64_lsb_first(w, blk_ptr, WCNT);
96 debug_save_tweak(ctx); 403 debug_save_tweak(ctx);
97 skein_show_block(BLK_BITS, &ctx->h, ctx->x, blk_ptr, w, ks, ts);
98 404
99 X0 = w[0] + ks[0]; /* do the first full key injection */ 405 /* do the first full key injection */
406 X0 = w[0] + ks[0];
100 X1 = w[1] + ks[1] + ts[0]; 407 X1 = w[1] + ks[1] + ts[0];
101 X2 = w[2] + ks[2] + ts[1]; 408 X2 = w[2] + ks[2] + ts[1];
102 X3 = w[3] + ks[3]; 409 X3 = w[3] + ks[3];
103 410
104 /* show starting state values */
105 skein_show_r_ptr(BLK_BITS, &ctx->h, SKEIN_RND_KEY_INITIAL,
106 x_ptr);
107
108 blk_ptr += SKEIN_256_BLOCK_BYTES; 411 blk_ptr += SKEIN_256_BLOCK_BYTES;
109 412
110 /* run the rounds */ 413 /* run the rounds */
111 414 for (r = 1;
112#define ROUND256(p0, p1, p2, p3, ROT, r_num) \ 415 r < (SKEIN_UNROLL_256 ? 2 * RCNT : 2);
113do { \ 416 r += (SKEIN_UNROLL_256 ? 2 * SKEIN_UNROLL_256 : 1)) {
114 X##p0 += X##p1; X##p1 = rotl_64(X##p1, ROT##_0); X##p1 ^= X##p0; \ 417 R256_8_ROUNDS(0);
115 X##p2 += X##p3; X##p3 = rotl_64(X##p3, ROT##_1); X##p3 ^= X##p2; \ 418#if R256_UNROLL_R(1)
116} while (0) 419 R256_8_ROUNDS(1);
117 420#endif
118#if SKEIN_UNROLL_256 == 0 421#if R256_UNROLL_R(2)
119#define R256(p0, p1, p2, p3, ROT, r_num) /* fully unrolled */ \ 422 R256_8_ROUNDS(2);
120do { \ 423#endif
121 ROUND256(p0, p1, p2, p3, ROT, r_num); \ 424#if R256_UNROLL_R(3)
122 skein_show_r_ptr(BLK_BITS, &ctx->h, r_num, X_ptr); \ 425 R256_8_ROUNDS(3);
123} while (0) 426#endif
124 427#if R256_UNROLL_R(4)
125#define I256(R) \ 428 R256_8_ROUNDS(4);
126do { \ 429#endif
127 /* inject the key schedule value */ \ 430#if R256_UNROLL_R(5)
128 X0 += ks[((R)+1) % 5]; \ 431 R256_8_ROUNDS(5);
129 X1 += ks[((R)+2) % 5] + ts[((R)+1) % 3]; \ 432#endif
130 X2 += ks[((R)+3) % 5] + ts[((R)+2) % 3]; \ 433#if R256_UNROLL_R(6)
131 X3 += ks[((R)+4) % 5] + (R)+1; \ 434 R256_8_ROUNDS(6);
132 skein_show_r_ptr(BLK_BITS, &ctx->h, SKEIN_RND_KEY_INJECT, X_ptr); \ 435#endif
133} while (0) 436#if R256_UNROLL_R(7)
134#else /* looping version */ 437 R256_8_ROUNDS(7);
135#define R256(p0, p1, p2, p3, ROT, r_num) \ 438#endif
136do { \ 439#if R256_UNROLL_R(8)
137 ROUND256(p0, p1, p2, p3, ROT, r_num); \ 440 R256_8_ROUNDS(8);
138 skein_show_r_ptr(BLK_BITS, &ctx->h, 4 * (r - 1) + r_num, X_ptr); \ 441#endif
139} while (0) 442#if R256_UNROLL_R(9)
140 443 R256_8_ROUNDS(9);
141#define I256(R) \ 444#endif
142do { \ 445#if R256_UNROLL_R(10)
143 /* inject the key schedule value */ \ 446 R256_8_ROUNDS(10);
144 X0 += ks[r+(R)+0]; \ 447#endif
145 X1 += ks[r+(R)+1] + ts[r+(R)+0]; \ 448#if R256_UNROLL_R(11)
146 X2 += ks[r+(R)+2] + ts[r+(R)+1]; \ 449 R256_8_ROUNDS(11);
147 X3 += ks[r+(R)+3] + r+(R); \ 450#endif
148 /* rotate key schedule */ \ 451#if R256_UNROLL_R(12)
149 ks[r + (R) + 4] = ks[r + (R) - 1]; \ 452 R256_8_ROUNDS(12);
150 ts[r + (R) + 2] = ts[r + (R) - 1]; \ 453#endif
151 skein_show_r_ptr(BLK_BITS, &ctx->h, SKEIN_RND_KEY_INJECT, X_ptr); \ 454#if R256_UNROLL_R(13)
152} while (0) 455 R256_8_ROUNDS(13);
153 456#endif
154 for (r = 1; r < 2 * RCNT; r += 2 * SKEIN_UNROLL_256) 457#if R256_UNROLL_R(14)
458 R256_8_ROUNDS(14);
155#endif 459#endif
156 {
157#define R256_8_ROUNDS(R) \
158do { \
159 R256(0, 1, 2, 3, R_256_0, 8 * (R) + 1); \
160 R256(0, 3, 2, 1, R_256_1, 8 * (R) + 2); \
161 R256(0, 1, 2, 3, R_256_2, 8 * (R) + 3); \
162 R256(0, 3, 2, 1, R_256_3, 8 * (R) + 4); \
163 I256(2 * (R)); \
164 R256(0, 1, 2, 3, R_256_4, 8 * (R) + 5); \
165 R256(0, 3, 2, 1, R_256_5, 8 * (R) + 6); \
166 R256(0, 1, 2, 3, R_256_6, 8 * (R) + 7); \
167 R256(0, 3, 2, 1, R_256_7, 8 * (R) + 8); \
168 I256(2 * (R) + 1); \
169} while (0)
170
171 R256_8_ROUNDS(0);
172
173#define R256_UNROLL_R(NN) \
174 ((SKEIN_UNROLL_256 == 0 && \
175 SKEIN_256_ROUNDS_TOTAL/8 > (NN)) || \
176 (SKEIN_UNROLL_256 > (NN)))
177
178 #if R256_UNROLL_R(1)
179 R256_8_ROUNDS(1);
180 #endif
181 #if R256_UNROLL_R(2)
182 R256_8_ROUNDS(2);
183 #endif
184 #if R256_UNROLL_R(3)
185 R256_8_ROUNDS(3);
186 #endif
187 #if R256_UNROLL_R(4)
188 R256_8_ROUNDS(4);
189 #endif
190 #if R256_UNROLL_R(5)
191 R256_8_ROUNDS(5);
192 #endif
193 #if R256_UNROLL_R(6)
194 R256_8_ROUNDS(6);
195 #endif
196 #if R256_UNROLL_R(7)
197 R256_8_ROUNDS(7);
198 #endif
199 #if R256_UNROLL_R(8)
200 R256_8_ROUNDS(8);
201 #endif
202 #if R256_UNROLL_R(9)
203 R256_8_ROUNDS(9);
204 #endif
205 #if R256_UNROLL_R(10)
206 R256_8_ROUNDS(10);
207 #endif
208 #if R256_UNROLL_R(11)
209 R256_8_ROUNDS(11);
210 #endif
211 #if R256_UNROLL_R(12)
212 R256_8_ROUNDS(12);
213 #endif
214 #if R256_UNROLL_R(13)
215 R256_8_ROUNDS(13);
216 #endif
217 #if R256_UNROLL_R(14)
218 R256_8_ROUNDS(14);
219 #endif
220 #if (SKEIN_UNROLL_256 > 14)
221#error "need more unrolling in skein_256_process_block"
222 #endif
223 } 460 }
224 /* do the final "feedforward" xor, update context chaining */ 461 /* do the final "feedforward" xor, update context chaining */
225 ctx->x[0] = X0 ^ w[0]; 462 ctx->x[0] = X0 ^ w[0];
@@ -227,8 +464,6 @@ do { \
227 ctx->x[2] = X2 ^ w[2]; 464 ctx->x[2] = X2 ^ w[2];
228 ctx->x[3] = X3 ^ w[3]; 465 ctx->x[3] = X3 ^ w[3];
229 466
230 skein_show_round(BLK_BITS, &ctx->h, SKEIN_RND_FEED_FWD, ctx->x);
231
232 ts[1] &= ~SKEIN_T1_FLAG_FIRST; 467 ts[1] &= ~SKEIN_T1_FLAG_FIRST;
233 } while (--blk_cnt); 468 } while (--blk_cnt);
234 ctx->h.tweak[0] = ts[0]; 469 ctx->h.tweak[0] = ts[0];
@@ -256,20 +491,8 @@ void skein_512_process_block(struct skein_512_ctx *ctx, const u8 *blk_ptr,
256 enum { 491 enum {
257 WCNT = SKEIN_512_STATE_WORDS 492 WCNT = SKEIN_512_STATE_WORDS
258 }; 493 };
259#undef RCNT
260#define RCNT (SKEIN_512_ROUNDS_TOTAL/8)
261
262#ifdef SKEIN_LOOP /* configure how much to unroll the loop */
263#define SKEIN_UNROLL_512 (((SKEIN_LOOP)/10)%10)
264#else
265#define SKEIN_UNROLL_512 (0)
266#endif
267
268#if SKEIN_UNROLL_512
269#if (RCNT % SKEIN_UNROLL_512)
270#error "Invalid SKEIN_UNROLL_512" /* sanity check on unroll count */
271#endif
272 size_t r; 494 size_t r;
495#if SKEIN_UNROLL_512
273 u64 kw[WCNT+4+RCNT*2]; /* key sched: chaining vars + tweak + "rot"*/ 496 u64 kw[WCNT+4+RCNT*2]; /* key sched: chaining vars + tweak + "rot"*/
274#else 497#else
275 u64 kw[WCNT+4]; /* key schedule words : chaining vars + tweak */ 498 u64 kw[WCNT+4]; /* key schedule words : chaining vars + tweak */
@@ -279,8 +502,14 @@ void skein_512_process_block(struct skein_512_ctx *ctx, const u8 *blk_ptr,
279#ifdef SKEIN_DEBUG 502#ifdef SKEIN_DEBUG
280 const u64 *X_ptr[8]; /* use for debugging (help cc put Xn in regs) */ 503 const u64 *X_ptr[8]; /* use for debugging (help cc put Xn in regs) */
281 504
282 X_ptr[0] = &X0; X_ptr[1] = &X1; X_ptr[2] = &X2; X_ptr[3] = &X3; 505 X_ptr[0] = &X0;
283 X_ptr[4] = &X4; X_ptr[5] = &X5; X_ptr[6] = &X6; X_ptr[7] = &X7; 506 X_ptr[1] = &X1;
507 X_ptr[2] = &X2;
508 X_ptr[3] = &X3;
509 X_ptr[4] = &X4;
510 X_ptr[5] = &X5;
511 X_ptr[6] = &X6;
512 X_ptr[7] = &X7;
284#endif 513#endif
285 514
286 skein_assert(blk_cnt != 0); /* never call with blk_cnt == 0! */ 515 skein_assert(blk_cnt != 0); /* never call with blk_cnt == 0! */
@@ -310,143 +539,68 @@ void skein_512_process_block(struct skein_512_ctx *ctx, const u8 *blk_ptr,
310 /* get input block in little-endian format */ 539 /* get input block in little-endian format */
311 skein_get64_lsb_first(w, blk_ptr, WCNT); 540 skein_get64_lsb_first(w, blk_ptr, WCNT);
312 debug_save_tweak(ctx); 541 debug_save_tweak(ctx);
313 skein_show_block(BLK_BITS, &ctx->h, ctx->x, blk_ptr, w, ks, ts);
314 542
315 X0 = w[0] + ks[0]; /* do the first full key injection */ 543 /* do the first full key injection */
316 X1 = w[1] + ks[1]; 544 X0 = w[0] + ks[0];
317 X2 = w[2] + ks[2]; 545 X1 = w[1] + ks[1];
318 X3 = w[3] + ks[3]; 546 X2 = w[2] + ks[2];
319 X4 = w[4] + ks[4]; 547 X3 = w[3] + ks[3];
320 X5 = w[5] + ks[5] + ts[0]; 548 X4 = w[4] + ks[4];
321 X6 = w[6] + ks[6] + ts[1]; 549 X5 = w[5] + ks[5] + ts[0];
322 X7 = w[7] + ks[7]; 550 X6 = w[6] + ks[6] + ts[1];
551 X7 = w[7] + ks[7];
323 552
324 blk_ptr += SKEIN_512_BLOCK_BYTES; 553 blk_ptr += SKEIN_512_BLOCK_BYTES;
325 554
326 skein_show_r_ptr(BLK_BITS, &ctx->h, SKEIN_RND_KEY_INITIAL,
327 X_ptr);
328 /* run the rounds */ 555 /* run the rounds */
329#define ROUND512(p0, p1, p2, p3, p4, p5, p6, p7, ROT, r_num) \ 556 for (r = 1;
330do { \ 557 r < (SKEIN_UNROLL_512 ? 2 * RCNT : 2);
331 X##p0 += X##p1; X##p1 = rotl_64(X##p1, ROT##_0); X##p1 ^= X##p0; \ 558 r += (SKEIN_UNROLL_512 ? 2 * SKEIN_UNROLL_512 : 1)) {
332 X##p2 += X##p3; X##p3 = rotl_64(X##p3, ROT##_1); X##p3 ^= X##p2; \
333 X##p4 += X##p5; X##p5 = rotl_64(X##p5, ROT##_2); X##p5 ^= X##p4; \
334 X##p6 += X##p7; X##p7 = rotl_64(X##p7, ROT##_3); X##p7 ^= X##p6; \
335} while (0)
336
337#if SKEIN_UNROLL_512 == 0
338#define R512(p0, p1, p2, p3, p4, p5, p6, p7, ROT, r_num) /* unrolled */ \
339do { \
340 ROUND512(p0, p1, p2, p3, p4, p5, p6, p7, ROT, r_num) \
341 skein_show_r_ptr(BLK_BITS, &ctx->h, r_num, X_ptr); \
342} while (0)
343
344#define I512(R) \
345do { \
346 /* inject the key schedule value */ \
347 X0 += ks[((R) + 1) % 9]; \
348 X1 += ks[((R) + 2) % 9]; \
349 X2 += ks[((R) + 3) % 9]; \
350 X3 += ks[((R) + 4) % 9]; \
351 X4 += ks[((R) + 5) % 9]; \
352 X5 += ks[((R) + 6) % 9] + ts[((R) + 1) % 3]; \
353 X6 += ks[((R) + 7) % 9] + ts[((R) + 2) % 3]; \
354 X7 += ks[((R) + 8) % 9] + (R) + 1; \
355 skein_show_r_ptr(BLK_BITS, &ctx->h, SKEIN_RND_KEY_INJECT, X_ptr); \
356} while (0)
357#else /* looping version */
358#define R512(p0, p1, p2, p3, p4, p5, p6, p7, ROT, r_num) \
359do { \
360 ROUND512(p0, p1, p2, p3, p4, p5, p6, p7, ROT, r_num); \
361 skein_show_r_ptr(BLK_BITS, &ctx->h, 4 * (r - 1) + r_num, X_ptr); \
362} while (0)
363
364#define I512(R) \
365do { \
366 /* inject the key schedule value */ \
367 X0 += ks[r + (R) + 0]; \
368 X1 += ks[r + (R) + 1]; \
369 X2 += ks[r + (R) + 2]; \
370 X3 += ks[r + (R) + 3]; \
371 X4 += ks[r + (R) + 4]; \
372 X5 += ks[r + (R) + 5] + ts[r + (R) + 0]; \
373 X6 += ks[r + (R) + 6] + ts[r + (R) + 1]; \
374 X7 += ks[r + (R) + 7] + r + (R); \
375 /* rotate key schedule */ \
376 ks[r + (R) + 8] = ks[r + (R) - 1]; \
377 ts[r + (R) + 2] = ts[r + (R) - 1]; \
378 skein_show_r_ptr(BLK_BITS, &ctx->h, SKEIN_RND_KEY_INJECT, X_ptr); \
379} while (0)
380
381 for (r = 1; r < 2 * RCNT; r += 2 * SKEIN_UNROLL_512)
382#endif /* end of looped code definitions */
383 {
384#define R512_8_ROUNDS(R) /* do 8 full rounds */ \
385do { \
386 R512(0, 1, 2, 3, 4, 5, 6, 7, R_512_0, 8 * (R) + 1); \
387 R512(2, 1, 4, 7, 6, 5, 0, 3, R_512_1, 8 * (R) + 2); \
388 R512(4, 1, 6, 3, 0, 5, 2, 7, R_512_2, 8 * (R) + 3); \
389 R512(6, 1, 0, 7, 2, 5, 4, 3, R_512_3, 8 * (R) + 4); \
390 I512(2 * (R)); \
391 R512(0, 1, 2, 3, 4, 5, 6, 7, R_512_4, 8 * (R) + 5); \
392 R512(2, 1, 4, 7, 6, 5, 0, 3, R_512_5, 8 * (R) + 6); \
393 R512(4, 1, 6, 3, 0, 5, 2, 7, R_512_6, 8 * (R) + 7); \
394 R512(6, 1, 0, 7, 2, 5, 4, 3, R_512_7, 8 * (R) + 8); \
395 I512(2 * (R) + 1); /* and key injection */ \
396} while (0)
397 559
398 R512_8_ROUNDS(0); 560 R512_8_ROUNDS(0);
399 561
400#define R512_UNROLL_R(NN) \ 562#if R512_UNROLL_R(1)
401 ((SKEIN_UNROLL_512 == 0 && \
402 SKEIN_512_ROUNDS_TOTAL/8 > (NN)) || \
403 (SKEIN_UNROLL_512 > (NN)))
404
405 #if R512_UNROLL_R(1)
406 R512_8_ROUNDS(1); 563 R512_8_ROUNDS(1);
407 #endif 564#endif
408 #if R512_UNROLL_R(2) 565#if R512_UNROLL_R(2)
409 R512_8_ROUNDS(2); 566 R512_8_ROUNDS(2);
410 #endif 567#endif
411 #if R512_UNROLL_R(3) 568#if R512_UNROLL_R(3)
412 R512_8_ROUNDS(3); 569 R512_8_ROUNDS(3);
413 #endif 570#endif
414 #if R512_UNROLL_R(4) 571#if R512_UNROLL_R(4)
415 R512_8_ROUNDS(4); 572 R512_8_ROUNDS(4);
416 #endif 573#endif
417 #if R512_UNROLL_R(5) 574#if R512_UNROLL_R(5)
418 R512_8_ROUNDS(5); 575 R512_8_ROUNDS(5);
419 #endif 576#endif
420 #if R512_UNROLL_R(6) 577#if R512_UNROLL_R(6)
421 R512_8_ROUNDS(6); 578 R512_8_ROUNDS(6);
422 #endif 579#endif
423 #if R512_UNROLL_R(7) 580#if R512_UNROLL_R(7)
424 R512_8_ROUNDS(7); 581 R512_8_ROUNDS(7);
425 #endif 582#endif
426 #if R512_UNROLL_R(8) 583#if R512_UNROLL_R(8)
427 R512_8_ROUNDS(8); 584 R512_8_ROUNDS(8);
428 #endif 585#endif
429 #if R512_UNROLL_R(9) 586#if R512_UNROLL_R(9)
430 R512_8_ROUNDS(9); 587 R512_8_ROUNDS(9);
431 #endif 588#endif
432 #if R512_UNROLL_R(10) 589#if R512_UNROLL_R(10)
433 R512_8_ROUNDS(10); 590 R512_8_ROUNDS(10);
434 #endif 591#endif
435 #if R512_UNROLL_R(11) 592#if R512_UNROLL_R(11)
436 R512_8_ROUNDS(11); 593 R512_8_ROUNDS(11);
437 #endif 594#endif
438 #if R512_UNROLL_R(12) 595#if R512_UNROLL_R(12)
439 R512_8_ROUNDS(12); 596 R512_8_ROUNDS(12);
440 #endif 597#endif
441 #if R512_UNROLL_R(13) 598#if R512_UNROLL_R(13)
442 R512_8_ROUNDS(13); 599 R512_8_ROUNDS(13);
443 #endif 600#endif
444 #if R512_UNROLL_R(14) 601#if R512_UNROLL_R(14)
445 R512_8_ROUNDS(14); 602 R512_8_ROUNDS(14);
446 #endif 603#endif
447 #if (SKEIN_UNROLL_512 > 14)
448#error "need more unrolling in skein_512_process_block"
449 #endif
450 } 604 }
451 605
452 /* do the final "feedforward" xor, update context chaining */ 606 /* do the final "feedforward" xor, update context chaining */
@@ -458,7 +612,6 @@ do { \
458 ctx->x[5] = X5 ^ w[5]; 612 ctx->x[5] = X5 ^ w[5];
459 ctx->x[6] = X6 ^ w[6]; 613 ctx->x[6] = X6 ^ w[6];
460 ctx->x[7] = X7 ^ w[7]; 614 ctx->x[7] = X7 ^ w[7];
461 skein_show_round(BLK_BITS, &ctx->h, SKEIN_RND_FEED_FWD, ctx->x);
462 615
463 ts[1] &= ~SKEIN_T1_FLAG_FIRST; 616 ts[1] &= ~SKEIN_T1_FLAG_FIRST;
464 } while (--blk_cnt); 617 } while (--blk_cnt);
@@ -487,20 +640,8 @@ void skein_1024_process_block(struct skein_1024_ctx *ctx, const u8 *blk_ptr,
487 enum { 640 enum {
488 WCNT = SKEIN_1024_STATE_WORDS 641 WCNT = SKEIN_1024_STATE_WORDS
489 }; 642 };
490#undef RCNT
491#define RCNT (SKEIN_1024_ROUNDS_TOTAL/8)
492
493#ifdef SKEIN_LOOP /* configure how much to unroll the loop */
494#define SKEIN_UNROLL_1024 ((SKEIN_LOOP)%10)
495#else
496#define SKEIN_UNROLL_1024 (0)
497#endif
498
499#if (SKEIN_UNROLL_1024 != 0)
500#if (RCNT % SKEIN_UNROLL_1024)
501#error "Invalid SKEIN_UNROLL_1024" /* sanity check on unroll count */
502#endif
503 size_t r; 643 size_t r;
644#if (SKEIN_UNROLL_1024 != 0)
504 u64 kw[WCNT+4+RCNT*2]; /* key sched: chaining vars + tweak + "rot" */ 645 u64 kw[WCNT+4+RCNT*2]; /* key sched: chaining vars + tweak + "rot" */
505#else 646#else
506 u64 kw[WCNT+4]; /* key schedule words : chaining vars + tweak */ 647 u64 kw[WCNT+4]; /* key schedule words : chaining vars + tweak */
@@ -510,16 +651,6 @@ void skein_1024_process_block(struct skein_1024_ctx *ctx, const u8 *blk_ptr,
510 u64 X00, X01, X02, X03, X04, X05, X06, X07, 651 u64 X00, X01, X02, X03, X04, X05, X06, X07,
511 X08, X09, X10, X11, X12, X13, X14, X15; 652 X08, X09, X10, X11, X12, X13, X14, X15;
512 u64 w[WCNT]; /* local copy of input block */ 653 u64 w[WCNT]; /* local copy of input block */
513#ifdef SKEIN_DEBUG
514 const u64 *X_ptr[16]; /* use for debugging (help cc put Xn in regs) */
515
516 X_ptr[0] = &X00; X_ptr[1] = &X01; X_ptr[2] = &X02;
517 X_ptr[3] = &X03; X_ptr[4] = &X04; X_ptr[5] = &X05;
518 X_ptr[6] = &X06; X_ptr[7] = &X07; X_ptr[8] = &X08;
519 X_ptr[9] = &X09; X_ptr[10] = &X10; X_ptr[11] = &X11;
520 X_ptr[12] = &X12; X_ptr[13] = &X13; X_ptr[14] = &X14;
521 X_ptr[15] = &X15;
522#endif
523 654
524 skein_assert(blk_cnt != 0); /* never call with blk_cnt == 0! */ 655 skein_assert(blk_cnt != 0); /* never call with blk_cnt == 0! */
525 ts[0] = ctx->h.tweak[0]; 656 ts[0] = ctx->h.tweak[0];
@@ -548,192 +679,81 @@ void skein_1024_process_block(struct skein_1024_ctx *ctx, const u8 *blk_ptr,
548 ks[13] = ctx->x[13]; 679 ks[13] = ctx->x[13];
549 ks[14] = ctx->x[14]; 680 ks[14] = ctx->x[14];
550 ks[15] = ctx->x[15]; 681 ks[15] = ctx->x[15];
551 ks[16] = ks[0] ^ ks[1] ^ ks[2] ^ ks[3] ^ 682 ks[16] = ks[0] ^ ks[1] ^ ks[2] ^ ks[3] ^
552 ks[4] ^ ks[5] ^ ks[6] ^ ks[7] ^ 683 ks[4] ^ ks[5] ^ ks[6] ^ ks[7] ^
553 ks[8] ^ ks[9] ^ ks[10] ^ ks[11] ^ 684 ks[8] ^ ks[9] ^ ks[10] ^ ks[11] ^
554 ks[12] ^ ks[13] ^ ks[14] ^ ks[15] ^ SKEIN_KS_PARITY; 685 ks[12] ^ ks[13] ^ ks[14] ^ ks[15] ^ SKEIN_KS_PARITY;
555 686
556 ts[2] = ts[0] ^ ts[1]; 687 ts[2] = ts[0] ^ ts[1];
557 688
558 /* get input block in little-endian format */ 689 /* get input block in little-endian format */
559 skein_get64_lsb_first(w, blk_ptr, WCNT); 690 skein_get64_lsb_first(w, blk_ptr, WCNT);
560 debug_save_tweak(ctx); 691 debug_save_tweak(ctx);
561 skein_show_block(BLK_BITS, &ctx->h, ctx->x, blk_ptr, w, ks, ts);
562
563 X00 = w[0] + ks[0]; /* do the first full key injection */
564 X01 = w[1] + ks[1];
565 X02 = w[2] + ks[2];
566 X03 = w[3] + ks[3];
567 X04 = w[4] + ks[4];
568 X05 = w[5] + ks[5];
569 X06 = w[6] + ks[6];
570 X07 = w[7] + ks[7];
571 X08 = w[8] + ks[8];
572 X09 = w[9] + ks[9];
573 X10 = w[10] + ks[10];
574 X11 = w[11] + ks[11];
575 X12 = w[12] + ks[12];
576 X13 = w[13] + ks[13] + ts[0];
577 X14 = w[14] + ks[14] + ts[1];
578 X15 = w[15] + ks[15];
579
580 skein_show_r_ptr(BLK_BITS, &ctx->h, SKEIN_RND_KEY_INITIAL,
581 X_ptr);
582
583#define ROUND1024(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, pA, pB, pC, pD, pE, \
584 pF, ROT, r_num) \
585do { \
586 X##p0 += X##p1; X##p1 = rotl_64(X##p1, ROT##_0); X##p1 ^= X##p0; \
587 X##p2 += X##p3; X##p3 = rotl_64(X##p3, ROT##_1); X##p3 ^= X##p2; \
588 X##p4 += X##p5; X##p5 = rotl_64(X##p5, ROT##_2); X##p5 ^= X##p4; \
589 X##p6 += X##p7; X##p7 = rotl_64(X##p7, ROT##_3); X##p7 ^= X##p6; \
590 X##p8 += X##p9; X##p9 = rotl_64(X##p9, ROT##_4); X##p9 ^= X##p8; \
591 X##pA += X##pB; X##pB = rotl_64(X##pB, ROT##_5); X##pB ^= X##pA; \
592 X##pC += X##pD; X##pD = rotl_64(X##pD, ROT##_6); X##pD ^= X##pC; \
593 X##pE += X##pF; X##pF = rotl_64(X##pF, ROT##_7); X##pF ^= X##pE; \
594} while (0)
595
596#if SKEIN_UNROLL_1024 == 0
597#define R1024(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, pA, pB, pC, pD, pE, pF, \
598 ROT, rn) \
599do { \
600 ROUND1024(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, pA, pB, pC, pD, pE, \
601 pF, ROT, rn); \
602 skein_show_r_ptr(BLK_BITS, &ctx->h, rn, X_ptr); \
603} while (0)
604
605#define I1024(R) \
606do { \
607 /* inject the key schedule value */ \
608 X00 += ks[((R) + 1) % 17]; \
609 X01 += ks[((R) + 2) % 17]; \
610 X02 += ks[((R) + 3) % 17]; \
611 X03 += ks[((R) + 4) % 17]; \
612 X04 += ks[((R) + 5) % 17]; \
613 X05 += ks[((R) + 6) % 17]; \
614 X06 += ks[((R) + 7) % 17]; \
615 X07 += ks[((R) + 8) % 17]; \
616 X08 += ks[((R) + 9) % 17]; \
617 X09 += ks[((R) + 10) % 17]; \
618 X10 += ks[((R) + 11) % 17]; \
619 X11 += ks[((R) + 12) % 17]; \
620 X12 += ks[((R) + 13) % 17]; \
621 X13 += ks[((R) + 14) % 17] + ts[((R) + 1) % 3]; \
622 X14 += ks[((R) + 15) % 17] + ts[((R) + 2) % 3]; \
623 X15 += ks[((R) + 16) % 17] + (R) + 1; \
624 skein_show_r_ptr(BLK_BITS, &ctx->h, SKEIN_RND_KEY_INJECT, X_ptr); \
625} while (0)
626#else /* looping version */
627#define R1024(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, pA, pB, pC, pD, pE, pF, \
628 ROT, rn) \
629do { \
630 ROUND1024(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, pA, pB, pC, pD, pE, \
631 pF, ROT, rn); \
632 skein_show_r_ptr(BLK_BITS, &ctx->h, 4 * (r - 1) + rn, X_ptr); \
633} while (0)
634
635#define I1024(R) \
636do { \
637 /* inject the key schedule value */ \
638 X00 += ks[r + (R) + 0]; \
639 X01 += ks[r + (R) + 1]; \
640 X02 += ks[r + (R) + 2]; \
641 X03 += ks[r + (R) + 3]; \
642 X04 += ks[r + (R) + 4]; \
643 X05 += ks[r + (R) + 5]; \
644 X06 += ks[r + (R) + 6]; \
645 X07 += ks[r + (R) + 7]; \
646 X08 += ks[r + (R) + 8]; \
647 X09 += ks[r + (R) + 9]; \
648 X10 += ks[r + (R) + 10]; \
649 X11 += ks[r + (R) + 11]; \
650 X12 += ks[r + (R) + 12]; \
651 X13 += ks[r + (R) + 13] + ts[r + (R) + 0]; \
652 X14 += ks[r + (R) + 14] + ts[r + (R) + 1]; \
653 X15 += ks[r + (R) + 15] + r + (R); \
654 /* rotate key schedule */ \
655 ks[r + (R) + 16] = ks[r + (R) - 1]; \
656 ts[r + (R) + 2] = ts[r + (R) - 1]; \
657 skein_show_r_ptr(BLK_BITSi, &ctx->h, SKEIN_RND_KEY_INJECT, X_ptr); \
658} while (0)
659
660 for (r = 1; r <= 2 * RCNT; r += 2 * SKEIN_UNROLL_1024)
661#endif
662 {
663#define R1024_8_ROUNDS(R) \
664do { \
665 R1024(00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, \
666 R1024_0, 8*(R) + 1); \
667 R1024(00, 09, 02, 13, 06, 11, 04, 15, 10, 07, 12, 03, 14, 05, 08, 01, \
668 R1024_1, 8*(R) + 2); \
669 R1024(00, 07, 02, 05, 04, 03, 06, 01, 12, 15, 14, 13, 08, 11, 10, 09, \
670 R1024_2, 8*(R) + 3); \
671 R1024(00, 15, 02, 11, 06, 13, 04, 09, 14, 01, 08, 05, 10, 03, 12, 07, \
672 R1024_3, 8*(R) + 4); \
673 I1024(2*(R)); \
674 R1024(00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, \
675 R1024_4, 8*(R) + 5); \
676 R1024(00, 09, 02, 13, 06, 11, 04, 15, 10, 07, 12, 03, 14, 05, 08, 01, \
677 R1024_5, 8*(R) + 6); \
678 R1024(00, 07, 02, 05, 04, 03, 06, 01, 12, 15, 14, 13, 08, 11, 10, 09, \
679 R1024_6, 8*(R) + 7); \
680 R1024(00, 15, 02, 11, 06, 13, 04, 09, 14, 01, 08, 05, 10, 03, 12, 07, \
681 R1024_7, 8*(R) + 8); \
682 I1024(2*(R)+1); \
683} while (0)
684 692
693 /* do the first full key injection */
694 X00 = w[0] + ks[0];
695 X01 = w[1] + ks[1];
696 X02 = w[2] + ks[2];
697 X03 = w[3] + ks[3];
698 X04 = w[4] + ks[4];
699 X05 = w[5] + ks[5];
700 X06 = w[6] + ks[6];
701 X07 = w[7] + ks[7];
702 X08 = w[8] + ks[8];
703 X09 = w[9] + ks[9];
704 X10 = w[10] + ks[10];
705 X11 = w[11] + ks[11];
706 X12 = w[12] + ks[12];
707 X13 = w[13] + ks[13] + ts[0];
708 X14 = w[14] + ks[14] + ts[1];
709 X15 = w[15] + ks[15];
710
711 for (r = 1;
712 r < (SKEIN_UNROLL_1024 ? 2 * RCNT : 2);
713 r += (SKEIN_UNROLL_1024 ? 2 * SKEIN_UNROLL_1024 : 1)) {
685 R1024_8_ROUNDS(0); 714 R1024_8_ROUNDS(0);
686 715#if R1024_UNROLL_R(1)
687#define R1024_UNROLL_R(NN) \
688 ((SKEIN_UNROLL_1024 == 0 && \
689 SKEIN_1024_ROUNDS_TOTAL/8 > (NN)) || \
690 (SKEIN_UNROLL_1024 > (NN)))
691
692 #if R1024_UNROLL_R(1)
693 R1024_8_ROUNDS(1); 716 R1024_8_ROUNDS(1);
694 #endif 717#endif
695 #if R1024_UNROLL_R(2) 718#if R1024_UNROLL_R(2)
696 R1024_8_ROUNDS(2); 719 R1024_8_ROUNDS(2);
697 #endif 720#endif
698 #if R1024_UNROLL_R(3) 721#if R1024_UNROLL_R(3)
699 R1024_8_ROUNDS(3); 722 R1024_8_ROUNDS(3);
700 #endif 723#endif
701 #if R1024_UNROLL_R(4) 724#if R1024_UNROLL_R(4)
702 R1024_8_ROUNDS(4); 725 R1024_8_ROUNDS(4);
703 #endif 726#endif
704 #if R1024_UNROLL_R(5) 727#if R1024_UNROLL_R(5)
705 R1024_8_ROUNDS(5); 728 R1024_8_ROUNDS(5);
706 #endif 729#endif
707 #if R1024_UNROLL_R(6) 730#if R1024_UNROLL_R(6)
708 R1024_8_ROUNDS(6); 731 R1024_8_ROUNDS(6);
709 #endif 732#endif
710 #if R1024_UNROLL_R(7) 733#if R1024_UNROLL_R(7)
711 R1024_8_ROUNDS(7); 734 R1024_8_ROUNDS(7);
712 #endif 735#endif
713 #if R1024_UNROLL_R(8) 736#if R1024_UNROLL_R(8)
714 R1024_8_ROUNDS(8); 737 R1024_8_ROUNDS(8);
715 #endif 738#endif
716 #if R1024_UNROLL_R(9) 739#if R1024_UNROLL_R(9)
717 R1024_8_ROUNDS(9); 740 R1024_8_ROUNDS(9);
718 #endif 741#endif
719 #if R1024_UNROLL_R(10) 742#if R1024_UNROLL_R(10)
720 R1024_8_ROUNDS(10); 743 R1024_8_ROUNDS(10);
721 #endif 744#endif
722 #if R1024_UNROLL_R(11) 745#if R1024_UNROLL_R(11)
723 R1024_8_ROUNDS(11); 746 R1024_8_ROUNDS(11);
724 #endif 747#endif
725 #if R1024_UNROLL_R(12) 748#if R1024_UNROLL_R(12)
726 R1024_8_ROUNDS(12); 749 R1024_8_ROUNDS(12);
727 #endif 750#endif
728 #if R1024_UNROLL_R(13) 751#if R1024_UNROLL_R(13)
729 R1024_8_ROUNDS(13); 752 R1024_8_ROUNDS(13);
730 #endif 753#endif
731 #if R1024_UNROLL_R(14) 754#if R1024_UNROLL_R(14)
732 R1024_8_ROUNDS(14); 755 R1024_8_ROUNDS(14);
733 #endif 756#endif
734#if (SKEIN_UNROLL_1024 > 14)
735#error "need more unrolling in Skein_1024_Process_Block"
736 #endif
737 } 757 }
738 /* do the final "feedforward" xor, update context chaining */ 758 /* do the final "feedforward" xor, update context chaining */
739 759
@@ -754,8 +774,6 @@ do { \
754 ctx->x[14] = X14 ^ w[14]; 774 ctx->x[14] = X14 ^ w[14];
755 ctx->x[15] = X15 ^ w[15]; 775 ctx->x[15] = X15 ^ w[15];
756 776
757 skein_show_round(BLK_BITS, &ctx->h, SKEIN_RND_FEED_FWD, ctx->x);
758
759 ts[1] &= ~SKEIN_T1_FLAG_FIRST; 777 ts[1] &= ~SKEIN_T1_FLAG_FIRST;
760 blk_ptr += SKEIN_1024_BLOCK_BYTES; 778 blk_ptr += SKEIN_1024_BLOCK_BYTES;
761 } while (--blk_cnt); 779 } while (--blk_cnt);
diff --git a/drivers/staging/skein/skein_block.h b/drivers/staging/skein/skein_block.h
index bd7bdc35df29..9d40f4a5267b 100644
--- a/drivers/staging/skein/skein_block.h
+++ b/drivers/staging/skein/skein_block.h
@@ -10,7 +10,7 @@
10#ifndef _SKEIN_BLOCK_H_ 10#ifndef _SKEIN_BLOCK_H_
11#define _SKEIN_BLOCK_H_ 11#define _SKEIN_BLOCK_H_
12 12
13#include "skein.h" /* get the Skein API definitions */ 13#include "skein_base.h" /* get the Skein API definitions */
14 14
15void skein_256_process_block(struct skein_256_ctx *ctx, const u8 *blk_ptr, 15void skein_256_process_block(struct skein_256_ctx *ctx, const u8 *blk_ptr,
16 size_t blk_cnt, size_t byte_cnt_add); 16 size_t blk_cnt, size_t byte_cnt_add);
diff --git a/drivers/staging/skein/skein_generic.c b/drivers/staging/skein/skein_generic.c
new file mode 100644
index 000000000000..85bd7d0168b0
--- /dev/null
+++ b/drivers/staging/skein/skein_generic.c
@@ -0,0 +1,216 @@
1/*
2 * Cryptographic API.
3 *
4 * Skein256 Hash Algorithm.
5 *
6 * Derived from cryptoapi implementation, adapted for in-place
7 * scatterlist interface.
8 *
9 * Copyright (c) Eric Rost <eric.rost@mybabylon.net>
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License, or (at your option)
14 * any later version.
15 *
16 */
17#include <linux/types.h>
18#include <linux/init.h>
19#include <linux/module.h>
20#include <crypto/internal/hash.h>
21#include "skein_base.h"
22
23
24static int skein256_init(struct shash_desc *desc)
25{
26 return skein_256_init((struct skein_256_ctx *) shash_desc_ctx(desc),
27 SKEIN256_DIGEST_BIT_SIZE);
28}
29
30static int skein256_update(struct shash_desc *desc, const u8 *data,
31 unsigned int len)
32{
33 return skein_256_update((struct skein_256_ctx *)shash_desc_ctx(desc),
34 data, len);
35}
36
37static int skein256_final(struct shash_desc *desc, u8 *out)
38{
39 return skein_256_final((struct skein_256_ctx *)shash_desc_ctx(desc),
40 out);
41}
42
43static int skein256_export(struct shash_desc *desc, void *out)
44{
45 struct skein_256_ctx *sctx = shash_desc_ctx(desc);
46
47 memcpy(out, sctx, sizeof(*sctx));
48 return 0;
49}
50
51static int skein256_import(struct shash_desc *desc, const void *in)
52{
53 struct skein_256_ctx *sctx = shash_desc_ctx(desc);
54
55 memcpy(sctx, in, sizeof(*sctx));
56 return 0;
57}
58
59static int skein512_init(struct shash_desc *desc)
60{
61 return skein_512_init((struct skein_512_ctx *)shash_desc_ctx(desc),
62 SKEIN512_DIGEST_BIT_SIZE);
63}
64
65static int skein512_update(struct shash_desc *desc, const u8 *data,
66 unsigned int len)
67{
68 return skein_512_update((struct skein_512_ctx *)shash_desc_ctx(desc),
69 data, len);
70}
71
72static int skein512_final(struct shash_desc *desc, u8 *out)
73{
74 return skein_512_final((struct skein_512_ctx *)shash_desc_ctx(desc),
75 out);
76}
77
78static int skein512_export(struct shash_desc *desc, void *out)
79{
80 struct skein_512_ctx *sctx = shash_desc_ctx(desc);
81
82 memcpy(out, sctx, sizeof(*sctx));
83 return 0;
84}
85
86static int skein512_import(struct shash_desc *desc, const void *in)
87{
88 struct skein_512_ctx *sctx = shash_desc_ctx(desc);
89
90 memcpy(sctx, in, sizeof(*sctx));
91 return 0;
92}
93
94static int skein1024_init(struct shash_desc *desc)
95{
96 return skein_1024_init((struct skein_1024_ctx *)shash_desc_ctx(desc),
97 SKEIN1024_DIGEST_BIT_SIZE);
98}
99
100static int skein1024_update(struct shash_desc *desc, const u8 *data,
101 unsigned int len)
102{
103 return skein_1024_update((struct skein_1024_ctx *)shash_desc_ctx(desc),
104 data, len);
105}
106
107static int skein1024_final(struct shash_desc *desc, u8 *out)
108{
109 return skein_1024_final((struct skein_1024_ctx *)shash_desc_ctx(desc),
110 out);
111}
112
113static int skein1024_export(struct shash_desc *desc, void *out)
114{
115 struct skein_1024_ctx *sctx = shash_desc_ctx(desc);
116
117 memcpy(out, sctx, sizeof(*sctx));
118 return 0;
119}
120
121static int skein1024_import(struct shash_desc *desc, const void *in)
122{
123 struct skein_1024_ctx *sctx = shash_desc_ctx(desc);
124
125 memcpy(sctx, in, sizeof(*sctx));
126 return 0;
127}
128
129static struct shash_alg alg256 = {
130 .digestsize = (SKEIN256_DIGEST_BIT_SIZE / 8),
131 .init = skein256_init,
132 .update = skein256_update,
133 .final = skein256_final,
134 .export = skein256_export,
135 .import = skein256_import,
136 .descsize = sizeof(struct skein_256_ctx),
137 .statesize = sizeof(struct skein_256_ctx),
138 .base = {
139 .cra_name = "skein256",
140 .cra_driver_name = "skein",
141 .cra_flags = CRYPTO_ALG_TYPE_SHASH,
142 .cra_blocksize = SKEIN_256_BLOCK_BYTES,
143 .cra_module = THIS_MODULE,
144 }
145};
146
147static struct shash_alg alg512 = {
148 .digestsize = (SKEIN512_DIGEST_BIT_SIZE / 8),
149 .init = skein512_init,
150 .update = skein512_update,
151 .final = skein512_final,
152 .export = skein512_export,
153 .import = skein512_import,
154 .descsize = sizeof(struct skein_512_ctx),
155 .statesize = sizeof(struct skein_512_ctx),
156 .base = {
157 .cra_name = "skein512",
158 .cra_driver_name = "skein",
159 .cra_flags = CRYPTO_ALG_TYPE_SHASH,
160 .cra_blocksize = SKEIN_512_BLOCK_BYTES,
161 .cra_module = THIS_MODULE,
162 }
163};
164
165static struct shash_alg alg1024 = {
166 .digestsize = (SKEIN1024_DIGEST_BIT_SIZE / 8),
167 .init = skein1024_init,
168 .update = skein1024_update,
169 .final = skein1024_final,
170 .export = skein1024_export,
171 .import = skein1024_import,
172 .descsize = sizeof(struct skein_1024_ctx),
173 .statesize = sizeof(struct skein_1024_ctx),
174 .base = {
175 .cra_name = "skein1024",
176 .cra_driver_name = "skein",
177 .cra_flags = CRYPTO_ALG_TYPE_SHASH,
178 .cra_blocksize = SKEIN_1024_BLOCK_BYTES,
179 .cra_module = THIS_MODULE,
180 }
181};
182
183static int __init skein_generic_init(void)
184{
185 if (crypto_register_shash(&alg256))
186 goto out;
187 if (crypto_register_shash(&alg512))
188 goto unreg256;
189 if (crypto_register_shash(&alg1024))
190 goto unreg512;
191
192 return 0;
193
194
195unreg512:
196 crypto_unregister_shash(&alg512);
197unreg256:
198 crypto_unregister_shash(&alg256);
199out:
200 return -1;
201}
202
203static void __exit skein_generic_fini(void)
204{
205 crypto_unregister_shash(&alg256);
206 crypto_unregister_shash(&alg512);
207 crypto_unregister_shash(&alg1024);
208}
209
210module_init(skein_generic_init);
211module_exit(skein_generic_fini);
212
213MODULE_LICENSE("GPL");
214MODULE_DESCRIPTION("Skein Hash Algorithm");
215
216MODULE_ALIAS("skein");
diff --git a/drivers/staging/skein/skein_iv.h b/drivers/staging/skein/skein_iv.h
index d9dc1d5ed551..8a06314d0ed4 100644
--- a/drivers/staging/skein/skein_iv.h
+++ b/drivers/staging/skein/skein_iv.h
@@ -1,7 +1,7 @@
1#ifndef _SKEIN_IV_H_ 1#ifndef _SKEIN_IV_H_
2#define _SKEIN_IV_H_ 2#define _SKEIN_IV_H_
3 3
4#include "skein.h" /* get Skein macros and types */ 4#include "skein_base.h" /* get Skein macros and types */
5 5
6/* 6/*
7***************** Pre-computed Skein IVs ******************* 7***************** Pre-computed Skein IVs *******************
diff --git a/drivers/staging/skein/threefish_api.h b/drivers/staging/skein/threefish_api.h
index 8d5ddf8b3a9b..8e0a0b77ecce 100644
--- a/drivers/staging/skein/threefish_api.h
+++ b/drivers/staging/skein/threefish_api.h
@@ -29,7 +29,7 @@
29 */ 29 */
30 30
31#include <linux/types.h> 31#include <linux/types.h>
32#include "skein.h" 32#include "skein_base.h"
33 33
34#define KEY_SCHEDULE_CONST 0x1BD11BDAA9FC1A22L 34#define KEY_SCHEDULE_CONST 0x1BD11BDAA9FC1A22L
35 35
diff --git a/drivers/staging/slicoss/slicoss.c b/drivers/staging/slicoss/slicoss.c
index 56ca3b6c1444..42d62ef56cb8 100644
--- a/drivers/staging/slicoss/slicoss.c
+++ b/drivers/staging/slicoss/slicoss.c
@@ -498,12 +498,14 @@ static int slic_card_download(struct adapter *adapter)
498 slic_reg32_write(&slic_regs->slic_wcs, 498 slic_reg32_write(&slic_regs->slic_wcs,
499 baseaddress + codeaddr, FLUSH); 499 baseaddress + codeaddr, FLUSH);
500 /* Write out instruction to low addr */ 500 /* Write out instruction to low addr */
501 slic_reg32_write(&slic_regs->slic_wcs, instruction, FLUSH); 501 slic_reg32_write(&slic_regs->slic_wcs,
502 instruction, FLUSH);
502 instruction = *(u32 *)(fw->data + index); 503 instruction = *(u32 *)(fw->data + index);
503 index += 4; 504 index += 4;
504 505
505 /* Write out instruction to high addr */ 506 /* Write out instruction to high addr */
506 slic_reg32_write(&slic_regs->slic_wcs, instruction, FLUSH); 507 slic_reg32_write(&slic_regs->slic_wcs,
508 instruction, FLUSH);
507 instruction = *(u32 *)(fw->data + index); 509 instruction = *(u32 *)(fw->data + index);
508 index += 4; 510 index += 4;
509 } 511 }
@@ -596,8 +598,7 @@ static void slic_mac_address_config(struct adapter *adapter)
596 u32 value2; 598 u32 value2;
597 __iomem struct slic_regs *slic_regs = adapter->slic_regs; 599 __iomem struct slic_regs *slic_regs = adapter->slic_regs;
598 600
599 value = *(u32 *) &adapter->currmacaddr[2]; 601 value = ntohl(*(__be32 *) &adapter->currmacaddr[2]);
600 value = ntohl(value);
601 slic_reg32_write(&slic_regs->slic_wraddral, value, FLUSH); 602 slic_reg32_write(&slic_regs->slic_wraddral, value, FLUSH);
602 slic_reg32_write(&slic_regs->slic_wraddrbl, value, FLUSH); 603 slic_reg32_write(&slic_regs->slic_wraddrbl, value, FLUSH);
603 604
@@ -1533,14 +1534,18 @@ retry_rcvqfill:
1533 dev_err(dev, "%s: LOW 32bits PHYSICAL ADDRESS == 0\n", 1534 dev_err(dev, "%s: LOW 32bits PHYSICAL ADDRESS == 0\n",
1534 __func__); 1535 __func__);
1535 dev_err(dev, "skb[%p] PROBLEM\n", skb); 1536 dev_err(dev, "skb[%p] PROBLEM\n", skb);
1536 dev_err(dev, " skbdata[%p]\n", skb->data); 1537 dev_err(dev, " skbdata[%p]\n",
1538 skb->data);
1537 dev_err(dev, " skblen[%x]\n", skb->len); 1539 dev_err(dev, " skblen[%x]\n", skb->len);
1538 dev_err(dev, " paddr[%p]\n", paddr); 1540 dev_err(dev, " paddr[%p]\n", paddr);
1539 dev_err(dev, " paddrl[%x]\n", paddrl); 1541 dev_err(dev, " paddrl[%x]\n", paddrl);
1540 dev_err(dev, " paddrh[%x]\n", paddrh); 1542 dev_err(dev, " paddrh[%x]\n", paddrh);
1541 dev_err(dev, " rcvq->head[%p]\n", rcvq->head); 1543 dev_err(dev, " rcvq->head[%p]\n",
1542 dev_err(dev, " rcvq->tail[%p]\n", rcvq->tail); 1544 rcvq->head);
1543 dev_err(dev, " rcvq->count[%x]\n", rcvq->count); 1545 dev_err(dev, " rcvq->tail[%p]\n",
1546 rcvq->tail);
1547 dev_err(dev, " rcvq->count[%x]\n",
1548 rcvq->count);
1544 dev_err(dev, "SKIP THIS SKB!!!!!!!!\n"); 1549 dev_err(dev, "SKIP THIS SKB!!!!!!!!\n");
1545 goto retry_rcvqfill; 1550 goto retry_rcvqfill;
1546 } 1551 }
@@ -1549,14 +1554,18 @@ retry_rcvqfill:
1549 dev_err(dev, "%s: LOW 32bits PHYSICAL ADDRESS == 0\n", 1554 dev_err(dev, "%s: LOW 32bits PHYSICAL ADDRESS == 0\n",
1550 __func__); 1555 __func__);
1551 dev_err(dev, "skb[%p] PROBLEM\n", skb); 1556 dev_err(dev, "skb[%p] PROBLEM\n", skb);
1552 dev_err(dev, " skbdata[%p]\n", skb->data); 1557 dev_err(dev, " skbdata[%p]\n",
1558 skb->data);
1553 dev_err(dev, " skblen[%x]\n", skb->len); 1559 dev_err(dev, " skblen[%x]\n", skb->len);
1554 dev_err(dev, " paddr[%p]\n", paddr); 1560 dev_err(dev, " paddr[%p]\n", paddr);
1555 dev_err(dev, " paddrl[%x]\n", paddrl); 1561 dev_err(dev, " paddrl[%x]\n", paddrl);
1556 dev_err(dev, " paddrh[%x]\n", paddrh); 1562 dev_err(dev, " paddrh[%x]\n", paddrh);
1557 dev_err(dev, " rcvq->head[%p]\n", rcvq->head); 1563 dev_err(dev, " rcvq->head[%p]\n",
1558 dev_err(dev, " rcvq->tail[%p]\n", rcvq->tail); 1564 rcvq->head);
1559 dev_err(dev, " rcvq->count[%x]\n", rcvq->count); 1565 dev_err(dev, " rcvq->tail[%p]\n",
1566 rcvq->tail);
1567 dev_err(dev, " rcvq->count[%x]\n",
1568 rcvq->count);
1560 dev_err(dev, "GIVE TO CARD ANYWAY\n"); 1569 dev_err(dev, "GIVE TO CARD ANYWAY\n");
1561 } 1570 }
1562#endif 1571#endif
@@ -1612,7 +1621,7 @@ static int slic_rcvqueue_init(struct adapter *adapter)
1612 rcvq->size = SLIC_RCVQ_ENTRIES; 1621 rcvq->size = SLIC_RCVQ_ENTRIES;
1613 rcvq->errors = 0; 1622 rcvq->errors = 0;
1614 rcvq->count = 0; 1623 rcvq->count = 0;
1615 i = (SLIC_RCVQ_ENTRIES / SLIC_RCVQ_FILLENTRIES); 1624 i = SLIC_RCVQ_ENTRIES / SLIC_RCVQ_FILLENTRIES;
1616 count = 0; 1625 count = 0;
1617 while (i) { 1626 while (i) {
1618 count += slic_rcvqueue_fill(adapter); 1627 count += slic_rcvqueue_fill(adapter);
@@ -1788,7 +1797,7 @@ static int slic_mcast_add_list(struct adapter *adapter, char *address)
1788 if (mcaddr == NULL) 1797 if (mcaddr == NULL)
1789 return 1; 1798 return 1;
1790 1799
1791 memcpy(mcaddr->address, address, ETH_ALEN); 1800 ether_addr_copy(mcaddr->address, address);
1792 1801
1793 mcaddr->next = adapter->mcastaddrs; 1802 mcaddr->next = adapter->mcastaddrs;
1794 adapter->mcastaddrs = mcaddr; 1803 adapter->mcastaddrs = mcaddr;
@@ -1885,7 +1894,8 @@ static void slic_xmit_fail(struct adapter *adapter,
1885 break; 1894 break;
1886 case XMIT_FAIL_HOSTCMD_FAIL: 1895 case XMIT_FAIL_HOSTCMD_FAIL:
1887 dev_err(&adapter->netdev->dev, 1896 dev_err(&adapter->netdev->dev,
1888 "xmit_start skb[%p] type[%x] No host commands available\n", skb, skb->pkt_type); 1897 "xmit_start skb[%p] type[%x] No host commands available\n",
1898 skb, skb->pkt_type);
1889 break; 1899 break;
1890 } 1900 }
1891 } 1901 }
@@ -2097,7 +2107,8 @@ static void slic_interrupt_card_up(u32 isr, struct adapter *adapter,
2097 } 2107 }
2098 } else if (isr & ISR_XDROP) { 2108 } else if (isr & ISR_XDROP) {
2099 dev_err(&dev->dev, 2109 dev_err(&dev->dev,
2100 "isr & ISR_ERR [%x] ISR_XDROP\n", isr); 2110 "isr & ISR_ERR [%x] ISR_XDROP\n",
2111 isr);
2101 } else { 2112 } else {
2102 dev_err(&dev->dev, 2113 dev_err(&dev->dev,
2103 "isr & ISR_ERR [%x]\n", 2114 "isr & ISR_ERR [%x]\n",
@@ -2341,7 +2352,8 @@ static int slic_if_init(struct adapter *adapter)
2341 SLIC_GET_ADDR_LOW(&pshmem->isr), FLUSH); 2352 SLIC_GET_ADDR_LOW(&pshmem->isr), FLUSH);
2342#else 2353#else
2343 slic_reg32_write(&slic_regs->slic_addr_upper, 0, DONT_FLUSH); 2354 slic_reg32_write(&slic_regs->slic_addr_upper, 0, DONT_FLUSH);
2344 slic_reg32_write(&slic_regs->slic_isp, (u32)&pshmem->isr, FLUSH); 2355 slic_reg32_write(&slic_regs->slic_isp, (u32)&pshmem->isr,
2356 FLUSH);
2345#endif 2357#endif
2346 spin_unlock_irqrestore(&adapter->bit64reglock.lock, 2358 spin_unlock_irqrestore(&adapter->bit64reglock.lock,
2347 adapter->bit64reglock.flags); 2359 adapter->bit64reglock.flags);
diff --git a/drivers/staging/speakup/kobjects.c b/drivers/staging/speakup/kobjects.c
index bcc7f62654f4..b12c76de60b0 100644
--- a/drivers/staging/speakup/kobjects.c
+++ b/drivers/staging/speakup/kobjects.c
@@ -81,7 +81,7 @@ static ssize_t chars_chartab_show(struct kobject *kobj,
81static void report_char_chartab_status(int reset, int received, int used, 81static void report_char_chartab_status(int reset, int received, int used,
82 int rejected, int do_characters) 82 int rejected, int do_characters)
83{ 83{
84 char *object_type[] = { 84 static char const *object_type[] = {
85 "character class entries", 85 "character class entries",
86 "character descriptions", 86 "character descriptions",
87 }; 87 };
@@ -809,10 +809,10 @@ static ssize_t message_store_helper(const char *buf, size_t count,
809 if (msg_stored == -ENOMEM) 809 if (msg_stored == -ENOMEM)
810 reset = 1; 810 reset = 1;
811 break; 811 break;
812 } else {
813 used++;
814 } 812 }
815 813
814 used++;
815
816 cp = linefeed + 1; 816 cp = linefeed + 1;
817 } 817 }
818 818
diff --git a/drivers/staging/speakup/main.c b/drivers/staging/speakup/main.c
index 3f30a1b6e72c..e9f0c150d246 100644
--- a/drivers/staging/speakup/main.c
+++ b/drivers/staging/speakup/main.c
@@ -695,7 +695,7 @@ static void say_next_word(struct vc_data *vc)
695 695
696static void spell_word(struct vc_data *vc) 696static void spell_word(struct vc_data *vc)
697{ 697{
698 static char *delay_str[] = { "", ",", ".", ". .", ". . ." }; 698 static char const *delay_str[] = { "", ",", ".", ". .", ". . ." };
699 char *cp = buf, *str_cap = spk_str_caps_stop; 699 char *cp = buf, *str_cap = spk_str_caps_stop;
700 char *cp1, *last_cap = spk_str_caps_stop; 700 char *cp1, *last_cap = spk_str_caps_stop;
701 u_char ch; 701 u_char ch;
diff --git a/drivers/staging/speakup/speakup_dtlk.c b/drivers/staging/speakup/speakup_dtlk.c
index d7d515273896..4e059ea78d4c 100644
--- a/drivers/staging/speakup/speakup_dtlk.c
+++ b/drivers/staging/speakup/speakup_dtlk.c
@@ -231,7 +231,7 @@ static void do_catch_up(struct spk_synth *synth)
231 if (ch == '\n') 231 if (ch == '\n')
232 ch = PROCSPEECH; 232 ch = PROCSPEECH;
233 spk_out(ch); 233 spk_out(ch);
234 if ((jiffies >= jiff_max) && (ch == SPACE)) { 234 if (time_after_eq(jiffies, jiff_max) && (ch == SPACE)) {
235 spk_out(PROCSPEECH); 235 spk_out(PROCSPEECH);
236 spin_lock_irqsave(&speakup_info.spinlock, flags); 236 spin_lock_irqsave(&speakup_info.spinlock, flags);
237 delay_time_val = delay_time->u.n.value; 237 delay_time_val = delay_time->u.n.value;
diff --git a/drivers/staging/speakup/speakup_keypc.c b/drivers/staging/speakup/speakup_keypc.c
index 4ed38898a17a..cef20fdda646 100644
--- a/drivers/staging/speakup/speakup_keypc.c
+++ b/drivers/staging/speakup/speakup_keypc.c
@@ -229,7 +229,7 @@ spin_lock_irqsave(&speakup_info.spinlock, flags);
229 ch = PROCSPEECH; 229 ch = PROCSPEECH;
230 outb_p(ch, synth_port); 230 outb_p(ch, synth_port);
231 SWAIT; 231 SWAIT;
232 if ((jiffies >= jiff_max) && (ch == SPACE)) { 232 if (time_after_eq(jiffies, jiff_max) && (ch == SPACE)) {
233 timeout = 1000; 233 timeout = 1000;
234 while (synth_writable()) 234 while (synth_writable())
235 if (--timeout <= 0) 235 if (--timeout <= 0)
diff --git a/drivers/staging/unisys/channels/channel.c b/drivers/staging/unisys/channels/channel.c
index b4bdee4b575b..74cc4d6b515f 100644
--- a/drivers/staging/unisys/channels/channel.c
+++ b/drivers/staging/unisys/channels/channel.c
@@ -43,45 +43,45 @@
43 * Return value: 43 * Return value:
44 * 1 if the insertion succeeds, 0 if the queue was full. 44 * 1 if the insertion succeeds, 0 if the queue was full.
45 */ 45 */
46unsigned char 46unsigned char spar_signal_insert(struct channel_header __iomem *ch, u32 queue,
47visor_signal_insert(CHANNEL_HEADER __iomem *pChannel, u32 Queue, void *pSignal) 47 void *sig)
48{ 48{
49 void __iomem *psignal; 49 void __iomem *psignal;
50 unsigned int head, tail, nof; 50 unsigned int head, tail, nof;
51 51
52 SIGNAL_QUEUE_HEADER __iomem *pqhdr = 52 struct signal_queue_header __iomem *pqhdr =
53 (SIGNAL_QUEUE_HEADER __iomem *) 53 (struct signal_queue_header __iomem *)
54 ((char __iomem *) pChannel + readq(&pChannel->oChannelSpace)) 54 ((char __iomem *)ch + readq(&ch->ch_space_offset))
55 + Queue; 55 + queue;
56 56
57 /* capture current head and tail */ 57 /* capture current head and tail */
58 head = readl(&pqhdr->Head); 58 head = readl(&pqhdr->head);
59 tail = readl(&pqhdr->Tail); 59 tail = readl(&pqhdr->tail);
60 60
61 /* queue is full if (head + 1) % n equals tail */ 61 /* queue is full if (head + 1) % n equals tail */
62 if (((head + 1) % readl(&pqhdr->MaxSignalSlots)) == tail) { 62 if (((head + 1) % readl(&pqhdr->max_slots)) == tail) {
63 nof = readq(&pqhdr->NumOverflows) + 1; 63 nof = readq(&pqhdr->num_overflows) + 1;
64 writeq(nof, &pqhdr->NumOverflows); 64 writeq(nof, &pqhdr->num_overflows);
65 return 0; 65 return 0;
66 } 66 }
67 67
68 /* increment the head index */ 68 /* increment the head index */
69 head = (head + 1) % readl(&pqhdr->MaxSignalSlots); 69 head = (head + 1) % readl(&pqhdr->max_slots);
70 70
71 /* copy signal to the head location from the area pointed to 71 /* copy signal to the head location from the area pointed to
72 * by pSignal 72 * by pSignal
73 */ 73 */
74 psignal = (char __iomem *)pqhdr + readq(&pqhdr->oSignalBase) + 74 psignal = (char __iomem *)pqhdr + readq(&pqhdr->sig_base_offset) +
75 (head * readl(&pqhdr->SignalSize)); 75 (head * readl(&pqhdr->signal_size));
76 memcpy_toio(psignal, pSignal, readl(&pqhdr->SignalSize)); 76 memcpy_toio(psignal, sig, readl(&pqhdr->signal_size));
77 77
78 mb(); /* channel synch */ 78 mb(); /* channel synch */
79 writel(head, &pqhdr->Head); 79 writel(head, &pqhdr->head);
80 80
81 writeq(readq(&pqhdr->NumSignalsSent) + 1, &pqhdr->NumSignalsSent); 81 writeq(readq(&pqhdr->num_sent) + 1, &pqhdr->num_sent);
82 return 1; 82 return 1;
83} 83}
84EXPORT_SYMBOL_GPL(visor_signal_insert); 84EXPORT_SYMBOL_GPL(spar_signal_insert);
85 85
86/* 86/*
87 * Routine Description: 87 * Routine Description:
@@ -102,40 +102,40 @@ EXPORT_SYMBOL_GPL(visor_signal_insert);
102 * 1 if the removal succeeds, 0 if the queue was empty. 102 * 1 if the removal succeeds, 0 if the queue was empty.
103 */ 103 */
104unsigned char 104unsigned char
105visor_signal_remove(CHANNEL_HEADER __iomem *pChannel, u32 Queue, void *pSignal) 105spar_signal_remove(struct channel_header __iomem *ch, u32 queue, void *sig)
106{ 106{
107 void __iomem *psource; 107 void __iomem *psource;
108 unsigned int head, tail; 108 unsigned int head, tail;
109 SIGNAL_QUEUE_HEADER __iomem *pqhdr = 109 struct signal_queue_header __iomem *pqhdr =
110 (SIGNAL_QUEUE_HEADER __iomem *) ((char __iomem *) pChannel + 110 (struct signal_queue_header __iomem *)((char __iomem *)ch +
111 readq(&pChannel->oChannelSpace)) + Queue; 111 readq(&ch->ch_space_offset)) + queue;
112 112
113 /* capture current head and tail */ 113 /* capture current head and tail */
114 head = readl(&pqhdr->Head); 114 head = readl(&pqhdr->head);
115 tail = readl(&pqhdr->Tail); 115 tail = readl(&pqhdr->tail);
116 116
117 /* queue is empty if the head index equals the tail index */ 117 /* queue is empty if the head index equals the tail index */
118 if (head == tail) { 118 if (head == tail) {
119 writeq(readq(&pqhdr->NumEmptyCnt) + 1, &pqhdr->NumEmptyCnt); 119 writeq(readq(&pqhdr->num_empty) + 1, &pqhdr->num_empty);
120 return 0; 120 return 0;
121 } 121 }
122 122
123 /* advance past the 'empty' front slot */ 123 /* advance past the 'empty' front slot */
124 tail = (tail + 1) % readl(&pqhdr->MaxSignalSlots); 124 tail = (tail + 1) % readl(&pqhdr->max_slots);
125 125
126 /* copy signal from tail location to the area pointed to by pSignal */ 126 /* copy signal from tail location to the area pointed to by pSignal */
127 psource = (char __iomem *) pqhdr + readq(&pqhdr->oSignalBase) + 127 psource = (char __iomem *)pqhdr + readq(&pqhdr->sig_base_offset) +
128 (tail * readl(&pqhdr->SignalSize)); 128 (tail * readl(&pqhdr->signal_size));
129 memcpy_fromio(pSignal, psource, readl(&pqhdr->SignalSize)); 129 memcpy_fromio(sig, psource, readl(&pqhdr->signal_size));
130 130
131 mb(); /* channel synch */ 131 mb(); /* channel synch */
132 writel(tail, &pqhdr->Tail); 132 writel(tail, &pqhdr->tail);
133 133
134 writeq(readq(&pqhdr->NumSignalsReceived) + 1, 134 writeq(readq(&pqhdr->num_received) + 1,
135 &pqhdr->NumSignalsReceived); 135 &pqhdr->num_received);
136 return 1; 136 return 1;
137} 137}
138EXPORT_SYMBOL_GPL(visor_signal_remove); 138EXPORT_SYMBOL_GPL(spar_signal_remove);
139 139
140/* 140/*
141 * Routine Description: 141 * Routine Description:
@@ -156,18 +156,18 @@ EXPORT_SYMBOL_GPL(visor_signal_remove);
156 * Return value: 156 * Return value:
157 * # of signals copied. 157 * # of signals copied.
158 */ 158 */
159unsigned int 159unsigned int spar_signal_remove_all(struct channel_header *ch, u32 queue,
160SignalRemoveAll(pCHANNEL_HEADER pChannel, u32 Queue, void *pSignal) 160 void *sig)
161{ 161{
162 void *psource; 162 void *psource;
163 unsigned int head, tail, signalCount = 0; 163 unsigned int head, tail, count = 0;
164 pSIGNAL_QUEUE_HEADER pqhdr = 164 struct signal_queue_header *pqhdr =
165 (pSIGNAL_QUEUE_HEADER) ((char *) pChannel + 165 (struct signal_queue_header *)((char *)ch +
166 pChannel->oChannelSpace) + Queue; 166 ch->ch_space_offset) + queue;
167 167
168 /* capture current head and tail */ 168 /* capture current head and tail */
169 head = pqhdr->Head; 169 head = pqhdr->head;
170 tail = pqhdr->Tail; 170 tail = pqhdr->tail;
171 171
172 /* queue is empty if the head index equals the tail index */ 172 /* queue is empty if the head index equals the tail index */
173 if (head == tail) 173 if (head == tail)
@@ -175,25 +175,25 @@ SignalRemoveAll(pCHANNEL_HEADER pChannel, u32 Queue, void *pSignal)
175 175
176 while (head != tail) { 176 while (head != tail) {
177 /* advance past the 'empty' front slot */ 177 /* advance past the 'empty' front slot */
178 tail = (tail + 1) % pqhdr->MaxSignalSlots; 178 tail = (tail + 1) % pqhdr->max_slots;
179 179
180 /* copy signal from tail location to the area pointed 180 /* copy signal from tail location to the area pointed
181 * to by pSignal 181 * to by pSignal
182 */ 182 */
183 psource = 183 psource =
184 (char *) pqhdr + pqhdr->oSignalBase + 184 (char *)pqhdr + pqhdr->sig_base_offset +
185 (tail * pqhdr->SignalSize); 185 (tail * pqhdr->signal_size);
186 memcpy((char *) pSignal + (pqhdr->SignalSize * signalCount), 186 memcpy((char *)sig + (pqhdr->signal_size * count),
187 psource, pqhdr->SignalSize); 187 psource, pqhdr->signal_size);
188 188
189 mb(); /* channel synch */ 189 mb(); /* channel synch */
190 pqhdr->Tail = tail; 190 pqhdr->tail = tail;
191 191
192 signalCount++; 192 count++;
193 pqhdr->NumSignalsReceived++; 193 pqhdr->num_received++;
194 } 194 }
195 195
196 return signalCount; 196 return count;
197} 197}
198 198
199/* 199/*
@@ -207,13 +207,13 @@ SignalRemoveAll(pCHANNEL_HEADER pChannel, u32 Queue, void *pSignal)
207 * Return value: 207 * Return value:
208 * 1 if the signal queue is empty, 0 otherwise. 208 * 1 if the signal queue is empty, 0 otherwise.
209 */ 209 */
210unsigned char 210unsigned char spar_signalqueue_empty(struct channel_header __iomem *ch,
211visor_signalqueue_empty(CHANNEL_HEADER __iomem *pChannel, u32 Queue) 211 u32 queue)
212{ 212{
213 SIGNAL_QUEUE_HEADER __iomem *pqhdr = 213 struct signal_queue_header __iomem *pqhdr =
214 (SIGNAL_QUEUE_HEADER __iomem *) ((char __iomem *) pChannel + 214 (struct signal_queue_header __iomem *)((char __iomem *)ch +
215 readq(&pChannel->oChannelSpace)) + Queue; 215 readq(&ch->ch_space_offset)) + queue;
216 return readl(&pqhdr->Head) == readl(&pqhdr->Tail); 216 return readl(&pqhdr->head) == readl(&pqhdr->tail);
217} 217}
218EXPORT_SYMBOL_GPL(visor_signalqueue_empty); 218EXPORT_SYMBOL_GPL(spar_signalqueue_empty);
219 219
diff --git a/drivers/staging/unisys/channels/chanstub.c b/drivers/staging/unisys/channels/chanstub.c
index d54c5d635a94..b6fd126f16f1 100644
--- a/drivers/staging/unisys/channels/chanstub.c
+++ b/drivers/staging/unisys/channels/chanstub.c
@@ -42,26 +42,26 @@ channel_mod_exit(void)
42} 42}
43 43
44unsigned char 44unsigned char
45SignalInsert_withLock(CHANNEL_HEADER __iomem *pChannel, u32 Queue, 45SignalInsert_withLock(struct channel_header __iomem *pChannel, u32 Queue,
46 void *pSignal, spinlock_t *lock) 46 void *pSignal, spinlock_t *lock)
47{ 47{
48 unsigned char result; 48 unsigned char result;
49 unsigned long flags; 49 unsigned long flags;
50 50
51 spin_lock_irqsave(lock, flags); 51 spin_lock_irqsave(lock, flags);
52 result = visor_signal_insert(pChannel, Queue, pSignal); 52 result = spar_signal_insert(pChannel, Queue, pSignal);
53 spin_unlock_irqrestore(lock, flags); 53 spin_unlock_irqrestore(lock, flags);
54 return result; 54 return result;
55} 55}
56 56
57unsigned char 57unsigned char
58SignalRemove_withLock(CHANNEL_HEADER __iomem *pChannel, u32 Queue, 58SignalRemove_withLock(struct channel_header __iomem *pChannel, u32 Queue,
59 void *pSignal, spinlock_t *lock) 59 void *pSignal, spinlock_t *lock)
60{ 60{
61 unsigned char result; 61 unsigned char result;
62 62
63 spin_lock(lock); 63 spin_lock(lock);
64 result = visor_signal_remove(pChannel, Queue, pSignal); 64 result = spar_signal_remove(pChannel, Queue, pSignal);
65 spin_unlock(lock); 65 spin_unlock(lock);
66 return result; 66 return result;
67} 67}
diff --git a/drivers/staging/unisys/channels/chanstub.h b/drivers/staging/unisys/channels/chanstub.h
index d08e2c69d2ad..1531759a1b31 100644
--- a/drivers/staging/unisys/channels/chanstub.h
+++ b/drivers/staging/unisys/channels/chanstub.h
@@ -15,9 +15,9 @@
15 15
16#ifndef __CHANSTUB_H__ 16#ifndef __CHANSTUB_H__
17#define __CHANSTUB_H__ 17#define __CHANSTUB_H__
18unsigned char SignalInsert_withLock(CHANNEL_HEADER __iomem *pChannel, u32 Queue, 18unsigned char SignalInsert_withLock(struct channel_header __iomem *pChannel,
19 void *pSignal, spinlock_t *lock); 19 u32 Queue, void *pSignal, spinlock_t *lock);
20unsigned char SignalRemove_withLock(CHANNEL_HEADER __iomem *pChannel, u32 Queue, 20unsigned char SignalRemove_withLock(struct channel_header __iomem *pChannel,
21 void *pSignal, spinlock_t *lock); 21 u32 Queue, void *pSignal, spinlock_t *lock);
22 22
23#endif 23#endif
diff --git a/drivers/staging/unisys/common-spar/include/channels/channel.h b/drivers/staging/unisys/common-spar/include/channels/channel.h
index c25dfbf7f6bc..6fb6e5b3ddaf 100644
--- a/drivers/staging/unisys/common-spar/include/channels/channel.h
+++ b/drivers/staging/unisys/common-spar/include/channels/channel.h
@@ -50,43 +50,12 @@
50 50
51#define ULTRA_CHANNEL_PROTOCOL_SIGNATURE SIGNATURE_32('E', 'C', 'N', 'L') 51#define ULTRA_CHANNEL_PROTOCOL_SIGNATURE SIGNATURE_32('E', 'C', 'N', 'L')
52 52
53#define CHANNEL_GUID_MISMATCH(chType, chName, field, expected, actual, fil, \ 53enum channel_serverstate {
54 lin, logCtx) \
55 do { \
56 pr_err("Channel mismatch on channel=%s(%pUL) field=%s expected=%pUL actual=%pUL @%s:%d\n", \
57 chName, &chType, field, \
58 &expected, &actual, \
59 fil, lin); \
60 } while (0)
61#define CHANNEL_U32_MISMATCH(chType, chName, field, expected, actual, fil, \
62 lin, logCtx) \
63 do { \
64 pr_err("Channel mismatch on channel=%s(%pUL) field=%s expected=0x%-8.8lx actual=0x%-8.8lx @%s:%d\n", \
65 chName, &chType, field, \
66 (unsigned long)expected, (unsigned long)actual, \
67 fil, lin); \
68 } while (0)
69
70#define CHANNEL_U64_MISMATCH(chType, chName, field, expected, actual, fil, \
71 lin, logCtx) \
72 do { \
73 pr_err("Channel mismatch on channel=%s(%pUL) field=%s expected=0x%-8.8Lx actual=0x%-8.8Lx @%s:%d\n", \
74 chName, &chType, field, \
75 (unsigned long long)expected, \
76 (unsigned long long)actual, \
77 fil, lin); \
78 } while (0)
79
80#define UltraLogEvent(logCtx, EventId, Severity, SubsystemMask, pFunctionName, \
81 LineNumber, Str, args...) \
82 pr_info(Str, ## args)
83
84typedef enum {
85 CHANNELSRV_UNINITIALIZED = 0, /* channel is in an undefined state */ 54 CHANNELSRV_UNINITIALIZED = 0, /* channel is in an undefined state */
86 CHANNELSRV_READY = 1 /* channel has been initialized by server */ 55 CHANNELSRV_READY = 1 /* channel has been initialized by server */
87} CHANNEL_SERVERSTATE; 56};
88 57
89typedef enum { 58enum channel_clientstate {
90 CHANNELCLI_DETACHED = 0, 59 CHANNELCLI_DETACHED = 0,
91 CHANNELCLI_DISABLED = 1, /* client can see channel but is NOT 60 CHANNELCLI_DISABLED = 1, /* client can see channel but is NOT
92 * allowed to use it unless given TBD 61 * allowed to use it unless given TBD
@@ -100,32 +69,32 @@ typedef enum {
100 * using channel */ 69 * using channel */
101 CHANNELCLI_OWNED = 5 /* "no worries" state - client can 70 CHANNELCLI_OWNED = 5 /* "no worries" state - client can
102 * access channel anytime */ 71 * access channel anytime */
103} CHANNEL_CLIENTSTATE; 72};
73
104static inline const u8 * 74static inline const u8 *
105ULTRA_CHANNELCLI_STRING(u32 v) 75ULTRA_CHANNELCLI_STRING(u32 v)
106{ 76{
107 switch (v) { 77 switch (v) {
108 case CHANNELCLI_DETACHED: 78 case CHANNELCLI_DETACHED:
109 return (const u8 *) ("DETACHED"); 79 return (const u8 *)("DETACHED");
110 case CHANNELCLI_DISABLED: 80 case CHANNELCLI_DISABLED:
111 return (const u8 *) ("DISABLED"); 81 return (const u8 *)("DISABLED");
112 case CHANNELCLI_ATTACHING: 82 case CHANNELCLI_ATTACHING:
113 return (const u8 *) ("ATTACHING"); 83 return (const u8 *)("ATTACHING");
114 case CHANNELCLI_ATTACHED: 84 case CHANNELCLI_ATTACHED:
115 return (const u8 *) ("ATTACHED"); 85 return (const u8 *)("ATTACHED");
116 case CHANNELCLI_BUSY: 86 case CHANNELCLI_BUSY:
117 return (const u8 *) ("BUSY"); 87 return (const u8 *)("BUSY");
118 case CHANNELCLI_OWNED: 88 case CHANNELCLI_OWNED:
119 return (const u8 *) ("OWNED"); 89 return (const u8 *)("OWNED");
120 default: 90 default:
121 break; 91 break;
122 } 92 }
123 return (const u8 *) ("?"); 93 return (const u8 *)("?");
124} 94}
125 95
126#define ULTRA_CHANNELSRV_IS_READY(x) ((x) == CHANNELSRV_READY) 96#define SPAR_CHANNEL_SERVER_READY(ch) \
127#define ULTRA_CHANNEL_SERVER_READY(pChannel) \ 97 (readl(&(ch)->srv_state) == CHANNELSRV_READY)
128 (ULTRA_CHANNELSRV_IS_READY(readl(&(pChannel)->SrvState)))
129 98
130#define ULTRA_VALID_CHANNELCLI_TRANSITION(o, n) \ 99#define ULTRA_VALID_CHANNELCLI_TRANSITION(o, n) \
131 (((((o) == CHANNELCLI_DETACHED) && ((n) == CHANNELCLI_DISABLED)) || \ 100 (((((o) == CHANNELCLI_DETACHED) && ((n) == CHANNELCLI_DISABLED)) || \
@@ -145,60 +114,41 @@ ULTRA_CHANNELCLI_STRING(u32 v)
145 (((o) == CHANNELCLI_BUSY) && ((n) == CHANNELCLI_OWNED)) || (0)) \ 114 (((o) == CHANNELCLI_BUSY) && ((n) == CHANNELCLI_OWNED)) || (0)) \
146 ? (1) : (0)) 115 ? (1) : (0))
147 116
148#define ULTRA_CHANNEL_CLIENT_CHK_TRANSITION(old, new, chanId, logCtx, \ 117#define SPAR_CHANNEL_CLIENT_CHK_TRANSITION(old, new, id, log, \
149 file, line) \ 118 file, line) \
150 do { \ 119 do { \
151 if (!ULTRA_VALID_CHANNELCLI_TRANSITION(old, new)) \ 120 if (!ULTRA_VALID_CHANNELCLI_TRANSITION(old, new)) \
152 UltraLogEvent(logCtx, \ 121 pr_info("%s Channel StateTransition INVALID! (%s) %s(%d)-->%s(%d) @%s:%d\n", \
153 CHANNELSTATE_DIAG_EVENTID_TRANSITERR, \ 122 id, "CliState<x>", \
154 CHANNELSTATE_DIAG_SEVERITY, \ 123 ULTRA_CHANNELCLI_STRING(old), \
155 CHANNELSTATE_DIAG_SUBSYS, \ 124 old, \
156 __func__, __LINE__, \ 125 ULTRA_CHANNELCLI_STRING(new), \
157 "%s Channel StateTransition INVALID! (%s) %s(%d)-->%s(%d) @%s:%d\n", \ 126 new, \
158 chanId, "CliState<x>", \ 127 pathname_last_n_nodes((u8 *)file, 4), \
159 ULTRA_CHANNELCLI_STRING(old), \ 128 line); \
160 old, \
161 ULTRA_CHANNELCLI_STRING(new), \
162 new, \
163 PathName_Last_N_Nodes((u8 *)file, 4), \
164 line); \
165 } while (0) 129 } while (0)
166 130
167#define ULTRA_CHANNEL_CLIENT_TRANSITION(pChan, chanId, \ 131#define SPAR_CHANNEL_CLIENT_TRANSITION(ch, id, newstate, log) \
168 newstate, logCtx) \
169 do { \ 132 do { \
170 ULTRA_CHANNEL_CLIENT_CHK_TRANSITION( \ 133 SPAR_CHANNEL_CLIENT_CHK_TRANSITION( \
171 readl(&(((CHANNEL_HEADER __iomem *) \ 134 readl(&(((struct channel_header __iomem *)\
172 (pChan))->CliStateOS)), \ 135 (ch))->cli_state_os)), \
173 newstate, \ 136 newstate, id, log, __FILE__, __LINE__); \
174 chanId, logCtx, __FILE__, __LINE__); \ 137 pr_info("%s Channel StateTransition (%s) %s(%d)-->%s(%d) @%s:%d\n", \
175 UltraLogEvent(logCtx, CHANNELSTATE_DIAG_EVENTID_TRANSITOK, \ 138 id, "CliStateOS", \
176 CHANNELSTATE_DIAG_SEVERITY, \ 139 ULTRA_CHANNELCLI_STRING( \
177 CHANNELSTATE_DIAG_SUBSYS, \ 140 readl(&((struct channel_header __iomem *)\
178 __func__, __LINE__, \ 141 (ch))->cli_state_os)), \
179 "%s Channel StateTransition (%s) %s(%d)-->%s(%d) @%s:%d\n", \ 142 readl(&((struct channel_header __iomem *)\
180 chanId, "CliStateOS", \ 143 (ch))->cli_state_os), \
181 ULTRA_CHANNELCLI_STRING( \ 144 ULTRA_CHANNELCLI_STRING(newstate), \
182 readl(&((CHANNEL_HEADER __iomem *) \ 145 newstate, \
183 (pChan))->CliStateOS)), \ 146 pathname_last_n_nodes(__FILE__, 4), __LINE__); \
184 readl(&((CHANNEL_HEADER __iomem *) \ 147 writel(newstate, &((struct channel_header __iomem *)\
185 (pChan))->CliStateOS), \ 148 (ch))->cli_state_os); \
186 ULTRA_CHANNELCLI_STRING(newstate), \
187 newstate, \
188 PathName_Last_N_Nodes(__FILE__, 4), __LINE__); \
189 writel(newstate, &((CHANNEL_HEADER __iomem *) \
190 (pChan))->CliStateOS); \
191 mb(); /* required for channel synch */ \ 149 mb(); /* required for channel synch */ \
192 } while (0) 150 } while (0)
193 151
194#define ULTRA_CHANNEL_CLIENT_ACQUIRE_OS(pChan, chanId, logCtx) \
195 ULTRA_channel_client_acquire_os(pChan, chanId, logCtx, \
196 (char *)__FILE__, __LINE__, \
197 (char *)__func__)
198#define ULTRA_CHANNEL_CLIENT_RELEASE_OS(pChan, chanId, logCtx) \
199 ULTRA_channel_client_release_os(pChan, chanId, logCtx, \
200 (char *)__FILE__, __LINE__, (char *)__func__)
201
202/* Values for ULTRA_CHANNEL_PROTOCOL.CliErrorBoot: */ 152/* Values for ULTRA_CHANNEL_PROTOCOL.CliErrorBoot: */
203/* throttling invalid boot channel statetransition error due to client 153/* throttling invalid boot channel statetransition error due to client
204 * disabled */ 154 * disabled */
@@ -239,98 +189,98 @@ ULTRA_CHANNELCLI_STRING(u32 v)
239 189
240#pragma pack(push, 1) /* both GCC and VC now allow this pragma */ 190#pragma pack(push, 1) /* both GCC and VC now allow this pragma */
241/* Common Channel Header */ 191/* Common Channel Header */
242typedef struct _CHANNEL_HEADER { 192struct channel_header {
243 u64 Signature; /* Signature */ 193 u64 signature; /* Signature */
244 u32 LegacyState; /* DEPRECATED - being replaced by */ 194 u32 legacy_state; /* DEPRECATED - being replaced by */
245 /* / SrvState, CliStateBoot, and CliStateOS below */ 195 /* / SrvState, CliStateBoot, and CliStateOS below */
246 u32 HeaderSize; /* sizeof(CHANNEL_HEADER) */ 196 u32 header_size; /* sizeof(struct channel_header) */
247 u64 Size; /* Total size of this channel in bytes */ 197 u64 size; /* Total size of this channel in bytes */
248 u64 Features; /* Flags to modify behavior */ 198 u64 features; /* Flags to modify behavior */
249 uuid_le Type; /* Channel type: data, bus, control, etc. */ 199 uuid_le chtype; /* Channel type: data, bus, control, etc. */
250 u64 PartitionHandle; /* ID of guest partition */ 200 u64 partition_handle; /* ID of guest partition */
251 u64 Handle; /* Device number of this channel in client */ 201 u64 handle; /* Device number of this channel in client */
252 u64 oChannelSpace; /* Offset in bytes to channel specific area */ 202 u64 ch_space_offset; /* Offset in bytes to channel specific area */
253 u32 VersionId; /* CHANNEL_HEADER Version ID */ 203 u32 version_id; /* struct channel_header Version ID */
254 u32 PartitionIndex; /* Index of guest partition */ 204 u32 partition_index; /* Index of guest partition */
255 uuid_le ZoneGuid; /* Guid of Channel's zone */ 205 uuid_le zone_uuid; /* Guid of Channel's zone */
256 u32 oClientString; /* offset from channel header to 206 u32 cli_str_offset; /* offset from channel header to
257 * nul-terminated ClientString (0 if 207 * nul-terminated ClientString (0 if
258 * ClientString not present) */ 208 * ClientString not present) */
259 u32 CliStateBoot; /* CHANNEL_CLIENTSTATE of pre-boot 209 u32 cli_state_boot; /* CHANNEL_CLIENTSTATE of pre-boot
260 * EFI client of this channel */ 210 * EFI client of this channel */
261 u32 CmdStateCli; /* CHANNEL_COMMANDSTATE (overloaded in 211 u32 cmd_state_cli; /* CHANNEL_COMMANDSTATE (overloaded in
262 * Windows drivers, see ServerStateUp, 212 * Windows drivers, see ServerStateUp,
263 * ServerStateDown, etc) */ 213 * ServerStateDown, etc) */
264 u32 CliStateOS; /* CHANNEL_CLIENTSTATE of Guest OS 214 u32 cli_state_os; /* CHANNEL_CLIENTSTATE of Guest OS
265 * client of this channel */ 215 * client of this channel */
266 u32 ChannelCharacteristics; /* CHANNEL_CHARACTERISTIC_<xxx> */ 216 u32 ch_characteristic; /* CHANNEL_CHARACTERISTIC_<xxx> */
267 u32 CmdStateSrv; /* CHANNEL_COMMANDSTATE (overloaded in 217 u32 cmd_state_srv; /* CHANNEL_COMMANDSTATE (overloaded in
268 * Windows drivers, see ServerStateUp, 218 * Windows drivers, see ServerStateUp,
269 * ServerStateDown, etc) */ 219 * ServerStateDown, etc) */
270 u32 SrvState; /* CHANNEL_SERVERSTATE */ 220 u32 srv_state; /* CHANNEL_SERVERSTATE */
271 u8 CliErrorBoot; /* bits to indicate err states for 221 u8 cli_error_boot; /* bits to indicate err states for
272 * boot clients, so err messages can 222 * boot clients, so err messages can
273 * be throttled */ 223 * be throttled */
274 u8 CliErrorOS; /* bits to indicate err states for OS 224 u8 cli_error_os; /* bits to indicate err states for OS
275 * clients, so err messages can be 225 * clients, so err messages can be
276 * throttled */ 226 * throttled */
277 u8 Filler[1]; /* Pad out to 128 byte cacheline */ 227 u8 filler[1]; /* Pad out to 128 byte cacheline */
278 /* Please add all new single-byte values below here */ 228 /* Please add all new single-byte values below here */
279 u8 RecoverChannel; 229 u8 recover_channel;
280} CHANNEL_HEADER, *pCHANNEL_HEADER, ULTRA_CHANNEL_PROTOCOL; 230};
281 231
282#define ULTRA_CHANNEL_ENABLE_INTS (0x1ULL << 0) 232#define ULTRA_CHANNEL_ENABLE_INTS (0x1ULL << 0)
283 233
284/* Subheader for the Signal Type variation of the Common Channel */ 234/* Subheader for the Signal Type variation of the Common Channel */
285typedef struct _SIGNAL_QUEUE_HEADER { 235struct signal_queue_header {
286 /* 1st cache line */ 236 /* 1st cache line */
287 u32 VersionId; /* SIGNAL_QUEUE_HEADER Version ID */ 237 u32 version; /* SIGNAL_QUEUE_HEADER Version ID */
288 u32 Type; /* Queue type: storage, network */ 238 u32 chtype; /* Queue type: storage, network */
289 u64 Size; /* Total size of this queue in bytes */ 239 u64 size; /* Total size of this queue in bytes */
290 u64 oSignalBase; /* Offset to signal queue area */ 240 u64 sig_base_offset; /* Offset to signal queue area */
291 u64 FeatureFlags; /* Flags to modify behavior */ 241 u64 features; /* Flags to modify behavior */
292 u64 NumSignalsSent; /* Total # of signals placed in this queue */ 242 u64 num_sent; /* Total # of signals placed in this queue */
293 u64 NumOverflows; /* Total # of inserts failed due to 243 u64 num_overflows; /* Total # of inserts failed due to
294 * full queue */ 244 * full queue */
295 u32 SignalSize; /* Total size of a signal for this queue */ 245 u32 signal_size; /* Total size of a signal for this queue */
296 u32 MaxSignalSlots; /* Max # of slots in queue, 1 slot is 246 u32 max_slots; /* Max # of slots in queue, 1 slot is
297 * always empty */ 247 * always empty */
298 u32 MaxSignals; /* Max # of signals in queue 248 u32 max_signals; /* Max # of signals in queue
299 * (MaxSignalSlots-1) */ 249 * (MaxSignalSlots-1) */
300 u32 Head; /* Queue head signal # */ 250 u32 head; /* Queue head signal # */
301 /* 2nd cache line */ 251 /* 2nd cache line */
302 u64 NumSignalsReceived; /* Total # of signals removed from this queue */ 252 u64 num_received; /* Total # of signals removed from this queue */
303 u32 Tail; /* Queue tail signal # (on separate 253 u32 tail; /* Queue tail signal # (on separate
304 * cache line) */ 254 * cache line) */
305 u32 Reserved1; /* Reserved field */ 255 u32 reserved1; /* Reserved field */
306 u64 Reserved2; /* Resrved field */ 256 u64 reserved2; /* Reserved field */
307 u64 ClientQueue; 257 u64 client_queue;
308 u64 NumInterruptsReceived; /* Total # of Interrupts received. This 258 u64 num_irq_received; /* Total # of Interrupts received. This
309 * is incremented by the ISR in the 259 * is incremented by the ISR in the
310 * guest windows driver */ 260 * guest windows driver */
311 u64 NumEmptyCnt; /* Number of times that visor_signal_remove 261 u64 num_empty; /* Number of times that visor_signal_remove
312 * is called and returned Empty 262 * is called and returned Empty
313 * Status. */ 263 * Status. */
314 u32 ErrorFlags; /* Error bits set during SignalReinit 264 u32 errorflags; /* Error bits set during SignalReinit
315 * to denote trouble with client's 265 * to denote trouble with client's
316 * fields */ 266 * fields */
317 u8 Filler[12]; /* Pad out to 64 byte cacheline */ 267 u8 filler[12]; /* Pad out to 64 byte cacheline */
318} SIGNAL_QUEUE_HEADER, *pSIGNAL_QUEUE_HEADER; 268};
319 269
320#pragma pack(pop) 270#pragma pack(pop)
321 271
322#define SignalInit(chan, QHDRFLD, QDATAFLD, QDATATYPE, ver, typ) \ 272#define spar_signal_init(chan, QHDRFLD, QDATAFLD, QDATATYPE, ver, typ) \
323 do { \ 273 do { \
324 memset(&chan->QHDRFLD, 0, sizeof(chan->QHDRFLD)); \ 274 memset(&chan->QHDRFLD, 0, sizeof(chan->QHDRFLD)); \
325 chan->QHDRFLD.VersionId = ver; \ 275 chan->QHDRFLD.version = ver; \
326 chan->QHDRFLD.Type = typ; \ 276 chan->QHDRFLD.chtype = typ; \
327 chan->QHDRFLD.Size = sizeof(chan->QDATAFLD); \ 277 chan->QHDRFLD.size = sizeof(chan->QDATAFLD); \
328 chan->QHDRFLD.SignalSize = sizeof(QDATATYPE); \ 278 chan->QHDRFLD.signal_size = sizeof(QDATATYPE); \
329 chan->QHDRFLD.oSignalBase = (u64)(chan->QDATAFLD)- \ 279 chan->QHDRFLD.sig_base_offset = (u64)(chan->QDATAFLD)- \
330 (u64)(&chan->QHDRFLD); \ 280 (u64)(&chan->QHDRFLD); \
331 chan->QHDRFLD.MaxSignalSlots = \ 281 chan->QHDRFLD.max_slots = \
332 sizeof(chan->QDATAFLD)/sizeof(QDATATYPE); \ 282 sizeof(chan->QDATAFLD)/sizeof(QDATATYPE); \
333 chan->QHDRFLD.MaxSignals = chan->QHDRFLD.MaxSignalSlots-1; \ 283 chan->QHDRFLD.max_signals = chan->QHDRFLD.max_slots-1; \
334 } while (0) 284 } while (0)
335 285
336/* Generic function useful for validating any type of channel when it is 286/* Generic function useful for validating any type of channel when it is
@@ -339,64 +289,62 @@ typedef struct _SIGNAL_QUEUE_HEADER {
339 * is used to pass the EFI_DIAG_CAPTURE_PROTOCOL needed to log messages. 289 * is used to pass the EFI_DIAG_CAPTURE_PROTOCOL needed to log messages.
340 */ 290 */
341static inline int 291static inline int
342ULTRA_check_channel_client(void __iomem *pChannel, 292spar_check_channel_client(void __iomem *ch,
343 uuid_le expectedTypeGuid, 293 uuid_le expected_uuid,
344 char *channelName, 294 char *chname,
345 u64 expectedMinBytes, 295 u64 expected_min_bytes,
346 u32 expectedVersionId, 296 u32 expected_version,
347 u64 expectedSignature, 297 u64 expected_signature)
348 char *fileName, int lineNumber, void *logCtx)
349{ 298{
350 if (uuid_le_cmp(expectedTypeGuid, NULL_UUID_LE) != 0) { 299 if (uuid_le_cmp(expected_uuid, NULL_UUID_LE) != 0) {
351 uuid_le guid; 300 uuid_le guid;
352 301
353 memcpy_fromio(&guid, 302 memcpy_fromio(&guid,
354 &((CHANNEL_HEADER __iomem *)(pChannel))->Type, 303 &((struct channel_header __iomem *)(ch))->chtype,
355 sizeof(guid)); 304 sizeof(guid));
356 /* caller wants us to verify type GUID */ 305 /* caller wants us to verify type GUID */
357 if (uuid_le_cmp(guid, expectedTypeGuid) != 0) { 306 if (uuid_le_cmp(guid, expected_uuid) != 0) {
358 CHANNEL_GUID_MISMATCH(expectedTypeGuid, channelName, 307 pr_err("Channel mismatch on channel=%s(%pUL) field=type expected=%pUL actual=%pUL\n",
359 "type", expectedTypeGuid, 308 chname, &expected_uuid,
360 guid, fileName, 309 &expected_uuid, &guid);
361 lineNumber, logCtx);
362 return 0; 310 return 0;
363 } 311 }
364 } 312 }
365 if (expectedMinBytes > 0) /* caller wants us to verify 313 if (expected_min_bytes > 0) { /* caller wants us to verify
366 * channel size */ 314 * channel size */
367 if (readq(&((CHANNEL_HEADER __iomem *) 315 unsigned long long bytes =
368 (pChannel))->Size) < expectedMinBytes) { 316 readq(&((struct channel_header __iomem *)
369 CHANNEL_U64_MISMATCH(expectedTypeGuid, channelName, 317 (ch))->size);
370 "size", expectedMinBytes, 318 if (bytes < expected_min_bytes) {
371 readq(&((CHANNEL_HEADER __iomem *) 319 pr_err("Channel mismatch on channel=%s(%pUL) field=size expected=0x%-8.8Lx actual=0x%-8.8Lx\n",
372 (pChannel))->Size), 320 chname, &expected_uuid,
373 fileName, 321 (unsigned long long)expected_min_bytes, bytes);
374 lineNumber, logCtx);
375 return 0; 322 return 0;
376 } 323 }
377 if (expectedVersionId > 0) /* caller wants us to verify 324 }
325 if (expected_version > 0) { /* caller wants us to verify
378 * channel version */ 326 * channel version */
379 if (readl(&((CHANNEL_HEADER __iomem *) (pChannel))->VersionId) 327 unsigned long ver = readl(&((struct channel_header __iomem *)
380 != expectedVersionId) { 328 (ch))->version_id);
381 CHANNEL_U32_MISMATCH(expectedTypeGuid, channelName, 329 if (ver != expected_version) {
382 "version", expectedVersionId, 330 pr_err("Channel mismatch on channel=%s(%pUL) field=version expected=0x%-8.8lx actual=0x%-8.8lx\n",
383 readl(&((CHANNEL_HEADER __iomem *) 331 chname, &expected_uuid,
384 (pChannel))->VersionId), 332 (unsigned long)expected_version, ver);
385 fileName, lineNumber, logCtx);
386 return 0; 333 return 0;
387 } 334 }
388 if (expectedSignature > 0) /* caller wants us to verify 335 }
336 if (expected_signature > 0) { /* caller wants us to verify
389 * channel signature */ 337 * channel signature */
390 if (readq(&((CHANNEL_HEADER __iomem *) (pChannel))->Signature) 338 unsigned long long sig =
391 != expectedSignature) { 339 readq(&((struct channel_header __iomem *)
392 CHANNEL_U64_MISMATCH(expectedTypeGuid, channelName, 340 (ch))->signature);
393 "signature", expectedSignature, 341 if (sig != expected_signature) {
394 readq(&((CHANNEL_HEADER __iomem *) 342 pr_err("Channel mismatch on channel=%s(%pUL) field=signature expected=0x%-8.8llx actual=0x%-8.8llx\n",
395 (pChannel))->Signature), 343 chname, &expected_uuid,
396 fileName, 344 expected_signature, sig);
397 lineNumber, logCtx);
398 return 0; 345 return 0;
399 } 346 }
347 }
400 return 1; 348 return 1;
401} 349}
402 350
@@ -405,19 +353,16 @@ ULTRA_check_channel_client(void __iomem *pChannel,
405 * Note that <logCtx> is only needed for callers in the EFI environment, and 353 * Note that <logCtx> is only needed for callers in the EFI environment, and
406 * is used to pass the EFI_DIAG_CAPTURE_PROTOCOL needed to log messages. 354 * is used to pass the EFI_DIAG_CAPTURE_PROTOCOL needed to log messages.
407 */ 355 */
408static inline int 356static inline int spar_check_channel_server(uuid_le typeuuid, char *name,
409ULTRA_check_channel_server(uuid_le typeGuid, 357 u64 expected_min_bytes,
410 char *channelName, 358 u64 actual_bytes)
411 u64 expectedMinBytes,
412 u64 actualBytes,
413 char *fileName, int lineNumber, void *logCtx)
414{ 359{
415 if (expectedMinBytes > 0) /* caller wants us to verify 360 if (expected_min_bytes > 0) /* caller wants us to verify
416 * channel size */ 361 * channel size */
417 if (actualBytes < expectedMinBytes) { 362 if (actual_bytes < expected_min_bytes) {
418 CHANNEL_U64_MISMATCH(typeGuid, channelName, "size", 363 pr_err("Channel mismatch on channel=%s(%pUL) field=size expected=0x%-8.8llx actual=0x%-8.8llx\n",
419 expectedMinBytes, actualBytes, 364 name, &typeuuid, expected_min_bytes,
420 fileName, lineNumber, logCtx); 365 actual_bytes);
421 return 0; 366 return 0;
422 } 367 }
423 return 1; 368 return 1;
@@ -430,7 +375,7 @@ ULTRA_check_channel_server(uuid_le typeGuid,
430 * in it, the return pointer will be to the beginning of the string. 375 * in it, the return pointer will be to the beginning of the string.
431 */ 376 */
432static inline u8 * 377static inline u8 *
433PathName_Last_N_Nodes(u8 *s, unsigned int n) 378pathname_last_n_nodes(u8 *s, unsigned int n)
434{ 379{
435 u8 *p = s; 380 u8 *p = s;
436 unsigned int node_count = 0; 381 unsigned int node_count = 0;
@@ -455,59 +400,43 @@ PathName_Last_N_Nodes(u8 *s, unsigned int n)
455} 400}
456 401
457static inline int 402static inline int
458ULTRA_channel_client_acquire_os(void __iomem *pChannel, u8 *chanId, 403spar_channel_client_acquire_os(void __iomem *ch, u8 *id)
459 void *logCtx, char *file, int line, char *func)
460{ 404{
461 CHANNEL_HEADER __iomem *pChan = pChannel; 405 struct channel_header __iomem *hdr = ch;
462 406
463 if (readl(&pChan->CliStateOS) == CHANNELCLI_DISABLED) { 407 if (readl(&hdr->cli_state_os) == CHANNELCLI_DISABLED) {
464 if ((readb(&pChan->CliErrorOS) 408 if ((readb(&hdr->cli_error_os)
465 & ULTRA_CLIERROROS_THROTTLEMSG_DISABLED) == 0) { 409 & ULTRA_CLIERROROS_THROTTLEMSG_DISABLED) == 0) {
466 /* we are NOT throttling this message */ 410 /* we are NOT throttling this message */
467 writeb(readb(&pChan->CliErrorOS) | 411 writeb(readb(&hdr->cli_error_os) |
468 ULTRA_CLIERROROS_THROTTLEMSG_DISABLED, 412 ULTRA_CLIERROROS_THROTTLEMSG_DISABLED,
469 &pChan->CliErrorOS); 413 &hdr->cli_error_os);
470 /* throttle until acquire successful */ 414 /* throttle until acquire successful */
471 415
472 UltraLogEvent(logCtx, 416 pr_info("%s Channel StateTransition INVALID! - acquire failed because OS client DISABLED\n",
473 CHANNELSTATE_DIAG_EVENTID_TRANSITERR, 417 id);
474 CHANNELSTATE_DIAG_SEVERITY,
475 CHANNELSTATE_DIAG_SUBSYS, func, line,
476 "%s Channel StateTransition INVALID! - acquire failed because OS client DISABLED @%s:%d\n",
477 chanId, PathName_Last_N_Nodes(
478 (u8 *) file, 4), line);
479 } 418 }
480 return 0; 419 return 0;
481 } 420 }
482 if ((readl(&pChan->CliStateOS) != CHANNELCLI_OWNED) 421 if ((readl(&hdr->cli_state_os) != CHANNELCLI_OWNED) &&
483 && (readl(&pChan->CliStateBoot) == CHANNELCLI_DISABLED)) { 422 (readl(&hdr->cli_state_boot) == CHANNELCLI_DISABLED)) {
484 /* Our competitor is DISABLED, so we can transition to OWNED */ 423 /* Our competitor is DISABLED, so we can transition to OWNED */
485 UltraLogEvent(logCtx, CHANNELSTATE_DIAG_EVENTID_TRANSITOK, 424 pr_info("%s Channel StateTransition (%s) %s(%d)-->%s(%d)\n",
486 CHANNELSTATE_DIAG_SEVERITY, 425 id, "cli_state_os",
487 CHANNELSTATE_DIAG_SUBSYS, func, line, 426 ULTRA_CHANNELCLI_STRING(readl(&hdr->cli_state_os)),
488 "%s Channel StateTransition (%s) %s(%d)-->%s(%d) @%s:%d\n", 427 readl(&hdr->cli_state_os),
489 chanId, "CliStateOS", 428 ULTRA_CHANNELCLI_STRING(CHANNELCLI_OWNED),
490 ULTRA_CHANNELCLI_STRING( 429 CHANNELCLI_OWNED);
491 readl(&pChan->CliStateOS)), 430 writel(CHANNELCLI_OWNED, &hdr->cli_state_os);
492 readl(&pChan->CliStateOS),
493 ULTRA_CHANNELCLI_STRING(CHANNELCLI_OWNED),
494 CHANNELCLI_OWNED,
495 PathName_Last_N_Nodes((u8 *) file, 4), line);
496 writel(CHANNELCLI_OWNED, &pChan->CliStateOS);
497 mb(); /* required for channel synch */ 431 mb(); /* required for channel synch */
498 } 432 }
499 if (readl(&pChan->CliStateOS) == CHANNELCLI_OWNED) { 433 if (readl(&hdr->cli_state_os) == CHANNELCLI_OWNED) {
500 if (readb(&pChan->CliErrorOS) != 0) { 434 if (readb(&hdr->cli_error_os) != 0) {
501 /* we are in an error msg throttling state; 435 /* we are in an error msg throttling state;
502 * come out of it */ 436 * come out of it */
503 UltraLogEvent(logCtx, 437 pr_info("%s Channel OS client acquire now successful\n",
504 CHANNELSTATE_DIAG_EVENTID_TRANSITOK, 438 id);
505 CHANNELSTATE_DIAG_SEVERITY, 439 writeb(0, &hdr->cli_error_os);
506 CHANNELSTATE_DIAG_SUBSYS, func, line,
507 "%s Channel OS client acquire now successful @%s:%d\n",
508 chanId, PathName_Last_N_Nodes((u8 *) file,
509 4), line);
510 writeb(0, &pChan->CliErrorOS);
511 } 440 }
512 return 1; 441 return 1;
513 } 442 }
@@ -515,95 +444,67 @@ ULTRA_channel_client_acquire_os(void __iomem *pChannel, u8 *chanId,
515 /* We have to do it the "hard way". We transition to BUSY, 444 /* We have to do it the "hard way". We transition to BUSY,
516 * and can use the channel iff our competitor has not also 445 * and can use the channel iff our competitor has not also
517 * transitioned to BUSY. */ 446 * transitioned to BUSY. */
518 if (readl(&pChan->CliStateOS) != CHANNELCLI_ATTACHED) { 447 if (readl(&hdr->cli_state_os) != CHANNELCLI_ATTACHED) {
519 if ((readb(&pChan->CliErrorOS) 448 if ((readb(&hdr->cli_error_os)
520 & ULTRA_CLIERROROS_THROTTLEMSG_NOTATTACHED) == 0) { 449 & ULTRA_CLIERROROS_THROTTLEMSG_NOTATTACHED) == 0) {
521 /* we are NOT throttling this message */ 450 /* we are NOT throttling this message */
522 writeb(readb(&pChan->CliErrorOS) | 451 writeb(readb(&hdr->cli_error_os) |
523 ULTRA_CLIERROROS_THROTTLEMSG_NOTATTACHED, 452 ULTRA_CLIERROROS_THROTTLEMSG_NOTATTACHED,
524 &pChan->CliErrorOS); 453 &hdr->cli_error_os);
525 /* throttle until acquire successful */ 454 /* throttle until acquire successful */
526 UltraLogEvent(logCtx, 455 pr_info("%s Channel StateTransition INVALID! - acquire failed because OS client NOT ATTACHED (state=%s(%d))\n",
527 CHANNELSTATE_DIAG_EVENTID_TRANSITERR, 456 id, ULTRA_CHANNELCLI_STRING(
528 CHANNELSTATE_DIAG_SEVERITY, 457 readl(&hdr->cli_state_os)),
529 CHANNELSTATE_DIAG_SUBSYS, func, line, 458 readl(&hdr->cli_state_os));
530 "%s Channel StateTransition INVALID! - acquire failed because OS client NOT ATTACHED (state=%s(%d)) @%s:%d\n",
531 chanId,
532 ULTRA_CHANNELCLI_STRING(
533 readl(&pChan->CliStateOS)),
534 readl(&pChan->CliStateOS),
535 PathName_Last_N_Nodes((u8 *) file, 4),
536 line);
537 } 459 }
538 return 0; 460 return 0;
539 } 461 }
540 writel(CHANNELCLI_BUSY, &pChan->CliStateOS); 462 writel(CHANNELCLI_BUSY, &hdr->cli_state_os);
541 mb(); /* required for channel synch */ 463 mb(); /* required for channel synch */
542 if (readl(&pChan->CliStateBoot) == CHANNELCLI_BUSY) { 464 if (readl(&hdr->cli_state_boot) == CHANNELCLI_BUSY) {
543 if ((readb(&pChan->CliErrorOS) 465 if ((readb(&hdr->cli_error_os)
544 & ULTRA_CLIERROROS_THROTTLEMSG_BUSY) == 0) { 466 & ULTRA_CLIERROROS_THROTTLEMSG_BUSY) == 0) {
545 /* we are NOT throttling this message */ 467 /* we are NOT throttling this message */
546 writeb(readb(&pChan->CliErrorOS) | 468 writeb(readb(&hdr->cli_error_os) |
547 ULTRA_CLIERROROS_THROTTLEMSG_BUSY, 469 ULTRA_CLIERROROS_THROTTLEMSG_BUSY,
548 &pChan->CliErrorOS); 470 &hdr->cli_error_os);
549 /* throttle until acquire successful */ 471 /* throttle until acquire successful */
550 UltraLogEvent(logCtx, 472 pr_info("%s Channel StateTransition failed - host OS acquire failed because boot BUSY\n",
551 CHANNELSTATE_DIAG_EVENTID_TRANSITBUSY, 473 id);
552 CHANNELSTATE_DIAG_SEVERITY,
553 CHANNELSTATE_DIAG_SUBSYS, func, line,
554 "%s Channel StateTransition failed - host OS acquire failed because boot BUSY @%s:%d\n",
555 chanId, PathName_Last_N_Nodes((u8 *) file,
556 4), line);
557 } 474 }
558 /* reset busy */ 475 /* reset busy */
559 writel(CHANNELCLI_ATTACHED, &pChan->CliStateOS); 476 writel(CHANNELCLI_ATTACHED, &hdr->cli_state_os);
560 mb(); /* required for channel synch */ 477 mb(); /* required for channel synch */
561 return 0; 478 return 0;
562 } 479 }
563 if (readb(&pChan->CliErrorOS) != 0) { 480 if (readb(&hdr->cli_error_os) != 0) {
564 /* we are in an error msg throttling state; come out of it */ 481 /* we are in an error msg throttling state; come out of it */
565 UltraLogEvent(logCtx, CHANNELSTATE_DIAG_EVENTID_TRANSITOK, 482 pr_info("%s Channel OS client acquire now successful\n", id);
566 CHANNELSTATE_DIAG_SEVERITY, 483 writeb(0, &hdr->cli_error_os);
567 CHANNELSTATE_DIAG_SUBSYS, func, line,
568 "%s Channel OS client acquire now successful @%s:%d\n",
569 chanId, PathName_Last_N_Nodes((u8 *) file, 4),
570 line);
571 writeb(0, &pChan->CliErrorOS);
572 } 484 }
573 return 1; 485 return 1;
574} 486}
575 487
576static inline void 488static inline void
577ULTRA_channel_client_release_os(void __iomem *pChannel, u8 *chanId, 489spar_channel_client_release_os(void __iomem *ch, u8 *id)
578 void *logCtx, char *file, int line, char *func)
579{ 490{
580 CHANNEL_HEADER __iomem *pChan = pChannel; 491 struct channel_header __iomem *hdr = ch;
581 492
582 if (readb(&pChan->CliErrorOS) != 0) { 493 if (readb(&hdr->cli_error_os) != 0) {
583 /* we are in an error msg throttling state; come out of it */ 494 /* we are in an error msg throttling state; come out of it */
584 UltraLogEvent(logCtx, CHANNELSTATE_DIAG_EVENTID_TRANSITOK, 495 pr_info("%s Channel OS client error state cleared\n", id);
585 CHANNELSTATE_DIAG_SEVERITY, 496 writeb(0, &hdr->cli_error_os);
586 CHANNELSTATE_DIAG_SUBSYS, func, line,
587 "%s Channel OS client error state cleared @%s:%d\n",
588 chanId, PathName_Last_N_Nodes((u8 *) file, 4),
589 line);
590 writeb(0, &pChan->CliErrorOS);
591 } 497 }
592 if (readl(&pChan->CliStateOS) == CHANNELCLI_OWNED) 498 if (readl(&hdr->cli_state_os) == CHANNELCLI_OWNED)
593 return; 499 return;
594 if (readl(&pChan->CliStateOS) != CHANNELCLI_BUSY) { 500 if (readl(&hdr->cli_state_os) != CHANNELCLI_BUSY) {
595 UltraLogEvent(logCtx, CHANNELSTATE_DIAG_EVENTID_TRANSITERR, 501 pr_info("%s Channel StateTransition INVALID! - release failed because OS client NOT BUSY (state=%s(%d))\n",
596 CHANNELSTATE_DIAG_SEVERITY, 502 id, ULTRA_CHANNELCLI_STRING(
597 CHANNELSTATE_DIAG_SUBSYS, func, line, 503 readl(&hdr->cli_state_os)),
598 "%s Channel StateTransition INVALID! - release failed because OS client NOT BUSY (state=%s(%d)) @%s:%d\n", 504 readl(&hdr->cli_state_os));
599 chanId,
600 ULTRA_CHANNELCLI_STRING(
601 readl(&pChan->CliStateOS)),
602 readl(&pChan->CliStateOS),
603 PathName_Last_N_Nodes((u8 *) file, 4), line);
604 /* return; */ 505 /* return; */
605 } 506 }
606 writel(CHANNELCLI_ATTACHED, &pChan->CliStateOS); /* release busy */ 507 writel(CHANNELCLI_ATTACHED, &hdr->cli_state_os); /* release busy */
607} 508}
608 509
609/* 510/*
@@ -625,8 +526,8 @@ ULTRA_channel_client_release_os(void __iomem *pChannel, u8 *chanId,
625* full. 526* full.
626*/ 527*/
627 528
628unsigned char visor_signal_insert(CHANNEL_HEADER __iomem *pChannel, u32 Queue, 529unsigned char spar_signal_insert(struct channel_header __iomem *ch, u32 queue,
629 void *pSignal); 530 void *sig);
630 531
631/* 532/*
632* Routine Description: 533* Routine Description:
@@ -647,8 +548,8 @@ unsigned char visor_signal_insert(CHANNEL_HEADER __iomem *pChannel, u32 Queue,
647* empty. 548* empty.
648*/ 549*/
649 550
650unsigned char visor_signal_remove(CHANNEL_HEADER __iomem *pChannel, u32 Queue, 551unsigned char spar_signal_remove(struct channel_header __iomem *ch, u32 queue,
651 void *pSignal); 552 void *sig);
652 553
653/* 554/*
654* Routine Description: 555* Routine Description:
@@ -669,8 +570,8 @@ unsigned char visor_signal_remove(CHANNEL_HEADER __iomem *pChannel, u32 Queue,
669* Return value: 570* Return value:
670* # of signals copied. 571* # of signals copied.
671*/ 572*/
672unsigned int SignalRemoveAll(pCHANNEL_HEADER pChannel, u32 Queue, 573unsigned int spar_signal_remove_all(struct channel_header *ch, u32 queue,
673 void *pSignal); 574 void *sig);
674 575
675/* 576/*
676* Routine Description: 577* Routine Description:
@@ -683,7 +584,7 @@ unsigned int SignalRemoveAll(pCHANNEL_HEADER pChannel, u32 Queue,
683* Return value: 584* Return value:
684* 1 if the signal queue is empty, 0 otherwise. 585* 1 if the signal queue is empty, 0 otherwise.
685*/ 586*/
686unsigned char visor_signalqueue_empty(CHANNEL_HEADER __iomem *pChannel, 587unsigned char spar_signalqueue_empty(struct channel_header __iomem *ch,
687 u32 Queue); 588 u32 queue);
688 589
689#endif 590#endif
diff --git a/drivers/staging/unisys/common-spar/include/channels/channel_guid.h b/drivers/staging/unisys/common-spar/include/channels/channel_guid.h
index 63c67ca4c9ec..706363fc3e9a 100644
--- a/drivers/staging/unisys/common-spar/include/channels/channel_guid.h
+++ b/drivers/staging/unisys/common-spar/include/channels/channel_guid.h
@@ -20,45 +20,42 @@
20/* Used in IOChannel 20/* Used in IOChannel
21 * {414815ed-c58c-11da-95a9-00e08161165f} 21 * {414815ed-c58c-11da-95a9-00e08161165f}
22 */ 22 */
23#define ULTRA_VHBA_CHANNEL_PROTOCOL_GUID \ 23#define SPAR_VHBA_CHANNEL_PROTOCOL_UUID \
24 UUID_LE(0x414815ed, 0xc58c, 0x11da, \ 24 UUID_LE(0x414815ed, 0xc58c, 0x11da, \
25 0x95, 0xa9, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f) 25 0x95, 0xa9, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f)
26static const uuid_le UltraVhbaChannelProtocolGuid = 26static const uuid_le spar_vhba_channel_protocol_uuid =
27 ULTRA_VHBA_CHANNEL_PROTOCOL_GUID; 27 SPAR_VHBA_CHANNEL_PROTOCOL_UUID;
28 28
29/* Used in IOChannel 29/* Used in IOChannel
30 * {8cd5994d-c58e-11da-95a9-00e08161165f} 30 * {8cd5994d-c58e-11da-95a9-00e08161165f}
31 */ 31 */
32#define ULTRA_VNIC_CHANNEL_PROTOCOL_GUID \ 32#define SPAR_VNIC_CHANNEL_PROTOCOL_UUID \
33 UUID_LE(0x8cd5994d, 0xc58e, 0x11da, \ 33 UUID_LE(0x8cd5994d, 0xc58e, 0x11da, \
34 0x95, 0xa9, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f) 34 0x95, 0xa9, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f)
35static const uuid_le UltraVnicChannelProtocolGuid = 35static const uuid_le spar_vnic_channel_protocol_uuid =
36 ULTRA_VNIC_CHANNEL_PROTOCOL_GUID; 36 SPAR_VNIC_CHANNEL_PROTOCOL_UUID;
37 37
38/* Used in IOChannel 38/* Used in IOChannel
39 * {72120008-4AAB-11DC-8530-444553544200} 39 * {72120008-4AAB-11DC-8530-444553544200}
40 */ 40 */
41#define ULTRA_SIOVM_GUID \ 41#define SPAR_SIOVM_UUID \
42 UUID_LE(0x72120008, 0x4AAB, 0x11DC, \ 42 UUID_LE(0x72120008, 0x4AAB, 0x11DC, \
43 0x85, 0x30, 0x44, 0x45, 0x53, 0x54, 0x42, 0x00) 43 0x85, 0x30, 0x44, 0x45, 0x53, 0x54, 0x42, 0x00)
44static const uuid_le UltraSIOVMGuid = ULTRA_SIOVM_GUID; 44static const uuid_le spar_siovm_uuid = SPAR_SIOVM_UUID;
45
46 45
47/* Used in visornoop/visornoop_main.c 46/* Used in visornoop/visornoop_main.c
48 * {5b52c5ac-e5f5-4d42-8dff-429eaecd221f} 47 * {5b52c5ac-e5f5-4d42-8dff-429eaecd221f}
49 */ 48 */
50#define ULTRA_CONTROLDIRECTOR_CHANNEL_PROTOCOL_GUID \ 49#define SPAR_CONTROLDIRECTOR_CHANNEL_PROTOCOL_UUID \
51 UUID_LE(0x5b52c5ac, 0xe5f5, 0x4d42, \ 50 UUID_LE(0x5b52c5ac, 0xe5f5, 0x4d42, \
52 0x8d, 0xff, 0x42, 0x9e, 0xae, 0xcd, 0x22, 0x1f) 51 0x8d, 0xff, 0x42, 0x9e, 0xae, 0xcd, 0x22, 0x1f)
53 52
54static const uuid_le UltraControlDirectorChannelProtocolGuid = 53static const uuid_le spar_controldirector_channel_protocol_uuid =
55 ULTRA_CONTROLDIRECTOR_CHANNEL_PROTOCOL_GUID; 54 SPAR_CONTROLDIRECTOR_CHANNEL_PROTOCOL_UUID;
56 55
57/* Used in visorchipset/visorchipset_main.c 56/* Used in visorchipset/visorchipset_main.c
58 * {B4E79625-AEDE-4EAA-9E11-D3EDDCD4504C} 57 * {B4E79625-AEDE-4EAA-9E11-D3EDDCD4504C}
59 */ 58 */
60#define ULTRA_DIAG_POOL_CHANNEL_PROTOCOL_GUID \ 59#define SPAR_DIAG_POOL_CHANNEL_PROTOCOL_UUID \
61 UUID_LE(0xb4e79625, 0xaede, 0x4eaa, \ 60 UUID_LE(0xb4e79625, 0xaede, 0x4eaa, \
62 0x9e, 0x11, 0xd3, 0xed, 0xdc, 0xd4, 0x50, 0x4c) 61 0x9e, 0x11, 0xd3, 0xed, 0xdc, 0xd4, 0x50, 0x4c)
63
64
diff --git a/drivers/staging/unisys/common-spar/include/channels/controlframework.h b/drivers/staging/unisys/common-spar/include/channels/controlframework.h
index fd4726e754ea..33d9caf337c8 100644
--- a/drivers/staging/unisys/common-spar/include/channels/controlframework.h
+++ b/drivers/staging/unisys/common-spar/include/channels/controlframework.h
@@ -28,50 +28,35 @@
28#include <linux/types.h> 28#include <linux/types.h>
29#include "channel.h" 29#include "channel.h"
30 30
31#define ULTRA_MEMORY_COUNT_Ki 1024 31struct spar_segment_state {
32 32 u16 enabled:1; /* Bit 0: May enter other states */
33/* Scale order 0 is one 32-bit (4-byte) word (in 64 or 128-bit 33 u16 active:1; /* Bit 1: Assigned to active partition */
34 * architecture potentially 64 or 128-bit word) */ 34 u16 alive:1; /* Bit 2: Configure message sent to
35#define ULTRA_MEMORY_PAGE_WORD 4
36
37/* Define Ki scale page to be traditional 4KB page */
38#define ULTRA_MEMORY_PAGE_Ki (ULTRA_MEMORY_PAGE_WORD * ULTRA_MEMORY_COUNT_Ki)
39typedef struct _ULTRA_SEGMENT_STATE {
40 u16 Enabled:1; /* Bit 0: May enter other states */
41 u16 Active:1; /* Bit 1: Assigned to active partition */
42 u16 Alive:1; /* Bit 2: Configure message sent to
43 * service/server */ 35 * service/server */
44 u16 Revoked:1; /* Bit 3: similar to partition state 36 u16 revoked:1; /* Bit 3: similar to partition state
45 * ShuttingDown */ 37 * ShuttingDown */
46 u16 Allocated:1; /* Bit 4: memory (device/port number) 38 u16 allocated:1; /* Bit 4: memory (device/port number)
47 * has been selected by Command */ 39 * has been selected by Command */
48 u16 Known:1; /* Bit 5: has been introduced to the 40 u16 known:1; /* Bit 5: has been introduced to the
49 * service/guest partition */ 41 * service/guest partition */
50 u16 Ready:1; /* Bit 6: service/Guest partition has 42 u16 ready:1; /* Bit 6: service/Guest partition has
51 * responded to introduction */ 43 * responded to introduction */
52 u16 Operating:1; /* Bit 7: resource is configured and 44 u16 operating:1; /* Bit 7: resource is configured and
53 * operating */ 45 * operating */
54 /* Note: don't use high bit unless we need to switch to ushort 46 /* Note: don't use high bit unless we need to switch to ushort
55 * which is non-compliant */ 47 * which is non-compliant */
56} ULTRA_SEGMENT_STATE; 48};
57static const ULTRA_SEGMENT_STATE SegmentStateRunning = { 49
50static const struct spar_segment_state segment_state_running = {
58 1, 1, 1, 0, 1, 1, 1, 1 51 1, 1, 1, 0, 1, 1, 1, 1
59}; 52};
60static const ULTRA_SEGMENT_STATE SegmentStatePaused = { 53
54static const struct spar_segment_state segment_state_paused = {
61 1, 1, 1, 0, 1, 1, 1, 0 55 1, 1, 1, 0, 1, 1, 1, 0
62}; 56};
63static const ULTRA_SEGMENT_STATE SegmentStateStandby = { 57
58static const struct spar_segment_state segment_state_standby = {
64 1, 1, 0, 0, 1, 1, 1, 0 59 1, 1, 0, 0, 1, 1, 1, 0
65}; 60};
66typedef union {
67 u64 Full;
68 struct {
69 u8 Major; /* will be 1 for the first release and
70 * increment thereafter */
71 u8 Minor;
72 u16 Maintenance;
73 u32 Revision; /* Subversion revision */
74 } Part;
75} ULTRA_COMPONENT_VERSION;
76 61
77#endif /* _CONTROL_FRAMEWORK_H_ not defined */ 62#endif /* _CONTROL_FRAMEWORK_H_ not defined */
diff --git a/drivers/staging/unisys/common-spar/include/channels/controlvmchannel.h b/drivers/staging/unisys/common-spar/include/channels/controlvmchannel.h
index d08c198e0de3..a66db7968d6c 100644
--- a/drivers/staging/unisys/common-spar/include/channels/controlvmchannel.h
+++ b/drivers/staging/unisys/common-spar/include/channels/controlvmchannel.h
@@ -27,12 +27,12 @@ enum { INVALID_GUEST_FIRMWARE, SAMPLE_GUEST_FIRMWARE,
27}; 27};
28 28
29/* {2B3C2D10-7EF5-4ad8-B966-3448B7386B3D} */ 29/* {2B3C2D10-7EF5-4ad8-B966-3448B7386B3D} */
30#define ULTRA_CONTROLVM_CHANNEL_PROTOCOL_GUID \ 30#define SPAR_CONTROLVM_CHANNEL_PROTOCOL_UUID \
31 UUID_LE(0x2b3c2d10, 0x7ef5, 0x4ad8, \ 31 UUID_LE(0x2b3c2d10, 0x7ef5, 0x4ad8, \
32 0xb9, 0x66, 0x34, 0x48, 0xb7, 0x38, 0x6b, 0x3d) 32 0xb9, 0x66, 0x34, 0x48, 0xb7, 0x38, 0x6b, 0x3d)
33 33
34static const uuid_le UltraControlvmChannelProtocolGuid = 34static const uuid_le spar_controlvm_channel_protocol_uuid =
35 ULTRA_CONTROLVM_CHANNEL_PROTOCOL_GUID; 35 SPAR_CONTROLVM_CHANNEL_PROTOCOL_UUID;
36 36
37#define ULTRA_CONTROLVM_CHANNEL_PROTOCOL_SIGNATURE \ 37#define ULTRA_CONTROLVM_CHANNEL_PROTOCOL_SIGNATURE \
38 ULTRA_CHANNEL_PROTOCOL_SIGNATURE 38 ULTRA_CHANNEL_PROTOCOL_SIGNATURE
@@ -45,19 +45,13 @@ static const uuid_le UltraControlvmChannelProtocolGuid =
45* channel struct withOUT needing to increment this. */ 45* channel struct withOUT needing to increment this. */
46#define ULTRA_CONTROLVM_CHANNEL_PROTOCOL_VERSIONID 1 46#define ULTRA_CONTROLVM_CHANNEL_PROTOCOL_VERSIONID 1
47 47
48#define ULTRA_CONTROLVM_CHANNEL_OK_CLIENT(pChannel, logCtx) \ 48#define SPAR_CONTROLVM_CHANNEL_OK_CLIENT(ch) \
49 (ULTRA_check_channel_client(pChannel, \ 49 spar_check_channel_client(ch, \
50 UltraControlvmChannelProtocolGuid, \ 50 spar_controlvm_channel_protocol_uuid, \
51 "controlvm", \ 51 "controlvm", \
52 sizeof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL), \ 52 sizeof(struct spar_controlvm_channel_protocol), \
53 ULTRA_CONTROLVM_CHANNEL_PROTOCOL_VERSIONID, \ 53 ULTRA_CONTROLVM_CHANNEL_PROTOCOL_VERSIONID, \
54 ULTRA_CONTROLVM_CHANNEL_PROTOCOL_SIGNATURE, \ 54 ULTRA_CONTROLVM_CHANNEL_PROTOCOL_SIGNATURE)
55 __FILE__, __LINE__, logCtx))
56#define ULTRA_CONTROLVM_CHANNEL_OK_SERVER(actualBytes, logCtx) \
57 (ULTRA_check_channel_server(UltraControlvmChannelProtocolGuid, \
58 "controlvm", \
59 sizeof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL), \
60 actualBytes, __FILE__, __LINE__, logCtx))
61 55
62#define MY_DEVICE_INDEX 0 56#define MY_DEVICE_INDEX 0
63#define MAX_MACDATA_LEN 8 /* number of bytes for MAC address in config packet */ 57#define MAX_MACDATA_LEN 8 /* number of bytes for MAC address in config packet */
@@ -88,7 +82,7 @@ static const uuid_le UltraControlvmChannelProtocolGuid =
88 * - issued on the EventQueue queue (q #2) in the ControlVm channel 82 * - issued on the EventQueue queue (q #2) in the ControlVm channel
89 * - responded to on the EventAckQueue queue (q #3) in the ControlVm channel 83 * - responded to on the EventAckQueue queue (q #3) in the ControlVm channel
90 */ 84 */
91typedef enum { 85enum controlvm_id {
92 CONTROLVM_INVALID = 0, 86 CONTROLVM_INVALID = 0,
93 /* SWITCH commands required Parameter: SwitchNumber */ 87 /* SWITCH commands required Parameter: SwitchNumber */
94 /* BUS commands required Parameter: BusNumber */ 88 /* BUS commands required Parameter: BusNumber */
@@ -117,9 +111,9 @@ typedef enum {
117 CONTROLVM_CHIPSET_READY = 0x304, /* CP --> SP */ 111 CONTROLVM_CHIPSET_READY = 0x304, /* CP --> SP */
118 CONTROLVM_CHIPSET_SELFTEST = 0x305, /* CP --> SP */ 112 CONTROLVM_CHIPSET_SELFTEST = 0x305, /* CP --> SP */
119 113
120} CONTROLVM_ID; 114};
121 115
122struct InterruptInfo { 116struct irq_info {
123 /**< specifies interrupt info. It is used to send interrupts 117 /**< specifies interrupt info. It is used to send interrupts
124 * for this channel. The peer at the end of this channel 118 * for this channel. The peer at the end of this channel
125 * who has registered an interrupt (using recv fields 119 * who has registered an interrupt (using recv fields
@@ -128,495 +122,390 @@ struct InterruptInfo {
128 * interrupt. Currently this is used by IOPart-SP to wake 122 * interrupt. Currently this is used by IOPart-SP to wake
129 * up GP when Data Channel transitions from empty to 123 * up GP when Data Channel transitions from empty to
130 * non-empty.*/ 124 * non-empty.*/
131 u64 sendInterruptHandle; 125 u64 send_irq_handle;
132 126
133 /**< specifies interrupt handle. It is used to retrieve the 127 /**< specifies interrupt handle. It is used to retrieve the
134 * corresponding interrupt pin from Monitor; and the 128 * corresponding interrupt pin from Monitor; and the
135 * interrupt pin is used to connect to the corresponding 129 * interrupt pin is used to connect to the corresponding
136 * intrrupt. Used by IOPart-GP only. */ 130 * interrupt. Used by IOPart-GP only. */
137 u64 recvInterruptHandle; 131 u64 recv_irq_handle;
138 132
139 /**< specifies interrupt vector. It, interrupt pin, and shared are 133 /**< specifies interrupt vector. It, interrupt pin, and shared are
140 * used to connect to the corresponding interrupt. Used by 134 * used to connect to the corresponding interrupt. Used by
141 * IOPart-GP only. */ 135 * IOPart-GP only. */
142 u32 recvInterruptVector; 136 u32 recv_irq_vector;
143 137
144 /**< specifies if the recvInterrupt is shared. It, interrupt pin 138 /**< specifies if the recvInterrupt is shared. It, interrupt pin
145 * and vector are used to connect to 0 = not shared; 1 = shared. 139 * and vector are used to connect to 0 = not shared; 1 = shared.
146 * the corresponding interrupt. Used by IOPart-GP only. */ 140 * the corresponding interrupt. Used by IOPart-GP only. */
147 u8 recvInterruptShared; 141 u8 recv_irq_shared;
148 u8 reserved[3]; /* Natural alignment purposes */ 142 u8 reserved[3]; /* Natural alignment purposes */
149}; 143};
150 144
151struct PciId { 145struct pci_id {
152 u16 Domain; 146 u16 domain;
153 u8 Bus; 147 u8 bus;
154 u8 Slot; 148 u8 slot;
155 u8 Func; 149 u8 func;
156 u8 Reserved[3]; /* Natural alignment purposes */ 150 u8 reserved[3]; /* Natural alignment purposes */
157};
158
159struct PciConfigHdr {
160 u16 VendorId;
161 u16 SubSysVendor;
162 u16 DeviceId;
163 u16 SubSysDevice;
164 u32 ClassCode;
165 u32 Reserved; /* Natural alignment purposes */
166};
167
168struct ScsiId {
169 u32 Bus;
170 u32 Target;
171 u32 Lun;
172 u32 Host; /* Command should ignore this for *
173 * DiskArrival/RemovalEvents */
174};
175
176struct WWID {
177 u32 wwid1;
178 u32 wwid2;
179};
180
181struct virtDiskInfo {
182 u32 switchNo; /* defined by SWITCH_CREATE */
183 u32 externalPortNo; /* 0 for SAS RAID provided (external)
184 * virtual disks, 1 for virtual disk
185 * images, 2 for gold disk images */
186 u16 VirtualDiskIndex; /* Index of disk descriptor in the
187 * VirtualDisk segment associated with
188 * externalPortNo */
189 u16 Reserved1;
190 u32 Reserved2;
191}; 151};
192 152
193typedef enum { 153struct efi_spar_indication {
194 CONTROLVM_ACTION_NONE = 0, 154 u64 boot_to_fw_ui:1; /* Bit 0: Stop in uefi ui */
195 CONTROLVM_ACTION_SET_RESTORE = 0x05E7, 155 u64 clear_nvram:1; /* Bit 1: Clear NVRAM */
196 CONTROLVM_ACTION_CLEAR_RESTORE = 0x0C18, 156 u64 clear_cmos:1; /* Bit 2: Clear CMOS */
197 CONTROLVM_ACTION_RESTORING = 0x08E5, 157 u64 boot_to_tool:1; /* Bit 3: Run install tool */
198 CONTROLVM_ACTION_RESTORE_BUSY = 0x0999,
199 CONTROLVM_ACTION_CLEAR_NVRAM = 0xB01
200} CONTROLVM_ACTION;
201
202typedef enum _ULTRA_TOOL_ACTIONS {
203 /* enumeration that defines intended action */
204 ULTRA_TOOL_ACTION_NONE = 0, /* normal boot of boot disk */
205 ULTRA_TOOL_ACTION_INSTALL = 1, /* install source disk(s) to boot
206 * disk */
207 ULTRA_TOOL_ACTION_CAPTURE = 2, /* capture boot disk to target disk(s)
208 * as 'gold image' */
209 ULTRA_TOOL_ACTION_REPAIR = 3, /* use source disk(s) to repair
210 * installation on boot disk */
211 ULTRA_TOOL_ACTION_CLEAN = 4, /* 'scrub' virtual disk before
212 * releasing back to storage pool */
213 ULTRA_TOOL_ACTION_UPGRADE = 5, /* upgrade to use content of images
214 * referenced from newer blueprint */
215 ULTRA_TOOL_ACTION_DIAG = 6, /* use tool to invoke diagnostic script
216 * provided by blueprint */
217 ULTRA_TOOL_ACTION_FAILED = 7, /* used when tool fails installation
218 and cannot continue */
219 ULTRA_TOOL_ACTION_COUNT = 8
220} ULTRA_TOOL_ACTIONS;
221
222typedef struct _ULTRA_EFI_SPAR_INDICATION {
223 u64 BootToFirmwareUI:1; /* Bit 0: Stop in uefi ui */
224 u64 ClearNvram:1; /* Bit 1: Clear NVRAM */
225 u64 ClearCmos:1; /* Bit 2: Clear CMOS */
226 u64 BootToTool:1; /* Bit 3: Run install tool */
227 /* remaining bits are available */ 158 /* remaining bits are available */
228} ULTRA_EFI_SPAR_INDICATION; 159};
229 160
230typedef enum { 161enum ultra_chipset_feature {
231 ULTRA_CHIPSET_FEATURE_REPLY = 0x00000001, 162 ULTRA_CHIPSET_FEATURE_REPLY = 0x00000001,
232 ULTRA_CHIPSET_FEATURE_PARA_HOTPLUG = 0x00000002, 163 ULTRA_CHIPSET_FEATURE_PARA_HOTPLUG = 0x00000002,
233 ULTRA_CHIPSET_FEATURE_PCIVBUS = 0x00000004 164 ULTRA_CHIPSET_FEATURE_PCIVBUS = 0x00000004
234} ULTRA_CHIPSET_FEATURE; 165};
235 166
236/** This is the common structure that is at the beginning of every 167/** This is the common structure that is at the beginning of every
237 * ControlVm message (both commands and responses) in any ControlVm 168 * ControlVm message (both commands and responses) in any ControlVm
238 * queue. Commands are easily distinguished from responses by 169 * queue. Commands are easily distinguished from responses by
239 * looking at the flags.response field. 170 * looking at the flags.response field.
240 */ 171 */
241typedef struct _CONTROLVM_MESSAGE_HEADER { 172struct controlvm_message_header {
242 u32 Id; /* See CONTROLVM_ID. */ 173 u32 id; /* See CONTROLVM_ID. */
243 /* For requests, indicates the message type. */ 174 /* For requests, indicates the message type. */
244 /* For responses, indicates the type of message we are responding to. */ 175 /* For responses, indicates the type of message we are responding to. */
245 176
246 u32 MessageSize; /* Includes size of this struct + size 177 u32 message_size; /* Includes size of this struct + size
247 * of message */ 178 * of message */
248 u32 SegmentIndex; /* Index of segment containing Vm 179 u32 segment_index; /* Index of segment containing Vm
249 * message/information */ 180 * message/information */
250 u32 CompletionStatus; /* Error status code or result of 181 u32 completion_status; /* Error status code or result of
251 * message completion */ 182 * message completion */
252 struct { 183 struct {
253 u32 failed:1; /**< =1 in a response to * signify 184 u32 failed:1; /**< =1 in a response to * signify
254 * failure */ 185 * failure */
255 u32 responseExpected:1; /**< =1 in all messages that expect a 186 u32 response_expected:1; /**< =1 in all messages that expect a
256 * response (Control ignores this 187 * response (Control ignores this
257 * bit) */ 188 * bit) */
258 u32 server:1; /**< =1 in all bus & device-related 189 u32 server:1; /**< =1 in all bus & device-related
259 * messages where the message 190 * messages where the message
260 * receiver is to act as the bus or 191 * receiver is to act as the bus or
261 * device server */ 192 * device server */
262 u32 testMessage:1; /**< =1 for testing use only 193 u32 test_message:1; /**< =1 for testing use only
263 * (Control and Command ignore this 194 * (Control and Command ignore this
264 * bit) */ 195 * bit) */
265 u32 partialCompletion:1; /**< =1 if there are forthcoming 196 u32 partial_completion:1; /**< =1 if there are forthcoming
266 * responses/acks associated 197 * responses/acks associated
267 * with this message */ 198 * with this message */
268 u32 preserve:1; /**< =1 this is to let us know to 199 u32 preserve:1; /**< =1 this is to let us know to
269 * preserve channel contents 200 * preserve channel contents
270 * (for running guests)*/ 201 * (for running guests)*/
271 u32 writerInDiag:1; /**< =1 the DiagWriter is active in the 202 u32 writer_in_diag:1; /**< =1 the DiagWriter is active in the
272 * Diagnostic Partition*/ 203 * Diagnostic Partition*/
273 204 } flags;
274 /* remaining bits in this 32-bit word are available */ 205 u32 reserved; /* Natural alignment */
275 } Flags; 206 u64 message_handle; /* Identifies the particular message instance,
276 u32 Reserved; /* Natural alignment */
277 u64 MessageHandle; /* Identifies the particular message instance,
278 * and is used to match particular */ 207 * and is used to match particular */
279 /* request instances with the corresponding response instance. */ 208 /* request instances with the corresponding response instance. */
280 u64 PayloadVmOffset; /* Offset of payload area from start of this 209 u64 payload_vm_offset; /* Offset of payload area from start of this
281 * instance of ControlVm segment */ 210 * instance of ControlVm segment */
282 u32 PayloadMaxBytes; /* Maximum bytes allocated in payload 211 u32 payload_max_bytes; /* Maximum bytes allocated in payload
283 * area of ControlVm segment */ 212 * area of ControlVm segment */
284 u32 PayloadBytes; /* Actual number of bytes of payload 213 u32 payload_bytes; /* Actual number of bytes of payload
285 * area to copy between IO/Command; */ 214 * area to copy between IO/Command; */
286 /* if non-zero, there is a payload to copy. */ 215 /* if non-zero, there is a payload to copy. */
287} CONTROLVM_MESSAGE_HEADER; 216};
288
289typedef struct _CONTROLVM_PACKET_DEVICE_CREATE {
290 u32 busNo; /**< bus # (0..n-1) from the msg receiver's
291 * perspective */
292 217
293 /* Control uses header SegmentIndex field to access bus number... */ 218struct controlvm_packet_device_create {
294 u32 devNo; /**< bus-relative (0..n-1) device number */ 219 u32 bus_no; /* bus # (0..n-1) from the msg receiver's end */
295 u64 channelAddr; /**< Guest physical address of the channel, which 220 u32 dev_no; /* bus-relative (0..n-1) device number */
296 * can be dereferenced by the receiver 221 u64 channel_addr; /* Guest physical address of the channel, which
297 * of this ControlVm command */ 222 * can be dereferenced by the receiver of this
298 u64 channelBytes; /**< specifies size of the channel in bytes */ 223 * ControlVm command */
299 uuid_le dataTypeGuid;/**< specifies format of data in channel */ 224 u64 channel_bytes; /* specifies size of the channel in bytes */
300 uuid_le devInstGuid; /**< instance guid for the device */ 225 uuid_le data_type_uuid; /* specifies format of data in channel */
301 struct InterruptInfo intr; /**< specifies interrupt information */ 226 uuid_le dev_inst_uuid; /* instance guid for the device */
302} CONTROLVM_PACKET_DEVICE_CREATE; /* for CONTROLVM_DEVICE_CREATE */ 227 struct irq_info intr; /* specifies interrupt information */
303 228}; /* for CONTROLVM_DEVICE_CREATE */
304typedef struct _CONTROLVM_PACKET_DEVICE_CONFIGURE { 229
305 u32 busNo; /**< bus # (0..n-1) from the msg 230struct controlvm_packet_device_configure {
231 u32 bus_no; /**< bus # (0..n-1) from the msg
306 * receiver's perspective */ 232 * receiver's perspective */
307 233
308 /* Control uses header SegmentIndex field to access bus number... */ 234 /* Control uses header SegmentIndex field to access bus number... */
309 u32 devNo; /**< bus-relative (0..n-1) device number */ 235 u32 dev_no; /**< bus-relative (0..n-1) device number */
310} CONTROLVM_PACKET_DEVICE_CONFIGURE; /* for CONTROLVM_DEVICE_CONFIGURE */ 236} ; /* for CONTROLVM_DEVICE_CONFIGURE */
311 237
312typedef struct _CONTROLVM_MESSAGE_DEVICE_CREATE { 238struct controlvm_message_device_create {
313 CONTROLVM_MESSAGE_HEADER Header; 239 struct controlvm_message_header header;
314 CONTROLVM_PACKET_DEVICE_CREATE Packet; 240 struct controlvm_packet_device_create packet;
315} CONTROLVM_MESSAGE_DEVICE_CREATE; /* total 128 bytes */ 241}; /* total 128 bytes */
316 242
317typedef struct _CONTROLVM_MESSAGE_DEVICE_CONFIGURE { 243struct controlvm_message_device_configure {
318 CONTROLVM_MESSAGE_HEADER Header; 244 struct controlvm_message_header header;
319 CONTROLVM_PACKET_DEVICE_CONFIGURE Packet; 245 struct controlvm_packet_device_configure packet;
320} CONTROLVM_MESSAGE_DEVICE_CONFIGURE; /* total 56 bytes */ 246}; /* total 56 bytes */
321 247
322/* This is the format for a message in any ControlVm queue. */ 248/* This is the format for a message in any ControlVm queue. */
323typedef struct _CONTROLVM_MESSAGE_PACKET { 249struct controlvm_message_packet {
324 union { 250 union {
325
326 /* BEGIN Request messages */
327 struct { 251 struct {
328 u32 busNo; /*< bus # (0..n-1) from the msg 252 u32 bus_no; /* bus # (0..n-1) from the msg
329 * receiver's perspective */ 253 * receiver's perspective */
330 254 u32 dev_count; /* indicates the max number of
331 /* Control uses header SegmentIndex field to access bus number... */ 255 * devices on this bus */
332 u32 deviceCount; /*< indicates the max number of 256 u64 channel_addr; /* Guest physical address of
333 * devices on this bus */ 257 * the channel, which can be
334 u64 channelAddr; /*< Guest physical address of the 258 * dereferenced by the receiver
335 * channel, which can be 259 * of this ControlVm command */
336 * dereferenced by the receiver 260 u64 channel_bytes; /* size of the channel */
337 * of this ControlVm command */ 261 uuid_le bus_data_type_uuid; /* indicates format of
338 u64 channelBytes; /*< size of the channel in bytes */ 262 * data in bus channel*/
339 uuid_le busDataTypeGuid;/*< indicates format of data in 263 uuid_le bus_inst_uuid; /* instance uuid for the bus */
340 bus channel */ 264 } create_bus; /* for CONTROLVM_BUS_CREATE */
341 uuid_le busInstGuid; /*< instance guid for the bus */
342 } createBus; /* for CONTROLVM_BUS_CREATE */
343 struct { 265 struct {
344 u32 busNo; /*< bus # (0..n-1) from the msg 266 u32 bus_no; /* bus # (0..n-1) from the msg
345 * receiver's perspective */ 267 * receiver's perspective */
346
347 /* Control uses header SegmentIndex field to access bus number... */
348 u32 reserved; /* Natural alignment purposes */ 268 u32 reserved; /* Natural alignment purposes */
349 } destroyBus; /* for CONTROLVM_BUS_DESTROY */ 269 } destroy_bus; /* for CONTROLVM_BUS_DESTROY */
350 struct { 270 struct {
351 u32 busNo; /*< bus # (0..n-1) from the 271 u32 bus_no; /* bus # (0..n-1) from the receiver's
352 * msg receiver's 272 * perspective */
353 * perspective */ 273 u32 reserved1; /* for alignment purposes */
354 274 u64 guest_handle; /* This is used to convert
355 /* Control uses header SegmentIndex field to access bus number... */ 275 * guest physical address to
356 u32 reserved1; /* for alignment purposes */ 276 * physical address */
357 u64 guestHandle; /* This is used to convert 277 u64 recv_bus_irq_handle;
358 * guest physical address to real 278 /* specifies interrupt info. It is used by SP
359 * physical address for DMA, for ex. */ 279 * to register to receive interrupts from the
360 u64 recvBusInterruptHandle;/*< specifies interrupt 280 * CP. This interrupt is used for bus level
361 * info. It is used by SP to register 281 * notifications. The corresponding
362 * to receive interrupts from the CP. 282 * sendBusInterruptHandle is kept in CP. */
363 * This interrupt is used for bus 283 } configure_bus; /* for CONTROLVM_BUS_CONFIGURE */
364 * level notifications. The
365 * corresponding
366 * sendBusInterruptHandle is kept in
367 * CP. */
368 } configureBus; /* for CONTROLVM_BUS_CONFIGURE */
369
370 /* for CONTROLVM_DEVICE_CREATE */ 284 /* for CONTROLVM_DEVICE_CREATE */
371 CONTROLVM_PACKET_DEVICE_CREATE createDevice; 285 struct controlvm_packet_device_create create_device;
372 struct { 286 struct {
373 u32 busNo; /*< bus # (0..n-1) from the msg 287 u32 bus_no; /* bus # (0..n-1) from the msg
374 * receiver's perspective */ 288 * receiver's perspective */
375 289 u32 dev_no; /* bus-relative (0..n-1) device # */
376 /* Control uses header SegmentIndex field to access bus number... */ 290 } destroy_device; /* for CONTROLVM_DEVICE_DESTROY */
377 u32 devNo; /*< bus-relative (0..n-1) device
378 * number */
379 } destroyDevice; /* for CONTROLVM_DEVICE_DESTROY */
380
381 /* for CONTROLVM_DEVICE_CONFIGURE */ 291 /* for CONTROLVM_DEVICE_CONFIGURE */
382 CONTROLVM_PACKET_DEVICE_CONFIGURE configureDevice; 292 struct controlvm_packet_device_configure configure_device;
383 struct { 293 struct {
384 u32 busNo; /*< bus # (0..n-1) from the msg 294 u32 bus_no; /* bus # (0..n-1) from the msg
385 * receiver's perspective */ 295 * receiver's perspective */
386 296 u32 dev_no; /* bus-relative (0..n-1) device # */
387 /* Control uses header SegmentIndex field to access bus number... */ 297 } reconfigure_device; /* for CONTROLVM_DEVICE_RECONFIGURE */
388 u32 devNo; /*< bus-relative (0..n-1) device
389 * number */
390 } reconfigureDevice; /* for CONTROLVM_DEVICE_RECONFIGURE */
391 struct { 298 struct {
392 u32 busNo; 299 u32 bus_no;
393 ULTRA_SEGMENT_STATE state; 300 struct spar_segment_state state;
394 u8 reserved[2]; /* Natural alignment purposes */ 301 u8 reserved[2]; /* Natural alignment purposes */
395 } busChangeState; /* for CONTROLVM_BUS_CHANGESTATE */ 302 } bus_change_state; /* for CONTROLVM_BUS_CHANGESTATE */
396 struct { 303 struct {
397 u32 busNo; 304 u32 bus_no;
398 u32 devNo; 305 u32 dev_no;
399 ULTRA_SEGMENT_STATE state; 306 struct spar_segment_state state;
400 struct { 307 struct {
401 u32 physicalDevice:1; /* =1 if message is for 308 u32 phys_device:1; /* =1 if message is for
402 * a physical device */ 309 * a physical device */
403 /* remaining bits in this 32-bit word are available */
404 } flags; 310 } flags;
405 u8 reserved[2]; /* Natural alignment purposes */ 311 u8 reserved[2]; /* Natural alignment purposes */
406 } deviceChangeState; /* for CONTROLVM_DEVICE_CHANGESTATE */ 312 } device_change_state; /* for CONTROLVM_DEVICE_CHANGESTATE */
407 struct { 313 struct {
408 u32 busNo; 314 u32 bus_no;
409 u32 devNo; 315 u32 dev_no;
410 ULTRA_SEGMENT_STATE state; 316 struct spar_segment_state state;
411 u8 reserved[6]; /* Natural alignment purposes */ 317 u8 reserved[6]; /* Natural alignment purposes */
412 } deviceChangeStateEvent; /* for CONTROLVM_DEVICE_CHANGESTATE_EVENT */ 318 } device_change_state_event;
319 /* for CONTROLVM_DEVICE_CHANGESTATE_EVENT */
413 struct { 320 struct {
414 u32 busCount; /*< indicates the max number of busses */ 321 u32 bus_count; /* indicates the max number of busses */
415 u32 switchCount; /*< indicates the max number of 322 u32 switch_count; /* indicates the max number of
416 * switches (applicable for service 323 * switches if a service partition */
417 * partition only) */ 324 enum ultra_chipset_feature features;
418 ULTRA_CHIPSET_FEATURE features; 325 u32 platform_number; /* Platform Number */
419 u32 platformNumber; /* Platform Number */ 326 } init_chipset; /* for CONTROLVM_CHIPSET_INIT */
420 } initChipset; /* for CONTROLVM_CHIPSET_INIT */
421 struct { 327 struct {
422 u32 Options; /*< reserved */ 328 u32 options; /* reserved */
423 u32 Test; /*< bit 0 set to run embedded selftest */ 329 u32 test; /* bit 0 set to run embedded selftest */
424 } chipsetSelftest; /* for CONTROLVM_CHIPSET_SELFTEST */ 330 } chipset_selftest; /* for CONTROLVM_CHIPSET_SELFTEST */
425 331 u64 addr; /* a physical address of something, that can be
426 /* END Request messages */ 332 * dereferenced by the receiver of this
427 333 * ControlVm command (depends on command id) */
428 /* BEGIN Response messages */ 334 u64 handle; /* a handle of something (depends on command
429 335 * id) */
430 /* END Response messages */ 336 };
431 337};
432 /* BEGIN Event messages */
433 338
434 /* END Event messages */ 339/* All messages in any ControlVm queue have this layout. */
340struct controlvm_message {
341 struct controlvm_message_header hdr;
342 struct controlvm_message_packet cmd;
343};
435 344
436 /* BEGIN Ack messages */ 345struct device_map {
346 GUEST_PHYSICAL_ADDRESS device_channel_address;
347 u64 device_channel_size;
348 u32 ca_index;
349 u32 reserved; /* natural alignment */
350 u64 reserved2; /* Align structure on 32-byte boundary */
351};
437 352
438 /* END Ack messages */ 353struct guest_devices {
439 u64 addr; /*< a physical address of something, that 354 struct device_map video_channel;
440 * can be dereferenced by the receiver of 355 struct device_map keyboard_channel;
441 * this ControlVm command (depends on 356 struct device_map network_channel;
442 * command id) */ 357 struct device_map storage_channel;
443 u64 handle; /*< a handle of something (depends on 358 struct device_map console_channel;
444 * command id) */ 359 u32 partition_index;
445 }; 360 u32 pad;
446} CONTROLVM_MESSAGE_PACKET; 361};
447 362
448/* All messages in any ControlVm queue have this layout. */ 363struct spar_controlvm_channel_protocol {
449typedef struct _CONTROLVM_MESSAGE { 364 struct channel_header header;
450 CONTROLVM_MESSAGE_HEADER hdr; 365 GUEST_PHYSICAL_ADDRESS gp_controlvm; /* guest physical address of
451 CONTROLVM_MESSAGE_PACKET cmd;
452} CONTROLVM_MESSAGE;
453
454typedef struct _DEVICE_MAP {
455 GUEST_PHYSICAL_ADDRESS DeviceChannelAddress;
456 u64 DeviceChannelSize;
457 u32 CA_Index;
458 u32 Reserved; /* natural alignment */
459 u64 Reserved2; /* Align structure on 32-byte boundary */
460} DEVICE_MAP;
461
462typedef struct _GUEST_DEVICES {
463 DEVICE_MAP VideoChannel;
464 DEVICE_MAP KeyboardChannel;
465 DEVICE_MAP NetworkChannel;
466 DEVICE_MAP StorageChannel;
467 DEVICE_MAP ConsoleChannel;
468 u32 PartitionIndex;
469 u32 Pad;
470} GUEST_DEVICES;
471
472typedef struct _ULTRA_CONTROLVM_CHANNEL_PROTOCOL {
473 CHANNEL_HEADER Header;
474 GUEST_PHYSICAL_ADDRESS gpControlVm; /* guest physical address of
475 * this channel */ 366 * this channel */
476 GUEST_PHYSICAL_ADDRESS gpPartitionTables; /* guest physical address of 367 GUEST_PHYSICAL_ADDRESS gp_partition_tables;/* guest physical address of
477 * partition tables */ 368 * partition tables */
478 GUEST_PHYSICAL_ADDRESS gpDiagGuest; /* guest physical address of 369 GUEST_PHYSICAL_ADDRESS gp_diag_guest; /* guest physical address of
479 * diagnostic channel */ 370 * diagnostic channel */
480 GUEST_PHYSICAL_ADDRESS gpBootRomDisk; /* guest phys addr of (read 371 GUEST_PHYSICAL_ADDRESS gp_boot_romdisk;/* guest phys addr of (read
481 * only) Boot ROM disk */ 372 * only) Boot ROM disk */
482 GUEST_PHYSICAL_ADDRESS gpBootRamDisk; /* guest phys addr of writable 373 GUEST_PHYSICAL_ADDRESS gp_boot_ramdisk;/* guest phys addr of writable
483 * Boot RAM disk */ 374 * Boot RAM disk */
484 GUEST_PHYSICAL_ADDRESS gpAcpiTable; /* guest phys addr of acpi 375 GUEST_PHYSICAL_ADDRESS gp_acpi_table; /* guest phys addr of acpi
485 * table */ 376 * table */
486 GUEST_PHYSICAL_ADDRESS gpControlChannel; /* guest phys addr of control 377 GUEST_PHYSICAL_ADDRESS gp_control_channel;/* guest phys addr of control
487 * channel */ 378 * channel */
488 GUEST_PHYSICAL_ADDRESS gpDiagRomDisk; /* guest phys addr of diagnostic 379 GUEST_PHYSICAL_ADDRESS gp_diag_romdisk;/* guest phys addr of diagnostic
489 * ROM disk */ 380 * ROM disk */
490 GUEST_PHYSICAL_ADDRESS gpNvram; /* guest phys addr of NVRAM 381 GUEST_PHYSICAL_ADDRESS gp_nvram; /* guest phys addr of NVRAM
491 * channel */ 382 * channel */
492 u64 RequestPayloadOffset; /* Offset to request payload area */ 383 u64 request_payload_offset; /* Offset to request payload area */
493 u64 EventPayloadOffset; /* Offset to event payload area */ 384 u64 event_payload_offset; /* Offset to event payload area */
494 u32 RequestPayloadBytes; /* Bytes available in request payload 385 u32 request_payload_bytes; /* Bytes available in request payload
495 * area */ 386 * area */
496 u32 EventPayloadBytes; /* Bytes available in event payload area */ 387 u32 event_payload_bytes;/* Bytes available in event payload area */
497 u32 ControlChannelBytes; 388 u32 control_channel_bytes;
498 u32 NvramChannelBytes; /* Bytes in PartitionNvram segment */ 389 u32 nvram_channel_bytes; /* Bytes in PartitionNvram segment */
499 u32 MessageBytes; /* sizeof(CONTROLVM_MESSAGE) */ 390 u32 message_bytes; /* sizeof(CONTROLVM_MESSAGE) */
500 u32 MessageCount; /* CONTROLVM_MESSAGE_MAX */ 391 u32 message_count; /* CONTROLVM_MESSAGE_MAX */
501 GUEST_PHYSICAL_ADDRESS gpSmbiosTable; /* guest phys addr of SMBIOS 392 GUEST_PHYSICAL_ADDRESS gp_smbios_table;/* guest phys addr of SMBIOS
502 * tables */ 393 * tables */
503 GUEST_PHYSICAL_ADDRESS gpPhysicalSmbiosTable; /* guest phys addr of 394 GUEST_PHYSICAL_ADDRESS gp_physical_smbios_table;/* guest phys addr of
504 * SMBIOS table */ 395 * SMBIOS table */
505 /* ULTRA_MAX_GUESTS_PER_SERVICE */ 396 /* ULTRA_MAX_GUESTS_PER_SERVICE */
506 GUEST_DEVICES gpObsoleteGuestDevices[16]; 397 struct guest_devices gp_obsolete_guest_devices[16];
507 398
508 /* guest physical address of EFI firmware image base */ 399 /* guest physical address of EFI firmware image base */
509 GUEST_PHYSICAL_ADDRESS VirtualGuestFirmwareImageBase; 400 GUEST_PHYSICAL_ADDRESS virtual_guest_firmware_image_base;
510 401
511 /* guest physical address of EFI firmware entry point */ 402 /* guest physical address of EFI firmware entry point */
512 GUEST_PHYSICAL_ADDRESS VirtualGuestFirmwareEntryPoint; 403 GUEST_PHYSICAL_ADDRESS virtual_guest_firmware_entry_point;
513 404
514 /* guest EFI firmware image size */ 405 /* guest EFI firmware image size */
515 u64 VirtualGuestFirmwareImageSize; 406 u64 virtual_guest_firmware_image_size;
516 407
517 /* GPA = 1MB where EFI firmware image is copied to */ 408 /* GPA = 1MB where EFI firmware image is copied to */
518 GUEST_PHYSICAL_ADDRESS VirtualGuestFirmwareBootBase; 409 GUEST_PHYSICAL_ADDRESS virtual_guest_firmware_boot_base;
519 GUEST_PHYSICAL_ADDRESS VirtualGuestImageBase; 410 GUEST_PHYSICAL_ADDRESS virtual_guest_image_base;
520 GUEST_PHYSICAL_ADDRESS VirtualGuestImageSize; 411 GUEST_PHYSICAL_ADDRESS virtual_guest_image_size;
521 u64 PrototypeControlChannelOffset; 412 u64 prototype_control_channel_offset;
522 GUEST_PHYSICAL_ADDRESS VirtualGuestPartitionHandle; 413 GUEST_PHYSICAL_ADDRESS virtual_guest_partition_handle;
523 414
524 u16 RestoreAction; /* Restore Action field to restore the guest 415 u16 restore_action; /* Restore Action field to restore the guest
525 * partition */ 416 * partition */
526 u16 DumpAction; /* For Windows guests it shows if the visordisk 417 u16 dump_action; /* For Windows guests it shows if the visordisk
527 * is running in dump mode */ 418 * is running in dump mode */
528 u16 NvramFailCount; 419 u16 nvram_fail_count;
529 u16 SavedCrashMsgCount; /* = CONTROLVM_CRASHMSG_MAX */ 420 u16 saved_crash_message_count; /* = CONTROLVM_CRASHMSG_MAX */
530 u32 SavedCrashMsgOffset; /* Offset to request payload area needed 421 u32 saved_crash_message_offset; /* Offset to request payload area needed
531 * for crash dump */ 422 * for crash dump */
532 u32 InstallationError; /* Type of error encountered during 423 u32 installation_error; /* Type of error encountered during
533 * installation */ 424 * installation */
534 u32 InstallationTextId; /* Id of string to display */ 425 u32 installation_text_id; /* Id of string to display */
535 u16 InstallationRemainingSteps; /* Number of remaining installation 426 u16 installation_remaining_steps;/* Number of remaining installation
536 * steps (for progress bars) */ 427 * steps (for progress bars) */
537 u8 ToolAction; /* ULTRA_TOOL_ACTIONS Installation Action 428 u8 tool_action; /* ULTRA_TOOL_ACTIONS Installation Action
538 * field */ 429 * field */
539 u8 Reserved; /* alignment */ 430 u8 reserved; /* alignment */
540 ULTRA_EFI_SPAR_INDICATION EfiSparIndication; 431 struct efi_spar_indication efi_spar_ind;
541 ULTRA_EFI_SPAR_INDICATION EfiSparIndicationSupported; 432 struct efi_spar_indication efi_spar_ind_supported;
542 u32 SPReserved; 433 u32 sp_reserved;
543 u8 Reserved2[28]; /* Force signals to begin on 128-byte cache 434 u8 reserved2[28]; /* Force signals to begin on 128-byte cache
544 * line */ 435 * line */
545 SIGNAL_QUEUE_HEADER RequestQueue; /* Service or guest partition 436 struct signal_queue_header request_queue;/* Service or guest partition
546 * uses this queue to send 437 * uses this queue to send
547 * requests to Control */ 438 * requests to Control */
548 SIGNAL_QUEUE_HEADER ResponseQueue; /* Control uses this queue to 439 struct signal_queue_header response_queue;/* Control uses this queue to
549 * respond to service or guest 440 * respond to service or guest
550 * partition requests */ 441 * partition requests */
551 SIGNAL_QUEUE_HEADER EventQueue; /* Control uses this queue to 442 struct signal_queue_header event_queue; /* Control uses this queue to
552 * send events to service or 443 * send events to service or
553 * guest partition */ 444 * guest partition */
554 SIGNAL_QUEUE_HEADER EventAckQueue; /* Service or guest partition 445 struct signal_queue_header event_ack_queue;/* Service or guest partition
555 * uses this queue to ack 446 * uses this queue to ack
556 * Control events */ 447 * Control events */
557 448
558 /* Request fixed-size message pool - does not include payload */ 449 /* Request fixed-size message pool - does not include payload */
559 CONTROLVM_MESSAGE RequestMsg[CONTROLVM_MESSAGE_MAX]; 450 struct controlvm_message request_msg[CONTROLVM_MESSAGE_MAX];
560 451
561 /* Response fixed-size message pool - does not include payload */ 452 /* Response fixed-size message pool - does not include payload */
562 CONTROLVM_MESSAGE ResponseMsg[CONTROLVM_MESSAGE_MAX]; 453 struct controlvm_message response_msg[CONTROLVM_MESSAGE_MAX];
563 454
564 /* Event fixed-size message pool - does not include payload */ 455 /* Event fixed-size message pool - does not include payload */
565 CONTROLVM_MESSAGE EventMsg[CONTROLVM_MESSAGE_MAX]; 456 struct controlvm_message event_msg[CONTROLVM_MESSAGE_MAX];
566 457
567 /* Ack fixed-size message pool - does not include payload */ 458 /* Ack fixed-size message pool - does not include payload */
568 CONTROLVM_MESSAGE EventAckMsg[CONTROLVM_MESSAGE_MAX]; 459 struct controlvm_message event_ack_msg[CONTROLVM_MESSAGE_MAX];
569 460
570 /* Message stored during IOVM creation to be reused after crash */ 461 /* Message stored during IOVM creation to be reused after crash */
571 CONTROLVM_MESSAGE SavedCrashMsg[CONTROLVM_CRASHMSG_MAX]; 462 struct controlvm_message saved_crash_msg[CONTROLVM_CRASHMSG_MAX];
572} ULTRA_CONTROLVM_CHANNEL_PROTOCOL; 463};
573 464
574/* Offsets for VM channel attributes... */ 465/* Offsets for VM channel attributes... */
575#define VM_CH_REQ_QUEUE_OFFSET \ 466#define VM_CH_REQ_QUEUE_OFFSET \
576 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL, RequestQueue) 467 offsetof(struct spar_controlvm_channel_protocol, request_queue)
577#define VM_CH_RESP_QUEUE_OFFSET \ 468#define VM_CH_RESP_QUEUE_OFFSET \
578 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL, ResponseQueue) 469 offsetof(struct spar_controlvm_channel_protocol, response_queue)
579#define VM_CH_EVENT_QUEUE_OFFSET \ 470#define VM_CH_EVENT_QUEUE_OFFSET \
580 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL, EventQueue) 471 offsetof(struct spar_controlvm_channel_protocol, event_queue)
581#define VM_CH_ACK_QUEUE_OFFSET \ 472#define VM_CH_ACK_QUEUE_OFFSET \
582 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL, EventAckQueue) 473 offsetof(struct spar_controlvm_channel_protocol, event_ack_queue)
583#define VM_CH_REQ_MSG_OFFSET \ 474#define VM_CH_REQ_MSG_OFFSET \
584 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL, RequestMsg) 475 offsetof(struct spar_controlvm_channel_protocol, request_msg)
585#define VM_CH_RESP_MSG_OFFSET \ 476#define VM_CH_RESP_MSG_OFFSET \
586 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL, ResponseMsg) 477 offsetof(struct spar_controlvm_channel_protocol, response_msg)
587#define VM_CH_EVENT_MSG_OFFSET \ 478#define VM_CH_EVENT_MSG_OFFSET \
588 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL, EventMsg) 479 offsetof(struct spar_controlvm_channel_protocol, event_msg)
589#define VM_CH_ACK_MSG_OFFSET \ 480#define VM_CH_ACK_MSG_OFFSET \
590 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL, EventAckMsg) 481 offsetof(struct spar_controlvm_channel_protocol, event_ack_msg)
591#define VM_CH_CRASH_MSG_OFFSET \ 482#define VM_CH_CRASH_MSG_OFFSET \
592 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL, SavedCrashMsg) 483 offsetof(struct spar_controlvm_channel_protocol, saved_crash_msg)
593 484
594/* The following header will be located at the beginning of PayloadVmOffset for 485/* The following header will be located at the beginning of PayloadVmOffset for
595 * various ControlVm commands. The receiver of a ControlVm command with a 486 * various ControlVm commands. The receiver of a ControlVm command with a
596 * PayloadVmOffset will dereference this address and then use ConnectionOffset, 487 * PayloadVmOffset will dereference this address and then use connection_offset,
597 * InitiatorOffset, and TargetOffset to get the location of UTF-8 formatted 488 * initiator_offset, and target_offset to get the location of UTF-8 formatted
598 * strings that can be parsed to obtain command-specific information. The value 489 * strings that can be parsed to obtain command-specific information. The value
599 * of TotalLength should equal PayloadBytes. The format of the strings at 490 * of total_length should equal PayloadBytes. The format of the strings at
600 * PayloadVmOffset will take different forms depending on the message. See the 491 * PayloadVmOffset will take different forms depending on the message.
601 * following Wiki page for more information:
602 * https://ustr-linux-1.na.uis.unisys.com/spar/index.php/ControlVm_Parameters_Area
603 */ 492 */
604typedef struct _ULTRA_CONTROLVM_PARAMETERS_HEADER { 493struct spar_controlvm_parameters_header {
605 u32 TotalLength; 494 u32 total_length;
606 u32 HeaderLength; 495 u32 header_length;
607 u32 ConnectionOffset; 496 u32 connection_offset;
608 u32 ConnectionLength; 497 u32 connection_length;
609 u32 InitiatorOffset; 498 u32 initiator_offset;
610 u32 InitiatorLength; 499 u32 initiator_length;
611 u32 TargetOffset; 500 u32 target_offset;
612 u32 TargetLength; 501 u32 target_length;
613 u32 ClientOffset; 502 u32 client_offset;
614 u32 ClientLength; 503 u32 client_length;
615 u32 NameOffset; 504 u32 name_offset;
616 u32 NameLength; 505 u32 name_length;
617 uuid_le Id; 506 uuid_le id;
618 u32 Revision; 507 u32 revision;
619 u32 Reserved; /* Natural alignment */ 508 u32 reserved; /* Natural alignment */
620} ULTRA_CONTROLVM_PARAMETERS_HEADER; 509};
621 510
622#endif /* __CONTROLVMCHANNEL_H__ */ 511#endif /* __CONTROLVMCHANNEL_H__ */
diff --git a/drivers/staging/unisys/common-spar/include/channels/diagchannel.h b/drivers/staging/unisys/common-spar/include/channels/diagchannel.h
index 9912e51b89b5..e8fb8678a8e2 100644
--- a/drivers/staging/unisys/common-spar/include/channels/diagchannel.h
+++ b/drivers/staging/unisys/common-spar/include/channels/diagchannel.h
@@ -37,12 +37,12 @@
37#include "channel.h" 37#include "channel.h"
38 38
39/* {EEA7A573-DB82-447c-8716-EFBEAAAE4858} */ 39/* {EEA7A573-DB82-447c-8716-EFBEAAAE4858} */
40#define ULTRA_DIAG_CHANNEL_PROTOCOL_GUID \ 40#define SPAR_DIAG_CHANNEL_PROTOCOL_UUID \
41 UUID_LE(0xeea7a573, 0xdb82, 0x447c, \ 41 UUID_LE(0xeea7a573, 0xdb82, 0x447c, \
42 0x87, 0x16, 0xef, 0xbe, 0xaa, 0xae, 0x48, 0x58) 42 0x87, 0x16, 0xef, 0xbe, 0xaa, 0xae, 0x48, 0x58)
43 43
44static const uuid_le UltraDiagChannelProtocolGuid = 44static const uuid_le spar_diag_channel_protocol_uuid =
45 ULTRA_DIAG_CHANNEL_PROTOCOL_GUID; 45 SPAR_DIAG_CHANNEL_PROTOCOL_UUID;
46 46
47/* {E850F968-3263-4484-8CA5-2A35D087A5A8} */ 47/* {E850F968-3263-4484-8CA5-2A35D087A5A8} */
48#define ULTRA_DIAG_ROOT_CHANNEL_PROTOCOL_GUID \ 48#define ULTRA_DIAG_ROOT_CHANNEL_PROTOCOL_GUID \
@@ -58,19 +58,20 @@ static const uuid_le UltraDiagChannelProtocolGuid =
58* increment this. */ 58* increment this. */
59#define ULTRA_DIAG_CHANNEL_PROTOCOL_VERSIONID 2 59#define ULTRA_DIAG_CHANNEL_PROTOCOL_VERSIONID 2
60 60
61#define ULTRA_DIAG_CHANNEL_OK_CLIENT(pChannel, logCtx) \ 61#define SPAR_DIAG_CHANNEL_OK_CLIENT(ch)\
62 (ULTRA_check_channel_client(pChannel, \ 62 (spar_check_channel_client(ch,\
63 UltraDiagChannelProtocolGuid, \ 63 spar_diag_channel_protocol_uuid,\
64 "diag", \ 64 "diag",\
65 sizeof(ULTRA_DIAG_CHANNEL_PROTOCOL), \ 65 sizeof(struct spar_diag_channel_protocol),\
66 ULTRA_DIAG_CHANNEL_PROTOCOL_VERSIONID, \ 66 ULTRA_DIAG_CHANNEL_PROTOCOL_VERSIONID,\
67 ULTRA_DIAG_CHANNEL_PROTOCOL_SIGNATURE, \ 67 ULTRA_DIAG_CHANNEL_PROTOCOL_SIGNATURE))
68 __FILE__, __LINE__, logCtx)) 68
69#define ULTRA_DIAG_CHANNEL_OK_SERVER(actualBytes, logCtx) \ 69#define SPAR_DIAG_CHANNEL_OK_SERVER(bytes)\
70 (ULTRA_check_channel_server(UltraDiagChannelProtocolGuid, \ 70 (spar_check_channel_server(spar_diag_channel_protocol_uuid,\
71 "diag", \ 71 "diag",\
72 sizeof(ULTRA_DIAG_CHANNEL_PROTOCOL), \ 72 sizeof(struct spar_diag_channel_protocol),\
73 actualBytes, __FILE__, __LINE__, logCtx)) 73 bytes))
74
74#define MAX_MODULE_NAME_SIZE 128 /* Maximum length of module name... */ 75#define MAX_MODULE_NAME_SIZE 128 /* Maximum length of module name... */
75#define MAX_ADDITIONAL_INFO_SIZE 256 /* Maximum length of any additional info 76#define MAX_ADDITIONAL_INFO_SIZE 256 /* Maximum length of any additional info
76 * accompanying event... */ 77 * accompanying event... */
@@ -105,21 +106,21 @@ static const uuid_le UltraDiagChannelProtocolGuid =
105/* Copied from EFI's EFI_TIME struct in efidef.h. EFI headers are not allowed 106/* Copied from EFI's EFI_TIME struct in efidef.h. EFI headers are not allowed
106* in some of the Supervisor areas, such as Monitor, so it has been "ported" here 107* in some of the Supervisor areas, such as Monitor, so it has been "ported" here
107* for use in diagnostic event timestamps... */ 108* for use in diagnostic event timestamps... */
108typedef struct _DIAG_EFI_TIME { 109struct diag_efi_time {
109 u16 Year; /* 1998 - 20XX */ 110 u16 year; /* 1998 - 20XX */
110 u8 Month; /* 1 - 12 */ 111 u8 month; /* 1 - 12 */
111 u8 Day; /* 1 - 31 */ 112 u8 day; /* 1 - 31 */
112 u8 Hour; /* 0 - 23 */ 113 u8 hour; /* 0 - 23 */
113 u8 Minute; /* 0 - 59 */ 114 u8 minute; /* 0 - 59 */
114 u8 Second; /* 0 - 59 */ 115 u8 second; /* 0 - 59 */
115 u8 Pad1; 116 u8 pad1;
116 u32 Nanosecond; /* 0 - 999, 999, 999 */ 117 u32 nanosecond; /* 0 - 999, 999, 999 */
117 s16 TimeZone; /* -1440 to 1440 or 2047 */ 118 s16 timezone; /* -1440 to 1440 or 2047 */
118 u8 Daylight; 119 u8 daylight;
119 u8 Pad2; 120 u8 pad2;
120} DIAG_EFI_TIME; 121};
121 122
122typedef enum { 123enum spar_component_types {
123 ULTRA_COMPONENT_GUEST = 0, 124 ULTRA_COMPONENT_GUEST = 0,
124 ULTRA_COMPONENT_MONITOR = 0x01, 125 ULTRA_COMPONENT_MONITOR = 0x01,
125 ULTRA_COMPONENT_CCM = 0x02, /* Common Control module */ 126 ULTRA_COMPONENT_CCM = 0x02, /* Common Control module */
@@ -144,9 +145,9 @@ typedef enum {
144 ULTRA_COMPONENT_PSERVICES = 0x17, 145 ULTRA_COMPONENT_PSERVICES = 0x17,
145 ULTRA_COMPONENT_PDIAG = 0x18 146 ULTRA_COMPONENT_PDIAG = 0x18
146 /* RESERVED 0x18 - 0x1F */ 147 /* RESERVED 0x18 - 0x1F */
147} ULTRA_COMPONENT_TYPES; 148};
148 149
149/* Structure: DIAG_CHANNEL_EVENT Purpose: Contains attributes that make up an 150/* Structure: diag_channel_event Purpose: Contains attributes that make up an
150 * event to be written to the DIAG_CHANNEL memory. Attributes: EventId: Id of 151 * event to be written to the DIAG_CHANNEL memory. Attributes: EventId: Id of
151 * the diagnostic event to write to memory. Severity: Severity of the event 152 * the diagnostic event to write to memory. Severity: Severity of the event
152 * (Error, Info, etc). ModuleName: Module/file name where event originated. 153 * (Error, Info, etc). ModuleName: Module/file name where event originated.
@@ -155,40 +156,40 @@ typedef enum {
155 * Reserved: Padding to align structure on a 64-byte cache line boundary. 156 * Reserved: Padding to align structure on a 64-byte cache line boundary.
156 * AdditionalInfo: Array of characters for additional event info (may be 157 * AdditionalInfo: Array of characters for additional event info (may be
157 * empty). */ 158 * empty). */
158typedef struct _DIAG_CHANNEL_EVENT { 159struct diag_channel_event {
159 u32 EventId; 160 u32 event_id;
160 u32 Severity; 161 u32 severity;
161 u8 ModuleName[MAX_MODULE_NAME_SIZE]; 162 u8 module_name[MAX_MODULE_NAME_SIZE];
162 u32 LineNumber; 163 u32 line_number;
163 DIAG_EFI_TIME Timestamp; /* Size = 16 bytes */ 164 struct diag_efi_time timestamp; /* Size = 16 bytes */
164 u32 PartitionNumber; /* Filled in by Diag Switch as pool blocks are 165 u32 partition_number; /* Filled in by Diag Switch as pool blocks are
165 * filled */ 166 * filled */
166 u16 VirtualProcessorNumber; 167 u16 vcpu_number;
167 u16 LogicalProcessorNumber; 168 u16 lcpu_number;
168 u8 ComponentType; /* ULTRA_COMPONENT_TYPES */ 169 u8 component_type; /* ULTRA_COMPONENT_TYPES */
169 u8 Subsystem; 170 u8 subsystem;
170 u16 Reserved0; /* pad to u64 alignment */ 171 u16 reserved0; /* pad to u64 alignment */
171 u32 BlockNumber; /* filled in by DiagSwitch as pool blocks are 172 u32 block_no; /* filled in by DiagSwitch as pool blocks are
172 * filled */ 173 * filled */
173 u32 BlockNumberHigh; 174 u32 block_no_high;
174 u32 EventNumber; /* filled in by DiagSwitch as pool blocks are 175 u32 event_no; /* filled in by DiagSwitch as pool blocks are
175 * filled */ 176 * filled */
176 u32 EventNumberHigh; 177 u32 event_no_high;
177 178
178 /* The BlockNumber and EventNumber fields are set only by DiagSwitch 179 /* The block_no and event_no fields are set only by DiagSwitch
179 * and referenced only by WinDiagDisplay formatting tool as 180 * and referenced only by WinDiagDisplay formatting tool as
180 * additional diagnostic information. Other tools including 181 * additional diagnostic information. Other tools including
181 * WinDiagDisplay currently ignore these 'Reserved' bytes. */ 182 * WinDiagDisplay currently ignore these 'Reserved' bytes. */
182 u8 Reserved[8]; 183 u8 reserved[8];
183 u8 AdditionalInfo[MAX_ADDITIONAL_INFO_SIZE]; 184 u8 additional_info[MAX_ADDITIONAL_INFO_SIZE];
184 185
185 /* NOTE: Changesto DIAG_CHANNEL_EVENT generally need to be reflected in 186 /* NOTE: Changes to diag_channel_event generally need to be reflected in
186 * existing copies * 187 * existing copies *
187 * - for AppOS at 188 * - for AppOS at
188 * GuestLinux/visordiag_early/supervisor_diagchannel.h * 189 * GuestLinux/visordiag_early/supervisor_diagchannel.h *
189 * - for WinDiagDisplay at 190 * - for WinDiagDisplay at
190 * EFI/Ultra/Tools/WinDiagDisplay/WinDiagDisplay/diagstruct.h */ 191 * EFI/Ultra/Tools/WinDiagDisplay/WinDiagDisplay/diagstruct.h */
191} DIAG_CHANNEL_EVENT; 192};
192 193
193/* Levels of severity for diagnostic events, in order from lowest severity to 194/* Levels of severity for diagnostic events, in order from lowest severity to
194* highest (i.e. fatal errors are the most severe, and should always be logged, 195* highest (i.e. fatal errors are the most severe, and should always be logged,
@@ -201,7 +202,8 @@ typedef struct _DIAG_CHANNEL_EVENT {
201* they are valid for controlling the amount of event data. This enum is also 202* they are valid for controlling the amount of event data. This enum is also
202* defined in DotNet\sParFramework\ControlFramework\ControlFramework.cs. If a 203* defined in DotNet\sParFramework\ControlFramework\ControlFramework.cs. If a
203* change is made to this enum, they should also be reflected in that file. */ 204* change is made to this enum, they should also be reflected in that file. */
204typedef enum { DIAG_SEVERITY_ENUM_BEGIN = 0, 205enum diag_severity {
206 DIAG_SEVERITY_ENUM_BEGIN = 0,
205 DIAG_SEVERITY_OVERRIDE = DIAG_SEVERITY_ENUM_BEGIN, 207 DIAG_SEVERITY_OVERRIDE = DIAG_SEVERITY_ENUM_BEGIN,
206 DIAG_SEVERITY_VERBOSE = DIAG_SEVERITY_OVERRIDE, /* 0 */ 208 DIAG_SEVERITY_VERBOSE = DIAG_SEVERITY_OVERRIDE, /* 0 */
207 DIAG_SEVERITY_INFO = DIAG_SEVERITY_VERBOSE + 1, /* 1 */ 209 DIAG_SEVERITY_INFO = DIAG_SEVERITY_VERBOSE + 1, /* 1 */
@@ -212,7 +214,7 @@ typedef enum { DIAG_SEVERITY_ENUM_BEGIN = 0,
212 DIAG_SEVERITY_ENUM_END = DIAG_SEVERITY_SHUTOFF, /* 5 */ 214 DIAG_SEVERITY_ENUM_END = DIAG_SEVERITY_SHUTOFF, /* 5 */
213 DIAG_SEVERITY_NONFATAL_ERR = DIAG_SEVERITY_ERR, 215 DIAG_SEVERITY_NONFATAL_ERR = DIAG_SEVERITY_ERR,
214 DIAG_SEVERITY_FATAL_ERR = DIAG_SEVERITY_PRINT 216 DIAG_SEVERITY_FATAL_ERR = DIAG_SEVERITY_PRINT
215} DIAG_SEVERITY; 217};
216 218
217/* Event Cause enums 219/* Event Cause enums
218* 220*
@@ -233,26 +235,24 @@ typedef enum { DIAG_SEVERITY_ENUM_BEGIN = 0,
233* If a change is made to this enum, they should also be reflected in that 235* If a change is made to this enum, they should also be reflected in that
234* file. */ 236* file. */
235 237
236
237
238/* A cause value "DIAG_CAUSE_FILE_XFER" together with a severity value of 238/* A cause value "DIAG_CAUSE_FILE_XFER" together with a severity value of
239* "DIAG_SEVERITY_PRINT" (=4), is used for transferring text or binary file to 239* "DIAG_SEVERITY_PRINT" (=4), is used for transferring text or binary file to
240* the Diag partition. This cause-severity combination will be used by Logger 240* the Diag partition. This cause-severity combination will be used by Logger
241* DiagSwitch to segregate events into block types. The files are transferred in 241* DiagSwitch to segregate events into block types. The files are transferred in
242* 256 byte chunks maximum, in the AdditionalInfo field of the DIAG_CHANNEL_EVENT 242* 256 byte chunks maximum, in the AdditionalInfo field of the diag_channel_event
243* structure. In the file transfer mode, some event fields will have different 243* structure. In the file transfer mode, some event fields will have different
244* meaning: EventId specifies the file offset, severity specifies the block type, 244* meaning: EventId specifies the file offset, severity specifies the block type,
245* ModuleName specifies the filename, LineNumber specifies the number of valid 245* ModuleName specifies the filename, LineNumber specifies the number of valid
246* data bytes in an event and AdditionalInfo contains up to 256 bytes of data. */ 246* data bytes in an event and AdditionalInfo contains up to 256 bytes of data. */
247 247
248/* The Diag DiagWriter appends event blocks to events.raw as today, and for data 248/* The Diag DiagWriter appends event blocks to events.raw as today, and for data
249 * blocks uses DIAG_CHANNEL_EVENT 249 * blocks uses diag_channel_event
250 * PartitionNumber to extract and append 'AdditionalInfo' to filename (specified 250 * PartitionNumber to extract and append 'AdditionalInfo' to filename (specified
251 * by ModuleName). */ 251 * by ModuleName). */
252 252
253/* The Dell PDiag uses this new mechanism to stash DSET .zip onto the 253/* The Dell PDiag uses this new mechanism to stash DSET .zip onto the
254 * 'diagnostic' virtual disk. */ 254 * 'diagnostic' virtual disk. */
255typedef enum { 255enum diag_cause {
256 DIAG_CAUSE_UNKNOWN = 0, 256 DIAG_CAUSE_UNKNOWN = 0,
257 DIAG_CAUSE_UNKNOWN_DEBUG = DIAG_CAUSE_UNKNOWN + 1, /* 1 */ 257 DIAG_CAUSE_UNKNOWN_DEBUG = DIAG_CAUSE_UNKNOWN + 1, /* 1 */
258 DIAG_CAUSE_DEBUG = DIAG_CAUSE_UNKNOWN_DEBUG + 1, /* 2 */ 258 DIAG_CAUSE_DEBUG = DIAG_CAUSE_UNKNOWN_DEBUG + 1, /* 2 */
@@ -264,7 +264,7 @@ typedef enum {
264 DIAG_CAUSE_INTERNAL_ERROR = DIAG_CAUSE_INVALID_REQUEST + 1, /* 8 */ 264 DIAG_CAUSE_INTERNAL_ERROR = DIAG_CAUSE_INVALID_REQUEST + 1, /* 8 */
265 DIAG_CAUSE_FILE_XFER = DIAG_CAUSE_INTERNAL_ERROR + 1, /* 9 */ 265 DIAG_CAUSE_FILE_XFER = DIAG_CAUSE_INTERNAL_ERROR + 1, /* 9 */
266 DIAG_CAUSE_ENUM_END = DIAG_CAUSE_FILE_XFER /* 9 */ 266 DIAG_CAUSE_ENUM_END = DIAG_CAUSE_FILE_XFER /* 9 */
267} DIAG_CAUSE; 267};
268 268
269/* Event Cause category defined into the byte 2 of Severity */ 269/* Event Cause category defined into the byte 2 of Severity */
270#define CAUSE_DEBUG (DIAG_CAUSE_DEBUG << CAUSE_SHIFT_AMT) 270#define CAUSE_DEBUG (DIAG_CAUSE_DEBUG << CAUSE_SHIFT_AMT)
@@ -344,7 +344,7 @@ typedef enum {
344#define CAUSE_FILE_XFER_SEVERITY_PRINT \ 344#define CAUSE_FILE_XFER_SEVERITY_PRINT \
345 (CAUSE_FILE_XFER | DIAG_SEVERITY_PRINT) 345 (CAUSE_FILE_XFER | DIAG_SEVERITY_PRINT)
346 346
347/* Structure: DIAG_CHANNEL_PROTOCOL_HEADER 347/* Structure: diag_channel_protocol_header
348 * 348 *
349 * Purpose: Contains attributes that make up the header specific to the 349 * Purpose: Contains attributes that make up the header specific to the
350 * DIAG_CHANNEL area. 350 * DIAG_CHANNEL area.
@@ -362,12 +362,12 @@ typedef enum {
362 * whether events are logged. Any event's severity for a 362 * whether events are logged. Any event's severity for a
363 * particular subsystem below this level will be discarded. 363 * particular subsystem below this level will be discarded.
364 */ 364 */
365typedef struct _DIAG_CHANNEL_PROTOCOL_HEADER { 365struct diag_channel_protocol_header {
366 volatile u32 DiagLock; 366 u32 diag_lock;
367 u8 IsChannelInitialized; 367 u8 channel_initialized;
368 u8 Reserved[3]; 368 u8 reserved[3];
369 u8 SubsystemSeverityFilter[64]; 369 u8 subsystem_severity_filter[64];
370} DIAG_CHANNEL_PROTOCOL_HEADER; 370};
371 371
372/* The Diagram for the Diagnostic Channel: */ 372/* The Diagram for the Diagnostic Channel: */
373/* ----------------------- */ 373/* ----------------------- */
@@ -375,19 +375,20 @@ typedef struct _DIAG_CHANNEL_PROTOCOL_HEADER {
375/* ----------------------- */ 375/* ----------------------- */
376/* | Signal Queue Header | Defined by SIGNAL_QUEUE_HEADER */ 376/* | Signal Queue Header | Defined by SIGNAL_QUEUE_HEADER */
377/* ----------------------- */ 377/* ----------------------- */
378/* | DiagChannel Header | Defined by DIAG_CHANNEL_PROTOCOL_HEADER */ 378/* | DiagChannel Header | Defined by diag_channel_protocol_header */
379/* ----------------------- */ 379/* ----------------------- */
380/* | Channel Event Info | Defined by (DIAG_CHANNEL_EVENT * MAX_EVENTS) */ 380/* | Channel Event Info | Defined by diag_channel_event*MAX_EVENTS */
381/* ----------------------- */ 381/* ----------------------- */
382/* | Reserved | Reserved (pad out to 4MB) */ 382/* | Reserved | Reserved (pad out to 4MB) */
383/* ----------------------- */ 383/* ----------------------- */
384 384
385/* Offsets/sizes for diagnostic channel attributes... */ 385/* Offsets/sizes for diagnostic channel attributes... */
386#define DIAG_CH_QUEUE_HEADER_OFFSET (sizeof(ULTRA_CHANNEL_PROTOCOL)) 386#define DIAG_CH_QUEUE_HEADER_OFFSET (sizeof(struct channel_header))
387#define DIAG_CH_QUEUE_HEADER_SIZE (sizeof(SIGNAL_QUEUE_HEADER)) 387#define DIAG_CH_QUEUE_HEADER_SIZE (sizeof(struct signal_queue_header))
388#define DIAG_CH_PROTOCOL_HEADER_OFFSET \ 388#define DIAG_CH_PROTOCOL_HEADER_OFFSET \
389 (DIAG_CH_QUEUE_HEADER_OFFSET + DIAG_CH_QUEUE_HEADER_SIZE) 389 (DIAG_CH_QUEUE_HEADER_OFFSET + DIAG_CH_QUEUE_HEADER_SIZE)
390#define DIAG_CH_PROTOCOL_HEADER_SIZE (sizeof(DIAG_CHANNEL_PROTOCOL_HEADER)) 390#define DIAG_CH_PROTOCOL_HEADER_SIZE \
391 (sizeof(struct diag_channel_protocol_header))
391#define DIAG_CH_EVENT_OFFSET \ 392#define DIAG_CH_EVENT_OFFSET \
392 (DIAG_CH_PROTOCOL_HEADER_OFFSET + DIAG_CH_PROTOCOL_HEADER_SIZE) 393 (DIAG_CH_PROTOCOL_HEADER_OFFSET + DIAG_CH_PROTOCOL_HEADER_SIZE)
393#define DIAG_CH_SIZE (4096 * 1024) 394#define DIAG_CH_SIZE (4096 * 1024)
@@ -397,7 +398,7 @@ typedef struct _DIAG_CHANNEL_PROTOCOL_HEADER {
397#define DIAG_CH_LRG_SIZE (2 * DIAG_CH_SIZE) /* 8 MB */ 398#define DIAG_CH_LRG_SIZE (2 * DIAG_CH_SIZE) /* 8 MB */
398 399
399/* 400/*
400 * Structure: ULTRA_DIAG_CHANNEL_PROTOCOL 401 * Structure: spar_diag_channel_protocol
401 * 402 *
402 * Purpose: Contains attributes that make up the DIAG_CHANNEL memory. 403 * Purpose: Contains attributes that make up the DIAG_CHANNEL memory.
403 * 404 *
@@ -409,19 +410,18 @@ typedef struct _DIAG_CHANNEL_PROTOCOL_HEADER {
409 * store event. 410 * store event.
410 * 411 *
411 * DiagChannelHeader: Diagnostic channel header info (see 412 * DiagChannelHeader: Diagnostic channel header info (see
412 * DIAG_CHANNEL_PROTOCOL_HEADER comments). 413 * diag_channel_protocol_header comments).
413 * 414 *
414 * Events: Area where diagnostic events (up to MAX_EVENTS) are written. 415 * Events: Area where diagnostic events (up to MAX_EVENTS) are written.
415 * 416 *
416 *Reserved: Reserved area to allow for correct channel size padding. 417 *Reserved: Reserved area to allow for correct channel size padding.
417*/ 418*/
418typedef struct _ULTRA_DIAG_CHANNEL_PROTOCOL { 419struct spar_diag_channel_protocol {
419 ULTRA_CHANNEL_PROTOCOL CommonChannelHeader; 420 struct channel_header common_channel_header;
420 SIGNAL_QUEUE_HEADER QueueHeader; 421 struct signal_queue_header queue_header;
421 DIAG_CHANNEL_PROTOCOL_HEADER DiagChannelHeader; 422 struct diag_channel_protocol_header diag_channel_header;
422 DIAG_CHANNEL_EVENT Events[(DIAG_CH_SIZE - DIAG_CH_EVENT_OFFSET) / 423 struct diag_channel_event events[(DIAG_CH_SIZE - DIAG_CH_EVENT_OFFSET) /
423 sizeof(DIAG_CHANNEL_EVENT)]; 424 sizeof(struct diag_channel_event)];
424} 425};
425ULTRA_DIAG_CHANNEL_PROTOCOL;
426 426
427#endif 427#endif
diff --git a/drivers/staging/unisys/common-spar/include/channels/iochannel.h b/drivers/staging/unisys/common-spar/include/channels/iochannel.h
index b1dd73d1f42c..eb7efe484f6f 100644
--- a/drivers/staging/unisys/common-spar/include/channels/iochannel.h
+++ b/drivers/staging/unisys/common-spar/include/channels/iochannel.h
@@ -8,7 +8,6 @@
8* this file. Note: Everything is OS-independent because this file is 8* this file. Note: Everything is OS-independent because this file is
9* used by Windows, Linux and possible EFI drivers. */ 9* used by Windows, Linux and possible EFI drivers. */
10 10
11
12/* 11/*
13* Communication flow between the IOPart and GuestPart uses the channel headers 12* Communication flow between the IOPart and GuestPart uses the channel headers
14* channel state. The following states are currently being used: 13* channel state. The following states are currently being used:
@@ -60,42 +59,22 @@
60#define ULTRA_VNIC_CHANNEL_PROTOCOL_VERSIONID 2 59#define ULTRA_VNIC_CHANNEL_PROTOCOL_VERSIONID 2
61#define ULTRA_VSWITCH_CHANNEL_PROTOCOL_VERSIONID 1 60#define ULTRA_VSWITCH_CHANNEL_PROTOCOL_VERSIONID 1
62 61
63#define ULTRA_VHBA_CHANNEL_OK_CLIENT(pChannel, logCtx) \ 62#define SPAR_VHBA_CHANNEL_OK_CLIENT(ch) \
64 (ULTRA_check_channel_client(pChannel, UltraVhbaChannelProtocolGuid, \ 63 (spar_check_channel_client(ch, spar_vhba_channel_protocol_uuid, \
65 "vhba", MIN_IO_CHANNEL_SIZE, \ 64 "vhba", MIN_IO_CHANNEL_SIZE, \
66 ULTRA_VHBA_CHANNEL_PROTOCOL_VERSIONID, \ 65 ULTRA_VHBA_CHANNEL_PROTOCOL_VERSIONID, \
67 ULTRA_VHBA_CHANNEL_PROTOCOL_SIGNATURE, \ 66 ULTRA_VHBA_CHANNEL_PROTOCOL_SIGNATURE))
68 __FILE__, __LINE__, logCtx)) 67
69#define ULTRA_VHBA_CHANNEL_OK_SERVER(actualBytes, logCtx) \ 68#define SPAR_VNIC_CHANNEL_OK_CLIENT(ch) \
70 (ULTRA_check_channel_server(UltraVhbaChannelProtocolGuid, \ 69 (spar_check_channel_client(ch, spar_vnic_channel_protocol_uuid, \
71 "vhba", MIN_IO_CHANNEL_SIZE, actualBytes, \ 70 "vnic", MIN_IO_CHANNEL_SIZE, \
72 __FILE__, __LINE__, logCtx)) 71 ULTRA_VNIC_CHANNEL_PROTOCOL_VERSIONID, \
73#define ULTRA_VNIC_CHANNEL_OK_CLIENT(pChannel, logCtx) \ 72 ULTRA_VNIC_CHANNEL_PROTOCOL_SIGNATURE))
74 (ULTRA_check_channel_client(pChannel, UltraVnicChannelProtocolGuid, \ 73
75 "vnic", MIN_IO_CHANNEL_SIZE, \
76 ULTRA_VNIC_CHANNEL_PROTOCOL_VERSIONID, \
77 ULTRA_VNIC_CHANNEL_PROTOCOL_SIGNATURE, \
78 __FILE__, __LINE__, logCtx))
79#define ULTRA_VNIC_CHANNEL_OK_SERVER(actualBytes, logCtx) \
80 (ULTRA_check_channel_server(UltraVnicChannelProtocolGuid, \
81 "vnic", MIN_IO_CHANNEL_SIZE, actualBytes, \
82 __FILE__, __LINE__, logCtx))
83#define ULTRA_VSWITCH_CHANNEL_OK_CLIENT(pChannel, logCtx) \
84 (ULTRA_check_channel_client(pChannel, UltraVswitchChannelProtocolGuid, \
85 "vswitch", MIN_IO_CHANNEL_SIZE, \
86 ULTRA_VSWITCH_CHANNEL_PROTOCOL_VERSIONID, \
87 ULTRA_VSWITCH_CHANNEL_PROTOCOL_SIGNATURE, \
88 __FILE__, __LINE__, logCtx))
89#define ULTRA_VSWITCH_CHANNEL_OK_SERVER(actualBytes, logCtx) \
90 (ULTRA_check_channel_server(UltraVswitchChannelProtocolGuid, \
91 "vswitch", MIN_IO_CHANNEL_SIZE, \
92 actualBytes, \
93 __FILE__, __LINE__, logCtx))
94/* 74/*
95* Everything necessary to handle SCSI & NIC traffic between Guest Partition and 75* Everything necessary to handle SCSI & NIC traffic between Guest Partition and
96* IO Partition is defined below. */ 76* IO Partition is defined below. */
97 77
98
99/* 78/*
100* Defines and enums. 79* Defines and enums.
101*/ 80*/
@@ -172,8 +151,9 @@
172 * SCSI Host value */ 151 * SCSI Host value */
173 152
174/* various types of network packets that can be sent in cmdrsp */ 153/* various types of network packets that can be sent in cmdrsp */
175typedef enum { NET_RCV_POST = 0, /* submit buffer to hold receiving 154enum net_types {
176 * incoming packet */ 155 NET_RCV_POST = 0, /* submit buffer to hold receiving
156 * incoming packet */
177 /* virtnic -> uisnic */ 157 /* virtnic -> uisnic */
178 NET_RCV, /* incoming packet received */ 158 NET_RCV, /* incoming packet received */
179 /* uisnic -> virtpci */ 159 /* uisnic -> virtpci */
@@ -195,7 +175,7 @@ typedef enum { NET_RCV_POST = 0, /* submit buffer to hold receiving
195 * its MAC addr */ 175 * its MAC addr */
196 NET_MACADDR_ACK, /* MAC address */ 176 NET_MACADDR_ACK, /* MAC address */
197 177
198} NET_TYPES; 178};
199 179
200#define ETH_HEADER_SIZE 14 /* size of ethernet header */ 180#define ETH_HEADER_SIZE 14 /* size of ethernet header */
201 181
@@ -211,19 +191,23 @@ typedef enum { NET_RCV_POST = 0, /* submit buffer to hold receiving
211#define MAX_MACADDR_LEN 6 /* number of bytes in MAC address */ 191#define MAX_MACADDR_LEN 6 /* number of bytes in MAC address */
212#endif /* MAX_MACADDR_LEN */ 192#endif /* MAX_MACADDR_LEN */
213 193
214#define ETH_IS_LOCALLY_ADMINISTERED(Address) \ 194#define ETH_IS_LOCALLY_ADMINISTERED(address) \
215 (((u8 *) (Address))[0] & ((u8) 0x02)) 195 (((u8 *)(address))[0] & ((u8)0x02))
216#define NIC_VENDOR_ID 0x0008000B 196#define NIC_VENDOR_ID 0x0008000B
217 197
218/* various types of scsi task mgmt commands */ 198/* various types of scsi task mgmt commands */
219typedef enum { TASK_MGMT_ABORT_TASK = 199enum task_mgmt_types {
220 1, TASK_MGMT_BUS_RESET, TASK_MGMT_LUN_RESET, 200 TASK_MGMT_ABORT_TASK = 1,
221 TASK_MGMT_TARGET_RESET, 201 TASK_MGMT_BUS_RESET,
222} TASK_MGMT_TYPES; 202 TASK_MGMT_LUN_RESET,
203 TASK_MGMT_TARGET_RESET,
204};
223 205
224/* various types of vdisk mgmt commands */ 206/* various types of vdisk mgmt commands */
225typedef enum { VDISK_MGMT_ACQUIRE = 1, VDISK_MGMT_RELEASE, 207enum vdisk_mgmt_types {
226} VDISK_MGMT_TYPES; 208 VDISK_MGMT_ACQUIRE = 1,
209 VDISK_MGMT_RELEASE,
210};
227 211
228/* this is used in the vdest field */ 212/* this is used in the vdest field */
229#define VDEST_ALL 0xFFFF 213#define VDEST_ALL 0xFFFF
@@ -242,7 +226,6 @@ typedef enum { VDISK_MGMT_ACQUIRE = 1, VDISK_MGMT_RELEASE,
242/* 226/*
243 * structs with pragma pack */ 227 * structs with pragma pack */
244 228
245
246/* ///////////// BEGIN PRAGMA PACK PUSH 1 ///////////////////////// */ 229/* ///////////// BEGIN PRAGMA PACK PUSH 1 ///////////////////////// */
247/* ///////////// ONLY STRUCT TYPE SHOULD BE BELOW */ 230/* ///////////// ONLY STRUCT TYPE SHOULD BE BELOW */
248 231
@@ -377,16 +360,16 @@ struct uiscmdrsp_scsi {
377 do { \ 360 do { \
378 memset(buf, 0, \ 361 memset(buf, 0, \
379 MINNUM(len, \ 362 MINNUM(len, \
380 (unsigned int) NO_DISK_INQUIRY_RESULT_LEN)); \ 363 (unsigned int)NO_DISK_INQUIRY_RESULT_LEN)); \
381 buf[2] = (u8) SCSI_SPC2_VER; \ 364 buf[2] = (u8)SCSI_SPC2_VER; \
382 if (lun == 0) { \ 365 if (lun == 0) { \
383 buf[0] = (u8) lun0notpresent; \ 366 buf[0] = (u8)lun0notpresent; \
384 buf[3] = (u8) DEV_HISUPPORT; \ 367 buf[3] = (u8)DEV_HISUPPORT; \
385 } else \ 368 } else \
386 buf[0] = (u8) notpresent; \ 369 buf[0] = (u8)notpresent; \
387 buf[4] = (u8) ( \ 370 buf[4] = (u8)( \
388 MINNUM(len, \ 371 MINNUM(len, \
389 (unsigned int) NO_DISK_INQUIRY_RESULT_LEN) - 5); \ 372 (unsigned int)NO_DISK_INQUIRY_RESULT_LEN) - 5);\
390 if (len >= NO_DISK_INQUIRY_RESULT_LEN) { \ 373 if (len >= NO_DISK_INQUIRY_RESULT_LEN) { \
391 buf[8] = 'D'; \ 374 buf[8] = 'D'; \
392 buf[9] = 'E'; \ 375 buf[9] = 'E'; \
@@ -410,12 +393,10 @@ struct uiscmdrsp_scsi {
410 } \ 393 } \
411 } while (0) 394 } while (0)
412 395
413
414/* 396/*
415* Struct & Defines to support sense information. 397* Struct & Defines to support sense information.
416*/ 398*/
417 399
418
419/* The following struct is returned in sensebuf field in uiscmdrsp_scsi. It is 400/* The following struct is returned in sensebuf field in uiscmdrsp_scsi. It is
420* initialized in exactly the manner that is recommended in Windows (hence the 401* initialized in exactly the manner that is recommended in Windows (hence the
421* odd values). 402* odd values).
@@ -429,21 +410,21 @@ struct uiscmdrsp_scsi {
429* AdditionalSenseLength contains will be sizeof(sense_data)-8=10. 410* AdditionalSenseLength contains will be sizeof(sense_data)-8=10.
430*/ 411*/
431struct sense_data { 412struct sense_data {
432 u8 ErrorCode:7; 413 u8 errorcode:7;
433 u8 Valid:1; 414 u8 valid:1;
434 u8 SegmentNumber; 415 u8 segment_number;
435 u8 SenseKey:4; 416 u8 sense_key:4;
436 u8 Reserved:1; 417 u8 reserved:1;
437 u8 IncorrectLength:1; 418 u8 incorrect_length:1;
438 u8 EndOfMedia:1; 419 u8 end_of_media:1;
439 u8 FileMark:1; 420 u8 file_mark:1;
440 u8 Information[4]; 421 u8 information[4];
441 u8 AdditionalSenseLength; 422 u8 additional_sense_length;
442 u8 CommandSpecificInformation[4]; 423 u8 command_specific_information[4];
443 u8 AdditionalSenseCode; 424 u8 additional_sense_code;
444 u8 AdditionalSenseCodeQualifier; 425 u8 additional_sense_code_qualifier;
445 u8 FieldReplaceableUnitCode; 426 u8 fru_code;
446 u8 SenseKeySpecific[3]; 427 u8 sense_key_specific[3];
447}; 428};
448 429
449/* some SCSI ADSENSE codes */ 430/* some SCSI ADSENSE codes */
@@ -484,7 +465,6 @@ struct net_pkt_xmt {
484 * each fragment */ 465 * each fragment */
485 char ethhdr[ETH_HEADER_SIZE]; /* the ethernet header */ 466 char ethhdr[ETH_HEADER_SIZE]; /* the ethernet header */
486 struct { 467 struct {
487
488 /* these are needed for csum at uisnic end */ 468 /* these are needed for csum at uisnic end */
489 u8 valid; /* 1 = rest of this struct is valid - else 469 u8 valid; /* 1 = rest of this struct is valid - else
490 * ignore */ 470 * ignore */
@@ -528,13 +508,12 @@ struct net_pkt_rcvpost {
528 * to be describable */ 508 * to be describable */
529 struct phys_info frag; /* physical page information for the 509 struct phys_info frag; /* physical page information for the
530 * single fragment 2K rcv buf */ 510 * single fragment 2K rcv buf */
531 u64 UniqueNum; /* This is used to make sure that 511 u64 unique_num; /* This is used to make sure that
532 * receive posts are returned to */ 512 * receive posts are returned to */
533 /* the Adapter which sent them origonally. */ 513 /* the Adapter which sent them origonally. */
534}; 514};
535 515
536struct net_pkt_rcv { 516struct net_pkt_rcv {
537
538 /* the number of receive buffers that can be chained */ 517 /* the number of receive buffers that can be chained */
539 /* is based on max mtu and size of each rcv buf */ 518 /* is based on max mtu and size of each rcv buf */
540 u32 rcv_done_len; /* length of received data */ 519 u32 rcv_done_len; /* length of received data */
@@ -544,8 +523,8 @@ struct net_pkt_rcv {
544 * that must be chained; */ 523 * that must be chained; */
545 /* each entry is a receive buffer provided by NET_RCV_POST. */ 524 /* each entry is a receive buffer provided by NET_RCV_POST. */
546 /* NOTE: first rcvbuf in the chain will also be provided in net.buf. */ 525 /* NOTE: first rcvbuf in the chain will also be provided in net.buf. */
547 u64 UniqueNum; 526 u64 unique_num;
548 u32 RcvsDroppedDelta; 527 u32 rcvs_dropped_delta;
549}; 528};
550 529
551struct net_pkt_enbdis { 530struct net_pkt_enbdis {
@@ -560,7 +539,7 @@ struct net_pkt_macaddr {
560 539
561/* cmd rsp packet used for VNIC network traffic */ 540/* cmd rsp packet used for VNIC network traffic */
562struct uiscmdrsp_net { 541struct uiscmdrsp_net {
563 NET_TYPES type; 542 enum net_types type;
564 void *buf; 543 void *buf;
565 union { 544 union {
566 struct net_pkt_xmt xmt; /* used for NET_XMIT */ 545 struct net_pkt_xmt xmt; /* used for NET_XMIT */
@@ -576,7 +555,7 @@ struct uiscmdrsp_net {
576}; 555};
577 556
578struct uiscmdrsp_scsitaskmgmt { 557struct uiscmdrsp_scsitaskmgmt {
579 TASK_MGMT_TYPES tasktype; 558 enum task_mgmt_types tasktype;
580 559
581 /* the type of task */ 560 /* the type of task */
582 struct uisscsi_dest vdest; 561 struct uisscsi_dest vdest;
@@ -594,7 +573,7 @@ struct uiscmdrsp_scsitaskmgmt {
594 * For windows guests, this is a pointer to a location that a waiting 573 * For windows guests, this is a pointer to a location that a waiting
595 * thread is testing to see if the taskmgmt command has completed. 574 * thread is testing to see if the taskmgmt command has completed.
596 * When the rsp is received by guest, the thread receiving the 575 * When the rsp is received by guest, the thread receiving the
597 * response uses this to notify the the thread waiting for taskmgmt 576 * response uses this to notify the thread waiting for taskmgmt
598 * command completion. Its value is preserved by iopart & returned 577 * command completion. Its value is preserved by iopart & returned
599 * as is in the task mgmt rsp. */ 578 * as is in the task mgmt rsp. */
600 void *notifyresult; 579 void *notifyresult;
@@ -615,7 +594,7 @@ struct uiscmdrsp_scsitaskmgmt {
615/* Note that the vHba pointer is not used by the Client/Guest side. */ 594/* Note that the vHba pointer is not used by the Client/Guest side. */
616struct uiscmdrsp_disknotify { 595struct uiscmdrsp_disknotify {
617 u8 add; /* 0-remove, 1-add */ 596 u8 add; /* 0-remove, 1-add */
618 void *vHba; /* Pointer to vhba_info for channel info to 597 void *v_hba; /* Pointer to vhba_info for channel info to
619 * route msg */ 598 * route msg */
620 u32 channel, id, lun; /* SCSI Path of Disk to added or removed */ 599 u32 channel, id, lun; /* SCSI Path of Disk to added or removed */
621}; 600};
@@ -623,7 +602,7 @@ struct uiscmdrsp_disknotify {
623/* The following is used by virthba/vSCSI to send the Acquire/Release commands 602/* The following is used by virthba/vSCSI to send the Acquire/Release commands
624* to the IOVM. */ 603* to the IOVM. */
625struct uiscmdrsp_vdiskmgmt { 604struct uiscmdrsp_vdiskmgmt {
626 VDISK_MGMT_TYPES vdisktype; 605 enum vdisk_mgmt_types vdisktype;
627 606
628 /* the type of task */ 607 /* the type of task */
629 struct uisscsi_dest vdest; 608 struct uisscsi_dest vdest;
@@ -641,7 +620,7 @@ struct uiscmdrsp_vdiskmgmt {
641 * For windows guests, this is a pointer to a location that a waiting 620 * For windows guests, this is a pointer to a location that a waiting
642 * thread is testing to see if the taskmgmt command has completed. 621 * thread is testing to see if the taskmgmt command has completed.
643 * When the rsp is received by guest, the thread receiving the 622 * When the rsp is received by guest, the thread receiving the
644 * response uses this to notify the the thread waiting for taskmgmt 623 * response uses this to notify the thread waiting for taskmgmt
645 * command completion. Its value is preserved by iopart & returned 624 * command completion. Its value is preserved by iopart & returned
646 * as is in the task mgmt rsp. */ 625 * as is in the task mgmt rsp. */
647 void *notifyresult; 626 void *notifyresult;
@@ -683,11 +662,11 @@ struct uiscmdrsp {
683 662
684/* This is just the header of the IO channel. It is assumed that directly after 663/* This is just the header of the IO channel. It is assumed that directly after
685* this header there is a large region of memory which contains the command and 664* this header there is a large region of memory which contains the command and
686* response queues as specified in cmdQ and rspQ SIGNAL_QUEUE_HEADERS. */ 665* response queues as specified in cmd_q and rsp_q SIGNAL_QUEUE_HEADERS. */
687typedef struct _ULTRA_IO_CHANNEL_PROTOCOL { 666struct spar_io_channel_protocol {
688 CHANNEL_HEADER ChannelHeader; 667 struct channel_header channel_header;
689 SIGNAL_QUEUE_HEADER cmdQ; 668 struct signal_queue_header cmd_q;
690 SIGNAL_QUEUE_HEADER rspQ; 669 struct signal_queue_header rsp_q;
691 union { 670 union {
692 struct { 671 struct {
693 struct vhba_wwnn wwnn; /* 8 bytes */ 672 struct vhba_wwnn wwnn; /* 8 bytes */
@@ -697,14 +676,14 @@ typedef struct _ULTRA_IO_CHANNEL_PROTOCOL {
697 u8 macaddr[MAX_MACADDR_LEN]; /* 6 bytes */ 676 u8 macaddr[MAX_MACADDR_LEN]; /* 6 bytes */
698 u32 num_rcv_bufs; /* 4 */ 677 u32 num_rcv_bufs; /* 4 */
699 u32 mtu; /* 4 */ 678 u32 mtu; /* 4 */
700 uuid_le zoneGuid; /* 16 */ 679 uuid_le zone_uuid; /* 16 */
701 } vnic; /* total 30 */ 680 } vnic; /* total 30 */
702 }; 681 };
703 682
704#define MAX_CLIENTSTRING_LEN 1024 683#define MAX_CLIENTSTRING_LEN 1024
705 u8 clientString[MAX_CLIENTSTRING_LEN]; /* NULL terminated - so holds 684 u8 client_string[MAX_CLIENTSTRING_LEN];/* NULL terminated - so holds
706 * max - 1 bytes */ 685 * max - 1 bytes */
707} ULTRA_IO_CHANNEL_PROTOCOL; 686};
708 687
709#pragma pack(pop) 688#pragma pack(pop)
710/* ///////////// END PRAGMA PACK PUSH 1 /////////////////////////// */ 689/* ///////////// END PRAGMA PACK PUSH 1 /////////////////////////// */
@@ -733,144 +712,17 @@ typedef struct _ULTRA_IO_CHANNEL_PROTOCOL {
733* INLINE functions for initializing and accessing I/O data channels 712* INLINE functions for initializing and accessing I/O data channels
734*/ 713*/
735 714
736 715#define SIZEOF_PROTOCOL (COVER(sizeof(struct spar_io_channel_protocol), 64))
737#define NUMSIGNALS(x, q) (((ULTRA_IO_CHANNEL_PROTOCOL *)(x))->q.MaxSignalSlots)
738#define SIZEOF_PROTOCOL (COVER(sizeof(ULTRA_IO_CHANNEL_PROTOCOL), 64))
739#define SIZEOF_CMDRSP (COVER(sizeof(struct uiscmdrsp), 64)) 716#define SIZEOF_CMDRSP (COVER(sizeof(struct uiscmdrsp), 64))
740 717
741#define IO_CHANNEL_SIZE(x) COVER(SIZEOF_PROTOCOL + \
742 (NUMSIGNALS(x, cmdQ) + \
743 NUMSIGNALS(x, rspQ)) * SIZEOF_CMDRSP, 4096)
744#define MIN_IO_CHANNEL_SIZE COVER(SIZEOF_PROTOCOL + \ 718#define MIN_IO_CHANNEL_SIZE COVER(SIZEOF_PROTOCOL + \
745 2 * MIN_NUMSIGNALS * SIZEOF_CMDRSP, 4096) 719 2 * MIN_NUMSIGNALS * SIZEOF_CMDRSP, 4096)
746#ifdef __GNUC__
747/* These defines should only ever be used in service partitons */
748/* because they rely on the size of uiscmdrsp */
749#define QSLOTSFROMBYTES(bytes) (((bytes-SIZEOF_PROTOCOL)/2)/SIZEOF_CMDRSP)
750#define QSIZEFROMBYTES(bytes) (QSLOTSFROMBYTES(bytes)*SIZEOF_CMDRSP)
751#define SignalQInit(x) \
752 do { \
753 x->cmdQ.Size = QSIZEFROMBYTES(x->ChannelHeader.Size); \
754 x->cmdQ.oSignalBase = SIZEOF_PROTOCOL - \
755 offsetof(ULTRA_IO_CHANNEL_PROTOCOL, cmdQ); \
756 x->cmdQ.SignalSize = SIZEOF_CMDRSP; \
757 x->cmdQ.MaxSignalSlots = \
758 QSLOTSFROMBYTES(x->ChannelHeader.Size); \
759 x->cmdQ.MaxSignals = x->cmdQ.MaxSignalSlots - 1; \
760 x->rspQ.Size = QSIZEFROMBYTES(x->ChannelHeader.Size); \
761 x->rspQ.oSignalBase = \
762 (SIZEOF_PROTOCOL + x->cmdQ.Size) - \
763 offsetof(ULTRA_IO_CHANNEL_PROTOCOL, rspQ); \
764 x->rspQ.SignalSize = SIZEOF_CMDRSP; \
765 x->rspQ.MaxSignalSlots = \
766 QSLOTSFROMBYTES(x->ChannelHeader.Size); \
767 x->rspQ.MaxSignals = x->rspQ.MaxSignalSlots - 1; \
768 x->ChannelHeader.oChannelSpace = \
769 offsetof(ULTRA_IO_CHANNEL_PROTOCOL, cmdQ); \
770 } while (0)
771
772#define INIT_CLIENTSTRING(chan, type, clientStr, clientStrLen) \
773 do { \
774 if (clientStr) { \
775 chan->ChannelHeader.oClientString = \
776 offsetof(type, clientString); \
777 memcpy(chan->clientString, clientStr, \
778 MINNUM(clientStrLen, \
779 (u32) (MAX_CLIENTSTRING_LEN - 1))); \
780 chan->clientString[MINNUM(clientStrLen, \
781 (u32) (MAX_CLIENTSTRING_LEN \
782 - 1))] \
783 = '\0'; \
784 } \
785 else \
786 if (clientStrLen > 0) \
787 return 0; \
788 } while (0)
789
790
791#define ULTRA_IO_CHANNEL_SERVER_READY(x, chanId, logCtx) \
792 ULTRA_CHANNEL_SERVER_TRANSITION(x, chanId, SrvState, CHANNELSRV_READY, \
793 logCtx)
794
795#define ULTRA_IO_CHANNEL_SERVER_NOTREADY(x, chanId, logCtx) \
796 ULTRA_CHANNEL_SERVER_TRANSITION(x, chanId, SrvState, \
797 CHANNELSRV_UNINITIALIZED, logCtx)
798
799static inline int ULTRA_VHBA_init_channel(ULTRA_IO_CHANNEL_PROTOCOL *x,
800 struct vhba_wwnn *wwnn,
801 struct vhba_config_max *max,
802 unsigned char *clientStr,
803 u32 clientStrLen, u64 bytes) {
804 memset(x, 0, sizeof(ULTRA_IO_CHANNEL_PROTOCOL));
805 x->ChannelHeader.VersionId = ULTRA_VHBA_CHANNEL_PROTOCOL_VERSIONID;
806 x->ChannelHeader.Signature = ULTRA_VHBA_CHANNEL_PROTOCOL_SIGNATURE;
807 x->ChannelHeader.SrvState = CHANNELSRV_UNINITIALIZED;
808 x->ChannelHeader.HeaderSize = sizeof(x->ChannelHeader);
809 x->ChannelHeader.Size = COVER(bytes, 4096);
810 x->ChannelHeader.Type = UltraVhbaChannelProtocolGuid;
811 x->ChannelHeader.ZoneGuid = NULL_UUID_LE;
812 x->vhba.wwnn = *wwnn;
813 x->vhba.max = *max;
814 INIT_CLIENTSTRING(x, ULTRA_IO_CHANNEL_PROTOCOL, clientStr,
815 clientStrLen);
816 SignalQInit(x);
817 if ((x->cmdQ.MaxSignalSlots > MAX_NUMSIGNALS) ||
818 (x->rspQ.MaxSignalSlots > MAX_NUMSIGNALS)) {
819 return 0;
820 }
821 if ((x->cmdQ.MaxSignalSlots < MIN_NUMSIGNALS) ||
822 (x->rspQ.MaxSignalSlots < MIN_NUMSIGNALS)) {
823 return 0;
824 }
825 return 1;
826}
827
828static inline void ULTRA_VHBA_set_max(ULTRA_IO_CHANNEL_PROTOCOL *x,
829 struct vhba_config_max *max) {
830 x->vhba.max = *max;
831}
832
833static inline int ULTRA_VNIC_init_channel(ULTRA_IO_CHANNEL_PROTOCOL *x,
834 unsigned char *macaddr,
835 u32 num_rcv_bufs, u32 mtu,
836 uuid_le zoneGuid,
837 unsigned char *clientStr,
838 u32 clientStrLen,
839 u64 bytes) {
840 memset(x, 0, sizeof(ULTRA_IO_CHANNEL_PROTOCOL));
841 x->ChannelHeader.VersionId = ULTRA_VNIC_CHANNEL_PROTOCOL_VERSIONID;
842 x->ChannelHeader.Signature = ULTRA_VNIC_CHANNEL_PROTOCOL_SIGNATURE;
843 x->ChannelHeader.SrvState = CHANNELSRV_UNINITIALIZED;
844 x->ChannelHeader.HeaderSize = sizeof(x->ChannelHeader);
845 x->ChannelHeader.Size = COVER(bytes, 4096);
846 x->ChannelHeader.Type = UltraVnicChannelProtocolGuid;
847 x->ChannelHeader.ZoneGuid = NULL_UUID_LE;
848 memcpy(x->vnic.macaddr, macaddr, MAX_MACADDR_LEN);
849 x->vnic.num_rcv_bufs = num_rcv_bufs;
850 x->vnic.mtu = mtu;
851 x->vnic.zoneGuid = zoneGuid;
852 INIT_CLIENTSTRING(x, ULTRA_IO_CHANNEL_PROTOCOL, clientStr,
853 clientStrLen);
854 SignalQInit(x);
855 if ((x->cmdQ.MaxSignalSlots > MAX_NUMSIGNALS) ||
856 (x->rspQ.MaxSignalSlots > MAX_NUMSIGNALS)) {
857 return 0;
858 }
859 if ((x->cmdQ.MaxSignalSlots < MIN_NUMSIGNALS) ||
860 (x->rspQ.MaxSignalSlots < MIN_NUMSIGNALS)) {
861 return 0;
862 }
863 return 1;
864}
865
866#endif /* __GNUC__ */
867 720
868/* 721/*
869* INLINE function for expanding a guest's pfn-off-size into multiple 4K page 722* INLINE function for expanding a guest's pfn-off-size into multiple 4K page
870* pfn-off-size entires. 723* pfn-off-size entires.
871*/ 724*/
872 725
873
874/* we deal with 4K page sizes when we it comes to passing page information 726/* we deal with 4K page sizes when we it comes to passing page information
875 * between */ 727 * between */
876/* Guest and IOPartition. */ 728/* Guest and IOPartition. */
@@ -900,13 +752,12 @@ add_physinfo_entries(u32 inp_pfn, /* input - specifies the pfn to be used
900 752
901 firstlen = PI_PAGE_SIZE - inp_off; 753 firstlen = PI_PAGE_SIZE - inp_off;
902 if (inp_len <= firstlen) { 754 if (inp_len <= firstlen) {
903
904 /* the input entry spans only one page - add as is */ 755 /* the input entry spans only one page - add as is */
905 if (index >= max_pi_arr_entries) 756 if (index >= max_pi_arr_entries)
906 return 0; 757 return 0;
907 pi_arr[index].pi_pfn = inp_pfn; 758 pi_arr[index].pi_pfn = inp_pfn;
908 pi_arr[index].pi_off = (u16) inp_off; 759 pi_arr[index].pi_off = (u16)inp_off;
909 pi_arr[index].pi_len = (u16) inp_len; 760 pi_arr[index].pi_len = (u16)inp_len;
910 return index + 1; 761 return index + 1;
911 } 762 }
912 763
@@ -924,9 +775,8 @@ add_physinfo_entries(u32 inp_pfn, /* input - specifies the pfn to be used
924 else { 775 else {
925 pi_arr[index + i].pi_off = 0; 776 pi_arr[index + i].pi_off = 0;
926 pi_arr[index + i].pi_len = 777 pi_arr[index + i].pi_len =
927 (u16) MINNUM(len, (u32) PI_PAGE_SIZE); 778 (u16)MINNUM(len, (u32)PI_PAGE_SIZE);
928 } 779 }
929
930 } 780 }
931 return index + i; 781 return index + i;
932} 782}
diff --git a/drivers/staging/unisys/common-spar/include/channels/vbuschannel.h b/drivers/staging/unisys/common-spar/include/channels/vbuschannel.h
index 1231c454176f..2c42ce16e0cf 100644
--- a/drivers/staging/unisys/common-spar/include/channels/vbuschannel.h
+++ b/drivers/staging/unisys/common-spar/include/channels/vbuschannel.h
@@ -28,65 +28,61 @@
28#include "channel.h" 28#include "channel.h"
29 29
30/* {193b331b-c58f-11da-95a9-00e08161165f} */ 30/* {193b331b-c58f-11da-95a9-00e08161165f} */
31#define ULTRA_VBUS_CHANNEL_PROTOCOL_GUID \ 31#define SPAR_VBUS_CHANNEL_PROTOCOL_UUID \
32 UUID_LE(0x193b331b, 0xc58f, 0x11da, \ 32 UUID_LE(0x193b331b, 0xc58f, 0x11da, \
33 0x95, 0xa9, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f) 33 0x95, 0xa9, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f)
34static const uuid_le UltraVbusChannelProtocolGuid = 34static const uuid_le spar_vbus_channel_protocol_uuid =
35 ULTRA_VBUS_CHANNEL_PROTOCOL_GUID; 35 SPAR_VBUS_CHANNEL_PROTOCOL_UUID;
36 36
37#define ULTRA_VBUS_CHANNEL_PROTOCOL_SIGNATURE ULTRA_CHANNEL_PROTOCOL_SIGNATURE 37#define SPAR_VBUS_CHANNEL_PROTOCOL_SIGNATURE ULTRA_CHANNEL_PROTOCOL_SIGNATURE
38 38
39/* Must increment this whenever you insert or delete fields within this channel 39/* Must increment this whenever you insert or delete fields within this channel
40* struct. Also increment whenever you change the meaning of fields within this 40* struct. Also increment whenever you change the meaning of fields within this
41* channel struct so as to break pre-existing software. Note that you can 41* channel struct so as to break pre-existing software. Note that you can
42* usually add fields to the END of the channel struct withOUT needing to 42* usually add fields to the END of the channel struct withOUT needing to
43* increment this. */ 43* increment this. */
44#define ULTRA_VBUS_CHANNEL_PROTOCOL_VERSIONID 1 44#define SPAR_VBUS_CHANNEL_PROTOCOL_VERSIONID 1
45 45
46#define ULTRA_VBUS_CHANNEL_OK_CLIENT(pChannel, logCtx) \ 46#define SPAR_VBUS_CHANNEL_OK_CLIENT(ch) \
47 (ULTRA_check_channel_client(pChannel, \ 47 spar_check_channel_client(ch, \
48 UltraVbusChannelProtocolGuid, \ 48 spar_vbus_channel_protocol_uuid, \
49 "vbus", \ 49 "vbus", \
50 sizeof(ULTRA_VBUS_CHANNEL_PROTOCOL), \ 50 sizeof(struct spar_vbus_channel_protocol),\
51 ULTRA_VBUS_CHANNEL_PROTOCOL_VERSIONID, \ 51 SPAR_VBUS_CHANNEL_PROTOCOL_VERSIONID, \
52 ULTRA_VBUS_CHANNEL_PROTOCOL_SIGNATURE, \ 52 SPAR_VBUS_CHANNEL_PROTOCOL_SIGNATURE)
53 __FILE__, __LINE__, logCtx))
54
55#define ULTRA_VBUS_CHANNEL_OK_SERVER(actualBytes, logCtx) \
56 (ULTRA_check_channel_server(UltraVbusChannelProtocolGuid, \
57 "vbus", \
58 sizeof(ULTRA_VBUS_CHANNEL_PROTOCOL), \
59 actualBytes, \
60 __FILE__, __LINE__, logCtx))
61 53
54#define SPAR_VBUS_CHANNEL_OK_SERVER(actual_bytes) \
55 (spar_check_channel_server(spar_vbus_channel_protocol_uuid, \
56 "vbus", \
57 sizeof(struct ultra_vbus_channel_protocol),\
58 actual_bytes))
62 59
63#pragma pack(push, 1) /* both GCC and VC now allow this pragma */ 60#pragma pack(push, 1) /* both GCC and VC now allow this pragma */
64typedef struct _ULTRA_VBUS_HEADERINFO { 61struct spar_vbus_headerinfo {
65 u32 structBytes; /* size of this struct in bytes */ 62 u32 struct_bytes; /* size of this struct in bytes */
66 u32 deviceInfoStructBytes; /* sizeof(ULTRA_VBUS_DEVICEINFO) */ 63 u32 device_info_struct_bytes; /* sizeof(ULTRA_VBUS_DEVICEINFO) */
67 u32 devInfoCount; /* num of items in DevInfo member */ 64 u32 dev_info_count; /* num of items in DevInfo member */
68 /* (this is the allocated size) */ 65 /* (this is the allocated size) */
69 u32 chpInfoByteOffset; /* byte offset from beginning of this struct */ 66 u32 chp_info_offset; /* byte offset from beginning of this struct */
70 /* to the the ChpInfo struct (below) */ 67 /* to the ChpInfo struct (below) */
71 u32 busInfoByteOffset; /* byte offset from beginning of this struct */ 68 u32 bus_info_offset; /* byte offset from beginning of this struct */
72 /* to the the BusInfo struct (below) */ 69 /* to the BusInfo struct (below) */
73 u32 devInfoByteOffset; /* byte offset from beginning of this struct */ 70 u32 dev_info_offset; /* byte offset from beginning of this struct */
74 /* to the the DevInfo array (below) */ 71 /* to the DevInfo array (below) */
75 u8 reserved[104]; 72 u8 reserved[104];
76} ULTRA_VBUS_HEADERINFO; 73};
77 74
78typedef struct _ULTRA_VBUS_CHANNEL_PROTOCOL { 75struct spar_vbus_channel_protocol {
79 ULTRA_CHANNEL_PROTOCOL ChannelHeader; /* initialized by server */ 76 struct channel_header channel_header; /* initialized by server */
80 ULTRA_VBUS_HEADERINFO HdrInfo; /* initialized by server */ 77 struct spar_vbus_headerinfo hdr_info; /* initialized by server */
81 /* the remainder of this channel is filled in by the client */ 78 /* the remainder of this channel is filled in by the client */
82 ULTRA_VBUS_DEVICEINFO ChpInfo; /* describes client chipset device and 79 struct ultra_vbus_deviceinfo chp_info;
83 * driver */ 80 /* describes client chipset device and driver */
84 ULTRA_VBUS_DEVICEINFO BusInfo; /* describes client bus device and 81 struct ultra_vbus_deviceinfo bus_info;
85 * driver */ 82 /* describes client bus device and driver */
86 ULTRA_VBUS_DEVICEINFO DevInfo[0]; /* describes client device and 83 struct ultra_vbus_deviceinfo dev_info[0];
87 * driver for */ 84 /* describes client device and driver for each device on the bus */
88 /* each device on the bus */ 85};
89} ULTRA_VBUS_CHANNEL_PROTOCOL;
90 86
91#define VBUS_CH_SIZE_EXACT(MAXDEVICES) \ 87#define VBUS_CH_SIZE_EXACT(MAXDEVICES) \
92 (sizeof(ULTRA_VBUS_CHANNEL_PROTOCOL) + ((MAXDEVICES) * \ 88 (sizeof(ULTRA_VBUS_CHANNEL_PROTOCOL) + ((MAXDEVICES) * \
diff --git a/drivers/staging/unisys/common-spar/include/vbusdeviceinfo.h b/drivers/staging/unisys/common-spar/include/vbusdeviceinfo.h
index 3bbdc2bb7ebf..9b6d3e69355c 100644
--- a/drivers/staging/unisys/common-spar/include/vbusdeviceinfo.h
+++ b/drivers/staging/unisys/common-spar/include/vbusdeviceinfo.h
@@ -25,13 +25,13 @@
25 * It is filled in by the client side to provide info about the device 25 * It is filled in by the client side to provide info about the device
26 * and driver from the client's perspective. 26 * and driver from the client's perspective.
27 */ 27 */
28typedef struct _ULTRA_VBUS_DEVICEINFO { 28struct ultra_vbus_deviceinfo {
29 u8 devType[16]; /* short string identifying the device type */ 29 u8 devtype[16]; /* short string identifying the device type */
30 u8 drvName[16]; /* driver .sys file name */ 30 u8 drvname[16]; /* driver .sys file name */
31 u8 infoStrings[96]; /* sequence of tab-delimited id strings: */ 31 u8 infostrs[96]; /* sequence of tab-delimited id strings: */
32 /* <DRIVER_REV> <DRIVER_VERTAG> <DRIVER_COMPILETIME> */ 32 /* <DRIVER_REV> <DRIVER_VERTAG> <DRIVER_COMPILETIME> */
33 u8 reserved[128]; /* pad size to 256 bytes */ 33 u8 reserved[128]; /* pad size to 256 bytes */
34} ULTRA_VBUS_DEVICEINFO; 34};
35 35
36#pragma pack(pop) 36#pragma pack(pop)
37 37
@@ -63,8 +63,9 @@ vbuschannel_sanitize_buffer(char *p, int remain, char *src, int srcmax)
63 p++; 63 p++;
64 remain--; 64 remain--;
65 chars++; 65 chars++;
66 } else if (p == NULL) 66 } else if (p == NULL) {
67 chars++; 67 chars++;
68 }
68 nonprintable_streak = 0; 69 nonprintable_streak = 0;
69 } 70 }
70 if (remain > 0) { 71 if (remain > 0) {
@@ -72,10 +73,12 @@ vbuschannel_sanitize_buffer(char *p, int remain, char *src, int srcmax)
72 p++; 73 p++;
73 remain--; 74 remain--;
74 chars++; 75 chars++;
75 } else if (p == NULL) 76 } else if (p == NULL) {
76 chars++; 77 chars++;
77 } else 78 }
79 } else {
78 nonprintable_streak = 1; 80 nonprintable_streak = 1;
81 }
79 src++; 82 src++;
80 srcmax--; 83 srcmax--;
81 } 84 }
@@ -115,7 +118,7 @@ vbuschannel_itoa(char *p, int remain, int num)
115 } 118 }
116 /* form a backwards decimal ascii string in <s> */ 119 /* form a backwards decimal ascii string in <s> */
117 while (num > 0) { 120 while (num > 0) {
118 if (digits >= (int) sizeof(s)) 121 if (digits >= (int)sizeof(s))
119 return 0; 122 return 0;
120 s[digits++] = (num % 10) + '0'; 123 s[digits++] = (num % 10) + '0';
121 num = num / 10; 124 num = num / 10;
@@ -147,15 +150,15 @@ vbuschannel_itoa(char *p, int remain, int num)
147 * Returns the number of bytes written to <p>. 150 * Returns the number of bytes written to <p>.
148 */ 151 */
149static inline int 152static inline int
150vbuschannel_devinfo_to_string(ULTRA_VBUS_DEVICEINFO *devinfo, 153vbuschannel_devinfo_to_string(struct ultra_vbus_deviceinfo *devinfo,
151 char *p, int remain, int devix) 154 char *p, int remain, int devix)
152{ 155{
153 char *psrc; 156 char *psrc;
154 int nsrc, x, i, pad; 157 int nsrc, x, i, pad;
155 int chars = 0; 158 int chars = 0;
156 159
157 psrc = &(devinfo->devType[0]); 160 psrc = &devinfo->devtype[0];
158 nsrc = sizeof(devinfo->devType); 161 nsrc = sizeof(devinfo->devtype);
159 if (vbuschannel_sanitize_buffer(NULL, 0, psrc, nsrc) <= 0) 162 if (vbuschannel_sanitize_buffer(NULL, 0, psrc, nsrc) <= 0)
160 return 0; 163 return 0;
161 164
@@ -184,8 +187,8 @@ vbuschannel_devinfo_to_string(ULTRA_VBUS_DEVICEINFO *devinfo,
184 VBUSCHANNEL_ADDACHAR(' ', p, remain, chars); 187 VBUSCHANNEL_ADDACHAR(' ', p, remain, chars);
185 188
186 /* emit driver name */ 189 /* emit driver name */
187 psrc = &(devinfo->drvName[0]); 190 psrc = &devinfo->drvname[0];
188 nsrc = sizeof(devinfo->drvName); 191 nsrc = sizeof(devinfo->drvname);
189 x = vbuschannel_sanitize_buffer(p, remain, psrc, nsrc); 192 x = vbuschannel_sanitize_buffer(p, remain, psrc, nsrc);
190 p += x; 193 p += x;
191 remain -= x; 194 remain -= x;
@@ -196,8 +199,8 @@ vbuschannel_devinfo_to_string(ULTRA_VBUS_DEVICEINFO *devinfo,
196 VBUSCHANNEL_ADDACHAR(' ', p, remain, chars); 199 VBUSCHANNEL_ADDACHAR(' ', p, remain, chars);
197 200
198 /* emit strings */ 201 /* emit strings */
199 psrc = &(devinfo->infoStrings[0]); 202 psrc = &devinfo->infostrs[0];
200 nsrc = sizeof(devinfo->infoStrings); 203 nsrc = sizeof(devinfo->infostrs);
201 x = vbuschannel_sanitize_buffer(p, remain, psrc, nsrc); 204 x = vbuschannel_sanitize_buffer(p, remain, psrc, nsrc);
202 p += x; 205 p += x;
203 remain -= x; 206 remain -= x;
diff --git a/drivers/staging/unisys/common-spar/include/vmcallinterface.h b/drivers/staging/unisys/common-spar/include/vmcallinterface.h
index 0b5b5626af5a..78333719c496 100644
--- a/drivers/staging/unisys/common-spar/include/vmcallinterface.h
+++ b/drivers/staging/unisys/common-spar/include/vmcallinterface.h
@@ -33,7 +33,7 @@
33 33
34/* define subsystem number for AppOS, used in uislib driver */ 34/* define subsystem number for AppOS, used in uislib driver */
35#define MDS_APPOS 0x4000000000000000L /* subsystem = 62 - AppOS */ 35#define MDS_APPOS 0x4000000000000000L /* subsystem = 62 - AppOS */
36typedef enum { /* VMCALL identification tuples */ 36enum vmcall_monitor_interface_method_tuple { /* VMCALL identification tuples */
37 /* Note: when a new VMCALL is added: 37 /* Note: when a new VMCALL is added:
38 * - the 1st 2 hex digits correspond to one of the 38 * - the 1st 2 hex digits correspond to one of the
39 * VMCALL_MONITOR_INTERFACE types and 39 * VMCALL_MONITOR_INTERFACE types and
@@ -66,7 +66,7 @@ typedef enum { /* VMCALL identification tuples */
66 * ULTRA_SERVICE_CAPABILITY_TIME 66 * ULTRA_SERVICE_CAPABILITY_TIME
67 * capable guest to make 67 * capable guest to make
68 * VMCALL */ 68 * VMCALL */
69} VMCALL_MONITOR_INTERFACE_METHOD_TUPLE; 69};
70 70
71#define VMCALL_SUCCESS 0 71#define VMCALL_SUCCESS 0
72#define VMCALL_SUCCESSFUL(result) (result == 0) 72#define VMCALL_SUCCESSFUL(result) (result == 0)
@@ -76,12 +76,12 @@ typedef enum { /* VMCALL identification tuples */
76 __unisys_vmcall_gnuc(tuple, reg_ebx, reg_ecx) 76 __unisys_vmcall_gnuc(tuple, reg_ebx, reg_ecx)
77#define unisys_extended_vmcall(tuple, reg_ebx, reg_ecx, reg_edx) \ 77#define unisys_extended_vmcall(tuple, reg_ebx, reg_ecx, reg_edx) \
78 __unisys_extended_vmcall_gnuc(tuple, reg_ebx, reg_ecx, reg_edx) 78 __unisys_extended_vmcall_gnuc(tuple, reg_ebx, reg_ecx, reg_edx)
79#define ISSUE_IO_VMCALL(InterfaceMethod, param, result) \ 79#define ISSUE_IO_VMCALL(method, param, result) \
80 (result = unisys_vmcall(InterfaceMethod, (param) & 0xFFFFFFFF, \ 80 (result = unisys_vmcall(method, (param) & 0xFFFFFFFF, \
81 (param) >> 32)) 81 (param) >> 32))
82#define ISSUE_IO_EXTENDED_VMCALL(InterfaceMethod, param1, param2, \ 82#define ISSUE_IO_EXTENDED_VMCALL(method, param1, param2, \
83 param3, result) \ 83 param3, result) \
84 (result = unisys_extended_vmcall(InterfaceMethod, param1, \ 84 (result = unisys_extended_vmcall(method, param1, \
85 param2, param3)) 85 param2, param3))
86 86
87 /* The following uses VMCALL_POST_CODE_LOGEVENT interface but is currently 87 /* The following uses VMCALL_POST_CODE_LOGEVENT interface but is currently
@@ -107,21 +107,20 @@ struct phys_info {
107 107
108#pragma pack(pop) 108#pragma pack(pop)
109/* ///////////// END PRAGMA PACK PUSH 1 /////////////////////////// */ 109/* ///////////// END PRAGMA PACK PUSH 1 /////////////////////////// */
110typedef struct phys_info IO_DATA_STRUCTURE;
111 110
112/* ///////////// BEGIN PRAGMA PACK PUSH 1 ///////////////////////// */ 111/* ///////////// BEGIN PRAGMA PACK PUSH 1 ///////////////////////// */
113/* ///////////// ONLY STRUCT TYPE SHOULD BE BELOW */ 112/* ///////////// ONLY STRUCT TYPE SHOULD BE BELOW */
114#pragma pack(push, 1) 113#pragma pack(push, 1)
115/* Parameters to VMCALL_IO_CONTROLVM_ADDR interface */ 114/* Parameters to VMCALL_IO_CONTROLVM_ADDR interface */
116typedef struct _VMCALL_IO_CONTROLVM_ADDR_PARAMS { 115struct vmcall_io_controlvm_addr_params {
117 /* The Guest-relative physical address of the ControlVm channel. 116 /* The Guest-relative physical address of the ControlVm channel.
118 * This VMCall fills this in with the appropriate address. */ 117 * This VMCall fills this in with the appropriate address. */
119 u64 ChannelAddress; /* contents provided by this VMCALL (OUT) */ 118 u64 address; /* contents provided by this VMCALL (OUT) */
120 /* the size of the ControlVm channel in bytes This VMCall fills this 119 /* the size of the ControlVm channel in bytes This VMCall fills this
121 * in with the appropriate address. */ 120 * in with the appropriate address. */
122 u32 ChannelBytes; /* contents provided by this VMCALL (OUT) */ 121 u32 channel_bytes; /* contents provided by this VMCALL (OUT) */
123 u8 Unused[4]; /* Unused Bytes in the 64-Bit Aligned Struct */ 122 u8 unused[4]; /* Unused Bytes in the 64-Bit Aligned Struct */
124} VMCALL_IO_CONTROLVM_ADDR_PARAMS; 123};
125 124
126#pragma pack(pop) 125#pragma pack(pop)
127/* ///////////// END PRAGMA PACK PUSH 1 /////////////////////////// */ 126/* ///////////// END PRAGMA PACK PUSH 1 /////////////////////////// */
@@ -130,11 +129,11 @@ typedef struct _VMCALL_IO_CONTROLVM_ADDR_PARAMS {
130/* ///////////// ONLY STRUCT TYPE SHOULD BE BELOW */ 129/* ///////////// ONLY STRUCT TYPE SHOULD BE BELOW */
131#pragma pack(push, 1) 130#pragma pack(push, 1)
132/* Parameters to VMCALL_IO_DIAG_ADDR interface */ 131/* Parameters to VMCALL_IO_DIAG_ADDR interface */
133typedef struct _VMCALL_IO_DIAG_ADDR_PARAMS { 132struct vmcall_io_diag_addr_params {
134 /* The Guest-relative physical address of the diagnostic channel. 133 /* The Guest-relative physical address of the diagnostic channel.
135 * This VMCall fills this in with the appropriate address. */ 134 * This VMCall fills this in with the appropriate address. */
136 u64 ChannelAddress; /* contents provided by this VMCALL (OUT) */ 135 u64 address; /* contents provided by this VMCALL (OUT) */
137} VMCALL_IO_DIAG_ADDR_PARAMS; 136};
138 137
139#pragma pack(pop) 138#pragma pack(pop)
140/* ///////////// END PRAGMA PACK PUSH 1 /////////////////////////// */ 139/* ///////////// END PRAGMA PACK PUSH 1 /////////////////////////// */
@@ -143,25 +142,25 @@ typedef struct _VMCALL_IO_DIAG_ADDR_PARAMS {
143/* ///////////// ONLY STRUCT TYPE SHOULD BE BELOW */ 142/* ///////////// ONLY STRUCT TYPE SHOULD BE BELOW */
144#pragma pack(push, 1) 143#pragma pack(push, 1)
145/* Parameters to VMCALL_IO_VISORSERIAL_ADDR interface */ 144/* Parameters to VMCALL_IO_VISORSERIAL_ADDR interface */
146typedef struct _VMCALL_IO_VISORSERIAL_ADDR_PARAMS { 145struct vmcall_io_visorserial_addr_params {
147 /* The Guest-relative physical address of the serial console 146 /* The Guest-relative physical address of the serial console
148 * channel. This VMCall fills this in with the appropriate 147 * channel. This VMCall fills this in with the appropriate
149 * address. */ 148 * address. */
150 u64 ChannelAddress; /* contents provided by this VMCALL (OUT) */ 149 u64 address; /* contents provided by this VMCALL (OUT) */
151} VMCALL_IO_VISORSERIAL_ADDR_PARAMS; 150};
152 151
153#pragma pack(pop) 152#pragma pack(pop)
154/* ///////////// END PRAGMA PACK PUSH 1 /////////////////////////// */ 153/* ///////////// END PRAGMA PACK PUSH 1 /////////////////////////// */
155 154
156/* Parameters to VMCALL_CHANNEL_MISMATCH interface */ 155/* Parameters to VMCALL_CHANNEL_MISMATCH interface */
157typedef struct _VMCALL_CHANNEL_VERSION_MISMATCH_PARAMS { 156struct vmcall_channel_version_mismatch_params {
158 u8 ChannelName[32]; /* Null terminated string giving name of channel 157 u8 chname[32]; /* Null terminated string giving name of channel
159 * (IN) */ 158 * (IN) */
160 u8 ItemName[32]; /* Null terminated string giving name of 159 u8 item_name[32]; /* Null terminated string giving name of
161 * mismatched item (IN) */ 160 * mismatched item (IN) */
162 u32 SourceLineNumber; /* line# where invoked. (IN) */ 161 u32 line_no; /* line# where invoked. (IN) */
163 u8 SourceFileName[36]; /* source code where invoked - Null terminated 162 u8 file_name[36]; /* source code where invoked - Null terminated
164 * string (IN) */ 163 * string (IN) */
165} VMCALL_CHANNEL_VERSION_MISMATCH_PARAMS; 164};
166 165
167#endif /* __IOMONINTF_H__ */ 166#endif /* __IOMONINTF_H__ */
diff --git a/drivers/staging/unisys/include/timskmod.h b/drivers/staging/unisys/include/timskmod.h
index b14494ff6c1b..cff7983dab85 100644
--- a/drivers/staging/unisys/include/timskmod.h
+++ b/drivers/staging/unisys/include/timskmod.h
@@ -31,7 +31,6 @@
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/errno.h> 32#include <linux/errno.h>
33#include <linux/interrupt.h> 33#include <linux/interrupt.h>
34#include <linux/sched.h>
35#include <linux/wait.h> 34#include <linux/wait.h>
36#include <linux/vmalloc.h> 35#include <linux/vmalloc.h>
37#include <linux/proc_fs.h> 36#include <linux/proc_fs.h>
@@ -71,7 +70,6 @@
71 70
72/** Try to evaulate the provided expression, and do a RETINT(x) iff 71/** Try to evaulate the provided expression, and do a RETINT(x) iff
73 * the expression evaluates to < 0. 72 * the expression evaluates to < 0.
74 * @param x the expression to try
75 */ 73 */
76#define ASSERT(cond) \ 74#define ASSERT(cond) \
77 do { if (!(cond)) \ 75 do { if (!(cond)) \
@@ -89,11 +87,6 @@
89 (void *)(p2) = SWAPPOINTERS_TEMP; \ 87 (void *)(p2) = SWAPPOINTERS_TEMP; \
90 } while (0) 88 } while (0)
91 89
92/**
93 * @addtogroup driverlogging
94 * @{
95 */
96
97#define PRINTKDRV(fmt, args...) LOGINF(fmt, ## args) 90#define PRINTKDRV(fmt, args...) LOGINF(fmt, ## args)
98#define TBDDRV(fmt, args...) LOGERR(fmt, ## args) 91#define TBDDRV(fmt, args...) LOGERR(fmt, ## args)
99#define HUHDRV(fmt, args...) LOGERR(fmt, ## args) 92#define HUHDRV(fmt, args...) LOGERR(fmt, ## args)
@@ -114,8 +107,6 @@
114#define INFODEVX(devno, fmt, args...) LOGINFDEVX(devno, fmt, ## args) 107#define INFODEVX(devno, fmt, args...) LOGINFDEVX(devno, fmt, ## args)
115#define DEBUGDEV(devname, fmt, args...) DBGINFDEV(devname, fmt, ## args) 108#define DEBUGDEV(devname, fmt, args...) DBGINFDEV(devname, fmt, ## args)
116 109
117/* @} */
118
119/** Verifies the consistency of your PRIVATEDEVICEDATA structure using 110/** Verifies the consistency of your PRIVATEDEVICEDATA structure using
120 * conventional "signature" fields: 111 * conventional "signature" fields:
121 * <p> 112 * <p>
@@ -139,7 +130,7 @@
139 ((fd)->sig2 == fd)) 130 ((fd)->sig2 == fd))
140 131
141/** Sleep for an indicated number of seconds (for use in kernel mode). 132/** Sleep for an indicated number of seconds (for use in kernel mode).
142 * @param x the number of seconds to sleep. 133 * x - the number of seconds to sleep.
143 */ 134 */
144#define SLEEP(x) \ 135#define SLEEP(x) \
145 do { current->state = TASK_INTERRUPTIBLE; \ 136 do { current->state = TASK_INTERRUPTIBLE; \
@@ -147,17 +138,13 @@
147 } while (0) 138 } while (0)
148 139
149/** Sleep for an indicated number of jiffies (for use in kernel mode). 140/** Sleep for an indicated number of jiffies (for use in kernel mode).
150 * @param x the number of jiffies to sleep. 141 * x - the number of jiffies to sleep.
151 */ 142 */
152#define SLEEPJIFFIES(x) \ 143#define SLEEPJIFFIES(x) \
153 do { current->state = TASK_INTERRUPTIBLE; \ 144 do { current->state = TASK_INTERRUPTIBLE; \
154 schedule_timeout(x); \ 145 schedule_timeout(x); \
155 } while (0) 146 } while (0)
156 147
157#ifndef max
158#define max(a, b) (((a) > (b)) ? (a) : (b))
159#endif
160
161static inline struct cdev *cdev_alloc_init(struct module *owner, 148static inline struct cdev *cdev_alloc_init(struct module *owner,
162 const struct file_operations *fops) 149 const struct file_operations *fops)
163{ 150{
diff --git a/drivers/staging/unisys/include/uisqueue.h b/drivers/staging/unisys/include/uisqueue.h
index 5178270b98d1..25b6181d78af 100644
--- a/drivers/staging/unisys/include/uisqueue.h
+++ b/drivers/staging/unisys/include/uisqueue.h
@@ -34,8 +34,7 @@
34#include "controlvmcompletionstatus.h" 34#include "controlvmcompletionstatus.h"
35 35
36struct uisqueue_info { 36struct uisqueue_info {
37 37 struct channel_header __iomem *chan;
38 CHANNEL_HEADER __iomem *chan;
39 /* channel containing queues in which scsi commands & 38 /* channel containing queues in which scsi commands &
40 * responses are queued 39 * responses are queued
41 */ 40 */
@@ -48,8 +47,8 @@ struct uisqueue_info {
48 u64 non_empty_wakeup_cnt; 47 u64 non_empty_wakeup_cnt;
49 48
50 struct { 49 struct {
51 SIGNAL_QUEUE_HEADER reserved1; /* */ 50 struct signal_queue_header reserved1; /* */
52 SIGNAL_QUEUE_HEADER reserved2; /* */ 51 struct signal_queue_header reserved2; /* */
53 } safe_uis_queue; 52 } safe_uis_queue;
54 unsigned int (*send_int_if_needed)(struct uisqueue_info *info, 53 unsigned int (*send_int_if_needed)(struct uisqueue_info *info,
55 unsigned int whichcqueue, 54 unsigned int whichcqueue,
@@ -119,7 +118,7 @@ struct extport_info {
119 */ 118 */
120 119
121 struct switch_info *swtch; 120 struct switch_info *swtch;
122 struct PciId pci_id; 121 struct pci_id pci_id;
123 char name[MAX_NAME_SIZE_UISQUEUE]; 122 char name[MAX_NAME_SIZE_UISQUEUE];
124 union { 123 union {
125 struct vhba_wwnn wwnn; 124 struct vhba_wwnn wwnn;
@@ -133,7 +132,7 @@ struct device_info {
133 u64 channel_bytes; 132 u64 channel_bytes;
134 uuid_le channel_uuid; 133 uuid_le channel_uuid;
135 uuid_le instance_uuid; 134 uuid_le instance_uuid;
136 struct InterruptInfo intr; 135 struct irq_info intr;
137 struct switch_info *swtch; 136 struct switch_info *swtch;
138 char devid[30]; /* "vbus<busno>:dev<devno>" */ 137 char devid[30]; /* "vbus<busno>:dev<devno>" */
139 u16 polling; 138 u16 polling;
@@ -149,30 +148,27 @@ struct device_info {
149 unsigned long long last_on_list_cnt; 148 unsigned long long last_on_list_cnt;
150}; 149};
151 150
152typedef enum { 151enum switch_type {
153 RECOVERY_LAN = 1, 152 RECOVERY_LAN = 1,
154 IB_LAN = 2 153 IB_LAN = 2
155} SWITCH_TYPE; 154};
156 155
157struct bus_info { 156struct bus_info {
158 u32 busNo, deviceCount; 157 u32 bus_no, device_count;
159 struct device_info **device; 158 struct device_info **device;
160 u64 guestHandle, recvBusInterruptHandle; 159 u64 guest_handle, recv_bus_irq_handle;
161 uuid_le busInstGuid; 160 uuid_le bus_inst_uuid;
162 ULTRA_VBUS_CHANNEL_PROTOCOL __iomem *pBusChannel; 161 struct ultra_vbus_channel_protocol __iomem *bus_channel;
163 int busChannelBytes; 162 int bus_channel_bytes;
164 struct proc_dir_entry *proc_dir; /* proc/uislib/vbus/<x> */ 163 struct proc_dir_entry *proc_dir; /* proc/uislib/vbus/<x> */
165 struct proc_dir_entry *proc_info; /* proc/uislib/vbus/<x>/info */ 164 struct proc_dir_entry *proc_info; /* proc/uislib/vbus/<x>/info */
166 char name[25]; 165 char name[25];
167 char partitionName[99]; 166 char partition_name[99];
168 struct bus_info *next; 167 struct bus_info *next;
169 u8 localVnic; /* 1 if local vnic created internally 168 u8 local_vnic; /* 1 if local vnic created internally
170 * by IOVM; 0 otherwise... */ 169 * by IOVM; 0 otherwise... */
171}; 170};
172 171
173#define DEDICATED_SWITCH(s) ((s->extPortCount == 1) && \
174 (s->intPortCount == 1))
175
176struct sn_list_entry { 172struct sn_list_entry {
177 struct uisscsi_dest pdest; /* scsi bus, target, lun for 173 struct uisscsi_dest pdest; /* scsi bus, target, lun for
178 * phys disk */ 174 * phys disk */
@@ -183,23 +179,12 @@ struct sn_list_entry {
183 struct sn_list_entry *next; 179 struct sn_list_entry *next;
184}; 180};
185 181
186struct network_policy {
187 u32 promiscuous:1;
188 u32 macassign:1;
189 u32 peerforwarding:1;
190 u32 nonotify:1;
191 u32 standby:1;
192 u32 callhome:2;
193 char ip_addr[30];
194};
195
196/* 182/*
197 * IO messages sent to UisnicControlChanFunc & UissdControlChanFunc by 183 * IO messages sent to UisnicControlChanFunc & UissdControlChanFunc by
198 * code that processes the ControlVm channel messages. 184 * code that processes the ControlVm channel messages.
199 */ 185 */
200 186
201 187enum iopart_msg_type {
202typedef enum {
203 IOPART_ADD_VNIC, 188 IOPART_ADD_VNIC,
204 IOPART_DEL_VNIC, 189 IOPART_DEL_VNIC,
205 IOPART_DEL_ALL_VNICS, 190 IOPART_DEL_ALL_VNICS,
@@ -219,7 +204,7 @@ typedef enum {
219 IOPART_RESUME_VDISK, 204 IOPART_RESUME_VDISK,
220 IOPART_ADD_DEVICE, /* add generic device */ 205 IOPART_ADD_DEVICE, /* add generic device */
221 IOPART_DEL_DEVICE, /* del generic device */ 206 IOPART_DEL_DEVICE, /* del generic device */
222} IOPART_MSG_TYPE; 207};
223 208
224struct add_virt_iopart { 209struct add_virt_iopart {
225 void *chanptr; /* pointer to data channel */ 210 void *chanptr; /* pointer to data channel */
@@ -228,7 +213,7 @@ struct add_virt_iopart {
228 * for DMA, for ex. */ 213 * for DMA, for ex. */
229 u64 recv_bus_irq_handle; /* used to register to receive 214 u64 recv_bus_irq_handle; /* used to register to receive
230 * bus level interrupts. */ 215 * bus level interrupts. */
231 struct InterruptInfo intr; /* contains recv & send 216 struct irq_info intr; /* contains recv & send
232 * interrupt info */ 217 * interrupt info */
233 /* recvInterruptHandle is used to register to receive 218 /* recvInterruptHandle is used to register to receive
234 * interrupts on the data channel. Used by GuestLinux/Windows 219 * interrupts on the data channel. Used by GuestLinux/Windows
@@ -259,21 +244,15 @@ struct add_vdisk_iopart {
259 struct uisscsi_dest pdest; /* scsi bus, target, lun for phys disk */ 244 struct uisscsi_dest pdest; /* scsi bus, target, lun for phys disk */
260 u8 sernum[MAX_SERIAL_NUM]; /* serial num of physical disk */ 245 u8 sernum[MAX_SERIAL_NUM]; /* serial num of physical disk */
261 u32 serlen; /* length of serial num */ 246 u32 serlen; /* length of serial num */
262 u32 bus_no;
263 u32 dev_no;
264}; 247};
265 248
266struct del_vdisk_iopart { 249struct del_vdisk_iopart {
267 void *chanptr; /* pointer to data channel */ 250 void *chanptr; /* pointer to data channel */
268 struct uisscsi_dest vdest; /* scsi bus, target, lun for virt disk */ 251 struct uisscsi_dest vdest; /* scsi bus, target, lun for virt disk */
269 u32 bus_no;
270 u32 dev_no;
271}; 252};
272 253
273struct del_virt_iopart { 254struct del_virt_iopart {
274 void *chanptr; /* pointer to data channel */ 255 void *chanptr; /* pointer to data channel */
275 u32 bus_no;
276 u32 dev_no;
277}; 256};
278 257
279struct det_virt_iopart { /* detach internal port */ 258struct det_virt_iopart { /* detach internal port */
@@ -297,8 +276,7 @@ struct del_switch_iopart { /* destroy switch */
297}; 276};
298 277
299struct io_msgs { 278struct io_msgs {
300 279 enum iopart_msg_type msgtype;
301 IOPART_MSG_TYPE msgtype;
302 280
303 /* additional params needed by some messages */ 281 /* additional params needed by some messages */
304 union { 282 union {
@@ -329,7 +307,7 @@ struct io_msgs {
329* the ControlVm channel messages. 307* the ControlVm channel messages.
330*/ 308*/
331 309
332typedef enum { 310enum guestpart_msg_type {
333 GUEST_ADD_VBUS, 311 GUEST_ADD_VBUS,
334 GUEST_ADD_VHBA, 312 GUEST_ADD_VHBA,
335 GUEST_ADD_VNIC, 313 GUEST_ADD_VNIC,
@@ -344,15 +322,15 @@ typedef enum {
344 GUEST_PAUSE_VNIC, 322 GUEST_PAUSE_VNIC,
345 GUEST_RESUME_VHBA, 323 GUEST_RESUME_VHBA,
346 GUEST_RESUME_VNIC 324 GUEST_RESUME_VNIC
347} GUESTPART_MSG_TYPE; 325};
348 326
349struct add_vbus_guestpart { 327struct add_vbus_guestpart {
350 void __iomem *chanptr; /* pointer to data channel for bus - 328 void __iomem *chanptr; /* pointer to data channel for bus -
351 * NOT YET USED */ 329 * NOT YET USED */
352 u32 busNo; /* bus number to be created/deleted */ 330 u32 bus_no; /* bus number to be created/deleted */
353 u32 deviceCount; /* max num of devices on bus */ 331 u32 dev_count; /* max num of devices on bus */
354 uuid_le busTypeGuid; /* indicates type of bus */ 332 uuid_le bus_uuid; /* indicates type of bus */
355 uuid_le busInstGuid; /* instance guid for device */ 333 uuid_le instance_uuid; /* instance guid for device */
356}; 334};
357 335
358struct del_vbus_guestpart { 336struct del_vbus_guestpart {
@@ -367,7 +345,7 @@ struct add_virt_guestpart {
367 u32 bus_no; /* bus number for the operation */ 345 u32 bus_no; /* bus number for the operation */
368 u32 device_no; /* number of device on the bus */ 346 u32 device_no; /* number of device on the bus */
369 uuid_le instance_uuid; /* instance guid for device */ 347 uuid_le instance_uuid; /* instance guid for device */
370 struct InterruptInfo intr; /* recv/send interrupt info */ 348 struct irq_info intr; /* recv/send interrupt info */
371 /* recvInterruptHandle contains info needed in order to 349 /* recvInterruptHandle contains info needed in order to
372 * register to receive interrupts on the data channel. 350 * register to receive interrupts on the data channel.
373 * sendInterruptHandle contains handle which is provided to 351 * sendInterruptHandle contains handle which is provided to
@@ -394,8 +372,7 @@ struct init_chipset_guestpart {
394}; 372};
395 373
396struct guest_msgs { 374struct guest_msgs {
397 375 enum guestpart_msg_type msgtype;
398 GUESTPART_MSG_TYPE msgtype;
399 376
400 /* additional params needed by messages */ 377 /* additional params needed by messages */
401 union { 378 union {
diff --git a/drivers/staging/unisys/include/uisutils.h b/drivers/staging/unisys/include/uisutils.h
index 74e7cf65502c..7414220676d3 100644
--- a/drivers/staging/unisys/include/uisutils.h
+++ b/drivers/staging/unisys/include/uisutils.h
@@ -26,6 +26,7 @@
26#include <linux/sched.h> 26#include <linux/sched.h>
27#include <linux/gfp.h> 27#include <linux/gfp.h>
28#include <linux/uuid.h> 28#include <linux/uuid.h>
29#include <linux/if_ether.h>
29 30
30#include "vmcallinterface.h" 31#include "vmcallinterface.h"
31#include "channel.h" 32#include "channel.h"
@@ -43,39 +44,38 @@
43/* global function pointers that act as callback functions into 44/* global function pointers that act as callback functions into
44 * uisnicmod, uissdmod, and virtpcimod 45 * uisnicmod, uissdmod, and virtpcimod
45 */ 46 */
46extern int (*UisnicControlChanFunc)(struct io_msgs *); 47extern int (*uisnic_control_chan_func)(struct io_msgs *);
47extern int (*UissdControlChanFunc)(struct io_msgs *); 48extern int (*uissd_control_chan_func)(struct io_msgs *);
48extern int (*VirtControlChanFunc)(struct guest_msgs *); 49extern int (*virt_control_chan_func)(struct guest_msgs *);
49 50
50/* Return values of above callback functions: */ 51/* Return values of above callback functions: */
51#define CCF_ERROR 0 /* completed and failed */ 52#define CCF_ERROR 0 /* completed and failed */
52#define CCF_OK 1 /* completed successfully */ 53#define CCF_OK 1 /* completed successfully */
53#define CCF_PENDING 2 /* operation still pending */ 54#define CCF_PENDING 2 /* operation still pending */
54extern atomic_t UisUtils_Registered_Services; 55extern atomic_t uisutils_registered_services;
55 56
56typedef unsigned int MACARRAY[MAX_MACADDR_LEN]; 57struct req_handler_info {
57typedef struct ReqHandlerInfo_struct { 58 uuid_le switch_uuid;
58 uuid_le switchTypeGuid;
59 int (*controlfunc)(struct io_msgs *); 59 int (*controlfunc)(struct io_msgs *);
60 unsigned long min_channel_bytes; 60 unsigned long min_channel_bytes;
61 int (*Server_Channel_Ok)(unsigned long channelBytes); 61 int (*server_channel_ok)(unsigned long channel_bytes);
62 int (*Server_Channel_Init) 62 int (*server_channel_init)(void *x, unsigned char *client_str,
63 (void *x, unsigned char *clientStr, u32 clientStrLen, u64 bytes); 63 u32 client_str_len, u64 bytes);
64 char switch_type_name[99]; 64 char switch_type_name[99];
65 struct list_head list_link; /* links into ReqHandlerInfo_list */ 65 struct list_head list_link; /* links into ReqHandlerInfo_list */
66} ReqHandlerInfo_t; 66};
67 67
68ReqHandlerInfo_t *ReqHandlerAdd(uuid_le switchTypeGuid, 68struct req_handler_info *req_handler_add(uuid_le switch_uuid,
69 const char *switch_type_name, 69 const char *switch_type_name,
70 int (*controlfunc)(struct io_msgs *), 70 int (*controlfunc)(struct io_msgs *),
71 unsigned long min_channel_bytes, 71 unsigned long min_channel_bytes,
72 int (*Server_Channel_Ok)(unsigned long 72 int (*svr_channel_ok)(unsigned long
73 channelBytes), 73 channel_bytes),
74 int (*Server_Channel_Init) 74 int (*svr_channel_init)(void *x,
75 (void *x, unsigned char *clientStr, 75 unsigned char *client_str,
76 u32 clientStrLen, u64 bytes)); 76 u32 client_str_len, u64 bytes));
77ReqHandlerInfo_t *ReqHandlerFind(uuid_le switchTypeGuid); 77struct req_handler_info *req_handler_find(uuid_le switch_uuid);
78int ReqHandlerDel(uuid_le switchTypeGuid); 78int req_handler_del(uuid_le switch_uuid);
79 79
80#define uislib_ioremap_cache(addr, size) \ 80#define uislib_ioremap_cache(addr, size) \
81 dbg_ioremap_cache(addr, size, __FILE__, __LINE__) 81 dbg_ioremap_cache(addr, size, __FILE__, __LINE__)
@@ -114,52 +114,49 @@ int uisutil_add_proc_line_ex(int *total, char **buffer, int *buffer_remaining,
114 char *format, ...); 114 char *format, ...);
115 115
116int uisctrl_register_req_handler(int type, void *fptr, 116int uisctrl_register_req_handler(int type, void *fptr,
117 ULTRA_VBUS_DEVICEINFO *chipset_driver_info); 117 struct ultra_vbus_deviceinfo *chipset_driver_info);
118int uisctrl_register_req_handler_ex(uuid_le switchTypeGuid, 118int uisctrl_register_req_handler_ex(uuid_le switch_guid,
119 const char *switch_type_name, 119 const char *switch_type_name,
120 int (*fptr)(struct io_msgs *), 120 int (*fptr)(struct io_msgs *),
121 unsigned long min_channel_bytes, 121 unsigned long min_channel_bytes,
122 int (*Server_Channel_Ok)(unsigned long 122 int (*svr_channel_ok)(unsigned long
123 channelBytes), 123 channel_bytes),
124 int (*Server_Channel_Init) 124 int (*svr_channel_init)(void *x,
125 (void *x, unsigned char *clientStr, 125 unsigned char *client_str,
126 u32 clientStrLen, u64 bytes), 126 u32 client_str_len,
127 ULTRA_VBUS_DEVICEINFO *chipset_DriverInfo); 127 u64 bytes),
128 128 struct ultra_vbus_deviceinfo *chipset_driver_info);
129int uisctrl_unregister_req_handler_ex(uuid_le switchTypeGuid); 129
130int uisctrl_unregister_req_handler_ex(uuid_le switch_uuid);
130unsigned char *util_map_virt(struct phys_info *sg); 131unsigned char *util_map_virt(struct phys_info *sg);
131void util_unmap_virt(struct phys_info *sg); 132void util_unmap_virt(struct phys_info *sg);
132unsigned char *util_map_virt_atomic(struct phys_info *sg); 133unsigned char *util_map_virt_atomic(struct phys_info *sg);
133void util_unmap_virt_atomic(void *buf); 134void util_unmap_virt_atomic(void *buf);
134int uislib_server_inject_add_vnic(u32 switchNo, u32 BusNo, u32 numIntPorts, 135int uislib_client_inject_add_bus(u32 bus_no, uuid_le inst_uuid,
135 u32 numExtPorts, MACARRAY pmac[], 136 u64 channel_addr, ulong n_channel_bytes);
136 pCHANNEL_HEADER **chan); 137int uislib_client_inject_del_bus(u32 bus_no);
137void uislib_server_inject_del_vnic(u32 switchNo, u32 busNo, u32 numIntPorts, 138
138 u32 numExtPorts); 139int uislib_client_inject_add_vhba(u32 bus_no, u32 dev_no,
139int uislib_client_inject_add_bus(u32 busNo, uuid_le instGuid,
140 u64 channelAddr, ulong nChannelBytes);
141int uislib_client_inject_del_bus(u32 busNo);
142
143int uislib_client_inject_add_vhba(u32 busNo, u32 devNo,
144 u64 phys_chan_addr, u32 chan_bytes, 140 u64 phys_chan_addr, u32 chan_bytes,
145 int is_test_addr, uuid_le instGuid, 141 int is_test_addr, uuid_le inst_uuid,
146 struct InterruptInfo *intr); 142 struct irq_info *intr);
147int uislib_client_inject_pause_vhba(u32 busNo, u32 devNo); 143int uislib_client_inject_pause_vhba(u32 bus_no, u32 dev_no);
148int uislib_client_inject_resume_vhba(u32 busNo, u32 devNo); 144int uislib_client_inject_resume_vhba(u32 bus_no, u32 dev_no);
149int uislib_client_inject_del_vhba(u32 busNo, u32 devNo); 145int uislib_client_inject_del_vhba(u32 bus_no, u32 dev_no);
150int uislib_client_inject_add_vnic(u32 busNo, u32 devNo, 146int uislib_client_inject_add_vnic(u32 bus_no, u32 dev_no,
151 u64 phys_chan_addr, u32 chan_bytes, 147 u64 phys_chan_addr, u32 chan_bytes,
152 int is_test_addr, uuid_le instGuid, 148 int is_test_addr, uuid_le inst_uuid,
153 struct InterruptInfo *intr); 149 struct irq_info *intr);
154int uislib_client_inject_pause_vnic(u32 busNo, u32 devNo); 150int uislib_client_inject_pause_vnic(u32 bus_no, u32 dev_no);
155int uislib_client_inject_resume_vnic(u32 busNo, u32 devNo); 151int uislib_client_inject_resume_vnic(u32 bus_no, u32 dev_no);
156int uislib_client_inject_del_vnic(u32 busNo, u32 devNo); 152int uislib_client_inject_del_vnic(u32 bus_no, u32 dev_no);
157#ifdef STORAGE_CHANNEL 153#ifdef STORAGE_CHANNEL
158u64 uislib_storage_channel(int client_id); 154u64 uislib_storage_channel(int client_id);
159#endif 155#endif
160int uislib_get_owned_pdest(struct uisscsi_dest *pdest); 156int uislib_get_owned_pdest(struct uisscsi_dest *pdest);
161 157
162int uislib_send_event(CONTROLVM_ID id, CONTROLVM_MESSAGE_PACKET *event); 158int uislib_send_event(enum controlvm_id id,
159 struct controlvm_message_packet *event);
163 160
164/* structure used by vhba & vnic to keep track of queue & thread info */ 161/* structure used by vhba & vnic to keep track of queue & thread info */
165struct chaninfo { 162struct chaninfo {
@@ -182,11 +179,14 @@ struct chaninfo {
182 set_current_state(TASK_INTERRUPTIBLE); \ 179 set_current_state(TASK_INTERRUPTIBLE); \
183 schedule_timeout(msecs_to_jiffies(x)); \ 180 schedule_timeout(msecs_to_jiffies(x)); \
184} 181}
182
185#define UIS_THREAD_WAIT_USEC(x) { \ 183#define UIS_THREAD_WAIT_USEC(x) { \
186 set_current_state(TASK_INTERRUPTIBLE); \ 184 set_current_state(TASK_INTERRUPTIBLE); \
187 schedule_timeout(usecs_to_jiffies(x)); \ 185 schedule_timeout(usecs_to_jiffies(x)); \
188} 186}
187
189#define UIS_THREAD_WAIT UIS_THREAD_WAIT_MSEC(5) 188#define UIS_THREAD_WAIT UIS_THREAD_WAIT_MSEC(5)
189
190#define UIS_THREAD_WAIT_SEC(x) { \ 190#define UIS_THREAD_WAIT_SEC(x) { \
191 set_current_state(TASK_INTERRUPTIBLE); \ 191 set_current_state(TASK_INTERRUPTIBLE); \
192 schedule_timeout((x)*HZ); \ 192 schedule_timeout((x)*HZ); \
@@ -224,42 +224,42 @@ unsigned int uisutil_copy_fragsinfo_from_skb(unsigned char *calling_ctx,
224static inline unsigned int 224static inline unsigned int
225issue_vmcall_io_controlvm_addr(u64 *control_addr, u32 *control_bytes) 225issue_vmcall_io_controlvm_addr(u64 *control_addr, u32 *control_bytes)
226{ 226{
227 VMCALL_IO_CONTROLVM_ADDR_PARAMS params; 227 struct vmcall_io_controlvm_addr_params params;
228 int result = VMCALL_SUCCESS; 228 int result = VMCALL_SUCCESS;
229 u64 physaddr; 229 u64 physaddr;
230 230
231 physaddr = virt_to_phys(&params); 231 physaddr = virt_to_phys(&params);
232 ISSUE_IO_VMCALL(VMCALL_IO_CONTROLVM_ADDR, physaddr, result); 232 ISSUE_IO_VMCALL(VMCALL_IO_CONTROLVM_ADDR, physaddr, result);
233 if (VMCALL_SUCCESSFUL(result)) { 233 if (VMCALL_SUCCESSFUL(result)) {
234 *control_addr = params.ChannelAddress; 234 *control_addr = params.address;
235 *control_bytes = params.ChannelBytes; 235 *control_bytes = params.channel_bytes;
236 } 236 }
237 return result; 237 return result;
238} 238}
239 239
240static inline unsigned int issue_vmcall_io_diag_addr(u64 *diag_channel_addr) 240static inline unsigned int issue_vmcall_io_diag_addr(u64 *diag_channel_addr)
241{ 241{
242 VMCALL_IO_DIAG_ADDR_PARAMS params; 242 struct vmcall_io_diag_addr_params params;
243 int result = VMCALL_SUCCESS; 243 int result = VMCALL_SUCCESS;
244 u64 physaddr; 244 u64 physaddr;
245 245
246 physaddr = virt_to_phys(&params); 246 physaddr = virt_to_phys(&params);
247 ISSUE_IO_VMCALL(VMCALL_IO_DIAG_ADDR, physaddr, result); 247 ISSUE_IO_VMCALL(VMCALL_IO_DIAG_ADDR, physaddr, result);
248 if (VMCALL_SUCCESSFUL(result)) 248 if (VMCALL_SUCCESSFUL(result))
249 *diag_channel_addr = params.ChannelAddress; 249 *diag_channel_addr = params.address;
250 return result; 250 return result;
251} 251}
252 252
253static inline unsigned int issue_vmcall_io_visorserial_addr(u64 *channel_addr) 253static inline unsigned int issue_vmcall_io_visorserial_addr(u64 *channel_addr)
254{ 254{
255 VMCALL_IO_VISORSERIAL_ADDR_PARAMS params; 255 struct vmcall_io_visorserial_addr_params params;
256 int result = VMCALL_SUCCESS; 256 int result = VMCALL_SUCCESS;
257 u64 physaddr; 257 u64 physaddr;
258 258
259 physaddr = virt_to_phys(&params); 259 physaddr = virt_to_phys(&params);
260 ISSUE_IO_VMCALL(VMCALL_IO_VISORSERIAL_ADDR, physaddr, result); 260 ISSUE_IO_VMCALL(VMCALL_IO_VISORSERIAL_ADDR, physaddr, result);
261 if (VMCALL_SUCCESSFUL(result)) 261 if (VMCALL_SUCCESSFUL(result))
262 *channel_addr = params.ChannelAddress; 262 *channel_addr = params.address;
263 return result; 263 return result;
264} 264}
265 265
@@ -273,17 +273,8 @@ static inline s64 issue_vmcall_query_guest_virtual_time_offset(void)
273 return result; 273 return result;
274} 274}
275 275
276static inline s64 issue_vmcall_measurement_do_nothing(void)
277{
278 u64 result = VMCALL_SUCCESS;
279 u64 physaddr = 0;
280
281 ISSUE_IO_VMCALL(VMCALL_MEASUREMENT_DO_NOTHING, physaddr, result);
282 return result;
283}
284
285struct log_info_t { 276struct log_info_t {
286 volatile unsigned long long last_cycles; 277 unsigned long long last_cycles;
287 unsigned long long delta_sum[64]; 278 unsigned long long delta_sum[64];
288 unsigned long long delta_cnt[64]; 279 unsigned long long delta_cnt[64];
289 unsigned long long max_delta[64]; 280 unsigned long long max_delta[64];
@@ -302,44 +293,29 @@ static inline unsigned int issue_vmcall_channel_mismatch(const char *chname,
302 const char *item_name, u32 line_no, 293 const char *item_name, u32 line_no,
303 const char *path_n_fn) 294 const char *path_n_fn)
304{ 295{
305 VMCALL_CHANNEL_VERSION_MISMATCH_PARAMS params; 296 struct vmcall_channel_version_mismatch_params params;
306 int result = VMCALL_SUCCESS; 297 int result = VMCALL_SUCCESS;
307 u64 physaddr; 298 u64 physaddr;
308 char *last_slash = NULL; 299 char *last_slash = NULL;
309 300
310 strlcpy(params.ChannelName, chname, 301 strlcpy(params.chname, chname, sizeof(params.chname));
311 lengthof(VMCALL_CHANNEL_VERSION_MISMATCH_PARAMS, ChannelName)); 302 strlcpy(params.item_name, item_name, sizeof(params.item_name));
312 strlcpy(params.ItemName, item_name, 303 params.line_no = line_no;
313 lengthof(VMCALL_CHANNEL_VERSION_MISMATCH_PARAMS, ItemName));
314 params.SourceLineNumber = line_no;
315 304
316 last_slash = strrchr(path_n_fn, '/'); 305 last_slash = strrchr(path_n_fn, '/');
317 if (last_slash != NULL) { 306 if (last_slash != NULL) {
318 last_slash++; 307 last_slash++;
319 strlcpy(params.SourceFileName, last_slash, 308 strlcpy(params.file_name, last_slash, sizeof(params.file_name));
320 lengthof(VMCALL_CHANNEL_VERSION_MISMATCH_PARAMS,
321 SourceFileName));
322 } else 309 } else
323 strlcpy(params.SourceFileName, 310 strlcpy(params.file_name,
324 "Cannot determine source filename", 311 "Cannot determine source filename",
325 lengthof(VMCALL_CHANNEL_VERSION_MISMATCH_PARAMS, 312 sizeof(params.file_name));
326 SourceFileName));
327 313
328 physaddr = virt_to_phys(&params); 314 physaddr = virt_to_phys(&params);
329 ISSUE_IO_VMCALL(VMCALL_CHANNEL_VERSION_MISMATCH, physaddr, result); 315 ISSUE_IO_VMCALL(VMCALL_CHANNEL_VERSION_MISMATCH, physaddr, result);
330 return result; 316 return result;
331} 317}
332 318
333static inline unsigned int issue_vmcall_fatal(void)
334{
335 int result = VMCALL_SUCCESS;
336 u64 physaddr = 0;
337
338 ISSUE_IO_VMCALL(VMCALL_GENERIC_SURRENDER_QUANTUM_FOREVER, physaddr,
339 result);
340 return result;
341}
342
343#define UIS_DAEMONIZE(nam) 319#define UIS_DAEMONIZE(nam)
344void *uislib_cache_alloc(struct kmem_cache *cur_pool, char *fn, int ln); 320void *uislib_cache_alloc(struct kmem_cache *cur_pool, char *fn, int ln);
345#define UISCACHEALLOC(cur_pool) uislib_cache_alloc(cur_pool, __FILE__, __LINE__) 321#define UISCACHEALLOC(cur_pool) uislib_cache_alloc(cur_pool, __FILE__, __LINE__)
diff --git a/drivers/staging/unisys/include/vbushelper.h b/drivers/staging/unisys/include/vbushelper.h
index 1bde549ec0df..84abe5f99f54 100644
--- a/drivers/staging/unisys/include/vbushelper.h
+++ b/drivers/staging/unisys/include/vbushelper.h
@@ -26,19 +26,19 @@
26#define TARGET_HOSTNAME "linuxguest" 26#define TARGET_HOSTNAME "linuxguest"
27 27
28static inline void bus_device_info_init( 28static inline void bus_device_info_init(
29 ULTRA_VBUS_DEVICEINFO * bus_device_info_ptr, 29 struct ultra_vbus_deviceinfo *bus_device_info_ptr,
30 const char *dev_type, const char *drv_name, 30 const char *dev_type, const char *drv_name,
31 const char *ver, const char *ver_tag) 31 const char *ver, const char *ver_tag)
32{ 32{
33 memset(bus_device_info_ptr, 0, sizeof(ULTRA_VBUS_DEVICEINFO)); 33 memset(bus_device_info_ptr, 0, sizeof(struct ultra_vbus_deviceinfo));
34 snprintf(bus_device_info_ptr->devType, 34 snprintf(bus_device_info_ptr->devtype,
35 sizeof(bus_device_info_ptr->devType), 35 sizeof(bus_device_info_ptr->devtype),
36 "%s", (dev_type) ? dev_type : "unknownType"); 36 "%s", (dev_type) ? dev_type : "unknownType");
37 snprintf(bus_device_info_ptr->drvName, 37 snprintf(bus_device_info_ptr->drvname,
38 sizeof(bus_device_info_ptr->drvName), 38 sizeof(bus_device_info_ptr->drvname),
39 "%s", (drv_name) ? drv_name : "unknownDriver"); 39 "%s", (drv_name) ? drv_name : "unknownDriver");
40 snprintf(bus_device_info_ptr->infoStrings, 40 snprintf(bus_device_info_ptr->infostrs,
41 sizeof(bus_device_info_ptr->infoStrings), "%s\t%s\t%s", 41 sizeof(bus_device_info_ptr->infostrs), "%s\t%s\t%s",
42 (ver) ? ver : "unknownVer", 42 (ver) ? ver : "unknownVer",
43 (ver_tag) ? ver_tag : "unknownVerTag", 43 (ver_tag) ? ver_tag : "unknownVerTag",
44 TARGET_HOSTNAME); 44 TARGET_HOSTNAME);
diff --git a/drivers/staging/unisys/uislib/uislib.c b/drivers/staging/unisys/uislib/uislib.c
index 706f1c0c2c6e..7c87452a9f14 100644
--- a/drivers/staging/unisys/uislib/uislib.c
+++ b/drivers/staging/unisys/uislib/uislib.c
@@ -57,7 +57,7 @@
57#define __MYFILE__ "uislib.c" 57#define __MYFILE__ "uislib.c"
58 58
59/* global function pointers that act as callback functions into virtpcimod */ 59/* global function pointers that act as callback functions into virtpcimod */
60int (*VirtControlChanFunc)(struct guest_msgs *); 60int (*virt_control_chan_func)(struct guest_msgs *);
61 61
62static int ProcReadBufferValid; 62static int ProcReadBufferValid;
63static char *ProcReadBuffer; /* Note this MUST be global, 63static char *ProcReadBuffer; /* Note this MUST be global,
@@ -121,12 +121,12 @@ static const struct file_operations debugfs_info_fops = {
121}; 121};
122 122
123static void 123static void
124init_msg_header(CONTROLVM_MESSAGE *msg, u32 id, uint rsp, uint svr) 124init_msg_header(struct controlvm_message *msg, u32 id, uint rsp, uint svr)
125{ 125{
126 memset(msg, 0, sizeof(CONTROLVM_MESSAGE)); 126 memset(msg, 0, sizeof(struct controlvm_message));
127 msg->hdr.Id = id; 127 msg->hdr.id = id;
128 msg->hdr.Flags.responseExpected = rsp; 128 msg->hdr.flags.response_expected = rsp;
129 msg->hdr.Flags.server = svr; 129 msg->hdr.flags.server = svr;
130} 130}
131 131
132static __iomem void * 132static __iomem void *
@@ -142,7 +142,7 @@ init_vbus_channel(u64 channelAddr, u32 channelBytes)
142 rc = NULL; 142 rc = NULL;
143 goto Away; 143 goto Away;
144 } 144 }
145 if (!ULTRA_VBUS_CHANNEL_OK_CLIENT(pChan, NULL)) { 145 if (!SPAR_VBUS_CHANNEL_OK_CLIENT(pChan)) {
146 ERRDRV("%s channel cannot be used", __func__); 146 ERRDRV("%s channel cannot be used", __func__);
147 uislib_iounmap(pChan); 147 uislib_iounmap(pChan);
148 rc = NULL; 148 rc = NULL;
@@ -154,7 +154,7 @@ Away:
154} 154}
155 155
156static int 156static int
157create_bus(CONTROLVM_MESSAGE *msg, char *buf) 157create_bus(struct controlvm_message *msg, char *buf)
158{ 158{
159 u32 busNo, deviceCount; 159 u32 busNo, deviceCount;
160 struct bus_info *tmp, *bus; 160 struct bus_info *tmp, *bus;
@@ -168,8 +168,8 @@ create_bus(CONTROLVM_MESSAGE *msg, char *buf)
168 return CONTROLVM_RESP_ERROR_MAX_BUSES; 168 return CONTROLVM_RESP_ERROR_MAX_BUSES;
169 } 169 }
170 170
171 busNo = msg->cmd.createBus.busNo; 171 busNo = msg->cmd.create_bus.bus_no;
172 deviceCount = msg->cmd.createBus.deviceCount; 172 deviceCount = msg->cmd.create_bus.dev_count;
173 173
174 POSTCODE_LINUX_4(BUS_CREATE_ENTRY_PC, busNo, deviceCount, 174 POSTCODE_LINUX_4(BUS_CREATE_ENTRY_PC, busNo, deviceCount,
175 POSTCODE_SEVERITY_INFO); 175 POSTCODE_SEVERITY_INFO);
@@ -188,25 +188,25 @@ create_bus(CONTROLVM_MESSAGE *msg, char *buf)
188 /* Currently by default, the bus Number is the GuestHandle. 188 /* Currently by default, the bus Number is the GuestHandle.
189 * Configure Bus message can override this. 189 * Configure Bus message can override this.
190 */ 190 */
191 if (msg->hdr.Flags.testMessage) { 191 if (msg->hdr.flags.test_message) {
192 /* This implies we're the IOVM so set guest handle to 0... */ 192 /* This implies we're the IOVM so set guest handle to 0... */
193 bus->guestHandle = 0; 193 bus->guest_handle = 0;
194 bus->busNo = busNo; 194 bus->bus_no = busNo;
195 bus->localVnic = 1; 195 bus->local_vnic = 1;
196 } else 196 } else
197 bus->busNo = bus->guestHandle = busNo; 197 bus->bus_no = bus->guest_handle = busNo;
198 sprintf(bus->name, "%d", (int) bus->busNo); 198 sprintf(bus->name, "%d", (int) bus->bus_no);
199 bus->deviceCount = deviceCount; 199 bus->device_count = deviceCount;
200 bus->device = 200 bus->device =
201 (struct device_info **) ((char *) bus + sizeof(struct bus_info)); 201 (struct device_info **) ((char *) bus + sizeof(struct bus_info));
202 bus->busInstGuid = msg->cmd.createBus.busInstGuid; 202 bus->bus_inst_uuid = msg->cmd.create_bus.bus_inst_uuid;
203 bus->busChannelBytes = 0; 203 bus->bus_channel_bytes = 0;
204 bus->pBusChannel = NULL; 204 bus->bus_channel = NULL;
205 205
206 /* add bus to our bus list - but check for duplicates first */ 206 /* add bus to our bus list - but check for duplicates first */
207 read_lock(&BusListLock); 207 read_lock(&BusListLock);
208 for (tmp = BusListHead; tmp; tmp = tmp->next) { 208 for (tmp = BusListHead; tmp; tmp = tmp->next) {
209 if (tmp->busNo == bus->busNo) 209 if (tmp->bus_no == bus->bus_no)
210 break; 210 break;
211 } 211 }
212 read_unlock(&BusListLock); 212 read_unlock(&BusListLock);
@@ -215,39 +215,39 @@ create_bus(CONTROLVM_MESSAGE *msg, char *buf)
215 * reject add 215 * reject add
216 */ 216 */
217 LOGERR("CONTROLVM_BUS_CREATE Failed: bus %d already exists.\n", 217 LOGERR("CONTROLVM_BUS_CREATE Failed: bus %d already exists.\n",
218 bus->busNo); 218 bus->bus_no);
219 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, bus->busNo, 219 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, bus->bus_no,
220 POSTCODE_SEVERITY_ERR); 220 POSTCODE_SEVERITY_ERR);
221 kfree(bus); 221 kfree(bus);
222 return CONTROLVM_RESP_ERROR_ALREADY_DONE; 222 return CONTROLVM_RESP_ERROR_ALREADY_DONE;
223 } 223 }
224 if ((msg->cmd.createBus.channelAddr != 0) 224 if ((msg->cmd.create_bus.channel_addr != 0)
225 && (msg->cmd.createBus.channelBytes != 0)) { 225 && (msg->cmd.create_bus.channel_bytes != 0)) {
226 bus->busChannelBytes = msg->cmd.createBus.channelBytes; 226 bus->bus_channel_bytes = msg->cmd.create_bus.channel_bytes;
227 bus->pBusChannel = 227 bus->bus_channel =
228 init_vbus_channel(msg->cmd.createBus.channelAddr, 228 init_vbus_channel(msg->cmd.create_bus.channel_addr,
229 msg->cmd.createBus.channelBytes); 229 msg->cmd.create_bus.channel_bytes);
230 } 230 }
231 /* the msg is bound for virtpci; send guest_msgs struct to callback */ 231 /* the msg is bound for virtpci; send guest_msgs struct to callback */
232 if (!msg->hdr.Flags.server) { 232 if (!msg->hdr.flags.server) {
233 struct guest_msgs cmd; 233 struct guest_msgs cmd;
234 234
235 cmd.msgtype = GUEST_ADD_VBUS; 235 cmd.msgtype = GUEST_ADD_VBUS;
236 cmd.add_vbus.busNo = busNo; 236 cmd.add_vbus.bus_no = busNo;
237 cmd.add_vbus.chanptr = bus->pBusChannel; 237 cmd.add_vbus.chanptr = bus->bus_channel;
238 cmd.add_vbus.deviceCount = deviceCount; 238 cmd.add_vbus.dev_count = deviceCount;
239 cmd.add_vbus.busTypeGuid = msg->cmd.createBus.busDataTypeGuid; 239 cmd.add_vbus.bus_uuid = msg->cmd.create_bus.bus_data_type_uuid;
240 cmd.add_vbus.busInstGuid = msg->cmd.createBus.busInstGuid; 240 cmd.add_vbus.instance_uuid = msg->cmd.create_bus.bus_inst_uuid;
241 if (!VirtControlChanFunc) { 241 if (!virt_control_chan_func) {
242 LOGERR("CONTROLVM_BUS_CREATE Failed: virtpci callback not registered."); 242 LOGERR("CONTROLVM_BUS_CREATE Failed: virtpci callback not registered.");
243 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, bus->busNo, 243 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, bus->bus_no,
244 POSTCODE_SEVERITY_ERR); 244 POSTCODE_SEVERITY_ERR);
245 kfree(bus); 245 kfree(bus);
246 return CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_FAILURE; 246 return CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_FAILURE;
247 } 247 }
248 if (!VirtControlChanFunc(&cmd)) { 248 if (!virt_control_chan_func(&cmd)) {
249 LOGERR("CONTROLVM_BUS_CREATE Failed: virtpci GUEST_ADD_VBUS returned error."); 249 LOGERR("CONTROLVM_BUS_CREATE Failed: virtpci GUEST_ADD_VBUS returned error.");
250 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, bus->busNo, 250 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, bus->bus_no,
251 POSTCODE_SEVERITY_ERR); 251 POSTCODE_SEVERITY_ERR);
252 kfree(bus); 252 kfree(bus);
253 return 253 return
@@ -266,26 +266,26 @@ create_bus(CONTROLVM_MESSAGE *msg, char *buf)
266 BusListCount++; 266 BusListCount++;
267 write_unlock(&BusListLock); 267 write_unlock(&BusListLock);
268 268
269 POSTCODE_LINUX_3(BUS_CREATE_EXIT_PC, bus->busNo, 269 POSTCODE_LINUX_3(BUS_CREATE_EXIT_PC, bus->bus_no,
270 POSTCODE_SEVERITY_INFO); 270 POSTCODE_SEVERITY_INFO);
271 return CONTROLVM_RESP_SUCCESS; 271 return CONTROLVM_RESP_SUCCESS;
272} 272}
273 273
274static int 274static int
275destroy_bus(CONTROLVM_MESSAGE *msg, char *buf) 275destroy_bus(struct controlvm_message *msg, char *buf)
276{ 276{
277 int i; 277 int i;
278 struct bus_info *bus, *prev = NULL; 278 struct bus_info *bus, *prev = NULL;
279 struct guest_msgs cmd; 279 struct guest_msgs cmd;
280 u32 busNo; 280 u32 busNo;
281 281
282 busNo = msg->cmd.destroyBus.busNo; 282 busNo = msg->cmd.destroy_bus.bus_no;
283 283
284 read_lock(&BusListLock); 284 read_lock(&BusListLock);
285 285
286 bus = BusListHead; 286 bus = BusListHead;
287 while (bus) { 287 while (bus) {
288 if (bus->busNo == busNo) 288 if (bus->bus_no == busNo)
289 break; 289 break;
290 prev = bus; 290 prev = bus;
291 bus = bus->next; 291 bus = bus->next;
@@ -299,7 +299,7 @@ destroy_bus(CONTROLVM_MESSAGE *msg, char *buf)
299 } 299 }
300 300
301 /* verify that this bus has no devices. */ 301 /* verify that this bus has no devices. */
302 for (i = 0; i < bus->deviceCount; i++) { 302 for (i = 0; i < bus->device_count; i++) {
303 if (bus->device[i] != NULL) { 303 if (bus->device[i] != NULL) {
304 LOGERR("CONTROLVM_BUS_DESTROY Failed: device %i attached to bus %d.", 304 LOGERR("CONTROLVM_BUS_DESTROY Failed: device %i attached to bus %d.",
305 i, busNo); 305 i, busNo);
@@ -309,18 +309,18 @@ destroy_bus(CONTROLVM_MESSAGE *msg, char *buf)
309 } 309 }
310 read_unlock(&BusListLock); 310 read_unlock(&BusListLock);
311 311
312 if (msg->hdr.Flags.server) 312 if (msg->hdr.flags.server)
313 goto remove; 313 goto remove;
314 314
315 /* client messages require us to call the virtpci callback associated 315 /* client messages require us to call the virtpci callback associated
316 with this bus. */ 316 with this bus. */
317 cmd.msgtype = GUEST_DEL_VBUS; 317 cmd.msgtype = GUEST_DEL_VBUS;
318 cmd.del_vbus.bus_no = busNo; 318 cmd.del_vbus.bus_no = busNo;
319 if (!VirtControlChanFunc) { 319 if (!virt_control_chan_func) {
320 LOGERR("CONTROLVM_BUS_DESTROY Failed: virtpci callback not registered."); 320 LOGERR("CONTROLVM_BUS_DESTROY Failed: virtpci callback not registered.");
321 return CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_FAILURE; 321 return CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_FAILURE;
322 } 322 }
323 if (!VirtControlChanFunc(&cmd)) { 323 if (!virt_control_chan_func(&cmd)) {
324 LOGERR("CONTROLVM_BUS_DESTROY Failed: virtpci GUEST_DEL_VBUS returned error."); 324 LOGERR("CONTROLVM_BUS_DESTROY Failed: virtpci GUEST_DEL_VBUS returned error.");
325 return CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_CALLBACK_ERROR; 325 return CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_CALLBACK_ERROR;
326 } 326 }
@@ -335,9 +335,9 @@ remove:
335 BusListCount--; 335 BusListCount--;
336 write_unlock(&BusListLock); 336 write_unlock(&BusListLock);
337 337
338 if (bus->pBusChannel) { 338 if (bus->bus_channel) {
339 uislib_iounmap(bus->pBusChannel); 339 uislib_iounmap(bus->bus_channel);
340 bus->pBusChannel = NULL; 340 bus->bus_channel = NULL;
341 } 341 }
342 342
343 kfree(bus); 343 kfree(bus);
@@ -345,17 +345,17 @@ remove:
345} 345}
346 346
347static int 347static int
348create_device(CONTROLVM_MESSAGE *msg, char *buf) 348create_device(struct controlvm_message *msg, char *buf)
349{ 349{
350 struct device_info *dev; 350 struct device_info *dev;
351 struct bus_info *bus; 351 struct bus_info *bus;
352 u32 busNo, devNo; 352 u32 busNo, devNo;
353 int result = CONTROLVM_RESP_SUCCESS; 353 int result = CONTROLVM_RESP_SUCCESS;
354 u64 minSize = MIN_IO_CHANNEL_SIZE; 354 u64 minSize = MIN_IO_CHANNEL_SIZE;
355 ReqHandlerInfo_t *pReqHandler; 355 struct req_handler_info *pReqHandler;
356 356
357 busNo = msg->cmd.createDevice.busNo; 357 busNo = msg->cmd.create_device.bus_no;
358 devNo = msg->cmd.createDevice.devNo; 358 devNo = msg->cmd.create_device.dev_no;
359 359
360 POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC, devNo, busNo, 360 POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC, devNo, busNo,
361 POSTCODE_SEVERITY_INFO); 361 POSTCODE_SEVERITY_INFO);
@@ -368,26 +368,26 @@ create_device(CONTROLVM_MESSAGE *msg, char *buf)
368 return CONTROLVM_RESP_ERROR_KMALLOC_FAILED; 368 return CONTROLVM_RESP_ERROR_KMALLOC_FAILED;
369 } 369 }
370 370
371 dev->channel_uuid = msg->cmd.createDevice.dataTypeGuid; 371 dev->channel_uuid = msg->cmd.create_device.data_type_uuid;
372 dev->intr = msg->cmd.createDevice.intr; 372 dev->intr = msg->cmd.create_device.intr;
373 dev->channel_addr = msg->cmd.createDevice.channelAddr; 373 dev->channel_addr = msg->cmd.create_device.channel_addr;
374 dev->bus_no = busNo; 374 dev->bus_no = busNo;
375 dev->dev_no = devNo; 375 dev->dev_no = devNo;
376 sema_init(&dev->interrupt_callback_lock, 1); /* unlocked */ 376 sema_init(&dev->interrupt_callback_lock, 1); /* unlocked */
377 sprintf(dev->devid, "vbus%u:dev%u", (unsigned) busNo, (unsigned) devNo); 377 sprintf(dev->devid, "vbus%u:dev%u", (unsigned) busNo, (unsigned) devNo);
378 /* map the channel memory for the device. */ 378 /* map the channel memory for the device. */
379 if (msg->hdr.Flags.testMessage) 379 if (msg->hdr.flags.test_message)
380 dev->chanptr = (void __iomem *)__va(dev->channel_addr); 380 dev->chanptr = (void __iomem *)__va(dev->channel_addr);
381 else { 381 else {
382 pReqHandler = ReqHandlerFind(dev->channel_uuid); 382 pReqHandler = req_handler_find(dev->channel_uuid);
383 if (pReqHandler) 383 if (pReqHandler)
384 /* generic service handler registered for this 384 /* generic service handler registered for this
385 * channel 385 * channel
386 */ 386 */
387 minSize = pReqHandler->min_channel_bytes; 387 minSize = pReqHandler->min_channel_bytes;
388 if (minSize > msg->cmd.createDevice.channelBytes) { 388 if (minSize > msg->cmd.create_device.channel_bytes) {
389 LOGERR("CONTROLVM_DEVICE_CREATE Failed: channel size is too small, channel size:0x%lx, required size:0x%lx", 389 LOGERR("CONTROLVM_DEVICE_CREATE Failed: channel size is too small, channel size:0x%lx, required size:0x%lx",
390 (ulong) msg->cmd.createDevice.channelBytes, 390 (ulong) msg->cmd.create_device.channel_bytes,
391 (ulong) minSize); 391 (ulong) minSize);
392 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, devNo, busNo, 392 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, devNo, busNo,
393 POSTCODE_SEVERITY_ERR); 393 POSTCODE_SEVERITY_ERR);
@@ -396,27 +396,27 @@ create_device(CONTROLVM_MESSAGE *msg, char *buf)
396 } 396 }
397 dev->chanptr = 397 dev->chanptr =
398 uislib_ioremap_cache(dev->channel_addr, 398 uislib_ioremap_cache(dev->channel_addr,
399 msg->cmd.createDevice.channelBytes); 399 msg->cmd.create_device.channel_bytes);
400 if (!dev->chanptr) { 400 if (!dev->chanptr) {
401 LOGERR("CONTROLVM_DEVICE_CREATE Failed: ioremap_cache of channelAddr:%Lx for channelBytes:%llu failed", 401 LOGERR("CONTROLVM_DEVICE_CREATE Failed: ioremap_cache of channelAddr:%Lx for channelBytes:%llu failed",
402 dev->channel_addr, 402 dev->channel_addr,
403 msg->cmd.createDevice.channelBytes); 403 msg->cmd.create_device.channel_bytes);
404 result = CONTROLVM_RESP_ERROR_IOREMAP_FAILED; 404 result = CONTROLVM_RESP_ERROR_IOREMAP_FAILED;
405 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, devNo, busNo, 405 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, devNo, busNo,
406 POSTCODE_SEVERITY_ERR); 406 POSTCODE_SEVERITY_ERR);
407 goto Away; 407 goto Away;
408 } 408 }
409 } 409 }
410 dev->instance_uuid = msg->cmd.createDevice.devInstGuid; 410 dev->instance_uuid = msg->cmd.create_device.dev_inst_uuid;
411 dev->channel_bytes = msg->cmd.createDevice.channelBytes; 411 dev->channel_bytes = msg->cmd.create_device.channel_bytes;
412 412
413 read_lock(&BusListLock); 413 read_lock(&BusListLock);
414 for (bus = BusListHead; bus; bus = bus->next) { 414 for (bus = BusListHead; bus; bus = bus->next) {
415 if (bus->busNo == busNo) { 415 if (bus->bus_no == busNo) {
416 /* make sure the device number is valid */ 416 /* make sure the device number is valid */
417 if (devNo >= bus->deviceCount) { 417 if (devNo >= bus->device_count) {
418 LOGERR("CONTROLVM_DEVICE_CREATE Failed: device (%d) >= deviceCount (%d).", 418 LOGERR("CONTROLVM_DEVICE_CREATE Failed: device (%d) >= deviceCount (%d).",
419 devNo, bus->deviceCount); 419 devNo, bus->device_count);
420 result = CONTROLVM_RESP_ERROR_MAX_DEVICES; 420 result = CONTROLVM_RESP_ERROR_MAX_DEVICES;
421 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, 421 POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC,
422 devNo, busNo, 422 devNo, busNo,
@@ -439,17 +439,18 @@ create_device(CONTROLVM_MESSAGE *msg, char *buf)
439 /* the msg is bound for virtpci; send 439 /* the msg is bound for virtpci; send
440 * guest_msgs struct to callback 440 * guest_msgs struct to callback
441 */ 441 */
442 if (!msg->hdr.Flags.server) { 442 if (!msg->hdr.flags.server) {
443 struct guest_msgs cmd; 443 struct guest_msgs cmd;
444 444
445 if (!uuid_le_cmp(dev->channel_uuid, 445 if (!uuid_le_cmp(dev->channel_uuid,
446 UltraVhbaChannelProtocolGuid)) { 446 spar_vhba_channel_protocol_uuid)) {
447 wait_for_valid_guid(&((CHANNEL_HEADER 447 wait_for_valid_guid(&((
448 __iomem *) (dev-> 448 struct channel_header
449 __iomem *) (dev->
449 chanptr))-> 450 chanptr))->
450 Type); 451 chtype);
451 if (!ULTRA_VHBA_CHANNEL_OK_CLIENT 452 if (!SPAR_VHBA_CHANNEL_OK_CLIENT
452 (dev->chanptr, NULL)) { 453 (dev->chanptr)) {
453 LOGERR("CONTROLVM_DEVICE_CREATE Failed:[CLIENT]VHBA dev %d chan invalid.", 454 LOGERR("CONTROLVM_DEVICE_CREATE Failed:[CLIENT]VHBA dev %d chan invalid.",
454 devNo); 455 devNo);
455 POSTCODE_LINUX_4 456 POSTCODE_LINUX_4
@@ -468,13 +469,14 @@ create_device(CONTROLVM_MESSAGE *msg, char *buf)
468 cmd.add_vhba.intr = dev->intr; 469 cmd.add_vhba.intr = dev->intr;
469 } else 470 } else
470 if (!uuid_le_cmp(dev->channel_uuid, 471 if (!uuid_le_cmp(dev->channel_uuid,
471 UltraVnicChannelProtocolGuid)) { 472 spar_vnic_channel_protocol_uuid)) {
472 wait_for_valid_guid(&((CHANNEL_HEADER 473 wait_for_valid_guid(&((
473 __iomem *) (dev-> 474 struct channel_header
475 __iomem *) (dev->
474 chanptr))-> 476 chanptr))->
475 Type); 477 chtype);
476 if (!ULTRA_VNIC_CHANNEL_OK_CLIENT 478 if (!SPAR_VNIC_CHANNEL_OK_CLIENT
477 (dev->chanptr, NULL)) { 479 (dev->chanptr)) {
478 LOGERR("CONTROLVM_DEVICE_CREATE Failed: VNIC[CLIENT] dev %d chan invalid.", 480 LOGERR("CONTROLVM_DEVICE_CREATE Failed: VNIC[CLIENT] dev %d chan invalid.",
479 devNo); 481 devNo);
480 POSTCODE_LINUX_4 482 POSTCODE_LINUX_4
@@ -500,7 +502,7 @@ create_device(CONTROLVM_MESSAGE *msg, char *buf)
500 goto Away; 502 goto Away;
501 } 503 }
502 504
503 if (!VirtControlChanFunc) { 505 if (!virt_control_chan_func) {
504 LOGERR("CONTROLVM_DEVICE_CREATE Failed: virtpci callback not registered."); 506 LOGERR("CONTROLVM_DEVICE_CREATE Failed: virtpci callback not registered.");
505 POSTCODE_LINUX_4 507 POSTCODE_LINUX_4
506 (DEVICE_CREATE_FAILURE_PC, devNo, 508 (DEVICE_CREATE_FAILURE_PC, devNo,
@@ -509,7 +511,7 @@ create_device(CONTROLVM_MESSAGE *msg, char *buf)
509 goto Away; 511 goto Away;
510 } 512 }
511 513
512 if (!VirtControlChanFunc(&cmd)) { 514 if (!virt_control_chan_func(&cmd)) {
513 LOGERR("CONTROLVM_DEVICE_CREATE Failed: virtpci GUEST_ADD_[VHBA||VNIC] returned error."); 515 LOGERR("CONTROLVM_DEVICE_CREATE Failed: virtpci GUEST_ADD_[VHBA||VNIC] returned error.");
514 POSTCODE_LINUX_4 516 POSTCODE_LINUX_4
515 (DEVICE_CREATE_FAILURE_PC, devNo, 517 (DEVICE_CREATE_FAILURE_PC, devNo,
@@ -532,7 +534,7 @@ create_device(CONTROLVM_MESSAGE *msg, char *buf)
532 result = CONTROLVM_RESP_ERROR_BUS_INVALID; 534 result = CONTROLVM_RESP_ERROR_BUS_INVALID;
533 535
534Away: 536Away:
535 if (!msg->hdr.Flags.testMessage) { 537 if (!msg->hdr.flags.test_message) {
536 uislib_iounmap(dev->chanptr); 538 uislib_iounmap(dev->chanptr);
537 dev->chanptr = NULL; 539 dev->chanptr = NULL;
538 } 540 }
@@ -542,7 +544,7 @@ Away:
542} 544}
543 545
544static int 546static int
545pause_device(CONTROLVM_MESSAGE *msg) 547pause_device(struct controlvm_message *msg)
546{ 548{
547 u32 busNo, devNo; 549 u32 busNo, devNo;
548 struct bus_info *bus; 550 struct bus_info *bus;
@@ -550,16 +552,16 @@ pause_device(CONTROLVM_MESSAGE *msg)
550 struct guest_msgs cmd; 552 struct guest_msgs cmd;
551 int retval = CONTROLVM_RESP_SUCCESS; 553 int retval = CONTROLVM_RESP_SUCCESS;
552 554
553 busNo = msg->cmd.deviceChangeState.busNo; 555 busNo = msg->cmd.device_change_state.bus_no;
554 devNo = msg->cmd.deviceChangeState.devNo; 556 devNo = msg->cmd.device_change_state.dev_no;
555 557
556 read_lock(&BusListLock); 558 read_lock(&BusListLock);
557 for (bus = BusListHead; bus; bus = bus->next) { 559 for (bus = BusListHead; bus; bus = bus->next) {
558 if (bus->busNo == busNo) { 560 if (bus->bus_no == busNo) {
559 /* make sure the device number is valid */ 561 /* make sure the device number is valid */
560 if (devNo >= bus->deviceCount) { 562 if (devNo >= bus->device_count) {
561 LOGERR("CONTROLVM_DEVICE_CHANGESTATE:pause Failed: device(%d) >= deviceCount(%d).", 563 LOGERR("CONTROLVM_DEVICE_CHANGESTATE:pause Failed: device(%d) >= deviceCount(%d).",
562 devNo, bus->deviceCount); 564 devNo, bus->device_count);
563 retval = CONTROLVM_RESP_ERROR_DEVICE_INVALID; 565 retval = CONTROLVM_RESP_ERROR_DEVICE_INVALID;
564 } else { 566 } else {
565 /* make sure this device exists */ 567 /* make sure this device exists */
@@ -585,22 +587,22 @@ pause_device(CONTROLVM_MESSAGE *msg)
585 * guest_msgs struct to callback 587 * guest_msgs struct to callback
586 */ 588 */
587 if (!uuid_le_cmp(dev->channel_uuid, 589 if (!uuid_le_cmp(dev->channel_uuid,
588 UltraVhbaChannelProtocolGuid)) { 590 spar_vhba_channel_protocol_uuid)) {
589 cmd.msgtype = GUEST_PAUSE_VHBA; 591 cmd.msgtype = GUEST_PAUSE_VHBA;
590 cmd.pause_vhba.chanptr = dev->chanptr; 592 cmd.pause_vhba.chanptr = dev->chanptr;
591 } else if (!uuid_le_cmp(dev->channel_uuid, 593 } else if (!uuid_le_cmp(dev->channel_uuid,
592 UltraVnicChannelProtocolGuid)) { 594 spar_vnic_channel_protocol_uuid)) {
593 cmd.msgtype = GUEST_PAUSE_VNIC; 595 cmd.msgtype = GUEST_PAUSE_VNIC;
594 cmd.pause_vnic.chanptr = dev->chanptr; 596 cmd.pause_vnic.chanptr = dev->chanptr;
595 } else { 597 } else {
596 LOGERR("CONTROLVM_DEVICE_CHANGESTATE:pause Failed: unknown channelTypeGuid.\n"); 598 LOGERR("CONTROLVM_DEVICE_CHANGESTATE:pause Failed: unknown channelTypeGuid.\n");
597 return CONTROLVM_RESP_ERROR_CHANNEL_TYPE_UNKNOWN; 599 return CONTROLVM_RESP_ERROR_CHANNEL_TYPE_UNKNOWN;
598 } 600 }
599 if (!VirtControlChanFunc) { 601 if (!virt_control_chan_func) {
600 LOGERR("CONTROLVM_DEVICE_CHANGESTATE Failed: virtpci callback not registered."); 602 LOGERR("CONTROLVM_DEVICE_CHANGESTATE Failed: virtpci callback not registered.");
601 return CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_FAILURE; 603 return CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_FAILURE;
602 } 604 }
603 if (!VirtControlChanFunc(&cmd)) { 605 if (!virt_control_chan_func(&cmd)) {
604 LOGERR("CONTROLVM_DEVICE_CHANGESTATE:pause Failed: virtpci GUEST_PAUSE_[VHBA||VNIC] returned error."); 606 LOGERR("CONTROLVM_DEVICE_CHANGESTATE:pause Failed: virtpci GUEST_PAUSE_[VHBA||VNIC] returned error.");
605 return 607 return
606 CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_CALLBACK_ERROR; 608 CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_CALLBACK_ERROR;
@@ -610,7 +612,7 @@ pause_device(CONTROLVM_MESSAGE *msg)
610} 612}
611 613
612static int 614static int
613resume_device(CONTROLVM_MESSAGE *msg) 615resume_device(struct controlvm_message *msg)
614{ 616{
615 u32 busNo, devNo; 617 u32 busNo, devNo;
616 struct bus_info *bus; 618 struct bus_info *bus;
@@ -618,16 +620,16 @@ resume_device(CONTROLVM_MESSAGE *msg)
618 struct guest_msgs cmd; 620 struct guest_msgs cmd;
619 int retval = CONTROLVM_RESP_SUCCESS; 621 int retval = CONTROLVM_RESP_SUCCESS;
620 622
621 busNo = msg->cmd.deviceChangeState.busNo; 623 busNo = msg->cmd.device_change_state.bus_no;
622 devNo = msg->cmd.deviceChangeState.devNo; 624 devNo = msg->cmd.device_change_state.dev_no;
623 625
624 read_lock(&BusListLock); 626 read_lock(&BusListLock);
625 for (bus = BusListHead; bus; bus = bus->next) { 627 for (bus = BusListHead; bus; bus = bus->next) {
626 if (bus->busNo == busNo) { 628 if (bus->bus_no == busNo) {
627 /* make sure the device number is valid */ 629 /* make sure the device number is valid */
628 if (devNo >= bus->deviceCount) { 630 if (devNo >= bus->device_count) {
629 LOGERR("CONTROLVM_DEVICE_CHANGESTATE:resume Failed: device(%d) >= deviceCount(%d).", 631 LOGERR("CONTROLVM_DEVICE_CHANGESTATE:resume Failed: device(%d) >= deviceCount(%d).",
630 devNo, bus->deviceCount); 632 devNo, bus->device_count);
631 retval = CONTROLVM_RESP_ERROR_DEVICE_INVALID; 633 retval = CONTROLVM_RESP_ERROR_DEVICE_INVALID;
632 } else { 634 } else {
633 /* make sure this device exists */ 635 /* make sure this device exists */
@@ -654,22 +656,22 @@ resume_device(CONTROLVM_MESSAGE *msg)
654 */ 656 */
655 if (retval == CONTROLVM_RESP_SUCCESS) { 657 if (retval == CONTROLVM_RESP_SUCCESS) {
656 if (!uuid_le_cmp(dev->channel_uuid, 658 if (!uuid_le_cmp(dev->channel_uuid,
657 UltraVhbaChannelProtocolGuid)) { 659 spar_vhba_channel_protocol_uuid)) {
658 cmd.msgtype = GUEST_RESUME_VHBA; 660 cmd.msgtype = GUEST_RESUME_VHBA;
659 cmd.resume_vhba.chanptr = dev->chanptr; 661 cmd.resume_vhba.chanptr = dev->chanptr;
660 } else if (!uuid_le_cmp(dev->channel_uuid, 662 } else if (!uuid_le_cmp(dev->channel_uuid,
661 UltraVnicChannelProtocolGuid)) { 663 spar_vnic_channel_protocol_uuid)) {
662 cmd.msgtype = GUEST_RESUME_VNIC; 664 cmd.msgtype = GUEST_RESUME_VNIC;
663 cmd.resume_vnic.chanptr = dev->chanptr; 665 cmd.resume_vnic.chanptr = dev->chanptr;
664 } else { 666 } else {
665 LOGERR("CONTROLVM_DEVICE_CHANGESTATE:resume Failed: unknown channelTypeGuid.\n"); 667 LOGERR("CONTROLVM_DEVICE_CHANGESTATE:resume Failed: unknown channelTypeGuid.\n");
666 return CONTROLVM_RESP_ERROR_CHANNEL_TYPE_UNKNOWN; 668 return CONTROLVM_RESP_ERROR_CHANNEL_TYPE_UNKNOWN;
667 } 669 }
668 if (!VirtControlChanFunc) { 670 if (!virt_control_chan_func) {
669 LOGERR("CONTROLVM_DEVICE_CHANGESTATE Failed: virtpci callback not registered."); 671 LOGERR("CONTROLVM_DEVICE_CHANGESTATE Failed: virtpci callback not registered.");
670 return CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_FAILURE; 672 return CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_FAILURE;
671 } 673 }
672 if (!VirtControlChanFunc(&cmd)) { 674 if (!virt_control_chan_func(&cmd)) {
673 LOGERR("CONTROLVM_DEVICE_CHANGESTATE:resume Failed: virtpci GUEST_RESUME_[VHBA||VNIC] returned error."); 675 LOGERR("CONTROLVM_DEVICE_CHANGESTATE:resume Failed: virtpci GUEST_RESUME_[VHBA||VNIC] returned error.");
674 return 676 return
675 CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_CALLBACK_ERROR; 677 CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_CALLBACK_ERROR;
@@ -679,7 +681,7 @@ resume_device(CONTROLVM_MESSAGE *msg)
679} 681}
680 682
681static int 683static int
682destroy_device(CONTROLVM_MESSAGE *msg, char *buf) 684destroy_device(struct controlvm_message *msg, char *buf)
683{ 685{
684 u32 busNo, devNo; 686 u32 busNo, devNo;
685 struct bus_info *bus; 687 struct bus_info *bus;
@@ -687,17 +689,17 @@ destroy_device(CONTROLVM_MESSAGE *msg, char *buf)
687 struct guest_msgs cmd; 689 struct guest_msgs cmd;
688 int retval = CONTROLVM_RESP_SUCCESS; 690 int retval = CONTROLVM_RESP_SUCCESS;
689 691
690 busNo = msg->cmd.destroyDevice.busNo; 692 busNo = msg->cmd.destroy_device.bus_no;
691 devNo = msg->cmd.destroyDevice.devNo; 693 devNo = msg->cmd.destroy_device.bus_no;
692 694
693 read_lock(&BusListLock); 695 read_lock(&BusListLock);
694 LOGINF("destroy_device called for busNo=%u, devNo=%u", busNo, devNo); 696 LOGINF("destroy_device called for busNo=%u, devNo=%u", busNo, devNo);
695 for (bus = BusListHead; bus; bus = bus->next) { 697 for (bus = BusListHead; bus; bus = bus->next) {
696 if (bus->busNo == busNo) { 698 if (bus->bus_no == busNo) {
697 /* make sure the device number is valid */ 699 /* make sure the device number is valid */
698 if (devNo >= bus->deviceCount) { 700 if (devNo >= bus->device_count) {
699 LOGERR("CONTROLVM_DEVICE_DESTORY Failed: device(%d) >= deviceCount(%d).", 701 LOGERR("CONTROLVM_DEVICE_DESTORY Failed: device(%d) >= deviceCount(%d).",
700 devNo, bus->deviceCount); 702 devNo, bus->device_count);
701 retval = CONTROLVM_RESP_ERROR_DEVICE_INVALID; 703 retval = CONTROLVM_RESP_ERROR_DEVICE_INVALID;
702 } else { 704 } else {
703 /* make sure this device exists */ 705 /* make sure this device exists */
@@ -724,11 +726,11 @@ destroy_device(CONTROLVM_MESSAGE *msg, char *buf)
724 * guest_msgs struct to callback 726 * guest_msgs struct to callback
725 */ 727 */
726 if (!uuid_le_cmp(dev->channel_uuid, 728 if (!uuid_le_cmp(dev->channel_uuid,
727 UltraVhbaChannelProtocolGuid)) { 729 spar_vhba_channel_protocol_uuid)) {
728 cmd.msgtype = GUEST_DEL_VHBA; 730 cmd.msgtype = GUEST_DEL_VHBA;
729 cmd.del_vhba.chanptr = dev->chanptr; 731 cmd.del_vhba.chanptr = dev->chanptr;
730 } else if (!uuid_le_cmp(dev->channel_uuid, 732 } else if (!uuid_le_cmp(dev->channel_uuid,
731 UltraVnicChannelProtocolGuid)) { 733 spar_vnic_channel_protocol_uuid)) {
732 cmd.msgtype = GUEST_DEL_VNIC; 734 cmd.msgtype = GUEST_DEL_VNIC;
733 cmd.del_vnic.chanptr = dev->chanptr; 735 cmd.del_vnic.chanptr = dev->chanptr;
734 } else { 736 } else {
@@ -736,12 +738,12 @@ destroy_device(CONTROLVM_MESSAGE *msg, char *buf)
736 return 738 return
737 CONTROLVM_RESP_ERROR_CHANNEL_TYPE_UNKNOWN; 739 CONTROLVM_RESP_ERROR_CHANNEL_TYPE_UNKNOWN;
738 } 740 }
739 if (!VirtControlChanFunc) { 741 if (!virt_control_chan_func) {
740 LOGERR("CONTROLVM_DEVICE_DESTORY Failed: virtpci callback not registered."); 742 LOGERR("CONTROLVM_DEVICE_DESTORY Failed: virtpci callback not registered.");
741 return 743 return
742 CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_FAILURE; 744 CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_FAILURE;
743 } 745 }
744 if (!VirtControlChanFunc(&cmd)) { 746 if (!virt_control_chan_func(&cmd)) {
745 LOGERR("CONTROLVM_DEVICE_DESTROY Failed: virtpci GUEST_DEL_[VHBA||VNIC] returned error."); 747 LOGERR("CONTROLVM_DEVICE_DESTROY Failed: virtpci GUEST_DEL_[VHBA||VNIC] returned error.");
746 return 748 return
747 CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_CALLBACK_ERROR; 749 CONTROLVM_RESP_ERROR_VIRTPCI_DRIVER_CALLBACK_ERROR;
@@ -756,7 +758,7 @@ destroy_device(CONTROLVM_MESSAGE *msg, char *buf)
756 uislib_disable_channel_interrupts(busNo, devNo); 758 uislib_disable_channel_interrupts(busNo, devNo);
757 } 759 }
758 /* unmap the channel memory for the device. */ 760 /* unmap the channel memory for the device. */
759 if (!msg->hdr.Flags.testMessage) { 761 if (!msg->hdr.flags.test_message) {
760 LOGINF("destroy_device, doing iounmap"); 762 LOGINF("destroy_device, doing iounmap");
761 uislib_iounmap(dev->chanptr); 763 uislib_iounmap(dev->chanptr);
762 } 764 }
@@ -767,23 +769,23 @@ destroy_device(CONTROLVM_MESSAGE *msg, char *buf)
767} 769}
768 770
769static int 771static int
770init_chipset(CONTROLVM_MESSAGE *msg, char *buf) 772init_chipset(struct controlvm_message *msg, char *buf)
771{ 773{
772 POSTCODE_LINUX_2(CHIPSET_INIT_ENTRY_PC, POSTCODE_SEVERITY_INFO); 774 POSTCODE_LINUX_2(CHIPSET_INIT_ENTRY_PC, POSTCODE_SEVERITY_INFO);
773 775
774 MaxBusCount = msg->cmd.initChipset.busCount; 776 MaxBusCount = msg->cmd.init_chipset.bus_count;
775 PlatformNumber = msg->cmd.initChipset.platformNumber; 777 PlatformNumber = msg->cmd.init_chipset.platform_number;
776 PhysicalDataChan = 0; 778 PhysicalDataChan = 0;
777 779
778 /* We need to make sure we have our functions registered 780 /* We need to make sure we have our functions registered
779 * before processing messages. If we are a test vehicle the 781 * before processing messages. If we are a test vehicle the
780 * testMessage for init_chipset will be set. We can ignore the 782 * test_message for init_chipset will be set. We can ignore the
781 * waits for the callbacks, since this will be manually entered 783 * waits for the callbacks, since this will be manually entered
782 * from a user. If no testMessage is set, we will wait for the 784 * from a user. If no test_message is set, we will wait for the
783 * functions. 785 * functions.
784 */ 786 */
785 if (!msg->hdr.Flags.testMessage) 787 if (!msg->hdr.flags.test_message)
786 WAIT_ON_CALLBACK(VirtControlChanFunc); 788 WAIT_ON_CALLBACK(virt_control_chan_func);
787 789
788 chipset_inited = 1; 790 chipset_inited = 1;
789 POSTCODE_LINUX_2(CHIPSET_INIT_EXIT_PC, POSTCODE_SEVERITY_INFO); 791 POSTCODE_LINUX_2(CHIPSET_INIT_EXIT_PC, POSTCODE_SEVERITY_INFO);
@@ -794,10 +796,10 @@ init_chipset(CONTROLVM_MESSAGE *msg, char *buf)
794static int 796static int
795delete_bus_glue(u32 busNo) 797delete_bus_glue(u32 busNo)
796{ 798{
797 CONTROLVM_MESSAGE msg; 799 struct controlvm_message msg;
798 800
799 init_msg_header(&msg, CONTROLVM_BUS_DESTROY, 0, 0); 801 init_msg_header(&msg, CONTROLVM_BUS_DESTROY, 0, 0);
800 msg.cmd.destroyBus.busNo = busNo; 802 msg.cmd.destroy_bus.bus_no = busNo;
801 if (destroy_bus(&msg, NULL) != CONTROLVM_RESP_SUCCESS) { 803 if (destroy_bus(&msg, NULL) != CONTROLVM_RESP_SUCCESS) {
802 LOGERR("destroy_bus failed. busNo=0x%x\n", busNo); 804 LOGERR("destroy_bus failed. busNo=0x%x\n", busNo);
803 return 0; 805 return 0;
@@ -808,11 +810,11 @@ delete_bus_glue(u32 busNo)
808static int 810static int
809delete_device_glue(u32 busNo, u32 devNo) 811delete_device_glue(u32 busNo, u32 devNo)
810{ 812{
811 CONTROLVM_MESSAGE msg; 813 struct controlvm_message msg;
812 814
813 init_msg_header(&msg, CONTROLVM_DEVICE_DESTROY, 0, 0); 815 init_msg_header(&msg, CONTROLVM_DEVICE_DESTROY, 0, 0);
814 msg.cmd.destroyDevice.busNo = busNo; 816 msg.cmd.destroy_device.bus_no = busNo;
815 msg.cmd.destroyDevice.devNo = devNo; 817 msg.cmd.destroy_device.dev_no = devNo;
816 if (destroy_device(&msg, NULL) != CONTROLVM_RESP_SUCCESS) { 818 if (destroy_device(&msg, NULL) != CONTROLVM_RESP_SUCCESS) {
817 LOGERR("destroy_device failed. busNo=0x%x devNo=0x%x\n", busNo, 819 LOGERR("destroy_device failed. busNo=0x%x devNo=0x%x\n", busNo,
818 devNo); 820 devNo);
@@ -822,14 +824,14 @@ delete_device_glue(u32 busNo, u32 devNo)
822} 824}
823 825
824int 826int
825uislib_client_inject_add_bus(u32 busNo, uuid_le instGuid, 827uislib_client_inject_add_bus(u32 bus_no, uuid_le inst_uuid,
826 u64 channelAddr, ulong nChannelBytes) 828 u64 channel_addr, ulong n_channel_bytes)
827{ 829{
828 CONTROLVM_MESSAGE msg; 830 struct controlvm_message msg;
829 831
830 LOGINF("enter busNo=0x%x\n", busNo); 832 LOGINF("enter busNo=0x%x\n", bus_no);
831 /* step 0: init the chipset */ 833 /* step 0: init the chipset */
832 POSTCODE_LINUX_3(CHIPSET_INIT_ENTRY_PC, busNo, POSTCODE_SEVERITY_INFO); 834 POSTCODE_LINUX_3(CHIPSET_INIT_ENTRY_PC, bus_no, POSTCODE_SEVERITY_INFO);
833 835
834 if (!chipset_inited) { 836 if (!chipset_inited) {
835 /* step: initialize the chipset */ 837 /* step: initialize the chipset */
@@ -841,31 +843,32 @@ uislib_client_inject_add_bus(u32 busNo, uuid_le instGuid,
841 * after number 4, then the add_vnic will fail, and the 843 * after number 4, then the add_vnic will fail, and the
842 * ultraboot will fail. 844 * ultraboot will fail.
843 */ 845 */
844 msg.cmd.initChipset.busCount = 23; 846 msg.cmd.init_chipset.bus_count = 23;
845 msg.cmd.initChipset.switchCount = 0; 847 msg.cmd.init_chipset.switch_count = 0;
846 if (init_chipset(&msg, NULL) != CONTROLVM_RESP_SUCCESS) { 848 if (init_chipset(&msg, NULL) != CONTROLVM_RESP_SUCCESS) {
847 LOGERR("init_chipset failed.\n"); 849 LOGERR("init_chipset failed.\n");
848 return 0; 850 return 0;
849 } 851 }
850 LOGINF("chipset initialized\n"); 852 LOGINF("chipset initialized\n");
851 POSTCODE_LINUX_3(CHIPSET_INIT_EXIT_PC, busNo, 853 POSTCODE_LINUX_3(CHIPSET_INIT_EXIT_PC, bus_no,
852 POSTCODE_SEVERITY_INFO); 854 POSTCODE_SEVERITY_INFO);
853 } 855 }
854 856
855 /* step 1: create a bus */ 857 /* step 1: create a bus */
856 POSTCODE_LINUX_3(BUS_CREATE_ENTRY_PC, busNo, POSTCODE_SEVERITY_WARNING); 858 POSTCODE_LINUX_3(BUS_CREATE_ENTRY_PC, bus_no,
859 POSTCODE_SEVERITY_WARNING);
857 init_msg_header(&msg, CONTROLVM_BUS_CREATE, 0, 0); 860 init_msg_header(&msg, CONTROLVM_BUS_CREATE, 0, 0);
858 msg.cmd.createBus.busNo = busNo; 861 msg.cmd.create_bus.bus_no = bus_no;
859 msg.cmd.createBus.deviceCount = 23; /* devNo+1; */ 862 msg.cmd.create_bus.dev_count = 23; /* devNo+1; */
860 msg.cmd.createBus.channelAddr = channelAddr; 863 msg.cmd.create_bus.channel_addr = channel_addr;
861 msg.cmd.createBus.channelBytes = nChannelBytes; 864 msg.cmd.create_bus.channel_bytes = n_channel_bytes;
862 if (create_bus(&msg, NULL) != CONTROLVM_RESP_SUCCESS) { 865 if (create_bus(&msg, NULL) != CONTROLVM_RESP_SUCCESS) {
863 LOGERR("create_bus failed.\n"); 866 LOGERR("create_bus failed.\n");
864 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, busNo, 867 POSTCODE_LINUX_3(BUS_CREATE_FAILURE_PC, bus_no,
865 POSTCODE_SEVERITY_ERR); 868 POSTCODE_SEVERITY_ERR);
866 return 0; 869 return 0;
867 } 870 }
868 POSTCODE_LINUX_3(BUS_CREATE_EXIT_PC, busNo, POSTCODE_SEVERITY_INFO); 871 POSTCODE_LINUX_3(BUS_CREATE_EXIT_PC, bus_no, POSTCODE_SEVERITY_INFO);
869 872
870 return 1; 873 return 1;
871} 874}
@@ -873,26 +876,26 @@ EXPORT_SYMBOL_GPL(uislib_client_inject_add_bus);
873 876
874 877
875int 878int
876uislib_client_inject_del_bus(u32 busNo) 879uislib_client_inject_del_bus(u32 bus_no)
877{ 880{
878 return delete_bus_glue(busNo); 881 return delete_bus_glue(bus_no);
879} 882}
880EXPORT_SYMBOL_GPL(uislib_client_inject_del_bus); 883EXPORT_SYMBOL_GPL(uislib_client_inject_del_bus);
881 884
882int 885int
883uislib_client_inject_pause_vhba(u32 busNo, u32 devNo) 886uislib_client_inject_pause_vhba(u32 bus_no, u32 dev_no)
884{ 887{
885 CONTROLVM_MESSAGE msg; 888 struct controlvm_message msg;
886 int rc; 889 int rc;
887 890
888 init_msg_header(&msg, CONTROLVM_DEVICE_CHANGESTATE, 0, 0); 891 init_msg_header(&msg, CONTROLVM_DEVICE_CHANGESTATE, 0, 0);
889 msg.cmd.deviceChangeState.busNo = busNo; 892 msg.cmd.device_change_state.bus_no = bus_no;
890 msg.cmd.deviceChangeState.devNo = devNo; 893 msg.cmd.device_change_state.dev_no = dev_no;
891 msg.cmd.deviceChangeState.state = SegmentStateStandby; 894 msg.cmd.device_change_state.state = segment_state_standby;
892 rc = pause_device(&msg); 895 rc = pause_device(&msg);
893 if (rc != CONTROLVM_RESP_SUCCESS) { 896 if (rc != CONTROLVM_RESP_SUCCESS) {
894 LOGERR("VHBA pause_device failed. busNo=0x%x devNo=0x%x\n", 897 LOGERR("VHBA pause_device failed. busNo=0x%x devNo=0x%x\n",
895 busNo, devNo); 898 bus_no, dev_no);
896 return rc; 899 return rc;
897 } 900 }
898 return 0; 901 return 0;
@@ -900,19 +903,19 @@ uislib_client_inject_pause_vhba(u32 busNo, u32 devNo)
900EXPORT_SYMBOL_GPL(uislib_client_inject_pause_vhba); 903EXPORT_SYMBOL_GPL(uislib_client_inject_pause_vhba);
901 904
902int 905int
903uislib_client_inject_resume_vhba(u32 busNo, u32 devNo) 906uislib_client_inject_resume_vhba(u32 bus_no, u32 dev_no)
904{ 907{
905 CONTROLVM_MESSAGE msg; 908 struct controlvm_message msg;
906 int rc; 909 int rc;
907 910
908 init_msg_header(&msg, CONTROLVM_DEVICE_CHANGESTATE, 0, 0); 911 init_msg_header(&msg, CONTROLVM_DEVICE_CHANGESTATE, 0, 0);
909 msg.cmd.deviceChangeState.busNo = busNo; 912 msg.cmd.device_change_state.bus_no = bus_no;
910 msg.cmd.deviceChangeState.devNo = devNo; 913 msg.cmd.device_change_state.dev_no = dev_no;
911 msg.cmd.deviceChangeState.state = SegmentStateRunning; 914 msg.cmd.device_change_state.state = segment_state_running;
912 rc = resume_device(&msg); 915 rc = resume_device(&msg);
913 if (rc != CONTROLVM_RESP_SUCCESS) { 916 if (rc != CONTROLVM_RESP_SUCCESS) {
914 LOGERR("VHBA resume_device failed. busNo=0x%x devNo=0x%x\n", 917 LOGERR("VHBA resume_device failed. busNo=0x%x devNo=0x%x\n",
915 busNo, devNo); 918 bus_no, dev_no);
916 return rc; 919 return rc;
917 } 920 }
918 return 0; 921 return 0;
@@ -921,19 +924,19 @@ uislib_client_inject_resume_vhba(u32 busNo, u32 devNo)
921EXPORT_SYMBOL_GPL(uislib_client_inject_resume_vhba); 924EXPORT_SYMBOL_GPL(uislib_client_inject_resume_vhba);
922 925
923int 926int
924uislib_client_inject_add_vhba(u32 busNo, u32 devNo, 927uislib_client_inject_add_vhba(u32 bus_no, u32 dev_no,
925 u64 phys_chan_addr, u32 chan_bytes, 928 u64 phys_chan_addr, u32 chan_bytes,
926 int is_test_addr, uuid_le instGuid, 929 int is_test_addr, uuid_le inst_uuid,
927 struct InterruptInfo *intr) 930 struct irq_info *intr)
928{ 931{
929 CONTROLVM_MESSAGE msg; 932 struct controlvm_message msg;
930 933
931 LOGINF(" enter busNo=0x%x devNo=0x%x\n", busNo, devNo); 934 LOGINF(" enter busNo=0x%x devNo=0x%x\n", bus_no, dev_no);
932 /* chipset init'ed with bus bus has been previously created - 935 /* chipset init'ed with bus bus has been previously created -
933 * Verify it still exists step 2: create the VHBA device on the 936 * Verify it still exists step 2: create the VHBA device on the
934 * bus 937 * bus
935 */ 938 */
936 POSTCODE_LINUX_4(VHBA_CREATE_ENTRY_PC, devNo, busNo, 939 POSTCODE_LINUX_4(VHBA_CREATE_ENTRY_PC, dev_no, bus_no,
937 POSTCODE_SEVERITY_INFO); 940 POSTCODE_SEVERITY_INFO);
938 941
939 init_msg_header(&msg, CONTROLVM_DEVICE_CREATE, 0, 0); 942 init_msg_header(&msg, CONTROLVM_DEVICE_CREATE, 0, 0);
@@ -941,16 +944,16 @@ uislib_client_inject_add_vhba(u32 busNo, u32 devNo,
941 /* signify that the physical channel address does NOT 944 /* signify that the physical channel address does NOT
942 * need to be ioremap()ed 945 * need to be ioremap()ed
943 */ 946 */
944 msg.hdr.Flags.testMessage = 1; 947 msg.hdr.flags.test_message = 1;
945 msg.cmd.createDevice.busNo = busNo; 948 msg.cmd.create_device.bus_no = bus_no;
946 msg.cmd.createDevice.devNo = devNo; 949 msg.cmd.create_device.dev_no = dev_no;
947 msg.cmd.createDevice.devInstGuid = instGuid; 950 msg.cmd.create_device.dev_inst_uuid = inst_uuid;
948 if (intr) 951 if (intr)
949 msg.cmd.createDevice.intr = *intr; 952 msg.cmd.create_device.intr = *intr;
950 else 953 else
951 memset(&msg.cmd.createDevice.intr, 0, 954 memset(&msg.cmd.create_device.intr, 0,
952 sizeof(struct InterruptInfo)); 955 sizeof(struct irq_info));
953 msg.cmd.createDevice.channelAddr = phys_chan_addr; 956 msg.cmd.create_device.channel_addr = phys_chan_addr;
954 if (chan_bytes < MIN_IO_CHANNEL_SIZE) { 957 if (chan_bytes < MIN_IO_CHANNEL_SIZE) {
955 LOGERR("wrong channel size.chan_bytes = 0x%x IO_CHANNEL_SIZE= 0x%x\n", 958 LOGERR("wrong channel size.chan_bytes = 0x%x IO_CHANNEL_SIZE= 0x%x\n",
956 chan_bytes, (unsigned int) MIN_IO_CHANNEL_SIZE); 959 chan_bytes, (unsigned int) MIN_IO_CHANNEL_SIZE);
@@ -958,41 +961,41 @@ uislib_client_inject_add_vhba(u32 busNo, u32 devNo,
958 MIN_IO_CHANNEL_SIZE, POSTCODE_SEVERITY_ERR); 961 MIN_IO_CHANNEL_SIZE, POSTCODE_SEVERITY_ERR);
959 return 0; 962 return 0;
960 } 963 }
961 msg.cmd.createDevice.channelBytes = chan_bytes; 964 msg.cmd.create_device.channel_bytes = chan_bytes;
962 msg.cmd.createDevice.dataTypeGuid = UltraVhbaChannelProtocolGuid; 965 msg.cmd.create_device.data_type_uuid = spar_vhba_channel_protocol_uuid;
963 if (create_device(&msg, NULL) != CONTROLVM_RESP_SUCCESS) { 966 if (create_device(&msg, NULL) != CONTROLVM_RESP_SUCCESS) {
964 LOGERR("VHBA create_device failed.\n"); 967 LOGERR("VHBA create_device failed.\n");
965 POSTCODE_LINUX_4(VHBA_CREATE_FAILURE_PC, devNo, busNo, 968 POSTCODE_LINUX_4(VHBA_CREATE_FAILURE_PC, dev_no, bus_no,
966 POSTCODE_SEVERITY_ERR); 969 POSTCODE_SEVERITY_ERR);
967 return 0; 970 return 0;
968 } 971 }
969 POSTCODE_LINUX_4(VHBA_CREATE_SUCCESS_PC, devNo, busNo, 972 POSTCODE_LINUX_4(VHBA_CREATE_SUCCESS_PC, dev_no, bus_no,
970 POSTCODE_SEVERITY_INFO); 973 POSTCODE_SEVERITY_INFO);
971 return 1; 974 return 1;
972} 975}
973EXPORT_SYMBOL_GPL(uislib_client_inject_add_vhba); 976EXPORT_SYMBOL_GPL(uislib_client_inject_add_vhba);
974 977
975int 978int
976uislib_client_inject_del_vhba(u32 busNo, u32 devNo) 979uislib_client_inject_del_vhba(u32 bus_no, u32 dev_no)
977{ 980{
978 return delete_device_glue(busNo, devNo); 981 return delete_device_glue(bus_no, dev_no);
979} 982}
980EXPORT_SYMBOL_GPL(uislib_client_inject_del_vhba); 983EXPORT_SYMBOL_GPL(uislib_client_inject_del_vhba);
981 984
982int 985int
983uislib_client_inject_add_vnic(u32 busNo, u32 devNo, 986uislib_client_inject_add_vnic(u32 bus_no, u32 dev_no,
984 u64 phys_chan_addr, u32 chan_bytes, 987 u64 phys_chan_addr, u32 chan_bytes,
985 int is_test_addr, uuid_le instGuid, 988 int is_test_addr, uuid_le inst_uuid,
986 struct InterruptInfo *intr) 989 struct irq_info *intr)
987{ 990{
988 CONTROLVM_MESSAGE msg; 991 struct controlvm_message msg;
989 992
990 LOGINF(" enter busNo=0x%x devNo=0x%x\n", busNo, devNo); 993 LOGINF(" enter busNo=0x%x devNo=0x%x\n", bus_no, dev_no);
991 /* chipset init'ed with bus bus has been previously created - 994 /* chipset init'ed with bus bus has been previously created -
992 * Verify it still exists step 2: create the VNIC device on the 995 * Verify it still exists step 2: create the VNIC device on the
993 * bus 996 * bus
994 */ 997 */
995 POSTCODE_LINUX_4(VNIC_CREATE_ENTRY_PC, devNo, busNo, 998 POSTCODE_LINUX_4(VNIC_CREATE_ENTRY_PC, dev_no, bus_no,
996 POSTCODE_SEVERITY_INFO); 999 POSTCODE_SEVERITY_INFO);
997 1000
998 init_msg_header(&msg, CONTROLVM_DEVICE_CREATE, 0, 0); 1001 init_msg_header(&msg, CONTROLVM_DEVICE_CREATE, 0, 0);
@@ -1000,16 +1003,16 @@ uislib_client_inject_add_vnic(u32 busNo, u32 devNo,
1000 /* signify that the physical channel address does NOT 1003 /* signify that the physical channel address does NOT
1001 * need to be ioremap()ed 1004 * need to be ioremap()ed
1002 */ 1005 */
1003 msg.hdr.Flags.testMessage = 1; 1006 msg.hdr.flags.test_message = 1;
1004 msg.cmd.createDevice.busNo = busNo; 1007 msg.cmd.create_device.bus_no = bus_no;
1005 msg.cmd.createDevice.devNo = devNo; 1008 msg.cmd.create_device.dev_no = dev_no;
1006 msg.cmd.createDevice.devInstGuid = instGuid; 1009 msg.cmd.create_device.dev_inst_uuid = inst_uuid;
1007 if (intr) 1010 if (intr)
1008 msg.cmd.createDevice.intr = *intr; 1011 msg.cmd.create_device.intr = *intr;
1009 else 1012 else
1010 memset(&msg.cmd.createDevice.intr, 0, 1013 memset(&msg.cmd.create_device.intr, 0,
1011 sizeof(struct InterruptInfo)); 1014 sizeof(struct irq_info));
1012 msg.cmd.createDevice.channelAddr = phys_chan_addr; 1015 msg.cmd.create_device.channel_addr = phys_chan_addr;
1013 if (chan_bytes < MIN_IO_CHANNEL_SIZE) { 1016 if (chan_bytes < MIN_IO_CHANNEL_SIZE) {
1014 LOGERR("wrong channel size.chan_bytes = 0x%x IO_CHANNEL_SIZE= 0x%x\n", 1017 LOGERR("wrong channel size.chan_bytes = 0x%x IO_CHANNEL_SIZE= 0x%x\n",
1015 chan_bytes, (unsigned int) MIN_IO_CHANNEL_SIZE); 1018 chan_bytes, (unsigned int) MIN_IO_CHANNEL_SIZE);
@@ -1017,35 +1020,35 @@ uislib_client_inject_add_vnic(u32 busNo, u32 devNo,
1017 MIN_IO_CHANNEL_SIZE, POSTCODE_SEVERITY_ERR); 1020 MIN_IO_CHANNEL_SIZE, POSTCODE_SEVERITY_ERR);
1018 return 0; 1021 return 0;
1019 } 1022 }
1020 msg.cmd.createDevice.channelBytes = chan_bytes; 1023 msg.cmd.create_device.channel_bytes = chan_bytes;
1021 msg.cmd.createDevice.dataTypeGuid = UltraVnicChannelProtocolGuid; 1024 msg.cmd.create_device.data_type_uuid = spar_vnic_channel_protocol_uuid;
1022 if (create_device(&msg, NULL) != CONTROLVM_RESP_SUCCESS) { 1025 if (create_device(&msg, NULL) != CONTROLVM_RESP_SUCCESS) {
1023 LOGERR("VNIC create_device failed.\n"); 1026 LOGERR("VNIC create_device failed.\n");
1024 POSTCODE_LINUX_4(VNIC_CREATE_FAILURE_PC, devNo, busNo, 1027 POSTCODE_LINUX_4(VNIC_CREATE_FAILURE_PC, dev_no, bus_no,
1025 POSTCODE_SEVERITY_ERR); 1028 POSTCODE_SEVERITY_ERR);
1026 return 0; 1029 return 0;
1027 } 1030 }
1028 1031
1029 POSTCODE_LINUX_4(VNIC_CREATE_SUCCESS_PC, devNo, busNo, 1032 POSTCODE_LINUX_4(VNIC_CREATE_SUCCESS_PC, dev_no, bus_no,
1030 POSTCODE_SEVERITY_INFO); 1033 POSTCODE_SEVERITY_INFO);
1031 return 1; 1034 return 1;
1032} 1035}
1033EXPORT_SYMBOL_GPL(uislib_client_inject_add_vnic); 1036EXPORT_SYMBOL_GPL(uislib_client_inject_add_vnic);
1034 1037
1035int 1038int
1036uislib_client_inject_pause_vnic(u32 busNo, u32 devNo) 1039uislib_client_inject_pause_vnic(u32 bus_no, u32 dev_no)
1037{ 1040{
1038 CONTROLVM_MESSAGE msg; 1041 struct controlvm_message msg;
1039 int rc; 1042 int rc;
1040 1043
1041 init_msg_header(&msg, CONTROLVM_DEVICE_CHANGESTATE, 0, 0); 1044 init_msg_header(&msg, CONTROLVM_DEVICE_CHANGESTATE, 0, 0);
1042 msg.cmd.deviceChangeState.busNo = busNo; 1045 msg.cmd.device_change_state.bus_no = bus_no;
1043 msg.cmd.deviceChangeState.devNo = devNo; 1046 msg.cmd.device_change_state.dev_no = dev_no;
1044 msg.cmd.deviceChangeState.state = SegmentStateStandby; 1047 msg.cmd.device_change_state.state = segment_state_standby;
1045 rc = pause_device(&msg); 1048 rc = pause_device(&msg);
1046 if (rc != CONTROLVM_RESP_SUCCESS) { 1049 if (rc != CONTROLVM_RESP_SUCCESS) {
1047 LOGERR("VNIC pause_device failed. busNo=0x%x devNo=0x%x\n", 1050 LOGERR("VNIC pause_device failed. busNo=0x%x devNo=0x%x\n",
1048 busNo, devNo); 1051 bus_no, dev_no);
1049 return -1; 1052 return -1;
1050 } 1053 }
1051 return 0; 1054 return 0;
@@ -1053,19 +1056,19 @@ uislib_client_inject_pause_vnic(u32 busNo, u32 devNo)
1053EXPORT_SYMBOL_GPL(uislib_client_inject_pause_vnic); 1056EXPORT_SYMBOL_GPL(uislib_client_inject_pause_vnic);
1054 1057
1055int 1058int
1056uislib_client_inject_resume_vnic(u32 busNo, u32 devNo) 1059uislib_client_inject_resume_vnic(u32 bus_no, u32 dev_no)
1057{ 1060{
1058 CONTROLVM_MESSAGE msg; 1061 struct controlvm_message msg;
1059 int rc; 1062 int rc;
1060 1063
1061 init_msg_header(&msg, CONTROLVM_DEVICE_CHANGESTATE, 0, 0); 1064 init_msg_header(&msg, CONTROLVM_DEVICE_CHANGESTATE, 0, 0);
1062 msg.cmd.deviceChangeState.busNo = busNo; 1065 msg.cmd.device_change_state.bus_no = bus_no;
1063 msg.cmd.deviceChangeState.devNo = devNo; 1066 msg.cmd.device_change_state.dev_no = dev_no;
1064 msg.cmd.deviceChangeState.state = SegmentStateRunning; 1067 msg.cmd.device_change_state.state = segment_state_running;
1065 rc = resume_device(&msg); 1068 rc = resume_device(&msg);
1066 if (rc != CONTROLVM_RESP_SUCCESS) { 1069 if (rc != CONTROLVM_RESP_SUCCESS) {
1067 LOGERR("VNIC resume_device failed. busNo=0x%x devNo=0x%x\n", 1070 LOGERR("VNIC resume_device failed. busNo=0x%x devNo=0x%x\n",
1068 busNo, devNo); 1071 bus_no, dev_no);
1069 return -1; 1072 return -1;
1070 } 1073 }
1071 return 0; 1074 return 0;
@@ -1074,88 +1077,12 @@ uislib_client_inject_resume_vnic(u32 busNo, u32 devNo)
1074EXPORT_SYMBOL_GPL(uislib_client_inject_resume_vnic); 1077EXPORT_SYMBOL_GPL(uislib_client_inject_resume_vnic);
1075 1078
1076int 1079int
1077uislib_client_inject_del_vnic(u32 busNo, u32 devNo) 1080uislib_client_inject_del_vnic(u32 bus_no, u32 dev_no)
1078{ 1081{
1079 return delete_device_glue(busNo, devNo); 1082 return delete_device_glue(bus_no, dev_no);
1080} 1083}
1081EXPORT_SYMBOL_GPL(uislib_client_inject_del_vnic); 1084EXPORT_SYMBOL_GPL(uislib_client_inject_del_vnic);
1082 1085
1083static int
1084uislib_client_add_vnic(u32 busNo)
1085{
1086 BOOL busCreated = FALSE;
1087 int devNo = 0; /* Default to 0, since only one device
1088 * will be created for this bus... */
1089 CONTROLVM_MESSAGE msg;
1090
1091 init_msg_header(&msg, CONTROLVM_BUS_CREATE, 0, 0);
1092 msg.hdr.Flags.testMessage = 1;
1093 msg.cmd.createBus.busNo = busNo;
1094 msg.cmd.createBus.deviceCount = 4;
1095 msg.cmd.createBus.channelAddr = 0;
1096 msg.cmd.createBus.channelBytes = 0;
1097 if (create_bus(&msg, NULL) != CONTROLVM_RESP_SUCCESS) {
1098 LOGERR("client create_bus failed");
1099 return 0;
1100 }
1101 busCreated = TRUE;
1102
1103 init_msg_header(&msg, CONTROLVM_DEVICE_CREATE, 0, 0);
1104 msg.hdr.Flags.testMessage = 1;
1105 msg.cmd.createDevice.busNo = busNo;
1106 msg.cmd.createDevice.devNo = devNo;
1107 msg.cmd.createDevice.devInstGuid = NULL_UUID_LE;
1108 memset(&msg.cmd.createDevice.intr, 0, sizeof(struct InterruptInfo));
1109 msg.cmd.createDevice.channelAddr = PhysicalDataChan;
1110 msg.cmd.createDevice.channelBytes = MIN_IO_CHANNEL_SIZE;
1111 msg.cmd.createDevice.dataTypeGuid = UltraVnicChannelProtocolGuid;
1112 if (create_device(&msg, NULL) != CONTROLVM_RESP_SUCCESS) {
1113 LOGERR("client create_device failed");
1114 goto AwayCleanup;
1115 }
1116
1117 return 1;
1118
1119AwayCleanup:
1120 if (busCreated) {
1121 init_msg_header(&msg, CONTROLVM_BUS_DESTROY, 0, 0);
1122 msg.hdr.Flags.testMessage = 1;
1123 msg.cmd.destroyBus.busNo = busNo;
1124 if (destroy_bus(&msg, NULL) != CONTROLVM_RESP_SUCCESS)
1125 LOGERR("client destroy_bus failed.\n");
1126 }
1127
1128 return 0;
1129} /* end uislib_client_add_vnic */
1130EXPORT_SYMBOL_GPL(uislib_client_add_vnic);
1131
1132static int
1133uislib_client_delete_vnic(u32 busNo)
1134{
1135 int devNo = 0; /* Default to 0, since only one device
1136 * will be created for this bus... */
1137 CONTROLVM_MESSAGE msg;
1138
1139 init_msg_header(&msg, CONTROLVM_DEVICE_DESTROY, 0, 0);
1140 msg.hdr.Flags.testMessage = 1;
1141 msg.cmd.destroyDevice.busNo = busNo;
1142 msg.cmd.destroyDevice.devNo = devNo;
1143 if (destroy_device(&msg, NULL) != CONTROLVM_RESP_SUCCESS) {
1144 /* Don't error exit - try to see if bus can be destroyed... */
1145 LOGERR("client destroy_device failed.\n");
1146 }
1147
1148 init_msg_header(&msg, CONTROLVM_BUS_DESTROY, 0, 0);
1149 msg.hdr.Flags.testMessage = 1;
1150 msg.cmd.destroyBus.busNo = busNo;
1151 if (destroy_bus(&msg, NULL) != CONTROLVM_RESP_SUCCESS)
1152 LOGERR("client destroy_bus failed.\n");
1153
1154 return 1;
1155}
1156EXPORT_SYMBOL_GPL(uislib_client_delete_vnic);
1157/* end client_delete_vnic */
1158
1159void * 1086void *
1160uislib_cache_alloc(struct kmem_cache *cur_pool, char *fn, int ln) 1087uislib_cache_alloc(struct kmem_cache *cur_pool, char *fn, int ln)
1161{ 1088{
@@ -1206,17 +1133,17 @@ info_debugfs_read_helper(char **buff, int *buff_len)
1206 for (bus = BusListHead; bus; bus = bus->next) { 1133 for (bus = BusListHead; bus; bus = bus->next) {
1207 1134
1208 if (PLINE(" bus=0x%p, busNo=%d, deviceCount=%d\n", 1135 if (PLINE(" bus=0x%p, busNo=%d, deviceCount=%d\n",
1209 bus, bus->busNo, bus->deviceCount) < 0) 1136 bus, bus->bus_no, bus->device_count) < 0)
1210 goto err_done_unlock; 1137 goto err_done_unlock;
1211 1138
1212 1139
1213 if (PLINE(" Devices:\n") < 0) 1140 if (PLINE(" Devices:\n") < 0)
1214 goto err_done_unlock; 1141 goto err_done_unlock;
1215 1142
1216 for (i = 0; i < bus->deviceCount; i++) { 1143 for (i = 0; i < bus->device_count; i++) {
1217 if (bus->device[i]) { 1144 if (bus->device[i]) {
1218 if (PLINE(" busNo %d, device[%i]: 0x%p, chanptr=0x%p, swtch=0x%p\n", 1145 if (PLINE(" busNo %d, device[%i]: 0x%p, chanptr=0x%p, swtch=0x%p\n",
1219 bus->busNo, i, bus->device[i], 1146 bus->bus_no, i, bus->device[i],
1220 bus->device[i]->chanptr, 1147 bus->device[i]->chanptr,
1221 bus->device[i]->swtch) < 0) 1148 bus->device[i]->swtch) < 0)
1222 goto err_done_unlock; 1149 goto err_done_unlock;
@@ -1232,7 +1159,7 @@ info_debugfs_read_helper(char **buff, int *buff_len)
1232 read_unlock(&BusListLock); 1159 read_unlock(&BusListLock);
1233 1160
1234 if (PLINE("UisUtils_Registered_Services: %d\n", 1161 if (PLINE("UisUtils_Registered_Services: %d\n",
1235 atomic_read(&UisUtils_Registered_Services)) < 0) 1162 atomic_read(&uisutils_registered_services)) < 0)
1236 goto err_done; 1163 goto err_done;
1237 if (PLINE("cycles_before_wait %llu wait_cycles:%llu\n", 1164 if (PLINE("cycles_before_wait %llu wait_cycles:%llu\n",
1238 cycles_before_wait, wait_cycles) < 0) 1165 cycles_before_wait, wait_cycles) < 0)
@@ -1294,9 +1221,9 @@ find_dev(u32 busNo, u32 devNo)
1294 1221
1295 read_lock(&BusListLock); 1222 read_lock(&BusListLock);
1296 for (bus = BusListHead; bus; bus = bus->next) { 1223 for (bus = BusListHead; bus; bus = bus->next) {
1297 if (bus->busNo == busNo) { 1224 if (bus->bus_no == busNo) {
1298 /* make sure the device number is valid */ 1225 /* make sure the device number is valid */
1299 if (devNo >= bus->deviceCount) { 1226 if (devNo >= bus->device_count) {
1300 LOGERR("%s bad busNo, devNo=%d,%d", 1227 LOGERR("%s bad busNo, devNo=%d,%d",
1301 __func__, 1228 __func__,
1302 (int) (busNo), (int) (devNo)); 1229 (int) (busNo), (int) (devNo));
@@ -1560,13 +1487,13 @@ uislib_mod_init(void)
1560 LOGINF("sizeof(uiscmdrsp_net):%lu\n", 1487 LOGINF("sizeof(uiscmdrsp_net):%lu\n",
1561 (ulong) sizeof(struct uiscmdrsp_net)); 1488 (ulong) sizeof(struct uiscmdrsp_net));
1562 LOGINF("sizeof(CONTROLVM_MESSAGE):%lu bytes\n", 1489 LOGINF("sizeof(CONTROLVM_MESSAGE):%lu bytes\n",
1563 (ulong) sizeof(CONTROLVM_MESSAGE)); 1490 (ulong) sizeof(struct controlvm_message));
1564 LOGINF("sizeof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL):%lu bytes\n", 1491 LOGINF("sizeof(struct spar_controlvm_channel_protocol):%lu bytes\n",
1565 (ulong) sizeof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL)); 1492 (ulong) sizeof(struct spar_controlvm_channel_protocol));
1566 LOGINF("sizeof(CHANNEL_HEADER):%lu bytes\n", 1493 LOGINF("sizeof(CHANNEL_HEADER):%lu bytes\n",
1567 (ulong) sizeof(CHANNEL_HEADER)); 1494 (ulong) sizeof(struct channel_header));
1568 LOGINF("sizeof(ULTRA_IO_CHANNEL_PROTOCOL):%lu bytes\n", 1495 LOGINF("sizeof(struct spar_io_channel_protocol):%lu bytes\n",
1569 (ulong) sizeof(ULTRA_IO_CHANNEL_PROTOCOL)); 1496 (ulong) sizeof(struct spar_io_channel_protocol));
1570 LOGINF("SIZEOF_CMDRSP:%lu bytes\n", SIZEOF_CMDRSP); 1497 LOGINF("SIZEOF_CMDRSP:%lu bytes\n", SIZEOF_CMDRSP);
1571 LOGINF("SIZEOF_PROTOCOL:%lu bytes\n", SIZEOF_PROTOCOL); 1498 LOGINF("SIZEOF_PROTOCOL:%lu bytes\n", SIZEOF_PROTOCOL);
1572 1499
@@ -1574,7 +1501,7 @@ uislib_mod_init(void)
1574 BusListHead = NULL; 1501 BusListHead = NULL;
1575 BusListCount = MaxBusCount = 0; 1502 BusListCount = MaxBusCount = 0;
1576 rwlock_init(&BusListLock); 1503 rwlock_init(&BusListLock);
1577 VirtControlChanFunc = NULL; 1504 virt_control_chan_func = NULL;
1578 1505
1579 /* Issue VMCALL_GET_CONTROLVM_ADDR to get CtrlChanPhysAddr and 1506 /* Issue VMCALL_GET_CONTROLVM_ADDR to get CtrlChanPhysAddr and
1580 * then map this physical address to a virtual address. */ 1507 * then map this physical address to a virtual address. */
diff --git a/drivers/staging/unisys/uislib/uisqueue.c b/drivers/staging/unisys/uislib/uisqueue.c
index 44208841bd5a..f9f8442d58c5 100644
--- a/drivers/staging/unisys/uislib/uisqueue.c
+++ b/drivers/staging/unisys/uislib/uisqueue.c
@@ -81,13 +81,13 @@ do_locked_client_insert(struct uisqueue_info *queueinfo,
81 u8 rc = 0; 81 u8 rc = 0;
82 82
83 spin_lock_irqsave(lock, flags); 83 spin_lock_irqsave(lock, flags);
84 if (!ULTRA_CHANNEL_CLIENT_ACQUIRE_OS(queueinfo->chan, channelId, NULL)) 84 if (!spar_channel_client_acquire_os(queueinfo->chan, channelId))
85 goto unlock; 85 goto unlock;
86 if (visor_signal_insert(queueinfo->chan, whichqueue, pSignal)) { 86 if (spar_signal_insert(queueinfo->chan, whichqueue, pSignal)) {
87 queueinfo->packets_sent++; 87 queueinfo->packets_sent++;
88 rc = 1; 88 rc = 1;
89 } 89 }
90 ULTRA_CHANNEL_CLIENT_RELEASE_OS(queueinfo->chan, channelId, NULL); 90 spar_channel_client_release_os(queueinfo->chan, channelId);
91unlock: 91unlock:
92 spin_unlock_irqrestore((spinlock_t *)lock, flags); 92 spin_unlock_irqrestore((spinlock_t *)lock, flags);
93 return rc; 93 return rc;
@@ -125,7 +125,7 @@ int
125uisqueue_get_cmdrsp(struct uisqueue_info *queueinfo, 125uisqueue_get_cmdrsp(struct uisqueue_info *queueinfo,
126 void *cmdrsp, unsigned int whichqueue) 126 void *cmdrsp, unsigned int whichqueue)
127{ 127{
128 if (!visor_signal_remove(queueinfo->chan, whichqueue, cmdrsp)) 128 if (!spar_signal_remove(queueinfo->chan, whichqueue, cmdrsp))
129 return 0; 129 return 0;
130 130
131 queueinfo->packets_received++; 131 queueinfo->packets_received++;
diff --git a/drivers/staging/unisys/uislib/uisutils.c b/drivers/staging/unisys/uislib/uisutils.c
index 8ff6d26ff00b..4a5b86773927 100644
--- a/drivers/staging/unisys/uislib/uisutils.c
+++ b/drivers/staging/unisys/uislib/uisutils.c
@@ -25,9 +25,7 @@
25#include "uisutils.h" 25#include "uisutils.h"
26#include "version.h" 26#include "version.h"
27#include "vbushelper.h" 27#include "vbushelper.h"
28#include <linux/uuid.h>
29#include <linux/skbuff.h> 28#include <linux/skbuff.h>
30#include <linux/uuid.h>
31#ifdef CONFIG_HIGHMEM 29#ifdef CONFIG_HIGHMEM
32#include <linux/highmem.h> 30#include <linux/highmem.h>
33#endif 31#endif
@@ -39,7 +37,7 @@
39#define __MYFILE__ "uisutils.c" 37#define __MYFILE__ "uisutils.c"
40 38
41/* exports */ 39/* exports */
42atomic_t UisUtils_Registered_Services = ATOMIC_INIT(0); 40atomic_t uisutils_registered_services = ATOMIC_INIT(0);
43 /* num registrations via 41 /* num registrations via
44 * uisctrl_register_req_handler() or 42 * uisctrl_register_req_handler() or
45 * uisctrl_register_req_handler_ex() */ 43 * uisctrl_register_req_handler_ex() */
@@ -75,20 +73,20 @@ EXPORT_SYMBOL_GPL(uisutil_add_proc_line_ex);
75 73
76int 74int
77uisctrl_register_req_handler(int type, void *fptr, 75uisctrl_register_req_handler(int type, void *fptr,
78 ULTRA_VBUS_DEVICEINFO *chipset_driver_info) 76 struct ultra_vbus_deviceinfo *chipset_driver_info)
79{ 77{
80 LOGINF("type = %d, fptr = 0x%p.\n", type, fptr); 78 LOGINF("type = %d, fptr = 0x%p.\n", type, fptr);
81 79
82 switch (type) { 80 switch (type) {
83 case 2: 81 case 2:
84 if (fptr) { 82 if (fptr) {
85 if (!VirtControlChanFunc) 83 if (!virt_control_chan_func)
86 atomic_inc(&UisUtils_Registered_Services); 84 atomic_inc(&uisutils_registered_services);
87 VirtControlChanFunc = fptr; 85 virt_control_chan_func = fptr;
88 } else { 86 } else {
89 if (VirtControlChanFunc) 87 if (virt_control_chan_func)
90 atomic_dec(&UisUtils_Registered_Services); 88 atomic_dec(&uisutils_registered_services);
91 VirtControlChanFunc = NULL; 89 virt_control_chan_func = NULL;
92 } 90 }
93 break; 91 break;
94 92
@@ -105,76 +103,75 @@ uisctrl_register_req_handler(int type, void *fptr,
105EXPORT_SYMBOL_GPL(uisctrl_register_req_handler); 103EXPORT_SYMBOL_GPL(uisctrl_register_req_handler);
106 104
107int 105int
108uisctrl_register_req_handler_ex(uuid_le switchTypeGuid, 106uisctrl_register_req_handler_ex(uuid_le switch_uuid,
109 const char *switch_type_name, 107 const char *switch_type_name,
110 int (*controlfunc)(struct io_msgs *), 108 int (*controlfunc)(struct io_msgs *),
111 unsigned long min_channel_bytes, 109 unsigned long min_channel_bytes,
112 int (*Server_Channel_Ok)(unsigned long 110 int (*server_channel_ok)(unsigned long channel_bytes),
113 channelBytes), 111 int (*server_channel_init)(void *x,
114 int (*Server_Channel_Init) 112 unsigned char *client_str,
115 (void *x, unsigned char *clientStr, 113 u32 client_str_len, u64 bytes),
116 u32 clientStrLen, u64 bytes), 114 struct ultra_vbus_deviceinfo *chipset_driver_info)
117 ULTRA_VBUS_DEVICEINFO *chipset_DriverInfo)
118{ 115{
119 ReqHandlerInfo_t *pReqHandlerInfo; 116 struct req_handler_info *pReqHandlerInfo;
120 int rc = 0; /* assume failure */ 117 int rc = 0; /* assume failure */
121 118
122 LOGINF("type=%pUL, controlfunc=0x%p.\n", 119 LOGINF("type=%pUL, controlfunc=0x%p.\n",
123 &switchTypeGuid, controlfunc); 120 &switch_uuid, controlfunc);
124 if (!controlfunc) { 121 if (!controlfunc) {
125 LOGERR("%pUL: controlfunc must be supplied\n", &switchTypeGuid); 122 LOGERR("%pUL: controlfunc must be supplied\n", &switch_uuid);
126 goto Away; 123 goto Away;
127 } 124 }
128 if (!Server_Channel_Ok) { 125 if (!server_channel_ok) {
129 LOGERR("%pUL: Server_Channel_Ok must be supplied\n", 126 LOGERR("%pUL: Server_Channel_Ok must be supplied\n",
130 &switchTypeGuid); 127 &switch_uuid);
131 goto Away; 128 goto Away;
132 } 129 }
133 if (!Server_Channel_Init) { 130 if (!server_channel_init) {
134 LOGERR("%pUL: Server_Channel_Init must be supplied\n", 131 LOGERR("%pUL: Server_Channel_Init must be supplied\n",
135 &switchTypeGuid); 132 &switch_uuid);
136 goto Away; 133 goto Away;
137 } 134 }
138 pReqHandlerInfo = ReqHandlerAdd(switchTypeGuid, 135 pReqHandlerInfo = req_handler_add(switch_uuid,
139 switch_type_name, 136 switch_type_name,
140 controlfunc, 137 controlfunc,
141 min_channel_bytes, 138 min_channel_bytes,
142 Server_Channel_Ok, Server_Channel_Init); 139 server_channel_ok, server_channel_init);
143 if (!pReqHandlerInfo) { 140 if (!pReqHandlerInfo) {
144 LOGERR("failed to add %pUL to server list\n", &switchTypeGuid); 141 LOGERR("failed to add %pUL to server list\n", &switch_uuid);
145 goto Away; 142 goto Away;
146 } 143 }
147 144
148 atomic_inc(&UisUtils_Registered_Services); 145 atomic_inc(&uisutils_registered_services);
149 rc = 1; /* success */ 146 rc = 1; /* success */
150Away: 147Away:
151 if (rc) { 148 if (rc) {
152 if (chipset_DriverInfo) 149 if (chipset_driver_info)
153 bus_device_info_init(chipset_DriverInfo, "chipset", 150 bus_device_info_init(chipset_driver_info, "chipset",
154 "uislib", VERSION, NULL); 151 "uislib", VERSION, NULL);
155 } else 152 } else
156 LOGERR("failed to register type %pUL.\n", &switchTypeGuid); 153 LOGERR("failed to register type %pUL.\n", &switch_uuid);
157 154
158 return rc; 155 return rc;
159} 156}
160EXPORT_SYMBOL_GPL(uisctrl_register_req_handler_ex); 157EXPORT_SYMBOL_GPL(uisctrl_register_req_handler_ex);
161 158
162int 159int
163uisctrl_unregister_req_handler_ex(uuid_le switchTypeGuid) 160uisctrl_unregister_req_handler_ex(uuid_le switch_uuid)
164{ 161{
165 int rc = 0; /* assume failure */ 162 int rc = 0; /* assume failure */
166 163
167 LOGINF("type=%pUL.\n", &switchTypeGuid); 164 LOGINF("type=%pUL.\n", &switch_uuid);
168 if (ReqHandlerDel(switchTypeGuid) < 0) { 165 if (req_handler_del(switch_uuid) < 0) {
169 LOGERR("failed to remove %pUL from server list\n", 166 LOGERR("failed to remove %pUL from server list\n",
170 &switchTypeGuid); 167 &switch_uuid);
171 goto Away; 168 goto Away;
172 } 169 }
173 atomic_dec(&UisUtils_Registered_Services); 170 atomic_dec(&uisutils_registered_services);
174 rc = 1; /* success */ 171 rc = 1; /* success */
175Away: 172Away:
176 if (!rc) 173 if (!rc)
177 LOGERR("failed to unregister type %pUL.\n", &switchTypeGuid); 174 LOGERR("failed to unregister type %pUL.\n", &switch_uuid);
178 return rc; 175 return rc;
179} 176}
180EXPORT_SYMBOL_GPL(uisctrl_unregister_req_handler_ex); 177EXPORT_SYMBOL_GPL(uisctrl_unregister_req_handler_ex);
@@ -275,11 +272,11 @@ dolist: if (skb_shinfo(skb)->frag_list) {
275} 272}
276EXPORT_SYMBOL_GPL(uisutil_copy_fragsinfo_from_skb); 273EXPORT_SYMBOL_GPL(uisutil_copy_fragsinfo_from_skb);
277 274
278static LIST_HEAD(ReqHandlerInfo_list); /* list of ReqHandlerInfo_t */ 275static LIST_HEAD(ReqHandlerInfo_list); /* list of struct req_handler_info */
279static DEFINE_SPINLOCK(ReqHandlerInfo_list_lock); 276static DEFINE_SPINLOCK(ReqHandlerInfo_list_lock);
280 277
281ReqHandlerInfo_t * 278struct req_handler_info *
282ReqHandlerAdd(uuid_le switchTypeGuid, 279req_handler_add(uuid_le switch_uuid,
283 const char *switch_type_name, 280 const char *switch_type_name,
284 int (*controlfunc)(struct io_msgs *), 281 int (*controlfunc)(struct io_msgs *),
285 unsigned long min_channel_bytes, 282 unsigned long min_channel_bytes,
@@ -287,16 +284,16 @@ ReqHandlerAdd(uuid_le switchTypeGuid,
287 int (*Server_Channel_Init) 284 int (*Server_Channel_Init)
288 (void *x, unsigned char *clientStr, u32 clientStrLen, u64 bytes)) 285 (void *x, unsigned char *clientStr, u32 clientStrLen, u64 bytes))
289{ 286{
290 ReqHandlerInfo_t *rc = NULL; 287 struct req_handler_info *rc = NULL;
291 288
292 rc = kzalloc(sizeof(*rc), GFP_ATOMIC); 289 rc = kzalloc(sizeof(*rc), GFP_ATOMIC);
293 if (!rc) 290 if (!rc)
294 return NULL; 291 return NULL;
295 rc->switchTypeGuid = switchTypeGuid; 292 rc->switch_uuid = switch_uuid;
296 rc->controlfunc = controlfunc; 293 rc->controlfunc = controlfunc;
297 rc->min_channel_bytes = min_channel_bytes; 294 rc->min_channel_bytes = min_channel_bytes;
298 rc->Server_Channel_Ok = Server_Channel_Ok; 295 rc->server_channel_ok = Server_Channel_Ok;
299 rc->Server_Channel_Init = Server_Channel_Init; 296 rc->server_channel_init = Server_Channel_Init;
300 if (switch_type_name) 297 if (switch_type_name)
301 strncpy(rc->switch_type_name, switch_type_name, 298 strncpy(rc->switch_type_name, switch_type_name,
302 sizeof(rc->switch_type_name) - 1); 299 sizeof(rc->switch_type_name) - 1);
@@ -307,16 +304,16 @@ ReqHandlerAdd(uuid_le switchTypeGuid,
307 return rc; 304 return rc;
308} 305}
309 306
310ReqHandlerInfo_t * 307struct req_handler_info *
311ReqHandlerFind(uuid_le switchTypeGuid) 308req_handler_find(uuid_le switch_uuid)
312{ 309{
313 struct list_head *lelt, *tmp; 310 struct list_head *lelt, *tmp;
314 ReqHandlerInfo_t *entry = NULL; 311 struct req_handler_info *entry = NULL;
315 312
316 spin_lock(&ReqHandlerInfo_list_lock); 313 spin_lock(&ReqHandlerInfo_list_lock);
317 list_for_each_safe(lelt, tmp, &ReqHandlerInfo_list) { 314 list_for_each_safe(lelt, tmp, &ReqHandlerInfo_list) {
318 entry = list_entry(lelt, ReqHandlerInfo_t, list_link); 315 entry = list_entry(lelt, struct req_handler_info, list_link);
319 if (uuid_le_cmp(entry->switchTypeGuid, switchTypeGuid) == 0) { 316 if (uuid_le_cmp(entry->switch_uuid, switch_uuid) == 0) {
320 spin_unlock(&ReqHandlerInfo_list_lock); 317 spin_unlock(&ReqHandlerInfo_list_lock);
321 return entry; 318 return entry;
322 } 319 }
@@ -326,16 +323,16 @@ ReqHandlerFind(uuid_le switchTypeGuid)
326} 323}
327 324
328int 325int
329ReqHandlerDel(uuid_le switchTypeGuid) 326req_handler_del(uuid_le switch_uuid)
330{ 327{
331 struct list_head *lelt, *tmp; 328 struct list_head *lelt, *tmp;
332 ReqHandlerInfo_t *entry = NULL; 329 struct req_handler_info *entry = NULL;
333 int rc = -1; 330 int rc = -1;
334 331
335 spin_lock(&ReqHandlerInfo_list_lock); 332 spin_lock(&ReqHandlerInfo_list_lock);
336 list_for_each_safe(lelt, tmp, &ReqHandlerInfo_list) { 333 list_for_each_safe(lelt, tmp, &ReqHandlerInfo_list) {
337 entry = list_entry(lelt, ReqHandlerInfo_t, list_link); 334 entry = list_entry(lelt, struct req_handler_info, list_link);
338 if (uuid_le_cmp(entry->switchTypeGuid, switchTypeGuid) == 0) { 335 if (uuid_le_cmp(entry->switch_uuid, switch_uuid) == 0) {
339 list_del(lelt); 336 list_del(lelt);
340 kfree(entry); 337 kfree(entry);
341 rc++; 338 rc++;
diff --git a/drivers/staging/unisys/virthba/virthba.c b/drivers/staging/unisys/virthba/virthba.c
index 938e2c82c1ab..d7a629b5f111 100644
--- a/drivers/staging/unisys/virthba/virthba.c
+++ b/drivers/staging/unisys/virthba/virthba.c
@@ -101,7 +101,6 @@ static DEF_SCSI_QCMD(virthba_queue_command)
101#define virthba_queue_command virthba_queue_command_lck 101#define virthba_queue_command virthba_queue_command_lck
102#endif 102#endif
103 103
104
105static int virthba_slave_alloc(struct scsi_device *scsidev); 104static int virthba_slave_alloc(struct scsi_device *scsidev);
106static int virthba_slave_configure(struct scsi_device *scsidev); 105static int virthba_slave_configure(struct scsi_device *scsidev);
107static void virthba_slave_destroy(struct scsi_device *scsidev); 106static void virthba_slave_destroy(struct scsi_device *scsidev);
@@ -172,7 +171,7 @@ struct virthba_info {
172 struct virtpci_dev *virtpcidev; 171 struct virtpci_dev *virtpcidev;
173 struct list_head dev_info_list; 172 struct list_head dev_info_list;
174 struct chaninfo chinfo; 173 struct chaninfo chinfo;
175 struct InterruptInfo intr; /* use recvInterrupt info to receive 174 struct irq_info intr; /* use recvInterrupt info to receive
176 interrupts when IOs complete */ 175 interrupts when IOs complete */
177 int interrupt_vector; 176 int interrupt_vector;
178 struct scsipending pending[MAX_PENDING_REQUESTS]; /* Tracks the requests 177 struct scsipending pending[MAX_PENDING_REQUESTS]; /* Tracks the requests
@@ -420,8 +419,8 @@ static irqreturn_t
420virthba_ISR(int irq, void *dev_id) 419virthba_ISR(int irq, void *dev_id)
421{ 420{
422 struct virthba_info *virthbainfo = (struct virthba_info *) dev_id; 421 struct virthba_info *virthbainfo = (struct virthba_info *) dev_id;
423 CHANNEL_HEADER __iomem *pChannelHeader; 422 struct channel_header __iomem *pChannelHeader;
424 SIGNAL_QUEUE_HEADER __iomem *pqhdr; 423 struct signal_queue_header __iomem *pqhdr;
425 u64 mask; 424 u64 mask;
426 unsigned long long rc1; 425 unsigned long long rc1;
427 426
@@ -429,24 +428,24 @@ virthba_ISR(int irq, void *dev_id)
429 return IRQ_NONE; 428 return IRQ_NONE;
430 virthbainfo->interrupts_rcvd++; 429 virthbainfo->interrupts_rcvd++;
431 pChannelHeader = virthbainfo->chinfo.queueinfo->chan; 430 pChannelHeader = virthbainfo->chinfo.queueinfo->chan;
432 if (((readq(&pChannelHeader->Features) 431 if (((readq(&pChannelHeader->features)
433 & ULTRA_IO_IOVM_IS_OK_WITH_DRIVER_DISABLING_INTS) != 0) 432 & ULTRA_IO_IOVM_IS_OK_WITH_DRIVER_DISABLING_INTS) != 0)
434 && ((readq(&pChannelHeader->Features) & 433 && ((readq(&pChannelHeader->features) &
435 ULTRA_IO_DRIVER_DISABLES_INTS) != 434 ULTRA_IO_DRIVER_DISABLES_INTS) !=
436 0)) { 435 0)) {
437 virthbainfo->interrupts_disabled++; 436 virthbainfo->interrupts_disabled++;
438 mask = ~ULTRA_CHANNEL_ENABLE_INTS; 437 mask = ~ULTRA_CHANNEL_ENABLE_INTS;
439 rc1 = uisqueue_interlocked_and(virthbainfo->flags_addr, mask); 438 rc1 = uisqueue_interlocked_and(virthbainfo->flags_addr, mask);
440 } 439 }
441 if (visor_signalqueue_empty(pChannelHeader, IOCHAN_FROM_IOPART)) { 440 if (spar_signalqueue_empty(pChannelHeader, IOCHAN_FROM_IOPART)) {
442 virthbainfo->interrupts_notme++; 441 virthbainfo->interrupts_notme++;
443 return IRQ_NONE; 442 return IRQ_NONE;
444 } 443 }
445 pqhdr = (SIGNAL_QUEUE_HEADER __iomem *) 444 pqhdr = (struct signal_queue_header __iomem *)
446 ((char __iomem *) pChannelHeader + 445 ((char __iomem *) pChannelHeader +
447 readq(&pChannelHeader->oChannelSpace)) + IOCHAN_FROM_IOPART; 446 readq(&pChannelHeader->ch_space_offset)) + IOCHAN_FROM_IOPART;
448 writeq(readq(&pqhdr->NumInterruptsReceived) + 1, 447 writeq(readq(&pqhdr->num_irq_received) + 1,
449 &pqhdr->NumInterruptsReceived); 448 &pqhdr->num_irq_received);
450 atomic_set(&virthbainfo->interrupt_rcvd, 1); 449 atomic_set(&virthbainfo->interrupt_rcvd, 1);
451 wake_up_interruptible(&virthbainfo->rsp_queue); 450 wake_up_interruptible(&virthbainfo->rsp_queue);
452 return IRQ_HANDLED; 451 return IRQ_HANDLED;
@@ -461,17 +460,17 @@ virthba_probe(struct virtpci_dev *virtpcidev, const struct pci_device_id *id)
461 int rsp; 460 int rsp;
462 int i; 461 int i;
463 irq_handler_t handler = virthba_ISR; 462 irq_handler_t handler = virthba_ISR;
464 CHANNEL_HEADER __iomem *pChannelHeader; 463 struct channel_header __iomem *pChannelHeader;
465 SIGNAL_QUEUE_HEADER __iomem *pqhdr; 464 struct signal_queue_header __iomem *pqhdr;
466 u64 mask; 465 u64 mask;
467 466
468 LOGVER("entering virthba_probe...\n"); 467 LOGVER("entering virthba_probe...\n");
469 LOGVER("virtpcidev busNo<<%d>>devNo<<%d>>", virtpcidev->busNo, 468 LOGVER("virtpcidev bus_no<<%d>>devNo<<%d>>", virtpcidev->bus_no,
470 virtpcidev->deviceNo); 469 virtpcidev->device_no);
471 470
472 LOGINF("entering virthba_probe...\n"); 471 LOGINF("entering virthba_probe...\n");
473 LOGINF("virtpcidev busNo<<%d>>devNo<<%d>>", virtpcidev->busNo, 472 LOGINF("virtpcidev bus_no<<%d>>devNo<<%d>>", virtpcidev->bus_no,
474 virtpcidev->deviceNo); 473 virtpcidev->device_no);
475 POSTCODE_LINUX_2(VHBA_PROBE_ENTRY_PC, POSTCODE_SEVERITY_INFO); 474 POSTCODE_LINUX_2(VHBA_PROBE_ENTRY_PC, POSTCODE_SEVERITY_INFO);
476 /* call scsi_host_alloc to register a scsi host adapter 475 /* call scsi_host_alloc to register a scsi host adapter
477 * instance - this virthba that has just been created is an 476 * instance - this virthba that has just been created is an
@@ -578,18 +577,18 @@ virthba_probe(struct virtpci_dev *virtpcidev, const struct pci_device_id *id)
578 INIT_WORK(&virthbainfo->serverdown_completion, 577 INIT_WORK(&virthbainfo->serverdown_completion,
579 virthba_serverdown_complete); 578 virthba_serverdown_complete);
580 579
581 writeq(readq(&virthbainfo->chinfo.queueinfo->chan->Features) | 580 writeq(readq(&virthbainfo->chinfo.queueinfo->chan->features) |
582 ULTRA_IO_CHANNEL_IS_POLLING, 581 ULTRA_IO_CHANNEL_IS_POLLING,
583 &virthbainfo->chinfo.queueinfo->chan->Features); 582 &virthbainfo->chinfo.queueinfo->chan->features);
584 /* start thread that will receive scsicmnd responses */ 583 /* start thread that will receive scsicmnd responses */
585 DBGINF("starting rsp thread -- queueinfo: 0x%p, threadinfo: 0x%p.\n", 584 DBGINF("starting rsp thread -- queueinfo: 0x%p, threadinfo: 0x%p.\n",
586 virthbainfo->chinfo.queueinfo, &virthbainfo->chinfo.threadinfo); 585 virthbainfo->chinfo.queueinfo, &virthbainfo->chinfo.threadinfo);
587 586
588 pChannelHeader = virthbainfo->chinfo.queueinfo->chan; 587 pChannelHeader = virthbainfo->chinfo.queueinfo->chan;
589 pqhdr = (SIGNAL_QUEUE_HEADER __iomem *) 588 pqhdr = (struct signal_queue_header __iomem *)
590 ((char __iomem *)pChannelHeader + 589 ((char __iomem *)pChannelHeader +
591 readq(&pChannelHeader->oChannelSpace)) + IOCHAN_FROM_IOPART; 590 readq(&pChannelHeader->ch_space_offset)) + IOCHAN_FROM_IOPART;
592 virthbainfo->flags_addr = &pqhdr->FeatureFlags; 591 virthbainfo->flags_addr = &pqhdr->features;
593 592
594 if (!uisthread_start(&virthbainfo->chinfo.threadinfo, 593 if (!uisthread_start(&virthbainfo->chinfo.threadinfo,
595 process_incoming_rsps, 594 process_incoming_rsps,
@@ -603,16 +602,16 @@ virthba_probe(struct virtpci_dev *virtpcidev, const struct pci_device_id *id)
603 return -ENODEV; 602 return -ENODEV;
604 } 603 }
605 LOGINF("sendInterruptHandle=0x%16llX", 604 LOGINF("sendInterruptHandle=0x%16llX",
606 virthbainfo->intr.sendInterruptHandle); 605 virthbainfo->intr.send_irq_handle);
607 LOGINF("recvInterruptHandle=0x%16llX", 606 LOGINF("recvInterruptHandle=0x%16llX",
608 virthbainfo->intr.recvInterruptHandle); 607 virthbainfo->intr.recv_irq_handle);
609 LOGINF("recvInterruptVector=0x%8X", 608 LOGINF("recvInterruptVector=0x%8X",
610 virthbainfo->intr.recvInterruptVector); 609 virthbainfo->intr.recv_irq_vector);
611 LOGINF("recvInterruptShared=0x%2X", 610 LOGINF("recvInterruptShared=0x%2X",
612 virthbainfo->intr.recvInterruptShared); 611 virthbainfo->intr.recv_irq_shared);
613 LOGINF("scsihost.hostt->name=%s", scsihost->hostt->name); 612 LOGINF("scsihost.hostt->name=%s", scsihost->hostt->name);
614 virthbainfo->interrupt_vector = 613 virthbainfo->interrupt_vector =
615 virthbainfo->intr.recvInterruptHandle & INTERRUPT_VECTOR_MASK; 614 virthbainfo->intr.recv_irq_handle & INTERRUPT_VECTOR_MASK;
616 rsp = request_irq(virthbainfo->interrupt_vector, handler, IRQF_SHARED, 615 rsp = request_irq(virthbainfo->interrupt_vector, handler, IRQF_SHARED,
617 scsihost->hostt->name, virthbainfo); 616 scsihost->hostt->name, virthbainfo);
618 if (rsp != 0) { 617 if (rsp != 0) {
@@ -622,7 +621,7 @@ virthba_probe(struct virtpci_dev *virtpcidev, const struct pci_device_id *id)
622 POSTCODE_LINUX_2(VHBA_PROBE_FAILURE_PC, POSTCODE_SEVERITY_ERR); 621 POSTCODE_LINUX_2(VHBA_PROBE_FAILURE_PC, POSTCODE_SEVERITY_ERR);
623 } else { 622 } else {
624 u64 __iomem *Features_addr = 623 u64 __iomem *Features_addr =
625 &virthbainfo->chinfo.queueinfo->chan->Features; 624 &virthbainfo->chinfo.queueinfo->chan->features;
626 LOGERR("request_irq(%d) uislib_virthba_ISR request succeeded\n", 625 LOGERR("request_irq(%d) uislib_virthba_ISR request succeeded\n",
627 virthbainfo->interrupt_vector); 626 virthbainfo->interrupt_vector);
628 mask = ~(ULTRA_IO_CHANNEL_IS_POLLING | 627 mask = ~(ULTRA_IO_CHANNEL_IS_POLLING |
@@ -649,8 +648,8 @@ virthba_remove(struct virtpci_dev *virtpcidev)
649 struct Scsi_Host *scsihost = 648 struct Scsi_Host *scsihost =
650 (struct Scsi_Host *) virtpcidev->scsi.scsihost; 649 (struct Scsi_Host *) virtpcidev->scsi.scsihost;
651 650
652 LOGINF("virtpcidev busNo<<%d>>devNo<<%d>>", virtpcidev->busNo, 651 LOGINF("virtpcidev bus_no<<%d>>devNo<<%d>>", virtpcidev->bus_no,
653 virtpcidev->deviceNo); 652 virtpcidev->device_no);
654 virthbainfo = (struct virthba_info *) scsihost->hostdata; 653 virthbainfo = (struct virthba_info *) scsihost->hostdata;
655 if (virthbainfo->interrupt_vector != -1) 654 if (virthbainfo->interrupt_vector != -1)
656 free_irq(virthbainfo->interrupt_vector, virthbainfo); 655 free_irq(virthbainfo->interrupt_vector, virthbainfo);
@@ -674,7 +673,7 @@ virthba_remove(struct virtpci_dev *virtpcidev)
674} 673}
675 674
676static int 675static int
677forward_vdiskmgmt_command(VDISK_MGMT_TYPES vdiskcmdtype, 676forward_vdiskmgmt_command(enum vdisk_mgmt_types vdiskcmdtype,
678 struct Scsi_Host *scsihost, 677 struct Scsi_Host *scsihost,
679 struct uisscsi_dest *vdest) 678 struct uisscsi_dest *vdest)
680{ 679{
@@ -738,7 +737,8 @@ forward_vdiskmgmt_command(VDISK_MGMT_TYPES vdiskcmdtype,
738/*****************************************************/ 737/*****************************************************/
739 738
740static int 739static int
741forward_taskmgmt_command(TASK_MGMT_TYPES tasktype, struct scsi_device *scsidev) 740forward_taskmgmt_command(enum task_mgmt_types tasktype,
741 struct scsi_device *scsidev)
742{ 742{
743 struct uiscmdrsp *cmdrsp; 743 struct uiscmdrsp *cmdrsp;
744 struct virthba_info *virthbainfo = 744 struct virthba_info *virthbainfo =
@@ -1142,9 +1142,9 @@ do_scsi_linuxstat(struct uiscmdrsp *cmdrsp, struct scsi_cmnd *scsicmd)
1142 scsicmd, cmdrsp->scsi.cmnd[0], 1142 scsicmd, cmdrsp->scsi.cmnd[0],
1143 scsidev->host->host_no, scsidev->id, 1143 scsidev->host->host_no, scsidev->id,
1144 scsidev->channel, scsidev->lun, 1144 scsidev->channel, scsidev->lun,
1145 cmdrsp->scsi.linuxstat, sd->Valid, sd->SenseKey, 1145 cmdrsp->scsi.linuxstat, sd->valid, sd->sense_key,
1146 sd->AdditionalSenseCode, 1146 sd->additional_sense_code,
1147 sd->AdditionalSenseCodeQualifier); 1147 sd->additional_sense_code_qualifier);
1148 if (atomic_read(&vdisk->error_count) == 1148 if (atomic_read(&vdisk->error_count) ==
1149 VIRTHBA_ERROR_COUNT) { 1149 VIRTHBA_ERROR_COUNT) {
1150 LOGERR("Throtling SCSICMD errors disk <%d:%d:%d:%llu>\n", 1150 LOGERR("Throtling SCSICMD errors disk <%d:%d:%d:%llu>\n",
@@ -1276,8 +1276,8 @@ drain_queue(struct virthba_info *virthbainfo, struct chaninfo *dc,
1276 1276
1277 while (1) { 1277 while (1) {
1278 spin_lock_irqsave(&virthbainfo->chinfo.insertlock, flags); 1278 spin_lock_irqsave(&virthbainfo->chinfo.insertlock, flags);
1279 if (!ULTRA_CHANNEL_CLIENT_ACQUIRE_OS(dc->queueinfo->chan, 1279 if (!spar_channel_client_acquire_os(dc->queueinfo->chan,
1280 "vhba", NULL)) { 1280 "vhba")) {
1281 spin_unlock_irqrestore(&virthbainfo->chinfo.insertlock, 1281 spin_unlock_irqrestore(&virthbainfo->chinfo.insertlock,
1282 flags); 1282 flags);
1283 virthbainfo->acquire_failed_cnt++; 1283 virthbainfo->acquire_failed_cnt++;
@@ -1285,8 +1285,7 @@ drain_queue(struct virthba_info *virthbainfo, struct chaninfo *dc,
1285 } 1285 }
1286 qrslt = uisqueue_get_cmdrsp(dc->queueinfo, cmdrsp, 1286 qrslt = uisqueue_get_cmdrsp(dc->queueinfo, cmdrsp,
1287 IOCHAN_FROM_IOPART); 1287 IOCHAN_FROM_IOPART);
1288 ULTRA_CHANNEL_CLIENT_RELEASE_OS(dc->queueinfo->chan, 1288 spar_channel_client_release_os(dc->queueinfo->chan, "vhba");
1289 "vhba", NULL);
1290 spin_unlock_irqrestore(&virthbainfo->chinfo.insertlock, flags); 1289 spin_unlock_irqrestore(&virthbainfo->chinfo.insertlock, flags);
1291 if (qrslt == 0) 1290 if (qrslt == 0)
1292 break; 1291 break;
@@ -1310,7 +1309,7 @@ drain_queue(struct virthba_info *virthbainfo, struct chaninfo *dc,
1310 * a Client/Guest Partition. Let's be 1309 * a Client/Guest Partition. Let's be
1311 * safe and set it to NULL now. Do 1310 * safe and set it to NULL now. Do
1312 * not use it here! */ 1311 * not use it here! */
1313 cmdrsp->disknotify.vHba = NULL; 1312 cmdrsp->disknotify.v_hba = NULL;
1314 process_disk_notify(shost, cmdrsp); 1313 process_disk_notify(shost, cmdrsp);
1315 } else if (cmdrsp->cmdtype == CMD_VDISKMGMT_TYPE) { 1314 } else if (cmdrsp->cmdtype == CMD_VDISKMGMT_TYPE) {
1316 if (!del_scsipending_entry(virthbainfo, 1315 if (!del_scsipending_entry(virthbainfo,
@@ -1323,7 +1322,6 @@ drain_queue(struct virthba_info *virthbainfo, struct chaninfo *dc,
1323 } 1322 }
1324} 1323}
1325 1324
1326
1327/* main function for the thread that waits for scsi commands to arrive 1325/* main function for the thread that waits for scsi commands to arrive
1328 * in a specified queue 1326 * in a specified queue
1329 */ 1327 */
@@ -1453,7 +1451,7 @@ static ssize_t enable_ints_write(struct file *file,
1453 if (VirtHbasOpen[i].virthbainfo != NULL) { 1451 if (VirtHbasOpen[i].virthbainfo != NULL) {
1454 virthbainfo = VirtHbasOpen[i].virthbainfo; 1452 virthbainfo = VirtHbasOpen[i].virthbainfo;
1455 Features_addr = 1453 Features_addr =
1456 &virthbainfo->chinfo.queueinfo->chan->Features; 1454 &virthbainfo->chinfo.queueinfo->chan->features;
1457 if (new_value == 1) { 1455 if (new_value == 1) {
1458 mask = ~(ULTRA_IO_CHANNEL_IS_POLLING | 1456 mask = ~(ULTRA_IO_CHANNEL_IS_POLLING |
1459 ULTRA_IO_DRIVER_DISABLES_INTS); 1457 ULTRA_IO_DRIVER_DISABLES_INTS);
@@ -1482,8 +1480,8 @@ virthba_serverup(struct virtpci_dev *virtpcidev)
1482 (struct virthba_info *) ((struct Scsi_Host *) virtpcidev->scsi. 1480 (struct virthba_info *) ((struct Scsi_Host *) virtpcidev->scsi.
1483 scsihost)->hostdata; 1481 scsihost)->hostdata;
1484 1482
1485 DBGINF("virtpcidev busNo<<%d>>devNo<<%d>>", virtpcidev->busNo, 1483 DBGINF("virtpcidev bus_no<<%d>>devNo<<%d>>", virtpcidev->bus_no,
1486 virtpcidev->deviceNo); 1484 virtpcidev->device_no);
1487 1485
1488 if (!virthbainfo->serverdown) { 1486 if (!virthbainfo->serverdown) {
1489 DBGINF("Server up message received while server is already up.\n"); 1487 DBGINF("Server up message received while server is already up.\n");
@@ -1498,9 +1496,9 @@ virthba_serverup(struct virtpci_dev *virtpcidev)
1498 /* Must transition channel to ATTACHED state BEFORE we 1496 /* Must transition channel to ATTACHED state BEFORE we
1499 * can start using the device again 1497 * can start using the device again
1500 */ 1498 */
1501 ULTRA_CHANNEL_CLIENT_TRANSITION(virthbainfo->chinfo.queueinfo->chan, 1499 SPAR_CHANNEL_CLIENT_TRANSITION(virthbainfo->chinfo.queueinfo->chan,
1502 dev_name(&virtpcidev->generic_dev), 1500 dev_name(&virtpcidev->generic_dev),
1503 CHANNELCLI_ATTACHED, NULL); 1501 CHANNELCLI_ATTACHED, NULL);
1504 1502
1505 /* Start Processing the IOVM Response Queue Again */ 1503 /* Start Processing the IOVM Response Queue Again */
1506 if (!uisthread_start(&virthbainfo->chinfo.threadinfo, 1504 if (!uisthread_start(&virthbainfo->chinfo.threadinfo,
@@ -1573,13 +1571,13 @@ virthba_serverdown_complete(struct work_struct *work)
1573 1571
1574 virtpcidev = virthbainfo->virtpcidev; 1572 virtpcidev = virthbainfo->virtpcidev;
1575 1573
1576 DBGINF("virtpcidev busNo<<%d>>devNo<<%d>>", virtpcidev->busNo, 1574 DBGINF("virtpcidev bus_no<<%d>>devNo<<%d>>", virtpcidev->bus_no,
1577 virtpcidev->deviceNo); 1575 virtpcidev->device_no);
1578 virthbainfo->serverdown = true; 1576 virthbainfo->serverdown = true;
1579 virthbainfo->serverchangingstate = false; 1577 virthbainfo->serverchangingstate = false;
1580 /* Return the ServerDown response to Command */ 1578 /* Return the ServerDown response to Command */
1581 visorchipset_device_pause_response(virtpcidev->busNo, 1579 visorchipset_device_pause_response(virtpcidev->bus_no,
1582 virtpcidev->deviceNo, 0); 1580 virtpcidev->device_no, 0);
1583} 1581}
1584 1582
1585/* As per VirtpciFunc returns 1 for success and 0 for failure */ 1583/* As per VirtpciFunc returns 1 for success and 0 for failure */
@@ -1591,8 +1589,8 @@ virthba_serverdown(struct virtpci_dev *virtpcidev, u32 state)
1591 scsihost)->hostdata; 1589 scsihost)->hostdata;
1592 1590
1593 DBGINF("virthba_serverdown"); 1591 DBGINF("virthba_serverdown");
1594 DBGINF("virtpcidev busNo<<%d>>devNo<<%d>>", virtpcidev->busNo, 1592 DBGINF("virtpcidev bus_no<<%d>>devNo<<%d>>", virtpcidev->bus_no,
1595 virtpcidev->deviceNo); 1593 virtpcidev->device_no);
1596 1594
1597 if (!virthbainfo->serverdown && !virthbainfo->serverchangingstate) { 1595 if (!virthbainfo->serverdown && !virthbainfo->serverchangingstate) {
1598 virthbainfo->serverchangingstate = true; 1596 virthbainfo->serverchangingstate = true;
diff --git a/drivers/staging/unisys/virthba/virthba.h b/drivers/staging/unisys/virthba/virthba.h
index d4b809b0c7bc..59901668d4f4 100644
--- a/drivers/staging/unisys/virthba/virthba.h
+++ b/drivers/staging/unisys/virthba/virthba.h
@@ -19,13 +19,9 @@
19 * Unisys Virtual HBA driver header 19 * Unisys Virtual HBA driver header
20 */ 20 */
21 21
22
23
24#ifndef __VIRTHBA_H__ 22#ifndef __VIRTHBA_H__
25#define __VIRTHBA_H__ 23#define __VIRTHBA_H__
26 24
27
28#define VIRTHBA_VERSION "01.00" 25#define VIRTHBA_VERSION "01.00"
29 26
30
31#endif /* __VIRTHBA_H__ */ 27#endif /* __VIRTHBA_H__ */
diff --git a/drivers/staging/unisys/virtpci/virtpci.c b/drivers/staging/unisys/virtpci/virtpci.c
index ee9f8260cd15..39b828dce503 100644
--- a/drivers/staging/unisys/virtpci/virtpci.c
+++ b/drivers/staging/unisys/virtpci/virtpci.c
@@ -50,6 +50,7 @@ struct driver_private {
50 struct module_kobject *mkobj; 50 struct module_kobject *mkobj;
51 struct device_driver *driver; 51 struct device_driver *driver;
52}; 52};
53
53#define to_driver(obj) container_of(obj, struct driver_private, kobj) 54#define to_driver(obj) container_of(obj, struct driver_private, kobj)
54 55
55/* bus_id went away in 2.6.30 - the size was 20 bytes, so we'll define 56/* bus_id went away in 2.6.30 - the size was 20 bytes, so we'll define
@@ -109,7 +110,7 @@ static int virtpci_device_probe(struct device *dev);
109static int virtpci_device_remove(struct device *dev); 110static int virtpci_device_remove(struct device *dev);
110 111
111static ssize_t info_debugfs_read(struct file *file, char __user *buf, 112static ssize_t info_debugfs_read(struct file *file, char __user *buf,
112 size_t len, loff_t *offset); 113 size_t len, loff_t *offset);
113 114
114static const struct file_operations debugfs_info_fops = { 115static const struct file_operations debugfs_info_fops = {
115 .read = info_debugfs_read, 116 .read = info_debugfs_read,
@@ -137,7 +138,7 @@ static struct device virtpci_rootbus_device = {
137}; 138};
138 139
139/* filled in with info about parent chipset driver when we register with it */ 140/* filled in with info about parent chipset driver when we register with it */
140static ULTRA_VBUS_DEVICEINFO Chipset_DriverInfo; 141static struct ultra_vbus_deviceinfo chipset_driver_info;
141 142
142static const struct sysfs_ops virtpci_driver_sysfs_ops = { 143static const struct sysfs_ops virtpci_driver_sysfs_ops = {
143 .show = virtpci_driver_attr_show, 144 .show = virtpci_driver_attr_show,
@@ -148,11 +149,11 @@ static struct kobj_type virtpci_driver_kobj_type = {
148 .sysfs_ops = &virtpci_driver_sysfs_ops, 149 .sysfs_ops = &virtpci_driver_sysfs_ops,
149}; 150};
150 151
151static struct virtpci_dev *VpcidevListHead; 152static struct virtpci_dev *vpcidev_list_head;
152static DEFINE_RWLOCK(VpcidevListLock); 153static DEFINE_RWLOCK(vpcidev_list_lock);
153 154
154/* filled in with info about this driver, wrt it servicing client busses */ 155/* filled in with info about this driver, wrt it servicing client busses */
155static ULTRA_VBUS_DEVICEINFO Bus_DriverInfo; 156static struct ultra_vbus_deviceinfo bus_driver_info;
156 157
157/*****************************************************/ 158/*****************************************************/
158/* debugfs entries */ 159/* debugfs entries */
@@ -171,13 +172,12 @@ struct virtpci_busdev {
171/*****************************************************/ 172/*****************************************************/
172 173
173static inline 174static inline
174int WAIT_FOR_IO_CHANNEL(ULTRA_IO_CHANNEL_PROTOCOL __iomem *chanptr) 175int WAIT_FOR_IO_CHANNEL(struct spar_io_channel_protocol __iomem *chanptr)
175{ 176{
176 int count = 120; 177 int count = 120;
177 178
178 while (count > 0) { 179 while (count > 0) {
179 180 if (SPAR_CHANNEL_SERVER_READY(&chanptr->channel_header))
180 if (ULTRA_CHANNEL_SERVER_READY(&chanptr->ChannelHeader))
181 return 1; 181 return 1;
182 UIS_THREAD_WAIT_SEC(1); 182 UIS_THREAD_WAIT_SEC(1);
183 count--; 183 count--;
@@ -186,8 +186,8 @@ int WAIT_FOR_IO_CHANNEL(ULTRA_IO_CHANNEL_PROTOCOL __iomem *chanptr)
186} 186}
187 187
188/* Write the contents of <info> to the ULTRA_VBUS_CHANNEL_PROTOCOL.ChpInfo. */ 188/* Write the contents of <info> to the ULTRA_VBUS_CHANNEL_PROTOCOL.ChpInfo. */
189static int write_vbus_chpInfo(ULTRA_VBUS_CHANNEL_PROTOCOL *chan, 189static int write_vbus_chp_info(struct spar_vbus_channel_protocol *chan,
190 ULTRA_VBUS_DEVICEINFO *info) 190 struct ultra_vbus_deviceinfo *info)
191{ 191{
192 int off; 192 int off;
193 193
@@ -195,18 +195,18 @@ static int write_vbus_chpInfo(ULTRA_VBUS_CHANNEL_PROTOCOL *chan,
195 LOGERR("vbus channel not present"); 195 LOGERR("vbus channel not present");
196 return -1; 196 return -1;
197 } 197 }
198 off = sizeof(ULTRA_CHANNEL_PROTOCOL) + chan->HdrInfo.chpInfoByteOffset; 198 off = sizeof(struct channel_header) + chan->hdr_info.chp_info_offset;
199 if (chan->HdrInfo.chpInfoByteOffset == 0) { 199 if (chan->hdr_info.chp_info_offset == 0) {
200 LOGERR("vbus channel not used, because chpInfoByteOffset == 0"); 200 LOGERR("vbus channel not used, because chp_info_offset == 0");
201 return -1; 201 return -1;
202 } 202 }
203 memcpy(((u8 *) (chan)) + off, info, sizeof(*info)); 203 memcpy(((u8 *)(chan)) + off, info, sizeof(*info));
204 return 0; 204 return 0;
205} 205}
206 206
207/* Write the contents of <info> to the ULTRA_VBUS_CHANNEL_PROTOCOL.BusInfo. */ 207/* Write the contents of <info> to the ULTRA_VBUS_CHANNEL_PROTOCOL.BusInfo. */
208static int write_vbus_busInfo(ULTRA_VBUS_CHANNEL_PROTOCOL *chan, 208static int write_vbus_bus_info(struct spar_vbus_channel_protocol *chan,
209 ULTRA_VBUS_DEVICEINFO *info) 209 struct ultra_vbus_deviceinfo *info)
210{ 210{
211 int off; 211 int off;
212 212
@@ -214,12 +214,12 @@ static int write_vbus_busInfo(ULTRA_VBUS_CHANNEL_PROTOCOL *chan,
214 LOGERR("vbus channel not present"); 214 LOGERR("vbus channel not present");
215 return -1; 215 return -1;
216 } 216 }
217 off = sizeof(ULTRA_CHANNEL_PROTOCOL) + chan->HdrInfo.busInfoByteOffset; 217 off = sizeof(struct channel_header) + chan->hdr_info.bus_info_offset;
218 if (chan->HdrInfo.busInfoByteOffset == 0) { 218 if (chan->hdr_info.bus_info_offset == 0) {
219 LOGERR("vbus channel not used, because busInfoByteOffset == 0"); 219 LOGERR("vbus channel not used, because bus_info_offset == 0");
220 return -1; 220 return -1;
221 } 221 }
222 memcpy(((u8 *) (chan)) + off, info, sizeof(*info)); 222 memcpy(((u8 *)(chan)) + off, info, sizeof(*info));
223 return 0; 223 return 0;
224} 224}
225 225
@@ -227,8 +227,8 @@ static int write_vbus_busInfo(ULTRA_VBUS_CHANNEL_PROTOCOL *chan,
227 * ULTRA_VBUS_CHANNEL_PROTOCOL.DevInfo[<devix>]. 227 * ULTRA_VBUS_CHANNEL_PROTOCOL.DevInfo[<devix>].
228 */ 228 */
229static int 229static int
230write_vbus_devInfo(ULTRA_VBUS_CHANNEL_PROTOCOL *chan, 230write_vbus_dev_info(struct spar_vbus_channel_protocol *chan,
231 ULTRA_VBUS_DEVICEINFO *info, int devix) 231 struct ultra_vbus_deviceinfo *info, int devix)
232{ 232{
233 int off; 233 int off;
234 234
@@ -237,14 +237,14 @@ write_vbus_devInfo(ULTRA_VBUS_CHANNEL_PROTOCOL *chan,
237 return -1; 237 return -1;
238 } 238 }
239 off = 239 off =
240 (sizeof(ULTRA_CHANNEL_PROTOCOL) + 240 (sizeof(struct channel_header) +
241 chan->HdrInfo.devInfoByteOffset) + 241 chan->hdr_info.dev_info_offset) +
242 (chan->HdrInfo.deviceInfoStructBytes * devix); 242 (chan->hdr_info.device_info_struct_bytes * devix);
243 if (chan->HdrInfo.devInfoByteOffset == 0) { 243 if (chan->hdr_info.dev_info_offset == 0) {
244 LOGERR("vbus channel not used, because devInfoByteOffset == 0"); 244 LOGERR("vbus channel not used, because dev_info_offset == 0");
245 return -1; 245 return -1;
246 } 246 }
247 memcpy(((u8 *) (chan)) + off, info, sizeof(*info)); 247 memcpy(((u8 *)(chan)) + off, info, sizeof(*info));
248 return 0; 248 return 0;
249} 249}
250 250
@@ -256,13 +256,13 @@ static int add_vbus(struct add_vbus_guestpart *addparams)
256 int ret; 256 int ret;
257 struct device *vbus; 257 struct device *vbus;
258 258
259 vbus = kzalloc(sizeof(struct device), GFP_ATOMIC); 259 vbus = kzalloc(sizeof(*vbus), GFP_ATOMIC);
260 260
261 POSTCODE_LINUX_2(VPCI_CREATE_ENTRY_PC, POSTCODE_SEVERITY_INFO); 261 POSTCODE_LINUX_2(VPCI_CREATE_ENTRY_PC, POSTCODE_SEVERITY_INFO);
262 if (!vbus) 262 if (!vbus)
263 return 0; 263 return 0;
264 264
265 dev_set_name(vbus, "vbus%d", addparams->busNo); 265 dev_set_name(vbus, "vbus%d", addparams->bus_no);
266 vbus->release = virtpci_bus_release; 266 vbus->release = virtpci_bus_release;
267 vbus->parent = &virtpci_rootbus_device; /* root bus is parent */ 267 vbus->parent = &virtpci_rootbus_device; /* root bus is parent */
268 vbus->bus = &virtpci_bus_type; /* bus type */ 268 vbus->bus = &virtpci_bus_type; /* bus type */
@@ -279,11 +279,12 @@ static int add_vbus(struct add_vbus_guestpart *addparams)
279 POSTCODE_LINUX_2(VPCI_CREATE_FAILURE_PC, POSTCODE_SEVERITY_ERR); 279 POSTCODE_LINUX_2(VPCI_CREATE_FAILURE_PC, POSTCODE_SEVERITY_ERR);
280 return 0; 280 return 0;
281 } 281 }
282 write_vbus_chpInfo(vbus->platform_data /* chanptr */ , 282 write_vbus_chp_info(vbus->platform_data /* chanptr */ ,
283 &Chipset_DriverInfo); 283 &chipset_driver_info);
284 write_vbus_busInfo(vbus->platform_data /* chanptr */ , &Bus_DriverInfo); 284 write_vbus_bus_info(vbus->platform_data /* chanptr */ ,
285 &bus_driver_info);
285 LOGINF("Added vbus %d; device %s created successfully\n", 286 LOGINF("Added vbus %d; device %s created successfully\n",
286 addparams->busNo, BUS_ID(vbus)); 287 addparams->bus_no, BUS_ID(vbus));
287 POSTCODE_LINUX_2(VPCI_CREATE_EXIT_PC, POSTCODE_SEVERITY_INFO); 288 POSTCODE_LINUX_2(VPCI_CREATE_EXIT_PC, POSTCODE_SEVERITY_INFO);
288 return 1; 289 return 1;
289} 290}
@@ -293,26 +294,15 @@ static int add_vbus(struct add_vbus_guestpart *addparams)
293 */ 294 */
294#define GET_SCSIADAPINFO_FROM_CHANPTR(chanptr) { \ 295#define GET_SCSIADAPINFO_FROM_CHANPTR(chanptr) { \
295 memcpy_fromio(&scsi.wwnn, \ 296 memcpy_fromio(&scsi.wwnn, \
296 &((ULTRA_IO_CHANNEL_PROTOCOL __iomem *) \ 297 &((struct spar_io_channel_protocol __iomem *) \
297 chanptr)->vhba.wwnn, \ 298 chanptr)->vhba.wwnn, \
298 sizeof(struct vhba_wwnn)); \ 299 sizeof(struct vhba_wwnn)); \
299 memcpy_fromio(&scsi.max, \ 300 memcpy_fromio(&scsi.max, \
300 &((ULTRA_IO_CHANNEL_PROTOCOL __iomem *) \ 301 &((struct spar_io_channel_protocol __iomem *) \
301 chanptr)->vhba.max, \ 302 chanptr)->vhba.max, \
302 sizeof(struct vhba_config_max)); \ 303 sizeof(struct vhba_config_max)); \
303 } 304 }
304 305
305/* find bus device with the busid that matches - match_busid matches bus_id */
306#define GET_BUS_DEV(busno) { \
307 sprintf(busid, "vbus%d", busno); \
308 vbus = bus_find_device(&virtpci_bus_type, NULL, \
309 (void *)busid, match_busid); \
310 if (!vbus) { \
311 LOGERR("**** FAILED to find vbus %s\n", busid); \
312 return 0; \
313 } \
314}
315
316/* adds a vhba 306/* adds a vhba
317 * returns 0 failure, 1 success, 307 * returns 0 failure, 1 success,
318 */ 308 */
@@ -325,7 +315,7 @@ static int add_vhba(struct add_virt_guestpart *addparams)
325 315
326 POSTCODE_LINUX_2(VPCI_CREATE_ENTRY_PC, POSTCODE_SEVERITY_INFO); 316 POSTCODE_LINUX_2(VPCI_CREATE_ENTRY_PC, POSTCODE_SEVERITY_INFO);
327 if (!WAIT_FOR_IO_CHANNEL 317 if (!WAIT_FOR_IO_CHANNEL
328 ((ULTRA_IO_CHANNEL_PROTOCOL __iomem *) addparams->chanptr)) { 318 ((struct spar_io_channel_protocol __iomem *)addparams->chanptr)) {
329 LOGERR("Timed out. Channel not ready\n"); 319 LOGERR("Timed out. Channel not ready\n");
330 POSTCODE_LINUX_2(VPCI_CREATE_FAILURE_PC, POSTCODE_SEVERITY_ERR); 320 POSTCODE_LINUX_2(VPCI_CREATE_FAILURE_PC, POSTCODE_SEVERITY_ERR);
331 return 0; 321 return 0;
@@ -333,7 +323,14 @@ static int add_vhba(struct add_virt_guestpart *addparams)
333 323
334 GET_SCSIADAPINFO_FROM_CHANPTR(addparams->chanptr); 324 GET_SCSIADAPINFO_FROM_CHANPTR(addparams->chanptr);
335 325
336 GET_BUS_DEV(addparams->bus_no); 326 /* find bus device with the busid that matches match_busid */
327 sprintf(busid, "vbus%d", addparams->bus_no);
328 vbus = bus_find_device(&virtpci_bus_type, NULL,
329 (void *)busid, match_busid);
330 if (!vbus) {
331 LOGERR("**** FAILED to find vbus %s\n", busid);
332 return 0;
333 }
337 334
338 LOGINF("Adding vhba wwnn:%x:%x config:%d-%d-%d-%d chanptr:%p\n", 335 LOGINF("Adding vhba wwnn:%x:%x config:%d-%d-%d-%d chanptr:%p\n",
339 scsi.wwnn.wwnn1, scsi.wwnn.wwnn2, 336 scsi.wwnn.wwnn1, scsi.wwnn.wwnn2,
@@ -347,7 +344,6 @@ static int add_vhba(struct add_virt_guestpart *addparams)
347 POSTCODE_SEVERITY_INFO); 344 POSTCODE_SEVERITY_INFO);
348 } 345 }
349 return i; 346 return i;
350
351} 347}
352 348
353/* for CHANSOCK macaddr is AUTO-GENERATED; for normal channels, 349/* for CHANSOCK macaddr is AUTO-GENERATED; for normal channels,
@@ -355,17 +351,17 @@ static int add_vhba(struct add_virt_guestpart *addparams)
355 */ 351 */
356#define GET_NETADAPINFO_FROM_CHANPTR(chanptr) { \ 352#define GET_NETADAPINFO_FROM_CHANPTR(chanptr) { \
357 memcpy_fromio(net.mac_addr, \ 353 memcpy_fromio(net.mac_addr, \
358 ((ULTRA_IO_CHANNEL_PROTOCOL __iomem *) \ 354 ((struct spar_io_channel_protocol __iomem *) \
359 chanptr)->vnic.macaddr, \ 355 chanptr)->vnic.macaddr, \
360 MAX_MACADDR_LEN); \ 356 MAX_MACADDR_LEN); \
361 net.num_rcv_bufs = \ 357 net.num_rcv_bufs = \
362 readl(&((ULTRA_IO_CHANNEL_PROTOCOL __iomem *) \ 358 readl(&((struct spar_io_channel_protocol __iomem *)\
363 chanptr)->vnic.num_rcv_bufs); \ 359 chanptr)->vnic.num_rcv_bufs); \
364 net.mtu = readl(&((ULTRA_IO_CHANNEL_PROTOCOL __iomem *) \ 360 net.mtu = readl(&((struct spar_io_channel_protocol __iomem *) \
365 chanptr)->vnic.mtu); \ 361 chanptr)->vnic.mtu); \
366 memcpy_fromio(&net.zoneGuid, \ 362 memcpy_fromio(&net.zone_uuid, \
367 &((ULTRA_IO_CHANNEL_PROTOCOL __iomem *) \ 363 &((struct spar_io_channel_protocol __iomem *)\
368 chanptr)->vnic.zoneGuid, \ 364 chanptr)->vnic.zone_uuid, \
369 sizeof(uuid_le)); \ 365 sizeof(uuid_le)); \
370} 366}
371 367
@@ -382,7 +378,7 @@ add_vnic(struct add_virt_guestpart *addparams)
382 378
383 POSTCODE_LINUX_2(VPCI_CREATE_ENTRY_PC, POSTCODE_SEVERITY_INFO); 379 POSTCODE_LINUX_2(VPCI_CREATE_ENTRY_PC, POSTCODE_SEVERITY_INFO);
384 if (!WAIT_FOR_IO_CHANNEL 380 if (!WAIT_FOR_IO_CHANNEL
385 ((ULTRA_IO_CHANNEL_PROTOCOL __iomem *) addparams->chanptr)) { 381 ((struct spar_io_channel_protocol __iomem *)addparams->chanptr)) {
386 LOGERR("Timed out, channel not ready\n"); 382 LOGERR("Timed out, channel not ready\n");
387 POSTCODE_LINUX_2(VPCI_CREATE_FAILURE_PC, POSTCODE_SEVERITY_ERR); 383 POSTCODE_LINUX_2(VPCI_CREATE_FAILURE_PC, POSTCODE_SEVERITY_ERR);
388 return 0; 384 return 0;
@@ -390,12 +386,19 @@ add_vnic(struct add_virt_guestpart *addparams)
390 386
391 GET_NETADAPINFO_FROM_CHANPTR(addparams->chanptr); 387 GET_NETADAPINFO_FROM_CHANPTR(addparams->chanptr);
392 388
393 GET_BUS_DEV(addparams->bus_no); 389 /* find bus device with the busid that matches match_busid */
390 sprintf(busid, "vbus%d", addparams->bus_no);
391 vbus = bus_find_device(&virtpci_bus_type, NULL,
392 (void *)busid, match_busid);
393 if (!vbus) {
394 LOGERR("**** FAILED to find vbus %s\n", busid);
395 return 0;
396 }
394 397
395 LOGINF("Adding vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x rcvbufs:%d mtu:%d chanptr:%p%pUL\n", 398 LOGINF("Adding vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x rcvbufs:%d mtu:%d chanptr:%p%pUL\n",
396 net.mac_addr[0], net.mac_addr[1], net.mac_addr[2], net.mac_addr[3], 399 net.mac_addr[0], net.mac_addr[1], net.mac_addr[2],
397 net.mac_addr[4], net.mac_addr[5], net.num_rcv_bufs, net.mtu, 400 net.mac_addr[3], net.mac_addr[4], net.mac_addr[5],
398 addparams->chanptr, &net.zoneGuid); 401 net.num_rcv_bufs, net.mtu, addparams->chanptr, &net.zone_uuid);
399 i = virtpci_device_add(vbus, VIRTNIC_TYPE, addparams, NULL, &net); 402 i = virtpci_device_add(vbus, VIRTNIC_TYPE, addparams, NULL, &net);
400 if (i) { 403 if (i) {
401 LOGINF("Added vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x\n", 404 LOGINF("Added vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x\n",
@@ -417,7 +420,15 @@ delete_vbus(struct del_vbus_guestpart *delparams)
417 struct device *vbus; 420 struct device *vbus;
418 unsigned char busid[BUS_ID_SIZE]; 421 unsigned char busid[BUS_ID_SIZE];
419 422
420 GET_BUS_DEV(delparams->bus_no); 423 /* find bus device with the busid that matches match_busid */
424 sprintf(busid, "vbus%d", delparams->bus_no);
425 vbus = bus_find_device(&virtpci_bus_type, NULL,
426 (void *)busid, match_busid);
427 if (!vbus) {
428 LOGERR("**** FAILED to find vbus %s\n", busid);
429 return 0;
430 }
431
421 /* ensure that bus has no devices? -- TBD */ 432 /* ensure that bus has no devices? -- TBD */
422 LOGINF("Deleting %s\n", BUS_ID(vbus)); 433 LOGINF("Deleting %s\n", BUS_ID(vbus));
423 if (delete_vbus_device(vbus, NULL)) 434 if (delete_vbus_device(vbus, NULL))
@@ -430,9 +441,9 @@ static int
430delete_vbus_device(struct device *vbus, void *data) 441delete_vbus_device(struct device *vbus, void *data)
431{ 442{
432 int checkforroot = (data != NULL); 443 int checkforroot = (data != NULL);
433 struct device *pDev = &virtpci_rootbus_device; 444 struct device *dev = &virtpci_rootbus_device;
434 445
435 if ((checkforroot) && match_busid(vbus, (void *) BUS_ID(pDev))) { 446 if ((checkforroot) && match_busid(vbus, (void *)BUS_ID(dev))) {
436 /* skip it - don't delete root bus */ 447 /* skip it - don't delete root bus */
437 LOGINF("skipping root bus\n"); 448 LOGINF("skipping root bus\n");
438 return 0; /* pretend no error */ 449 return 0; /* pretend no error */
@@ -590,10 +601,10 @@ static void delete_all(void)
590 struct virtpci_dev *tmpvpcidev, *nextvpcidev; 601 struct virtpci_dev *tmpvpcidev, *nextvpcidev;
591 602
592 /* delete the entire vhba/vnic list in one shot */ 603 /* delete the entire vhba/vnic list in one shot */
593 write_lock_irqsave(&VpcidevListLock, flags); 604 write_lock_irqsave(&vpcidev_list_lock, flags);
594 tmpvpcidev = VpcidevListHead; 605 tmpvpcidev = vpcidev_list_head;
595 VpcidevListHead = NULL; 606 vpcidev_list_head = NULL;
596 write_unlock_irqrestore(&VpcidevListLock, flags); 607 write_unlock_irqrestore(&vpcidev_list_lock, flags);
597 608
598 /* delete one vhba/vnic at a time */ 609 /* delete one vhba/vnic at a time */
599 while (tmpvpcidev) { 610 while (tmpvpcidev) {
@@ -607,24 +618,32 @@ static void delete_all(void)
607 618
608 /* now delete each vbus */ 619 /* now delete each vbus */
609 if (bus_for_each_dev 620 if (bus_for_each_dev
610 (&virtpci_bus_type, NULL, (void *) 1, delete_vbus_device)) 621 (&virtpci_bus_type, NULL, (void *)1, delete_vbus_device))
611 LOGERR("delete of all vbus failed\n"); 622 LOGERR("delete of all vbus failed\n");
612} 623}
613 624
614/* deletes all vnics or vhbas 625/* deletes all vnics or vhbas
615 * returns 0 failure, 1 success, 626 * returns 0 failure, 1 success,
616 */ 627 */
617static int delete_all_virt(VIRTPCI_DEV_TYPE devtype, struct del_vbus_guestpart *delparams) 628static int delete_all_virt(enum virtpci_dev_type devtype,
629 struct del_vbus_guestpart *delparams)
618{ 630{
619 int i; 631 int i;
620 unsigned char busid[BUS_ID_SIZE]; 632 unsigned char busid[BUS_ID_SIZE];
621 struct device *vbus; 633 struct device *vbus;
622 634
623 GET_BUS_DEV(delparams->bus_no); 635 /* find bus device with the busid that matches match_busid */
636 sprintf(busid, "vbus%d", delparams->bus_no);
637 vbus = bus_find_device(&virtpci_bus_type, NULL,
638 (void *)busid, match_busid);
639 if (!vbus) {
640 LOGERR("**** FAILED to find vbus %s\n", busid);
641 return 0;
642 }
624 643
625 if ((devtype != VIRTHBA_TYPE) && (devtype != VIRTNIC_TYPE)) { 644 if ((devtype != VIRTHBA_TYPE) && (devtype != VIRTNIC_TYPE)) {
626 LOGERR("**** FAILED to delete all devices; devtype:%d not vhba:%d or vnic:%d\n", 645 LOGERR("**** FAILED to delete all devices; devtype:%d not vhba:%d or vnic:%d\n",
627 devtype, VIRTHBA_TYPE, VIRTNIC_TYPE); 646 devtype, VIRTHBA_TYPE, VIRTNIC_TYPE);
628 return 0; 647 return 0;
629 } 648 }
630 649
@@ -694,10 +713,10 @@ virtpci_match_device(const struct pci_device_id *ids,
694{ 713{
695 while (ids->vendor || ids->subvendor || ids->class_mask) { 714 while (ids->vendor || ids->subvendor || ids->class_mask) {
696 DBGINF("ids->vendor:%x dev->vendor:%x ids->device:%x dev->device:%x\n", 715 DBGINF("ids->vendor:%x dev->vendor:%x ids->device:%x dev->device:%x\n",
697 ids->vendor, dev->vendor, ids->device, dev->device); 716 ids->vendor, dev->vendor, ids->device, dev->device);
698 717
699 if ((ids->vendor == dev->vendor) 718 if ((ids->vendor == dev->vendor) &&
700 && (ids->device == dev->device)) 719 (ids->device == dev->device))
701 return ids; 720 return ids;
702 721
703 ids++; 722 ids++;
@@ -752,15 +771,15 @@ static int virtpci_device_resume(struct device *dev)
752 771
753/* For a child device just created on a client bus, fill in 772/* For a child device just created on a client bus, fill in
754 * information about the driver that is controlling this device into 773 * information about the driver that is controlling this device into
755 * the the appropriate slot within the vbus channel of the bus 774 * the appropriate slot within the vbus channel of the bus
756 * instance. 775 * instance.
757 */ 776 */
758static void fix_vbus_devInfo(struct device *dev, int devNo, int devType, 777static void fix_vbus_dev_info(struct device *dev, int dev_no, int dev_type,
759 struct virtpci_driver *virtpcidrv) 778 struct virtpci_driver *virtpcidrv)
760{ 779{
761 struct device *vbus; 780 struct device *vbus;
762 void *pChan; 781 void *chan;
763 ULTRA_VBUS_DEVICEINFO devInfo; 782 struct ultra_vbus_deviceinfo dev_info;
764 const char *stype; 783 const char *stype;
765 784
766 if (!dev) { 785 if (!dev) {
@@ -776,12 +795,12 @@ static void fix_vbus_devInfo(struct device *dev, int devNo, int devType,
776 LOGERR("%s dev has no parent bus", __func__); 795 LOGERR("%s dev has no parent bus", __func__);
777 return; 796 return;
778 } 797 }
779 pChan = vbus->platform_data; 798 chan = vbus->platform_data;
780 if (!pChan) { 799 if (!chan) {
781 LOGERR("%s dev bus has no channel", __func__); 800 LOGERR("%s dev bus has no channel", __func__);
782 return; 801 return;
783 } 802 }
784 switch (devType) { 803 switch (dev_type) {
785 case PCI_DEVICE_ID_VIRTHBA: 804 case PCI_DEVICE_ID_VIRTHBA:
786 stype = "vHBA"; 805 stype = "vHBA";
787 break; 806 break;
@@ -792,17 +811,17 @@ static void fix_vbus_devInfo(struct device *dev, int devNo, int devType,
792 stype = "unknown"; 811 stype = "unknown";
793 break; 812 break;
794 } 813 }
795 bus_device_info_init(&devInfo, stype, 814 bus_device_info_init(&dev_info, stype,
796 virtpcidrv->name, 815 virtpcidrv->name,
797 virtpcidrv->version, 816 virtpcidrv->version,
798 virtpcidrv->vertag); 817 virtpcidrv->vertag);
799 write_vbus_devInfo(pChan, &devInfo, devNo); 818 write_vbus_dev_info(chan, &dev_info, dev_no);
800 819
801 /* Re-write bus+chipset info, because it is possible that this 820 /* Re-write bus+chipset info, because it is possible that this
802 * was previously written by our good counterpart, visorbus. 821 * was previously written by our good counterpart, visorbus.
803 */ 822 */
804 write_vbus_chpInfo(pChan, &Chipset_DriverInfo); 823 write_vbus_chp_info(chan, &chipset_driver_info);
805 write_vbus_busInfo(pChan, &Bus_DriverInfo); 824 write_vbus_bus_info(chan, &bus_driver_info);
806} 825}
807 826
808/* This function is called to query the existence of a specific device 827/* This function is called to query the existence of a specific device
@@ -842,13 +861,14 @@ static int virtpci_device_probe(struct device *dev)
842 */ 861 */
843 error = virtpcidrv->probe(virtpcidev, id); 862 error = virtpcidrv->probe(virtpcidev, id);
844 if (!error) { 863 if (!error) {
845 fix_vbus_devInfo(dev, virtpcidev->deviceNo, 864 fix_vbus_dev_info(dev, virtpcidev->device_no,
846 virtpcidev->device, virtpcidrv); 865 virtpcidev->device, virtpcidrv);
847 virtpcidev->mydriver = virtpcidrv; 866 virtpcidev->mydriver = virtpcidrv;
848 POSTCODE_LINUX_2(VPCI_PROBE_EXIT_PC, 867 POSTCODE_LINUX_2(VPCI_PROBE_EXIT_PC,
849 POSTCODE_SEVERITY_INFO); 868 POSTCODE_SEVERITY_INFO);
850 } else 869 } else {
851 put_device(dev); 870 put_device(dev);
871 }
852 } 872 }
853 POSTCODE_LINUX_2(VPCI_PROBE_FAILURE_PC, POSTCODE_SEVERITY_ERR); 873 POSTCODE_LINUX_2(VPCI_PROBE_FAILURE_PC, POSTCODE_SEVERITY_ERR);
854 return error; /* -ENODEV for probe failure */ 874 return error; /* -ENODEV for probe failure */
@@ -896,17 +916,20 @@ static void virtpci_bus_release(struct device *dev)
896/* Adapter functions */ 916/* Adapter functions */
897/*****************************************************/ 917/*****************************************************/
898 918
919/* scsi is expected to be NULL for VNIC add
920 * net is expected to be NULL for VHBA add
921 */
899static int virtpci_device_add(struct device *parentbus, int devtype, 922static int virtpci_device_add(struct device *parentbus, int devtype,
900 struct add_virt_guestpart *addparams, 923 struct add_virt_guestpart *addparams,
901 struct scsi_adap_info *scsi, /* NULL for VNIC add */ 924 struct scsi_adap_info *scsi,
902 struct net_adap_info *net /* NULL for VHBA add */) 925 struct net_adap_info *net)
903{ 926{
904 struct virtpci_dev *virtpcidev = NULL; 927 struct virtpci_dev *virtpcidev = NULL;
905 struct virtpci_dev *tmpvpcidev = NULL, *prev; 928 struct virtpci_dev *tmpvpcidev = NULL, *prev;
906 unsigned long flags; 929 unsigned long flags;
907 int ret; 930 int ret;
908 ULTRA_IO_CHANNEL_PROTOCOL __iomem *pIoChan = NULL; 931 struct spar_io_channel_protocol __iomem *io_chan = NULL;
909 struct device *pDev; 932 struct device *dev;
910 933
911 LOGINF("virtpci_device_add parentbus:%p chanptr:%p\n", parentbus, 934 LOGINF("virtpci_device_add parentbus:%p chanptr:%p\n", parentbus,
912 addparams->chanptr); 935 addparams->chanptr);
@@ -915,14 +938,14 @@ static int virtpci_device_add(struct device *parentbus, int devtype,
915 938
916 if ((devtype != VIRTHBA_TYPE) && (devtype != VIRTNIC_TYPE)) { 939 if ((devtype != VIRTHBA_TYPE) && (devtype != VIRTNIC_TYPE)) {
917 LOGERR("**** FAILED to add device; devtype:%d not vhba:%d or vnic:%d\n", 940 LOGERR("**** FAILED to add device; devtype:%d not vhba:%d or vnic:%d\n",
918 devtype, VIRTHBA_TYPE, VIRTNIC_TYPE); 941 devtype, VIRTHBA_TYPE, VIRTNIC_TYPE);
919 POSTCODE_LINUX_3(VPCI_CREATE_FAILURE_PC, devtype, 942 POSTCODE_LINUX_3(VPCI_CREATE_FAILURE_PC, devtype,
920 POSTCODE_SEVERITY_ERR); 943 POSTCODE_SEVERITY_ERR);
921 return 0; 944 return 0;
922 } 945 }
923 946
924 /* add a Virtual Device */ 947 /* add a Virtual Device */
925 virtpcidev = kzalloc(sizeof(struct virtpci_dev), GFP_ATOMIC); 948 virtpcidev = kzalloc(sizeof(*virtpcidev), GFP_ATOMIC);
926 if (virtpcidev == NULL) { 949 if (virtpcidev == NULL) {
927 LOGERR("can't add device - malloc FALLED\n"); 950 LOGERR("can't add device - malloc FALLED\n");
928 POSTCODE_LINUX_2(MALLOC_FAILURE_PC, POSTCODE_SEVERITY_ERR); 951 POSTCODE_LINUX_2(MALLOC_FAILURE_PC, POSTCODE_SEVERITY_ERR);
@@ -939,14 +962,14 @@ static int virtpci_device_add(struct device *parentbus, int devtype,
939 virtpcidev->net = *net; 962 virtpcidev->net = *net;
940 } 963 }
941 virtpcidev->vendor = PCI_VENDOR_ID_UNISYS; 964 virtpcidev->vendor = PCI_VENDOR_ID_UNISYS;
942 virtpcidev->busNo = addparams->bus_no; 965 virtpcidev->bus_no = addparams->bus_no;
943 virtpcidev->deviceNo = addparams->device_no; 966 virtpcidev->device_no = addparams->device_no;
944 967
945 virtpcidev->queueinfo.chan = addparams->chanptr; 968 virtpcidev->queueinfo.chan = addparams->chanptr;
946 virtpcidev->queueinfo.send_int_if_needed = NULL; 969 virtpcidev->queueinfo.send_int_if_needed = NULL;
947 970
948 /* Set up safe queue... */ 971 /* Set up safe queue... */
949 pIoChan = (ULTRA_IO_CHANNEL_PROTOCOL __iomem *) 972 io_chan = (struct spar_io_channel_protocol __iomem *)
950 virtpcidev->queueinfo.chan; 973 virtpcidev->queueinfo.chan;
951 974
952 virtpcidev->intr = addparams->intr; 975 virtpcidev->intr = addparams->intr;
@@ -962,8 +985,8 @@ static int virtpci_device_add(struct device *parentbus, int devtype,
962 /* add the vhba/vnic to virtpci device list - but check for 985 /* add the vhba/vnic to virtpci device list - but check for
963 * duplicate wwnn/macaddr first 986 * duplicate wwnn/macaddr first
964 */ 987 */
965 write_lock_irqsave(&VpcidevListLock, flags); 988 write_lock_irqsave(&vpcidev_list_lock, flags);
966 for (tmpvpcidev = VpcidevListHead; tmpvpcidev; 989 for (tmpvpcidev = vpcidev_list_head; tmpvpcidev;
967 tmpvpcidev = tmpvpcidev->next) { 990 tmpvpcidev = tmpvpcidev->next) {
968 if (devtype == VIRTHBA_TYPE) { 991 if (devtype == VIRTHBA_TYPE) {
969 if ((tmpvpcidev->scsi.wwnn.wwnn1 == scsi->wwnn.wwnn1) && 992 if ((tmpvpcidev->scsi.wwnn.wwnn1 == scsi->wwnn.wwnn1) &&
@@ -984,7 +1007,7 @@ static int virtpci_device_add(struct device *parentbus, int devtype,
984 /* found a vhba/vnic already in the list with same 1007 /* found a vhba/vnic already in the list with same
985 * wwnn or macaddr - reject add 1008 * wwnn or macaddr - reject add
986 */ 1009 */
987 write_unlock_irqrestore(&VpcidevListLock, flags); 1010 write_unlock_irqrestore(&vpcidev_list_lock, flags);
988 kfree(virtpcidev); 1011 kfree(virtpcidev);
989 LOGERR("**** FAILED vhba/vnic already exists in the list\n"); 1012 LOGERR("**** FAILED vhba/vnic already exists in the list\n");
990 POSTCODE_LINUX_2(VPCI_CREATE_FAILURE_PC, POSTCODE_SEVERITY_ERR); 1013 POSTCODE_LINUX_2(VPCI_CREATE_FAILURE_PC, POSTCODE_SEVERITY_ERR);
@@ -992,26 +1015,26 @@ static int virtpci_device_add(struct device *parentbus, int devtype,
992 } 1015 }
993 1016
994 /* add it at the head */ 1017 /* add it at the head */
995 if (!VpcidevListHead) 1018 if (!vpcidev_list_head) {
996 VpcidevListHead = virtpcidev; 1019 vpcidev_list_head = virtpcidev;
997 else { 1020 } else {
998 /* insert virtpcidev at the head of our linked list of 1021 /* insert virtpcidev at the head of our linked list of
999 * vpcidevs 1022 * vpcidevs
1000 */ 1023 */
1001 virtpcidev->next = VpcidevListHead; 1024 virtpcidev->next = vpcidev_list_head;
1002 VpcidevListHead = virtpcidev; 1025 vpcidev_list_head = virtpcidev;
1003 } 1026 }
1004 1027
1005 write_unlock_irqrestore(&VpcidevListLock, flags); 1028 write_unlock_irqrestore(&vpcidev_list_lock, flags);
1006 1029
1007 /* Must transition channel to ATTACHED state BEFORE 1030 /* Must transition channel to ATTACHED state BEFORE
1008 * registering the device, because polling of the channel 1031 * registering the device, because polling of the channel
1009 * queues can begin at any time after device_register(). 1032 * queues can begin at any time after device_register().
1010 */ 1033 */
1011 pDev = &virtpcidev->generic_dev; 1034 dev = &virtpcidev->generic_dev;
1012 ULTRA_CHANNEL_CLIENT_TRANSITION(addparams->chanptr, 1035 SPAR_CHANNEL_CLIENT_TRANSITION(addparams->chanptr,
1013 BUS_ID(pDev), 1036 BUS_ID(dev),
1014 CHANNELCLI_ATTACHED, NULL); 1037 CHANNELCLI_ATTACHED, NULL);
1015 1038
1016 /* don't register until device has been added to 1039 /* don't register until device has been added to
1017 * list. Otherwise, a device_unregister from this function can 1040 * list. Otherwise, a device_unregister from this function can
@@ -1031,24 +1054,24 @@ static int virtpci_device_add(struct device *parentbus, int devtype,
1031 */ 1054 */
1032 if (ret) { 1055 if (ret) {
1033 LOGERR("device_register returned %d\n", ret); 1056 LOGERR("device_register returned %d\n", ret);
1034 pDev = &virtpcidev->generic_dev; 1057 dev = &virtpcidev->generic_dev;
1035 ULTRA_CHANNEL_CLIENT_TRANSITION(addparams->chanptr, 1058 SPAR_CHANNEL_CLIENT_TRANSITION(addparams->chanptr,
1036 BUS_ID(pDev), 1059 BUS_ID(dev),
1037 CHANNELCLI_DETACHED, NULL); 1060 CHANNELCLI_DETACHED, NULL);
1038 /* remove virtpcidev, the one we just added, from the list */ 1061 /* remove virtpcidev, the one we just added, from the list */
1039 write_lock_irqsave(&VpcidevListLock, flags); 1062 write_lock_irqsave(&vpcidev_list_lock, flags);
1040 for (tmpvpcidev = VpcidevListHead, prev = NULL; 1063 for (tmpvpcidev = vpcidev_list_head, prev = NULL;
1041 tmpvpcidev; 1064 tmpvpcidev;
1042 prev = tmpvpcidev, tmpvpcidev = tmpvpcidev->next) { 1065 prev = tmpvpcidev, tmpvpcidev = tmpvpcidev->next) {
1043 if (tmpvpcidev == virtpcidev) { 1066 if (tmpvpcidev == virtpcidev) {
1044 if (prev) 1067 if (prev)
1045 prev->next = tmpvpcidev->next; 1068 prev->next = tmpvpcidev->next;
1046 else 1069 else
1047 VpcidevListHead = tmpvpcidev->next; 1070 vpcidev_list_head = tmpvpcidev->next;
1048 break; 1071 break;
1049 } 1072 }
1050 } 1073 }
1051 write_unlock_irqrestore(&VpcidevListLock, flags); 1074 write_unlock_irqrestore(&vpcidev_list_lock, flags);
1052 kfree(virtpcidev); 1075 kfree(virtpcidev);
1053 return 0; 1076 return 0;
1054 } 1077 }
@@ -1080,9 +1103,9 @@ static int virtpci_device_serverdown(struct device *parentbus,
1080 } 1103 }
1081 1104
1082 /* find the vhba or vnic in virtpci device list */ 1105 /* find the vhba or vnic in virtpci device list */
1083 write_lock_irqsave(&VpcidevListLock, flags); 1106 write_lock_irqsave(&vpcidev_list_lock, flags);
1084 1107
1085 for (tmpvpcidev = VpcidevListHead, prevvpcidev = NULL; 1108 for (tmpvpcidev = vpcidev_list_head, prevvpcidev = NULL;
1086 (tmpvpcidev && !found); 1109 (tmpvpcidev && !found);
1087 prevvpcidev = tmpvpcidev, tmpvpcidev = tmpvpcidev->next) { 1110 prevvpcidev = tmpvpcidev, tmpvpcidev = tmpvpcidev->next) {
1088 if (tmpvpcidev->devtype != devtype) 1111 if (tmpvpcidev->devtype != devtype)
@@ -1110,7 +1133,7 @@ static int virtpci_device_serverdown(struct device *parentbus,
1110 vpcidriver = tmpvpcidev->mydriver; 1133 vpcidriver = tmpvpcidev->mydriver;
1111 rc = vpcidriver->suspend(tmpvpcidev, 0); 1134 rc = vpcidriver->suspend(tmpvpcidev, 0);
1112 } 1135 }
1113 write_unlock_irqrestore(&VpcidevListLock, flags); 1136 write_unlock_irqrestore(&vpcidev_list_lock, flags);
1114 1137
1115 if (!found) { 1138 if (!found) {
1116 LOGERR("**** FAILED to find vhba/vnic in the list\n"); 1139 LOGERR("**** FAILED to find vhba/vnic in the list\n");
@@ -1139,9 +1162,9 @@ static int virtpci_device_serverup(struct device *parentbus,
1139 } 1162 }
1140 1163
1141 /* find the vhba or vnic in virtpci device list */ 1164 /* find the vhba or vnic in virtpci device list */
1142 write_lock_irqsave(&VpcidevListLock, flags); 1165 write_lock_irqsave(&vpcidev_list_lock, flags);
1143 1166
1144 for (tmpvpcidev = VpcidevListHead, prevvpcidev = NULL; 1167 for (tmpvpcidev = vpcidev_list_head, prevvpcidev = NULL;
1145 (tmpvpcidev && !found); 1168 (tmpvpcidev && !found);
1146 prevvpcidev = tmpvpcidev, tmpvpcidev = tmpvpcidev->next) { 1169 prevvpcidev = tmpvpcidev, tmpvpcidev = tmpvpcidev->next) {
1147 if (tmpvpcidev->devtype != devtype) 1170 if (tmpvpcidev->devtype != devtype)
@@ -1172,12 +1195,13 @@ static int virtpci_device_serverup(struct device *parentbus,
1172 * ever have a bus that contains NO devices, since we 1195 * ever have a bus that contains NO devices, since we
1173 * would never even get here in that case. 1196 * would never even get here in that case.
1174 */ 1197 */
1175 fix_vbus_devInfo(&tmpvpcidev->generic_dev, tmpvpcidev->deviceNo, 1198 fix_vbus_dev_info(&tmpvpcidev->generic_dev,
1176 tmpvpcidev->device, vpcidriver); 1199 tmpvpcidev->device_no,
1200 tmpvpcidev->device, vpcidriver);
1177 rc = vpcidriver->resume(tmpvpcidev); 1201 rc = vpcidriver->resume(tmpvpcidev);
1178 } 1202 }
1179 1203
1180 write_unlock_irqrestore(&VpcidevListLock, flags); 1204 write_unlock_irqrestore(&vpcidev_list_lock, flags);
1181 1205
1182 if (!found) { 1206 if (!found) {
1183 LOGERR("**** FAILED to find vhba/vnic in the list\n"); 1207 LOGERR("**** FAILED to find vhba/vnic in the list\n");
@@ -1218,8 +1242,8 @@ static int virtpci_device_del(struct device *parentbus,
1218 * device_unregister after we release the lock; otherwise we 1242 * device_unregister after we release the lock; otherwise we
1219 * encounter "schedule while atomic" 1243 * encounter "schedule while atomic"
1220 */ 1244 */
1221 write_lock_irqsave(&VpcidevListLock, flags); 1245 write_lock_irqsave(&vpcidev_list_lock, flags);
1222 for (tmpvpcidev = VpcidevListHead, prevvpcidev = NULL; tmpvpcidev;) { 1246 for (tmpvpcidev = vpcidev_list_head, prevvpcidev = NULL; tmpvpcidev;) {
1223 if (tmpvpcidev->devtype != devtype) 1247 if (tmpvpcidev->devtype != devtype)
1224 DEL_CONTINUE; 1248 DEL_CONTINUE;
1225 1249
@@ -1253,7 +1277,7 @@ static int virtpci_device_del(struct device *parentbus,
1253 /* not at head */ 1277 /* not at head */
1254 prevvpcidev->next = tmpvpcidev->next; 1278 prevvpcidev->next = tmpvpcidev->next;
1255 else 1279 else
1256 VpcidevListHead = tmpvpcidev->next; 1280 vpcidev_list_head = tmpvpcidev->next;
1257 1281
1258 /* add it to our deletelist */ 1282 /* add it to our deletelist */
1259 tmpvpcidev->next = dellist; 1283 tmpvpcidev->next = dellist;
@@ -1268,9 +1292,9 @@ static int virtpci_device_del(struct device *parentbus,
1268 if (prevvpcidev) 1292 if (prevvpcidev)
1269 tmpvpcidev = prevvpcidev->next; 1293 tmpvpcidev = prevvpcidev->next;
1270 else 1294 else
1271 tmpvpcidev = VpcidevListHead; 1295 tmpvpcidev = vpcidev_list_head;
1272 } 1296 }
1273 write_unlock_irqrestore(&VpcidevListLock, flags); 1297 write_unlock_irqrestore(&vpcidev_list_lock, flags);
1274 1298
1275 if (!all && (count == 0)) { 1299 if (!all && (count == 0)) {
1276 LOGERR("**** FAILED to find vhba/vnic in the list\n"); 1300 LOGERR("**** FAILED to find vhba/vnic in the list\n");
@@ -1425,7 +1449,7 @@ static int print_vbus(struct device *vbus, void *data)
1425} 1449}
1426 1450
1427static ssize_t info_debugfs_read(struct file *file, char __user *buf, 1451static ssize_t info_debugfs_read(struct file *file, char __user *buf,
1428 size_t len, loff_t *offset) 1452 size_t len, loff_t *offset)
1429{ 1453{
1430 ssize_t bytes_read = 0; 1454 ssize_t bytes_read = 0;
1431 int str_pos = 0; 1455 int str_pos = 0;
@@ -1446,18 +1470,19 @@ static ssize_t info_debugfs_read(struct file *file, char __user *buf,
1446 printparam.buf = vbuf; 1470 printparam.buf = vbuf;
1447 printparam.len = &len; 1471 printparam.len = &len;
1448 if (bus_for_each_dev(&virtpci_bus_type, NULL, 1472 if (bus_for_each_dev(&virtpci_bus_type, NULL,
1449 (void *) &printparam, print_vbus)) 1473 (void *)&printparam, print_vbus))
1450 LOGERR("Failed to find bus\n"); 1474 LOGERR("Failed to find bus\n");
1451 1475
1452 str_pos += scnprintf(vbuf + str_pos, len - str_pos, 1476 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1453 "\n Virtual PCI devices\n"); 1477 "\n Virtual PCI devices\n");
1454 read_lock_irqsave(&VpcidevListLock, flags); 1478 read_lock_irqsave(&vpcidev_list_lock, flags);
1455 tmpvpcidev = VpcidevListHead; 1479 tmpvpcidev = vpcidev_list_head;
1456 while (tmpvpcidev) { 1480 while (tmpvpcidev) {
1457 if (tmpvpcidev->devtype == VIRTHBA_TYPE) { 1481 if (tmpvpcidev->devtype == VIRTHBA_TYPE) {
1458 str_pos += scnprintf(vbuf + str_pos, len - str_pos, 1482 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1459 "[%d:%d] VHba:%08x:%08x max-config:%d-%d-%d-%d", 1483 "[%d:%d] VHba:%08x:%08x max-config:%d-%d-%d-%d",
1460 tmpvpcidev->busNo, tmpvpcidev->deviceNo, 1484 tmpvpcidev->bus_no,
1485 tmpvpcidev->device_no,
1461 tmpvpcidev->scsi.wwnn.wwnn1, 1486 tmpvpcidev->scsi.wwnn.wwnn1,
1462 tmpvpcidev->scsi.wwnn.wwnn2, 1487 tmpvpcidev->scsi.wwnn.wwnn2,
1463 tmpvpcidev->scsi.max.max_channel, 1488 tmpvpcidev->scsi.max.max_channel,
@@ -1467,7 +1492,8 @@ static ssize_t info_debugfs_read(struct file *file, char __user *buf,
1467 } else { 1492 } else {
1468 str_pos += scnprintf(vbuf + str_pos, len - str_pos, 1493 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1469 "[%d:%d] VNic:%02x:%02x:%02x:%02x:%02x:%02x num_rcv_bufs:%d mtu:%d", 1494 "[%d:%d] VNic:%02x:%02x:%02x:%02x:%02x:%02x num_rcv_bufs:%d mtu:%d",
1470 tmpvpcidev->busNo, tmpvpcidev->deviceNo, 1495 tmpvpcidev->bus_no,
1496 tmpvpcidev->device_no,
1471 tmpvpcidev->net.mac_addr[0], 1497 tmpvpcidev->net.mac_addr[0],
1472 tmpvpcidev->net.mac_addr[1], 1498 tmpvpcidev->net.mac_addr[1],
1473 tmpvpcidev->net.mac_addr[2], 1499 tmpvpcidev->net.mac_addr[2],
@@ -1482,7 +1508,7 @@ static ssize_t info_debugfs_read(struct file *file, char __user *buf,
1482 tmpvpcidev->queueinfo.chan); 1508 tmpvpcidev->queueinfo.chan);
1483 tmpvpcidev = tmpvpcidev->next; 1509 tmpvpcidev = tmpvpcidev->next;
1484 } 1510 }
1485 read_unlock_irqrestore(&VpcidevListLock, flags); 1511 read_unlock_irqrestore(&vpcidev_list_lock, flags);
1486 1512
1487 str_pos += scnprintf(vbuf + str_pos, len - str_pos, "\n"); 1513 str_pos += scnprintf(vbuf + str_pos, len - str_pos, "\n");
1488 bytes_read = simple_read_from_buffer(buf, len, offset, vbuf, str_pos); 1514 bytes_read = simple_read_from_buffer(buf, len, offset, vbuf, str_pos);
@@ -1498,7 +1524,6 @@ static int __init virtpci_mod_init(void)
1498{ 1524{
1499 int ret; 1525 int ret;
1500 1526
1501
1502 if (!unisys_spar_platform) 1527 if (!unisys_spar_platform)
1503 return -ENODEV; 1528 return -ENODEV;
1504 1529
@@ -1515,8 +1540,8 @@ static int __init virtpci_mod_init(void)
1515 return ret; 1540 return ret;
1516 } 1541 }
1517 DBGINF("bus_register successful\n"); 1542 DBGINF("bus_register successful\n");
1518 bus_device_info_init(&Bus_DriverInfo, "clientbus", "virtpci", 1543 bus_device_info_init(&bus_driver_info, "clientbus", "virtpci",
1519 VERSION, NULL); 1544 VERSION, NULL);
1520 1545
1521 /* create a root bus used to parent all the virtpci buses. */ 1546 /* create a root bus used to parent all the virtpci buses. */
1522 ret = device_register(&virtpci_rootbus_device); 1547 ret = device_register(&virtpci_rootbus_device);
@@ -1529,8 +1554,8 @@ static int __init virtpci_mod_init(void)
1529 } 1554 }
1530 DBGINF("device_register successful ret:%x\n", ret); 1555 DBGINF("device_register successful ret:%x\n", ret);
1531 1556
1532 if (!uisctrl_register_req_handler(2, (void *) &virtpci_ctrlchan_func, 1557 if (!uisctrl_register_req_handler(2, (void *)&virtpci_ctrlchan_func,
1533 &Chipset_DriverInfo)) { 1558 &chipset_driver_info)) {
1534 LOGERR("uisctrl_register_req_handler ****FAILED.\n"); 1559 LOGERR("uisctrl_register_req_handler ****FAILED.\n");
1535 POSTCODE_LINUX_2(VPCI_CREATE_FAILURE_PC, POSTCODE_SEVERITY_ERR); 1560 POSTCODE_LINUX_2(VPCI_CREATE_FAILURE_PC, POSTCODE_SEVERITY_ERR);
1536 device_unregister(&virtpci_rootbus_device); 1561 device_unregister(&virtpci_rootbus_device);
@@ -1539,11 +1564,11 @@ static int __init virtpci_mod_init(void)
1539 } 1564 }
1540 1565
1541 LOGINF("successfully registered virtpci_ctrlchan_func (0x%p) as callback.\n", 1566 LOGINF("successfully registered virtpci_ctrlchan_func (0x%p) as callback.\n",
1542 (void *) &virtpci_ctrlchan_func); 1567 (void *)&virtpci_ctrlchan_func);
1543 /* create debugfs directory and info file inside. */ 1568 /* create debugfs directory and info file inside. */
1544 virtpci_debugfs_dir = debugfs_create_dir("virtpci", NULL); 1569 virtpci_debugfs_dir = debugfs_create_dir("virtpci", NULL);
1545 debugfs_create_file("info", S_IRUSR, virtpci_debugfs_dir, 1570 debugfs_create_file("info", S_IRUSR, virtpci_debugfs_dir,
1546 NULL, &debugfs_info_fops); 1571 NULL, &debugfs_info_fops);
1547 LOGINF("Leaving\n"); 1572 LOGINF("Leaving\n");
1548 POSTCODE_LINUX_2(VPCI_CREATE_EXIT_PC, POSTCODE_SEVERITY_INFO); 1573 POSTCODE_LINUX_2(VPCI_CREATE_EXIT_PC, POSTCODE_SEVERITY_INFO);
1549 return 0; 1574 return 0;
@@ -1561,7 +1586,6 @@ static void __exit virtpci_mod_exit(void)
1561 bus_unregister(&virtpci_bus_type); 1586 bus_unregister(&virtpci_bus_type);
1562 debugfs_remove_recursive(virtpci_debugfs_dir); 1587 debugfs_remove_recursive(virtpci_debugfs_dir);
1563 LOGINF("Leaving\n"); 1588 LOGINF("Leaving\n");
1564
1565} 1589}
1566 1590
1567module_init(virtpci_mod_init); 1591module_init(virtpci_mod_init);
diff --git a/drivers/staging/unisys/virtpci/virtpci.h b/drivers/staging/unisys/virtpci/virtpci.h
index 6e26956c79f4..9d85f55e8169 100644
--- a/drivers/staging/unisys/virtpci/virtpci.h
+++ b/drivers/staging/unisys/virtpci/virtpci.h
@@ -42,25 +42,25 @@ struct net_adap_info {
42 u8 mac_addr[MAX_MACADDR_LEN]; 42 u8 mac_addr[MAX_MACADDR_LEN];
43 int num_rcv_bufs; 43 int num_rcv_bufs;
44 unsigned mtu; 44 unsigned mtu;
45 uuid_le zoneGuid; 45 uuid_le zone_uuid;
46}; 46};
47 47
48typedef enum { 48enum virtpci_dev_type {
49 VIRTHBA_TYPE = 0, 49 VIRTHBA_TYPE = 0,
50 VIRTNIC_TYPE = 1, 50 VIRTNIC_TYPE = 1,
51 VIRTBUS_TYPE = 6, 51 VIRTBUS_TYPE = 6,
52} VIRTPCI_DEV_TYPE; 52};
53 53
54struct virtpci_dev { 54struct virtpci_dev {
55 VIRTPCI_DEV_TYPE devtype; /* indicates type of the 55 enum virtpci_dev_type devtype; /* indicates type of the
56 * virtual pci device */ 56 * virtual pci device */
57 struct virtpci_driver *mydriver; /* which driver has allocated 57 struct virtpci_driver *mydriver; /* which driver has allocated
58 * this device */ 58 * this device */
59 unsigned short vendor; /* vendor id for device */ 59 unsigned short vendor; /* vendor id for device */
60 unsigned short device; /* device id for device */ 60 unsigned short device; /* device id for device */
61 u32 busNo; /* number of bus on which device exists */ 61 u32 bus_no; /* number of bus on which device exists */
62 u32 deviceNo; /* device's number on the bus */ 62 u32 device_no; /* device's number on the bus */
63 struct InterruptInfo intr; /* interrupt info */ 63 struct irq_info intr; /* interrupt info */
64 struct device generic_dev; /* generic device */ 64 struct device generic_dev; /* generic device */
65 union { 65 union {
66 struct scsi_adap_info scsi; 66 struct scsi_adap_info scsi;
@@ -80,15 +80,15 @@ struct virtpci_driver {
80 const struct pci_device_id *id_table; /* must be non-NULL for probe 80 const struct pci_device_id *id_table; /* must be non-NULL for probe
81 * to be called */ 81 * to be called */
82 int (*probe)(struct virtpci_dev *dev, 82 int (*probe)(struct virtpci_dev *dev,
83 const struct pci_device_id *id); /* device inserted */ 83 const struct pci_device_id *id); /* device inserted */
84 void (*remove)(struct virtpci_dev *dev); /* Device removed (NULL if 84 void (*remove)(struct virtpci_dev *dev); /* Device removed (NULL if
85 * not a hot-plug capable 85 * not a hot-plug capable
86 * driver) */ 86 * driver) */
87 int (*suspend)(struct virtpci_dev *dev, 87 int (*suspend)(struct virtpci_dev *dev,
88 u32 state); /* Device suspended */ 88 u32 state); /* Device suspended */
89 int (*resume)(struct virtpci_dev *dev); /* Device woken up */ 89 int (*resume)(struct virtpci_dev *dev); /* Device woken up */
90 int (*enable_wake)(struct virtpci_dev *dev, 90 int (*enable_wake)(struct virtpci_dev *dev,
91 u32 state, int enable); /* Enable wake event */ 91 u32 state, int enable); /* Enable wake event */
92 struct device_driver core_driver; /* VIRTPCI core fills this in */ 92 struct device_driver core_driver; /* VIRTPCI core fills this in */
93}; 93};
94 94
diff --git a/drivers/staging/unisys/visorchannel/globals.h b/drivers/staging/unisys/visorchannel/globals.h
index 07653b8dea7b..581ed83fe6d0 100644
--- a/drivers/staging/unisys/visorchannel/globals.h
+++ b/drivers/staging/unisys/visorchannel/globals.h
@@ -25,5 +25,4 @@
25 25
26#define MYDRVNAME "visorchannel" 26#define MYDRVNAME "visorchannel"
27 27
28
29#endif 28#endif
diff --git a/drivers/staging/unisys/visorchannel/visorchannel.h b/drivers/staging/unisys/visorchannel/visorchannel.h
index 9a4d7b6755d1..5061edff959a 100644
--- a/drivers/staging/unisys/visorchannel/visorchannel.h
+++ b/drivers/staging/unisys/visorchannel/visorchannel.h
@@ -66,7 +66,7 @@ char *visorchannel_id(VISORCHANNEL *channel, char *s);
66char *visorchannel_zoneid(VISORCHANNEL *channel, char *s); 66char *visorchannel_zoneid(VISORCHANNEL *channel, char *s);
67u64 visorchannel_get_clientpartition(VISORCHANNEL *channel); 67u64 visorchannel_get_clientpartition(VISORCHANNEL *channel);
68uuid_le visorchannel_get_uuid(VISORCHANNEL *channel); 68uuid_le visorchannel_get_uuid(VISORCHANNEL *channel);
69MEMREGION *visorchannel_get_memregion(VISORCHANNEL *channel); 69struct memregion *visorchannel_get_memregion(VISORCHANNEL *channel);
70char *visorchannel_uuid_id(uuid_le *guid, char *s); 70char *visorchannel_uuid_id(uuid_le *guid, char *s);
71void visorchannel_debug(VISORCHANNEL *channel, int nQueues, 71void visorchannel_debug(VISORCHANNEL *channel, int nQueues,
72 struct seq_file *seq, u32 off); 72 struct seq_file *seq, u32 off);
diff --git a/drivers/staging/unisys/visorchannel/visorchannel_funcs.c b/drivers/staging/unisys/visorchannel/visorchannel_funcs.c
index 01a44c553500..36559d5fa673 100644
--- a/drivers/staging/unisys/visorchannel/visorchannel_funcs.c
+++ b/drivers/staging/unisys/visorchannel/visorchannel_funcs.c
@@ -29,8 +29,8 @@
29#define MYDRVNAME "visorchannel" 29#define MYDRVNAME "visorchannel"
30 30
31struct VISORCHANNEL_Tag { 31struct VISORCHANNEL_Tag {
32 MEMREGION *memregion; /* from visor_memregion_create() */ 32 struct memregion *memregion; /* from visor_memregion_create() */
33 CHANNEL_HEADER chan_hdr; 33 struct channel_header chan_hdr;
34 uuid_le guid; 34 uuid_le guid;
35 ulong size; 35 ulong size;
36 BOOL needs_lock; 36 BOOL needs_lock;
@@ -38,10 +38,10 @@ struct VISORCHANNEL_Tag {
38 spinlock_t remove_lock; 38 spinlock_t remove_lock;
39 39
40 struct { 40 struct {
41 SIGNAL_QUEUE_HEADER req_queue; 41 struct signal_queue_header req_queue;
42 SIGNAL_QUEUE_HEADER rsp_queue; 42 struct signal_queue_header rsp_queue;
43 SIGNAL_QUEUE_HEADER event_queue; 43 struct signal_queue_header event_queue;
44 SIGNAL_QUEUE_HEADER ack_queue; 44 struct signal_queue_header ack_queue;
45 } safe_uis_queue; 45 } safe_uis_queue;
46}; 46};
47 47
@@ -60,7 +60,7 @@ visorchannel_create_guts(HOSTADDRESS physaddr, ulong channelBytes,
60 if (p == NULL) { 60 if (p == NULL) {
61 ERRDRV("allocation failed: (status=0)\n"); 61 ERRDRV("allocation failed: (status=0)\n");
62 rc = NULL; 62 rc = NULL;
63 goto Away; 63 goto cleanup;
64 } 64 }
65 p->memregion = NULL; 65 p->memregion = NULL;
66 p->needs_lock = needs_lock; 66 p->needs_lock = needs_lock;
@@ -70,39 +70,39 @@ visorchannel_create_guts(HOSTADDRESS physaddr, ulong channelBytes,
70 /* prepare chan_hdr (abstraction to read/write channel memory) */ 70 /* prepare chan_hdr (abstraction to read/write channel memory) */
71 if (parent == NULL) 71 if (parent == NULL)
72 p->memregion = 72 p->memregion =
73 visor_memregion_create(physaddr, sizeof(CHANNEL_HEADER)); 73 visor_memregion_create(physaddr,
74 sizeof(struct channel_header));
74 else 75 else
75 p->memregion = 76 p->memregion =
76 visor_memregion_create_overlapped(parent->memregion, 77 visor_memregion_create_overlapped(parent->memregion,
77 off, 78 off, sizeof(struct channel_header));
78 sizeof(CHANNEL_HEADER));
79 if (p->memregion == NULL) { 79 if (p->memregion == NULL) {
80 ERRDRV("visor_memregion_create failed failed: (status=0)\n"); 80 ERRDRV("visor_memregion_create failed failed: (status=0)\n");
81 rc = NULL; 81 rc = NULL;
82 goto Away; 82 goto cleanup;
83 } 83 }
84 if (visor_memregion_read(p->memregion, 0, &p->chan_hdr, 84 if (visor_memregion_read(p->memregion, 0, &p->chan_hdr,
85 sizeof(CHANNEL_HEADER)) < 0) { 85 sizeof(struct channel_header)) < 0) {
86 ERRDRV("visor_memregion_read failed: (status=0)\n"); 86 ERRDRV("visor_memregion_read failed: (status=0)\n");
87 rc = NULL; 87 rc = NULL;
88 goto Away; 88 goto cleanup;
89 } 89 }
90 if (channelBytes == 0) 90 if (channelBytes == 0)
91 /* we had better be a CLIENT of this channel */ 91 /* we had better be a CLIENT of this channel */
92 channelBytes = (ulong) p->chan_hdr.Size; 92 channelBytes = (ulong)p->chan_hdr.size;
93 if (uuid_le_cmp(guid, NULL_UUID_LE) == 0) 93 if (uuid_le_cmp(guid, NULL_UUID_LE) == 0)
94 /* we had better be a CLIENT of this channel */ 94 /* we had better be a CLIENT of this channel */
95 guid = p->chan_hdr.Type; 95 guid = p->chan_hdr.chtype;
96 if (visor_memregion_resize(p->memregion, channelBytes) < 0) { 96 if (visor_memregion_resize(p->memregion, channelBytes) < 0) {
97 ERRDRV("visor_memregion_resize failed: (status=0)\n"); 97 ERRDRV("visor_memregion_resize failed: (status=0)\n");
98 rc = NULL; 98 rc = NULL;
99 goto Away; 99 goto cleanup;
100 } 100 }
101 p->size = channelBytes; 101 p->size = channelBytes;
102 p->guid = guid; 102 p->guid = guid;
103 103
104 rc = p; 104 rc = p;
105Away: 105cleanup:
106 106
107 if (rc == NULL) { 107 if (rc == NULL) {
108 if (p != NULL) { 108 if (p != NULL) {
@@ -194,14 +194,14 @@ EXPORT_SYMBOL_GPL(visorchannel_id);
194char * 194char *
195visorchannel_zoneid(VISORCHANNEL *channel, char *s) 195visorchannel_zoneid(VISORCHANNEL *channel, char *s)
196{ 196{
197 return visorchannel_uuid_id(&channel->chan_hdr.ZoneGuid, s); 197 return visorchannel_uuid_id(&channel->chan_hdr.zone_uuid, s);
198} 198}
199EXPORT_SYMBOL_GPL(visorchannel_zoneid); 199EXPORT_SYMBOL_GPL(visorchannel_zoneid);
200 200
201HOSTADDRESS 201HOSTADDRESS
202visorchannel_get_clientpartition(VISORCHANNEL *channel) 202visorchannel_get_clientpartition(VISORCHANNEL *channel)
203{ 203{
204 return channel->chan_hdr.PartitionHandle; 204 return channel->chan_hdr.partition_handle;
205} 205}
206EXPORT_SYMBOL_GPL(visorchannel_get_clientpartition); 206EXPORT_SYMBOL_GPL(visorchannel_get_clientpartition);
207 207
@@ -212,7 +212,7 @@ visorchannel_get_uuid(VISORCHANNEL *channel)
212} 212}
213EXPORT_SYMBOL_GPL(visorchannel_get_uuid); 213EXPORT_SYMBOL_GPL(visorchannel_get_uuid);
214 214
215MEMREGION * 215struct memregion *
216visorchannel_get_memregion(VISORCHANNEL *channel) 216visorchannel_get_memregion(VISORCHANNEL *channel)
217{ 217{
218 return channel->memregion; 218 return channel->memregion;
@@ -225,8 +225,11 @@ visorchannel_read(VISORCHANNEL *channel, ulong offset,
225{ 225{
226 int rc = visor_memregion_read(channel->memregion, offset, 226 int rc = visor_memregion_read(channel->memregion, offset,
227 local, nbytes); 227 local, nbytes);
228 if ((rc >= 0) && (offset == 0) && (nbytes >= sizeof(CHANNEL_HEADER))) 228 if ((rc >= 0) && (offset == 0) &&
229 memcpy(&channel->chan_hdr, local, sizeof(CHANNEL_HEADER)); 229 (nbytes >= sizeof(struct channel_header))) {
230 memcpy(&channel->chan_hdr, local,
231 sizeof(struct channel_header));
232 }
230 return rc; 233 return rc;
231} 234}
232EXPORT_SYMBOL_GPL(visorchannel_read); 235EXPORT_SYMBOL_GPL(visorchannel_read);
@@ -235,8 +238,9 @@ int
235visorchannel_write(VISORCHANNEL *channel, ulong offset, 238visorchannel_write(VISORCHANNEL *channel, ulong offset,
236 void *local, ulong nbytes) 239 void *local, ulong nbytes)
237{ 240{
238 if (offset == 0 && nbytes >= sizeof(CHANNEL_HEADER)) 241 if (offset == 0 && nbytes >= sizeof(struct channel_header))
239 memcpy(&channel->chan_hdr, local, sizeof(CHANNEL_HEADER)); 242 memcpy(&channel->chan_hdr, local,
243 sizeof(struct channel_header));
240 return visor_memregion_write(channel->memregion, offset, local, nbytes); 244 return visor_memregion_write(channel->memregion, offset, local, nbytes);
241} 245}
242EXPORT_SYMBOL_GPL(visorchannel_write); 246EXPORT_SYMBOL_GPL(visorchannel_write);
@@ -251,7 +255,7 @@ visorchannel_clear(VISORCHANNEL *channel, ulong offset, u8 ch, ulong nbytes)
251 255
252 if (buf == NULL) { 256 if (buf == NULL) {
253 ERRDRV("%s failed memory allocation", __func__); 257 ERRDRV("%s failed memory allocation", __func__);
254 goto Away; 258 goto cleanup;
255 } 259 }
256 memset(buf, ch, bufsize); 260 memset(buf, ch, bufsize);
257 while (nbytes > 0) { 261 while (nbytes > 0) {
@@ -264,14 +268,14 @@ visorchannel_clear(VISORCHANNEL *channel, ulong offset, u8 ch, ulong nbytes)
264 buf, thisbytes); 268 buf, thisbytes);
265 if (x < 0) { 269 if (x < 0) {
266 rc = x; 270 rc = x;
267 goto Away; 271 goto cleanup;
268 } 272 }
269 written += thisbytes; 273 written += thisbytes;
270 nbytes -= thisbytes; 274 nbytes -= thisbytes;
271 } 275 }
272 rc = 0; 276 rc = 0;
273 277
274Away: 278cleanup:
275 if (buf != NULL) { 279 if (buf != NULL) {
276 vfree(buf); 280 vfree(buf);
277 buf = NULL; 281 buf = NULL;
@@ -283,7 +287,7 @@ EXPORT_SYMBOL_GPL(visorchannel_clear);
283void __iomem * 287void __iomem *
284visorchannel_get_header(VISORCHANNEL *channel) 288visorchannel_get_header(VISORCHANNEL *channel)
285{ 289{
286 return (void __iomem *) &(channel->chan_hdr); 290 return (void __iomem *)&channel->chan_hdr;
287} 291}
288EXPORT_SYMBOL_GPL(visorchannel_get_header); 292EXPORT_SYMBOL_GPL(visorchannel_get_header);
289 293
@@ -291,14 +295,15 @@ EXPORT_SYMBOL_GPL(visorchannel_get_header);
291 * channel header 295 * channel header
292 */ 296 */
293#define SIG_QUEUE_OFFSET(chan_hdr, q) \ 297#define SIG_QUEUE_OFFSET(chan_hdr, q) \
294 ((chan_hdr)->oChannelSpace + ((q) * sizeof(SIGNAL_QUEUE_HEADER))) 298 ((chan_hdr)->ch_space_offset + \
299 ((q) * sizeof(struct signal_queue_header)))
295 300
296/** Return offset of a specific queue entry (data) from the beginning of a 301/** Return offset of a specific queue entry (data) from the beginning of a
297 * channel header 302 * channel header
298 */ 303 */
299#define SIG_DATA_OFFSET(chan_hdr, q, sig_hdr, slot) \ 304#define SIG_DATA_OFFSET(chan_hdr, q, sig_hdr, slot) \
300 (SIG_QUEUE_OFFSET(chan_hdr, q) + (sig_hdr)->oSignalBase + \ 305 (SIG_QUEUE_OFFSET(chan_hdr, q) + (sig_hdr)->sig_base_offset + \
301 ((slot) * (sig_hdr)->SignalSize)) 306 ((slot) * (sig_hdr)->signal_size))
302 307
303/** Write the contents of a specific field within a SIGNAL_QUEUE_HEADER back 308/** Write the contents of a specific field within a SIGNAL_QUEUE_HEADER back
304 * into host memory 309 * into host memory
@@ -306,39 +311,42 @@ EXPORT_SYMBOL_GPL(visorchannel_get_header);
306#define SIG_WRITE_FIELD(channel, queue, sig_hdr, FIELD) \ 311#define SIG_WRITE_FIELD(channel, queue, sig_hdr, FIELD) \
307 (visor_memregion_write(channel->memregion, \ 312 (visor_memregion_write(channel->memregion, \
308 SIG_QUEUE_OFFSET(&channel->chan_hdr, queue)+ \ 313 SIG_QUEUE_OFFSET(&channel->chan_hdr, queue)+ \
309 offsetof(SIGNAL_QUEUE_HEADER, FIELD), \ 314 offsetof(struct signal_queue_header, FIELD),\
310 &((sig_hdr)->FIELD), \ 315 &((sig_hdr)->FIELD), \
311 sizeof((sig_hdr)->FIELD)) >= 0) 316 sizeof((sig_hdr)->FIELD)) >= 0)
312 317
313static BOOL 318static BOOL
314sig_read_header(VISORCHANNEL *channel, u32 queue, 319sig_read_header(VISORCHANNEL *channel, u32 queue,
315 SIGNAL_QUEUE_HEADER *sig_hdr) 320 struct signal_queue_header *sig_hdr)
316{ 321{
317 BOOL rc = FALSE; 322 BOOL rc = FALSE;
318 323
319 if (channel->chan_hdr.oChannelSpace < sizeof(CHANNEL_HEADER)) { 324 if (channel->chan_hdr.ch_space_offset < sizeof(struct channel_header)) {
320 ERRDRV("oChannelSpace too small: (status=%d)\n", rc); 325 ERRDRV("oChannelSpace too small: (status=%d)\n", rc);
321 goto Away; 326 goto cleanup;
322 } 327 }
323 328
324 /* Read the appropriate SIGNAL_QUEUE_HEADER into local memory. */ 329 /* Read the appropriate SIGNAL_QUEUE_HEADER into local memory. */
325 330
326 if (visor_memregion_read(channel->memregion, 331 if (visor_memregion_read(channel->memregion,
327 SIG_QUEUE_OFFSET(&channel->chan_hdr, queue), 332 SIG_QUEUE_OFFSET(&channel->chan_hdr, queue),
328 sig_hdr, sizeof(SIGNAL_QUEUE_HEADER)) < 0) { 333 sig_hdr,
334 sizeof(struct signal_queue_header)) < 0) {
329 ERRDRV("queue=%d SIG_QUEUE_OFFSET=%d", 335 ERRDRV("queue=%d SIG_QUEUE_OFFSET=%d",
330 queue, (int)SIG_QUEUE_OFFSET(&channel->chan_hdr, queue)); 336 queue, (int)SIG_QUEUE_OFFSET(&channel->chan_hdr, queue));
331 ERRDRV("visor_memregion_read of signal queue failed: (status=%d)\n", rc); 337 ERRDRV("visor_memregion_read of signal queue failed: (status=%d)\n",
332 goto Away; 338 rc);
339 goto cleanup;
333 } 340 }
334 rc = TRUE; 341 rc = TRUE;
335Away: 342cleanup:
336 return rc; 343 return rc;
337} 344}
338 345
339static BOOL 346static BOOL
340sig_do_data(VISORCHANNEL *channel, u32 queue, 347sig_do_data(VISORCHANNEL *channel, u32 queue,
341 SIGNAL_QUEUE_HEADER *sig_hdr, u32 slot, void *data, BOOL is_write) 348 struct signal_queue_header *sig_hdr, u32 slot, void *data,
349 BOOL is_write)
342{ 350{
343 BOOL rc = FALSE; 351 BOOL rc = FALSE;
344 int signal_data_offset = SIG_DATA_OFFSET(&channel->chan_hdr, queue, 352 int signal_data_offset = SIG_DATA_OFFSET(&channel->chan_hdr, queue,
@@ -346,53 +354,55 @@ sig_do_data(VISORCHANNEL *channel, u32 queue,
346 if (is_write) { 354 if (is_write) {
347 if (visor_memregion_write(channel->memregion, 355 if (visor_memregion_write(channel->memregion,
348 signal_data_offset, 356 signal_data_offset,
349 data, sig_hdr->SignalSize) < 0) { 357 data, sig_hdr->signal_size) < 0) {
350 ERRDRV("visor_memregion_write of signal data failed: (status=%d)\n", rc); 358 ERRDRV("visor_memregion_write of signal data failed: (status=%d)\n",
351 goto Away; 359 rc);
360 goto cleanup;
352 } 361 }
353 } else { 362 } else {
354 if (visor_memregion_read(channel->memregion, signal_data_offset, 363 if (visor_memregion_read(channel->memregion, signal_data_offset,
355 data, sig_hdr->SignalSize) < 0) { 364 data, sig_hdr->signal_size) < 0) {
356 ERRDRV("visor_memregion_read of signal data failed: (status=%d)\n", rc); 365 ERRDRV("visor_memregion_read of signal data failed: (status=%d)\n",
357 goto Away; 366 rc);
367 goto cleanup;
358 } 368 }
359 } 369 }
360 rc = TRUE; 370 rc = TRUE;
361Away: 371cleanup:
362 return rc; 372 return rc;
363} 373}
364 374
365static inline BOOL 375static inline BOOL
366sig_read_data(VISORCHANNEL *channel, u32 queue, 376sig_read_data(VISORCHANNEL *channel, u32 queue,
367 SIGNAL_QUEUE_HEADER *sig_hdr, u32 slot, void *data) 377 struct signal_queue_header *sig_hdr, u32 slot, void *data)
368{ 378{
369 return sig_do_data(channel, queue, sig_hdr, slot, data, FALSE); 379 return sig_do_data(channel, queue, sig_hdr, slot, data, FALSE);
370} 380}
371 381
372static inline BOOL 382static inline BOOL
373sig_write_data(VISORCHANNEL *channel, u32 queue, 383sig_write_data(VISORCHANNEL *channel, u32 queue,
374 SIGNAL_QUEUE_HEADER *sig_hdr, u32 slot, void *data) 384 struct signal_queue_header *sig_hdr, u32 slot, void *data)
375{ 385{
376 return sig_do_data(channel, queue, sig_hdr, slot, data, TRUE); 386 return sig_do_data(channel, queue, sig_hdr, slot, data, TRUE);
377} 387}
378 388
379static inline unsigned char 389static inline unsigned char
380safe_sig_queue_validate(pSIGNAL_QUEUE_HEADER psafe_sqh, 390safe_sig_queue_validate(struct signal_queue_header *psafe_sqh,
381 pSIGNAL_QUEUE_HEADER punsafe_sqh, 391 struct signal_queue_header *punsafe_sqh,
382 u32 *phead, u32 *ptail) 392 u32 *phead, u32 *ptail)
383{ 393{
384 if ((*phead >= psafe_sqh->MaxSignalSlots) 394 if ((*phead >= psafe_sqh->max_slots) ||
385 || (*ptail >= psafe_sqh->MaxSignalSlots)) { 395 (*ptail >= psafe_sqh->max_slots)) {
386 /* Choose 0 or max, maybe based on current tail value */ 396 /* Choose 0 or max, maybe based on current tail value */
387 *phead = 0; 397 *phead = 0;
388 *ptail = 0; 398 *ptail = 0;
389 399
390 /* Sync with client as necessary */ 400 /* Sync with client as necessary */
391 punsafe_sqh->Head = *phead; 401 punsafe_sqh->head = *phead;
392 punsafe_sqh->Tail = *ptail; 402 punsafe_sqh->tail = *ptail;
393 403
394 ERRDRV("safe_sig_queue_validate: head = 0x%x, tail = 0x%x, MaxSlots = 0x%x", 404 ERRDRV("safe_sig_queue_validate: head = 0x%x, tail = 0x%x, MaxSlots = 0x%x",
395 *phead, *ptail, psafe_sqh->MaxSignalSlots); 405 *phead, *ptail, psafe_sqh->max_slots);
396 return 0; 406 return 0;
397 } 407 }
398 return 1; 408 return 1;
@@ -402,41 +412,42 @@ BOOL
402visorchannel_signalremove(VISORCHANNEL *channel, u32 queue, void *msg) 412visorchannel_signalremove(VISORCHANNEL *channel, u32 queue, void *msg)
403{ 413{
404 BOOL rc = FALSE; 414 BOOL rc = FALSE;
405 SIGNAL_QUEUE_HEADER sig_hdr; 415 struct signal_queue_header sig_hdr;
406 416
407 if (channel->needs_lock) 417 if (channel->needs_lock)
408 spin_lock(&channel->remove_lock); 418 spin_lock(&channel->remove_lock);
409 419
410 if (!sig_read_header(channel, queue, &sig_hdr)) { 420 if (!sig_read_header(channel, queue, &sig_hdr)) {
411 rc = FALSE; 421 rc = FALSE;
412 goto Away; 422 goto cleanup;
413 } 423 }
414 if (sig_hdr.Head == sig_hdr.Tail) { 424 if (sig_hdr.head == sig_hdr.tail) {
415 rc = FALSE; /* no signals to remove */ 425 rc = FALSE; /* no signals to remove */
416 goto Away; 426 goto cleanup;
417 } 427 }
418 sig_hdr.Tail = (sig_hdr.Tail + 1) % sig_hdr.MaxSignalSlots; 428 sig_hdr.tail = (sig_hdr.tail + 1) % sig_hdr.max_slots;
419 if (!sig_read_data(channel, queue, &sig_hdr, sig_hdr.Tail, msg)) { 429 if (!sig_read_data(channel, queue, &sig_hdr, sig_hdr.tail, msg)) {
420 ERRDRV("sig_read_data failed: (status=%d)\n", rc); 430 ERRDRV("sig_read_data failed: (status=%d)\n", rc);
421 goto Away; 431 goto cleanup;
422 } 432 }
423 sig_hdr.NumSignalsReceived++; 433 sig_hdr.num_received++;
424 434
425 /* For each data field in SIGNAL_QUEUE_HEADER that was modified, 435 /* For each data field in SIGNAL_QUEUE_HEADER that was modified,
426 * update host memory. 436 * update host memory.
427 */ 437 */
428 mb(); /* required for channel synch */ 438 mb(); /* required for channel synch */
429 if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, Tail)) { 439 if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, tail)) {
430 ERRDRV("visor_memregion_write of Tail failed: (status=%d)\n", 440 ERRDRV("visor_memregion_write of Tail failed: (status=%d)\n",
431 rc); 441 rc);
432 goto Away; 442 goto cleanup;
433 } 443 }
434 if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, NumSignalsReceived)) { 444 if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, num_received)) {
435 ERRDRV("visor_memregion_write of NumSignalsReceived failed: (status=%d)\n", rc); 445 ERRDRV("visor_memregion_write of NumSignalsReceived failed: (status=%d)\n",
436 goto Away; 446 rc);
447 goto cleanup;
437 } 448 }
438 rc = TRUE; 449 rc = TRUE;
439Away: 450cleanup:
440 if (channel->needs_lock) 451 if (channel->needs_lock)
441 spin_unlock(&channel->remove_lock); 452 spin_unlock(&channel->remove_lock);
442 453
@@ -448,48 +459,50 @@ BOOL
448visorchannel_signalinsert(VISORCHANNEL *channel, u32 queue, void *msg) 459visorchannel_signalinsert(VISORCHANNEL *channel, u32 queue, void *msg)
449{ 460{
450 BOOL rc = FALSE; 461 BOOL rc = FALSE;
451 SIGNAL_QUEUE_HEADER sig_hdr; 462 struct signal_queue_header sig_hdr;
452 463
453 if (channel->needs_lock) 464 if (channel->needs_lock)
454 spin_lock(&channel->insert_lock); 465 spin_lock(&channel->insert_lock);
455 466
456 if (!sig_read_header(channel, queue, &sig_hdr)) { 467 if (!sig_read_header(channel, queue, &sig_hdr)) {
457 rc = FALSE; 468 rc = FALSE;
458 goto Away; 469 goto cleanup;
459 } 470 }
460 471
461 sig_hdr.Head = ((sig_hdr.Head + 1) % sig_hdr.MaxSignalSlots); 472 sig_hdr.head = ((sig_hdr.head + 1) % sig_hdr.max_slots);
462 if (sig_hdr.Head == sig_hdr.Tail) { 473 if (sig_hdr.head == sig_hdr.tail) {
463 sig_hdr.NumOverflows++; 474 sig_hdr.num_overflows++;
464 if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, NumOverflows)) { 475 if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, num_overflows)) {
465 ERRDRV("visor_memregion_write of NumOverflows failed: (status=%d)\n", rc); 476 ERRDRV("visor_memregion_write of NumOverflows failed: (status=%d)\n",
466 goto Away; 477 rc);
478 goto cleanup;
467 } 479 }
468 rc = FALSE; 480 rc = FALSE;
469 goto Away; 481 goto cleanup;
470 } 482 }
471 483
472 if (!sig_write_data(channel, queue, &sig_hdr, sig_hdr.Head, msg)) { 484 if (!sig_write_data(channel, queue, &sig_hdr, sig_hdr.head, msg)) {
473 ERRDRV("sig_write_data failed: (status=%d)\n", rc); 485 ERRDRV("sig_write_data failed: (status=%d)\n", rc);
474 goto Away; 486 goto cleanup;
475 } 487 }
476 sig_hdr.NumSignalsSent++; 488 sig_hdr.num_sent++;
477 489
478 /* For each data field in SIGNAL_QUEUE_HEADER that was modified, 490 /* For each data field in SIGNAL_QUEUE_HEADER that was modified,
479 * update host memory. 491 * update host memory.
480 */ 492 */
481 mb(); /* required for channel synch */ 493 mb(); /* required for channel synch */
482 if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, Head)) { 494 if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, head)) {
483 ERRDRV("visor_memregion_write of Head failed: (status=%d)\n", 495 ERRDRV("visor_memregion_write of Head failed: (status=%d)\n",
484 rc); 496 rc);
485 goto Away; 497 goto cleanup;
486 } 498 }
487 if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, NumSignalsSent)) { 499 if (!SIG_WRITE_FIELD(channel, queue, &sig_hdr, num_sent)) {
488 ERRDRV("visor_memregion_write of NumSignalsSent failed: (status=%d)\n", rc); 500 ERRDRV("visor_memregion_write of NumSignalsSent failed: (status=%d)\n",
489 goto Away; 501 rc);
502 goto cleanup;
490 } 503 }
491 rc = TRUE; 504 rc = TRUE;
492Away: 505cleanup:
493 if (channel->needs_lock) 506 if (channel->needs_lock)
494 spin_unlock(&channel->insert_lock); 507 spin_unlock(&channel->insert_lock);
495 508
@@ -497,59 +510,58 @@ Away:
497} 510}
498EXPORT_SYMBOL_GPL(visorchannel_signalinsert); 511EXPORT_SYMBOL_GPL(visorchannel_signalinsert);
499 512
500
501int 513int
502visorchannel_signalqueue_slots_avail(VISORCHANNEL *channel, u32 queue) 514visorchannel_signalqueue_slots_avail(VISORCHANNEL *channel, u32 queue)
503{ 515{
504 SIGNAL_QUEUE_HEADER sig_hdr; 516 struct signal_queue_header sig_hdr;
505 u32 slots_avail, slots_used; 517 u32 slots_avail, slots_used;
506 u32 head, tail; 518 u32 head, tail;
507 519
508 if (!sig_read_header(channel, queue, &sig_hdr)) 520 if (!sig_read_header(channel, queue, &sig_hdr))
509 return 0; 521 return 0;
510 head = sig_hdr.Head; 522 head = sig_hdr.head;
511 tail = sig_hdr.Tail; 523 tail = sig_hdr.tail;
512 if (head < tail) 524 if (head < tail)
513 head = head + sig_hdr.MaxSignalSlots; 525 head = head + sig_hdr.max_slots;
514 slots_used = (head - tail); 526 slots_used = (head - tail);
515 slots_avail = sig_hdr.MaxSignals - slots_used; 527 slots_avail = sig_hdr.max_signals - slots_used;
516 return (int) slots_avail; 528 return (int)slots_avail;
517} 529}
518EXPORT_SYMBOL_GPL(visorchannel_signalqueue_slots_avail); 530EXPORT_SYMBOL_GPL(visorchannel_signalqueue_slots_avail);
519 531
520int 532int
521visorchannel_signalqueue_max_slots(VISORCHANNEL *channel, u32 queue) 533visorchannel_signalqueue_max_slots(VISORCHANNEL *channel, u32 queue)
522{ 534{
523 SIGNAL_QUEUE_HEADER sig_hdr; 535 struct signal_queue_header sig_hdr;
524 536
525 if (!sig_read_header(channel, queue, &sig_hdr)) 537 if (!sig_read_header(channel, queue, &sig_hdr))
526 return 0; 538 return 0;
527 return (int) sig_hdr.MaxSignals; 539 return (int)sig_hdr.max_signals;
528} 540}
529EXPORT_SYMBOL_GPL(visorchannel_signalqueue_max_slots); 541EXPORT_SYMBOL_GPL(visorchannel_signalqueue_max_slots);
530 542
531static void 543static void
532sigqueue_debug(SIGNAL_QUEUE_HEADER *q, int which, struct seq_file *seq) 544sigqueue_debug(struct signal_queue_header *q, int which, struct seq_file *seq)
533{ 545{
534 seq_printf(seq, "Signal Queue #%d\n", which); 546 seq_printf(seq, "Signal Queue #%d\n", which);
535 seq_printf(seq, " VersionId = %lu\n", (ulong) q->VersionId); 547 seq_printf(seq, " VersionId = %lu\n", (ulong)q->version);
536 seq_printf(seq, " Type = %lu\n", (ulong) q->Type); 548 seq_printf(seq, " Type = %lu\n", (ulong)q->chtype);
537 seq_printf(seq, " oSignalBase = %llu\n", 549 seq_printf(seq, " oSignalBase = %llu\n",
538 (long long) q->oSignalBase); 550 (long long)q->sig_base_offset);
539 seq_printf(seq, " SignalSize = %lu\n", (ulong) q->SignalSize); 551 seq_printf(seq, " SignalSize = %lu\n", (ulong)q->signal_size);
540 seq_printf(seq, " MaxSignalSlots = %lu\n", 552 seq_printf(seq, " MaxSignalSlots = %lu\n",
541 (ulong) q->MaxSignalSlots); 553 (ulong)q->max_slots);
542 seq_printf(seq, " MaxSignals = %lu\n", (ulong) q->MaxSignals); 554 seq_printf(seq, " MaxSignals = %lu\n", (ulong)q->max_signals);
543 seq_printf(seq, " FeatureFlags = %-16.16Lx\n", 555 seq_printf(seq, " FeatureFlags = %-16.16Lx\n",
544 (long long) q->FeatureFlags); 556 (long long)q->features);
545 seq_printf(seq, " NumSignalsSent = %llu\n", 557 seq_printf(seq, " NumSignalsSent = %llu\n",
546 (long long) q->NumSignalsSent); 558 (long long)q->num_sent);
547 seq_printf(seq, " NumSignalsReceived = %llu\n", 559 seq_printf(seq, " NumSignalsReceived = %llu\n",
548 (long long) q->NumSignalsReceived); 560 (long long)q->num_received);
549 seq_printf(seq, " NumOverflows = %llu\n", 561 seq_printf(seq, " NumOverflows = %llu\n",
550 (long long) q->NumOverflows); 562 (long long)q->num_overflows);
551 seq_printf(seq, " Head = %lu\n", (ulong) q->Head); 563 seq_printf(seq, " Head = %lu\n", (ulong)q->head);
552 seq_printf(seq, " Tail = %lu\n", (ulong) q->Tail); 564 seq_printf(seq, " Tail = %lu\n", (ulong)q->tail);
553} 565}
554 566
555void 567void
@@ -558,9 +570,9 @@ visorchannel_debug(VISORCHANNEL *channel, int nQueues,
558{ 570{
559 HOSTADDRESS addr = 0; 571 HOSTADDRESS addr = 0;
560 ulong nbytes = 0, nbytes_region = 0; 572 ulong nbytes = 0, nbytes_region = 0;
561 MEMREGION *memregion = NULL; 573 struct memregion *memregion = NULL;
562 CHANNEL_HEADER hdr; 574 struct channel_header hdr;
563 CHANNEL_HEADER *phdr = &hdr; 575 struct channel_header *phdr = &hdr;
564 int i = 0; 576 int i = 0;
565 int errcode = 0; 577 int errcode = 0;
566 578
@@ -576,7 +588,7 @@ visorchannel_debug(VISORCHANNEL *channel, int nQueues,
576 addr = visor_memregion_get_physaddr(memregion); 588 addr = visor_memregion_get_physaddr(memregion);
577 nbytes_region = visor_memregion_get_nbytes(memregion); 589 nbytes_region = visor_memregion_get_nbytes(memregion);
578 errcode = visorchannel_read(channel, off, 590 errcode = visorchannel_read(channel, off,
579 phdr, sizeof(CHANNEL_HEADER)); 591 phdr, sizeof(struct channel_header));
580 if (errcode < 0) { 592 if (errcode < 0) {
581 seq_printf(seq, 593 seq_printf(seq,
582 "Read of channel header failed with errcode=%d)\n", 594 "Read of channel header failed with errcode=%d)\n",
@@ -584,39 +596,41 @@ visorchannel_debug(VISORCHANNEL *channel, int nQueues,
584 if (off == 0) { 596 if (off == 0) {
585 phdr = &channel->chan_hdr; 597 phdr = &channel->chan_hdr;
586 seq_puts(seq, "(following data may be stale)\n"); 598 seq_puts(seq, "(following data may be stale)\n");
587 } else 599 } else {
588 return; 600 return;
601 }
589 } 602 }
590 nbytes = (ulong) (phdr->Size); 603 nbytes = (ulong)(phdr->size);
591 seq_printf(seq, "--- Begin channel @0x%-16.16Lx for 0x%lx bytes (region=0x%lx bytes) ---\n", 604 seq_printf(seq, "--- Begin channel @0x%-16.16Lx for 0x%lx bytes (region=0x%lx bytes) ---\n",
592 addr + off, nbytes, nbytes_region); 605 addr + off, nbytes, nbytes_region);
593 seq_printf(seq, "Type = %pUL\n", &phdr->Type); 606 seq_printf(seq, "Type = %pUL\n", &phdr->chtype);
594 seq_printf(seq, "ZoneGuid = %pUL\n", &phdr->ZoneGuid); 607 seq_printf(seq, "ZoneGuid = %pUL\n", &phdr->zone_uuid);
595 seq_printf(seq, "Signature = 0x%-16.16Lx\n", 608 seq_printf(seq, "Signature = 0x%-16.16Lx\n",
596 (long long) phdr->Signature); 609 (long long)phdr->signature);
597 seq_printf(seq, "LegacyState = %lu\n", (ulong) phdr->LegacyState); 610 seq_printf(seq, "LegacyState = %lu\n", (ulong)phdr->legacy_state);
598 seq_printf(seq, "SrvState = %lu\n", (ulong) phdr->SrvState); 611 seq_printf(seq, "SrvState = %lu\n", (ulong)phdr->srv_state);
599 seq_printf(seq, "CliStateBoot = %lu\n", (ulong) phdr->CliStateBoot); 612 seq_printf(seq, "CliStateBoot = %lu\n", (ulong)phdr->cli_state_boot);
600 seq_printf(seq, "CliStateOS = %lu\n", (ulong) phdr->CliStateOS); 613 seq_printf(seq, "CliStateOS = %lu\n", (ulong)phdr->cli_state_os);
601 seq_printf(seq, "HeaderSize = %lu\n", (ulong) phdr->HeaderSize); 614 seq_printf(seq, "HeaderSize = %lu\n", (ulong)phdr->header_size);
602 seq_printf(seq, "Size = %llu\n", (long long) phdr->Size); 615 seq_printf(seq, "Size = %llu\n", (long long)phdr->size);
603 seq_printf(seq, "Features = 0x%-16.16llx\n", 616 seq_printf(seq, "Features = 0x%-16.16llx\n",
604 (long long) phdr->Features); 617 (long long)phdr->features);
605 seq_printf(seq, "PartitionHandle = 0x%-16.16llx\n", 618 seq_printf(seq, "PartitionHandle = 0x%-16.16llx\n",
606 (long long) phdr->PartitionHandle); 619 (long long)phdr->partition_handle);
607 seq_printf(seq, "Handle = 0x%-16.16llx\n", 620 seq_printf(seq, "Handle = 0x%-16.16llx\n",
608 (long long) phdr->Handle); 621 (long long)phdr->handle);
609 seq_printf(seq, "VersionId = %lu\n", (ulong) phdr->VersionId); 622 seq_printf(seq, "VersionId = %lu\n", (ulong)phdr->version_id);
610 seq_printf(seq, "oChannelSpace = %llu\n", 623 seq_printf(seq, "oChannelSpace = %llu\n",
611 (long long) phdr->oChannelSpace); 624 (long long)phdr->ch_space_offset);
612 if ((phdr->oChannelSpace == 0) || (errcode < 0)) 625 if ((phdr->ch_space_offset == 0) || (errcode < 0))
613 ; 626 ;
614 else 627 else
615 for (i = 0; i < nQueues; i++) { 628 for (i = 0; i < nQueues; i++) {
616 SIGNAL_QUEUE_HEADER q; 629 struct signal_queue_header q;
617 630
618 errcode = visorchannel_read(channel, 631 errcode = visorchannel_read(channel,
619 off + phdr->oChannelSpace + 632 off +
633 phdr->ch_space_offset +
620 (i * sizeof(q)), 634 (i * sizeof(q)),
621 &q, sizeof(q)); 635 &q, sizeof(q));
622 if (errcode < 0) { 636 if (errcode < 0) {
@@ -643,15 +657,17 @@ visorchannel_dump_section(VISORCHANNEL *chan, char *s,
643 657
644 fmtbufsize = 100 * COVQ(len, 16); 658 fmtbufsize = 100 * COVQ(len, 16);
645 buf = kmalloc(len, GFP_KERNEL|__GFP_NORETRY); 659 buf = kmalloc(len, GFP_KERNEL|__GFP_NORETRY);
660 if (!buf)
661 return;
646 fmtbuf = kmalloc(fmtbufsize, GFP_KERNEL|__GFP_NORETRY); 662 fmtbuf = kmalloc(fmtbufsize, GFP_KERNEL|__GFP_NORETRY);
647 if (buf == NULL || fmtbuf == NULL) 663 if (!fmtbuf)
648 goto Away; 664 goto fmt_failed;
649 665
650 errcode = visorchannel_read(chan, off, buf, len); 666 errcode = visorchannel_read(chan, off, buf, len);
651 if (errcode < 0) { 667 if (errcode < 0) {
652 ERRDRV("%s failed to read %s from channel errcode=%d", 668 ERRDRV("%s failed to read %s from channel errcode=%d",
653 s, __func__, errcode); 669 s, __func__, errcode);
654 goto Away; 670 goto read_failed;
655 } 671 }
656 seq_printf(seq, "channel %s:\n", s); 672 seq_printf(seq, "channel %s:\n", s);
657 tbuf = buf; 673 tbuf = buf;
@@ -663,14 +679,9 @@ visorchannel_dump_section(VISORCHANNEL *chan, char *s,
663 len -= 16; 679 len -= 16;
664 } 680 }
665 681
666Away: 682read_failed:
667 if (buf != NULL) { 683 kfree(fmtbuf);
668 kfree(buf); 684fmt_failed:
669 buf = NULL; 685 kfree(buf);
670 }
671 if (fmtbuf != NULL) {
672 kfree(fmtbuf);
673 fmtbuf = NULL;
674 }
675} 686}
676EXPORT_SYMBOL_GPL(visorchannel_dump_section); 687EXPORT_SYMBOL_GPL(visorchannel_dump_section);
diff --git a/drivers/staging/unisys/visorchipset/file.c b/drivers/staging/unisys/visorchipset/file.c
index 3321764069de..373fa36b7119 100644
--- a/drivers/staging/unisys/visorchipset/file.c
+++ b/drivers/staging/unisys/visorchipset/file.c
@@ -155,9 +155,9 @@ visorchipset_mmap(struct file *file, struct vm_area_struct *vma)
155 return -ENXIO; 155 return -ENXIO;
156 } 156 }
157 visorchannel_read(*PControlVm_channel, 157 visorchannel_read(*PControlVm_channel,
158 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL, 158 offsetof(struct spar_controlvm_channel_protocol,
159 gpControlChannel), &addr, 159 gp_control_channel),
160 sizeof(addr)); 160 &addr, sizeof(addr));
161 if (addr == 0) { 161 if (addr == 0) {
162 ERRDRV("%s control channel address is 0", __func__); 162 ERRDRV("%s control channel address is 0", __func__);
163 return -ENXIO; 163 return -ENXIO;
diff --git a/drivers/staging/unisys/visorchipset/parser.c b/drivers/staging/unisys/visorchipset/parser.c
index 661aaae9b154..9edbd3bbd186 100644
--- a/drivers/staging/unisys/visorchipset/parser.c
+++ b/drivers/staging/unisys/visorchipset/parser.c
@@ -47,8 +47,8 @@ parser_init_guts(u64 addr, u32 bytes, BOOL isLocal,
47 int allocbytes = sizeof(PARSER_CONTEXT) + bytes; 47 int allocbytes = sizeof(PARSER_CONTEXT) + bytes;
48 PARSER_CONTEXT *rc = NULL; 48 PARSER_CONTEXT *rc = NULL;
49 PARSER_CONTEXT *ctx = NULL; 49 PARSER_CONTEXT *ctx = NULL;
50 MEMREGION *rgn = NULL; 50 struct memregion *rgn = NULL;
51 ULTRA_CONTROLVM_PARAMETERS_HEADER *phdr = NULL; 51 struct spar_controlvm_parameters_header *phdr = NULL;
52 52
53 if (tryAgain) 53 if (tryAgain)
54 *tryAgain = FALSE; 54 *tryAgain = FALSE;
@@ -110,27 +110,29 @@ parser_init_guts(u64 addr, u32 bytes, BOOL isLocal,
110 rc = ctx; 110 rc = ctx;
111 goto Away; 111 goto Away;
112 } 112 }
113 phdr = (ULTRA_CONTROLVM_PARAMETERS_HEADER *) (ctx->data); 113 phdr = (struct spar_controlvm_parameters_header *)(ctx->data);
114 if (phdr->TotalLength != bytes) { 114 if (phdr->total_length != bytes) {
115 ERRDRV("%s - bad total length %lu (should be %lu)", 115 ERRDRV("%s - bad total length %lu (should be %lu)",
116 __func__, 116 __func__,
117 (ulong) (phdr->TotalLength), (ulong) (bytes)); 117 (ulong) (phdr->total_length), (ulong) (bytes));
118 rc = NULL; 118 rc = NULL;
119 goto Away; 119 goto Away;
120 } 120 }
121 if (phdr->TotalLength < phdr->HeaderLength) { 121 if (phdr->total_length < phdr->header_length) {
122 ERRDRV("%s - total length < header length (%lu < %lu)", 122 ERRDRV("%s - total length < header length (%lu < %lu)",
123 __func__, 123 __func__,
124 (ulong) (phdr->TotalLength), 124 (ulong) (phdr->total_length),
125 (ulong) (phdr->HeaderLength)); 125 (ulong) (phdr->header_length));
126 rc = NULL; 126 rc = NULL;
127 goto Away; 127 goto Away;
128 } 128 }
129 if (phdr->HeaderLength < sizeof(ULTRA_CONTROLVM_PARAMETERS_HEADER)) { 129 if (phdr->header_length <
130 sizeof(struct spar_controlvm_parameters_header)) {
130 ERRDRV("%s - header is too small (%lu < %lu)", 131 ERRDRV("%s - header is too small (%lu < %lu)",
131 __func__, 132 __func__,
132 (ulong) (phdr->HeaderLength), 133 (ulong) (phdr->header_length),
133 (ulong) (sizeof(ULTRA_CONTROLVM_PARAMETERS_HEADER))); 134 (ulong)(sizeof(
135 struct spar_controlvm_parameters_header)));
134 rc = NULL; 136 rc = NULL;
135 goto Away; 137 goto Away;
136 } 138 }
@@ -159,7 +161,7 @@ parser_init(u64 addr, u32 bytes, BOOL isLocal, BOOL *tryAgain)
159} 161}
160 162
161/* Call this instead of parser_init() if the payload area consists of just 163/* Call this instead of parser_init() if the payload area consists of just
162 * a sequence of bytes, rather than a ULTRA_CONTROLVM_PARAMETERS_HEADER 164 * a sequence of bytes, rather than a struct spar_controlvm_parameters_header
163 * structures. Afterwards, you can call parser_simpleString_get() or 165 * structures. Afterwards, you can call parser_simpleString_get() or
164 * parser_byteStream_get() to obtain the data. 166 * parser_byteStream_get() to obtain the data.
165 */ 167 */
@@ -196,44 +198,44 @@ parser_byteStream_get(PARSER_CONTEXT *ctx, ulong *nbytes)
196uuid_le 198uuid_le
197parser_id_get(PARSER_CONTEXT *ctx) 199parser_id_get(PARSER_CONTEXT *ctx)
198{ 200{
199 ULTRA_CONTROLVM_PARAMETERS_HEADER *phdr = NULL; 201 struct spar_controlvm_parameters_header *phdr = NULL;
200 202
201 if (ctx == NULL) { 203 if (ctx == NULL) {
202 ERRDRV("%s (%s:%d) - no context", 204 ERRDRV("%s (%s:%d) - no context",
203 __func__, __FILE__, __LINE__); 205 __func__, __FILE__, __LINE__);
204 return NULL_UUID_LE; 206 return NULL_UUID_LE;
205 } 207 }
206 phdr = (ULTRA_CONTROLVM_PARAMETERS_HEADER *) (ctx->data); 208 phdr = (struct spar_controlvm_parameters_header *)(ctx->data);
207 return phdr->Id; 209 return phdr->id;
208} 210}
209 211
210void 212void
211parser_param_start(PARSER_CONTEXT *ctx, PARSER_WHICH_STRING which_string) 213parser_param_start(PARSER_CONTEXT *ctx, PARSER_WHICH_STRING which_string)
212{ 214{
213 ULTRA_CONTROLVM_PARAMETERS_HEADER *phdr = NULL; 215 struct spar_controlvm_parameters_header *phdr = NULL;
214 216
215 if (ctx == NULL) { 217 if (ctx == NULL) {
216 ERRDRV("%s (%s:%d) - no context", 218 ERRDRV("%s (%s:%d) - no context",
217 __func__, __FILE__, __LINE__); 219 __func__, __FILE__, __LINE__);
218 goto Away; 220 goto Away;
219 } 221 }
220 phdr = (ULTRA_CONTROLVM_PARAMETERS_HEADER *) (ctx->data); 222 phdr = (struct spar_controlvm_parameters_header *)(ctx->data);
221 switch (which_string) { 223 switch (which_string) {
222 case PARSERSTRING_INITIATOR: 224 case PARSERSTRING_INITIATOR:
223 ctx->curr = ctx->data + phdr->InitiatorOffset; 225 ctx->curr = ctx->data + phdr->initiator_offset;
224 ctx->bytes_remaining = phdr->InitiatorLength; 226 ctx->bytes_remaining = phdr->initiator_length;
225 break; 227 break;
226 case PARSERSTRING_TARGET: 228 case PARSERSTRING_TARGET:
227 ctx->curr = ctx->data + phdr->TargetOffset; 229 ctx->curr = ctx->data + phdr->target_offset;
228 ctx->bytes_remaining = phdr->TargetLength; 230 ctx->bytes_remaining = phdr->target_length;
229 break; 231 break;
230 case PARSERSTRING_CONNECTION: 232 case PARSERSTRING_CONNECTION:
231 ctx->curr = ctx->data + phdr->ConnectionOffset; 233 ctx->curr = ctx->data + phdr->connection_offset;
232 ctx->bytes_remaining = phdr->ConnectionLength; 234 ctx->bytes_remaining = phdr->connection_length;
233 break; 235 break;
234 case PARSERSTRING_NAME: 236 case PARSERSTRING_NAME:
235 ctx->curr = ctx->data + phdr->NameOffset; 237 ctx->curr = ctx->data + phdr->name_offset;
236 ctx->bytes_remaining = phdr->NameLength; 238 ctx->bytes_remaining = phdr->name_length;
237 break; 239 break;
238 default: 240 default:
239 ERRDRV("%s - bad which_string %d", __func__, which_string); 241 ERRDRV("%s - bad which_string %d", __func__, which_string);
diff --git a/drivers/staging/unisys/visorchipset/testing.h b/drivers/staging/unisys/visorchipset/testing.h
index 015d502cbb16..573aa8b5ba6a 100644
--- a/drivers/staging/unisys/visorchipset/testing.h
+++ b/drivers/staging/unisys/visorchipset/testing.h
@@ -23,8 +23,9 @@
23#include "globals.h" 23#include "globals.h"
24#include "controlvmchannel.h" 24#include "controlvmchannel.h"
25 25
26void test_produce_test_message(CONTROLVM_MESSAGE *msg, int isLocalTestAddr); 26void test_produce_test_message(struct controlvm_message *msg,
27BOOL test_consume_test_message(CONTROLVM_MESSAGE *msg); 27 int isLocalTestAddr);
28BOOL test_consume_test_message(struct controlvm_message *msg);
28void test_manufacture_vnic_client_add(void *p); 29void test_manufacture_vnic_client_add(void *p);
29void test_manufacture_vnic_client_add_phys(HOSTADDRESS addr); 30void test_manufacture_vnic_client_add_phys(HOSTADDRESS addr);
30void test_manufacture_preamble_messages(void); 31void test_manufacture_preamble_messages(void);
diff --git a/drivers/staging/unisys/visorchipset/visorchipset.h b/drivers/staging/unisys/visorchipset/visorchipset.h
index 2bf2e2f368ef..46dad63fa2c8 100644
--- a/drivers/staging/unisys/visorchipset/visorchipset.h
+++ b/drivers/staging/unisys/visorchipset/visorchipset.h
@@ -31,85 +31,85 @@
31/** Describes the state from the perspective of which controlvm messages have 31/** Describes the state from the perspective of which controlvm messages have
32 * been received for a bus or device. 32 * been received for a bus or device.
33 */ 33 */
34typedef struct { 34struct visorchipset_state {
35 u32 created:1; 35 u32 created:1;
36 u32 attached:1; 36 u32 attached:1;
37 u32 configured:1; 37 u32 configured:1;
38 u32 running:1; 38 u32 running:1;
39 /* Add new fields above. */ 39 /* Add new fields above. */
40 /* Remaining bits in this 32-bit word are unused. */ 40 /* Remaining bits in this 32-bit word are unused. */
41} VISORCHIPSET_STATE; 41};
42 42
43typedef enum { 43enum visorchipset_addresstype {
44 /** address is guest physical, but outside of the physical memory 44 /** address is guest physical, but outside of the physical memory
45 * region that is controlled by the running OS (this is the normal 45 * region that is controlled by the running OS (this is the normal
46 * address type for Supervisor channels) 46 * address type for Supervisor channels)
47 */ 47 */
48 ADDRTYPE_localPhysical, 48 ADDRTYPE_LOCALPHYSICAL,
49 49
50 /** address is guest physical, and withIN the confines of the 50 /** address is guest physical, and withIN the confines of the
51 * physical memory controlled by the running OS. 51 * physical memory controlled by the running OS.
52 */ 52 */
53 ADDRTYPE_localTest, 53 ADDRTYPE_LOCALTEST,
54} VISORCHIPSET_ADDRESSTYPE; 54};
55 55
56typedef enum { 56enum crash_obj_type {
57 CRASH_dev, 57 CRASH_DEV,
58 CRASH_bus, 58 CRASH_BUS,
59} CRASH_OBJ_TYPE; 59};
60 60
61/** Attributes for a particular Supervisor channel. 61/** Attributes for a particular Supervisor channel.
62 */ 62 */
63typedef struct { 63struct visorchipset_channel_info {
64 VISORCHIPSET_ADDRESSTYPE addrType; 64 enum visorchipset_addresstype addr_type;
65 HOSTADDRESS channelAddr; 65 HOSTADDRESS channel_addr;
66 struct InterruptInfo intr; 66 struct irq_info intr;
67 u64 nChannelBytes; 67 u64 n_channel_bytes;
68 uuid_le channelTypeGuid; 68 uuid_le channel_type_uuid;
69 uuid_le channelInstGuid; 69 uuid_le channel_inst_uuid;
70 70
71} VISORCHIPSET_CHANNEL_INFO; 71};
72 72
73/** Attributes for a particular Supervisor device. 73/** Attributes for a particular Supervisor device.
74 * Any visorchipset client can query these attributes using 74 * Any visorchipset client can query these attributes using
75 * visorchipset_get_client_device_info() or 75 * visorchipset_get_client_device_info() or
76 * visorchipset_get_server_device_info(). 76 * visorchipset_get_server_device_info().
77 */ 77 */
78typedef struct { 78struct visorchipset_device_info {
79 struct list_head entry; 79 struct list_head entry;
80 u32 busNo; 80 u32 bus_no;
81 u32 devNo; 81 u32 dev_no;
82 uuid_le devInstGuid; 82 uuid_le dev_inst_uuid;
83 VISORCHIPSET_STATE state; 83 struct visorchipset_state state;
84 VISORCHIPSET_CHANNEL_INFO chanInfo; 84 struct visorchipset_channel_info chan_info;
85 u32 Reserved1; /* CONTROLVM_ID */ 85 u32 reserved1; /* control_vm_id */
86 u64 Reserved2; 86 u64 reserved2;
87 u32 switchNo; /* when devState.attached==1 */ 87 u32 switch_no; /* when devState.attached==1 */
88 u32 internalPortNo; /* when devState.attached==1 */ 88 u32 internal_port_no; /* when devState.attached==1 */
89 CONTROLVM_MESSAGE_HEADER pendingMsgHdr; /* CONTROLVM_MESSAGE */ 89 struct controlvm_message_header pending_msg_hdr;/* CONTROLVM_MESSAGE */
90 /** For private use by the bus driver */ 90 /** For private use by the bus driver */
91 void *bus_driver_context; 91 void *bus_driver_context;
92 92
93} VISORCHIPSET_DEVICE_INFO; 93};
94 94
95static inline VISORCHIPSET_DEVICE_INFO * 95static inline struct visorchipset_device_info *finddevice(
96finddevice(struct list_head *list, u32 busNo, u32 devNo) 96 struct list_head *list, u32 bus_no, u32 dev_no)
97{ 97{
98 VISORCHIPSET_DEVICE_INFO *p; 98 struct visorchipset_device_info *p;
99 99
100 list_for_each_entry(p, list, entry) { 100 list_for_each_entry(p, list, entry) {
101 if (p->busNo == busNo && p->devNo == devNo) 101 if (p->bus_no == bus_no && p->dev_no == dev_no)
102 return p; 102 return p;
103 } 103 }
104 return NULL; 104 return NULL;
105} 105}
106 106
107static inline void delbusdevices(struct list_head *list, u32 busNo) 107static inline void delbusdevices(struct list_head *list, u32 bus_no)
108{ 108{
109 VISORCHIPSET_DEVICE_INFO *p, *tmp; 109 struct visorchipset_device_info *p, *tmp;
110 110
111 list_for_each_entry_safe(p, tmp, list, entry) { 111 list_for_each_entry_safe(p, tmp, list, entry) {
112 if (p->busNo == busNo) { 112 if (p->bus_no == bus_no) {
113 list_del(&p->entry); 113 list_del(&p->entry);
114 kfree(p); 114 kfree(p);
115 } 115 }
@@ -122,37 +122,37 @@ static inline void delbusdevices(struct list_head *list, u32 busNo)
122 * Any visorchipset client can query these attributes using 122 * Any visorchipset client can query these attributes using
123 * visorchipset_get_client_bus_info() or visorchipset_get_bus_info(). 123 * visorchipset_get_client_bus_info() or visorchipset_get_bus_info().
124 */ 124 */
125typedef struct { 125struct visorchipset_bus_info {
126 struct list_head entry; 126 struct list_head entry;
127 u32 busNo; 127 u32 bus_no;
128 VISORCHIPSET_STATE state; 128 struct visorchipset_state state;
129 VISORCHIPSET_CHANNEL_INFO chanInfo; 129 struct visorchipset_channel_info chan_info;
130 uuid_le partitionGuid; 130 uuid_le partition_uuid;
131 u64 partitionHandle; 131 u64 partition_handle;
132 u8 *name; /* UTF8 */ 132 u8 *name; /* UTF8 */
133 u8 *description; /* UTF8 */ 133 u8 *description; /* UTF8 */
134 u64 Reserved1; 134 u64 reserved1;
135 u32 Reserved2; 135 u32 reserved2;
136 MYPROCOBJECT *procObject; 136 MYPROCOBJECT *proc_object;
137 struct { 137 struct {
138 u32 server:1; 138 u32 server:1;
139 /* Add new fields above. */ 139 /* Add new fields above. */
140 /* Remaining bits in this 32-bit word are unused. */ 140 /* Remaining bits in this 32-bit word are unused. */
141 } flags; 141 } flags;
142 CONTROLVM_MESSAGE_HEADER pendingMsgHdr; /* CONTROLVM MsgHdr */ 142 struct controlvm_message_header pending_msg_hdr;/* CONTROLVM MsgHdr */
143 /** For private use by the bus driver */ 143 /** For private use by the bus driver */
144 void *bus_driver_context; 144 void *bus_driver_context;
145 u64 devNo; 145 u64 dev_no;
146 146
147} VISORCHIPSET_BUS_INFO; 147};
148 148
149static inline VISORCHIPSET_BUS_INFO * 149static inline struct visorchipset_bus_info *
150findbus(struct list_head *list, u32 busNo) 150findbus(struct list_head *list, u32 bus_no)
151{ 151{
152 VISORCHIPSET_BUS_INFO *p; 152 struct visorchipset_bus_info *p;
153 153
154 list_for_each_entry(p, list, entry) { 154 list_for_each_entry(p, list, entry) {
155 if (p->busNo == busNo) 155 if (p->bus_no == bus_no)
156 return p; 156 return p;
157 } 157 }
158 return NULL; 158 return NULL;
@@ -160,75 +160,73 @@ findbus(struct list_head *list, u32 busNo)
160 160
161/** Attributes for a particular Supervisor switch. 161/** Attributes for a particular Supervisor switch.
162 */ 162 */
163typedef struct { 163struct visorchipset_switch_info {
164 u32 switchNo; 164 u32 switch_no;
165 VISORCHIPSET_STATE state; 165 struct visorchipset_state state;
166 uuid_le switchTypeGuid; 166 uuid_le switch_type_uuid;
167 u8 *authService1; 167 u8 *authservice1;
168 u8 *authService2; 168 u8 *authservice2;
169 u8 *authService3; 169 u8 *authservice3;
170 u8 *securityContext; 170 u8 *security_context;
171 u64 Reserved; 171 u64 reserved;
172 u32 Reserved2; /* CONTROLVM_ID */ 172 u32 reserved2; /* control_vm_id */
173 struct device dev; 173 struct device dev;
174 BOOL dev_exists; 174 BOOL dev_exists;
175 CONTROLVM_MESSAGE_HEADER pendingMsgHdr; 175 struct controlvm_message_header pending_msg_hdr;
176 176};
177} VISORCHIPSET_SWITCH_INFO;
178 177
179/** Attributes for a particular Supervisor external port, which is connected 178/** Attributes for a particular Supervisor external port, which is connected
180 * to a specific switch. 179 * to a specific switch.
181 */ 180 */
182typedef struct { 181struct visorchipset_externalport_info {
183 u32 switchNo; 182 u32 switch_no;
184 u32 externalPortNo; 183 u32 external_port_no;
185 VISORCHIPSET_STATE state; 184 struct visorchipset_state state;
186 uuid_le networkZoneGuid; 185 uuid_le network_zone_uuid;
187 int pdPort; 186 int pd_port;
188 u8 *ip; 187 u8 *ip;
189 u8 *ipNetmask; 188 u8 *ip_netmask;
190 u8 *ipBroadcast; 189 u8 *ip_broadcast;
191 u8 *ipNetwork; 190 u8 *ip_network;
192 u8 *ipGateway; 191 u8 *ip_gateway;
193 u8 *ipDNS; 192 u8 *ip_dns;
194 u64 Reserved1; 193 u64 reserved1;
195 u32 Reserved2; /* CONTROLVM_ID */ 194 u32 reserved2; /* control_vm_id */
196 struct device dev; 195 struct device dev;
197 BOOL dev_exists; 196 BOOL dev_exists;
198 CONTROLVM_MESSAGE_HEADER pendingMsgHdr; 197 struct controlvm_message_header pending_msg_hdr;
199 198};
200} VISORCHIPSET_EXTERNALPORT_INFO;
201 199
202/** Attributes for a particular Supervisor internal port, which is how a 200/** Attributes for a particular Supervisor internal port, which is how a
203 * device connects to a particular switch. 201 * device connects to a particular switch.
204 */ 202 */
205typedef struct { 203struct visorchipset_internalport_info {
206 u32 switchNo; 204 u32 switch_no;
207 u32 internalPortNo; 205 u32 internal_port_no;
208 VISORCHIPSET_STATE state; 206 struct visorchipset_state state;
209 u32 busNo; /* valid only when state.attached == 1 */ 207 u32 bus_no; /* valid only when state.attached == 1 */
210 u32 devNo; /* valid only when state.attached == 1 */ 208 u32 dev_no; /* valid only when state.attached == 1 */
211 u64 Reserved1; 209 u64 reserved1;
212 u32 Reserved2; /* CONTROLVM_ID */ 210 u32 reserved2; /* CONTROLVM_ID */
213 CONTROLVM_MESSAGE_HEADER pendingMsgHdr; 211 struct controlvm_message_header pending_msg_hdr;
214 MYPROCOBJECT *procObject; 212 MYPROCOBJECT *proc_object;
215 213
216} VISORCHIPSET_INTERNALPORT_INFO; 214};
217 215
218/* These functions will be called from within visorchipset when certain 216/* These functions will be called from within visorchipset when certain
219 * events happen. (The implementation of these functions is outside of 217 * events happen. (The implementation of these functions is outside of
220 * visorchipset.) 218 * visorchipset.)
221 */ 219 */
222typedef struct { 220struct visorchipset_busdev_notifiers {
223 void (*bus_create)(ulong busNo); 221 void (*bus_create)(ulong bus_no);
224 void (*bus_destroy)(ulong busNo); 222 void (*bus_destroy)(ulong bus_no);
225 void (*device_create)(ulong busNo, ulong devNo); 223 void (*device_create)(ulong bus_no, ulong dev_no);
226 void (*device_destroy)(ulong busNo, ulong devNo); 224 void (*device_destroy)(ulong bus_no, ulong dev_no);
227 void (*device_pause)(ulong busNo, ulong devNo); 225 void (*device_pause)(ulong bus_no, ulong dev_no);
228 void (*device_resume)(ulong busNo, ulong devNo); 226 void (*device_resume)(ulong bus_no, ulong dev_no);
229 int (*get_channel_info)(uuid_le typeGuid, ulong *minSize, 227 int (*get_channel_info)(uuid_le type_uuid, ulong *min_size,
230 ulong *maxSize); 228 ulong *max_size);
231} VISORCHIPSET_BUSDEV_NOTIFIERS; 229};
232 230
233/* These functions live inside visorchipset, and will be called to indicate 231/* These functions live inside visorchipset, and will be called to indicate
234 * responses to specific events (by code outside of visorchipset). 232 * responses to specific events (by code outside of visorchipset).
@@ -236,14 +234,14 @@ typedef struct {
236 * 0 = it worked 234 * 0 = it worked
237 * -1 = it failed 235 * -1 = it failed
238 */ 236 */
239typedef struct { 237struct visorchipset_busdev_responders {
240 void (*bus_create)(ulong busNo, int response); 238 void (*bus_create)(ulong bus_no, int response);
241 void (*bus_destroy)(ulong busNo, int response); 239 void (*bus_destroy)(ulong bus_no, int response);
242 void (*device_create)(ulong busNo, ulong devNo, int response); 240 void (*device_create)(ulong bus_no, ulong dev_no, int response);
243 void (*device_destroy)(ulong busNo, ulong devNo, int response); 241 void (*device_destroy)(ulong bus_no, ulong dev_no, int response);
244 void (*device_pause)(ulong busNo, ulong devNo, int response); 242 void (*device_pause)(ulong bus_no, ulong dev_no, int response);
245 void (*device_resume)(ulong busNo, ulong devNo, int response); 243 void (*device_resume)(ulong bus_no, ulong dev_no, int response);
246} VISORCHIPSET_BUSDEV_RESPONDERS; 244};
247 245
248/** Register functions (in the bus driver) to get called by visorchipset 246/** Register functions (in the bus driver) to get called by visorchipset
249 * whenever a bus or device appears for which this service partition is 247 * whenever a bus or device appears for which this service partition is
@@ -252,9 +250,10 @@ typedef struct {
252 * responses. 250 * responses.
253 */ 251 */
254void 252void
255visorchipset_register_busdev_client(VISORCHIPSET_BUSDEV_NOTIFIERS *notifiers, 253visorchipset_register_busdev_client(
256 VISORCHIPSET_BUSDEV_RESPONDERS *responders, 254 struct visorchipset_busdev_notifiers *notifiers,
257 ULTRA_VBUS_DEVICEINFO *driverInfo); 255 struct visorchipset_busdev_responders *responders,
256 struct ultra_vbus_deviceinfo *driver_info);
258 257
259/** Register functions (in the bus driver) to get called by visorchipset 258/** Register functions (in the bus driver) to get called by visorchipset
260 * whenever a bus or device appears for which this service partition is 259 * whenever a bus or device appears for which this service partition is
@@ -263,47 +262,31 @@ visorchipset_register_busdev_client(VISORCHIPSET_BUSDEV_NOTIFIERS *notifiers,
263 * responses. 262 * responses.
264 */ 263 */
265void 264void
266visorchipset_register_busdev_server(VISORCHIPSET_BUSDEV_NOTIFIERS *notifiers, 265visorchipset_register_busdev_server(
267 VISORCHIPSET_BUSDEV_RESPONDERS *responders, 266 struct visorchipset_busdev_notifiers *notifiers,
268 ULTRA_VBUS_DEVICEINFO *driverInfo); 267 struct visorchipset_busdev_responders *responders,
268 struct ultra_vbus_deviceinfo *driver_info);
269 269
270typedef void (*SPARREPORTEVENT_COMPLETE_FUNC) (CONTROLVM_MESSAGE *msg, 270typedef void (*SPARREPORTEVENT_COMPLETE_FUNC) (struct controlvm_message *msg,
271 int status); 271 int status);
272 272
273void visorchipset_device_pause_response(ulong busNo, ulong devNo, int response); 273void visorchipset_device_pause_response(ulong bus_no, ulong dev_no,
274 int response);
274 275
275BOOL visorchipset_get_bus_info(ulong busNo, VISORCHIPSET_BUS_INFO *busInfo); 276BOOL visorchipset_get_bus_info(ulong bus_no,
276BOOL visorchipset_get_device_info(ulong busNo, ulong devNo, 277 struct visorchipset_bus_info *bus_info);
277 VISORCHIPSET_DEVICE_INFO *devInfo); 278BOOL visorchipset_get_device_info(ulong bus_no, ulong dev_no,
278BOOL visorchipset_get_switch_info(ulong switchNo, 279 struct visorchipset_device_info *dev_info);
279 VISORCHIPSET_SWITCH_INFO *switchInfo); 280BOOL visorchipset_set_bus_context(ulong bus_no, void *context);
280BOOL visorchipset_get_externalport_info(ulong switchNo, ulong externalPortNo, 281BOOL visorchipset_set_device_context(ulong bus_no, ulong dev_no, void *context);
281 VISORCHIPSET_EXTERNALPORT_INFO
282 *externalPortInfo);
283BOOL visorchipset_set_bus_context(ulong busNo, void *context);
284BOOL visorchipset_set_device_context(ulong busNo, ulong devNo, void *context);
285int visorchipset_chipset_ready(void); 282int visorchipset_chipset_ready(void);
286int visorchipset_chipset_selftest(void); 283int visorchipset_chipset_selftest(void);
287int visorchipset_chipset_notready(void); 284int visorchipset_chipset_notready(void);
288void visorchipset_controlvm_respond_reportEvent(CONTROLVM_MESSAGE *msg, 285void visorchipset_save_message(struct controlvm_message *msg,
289 void *payload); 286 enum crash_obj_type type);
290void visorchipset_save_message(CONTROLVM_MESSAGE *msg, CRASH_OBJ_TYPE type);
291void *visorchipset_cache_alloc(struct kmem_cache *pool, 287void *visorchipset_cache_alloc(struct kmem_cache *pool,
292 BOOL ok_to_block, char *fn, int ln); 288 BOOL ok_to_block, char *fn, int ln);
293void visorchipset_cache_free(struct kmem_cache *pool, void *p, 289void visorchipset_cache_free(struct kmem_cache *pool, void *p,
294 char *fn, int ln); 290 char *fn, int ln);
295 291
296#if defined(TRANSMITFILE_DEBUG) || defined(DEBUG)
297#define DBG_GETFILE_PAYLOAD(msg, controlvm_header) \
298 LOGINF(msg, \
299 (ulong)controlvm_header.PayloadVmOffset, \
300 (ulong)controlvm_header.PayloadMaxBytes)
301#define DBG_GETFILE(fmt, ...) LOGINF(fmt, ##__VA_ARGS__)
302#define DBG_PUTFILE(fmt, ...) LOGINF(fmt, ##__VA_ARGS__)
303#else
304#define DBG_GETFILE_PAYLOAD(msg, controlvm_header)
305#define DBG_GETFILE(fmt, ...)
306#define DBG_PUTFILE(fmt, ...)
307#endif
308
309#endif 292#endif
diff --git a/drivers/staging/unisys/visorchipset/visorchipset_main.c b/drivers/staging/unisys/visorchipset/visorchipset_main.c
index e5df39554a1a..7e6be32cf7bb 100644
--- a/drivers/staging/unisys/visorchipset/visorchipset_main.c
+++ b/drivers/staging/unisys/visorchipset/visorchipset_main.c
@@ -72,26 +72,28 @@ static struct workqueue_struct *Periodic_controlvm_workqueue;
72static DEFINE_SEMAPHORE(NotifierLock); 72static DEFINE_SEMAPHORE(NotifierLock);
73 73
74typedef struct { 74typedef struct {
75 CONTROLVM_MESSAGE message; 75 struct controlvm_message message;
76 unsigned int crc; 76 unsigned int crc;
77} MESSAGE_ENVELOPE; 77} MESSAGE_ENVELOPE;
78 78
79static CONTROLVM_MESSAGE_HEADER g_DiagMsgHdr; 79static struct controlvm_message_header g_DiagMsgHdr;
80static CONTROLVM_MESSAGE_HEADER g_ChipSetMsgHdr; 80static struct controlvm_message_header g_ChipSetMsgHdr;
81static CONTROLVM_MESSAGE_HEADER g_DelDumpMsgHdr; 81static struct controlvm_message_header g_DelDumpMsgHdr;
82static const uuid_le UltraDiagPoolChannelProtocolGuid = 82static const uuid_le UltraDiagPoolChannelProtocolGuid =
83 ULTRA_DIAG_POOL_CHANNEL_PROTOCOL_GUID; 83 SPAR_DIAG_POOL_CHANNEL_PROTOCOL_UUID;
84/* 0xffffff is an invalid Bus/Device number */ 84/* 0xffffff is an invalid Bus/Device number */
85static ulong g_diagpoolBusNo = 0xffffff; 85static ulong g_diagpoolBusNo = 0xffffff;
86static ulong g_diagpoolDevNo = 0xffffff; 86static ulong g_diagpoolDevNo = 0xffffff;
87static CONTROLVM_MESSAGE_PACKET g_DeviceChangeStatePacket; 87static struct controlvm_message_packet g_DeviceChangeStatePacket;
88 88
89/* Only VNIC and VHBA channels are sent to visorclientbus (aka 89/* Only VNIC and VHBA channels are sent to visorclientbus (aka
90 * "visorhackbus") 90 * "visorhackbus")
91 */ 91 */
92#define FOR_VISORHACKBUS(channel_type_guid) \ 92#define FOR_VISORHACKBUS(channel_type_guid) \
93 (((uuid_le_cmp(channel_type_guid, UltraVnicChannelProtocolGuid) == 0)\ 93 (((uuid_le_cmp(channel_type_guid,\
94 || (uuid_le_cmp(channel_type_guid, UltraVhbaChannelProtocolGuid) == 0))) 94 spar_vnic_channel_protocol_uuid) == 0)\
95 || (uuid_le_cmp(channel_type_guid,\
96 spar_vhba_channel_protocol_uuid) == 0)))
95#define FOR_VISORBUS(channel_type_guid) (!(FOR_VISORHACKBUS(channel_type_guid))) 97#define FOR_VISORBUS(channel_type_guid) (!(FOR_VISORHACKBUS(channel_type_guid)))
96 98
97#define is_diagpool_channel(channel_type_guid) \ 99#define is_diagpool_channel(channel_type_guid) \
@@ -112,12 +114,12 @@ typedef struct {
112/* Manages the request payload in the controlvm channel */ 114/* Manages the request payload in the controlvm channel */
113static CONTROLVM_PAYLOAD_INFO ControlVm_payload_info; 115static CONTROLVM_PAYLOAD_INFO ControlVm_payload_info;
114 116
115static pCHANNEL_HEADER Test_Vnic_channel; 117static struct channel_header *Test_Vnic_channel;
116 118
117typedef struct { 119typedef struct {
118 CONTROLVM_MESSAGE_HEADER Dumpcapture_header; 120 struct controlvm_message_header Dumpcapture_header;
119 CONTROLVM_MESSAGE_HEADER Gettextdump_header; 121 struct controlvm_message_header Gettextdump_header;
120 CONTROLVM_MESSAGE_HEADER Dumpcomplete_header; 122 struct controlvm_message_header Dumpcomplete_header;
121 BOOL Gettextdump_outstanding; 123 BOOL Gettextdump_outstanding;
122 u32 crc32; 124 u32 crc32;
123 ulong length; 125 ulong length;
@@ -134,7 +136,7 @@ static LIVEDUMP_INFO LiveDump_info;
134 * this scenario, we simply stash the controlvm message, then attempt to 136 * this scenario, we simply stash the controlvm message, then attempt to
135 * process it again the next time controlvm_periodic_work() runs. 137 * process it again the next time controlvm_periodic_work() runs.
136 */ 138 */
137static CONTROLVM_MESSAGE ControlVm_Pending_Msg; 139static struct controlvm_message ControlVm_Pending_Msg;
138static BOOL ControlVm_Pending_Msg_Valid = FALSE; 140static BOOL ControlVm_Pending_Msg_Valid = FALSE;
139 141
140/* Pool of struct putfile_buffer_entry, for keeping track of pending (incoming) 142/* Pool of struct putfile_buffer_entry, for keeping track of pending (incoming)
@@ -180,7 +182,7 @@ struct putfile_request {
180 u64 sig; /* PUTFILE_REQUEST_SIG */ 182 u64 sig; /* PUTFILE_REQUEST_SIG */
181 183
182 /* header from original TransmitFile request */ 184 /* header from original TransmitFile request */
183 CONTROLVM_MESSAGE_HEADER controlvm_header; 185 struct controlvm_message_header controlvm_header;
184 u64 file_request_number; /* from original TransmitFile request */ 186 u64 file_request_number; /* from original TransmitFile request */
185 187
186 /* link to next struct putfile_request */ 188 /* link to next struct putfile_request */
@@ -218,7 +220,7 @@ struct parahotplug_request {
218 struct list_head list; 220 struct list_head list;
219 int id; 221 int id;
220 unsigned long expiration; 222 unsigned long expiration;
221 CONTROLVM_MESSAGE msg; 223 struct controlvm_message msg;
222}; 224};
223 225
224static LIST_HEAD(Parahotplug_request_list); 226static LIST_HEAD(Parahotplug_request_list);
@@ -228,8 +230,8 @@ static void parahotplug_process_list(void);
228/* Manages the info for a CONTROLVM_DUMP_CAPTURESTATE / 230/* Manages the info for a CONTROLVM_DUMP_CAPTURESTATE /
229 * CONTROLVM_REPORTEVENT. 231 * CONTROLVM_REPORTEVENT.
230 */ 232 */
231static VISORCHIPSET_BUSDEV_NOTIFIERS BusDev_Server_Notifiers; 233static struct visorchipset_busdev_notifiers BusDev_Server_Notifiers;
232static VISORCHIPSET_BUSDEV_NOTIFIERS BusDev_Client_Notifiers; 234static struct visorchipset_busdev_notifiers BusDev_Client_Notifiers;
233 235
234static void bus_create_response(ulong busNo, int response); 236static void bus_create_response(ulong busNo, int response);
235static void bus_destroy_response(ulong busNo, int response); 237static void bus_destroy_response(ulong busNo, int response);
@@ -237,7 +239,7 @@ static void device_create_response(ulong busNo, ulong devNo, int response);
237static void device_destroy_response(ulong busNo, ulong devNo, int response); 239static void device_destroy_response(ulong busNo, ulong devNo, int response);
238static void device_resume_response(ulong busNo, ulong devNo, int response); 240static void device_resume_response(ulong busNo, ulong devNo, int response);
239 241
240static VISORCHIPSET_BUSDEV_RESPONDERS BusDev_Responders = { 242static struct visorchipset_busdev_responders BusDev_Responders = {
241 .bus_create = bus_create_response, 243 .bus_create = bus_create_response,
242 .bus_destroy = bus_destroy_response, 244 .bus_destroy = bus_destroy_response,
243 .device_create = device_create_response, 245 .device_create = device_create_response,
@@ -342,13 +344,14 @@ static struct platform_device Visorchipset_platform_device = {
342}; 344};
343 345
344/* Function prototypes */ 346/* Function prototypes */
345static void controlvm_respond(CONTROLVM_MESSAGE_HEADER *msgHdr, int response); 347static void controlvm_respond(struct controlvm_message_header *msgHdr,
346static void controlvm_respond_chipset_init(CONTROLVM_MESSAGE_HEADER *msgHdr, 348 int response);
347 int response, 349static void controlvm_respond_chipset_init(
348 ULTRA_CHIPSET_FEATURE features); 350 struct controlvm_message_header *msgHdr, int response,
349static void controlvm_respond_physdev_changestate(CONTROLVM_MESSAGE_HEADER * 351 enum ultra_chipset_feature features);
350 msgHdr, int response, 352static void controlvm_respond_physdev_changestate(
351 ULTRA_SEGMENT_STATE state); 353 struct controlvm_message_header *msgHdr, int response,
354 struct spar_segment_state state);
352 355
353static ssize_t toolaction_show(struct device *dev, 356static ssize_t toolaction_show(struct device *dev,
354 struct device_attribute *attr, 357 struct device_attribute *attr,
@@ -357,8 +360,8 @@ static ssize_t toolaction_show(struct device *dev,
357 u8 toolAction; 360 u8 toolAction;
358 361
359 visorchannel_read(ControlVm_channel, 362 visorchannel_read(ControlVm_channel,
360 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL, 363 offsetof(struct spar_controlvm_channel_protocol,
361 ToolAction), &toolAction, sizeof(u8)); 364 tool_action), &toolAction, sizeof(u8));
362 return scnprintf(buf, PAGE_SIZE, "%u\n", toolAction); 365 return scnprintf(buf, PAGE_SIZE, "%u\n", toolAction);
363} 366}
364 367
@@ -373,7 +376,7 @@ static ssize_t toolaction_store(struct device *dev,
373 return -EINVAL; 376 return -EINVAL;
374 377
375 ret = visorchannel_write(ControlVm_channel, 378 ret = visorchannel_write(ControlVm_channel,
376 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL, ToolAction), 379 offsetof(struct spar_controlvm_channel_protocol, tool_action),
377 &toolAction, sizeof(u8)); 380 &toolAction, sizeof(u8));
378 381
379 if (ret) 382 if (ret)
@@ -385,14 +388,14 @@ static ssize_t boottotool_show(struct device *dev,
385 struct device_attribute *attr, 388 struct device_attribute *attr,
386 char *buf) 389 char *buf)
387{ 390{
388 ULTRA_EFI_SPAR_INDICATION efiSparIndication; 391 struct efi_spar_indication efiSparIndication;
389 392
390 visorchannel_read(ControlVm_channel, 393 visorchannel_read(ControlVm_channel,
391 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL, 394 offsetof(struct spar_controlvm_channel_protocol,
392 EfiSparIndication), &efiSparIndication, 395 efi_spar_ind), &efiSparIndication,
393 sizeof(ULTRA_EFI_SPAR_INDICATION)); 396 sizeof(struct efi_spar_indication));
394 return scnprintf(buf, PAGE_SIZE, "%u\n", 397 return scnprintf(buf, PAGE_SIZE, "%u\n",
395 efiSparIndication.BootToTool); 398 efiSparIndication.boot_to_tool);
396} 399}
397 400
398static ssize_t boottotool_store(struct device *dev, 401static ssize_t boottotool_store(struct device *dev,
@@ -400,17 +403,17 @@ static ssize_t boottotool_store(struct device *dev,
400 const char *buf, size_t count) 403 const char *buf, size_t count)
401{ 404{
402 int val, ret; 405 int val, ret;
403 ULTRA_EFI_SPAR_INDICATION efiSparIndication; 406 struct efi_spar_indication efiSparIndication;
404 407
405 if (kstrtoint(buf, 10, &val) != 0) 408 if (kstrtoint(buf, 10, &val) != 0)
406 return -EINVAL; 409 return -EINVAL;
407 410
408 efiSparIndication.BootToTool = val; 411 efiSparIndication.boot_to_tool = val;
409 ret = visorchannel_write(ControlVm_channel, 412 ret = visorchannel_write(ControlVm_channel,
410 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL, 413 offsetof(struct spar_controlvm_channel_protocol,
411 EfiSparIndication), 414 efi_spar_ind),
412 &(efiSparIndication), 415 &(efiSparIndication),
413 sizeof(ULTRA_EFI_SPAR_INDICATION)); 416 sizeof(struct efi_spar_indication));
414 417
415 if (ret) 418 if (ret)
416 return ret; 419 return ret;
@@ -423,7 +426,7 @@ static ssize_t error_show(struct device *dev, struct device_attribute *attr,
423 u32 error; 426 u32 error;
424 427
425 visorchannel_read(ControlVm_channel, offsetof( 428 visorchannel_read(ControlVm_channel, offsetof(
426 ULTRA_CONTROLVM_CHANNEL_PROTOCOL, InstallationError), 429 struct spar_controlvm_channel_protocol, installation_error),
427 &error, sizeof(u32)); 430 &error, sizeof(u32));
428 return scnprintf(buf, PAGE_SIZE, "%i\n", error); 431 return scnprintf(buf, PAGE_SIZE, "%i\n", error);
429} 432}
@@ -438,8 +441,8 @@ static ssize_t error_store(struct device *dev, struct device_attribute *attr,
438 return -EINVAL; 441 return -EINVAL;
439 442
440 ret = visorchannel_write(ControlVm_channel, 443 ret = visorchannel_write(ControlVm_channel,
441 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL, 444 offsetof(struct spar_controlvm_channel_protocol,
442 InstallationError), 445 installation_error),
443 &error, sizeof(u32)); 446 &error, sizeof(u32));
444 if (ret) 447 if (ret)
445 return ret; 448 return ret;
@@ -452,7 +455,7 @@ static ssize_t textid_show(struct device *dev, struct device_attribute *attr,
452 u32 textId; 455 u32 textId;
453 456
454 visorchannel_read(ControlVm_channel, offsetof( 457 visorchannel_read(ControlVm_channel, offsetof(
455 ULTRA_CONTROLVM_CHANNEL_PROTOCOL, InstallationTextId), 458 struct spar_controlvm_channel_protocol, installation_text_id),
456 &textId, sizeof(u32)); 459 &textId, sizeof(u32));
457 return scnprintf(buf, PAGE_SIZE, "%i\n", textId); 460 return scnprintf(buf, PAGE_SIZE, "%i\n", textId);
458} 461}
@@ -467,8 +470,8 @@ static ssize_t textid_store(struct device *dev, struct device_attribute *attr,
467 return -EINVAL; 470 return -EINVAL;
468 471
469 ret = visorchannel_write(ControlVm_channel, 472 ret = visorchannel_write(ControlVm_channel,
470 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL, 473 offsetof(struct spar_controlvm_channel_protocol,
471 InstallationTextId), 474 installation_text_id),
472 &textId, sizeof(u32)); 475 &textId, sizeof(u32));
473 if (ret) 476 if (ret)
474 return ret; 477 return ret;
@@ -482,8 +485,8 @@ static ssize_t remaining_steps_show(struct device *dev,
482 u16 remainingSteps; 485 u16 remainingSteps;
483 486
484 visorchannel_read(ControlVm_channel, 487 visorchannel_read(ControlVm_channel,
485 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL, 488 offsetof(struct spar_controlvm_channel_protocol,
486 InstallationRemainingSteps), 489 installation_remaining_steps),
487 &remainingSteps, 490 &remainingSteps,
488 sizeof(u16)); 491 sizeof(u16));
489 return scnprintf(buf, PAGE_SIZE, "%hu\n", remainingSteps); 492 return scnprintf(buf, PAGE_SIZE, "%hu\n", remainingSteps);
@@ -499,8 +502,8 @@ static ssize_t remaining_steps_store(struct device *dev,
499 return -EINVAL; 502 return -EINVAL;
500 503
501 ret = visorchannel_write(ControlVm_channel, 504 ret = visorchannel_write(ControlVm_channel,
502 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL, 505 offsetof(struct spar_controlvm_channel_protocol,
503 InstallationRemainingSteps), 506 installation_remaining_steps),
504 &remainingSteps, sizeof(u16)); 507 &remainingSteps, sizeof(u16));
505 if (ret) 508 if (ret)
506 return ret; 509 return ret;
@@ -539,11 +542,11 @@ testUnicode(void)
539static void 542static void
540busInfo_clear(void *v) 543busInfo_clear(void *v)
541{ 544{
542 VISORCHIPSET_BUS_INFO *p = (VISORCHIPSET_BUS_INFO *) (v); 545 struct visorchipset_bus_info *p = (struct visorchipset_bus_info *) (v);
543 546
544 if (p->procObject) { 547 if (p->proc_object) {
545 visor_proc_DestroyObject(p->procObject); 548 visor_proc_DestroyObject(p->proc_object);
546 p->procObject = NULL; 549 p->proc_object = NULL;
547 } 550 }
548 kfree(p->name); 551 kfree(p->name);
549 p->name = NULL; 552 p->name = NULL;
@@ -552,16 +555,17 @@ busInfo_clear(void *v)
552 p->description = NULL; 555 p->description = NULL;
553 556
554 p->state.created = 0; 557 p->state.created = 0;
555 memset(p, 0, sizeof(VISORCHIPSET_BUS_INFO)); 558 memset(p, 0, sizeof(struct visorchipset_bus_info));
556} 559}
557 560
558static void 561static void
559devInfo_clear(void *v) 562devInfo_clear(void *v)
560{ 563{
561 VISORCHIPSET_DEVICE_INFO *p = (VISORCHIPSET_DEVICE_INFO *) (v); 564 struct visorchipset_device_info *p =
565 (struct visorchipset_device_info *)(v);
562 566
563 p->state.created = 0; 567 p->state.created = 0;
564 memset(p, 0, sizeof(VISORCHIPSET_DEVICE_INFO)); 568 memset(p, 0, sizeof(struct visorchipset_device_info));
565} 569}
566 570
567static u8 571static u8
@@ -585,9 +589,10 @@ clear_chipset_events(void)
585} 589}
586 590
587void 591void
588visorchipset_register_busdev_server(VISORCHIPSET_BUSDEV_NOTIFIERS *notifiers, 592visorchipset_register_busdev_server(
589 VISORCHIPSET_BUSDEV_RESPONDERS *responders, 593 struct visorchipset_busdev_notifiers *notifiers,
590 ULTRA_VBUS_DEVICEINFO *driverInfo) 594 struct visorchipset_busdev_responders *responders,
595 struct ultra_vbus_deviceinfo *driver_info)
591{ 596{
592 down(&NotifierLock); 597 down(&NotifierLock);
593 if (notifiers == NULL) { 598 if (notifiers == NULL) {
@@ -600,8 +605,8 @@ visorchipset_register_busdev_server(VISORCHIPSET_BUSDEV_NOTIFIERS *notifiers,
600 } 605 }
601 if (responders) 606 if (responders)
602 *responders = BusDev_Responders; 607 *responders = BusDev_Responders;
603 if (driverInfo) 608 if (driver_info)
604 bus_device_info_init(driverInfo, "chipset", "visorchipset", 609 bus_device_info_init(driver_info, "chipset", "visorchipset",
605 VERSION, NULL); 610 VERSION, NULL);
606 611
607 up(&NotifierLock); 612 up(&NotifierLock);
@@ -609,9 +614,10 @@ visorchipset_register_busdev_server(VISORCHIPSET_BUSDEV_NOTIFIERS *notifiers,
609EXPORT_SYMBOL_GPL(visorchipset_register_busdev_server); 614EXPORT_SYMBOL_GPL(visorchipset_register_busdev_server);
610 615
611void 616void
612visorchipset_register_busdev_client(VISORCHIPSET_BUSDEV_NOTIFIERS *notifiers, 617visorchipset_register_busdev_client(
613 VISORCHIPSET_BUSDEV_RESPONDERS *responders, 618 struct visorchipset_busdev_notifiers *notifiers,
614 ULTRA_VBUS_DEVICEINFO *driverInfo) 619 struct visorchipset_busdev_responders *responders,
620 struct ultra_vbus_deviceinfo *driver_info)
615{ 621{
616 down(&NotifierLock); 622 down(&NotifierLock);
617 if (notifiers == NULL) { 623 if (notifiers == NULL) {
@@ -624,9 +630,9 @@ visorchipset_register_busdev_client(VISORCHIPSET_BUSDEV_NOTIFIERS *notifiers,
624 } 630 }
625 if (responders) 631 if (responders)
626 *responders = BusDev_Responders; 632 *responders = BusDev_Responders;
627 if (driverInfo) 633 if (driver_info)
628 bus_device_info_init(driverInfo, "chipset(bolts)", "visorchipset", 634 bus_device_info_init(driver_info, "chipset(bolts)",
629 VERSION, NULL); 635 "visorchipset", VERSION, NULL);
630 up(&NotifierLock); 636 up(&NotifierLock);
631} 637}
632EXPORT_SYMBOL_GPL(visorchipset_register_busdev_client); 638EXPORT_SYMBOL_GPL(visorchipset_register_busdev_client);
@@ -634,8 +640,8 @@ EXPORT_SYMBOL_GPL(visorchipset_register_busdev_client);
634static void 640static void
635cleanup_controlvm_structures(void) 641cleanup_controlvm_structures(void)
636{ 642{
637 VISORCHIPSET_BUS_INFO *bi, *tmp_bi; 643 struct visorchipset_bus_info *bi, *tmp_bi;
638 VISORCHIPSET_DEVICE_INFO *di, *tmp_di; 644 struct visorchipset_device_info *di, *tmp_di;
639 645
640 list_for_each_entry_safe(bi, tmp_bi, &BusInfoList, entry) { 646 list_for_each_entry_safe(bi, tmp_bi, &BusInfoList, entry) {
641 busInfo_clear(bi); 647 busInfo_clear(bi);
@@ -651,10 +657,10 @@ cleanup_controlvm_structures(void)
651} 657}
652 658
653static void 659static void
654chipset_init(CONTROLVM_MESSAGE *inmsg) 660chipset_init(struct controlvm_message *inmsg)
655{ 661{
656 static int chipset_inited; 662 static int chipset_inited;
657 ULTRA_CHIPSET_FEATURE features = 0; 663 enum ultra_chipset_feature features = 0;
658 int rc = CONTROLVM_RESP_SUCCESS; 664 int rc = CONTROLVM_RESP_SUCCESS;
659 665
660 POSTCODE_LINUX_2(CHIPSET_INIT_ENTRY_PC, POSTCODE_SEVERITY_INFO); 666 POSTCODE_LINUX_2(CHIPSET_INIT_ENTRY_PC, POSTCODE_SEVERITY_INFO);
@@ -669,7 +675,7 @@ chipset_init(CONTROLVM_MESSAGE *inmsg)
669 /* Set features to indicate we support parahotplug (if Command 675 /* Set features to indicate we support parahotplug (if Command
670 * also supports it). */ 676 * also supports it). */
671 features = 677 features =
672 inmsg->cmd.initChipset. 678 inmsg->cmd.init_chipset.
673 features & ULTRA_CHIPSET_FEATURE_PARA_HOTPLUG; 679 features & ULTRA_CHIPSET_FEATURE_PARA_HOTPLUG;
674 680
675 /* Set the "reply" bit so Command knows this is a 681 /* Set the "reply" bit so Command knows this is a
@@ -679,42 +685,42 @@ chipset_init(CONTROLVM_MESSAGE *inmsg)
679Away: 685Away:
680 if (rc < 0) 686 if (rc < 0)
681 cleanup_controlvm_structures(); 687 cleanup_controlvm_structures();
682 if (inmsg->hdr.Flags.responseExpected) 688 if (inmsg->hdr.flags.response_expected)
683 controlvm_respond_chipset_init(&inmsg->hdr, rc, features); 689 controlvm_respond_chipset_init(&inmsg->hdr, rc, features);
684} 690}
685 691
686static void 692static void
687controlvm_init_response(CONTROLVM_MESSAGE *msg, 693controlvm_init_response(struct controlvm_message *msg,
688 CONTROLVM_MESSAGE_HEADER *msgHdr, int response) 694 struct controlvm_message_header *msgHdr, int response)
689{ 695{
690 memset(msg, 0, sizeof(CONTROLVM_MESSAGE)); 696 memset(msg, 0, sizeof(struct controlvm_message));
691 memcpy(&msg->hdr, msgHdr, sizeof(CONTROLVM_MESSAGE_HEADER)); 697 memcpy(&msg->hdr, msgHdr, sizeof(struct controlvm_message_header));
692 msg->hdr.PayloadBytes = 0; 698 msg->hdr.payload_bytes = 0;
693 msg->hdr.PayloadVmOffset = 0; 699 msg->hdr.payload_vm_offset = 0;
694 msg->hdr.PayloadMaxBytes = 0; 700 msg->hdr.payload_max_bytes = 0;
695 if (response < 0) { 701 if (response < 0) {
696 msg->hdr.Flags.failed = 1; 702 msg->hdr.flags.failed = 1;
697 msg->hdr.CompletionStatus = (u32) (-response); 703 msg->hdr.completion_status = (u32) (-response);
698 } 704 }
699} 705}
700 706
701static void 707static void
702controlvm_respond(CONTROLVM_MESSAGE_HEADER *msgHdr, int response) 708controlvm_respond(struct controlvm_message_header *msgHdr, int response)
703{ 709{
704 CONTROLVM_MESSAGE outmsg; 710 struct controlvm_message outmsg;
705 711
706 controlvm_init_response(&outmsg, msgHdr, response); 712 controlvm_init_response(&outmsg, msgHdr, response);
707 /* For DiagPool channel DEVICE_CHANGESTATE, we need to send 713 /* For DiagPool channel DEVICE_CHANGESTATE, we need to send
708 * back the deviceChangeState structure in the packet. */ 714 * back the deviceChangeState structure in the packet. */
709 if (msgHdr->Id == CONTROLVM_DEVICE_CHANGESTATE 715 if (msgHdr->id == CONTROLVM_DEVICE_CHANGESTATE
710 && g_DeviceChangeStatePacket.deviceChangeState.busNo == 716 && g_DeviceChangeStatePacket.device_change_state.bus_no ==
711 g_diagpoolBusNo 717 g_diagpoolBusNo
712 && g_DeviceChangeStatePacket.deviceChangeState.devNo == 718 && g_DeviceChangeStatePacket.device_change_state.dev_no ==
713 g_diagpoolDevNo) 719 g_diagpoolDevNo)
714 outmsg.cmd = g_DeviceChangeStatePacket; 720 outmsg.cmd = g_DeviceChangeStatePacket;
715 if (outmsg.hdr.Flags.testMessage == 1) { 721 if (outmsg.hdr.flags.test_message == 1) {
716 LOGINF("%s controlvm_msg=0x%x response=%d for test message", 722 LOGINF("%s controlvm_msg=0x%x response=%d for test message",
717 __func__, outmsg.hdr.Id, response); 723 __func__, outmsg.hdr.id, response);
718 return; 724 return;
719 } 725 }
720 if (!visorchannel_signalinsert(ControlVm_channel, 726 if (!visorchannel_signalinsert(ControlVm_channel,
@@ -725,13 +731,14 @@ controlvm_respond(CONTROLVM_MESSAGE_HEADER *msgHdr, int response)
725} 731}
726 732
727static void 733static void
728controlvm_respond_chipset_init(CONTROLVM_MESSAGE_HEADER *msgHdr, int response, 734controlvm_respond_chipset_init(struct controlvm_message_header *msgHdr,
729 ULTRA_CHIPSET_FEATURE features) 735 int response,
736 enum ultra_chipset_feature features)
730{ 737{
731 CONTROLVM_MESSAGE outmsg; 738 struct controlvm_message outmsg;
732 739
733 controlvm_init_response(&outmsg, msgHdr, response); 740 controlvm_init_response(&outmsg, msgHdr, response);
734 outmsg.cmd.initChipset.features = features; 741 outmsg.cmd.init_chipset.features = features;
735 if (!visorchannel_signalinsert(ControlVm_channel, 742 if (!visorchannel_signalinsert(ControlVm_channel,
736 CONTROLVM_QUEUE_REQUEST, &outmsg)) { 743 CONTROLVM_QUEUE_REQUEST, &outmsg)) {
737 LOGERR("signalinsert failed!"); 744 LOGERR("signalinsert failed!");
@@ -739,15 +746,15 @@ controlvm_respond_chipset_init(CONTROLVM_MESSAGE_HEADER *msgHdr, int response,
739 } 746 }
740} 747}
741 748
742static void 749static void controlvm_respond_physdev_changestate(
743controlvm_respond_physdev_changestate(CONTROLVM_MESSAGE_HEADER *msgHdr, 750 struct controlvm_message_header *msgHdr, int response,
744 int response, ULTRA_SEGMENT_STATE state) 751 struct spar_segment_state state)
745{ 752{
746 CONTROLVM_MESSAGE outmsg; 753 struct controlvm_message outmsg;
747 754
748 controlvm_init_response(&outmsg, msgHdr, response); 755 controlvm_init_response(&outmsg, msgHdr, response);
749 outmsg.cmd.deviceChangeState.state = state; 756 outmsg.cmd.device_change_state.state = state;
750 outmsg.cmd.deviceChangeState.flags.physicalDevice = 1; 757 outmsg.cmd.device_change_state.flags.phys_device = 1;
751 if (!visorchannel_signalinsert(ControlVm_channel, 758 if (!visorchannel_signalinsert(ControlVm_channel,
752 CONTROLVM_QUEUE_REQUEST, &outmsg)) { 759 CONTROLVM_QUEUE_REQUEST, &outmsg)) {
753 LOGERR("signalinsert failed!"); 760 LOGERR("signalinsert failed!");
@@ -756,15 +763,16 @@ controlvm_respond_physdev_changestate(CONTROLVM_MESSAGE_HEADER *msgHdr,
756} 763}
757 764
758void 765void
759visorchipset_save_message(CONTROLVM_MESSAGE *msg, CRASH_OBJ_TYPE type) 766visorchipset_save_message(struct controlvm_message *msg,
767 enum crash_obj_type type)
760{ 768{
761 u32 localSavedCrashMsgOffset; 769 u32 localSavedCrashMsgOffset;
762 u16 localSavedCrashMsgCount; 770 u16 localSavedCrashMsgCount;
763 771
764 /* get saved message count */ 772 /* get saved message count */
765 if (visorchannel_read(ControlVm_channel, 773 if (visorchannel_read(ControlVm_channel,
766 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL, 774 offsetof(struct spar_controlvm_channel_protocol,
767 SavedCrashMsgCount), 775 saved_crash_message_count),
768 &localSavedCrashMsgCount, sizeof(u16)) < 0) { 776 &localSavedCrashMsgCount, sizeof(u16)) < 0) {
769 LOGERR("failed to get Saved Message Count"); 777 LOGERR("failed to get Saved Message Count");
770 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC, 778 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC,
@@ -783,8 +791,8 @@ visorchipset_save_message(CONTROLVM_MESSAGE *msg, CRASH_OBJ_TYPE type)
783 791
784 /* get saved crash message offset */ 792 /* get saved crash message offset */
785 if (visorchannel_read(ControlVm_channel, 793 if (visorchannel_read(ControlVm_channel,
786 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL, 794 offsetof(struct spar_controlvm_channel_protocol,
787 SavedCrashMsgOffset), 795 saved_crash_message_offset),
788 &localSavedCrashMsgOffset, sizeof(u32)) < 0) { 796 &localSavedCrashMsgOffset, sizeof(u32)) < 0) {
789 LOGERR("failed to get Saved Message Offset"); 797 LOGERR("failed to get Saved Message Offset");
790 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC, 798 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC,
@@ -792,10 +800,11 @@ visorchipset_save_message(CONTROLVM_MESSAGE *msg, CRASH_OBJ_TYPE type)
792 return; 800 return;
793 } 801 }
794 802
795 if (type == CRASH_bus) { 803 if (type == CRASH_BUS) {
796 if (visorchannel_write(ControlVm_channel, 804 if (visorchannel_write(ControlVm_channel,
797 localSavedCrashMsgOffset, 805 localSavedCrashMsgOffset,
798 msg, sizeof(CONTROLVM_MESSAGE)) < 0) { 806 msg,
807 sizeof(struct controlvm_message)) < 0) {
799 LOGERR("SAVE_MSG_BUS_FAILURE: Failed to write CrashCreateBusMsg!"); 808 LOGERR("SAVE_MSG_BUS_FAILURE: Failed to write CrashCreateBusMsg!");
800 POSTCODE_LINUX_2(SAVE_MSG_BUS_FAILURE_PC, 809 POSTCODE_LINUX_2(SAVE_MSG_BUS_FAILURE_PC,
801 POSTCODE_SEVERITY_ERR); 810 POSTCODE_SEVERITY_ERR);
@@ -804,8 +813,8 @@ visorchipset_save_message(CONTROLVM_MESSAGE *msg, CRASH_OBJ_TYPE type)
804 } else { 813 } else {
805 if (visorchannel_write(ControlVm_channel, 814 if (visorchannel_write(ControlVm_channel,
806 localSavedCrashMsgOffset + 815 localSavedCrashMsgOffset +
807 sizeof(CONTROLVM_MESSAGE), msg, 816 sizeof(struct controlvm_message), msg,
808 sizeof(CONTROLVM_MESSAGE)) < 0) { 817 sizeof(struct controlvm_message)) < 0) {
809 LOGERR("SAVE_MSG_DEV_FAILURE: Failed to write CrashCreateDevMsg!"); 818 LOGERR("SAVE_MSG_DEV_FAILURE: Failed to write CrashCreateDevMsg!");
810 POSTCODE_LINUX_2(SAVE_MSG_DEV_FAILURE_PC, 819 POSTCODE_LINUX_2(SAVE_MSG_DEV_FAILURE_PC,
811 POSTCODE_SEVERITY_ERR); 820 POSTCODE_SEVERITY_ERR);
@@ -816,9 +825,9 @@ visorchipset_save_message(CONTROLVM_MESSAGE *msg, CRASH_OBJ_TYPE type)
816EXPORT_SYMBOL_GPL(visorchipset_save_message); 825EXPORT_SYMBOL_GPL(visorchipset_save_message);
817 826
818static void 827static void
819bus_responder(CONTROLVM_ID cmdId, ulong busNo, int response) 828bus_responder(enum controlvm_id cmdId, ulong busNo, int response)
820{ 829{
821 VISORCHIPSET_BUS_INFO *p = NULL; 830 struct visorchipset_bus_info *p = NULL;
822 BOOL need_clear = FALSE; 831 BOOL need_clear = FALSE;
823 832
824 p = findbus(&BusInfoList, busNo); 833 p = findbus(&BusInfoList, busNo);
@@ -838,16 +847,16 @@ bus_responder(CONTROLVM_ID cmdId, ulong busNo, int response)
838 need_clear = TRUE; 847 need_clear = TRUE;
839 } 848 }
840 849
841 if (p->pendingMsgHdr.Id == CONTROLVM_INVALID) { 850 if (p->pending_msg_hdr.id == CONTROLVM_INVALID) {
842 LOGERR("bus_responder no pending msg"); 851 LOGERR("bus_responder no pending msg");
843 return; /* no controlvm response needed */ 852 return; /* no controlvm response needed */
844 } 853 }
845 if (p->pendingMsgHdr.Id != (u32) cmdId) { 854 if (p->pending_msg_hdr.id != (u32) cmdId) {
846 LOGERR("expected=%d, found=%d", cmdId, p->pendingMsgHdr.Id); 855 LOGERR("expected=%d, found=%d", cmdId, p->pending_msg_hdr.id);
847 return; 856 return;
848 } 857 }
849 controlvm_respond(&p->pendingMsgHdr, response); 858 controlvm_respond(&p->pending_msg_hdr, response);
850 p->pendingMsgHdr.Id = CONTROLVM_INVALID; 859 p->pending_msg_hdr.id = CONTROLVM_INVALID;
851 if (need_clear) { 860 if (need_clear) {
852 busInfo_clear(p); 861 busInfo_clear(p);
853 delbusdevices(&DevInfoList, busNo); 862 delbusdevices(&DevInfoList, busNo);
@@ -855,32 +864,32 @@ bus_responder(CONTROLVM_ID cmdId, ulong busNo, int response)
855} 864}
856 865
857static void 866static void
858device_changestate_responder(CONTROLVM_ID cmdId, 867device_changestate_responder(enum controlvm_id cmdId,
859 ulong busNo, ulong devNo, int response, 868 ulong busNo, ulong devNo, int response,
860 ULTRA_SEGMENT_STATE responseState) 869 struct spar_segment_state responseState)
861{ 870{
862 VISORCHIPSET_DEVICE_INFO *p = NULL; 871 struct visorchipset_device_info *p = NULL;
863 CONTROLVM_MESSAGE outmsg; 872 struct controlvm_message outmsg;
864 873
865 p = finddevice(&DevInfoList, busNo, devNo); 874 p = finddevice(&DevInfoList, busNo, devNo);
866 if (!p) { 875 if (!p) {
867 LOGERR("internal error; busNo=%lu, devNo=%lu", busNo, devNo); 876 LOGERR("internal error; busNo=%lu, devNo=%lu", busNo, devNo);
868 return; 877 return;
869 } 878 }
870 if (p->pendingMsgHdr.Id == CONTROLVM_INVALID) { 879 if (p->pending_msg_hdr.id == CONTROLVM_INVALID) {
871 LOGERR("device_responder no pending msg"); 880 LOGERR("device_responder no pending msg");
872 return; /* no controlvm response needed */ 881 return; /* no controlvm response needed */
873 } 882 }
874 if (p->pendingMsgHdr.Id != cmdId) { 883 if (p->pending_msg_hdr.id != cmdId) {
875 LOGERR("expected=%d, found=%d", cmdId, p->pendingMsgHdr.Id); 884 LOGERR("expected=%d, found=%d", cmdId, p->pending_msg_hdr.id);
876 return; 885 return;
877 } 886 }
878 887
879 controlvm_init_response(&outmsg, &p->pendingMsgHdr, response); 888 controlvm_init_response(&outmsg, &p->pending_msg_hdr, response);
880 889
881 outmsg.cmd.deviceChangeState.busNo = busNo; 890 outmsg.cmd.device_change_state.bus_no = busNo;
882 outmsg.cmd.deviceChangeState.devNo = devNo; 891 outmsg.cmd.device_change_state.dev_no = devNo;
883 outmsg.cmd.deviceChangeState.state = responseState; 892 outmsg.cmd.device_change_state.state = responseState;
884 893
885 if (!visorchannel_signalinsert(ControlVm_channel, 894 if (!visorchannel_signalinsert(ControlVm_channel,
886 CONTROLVM_QUEUE_REQUEST, &outmsg)) { 895 CONTROLVM_QUEUE_REQUEST, &outmsg)) {
@@ -888,13 +897,14 @@ device_changestate_responder(CONTROLVM_ID cmdId,
888 return; 897 return;
889 } 898 }
890 899
891 p->pendingMsgHdr.Id = CONTROLVM_INVALID; 900 p->pending_msg_hdr.id = CONTROLVM_INVALID;
892} 901}
893 902
894static void 903static void
895device_responder(CONTROLVM_ID cmdId, ulong busNo, ulong devNo, int response) 904device_responder(enum controlvm_id cmdId, ulong busNo, ulong devNo,
905 int response)
896{ 906{
897 VISORCHIPSET_DEVICE_INFO *p = NULL; 907 struct visorchipset_device_info *p = NULL;
898 BOOL need_clear = FALSE; 908 BOOL need_clear = FALSE;
899 909
900 p = finddevice(&DevInfoList, busNo, devNo); 910 p = finddevice(&DevInfoList, busNo, devNo);
@@ -909,38 +919,38 @@ device_responder(CONTROLVM_ID cmdId, ulong busNo, ulong devNo, int response)
909 need_clear = TRUE; 919 need_clear = TRUE;
910 } 920 }
911 921
912 if (p->pendingMsgHdr.Id == CONTROLVM_INVALID) { 922 if (p->pending_msg_hdr.id == CONTROLVM_INVALID) {
913 LOGERR("device_responder no pending msg"); 923 LOGERR("device_responder no pending msg");
914 return; /* no controlvm response needed */ 924 return; /* no controlvm response needed */
915 } 925 }
916 if (p->pendingMsgHdr.Id != (u32) cmdId) { 926 if (p->pending_msg_hdr.id != (u32) cmdId) {
917 LOGERR("expected=%d, found=%d", cmdId, p->pendingMsgHdr.Id); 927 LOGERR("expected=%d, found=%d", cmdId, p->pending_msg_hdr.id);
918 return; 928 return;
919 } 929 }
920 controlvm_respond(&p->pendingMsgHdr, response); 930 controlvm_respond(&p->pending_msg_hdr, response);
921 p->pendingMsgHdr.Id = CONTROLVM_INVALID; 931 p->pending_msg_hdr.id = CONTROLVM_INVALID;
922 if (need_clear) 932 if (need_clear)
923 devInfo_clear(p); 933 devInfo_clear(p);
924} 934}
925 935
926static void 936static void
927bus_epilog(u32 busNo, 937bus_epilog(u32 busNo,
928 u32 cmd, CONTROLVM_MESSAGE_HEADER *msgHdr, 938 u32 cmd, struct controlvm_message_header *msgHdr,
929 int response, BOOL needResponse) 939 int response, BOOL needResponse)
930{ 940{
931 BOOL notified = FALSE; 941 BOOL notified = FALSE;
932 942
933 VISORCHIPSET_BUS_INFO *pBusInfo = findbus(&BusInfoList, busNo); 943 struct visorchipset_bus_info *pBusInfo = findbus(&BusInfoList, busNo);
934 944
935 if (!pBusInfo) { 945 if (!pBusInfo) {
936 LOGERR("HUH? bad busNo=%d", busNo); 946 LOGERR("HUH? bad busNo=%d", busNo);
937 return; 947 return;
938 } 948 }
939 if (needResponse) { 949 if (needResponse) {
940 memcpy(&pBusInfo->pendingMsgHdr, msgHdr, 950 memcpy(&pBusInfo->pending_msg_hdr, msgHdr,
941 sizeof(CONTROLVM_MESSAGE_HEADER)); 951 sizeof(struct controlvm_message_header));
942 } else 952 } else
943 pBusInfo->pendingMsgHdr.Id = CONTROLVM_INVALID; 953 pBusInfo->pending_msg_hdr.id = CONTROLVM_INVALID;
944 954
945 down(&NotifierLock); 955 down(&NotifierLock);
946 if (response == CONTROLVM_RESP_SUCCESS) { 956 if (response == CONTROLVM_RESP_SUCCESS) {
@@ -981,7 +991,7 @@ bus_epilog(u32 busNo,
981 } 991 }
982 if (notified) 992 if (notified)
983 /* The callback function just called above is responsible 993 /* The callback function just called above is responsible
984 * for calling the appropriate VISORCHIPSET_BUSDEV_RESPONDERS 994 * for calling the appropriate visorchipset_busdev_responders
985 * function, which will call bus_responder() 995 * function, which will call bus_responder()
986 */ 996 */
987 ; 997 ;
@@ -991,14 +1001,14 @@ bus_epilog(u32 busNo,
991} 1001}
992 1002
993static void 1003static void
994device_epilog(u32 busNo, u32 devNo, ULTRA_SEGMENT_STATE state, u32 cmd, 1004device_epilog(u32 busNo, u32 devNo, struct spar_segment_state state, u32 cmd,
995 CONTROLVM_MESSAGE_HEADER *msgHdr, int response, 1005 struct controlvm_message_header *msgHdr, int response,
996 BOOL needResponse, BOOL for_visorbus) 1006 BOOL needResponse, BOOL for_visorbus)
997{ 1007{
998 VISORCHIPSET_BUSDEV_NOTIFIERS *notifiers = NULL; 1008 struct visorchipset_busdev_notifiers *notifiers = NULL;
999 BOOL notified = FALSE; 1009 BOOL notified = FALSE;
1000 1010
1001 VISORCHIPSET_DEVICE_INFO *pDevInfo = 1011 struct visorchipset_device_info *pDevInfo =
1002 finddevice(&DevInfoList, busNo, devNo); 1012 finddevice(&DevInfoList, busNo, devNo);
1003 char *envp[] = { 1013 char *envp[] = {
1004 "SPARSP_DIAGPOOL_PAUSED_STATE = 1", 1014 "SPARSP_DIAGPOOL_PAUSED_STATE = 1",
@@ -1014,10 +1024,10 @@ device_epilog(u32 busNo, u32 devNo, ULTRA_SEGMENT_STATE state, u32 cmd,
1014 else 1024 else
1015 notifiers = &BusDev_Client_Notifiers; 1025 notifiers = &BusDev_Client_Notifiers;
1016 if (needResponse) { 1026 if (needResponse) {
1017 memcpy(&pDevInfo->pendingMsgHdr, msgHdr, 1027 memcpy(&pDevInfo->pending_msg_hdr, msgHdr,
1018 sizeof(CONTROLVM_MESSAGE_HEADER)); 1028 sizeof(struct controlvm_message_header));
1019 } else 1029 } else
1020 pDevInfo->pendingMsgHdr.Id = CONTROLVM_INVALID; 1030 pDevInfo->pending_msg_hdr.id = CONTROLVM_INVALID;
1021 1031
1022 down(&NotifierLock); 1032 down(&NotifierLock);
1023 if (response >= 0) { 1033 if (response >= 0) {
@@ -1030,8 +1040,9 @@ device_epilog(u32 busNo, u32 devNo, ULTRA_SEGMENT_STATE state, u32 cmd,
1030 break; 1040 break;
1031 case CONTROLVM_DEVICE_CHANGESTATE: 1041 case CONTROLVM_DEVICE_CHANGESTATE:
1032 /* ServerReady / ServerRunning / SegmentStateRunning */ 1042 /* ServerReady / ServerRunning / SegmentStateRunning */
1033 if (state.Alive == SegmentStateRunning.Alive && 1043 if (state.alive == segment_state_running.alive &&
1034 state.Operating == SegmentStateRunning.Operating) { 1044 state.operating ==
1045 segment_state_running.operating) {
1035 if (notifiers->device_resume) { 1046 if (notifiers->device_resume) {
1036 (*notifiers->device_resume) (busNo, 1047 (*notifiers->device_resume) (busNo,
1037 devNo); 1048 devNo);
@@ -1039,9 +1050,9 @@ device_epilog(u32 busNo, u32 devNo, ULTRA_SEGMENT_STATE state, u32 cmd,
1039 } 1050 }
1040 } 1051 }
1041 /* ServerNotReady / ServerLost / SegmentStateStandby */ 1052 /* ServerNotReady / ServerLost / SegmentStateStandby */
1042 else if (state.Alive == SegmentStateStandby.Alive && 1053 else if (state.alive == segment_state_standby.alive &&
1043 state.Operating == 1054 state.operating ==
1044 SegmentStateStandby.Operating) { 1055 segment_state_standby.operating) {
1045 /* technically this is standby case 1056 /* technically this is standby case
1046 * where server is lost 1057 * where server is lost
1047 */ 1058 */
@@ -1050,9 +1061,9 @@ device_epilog(u32 busNo, u32 devNo, ULTRA_SEGMENT_STATE state, u32 cmd,
1050 devNo); 1061 devNo);
1051 notified = TRUE; 1062 notified = TRUE;
1052 } 1063 }
1053 } else if (state.Alive == SegmentStatePaused.Alive && 1064 } else if (state.alive == segment_state_paused.alive &&
1054 state.Operating == 1065 state.operating ==
1055 SegmentStatePaused.Operating) { 1066 segment_state_paused.operating) {
1056 /* this is lite pause where channel is 1067 /* this is lite pause where channel is
1057 * still valid just 'pause' of it 1068 * still valid just 'pause' of it
1058 */ 1069 */
@@ -1079,7 +1090,7 @@ device_epilog(u32 busNo, u32 devNo, ULTRA_SEGMENT_STATE state, u32 cmd,
1079 } 1090 }
1080 if (notified) 1091 if (notified)
1081 /* The callback function just called above is responsible 1092 /* The callback function just called above is responsible
1082 * for calling the appropriate VISORCHIPSET_BUSDEV_RESPONDERS 1093 * for calling the appropriate visorchipset_busdev_responders
1083 * function, which will call device_responder() 1094 * function, which will call device_responder()
1084 */ 1095 */
1085 ; 1096 ;
@@ -1089,12 +1100,12 @@ device_epilog(u32 busNo, u32 devNo, ULTRA_SEGMENT_STATE state, u32 cmd,
1089} 1100}
1090 1101
1091static void 1102static void
1092bus_create(CONTROLVM_MESSAGE *inmsg) 1103bus_create(struct controlvm_message *inmsg)
1093{ 1104{
1094 CONTROLVM_MESSAGE_PACKET *cmd = &inmsg->cmd; 1105 struct controlvm_message_packet *cmd = &inmsg->cmd;
1095 ulong busNo = cmd->createBus.busNo; 1106 ulong busNo = cmd->create_bus.bus_no;
1096 int rc = CONTROLVM_RESP_SUCCESS; 1107 int rc = CONTROLVM_RESP_SUCCESS;
1097 VISORCHIPSET_BUS_INFO *pBusInfo = NULL; 1108 struct visorchipset_bus_info *pBusInfo = NULL;
1098 1109
1099 1110
1100 pBusInfo = findbus(&BusInfoList, busNo); 1111 pBusInfo = findbus(&BusInfoList, busNo);
@@ -1106,7 +1117,7 @@ bus_create(CONTROLVM_MESSAGE *inmsg)
1106 rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE; 1117 rc = -CONTROLVM_RESP_ERROR_ALREADY_DONE;
1107 goto Away; 1118 goto Away;
1108 } 1119 }
1109 pBusInfo = kzalloc(sizeof(VISORCHIPSET_BUS_INFO), GFP_KERNEL); 1120 pBusInfo = kzalloc(sizeof(struct visorchipset_bus_info), GFP_KERNEL);
1110 if (pBusInfo == NULL) { 1121 if (pBusInfo == NULL) {
1111 LOGERR("CONTROLVM_BUS_CREATE Failed: bus %lu kzalloc failed", 1122 LOGERR("CONTROLVM_BUS_CREATE Failed: bus %lu kzalloc failed",
1112 busNo); 1123 busNo);
@@ -1117,21 +1128,22 @@ bus_create(CONTROLVM_MESSAGE *inmsg)
1117 } 1128 }
1118 1129
1119 INIT_LIST_HEAD(&pBusInfo->entry); 1130 INIT_LIST_HEAD(&pBusInfo->entry);
1120 pBusInfo->busNo = busNo; 1131 pBusInfo->bus_no = busNo;
1121 pBusInfo->devNo = cmd->createBus.deviceCount; 1132 pBusInfo->dev_no = cmd->create_bus.dev_count;
1122 1133
1123 POSTCODE_LINUX_3(BUS_CREATE_ENTRY_PC, busNo, POSTCODE_SEVERITY_INFO); 1134 POSTCODE_LINUX_3(BUS_CREATE_ENTRY_PC, busNo, POSTCODE_SEVERITY_INFO);
1124 1135
1125 if (inmsg->hdr.Flags.testMessage == 1) 1136 if (inmsg->hdr.flags.test_message == 1)
1126 pBusInfo->chanInfo.addrType = ADDRTYPE_localTest; 1137 pBusInfo->chan_info.addr_type = ADDRTYPE_LOCALTEST;
1127 else 1138 else
1128 pBusInfo->chanInfo.addrType = ADDRTYPE_localPhysical; 1139 pBusInfo->chan_info.addr_type = ADDRTYPE_LOCALPHYSICAL;
1129 1140
1130 pBusInfo->flags.server = inmsg->hdr.Flags.server; 1141 pBusInfo->flags.server = inmsg->hdr.flags.server;
1131 pBusInfo->chanInfo.channelAddr = cmd->createBus.channelAddr; 1142 pBusInfo->chan_info.channel_addr = cmd->create_bus.channel_addr;
1132 pBusInfo->chanInfo.nChannelBytes = cmd->createBus.channelBytes; 1143 pBusInfo->chan_info.n_channel_bytes = cmd->create_bus.channel_bytes;
1133 pBusInfo->chanInfo.channelTypeGuid = cmd->createBus.busDataTypeGuid; 1144 pBusInfo->chan_info.channel_type_uuid =
1134 pBusInfo->chanInfo.channelInstGuid = cmd->createBus.busInstGuid; 1145 cmd->create_bus.bus_data_type_uuid;
1146 pBusInfo->chan_info.channel_inst_uuid = cmd->create_bus.bus_inst_uuid;
1135 1147
1136 list_add(&pBusInfo->entry, &BusInfoList); 1148 list_add(&pBusInfo->entry, &BusInfoList);
1137 1149
@@ -1139,15 +1151,15 @@ bus_create(CONTROLVM_MESSAGE *inmsg)
1139 1151
1140Away: 1152Away:
1141 bus_epilog(busNo, CONTROLVM_BUS_CREATE, &inmsg->hdr, 1153 bus_epilog(busNo, CONTROLVM_BUS_CREATE, &inmsg->hdr,
1142 rc, inmsg->hdr.Flags.responseExpected == 1); 1154 rc, inmsg->hdr.flags.response_expected == 1);
1143} 1155}
1144 1156
1145static void 1157static void
1146bus_destroy(CONTROLVM_MESSAGE *inmsg) 1158bus_destroy(struct controlvm_message *inmsg)
1147{ 1159{
1148 CONTROLVM_MESSAGE_PACKET *cmd = &inmsg->cmd; 1160 struct controlvm_message_packet *cmd = &inmsg->cmd;
1149 ulong busNo = cmd->destroyBus.busNo; 1161 ulong busNo = cmd->destroy_bus.bus_no;
1150 VISORCHIPSET_BUS_INFO *pBusInfo; 1162 struct visorchipset_bus_info *pBusInfo;
1151 int rc = CONTROLVM_RESP_SUCCESS; 1163 int rc = CONTROLVM_RESP_SUCCESS;
1152 1164
1153 pBusInfo = findbus(&BusInfoList, busNo); 1165 pBusInfo = findbus(&BusInfoList, busNo);
@@ -1165,19 +1177,19 @@ bus_destroy(CONTROLVM_MESSAGE *inmsg)
1165 1177
1166Away: 1178Away:
1167 bus_epilog(busNo, CONTROLVM_BUS_DESTROY, &inmsg->hdr, 1179 bus_epilog(busNo, CONTROLVM_BUS_DESTROY, &inmsg->hdr,
1168 rc, inmsg->hdr.Flags.responseExpected == 1); 1180 rc, inmsg->hdr.flags.response_expected == 1);
1169} 1181}
1170 1182
1171static void 1183static void
1172bus_configure(CONTROLVM_MESSAGE *inmsg, PARSER_CONTEXT *parser_ctx) 1184bus_configure(struct controlvm_message *inmsg, PARSER_CONTEXT *parser_ctx)
1173{ 1185{
1174 CONTROLVM_MESSAGE_PACKET *cmd = &inmsg->cmd; 1186 struct controlvm_message_packet *cmd = &inmsg->cmd;
1175 ulong busNo = cmd->configureBus.busNo; 1187 ulong busNo = cmd->configure_bus.bus_no;
1176 VISORCHIPSET_BUS_INFO *pBusInfo = NULL; 1188 struct visorchipset_bus_info *pBusInfo = NULL;
1177 int rc = CONTROLVM_RESP_SUCCESS; 1189 int rc = CONTROLVM_RESP_SUCCESS;
1178 char s[99]; 1190 char s[99];
1179 1191
1180 busNo = cmd->configureBus.busNo; 1192 busNo = cmd->configure_bus.bus_no;
1181 POSTCODE_LINUX_3(BUS_CONFIGURE_ENTRY_PC, busNo, POSTCODE_SEVERITY_INFO); 1193 POSTCODE_LINUX_3(BUS_CONFIGURE_ENTRY_PC, busNo, POSTCODE_SEVERITY_INFO);
1182 1194
1183 pBusInfo = findbus(&BusInfoList, busNo); 1195 pBusInfo = findbus(&BusInfoList, busNo);
@@ -1198,35 +1210,35 @@ bus_configure(CONTROLVM_MESSAGE *inmsg, PARSER_CONTEXT *parser_ctx)
1198 goto Away; 1210 goto Away;
1199 } 1211 }
1200 /* TBD - add this check to other commands also... */ 1212 /* TBD - add this check to other commands also... */
1201 if (pBusInfo->pendingMsgHdr.Id != CONTROLVM_INVALID) { 1213 if (pBusInfo->pending_msg_hdr.id != CONTROLVM_INVALID) {
1202 LOGERR("CONTROLVM_BUS_CONFIGURE Failed: bus %lu MsgId=%u outstanding", 1214 LOGERR("CONTROLVM_BUS_CONFIGURE Failed: bus %lu MsgId=%u outstanding",
1203 busNo, (uint) pBusInfo->pendingMsgHdr.Id); 1215 busNo, (uint) pBusInfo->pending_msg_hdr.id);
1204 POSTCODE_LINUX_3(BUS_CONFIGURE_FAILURE_PC, busNo, 1216 POSTCODE_LINUX_3(BUS_CONFIGURE_FAILURE_PC, busNo,
1205 POSTCODE_SEVERITY_ERR); 1217 POSTCODE_SEVERITY_ERR);
1206 rc = -CONTROLVM_RESP_ERROR_MESSAGE_ID_INVALID_FOR_CLIENT; 1218 rc = -CONTROLVM_RESP_ERROR_MESSAGE_ID_INVALID_FOR_CLIENT;
1207 goto Away; 1219 goto Away;
1208 } 1220 }
1209 1221
1210 pBusInfo->partitionHandle = cmd->configureBus.guestHandle; 1222 pBusInfo->partition_handle = cmd->configure_bus.guest_handle;
1211 pBusInfo->partitionGuid = parser_id_get(parser_ctx); 1223 pBusInfo->partition_uuid = parser_id_get(parser_ctx);
1212 parser_param_start(parser_ctx, PARSERSTRING_NAME); 1224 parser_param_start(parser_ctx, PARSERSTRING_NAME);
1213 pBusInfo->name = parser_string_get(parser_ctx); 1225 pBusInfo->name = parser_string_get(parser_ctx);
1214 1226
1215 visorchannel_uuid_id(&pBusInfo->partitionGuid, s); 1227 visorchannel_uuid_id(&pBusInfo->partition_uuid, s);
1216 POSTCODE_LINUX_3(BUS_CONFIGURE_EXIT_PC, busNo, POSTCODE_SEVERITY_INFO); 1228 POSTCODE_LINUX_3(BUS_CONFIGURE_EXIT_PC, busNo, POSTCODE_SEVERITY_INFO);
1217Away: 1229Away:
1218 bus_epilog(busNo, CONTROLVM_BUS_CONFIGURE, &inmsg->hdr, 1230 bus_epilog(busNo, CONTROLVM_BUS_CONFIGURE, &inmsg->hdr,
1219 rc, inmsg->hdr.Flags.responseExpected == 1); 1231 rc, inmsg->hdr.flags.response_expected == 1);
1220} 1232}
1221 1233
1222static void 1234static void
1223my_device_create(CONTROLVM_MESSAGE *inmsg) 1235my_device_create(struct controlvm_message *inmsg)
1224{ 1236{
1225 CONTROLVM_MESSAGE_PACKET *cmd = &inmsg->cmd; 1237 struct controlvm_message_packet *cmd = &inmsg->cmd;
1226 ulong busNo = cmd->createDevice.busNo; 1238 ulong busNo = cmd->create_device.bus_no;
1227 ulong devNo = cmd->createDevice.devNo; 1239 ulong devNo = cmd->create_device.dev_no;
1228 VISORCHIPSET_DEVICE_INFO *pDevInfo = NULL; 1240 struct visorchipset_device_info *pDevInfo = NULL;
1229 VISORCHIPSET_BUS_INFO *pBusInfo = NULL; 1241 struct visorchipset_bus_info *pBusInfo = NULL;
1230 int rc = CONTROLVM_RESP_SUCCESS; 1242 int rc = CONTROLVM_RESP_SUCCESS;
1231 1243
1232 pDevInfo = finddevice(&DevInfoList, busNo, devNo); 1244 pDevInfo = finddevice(&DevInfoList, busNo, devNo);
@@ -1255,7 +1267,7 @@ my_device_create(CONTROLVM_MESSAGE *inmsg)
1255 rc = -CONTROLVM_RESP_ERROR_BUS_INVALID; 1267 rc = -CONTROLVM_RESP_ERROR_BUS_INVALID;
1256 goto Away; 1268 goto Away;
1257 } 1269 }
1258 pDevInfo = kzalloc(sizeof(VISORCHIPSET_DEVICE_INFO), GFP_KERNEL); 1270 pDevInfo = kzalloc(sizeof(struct visorchipset_device_info), GFP_KERNEL);
1259 if (pDevInfo == NULL) { 1271 if (pDevInfo == NULL) {
1260 LOGERR("CONTROLVM_DEVICE_CREATE Failed: busNo=%lu, devNo=%lu kmaloc failed", 1272 LOGERR("CONTROLVM_DEVICE_CREATE Failed: busNo=%lu, devNo=%lu kmaloc failed",
1261 busNo, devNo); 1273 busNo, devNo);
@@ -1266,45 +1278,47 @@ my_device_create(CONTROLVM_MESSAGE *inmsg)
1266 } 1278 }
1267 1279
1268 INIT_LIST_HEAD(&pDevInfo->entry); 1280 INIT_LIST_HEAD(&pDevInfo->entry);
1269 pDevInfo->busNo = busNo; 1281 pDevInfo->bus_no = busNo;
1270 pDevInfo->devNo = devNo; 1282 pDevInfo->dev_no = devNo;
1271 pDevInfo->devInstGuid = cmd->createDevice.devInstGuid; 1283 pDevInfo->dev_inst_uuid = cmd->create_device.dev_inst_uuid;
1272 POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC, devNo, busNo, 1284 POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC, devNo, busNo,
1273 POSTCODE_SEVERITY_INFO); 1285 POSTCODE_SEVERITY_INFO);
1274 1286
1275 if (inmsg->hdr.Flags.testMessage == 1) 1287 if (inmsg->hdr.flags.test_message == 1)
1276 pDevInfo->chanInfo.addrType = ADDRTYPE_localTest; 1288 pDevInfo->chan_info.addr_type = ADDRTYPE_LOCALTEST;
1277 else 1289 else
1278 pDevInfo->chanInfo.addrType = ADDRTYPE_localPhysical; 1290 pDevInfo->chan_info.addr_type = ADDRTYPE_LOCALPHYSICAL;
1279 pDevInfo->chanInfo.channelAddr = cmd->createDevice.channelAddr; 1291 pDevInfo->chan_info.channel_addr = cmd->create_device.channel_addr;
1280 pDevInfo->chanInfo.nChannelBytes = cmd->createDevice.channelBytes; 1292 pDevInfo->chan_info.n_channel_bytes = cmd->create_device.channel_bytes;
1281 pDevInfo->chanInfo.channelTypeGuid = cmd->createDevice.dataTypeGuid; 1293 pDevInfo->chan_info.channel_type_uuid =
1282 pDevInfo->chanInfo.intr = cmd->createDevice.intr; 1294 cmd->create_device.data_type_uuid;
1295 pDevInfo->chan_info.intr = cmd->create_device.intr;
1283 list_add(&pDevInfo->entry, &DevInfoList); 1296 list_add(&pDevInfo->entry, &DevInfoList);
1284 POSTCODE_LINUX_4(DEVICE_CREATE_EXIT_PC, devNo, busNo, 1297 POSTCODE_LINUX_4(DEVICE_CREATE_EXIT_PC, devNo, busNo,
1285 POSTCODE_SEVERITY_INFO); 1298 POSTCODE_SEVERITY_INFO);
1286Away: 1299Away:
1287 /* get the bus and devNo for DiagPool channel */ 1300 /* get the bus and devNo for DiagPool channel */
1288 if (is_diagpool_channel(pDevInfo->chanInfo.channelTypeGuid)) { 1301 if (pDevInfo &&
1302 is_diagpool_channel(pDevInfo->chan_info.channel_type_uuid)) {
1289 g_diagpoolBusNo = busNo; 1303 g_diagpoolBusNo = busNo;
1290 g_diagpoolDevNo = devNo; 1304 g_diagpoolDevNo = devNo;
1291 LOGINF("CONTROLVM_DEVICE_CREATE for DiagPool channel: busNo=%lu, devNo=%lu", 1305 LOGINF("CONTROLVM_DEVICE_CREATE for DiagPool channel: busNo=%lu, devNo=%lu",
1292 g_diagpoolBusNo, g_diagpoolDevNo); 1306 g_diagpoolBusNo, g_diagpoolDevNo);
1293 } 1307 }
1294 device_epilog(busNo, devNo, SegmentStateRunning, 1308 device_epilog(busNo, devNo, segment_state_running,
1295 CONTROLVM_DEVICE_CREATE, &inmsg->hdr, rc, 1309 CONTROLVM_DEVICE_CREATE, &inmsg->hdr, rc,
1296 inmsg->hdr.Flags.responseExpected == 1, 1310 inmsg->hdr.flags.response_expected == 1,
1297 FOR_VISORBUS(pDevInfo->chanInfo.channelTypeGuid)); 1311 FOR_VISORBUS(pDevInfo->chan_info.channel_type_uuid));
1298} 1312}
1299 1313
1300static void 1314static void
1301my_device_changestate(CONTROLVM_MESSAGE *inmsg) 1315my_device_changestate(struct controlvm_message *inmsg)
1302{ 1316{
1303 CONTROLVM_MESSAGE_PACKET *cmd = &inmsg->cmd; 1317 struct controlvm_message_packet *cmd = &inmsg->cmd;
1304 ulong busNo = cmd->deviceChangeState.busNo; 1318 ulong busNo = cmd->device_change_state.bus_no;
1305 ulong devNo = cmd->deviceChangeState.devNo; 1319 ulong devNo = cmd->device_change_state.dev_no;
1306 ULTRA_SEGMENT_STATE state = cmd->deviceChangeState.state; 1320 struct spar_segment_state state = cmd->device_change_state.state;
1307 VISORCHIPSET_DEVICE_INFO *pDevInfo = NULL; 1321 struct visorchipset_device_info *pDevInfo = NULL;
1308 int rc = CONTROLVM_RESP_SUCCESS; 1322 int rc = CONTROLVM_RESP_SUCCESS;
1309 1323
1310 pDevInfo = finddevice(&DevInfoList, busNo, devNo); 1324 pDevInfo = finddevice(&DevInfoList, busNo, devNo);
@@ -1327,17 +1341,18 @@ Away:
1327 if ((rc >= CONTROLVM_RESP_SUCCESS) && pDevInfo) 1341 if ((rc >= CONTROLVM_RESP_SUCCESS) && pDevInfo)
1328 device_epilog(busNo, devNo, state, CONTROLVM_DEVICE_CHANGESTATE, 1342 device_epilog(busNo, devNo, state, CONTROLVM_DEVICE_CHANGESTATE,
1329 &inmsg->hdr, rc, 1343 &inmsg->hdr, rc,
1330 inmsg->hdr.Flags.responseExpected == 1, 1344 inmsg->hdr.flags.response_expected == 1,
1331 FOR_VISORBUS(pDevInfo->chanInfo.channelTypeGuid)); 1345 FOR_VISORBUS(
1346 pDevInfo->chan_info.channel_type_uuid));
1332} 1347}
1333 1348
1334static void 1349static void
1335my_device_destroy(CONTROLVM_MESSAGE *inmsg) 1350my_device_destroy(struct controlvm_message *inmsg)
1336{ 1351{
1337 CONTROLVM_MESSAGE_PACKET *cmd = &inmsg->cmd; 1352 struct controlvm_message_packet *cmd = &inmsg->cmd;
1338 ulong busNo = cmd->destroyDevice.busNo; 1353 ulong busNo = cmd->destroy_device.bus_no;
1339 ulong devNo = cmd->destroyDevice.devNo; 1354 ulong devNo = cmd->destroy_device.dev_no;
1340 VISORCHIPSET_DEVICE_INFO *pDevInfo = NULL; 1355 struct visorchipset_device_info *pDevInfo = NULL;
1341 int rc = CONTROLVM_RESP_SUCCESS; 1356 int rc = CONTROLVM_RESP_SUCCESS;
1342 1357
1343 pDevInfo = finddevice(&DevInfoList, busNo, devNo); 1358 pDevInfo = finddevice(&DevInfoList, busNo, devNo);
@@ -1355,10 +1370,11 @@ my_device_destroy(CONTROLVM_MESSAGE *inmsg)
1355 1370
1356Away: 1371Away:
1357 if ((rc >= CONTROLVM_RESP_SUCCESS) && pDevInfo) 1372 if ((rc >= CONTROLVM_RESP_SUCCESS) && pDevInfo)
1358 device_epilog(busNo, devNo, SegmentStateRunning, 1373 device_epilog(busNo, devNo, segment_state_running,
1359 CONTROLVM_DEVICE_DESTROY, &inmsg->hdr, rc, 1374 CONTROLVM_DEVICE_DESTROY, &inmsg->hdr, rc,
1360 inmsg->hdr.Flags.responseExpected == 1, 1375 inmsg->hdr.flags.response_expected == 1,
1361 FOR_VISORBUS(pDevInfo->chanInfo.channelTypeGuid)); 1376 FOR_VISORBUS(
1377 pDevInfo->chan_info.channel_type_uuid));
1362} 1378}
1363 1379
1364/* When provided with the physical address of the controlvm channel 1380/* When provided with the physical address of the controlvm channel
@@ -1382,7 +1398,7 @@ initialize_controlvm_payload_info(HOSTADDRESS phys_addr, u64 offset, u32 bytes,
1382 } 1398 }
1383 memset(info, 0, sizeof(CONTROLVM_PAYLOAD_INFO)); 1399 memset(info, 0, sizeof(CONTROLVM_PAYLOAD_INFO));
1384 if ((offset == 0) || (bytes == 0)) { 1400 if ((offset == 0) || (bytes == 0)) {
1385 LOGERR("CONTROLVM_PAYLOAD_INIT Failed: RequestPayloadOffset=%llu RequestPayloadBytes=%llu!", 1401 LOGERR("CONTROLVM_PAYLOAD_INIT Failed: request_payload_offset=%llu request_payload_bytes=%llu!",
1386 (u64) offset, (u64) bytes); 1402 (u64) offset, (u64) bytes);
1387 rc = -CONTROLVM_RESP_ERROR_PAYLOAD_INVALID; 1403 rc = -CONTROLVM_RESP_ERROR_PAYLOAD_INVALID;
1388 goto Away; 1404 goto Away;
@@ -1429,8 +1445,8 @@ initialize_controlvm_payload(void)
1429 u32 payloadBytes = 0; 1445 u32 payloadBytes = 0;
1430 1446
1431 if (visorchannel_read(ControlVm_channel, 1447 if (visorchannel_read(ControlVm_channel,
1432 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL, 1448 offsetof(struct spar_controlvm_channel_protocol,
1433 RequestPayloadOffset), 1449 request_payload_offset),
1434 &payloadOffset, sizeof(payloadOffset)) < 0) { 1450 &payloadOffset, sizeof(payloadOffset)) < 0) {
1435 LOGERR("CONTROLVM_PAYLOAD_INIT Failed to read controlvm channel!"); 1451 LOGERR("CONTROLVM_PAYLOAD_INIT Failed to read controlvm channel!");
1436 POSTCODE_LINUX_2(CONTROLVM_INIT_FAILURE_PC, 1452 POSTCODE_LINUX_2(CONTROLVM_INIT_FAILURE_PC,
@@ -1438,8 +1454,8 @@ initialize_controlvm_payload(void)
1438 return; 1454 return;
1439 } 1455 }
1440 if (visorchannel_read(ControlVm_channel, 1456 if (visorchannel_read(ControlVm_channel,
1441 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL, 1457 offsetof(struct spar_controlvm_channel_protocol,
1442 RequestPayloadBytes), 1458 request_payload_bytes),
1443 &payloadBytes, sizeof(payloadBytes)) < 0) { 1459 &payloadBytes, sizeof(payloadBytes)) < 0) {
1444 LOGERR("CONTROLVM_PAYLOAD_INIT Failed to read controlvm channel!"); 1460 LOGERR("CONTROLVM_PAYLOAD_INIT Failed to read controlvm channel!");
1445 POSTCODE_LINUX_2(CONTROLVM_INIT_FAILURE_PC, 1461 POSTCODE_LINUX_2(CONTROLVM_INIT_FAILURE_PC,
@@ -1487,15 +1503,15 @@ visorchipset_chipset_notready(void)
1487EXPORT_SYMBOL_GPL(visorchipset_chipset_notready); 1503EXPORT_SYMBOL_GPL(visorchipset_chipset_notready);
1488 1504
1489static void 1505static void
1490chipset_ready(CONTROLVM_MESSAGE_HEADER *msgHdr) 1506chipset_ready(struct controlvm_message_header *msgHdr)
1491{ 1507{
1492 int rc = visorchipset_chipset_ready(); 1508 int rc = visorchipset_chipset_ready();
1493 1509
1494 if (rc != CONTROLVM_RESP_SUCCESS) 1510 if (rc != CONTROLVM_RESP_SUCCESS)
1495 rc = -rc; 1511 rc = -rc;
1496 if (msgHdr->Flags.responseExpected && !visorchipset_holdchipsetready) 1512 if (msgHdr->flags.response_expected && !visorchipset_holdchipsetready)
1497 controlvm_respond(msgHdr, rc); 1513 controlvm_respond(msgHdr, rc);
1498 if (msgHdr->Flags.responseExpected && visorchipset_holdchipsetready) { 1514 if (msgHdr->flags.response_expected && visorchipset_holdchipsetready) {
1499 /* Send CHIPSET_READY response when all modules have been loaded 1515 /* Send CHIPSET_READY response when all modules have been loaded
1500 * and disks mounted for the partition 1516 * and disks mounted for the partition
1501 */ 1517 */
@@ -1505,24 +1521,24 @@ chipset_ready(CONTROLVM_MESSAGE_HEADER *msgHdr)
1505} 1521}
1506 1522
1507static void 1523static void
1508chipset_selftest(CONTROLVM_MESSAGE_HEADER *msgHdr) 1524chipset_selftest(struct controlvm_message_header *msgHdr)
1509{ 1525{
1510 int rc = visorchipset_chipset_selftest(); 1526 int rc = visorchipset_chipset_selftest();
1511 1527
1512 if (rc != CONTROLVM_RESP_SUCCESS) 1528 if (rc != CONTROLVM_RESP_SUCCESS)
1513 rc = -rc; 1529 rc = -rc;
1514 if (msgHdr->Flags.responseExpected) 1530 if (msgHdr->flags.response_expected)
1515 controlvm_respond(msgHdr, rc); 1531 controlvm_respond(msgHdr, rc);
1516} 1532}
1517 1533
1518static void 1534static void
1519chipset_notready(CONTROLVM_MESSAGE_HEADER *msgHdr) 1535chipset_notready(struct controlvm_message_header *msgHdr)
1520{ 1536{
1521 int rc = visorchipset_chipset_notready(); 1537 int rc = visorchipset_chipset_notready();
1522 1538
1523 if (rc != CONTROLVM_RESP_SUCCESS) 1539 if (rc != CONTROLVM_RESP_SUCCESS)
1524 rc = -rc; 1540 rc = -rc;
1525 if (msgHdr->Flags.responseExpected) 1541 if (msgHdr->flags.response_expected)
1526 controlvm_respond(msgHdr, rc); 1542 controlvm_respond(msgHdr, rc);
1527} 1543}
1528 1544
@@ -1530,13 +1546,14 @@ chipset_notready(CONTROLVM_MESSAGE_HEADER *msgHdr)
1530 * CONTROLVM_QUEUE_EVENT queue in the controlvm channel. 1546 * CONTROLVM_QUEUE_EVENT queue in the controlvm channel.
1531 */ 1547 */
1532static BOOL 1548static BOOL
1533read_controlvm_event(CONTROLVM_MESSAGE *msg) 1549read_controlvm_event(struct controlvm_message *msg)
1534{ 1550{
1535 if (visorchannel_signalremove(ControlVm_channel, 1551 if (visorchannel_signalremove(ControlVm_channel,
1536 CONTROLVM_QUEUE_EVENT, msg)) { 1552 CONTROLVM_QUEUE_EVENT, msg)) {
1537 /* got a message */ 1553 /* got a message */
1538 if (msg->hdr.Flags.testMessage == 1) { 1554 if (msg->hdr.flags.test_message == 1) {
1539 LOGERR("ignoring bad CONTROLVM_QUEUE_EVENT msg with controlvm_msg_id=0x%x because Flags.testMessage is nonsensical (=1)", msg->hdr.Id); 1555 LOGERR("ignoring bad CONTROLVM_QUEUE_EVENT msg with controlvm_msg_id=0x%x because Flags.testMessage is nonsensical (=1)",
1556 msg->hdr.id);
1540 return FALSE; 1557 return FALSE;
1541 } 1558 }
1542 return TRUE; 1559 return TRUE;
@@ -1586,7 +1603,7 @@ parahotplug_next_expiration(void)
1586 * CONTROLVM_MESSAGE that we can stick on a list 1603 * CONTROLVM_MESSAGE that we can stick on a list
1587 */ 1604 */
1588static struct parahotplug_request * 1605static struct parahotplug_request *
1589parahotplug_request_create(CONTROLVM_MESSAGE *msg) 1606parahotplug_request_create(struct controlvm_message *msg)
1590{ 1607{
1591 struct parahotplug_request *req = 1608 struct parahotplug_request *req =
1592 kmalloc(sizeof(struct parahotplug_request), 1609 kmalloc(sizeof(struct parahotplug_request),
@@ -1618,7 +1635,7 @@ parahotplug_request_destroy(struct parahotplug_request *req)
1618static void 1635static void
1619parahotplug_request_kickoff(struct parahotplug_request *req) 1636parahotplug_request_kickoff(struct parahotplug_request *req)
1620{ 1637{
1621 CONTROLVM_MESSAGE_PACKET *cmd = &req->msg.cmd; 1638 struct controlvm_message_packet *cmd = &req->msg.cmd;
1622 char env_cmd[40], env_id[40], env_state[40], env_bus[40], env_dev[40], 1639 char env_cmd[40], env_id[40], env_state[40], env_bus[40], env_dev[40],
1623 env_func[40]; 1640 env_func[40];
1624 char *envp[] = { 1641 char *envp[] = {
@@ -1628,18 +1645,19 @@ parahotplug_request_kickoff(struct parahotplug_request *req)
1628 sprintf(env_cmd, "SPAR_PARAHOTPLUG=1"); 1645 sprintf(env_cmd, "SPAR_PARAHOTPLUG=1");
1629 sprintf(env_id, "SPAR_PARAHOTPLUG_ID=%d", req->id); 1646 sprintf(env_id, "SPAR_PARAHOTPLUG_ID=%d", req->id);
1630 sprintf(env_state, "SPAR_PARAHOTPLUG_STATE=%d", 1647 sprintf(env_state, "SPAR_PARAHOTPLUG_STATE=%d",
1631 cmd->deviceChangeState.state.Active); 1648 cmd->device_change_state.state.active);
1632 sprintf(env_bus, "SPAR_PARAHOTPLUG_BUS=%d", 1649 sprintf(env_bus, "SPAR_PARAHOTPLUG_BUS=%d",
1633 cmd->deviceChangeState.busNo); 1650 cmd->device_change_state.bus_no);
1634 sprintf(env_dev, "SPAR_PARAHOTPLUG_DEVICE=%d", 1651 sprintf(env_dev, "SPAR_PARAHOTPLUG_DEVICE=%d",
1635 cmd->deviceChangeState.devNo >> 3); 1652 cmd->device_change_state.dev_no >> 3);
1636 sprintf(env_func, "SPAR_PARAHOTPLUG_FUNCTION=%d", 1653 sprintf(env_func, "SPAR_PARAHOTPLUG_FUNCTION=%d",
1637 cmd->deviceChangeState.devNo & 0x7); 1654 cmd->device_change_state.dev_no & 0x7);
1638 1655
1639 LOGINF("parahotplug_request_kickoff: state=%d, bdf=%d/%d/%d, id=%u\n", 1656 LOGINF("parahotplug_request_kickoff: state=%d, bdf=%d/%d/%d, id=%u\n",
1640 cmd->deviceChangeState.state.Active, 1657 cmd->device_change_state.state.active,
1641 cmd->deviceChangeState.busNo, cmd->deviceChangeState.devNo >> 3, 1658 cmd->device_change_state.bus_no,
1642 cmd->deviceChangeState.devNo & 7, req->id); 1659 cmd->device_change_state.dev_no >> 3,
1660 cmd->device_change_state.dev_no & 7, req->id);
1643 1661
1644 kobject_uevent_env(&Visorchipset_platform_device.dev.kobj, KOBJ_CHANGE, 1662 kobject_uevent_env(&Visorchipset_platform_device.dev.kobj, KOBJ_CHANGE,
1645 envp); 1663 envp);
@@ -1662,11 +1680,11 @@ parahotplug_process_list(void)
1662 list_entry(pos, struct parahotplug_request, list); 1680 list_entry(pos, struct parahotplug_request, list);
1663 if (time_after_eq(jiffies, req->expiration)) { 1681 if (time_after_eq(jiffies, req->expiration)) {
1664 list_del(pos); 1682 list_del(pos);
1665 if (req->msg.hdr.Flags.responseExpected) 1683 if (req->msg.hdr.flags.response_expected)
1666 controlvm_respond_physdev_changestate( 1684 controlvm_respond_physdev_changestate(
1667 &req->msg.hdr, 1685 &req->msg.hdr,
1668 CONTROLVM_RESP_ERROR_DEVICE_UDEV_TIMEOUT, 1686 CONTROLVM_RESP_ERROR_DEVICE_UDEV_TIMEOUT,
1669 req->msg.cmd.deviceChangeState.state); 1687 req->msg.cmd.device_change_state.state);
1670 parahotplug_request_destroy(req); 1688 parahotplug_request_destroy(req);
1671 } 1689 }
1672 } 1690 }
@@ -1697,11 +1715,11 @@ parahotplug_request_complete(int id, u16 active)
1697 */ 1715 */
1698 list_del(pos); 1716 list_del(pos);
1699 spin_unlock(&Parahotplug_request_list_lock); 1717 spin_unlock(&Parahotplug_request_list_lock);
1700 req->msg.cmd.deviceChangeState.state.Active = active; 1718 req->msg.cmd.device_change_state.state.active = active;
1701 if (req->msg.hdr.Flags.responseExpected) 1719 if (req->msg.hdr.flags.response_expected)
1702 controlvm_respond_physdev_changestate( 1720 controlvm_respond_physdev_changestate(
1703 &req->msg.hdr, CONTROLVM_RESP_SUCCESS, 1721 &req->msg.hdr, CONTROLVM_RESP_SUCCESS,
1704 req->msg.cmd.deviceChangeState.state); 1722 req->msg.cmd.device_change_state.state);
1705 parahotplug_request_destroy(req); 1723 parahotplug_request_destroy(req);
1706 return 0; 1724 return 0;
1707 } 1725 }
@@ -1715,7 +1733,7 @@ parahotplug_request_complete(int id, u16 active)
1715 * Enables or disables a PCI device by kicking off a udev script 1733 * Enables or disables a PCI device by kicking off a udev script
1716 */ 1734 */
1717static void 1735static void
1718parahotplug_process_message(CONTROLVM_MESSAGE *inmsg) 1736parahotplug_process_message(struct controlvm_message *inmsg)
1719{ 1737{
1720 struct parahotplug_request *req; 1738 struct parahotplug_request *req;
1721 1739
@@ -1726,7 +1744,7 @@ parahotplug_process_message(CONTROLVM_MESSAGE *inmsg)
1726 return; 1744 return;
1727 } 1745 }
1728 1746
1729 if (inmsg->cmd.deviceChangeState.state.Active) { 1747 if (inmsg->cmd.device_change_state.state.active) {
1730 /* For enable messages, just respond with success 1748 /* For enable messages, just respond with success
1731 * right away. This is a bit of a hack, but there are 1749 * right away. This is a bit of a hack, but there are
1732 * issues with the early enable messages we get (with 1750 * issues with the early enable messages we get (with
@@ -1738,9 +1756,8 @@ parahotplug_process_message(CONTROLVM_MESSAGE *inmsg)
1738 */ 1756 */
1739 parahotplug_request_kickoff(req); 1757 parahotplug_request_kickoff(req);
1740 controlvm_respond_physdev_changestate(&inmsg->hdr, 1758 controlvm_respond_physdev_changestate(&inmsg->hdr,
1741 CONTROLVM_RESP_SUCCESS, 1759 CONTROLVM_RESP_SUCCESS, inmsg->cmd.
1742 inmsg->cmd. 1760 device_change_state.state);
1743 deviceChangeState.state);
1744 parahotplug_request_destroy(req); 1761 parahotplug_request_destroy(req);
1745 } else { 1762 } else {
1746 /* For disable messages, add the request to the 1763 /* For disable messages, add the request to the
@@ -1768,23 +1785,23 @@ parahotplug_process_message(CONTROLVM_MESSAGE *inmsg)
1768 * either successfully or with an error. 1785 * either successfully or with an error.
1769 */ 1786 */
1770static BOOL 1787static BOOL
1771handle_command(CONTROLVM_MESSAGE inmsg, HOSTADDRESS channel_addr) 1788handle_command(struct controlvm_message inmsg, HOSTADDRESS channel_addr)
1772{ 1789{
1773 CONTROLVM_MESSAGE_PACKET *cmd = &inmsg.cmd; 1790 struct controlvm_message_packet *cmd = &inmsg.cmd;
1774 u64 parametersAddr = 0; 1791 u64 parametersAddr = 0;
1775 u32 parametersBytes = 0; 1792 u32 parametersBytes = 0;
1776 PARSER_CONTEXT *parser_ctx = NULL; 1793 PARSER_CONTEXT *parser_ctx = NULL;
1777 BOOL isLocalAddr = FALSE; 1794 BOOL isLocalAddr = FALSE;
1778 CONTROLVM_MESSAGE ackmsg; 1795 struct controlvm_message ackmsg;
1779 1796
1780 /* create parsing context if necessary */ 1797 /* create parsing context if necessary */
1781 isLocalAddr = (inmsg.hdr.Flags.testMessage == 1); 1798 isLocalAddr = (inmsg.hdr.flags.test_message == 1);
1782 if (channel_addr == 0) { 1799 if (channel_addr == 0) {
1783 LOGERR("HUH? channel_addr is 0!"); 1800 LOGERR("HUH? channel_addr is 0!");
1784 return TRUE; 1801 return TRUE;
1785 } 1802 }
1786 parametersAddr = channel_addr + inmsg.hdr.PayloadVmOffset; 1803 parametersAddr = channel_addr + inmsg.hdr.payload_vm_offset;
1787 parametersBytes = inmsg.hdr.PayloadBytes; 1804 parametersBytes = inmsg.hdr.payload_bytes;
1788 1805
1789 /* Parameter and channel addresses within test messages actually lie 1806 /* Parameter and channel addresses within test messages actually lie
1790 * within our OS-controlled memory. We need to know that, because it 1807 * within our OS-controlled memory. We need to know that, because it
@@ -1802,7 +1819,7 @@ handle_command(CONTROLVM_MESSAGE inmsg, HOSTADDRESS channel_addr)
1802 return FALSE; 1819 return FALSE;
1803 } 1820 }
1804 LOGWRN("parsing failed"); 1821 LOGWRN("parsing failed");
1805 LOGWRN("inmsg.hdr.Id=0x%lx", (ulong) inmsg.hdr.Id); 1822 LOGWRN("inmsg.hdr.Id=0x%lx", (ulong) inmsg.hdr.id);
1806 LOGWRN("parametersAddr=0x%llx", (u64) parametersAddr); 1823 LOGWRN("parametersAddr=0x%llx", (u64) parametersAddr);
1807 LOGWRN("parametersBytes=%lu", (ulong) parametersBytes); 1824 LOGWRN("parametersBytes=%lu", (ulong) parametersBytes);
1808 LOGWRN("isLocalAddr=%d", isLocalAddr); 1825 LOGWRN("isLocalAddr=%d", isLocalAddr);
@@ -1818,45 +1835,45 @@ handle_command(CONTROLVM_MESSAGE inmsg, HOSTADDRESS channel_addr)
1818 (ControlVm_channel, CONTROLVM_QUEUE_ACK, &ackmsg))) 1835 (ControlVm_channel, CONTROLVM_QUEUE_ACK, &ackmsg)))
1819 LOGWRN("failed to send ACK failed"); 1836 LOGWRN("failed to send ACK failed");
1820 } 1837 }
1821 switch (inmsg.hdr.Id) { 1838 switch (inmsg.hdr.id) {
1822 case CONTROLVM_CHIPSET_INIT: 1839 case CONTROLVM_CHIPSET_INIT:
1823 LOGINF("CHIPSET_INIT(#busses=%lu,#switches=%lu)", 1840 LOGINF("CHIPSET_INIT(#busses=%lu,#switches=%lu)",
1824 (ulong) inmsg.cmd.initChipset.busCount, 1841 (ulong) inmsg.cmd.init_chipset.bus_count,
1825 (ulong) inmsg.cmd.initChipset.switchCount); 1842 (ulong) inmsg.cmd.init_chipset.switch_count);
1826 chipset_init(&inmsg); 1843 chipset_init(&inmsg);
1827 break; 1844 break;
1828 case CONTROLVM_BUS_CREATE: 1845 case CONTROLVM_BUS_CREATE:
1829 LOGINF("BUS_CREATE(%lu,#devs=%lu)", 1846 LOGINF("BUS_CREATE(%lu,#devs=%lu)",
1830 (ulong) cmd->createBus.busNo, 1847 (ulong) cmd->create_bus.bus_no,
1831 (ulong) cmd->createBus.deviceCount); 1848 (ulong) cmd->create_bus.dev_count);
1832 bus_create(&inmsg); 1849 bus_create(&inmsg);
1833 break; 1850 break;
1834 case CONTROLVM_BUS_DESTROY: 1851 case CONTROLVM_BUS_DESTROY:
1835 LOGINF("BUS_DESTROY(%lu)", (ulong) cmd->destroyBus.busNo); 1852 LOGINF("BUS_DESTROY(%lu)", (ulong) cmd->destroy_bus.bus_no);
1836 bus_destroy(&inmsg); 1853 bus_destroy(&inmsg);
1837 break; 1854 break;
1838 case CONTROLVM_BUS_CONFIGURE: 1855 case CONTROLVM_BUS_CONFIGURE:
1839 LOGINF("BUS_CONFIGURE(%lu)", (ulong) cmd->configureBus.busNo); 1856 LOGINF("BUS_CONFIGURE(%lu)", (ulong) cmd->configure_bus.bus_no);
1840 bus_configure(&inmsg, parser_ctx); 1857 bus_configure(&inmsg, parser_ctx);
1841 break; 1858 break;
1842 case CONTROLVM_DEVICE_CREATE: 1859 case CONTROLVM_DEVICE_CREATE:
1843 LOGINF("DEVICE_CREATE(%lu,%lu)", 1860 LOGINF("DEVICE_CREATE(%lu,%lu)",
1844 (ulong) cmd->createDevice.busNo, 1861 (ulong) cmd->create_device.bus_no,
1845 (ulong) cmd->createDevice.devNo); 1862 (ulong) cmd->create_device.dev_no);
1846 my_device_create(&inmsg); 1863 my_device_create(&inmsg);
1847 break; 1864 break;
1848 case CONTROLVM_DEVICE_CHANGESTATE: 1865 case CONTROLVM_DEVICE_CHANGESTATE:
1849 if (cmd->deviceChangeState.flags.physicalDevice) { 1866 if (cmd->device_change_state.flags.phys_device) {
1850 LOGINF("DEVICE_CHANGESTATE for physical device (%lu,%lu, active=%lu)", 1867 LOGINF("DEVICE_CHANGESTATE for physical device (%lu,%lu, active=%lu)",
1851 (ulong) cmd->deviceChangeState.busNo, 1868 (ulong) cmd->device_change_state.bus_no,
1852 (ulong) cmd->deviceChangeState.devNo, 1869 (ulong) cmd->device_change_state.dev_no,
1853 (ulong) cmd->deviceChangeState.state.Active); 1870 (ulong) cmd->device_change_state.state.active);
1854 parahotplug_process_message(&inmsg); 1871 parahotplug_process_message(&inmsg);
1855 } else { 1872 } else {
1856 LOGINF("DEVICE_CHANGESTATE for virtual device (%lu,%lu, state.Alive=0x%lx)", 1873 LOGINF("DEVICE_CHANGESTATE for virtual device (%lu,%lu, state.Alive=0x%lx)",
1857 (ulong) cmd->deviceChangeState.busNo, 1874 (ulong) cmd->device_change_state.bus_no,
1858 (ulong) cmd->deviceChangeState.devNo, 1875 (ulong) cmd->device_change_state.dev_no,
1859 (ulong) cmd->deviceChangeState.state.Alive); 1876 (ulong) cmd->device_change_state.state.alive);
1860 /* save the hdr and cmd structures for later use */ 1877 /* save the hdr and cmd structures for later use */
1861 /* when sending back the response to Command */ 1878 /* when sending back the response to Command */
1862 my_device_changestate(&inmsg); 1879 my_device_changestate(&inmsg);
@@ -1867,16 +1884,16 @@ handle_command(CONTROLVM_MESSAGE inmsg, HOSTADDRESS channel_addr)
1867 break; 1884 break;
1868 case CONTROLVM_DEVICE_DESTROY: 1885 case CONTROLVM_DEVICE_DESTROY:
1869 LOGINF("DEVICE_DESTROY(%lu,%lu)", 1886 LOGINF("DEVICE_DESTROY(%lu,%lu)",
1870 (ulong) cmd->destroyDevice.busNo, 1887 (ulong) cmd->destroy_device.bus_no,
1871 (ulong) cmd->destroyDevice.devNo); 1888 (ulong) cmd->destroy_device.dev_no);
1872 my_device_destroy(&inmsg); 1889 my_device_destroy(&inmsg);
1873 break; 1890 break;
1874 case CONTROLVM_DEVICE_CONFIGURE: 1891 case CONTROLVM_DEVICE_CONFIGURE:
1875 LOGINF("DEVICE_CONFIGURE(%lu,%lu)", 1892 LOGINF("DEVICE_CONFIGURE(%lu,%lu)",
1876 (ulong) cmd->configureDevice.busNo, 1893 (ulong) cmd->configure_device.bus_no,
1877 (ulong) cmd->configureDevice.devNo); 1894 (ulong) cmd->configure_device.dev_no);
1878 /* no op for now, just send a respond that we passed */ 1895 /* no op for now, just send a respond that we passed */
1879 if (inmsg.hdr.Flags.responseExpected) 1896 if (inmsg.hdr.flags.response_expected)
1880 controlvm_respond(&inmsg.hdr, CONTROLVM_RESP_SUCCESS); 1897 controlvm_respond(&inmsg.hdr, CONTROLVM_RESP_SUCCESS);
1881 break; 1898 break;
1882 case CONTROLVM_CHIPSET_READY: 1899 case CONTROLVM_CHIPSET_READY:
@@ -1892,8 +1909,8 @@ handle_command(CONTROLVM_MESSAGE inmsg, HOSTADDRESS channel_addr)
1892 chipset_notready(&inmsg.hdr); 1909 chipset_notready(&inmsg.hdr);
1893 break; 1910 break;
1894 default: 1911 default:
1895 LOGERR("unrecognized controlvm cmd=%d", (int) inmsg.hdr.Id); 1912 LOGERR("unrecognized controlvm cmd=%d", (int) inmsg.hdr.id);
1896 if (inmsg.hdr.Flags.responseExpected) 1913 if (inmsg.hdr.flags.response_expected)
1897 controlvm_respond(&inmsg.hdr, 1914 controlvm_respond(&inmsg.hdr,
1898 -CONTROLVM_RESP_ERROR_MESSAGE_ID_UNKNOWN); 1915 -CONTROLVM_RESP_ERROR_MESSAGE_ID_UNKNOWN);
1899 break; 1916 break;
@@ -1923,8 +1940,7 @@ static HOSTADDRESS controlvm_get_channel_address(void)
1923static void 1940static void
1924controlvm_periodic_work(struct work_struct *work) 1941controlvm_periodic_work(struct work_struct *work)
1925{ 1942{
1926 VISORCHIPSET_CHANNEL_INFO chanInfo; 1943 struct controlvm_message inmsg;
1927 CONTROLVM_MESSAGE inmsg;
1928 BOOL gotACommand = FALSE; 1944 BOOL gotACommand = FALSE;
1929 BOOL handle_command_failed = FALSE; 1945 BOOL handle_command_failed = FALSE;
1930 static u64 Poll_Count; 1946 static u64 Poll_Count;
@@ -1938,8 +1954,6 @@ controlvm_periodic_work(struct work_struct *work)
1938 if (visorchipset_clientregwait && !clientregistered) 1954 if (visorchipset_clientregwait && !clientregistered)
1939 goto Away; 1955 goto Away;
1940 1956
1941 memset(&chanInfo, 0, sizeof(VISORCHIPSET_CHANNEL_INFO));
1942
1943 Poll_Count++; 1957 Poll_Count++;
1944 if (Poll_Count >= 250) 1958 if (Poll_Count >= 250)
1945 ; /* keep going */ 1959 ; /* keep going */
@@ -1950,24 +1964,24 @@ controlvm_periodic_work(struct work_struct *work)
1950 * should be sent 1964 * should be sent
1951 */ 1965 */
1952 if (visorchipset_holdchipsetready 1966 if (visorchipset_holdchipsetready
1953 && (g_ChipSetMsgHdr.Id != CONTROLVM_INVALID)) { 1967 && (g_ChipSetMsgHdr.id != CONTROLVM_INVALID)) {
1954 if (check_chipset_events() == 1) { 1968 if (check_chipset_events() == 1) {
1955 LOGINF("Sending CHIPSET_READY response"); 1969 LOGINF("Sending CHIPSET_READY response");
1956 controlvm_respond(&g_ChipSetMsgHdr, 0); 1970 controlvm_respond(&g_ChipSetMsgHdr, 0);
1957 clear_chipset_events(); 1971 clear_chipset_events();
1958 memset(&g_ChipSetMsgHdr, 0, 1972 memset(&g_ChipSetMsgHdr, 0,
1959 sizeof(CONTROLVM_MESSAGE_HEADER)); 1973 sizeof(struct controlvm_message_header));
1960 } 1974 }
1961 } 1975 }
1962 1976
1963 while (visorchannel_signalremove(ControlVm_channel, 1977 while (visorchannel_signalremove(ControlVm_channel,
1964 CONTROLVM_QUEUE_RESPONSE, 1978 CONTROLVM_QUEUE_RESPONSE,
1965 &inmsg)) { 1979 &inmsg)) {
1966 if (inmsg.hdr.PayloadMaxBytes != 0) { 1980 if (inmsg.hdr.payload_max_bytes != 0) {
1967 LOGERR("Payload of size %lu returned @%lu with unexpected message id %d.", 1981 LOGERR("Payload of size %lu returned @%lu with unexpected message id %d.",
1968 (ulong) inmsg.hdr.PayloadMaxBytes, 1982 (ulong) inmsg.hdr.payload_max_bytes,
1969 (ulong) inmsg.hdr.PayloadVmOffset, 1983 (ulong) inmsg.hdr.payload_vm_offset,
1970 inmsg.hdr.Id); 1984 inmsg.hdr.id);
1971 } 1985 }
1972 } 1986 }
1973 if (!gotACommand) { 1987 if (!gotACommand) {
@@ -2033,9 +2047,9 @@ static void
2033setup_crash_devices_work_queue(struct work_struct *work) 2047setup_crash_devices_work_queue(struct work_struct *work)
2034{ 2048{
2035 2049
2036 CONTROLVM_MESSAGE localCrashCreateBusMsg; 2050 struct controlvm_message localCrashCreateBusMsg;
2037 CONTROLVM_MESSAGE localCrashCreateDevMsg; 2051 struct controlvm_message localCrashCreateDevMsg;
2038 CONTROLVM_MESSAGE msg; 2052 struct controlvm_message msg;
2039 u32 localSavedCrashMsgOffset; 2053 u32 localSavedCrashMsgOffset;
2040 u16 localSavedCrashMsgCount; 2054 u16 localSavedCrashMsgCount;
2041 2055
@@ -2052,16 +2066,16 @@ setup_crash_devices_work_queue(struct work_struct *work)
2052 POSTCODE_LINUX_2(CRASH_DEV_ENTRY_PC, POSTCODE_SEVERITY_INFO); 2066 POSTCODE_LINUX_2(CRASH_DEV_ENTRY_PC, POSTCODE_SEVERITY_INFO);
2053 2067
2054 /* send init chipset msg */ 2068 /* send init chipset msg */
2055 msg.hdr.Id = CONTROLVM_CHIPSET_INIT; 2069 msg.hdr.id = CONTROLVM_CHIPSET_INIT;
2056 msg.cmd.initChipset.busCount = 23; 2070 msg.cmd.init_chipset.bus_count = 23;
2057 msg.cmd.initChipset.switchCount = 0; 2071 msg.cmd.init_chipset.switch_count = 0;
2058 2072
2059 chipset_init(&msg); 2073 chipset_init(&msg);
2060 2074
2061 /* get saved message count */ 2075 /* get saved message count */
2062 if (visorchannel_read(ControlVm_channel, 2076 if (visorchannel_read(ControlVm_channel,
2063 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL, 2077 offsetof(struct spar_controlvm_channel_protocol,
2064 SavedCrashMsgCount), 2078 saved_crash_message_count),
2065 &localSavedCrashMsgCount, sizeof(u16)) < 0) { 2079 &localSavedCrashMsgCount, sizeof(u16)) < 0) {
2066 LOGERR("failed to get Saved Message Count"); 2080 LOGERR("failed to get Saved Message Count");
2067 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC, 2081 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC,
@@ -2080,8 +2094,8 @@ setup_crash_devices_work_queue(struct work_struct *work)
2080 2094
2081 /* get saved crash message offset */ 2095 /* get saved crash message offset */
2082 if (visorchannel_read(ControlVm_channel, 2096 if (visorchannel_read(ControlVm_channel,
2083 offsetof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL, 2097 offsetof(struct spar_controlvm_channel_protocol,
2084 SavedCrashMsgOffset), 2098 saved_crash_message_offset),
2085 &localSavedCrashMsgOffset, sizeof(u32)) < 0) { 2099 &localSavedCrashMsgOffset, sizeof(u32)) < 0) {
2086 LOGERR("failed to get Saved Message Offset"); 2100 LOGERR("failed to get Saved Message Offset");
2087 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC, 2101 POSTCODE_LINUX_2(CRASH_DEV_CTRL_RD_FAILURE_PC,
@@ -2093,7 +2107,7 @@ setup_crash_devices_work_queue(struct work_struct *work)
2093 if (visorchannel_read(ControlVm_channel, 2107 if (visorchannel_read(ControlVm_channel,
2094 localSavedCrashMsgOffset, 2108 localSavedCrashMsgOffset,
2095 &localCrashCreateBusMsg, 2109 &localCrashCreateBusMsg,
2096 sizeof(CONTROLVM_MESSAGE)) < 0) { 2110 sizeof(struct controlvm_message)) < 0) {
2097 LOGERR("CRASH_DEV_RD_BUS_FAIULRE: Failed to read CrashCreateBusMsg!"); 2111 LOGERR("CRASH_DEV_RD_BUS_FAIULRE: Failed to read CrashCreateBusMsg!");
2098 POSTCODE_LINUX_2(CRASH_DEV_RD_BUS_FAIULRE_PC, 2112 POSTCODE_LINUX_2(CRASH_DEV_RD_BUS_FAIULRE_PC,
2099 POSTCODE_SEVERITY_ERR); 2113 POSTCODE_SEVERITY_ERR);
@@ -2103,9 +2117,9 @@ setup_crash_devices_work_queue(struct work_struct *work)
2103 /* read create device message for storage device */ 2117 /* read create device message for storage device */
2104 if (visorchannel_read(ControlVm_channel, 2118 if (visorchannel_read(ControlVm_channel,
2105 localSavedCrashMsgOffset + 2119 localSavedCrashMsgOffset +
2106 sizeof(CONTROLVM_MESSAGE), 2120 sizeof(struct controlvm_message),
2107 &localCrashCreateDevMsg, 2121 &localCrashCreateDevMsg,
2108 sizeof(CONTROLVM_MESSAGE)) < 0) { 2122 sizeof(struct controlvm_message)) < 0) {
2109 LOGERR("CRASH_DEV_RD_DEV_FAIULRE: Failed to read CrashCreateDevMsg!"); 2123 LOGERR("CRASH_DEV_RD_DEV_FAIULRE: Failed to read CrashCreateDevMsg!");
2110 POSTCODE_LINUX_2(CRASH_DEV_RD_DEV_FAIULRE_PC, 2124 POSTCODE_LINUX_2(CRASH_DEV_RD_DEV_FAIULRE_PC,
2111 POSTCODE_SEVERITY_ERR); 2125 POSTCODE_SEVERITY_ERR);
@@ -2113,7 +2127,7 @@ setup_crash_devices_work_queue(struct work_struct *work)
2113 } 2127 }
2114 2128
2115 /* reuse IOVM create bus message */ 2129 /* reuse IOVM create bus message */
2116 if (localCrashCreateBusMsg.cmd.createBus.channelAddr != 0) 2130 if (localCrashCreateBusMsg.cmd.create_bus.channel_addr != 0)
2117 bus_create(&localCrashCreateBusMsg); 2131 bus_create(&localCrashCreateBusMsg);
2118 else { 2132 else {
2119 LOGERR("CrashCreateBusMsg is null, no dump will be taken"); 2133 LOGERR("CrashCreateBusMsg is null, no dump will be taken");
@@ -2123,7 +2137,7 @@ setup_crash_devices_work_queue(struct work_struct *work)
2123 } 2137 }
2124 2138
2125 /* reuse create device message for storage device */ 2139 /* reuse create device message for storage device */
2126 if (localCrashCreateDevMsg.cmd.createDevice.channelAddr != 0) 2140 if (localCrashCreateDevMsg.cmd.create_device.channel_addr != 0)
2127 my_device_create(&localCrashCreateDevMsg); 2141 my_device_create(&localCrashCreateDevMsg);
2128 else { 2142 else {
2129 LOGERR("CrashCreateDevMsg is null, no dump will be taken"); 2143 LOGERR("CrashCreateDevMsg is null, no dump will be taken");
@@ -2168,12 +2182,12 @@ device_destroy_response(ulong busNo, ulong devNo, int response)
2168} 2182}
2169 2183
2170void 2184void
2171visorchipset_device_pause_response(ulong busNo, ulong devNo, int response) 2185visorchipset_device_pause_response(ulong bus_no, ulong dev_no, int response)
2172{ 2186{
2173 2187
2174 device_changestate_responder(CONTROLVM_DEVICE_CHANGESTATE, 2188 device_changestate_responder(CONTROLVM_DEVICE_CHANGESTATE,
2175 busNo, devNo, response, 2189 bus_no, dev_no, response,
2176 SegmentStateStandby); 2190 segment_state_standby);
2177} 2191}
2178EXPORT_SYMBOL_GPL(visorchipset_device_pause_response); 2192EXPORT_SYMBOL_GPL(visorchipset_device_pause_response);
2179 2193
@@ -2182,30 +2196,30 @@ device_resume_response(ulong busNo, ulong devNo, int response)
2182{ 2196{
2183 device_changestate_responder(CONTROLVM_DEVICE_CHANGESTATE, 2197 device_changestate_responder(CONTROLVM_DEVICE_CHANGESTATE,
2184 busNo, devNo, response, 2198 busNo, devNo, response,
2185 SegmentStateRunning); 2199 segment_state_running);
2186} 2200}
2187 2201
2188BOOL 2202BOOL
2189visorchipset_get_bus_info(ulong busNo, VISORCHIPSET_BUS_INFO *busInfo) 2203visorchipset_get_bus_info(ulong bus_no, struct visorchipset_bus_info *bus_info)
2190{ 2204{
2191 void *p = findbus(&BusInfoList, busNo); 2205 void *p = findbus(&BusInfoList, bus_no);
2192 2206
2193 if (!p) { 2207 if (!p) {
2194 LOGERR("(%lu) failed", busNo); 2208 LOGERR("(%lu) failed", bus_no);
2195 return FALSE; 2209 return FALSE;
2196 } 2210 }
2197 memcpy(busInfo, p, sizeof(VISORCHIPSET_BUS_INFO)); 2211 memcpy(bus_info, p, sizeof(struct visorchipset_bus_info));
2198 return TRUE; 2212 return TRUE;
2199} 2213}
2200EXPORT_SYMBOL_GPL(visorchipset_get_bus_info); 2214EXPORT_SYMBOL_GPL(visorchipset_get_bus_info);
2201 2215
2202BOOL 2216BOOL
2203visorchipset_set_bus_context(ulong busNo, void *context) 2217visorchipset_set_bus_context(ulong bus_no, void *context)
2204{ 2218{
2205 VISORCHIPSET_BUS_INFO *p = findbus(&BusInfoList, busNo); 2219 struct visorchipset_bus_info *p = findbus(&BusInfoList, bus_no);
2206 2220
2207 if (!p) { 2221 if (!p) {
2208 LOGERR("(%lu) failed", busNo); 2222 LOGERR("(%lu) failed", bus_no);
2209 return FALSE; 2223 return FALSE;
2210 } 2224 }
2211 p->bus_driver_context = context; 2225 p->bus_driver_context = context;
@@ -2214,27 +2228,28 @@ visorchipset_set_bus_context(ulong busNo, void *context)
2214EXPORT_SYMBOL_GPL(visorchipset_set_bus_context); 2228EXPORT_SYMBOL_GPL(visorchipset_set_bus_context);
2215 2229
2216BOOL 2230BOOL
2217visorchipset_get_device_info(ulong busNo, ulong devNo, 2231visorchipset_get_device_info(ulong bus_no, ulong dev_no,
2218 VISORCHIPSET_DEVICE_INFO *devInfo) 2232 struct visorchipset_device_info *dev_info)
2219{ 2233{
2220 void *p = finddevice(&DevInfoList, busNo, devNo); 2234 void *p = finddevice(&DevInfoList, bus_no, dev_no);
2221 2235
2222 if (!p) { 2236 if (!p) {
2223 LOGERR("(%lu,%lu) failed", busNo, devNo); 2237 LOGERR("(%lu,%lu) failed", bus_no, dev_no);
2224 return FALSE; 2238 return FALSE;
2225 } 2239 }
2226 memcpy(devInfo, p, sizeof(VISORCHIPSET_DEVICE_INFO)); 2240 memcpy(dev_info, p, sizeof(struct visorchipset_device_info));
2227 return TRUE; 2241 return TRUE;
2228} 2242}
2229EXPORT_SYMBOL_GPL(visorchipset_get_device_info); 2243EXPORT_SYMBOL_GPL(visorchipset_get_device_info);
2230 2244
2231BOOL 2245BOOL
2232visorchipset_set_device_context(ulong busNo, ulong devNo, void *context) 2246visorchipset_set_device_context(ulong bus_no, ulong dev_no, void *context)
2233{ 2247{
2234 VISORCHIPSET_DEVICE_INFO *p = finddevice(&DevInfoList, busNo, devNo); 2248 struct visorchipset_device_info *p =
2249 finddevice(&DevInfoList, bus_no, dev_no);
2235 2250
2236 if (!p) { 2251 if (!p) {
2237 LOGERR("(%lu,%lu) failed", busNo, devNo); 2252 LOGERR("(%lu,%lu) failed", bus_no, dev_no);
2238 return FALSE; 2253 return FALSE;
2239 } 2254 }
2240 p->bus_driver_context = context; 2255 p->bus_driver_context = context;
@@ -2377,11 +2392,10 @@ visorchipset_init(void)
2377 ControlVm_channel = 2392 ControlVm_channel =
2378 visorchannel_create_with_lock 2393 visorchannel_create_with_lock
2379 (addr, 2394 (addr,
2380 sizeof(ULTRA_CONTROLVM_CHANNEL_PROTOCOL), 2395 sizeof(struct spar_controlvm_channel_protocol),
2381 UltraControlvmChannelProtocolGuid); 2396 spar_controlvm_channel_protocol_uuid);
2382 if (ULTRA_CONTROLVM_CHANNEL_OK_CLIENT 2397 if (SPAR_CONTROLVM_CHANNEL_OK_CLIENT(
2383 (visorchannel_get_header(ControlVm_channel), 2398 visorchannel_get_header(ControlVm_channel))) {
2384 NULL)) {
2385 LOGINF("Channel %s (ControlVm) discovered", 2399 LOGINF("Channel %s (ControlVm) discovered",
2386 visorchannel_id(ControlVm_channel, s)); 2400 visorchannel_id(ControlVm_channel, s));
2387 initialize_controlvm_payload(); 2401 initialize_controlvm_payload();
@@ -2404,11 +2418,11 @@ visorchipset_init(void)
2404 goto Away; 2418 goto Away;
2405 } 2419 }
2406 2420
2407 memset(&g_DiagMsgHdr, 0, sizeof(CONTROLVM_MESSAGE_HEADER)); 2421 memset(&g_DiagMsgHdr, 0, sizeof(struct controlvm_message_header));
2408 2422
2409 memset(&g_ChipSetMsgHdr, 0, sizeof(CONTROLVM_MESSAGE_HEADER)); 2423 memset(&g_ChipSetMsgHdr, 0, sizeof(struct controlvm_message_header));
2410 2424
2411 memset(&g_DelDumpMsgHdr, 0, sizeof(CONTROLVM_MESSAGE_HEADER)); 2425 memset(&g_DelDumpMsgHdr, 0, sizeof(struct controlvm_message_header));
2412 2426
2413 Putfile_buffer_list_pool = 2427 Putfile_buffer_list_pool =
2414 kmem_cache_create(Putfile_buffer_list_pool_name, 2428 kmem_cache_create(Putfile_buffer_list_pool_name,
@@ -2497,11 +2511,11 @@ visorchipset_exit(void)
2497 2511
2498 cleanup_controlvm_structures(); 2512 cleanup_controlvm_structures();
2499 2513
2500 memset(&g_DiagMsgHdr, 0, sizeof(CONTROLVM_MESSAGE_HEADER)); 2514 memset(&g_DiagMsgHdr, 0, sizeof(struct controlvm_message_header));
2501 2515
2502 memset(&g_ChipSetMsgHdr, 0, sizeof(CONTROLVM_MESSAGE_HEADER)); 2516 memset(&g_ChipSetMsgHdr, 0, sizeof(struct controlvm_message_header));
2503 2517
2504 memset(&g_DelDumpMsgHdr, 0, sizeof(CONTROLVM_MESSAGE_HEADER)); 2518 memset(&g_DelDumpMsgHdr, 0, sizeof(struct controlvm_message_header));
2505 2519
2506 LOGINF("Channel %s (ControlVm) disconnected", 2520 LOGINF("Channel %s (ControlVm) disconnected",
2507 visorchannel_id(ControlVm_channel, s)); 2521 visorchannel_id(ControlVm_channel, s));
diff --git a/drivers/staging/unisys/visorutil/charqueue.c b/drivers/staging/unisys/visorutil/charqueue.c
index 22241c7b4f7f..1ce7003c3a90 100644
--- a/drivers/staging/unisys/visorutil/charqueue.c
+++ b/drivers/staging/unisys/visorutil/charqueue.c
@@ -25,9 +25,7 @@
25 25
26#define IS_EMPTY(charqueue) (charqueue->head == charqueue->tail) 26#define IS_EMPTY(charqueue) (charqueue->head == charqueue->tail)
27 27
28 28struct charqueue {
29
30struct CHARQUEUE_Tag {
31 int alloc_size; 29 int alloc_size;
32 int nslots; 30 int nslots;
33 spinlock_t lock; 31 spinlock_t lock;
@@ -35,12 +33,10 @@ struct CHARQUEUE_Tag {
35 unsigned char buf[0]; 33 unsigned char buf[0];
36}; 34};
37 35
38 36struct charqueue *visor_charqueue_create(ulong nslots)
39
40CHARQUEUE *visor_charqueue_create(ulong nslots)
41{ 37{
42 int alloc_size = sizeof(CHARQUEUE) + nslots + 1; 38 int alloc_size = sizeof(struct charqueue) + nslots + 1;
43 CHARQUEUE *cq = kmalloc(alloc_size, GFP_KERNEL|__GFP_NORETRY); 39 struct charqueue *cq = kmalloc(alloc_size, GFP_KERNEL|__GFP_NORETRY);
44 40
45 if (cq == NULL) { 41 if (cq == NULL) {
46 ERRDRV("visor_charqueue_create allocation failed (alloc_size=%d)", 42 ERRDRV("visor_charqueue_create allocation failed (alloc_size=%d)",
@@ -49,15 +45,14 @@ CHARQUEUE *visor_charqueue_create(ulong nslots)
49 } 45 }
50 cq->alloc_size = alloc_size; 46 cq->alloc_size = alloc_size;
51 cq->nslots = nslots; 47 cq->nslots = nslots;
52 cq->head = cq->tail = 0; 48 cq->head = 0;
49 cq->tail = 0;
53 spin_lock_init(&cq->lock); 50 spin_lock_init(&cq->lock);
54 return cq; 51 return cq;
55} 52}
56EXPORT_SYMBOL_GPL(visor_charqueue_create); 53EXPORT_SYMBOL_GPL(visor_charqueue_create);
57 54
58 55void visor_charqueue_enqueue(struct charqueue *charqueue, unsigned char c)
59
60void visor_charqueue_enqueue(CHARQUEUE *charqueue, unsigned char c)
61{ 56{
62 int alloc_slots = charqueue->nslots+1; /* 1 slot is always empty */ 57 int alloc_slots = charqueue->nslots+1; /* 1 slot is always empty */
63 58
@@ -71,9 +66,7 @@ void visor_charqueue_enqueue(CHARQUEUE *charqueue, unsigned char c)
71} 66}
72EXPORT_SYMBOL_GPL(visor_charqueue_enqueue); 67EXPORT_SYMBOL_GPL(visor_charqueue_enqueue);
73 68
74 69BOOL visor_charqueue_is_empty(struct charqueue *charqueue)
75
76BOOL visor_charqueue_is_empty(CHARQUEUE *charqueue)
77{ 70{
78 BOOL b; 71 BOOL b;
79 72
@@ -84,9 +77,7 @@ BOOL visor_charqueue_is_empty(CHARQUEUE *charqueue)
84} 77}
85EXPORT_SYMBOL_GPL(visor_charqueue_is_empty); 78EXPORT_SYMBOL_GPL(visor_charqueue_is_empty);
86 79
87 80static int charqueue_dequeue_1(struct charqueue *charqueue)
88
89static int charqueue_dequeue_1(CHARQUEUE *charqueue)
90{ 81{
91 int alloc_slots = charqueue->nslots + 1; /* 1 slot is always empty */ 82 int alloc_slots = charqueue->nslots + 1; /* 1 slot is always empty */
92 83
@@ -96,9 +87,7 @@ static int charqueue_dequeue_1(CHARQUEUE *charqueue)
96 return charqueue->buf[charqueue->tail]; 87 return charqueue->buf[charqueue->tail];
97} 88}
98 89
99 90int charqueue_dequeue(struct charqueue *charqueue)
100
101int charqueue_dequeue(CHARQUEUE *charqueue)
102{ 91{
103 int rc; 92 int rc;
104 93
@@ -108,9 +97,8 @@ int charqueue_dequeue(CHARQUEUE *charqueue)
108 return rc; 97 return rc;
109} 98}
110 99
111 100int visor_charqueue_dequeue_n(struct charqueue *charqueue, unsigned char *buf,
112 101 int n)
113int visor_charqueue_dequeue_n(CHARQUEUE *charqueue, unsigned char *buf, int n)
114{ 102{
115 int rc, counter = 0, c; 103 int rc, counter = 0, c;
116 104
@@ -132,9 +120,7 @@ int visor_charqueue_dequeue_n(CHARQUEUE *charqueue, unsigned char *buf, int n)
132} 120}
133EXPORT_SYMBOL_GPL(visor_charqueue_dequeue_n); 121EXPORT_SYMBOL_GPL(visor_charqueue_dequeue_n);
134 122
135 123void visor_charqueue_destroy(struct charqueue *charqueue)
136
137void visor_charqueue_destroy(CHARQUEUE *charqueue)
138{ 124{
139 if (charqueue == NULL) 125 if (charqueue == NULL)
140 return; 126 return;
diff --git a/drivers/staging/unisys/visorutil/charqueue.h b/drivers/staging/unisys/visorutil/charqueue.h
index d6f16587a364..56c1f79a54b0 100644
--- a/drivers/staging/unisys/visorutil/charqueue.h
+++ b/drivers/staging/unisys/visorutil/charqueue.h
@@ -21,17 +21,18 @@
21#include "uniklog.h" 21#include "uniklog.h"
22#include "timskmod.h" 22#include "timskmod.h"
23 23
24/* CHARQUEUE is an opaque structure to users. 24/* struct charqueue is an opaque structure to users.
25 * Fields are declared only in the implementation .c files. 25 * Fields are declared only in the implementation .c files.
26 */ 26 */
27typedef struct CHARQUEUE_Tag CHARQUEUE; 27struct charqueue;
28 28
29CHARQUEUE *visor_charqueue_create(ulong nslots); 29struct charqueue *visor_charqueue_create(ulong nslots);
30void visor_charqueue_enqueue(CHARQUEUE *charqueue, unsigned char c); 30void visor_charqueue_enqueue(struct charqueue *charqueue, unsigned char c);
31int charqueue_dequeue(CHARQUEUE *charqueue); 31int charqueue_dequeue(struct charqueue *charqueue);
32int visor_charqueue_dequeue_n(CHARQUEUE *charqueue, unsigned char *buf, int n); 32int visor_charqueue_dequeue_n(struct charqueue *charqueue, unsigned char *buf,
33BOOL visor_charqueue_is_empty(CHARQUEUE *charqueue); 33 int n);
34void visor_charqueue_destroy(CHARQUEUE *charqueue); 34BOOL visor_charqueue_is_empty(struct charqueue *charqueue);
35void visor_charqueue_destroy(struct charqueue *charqueue);
35 36
36#endif 37#endif
37 38
diff --git a/drivers/staging/unisys/visorutil/easyproc.c b/drivers/staging/unisys/visorutil/easyproc.c
index 3b388494e2af..40f1ae9a155c 100644
--- a/drivers/staging/unisys/visorutil/easyproc.c
+++ b/drivers/staging/unisys/visorutil/easyproc.c
@@ -254,9 +254,9 @@ void visor_easyproc_CreateDeviceProperty(struct easyproc_device_info *p,
254 } 254 }
255 strcpy(px->property_name, property_name); 255 strcpy(px->property_name, property_name);
256 if (px->procEntry == NULL) { 256 if (px->procEntry == NULL) {
257 ERRDEVX(p->devno, "failed to register /proc/%s/device/%d/%s entry", 257 ERRDEVX(p->devno,
258 p->pdriver->ProcId, p->devno, property_name 258 "failed to register /proc/%s/device/%d/%s entry",
259 ); 259 p->pdriver->ProcId, p->devno, property_name);
260 return; 260 return;
261 } 261 }
262 px->show_device_property_info = show_property_info; 262 px->show_device_property_info = show_property_info;
diff --git a/drivers/staging/unisys/visorutil/memregion.h b/drivers/staging/unisys/visorutil/memregion.h
index f4a65d2fcf02..0c3eebcf6d50 100644
--- a/drivers/staging/unisys/visorutil/memregion.h
+++ b/drivers/staging/unisys/visorutil/memregion.h
@@ -20,24 +20,24 @@
20 20
21#include "timskmod.h" 21#include "timskmod.h"
22 22
23/* MEMREGION is an opaque structure to users. 23/* struct memregion is an opaque structure to users.
24 * Fields are declared only in the implementation .c files. 24 * Fields are declared only in the implementation .c files.
25 */ 25 */
26typedef struct MEMREGION_Tag MEMREGION; 26struct memregion;
27 27
28MEMREGION *visor_memregion_create(HOSTADDRESS physaddr, ulong nbytes); 28struct memregion *visor_memregion_create(HOSTADDRESS physaddr, ulong nbytes);
29MEMREGION *visor_memregion_create_overlapped(MEMREGION *parent, 29struct memregion *visor_memregion_create_overlapped(struct memregion *parent,
30 ulong offset, ulong nbytes); 30 ulong offset, ulong nbytes);
31int visor_memregion_resize(MEMREGION *memregion, ulong newsize); 31int visor_memregion_resize(struct memregion *memregion, ulong newsize);
32int visor_memregion_read(MEMREGION *memregion, 32int visor_memregion_read(struct memregion *memregion,
33 ulong offset, void *dest, ulong nbytes); 33 ulong offset, void *dest, ulong nbytes);
34int visor_memregion_write(MEMREGION *memregion, 34int visor_memregion_write(struct memregion *memregion,
35 ulong offset, void *src, ulong nbytes); 35 ulong offset, void *src, ulong nbytes);
36void visor_memregion_destroy(MEMREGION *memregion); 36void visor_memregion_destroy(struct memregion *memregion);
37HOSTADDRESS visor_memregion_get_physaddr(MEMREGION *memregion); 37HOSTADDRESS visor_memregion_get_physaddr(struct memregion *memregion);
38ulong visor_memregion_get_nbytes(MEMREGION *memregion); 38ulong visor_memregion_get_nbytes(struct memregion *memregion);
39void memregion_dump(MEMREGION *memregion, char *s, 39void memregion_dump(struct memregion *memregion, char *s,
40 ulong off, ulong len, struct seq_file *seq); 40 ulong off, ulong len, struct seq_file *seq);
41void __iomem *visor_memregion_get_pointer(MEMREGION *memregion); 41void __iomem *visor_memregion_get_pointer(struct memregion *memregion);
42 42
43#endif 43#endif
diff --git a/drivers/staging/unisys/visorutil/memregion_direct.c b/drivers/staging/unisys/visorutil/memregion_direct.c
index 65bc07b947db..33522cc8c22c 100644
--- a/drivers/staging/unisys/visorutil/memregion_direct.c
+++ b/drivers/staging/unisys/visorutil/memregion_direct.c
@@ -26,7 +26,7 @@
26 26
27#define MYDRVNAME "memregion" 27#define MYDRVNAME "memregion"
28 28
29struct MEMREGION_Tag { 29struct memregion {
30 HOSTADDRESS physaddr; 30 HOSTADDRESS physaddr;
31 ulong nbytes; 31 ulong nbytes;
32 void __iomem *mapped; 32 void __iomem *mapped;
@@ -34,15 +34,15 @@ struct MEMREGION_Tag {
34 BOOL overlapped; 34 BOOL overlapped;
35}; 35};
36 36
37static BOOL mapit(MEMREGION *memregion); 37static BOOL mapit(struct memregion *memregion);
38static void unmapit(MEMREGION *memregion); 38static void unmapit(struct memregion *memregion);
39 39
40MEMREGION * 40struct memregion *
41visor_memregion_create(HOSTADDRESS physaddr, ulong nbytes) 41visor_memregion_create(HOSTADDRESS physaddr, ulong nbytes)
42{ 42{
43 MEMREGION *rc = NULL; 43 struct memregion *rc = NULL;
44 MEMREGION *memregion = kzalloc(sizeof(MEMREGION), 44 struct memregion *memregion = kzalloc(sizeof(*memregion),
45 GFP_KERNEL | __GFP_NORETRY); 45 GFP_KERNEL | __GFP_NORETRY);
46 if (memregion == NULL) { 46 if (memregion == NULL) {
47 ERRDRV("visor_memregion_create allocation failed"); 47 ERRDRV("visor_memregion_create allocation failed");
48 return NULL; 48 return NULL;
@@ -52,24 +52,23 @@ visor_memregion_create(HOSTADDRESS physaddr, ulong nbytes)
52 memregion->overlapped = FALSE; 52 memregion->overlapped = FALSE;
53 if (!mapit(memregion)) { 53 if (!mapit(memregion)) {
54 rc = NULL; 54 rc = NULL;
55 goto Away; 55 goto cleanup;
56 } 56 }
57 rc = memregion; 57 rc = memregion;
58Away: 58cleanup:
59 if (rc == NULL) { 59 if (rc == NULL) {
60 if (memregion != NULL) { 60 visor_memregion_destroy(memregion);
61 visor_memregion_destroy(memregion); 61 memregion = NULL;
62 memregion = NULL;
63 }
64 } 62 }
65 return rc; 63 return rc;
66} 64}
67EXPORT_SYMBOL_GPL(visor_memregion_create); 65EXPORT_SYMBOL_GPL(visor_memregion_create);
68 66
69MEMREGION * 67struct memregion *
70visor_memregion_create_overlapped(MEMREGION *parent, ulong offset, ulong nbytes) 68visor_memregion_create_overlapped(struct memregion *parent, ulong offset,
69 ulong nbytes)
71{ 70{
72 MEMREGION *memregion = NULL; 71 struct memregion *memregion = NULL;
73 72
74 if (parent == NULL) { 73 if (parent == NULL) {
75 ERRDRV("%s parent is NULL", __func__); 74 ERRDRV("%s parent is NULL", __func__);
@@ -85,7 +84,7 @@ visor_memregion_create_overlapped(MEMREGION *parent, ulong offset, ulong nbytes)
85 __func__, offset, nbytes); 84 __func__, offset, nbytes);
86 return NULL; 85 return NULL;
87 } 86 }
88 memregion = kzalloc(sizeof(MEMREGION), GFP_KERNEL|__GFP_NORETRY); 87 memregion = kzalloc(sizeof(*memregion), GFP_KERNEL|__GFP_NORETRY);
89 if (memregion == NULL) { 88 if (memregion == NULL) {
90 ERRDRV("%s allocation failed", __func__); 89 ERRDRV("%s allocation failed", __func__);
91 return NULL; 90 return NULL;
@@ -93,23 +92,23 @@ visor_memregion_create_overlapped(MEMREGION *parent, ulong offset, ulong nbytes)
93 92
94 memregion->physaddr = parent->physaddr + offset; 93 memregion->physaddr = parent->physaddr + offset;
95 memregion->nbytes = nbytes; 94 memregion->nbytes = nbytes;
96 memregion->mapped = ((u8 __iomem *) (parent->mapped)) + offset; 95 memregion->mapped = ((u8 __iomem *)(parent->mapped)) + offset;
97 memregion->requested = FALSE; 96 memregion->requested = FALSE;
98 memregion->overlapped = TRUE; 97 memregion->overlapped = TRUE;
99 return memregion; 98 return memregion;
100} 99}
101EXPORT_SYMBOL_GPL(visor_memregion_create_overlapped); 100EXPORT_SYMBOL_GPL(visor_memregion_create_overlapped);
102 101
103
104static BOOL 102static BOOL
105mapit(MEMREGION *memregion) 103mapit(struct memregion *memregion)
106{ 104{
107 ulong physaddr = (ulong) (memregion->physaddr); 105 ulong physaddr = (ulong)(memregion->physaddr);
108 ulong nbytes = memregion->nbytes; 106 ulong nbytes = memregion->nbytes;
109 107
110 memregion->requested = FALSE; 108 memregion->requested = FALSE;
111 if (!request_mem_region(physaddr, nbytes, MYDRVNAME)) 109 if (!request_mem_region(physaddr, nbytes, MYDRVNAME))
112 ERRDRV("cannot reserve channel memory @0x%lx for 0x%lx-- no big deal", physaddr, nbytes); 110 ERRDRV("cannot reserve channel memory @0x%lx for 0x%lx-- no big deal",
111 physaddr, nbytes);
113 else 112 else
114 memregion->requested = TRUE; 113 memregion->requested = TRUE;
115 memregion->mapped = ioremap_cache(physaddr, nbytes); 114 memregion->mapped = ioremap_cache(physaddr, nbytes);
@@ -122,42 +121,42 @@ mapit(MEMREGION *memregion)
122} 121}
123 122
124static void 123static void
125unmapit(MEMREGION *memregion) 124unmapit(struct memregion *memregion)
126{ 125{
127 if (memregion->mapped != NULL) { 126 if (memregion->mapped != NULL) {
128 iounmap(memregion->mapped); 127 iounmap(memregion->mapped);
129 memregion->mapped = NULL; 128 memregion->mapped = NULL;
130 } 129 }
131 if (memregion->requested) { 130 if (memregion->requested) {
132 release_mem_region((ulong) (memregion->physaddr), 131 release_mem_region((ulong)(memregion->physaddr),
133 memregion->nbytes); 132 memregion->nbytes);
134 memregion->requested = FALSE; 133 memregion->requested = FALSE;
135 } 134 }
136} 135}
137 136
138HOSTADDRESS 137HOSTADDRESS
139visor_memregion_get_physaddr(MEMREGION *memregion) 138visor_memregion_get_physaddr(struct memregion *memregion)
140{ 139{
141 return memregion->physaddr; 140 return memregion->physaddr;
142} 141}
143EXPORT_SYMBOL_GPL(visor_memregion_get_physaddr); 142EXPORT_SYMBOL_GPL(visor_memregion_get_physaddr);
144 143
145ulong 144ulong
146visor_memregion_get_nbytes(MEMREGION *memregion) 145visor_memregion_get_nbytes(struct memregion *memregion)
147{ 146{
148 return memregion->nbytes; 147 return memregion->nbytes;
149} 148}
150EXPORT_SYMBOL_GPL(visor_memregion_get_nbytes); 149EXPORT_SYMBOL_GPL(visor_memregion_get_nbytes);
151 150
152void __iomem * 151void __iomem *
153visor_memregion_get_pointer(MEMREGION *memregion) 152visor_memregion_get_pointer(struct memregion *memregion)
154{ 153{
155 return memregion->mapped; 154 return memregion->mapped;
156} 155}
157EXPORT_SYMBOL_GPL(visor_memregion_get_pointer); 156EXPORT_SYMBOL_GPL(visor_memregion_get_pointer);
158 157
159int 158int
160visor_memregion_resize(MEMREGION *memregion, ulong newsize) 159visor_memregion_resize(struct memregion *memregion, ulong newsize)
161{ 160{
162 if (newsize == memregion->nbytes) 161 if (newsize == memregion->nbytes)
163 return 0; 162 return 0;
@@ -176,10 +175,9 @@ visor_memregion_resize(MEMREGION *memregion, ulong newsize)
176} 175}
177EXPORT_SYMBOL_GPL(visor_memregion_resize); 176EXPORT_SYMBOL_GPL(visor_memregion_resize);
178 177
179
180static int 178static int
181memregion_readwrite(BOOL is_write, 179memregion_readwrite(BOOL is_write,
182 MEMREGION *memregion, ulong offset, 180 struct memregion *memregion, ulong offset,
183 void *local, ulong nbytes) 181 void *local, ulong nbytes)
184{ 182{
185 if (offset + nbytes > memregion->nbytes) { 183 if (offset + nbytes > memregion->nbytes) {
@@ -195,7 +193,7 @@ memregion_readwrite(BOOL is_write,
195} 193}
196 194
197int 195int
198visor_memregion_read(MEMREGION *memregion, ulong offset, void *dest, 196visor_memregion_read(struct memregion *memregion, ulong offset, void *dest,
199 ulong nbytes) 197 ulong nbytes)
200{ 198{
201 return memregion_readwrite(FALSE, memregion, offset, dest, nbytes); 199 return memregion_readwrite(FALSE, memregion, offset, dest, nbytes);
@@ -203,7 +201,7 @@ visor_memregion_read(MEMREGION *memregion, ulong offset, void *dest,
203EXPORT_SYMBOL_GPL(visor_memregion_read); 201EXPORT_SYMBOL_GPL(visor_memregion_read);
204 202
205int 203int
206visor_memregion_write(MEMREGION *memregion, ulong offset, void *src, 204visor_memregion_write(struct memregion *memregion, ulong offset, void *src,
207 ulong nbytes) 205 ulong nbytes)
208{ 206{
209 return memregion_readwrite(TRUE, memregion, offset, src, nbytes); 207 return memregion_readwrite(TRUE, memregion, offset, src, nbytes);
@@ -211,7 +209,7 @@ visor_memregion_write(MEMREGION *memregion, ulong offset, void *src,
211EXPORT_SYMBOL_GPL(visor_memregion_write); 209EXPORT_SYMBOL_GPL(visor_memregion_write);
212 210
213void 211void
214visor_memregion_destroy(MEMREGION *memregion) 212visor_memregion_destroy(struct memregion *memregion)
215{ 213{
216 if (memregion == NULL) 214 if (memregion == NULL)
217 return; 215 return;
diff --git a/drivers/staging/unisys/visorutil/periodic_work.c b/drivers/staging/unisys/visorutil/periodic_work.c
index 3dd1c04d0e14..0908bf929401 100644
--- a/drivers/staging/unisys/visorutil/periodic_work.c
+++ b/drivers/staging/unisys/visorutil/periodic_work.c
@@ -25,8 +25,6 @@
25 25
26#define MYDRVNAME "periodic_work" 26#define MYDRVNAME "periodic_work"
27 27
28
29
30struct periodic_work { 28struct periodic_work {
31 rwlock_t lock; 29 rwlock_t lock;
32 struct delayed_work work; 30 struct delayed_work work;
@@ -39,8 +37,6 @@ struct periodic_work {
39 const char *devnam; 37 const char *devnam;
40}; 38};
41 39
42
43
44static void periodic_work_func(struct work_struct *work) 40static void periodic_work_func(struct work_struct *work)
45{ 41{
46 struct periodic_work *pw; 42 struct periodic_work *pw;
@@ -49,8 +45,6 @@ static void periodic_work_func(struct work_struct *work)
49 (*pw->workfunc)(pw->workfuncarg); 45 (*pw->workfunc)(pw->workfuncarg);
50} 46}
51 47
52
53
54struct periodic_work *visor_periodic_work_create(ulong jiffy_interval, 48struct periodic_work *visor_periodic_work_create(ulong jiffy_interval,
55 struct workqueue_struct *workqueue, 49 struct workqueue_struct *workqueue,
56 void (*workfunc)(void *), 50 void (*workfunc)(void *),
@@ -73,16 +67,12 @@ struct periodic_work *visor_periodic_work_create(ulong jiffy_interval,
73} 67}
74EXPORT_SYMBOL_GPL(visor_periodic_work_create); 68EXPORT_SYMBOL_GPL(visor_periodic_work_create);
75 69
76
77
78void visor_periodic_work_destroy(struct periodic_work *pw) 70void visor_periodic_work_destroy(struct periodic_work *pw)
79{ 71{
80 kfree(pw); 72 kfree(pw);
81} 73}
82EXPORT_SYMBOL_GPL(visor_periodic_work_destroy); 74EXPORT_SYMBOL_GPL(visor_periodic_work_destroy);
83 75
84
85
86/** Call this from your periodic work worker function to schedule the next 76/** Call this from your periodic work worker function to schedule the next
87 * call. 77 * call.
88 * If this function returns FALSE, there was a failure and the 78 * If this function returns FALSE, there was a failure and the
@@ -112,8 +102,6 @@ unlock:
112} 102}
113EXPORT_SYMBOL_GPL(visor_periodic_work_nextperiod); 103EXPORT_SYMBOL_GPL(visor_periodic_work_nextperiod);
114 104
115
116
117/** This function returns TRUE iff new periodic work was actually started. 105/** This function returns TRUE iff new periodic work was actually started.
118 * If this function returns FALSE, then no work was started 106 * If this function returns FALSE, then no work was started
119 * (either because it was already started, or because of a failure). 107 * (either because it was already started, or because of a failure).
@@ -145,13 +133,9 @@ BOOL visor_periodic_work_start(struct periodic_work *pw)
145unlock: 133unlock:
146 write_unlock(&pw->lock); 134 write_unlock(&pw->lock);
147 return rc; 135 return rc;
148
149} 136}
150EXPORT_SYMBOL_GPL(visor_periodic_work_start); 137EXPORT_SYMBOL_GPL(visor_periodic_work_start);
151 138
152
153
154
155/** This function returns TRUE iff your call actually stopped the periodic 139/** This function returns TRUE iff your call actually stopped the periodic
156 * work. 140 * work.
157 * 141 *
@@ -223,8 +207,9 @@ BOOL visor_periodic_work_stop(struct periodic_work *pw)
223 */ 207 */
224 SLEEPJIFFIES(10); 208 SLEEPJIFFIES(10);
225 write_lock(&pw->lock); 209 write_lock(&pw->lock);
226 } else 210 } else {
227 pw->want_to_stop = FALSE; 211 pw->want_to_stop = FALSE;
212 }
228 } 213 }
229 write_unlock(&pw->lock); 214 write_unlock(&pw->lock);
230 return stopped_something; 215 return stopped_something;
diff --git a/drivers/staging/unisys/visorutil/procobjecttree.c b/drivers/staging/unisys/visorutil/procobjecttree.c
index c476036f7382..195772d22c9e 100644
--- a/drivers/staging/unisys/visorutil/procobjecttree.c
+++ b/drivers/staging/unisys/visorutil/procobjecttree.c
@@ -320,19 +320,18 @@ void visor_proc_DestroyObject(MYPROCOBJECT *obj)
320 kfree(obj->procDirProperties); 320 kfree(obj->procDirProperties);
321 obj->procDirProperties = NULL; 321 obj->procDirProperties = NULL;
322 } 322 }
323 if (obj->procDirPropertyContexts != NULL) { 323
324 kfree(obj->procDirPropertyContexts); 324 kfree(obj->procDirPropertyContexts);
325 obj->procDirPropertyContexts = NULL; 325 obj->procDirPropertyContexts = NULL;
326 } 326
327 if (obj->procDir != NULL) { 327 if (obj->procDir != NULL) {
328 if (obj->name != NULL) 328 if (obj->name != NULL)
329 remove_proc_entry(obj->name, type->procDir); 329 remove_proc_entry(obj->name, type->procDir);
330 obj->procDir = NULL; 330 obj->procDir = NULL;
331 } 331 }
332 if (obj->name != NULL) { 332
333 kfree(obj->name); 333 kfree(obj->name);
334 obj->name = NULL; 334 obj->name = NULL;
335 }
336 kfree(obj); 335 kfree(obj);
337} 336}
338EXPORT_SYMBOL_GPL(visor_proc_DestroyObject); 337EXPORT_SYMBOL_GPL(visor_proc_DestroyObject);
diff --git a/drivers/staging/unisys/visorutil/visorkmodutils.c b/drivers/staging/unisys/visorutil/visorkmodutils.c
index d6815f9e1337..556e2642d2d9 100644
--- a/drivers/staging/unisys/visorutil/visorkmodutils.c
+++ b/drivers/staging/unisys/visorutil/visorkmodutils.c
@@ -36,18 +36,7 @@
36int unisys_spar_platform; 36int unisys_spar_platform;
37EXPORT_SYMBOL_GPL(unisys_spar_platform); 37EXPORT_SYMBOL_GPL(unisys_spar_platform);
38 38
39/** Callers to interfaces that set __GFP_NORETRY flag below 39static __init uint32_t visorutil_spar_detect(void)
40 * must check for a NULL (error) result as we are telling the
41 * kernel interface that it is okay to fail.
42 */
43
44void *kmalloc_kernel(size_t siz)
45{
46 return kmalloc(siz, GFP_KERNEL | __GFP_NORETRY);
47}
48
49static __init uint32_t
50visorutil_spar_detect(void)
51{ 40{
52 unsigned int eax, ebx, ecx, edx; 41 unsigned int eax, ebx, ecx, edx;
53 42
@@ -57,22 +46,19 @@ visorutil_spar_detect(void)
57 return (ebx == UNISYS_SPAR_ID_EBX) && 46 return (ebx == UNISYS_SPAR_ID_EBX) &&
58 (ecx == UNISYS_SPAR_ID_ECX) && 47 (ecx == UNISYS_SPAR_ID_ECX) &&
59 (edx == UNISYS_SPAR_ID_EDX); 48 (edx == UNISYS_SPAR_ID_EDX);
60 } else 49 } else {
61 return 0; 50 return 0;
62 51 }
63} 52}
64 53
65 54static __init int visorutil_mod_init(void)
66
67
68static __init int
69visorutil_mod_init(void)
70{ 55{
71 if (visorutil_spar_detect()) { 56 if (visorutil_spar_detect()) {
72 unisys_spar_platform = TRUE; 57 unisys_spar_platform = TRUE;
73 return 0; 58 return 0;
74 } else 59 } else {
75 return -ENODEV; 60 return -ENODEV;
61 }
76} 62}
77 63
78static __exit void 64static __exit void
diff --git a/drivers/staging/vme/devices/Kconfig b/drivers/staging/vme/devices/Kconfig
index 8e8bbb1dcd9b..1d2ff0cc41f1 100644
--- a/drivers/staging/vme/devices/Kconfig
+++ b/drivers/staging/vme/devices/Kconfig
@@ -8,6 +8,9 @@ config VME_USER
8 VME windows in a manner at least semi-compatible with the interface 8 VME windows in a manner at least semi-compatible with the interface
9 provided with the original driver at <http://www.vmelinux.org/>. 9 provided with the original driver at <http://www.vmelinux.org/>.
10 10
11 To compile this driver as a module, choose M here. The module will
12 be called vme_user. If unsure, say N.
13
11config VME_PIO2 14config VME_PIO2
12 tristate "GE PIO2 VME" 15 tristate "GE PIO2 VME"
13 depends on STAGING && GPIOLIB 16 depends on STAGING && GPIOLIB
diff --git a/drivers/staging/vme/devices/vme_pio2_gpio.c b/drivers/staging/vme/devices/vme_pio2_gpio.c
index c64776f71809..da34d5529f51 100644
--- a/drivers/staging/vme/devices/vme_pio2_gpio.c
+++ b/drivers/staging/vme/devices/vme_pio2_gpio.c
@@ -191,11 +191,11 @@ int pio2_gpio_init(struct pio2_card *card)
191 int retval = 0; 191 int retval = 0;
192 char *label; 192 char *label;
193 193
194 label = kmalloc(PIO2_NUM_CHANNELS, GFP_KERNEL); 194 label = kasprintf(GFP_KERNEL,
195 "%s@%s", driver_name, dev_name(&card->vdev->dev));
195 if (label == NULL) 196 if (label == NULL)
196 return -ENOMEM; 197 return -ENOMEM;
197 198
198 sprintf(label, "%s@%s", driver_name, dev_name(&card->vdev->dev));
199 card->gc.label = label; 199 card->gc.label = label;
200 200
201 card->gc.ngpio = PIO2_NUM_CHANNELS; 201 card->gc.ngpio = PIO2_NUM_CHANNELS;
diff --git a/drivers/staging/vt6655/80211hdr.h b/drivers/staging/vt6655/80211hdr.h
deleted file mode 100644
index 36e14ec50564..000000000000
--- a/drivers/staging/vt6655/80211hdr.h
+++ /dev/null
@@ -1,318 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: 80211hdr.h
21 *
22 * Purpose: 802.11 MAC headers related pre-defines and macros.
23 *
24 *
25 * Author: Lyndon Chen
26 *
27 * Date: Apr 8, 2002
28 *
29 */
30
31#ifndef __80211HDR_H__
32#define __80211HDR_H__
33
34#include "ttype.h"
35
36/* bit type */
37#define BIT0 0x00000001
38#define BIT1 0x00000002
39#define BIT2 0x00000004
40#define BIT3 0x00000008
41#define BIT4 0x00000010
42#define BIT5 0x00000020
43#define BIT6 0x00000040
44#define BIT7 0x00000080
45#define BIT8 0x00000100
46#define BIT9 0x00000200
47#define BIT10 0x00000400
48#define BIT11 0x00000800
49#define BIT12 0x00001000
50#define BIT13 0x00002000
51#define BIT14 0x00004000
52#define BIT15 0x00008000
53#define BIT16 0x00010000
54#define BIT17 0x00020000
55#define BIT18 0x00040000
56#define BIT19 0x00080000
57#define BIT20 0x00100000
58#define BIT21 0x00200000
59#define BIT22 0x00400000
60#define BIT23 0x00800000
61#define BIT24 0x01000000
62#define BIT25 0x02000000
63#define BIT26 0x04000000
64#define BIT27 0x08000000
65#define BIT28 0x10000000
66#define BIT29 0x20000000
67#define BIT30 0x40000000
68#define BIT31 0x80000000
69
70/* 802.11 frame related, defined as 802.11 spec */
71#define WLAN_ADDR_LEN 6
72#define WLAN_CRC_LEN 4
73#define WLAN_CRC32_LEN 4
74#define WLAN_FCS_LEN 4
75#define WLAN_BSSID_LEN 6
76#define WLAN_BSS_TS_LEN 8
77#define WLAN_HDR_ADDR2_LEN 16
78#define WLAN_HDR_ADDR3_LEN 24
79#define WLAN_HDR_ADDR4_LEN 30
80#define WLAN_IEHDR_LEN 2
81#define WLAN_SSID_MAXLEN 32
82#define WLAN_RATES_MAXLEN 16
83#define WLAN_RATES_MAXLEN_11B 4
84#define WLAN_RSN_MAXLEN 32
85#define WLAN_DATA_MAXLEN 2312
86#define WLAN_A3FR_MAXLEN (WLAN_HDR_ADDR3_LEN + WLAN_DATA_MAXLEN + \
87 WLAN_CRC_LEN)
88
89#define WLAN_BEACON_FR_MAXLEN WLAN_A3FR_MAXLEN
90#define WLAN_ATIM_FR_MAXLEN (WLAN_HDR_ADDR3_LEN + 0)
91#define WLAN_NULLDATA_FR_MAXLEN (WLAN_HDR_ADDR3_LEN + 0)
92#define WLAN_DISASSOC_FR_MAXLEN (WLAN_HDR_ADDR3_LEN + 2)
93#define WLAN_ASSOCREQ_FR_MAXLEN WLAN_A3FR_MAXLEN
94#define WLAN_ASSOCRESP_FR_MAXLEN WLAN_A3FR_MAXLEN
95#define WLAN_REASSOCREQ_FR_MAXLEN WLAN_A3FR_MAXLEN
96#define WLAN_REASSOCRESP_FR_MAXLEN WLAN_A3FR_MAXLEN
97#define WLAN_PROBEREQ_FR_MAXLEN WLAN_A3FR_MAXLEN
98#define WLAN_PROBERESP_FR_MAXLEN WLAN_A3FR_MAXLEN
99#define WLAN_AUTHEN_FR_MAXLEN WLAN_A3FR_MAXLEN
100#define WLAN_DEAUTHEN_FR_MAXLEN (WLAN_HDR_ADDR3_LEN + 2)
101
102#define WLAN_WEP_NKEYS 4
103#define WLAN_WEP40_KEYLEN 5
104#define WLAN_WEP104_KEYLEN 13
105#define WLAN_WEP232_KEYLEN 29
106#define WLAN_WEPMAX_KEYLEN 32
107#define WLAN_CHALLENGE_IE_MAXLEN 255
108#define WLAN_CHALLENGE_IE_LEN 130
109#define WLAN_CHALLENGE_LEN 128
110#define WLAN_WEP_IV_LEN 4
111#define WLAN_WEP_ICV_LEN 4
112#define WLAN_FRAGS_MAX 16
113
114/* Frame Type */
115#define WLAN_TYPE_MGR 0x00
116#define WLAN_TYPE_CTL 0x01
117#define WLAN_TYPE_DATA 0x02
118
119#define WLAN_FTYPE_MGMT 0x00
120#define WLAN_FTYPE_CTL 0x01
121#define WLAN_FTYPE_DATA 0x02
122
123/* Frame Subtypes */
124#define WLAN_FSTYPE_ASSOCREQ 0x00
125#define WLAN_FSTYPE_ASSOCRESP 0x01
126#define WLAN_FSTYPE_REASSOCREQ 0x02
127#define WLAN_FSTYPE_REASSOCRESP 0x03
128#define WLAN_FSTYPE_PROBEREQ 0x04
129#define WLAN_FSTYPE_PROBERESP 0x05
130#define WLAN_FSTYPE_BEACON 0x08
131#define WLAN_FSTYPE_ATIM 0x09
132#define WLAN_FSTYPE_DISASSOC 0x0a
133#define WLAN_FSTYPE_AUTHEN 0x0b
134#define WLAN_FSTYPE_DEAUTHEN 0x0c
135#define WLAN_FSTYPE_ACTION 0x0d
136
137/* Control */
138#define WLAN_FSTYPE_PSPOLL 0x0a
139#define WLAN_FSTYPE_RTS 0x0b
140#define WLAN_FSTYPE_CTS 0x0c
141#define WLAN_FSTYPE_ACK 0x0d
142#define WLAN_FSTYPE_CFEND 0x0e
143#define WLAN_FSTYPE_CFENDCFACK 0x0f
144
145/* Data */
146#define WLAN_FSTYPE_DATAONLY 0x00
147#define WLAN_FSTYPE_DATA_CFACK 0x01
148#define WLAN_FSTYPE_DATA_CFPOLL 0x02
149#define WLAN_FSTYPE_DATA_CFACK_CFPOLL 0x03
150#define WLAN_FSTYPE_NULL 0x04
151#define WLAN_FSTYPE_CFACK 0x05
152#define WLAN_FSTYPE_CFPOLL 0x06
153#define WLAN_FSTYPE_CFACK_CFPOLL 0x07
154
155#ifdef __BIG_ENDIAN
156
157/* GET & SET Frame Control bit */
158#define WLAN_GET_FC_PRVER(n) (((unsigned short)(n) >> 8) & (BIT0 | BIT1))
159#define WLAN_GET_FC_FTYPE(n) ((((unsigned short)(n) >> 8) & (BIT2 | BIT3)) >> 2)
160#define WLAN_GET_FC_FSTYPE(n) ((((unsigned short)(n) >> 8) & (BIT4|BIT5|BIT6|BIT7)) >> 4)
161#define WLAN_GET_FC_TODS(n) ((((unsigned short)(n) << 8) & (BIT8)) >> 8)
162#define WLAN_GET_FC_FROMDS(n) ((((unsigned short)(n) << 8) & (BIT9)) >> 9)
163#define WLAN_GET_FC_MOREFRAG(n) ((((unsigned short)(n) << 8) & (BIT10)) >> 10)
164#define WLAN_GET_FC_RETRY(n) ((((unsigned short)(n) << 8) & (BIT11)) >> 11)
165#define WLAN_GET_FC_PWRMGT(n) ((((unsigned short)(n) << 8) & (BIT12)) >> 12)
166#define WLAN_GET_FC_MOREDATA(n) ((((unsigned short)(n) << 8) & (BIT13)) >> 13)
167#define WLAN_GET_FC_ISWEP(n) ((((unsigned short)(n) << 8) & (BIT14)) >> 14)
168#define WLAN_GET_FC_ORDER(n) ((((unsigned short)(n) << 8) & (BIT15)) >> 15)
169
170/* Sequence Field bit */
171#define WLAN_GET_SEQ_FRGNUM(n) (((unsigned short)(n) >> 8) & (BIT0|BIT1|BIT2|BIT3))
172#define WLAN_GET_SEQ_SEQNUM(n) ((((unsigned short)(n) >> 8) & (~(BIT0|BIT1|BIT2|BIT3))) >> 4)
173
174/* Capability Field bit */
175#define WLAN_GET_CAP_INFO_ESS(n) (((n) >> 8) & BIT0)
176#define WLAN_GET_CAP_INFO_IBSS(n) ((((n) >> 8) & BIT1) >> 1)
177#define WLAN_GET_CAP_INFO_CFPOLLABLE(n) ((((n) >> 8) & BIT2) >> 2)
178#define WLAN_GET_CAP_INFO_CFPOLLREQ(n) ((((n) >> 8) & BIT3) >> 3)
179#define WLAN_GET_CAP_INFO_PRIVACY(n) ((((n) >> 8) & BIT4) >> 4)
180#define WLAN_GET_CAP_INFO_SHORTPREAMBLE(n) ((((n) >> 8) & BIT5) >> 5)
181#define WLAN_GET_CAP_INFO_PBCC(n) ((((n) >> 8) & BIT6) >> 6)
182#define WLAN_GET_CAP_INFO_AGILITY(n) ((((n) >> 8) & BIT7) >> 7)
183#define WLAN_GET_CAP_INFO_SPECTRUMMNG(n) ((((n)) & BIT8) >> 10)
184#define WLAN_GET_CAP_INFO_SHORTSLOTTIME(n) ((((n)) & BIT10) >> 10)
185#define WLAN_GET_CAP_INFO_DSSSOFDM(n) ((((n)) & BIT13) >> 13)
186#define WLAN_GET_CAP_INFO_GRPACK(n) ((((n)) & BIT14) >> 14)
187
188#else
189
190/* GET & SET Frame Control bit */
191#define WLAN_GET_FC_PRVER(n) (((unsigned short)(n)) & (BIT0 | BIT1))
192#define WLAN_GET_FC_FTYPE(n) ((((unsigned short)(n)) & (BIT2 | BIT3)) >> 2)
193#define WLAN_GET_FC_FSTYPE(n) ((((unsigned short)(n)) & (BIT4|BIT5|BIT6|BIT7)) >> 4)
194#define WLAN_GET_FC_TODS(n) ((((unsigned short)(n)) & (BIT8)) >> 8)
195#define WLAN_GET_FC_FROMDS(n) ((((unsigned short)(n)) & (BIT9)) >> 9)
196#define WLAN_GET_FC_MOREFRAG(n) ((((unsigned short)(n)) & (BIT10)) >> 10)
197#define WLAN_GET_FC_RETRY(n) ((((unsigned short)(n)) & (BIT11)) >> 11)
198#define WLAN_GET_FC_PWRMGT(n) ((((unsigned short)(n)) & (BIT12)) >> 12)
199#define WLAN_GET_FC_MOREDATA(n) ((((unsigned short)(n)) & (BIT13)) >> 13)
200#define WLAN_GET_FC_ISWEP(n) ((((unsigned short)(n)) & (BIT14)) >> 14)
201#define WLAN_GET_FC_ORDER(n) ((((unsigned short)(n)) & (BIT15)) >> 15)
202
203/* Sequence Field bit */
204#define WLAN_GET_SEQ_FRGNUM(n) (((unsigned short)(n)) & (BIT0|BIT1|BIT2|BIT3))
205#define WLAN_GET_SEQ_SEQNUM(n) ((((unsigned short)(n)) & (~(BIT0|BIT1|BIT2|BIT3))) >> 4)
206
207/* Capability Field bit */
208#define WLAN_GET_CAP_INFO_ESS(n) ((n) & BIT0)
209#define WLAN_GET_CAP_INFO_IBSS(n) (((n) & BIT1) >> 1)
210#define WLAN_GET_CAP_INFO_CFPOLLABLE(n) (((n) & BIT2) >> 2)
211#define WLAN_GET_CAP_INFO_CFPOLLREQ(n) (((n) & BIT3) >> 3)
212#define WLAN_GET_CAP_INFO_PRIVACY(n) (((n) & BIT4) >> 4)
213#define WLAN_GET_CAP_INFO_SHORTPREAMBLE(n) (((n) & BIT5) >> 5)
214#define WLAN_GET_CAP_INFO_PBCC(n) (((n) & BIT6) >> 6)
215#define WLAN_GET_CAP_INFO_AGILITY(n) (((n) & BIT7) >> 7)
216#define WLAN_GET_CAP_INFO_SPECTRUMMNG(n) (((n) & BIT8) >> 10)
217#define WLAN_GET_CAP_INFO_SHORTSLOTTIME(n) (((n) & BIT10) >> 10)
218#define WLAN_GET_CAP_INFO_DSSSOFDM(n) (((n) & BIT13) >> 13)
219#define WLAN_GET_CAP_INFO_GRPACK(n) (((n) & BIT14) >> 14)
220
221#endif /*#ifdef __BIG_ENDIAN */
222
223#define WLAN_SET_CAP_INFO_ESS(n) (n)
224#define WLAN_SET_CAP_INFO_IBSS(n) ((n) << 1)
225#define WLAN_SET_CAP_INFO_CFPOLLABLE(n) ((n) << 2)
226#define WLAN_SET_CAP_INFO_CFPOLLREQ(n) ((n) << 3)
227#define WLAN_SET_CAP_INFO_PRIVACY(n) ((n) << 4)
228#define WLAN_SET_CAP_INFO_SHORTPREAMBLE(n) ((n) << 5)
229#define WLAN_SET_CAP_INFO_SPECTRUMMNG(n) ((n) << 8)
230#define WLAN_SET_CAP_INFO_PBCC(n) ((n) << 6)
231#define WLAN_SET_CAP_INFO_AGILITY(n) ((n) << 7)
232#define WLAN_SET_CAP_INFO_SHORTSLOTTIME(n) ((n) << 10)
233#define WLAN_SET_CAP_INFO_DSSSOFDM(n) ((n) << 13)
234#define WLAN_SET_CAP_INFO_GRPACK(n) ((n) << 14)
235
236#define WLAN_SET_FC_PRVER(n) ((unsigned short)(n))
237#define WLAN_SET_FC_FTYPE(n) (((unsigned short)(n)) << 2)
238#define WLAN_SET_FC_FSTYPE(n) (((unsigned short)(n)) << 4)
239#define WLAN_SET_FC_TODS(n) (((unsigned short)(n)) << 8)
240#define WLAN_SET_FC_FROMDS(n) (((unsigned short)(n)) << 9)
241#define WLAN_SET_FC_MOREFRAG(n) (((unsigned short)(n)) << 10)
242#define WLAN_SET_FC_RETRY(n) (((unsigned short)(n)) << 11)
243#define WLAN_SET_FC_PWRMGT(n) (((unsigned short)(n)) << 12)
244#define WLAN_SET_FC_MOREDATA(n) (((unsigned short)(n)) << 13)
245#define WLAN_SET_FC_ISWEP(n) (((unsigned short)(n)) << 14)
246#define WLAN_SET_FC_ORDER(n) (((unsigned short)(n)) << 15)
247
248#define WLAN_SET_SEQ_FRGNUM(n) ((unsigned short)(n))
249#define WLAN_SET_SEQ_SEQNUM(n) (((unsigned short)(n)) << 4)
250
251/* ERP Field bit */
252
253#define WLAN_GET_ERP_NONERP_PRESENT(n) ((n) & BIT0)
254#define WLAN_GET_ERP_USE_PROTECTION(n) (((n) & BIT1) >> 1)
255#define WLAN_GET_ERP_BARKER_MODE(n) (((n) & BIT2) >> 2)
256
257#define WLAN_SET_ERP_NONERP_PRESENT(n) (n)
258#define WLAN_SET_ERP_USE_PROTECTION(n) ((n) << 1)
259#define WLAN_SET_ERP_BARKER_MODE(n) ((n) << 2)
260
261/* Support & Basic Rates field */
262#define WLAN_MGMT_IS_BASICRATE(b) ((b) & BIT7)
263#define WLAN_MGMT_GET_RATE(b) ((b) & ~BIT7)
264
265/* TIM field */
266#define WLAN_MGMT_IS_MULTICAST_TIM(b) ((b) & BIT0)
267#define WLAN_MGMT_GET_TIM_OFFSET(b) (((b) & ~BIT0) >> 1)
268
269/* 3-Addr & 4-Addr */
270#define WLAN_HDR_A3_DATA_PTR(p) (((unsigned char *)(p)) + WLAN_HDR_ADDR3_LEN)
271#define WLAN_HDR_A4_DATA_PTR(p) (((unsigned char *)(p)) + WLAN_HDR_ADDR4_LEN)
272
273/* IEEE ADDR */
274#define IEEE_ADDR_UNIVERSAL 0x02
275#define IEEE_ADDR_GROUP 0x01
276
277typedef struct {
278 unsigned char abyAddr[6];
279} IEEE_ADDR, *PIEEE_ADDR;
280
281/* 802.11 Header Format */
282
283typedef struct tagWLAN_80211HDR_A2 {
284 unsigned short wFrameCtl;
285 unsigned short wDurationID;
286 unsigned char abyAddr1[WLAN_ADDR_LEN];
287 unsigned char abyAddr2[WLAN_ADDR_LEN];
288} __attribute__ ((__packed__))
289WLAN_80211HDR_A2, *PWLAN_80211HDR_A2;
290
291typedef struct tagWLAN_80211HDR_A3 {
292 unsigned short wFrameCtl;
293 unsigned short wDurationID;
294 unsigned char abyAddr1[WLAN_ADDR_LEN];
295 unsigned char abyAddr2[WLAN_ADDR_LEN];
296 unsigned char abyAddr3[WLAN_ADDR_LEN];
297 unsigned short wSeqCtl;
298} __attribute__ ((__packed__))
299WLAN_80211HDR_A3, *PWLAN_80211HDR_A3;
300
301typedef struct tagWLAN_80211HDR_A4 {
302 unsigned short wFrameCtl;
303 unsigned short wDurationID;
304 unsigned char abyAddr1[WLAN_ADDR_LEN];
305 unsigned char abyAddr2[WLAN_ADDR_LEN];
306 unsigned char abyAddr3[WLAN_ADDR_LEN];
307 unsigned short wSeqCtl;
308 unsigned char abyAddr4[WLAN_ADDR_LEN];
309} __attribute__ ((__packed__))
310WLAN_80211HDR_A4, *PWLAN_80211HDR_A4;
311
312typedef union tagUWLAN_80211HDR {
313 WLAN_80211HDR_A2 sA2;
314 WLAN_80211HDR_A3 sA3;
315 WLAN_80211HDR_A4 sA4;
316} UWLAN_80211HDR, *PUWLAN_80211HDR;
317
318#endif /* __80211HDR_H__ */
diff --git a/drivers/staging/vt6655/80211mgr.c b/drivers/staging/vt6655/80211mgr.c
deleted file mode 100644
index 7d2c6472ec9a..000000000000
--- a/drivers/staging/vt6655/80211mgr.c
+++ /dev/null
@@ -1,1019 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: 80211mgr.c
20 *
21 * Purpose: Handles the 802.11 management support functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 8, 2002
26 *
27 * Functions:
28 * vMgrEncodeBeacon - Encode the Beacon frame
29 * vMgrDecodeBeacon - Decode the Beacon frame
30 * vMgrEncodeIBSSATIM - Encode the IBSS ATIM frame
31 * vMgrDecodeIBSSATIM - Decode the IBSS ATIM frame
32 * vMgrEncodeDisassociation - Encode the Disassociation frame
33 * vMgrDecodeDisassociation - Decode the Disassociation frame
34 * vMgrEncodeAssocRequest - Encode the Association request frame
35 * vMgrDecodeAssocRequest - Decode the Association request frame
36 * vMgrEncodeAssocResponse - Encode the Association response frame
37 * vMgrDecodeAssocResponse - Decode the Association response frame
38 * vMgrEncodeReAssocRequest - Encode the ReAssociation request frame
39 * vMgrDecodeReAssocRequest - Decode the ReAssociation request frame
40 * vMgrEncodeProbeRequest - Encode the Probe request frame
41 * vMgrDecodeProbeRequest - Decode the Probe request frame
42 * vMgrEncodeProbeResponse - Encode the Probe response frame
43 * vMgrDecodeProbeResponse - Decode the Probe response frame
44 * vMgrEncodeAuthen - Encode the Authentication frame
45 * vMgrDecodeAuthen - Decode the Authentication frame
46 * vMgrEncodeDeauthen - Encode the DeAuthentication frame
47 * vMgrDecodeDeauthen - Decode the DeAuthentication frame
48 * vMgrEncodeReassocResponse - Encode the Reassociation response frame
49 * vMgrDecodeReassocResponse - Decode the Reassociation response frame
50 *
51 * Revision History:
52 *
53 */
54
55#include "tmacro.h"
56#include "tether.h"
57#include "80211mgr.h"
58#include "80211hdr.h"
59#include "device.h"
60#include "wpa.h"
61
62/*--------------------- Static Definitions -------------------------*/
63
64/*--------------------- Static Classes ----------------------------*/
65
66/*--------------------- Static Functions --------------------------*/
67
68/*--------------------- Export Variables --------------------------*/
69
70/*--------------------- Export Functions --------------------------*/
71
72/*+
73 *
74 * Routine Description:
75 * Encode Beacon frame body offset
76 *
77 * Return Value:
78 * None.
79 *
80 -*/
81
82void
83vMgrEncodeBeacon(
84 PWLAN_FR_BEACON pFrame
85)
86{
87 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
88
89 /* Fixed Fields */
90 pFrame->pqwTimestamp = (__le64 *)
91 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
92 WLAN_BEACON_OFF_TS);
93 pFrame->pwBeaconInterval = (unsigned short *)
94 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
95 WLAN_BEACON_OFF_BCN_INT);
96 pFrame->pwCapInfo = (unsigned short *)
97 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
98 WLAN_BEACON_OFF_CAPINFO);
99
100 pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_BEACON_OFF_SSID;
101}
102
103/*+
104 *
105 * Routine Description:
106 * Decode Beacon frame body offset
107 *
108 *
109 * Return Value:
110 * None.
111 *
112 -*/
113
114void
115vMgrDecodeBeacon(
116 PWLAN_FR_BEACON pFrame
117)
118{
119 PWLAN_IE pItem;
120
121 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
122
123 /* Fixed Fields */
124 pFrame->pqwTimestamp = (__le64 *)
125 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
126 WLAN_BEACON_OFF_TS);
127 pFrame->pwBeaconInterval = (unsigned short *)
128 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
129 WLAN_BEACON_OFF_BCN_INT);
130 pFrame->pwCapInfo = (unsigned short *)
131 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
132 WLAN_BEACON_OFF_CAPINFO);
133
134 /* Information elements */
135 pItem = (PWLAN_IE)((unsigned char *)
136 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))) +
137 WLAN_BEACON_OFF_SSID);
138 while (((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) {
139 switch (pItem->byElementID) {
140 case WLAN_EID_SSID:
141 if (pFrame->pSSID == NULL)
142 pFrame->pSSID = (PWLAN_IE_SSID)pItem;
143 break;
144 case WLAN_EID_SUPP_RATES:
145 if (pFrame->pSuppRates == NULL)
146 pFrame->pSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
147 break;
148 case WLAN_EID_FH_PARMS:
149 /* pFrame->pFHParms = (PWLAN_IE_FH_PARMS)pItem; */
150 break;
151 case WLAN_EID_DS_PARMS:
152 if (pFrame->pDSParms == NULL)
153 pFrame->pDSParms = (PWLAN_IE_DS_PARMS)pItem;
154 break;
155 case WLAN_EID_CF_PARMS:
156 if (pFrame->pCFParms == NULL)
157 pFrame->pCFParms = (PWLAN_IE_CF_PARMS)pItem;
158 break;
159 case WLAN_EID_IBSS_PARMS:
160 if (pFrame->pIBSSParms == NULL)
161 pFrame->pIBSSParms = (PWLAN_IE_IBSS_PARMS)pItem;
162 break;
163 case WLAN_EID_TIM:
164 if (pFrame->pTIM == NULL)
165 pFrame->pTIM = (PWLAN_IE_TIM)pItem;
166 break;
167
168 case WLAN_EID_RSN:
169 if (pFrame->pRSN == NULL)
170 pFrame->pRSN = (PWLAN_IE_RSN)pItem;
171 break;
172 case WLAN_EID_RSN_WPA:
173 if (pFrame->pRSNWPA == NULL) {
174 if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == true)
175 pFrame->pRSNWPA =
176 (PWLAN_IE_RSN_EXT)pItem;
177 }
178 break;
179
180 case WLAN_EID_ERP:
181 if (pFrame->pERP == NULL)
182 pFrame->pERP = (PWLAN_IE_ERP)pItem;
183 break;
184 case WLAN_EID_EXTSUPP_RATES:
185 if (pFrame->pExtSuppRates == NULL)
186 pFrame->pExtSuppRates =
187 (PWLAN_IE_SUPP_RATES)pItem;
188 break;
189
190 case WLAN_EID_COUNTRY: /* 7 */
191 if (pFrame->pIE_Country == NULL)
192 pFrame->pIE_Country = (PWLAN_IE_COUNTRY)pItem;
193 break;
194
195 case WLAN_EID_PWR_CONSTRAINT: /* 32 */
196 if (pFrame->pIE_PowerConstraint == NULL)
197 pFrame->pIE_PowerConstraint =
198 (PWLAN_IE_PW_CONST)pItem;
199 break;
200
201 case WLAN_EID_CH_SWITCH: /* 37 */
202 if (pFrame->pIE_CHSW == NULL)
203 pFrame->pIE_CHSW = (PWLAN_IE_CH_SW)pItem;
204 break;
205
206 case WLAN_EID_QUIET: /* 40 */
207 if (pFrame->pIE_Quiet == NULL)
208 pFrame->pIE_Quiet = (PWLAN_IE_QUIET)pItem;
209 break;
210
211 case WLAN_EID_IBSS_DFS:
212 if (pFrame->pIE_IBSSDFS == NULL)
213 pFrame->pIE_IBSSDFS = (PWLAN_IE_IBSS_DFS)pItem;
214 break;
215
216 default:
217 pr_debug("Unrecognized EID=%dd in beacon decode\n",
218 pItem->byElementID);
219 break;
220
221 }
222 pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 + pItem->len);
223 }
224}
225
226/*+
227 *
228 * Routine Description:
229 * Encode IBSS ATIM
230 *
231 *
232 * Return Value:
233 * None.
234 *
235 -*/
236
237void
238vMgrEncodeIBSSATIM(
239 PWLAN_FR_IBSSATIM pFrame
240)
241{
242 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
243 pFrame->len = WLAN_HDR_ADDR3_LEN;
244}
245
246/*+
247 *
248 * Routine Description:
249 * Decode IBSS ATIM
250 *
251 *
252 * Return Value:
253 * None.
254 *
255 -*/
256
257void
258vMgrDecodeIBSSATIM(
259 PWLAN_FR_IBSSATIM pFrame
260)
261{
262 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
263}
264
265/*+
266 *
267 * Routine Description:
268 * Encode Disassociation
269 *
270 *
271 * Return Value:
272 * None.
273 *
274 -*/
275
276void
277vMgrEncodeDisassociation(
278 PWLAN_FR_DISASSOC pFrame
279)
280{
281 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
282
283 /* Fixed Fields */
284 pFrame->pwReason = (unsigned short *)
285 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
286 WLAN_DISASSOC_OFF_REASON);
287 pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_DISASSOC_OFF_REASON +
288 sizeof(*(pFrame->pwReason));
289}
290
291/*+
292 *
293 * Routine Description:
294 * Decode Disassociation
295 *
296 *
297 * Return Value:
298 * None.
299 *
300 -*/
301
302void
303vMgrDecodeDisassociation(
304 PWLAN_FR_DISASSOC pFrame
305)
306{
307 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
308
309 /* Fixed Fields */
310 pFrame->pwReason = (unsigned short *)
311 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
312 WLAN_DISASSOC_OFF_REASON);
313}
314
315/*+
316 *
317 * Routine Description:
318 * Encode Association Request
319 *
320 *
321 * Return Value:
322 * None.
323 *
324 -*/
325
326void
327vMgrEncodeAssocRequest(
328 PWLAN_FR_ASSOCREQ pFrame
329)
330{
331 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
332 /* Fixed Fields */
333 pFrame->pwCapInfo = (unsigned short *)
334 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
335 WLAN_ASSOCREQ_OFF_CAP_INFO);
336 pFrame->pwListenInterval = (unsigned short *)
337 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
338 WLAN_ASSOCREQ_OFF_LISTEN_INT);
339 pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_ASSOCREQ_OFF_LISTEN_INT +
340 sizeof(*(pFrame->pwListenInterval));
341}
342
343/*+
344 *
345 * Routine Description: (AP)
346 * Decode Association Request
347 *
348 *
349 * Return Value:
350 * None.
351 *
352 -*/
353
354void
355vMgrDecodeAssocRequest(
356 PWLAN_FR_ASSOCREQ pFrame
357)
358{
359 PWLAN_IE pItem;
360
361 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
362 /* Fixed Fields */
363 pFrame->pwCapInfo = (unsigned short *)
364 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
365 WLAN_ASSOCREQ_OFF_CAP_INFO);
366 pFrame->pwListenInterval = (unsigned short *)
367 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
368 WLAN_ASSOCREQ_OFF_LISTEN_INT);
369
370 /* Information elements */
371 pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
372 + WLAN_ASSOCREQ_OFF_SSID);
373
374 while (((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) {
375 switch (pItem->byElementID) {
376 case WLAN_EID_SSID:
377 if (pFrame->pSSID == NULL)
378 pFrame->pSSID = (PWLAN_IE_SSID)pItem;
379 break;
380 case WLAN_EID_SUPP_RATES:
381 if (pFrame->pSuppRates == NULL)
382 pFrame->pSuppRates =
383 (PWLAN_IE_SUPP_RATES)pItem;
384 break;
385
386 case WLAN_EID_RSN:
387 if (pFrame->pRSN == NULL)
388 pFrame->pRSN = (PWLAN_IE_RSN)pItem;
389 break;
390 case WLAN_EID_RSN_WPA:
391 if (pFrame->pRSNWPA == NULL) {
392 if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == true)
393 pFrame->pRSNWPA =
394 (PWLAN_IE_RSN_EXT)pItem;
395 }
396 break;
397 case WLAN_EID_EXTSUPP_RATES:
398 if (pFrame->pExtSuppRates == NULL)
399 pFrame->pExtSuppRates =
400 (PWLAN_IE_SUPP_RATES)pItem;
401 break;
402
403 default:
404 pr_debug("Unrecognized EID=%dd in assocreq decode\n",
405 pItem->byElementID);
406 break;
407 }
408 pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 + pItem->len);
409 }
410}
411
412/*+
413 *
414 * Routine Description: (AP)
415 * Encode Association Response
416 *
417 *
418 * Return Value:
419 * None.
420 *
421 -*/
422
423void
424vMgrEncodeAssocResponse(
425 PWLAN_FR_ASSOCRESP pFrame
426)
427{
428 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
429
430 /* Fixed Fields */
431 pFrame->pwCapInfo = (unsigned short *)
432 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
433 WLAN_ASSOCRESP_OFF_CAP_INFO);
434 pFrame->pwStatus = (unsigned short *)
435 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
436 WLAN_ASSOCRESP_OFF_STATUS);
437 pFrame->pwAid = (unsigned short *)
438 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
439 WLAN_ASSOCRESP_OFF_AID);
440 pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_ASSOCRESP_OFF_AID +
441 sizeof(*(pFrame->pwAid));
442}
443
444/*+
445 *
446 * Routine Description:
447 * Decode Association Response
448 *
449 *
450 * Return Value:
451 * None.
452 *
453 -*/
454
455void
456vMgrDecodeAssocResponse(
457 PWLAN_FR_ASSOCRESP pFrame
458)
459{
460 PWLAN_IE pItem;
461
462 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
463
464 /* Fixed Fields */
465 pFrame->pwCapInfo = (unsigned short *)
466 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
467 WLAN_ASSOCRESP_OFF_CAP_INFO);
468 pFrame->pwStatus = (unsigned short *)
469 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
470 WLAN_ASSOCRESP_OFF_STATUS);
471 pFrame->pwAid = (unsigned short *)
472 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
473 WLAN_ASSOCRESP_OFF_AID);
474
475 /* Information elements */
476 pFrame->pSuppRates = (PWLAN_IE_SUPP_RATES)
477 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
478 WLAN_ASSOCRESP_OFF_SUPP_RATES);
479
480 pItem = (PWLAN_IE)(pFrame->pSuppRates);
481 pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 + pItem->len);
482
483 if ((((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) &&
484 (pItem->byElementID == WLAN_EID_EXTSUPP_RATES)) {
485 pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
486 pr_debug("pFrame->pExtSuppRates=[%p]\n", pItem);
487 } else {
488 pFrame->pExtSuppRates = NULL;
489 }
490}
491
492/*+
493 *
494 * Routine Description:
495 * Encode Reassociation Request
496 *
497 *
498 * Return Value:
499 * None.
500 *
501 -*/
502
503void
504vMgrEncodeReassocRequest(
505 PWLAN_FR_REASSOCREQ pFrame
506)
507{
508 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
509
510 /* Fixed Fields */
511 pFrame->pwCapInfo = (unsigned short *)
512 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
513 WLAN_REASSOCREQ_OFF_CAP_INFO);
514 pFrame->pwListenInterval = (unsigned short *)
515 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
516 WLAN_REASSOCREQ_OFF_LISTEN_INT);
517 pFrame->pAddrCurrAP = (PIEEE_ADDR)
518 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
519 WLAN_REASSOCREQ_OFF_CURR_AP);
520 pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_REASSOCREQ_OFF_CURR_AP +
521 sizeof(*(pFrame->pAddrCurrAP));
522}
523
524/*+
525 *
526 * Routine Description: (AP)
527 * Decode Reassociation Request
528 *
529 *
530 * Return Value:
531 * None.
532 *
533 -*/
534
535void
536vMgrDecodeReassocRequest(
537 PWLAN_FR_REASSOCREQ pFrame
538)
539{
540 PWLAN_IE pItem;
541
542 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
543
544 /* Fixed Fields */
545 pFrame->pwCapInfo = (unsigned short *)
546 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
547 WLAN_REASSOCREQ_OFF_CAP_INFO);
548 pFrame->pwListenInterval = (unsigned short *)
549 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
550 WLAN_REASSOCREQ_OFF_LISTEN_INT);
551 pFrame->pAddrCurrAP = (PIEEE_ADDR)
552 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
553 WLAN_REASSOCREQ_OFF_CURR_AP);
554
555 /* Information elements */
556 pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
557 + WLAN_REASSOCREQ_OFF_SSID);
558
559 while (((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) {
560 switch (pItem->byElementID) {
561 case WLAN_EID_SSID:
562 if (pFrame->pSSID == NULL)
563 pFrame->pSSID = (PWLAN_IE_SSID)pItem;
564 break;
565 case WLAN_EID_SUPP_RATES:
566 if (pFrame->pSuppRates == NULL)
567 pFrame->pSuppRates =
568 (PWLAN_IE_SUPP_RATES)pItem;
569 break;
570
571 case WLAN_EID_RSN:
572 if (pFrame->pRSN == NULL)
573 pFrame->pRSN = (PWLAN_IE_RSN)pItem;
574 break;
575 case WLAN_EID_RSN_WPA:
576 if (pFrame->pRSNWPA == NULL) {
577 if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == true)
578 pFrame->pRSNWPA =
579 (PWLAN_IE_RSN_EXT)pItem;
580 }
581 break;
582
583 case WLAN_EID_EXTSUPP_RATES:
584 if (pFrame->pExtSuppRates == NULL)
585 pFrame->pExtSuppRates =
586 (PWLAN_IE_SUPP_RATES)pItem;
587 break;
588 default:
589 pr_debug("Unrecognized EID=%dd in reassocreq decode\n",
590 pItem->byElementID);
591 break;
592 }
593 pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 + pItem->len);
594 }
595}
596
597/*+
598 *
599 * Routine Description:
600 * Encode Probe Request
601 *
602 *
603 * Return Value:
604 * None.
605 *
606 -*/
607
608void
609vMgrEncodeProbeRequest(
610 PWLAN_FR_PROBEREQ pFrame
611)
612{
613 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
614 pFrame->len = WLAN_HDR_ADDR3_LEN;
615}
616
617/*+
618 *
619 * Routine Description:
620 * Decode Probe Request
621 *
622 *
623 * Return Value:
624 * None.
625 *
626 -*/
627
628void
629vMgrDecodeProbeRequest(
630 PWLAN_FR_PROBEREQ pFrame
631)
632{
633 PWLAN_IE pItem;
634
635 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
636
637 /* Information elements */
638 pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)));
639
640 while (((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) {
641 switch (pItem->byElementID) {
642 case WLAN_EID_SSID:
643 if (pFrame->pSSID == NULL)
644 pFrame->pSSID = (PWLAN_IE_SSID)pItem;
645 break;
646
647 case WLAN_EID_SUPP_RATES:
648 if (pFrame->pSuppRates == NULL)
649 pFrame->pSuppRates =
650 (PWLAN_IE_SUPP_RATES)pItem;
651 break;
652
653 case WLAN_EID_EXTSUPP_RATES:
654 if (pFrame->pExtSuppRates == NULL)
655 pFrame->pExtSuppRates =
656 (PWLAN_IE_SUPP_RATES)pItem;
657 break;
658
659 default:
660 pr_debug("Bad EID=%dd in probereq\n",
661 pItem->byElementID);
662 break;
663 }
664
665 pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 + pItem->len);
666 }
667}
668
669/*+
670 *
671 * Routine Description:
672 * Encode Probe Response
673 *
674 *
675 * Return Value:
676 * None.
677 *
678 -*/
679
680void
681vMgrEncodeProbeResponse(
682 PWLAN_FR_PROBERESP pFrame
683)
684{
685 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
686
687 /* Fixed Fields */
688 pFrame->pqwTimestamp = (__le64 *)
689 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
690 WLAN_PROBERESP_OFF_TS);
691 pFrame->pwBeaconInterval = (unsigned short *)
692 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
693 WLAN_PROBERESP_OFF_BCN_INT);
694 pFrame->pwCapInfo = (unsigned short *)
695 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
696 WLAN_PROBERESP_OFF_CAP_INFO);
697
698 pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_PROBERESP_OFF_CAP_INFO +
699 sizeof(*(pFrame->pwCapInfo));
700}
701
702/*+
703 *
704 * Routine Description:
705 * Decode Probe Response
706 *
707 *
708 * Return Value:
709 * None.
710 *
711 -*/
712
713void
714vMgrDecodeProbeResponse(
715 PWLAN_FR_PROBERESP pFrame
716)
717{
718 PWLAN_IE pItem;
719
720 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
721
722 /* Fixed Fields */
723 pFrame->pqwTimestamp = (__le64 *)
724 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
725 WLAN_PROBERESP_OFF_TS);
726 pFrame->pwBeaconInterval = (unsigned short *)
727 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
728 WLAN_PROBERESP_OFF_BCN_INT);
729 pFrame->pwCapInfo = (unsigned short *)
730 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
731 WLAN_PROBERESP_OFF_CAP_INFO);
732
733 /* Information elements */
734 pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
735 + WLAN_PROBERESP_OFF_SSID);
736
737 while (((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) {
738 switch (pItem->byElementID) {
739 case WLAN_EID_SSID:
740 if (pFrame->pSSID == NULL)
741 pFrame->pSSID = (PWLAN_IE_SSID)pItem;
742 break;
743 case WLAN_EID_SUPP_RATES:
744 if (pFrame->pSuppRates == NULL)
745 pFrame->pSuppRates =
746 (PWLAN_IE_SUPP_RATES)pItem;
747 break;
748 case WLAN_EID_FH_PARMS:
749 break;
750 case WLAN_EID_DS_PARMS:
751 if (pFrame->pDSParms == NULL)
752 pFrame->pDSParms = (PWLAN_IE_DS_PARMS)pItem;
753 break;
754 case WLAN_EID_CF_PARMS:
755 if (pFrame->pCFParms == NULL)
756 pFrame->pCFParms = (PWLAN_IE_CF_PARMS)pItem;
757 break;
758 case WLAN_EID_IBSS_PARMS:
759 if (pFrame->pIBSSParms == NULL)
760 pFrame->pIBSSParms =
761 (PWLAN_IE_IBSS_PARMS)pItem;
762 break;
763
764 case WLAN_EID_RSN:
765 if (pFrame->pRSN == NULL)
766 pFrame->pRSN = (PWLAN_IE_RSN)pItem;
767 break;
768 case WLAN_EID_RSN_WPA:
769 if (pFrame->pRSNWPA == NULL) {
770 if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == true)
771 pFrame->pRSNWPA =
772 (PWLAN_IE_RSN_EXT)pItem;
773 }
774 break;
775 case WLAN_EID_ERP:
776 if (pFrame->pERP == NULL)
777 pFrame->pERP = (PWLAN_IE_ERP)pItem;
778 break;
779 case WLAN_EID_EXTSUPP_RATES:
780 if (pFrame->pExtSuppRates == NULL)
781 pFrame->pExtSuppRates =
782 (PWLAN_IE_SUPP_RATES)pItem;
783 break;
784
785 case WLAN_EID_COUNTRY: /* 7 */
786 if (pFrame->pIE_Country == NULL)
787 pFrame->pIE_Country = (PWLAN_IE_COUNTRY)pItem;
788 break;
789
790 case WLAN_EID_PWR_CONSTRAINT: /* 32 */
791 if (pFrame->pIE_PowerConstraint == NULL)
792 pFrame->pIE_PowerConstraint =
793 (PWLAN_IE_PW_CONST)pItem;
794 break;
795
796 case WLAN_EID_CH_SWITCH: /* 37 */
797 if (pFrame->pIE_CHSW == NULL)
798 pFrame->pIE_CHSW = (PWLAN_IE_CH_SW)pItem;
799 break;
800
801 case WLAN_EID_QUIET: /* 40 */
802 if (pFrame->pIE_Quiet == NULL)
803 pFrame->pIE_Quiet = (PWLAN_IE_QUIET)pItem;
804 break;
805
806 case WLAN_EID_IBSS_DFS:
807 if (pFrame->pIE_IBSSDFS == NULL)
808 pFrame->pIE_IBSSDFS = (PWLAN_IE_IBSS_DFS)pItem;
809 break;
810
811 default:
812 pr_debug("Bad EID=%dd in proberesp\n",
813 pItem->byElementID);
814 break;
815 }
816
817 pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 + pItem->len);
818 }
819}
820
821/*+
822 *
823 * Routine Description:
824 * Encode Authentication frame
825 *
826 *
827 * Return Value:
828 * None.
829 *
830 -*/
831
832void
833vMgrEncodeAuthen(
834 PWLAN_FR_AUTHEN pFrame
835)
836{
837 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
838
839 /* Fixed Fields */
840 pFrame->pwAuthAlgorithm = (unsigned short *)
841 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
842 WLAN_AUTHEN_OFF_AUTH_ALG);
843 pFrame->pwAuthSequence = (unsigned short *)
844 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
845 WLAN_AUTHEN_OFF_AUTH_SEQ);
846 pFrame->pwStatus = (unsigned short *)
847 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
848 WLAN_AUTHEN_OFF_STATUS);
849 pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_AUTHEN_OFF_STATUS +
850 sizeof(*(pFrame->pwStatus));
851}
852
853/*+
854 *
855 * Routine Description:
856 * Decode Authentication
857 *
858 *
859 * Return Value:
860 * None.
861 *
862 -*/
863
864void
865vMgrDecodeAuthen(
866 PWLAN_FR_AUTHEN pFrame
867)
868{
869 PWLAN_IE pItem;
870
871 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
872
873 /* Fixed Fields */
874 pFrame->pwAuthAlgorithm = (unsigned short *)
875 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
876 WLAN_AUTHEN_OFF_AUTH_ALG);
877 pFrame->pwAuthSequence = (unsigned short *)
878 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
879 WLAN_AUTHEN_OFF_AUTH_SEQ);
880 pFrame->pwStatus = (unsigned short *)
881 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
882 WLAN_AUTHEN_OFF_STATUS);
883
884 /* Information elements */
885 pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
886 + WLAN_AUTHEN_OFF_CHALLENGE);
887
888 if (((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len) &&
889 pItem->byElementID == WLAN_EID_CHALLENGE)
890 pFrame->pChallenge = (PWLAN_IE_CHALLENGE)pItem;
891}
892
893/*+
894 *
895 * Routine Description:
896 * Encode Authentication
897 *
898 *
899 * Return Value:
900 * None.
901 *
902 -*/
903
904void
905vMgrEncodeDeauthen(
906 PWLAN_FR_DEAUTHEN pFrame
907)
908{
909 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
910
911 /* Fixed Fields */
912 pFrame->pwReason = (unsigned short *)
913 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
914 WLAN_DEAUTHEN_OFF_REASON);
915 pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_DEAUTHEN_OFF_REASON +
916 sizeof(*(pFrame->pwReason));
917}
918
919/*+
920 *
921 * Routine Description:
922 * Decode Deauthentication
923 *
924 *
925 * Return Value:
926 * None.
927 *
928 -*/
929
930void
931vMgrDecodeDeauthen(
932 PWLAN_FR_DEAUTHEN pFrame
933)
934{
935 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
936
937 /* Fixed Fields */
938 pFrame->pwReason = (unsigned short *)
939 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
940 WLAN_DEAUTHEN_OFF_REASON);
941}
942
943/*+
944 *
945 * Routine Description: (AP)
946 * Encode Reassociation Response
947 *
948 *
949 * Return Value:
950 * None.
951 *
952 -*/
953
954void
955vMgrEncodeReassocResponse(
956 PWLAN_FR_REASSOCRESP pFrame
957)
958{
959 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
960
961 /* Fixed Fields */
962 pFrame->pwCapInfo = (unsigned short *)
963 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
964 WLAN_REASSOCRESP_OFF_CAP_INFO);
965 pFrame->pwStatus = (unsigned short *)
966 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
967 WLAN_REASSOCRESP_OFF_STATUS);
968 pFrame->pwAid = (unsigned short *)
969 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
970 WLAN_REASSOCRESP_OFF_AID);
971
972 pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_REASSOCRESP_OFF_AID +
973 sizeof(*(pFrame->pwAid));
974}
975
976/*+
977 *
978 * Routine Description:
979 * Decode Reassociation Response
980 *
981 *
982 * Return Value:
983 * None.
984 *
985 -*/
986
987void
988vMgrDecodeReassocResponse(
989 PWLAN_FR_REASSOCRESP pFrame
990)
991{
992 PWLAN_IE pItem;
993
994 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
995
996 /* Fixed Fields */
997 pFrame->pwCapInfo = (unsigned short *)
998 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
999 WLAN_REASSOCRESP_OFF_CAP_INFO);
1000 pFrame->pwStatus = (unsigned short *)
1001 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
1002 WLAN_REASSOCRESP_OFF_STATUS);
1003 pFrame->pwAid = (unsigned short *)
1004 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
1005 WLAN_REASSOCRESP_OFF_AID);
1006
1007 /* Information elements */
1008 pFrame->pSuppRates = (PWLAN_IE_SUPP_RATES)
1009 (WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)) +
1010 WLAN_REASSOCRESP_OFF_SUPP_RATES);
1011
1012 pItem = (PWLAN_IE)(pFrame->pSuppRates);
1013 pItem = (PWLAN_IE)(((unsigned char *)pItem) + 2 + pItem->len);
1014
1015 if ((((unsigned char *)pItem) < (pFrame->pBuf + pFrame->len)) &&
1016 (pItem->byElementID == WLAN_EID_EXTSUPP_RATES)) {
1017 pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
1018 }
1019}
diff --git a/drivers/staging/vt6655/80211mgr.h b/drivers/staging/vt6655/80211mgr.h
deleted file mode 100644
index d462a8af087b..000000000000
--- a/drivers/staging/vt6655/80211mgr.h
+++ /dev/null
@@ -1,725 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: 80211mgr.h
21 *
22 * Purpose: 802.11 management frames pre-defines.
23 *
24 *
25 * Author: Lyndon Chen
26 *
27 * Date: May 8, 2002
28 *
29 */
30
31#ifndef __80211MGR_H__
32#define __80211MGR_H__
33
34#include <linux/types.h>
35#include "linux/ieee80211.h"
36
37#include "ttype.h"
38#include "80211hdr.h"
39
40#define WLAN_MIN_ARRAY 1
41
42/* Information Element ID value */
43#define WLAN_EID_FH_PARMS 2
44#define WLAN_EID_DS_PARMS 3
45#define WLAN_EID_CF_PARMS 4
46#define WLAN_EID_IBSS_PARMS 6
47#define WLAN_EID_TPC_REQ 34
48#define WLAN_EID_TPC_REP 35
49#define WLAN_EID_SUPP_CH 36
50#define WLAN_EID_CH_SWITCH 37
51#define WLAN_EID_MEASURE_REQ 38
52#define WLAN_EID_MEASURE_REP 39
53#define WLAN_EID_QUIET 40
54#define WLAN_EID_IBSS_DFS 41
55#define WLAN_EID_ERP 42
56/* reference 802.11i 7.3.2 table 20 */
57#define WLAN_EID_EXTSUPP_RATES 50
58/* reference WiFi WPA spec. */
59#define WLAN_EID_RSN_WPA 221
60
61#define WLAN_EID_ERP_NONERP_PRESENT 0x01
62#define WLAN_EID_ERP_USE_PROTECTION 0x02
63#define WLAN_EID_ERP_BARKER_MODE 0x04
64
65/* Reason Codes */
66#define WLAN_MGMT_REASON_RSVD 0
67#define WLAN_MGMT_REASON_UNSPEC 1
68#define WLAN_MGMT_REASON_PRIOR_AUTH_INVALID 2
69#define WLAN_MGMT_REASON_DEAUTH_LEAVING 3
70#define WLAN_MGMT_REASON_DISASSOC_INACTIVE 4
71#define WLAN_MGMT_REASON_DISASSOC_AP_BUSY 5
72#define WLAN_MGMT_REASON_CLASS2_NONAUTH 6
73#define WLAN_MGMT_REASON_CLASS3_NONASSOC 7
74#define WLAN_MGMT_REASON_DISASSOC_STA_HASLEFT 8
75#define WLAN_MGMT_REASON_CANT_ASSOC_NONAUTH 9
76#define WLAN_MGMT_REASON_DISASSOC_PWR_CAP_UNACCEPT 10
77#define WLAN_MGMT_REASON_DISASSOC_SUPP_CH_UNACCEPT 11
78#define WLAN_MGMT_REASON_INVALID_IE 13
79#define WLAN_MGMT_REASON_MIC_FAILURE 14
80#define WLAN_MGMT_REASON_4WAY_HANDSHAKE_TIMEOUT 15
81#define WLAN_MGMT_REASON_GRPKEY_UPDATE_TIMEOUT 16
82#define WLAN_MGMT_REASON_4WAY_INFO_DIFFERENT 17
83#define WLAN_MGMT_REASON_MULTCAST_CIPHER_INVALID 18
84#define WLAN_MGMT_REASON_UNCAST_CIPHER_INVALID 19
85#define WLAN_MGMT_REASON_AKMP_INVALID 20
86#define WLAN_MGMT_REASON_RSNE_UNSUPPORTED 21
87#define WLAN_MGMT_REASON_RSNE_CAP_INVALID 22
88#define WLAN_MGMT_REASON_80211X_AUTH_FAILED 23
89
90/* Status Codes */
91#define WLAN_MGMT_STATUS_SUCCESS 0
92#define WLAN_MGMT_STATUS_UNSPEC_FAILURE 1
93#define WLAN_MGMT_STATUS_CAPS_UNSUPPORTED 10
94#define WLAN_MGMT_STATUS_REASSOC_NO_ASSOC 11
95#define WLAN_MGMT_STATUS_ASSOC_DENIED_UNSPEC 12
96#define WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG 13
97#define WLAN_MGMT_STATUS_RX_AUTH_NOSEQ 14
98#define WLAN_MGMT_STATUS_CHALLENGE_FAIL 15
99#define WLAN_MGMT_STATUS_AUTH_TIMEOUT 16
100#define WLAN_MGMT_STATUS_ASSOC_DENIED_BUSY 17
101#define WLAN_MGMT_STATUS_ASSOC_DENIED_RATES 18
102#define WLAN_MGMT_STATUS_ASSOC_DENIED_SHORTPREAMBLE 19
103#define WLAN_MGMT_STATUS_ASSOC_DENIED_PBCC 20
104#define WLAN_MGMT_STATUS_ASSOC_DENIED_AGILITY 21
105
106/* reference 802.11h 7.3.1.9 */
107#define WLAN_MGMT_STATUS_ASSOC_REJECT_BCS_SPECTRUM_MNG 22
108#define WLAN_MGMT_STATUS_ASSOC_REJECT_BCS_PWR_CAP 23
109#define WLAN_MGMT_STATUS_ASSOC_REJECT_BCS_SUPP_CH 24
110/* reference 802.11g 7.3.1.9 */
111#define WLAN_MGMT_STATUS_SHORTSLOTTIME_UNSUPPORTED 25
112#define WLAN_MGMT_STATUS_DSSSOFDM_UNSUPPORTED 26
113/* reference 802.11i 3.7.1.9 table 19 */
114#define WLAN_MGMT_STATUS_INVALID_IE 40
115#define WLAN_MGMT_STATUS_GROUP_CIPHER_INVALID 41
116#define WLAN_MGMT_STATUS_PAIRWISE_CIPHER_INVALID 42
117#define WLAN_MGMT_STATUS_AKMP_INVALID 43
118#define WLAN_MGMT_STATUS_UNSUPPORT_RSN_IE_VER 44
119#define WLAN_MGMT_STATUS_INVALID_RSN_IE_CAP 45
120#define WLAN_MGMT_STATUS_CIPHER_REJECT 46
121
122/* Auth Algorithm */
123#define WLAN_AUTH_ALG_OPENSYSTEM 0
124#define WLAN_AUTH_ALG_SHAREDKEY 1
125
126/* Management Frame Field Offsets */
127/* Note: Not all fields are listed because of variable lengths. */
128/* Note: These offsets are from the start of the frame data */
129
130#define WLAN_BEACON_OFF_TS 0
131#define WLAN_BEACON_OFF_BCN_INT 8
132#define WLAN_BEACON_OFF_CAPINFO 10
133#define WLAN_BEACON_OFF_SSID 12
134
135#define WLAN_DISASSOC_OFF_REASON 0
136
137#define WLAN_ASSOCREQ_OFF_CAP_INFO 0
138#define WLAN_ASSOCREQ_OFF_LISTEN_INT 2
139#define WLAN_ASSOCREQ_OFF_SSID 4
140
141#define WLAN_ASSOCRESP_OFF_CAP_INFO 0
142#define WLAN_ASSOCRESP_OFF_STATUS 2
143#define WLAN_ASSOCRESP_OFF_AID 4
144#define WLAN_ASSOCRESP_OFF_SUPP_RATES 6
145
146#define WLAN_REASSOCREQ_OFF_CAP_INFO 0
147#define WLAN_REASSOCREQ_OFF_LISTEN_INT 2
148#define WLAN_REASSOCREQ_OFF_CURR_AP 4
149#define WLAN_REASSOCREQ_OFF_SSID 10
150
151#define WLAN_REASSOCRESP_OFF_CAP_INFO 0
152#define WLAN_REASSOCRESP_OFF_STATUS 2
153#define WLAN_REASSOCRESP_OFF_AID 4
154#define WLAN_REASSOCRESP_OFF_SUPP_RATES 6
155
156#define WLAN_PROBEREQ_OFF_SSID 0
157
158#define WLAN_PROBERESP_OFF_TS 0
159#define WLAN_PROBERESP_OFF_BCN_INT 8
160#define WLAN_PROBERESP_OFF_CAP_INFO 10
161#define WLAN_PROBERESP_OFF_SSID 12
162
163#define WLAN_AUTHEN_OFF_AUTH_ALG 0
164#define WLAN_AUTHEN_OFF_AUTH_SEQ 2
165#define WLAN_AUTHEN_OFF_STATUS 4
166#define WLAN_AUTHEN_OFF_CHALLENGE 6
167
168#define WLAN_DEAUTHEN_OFF_REASON 0
169
170/* Cipher Suite Selectors defined in 802.11i */
171#define WLAN_11i_CSS_USE_GROUP 0
172#define WLAN_11i_CSS_WEP40 1
173#define WLAN_11i_CSS_TKIP 2
174#define WLAN_11i_CSS_CCMP 4
175#define WLAN_11i_CSS_WEP104 5
176#define WLAN_11i_CSS_UNKNOWN 255
177
178/* Authentication and Key Management Suite Selectors defined in 802.11i */
179#define WLAN_11i_AKMSS_802_1X 1
180#define WLAN_11i_AKMSS_PSK 2
181#define WLAN_11i_AKMSS_UNKNOWN 255
182
183/* Measurement type definitions reference ieee 802.11h Table 20b */
184#define MEASURE_TYPE_BASIC 0
185#define MEASURE_TYPE_CCA 1
186#define MEASURE_TYPE_RPI 2
187
188/* Measurement request mode definitions reference ieee 802.11h Figure 46h */
189#define MEASURE_MODE_ENABLE 0x02
190#define MEASURE_MODE_REQ 0x04
191#define MEASURE_MODE_REP 0x08
192
193/* Measurement report mode definitions reference ieee 802.11h Figure 46m */
194#define MEASURE_MODE_LATE 0x01
195#define MEASURE_MODE_INCAPABLE 0x02
196#define MEASURE_MODE_REFUSED 0x04
197
198/* Information Element Types */
199
200#pragma pack(1)
201typedef struct tagWLAN_IE {
202 unsigned char byElementID;
203 unsigned char len;
204} __attribute__ ((__packed__))
205WLAN_IE, *PWLAN_IE;
206
207/* Service Set Identity (SSID) */
208#pragma pack(1)
209typedef struct tagWLAN_IE_SSID {
210 unsigned char byElementID;
211 unsigned char len;
212 unsigned char abySSID[1];
213} __attribute__ ((__packed__))
214WLAN_IE_SSID, *PWLAN_IE_SSID;
215
216/* Supported Rates */
217#pragma pack(1)
218typedef struct tagWLAN_IE_SUPP_RATES {
219 unsigned char byElementID;
220 unsigned char len;
221 unsigned char abyRates[1];
222} __attribute__ ((__packed__))
223WLAN_IE_SUPP_RATES, *PWLAN_IE_SUPP_RATES;
224
225/* FH Parameter Set */
226#pragma pack(1)
227typedef struct _WLAN_IE_FH_PARMS {
228 unsigned char byElementID;
229 unsigned char len;
230 unsigned short wDwellTime;
231 unsigned char byHopSet;
232 unsigned char byHopPattern;
233 unsigned char byHopIndex;
234} WLAN_IE_FH_PARMS, *PWLAN_IE_FH_PARMS;
235
236/* DS Parameter Set */
237#pragma pack(1)
238typedef struct tagWLAN_IE_DS_PARMS {
239 unsigned char byElementID;
240 unsigned char len;
241 unsigned char byCurrChannel;
242} __attribute__ ((__packed__))
243WLAN_IE_DS_PARMS, *PWLAN_IE_DS_PARMS;
244
245/* CF Parameter Set */
246#pragma pack(1)
247typedef struct tagWLAN_IE_CF_PARMS {
248 unsigned char byElementID;
249 unsigned char len;
250 unsigned char byCFPCount;
251 unsigned char byCFPPeriod;
252 unsigned short wCFPMaxDuration;
253 unsigned short wCFPDurRemaining;
254} __attribute__ ((__packed__))
255WLAN_IE_CF_PARMS, *PWLAN_IE_CF_PARMS;
256
257/* TIM */
258#pragma pack(1)
259typedef struct tagWLAN_IE_TIM {
260 unsigned char byElementID;
261 unsigned char len;
262 unsigned char byDTIMCount;
263 unsigned char byDTIMPeriod;
264 unsigned char byBitMapCtl;
265 unsigned char byVirtBitMap[1];
266} __attribute__ ((__packed__))
267WLAN_IE_TIM, *PWLAN_IE_TIM;
268
269/* IBSS Parameter Set */
270#pragma pack(1)
271typedef struct tagWLAN_IE_IBSS_PARMS {
272 unsigned char byElementID;
273 unsigned char len;
274 unsigned short wATIMWindow;
275} __attribute__ ((__packed__))
276WLAN_IE_IBSS_PARMS, *PWLAN_IE_IBSS_PARMS;
277
278/* Challenge Text */
279#pragma pack(1)
280typedef struct tagWLAN_IE_CHALLENGE {
281 unsigned char byElementID;
282 unsigned char len;
283 unsigned char abyChallenge[1];
284} __attribute__ ((__packed__))
285WLAN_IE_CHALLENGE, *PWLAN_IE_CHALLENGE;
286
287#pragma pack(1)
288typedef struct tagWLAN_IE_RSN_EXT {
289 unsigned char byElementID;
290 unsigned char len;
291 unsigned char abyOUI[4];
292 unsigned short wVersion;
293 unsigned char abyMulticast[4];
294 unsigned short wPKCount;
295 struct {
296 unsigned char abyOUI[4];
297 } PKSList[1]; /* the rest is variable so need to */
298 /* overlay ieauth structure */
299} WLAN_IE_RSN_EXT, *PWLAN_IE_RSN_EXT;
300
301#pragma pack(1)
302typedef struct tagWLAN_IE_RSN_AUTH {
303 unsigned short wAuthCount;
304 struct {
305 unsigned char abyOUI[4];
306 } AuthKSList[1];
307} WLAN_IE_RSN_AUTH, *PWLAN_IE_RSN_AUTH;
308
309/* RSN Identity */
310#pragma pack(1)
311typedef struct tagWLAN_IE_RSN {
312 unsigned char byElementID;
313 unsigned char len;
314 unsigned short wVersion;
315 unsigned char abyRSN[WLAN_MIN_ARRAY];
316} WLAN_IE_RSN, *PWLAN_IE_RSN;
317
318/* ERP */
319#pragma pack(1)
320typedef struct tagWLAN_IE_ERP {
321 unsigned char byElementID;
322 unsigned char len;
323 unsigned char byContext;
324} __attribute__ ((__packed__))
325WLAN_IE_ERP, *PWLAN_IE_ERP;
326
327#pragma pack(1)
328typedef struct _MEASEURE_REQ {
329 unsigned char byChannel;
330 unsigned char abyStartTime[8];
331 unsigned char abyDuration[2];
332} MEASEURE_REQ, *PMEASEURE_REQ,
333 MEASEURE_REQ_BASIC, *PMEASEURE_REQ_BASIC,
334 MEASEURE_REQ_CCA, *PMEASEURE_REQ_CCA,
335 MEASEURE_REQ_RPI, *PMEASEURE_REQ_RPI;
336
337typedef struct _MEASEURE_REP_BASIC {
338 unsigned char byChannel;
339 unsigned char abyStartTime[8];
340 unsigned char abyDuration[2];
341 unsigned char byMap;
342} MEASEURE_REP_BASIC, *PMEASEURE_REP_BASIC;
343
344typedef struct _MEASEURE_REP_CCA {
345 unsigned char byChannel;
346 unsigned char abyStartTime[8];
347 unsigned char abyDuration[2];
348 unsigned char byCCABusyFraction;
349} MEASEURE_REP_CCA, *PMEASEURE_REP_CCA;
350
351typedef struct _MEASEURE_REP_RPI {
352 unsigned char byChannel;
353 unsigned char abyStartTime[8];
354 unsigned char abyDuration[2];
355 unsigned char abyRPIdensity[8];
356} MEASEURE_REP_RPI, *PMEASEURE_REP_RPI;
357
358typedef union _MEASEURE_REP {
359 MEASEURE_REP_BASIC sBasic;
360 MEASEURE_REP_CCA sCCA;
361 MEASEURE_REP_RPI sRPI;
362} MEASEURE_REP, *PMEASEURE_REP;
363
364typedef struct _WLAN_IE_MEASURE_REQ {
365 unsigned char byElementID;
366 unsigned char len;
367 unsigned char byToken;
368 unsigned char byMode;
369 unsigned char byType;
370 MEASEURE_REQ sReq;
371} WLAN_IE_MEASURE_REQ, *PWLAN_IE_MEASURE_REQ;
372
373typedef struct _WLAN_IE_MEASURE_REP {
374 unsigned char byElementID;
375 unsigned char len;
376 unsigned char byToken;
377 unsigned char byMode;
378 unsigned char byType;
379 MEASEURE_REP sRep;
380} WLAN_IE_MEASURE_REP, *PWLAN_IE_MEASURE_REP;
381
382typedef struct _WLAN_IE_CH_SW {
383 unsigned char byElementID;
384 unsigned char len;
385 unsigned char byMode;
386 unsigned char byChannel;
387 unsigned char byCount;
388} WLAN_IE_CH_SW, *PWLAN_IE_CH_SW;
389
390typedef struct _WLAN_IE_QUIET {
391 unsigned char byElementID;
392 unsigned char len;
393 unsigned char byQuietCount;
394 unsigned char byQuietPeriod;
395 unsigned char abyQuietDuration[2];
396 unsigned char abyQuietOffset[2];
397} WLAN_IE_QUIET, *PWLAN_IE_QUIET;
398
399typedef struct _WLAN_IE_COUNTRY {
400 unsigned char byElementID;
401 unsigned char len;
402 unsigned char abyCountryString[3];
403 unsigned char abyCountryInfo[3];
404} WLAN_IE_COUNTRY, *PWLAN_IE_COUNTRY;
405
406typedef struct _WLAN_IE_PW_CONST {
407 unsigned char byElementID;
408 unsigned char len;
409 unsigned char byPower;
410} WLAN_IE_PW_CONST, *PWLAN_IE_PW_CONST;
411
412typedef struct _WLAN_IE_PW_CAP {
413 unsigned char byElementID;
414 unsigned char len;
415 unsigned char byMinPower;
416 unsigned char byMaxPower;
417} WLAN_IE_PW_CAP, *PWLAN_IE_PW_CAP;
418
419typedef struct _WLAN_IE_SUPP_CH {
420 unsigned char byElementID;
421 unsigned char len;
422 unsigned char abyChannelTuple[2];
423} WLAN_IE_SUPP_CH, *PWLAN_IE_SUPP_CH;
424
425typedef struct _WLAN_IE_TPC_REQ {
426 unsigned char byElementID;
427 unsigned char len;
428} WLAN_IE_TPC_REQ, *PWLAN_IE_TPC_REQ;
429
430typedef struct _WLAN_IE_TPC_REP {
431 unsigned char byElementID;
432 unsigned char len;
433 unsigned char byTxPower;
434 unsigned char byLinkMargin;
435} WLAN_IE_TPC_REP, *PWLAN_IE_TPC_REP;
436
437typedef struct _WLAN_IE_IBSS_DFS {
438 unsigned char byElementID;
439 unsigned char len;
440 unsigned char abyDFSOwner[6];
441 unsigned char byDFSRecovery;
442 unsigned char abyChannelMap[2];
443} WLAN_IE_IBSS_DFS, *PWLAN_IE_IBSS_DFS;
444
445#pragma pack()
446
447/* Frame Types */
448/* prototype structure, all mgmt frame types will start with these members */
449typedef struct tagWLAN_FR_MGMT {
450 unsigned int uType;
451 unsigned int len;
452 unsigned char *pBuf;
453 PUWLAN_80211HDR pHdr;
454} WLAN_FR_MGMT, *PWLAN_FR_MGMT;
455
456/* Beacon frame */
457typedef struct tagWLAN_FR_BEACON {
458 unsigned int uType;
459 unsigned int len;
460 unsigned char *pBuf;
461 PUWLAN_80211HDR pHdr;
462 __le64 *pqwTimestamp;
463 unsigned short *pwBeaconInterval;
464 unsigned short *pwCapInfo;
465 PWLAN_IE_SSID pSSID;
466 PWLAN_IE_SUPP_RATES pSuppRates;
467 PWLAN_IE_DS_PARMS pDSParms;
468 PWLAN_IE_CF_PARMS pCFParms;
469 PWLAN_IE_TIM pTIM;
470 PWLAN_IE_IBSS_PARMS pIBSSParms;
471 PWLAN_IE_RSN pRSN;
472 PWLAN_IE_RSN_EXT pRSNWPA;
473 PWLAN_IE_ERP pERP;
474 PWLAN_IE_SUPP_RATES pExtSuppRates;
475 PWLAN_IE_COUNTRY pIE_Country;
476 PWLAN_IE_PW_CONST pIE_PowerConstraint;
477 PWLAN_IE_CH_SW pIE_CHSW;
478 PWLAN_IE_IBSS_DFS pIE_IBSSDFS;
479 PWLAN_IE_QUIET pIE_Quiet;
480} WLAN_FR_BEACON, *PWLAN_FR_BEACON;
481
482/* IBSS ATIM frame */
483typedef struct tagWLAN_FR_IBSSATIM {
484 unsigned int uType;
485 unsigned int len;
486 unsigned char *pBuf;
487 PUWLAN_80211HDR pHdr;
488} WLAN_FR_IBSSATIM, *PWLAN_FR_IBSSATIM;
489
490/* Disassociation */
491typedef struct tagWLAN_FR_DISASSOC {
492 unsigned int uType;
493 unsigned int len;
494 unsigned char *pBuf;
495 PUWLAN_80211HDR pHdr;
496 unsigned short *pwReason;
497} WLAN_FR_DISASSOC, *PWLAN_FR_DISASSOC;
498
499/* Association Request */
500typedef struct tagWLAN_FR_ASSOCREQ {
501 unsigned int uType;
502 unsigned int len;
503 unsigned char *pBuf;
504 PUWLAN_80211HDR pHdr;
505 unsigned short *pwCapInfo;
506 unsigned short *pwListenInterval;
507 PWLAN_IE_SSID pSSID;
508 PWLAN_IE_SUPP_RATES pSuppRates;
509 PWLAN_IE_RSN pRSN;
510 PWLAN_IE_RSN_EXT pRSNWPA;
511 PWLAN_IE_SUPP_RATES pExtSuppRates;
512 PWLAN_IE_PW_CAP pCurrPowerCap;
513 PWLAN_IE_SUPP_CH pCurrSuppCh;
514} WLAN_FR_ASSOCREQ, *PWLAN_FR_ASSOCREQ;
515
516/* Association Response */
517typedef struct tagWLAN_FR_ASSOCRESP {
518 unsigned int uType;
519 unsigned int len;
520 unsigned char *pBuf;
521 PUWLAN_80211HDR pHdr;
522 unsigned short *pwCapInfo;
523 unsigned short *pwStatus;
524 unsigned short *pwAid;
525 PWLAN_IE_SUPP_RATES pSuppRates;
526 PWLAN_IE_SUPP_RATES pExtSuppRates;
527} WLAN_FR_ASSOCRESP, *PWLAN_FR_ASSOCRESP;
528
529/* Reassociation Request */
530typedef struct tagWLAN_FR_REASSOCREQ {
531 unsigned int uType;
532 unsigned int len;
533 unsigned char *pBuf;
534 PUWLAN_80211HDR pHdr;
535 unsigned short *pwCapInfo;
536 unsigned short *pwListenInterval;
537 PIEEE_ADDR pAddrCurrAP;
538 PWLAN_IE_SSID pSSID;
539 PWLAN_IE_SUPP_RATES pSuppRates;
540 PWLAN_IE_RSN pRSN;
541 PWLAN_IE_RSN_EXT pRSNWPA;
542 PWLAN_IE_SUPP_RATES pExtSuppRates;
543} WLAN_FR_REASSOCREQ, *PWLAN_FR_REASSOCREQ;
544
545/* Reassociation Response */
546typedef struct tagWLAN_FR_REASSOCRESP {
547 unsigned int uType;
548 unsigned int len;
549 unsigned char *pBuf;
550 PUWLAN_80211HDR pHdr;
551 unsigned short *pwCapInfo;
552 unsigned short *pwStatus;
553 unsigned short *pwAid;
554 PWLAN_IE_SUPP_RATES pSuppRates;
555 PWLAN_IE_SUPP_RATES pExtSuppRates;
556} WLAN_FR_REASSOCRESP, *PWLAN_FR_REASSOCRESP;
557
558/* Probe Request */
559typedef struct tagWLAN_FR_PROBEREQ {
560 unsigned int uType;
561 unsigned int len;
562 unsigned char *pBuf;
563 PUWLAN_80211HDR pHdr;
564 PWLAN_IE_SSID pSSID;
565 PWLAN_IE_SUPP_RATES pSuppRates;
566 PWLAN_IE_SUPP_RATES pExtSuppRates;
567} WLAN_FR_PROBEREQ, *PWLAN_FR_PROBEREQ;
568
569/* Probe Response */
570typedef struct tagWLAN_FR_PROBERESP {
571 unsigned int uType;
572 unsigned int len;
573 unsigned char *pBuf;
574 PUWLAN_80211HDR pHdr;
575 __le64 *pqwTimestamp;
576 unsigned short *pwBeaconInterval;
577 unsigned short *pwCapInfo;
578 PWLAN_IE_SSID pSSID;
579 PWLAN_IE_SUPP_RATES pSuppRates;
580 PWLAN_IE_DS_PARMS pDSParms;
581 PWLAN_IE_CF_PARMS pCFParms;
582 PWLAN_IE_IBSS_PARMS pIBSSParms;
583 PWLAN_IE_RSN pRSN;
584 PWLAN_IE_RSN_EXT pRSNWPA;
585 PWLAN_IE_ERP pERP;
586 PWLAN_IE_SUPP_RATES pExtSuppRates;
587 PWLAN_IE_COUNTRY pIE_Country;
588 PWLAN_IE_PW_CONST pIE_PowerConstraint;
589 PWLAN_IE_CH_SW pIE_CHSW;
590 PWLAN_IE_IBSS_DFS pIE_IBSSDFS;
591 PWLAN_IE_QUIET pIE_Quiet;
592} WLAN_FR_PROBERESP, *PWLAN_FR_PROBERESP;
593
594/* Authentication */
595typedef struct tagWLAN_FR_AUTHEN {
596 unsigned int uType;
597 unsigned int len;
598 unsigned char *pBuf;
599 PUWLAN_80211HDR pHdr;
600 unsigned short *pwAuthAlgorithm;
601 unsigned short *pwAuthSequence;
602 unsigned short *pwStatus;
603 PWLAN_IE_CHALLENGE pChallenge;
604} WLAN_FR_AUTHEN, *PWLAN_FR_AUTHEN;
605
606/* Deauthenication */
607typedef struct tagWLAN_FR_DEAUTHEN {
608 unsigned int uType;
609 unsigned int len;
610 unsigned char *pBuf;
611 PUWLAN_80211HDR pHdr;
612 unsigned short *pwReason;
613} WLAN_FR_DEAUTHEN, *PWLAN_FR_DEAUTHEN;
614
615void
616vMgrEncodeBeacon(
617 PWLAN_FR_BEACON pFrame
618);
619
620void
621vMgrDecodeBeacon(
622 PWLAN_FR_BEACON pFrame
623);
624
625void
626vMgrEncodeIBSSATIM(
627 PWLAN_FR_IBSSATIM pFrame
628);
629
630void
631vMgrDecodeIBSSATIM(
632 PWLAN_FR_IBSSATIM pFrame
633);
634
635void
636vMgrEncodeDisassociation(
637 PWLAN_FR_DISASSOC pFrame
638);
639
640void
641vMgrDecodeDisassociation(
642 PWLAN_FR_DISASSOC pFrame
643);
644
645void
646vMgrEncodeAssocRequest(
647 PWLAN_FR_ASSOCREQ pFrame
648);
649
650void
651vMgrDecodeAssocRequest(
652 PWLAN_FR_ASSOCREQ pFrame
653);
654
655void
656vMgrEncodeAssocResponse(
657 PWLAN_FR_ASSOCRESP pFrame
658);
659
660void
661vMgrDecodeAssocResponse(
662 PWLAN_FR_ASSOCRESP pFrame
663);
664
665void
666vMgrEncodeReassocRequest(
667 PWLAN_FR_REASSOCREQ pFrame
668);
669
670void
671vMgrDecodeReassocRequest(
672 PWLAN_FR_REASSOCREQ pFrame
673);
674
675void
676vMgrEncodeProbeRequest(
677 PWLAN_FR_PROBEREQ pFrame
678);
679
680void
681vMgrDecodeProbeRequest(
682 PWLAN_FR_PROBEREQ pFrame
683);
684
685void
686vMgrEncodeProbeResponse(
687 PWLAN_FR_PROBERESP pFrame
688);
689
690void
691vMgrDecodeProbeResponse(
692 PWLAN_FR_PROBERESP pFrame
693);
694
695void
696vMgrEncodeAuthen(
697 PWLAN_FR_AUTHEN pFrame
698);
699
700void
701vMgrDecodeAuthen(
702 PWLAN_FR_AUTHEN pFrame
703);
704
705void
706vMgrEncodeDeauthen(
707 PWLAN_FR_DEAUTHEN pFrame
708);
709
710void
711vMgrDecodeDeauthen(
712 PWLAN_FR_DEAUTHEN pFrame
713);
714
715void
716vMgrEncodeReassocResponse(
717 PWLAN_FR_REASSOCRESP pFrame
718);
719
720void
721vMgrDecodeReassocResponse(
722 PWLAN_FR_REASSOCRESP pFrame
723);
724
725#endif/* __80211MGR_H__ */
diff --git a/drivers/staging/vt6655/IEEE11h.c b/drivers/staging/vt6655/IEEE11h.c
deleted file mode 100644
index 180a27cc74d7..000000000000
--- a/drivers/staging/vt6655/IEEE11h.c
+++ /dev/null
@@ -1,141 +0,0 @@
1/*
2 * Copyright (c) 1996, 2005 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: IEEE11h.c
21 *
22 * Purpose:
23 *
24 * Functions:
25 *
26 * Revision History:
27 *
28 * Author: Yiching Chen
29 *
30 * Date: Mar. 31, 2005
31 *
32 */
33
34#include "ttype.h"
35#include "tmacro.h"
36#include "tether.h"
37#include "IEEE11h.h"
38#include "device.h"
39#include "wmgr.h"
40#include "rxtx.h"
41#include "channel.h"
42
43/*--------------------- Static Definitions -------------------------*/
44
45#pragma pack(1)
46
47typedef struct _WLAN_FRAME_ACTION {
48 WLAN_80211HDR_A3 Header;
49 unsigned char byCategory;
50 unsigned char byAction;
51 unsigned char abyVars[1];
52} WLAN_FRAME_ACTION, *PWLAN_FRAME_ACTION;
53
54typedef struct _WLAN_FRAME_MSRREQ {
55 WLAN_80211HDR_A3 Header;
56 unsigned char byCategory;
57 unsigned char byAction;
58 unsigned char byDialogToken;
59 WLAN_IE_MEASURE_REQ sMSRReqEIDs[1];
60} WLAN_FRAME_MSRREQ, *PWLAN_FRAME_MSRREQ;
61
62typedef struct _WLAN_FRAME_MSRREP {
63 WLAN_80211HDR_A3 Header;
64 unsigned char byCategory;
65 unsigned char byAction;
66 unsigned char byDialogToken;
67 WLAN_IE_MEASURE_REP sMSRRepEIDs[1];
68} WLAN_FRAME_MSRREP, *PWLAN_FRAME_MSRREP;
69
70typedef struct _WLAN_FRAME_TPCREQ {
71 WLAN_80211HDR_A3 Header;
72 unsigned char byCategory;
73 unsigned char byAction;
74 unsigned char byDialogToken;
75 WLAN_IE_TPC_REQ sTPCReqEIDs;
76} WLAN_FRAME_TPCREQ, *PWLAN_FRAME_TPCREQ;
77
78typedef struct _WLAN_FRAME_TPCREP {
79 WLAN_80211HDR_A3 Header;
80 unsigned char byCategory;
81 unsigned char byAction;
82 unsigned char byDialogToken;
83 WLAN_IE_TPC_REP sTPCRepEIDs;
84} WLAN_FRAME_TPCREP, *PWLAN_FRAME_TPCREP;
85
86#pragma pack()
87
88/* action field reference ieee 802.11h Table 20e */
89#define ACTION_MSRREQ 0
90#define ACTION_MSRREP 1
91#define ACTION_TPCREQ 2
92#define ACTION_TPCREP 3
93#define ACTION_CHSW 4
94
95/*--------------------- Static Classes ----------------------------*/
96
97/*--------------------- Static Variables --------------------------*/
98
99/*--------------------- Static Functions --------------------------*/
100
101/*--------------------- Export Variables --------------------------*/
102
103/*--------------------- Export Functions --------------------------*/
104
105bool IEEE11hbMSRRepTx(void *pMgmtHandle)
106{
107 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtHandle;
108 PWLAN_FRAME_MSRREP pMSRRep = (PWLAN_FRAME_MSRREP)
109 (pMgmt->abyCurrentMSRRep + sizeof(STxMgmtPacket));
110 size_t uLength = 0;
111 PSTxMgmtPacket pTxPacket = NULL;
112
113 pTxPacket = (PSTxMgmtPacket)pMgmt->abyCurrentMSRRep;
114 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_A3FR_MAXLEN);
115 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket +
116 sizeof(STxMgmtPacket));
117
118 pMSRRep->Header.wFrameCtl = (WLAN_SET_FC_FTYPE(WLAN_FTYPE_MGMT) |
119 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ACTION)
120);
121
122 memcpy(pMSRRep->Header.abyAddr1, ((PWLAN_FRAME_MSRREQ)
123 (pMgmt->abyCurrentMSRReq))->Header.abyAddr2, WLAN_ADDR_LEN);
124 memcpy(pMSRRep->Header.abyAddr2,
125 CARDpGetCurrentAddress(pMgmt->pAdapter), WLAN_ADDR_LEN);
126 memcpy(pMSRRep->Header.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
127
128 pMSRRep->byCategory = 0;
129 pMSRRep->byAction = 1;
130 pMSRRep->byDialogToken = ((PWLAN_FRAME_MSRREQ)
131 (pMgmt->abyCurrentMSRReq))->byDialogToken;
132
133 uLength = pMgmt->uLengthOfRepEIDs + offsetof(WLAN_FRAME_MSRREP,
134 sMSRRepEIDs);
135
136 pTxPacket->cbMPDULen = uLength;
137 pTxPacket->cbPayloadLen = uLength - WLAN_HDR_ADDR3_LEN;
138 if (csMgmt_xmit(pMgmt->pAdapter, pTxPacket) != CMD_STATUS_PENDING)
139 return false;
140 return true;
141}
diff --git a/drivers/staging/vt6655/IEEE11h.h b/drivers/staging/vt6655/IEEE11h.h
deleted file mode 100644
index 551922022b19..000000000000
--- a/drivers/staging/vt6655/IEEE11h.h
+++ /dev/null
@@ -1,42 +0,0 @@
1/*
2 * Copyright (c) 1996, 2005 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: IEEE11h.h
21 *
22 * Purpose: Defines the macros, types, and functions for dealing
23 * with IEEE 802.11h.
24 *
25 * Author: Yiching Chen
26 *
27 * Date: Mar. 31, 2005
28 *
29 */
30
31#ifndef __IEEE11h_H__
32#define __IEEE11h_H__
33
34#include "ttype.h"
35#include "80211hdr.h"
36#include "80211mgr.h"
37
38bool IEEE11hbMSRRepTx(
39 void *pMgmtHandle
40);
41
42#endif // __IEEE11h_H__
diff --git a/drivers/staging/vt6655/Kconfig b/drivers/staging/vt6655/Kconfig
index c3ba693a8cad..77cfc708c516 100644
--- a/drivers/staging/vt6655/Kconfig
+++ b/drivers/staging/vt6655/Kconfig
@@ -1,8 +1,6 @@
1config VT6655 1config VT6655
2 tristate "VIA Technologies VT6655 support" 2 tristate "VIA Technologies VT6655 support"
3 depends on PCI && WLAN && m 3 depends on PCI && MAC80211 && m
4 select WIRELESS_EXT
5 select WEXT_PRIV
6 ---help--- 4 ---help---
7 This is a vendor-written driver for VIA VT6655. 5 This is a vendor-written driver for VIA VT6655.
8 6
diff --git a/drivers/staging/vt6655/Makefile b/drivers/staging/vt6655/Makefile
index f7544a6cb63e..115b951bf0d9 100644
--- a/drivers/staging/vt6655/Makefile
+++ b/drivers/staging/vt6655/Makefile
@@ -7,33 +7,12 @@ vt6655_stage-y += device_main.o \
7 channel.o \ 7 channel.o \
8 mac.o \ 8 mac.o \
9 baseband.o \ 9 baseband.o \
10 wctl.o \
11 80211mgr.o \
12 wcmd.o \
13 wmgr.o \
14 bssdb.o \
15 rxtx.o \ 10 rxtx.o \
16 dpc.o \ 11 dpc.o \
17 power.o \ 12 power.o \
18 datarate.o \
19 srom.o \ 13 srom.o \
20 mib.o \ 14 mib.o \
21 rc4.o \
22 tether.o \
23 tcrc.o \
24 ioctl.o \
25 hostap.o \
26 wpa.o \
27 key.o \ 15 key.o \
28 tkip.o \ 16 rf.o
29 michael.o \
30 wroute.o \
31 rf.o \
32 iwctl.o \
33 wpactl.o \
34 wpa2.o \
35 aes_ccmp.o \
36 vntwifi.o \
37 IEEE11h.o
38 17
39obj-$(CONFIG_VT6655) += vt6655_stage.o 18obj-$(CONFIG_VT6655) += vt6655_stage.o
diff --git a/drivers/staging/vt6655/aes_ccmp.c b/drivers/staging/vt6655/aes_ccmp.c
deleted file mode 100644
index 1dfcfcb3c69c..000000000000
--- a/drivers/staging/vt6655/aes_ccmp.c
+++ /dev/null
@@ -1,374 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: aes_ccmp.c
21 *
22 * Purpose: AES_CCMP decryption
23 *
24 * Author: Warren Hsu
25 *
26 * Date: Feb 15, 2005
27 *
28 * Functions:
29 * AESbGenCCMP - Parsing RX-packet
30 *
31 *
32 * Revision History:
33 *
34 */
35
36#include "device.h"
37#include "80211hdr.h"
38#include "aes_ccmp.h"
39
40/*--------------------- Static Definitions -------------------------*/
41
42/*--------------------- Static Classes ----------------------------*/
43
44/*--------------------- Static Variables --------------------------*/
45
46/*
47 * SBOX Table
48 */
49
50static unsigned char sbox_table[256] = {
51 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
52 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
53 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
54 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
55 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
56 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
57 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
58 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
59 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
60 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
61 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
62 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
63 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
64 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
65 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
66 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
67};
68
69static unsigned char dot2_table[256] = {
70 0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e,
71 0x20, 0x22, 0x24, 0x26, 0x28, 0x2a, 0x2c, 0x2e, 0x30, 0x32, 0x34, 0x36, 0x38, 0x3a, 0x3c, 0x3e,
72 0x40, 0x42, 0x44, 0x46, 0x48, 0x4a, 0x4c, 0x4e, 0x50, 0x52, 0x54, 0x56, 0x58, 0x5a, 0x5c, 0x5e,
73 0x60, 0x62, 0x64, 0x66, 0x68, 0x6a, 0x6c, 0x6e, 0x70, 0x72, 0x74, 0x76, 0x78, 0x7a, 0x7c, 0x7e,
74 0x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8c, 0x8e, 0x90, 0x92, 0x94, 0x96, 0x98, 0x9a, 0x9c, 0x9e,
75 0xa0, 0xa2, 0xa4, 0xa6, 0xa8, 0xaa, 0xac, 0xae, 0xb0, 0xb2, 0xb4, 0xb6, 0xb8, 0xba, 0xbc, 0xbe,
76 0xc0, 0xc2, 0xc4, 0xc6, 0xc8, 0xca, 0xcc, 0xce, 0xd0, 0xd2, 0xd4, 0xd6, 0xd8, 0xda, 0xdc, 0xde,
77 0xe0, 0xe2, 0xe4, 0xe6, 0xe8, 0xea, 0xec, 0xee, 0xf0, 0xf2, 0xf4, 0xf6, 0xf8, 0xfa, 0xfc, 0xfe,
78 0x1b, 0x19, 0x1f, 0x1d, 0x13, 0x11, 0x17, 0x15, 0x0b, 0x09, 0x0f, 0x0d, 0x03, 0x01, 0x07, 0x05,
79 0x3b, 0x39, 0x3f, 0x3d, 0x33, 0x31, 0x37, 0x35, 0x2b, 0x29, 0x2f, 0x2d, 0x23, 0x21, 0x27, 0x25,
80 0x5b, 0x59, 0x5f, 0x5d, 0x53, 0x51, 0x57, 0x55, 0x4b, 0x49, 0x4f, 0x4d, 0x43, 0x41, 0x47, 0x45,
81 0x7b, 0x79, 0x7f, 0x7d, 0x73, 0x71, 0x77, 0x75, 0x6b, 0x69, 0x6f, 0x6d, 0x63, 0x61, 0x67, 0x65,
82 0x9b, 0x99, 0x9f, 0x9d, 0x93, 0x91, 0x97, 0x95, 0x8b, 0x89, 0x8f, 0x8d, 0x83, 0x81, 0x87, 0x85,
83 0xbb, 0xb9, 0xbf, 0xbd, 0xb3, 0xb1, 0xb7, 0xb5, 0xab, 0xa9, 0xaf, 0xad, 0xa3, 0xa1, 0xa7, 0xa5,
84 0xdb, 0xd9, 0xdf, 0xdd, 0xd3, 0xd1, 0xd7, 0xd5, 0xcb, 0xc9, 0xcf, 0xcd, 0xc3, 0xc1, 0xc7, 0xc5,
85 0xfb, 0xf9, 0xff, 0xfd, 0xf3, 0xf1, 0xf7, 0xf5, 0xeb, 0xe9, 0xef, 0xed, 0xe3, 0xe1, 0xe7, 0xe5
86};
87
88static unsigned char dot3_table[256] = {
89 0x00, 0x03, 0x06, 0x05, 0x0c, 0x0f, 0x0a, 0x09, 0x18, 0x1b, 0x1e, 0x1d, 0x14, 0x17, 0x12, 0x11,
90 0x30, 0x33, 0x36, 0x35, 0x3c, 0x3f, 0x3a, 0x39, 0x28, 0x2b, 0x2e, 0x2d, 0x24, 0x27, 0x22, 0x21,
91 0x60, 0x63, 0x66, 0x65, 0x6c, 0x6f, 0x6a, 0x69, 0x78, 0x7b, 0x7e, 0x7d, 0x74, 0x77, 0x72, 0x71,
92 0x50, 0x53, 0x56, 0x55, 0x5c, 0x5f, 0x5a, 0x59, 0x48, 0x4b, 0x4e, 0x4d, 0x44, 0x47, 0x42, 0x41,
93 0xc0, 0xc3, 0xc6, 0xc5, 0xcc, 0xcf, 0xca, 0xc9, 0xd8, 0xdb, 0xde, 0xdd, 0xd4, 0xd7, 0xd2, 0xd1,
94 0xf0, 0xf3, 0xf6, 0xf5, 0xfc, 0xff, 0xfa, 0xf9, 0xe8, 0xeb, 0xee, 0xed, 0xe4, 0xe7, 0xe2, 0xe1,
95 0xa0, 0xa3, 0xa6, 0xa5, 0xac, 0xaf, 0xaa, 0xa9, 0xb8, 0xbb, 0xbe, 0xbd, 0xb4, 0xb7, 0xb2, 0xb1,
96 0x90, 0x93, 0x96, 0x95, 0x9c, 0x9f, 0x9a, 0x99, 0x88, 0x8b, 0x8e, 0x8d, 0x84, 0x87, 0x82, 0x81,
97 0x9b, 0x98, 0x9d, 0x9e, 0x97, 0x94, 0x91, 0x92, 0x83, 0x80, 0x85, 0x86, 0x8f, 0x8c, 0x89, 0x8a,
98 0xab, 0xa8, 0xad, 0xae, 0xa7, 0xa4, 0xa1, 0xa2, 0xb3, 0xb0, 0xb5, 0xb6, 0xbf, 0xbc, 0xb9, 0xba,
99 0xfb, 0xf8, 0xfd, 0xfe, 0xf7, 0xf4, 0xf1, 0xf2, 0xe3, 0xe0, 0xe5, 0xe6, 0xef, 0xec, 0xe9, 0xea,
100 0xcb, 0xc8, 0xcd, 0xce, 0xc7, 0xc4, 0xc1, 0xc2, 0xd3, 0xd0, 0xd5, 0xd6, 0xdf, 0xdc, 0xd9, 0xda,
101 0x5b, 0x58, 0x5d, 0x5e, 0x57, 0x54, 0x51, 0x52, 0x43, 0x40, 0x45, 0x46, 0x4f, 0x4c, 0x49, 0x4a,
102 0x6b, 0x68, 0x6d, 0x6e, 0x67, 0x64, 0x61, 0x62, 0x73, 0x70, 0x75, 0x76, 0x7f, 0x7c, 0x79, 0x7a,
103 0x3b, 0x38, 0x3d, 0x3e, 0x37, 0x34, 0x31, 0x32, 0x23, 0x20, 0x25, 0x26, 0x2f, 0x2c, 0x29, 0x2a,
104 0x0b, 0x08, 0x0d, 0x0e, 0x07, 0x04, 0x01, 0x02, 0x13, 0x10, 0x15, 0x16, 0x1f, 0x1c, 0x19, 0x1a
105};
106
107/*--------------------- Static Functions --------------------------*/
108
109/*--------------------- Export Variables --------------------------*/
110
111/*--------------------- Export Functions --------------------------*/
112
113static void xor_128(unsigned char *a, unsigned char *b, unsigned char *out)
114{
115 unsigned long *dwPtrA = (unsigned long *)a;
116 unsigned long *dwPtrB = (unsigned long *)b;
117 unsigned long *dwPtrOut = (unsigned long *)out;
118
119 (*dwPtrOut++) = (*dwPtrA++) ^ (*dwPtrB++);
120 (*dwPtrOut++) = (*dwPtrA++) ^ (*dwPtrB++);
121 (*dwPtrOut++) = (*dwPtrA++) ^ (*dwPtrB++);
122 (*dwPtrOut++) = (*dwPtrA++) ^ (*dwPtrB++);
123}
124
125static void xor_32(unsigned char *a, unsigned char *b, unsigned char *out)
126{
127 unsigned long *dwPtrA = (unsigned long *)a;
128 unsigned long *dwPtrB = (unsigned long *)b;
129 unsigned long *dwPtrOut = (unsigned long *)out;
130
131 (*dwPtrOut++) = (*dwPtrA++) ^ (*dwPtrB++);
132}
133
134static void AddRoundKey(unsigned char *key, int round)
135{
136 unsigned char sbox_key[4];
137 unsigned char rcon_table[10] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36};
138
139 sbox_key[0] = sbox_table[key[13]];
140 sbox_key[1] = sbox_table[key[14]];
141 sbox_key[2] = sbox_table[key[15]];
142 sbox_key[3] = sbox_table[key[12]];
143
144 key[0] = key[0] ^ rcon_table[round];
145 xor_32(&key[0], sbox_key, &key[0]);
146
147 xor_32(&key[4], &key[0], &key[4]);
148 xor_32(&key[8], &key[4], &key[8]);
149 xor_32(&key[12], &key[8], &key[12]);
150}
151
152static void SubBytes(unsigned char *in, unsigned char *out)
153{
154 int i;
155
156 for (i = 0; i < 16; i++)
157 out[i] = sbox_table[in[i]];
158}
159
160static void ShiftRows(unsigned char *in, unsigned char *out)
161{
162 out[0] = in[0];
163 out[1] = in[5];
164 out[2] = in[10];
165 out[3] = in[15];
166 out[4] = in[4];
167 out[5] = in[9];
168 out[6] = in[14];
169 out[7] = in[3];
170 out[8] = in[8];
171 out[9] = in[13];
172 out[10] = in[2];
173 out[11] = in[7];
174 out[12] = in[12];
175 out[13] = in[1];
176 out[14] = in[6];
177 out[15] = in[11];
178}
179
180static void MixColumns(unsigned char *in, unsigned char *out)
181{
182 out[0] = dot2_table[in[0]] ^ dot3_table[in[1]] ^ in[2] ^ in[3];
183 out[1] = in[0] ^ dot2_table[in[1]] ^ dot3_table[in[2]] ^ in[3];
184 out[2] = in[0] ^ in[1] ^ dot2_table[in[2]] ^ dot3_table[in[3]];
185 out[3] = dot3_table[in[0]] ^ in[1] ^ in[2] ^ dot2_table[in[3]];
186}
187
188static void AESv128(unsigned char *key, unsigned char *data, unsigned char *ciphertext)
189{
190 int i;
191 int round;
192 unsigned char TmpdataA[16];
193 unsigned char TmpdataB[16];
194 unsigned char abyRoundKey[16];
195
196 for (i = 0; i < 16; i++)
197 abyRoundKey[i] = key[i];
198
199 for (round = 0; round < 11; round++) {
200 if (round == 0) {
201 xor_128(abyRoundKey, data, ciphertext);
202 AddRoundKey(abyRoundKey, round);
203 } else if (round == 10) {
204 SubBytes(ciphertext, TmpdataA);
205 ShiftRows(TmpdataA, TmpdataB);
206 xor_128(TmpdataB, abyRoundKey, ciphertext);
207 } else /* round 1 ~ 9 */{
208 SubBytes(ciphertext, TmpdataA);
209 ShiftRows(TmpdataA, TmpdataB);
210 MixColumns(&TmpdataB[0], &TmpdataA[0]);
211 MixColumns(&TmpdataB[4], &TmpdataA[4]);
212 MixColumns(&TmpdataB[8], &TmpdataA[8]);
213 MixColumns(&TmpdataB[12], &TmpdataA[12]);
214 xor_128(TmpdataA, abyRoundKey, ciphertext);
215 AddRoundKey(abyRoundKey, round);
216 }
217 }
218}
219
220/*
221 * Description: AES decryption
222 *
223 * Parameters:
224 * In:
225 * pbyRxKey - The key used to decrypt
226 * pbyFrame - Starting address of packet header
227 * wFrameSize - Total packet size including CRC
228 * Out:
229 * none
230 *
231 * Return Value: MIC compare result
232 *
233 */
234bool AESbGenCCMP(unsigned char *pbyRxKey, unsigned char *pbyFrame, unsigned short wFrameSize)
235{
236 unsigned char abyNonce[13];
237 unsigned char MIC_IV[16];
238 unsigned char MIC_HDR1[16];
239 unsigned char MIC_HDR2[16];
240 unsigned char abyMIC[16];
241 unsigned char abyCTRPLD[16];
242 unsigned char abyTmp[16];
243 unsigned char abyPlainText[16];
244 unsigned char abyLastCipher[16];
245
246 PS802_11Header pMACHeader = (PS802_11Header) pbyFrame;
247 unsigned char *pbyIV;
248 unsigned char *pbyPayload;
249 unsigned short wHLen = 22;
250 unsigned short wPayloadSize = wFrameSize - 8 - 8 - 4 - WLAN_HDR_ADDR3_LEN;/* 8 is IV, 8 is MIC, 4 is CRC */
251 bool bA4 = false;
252 unsigned char byTmp;
253 unsigned short wCnt;
254 int ii, jj, kk;
255
256 pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN;
257 if (WLAN_GET_FC_TODS(*(unsigned short *)pbyFrame) &&
258 WLAN_GET_FC_FROMDS(*(unsigned short *)pbyFrame)) {
259 bA4 = true;
260 pbyIV += 6; /* 6 is 802.11 address4 */
261 wHLen += 6;
262 wPayloadSize -= 6;
263 }
264 pbyPayload = pbyIV + 8; /* IV-length */
265
266 abyNonce[0] = 0x00; /* now is 0, if Qos here will be priority */
267 memcpy(&(abyNonce[1]), pMACHeader->abyAddr2, ETH_ALEN);
268 abyNonce[7] = pbyIV[7];
269 abyNonce[8] = pbyIV[6];
270 abyNonce[9] = pbyIV[5];
271 abyNonce[10] = pbyIV[4];
272 abyNonce[11] = pbyIV[1];
273 abyNonce[12] = pbyIV[0];
274
275 /* MIC_IV */
276 MIC_IV[0] = 0x59;
277 memcpy(&(MIC_IV[1]), &(abyNonce[0]), 13);
278 MIC_IV[14] = (unsigned char)(wPayloadSize >> 8);
279 MIC_IV[15] = (unsigned char)(wPayloadSize & 0xff);
280
281 /* MIC_HDR1 */
282 MIC_HDR1[0] = (unsigned char)(wHLen >> 8);
283 MIC_HDR1[1] = (unsigned char)(wHLen & 0xff);
284 byTmp = (unsigned char)(pMACHeader->wFrameCtl & 0xff);
285 MIC_HDR1[2] = byTmp & 0x8f;
286 byTmp = (unsigned char)(pMACHeader->wFrameCtl >> 8);
287 byTmp &= 0x87;
288 MIC_HDR1[3] = byTmp | 0x40;
289 memcpy(&(MIC_HDR1[4]), pMACHeader->abyAddr1, ETH_ALEN);
290 memcpy(&(MIC_HDR1[10]), pMACHeader->abyAddr2, ETH_ALEN);
291
292 /* MIC_HDR2 */
293 memcpy(&(MIC_HDR2[0]), pMACHeader->abyAddr3, ETH_ALEN);
294 byTmp = (unsigned char)(pMACHeader->wSeqCtl & 0xff);
295 MIC_HDR2[6] = byTmp & 0x0f;
296 MIC_HDR2[7] = 0;
297 if (bA4) {
298 memcpy(&(MIC_HDR2[8]), pMACHeader->abyAddr4, ETH_ALEN);
299 } else {
300 MIC_HDR2[8] = 0x00;
301 MIC_HDR2[9] = 0x00;
302 MIC_HDR2[10] = 0x00;
303 MIC_HDR2[11] = 0x00;
304 MIC_HDR2[12] = 0x00;
305 MIC_HDR2[13] = 0x00;
306 }
307 MIC_HDR2[14] = 0x00;
308 MIC_HDR2[15] = 0x00;
309
310 /* CCMP */
311 AESv128(pbyRxKey, MIC_IV, abyMIC);
312 for (kk = 0; kk < 16; kk++)
313 abyTmp[kk] = MIC_HDR1[kk] ^ abyMIC[kk];
314 AESv128(pbyRxKey, abyTmp, abyMIC);
315 for (kk = 0; kk < 16; kk++)
316 abyTmp[kk] = MIC_HDR2[kk] ^ abyMIC[kk];
317 AESv128(pbyRxKey, abyTmp, abyMIC);
318
319 wCnt = 1;
320 abyCTRPLD[0] = 0x01;
321 memcpy(&(abyCTRPLD[1]), &(abyNonce[0]), 13);
322
323 for (jj = wPayloadSize; jj > 16; jj = jj - 16) {
324 abyCTRPLD[14] = (unsigned char)(wCnt >> 8);
325 abyCTRPLD[15] = (unsigned char)(wCnt & 0xff);
326
327 AESv128(pbyRxKey, abyCTRPLD, abyTmp);
328
329 for (kk = 0; kk < 16; kk++)
330 abyPlainText[kk] = abyTmp[kk] ^ pbyPayload[kk];
331 for (kk = 0; kk < 16; kk++)
332 abyTmp[kk] = abyMIC[kk] ^ abyPlainText[kk];
333 AESv128(pbyRxKey, abyTmp, abyMIC);
334
335 memcpy(pbyPayload, abyPlainText, 16);
336 wCnt++;
337 pbyPayload += 16;
338 } /* for wPayloadSize */
339
340 /* last payload */
341 memcpy(&(abyLastCipher[0]), pbyPayload, jj);
342 for (ii = jj; ii < 16; ii++)
343 abyLastCipher[ii] = 0x00;
344
345 abyCTRPLD[14] = (unsigned char)(wCnt >> 8);
346 abyCTRPLD[15] = (unsigned char)(wCnt & 0xff);
347
348 AESv128(pbyRxKey, abyCTRPLD, abyTmp);
349 for (kk = 0; kk < 16; kk++)
350 abyPlainText[kk] = abyTmp[kk] ^ abyLastCipher[kk];
351 memcpy(pbyPayload, abyPlainText, jj);
352 pbyPayload += jj;
353
354 /* for MIC calculation */
355 for (ii = jj; ii < 16; ii++)
356 abyPlainText[ii] = 0x00;
357 for (kk = 0; kk < 16; kk++)
358 abyTmp[kk] = abyMIC[kk] ^ abyPlainText[kk];
359 AESv128(pbyRxKey, abyTmp, abyMIC);
360
361 /* =>above is the calculate MIC */
362 /* -------------------------------------------- */
363
364 wCnt = 0;
365 abyCTRPLD[14] = (unsigned char)(wCnt >> 8);
366 abyCTRPLD[15] = (unsigned char)(wCnt & 0xff);
367 AESv128(pbyRxKey, abyCTRPLD, abyTmp);
368 for (kk = 0; kk < 8; kk++)
369 abyTmp[kk] = abyTmp[kk] ^ pbyPayload[kk];
370 /* =>above is the dec-MIC from packet */
371 /* -------------------------------------------- */
372
373 return !memcmp(abyMIC, abyTmp, 8);
374}
diff --git a/drivers/staging/vt6655/aes_ccmp.h b/drivers/staging/vt6655/aes_ccmp.h
deleted file mode 100644
index fe0c506205d5..000000000000
--- a/drivers/staging/vt6655/aes_ccmp.h
+++ /dev/null
@@ -1,37 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: aes_ccmp.h
21 *
22 * Purpose: AES_CCMP Decryption
23 *
24 * Author: Warren Hsu
25 *
26 * Date: Feb 15, 2005
27 *
28 */
29
30#ifndef __AES_H__
31#define __AES_H__
32
33#include "ttype.h"
34
35bool AESbGenCCMP(unsigned char *pbyRxKey, unsigned char *pbyFrame, unsigned short wFrameSize);
36
37#endif /* __AES_H__ */
diff --git a/drivers/staging/vt6655/baseband.c b/drivers/staging/vt6655/baseband.c
index de54923e8861..86c72ba0a0cd 100644
--- a/drivers/staging/vt6655/baseband.c
+++ b/drivers/staging/vt6655/baseband.c
@@ -30,12 +30,7 @@
30 * BBvCaculateParameter - Caculate PhyLength, PhyService and Phy Signal parameter for baseband Tx 30 * BBvCaculateParameter - Caculate PhyLength, PhyService and Phy Signal parameter for baseband Tx
31 * BBbReadEmbedded - Embedded read baseband register via MAC 31 * BBbReadEmbedded - Embedded read baseband register via MAC
32 * BBbWriteEmbedded - Embedded write baseband register via MAC 32 * BBbWriteEmbedded - Embedded write baseband register via MAC
33 * BBbIsRegBitsOn - Test if baseband register bits on
34 * BBbIsRegBitsOff - Test if baseband register bits off
35 * BBbVT3253Init - VIA VT3253 baseband chip init code 33 * BBbVT3253Init - VIA VT3253 baseband chip init code
36 * BBvReadAllRegs - Read All Baseband Registers
37 * BBvLoopbackOn - Turn on BaseBand Loopback mode
38 * BBvLoopbackOff - Turn off BaseBand Loopback mode
39 * 34 *
40 * Revision History: 35 * Revision History:
41 * 06-10-2003 Bryan YC Fan: Re-write codes to support VT3253 spec. 36 * 06-10-2003 Bryan YC Fan: Re-write codes to support VT3253 spec.
@@ -50,7 +45,6 @@
50 */ 45 */
51 46
52#include "tmacro.h" 47#include "tmacro.h"
53#include "tether.h"
54#include "mac.h" 48#include "mac.h"
55#include "baseband.h" 49#include "baseband.h"
56#include "srom.h" 50#include "srom.h"
@@ -1708,39 +1702,39 @@ static const unsigned short awcFrameTime[MAX_RATE] = {
1708 1702
1709static 1703static
1710unsigned long 1704unsigned long
1711s_ulGetRatio(struct vnt_private *pDevice); 1705s_ulGetRatio(struct vnt_private *priv);
1712 1706
1713static 1707static
1714void 1708void
1715s_vChangeAntenna( 1709s_vChangeAntenna(
1716 struct vnt_private *pDevice 1710 struct vnt_private *priv
1717); 1711);
1718 1712
1719static 1713static
1720void 1714void
1721s_vChangeAntenna( 1715s_vChangeAntenna(
1722 struct vnt_private *pDevice 1716 struct vnt_private *priv
1723) 1717)
1724{ 1718{
1725 if (pDevice->dwRxAntennaSel == 0) { 1719 if (priv->dwRxAntennaSel == 0) {
1726 pDevice->dwRxAntennaSel = 1; 1720 priv->dwRxAntennaSel = 1;
1727 if (pDevice->bTxRxAntInv == true) 1721 if (priv->bTxRxAntInv == true)
1728 BBvSetRxAntennaMode(pDevice->PortOffset, ANT_A); 1722 BBvSetRxAntennaMode(priv, ANT_A);
1729 else 1723 else
1730 BBvSetRxAntennaMode(pDevice->PortOffset, ANT_B); 1724 BBvSetRxAntennaMode(priv, ANT_B);
1731 } else { 1725 } else {
1732 pDevice->dwRxAntennaSel = 0; 1726 priv->dwRxAntennaSel = 0;
1733 if (pDevice->bTxRxAntInv == true) 1727 if (priv->bTxRxAntInv == true)
1734 BBvSetRxAntennaMode(pDevice->PortOffset, ANT_B); 1728 BBvSetRxAntennaMode(priv, ANT_B);
1735 else 1729 else
1736 BBvSetRxAntennaMode(pDevice->PortOffset, ANT_A); 1730 BBvSetRxAntennaMode(priv, ANT_A);
1737 } 1731 }
1738 if (pDevice->dwTxAntennaSel == 0) { 1732 if (priv->dwTxAntennaSel == 0) {
1739 pDevice->dwTxAntennaSel = 1; 1733 priv->dwTxAntennaSel = 1;
1740 BBvSetTxAntennaMode(pDevice->PortOffset, ANT_B); 1734 BBvSetTxAntennaMode(priv, ANT_B);
1741 } else { 1735 } else {
1742 pDevice->dwTxAntennaSel = 0; 1736 priv->dwTxAntennaSel = 0;
1743 BBvSetTxAntennaMode(pDevice->PortOffset, ANT_A); 1737 BBvSetTxAntennaMode(priv, ANT_A);
1744 } 1738 }
1745} 1739}
1746 1740
@@ -1792,18 +1786,17 @@ BBuGetFrameTime(
1792 uFrameTime++; 1786 uFrameTime++;
1793 1787
1794 return uPreamble + uFrameTime; 1788 return uPreamble + uFrameTime;
1795 } else { 1789 }
1796 uFrameTime = (cbFrameLength * 8 + 22) / uRate; /* ???????? */ 1790 uFrameTime = (cbFrameLength * 8 + 22) / uRate; /* ???????? */
1797 uTmp = ((uFrameTime * uRate) - 22) / 8; 1791 uTmp = ((uFrameTime * uRate) - 22) / 8;
1798 if (cbFrameLength != uTmp) 1792 if (cbFrameLength != uTmp)
1799 uFrameTime++; 1793 uFrameTime++;
1800 1794
1801 uFrameTime = uFrameTime * 4; /* ??????? */ 1795 uFrameTime = uFrameTime * 4; /* ??????? */
1802 if (byPktType != PK_TYPE_11A) 1796 if (byPktType != PK_TYPE_11A)
1803 uFrameTime += 6; /* ?????? */ 1797 uFrameTime += 6; /* ?????? */
1804 1798
1805 return 20 + uFrameTime; /* ?????? */ 1799 return 20 + uFrameTime; /* ?????? */
1806 }
1807} 1800}
1808 1801
1809/* 1802/*
@@ -1968,8 +1961,10 @@ void vnt_get_phy_field(struct vnt_private *priv, u32 frame_length,
1968 * Return Value: true if succeeded; false if failed. 1961 * Return Value: true if succeeded; false if failed.
1969 * 1962 *
1970 */ 1963 */
1971bool BBbReadEmbedded(void __iomem *dwIoBase, unsigned char byBBAddr, unsigned char *pbyData) 1964bool BBbReadEmbedded(struct vnt_private *priv,
1965 unsigned char byBBAddr, unsigned char *pbyData)
1972{ 1966{
1967 void __iomem *dwIoBase = priv->PortOffset;
1973 unsigned short ww; 1968 unsigned short ww;
1974 unsigned char byValue; 1969 unsigned char byValue;
1975 1970
@@ -2010,8 +2005,10 @@ bool BBbReadEmbedded(void __iomem *dwIoBase, unsigned char byBBAddr, unsigned ch
2010 * Return Value: true if succeeded; false if failed. 2005 * Return Value: true if succeeded; false if failed.
2011 * 2006 *
2012 */ 2007 */
2013bool BBbWriteEmbedded(void __iomem *dwIoBase, unsigned char byBBAddr, unsigned char byData) 2008bool BBbWriteEmbedded(struct vnt_private *priv,
2009 unsigned char byBBAddr, unsigned char byData)
2014{ 2010{
2011 void __iomem *dwIoBase = priv->PortOffset;
2015 unsigned short ww; 2012 unsigned short ww;
2016 unsigned char byValue; 2013 unsigned char byValue;
2017 2014
@@ -2038,50 +2035,6 @@ bool BBbWriteEmbedded(void __iomem *dwIoBase, unsigned char byBBAddr, unsigned c
2038} 2035}
2039 2036
2040/* 2037/*
2041 * Description: Test if all bits are set for the Baseband register
2042 *
2043 * Parameters:
2044 * In:
2045 * dwIoBase - I/O base address
2046 * byBBAddr - address of register in Baseband
2047 * byTestBits - TestBits
2048 * Out:
2049 * none
2050 *
2051 * Return Value: true if all TestBits are set; false otherwise.
2052 *
2053 */
2054bool BBbIsRegBitsOn(void __iomem *dwIoBase, unsigned char byBBAddr, unsigned char byTestBits)
2055{
2056 unsigned char byOrgData;
2057
2058 BBbReadEmbedded(dwIoBase, byBBAddr, &byOrgData);
2059 return (byOrgData & byTestBits) == byTestBits;
2060}
2061
2062/*
2063 * Description: Test if all bits are clear for the Baseband register
2064 *
2065 * Parameters:
2066 * In:
2067 * dwIoBase - I/O base address
2068 * byBBAddr - address of register in Baseband
2069 * byTestBits - TestBits
2070 * Out:
2071 * none
2072 *
2073 * Return Value: true if all TestBits are clear; false otherwise.
2074 *
2075 */
2076bool BBbIsRegBitsOff(void __iomem *dwIoBase, unsigned char byBBAddr, unsigned char byTestBits)
2077{
2078 unsigned char byOrgData;
2079
2080 BBbReadEmbedded(dwIoBase, byBBAddr, &byOrgData);
2081 return (byOrgData & byTestBits) == 0;
2082}
2083
2084/*
2085 * Description: VIA VT3253 Baseband chip init function 2038 * Description: VIA VT3253 Baseband chip init function
2086 * 2039 *
2087 * Parameters: 2040 * Parameters:
@@ -2096,126 +2049,126 @@ bool BBbIsRegBitsOff(void __iomem *dwIoBase, unsigned char byBBAddr, unsigned ch
2096 * 2049 *
2097 */ 2050 */
2098 2051
2099bool BBbVT3253Init(struct vnt_private *pDevice) 2052bool BBbVT3253Init(struct vnt_private *priv)
2100{ 2053{
2101 bool bResult = true; 2054 bool bResult = true;
2102 int ii; 2055 int ii;
2103 void __iomem *dwIoBase = pDevice->PortOffset; 2056 void __iomem *dwIoBase = priv->PortOffset;
2104 unsigned char byRFType = pDevice->byRFType; 2057 unsigned char byRFType = priv->byRFType;
2105 unsigned char byLocalID = pDevice->byLocalID; 2058 unsigned char byLocalID = priv->byLocalID;
2106 2059
2107 if (byRFType == RF_RFMD2959) { 2060 if (byRFType == RF_RFMD2959) {
2108 if (byLocalID <= REV_ID_VT3253_A1) { 2061 if (byLocalID <= REV_ID_VT3253_A1) {
2109 for (ii = 0; ii < CB_VT3253_INIT_FOR_RFMD; ii++) 2062 for (ii = 0; ii < CB_VT3253_INIT_FOR_RFMD; ii++)
2110 bResult &= BBbWriteEmbedded(dwIoBase, byVT3253InitTab_RFMD[ii][0], byVT3253InitTab_RFMD[ii][1]); 2063 bResult &= BBbWriteEmbedded(priv, byVT3253InitTab_RFMD[ii][0], byVT3253InitTab_RFMD[ii][1]);
2111 2064
2112 } else { 2065 } else {
2113 for (ii = 0; ii < CB_VT3253B0_INIT_FOR_RFMD; ii++) 2066 for (ii = 0; ii < CB_VT3253B0_INIT_FOR_RFMD; ii++)
2114 bResult &= BBbWriteEmbedded(dwIoBase, byVT3253B0_RFMD[ii][0], byVT3253B0_RFMD[ii][1]); 2067 bResult &= BBbWriteEmbedded(priv, byVT3253B0_RFMD[ii][0], byVT3253B0_RFMD[ii][1]);
2115 2068
2116 for (ii = 0; ii < CB_VT3253B0_AGC_FOR_RFMD2959; ii++) 2069 for (ii = 0; ii < CB_VT3253B0_AGC_FOR_RFMD2959; ii++)
2117 bResult &= BBbWriteEmbedded(dwIoBase, byVT3253B0_AGC4_RFMD2959[ii][0], byVT3253B0_AGC4_RFMD2959[ii][1]); 2070 bResult &= BBbWriteEmbedded(priv, byVT3253B0_AGC4_RFMD2959[ii][0], byVT3253B0_AGC4_RFMD2959[ii][1]);
2118 2071
2119 VNSvOutPortD(dwIoBase + MAC_REG_ITRTMSET, 0x23); 2072 VNSvOutPortD(dwIoBase + MAC_REG_ITRTMSET, 0x23);
2120 MACvRegBitsOn(dwIoBase, MAC_REG_PAPEDELAY, BIT0); 2073 MACvRegBitsOn(dwIoBase, MAC_REG_PAPEDELAY, BIT(0));
2121 } 2074 }
2122 pDevice->abyBBVGA[0] = 0x18; 2075 priv->abyBBVGA[0] = 0x18;
2123 pDevice->abyBBVGA[1] = 0x0A; 2076 priv->abyBBVGA[1] = 0x0A;
2124 pDevice->abyBBVGA[2] = 0x0; 2077 priv->abyBBVGA[2] = 0x0;
2125 pDevice->abyBBVGA[3] = 0x0; 2078 priv->abyBBVGA[3] = 0x0;
2126 pDevice->ldBmThreshold[0] = -70; 2079 priv->ldBmThreshold[0] = -70;
2127 pDevice->ldBmThreshold[1] = -50; 2080 priv->ldBmThreshold[1] = -50;
2128 pDevice->ldBmThreshold[2] = 0; 2081 priv->ldBmThreshold[2] = 0;
2129 pDevice->ldBmThreshold[3] = 0; 2082 priv->ldBmThreshold[3] = 0;
2130 } else if ((byRFType == RF_AIROHA) || (byRFType == RF_AL2230S)) { 2083 } else if ((byRFType == RF_AIROHA) || (byRFType == RF_AL2230S)) {
2131 for (ii = 0; ii < CB_VT3253B0_INIT_FOR_AIROHA2230; ii++) 2084 for (ii = 0; ii < CB_VT3253B0_INIT_FOR_AIROHA2230; ii++)
2132 bResult &= BBbWriteEmbedded(dwIoBase, byVT3253B0_AIROHA2230[ii][0], byVT3253B0_AIROHA2230[ii][1]); 2085 bResult &= BBbWriteEmbedded(priv, byVT3253B0_AIROHA2230[ii][0], byVT3253B0_AIROHA2230[ii][1]);
2133 2086
2134 for (ii = 0; ii < CB_VT3253B0_AGC; ii++) 2087 for (ii = 0; ii < CB_VT3253B0_AGC; ii++)
2135 bResult &= BBbWriteEmbedded(dwIoBase, byVT3253B0_AGC[ii][0], byVT3253B0_AGC[ii][1]); 2088 bResult &= BBbWriteEmbedded(priv, byVT3253B0_AGC[ii][0], byVT3253B0_AGC[ii][1]);
2136 2089
2137 pDevice->abyBBVGA[0] = 0x1C; 2090 priv->abyBBVGA[0] = 0x1C;
2138 pDevice->abyBBVGA[1] = 0x10; 2091 priv->abyBBVGA[1] = 0x10;
2139 pDevice->abyBBVGA[2] = 0x0; 2092 priv->abyBBVGA[2] = 0x0;
2140 pDevice->abyBBVGA[3] = 0x0; 2093 priv->abyBBVGA[3] = 0x0;
2141 pDevice->ldBmThreshold[0] = -70; 2094 priv->ldBmThreshold[0] = -70;
2142 pDevice->ldBmThreshold[1] = -48; 2095 priv->ldBmThreshold[1] = -48;
2143 pDevice->ldBmThreshold[2] = 0; 2096 priv->ldBmThreshold[2] = 0;
2144 pDevice->ldBmThreshold[3] = 0; 2097 priv->ldBmThreshold[3] = 0;
2145 } else if (byRFType == RF_UW2451) { 2098 } else if (byRFType == RF_UW2451) {
2146 for (ii = 0; ii < CB_VT3253B0_INIT_FOR_UW2451; ii++) 2099 for (ii = 0; ii < CB_VT3253B0_INIT_FOR_UW2451; ii++)
2147 bResult &= BBbWriteEmbedded(dwIoBase, byVT3253B0_UW2451[ii][0], byVT3253B0_UW2451[ii][1]); 2100 bResult &= BBbWriteEmbedded(priv, byVT3253B0_UW2451[ii][0], byVT3253B0_UW2451[ii][1]);
2148 2101
2149 for (ii = 0; ii < CB_VT3253B0_AGC; ii++) 2102 for (ii = 0; ii < CB_VT3253B0_AGC; ii++)
2150 bResult &= BBbWriteEmbedded(dwIoBase, byVT3253B0_AGC[ii][0], byVT3253B0_AGC[ii][1]); 2103 bResult &= BBbWriteEmbedded(priv, byVT3253B0_AGC[ii][0], byVT3253B0_AGC[ii][1]);
2151 2104
2152 VNSvOutPortB(dwIoBase + MAC_REG_ITRTMSET, 0x23); 2105 VNSvOutPortB(dwIoBase + MAC_REG_ITRTMSET, 0x23);
2153 MACvRegBitsOn(dwIoBase, MAC_REG_PAPEDELAY, BIT0); 2106 MACvRegBitsOn(dwIoBase, MAC_REG_PAPEDELAY, BIT(0));
2154 2107
2155 pDevice->abyBBVGA[0] = 0x14; 2108 priv->abyBBVGA[0] = 0x14;
2156 pDevice->abyBBVGA[1] = 0x0A; 2109 priv->abyBBVGA[1] = 0x0A;
2157 pDevice->abyBBVGA[2] = 0x0; 2110 priv->abyBBVGA[2] = 0x0;
2158 pDevice->abyBBVGA[3] = 0x0; 2111 priv->abyBBVGA[3] = 0x0;
2159 pDevice->ldBmThreshold[0] = -60; 2112 priv->ldBmThreshold[0] = -60;
2160 pDevice->ldBmThreshold[1] = -50; 2113 priv->ldBmThreshold[1] = -50;
2161 pDevice->ldBmThreshold[2] = 0; 2114 priv->ldBmThreshold[2] = 0;
2162 pDevice->ldBmThreshold[3] = 0; 2115 priv->ldBmThreshold[3] = 0;
2163 } else if (byRFType == RF_UW2452) { 2116 } else if (byRFType == RF_UW2452) {
2164 for (ii = 0; ii < CB_VT3253B0_INIT_FOR_UW2451; ii++) 2117 for (ii = 0; ii < CB_VT3253B0_INIT_FOR_UW2451; ii++)
2165 bResult &= BBbWriteEmbedded(dwIoBase, byVT3253B0_UW2451[ii][0], byVT3253B0_UW2451[ii][1]); 2118 bResult &= BBbWriteEmbedded(priv, byVT3253B0_UW2451[ii][0], byVT3253B0_UW2451[ii][1]);
2166 2119
2167 /* Init ANT B select,TX Config CR09 = 0x61->0x45, 0x45->0x41(VC1/VC2 define, make the ANT_A, ANT_B inverted) */ 2120 /* Init ANT B select,TX Config CR09 = 0x61->0x45, 0x45->0x41(VC1/VC2 define, make the ANT_A, ANT_B inverted) */
2168 /*bResult &= BBbWriteEmbedded(dwIoBase,0x09,0x41);*/ 2121 /*bResult &= BBbWriteEmbedded(dwIoBase,0x09,0x41);*/
2169 /* Init ANT B select,RX Config CR10 = 0x28->0x2A, 0x2A->0x28(VC1/VC2 define, make the ANT_A, ANT_B inverted) */ 2122 /* Init ANT B select,RX Config CR10 = 0x28->0x2A, 0x2A->0x28(VC1/VC2 define, make the ANT_A, ANT_B inverted) */
2170 /*bResult &= BBbWriteEmbedded(dwIoBase,0x0a,0x28);*/ 2123 /*bResult &= BBbWriteEmbedded(dwIoBase,0x0a,0x28);*/
2171 /* Select VC1/VC2, CR215 = 0x02->0x06 */ 2124 /* Select VC1/VC2, CR215 = 0x02->0x06 */
2172 bResult &= BBbWriteEmbedded(dwIoBase, 0xd7, 0x06); 2125 bResult &= BBbWriteEmbedded(priv, 0xd7, 0x06);
2173 2126
2174 /* {{RobertYu:20050125, request by Jack */ 2127 /* {{RobertYu:20050125, request by Jack */
2175 bResult &= BBbWriteEmbedded(dwIoBase, 0x90, 0x20); 2128 bResult &= BBbWriteEmbedded(priv, 0x90, 0x20);
2176 bResult &= BBbWriteEmbedded(dwIoBase, 0x97, 0xeb); 2129 bResult &= BBbWriteEmbedded(priv, 0x97, 0xeb);
2177 /* }} */ 2130 /* }} */
2178 2131
2179 /* {{RobertYu:20050221, request by Jack */ 2132 /* {{RobertYu:20050221, request by Jack */
2180 bResult &= BBbWriteEmbedded(dwIoBase, 0xa6, 0x00); 2133 bResult &= BBbWriteEmbedded(priv, 0xa6, 0x00);
2181 bResult &= BBbWriteEmbedded(dwIoBase, 0xa8, 0x30); 2134 bResult &= BBbWriteEmbedded(priv, 0xa8, 0x30);
2182 /* }} */ 2135 /* }} */
2183 bResult &= BBbWriteEmbedded(dwIoBase, 0xb0, 0x58); 2136 bResult &= BBbWriteEmbedded(priv, 0xb0, 0x58);
2184 2137
2185 for (ii = 0; ii < CB_VT3253B0_AGC; ii++) 2138 for (ii = 0; ii < CB_VT3253B0_AGC; ii++)
2186 bResult &= BBbWriteEmbedded(dwIoBase, byVT3253B0_AGC[ii][0], byVT3253B0_AGC[ii][1]); 2139 bResult &= BBbWriteEmbedded(priv, byVT3253B0_AGC[ii][0], byVT3253B0_AGC[ii][1]);
2187 2140
2188 pDevice->abyBBVGA[0] = 0x14; 2141 priv->abyBBVGA[0] = 0x14;
2189 pDevice->abyBBVGA[1] = 0x0A; 2142 priv->abyBBVGA[1] = 0x0A;
2190 pDevice->abyBBVGA[2] = 0x0; 2143 priv->abyBBVGA[2] = 0x0;
2191 pDevice->abyBBVGA[3] = 0x0; 2144 priv->abyBBVGA[3] = 0x0;
2192 pDevice->ldBmThreshold[0] = -60; 2145 priv->ldBmThreshold[0] = -60;
2193 pDevice->ldBmThreshold[1] = -50; 2146 priv->ldBmThreshold[1] = -50;
2194 pDevice->ldBmThreshold[2] = 0; 2147 priv->ldBmThreshold[2] = 0;
2195 pDevice->ldBmThreshold[3] = 0; 2148 priv->ldBmThreshold[3] = 0;
2196 /* }} RobertYu */ 2149 /* }} RobertYu */
2197 2150
2198 } else if (byRFType == RF_VT3226) { 2151 } else if (byRFType == RF_VT3226) {
2199 for (ii = 0; ii < CB_VT3253B0_INIT_FOR_AIROHA2230; ii++) 2152 for (ii = 0; ii < CB_VT3253B0_INIT_FOR_AIROHA2230; ii++)
2200 bResult &= BBbWriteEmbedded(dwIoBase, byVT3253B0_AIROHA2230[ii][0], byVT3253B0_AIROHA2230[ii][1]); 2153 bResult &= BBbWriteEmbedded(priv, byVT3253B0_AIROHA2230[ii][0], byVT3253B0_AIROHA2230[ii][1]);
2201 2154
2202 for (ii = 0; ii < CB_VT3253B0_AGC; ii++) 2155 for (ii = 0; ii < CB_VT3253B0_AGC; ii++)
2203 bResult &= BBbWriteEmbedded(dwIoBase, byVT3253B0_AGC[ii][0], byVT3253B0_AGC[ii][1]); 2156 bResult &= BBbWriteEmbedded(priv, byVT3253B0_AGC[ii][0], byVT3253B0_AGC[ii][1]);
2204 2157
2205 pDevice->abyBBVGA[0] = 0x1C; 2158 priv->abyBBVGA[0] = 0x1C;
2206 pDevice->abyBBVGA[1] = 0x10; 2159 priv->abyBBVGA[1] = 0x10;
2207 pDevice->abyBBVGA[2] = 0x0; 2160 priv->abyBBVGA[2] = 0x0;
2208 pDevice->abyBBVGA[3] = 0x0; 2161 priv->abyBBVGA[3] = 0x0;
2209 pDevice->ldBmThreshold[0] = -70; 2162 priv->ldBmThreshold[0] = -70;
2210 pDevice->ldBmThreshold[1] = -48; 2163 priv->ldBmThreshold[1] = -48;
2211 pDevice->ldBmThreshold[2] = 0; 2164 priv->ldBmThreshold[2] = 0;
2212 pDevice->ldBmThreshold[3] = 0; 2165 priv->ldBmThreshold[3] = 0;
2213 /* Fix VT3226 DFC system timing issue */ 2166 /* Fix VT3226 DFC system timing issue */
2214 MACvSetRFLE_LatchBase(dwIoBase); 2167 MACvSetRFLE_LatchBase(dwIoBase);
2215 /* {{ RobertYu: 20050104 */ 2168 /* {{ RobertYu: 20050104 */
2216 } else if (byRFType == RF_AIROHA7230) { 2169 } else if (byRFType == RF_AIROHA7230) {
2217 for (ii = 0; ii < CB_VT3253B0_INIT_FOR_AIROHA2230; ii++) 2170 for (ii = 0; ii < CB_VT3253B0_INIT_FOR_AIROHA2230; ii++)
2218 bResult &= BBbWriteEmbedded(dwIoBase, byVT3253B0_AIROHA2230[ii][0], byVT3253B0_AIROHA2230[ii][1]); 2171 bResult &= BBbWriteEmbedded(priv, byVT3253B0_AIROHA2230[ii][0], byVT3253B0_AIROHA2230[ii][1]);
2219 2172
2220 2173
2221 /* {{ RobertYu:20050223, request by JerryChung */ 2174 /* {{ RobertYu:20050223, request by JerryChung */
@@ -2228,150 +2181,37 @@ bool BBbVT3253Init(struct vnt_private *pDevice)
2228 /* }} */ 2181 /* }} */
2229 2182
2230 for (ii = 0; ii < CB_VT3253B0_AGC; ii++) 2183 for (ii = 0; ii < CB_VT3253B0_AGC; ii++)
2231 bResult &= BBbWriteEmbedded(dwIoBase, byVT3253B0_AGC[ii][0], byVT3253B0_AGC[ii][1]); 2184 bResult &= BBbWriteEmbedded(priv, byVT3253B0_AGC[ii][0], byVT3253B0_AGC[ii][1]);
2232 2185
2233 pDevice->abyBBVGA[0] = 0x1C; 2186 priv->abyBBVGA[0] = 0x1C;
2234 pDevice->abyBBVGA[1] = 0x10; 2187 priv->abyBBVGA[1] = 0x10;
2235 pDevice->abyBBVGA[2] = 0x0; 2188 priv->abyBBVGA[2] = 0x0;
2236 pDevice->abyBBVGA[3] = 0x0; 2189 priv->abyBBVGA[3] = 0x0;
2237 pDevice->ldBmThreshold[0] = -70; 2190 priv->ldBmThreshold[0] = -70;
2238 pDevice->ldBmThreshold[1] = -48; 2191 priv->ldBmThreshold[1] = -48;
2239 pDevice->ldBmThreshold[2] = 0; 2192 priv->ldBmThreshold[2] = 0;
2240 pDevice->ldBmThreshold[3] = 0; 2193 priv->ldBmThreshold[3] = 0;
2241 /* }} RobertYu */ 2194 /* }} RobertYu */
2242 } else { 2195 } else {
2243 /* No VGA Table now */ 2196 /* No VGA Table now */
2244 pDevice->bUpdateBBVGA = false; 2197 priv->bUpdateBBVGA = false;
2245 pDevice->abyBBVGA[0] = 0x1C; 2198 priv->abyBBVGA[0] = 0x1C;
2246 } 2199 }
2247 2200
2248 if (byLocalID > REV_ID_VT3253_A1) { 2201 if (byLocalID > REV_ID_VT3253_A1) {
2249 BBbWriteEmbedded(dwIoBase, 0x04, 0x7F); 2202 BBbWriteEmbedded(priv, 0x04, 0x7F);
2250 BBbWriteEmbedded(dwIoBase, 0x0D, 0x01); 2203 BBbWriteEmbedded(priv, 0x0D, 0x01);
2251 } 2204 }
2252 2205
2253 return bResult; 2206 return bResult;
2254} 2207}
2255 2208
2256/* 2209/*
2257 * Description: Read All Baseband Registers
2258 *
2259 * Parameters:
2260 * In:
2261 * dwIoBase - I/O base address
2262 * pbyBBRegs - Point to struct that stores Baseband Registers
2263 * Out:
2264 * none
2265 *
2266 * Return Value: none
2267 *
2268 */
2269void BBvReadAllRegs(void __iomem *dwIoBase, unsigned char *pbyBBRegs)
2270{
2271 int ii;
2272 unsigned char byBase = 1;
2273
2274 for (ii = 0; ii < BB_MAX_CONTEXT_SIZE; ii++) {
2275 BBbReadEmbedded(dwIoBase, (unsigned char)(ii*byBase), pbyBBRegs);
2276 pbyBBRegs += byBase;
2277 }
2278}
2279
2280/*
2281 * Description: Turn on BaseBand Loopback mode
2282 *
2283 * Parameters:
2284 * In:
2285 * dwIoBase - I/O base address
2286 * bCCK - If CCK is set
2287 * Out:
2288 * none
2289 *
2290 * Return Value: none
2291 *
2292 */
2293
2294void BBvLoopbackOn(struct vnt_private *pDevice)
2295{
2296 unsigned char byData;
2297 void __iomem *dwIoBase = pDevice->PortOffset;
2298
2299 /* CR C9 = 0x00 */
2300 BBbReadEmbedded(dwIoBase, 0xC9, &pDevice->byBBCRc9); /* CR201 */
2301 BBbWriteEmbedded(dwIoBase, 0xC9, 0);
2302 BBbReadEmbedded(dwIoBase, 0x4D, &pDevice->byBBCR4d); /* CR77 */
2303 BBbWriteEmbedded(dwIoBase, 0x4D, 0x90);
2304
2305 /* CR 88 = 0x02(CCK), 0x03(OFDM) */
2306 BBbReadEmbedded(dwIoBase, 0x88, &pDevice->byBBCR88); /* CR136 */
2307
2308 if (pDevice->uConnectionRate <= RATE_11M) { /* CCK */
2309 /* Enable internal digital loopback: CR33 |= 0000 0001 */
2310 BBbReadEmbedded(dwIoBase, 0x21, &byData); /* CR33 */
2311 BBbWriteEmbedded(dwIoBase, 0x21, (unsigned char)(byData | 0x01)); /* CR33 */
2312 /* CR154 = 0x00 */
2313 BBbWriteEmbedded(dwIoBase, 0x9A, 0); /* CR154 */
2314
2315 BBbWriteEmbedded(dwIoBase, 0x88, 0x02); /* CR239 */
2316 } else { /* OFDM */
2317 /* Enable internal digital loopback:CR154 |= 0000 0001 */
2318 BBbReadEmbedded(dwIoBase, 0x9A, &byData); /* CR154 */
2319 BBbWriteEmbedded(dwIoBase, 0x9A, (unsigned char)(byData | 0x01)); /* CR154 */
2320 /* CR33 = 0x00 */
2321 BBbWriteEmbedded(dwIoBase, 0x21, 0); /* CR33 */
2322
2323 BBbWriteEmbedded(dwIoBase, 0x88, 0x03); /* CR239 */
2324 }
2325
2326 /* CR14 = 0x00 */
2327 BBbWriteEmbedded(dwIoBase, 0x0E, 0); /* CR14 */
2328
2329 /* Disable TX_IQUN */
2330 BBbReadEmbedded(pDevice->PortOffset, 0x09, &pDevice->byBBCR09);
2331 BBbWriteEmbedded(pDevice->PortOffset, 0x09, (unsigned char)(pDevice->byBBCR09 & 0xDE));
2332}
2333
2334/*
2335 * Description: Turn off BaseBand Loopback mode
2336 *
2337 * Parameters:
2338 * In:
2339 * pDevice - Device Structure
2340 *
2341 * Out:
2342 * none
2343 *
2344 * Return Value: none
2345 *
2346 */
2347void BBvLoopbackOff(struct vnt_private *pDevice)
2348{
2349 unsigned char byData;
2350 void __iomem *dwIoBase = pDevice->PortOffset;
2351
2352 BBbWriteEmbedded(dwIoBase, 0xC9, pDevice->byBBCRc9); /* CR201 */
2353 BBbWriteEmbedded(dwIoBase, 0x88, pDevice->byBBCR88); /* CR136 */
2354 BBbWriteEmbedded(dwIoBase, 0x09, pDevice->byBBCR09); /* CR136 */
2355 BBbWriteEmbedded(dwIoBase, 0x4D, pDevice->byBBCR4d); /* CR77 */
2356
2357 if (pDevice->uConnectionRate <= RATE_11M) { /* CCK */
2358 /* Set the CR33 Bit2 to disable internal Loopback. */
2359 BBbReadEmbedded(dwIoBase, 0x21, &byData);/* CR33 */
2360 BBbWriteEmbedded(dwIoBase, 0x21, (unsigned char)(byData & 0xFE)); /* CR33 */
2361 } else { /* OFDM */
2362 BBbReadEmbedded(dwIoBase, 0x9A, &byData); /* CR154 */
2363 BBbWriteEmbedded(dwIoBase, 0x9A, (unsigned char)(byData & 0xFE)); /* CR154 */
2364 }
2365 BBbReadEmbedded(dwIoBase, 0x0E, &byData); /* CR14 */
2366 BBbWriteEmbedded(dwIoBase, 0x0E, (unsigned char)(byData | 0x80)); /* CR14 */
2367}
2368
2369/*
2370 * Description: Set ShortSlotTime mode 2210 * Description: Set ShortSlotTime mode
2371 * 2211 *
2372 * Parameters: 2212 * Parameters:
2373 * In: 2213 * In:
2374 * pDevice - Device Structure 2214 * priv - Device Structure
2375 * Out: 2215 * Out:
2376 * none 2216 * none
2377 * 2217 *
@@ -2379,42 +2219,42 @@ void BBvLoopbackOff(struct vnt_private *pDevice)
2379 * 2219 *
2380 */ 2220 */
2381void 2221void
2382BBvSetShortSlotTime(struct vnt_private *pDevice) 2222BBvSetShortSlotTime(struct vnt_private *priv)
2383{ 2223{
2384 unsigned char byBBRxConf = 0; 2224 unsigned char byBBRxConf = 0;
2385 unsigned char byBBVGA = 0; 2225 unsigned char byBBVGA = 0;
2386 2226
2387 BBbReadEmbedded(pDevice->PortOffset, 0x0A, &byBBRxConf); /* CR10 */ 2227 BBbReadEmbedded(priv, 0x0A, &byBBRxConf); /* CR10 */
2388 2228
2389 if (pDevice->bShortSlotTime) 2229 if (priv->bShortSlotTime)
2390 byBBRxConf &= 0xDF; /* 1101 1111 */ 2230 byBBRxConf &= 0xDF; /* 1101 1111 */
2391 else 2231 else
2392 byBBRxConf |= 0x20; /* 0010 0000 */ 2232 byBBRxConf |= 0x20; /* 0010 0000 */
2393 2233
2394 /* patch for 3253B0 Baseband with Cardbus module */ 2234 /* patch for 3253B0 Baseband with Cardbus module */
2395 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byBBVGA); 2235 BBbReadEmbedded(priv, 0xE7, &byBBVGA);
2396 if (byBBVGA == pDevice->abyBBVGA[0]) 2236 if (byBBVGA == priv->abyBBVGA[0])
2397 byBBRxConf |= 0x20; /* 0010 0000 */ 2237 byBBRxConf |= 0x20; /* 0010 0000 */
2398 2238
2399 BBbWriteEmbedded(pDevice->PortOffset, 0x0A, byBBRxConf); /* CR10 */ 2239 BBbWriteEmbedded(priv, 0x0A, byBBRxConf); /* CR10 */
2400} 2240}
2401 2241
2402void BBvSetVGAGainOffset(struct vnt_private *pDevice, unsigned char byData) 2242void BBvSetVGAGainOffset(struct vnt_private *priv, unsigned char byData)
2403{ 2243{
2404 unsigned char byBBRxConf = 0; 2244 unsigned char byBBRxConf = 0;
2405 2245
2406 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, byData); 2246 BBbWriteEmbedded(priv, 0xE7, byData);
2407 2247
2408 BBbReadEmbedded(pDevice->PortOffset, 0x0A, &byBBRxConf); /* CR10 */ 2248 BBbReadEmbedded(priv, 0x0A, &byBBRxConf); /* CR10 */
2409 /* patch for 3253B0 Baseband with Cardbus module */ 2249 /* patch for 3253B0 Baseband with Cardbus module */
2410 if (byData == pDevice->abyBBVGA[0]) 2250 if (byData == priv->abyBBVGA[0])
2411 byBBRxConf |= 0x20; /* 0010 0000 */ 2251 byBBRxConf |= 0x20; /* 0010 0000 */
2412 else if (pDevice->bShortSlotTime) 2252 else if (priv->bShortSlotTime)
2413 byBBRxConf &= 0xDF; /* 1101 1111 */ 2253 byBBRxConf &= 0xDF; /* 1101 1111 */
2414 else 2254 else
2415 byBBRxConf |= 0x20; /* 0010 0000 */ 2255 byBBRxConf |= 0x20; /* 0010 0000 */
2416 pDevice->byBBVGACurrent = byData; 2256 priv->byBBVGACurrent = byData;
2417 BBbWriteEmbedded(pDevice->PortOffset, 0x0A, byBBRxConf); /* CR10 */ 2257 BBbWriteEmbedded(priv, 0x0A, byBBRxConf); /* CR10 */
2418} 2258}
2419 2259
2420/* 2260/*
@@ -2430,12 +2270,12 @@ void BBvSetVGAGainOffset(struct vnt_private *pDevice, unsigned char byData)
2430 * 2270 *
2431 */ 2271 */
2432void 2272void
2433BBvSoftwareReset(void __iomem *dwIoBase) 2273BBvSoftwareReset(struct vnt_private *priv)
2434{ 2274{
2435 BBbWriteEmbedded(dwIoBase, 0x50, 0x40); 2275 BBbWriteEmbedded(priv, 0x50, 0x40);
2436 BBbWriteEmbedded(dwIoBase, 0x50, 0); 2276 BBbWriteEmbedded(priv, 0x50, 0);
2437 BBbWriteEmbedded(dwIoBase, 0x9C, 0x01); 2277 BBbWriteEmbedded(priv, 0x9C, 0x01);
2438 BBbWriteEmbedded(dwIoBase, 0x9C, 0); 2278 BBbWriteEmbedded(priv, 0x9C, 0);
2439} 2279}
2440 2280
2441/* 2281/*
@@ -2451,13 +2291,13 @@ BBvSoftwareReset(void __iomem *dwIoBase)
2451 * 2291 *
2452 */ 2292 */
2453void 2293void
2454BBvPowerSaveModeON(void __iomem *dwIoBase) 2294BBvPowerSaveModeON(struct vnt_private *priv)
2455{ 2295{
2456 unsigned char byOrgData; 2296 unsigned char byOrgData;
2457 2297
2458 BBbReadEmbedded(dwIoBase, 0x0D, &byOrgData); 2298 BBbReadEmbedded(priv, 0x0D, &byOrgData);
2459 byOrgData |= BIT0; 2299 byOrgData |= BIT(0);
2460 BBbWriteEmbedded(dwIoBase, 0x0D, byOrgData); 2300 BBbWriteEmbedded(priv, 0x0D, byOrgData);
2461} 2301}
2462 2302
2463/* 2303/*
@@ -2473,13 +2313,13 @@ BBvPowerSaveModeON(void __iomem *dwIoBase)
2473 * 2313 *
2474 */ 2314 */
2475void 2315void
2476BBvPowerSaveModeOFF(void __iomem *dwIoBase) 2316BBvPowerSaveModeOFF(struct vnt_private *priv)
2477{ 2317{
2478 unsigned char byOrgData; 2318 unsigned char byOrgData;
2479 2319
2480 BBbReadEmbedded(dwIoBase, 0x0D, &byOrgData); 2320 BBbReadEmbedded(priv, 0x0D, &byOrgData);
2481 byOrgData &= ~(BIT0); 2321 byOrgData &= ~(BIT(0));
2482 BBbWriteEmbedded(dwIoBase, 0x0D, byOrgData); 2322 BBbWriteEmbedded(priv, 0x0D, byOrgData);
2483} 2323}
2484 2324
2485/* 2325/*
@@ -2487,7 +2327,7 @@ BBvPowerSaveModeOFF(void __iomem *dwIoBase)
2487 * 2327 *
2488 * Parameters: 2328 * Parameters:
2489 * In: 2329 * In:
2490 * pDevice - Device Structure 2330 * priv - Device Structure
2491 * byAntennaMode - Antenna Mode 2331 * byAntennaMode - Antenna Mode
2492 * Out: 2332 * Out:
2493 * none 2333 * none
@@ -2497,11 +2337,11 @@ BBvPowerSaveModeOFF(void __iomem *dwIoBase)
2497 */ 2337 */
2498 2338
2499void 2339void
2500BBvSetTxAntennaMode(void __iomem *dwIoBase, unsigned char byAntennaMode) 2340BBvSetTxAntennaMode(struct vnt_private *priv, unsigned char byAntennaMode)
2501{ 2341{
2502 unsigned char byBBTxConf; 2342 unsigned char byBBTxConf;
2503 2343
2504 BBbReadEmbedded(dwIoBase, 0x09, &byBBTxConf); /* CR09 */ 2344 BBbReadEmbedded(priv, 0x09, &byBBTxConf); /* CR09 */
2505 if (byAntennaMode == ANT_DIVERSITY) { 2345 if (byAntennaMode == ANT_DIVERSITY) {
2506 /* bit 1 is diversity */ 2346 /* bit 1 is diversity */
2507 byBBTxConf |= 0x02; 2347 byBBTxConf |= 0x02;
@@ -2512,7 +2352,7 @@ BBvSetTxAntennaMode(void __iomem *dwIoBase, unsigned char byAntennaMode)
2512 byBBTxConf &= 0xFD; /* 1111 1101 */ 2352 byBBTxConf &= 0xFD; /* 1111 1101 */
2513 byBBTxConf |= 0x04; 2353 byBBTxConf |= 0x04;
2514 } 2354 }
2515 BBbWriteEmbedded(dwIoBase, 0x09, byBBTxConf); /* CR09 */ 2355 BBbWriteEmbedded(priv, 0x09, byBBTxConf); /* CR09 */
2516} 2356}
2517 2357
2518/* 2358/*
@@ -2520,7 +2360,7 @@ BBvSetTxAntennaMode(void __iomem *dwIoBase, unsigned char byAntennaMode)
2520 * 2360 *
2521 * Parameters: 2361 * Parameters:
2522 * In: 2362 * In:
2523 * pDevice - Device Structure 2363 * priv - Device Structure
2524 * byAntennaMode - Antenna Mode 2364 * byAntennaMode - Antenna Mode
2525 * Out: 2365 * Out:
2526 * none 2366 * none
@@ -2530,11 +2370,11 @@ BBvSetTxAntennaMode(void __iomem *dwIoBase, unsigned char byAntennaMode)
2530 */ 2370 */
2531 2371
2532void 2372void
2533BBvSetRxAntennaMode(void __iomem *dwIoBase, unsigned char byAntennaMode) 2373BBvSetRxAntennaMode(struct vnt_private *priv, unsigned char byAntennaMode)
2534{ 2374{
2535 unsigned char byBBRxConf; 2375 unsigned char byBBRxConf;
2536 2376
2537 BBbReadEmbedded(dwIoBase, 0x0A, &byBBRxConf); /* CR10 */ 2377 BBbReadEmbedded(priv, 0x0A, &byBBRxConf); /* CR10 */
2538 if (byAntennaMode == ANT_DIVERSITY) { 2378 if (byAntennaMode == ANT_DIVERSITY) {
2539 byBBRxConf |= 0x01; 2379 byBBRxConf |= 0x01;
2540 2380
@@ -2544,7 +2384,7 @@ BBvSetRxAntennaMode(void __iomem *dwIoBase, unsigned char byAntennaMode)
2544 byBBRxConf &= 0xFE; /* 1111 1110 */ 2384 byBBRxConf &= 0xFE; /* 1111 1110 */
2545 byBBRxConf |= 0x02; 2385 byBBRxConf |= 0x02;
2546 } 2386 }
2547 BBbWriteEmbedded(dwIoBase, 0x0A, byBBRxConf); /* CR10 */ 2387 BBbWriteEmbedded(priv, 0x0A, byBBRxConf); /* CR10 */
2548} 2388}
2549 2389
2550/* 2390/*
@@ -2552,7 +2392,7 @@ BBvSetRxAntennaMode(void __iomem *dwIoBase, unsigned char byAntennaMode)
2552 * 2392 *
2553 * Parameters: 2393 * Parameters:
2554 * In: 2394 * In:
2555 * pDevice - Device Structure 2395 * priv - Device Structure
2556 * Out: 2396 * Out:
2557 * none 2397 * none
2558 * 2398 *
@@ -2560,109 +2400,109 @@ BBvSetRxAntennaMode(void __iomem *dwIoBase, unsigned char byAntennaMode)
2560 * 2400 *
2561 */ 2401 */
2562void 2402void
2563BBvSetDeepSleep(void __iomem *dwIoBase, unsigned char byLocalID) 2403BBvSetDeepSleep(struct vnt_private *priv, unsigned char byLocalID)
2564{ 2404{
2565 BBbWriteEmbedded(dwIoBase, 0x0C, 0x17); /* CR12 */ 2405 BBbWriteEmbedded(priv, 0x0C, 0x17); /* CR12 */
2566 BBbWriteEmbedded(dwIoBase, 0x0D, 0xB9); /* CR13 */ 2406 BBbWriteEmbedded(priv, 0x0D, 0xB9); /* CR13 */
2567} 2407}
2568 2408
2569void 2409void
2570BBvExitDeepSleep(void __iomem *dwIoBase, unsigned char byLocalID) 2410BBvExitDeepSleep(struct vnt_private *priv, unsigned char byLocalID)
2571{ 2411{
2572 BBbWriteEmbedded(dwIoBase, 0x0C, 0x00); /* CR12 */ 2412 BBbWriteEmbedded(priv, 0x0C, 0x00); /* CR12 */
2573 BBbWriteEmbedded(dwIoBase, 0x0D, 0x01); /* CR13 */ 2413 BBbWriteEmbedded(priv, 0x0D, 0x01); /* CR13 */
2574} 2414}
2575 2415
2576static 2416static
2577unsigned long 2417unsigned long
2578s_ulGetRatio(struct vnt_private *pDevice) 2418s_ulGetRatio(struct vnt_private *priv)
2579{ 2419{
2580 unsigned long ulRatio = 0; 2420 unsigned long ulRatio = 0;
2581 unsigned long ulMaxPacket; 2421 unsigned long ulMaxPacket;
2582 unsigned long ulPacketNum; 2422 unsigned long ulPacketNum;
2583 2423
2584 /* This is a thousand-ratio */ 2424 /* This is a thousand-ratio */
2585 ulMaxPacket = pDevice->uNumSQ3[RATE_54M]; 2425 ulMaxPacket = priv->uNumSQ3[RATE_54M];
2586 if (pDevice->uNumSQ3[RATE_54M] != 0) { 2426 if (priv->uNumSQ3[RATE_54M] != 0) {
2587 ulPacketNum = pDevice->uNumSQ3[RATE_54M]; 2427 ulPacketNum = priv->uNumSQ3[RATE_54M];
2588 ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt); 2428 ulRatio = (ulPacketNum * 1000 / priv->uDiversityCnt);
2589 ulRatio += TOP_RATE_54M; 2429 ulRatio += TOP_RATE_54M;
2590 } 2430 }
2591 if (pDevice->uNumSQ3[RATE_48M] > ulMaxPacket) { 2431 if (priv->uNumSQ3[RATE_48M] > ulMaxPacket) {
2592 ulPacketNum = pDevice->uNumSQ3[RATE_54M] + pDevice->uNumSQ3[RATE_48M]; 2432 ulPacketNum = priv->uNumSQ3[RATE_54M] + priv->uNumSQ3[RATE_48M];
2593 ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt); 2433 ulRatio = (ulPacketNum * 1000 / priv->uDiversityCnt);
2594 ulRatio += TOP_RATE_48M; 2434 ulRatio += TOP_RATE_48M;
2595 ulMaxPacket = pDevice->uNumSQ3[RATE_48M]; 2435 ulMaxPacket = priv->uNumSQ3[RATE_48M];
2596 } 2436 }
2597 if (pDevice->uNumSQ3[RATE_36M] > ulMaxPacket) { 2437 if (priv->uNumSQ3[RATE_36M] > ulMaxPacket) {
2598 ulPacketNum = pDevice->uNumSQ3[RATE_54M] + pDevice->uNumSQ3[RATE_48M] + 2438 ulPacketNum = priv->uNumSQ3[RATE_54M] + priv->uNumSQ3[RATE_48M] +
2599 pDevice->uNumSQ3[RATE_36M]; 2439 priv->uNumSQ3[RATE_36M];
2600 ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt); 2440 ulRatio = (ulPacketNum * 1000 / priv->uDiversityCnt);
2601 ulRatio += TOP_RATE_36M; 2441 ulRatio += TOP_RATE_36M;
2602 ulMaxPacket = pDevice->uNumSQ3[RATE_36M]; 2442 ulMaxPacket = priv->uNumSQ3[RATE_36M];
2603 } 2443 }
2604 if (pDevice->uNumSQ3[RATE_24M] > ulMaxPacket) { 2444 if (priv->uNumSQ3[RATE_24M] > ulMaxPacket) {
2605 ulPacketNum = pDevice->uNumSQ3[RATE_54M] + pDevice->uNumSQ3[RATE_48M] + 2445 ulPacketNum = priv->uNumSQ3[RATE_54M] + priv->uNumSQ3[RATE_48M] +
2606 pDevice->uNumSQ3[RATE_36M] + pDevice->uNumSQ3[RATE_24M]; 2446 priv->uNumSQ3[RATE_36M] + priv->uNumSQ3[RATE_24M];
2607 ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt); 2447 ulRatio = (ulPacketNum * 1000 / priv->uDiversityCnt);
2608 ulRatio += TOP_RATE_24M; 2448 ulRatio += TOP_RATE_24M;
2609 ulMaxPacket = pDevice->uNumSQ3[RATE_24M]; 2449 ulMaxPacket = priv->uNumSQ3[RATE_24M];
2610 } 2450 }
2611 if (pDevice->uNumSQ3[RATE_18M] > ulMaxPacket) { 2451 if (priv->uNumSQ3[RATE_18M] > ulMaxPacket) {
2612 ulPacketNum = pDevice->uNumSQ3[RATE_54M] + pDevice->uNumSQ3[RATE_48M] + 2452 ulPacketNum = priv->uNumSQ3[RATE_54M] + priv->uNumSQ3[RATE_48M] +
2613 pDevice->uNumSQ3[RATE_36M] + pDevice->uNumSQ3[RATE_24M] + 2453 priv->uNumSQ3[RATE_36M] + priv->uNumSQ3[RATE_24M] +
2614 pDevice->uNumSQ3[RATE_18M]; 2454 priv->uNumSQ3[RATE_18M];
2615 ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt); 2455 ulRatio = (ulPacketNum * 1000 / priv->uDiversityCnt);
2616 ulRatio += TOP_RATE_18M; 2456 ulRatio += TOP_RATE_18M;
2617 ulMaxPacket = pDevice->uNumSQ3[RATE_18M]; 2457 ulMaxPacket = priv->uNumSQ3[RATE_18M];
2618 } 2458 }
2619 if (pDevice->uNumSQ3[RATE_12M] > ulMaxPacket) { 2459 if (priv->uNumSQ3[RATE_12M] > ulMaxPacket) {
2620 ulPacketNum = pDevice->uNumSQ3[RATE_54M] + pDevice->uNumSQ3[RATE_48M] + 2460 ulPacketNum = priv->uNumSQ3[RATE_54M] + priv->uNumSQ3[RATE_48M] +
2621 pDevice->uNumSQ3[RATE_36M] + pDevice->uNumSQ3[RATE_24M] + 2461 priv->uNumSQ3[RATE_36M] + priv->uNumSQ3[RATE_24M] +
2622 pDevice->uNumSQ3[RATE_18M] + pDevice->uNumSQ3[RATE_12M]; 2462 priv->uNumSQ3[RATE_18M] + priv->uNumSQ3[RATE_12M];
2623 ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt); 2463 ulRatio = (ulPacketNum * 1000 / priv->uDiversityCnt);
2624 ulRatio += TOP_RATE_12M; 2464 ulRatio += TOP_RATE_12M;
2625 ulMaxPacket = pDevice->uNumSQ3[RATE_12M]; 2465 ulMaxPacket = priv->uNumSQ3[RATE_12M];
2626 } 2466 }
2627 if (pDevice->uNumSQ3[RATE_11M] > ulMaxPacket) { 2467 if (priv->uNumSQ3[RATE_11M] > ulMaxPacket) {
2628 ulPacketNum = pDevice->uDiversityCnt - pDevice->uNumSQ3[RATE_1M] - 2468 ulPacketNum = priv->uDiversityCnt - priv->uNumSQ3[RATE_1M] -
2629 pDevice->uNumSQ3[RATE_2M] - pDevice->uNumSQ3[RATE_5M] - 2469 priv->uNumSQ3[RATE_2M] - priv->uNumSQ3[RATE_5M] -
2630 pDevice->uNumSQ3[RATE_6M] - pDevice->uNumSQ3[RATE_9M]; 2470 priv->uNumSQ3[RATE_6M] - priv->uNumSQ3[RATE_9M];
2631 ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt); 2471 ulRatio = (ulPacketNum * 1000 / priv->uDiversityCnt);
2632 ulRatio += TOP_RATE_11M; 2472 ulRatio += TOP_RATE_11M;
2633 ulMaxPacket = pDevice->uNumSQ3[RATE_11M]; 2473 ulMaxPacket = priv->uNumSQ3[RATE_11M];
2634 } 2474 }
2635 if (pDevice->uNumSQ3[RATE_9M] > ulMaxPacket) { 2475 if (priv->uNumSQ3[RATE_9M] > ulMaxPacket) {
2636 ulPacketNum = pDevice->uDiversityCnt - pDevice->uNumSQ3[RATE_1M] - 2476 ulPacketNum = priv->uDiversityCnt - priv->uNumSQ3[RATE_1M] -
2637 pDevice->uNumSQ3[RATE_2M] - pDevice->uNumSQ3[RATE_5M] - 2477 priv->uNumSQ3[RATE_2M] - priv->uNumSQ3[RATE_5M] -
2638 pDevice->uNumSQ3[RATE_6M]; 2478 priv->uNumSQ3[RATE_6M];
2639 ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt); 2479 ulRatio = (ulPacketNum * 1000 / priv->uDiversityCnt);
2640 ulRatio += TOP_RATE_9M; 2480 ulRatio += TOP_RATE_9M;
2641 ulMaxPacket = pDevice->uNumSQ3[RATE_9M]; 2481 ulMaxPacket = priv->uNumSQ3[RATE_9M];
2642 } 2482 }
2643 if (pDevice->uNumSQ3[RATE_6M] > ulMaxPacket) { 2483 if (priv->uNumSQ3[RATE_6M] > ulMaxPacket) {
2644 ulPacketNum = pDevice->uDiversityCnt - pDevice->uNumSQ3[RATE_1M] - 2484 ulPacketNum = priv->uDiversityCnt - priv->uNumSQ3[RATE_1M] -
2645 pDevice->uNumSQ3[RATE_2M] - pDevice->uNumSQ3[RATE_5M]; 2485 priv->uNumSQ3[RATE_2M] - priv->uNumSQ3[RATE_5M];
2646 ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt); 2486 ulRatio = (ulPacketNum * 1000 / priv->uDiversityCnt);
2647 ulRatio += TOP_RATE_6M; 2487 ulRatio += TOP_RATE_6M;
2648 ulMaxPacket = pDevice->uNumSQ3[RATE_6M]; 2488 ulMaxPacket = priv->uNumSQ3[RATE_6M];
2649 } 2489 }
2650 if (pDevice->uNumSQ3[RATE_5M] > ulMaxPacket) { 2490 if (priv->uNumSQ3[RATE_5M] > ulMaxPacket) {
2651 ulPacketNum = pDevice->uDiversityCnt - pDevice->uNumSQ3[RATE_1M] - 2491 ulPacketNum = priv->uDiversityCnt - priv->uNumSQ3[RATE_1M] -
2652 pDevice->uNumSQ3[RATE_2M]; 2492 priv->uNumSQ3[RATE_2M];
2653 ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt); 2493 ulRatio = (ulPacketNum * 1000 / priv->uDiversityCnt);
2654 ulRatio += TOP_RATE_55M; 2494 ulRatio += TOP_RATE_55M;
2655 ulMaxPacket = pDevice->uNumSQ3[RATE_5M]; 2495 ulMaxPacket = priv->uNumSQ3[RATE_5M];
2656 } 2496 }
2657 if (pDevice->uNumSQ3[RATE_2M] > ulMaxPacket) { 2497 if (priv->uNumSQ3[RATE_2M] > ulMaxPacket) {
2658 ulPacketNum = pDevice->uDiversityCnt - pDevice->uNumSQ3[RATE_1M]; 2498 ulPacketNum = priv->uDiversityCnt - priv->uNumSQ3[RATE_1M];
2659 ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt); 2499 ulRatio = (ulPacketNum * 1000 / priv->uDiversityCnt);
2660 ulRatio += TOP_RATE_2M; 2500 ulRatio += TOP_RATE_2M;
2661 ulMaxPacket = pDevice->uNumSQ3[RATE_2M]; 2501 ulMaxPacket = priv->uNumSQ3[RATE_2M];
2662 } 2502 }
2663 if (pDevice->uNumSQ3[RATE_1M] > ulMaxPacket) { 2503 if (priv->uNumSQ3[RATE_1M] > ulMaxPacket) {
2664 ulPacketNum = pDevice->uDiversityCnt; 2504 ulPacketNum = priv->uDiversityCnt;
2665 ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt); 2505 ulRatio = (ulPacketNum * 1000 / priv->uDiversityCnt);
2666 ulRatio += TOP_RATE_1M; 2506 ulRatio += TOP_RATE_1M;
2667 } 2507 }
2668 2508
@@ -2670,13 +2510,13 @@ s_ulGetRatio(struct vnt_private *pDevice)
2670} 2510}
2671 2511
2672void 2512void
2673BBvClearAntDivSQ3Value(struct vnt_private *pDevice) 2513BBvClearAntDivSQ3Value(struct vnt_private *priv)
2674{ 2514{
2675 unsigned int ii; 2515 unsigned int ii;
2676 2516
2677 pDevice->uDiversityCnt = 0; 2517 priv->uDiversityCnt = 0;
2678 for (ii = 0; ii < MAX_RATE; ii++) 2518 for (ii = 0; ii < MAX_RATE; ii++)
2679 pDevice->uNumSQ3[ii] = 0; 2519 priv->uNumSQ3[ii] = 0;
2680} 2520}
2681 2521
2682/* 2522/*
@@ -2684,7 +2524,7 @@ BBvClearAntDivSQ3Value(struct vnt_private *pDevice)
2684 * 2524 *
2685 * Parameters: 2525 * Parameters:
2686 * In: 2526 * In:
2687 * pDevice - Device Structure 2527 * priv - Device Structure
2688 * byRSR - RSR from received packet 2528 * byRSR - RSR from received packet
2689 * bySQ3 - SQ3 value from received packet 2529 * bySQ3 - SQ3 value from received packet
2690 * Out: 2530 * Out:
@@ -2694,75 +2534,75 @@ BBvClearAntDivSQ3Value(struct vnt_private *pDevice)
2694 * 2534 *
2695 */ 2535 */
2696 2536
2697void BBvAntennaDiversity(struct vnt_private *pDevice, 2537void BBvAntennaDiversity(struct vnt_private *priv,
2698 unsigned char byRxRate, unsigned char bySQ3) 2538 unsigned char byRxRate, unsigned char bySQ3)
2699{ 2539{
2700 if ((byRxRate >= MAX_RATE) || (pDevice->wAntDiversityMaxRate >= MAX_RATE)) 2540 if ((byRxRate >= MAX_RATE) || (priv->wAntDiversityMaxRate >= MAX_RATE))
2701 return; 2541 return;
2702 2542
2703 pDevice->uDiversityCnt++; 2543 priv->uDiversityCnt++;
2704 2544
2705 pDevice->uNumSQ3[byRxRate]++; 2545 priv->uNumSQ3[byRxRate]++;
2706 2546
2707 if (pDevice->byAntennaState == 0) { 2547 if (priv->byAntennaState == 0) {
2708 if (pDevice->uDiversityCnt > pDevice->ulDiversityNValue) { 2548 if (priv->uDiversityCnt > priv->ulDiversityNValue) {
2709 pr_debug("ulDiversityNValue=[%d],54M-[%d]\n", 2549 pr_debug("ulDiversityNValue=[%d],54M-[%d]\n",
2710 (int)pDevice->ulDiversityNValue, 2550 (int)priv->ulDiversityNValue,
2711 (int)pDevice->uNumSQ3[(int)pDevice->wAntDiversityMaxRate]); 2551 (int)priv->uNumSQ3[(int)priv->wAntDiversityMaxRate]);
2712 2552
2713 if (pDevice->uNumSQ3[pDevice->wAntDiversityMaxRate] < pDevice->uDiversityCnt/2) { 2553 if (priv->uNumSQ3[priv->wAntDiversityMaxRate] < priv->uDiversityCnt/2) {
2714 pDevice->ulRatio_State0 = s_ulGetRatio(pDevice); 2554 priv->ulRatio_State0 = s_ulGetRatio(priv);
2715 pr_debug("SQ3_State0, rate = [%08x]\n", 2555 pr_debug("SQ3_State0, rate = [%08x]\n",
2716 (int)pDevice->ulRatio_State0); 2556 (int)priv->ulRatio_State0);
2717 2557
2718 if (pDevice->byTMax == 0) 2558 if (priv->byTMax == 0)
2719 return; 2559 return;
2720 pr_debug("1.[%08x], uNumSQ3[%d]=%d, %d\n", 2560 pr_debug("1.[%08x], uNumSQ3[%d]=%d, %d\n",
2721 (int)pDevice->ulRatio_State0, 2561 (int)priv->ulRatio_State0,
2722 (int)pDevice->wAntDiversityMaxRate, 2562 (int)priv->wAntDiversityMaxRate,
2723 (int)pDevice->uNumSQ3[(int)pDevice->wAntDiversityMaxRate], 2563 (int)priv->uNumSQ3[(int)priv->wAntDiversityMaxRate],
2724 (int)pDevice->uDiversityCnt); 2564 (int)priv->uDiversityCnt);
2725 2565
2726 s_vChangeAntenna(pDevice); 2566 s_vChangeAntenna(priv);
2727 pDevice->byAntennaState = 1; 2567 priv->byAntennaState = 1;
2728 del_timer(&pDevice->TimerSQ3Tmax3); 2568 del_timer(&priv->TimerSQ3Tmax3);
2729 del_timer(&pDevice->TimerSQ3Tmax2); 2569 del_timer(&priv->TimerSQ3Tmax2);
2730 pDevice->TimerSQ3Tmax1.expires = RUN_AT(pDevice->byTMax * HZ); 2570 priv->TimerSQ3Tmax1.expires = RUN_AT(priv->byTMax * HZ);
2731 add_timer(&pDevice->TimerSQ3Tmax1); 2571 add_timer(&priv->TimerSQ3Tmax1);
2732 2572
2733 } else { 2573 } else {
2734 pDevice->TimerSQ3Tmax3.expires = RUN_AT(pDevice->byTMax3 * HZ); 2574 priv->TimerSQ3Tmax3.expires = RUN_AT(priv->byTMax3 * HZ);
2735 add_timer(&pDevice->TimerSQ3Tmax3); 2575 add_timer(&priv->TimerSQ3Tmax3);
2736 } 2576 }
2737 BBvClearAntDivSQ3Value(pDevice); 2577 BBvClearAntDivSQ3Value(priv);
2738 2578
2739 } 2579 }
2740 } else { /* byAntennaState == 1 */ 2580 } else { /* byAntennaState == 1 */
2741 2581
2742 if (pDevice->uDiversityCnt > pDevice->ulDiversityMValue) { 2582 if (priv->uDiversityCnt > priv->ulDiversityMValue) {
2743 del_timer(&pDevice->TimerSQ3Tmax1); 2583 del_timer(&priv->TimerSQ3Tmax1);
2744 2584
2745 pDevice->ulRatio_State1 = s_ulGetRatio(pDevice); 2585 priv->ulRatio_State1 = s_ulGetRatio(priv);
2746 pr_debug("RX:SQ3_State1, rate0 = %08x,rate1 = %08x\n", 2586 pr_debug("RX:SQ3_State1, rate0 = %08x,rate1 = %08x\n",
2747 (int)pDevice->ulRatio_State0, 2587 (int)priv->ulRatio_State0,
2748 (int)pDevice->ulRatio_State1); 2588 (int)priv->ulRatio_State1);
2749 2589
2750 if (pDevice->ulRatio_State1 < pDevice->ulRatio_State0) { 2590 if (priv->ulRatio_State1 < priv->ulRatio_State0) {
2751 pr_debug("2.[%08x][%08x], uNumSQ3[%d]=%d, %d\n", 2591 pr_debug("2.[%08x][%08x], uNumSQ3[%d]=%d, %d\n",
2752 (int)pDevice->ulRatio_State0, 2592 (int)priv->ulRatio_State0,
2753 (int)pDevice->ulRatio_State1, 2593 (int)priv->ulRatio_State1,
2754 (int)pDevice->wAntDiversityMaxRate, 2594 (int)priv->wAntDiversityMaxRate,
2755 (int)pDevice->uNumSQ3[(int)pDevice->wAntDiversityMaxRate], 2595 (int)priv->uNumSQ3[(int)priv->wAntDiversityMaxRate],
2756 (int)pDevice->uDiversityCnt); 2596 (int)priv->uDiversityCnt);
2757 2597
2758 s_vChangeAntenna(pDevice); 2598 s_vChangeAntenna(priv);
2759 pDevice->TimerSQ3Tmax3.expires = RUN_AT(pDevice->byTMax3 * HZ); 2599 priv->TimerSQ3Tmax3.expires = RUN_AT(priv->byTMax3 * HZ);
2760 pDevice->TimerSQ3Tmax2.expires = RUN_AT(pDevice->byTMax2 * HZ); 2600 priv->TimerSQ3Tmax2.expires = RUN_AT(priv->byTMax2 * HZ);
2761 add_timer(&pDevice->TimerSQ3Tmax3); 2601 add_timer(&priv->TimerSQ3Tmax3);
2762 add_timer(&pDevice->TimerSQ3Tmax2); 2602 add_timer(&priv->TimerSQ3Tmax2);
2763 } 2603 }
2764 pDevice->byAntennaState = 0; 2604 priv->byAntennaState = 0;
2765 BBvClearAntDivSQ3Value(pDevice); 2605 BBvClearAntDivSQ3Value(priv);
2766 } 2606 }
2767 } /* byAntennaState */ 2607 } /* byAntennaState */
2768} 2608}
@@ -2783,28 +2623,30 @@ void BBvAntennaDiversity(struct vnt_private *pDevice,
2783 2623
2784void 2624void
2785TimerSQ3CallBack( 2625TimerSQ3CallBack(
2786 void *hDeviceContext 2626 unsigned long data
2787) 2627)
2788{ 2628{
2789 struct vnt_private *pDevice = hDeviceContext; 2629 struct vnt_private *priv = (struct vnt_private *)data;
2630 unsigned long flags;
2790 2631
2791 pr_debug("TimerSQ3CallBack...\n"); 2632 pr_debug("TimerSQ3CallBack...\n");
2792 spin_lock_irq(&pDevice->lock); 2633
2634 spin_lock_irqsave(&priv->lock, flags);
2793 2635
2794 pr_debug("3.[%08x][%08x], %d\n", 2636 pr_debug("3.[%08x][%08x], %d\n",
2795 (int)pDevice->ulRatio_State0, (int)pDevice->ulRatio_State1, 2637 (int)priv->ulRatio_State0, (int)priv->ulRatio_State1,
2796 (int)pDevice->uDiversityCnt); 2638 (int)priv->uDiversityCnt);
2797 2639
2798 s_vChangeAntenna(pDevice); 2640 s_vChangeAntenna(priv);
2799 pDevice->byAntennaState = 0; 2641 priv->byAntennaState = 0;
2800 BBvClearAntDivSQ3Value(pDevice); 2642 BBvClearAntDivSQ3Value(priv);
2801 2643
2802 pDevice->TimerSQ3Tmax3.expires = RUN_AT(pDevice->byTMax3 * HZ); 2644 priv->TimerSQ3Tmax3.expires = RUN_AT(priv->byTMax3 * HZ);
2803 pDevice->TimerSQ3Tmax2.expires = RUN_AT(pDevice->byTMax2 * HZ); 2645 priv->TimerSQ3Tmax2.expires = RUN_AT(priv->byTMax2 * HZ);
2804 add_timer(&pDevice->TimerSQ3Tmax3); 2646 add_timer(&priv->TimerSQ3Tmax3);
2805 add_timer(&pDevice->TimerSQ3Tmax2); 2647 add_timer(&priv->TimerSQ3Tmax2);
2806 2648
2807 spin_unlock_irq(&pDevice->lock); 2649 spin_unlock_irqrestore(&priv->lock, flags);
2808} 2650}
2809 2651
2810/*+ 2652/*+
@@ -2827,43 +2669,46 @@ TimerSQ3CallBack(
2827 2669
2828void 2670void
2829TimerState1CallBack( 2671TimerState1CallBack(
2830 void *hDeviceContext 2672 unsigned long data
2831) 2673)
2832{ 2674{
2833 struct vnt_private *pDevice = hDeviceContext; 2675 struct vnt_private *priv = (struct vnt_private *)data;
2676 unsigned long flags;
2834 2677
2835 pr_debug("TimerState1CallBack...\n"); 2678 pr_debug("TimerState1CallBack...\n");
2836 2679
2837 spin_lock_irq(&pDevice->lock); 2680 spin_lock_irqsave(&priv->lock, flags);
2838 if (pDevice->uDiversityCnt < pDevice->ulDiversityMValue/100) { 2681
2839 s_vChangeAntenna(pDevice); 2682 if (priv->uDiversityCnt < priv->ulDiversityMValue/100) {
2840 pDevice->TimerSQ3Tmax3.expires = RUN_AT(pDevice->byTMax3 * HZ); 2683 s_vChangeAntenna(priv);
2841 pDevice->TimerSQ3Tmax2.expires = RUN_AT(pDevice->byTMax2 * HZ); 2684 priv->TimerSQ3Tmax3.expires = RUN_AT(priv->byTMax3 * HZ);
2842 add_timer(&pDevice->TimerSQ3Tmax3); 2685 priv->TimerSQ3Tmax2.expires = RUN_AT(priv->byTMax2 * HZ);
2843 add_timer(&pDevice->TimerSQ3Tmax2); 2686 add_timer(&priv->TimerSQ3Tmax3);
2687 add_timer(&priv->TimerSQ3Tmax2);
2844 } else { 2688 } else {
2845 pDevice->ulRatio_State1 = s_ulGetRatio(pDevice); 2689 priv->ulRatio_State1 = s_ulGetRatio(priv);
2846 pr_debug("SQ3_State1, rate0 = %08x,rate1 = %08x\n", 2690 pr_debug("SQ3_State1, rate0 = %08x,rate1 = %08x\n",
2847 (int)pDevice->ulRatio_State0, 2691 (int)priv->ulRatio_State0,
2848 (int)pDevice->ulRatio_State1); 2692 (int)priv->ulRatio_State1);
2849 2693
2850 if (pDevice->ulRatio_State1 < pDevice->ulRatio_State0) { 2694 if (priv->ulRatio_State1 < priv->ulRatio_State0) {
2851 pr_debug("2.[%08x][%08x], uNumSQ3[%d]=%d, %d\n", 2695 pr_debug("2.[%08x][%08x], uNumSQ3[%d]=%d, %d\n",
2852 (int)pDevice->ulRatio_State0, 2696 (int)priv->ulRatio_State0,
2853 (int)pDevice->ulRatio_State1, 2697 (int)priv->ulRatio_State1,
2854 (int)pDevice->wAntDiversityMaxRate, 2698 (int)priv->wAntDiversityMaxRate,
2855 (int)pDevice->uNumSQ3[(int)pDevice->wAntDiversityMaxRate], 2699 (int)priv->uNumSQ3[(int)priv->wAntDiversityMaxRate],
2856 (int)pDevice->uDiversityCnt); 2700 (int)priv->uDiversityCnt);
2857 2701
2858 s_vChangeAntenna(pDevice); 2702 s_vChangeAntenna(priv);
2859 2703
2860 pDevice->TimerSQ3Tmax3.expires = RUN_AT(pDevice->byTMax3 * HZ); 2704 priv->TimerSQ3Tmax3.expires = RUN_AT(priv->byTMax3 * HZ);
2861 pDevice->TimerSQ3Tmax2.expires = RUN_AT(pDevice->byTMax2 * HZ); 2705 priv->TimerSQ3Tmax2.expires = RUN_AT(priv->byTMax2 * HZ);
2862 add_timer(&pDevice->TimerSQ3Tmax3); 2706 add_timer(&priv->TimerSQ3Tmax3);
2863 add_timer(&pDevice->TimerSQ3Tmax2); 2707 add_timer(&priv->TimerSQ3Tmax2);
2864 } 2708 }
2865 } 2709 }
2866 pDevice->byAntennaState = 0; 2710 priv->byAntennaState = 0;
2867 BBvClearAntDivSQ3Value(pDevice); 2711 BBvClearAntDivSQ3Value(priv);
2868 spin_unlock_irq(&pDevice->lock); 2712
2713 spin_unlock_irqrestore(&priv->lock, flags);
2869} 2714}
diff --git a/drivers/staging/vt6655/baseband.h b/drivers/staging/vt6655/baseband.h
index 31f2255519cf..d9f6d63e4ab7 100644
--- a/drivers/staging/vt6655/baseband.h
+++ b/drivers/staging/vt6655/baseband.h
@@ -30,8 +30,6 @@
30#ifndef __BASEBAND_H__ 30#ifndef __BASEBAND_H__
31#define __BASEBAND_H__ 31#define __BASEBAND_H__
32 32
33#include "ttype.h"
34#include "tether.h"
35#include "device.h" 33#include "device.h"
36 34
37/* 35/*
@@ -79,42 +77,37 @@ BBuGetFrameTime(
79void vnt_get_phy_field(struct vnt_private *, u32 frame_length, 77void vnt_get_phy_field(struct vnt_private *, u32 frame_length,
80 u16 tx_rate, u8 pkt_type, struct vnt_phy_field *); 78 u16 tx_rate, u8 pkt_type, struct vnt_phy_field *);
81 79
82bool BBbReadEmbedded(void __iomem *dwIoBase, unsigned char byBBAddr, unsigned char *pbyData); 80bool BBbReadEmbedded(struct vnt_private *, unsigned char byBBAddr, unsigned char *pbyData);
83bool BBbWriteEmbedded(void __iomem *dwIoBase, unsigned char byBBAddr, unsigned char byData); 81bool BBbWriteEmbedded(struct vnt_private *, unsigned char byBBAddr, unsigned char byData);
84 82
85void BBvReadAllRegs(void __iomem *dwIoBase, unsigned char *pbyBBRegs); 83void BBvSetShortSlotTime(struct vnt_private *);
86void BBvLoopbackOn(struct vnt_private *pDevice); 84void BBvSetVGAGainOffset(struct vnt_private *, unsigned char byData);
87void BBvLoopbackOff(struct vnt_private *pDevice);
88void BBvSetShortSlotTime(struct vnt_private *pDevice);
89bool BBbIsRegBitsOn(void __iomem *dwIoBase, unsigned char byBBAddr, unsigned char byTestBits);
90bool BBbIsRegBitsOff(void __iomem *dwIoBase, unsigned char byBBAddr, unsigned char byTestBits);
91void BBvSetVGAGainOffset(struct vnt_private *pDevice, unsigned char byData);
92 85
93/* VT3253 Baseband */ 86/* VT3253 Baseband */
94bool BBbVT3253Init(struct vnt_private *pDevice); 87bool BBbVT3253Init(struct vnt_private *);
95void BBvSoftwareReset(void __iomem *dwIoBase); 88void BBvSoftwareReset(struct vnt_private *);
96void BBvPowerSaveModeON(void __iomem *dwIoBase); 89void BBvPowerSaveModeON(struct vnt_private *);
97void BBvPowerSaveModeOFF(void __iomem *dwIoBase); 90void BBvPowerSaveModeOFF(struct vnt_private *);
98void BBvSetTxAntennaMode(void __iomem *dwIoBase, unsigned char byAntennaMode); 91void BBvSetTxAntennaMode(struct vnt_private *, unsigned char byAntennaMode);
99void BBvSetRxAntennaMode(void __iomem *dwIoBase, unsigned char byAntennaMode); 92void BBvSetRxAntennaMode(struct vnt_private *, unsigned char byAntennaMode);
100void BBvSetDeepSleep(void __iomem *dwIoBase, unsigned char byLocalID); 93void BBvSetDeepSleep(struct vnt_private *, unsigned char byLocalID);
101void BBvExitDeepSleep(void __iomem *dwIoBase, unsigned char byLocalID); 94void BBvExitDeepSleep(struct vnt_private *, unsigned char byLocalID);
102 95
103/* timer for antenna diversity */ 96/* timer for antenna diversity */
104 97
105void 98void
106TimerSQ3CallBack( 99TimerSQ3CallBack(
107 void *hDeviceContext 100 unsigned long
108); 101);
109 102
110void 103void
111TimerState1CallBack( 104TimerState1CallBack(
112 void *hDeviceContext 105 unsigned long
113); 106);
114 107
115void BBvAntennaDiversity(struct vnt_private *pDevice, 108void BBvAntennaDiversity(struct vnt_private *,
116 unsigned char byRxRate, unsigned char bySQ3); 109 unsigned char byRxRate, unsigned char bySQ3);
117void 110void
118BBvClearAntDivSQ3Value(struct vnt_private *pDevice); 111BBvClearAntDivSQ3Value(struct vnt_private *);
119 112
120#endif /* __BASEBAND_H__ */ 113#endif /* __BASEBAND_H__ */
diff --git a/drivers/staging/vt6655/bssdb.c b/drivers/staging/vt6655/bssdb.c
deleted file mode 100644
index 996d3302ce3d..000000000000
--- a/drivers/staging/vt6655/bssdb.c
+++ /dev/null
@@ -1,1512 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: bssdb.c
20 *
21 * Purpose: Handles the Basic Service Set & Node Database functions
22 *
23 * Functions:
24 * BSSpSearchBSSList - Search known BSS list for Desire SSID or BSSID
25 * BSSvClearBSSList - Clear BSS List
26 * BSSbInsertToBSSList - Insert a BSS set into known BSS list
27 * BSSbUpdateToBSSList - Update BSS set in known BSS list
28 * BSSDBbIsSTAInNodeDB - Search Node DB table to find the index of matched DstAddr
29 * BSSvCreateOneNode - Allocate an Node for Node DB
30 * BSSvUpdateAPNode - Update AP Node content in Index 0 of KnownNodeDB
31 * BSSvSecondCallBack - One second timer callback function to update Node DB info & AP link status
32 * BSSvUpdateNodeTxCounter - Update Tx attemps, Tx failure counter in Node DB for auto-fall back rate control
33 *
34 * Revision History:
35 *
36 * Author: Lyndon Chen
37 *
38 * Date: July 17, 2002
39 *
40 */
41
42#include "ttype.h"
43#include "tmacro.h"
44#include "tether.h"
45#include "device.h"
46#include "80211hdr.h"
47#include "bssdb.h"
48#include "wmgr.h"
49#include "datarate.h"
50#include "desc.h"
51#include "wcmd.h"
52#include "wpa.h"
53#include "baseband.h"
54#include "rf.h"
55#include "card.h"
56#include "channel.h"
57#include "mac.h"
58#include "wpa2.h"
59#include "iowpa.h"
60
61/*--------------------- Static Definitions -------------------------*/
62
63/*--------------------- Static Classes ----------------------------*/
64
65/*--------------------- Static Variables --------------------------*/
66static const unsigned short awHWRetry0[5][5] = {
67 {RATE_18M, RATE_18M, RATE_12M, RATE_12M, RATE_12M},
68 {RATE_24M, RATE_24M, RATE_18M, RATE_12M, RATE_12M},
69 {RATE_36M, RATE_36M, RATE_24M, RATE_18M, RATE_18M},
70 {RATE_48M, RATE_48M, RATE_36M, RATE_24M, RATE_24M},
71 {RATE_54M, RATE_54M, RATE_48M, RATE_36M, RATE_36M}
72};
73static const unsigned short awHWRetry1[5][5] = {
74 {RATE_18M, RATE_18M, RATE_12M, RATE_6M, RATE_6M},
75 {RATE_24M, RATE_24M, RATE_18M, RATE_6M, RATE_6M},
76 {RATE_36M, RATE_36M, RATE_24M, RATE_12M, RATE_12M},
77 {RATE_48M, RATE_48M, RATE_24M, RATE_12M, RATE_12M},
78 {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M}
79};
80
81/*--------------------- Static Functions --------------------------*/
82
83void s_vCheckSensitivity(
84 void *hDeviceContext
85);
86
87#ifdef Calcu_LinkQual
88void s_uCalculateLinkQual(
89 void *hDeviceContext
90);
91#endif
92
93void s_vCheckPreEDThreshold(
94 void *hDeviceContext
95);
96/*--------------------- Export Variables --------------------------*/
97
98/*--------------------- Export Functions --------------------------*/
99
100/*+
101 *
102 * Routine Description:
103 * Search known BSS list for Desire SSID or BSSID.
104 *
105 * Return Value:
106 * PTR to KnownBSS or NULL
107 *
108 -*/
109
110PKnownBSS
111BSSpSearchBSSList(
112 void *hDeviceContext,
113 unsigned char *pbyDesireBSSID,
114 unsigned char *pbyDesireSSID,
115 CARD_PHY_TYPE ePhyType
116)
117{
118 struct vnt_private *pDevice = hDeviceContext;
119 PSMgmtObject pMgmt = pDevice->pMgmt;
120 unsigned char *pbyBSSID = NULL;
121 PWLAN_IE_SSID pSSID = NULL;
122 PKnownBSS pCurrBSS = NULL;
123 PKnownBSS pSelect = NULL;
124 unsigned char ZeroBSSID[WLAN_BSSID_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
125 unsigned int ii = 0;
126
127 if (pbyDesireBSSID != NULL) {
128 pr_debug("BSSpSearchBSSList BSSID[%pM]\n", pbyDesireBSSID);
129 if ((!is_broadcast_ether_addr(pbyDesireBSSID)) &&
130 (memcmp(pbyDesireBSSID, ZeroBSSID, 6) != 0))
131 pbyBSSID = pbyDesireBSSID;
132 }
133 if (pbyDesireSSID != NULL) {
134 if (((PWLAN_IE_SSID)pbyDesireSSID)->len != 0)
135 pSSID = (PWLAN_IE_SSID) pbyDesireSSID;
136 }
137
138 if (pbyBSSID != NULL) {
139 /* match BSSID first */
140 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
141 pCurrBSS = &(pMgmt->sBSSList[ii]);
142 if (!pDevice->bLinkPass)
143 pCurrBSS->bSelected = false;
144 if ((pCurrBSS->bActive) &&
145 (!pCurrBSS->bSelected)) {
146 if (ether_addr_equal(pCurrBSS->abyBSSID,
147 pbyBSSID)) {
148 if (pSSID != NULL) {
149 /* compare ssid */
150 if (!memcmp(pSSID->abySSID,
151 ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
152 pSSID->len)) {
153 if ((pMgmt->eConfigMode == WMAC_CONFIG_AUTO) ||
154 ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
155 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))
156) {
157 pCurrBSS->bSelected = true;
158 return pCurrBSS;
159 }
160 }
161 } else {
162 if ((pMgmt->eConfigMode == WMAC_CONFIG_AUTO) ||
163 ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
164 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))
165) {
166 pCurrBSS->bSelected = true;
167 return pCurrBSS;
168 }
169 }
170 }
171 }
172 }
173 } else {
174 /* ignore BSSID */
175 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
176 pCurrBSS = &(pMgmt->sBSSList[ii]);
177 /* 2007-0721-01<Add>by MikeLiu */
178 pCurrBSS->bSelected = false;
179 if (pCurrBSS->bActive) {
180 if (pSSID != NULL) {
181 /* matched SSID */
182 if (!!memcmp(pSSID->abySSID,
183 ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
184 pSSID->len) ||
185 (pSSID->len != ((PWLAN_IE_SSID)pCurrBSS->abySSID)->len)) {
186 /* SSID not match skip this BSS */
187 continue;
188 }
189 }
190 if (((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo)) ||
191 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo))
192) {
193 /* Type not match skip this BSS */
194 pr_debug("BSS type mismatch.... Config[%d] BSS[0x%04x]\n",
195 pMgmt->eConfigMode,
196 pCurrBSS->wCapInfo);
197 continue;
198 }
199
200 if (ePhyType != PHY_TYPE_AUTO) {
201 if (((ePhyType == PHY_TYPE_11A) && (PHY_TYPE_11A != pCurrBSS->eNetworkTypeInUse)) ||
202 ((ePhyType != PHY_TYPE_11A) && (PHY_TYPE_11A == pCurrBSS->eNetworkTypeInUse))) {
203 /* PhyType not match skip this BSS */
204 pr_debug("Physical type mismatch.... ePhyType[%d] BSS[%d]\n",
205 ePhyType,
206 pCurrBSS->eNetworkTypeInUse);
207 continue;
208 }
209 }
210
211 if (pSelect == NULL) {
212 pSelect = pCurrBSS;
213 } else {
214 /* compare RSSI, select signal strong one */
215 if (pCurrBSS->uRSSI < pSelect->uRSSI)
216 pSelect = pCurrBSS;
217 }
218 }
219 }
220 if (pSelect != NULL) {
221 pSelect->bSelected = true;
222 return pSelect;
223 }
224 }
225 return NULL;
226}
227
228/*+
229 *
230 * Routine Description:
231 * Clear BSS List
232 *
233 * Return Value:
234 * None.
235 *
236 -*/
237
238void
239BSSvClearBSSList(
240 void *hDeviceContext,
241 bool bKeepCurrBSSID
242)
243{
244 struct vnt_private *pDevice = hDeviceContext;
245 PSMgmtObject pMgmt = pDevice->pMgmt;
246 unsigned int ii;
247
248 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
249 if (bKeepCurrBSSID) {
250 if (pMgmt->sBSSList[ii].bActive &&
251 ether_addr_equal(pMgmt->sBSSList[ii].abyBSSID,
252 pMgmt->abyCurrBSSID)) {
253 continue;
254 }
255 }
256
257 if ((pMgmt->sBSSList[ii].bActive) && (pMgmt->sBSSList[ii].uClearCount < BSS_CLEAR_COUNT)) {
258 pMgmt->sBSSList[ii].uClearCount++;
259 continue;
260 }
261
262 pMgmt->sBSSList[ii].bActive = false;
263 memset(&pMgmt->sBSSList[ii], 0, sizeof(KnownBSS));
264 }
265 BSSvClearAnyBSSJoinRecord(pDevice);
266}
267
268/*+
269 *
270 * Routine Description:
271 * search BSS list by BSSID & SSID if matched
272 *
273 * Return Value:
274 * true if found.
275 *
276 -*/
277PKnownBSS
278BSSpAddrIsInBSSList(
279 void *hDeviceContext,
280 unsigned char *abyBSSID,
281 PWLAN_IE_SSID pSSID
282)
283{
284 struct vnt_private *pDevice = hDeviceContext;
285 PSMgmtObject pMgmt = pDevice->pMgmt;
286 PKnownBSS pBSSList = NULL;
287 unsigned int ii;
288
289 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
290 pBSSList = &(pMgmt->sBSSList[ii]);
291 if (pBSSList->bActive) {
292 if (ether_addr_equal(pBSSList->abyBSSID, abyBSSID)) {
293 if (pSSID->len == ((PWLAN_IE_SSID)pBSSList->abySSID)->len) {
294 if (memcmp(pSSID->abySSID,
295 ((PWLAN_IE_SSID)pBSSList->abySSID)->abySSID,
296 pSSID->len) == 0)
297 return pBSSList;
298 }
299 }
300 }
301 }
302
303 return NULL;
304};
305
306/*+
307 *
308 * Routine Description:
309 * Insert a BSS set into known BSS list
310 *
311 * Return Value:
312 * true if success.
313 *
314 -*/
315
316bool
317BSSbInsertToBSSList(
318 void *hDeviceContext,
319 unsigned char *abyBSSIDAddr,
320 __le64 qwTimestamp,
321 unsigned short wBeaconInterval,
322 unsigned short wCapInfo,
323 unsigned char byCurrChannel,
324 PWLAN_IE_SSID pSSID,
325 PWLAN_IE_SUPP_RATES pSuppRates,
326 PWLAN_IE_SUPP_RATES pExtSuppRates,
327 PERPObject psERP,
328 PWLAN_IE_RSN pRSN,
329 PWLAN_IE_RSN_EXT pRSNWPA,
330 PWLAN_IE_COUNTRY pIE_Country,
331 PWLAN_IE_QUIET pIE_Quiet,
332 unsigned int uIELength,
333 unsigned char *pbyIEs,
334 void *pRxPacketContext
335)
336{
337 struct vnt_private *pDevice = hDeviceContext;
338 PSMgmtObject pMgmt = pDevice->pMgmt;
339 PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
340 PKnownBSS pBSSList = NULL;
341 unsigned int ii;
342 bool bParsingQuiet = false;
343 PWLAN_IE_QUIET pQuiet = NULL;
344
345 pBSSList = (PKnownBSS)&(pMgmt->sBSSList[0]);
346
347 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
348 pBSSList = (PKnownBSS)&(pMgmt->sBSSList[ii]);
349 if (!pBSSList->bActive)
350 break;
351 }
352
353 if (ii == MAX_BSS_NUM) {
354 pr_debug("Get free KnowBSS node failed\n");
355 return false;
356 }
357 /* save the BSS info */
358 pBSSList->bActive = true;
359 memcpy(pBSSList->abyBSSID, abyBSSIDAddr, WLAN_BSSID_LEN);
360 pBSSList->qwBSSTimestamp = le64_to_cpu(qwTimestamp);
361 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
362 pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
363 pBSSList->uClearCount = 0;
364
365 if (pSSID->len > WLAN_SSID_MAXLEN)
366 pSSID->len = WLAN_SSID_MAXLEN;
367 memcpy(pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
368
369 pBSSList->uChannel = byCurrChannel;
370
371 if (pSuppRates->len > WLAN_RATES_MAXLEN)
372 pSuppRates->len = WLAN_RATES_MAXLEN;
373 memcpy(pBSSList->abySuppRates, pSuppRates, pSuppRates->len + WLAN_IEHDR_LEN);
374
375 if (pExtSuppRates != NULL) {
376 if (pExtSuppRates->len > WLAN_RATES_MAXLEN)
377 pExtSuppRates->len = WLAN_RATES_MAXLEN;
378 memcpy(pBSSList->abyExtSuppRates, pExtSuppRates, pExtSuppRates->len + WLAN_IEHDR_LEN);
379 pr_debug("BSSbInsertToBSSList: pExtSuppRates->len = %d\n",
380 pExtSuppRates->len);
381
382 } else {
383 memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
384 }
385 pBSSList->sERP.byERP = psERP->byERP;
386 pBSSList->sERP.bERPExist = psERP->bERPExist;
387
388 /* check if BSS is 802.11a/b/g */
389 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
390 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
391 } else {
392 if (pBSSList->sERP.bERPExist)
393 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
394 else
395 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
396 }
397
398 pBSSList->byRxRate = pRxPacket->byRxRate;
399 pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
400 pBSSList->uRSSI = pRxPacket->uRSSI;
401 pBSSList->bySQ = pRxPacket->bySQ;
402
403 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
404 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
405 /* assoc with BSS */
406 if (pBSSList == pMgmt->pCurrBSS)
407 bParsingQuiet = true;
408 }
409
410 WPA_ClearRSN(pBSSList);
411
412 if (pRSNWPA != NULL) {
413 unsigned int uLen = pRSNWPA->len + 2;
414
415 if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSNWPA - pbyIEs))) {
416 pBSSList->wWPALen = uLen;
417 memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
418 WPA_ParseRSN(pBSSList, pRSNWPA);
419 }
420 }
421
422 WPA2_ClearRSN(pBSSList);
423
424 if (pRSN != NULL) {
425 unsigned int uLen = pRSN->len + 2;
426
427 if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSN - pbyIEs))) {
428 pBSSList->wRSNLen = uLen;
429 memcpy(pBSSList->byRSNIE, pRSN, uLen);
430 WPA2vParseRSN(pBSSList, pRSN);
431 }
432 }
433
434 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) || pBSSList->bWPA2Valid) {
435 PSKeyItem pTransmitKey = NULL;
436 bool bIs802_1x = false;
437
438 for (ii = 0; ii < pBSSList->wAKMSSAuthCount; ii++) {
439 if (pBSSList->abyAKMSSAuthType[ii] == WLAN_11i_AKMSS_802_1X) {
440 bIs802_1x = true;
441 break;
442 }
443 }
444 if (bIs802_1x && (pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len) &&
445 (!memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID, pSSID->len))) {
446 bAdd_PMKID_Candidate((void *)pDevice, pBSSList->abyBSSID, &pBSSList->sRSNCapObj);
447
448 if (pDevice->bLinkPass && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
449 if (KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, PAIRWISE_KEY, &pTransmitKey) ||
450 KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, GROUP_KEY, &pTransmitKey)) {
451 pDevice->gsPMKIDCandidate.StatusType = Ndis802_11StatusType_PMKID_CandidateList;
452 pDevice->gsPMKIDCandidate.Version = 1;
453
454 }
455
456 }
457 }
458 }
459
460 if (pDevice->bUpdateBBVGA) {
461 /* monitor if RSSI is too strong */
462 pBSSList->byRSSIStatCnt = 0;
463 RFvRSSITodBm(pDevice, (unsigned char)(pRxPacket->uRSSI), &pBSSList->ldBmMAX);
464 pBSSList->ldBmAverage[0] = pBSSList->ldBmMAX;
465 for (ii = 1; ii < RSSI_STAT_COUNT; ii++)
466 pBSSList->ldBmAverage[ii] = 0;
467 }
468
469 if ((pIE_Country != NULL) && pMgmt->b11hEnable) {
470 set_country_info(pMgmt->pAdapter, pBSSList->eNetworkTypeInUse,
471 pIE_Country);
472 }
473
474 if (bParsingQuiet && (pIE_Quiet != NULL)) {
475 if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
476 (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
477 /* valid EID */
478 if (pQuiet == NULL) {
479 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
480 CARDbSetQuiet(pMgmt->pAdapter,
481 true,
482 pQuiet->byQuietCount,
483 pQuiet->byQuietPeriod,
484 *((unsigned short *)pQuiet->abyQuietDuration),
485 *((unsigned short *)pQuiet->abyQuietOffset)
486);
487 } else {
488 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
489 CARDbSetQuiet(pMgmt->pAdapter,
490 false,
491 pQuiet->byQuietCount,
492 pQuiet->byQuietPeriod,
493 *((unsigned short *)pQuiet->abyQuietDuration),
494 *((unsigned short *)pQuiet->abyQuietOffset)
495 );
496 }
497 }
498 }
499
500 if (bParsingQuiet && (pQuiet != NULL))
501 CARDbStartQuiet(pMgmt->pAdapter);
502
503 pBSSList->uIELength = uIELength;
504 if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
505 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
506 memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
507
508 return true;
509}
510
511/*+
512 *
513 * Routine Description:
514 * Update BSS set in known BSS list
515 *
516 * Return Value:
517 * true if success.
518 *
519 -*/
520/* TODO: input structure modify */
521
522bool
523BSSbUpdateToBSSList(
524 void *hDeviceContext,
525 __le64 qwTimestamp,
526 unsigned short wBeaconInterval,
527 unsigned short wCapInfo,
528 unsigned char byCurrChannel,
529 bool bChannelHit,
530 PWLAN_IE_SSID pSSID,
531 PWLAN_IE_SUPP_RATES pSuppRates,
532 PWLAN_IE_SUPP_RATES pExtSuppRates,
533 PERPObject psERP,
534 PWLAN_IE_RSN pRSN,
535 PWLAN_IE_RSN_EXT pRSNWPA,
536 PWLAN_IE_COUNTRY pIE_Country,
537 PWLAN_IE_QUIET pIE_Quiet,
538 PKnownBSS pBSSList,
539 unsigned int uIELength,
540 unsigned char *pbyIEs,
541 void *pRxPacketContext
542)
543{
544 int ii;
545 struct vnt_private *pDevice = hDeviceContext;
546 PSMgmtObject pMgmt = pDevice->pMgmt;
547 PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
548 long ldBm;
549 bool bParsingQuiet = false;
550 PWLAN_IE_QUIET pQuiet = NULL;
551
552 if (pBSSList == NULL)
553 return false;
554
555 pBSSList->qwBSSTimestamp = le64_to_cpu(qwTimestamp);
556 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
557 pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
558 pBSSList->uClearCount = 0;
559 pBSSList->uChannel = byCurrChannel;
560
561 if (pSSID->len > WLAN_SSID_MAXLEN)
562 pSSID->len = WLAN_SSID_MAXLEN;
563
564 if ((pSSID->len != 0) && (pSSID->abySSID[0] != 0))
565 memcpy(pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
566 memcpy(pBSSList->abySuppRates, pSuppRates, pSuppRates->len + WLAN_IEHDR_LEN);
567
568 if (pExtSuppRates != NULL)
569 memcpy(pBSSList->abyExtSuppRates, pExtSuppRates, pExtSuppRates->len + WLAN_IEHDR_LEN);
570 else
571 memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
572 pBSSList->sERP.byERP = psERP->byERP;
573 pBSSList->sERP.bERPExist = psERP->bERPExist;
574
575 /* check if BSS is 802.11a/b/g */
576 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
577 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
578 } else {
579 if (pBSSList->sERP.bERPExist)
580 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
581 else
582 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
583 }
584
585 pBSSList->byRxRate = pRxPacket->byRxRate;
586 pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
587 if (bChannelHit)
588 pBSSList->uRSSI = pRxPacket->uRSSI;
589 pBSSList->bySQ = pRxPacket->bySQ;
590
591 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
592 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
593 /* assoc with BSS */
594 if (pBSSList == pMgmt->pCurrBSS)
595 bParsingQuiet = true;
596 }
597
598 WPA_ClearRSN(pBSSList); /* mike update */
599
600 if (pRSNWPA != NULL) {
601 unsigned int uLen = pRSNWPA->len + 2;
602
603 if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSNWPA - pbyIEs))) {
604 pBSSList->wWPALen = uLen;
605 memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
606 WPA_ParseRSN(pBSSList, pRSNWPA);
607 }
608 }
609
610 WPA2_ClearRSN(pBSSList); /* mike update */
611
612 if (pRSN != NULL) {
613 unsigned int uLen = pRSN->len + 2;
614
615 if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSN - pbyIEs))) {
616 pBSSList->wRSNLen = uLen;
617 memcpy(pBSSList->byRSNIE, pRSN, uLen);
618 WPA2vParseRSN(pBSSList, pRSN);
619 }
620 }
621
622 if (pRxPacket->uRSSI != 0) {
623 RFvRSSITodBm(pDevice, (unsigned char)(pRxPacket->uRSSI), &ldBm);
624 /* monitor if RSSI is too strong */
625 pBSSList->byRSSIStatCnt++;
626 pBSSList->byRSSIStatCnt %= RSSI_STAT_COUNT;
627 pBSSList->ldBmAverage[pBSSList->byRSSIStatCnt] = ldBm;
628 for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
629 if (pBSSList->ldBmAverage[ii] != 0)
630 pBSSList->ldBmMAX = max(pBSSList->ldBmAverage[ii], ldBm);
631 }
632 }
633
634 if ((pIE_Country != NULL) && pMgmt->b11hEnable) {
635 set_country_info(pMgmt->pAdapter, pBSSList->eNetworkTypeInUse,
636 pIE_Country);
637 }
638
639 if (bParsingQuiet && (pIE_Quiet != NULL)) {
640 if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
641 (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
642 /* valid EID */
643 if (pQuiet == NULL) {
644 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
645 CARDbSetQuiet(pMgmt->pAdapter,
646 true,
647 pQuiet->byQuietCount,
648 pQuiet->byQuietPeriod,
649 *((unsigned short *)pQuiet->abyQuietDuration),
650 *((unsigned short *)pQuiet->abyQuietOffset)
651);
652 } else {
653 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
654 CARDbSetQuiet(pMgmt->pAdapter,
655 false,
656 pQuiet->byQuietCount,
657 pQuiet->byQuietPeriod,
658 *((unsigned short *)pQuiet->abyQuietDuration),
659 *((unsigned short *)pQuiet->abyQuietOffset)
660 );
661 }
662 }
663 }
664
665 if (bParsingQuiet && (pQuiet != NULL))
666 CARDbStartQuiet(pMgmt->pAdapter);
667
668 pBSSList->uIELength = uIELength;
669 if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
670 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
671 memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
672
673 return true;
674}
675
676/*+
677 *
678 * Routine Description:
679 * Search Node DB table to find the index of matched DstAddr
680 *
681 * Return Value:
682 * None
683 *
684 -*/
685
686bool
687BSSDBbIsSTAInNodeDB(void *pMgmtObject, unsigned char *abyDstAddr,
688 unsigned int *puNodeIndex)
689{
690 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
691 unsigned int ii;
692
693 /* Index = 0 reserved for AP Node */
694 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
695 if (pMgmt->sNodeDBTable[ii].bActive) {
696 if (ether_addr_equal(abyDstAddr,
697 pMgmt->sNodeDBTable[ii].abyMACAddr)) {
698 *puNodeIndex = ii;
699 return true;
700 }
701 }
702 }
703
704 return false;
705};
706
707/*+
708 *
709 * Routine Description:
710 * Find an empty node and allocat it; if there is no empty node,
711 * then use the most inactive one.
712 *
713 * Return Value:
714 * None
715 *
716 -*/
717void
718BSSvCreateOneNode(void *hDeviceContext, unsigned int *puNodeIndex)
719{
720 struct vnt_private *pDevice = hDeviceContext;
721 PSMgmtObject pMgmt = pDevice->pMgmt;
722 unsigned int ii;
723 unsigned int BigestCount = 0;
724 unsigned int SelectIndex;
725 struct sk_buff *skb;
726 /*
727 * Index = 0 reserved for AP Node (In STA mode)
728 * Index = 0 reserved for Broadcast/MultiCast (In AP mode)
729 */
730 SelectIndex = 1;
731 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
732 if (pMgmt->sNodeDBTable[ii].bActive) {
733 if (pMgmt->sNodeDBTable[ii].uInActiveCount > BigestCount) {
734 BigestCount = pMgmt->sNodeDBTable[ii].uInActiveCount;
735 SelectIndex = ii;
736 }
737 } else {
738 break;
739 }
740 }
741
742 /* if not found replace uInActiveCount is largest one */
743 if (ii == (MAX_NODE_NUM + 1)) {
744 *puNodeIndex = SelectIndex;
745 pr_info("Replace inactive node = %d\n", SelectIndex);
746 /* clear ps buffer */
747 if (pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue.next != NULL) {
748 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue)) != NULL)
749 dev_kfree_skb(skb);
750 }
751 } else {
752 *puNodeIndex = ii;
753 }
754
755 memset(&pMgmt->sNodeDBTable[*puNodeIndex], 0, sizeof(KnownNodeDB));
756 pMgmt->sNodeDBTable[*puNodeIndex].bActive = true;
757 pMgmt->sNodeDBTable[*puNodeIndex].uRatePollTimeout = FALLBACK_POLL_SECOND;
758 /* for AP mode PS queue */
759 skb_queue_head_init(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue);
760 pMgmt->sNodeDBTable[*puNodeIndex].byAuthSequence = 0;
761 pMgmt->sNodeDBTable[*puNodeIndex].wEnQueueCnt = 0;
762 pr_debug("Create node index = %d\n", ii);
763 return;
764};
765
766/*+
767 *
768 * Routine Description:
769 * Remove Node by NodeIndex
770 *
771 *
772 * Return Value:
773 * None
774 *
775 -*/
776void
777BSSvRemoveOneNode(
778 void *hDeviceContext,
779 unsigned int uNodeIndex
780)
781{
782 struct vnt_private *pDevice = hDeviceContext;
783 PSMgmtObject pMgmt = pDevice->pMgmt;
784 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
785 struct sk_buff *skb;
786
787 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue)) != NULL)
788 dev_kfree_skb(skb);
789 /* clear context */
790 memset(&pMgmt->sNodeDBTable[uNodeIndex], 0, sizeof(KnownNodeDB));
791 /* clear tx bit map */
792 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[uNodeIndex].wAID >> 3] &= ~byMask[pMgmt->sNodeDBTable[uNodeIndex].wAID & 7];
793
794 return;
795};
796/*+
797 *
798 * Routine Description:
799 * Update AP Node content in Index 0 of KnownNodeDB
800 *
801 *
802 * Return Value:
803 * None
804 *
805 -*/
806
807void
808BSSvUpdateAPNode(
809 void *hDeviceContext,
810 unsigned short *pwCapInfo,
811 PWLAN_IE_SUPP_RATES pSuppRates,
812 PWLAN_IE_SUPP_RATES pExtSuppRates
813)
814{
815 struct vnt_private *pDevice = hDeviceContext;
816 PSMgmtObject pMgmt = pDevice->pMgmt;
817 unsigned int uRateLen = WLAN_RATES_MAXLEN;
818
819 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
820
821 pMgmt->sNodeDBTable[0].bActive = true;
822 if (pDevice->eCurrentPHYType == PHY_TYPE_11B)
823 uRateLen = WLAN_RATES_MAXLEN_11B;
824 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pSuppRates,
825 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
826 uRateLen);
827 pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pExtSuppRates,
828 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
829 uRateLen);
830 RATEvParseMaxRate((void *)pDevice,
831 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
832 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
833 true,
834 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
835 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
836 &(pMgmt->sNodeDBTable[0].wSuppRate),
837 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
838 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
839);
840 memcpy(pMgmt->sNodeDBTable[0].abyMACAddr, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
841 pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxSuppRate;
842 pMgmt->sNodeDBTable[0].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*pwCapInfo);
843 pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
844 netdev_dbg(pDevice->dev, "BSSvUpdateAPNode:MaxSuppRate is %d\n",
845 pMgmt->sNodeDBTable[0].wMaxSuppRate);
846 /* auto rate fallback function initiation */
847 pr_debug("pMgmt->sNodeDBTable[0].wTxDataRate = %d\n",
848 pMgmt->sNodeDBTable[0].wTxDataRate);
849};
850
851/*+
852 *
853 * Routine Description:
854 * Add Multicast Node content in Index 0 of KnownNodeDB
855 *
856 *
857 * Return Value:
858 * None
859 *
860 -*/
861
862void
863BSSvAddMulticastNode(
864 void *hDeviceContext
865)
866{
867 struct vnt_private *pDevice = hDeviceContext;
868 PSMgmtObject pMgmt = pDevice->pMgmt;
869
870 if (!pDevice->bEnableHostWEP)
871 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
872 memset(pMgmt->sNodeDBTable[0].abyMACAddr, 0xff, WLAN_ADDR_LEN);
873 pMgmt->sNodeDBTable[0].bActive = true;
874 pMgmt->sNodeDBTable[0].bPSEnable = false;
875 skb_queue_head_init(&pMgmt->sNodeDBTable[0].sTxPSQueue);
876 RATEvParseMaxRate((void *)pDevice,
877 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
878 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
879 true,
880 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
881 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
882 &(pMgmt->sNodeDBTable[0].wSuppRate),
883 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
884 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
885);
886 pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxBasicRate;
887 netdev_dbg(pDevice->dev,
888 "BSSvAddMultiCastNode:pMgmt->sNodeDBTable[0].wTxDataRate is %d\n",
889 pMgmt->sNodeDBTable[0].wTxDataRate);
890 pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
891};
892
893/*+
894 *
895 * Routine Description:
896 *
897 *
898 * Second call back function to update Node DB info & AP link status
899 *
900 *
901 * Return Value:
902 * none.
903 *
904 -*/
905void
906BSSvSecondCallBack(
907 void *hDeviceContext
908)
909{
910 struct vnt_private *pDevice = hDeviceContext;
911 PSMgmtObject pMgmt = pDevice->pMgmt;
912 unsigned int ii;
913 PWLAN_IE_SSID pItemSSID, pCurrSSID;
914 unsigned int uSleepySTACnt = 0;
915 unsigned int uNonShortSlotSTACnt = 0;
916 unsigned int uLongPreambleSTACnt = 0;
917 viawget_wpa_header *wpahdr; /* DavidWang */
918
919 spin_lock_irq(&pDevice->lock);
920
921 pDevice->uAssocCount = 0;
922
923 pDevice->byERPFlag &=
924 ~(WLAN_SET_ERP_BARKER_MODE(1) | WLAN_SET_ERP_NONERP_PRESENT(1));
925
926 if (pDevice->wUseProtectCntDown > 0) {
927 pDevice->wUseProtectCntDown--;
928 } else {
929 /* disable protect mode */
930 pDevice->byERPFlag &= ~(WLAN_SET_ERP_USE_PROTECTION(1));
931 }
932
933 if (pDevice->eCommandState == WLAN_ASSOCIATE_WAIT) {
934 pDevice->byReAssocCount++;
935 /* 10 sec timeout */
936 if ((pDevice->byReAssocCount > 10) && (!pDevice->bLinkPass)) {
937 netdev_info(pDevice->dev, "Re-association timeout!!!\n");
938 pDevice->byReAssocCount = 0;
939#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
940 {
941 union iwreq_data wrqu;
942
943 memset(&wrqu, 0, sizeof(wrqu));
944 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
945 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
946 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
947 }
948#endif
949 } else if (pDevice->bLinkPass)
950 pDevice->byReAssocCount = 0;
951 }
952
953#ifdef Calcu_LinkQual
954 s_uCalculateLinkQual((void *)pDevice);
955#endif
956
957 for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
958 if (pMgmt->sNodeDBTable[ii].bActive) {
959 /* increase in-activity counter */
960 pMgmt->sNodeDBTable[ii].uInActiveCount++;
961
962 if (ii > 0) {
963 if (pMgmt->sNodeDBTable[ii].uInActiveCount > MAX_INACTIVE_COUNT) {
964 BSSvRemoveOneNode(pDevice, ii);
965 pr_debug("Inactive timeout [%d] sec, STA index = [%d] remove\n",
966 MAX_INACTIVE_COUNT, ii);
967 continue;
968 }
969
970 if (pMgmt->sNodeDBTable[ii].eNodeState >= NODE_ASSOC) {
971 pDevice->uAssocCount++;
972
973 /* check if Non ERP exist */
974 if (pMgmt->sNodeDBTable[ii].uInActiveCount < ERP_RECOVER_COUNT) {
975 if (!pMgmt->sNodeDBTable[ii].bShortPreamble) {
976 pDevice->byERPFlag |= WLAN_SET_ERP_BARKER_MODE(1);
977 uLongPreambleSTACnt++;
978 }
979 if (!pMgmt->sNodeDBTable[ii].bERPExist) {
980 pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
981 pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
982 }
983 if (!pMgmt->sNodeDBTable[ii].bShortSlotTime)
984 uNonShortSlotSTACnt++;
985 }
986 }
987
988 /* check if any STA in PS mode */
989 if (pMgmt->sNodeDBTable[ii].bPSEnable)
990 uSleepySTACnt++;
991
992 }
993
994 /* rate fallback check */
995 if (!pDevice->bFixRate) {
996 if (ii > 0) {
997 /* ii = 0 for multicast node (AP & Adhoc) */
998 RATEvTxRateFallBack((void *)pDevice, &(pMgmt->sNodeDBTable[ii]));
999 } else {
1000 /* ii = 0 reserved for unicast AP node (Infra STA) */
1001 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)
1002 netdev_dbg(pDevice->dev,
1003 "SecondCallback:Before:TxDataRate is %d\n",
1004 pMgmt->sNodeDBTable[0].wTxDataRate);
1005 RATEvTxRateFallBack((void *)pDevice, &(pMgmt->sNodeDBTable[ii]));
1006 netdev_dbg(pDevice->dev,
1007 "SecondCallback:After:TxDataRate is %d\n",
1008 pMgmt->sNodeDBTable[0].wTxDataRate);
1009
1010 }
1011
1012 }
1013
1014 /* check if pending PS queue */
1015 if (pMgmt->sNodeDBTable[ii].wEnQueueCnt != 0) {
1016 pr_debug("Index= %d, Queue = %d pending\n",
1017 ii,
1018 pMgmt->sNodeDBTable[ii].wEnQueueCnt);
1019 if ((ii > 0) && (pMgmt->sNodeDBTable[ii].wEnQueueCnt > 15)) {
1020 BSSvRemoveOneNode(pDevice, ii);
1021 pr_info("Pending many queues PS STA Index = %d remove\n",
1022 ii);
1023 continue;
1024 }
1025 }
1026 }
1027
1028 }
1029
1030 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->eCurrentPHYType == PHY_TYPE_11G)) {
1031 /* on/off protect mode */
1032 if (WLAN_GET_ERP_USE_PROTECTION(pDevice->byERPFlag)) {
1033 if (!pDevice->bProtectMode) {
1034 MACvEnableProtectMD(pDevice->PortOffset);
1035 pDevice->bProtectMode = true;
1036 }
1037 } else {
1038 if (pDevice->bProtectMode) {
1039 MACvDisableProtectMD(pDevice->PortOffset);
1040 pDevice->bProtectMode = false;
1041 }
1042 }
1043 /* on/off short slot time */
1044
1045 if (uNonShortSlotSTACnt > 0) {
1046 if (pDevice->bShortSlotTime) {
1047 pDevice->bShortSlotTime = false;
1048 BBvSetShortSlotTime(pDevice);
1049 vUpdateIFS((void *)pDevice);
1050 }
1051 } else {
1052 if (!pDevice->bShortSlotTime) {
1053 pDevice->bShortSlotTime = true;
1054 BBvSetShortSlotTime(pDevice);
1055 vUpdateIFS((void *)pDevice);
1056 }
1057 }
1058
1059 /* on/off barker long preamble mode */
1060
1061 if (uLongPreambleSTACnt > 0) {
1062 if (!pDevice->bBarkerPreambleMd) {
1063 MACvEnableBarkerPreambleMd(pDevice->PortOffset);
1064 pDevice->bBarkerPreambleMd = true;
1065 }
1066 } else {
1067 if (pDevice->bBarkerPreambleMd) {
1068 MACvDisableBarkerPreambleMd(pDevice->PortOffset);
1069 pDevice->bBarkerPreambleMd = false;
1070 }
1071 }
1072
1073 }
1074
1075 /* check if any STA in PS mode, enable DTIM multicast deliver */
1076 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1077 if (uSleepySTACnt > 0)
1078 pMgmt->sNodeDBTable[0].bPSEnable = true;
1079 else
1080 pMgmt->sNodeDBTable[0].bPSEnable = false;
1081 }
1082
1083 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
1084 pCurrSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
1085
1086 if ((pMgmt->eCurrMode == WMAC_MODE_STANDBY) ||
1087 (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)) {
1088 /* assoc with BSS */
1089 if (pMgmt->sNodeDBTable[0].bActive) {
1090 if (pDevice->bUpdateBBVGA)
1091 s_vCheckPreEDThreshold((void *)pDevice);
1092
1093 if ((pMgmt->sNodeDBTable[0].uInActiveCount >= (LOST_BEACON_COUNT/2)) &&
1094 (pDevice->byBBVGACurrent != pDevice->abyBBVGA[0])) {
1095 pDevice->byBBVGANew = pDevice->abyBBVGA[0];
1096 bScheduleCommand((void *)pDevice, WLAN_CMD_CHANGE_BBSENSITIVITY, NULL);
1097 }
1098
1099 if (pMgmt->sNodeDBTable[0].uInActiveCount >= LOST_BEACON_COUNT) {
1100 pMgmt->sNodeDBTable[0].bActive = false;
1101 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1102 pMgmt->eCurrState = WMAC_STATE_IDLE;
1103 netif_stop_queue(pDevice->dev);
1104 pDevice->bLinkPass = false;
1105 pDevice->bRoaming = true;
1106 pr_info("Lost AP beacon [%d] sec, disconnected !\n",
1107 pMgmt->sNodeDBTable[0].uInActiveCount);
1108 if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
1109 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
1110 wpahdr->type = VIAWGET_DISASSOC_MSG;
1111 wpahdr->resp_ie_len = 0;
1112 wpahdr->req_ie_len = 0;
1113 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
1114 pDevice->skb->dev = pDevice->wpadev;
1115 skb_reset_mac_header(pDevice->skb);
1116 pDevice->skb->pkt_type = PACKET_HOST;
1117 pDevice->skb->protocol = htons(ETH_P_802_2);
1118 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
1119 netif_rx(pDevice->skb);
1120 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1121 }
1122#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1123 {
1124 union iwreq_data wrqu;
1125
1126 memset(&wrqu, 0, sizeof(wrqu));
1127 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1128 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
1129 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1130 }
1131#endif
1132 }
1133 } else if (pItemSSID->len != 0) {
1134 if (pDevice->uAutoReConnectTime < 10) {
1135 pDevice->uAutoReConnectTime++;
1136#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1137 /*
1138 * network manager support need not do
1139 * Roaming scan???
1140 */
1141 if (pDevice->bWPASuppWextEnabled)
1142 pDevice->uAutoReConnectTime = 0;
1143#endif
1144 } else {
1145 /*
1146 * mike use old encryption status
1147 * for wpa reauthentication
1148 */
1149 if (pDevice->bWPADEVUp)
1150 pDevice->eEncryptionStatus = pDevice->eOldEncryptionStatus;
1151
1152 pr_debug("Roaming ...\n");
1153 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
1154 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1155 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
1156 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
1157 pDevice->uAutoReConnectTime = 0;
1158 }
1159 }
1160 }
1161
1162 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1163 /* if adhoc started which essid is NULL string, rescanning */
1164 if ((pMgmt->eCurrState == WMAC_STATE_STARTED) && (pCurrSSID->len == 0)) {
1165 if (pDevice->uAutoReConnectTime < 10) {
1166 pDevice->uAutoReConnectTime++;
1167 } else {
1168 pr_info("Adhoc re-scanning ...\n");
1169 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1170 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1171 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
1172 pDevice->uAutoReConnectTime = 0;
1173 }
1174 }
1175 if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
1176 if (pDevice->bUpdateBBVGA)
1177 s_vCheckPreEDThreshold((void *)pDevice);
1178 if (pMgmt->sNodeDBTable[0].uInActiveCount >= ADHOC_LOST_BEACON_COUNT) {
1179 pr_info("Lost other STA beacon [%d] sec, started !\n",
1180 pMgmt->sNodeDBTable[0].uInActiveCount);
1181 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
1182 pMgmt->eCurrState = WMAC_STATE_STARTED;
1183 netif_stop_queue(pDevice->dev);
1184 pDevice->bLinkPass = false;
1185 }
1186 }
1187 }
1188
1189 spin_unlock_irq(&pDevice->lock);
1190
1191 pMgmt->sTimerSecondCallback.expires = RUN_AT(HZ);
1192 add_timer(&pMgmt->sTimerSecondCallback);
1193}
1194
1195/*+
1196 *
1197 * Routine Description:
1198 *
1199 *
1200 * Update Tx attemps, Tx failure counter in Node DB
1201 *
1202 *
1203 * Return Value:
1204 * none.
1205 *
1206 -*/
1207
1208void
1209BSSvUpdateNodeTxCounter(
1210 void *hDeviceContext,
1211 unsigned char byTsr0,
1212 unsigned char byTsr1,
1213 unsigned char *pbyBuffer,
1214 unsigned int uFIFOHeaderSize
1215)
1216{
1217 struct vnt_private *pDevice = hDeviceContext;
1218 PSMgmtObject pMgmt = pDevice->pMgmt;
1219 unsigned int uNodeIndex = 0;
1220 unsigned char byTxRetry = (byTsr0 & TSR0_NCR);
1221 PSTxBufHead pTxBufHead;
1222 PS802_11Header pMACHeader;
1223 unsigned short wRate;
1224 unsigned short wFallBackRate = RATE_1M;
1225 unsigned char byFallBack;
1226 unsigned int ii;
1227
1228 pTxBufHead = (PSTxBufHead) pbyBuffer;
1229 if (pTxBufHead->wFIFOCtl & FIFOCTL_AUTO_FB_0)
1230 byFallBack = AUTO_FB_0;
1231 else if (pTxBufHead->wFIFOCtl & FIFOCTL_AUTO_FB_1)
1232 byFallBack = AUTO_FB_1;
1233 else
1234 byFallBack = AUTO_FB_NONE;
1235 wRate = pTxBufHead->wReserved;
1236
1237 /* Only Unicast using support rates */
1238 if (pTxBufHead->wFIFOCtl & FIFOCTL_NEEDACK) {
1239 pr_debug("wRate %04X, byTsr0 %02X, byTsr1 %02X\n",
1240 wRate, byTsr0, byTsr1);
1241 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) {
1242 pMgmt->sNodeDBTable[0].uTxAttempts += 1;
1243 if ((byTsr1 & TSR1_TERR) == 0) {
1244 /* transmit success, TxAttempts at least plus one */
1245 pMgmt->sNodeDBTable[0].uTxOk[MAX_RATE]++;
1246 if ((byFallBack == AUTO_FB_NONE) ||
1247 (wRate < RATE_18M)) {
1248 wFallBackRate = wRate;
1249 } else if (byFallBack == AUTO_FB_0) {
1250 if (byTxRetry < 5)
1251 wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
1252 else
1253 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1254 } else if (byFallBack == AUTO_FB_1) {
1255 if (byTxRetry < 5)
1256 wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1257 else
1258 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1259 }
1260 pMgmt->sNodeDBTable[0].uTxOk[wFallBackRate]++;
1261 } else {
1262 pMgmt->sNodeDBTable[0].uTxFailures++;
1263 }
1264 pMgmt->sNodeDBTable[0].uTxRetry += byTxRetry;
1265 if (byTxRetry != 0) {
1266 pMgmt->sNodeDBTable[0].uTxFail[MAX_RATE] += byTxRetry;
1267 if ((byFallBack == AUTO_FB_NONE) ||
1268 (wRate < RATE_18M)) {
1269 pMgmt->sNodeDBTable[0].uTxFail[wRate] += byTxRetry;
1270 } else if (byFallBack == AUTO_FB_0) {
1271 for (ii = 0; ii < byTxRetry; ii++) {
1272 if (ii < 5)
1273 wFallBackRate = awHWRetry0[wRate-RATE_18M][ii];
1274 else
1275 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1276 pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
1277 }
1278 } else if (byFallBack == AUTO_FB_1) {
1279 for (ii = 0; ii < byTxRetry; ii++) {
1280 if (ii < 5)
1281 wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
1282 else
1283 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1284 pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
1285 }
1286 }
1287 }
1288 }
1289
1290 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
1291 (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
1292 pMACHeader = (PS802_11Header)(pbyBuffer + uFIFOHeaderSize);
1293
1294 if (BSSDBbIsSTAInNodeDB((void *)pMgmt, &(pMACHeader->abyAddr1[0]), &uNodeIndex)) {
1295 pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts += 1;
1296 if ((byTsr1 & TSR1_TERR) == 0) {
1297 /* transmit success, TxAttempts at least plus one */
1298 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[MAX_RATE]++;
1299 if ((byFallBack == AUTO_FB_NONE) ||
1300 (wRate < RATE_18M)) {
1301 wFallBackRate = wRate;
1302 } else if (byFallBack == AUTO_FB_0) {
1303 if (byTxRetry < 5)
1304 wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
1305 else
1306 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1307 } else if (byFallBack == AUTO_FB_1) {
1308 if (byTxRetry < 5)
1309 wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1310 else
1311 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1312 }
1313 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[wFallBackRate]++;
1314 } else {
1315 pMgmt->sNodeDBTable[uNodeIndex].uTxFailures++;
1316 }
1317 pMgmt->sNodeDBTable[uNodeIndex].uTxRetry += byTxRetry;
1318 if (byTxRetry != 0) {
1319 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[MAX_RATE] += byTxRetry;
1320 if ((byFallBack == AUTO_FB_NONE) ||
1321 (wRate < RATE_18M)) {
1322 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wRate] += byTxRetry;
1323 } else if (byFallBack == AUTO_FB_0) {
1324 for (ii = 0; ii < byTxRetry; ii++) {
1325 if (ii < 5)
1326 wFallBackRate = awHWRetry0[wRate - RATE_18M][ii];
1327 else
1328 wFallBackRate = awHWRetry0[wRate - RATE_18M][4];
1329 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1330 }
1331 } else if (byFallBack == AUTO_FB_1) {
1332 for (ii = 0; ii < byTxRetry; ii++) {
1333 if (ii < 5)
1334 wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
1335 else
1336 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1337 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1338 }
1339 }
1340 }
1341 }
1342 }
1343 }
1344}
1345
1346/*+
1347 *
1348 * Routine Description:
1349 * Clear Nodes & skb in DB Table
1350 *
1351 *
1352 * Parameters:
1353 * In:
1354 * hDeviceContext - The adapter context.
1355 * uStartIndex - starting index
1356 * Out:
1357 * none
1358 *
1359 * Return Value:
1360 * None.
1361 *
1362 -*/
1363
1364void
1365BSSvClearNodeDBTable(
1366 void *hDeviceContext,
1367 unsigned int uStartIndex
1368)
1369
1370{
1371 struct vnt_private *pDevice = hDeviceContext;
1372 PSMgmtObject pMgmt = pDevice->pMgmt;
1373 struct sk_buff *skb;
1374 unsigned int ii;
1375
1376 for (ii = uStartIndex; ii < (MAX_NODE_NUM + 1); ii++) {
1377 if (pMgmt->sNodeDBTable[ii].bActive) {
1378 /* check if sTxPSQueue has been initial */
1379 if (pMgmt->sNodeDBTable[ii].sTxPSQueue.next != NULL) {
1380 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL) {
1381 pr_debug("PS skb != NULL %d\n", ii);
1382 dev_kfree_skb(skb);
1383 }
1384 }
1385 memset(&pMgmt->sNodeDBTable[ii], 0, sizeof(KnownNodeDB));
1386 }
1387 }
1388
1389 return;
1390};
1391
1392void s_vCheckSensitivity(
1393 void *hDeviceContext
1394)
1395{
1396 struct vnt_private *pDevice = hDeviceContext;
1397 PKnownBSS pBSSList = NULL;
1398 PSMgmtObject pMgmt = pDevice->pMgmt;
1399 int ii;
1400
1401 if ((pDevice->byLocalID <= REV_ID_VT3253_A1) && (pDevice->byRFType == RF_RFMD2959) &&
1402 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
1403 return;
1404 }
1405
1406 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1407 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
1408 pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
1409 if (pBSSList != NULL) {
1410 /* Update BB Reg if RSSI is too strong */
1411 long LocalldBmAverage = 0;
1412 long uNumofdBm = 0;
1413
1414 for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
1415 if (pBSSList->ldBmAverage[ii] != 0) {
1416 uNumofdBm++;
1417 LocalldBmAverage += pBSSList->ldBmAverage[ii];
1418 }
1419 }
1420 if (uNumofdBm > 0) {
1421 LocalldBmAverage = LocalldBmAverage/uNumofdBm;
1422 for (ii = 0; ii < BB_VGA_LEVEL; ii++) {
1423 pr_debug("LocalldBmAverage:%ld, %ld %02x\n",
1424 LocalldBmAverage,
1425 pDevice->ldBmThreshold[ii],
1426 pDevice->abyBBVGA[ii]);
1427 if (LocalldBmAverage < pDevice->ldBmThreshold[ii]) {
1428 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
1429 break;
1430 }
1431 }
1432 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
1433 pDevice->uBBVGADiffCount++;
1434 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD)
1435 bScheduleCommand((void *)pDevice, WLAN_CMD_CHANGE_BBSENSITIVITY, NULL);
1436 } else {
1437 pDevice->uBBVGADiffCount = 0;
1438 }
1439 }
1440 }
1441 }
1442}
1443
1444void
1445BSSvClearAnyBSSJoinRecord(
1446 void *hDeviceContext
1447)
1448{
1449 struct vnt_private *pDevice = hDeviceContext;
1450 PSMgmtObject pMgmt = pDevice->pMgmt;
1451 unsigned int ii;
1452
1453 for (ii = 0; ii < MAX_BSS_NUM; ii++)
1454 pMgmt->sBSSList[ii].bSelected = false;
1455}
1456
1457#ifdef Calcu_LinkQual
1458void s_uCalculateLinkQual(
1459 void *hDeviceContext
1460)
1461{
1462 struct vnt_private *pDevice = hDeviceContext;
1463 unsigned long TxOkRatio, TxCnt;
1464 unsigned long RxOkRatio, RxCnt;
1465 unsigned long RssiRatio;
1466 long ldBm;
1467
1468 TxCnt = pDevice->scStatistic.TxNoRetryOkCount +
1469 pDevice->scStatistic.TxRetryOkCount +
1470 pDevice->scStatistic.TxFailCount;
1471 RxCnt = pDevice->scStatistic.RxFcsErrCnt +
1472 pDevice->scStatistic.RxOkCnt;
1473 TxOkRatio = (TxCnt < 6) ? 4000 : ((pDevice->scStatistic.TxNoRetryOkCount * 4000) / TxCnt);
1474 RxOkRatio = (RxCnt < 6) ? 2000 : ((pDevice->scStatistic.RxOkCnt * 2000) / RxCnt);
1475 /* decide link quality */
1476 if (!pDevice->bLinkPass) {
1477 pDevice->scStatistic.LinkQuality = 0;
1478 pDevice->scStatistic.SignalStren = 0;
1479 } else {
1480 RFvRSSITodBm(pDevice, (unsigned char)(pDevice->uCurrRSSI), &ldBm);
1481 if (-ldBm < 50)
1482 RssiRatio = 4000;
1483 else if (-ldBm > 90)
1484 RssiRatio = 0;
1485 else
1486 RssiRatio = (40-(-ldBm-50))*4000/40;
1487 pDevice->scStatistic.SignalStren = RssiRatio/40;
1488 pDevice->scStatistic.LinkQuality = (RssiRatio+TxOkRatio+RxOkRatio)/100;
1489 }
1490 pDevice->scStatistic.RxFcsErrCnt = 0;
1491 pDevice->scStatistic.RxOkCnt = 0;
1492 pDevice->scStatistic.TxFailCount = 0;
1493 pDevice->scStatistic.TxNoRetryOkCount = 0;
1494 pDevice->scStatistic.TxRetryOkCount = 0;
1495}
1496#endif
1497
1498void s_vCheckPreEDThreshold(
1499 void *hDeviceContext
1500)
1501{
1502 struct vnt_private *pDevice = hDeviceContext;
1503 PKnownBSS pBSSList = NULL;
1504 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1505
1506 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1507 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
1508 pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
1509 if (pBSSList != NULL)
1510 pDevice->byBBPreEDRSSI = (unsigned char) (~(pBSSList->ldBmAverRange) + 1);
1511 }
1512}
diff --git a/drivers/staging/vt6655/bssdb.h b/drivers/staging/vt6655/bssdb.h
deleted file mode 100644
index 5d4dd28b6223..000000000000
--- a/drivers/staging/vt6655/bssdb.h
+++ /dev/null
@@ -1,326 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: bssdb.h
21 *
22 * Purpose: Handles the Basic Service Set & Node Database functions
23 *
24 * Author: Lyndon Chen
25 *
26 * Date: July 16, 2002
27 *
28 */
29
30#ifndef __BSSDB_H__
31#define __BSSDB_H__
32
33#include <linux/skbuff.h>
34#include "80211hdr.h"
35#include "80211mgr.h"
36#include "card.h"
37
38#define MAX_NODE_NUM 64
39#define MAX_BSS_NUM 42
40#define LOST_BEACON_COUNT 10 // 10 sec, XP defined
41#define MAX_PS_TX_BUF 32 // sta max power saving tx buf
42#define ADHOC_LOST_BEACON_COUNT 30 // 30 sec, beacon lost for adhoc only
43#define MAX_INACTIVE_COUNT 300 // 300 sec, inactive STA node refresh
44
45#define USE_PROTECT_PERIOD 10 // 10 sec, Use protect mode check period
46#define ERP_RECOVER_COUNT 30 // 30 sec, ERP support callback check
47#define BSS_CLEAR_COUNT 1
48
49#define RSSI_STAT_COUNT 10
50#define MAX_CHECK_RSSI_COUNT 8
51
52// STA dwflags
53#define WLAN_STA_AUTH BIT0
54#define WLAN_STA_ASSOC BIT1
55#define WLAN_STA_PS BIT2
56#define WLAN_STA_TIM BIT3
57// permanent; do not remove entry on expiration
58#define WLAN_STA_PERM BIT4
59// If 802.1X is used, this flag is
60// controlling whether STA is authorized to
61// send and receive non-IEEE 802.1X frames
62#define WLAN_STA_AUTHORIZED BIT5
63
64#define MAX_RATE 12
65
66#define MAX_WPA_IE_LEN 64
67
68//
69// IEEE 802.11 Structures and definitions
70//
71
72typedef enum _NDIS_802_11_NETWORK_TYPE {
73 Ndis802_11FH,
74 Ndis802_11DS,
75 Ndis802_11OFDM5,
76 Ndis802_11OFDM24,
77 Ndis802_11NetworkTypeMax // not a real type, defined as an upper bound
78} NDIS_802_11_NETWORK_TYPE, *PNDIS_802_11_NETWORK_TYPE;
79
80typedef struct tagSERPObject {
81 bool bERPExist;
82 unsigned char byERP;
83} ERPObject, *PERPObject;
84
85typedef struct tagSRSNCapObject {
86 bool bRSNCapExist;
87 unsigned short wRSNCap;
88} SRSNCapObject, *PSRSNCapObject;
89
90// BSS info(AP)
91#pragma pack(1)
92typedef struct tagKnownBSS {
93 bool bActive;
94 unsigned char abyBSSID[WLAN_BSSID_LEN];
95 unsigned int uChannel;
96 unsigned char abySuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
97 unsigned char abyExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
98 unsigned int uRSSI;
99 unsigned char bySQ;
100 unsigned short wBeaconInterval;
101 unsigned short wCapInfo;
102 unsigned char abySSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
103 unsigned char byRxRate;
104
105 unsigned char byRSSIStatCnt;
106 long ldBmMAX;
107 long ldBmAverage[RSSI_STAT_COUNT];
108 long ldBmAverRange;
109 bool bSelected;
110
111 bool bWPAValid;
112 unsigned char byGKType;
113 unsigned char abyPKType[4];
114 unsigned short wPKCount;
115 unsigned char abyAuthType[4];
116 unsigned short wAuthCount;
117 unsigned char byDefaultK_as_PK;
118 unsigned char byReplayIdx;
119
120 bool bWPA2Valid;
121 unsigned char byCSSGK;
122 unsigned short wCSSPKCount;
123 unsigned char abyCSSPK[4];
124 unsigned short wAKMSSAuthCount;
125 unsigned char abyAKMSSAuthType[4];
126
127 unsigned char byWPAIE[MAX_WPA_IE_LEN];
128 unsigned char byRSNIE[MAX_WPA_IE_LEN];
129 unsigned short wWPALen;
130 unsigned short wRSNLen;
131
132 unsigned int uClearCount;
133 unsigned int uIELength;
134 u64 qwBSSTimestamp;
135 u64 qwLocalTSF;
136
137 CARD_PHY_TYPE eNetworkTypeInUse;
138
139 ERPObject sERP;
140 SRSNCapObject sRSNCapObj;
141 unsigned char abyIEs[1024];
142} __attribute__ ((__packed__))
143KnownBSS , *PKnownBSS;
144
145#pragma pack()
146
147typedef enum tagNODE_STATE {
148 NODE_FREE,
149 NODE_AGED,
150 NODE_KNOWN,
151 NODE_AUTH,
152 NODE_ASSOC
153} NODE_STATE, *PNODE_STATE;
154
155// STA node info
156typedef struct tagKnownNodeDB {
157 bool bActive;
158 unsigned char abyMACAddr[WLAN_ADDR_LEN];
159 unsigned char abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN];
160 unsigned char abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN];
161 unsigned short wTxDataRate;
162 bool bShortPreamble;
163 bool bERPExist;
164 bool bShortSlotTime;
165 unsigned int uInActiveCount;
166 unsigned short wMaxBasicRate; //Get from byTopOFDMBasicRate or byTopCCKBasicRate which depends on packetTyp.
167 unsigned short wMaxSuppRate; //Records the highest supported rate getting from SuppRates IE and ExtSuppRates IE in Beacon.
168 unsigned short wSuppRate;
169 unsigned char byTopOFDMBasicRate;//Records the highest basic rate in OFDM mode
170 unsigned char byTopCCKBasicRate; //Records the highest basic rate in CCK mode
171
172 // For AP mode
173 struct sk_buff_head sTxPSQueue;
174 unsigned short wCapInfo;
175 unsigned short wListenInterval;
176 unsigned short wAID;
177 NODE_STATE eNodeState;
178 bool bPSEnable;
179 bool bRxPSPoll;
180 unsigned char byAuthSequence;
181 unsigned long ulLastRxJiffer;
182 unsigned char bySuppRate;
183 unsigned long dwFlags;
184 unsigned short wEnQueueCnt;
185
186 bool bOnFly;
187 unsigned long long KeyRSC;
188 unsigned char byKeyIndex;
189 unsigned long dwKeyIndex;
190 unsigned char byCipherSuite;
191 unsigned long dwTSC47_16;
192 unsigned short wTSC15_0;
193 unsigned int uWepKeyLength;
194 unsigned char abyWepKey[WLAN_WEPMAX_KEYLEN];
195 // Auto rate fallback vars
196 bool bIsInFallback;
197 unsigned int uAverageRSSI;
198 unsigned int uRateRecoveryTimeout;
199 unsigned int uRatePollTimeout;
200 unsigned int uTxFailures;
201 unsigned int uTxAttempts;
202
203 unsigned int uTxRetry;
204 unsigned int uFailureRatio;
205 unsigned int uRetryRatio;
206 unsigned int uTxOk[MAX_RATE+1];
207 unsigned int uTxFail[MAX_RATE+1];
208 unsigned int uTimeCount;
209} KnownNodeDB, *PKnownNodeDB;
210
211PKnownBSS
212BSSpSearchBSSList(
213 void *hDeviceContext,
214 unsigned char *pbyDesireBSSID,
215 unsigned char *pbyDesireSSID,
216 CARD_PHY_TYPE ePhyType
217);
218
219PKnownBSS
220BSSpAddrIsInBSSList(
221 void *hDeviceContext,
222 unsigned char *abyBSSID,
223 PWLAN_IE_SSID pSSID
224);
225
226void
227BSSvClearBSSList(
228 void *hDeviceContext,
229 bool bKeepCurrBSSID
230);
231
232bool
233BSSbInsertToBSSList(
234 void *hDeviceContext,
235 unsigned char *abyBSSIDAddr,
236 __le64 qwTimestamp,
237 unsigned short wBeaconInterval,
238 unsigned short wCapInfo,
239 unsigned char byCurrChannel,
240 PWLAN_IE_SSID pSSID,
241 PWLAN_IE_SUPP_RATES pSuppRates,
242 PWLAN_IE_SUPP_RATES pExtSuppRates,
243 PERPObject psERP,
244 PWLAN_IE_RSN pRSN,
245 PWLAN_IE_RSN_EXT pRSNWPA,
246 PWLAN_IE_COUNTRY pIE_Country,
247 PWLAN_IE_QUIET pIE_Quiet,
248 unsigned int uIELength,
249 unsigned char *pbyIEs,
250 void *pRxPacketContext
251);
252
253bool
254BSSbUpdateToBSSList(
255 void *hDeviceContext,
256 __le64 qwTimestamp,
257 unsigned short wBeaconInterval,
258 unsigned short wCapInfo,
259 unsigned char byCurrChannel,
260 bool bChannelHit,
261 PWLAN_IE_SSID pSSID,
262 PWLAN_IE_SUPP_RATES pSuppRates,
263 PWLAN_IE_SUPP_RATES pExtSuppRates,
264 PERPObject psERP,
265 PWLAN_IE_RSN pRSN,
266 PWLAN_IE_RSN_EXT pRSNWPA,
267 PWLAN_IE_COUNTRY pIE_Country,
268 PWLAN_IE_QUIET pIE_Quiet,
269 PKnownBSS pBSSList,
270 unsigned int uIELength,
271 unsigned char *pbyIEs,
272 void *pRxPacketContext
273);
274
275bool
276BSSDBbIsSTAInNodeDB(void *hDeviceContext, unsigned char *abyDstAddr,
277 unsigned int *puNodeIndex);
278
279void
280BSSvCreateOneNode(void *hDeviceContext, unsigned int *puNodeIndex);
281
282void
283BSSvUpdateAPNode(
284 void *hDeviceContext,
285 unsigned short *pwCapInfo,
286 PWLAN_IE_SUPP_RATES pItemRates,
287 PWLAN_IE_SUPP_RATES pExtSuppRates
288);
289
290void
291BSSvSecondCallBack(
292 void *hDeviceContext
293);
294
295void
296BSSvUpdateNodeTxCounter(
297 void *hDeviceContext,
298 unsigned char byTsr0,
299 unsigned char byTsr1,
300 unsigned char *pbyBuffer,
301 unsigned int uFIFOHeaderSize
302);
303
304void
305BSSvRemoveOneNode(
306 void *hDeviceContext,
307 unsigned int uNodeIndex
308);
309
310void
311BSSvAddMulticastNode(
312 void *hDeviceContext
313);
314
315void
316BSSvClearNodeDBTable(
317 void *hDeviceContext,
318 unsigned int uStartIndex
319);
320
321void
322BSSvClearAnyBSSJoinRecord(
323 void *hDeviceContext
324);
325
326#endif //__BSSDB_H__
diff --git a/drivers/staging/vt6655/card.c b/drivers/staging/vt6655/card.c
index 5a6950264bdc..a0796405c308 100644
--- a/drivers/staging/vt6655/card.c
+++ b/drivers/staging/vt6655/card.c
@@ -21,7 +21,6 @@
21 * Functions: 21 * Functions:
22 * s_vSafeResetTx - Rest Tx 22 * s_vSafeResetTx - Rest Tx
23 * CARDvSetRSPINF - Set RSPINF 23 * CARDvSetRSPINF - Set RSPINF
24 * vUpdateIFS - Update slotTime,SIFS,DIFS, and EIFS
25 * CARDvUpdateBasicTopRate - Update BasicTopRate 24 * CARDvUpdateBasicTopRate - Update BasicTopRate
26 * CARDbAddBasicRate - Add to BasicRateSet 25 * CARDbAddBasicRate - Add to BasicRateSet
27 * CARDbIsOFDMinBasicRate - Check if any OFDM rate is in BasicRateSet 26 * CARDbIsOFDMinBasicRate - Check if any OFDM rate is in BasicRateSet
@@ -34,8 +33,6 @@
34 * CARDvUpdateNextTBTT - Sync. NIC Beacon time 33 * CARDvUpdateNextTBTT - Sync. NIC Beacon time
35 * CARDbRadioPowerOff - Turn Off NIC Radio Power 34 * CARDbRadioPowerOff - Turn Off NIC Radio Power
36 * CARDbRadioPowerOn - Turn On NIC Radio Power 35 * CARDbRadioPowerOn - Turn On NIC Radio Power
37 * CARDbSetWEPMode - Set NIC Wep mode
38 * CARDbSetTxPower - Set NIC tx power
39 * 36 *
40 * Revision History: 37 * Revision History:
41 * 06-10-2003 Bryan YC Fan: Re-write codes to support VT3253 spec. 38 * 06-10-2003 Bryan YC Fan: Re-write codes to support VT3253 spec.
@@ -50,38 +47,24 @@
50#include "mac.h" 47#include "mac.h"
51#include "desc.h" 48#include "desc.h"
52#include "rf.h" 49#include "rf.h"
53#include "vntwifi.h"
54#include "power.h" 50#include "power.h"
55#include "key.h"
56#include "rc4.h"
57#include "country.h"
58#include "channel.h"
59 51
60/*--------------------- Static Definitions -------------------------*/ 52/*--------------------- Static Definitions -------------------------*/
61 53
62#define C_SIFS_A 16 // micro sec. 54#define C_SIFS_A 16 /* micro sec. */
63#define C_SIFS_BG 10 55#define C_SIFS_BG 10
64 56
65#define C_EIFS 80 // micro sec. 57#define C_EIFS 80 /* micro sec. */
66 58
67#define C_SLOT_SHORT 9 // micro sec. 59#define C_SLOT_SHORT 9 /* micro sec. */
68#define C_SLOT_LONG 20 60#define C_SLOT_LONG 20
69 61
70#define C_CWMIN_A 15 // slot time 62#define C_CWMIN_A 15 /* slot time */
71#define C_CWMIN_B 31 63#define C_CWMIN_B 31
72 64
73#define C_CWMAX 1023 // slot time 65#define C_CWMAX 1023 /* slot time */
74 66
75#define WAIT_BEACON_TX_DOWN_TMO 3 // Times 67#define WAIT_BEACON_TX_DOWN_TMO 3 /* Times */
76
77//1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
78static unsigned char abyDefaultSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
79//6M, 9M, 12M, 48M
80static unsigned char abyDefaultExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
81//6M, 9M, 12M, 18M, 24M, 36M, 48M, 54M
82static unsigned char abyDefaultSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
83//1M, 2M, 5M, 11M,
84static unsigned char abyDefaultSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
85 68
86/*--------------------- Static Variables --------------------------*/ 69/*--------------------- Static Variables --------------------------*/
87 70
@@ -94,7 +77,7 @@ static
94void 77void
95s_vCalculateOFDMRParameter( 78s_vCalculateOFDMRParameter(
96 unsigned char byRate, 79 unsigned char byRate,
97 CARD_PHY_TYPE ePHYType, 80 u8 bb_type,
98 unsigned char *pbyTxRate, 81 unsigned char *pbyTxRate,
99 unsigned char *pbyRsvTime 82 unsigned char *pbyRsvTime
100); 83);
@@ -113,20 +96,19 @@ s_vCalculateOFDMRParameter(
113 * pbyRsvTime - pointer to RSPINF RsvTime field 96 * pbyRsvTime - pointer to RSPINF RsvTime field
114 * 97 *
115 * Return Value: none 98 * Return Value: none
116 *
117 */ 99 */
118static 100static
119void 101void
120s_vCalculateOFDMRParameter( 102s_vCalculateOFDMRParameter(
121 unsigned char byRate, 103 unsigned char byRate,
122 CARD_PHY_TYPE ePHYType, 104 u8 bb_type,
123 unsigned char *pbyTxRate, 105 unsigned char *pbyTxRate,
124 unsigned char *pbyRsvTime 106 unsigned char *pbyRsvTime
125) 107)
126{ 108{
127 switch (byRate) { 109 switch (byRate) {
128 case RATE_6M: 110 case RATE_6M:
129 if (ePHYType == PHY_TYPE_11A) {//5GHZ 111 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
130 *pbyTxRate = 0x9B; 112 *pbyTxRate = 0x9B;
131 *pbyRsvTime = 44; 113 *pbyRsvTime = 44;
132 } else { 114 } else {
@@ -136,7 +118,7 @@ s_vCalculateOFDMRParameter(
136 break; 118 break;
137 119
138 case RATE_9M: 120 case RATE_9M:
139 if (ePHYType == PHY_TYPE_11A) {//5GHZ 121 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
140 *pbyTxRate = 0x9F; 122 *pbyTxRate = 0x9F;
141 *pbyRsvTime = 36; 123 *pbyRsvTime = 36;
142 } else { 124 } else {
@@ -146,7 +128,7 @@ s_vCalculateOFDMRParameter(
146 break; 128 break;
147 129
148 case RATE_12M: 130 case RATE_12M:
149 if (ePHYType == PHY_TYPE_11A) {//5GHZ 131 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
150 *pbyTxRate = 0x9A; 132 *pbyTxRate = 0x9A;
151 *pbyRsvTime = 32; 133 *pbyRsvTime = 32;
152 } else { 134 } else {
@@ -156,7 +138,7 @@ s_vCalculateOFDMRParameter(
156 break; 138 break;
157 139
158 case RATE_18M: 140 case RATE_18M:
159 if (ePHYType == PHY_TYPE_11A) {//5GHZ 141 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
160 *pbyTxRate = 0x9E; 142 *pbyTxRate = 0x9E;
161 *pbyRsvTime = 28; 143 *pbyRsvTime = 28;
162 } else { 144 } else {
@@ -166,7 +148,7 @@ s_vCalculateOFDMRParameter(
166 break; 148 break;
167 149
168 case RATE_36M: 150 case RATE_36M:
169 if (ePHYType == PHY_TYPE_11A) {//5GHZ 151 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
170 *pbyTxRate = 0x9D; 152 *pbyTxRate = 0x9D;
171 *pbyRsvTime = 24; 153 *pbyRsvTime = 24;
172 } else { 154 } else {
@@ -176,7 +158,7 @@ s_vCalculateOFDMRParameter(
176 break; 158 break;
177 159
178 case RATE_48M: 160 case RATE_48M:
179 if (ePHYType == PHY_TYPE_11A) {//5GHZ 161 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
180 *pbyTxRate = 0x98; 162 *pbyTxRate = 0x98;
181 *pbyRsvTime = 24; 163 *pbyRsvTime = 24;
182 } else { 164 } else {
@@ -186,7 +168,7 @@ s_vCalculateOFDMRParameter(
186 break; 168 break;
187 169
188 case RATE_54M: 170 case RATE_54M:
189 if (ePHYType == PHY_TYPE_11A) {//5GHZ 171 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
190 *pbyTxRate = 0x9C; 172 *pbyTxRate = 0x9C;
191 *pbyRsvTime = 24; 173 *pbyRsvTime = 24;
192 } else { 174 } else {
@@ -197,7 +179,7 @@ s_vCalculateOFDMRParameter(
197 179
198 case RATE_24M: 180 case RATE_24M:
199 default: 181 default:
200 if (ePHYType == PHY_TYPE_11A) {//5GHZ 182 if (bb_type == BB_TYPE_11A) { /* 5GHZ */
201 *pbyTxRate = 0x99; 183 *pbyTxRate = 0x99;
202 *pbyRsvTime = 28; 184 *pbyRsvTime = 28;
203 } else { 185 } else {
@@ -208,167 +190,9 @@ s_vCalculateOFDMRParameter(
208 } 190 }
209} 191}
210 192
211/*
212 * Description: Set RSPINF
213 *
214 * Parameters:
215 * In:
216 * pDevice - The adapter to be set
217 * Out:
218 * none
219 *
220 * Return Value: None.
221 *
222 */
223static
224void
225s_vSetRSPINF(struct vnt_private *pDevice, CARD_PHY_TYPE ePHYType,
226 void *pvSupportRateIEs, void *pvExtSupportRateIEs)
227{
228 union vnt_phy_field_swap phy;
229 unsigned char byTxRate = 0, byRsvTime = 0; // For OFDM
230
231 //Set to Page1
232 MACvSelectPage1(pDevice->PortOffset);
233
234 /* RSPINF_b_1 */
235 vnt_get_phy_field(pDevice,
236 14,
237 VNTWIFIbyGetACKTxRate(RATE_1M, pvSupportRateIEs, pvExtSupportRateIEs),
238 PK_TYPE_11B,
239 &phy.field_read);
240
241 /* swap over to get correct write order */
242 swap(phy.swap[0], phy.swap[1]);
243
244 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, phy.field_write);
245
246 /* RSPINF_b_2 */
247 vnt_get_phy_field(pDevice, 14,
248 VNTWIFIbyGetACKTxRate(RATE_2M, pvSupportRateIEs, pvExtSupportRateIEs),
249 PK_TYPE_11B, &phy.field_read);
250
251 swap(phy.swap[0], phy.swap[1]);
252
253 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, phy.field_write);
254
255 /* RSPINF_b_5 */
256 vnt_get_phy_field(pDevice, 14,
257 VNTWIFIbyGetACKTxRate(RATE_5M, pvSupportRateIEs, pvExtSupportRateIEs),
258 PK_TYPE_11B, &phy.field_read);
259
260 swap(phy.swap[0], phy.swap[1]);
261
262 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, phy.field_write);
263
264 /* RSPINF_b_11 */
265 vnt_get_phy_field(pDevice, 14,
266 VNTWIFIbyGetACKTxRate(RATE_11M, pvSupportRateIEs, pvExtSupportRateIEs),
267 PK_TYPE_11B, &phy.field_read);
268
269 swap(phy.swap[0], phy.swap[1]);
270
271 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, phy.field_write);
272
273 //RSPINF_a_6
274 s_vCalculateOFDMRParameter(RATE_6M,
275 ePHYType,
276 &byTxRate,
277 &byRsvTime);
278 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime));
279 //RSPINF_a_9
280 s_vCalculateOFDMRParameter(RATE_9M,
281 ePHYType,
282 &byTxRate,
283 &byRsvTime);
284 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime));
285 //RSPINF_a_12
286 s_vCalculateOFDMRParameter(RATE_12M,
287 ePHYType,
288 &byTxRate,
289 &byRsvTime);
290 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime));
291 //RSPINF_a_18
292 s_vCalculateOFDMRParameter(RATE_18M,
293 ePHYType,
294 &byTxRate,
295 &byRsvTime);
296 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime));
297 //RSPINF_a_24
298 s_vCalculateOFDMRParameter(RATE_24M,
299 ePHYType,
300 &byTxRate,
301 &byRsvTime);
302 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime));
303 //RSPINF_a_36
304 s_vCalculateOFDMRParameter(
305 VNTWIFIbyGetACKTxRate(RATE_36M, pvSupportRateIEs, pvExtSupportRateIEs),
306 ePHYType,
307 &byTxRate,
308 &byRsvTime);
309 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime));
310 //RSPINF_a_48
311 s_vCalculateOFDMRParameter(
312 VNTWIFIbyGetACKTxRate(RATE_48M, pvSupportRateIEs, pvExtSupportRateIEs),
313 ePHYType,
314 &byTxRate,
315 &byRsvTime);
316 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime));
317 //RSPINF_a_54
318 s_vCalculateOFDMRParameter(
319 VNTWIFIbyGetACKTxRate(RATE_54M, pvSupportRateIEs, pvExtSupportRateIEs),
320 ePHYType,
321 &byTxRate,
322 &byRsvTime);
323 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime));
324 //RSPINF_a_72
325 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime));
326 //Set to Page0
327 MACvSelectPage0(pDevice->PortOffset);
328}
329
330/*--------------------- Export Functions --------------------------*/ 193/*--------------------- Export Functions --------------------------*/
331 194
332/* 195/*
333 * Description: Get Card short preamble option value
334 *
335 * Parameters:
336 * In:
337 * pDevice - The adapter to be set
338 * Out:
339 * none
340 *
341 * Return Value: true if short preamble; otherwise false
342 *
343 */
344bool CARDbIsShortPreamble(struct vnt_private *pDevice)
345{
346
347 if (pDevice->byPreambleType == 0)
348 return false;
349
350 return true;
351}
352
353/*
354 * Description: Get Card short slot time option value
355 *
356 * Parameters:
357 * In:
358 * pDevice - The adapter to be set
359 * Out:
360 * none
361 *
362 * Return Value: true if short slot time; otherwise false
363 *
364 */
365bool CARDbIsShorSlotTime(struct vnt_private *pDevice)
366{
367
368 return pDevice->bShortSlotTime;
369}
370
371/*
372 * Description: Update IFS 196 * Description: Update IFS
373 * 197 *
374 * Parameters: 198 * Parameters:
@@ -378,138 +202,118 @@ bool CARDbIsShorSlotTime(struct vnt_private *pDevice)
378 * none 202 * none
379 * 203 *
380 * Return Value: None. 204 * Return Value: None.
381 *
382 */ 205 */
383bool CARDbSetPhyParameter(struct vnt_private *pDevice, CARD_PHY_TYPE ePHYType, 206bool CARDbSetPhyParameter(struct vnt_private *pDevice, u8 bb_type)
384 unsigned short wCapInfo, unsigned char byERPField,
385 void *pvSupportRateIEs, void *pvExtSupportRateIEs)
386{ 207{
387 unsigned char byCWMaxMin = 0; 208 unsigned char byCWMaxMin = 0;
388 unsigned char bySlot = 0; 209 unsigned char bySlot = 0;
389 unsigned char bySIFS = 0; 210 unsigned char bySIFS = 0;
390 unsigned char byDIFS = 0; 211 unsigned char byDIFS = 0;
391 unsigned char byData; 212 unsigned char byData;
392 PWLAN_IE_SUPP_RATES pSupportRates = (PWLAN_IE_SUPP_RATES) pvSupportRateIEs; 213 int i;
393 PWLAN_IE_SUPP_RATES pExtSupportRates = (PWLAN_IE_SUPP_RATES) pvExtSupportRateIEs;
394
395 //Set SIFS, DIFS, EIFS, SlotTime, CwMin
396 if (ePHYType == PHY_TYPE_11A) {
397 if (pSupportRates == NULL)
398 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesA;
399 214
215 /* Set SIFS, DIFS, EIFS, SlotTime, CwMin */
216 if (bb_type == BB_TYPE_11A) {
400 if (pDevice->byRFType == RF_AIROHA7230) { 217 if (pDevice->byRFType == RF_AIROHA7230) {
401 // AL7230 use single PAPE and connect to PAPE_2.4G 218 /* AL7230 use single PAPE and connect to PAPE_2.4G */
402 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G); 219 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
403 pDevice->abyBBVGA[0] = 0x20; 220 pDevice->abyBBVGA[0] = 0x20;
404 pDevice->abyBBVGA[2] = 0x10; 221 pDevice->abyBBVGA[2] = 0x10;
405 pDevice->abyBBVGA[3] = 0x10; 222 pDevice->abyBBVGA[3] = 0x10;
406 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData); 223 BBbReadEmbedded(pDevice, 0xE7, &byData);
407 if (byData == 0x1C) 224 if (byData == 0x1C)
408 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]); 225 BBbWriteEmbedded(pDevice, 0xE7, pDevice->abyBBVGA[0]);
409 226
410 } else if (pDevice->byRFType == RF_UW2452) { 227 } else if (pDevice->byRFType == RF_UW2452) {
411 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A); 228 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
412 pDevice->abyBBVGA[0] = 0x18; 229 pDevice->abyBBVGA[0] = 0x18;
413 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData); 230 BBbReadEmbedded(pDevice, 0xE7, &byData);
414 if (byData == 0x14) { 231 if (byData == 0x14) {
415 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]); 232 BBbWriteEmbedded(pDevice, 0xE7, pDevice->abyBBVGA[0]);
416 BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0x57); 233 BBbWriteEmbedded(pDevice, 0xE1, 0x57);
417 } 234 }
418 } else { 235 } else {
419 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A); 236 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
420 } 237 }
421 BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x03); 238 BBbWriteEmbedded(pDevice, 0x88, 0x03);
422 bySlot = C_SLOT_SHORT; 239 bySlot = C_SLOT_SHORT;
423 bySIFS = C_SIFS_A; 240 bySIFS = C_SIFS_A;
424 byDIFS = C_SIFS_A + 2*C_SLOT_SHORT; 241 byDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
425 byCWMaxMin = 0xA4; 242 byCWMaxMin = 0xA4;
426 } else if (ePHYType == PHY_TYPE_11B) { 243 } else if (bb_type == BB_TYPE_11B) {
427 if (pSupportRates == NULL)
428 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesB;
429
430 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11B); 244 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11B);
431 if (pDevice->byRFType == RF_AIROHA7230) { 245 if (pDevice->byRFType == RF_AIROHA7230) {
432 pDevice->abyBBVGA[0] = 0x1C; 246 pDevice->abyBBVGA[0] = 0x1C;
433 pDevice->abyBBVGA[2] = 0x00; 247 pDevice->abyBBVGA[2] = 0x00;
434 pDevice->abyBBVGA[3] = 0x00; 248 pDevice->abyBBVGA[3] = 0x00;
435 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData); 249 BBbReadEmbedded(pDevice, 0xE7, &byData);
436 if (byData == 0x20) 250 if (byData == 0x20)
437 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]); 251 BBbWriteEmbedded(pDevice, 0xE7, pDevice->abyBBVGA[0]);
438 252
439 } else if (pDevice->byRFType == RF_UW2452) { 253 } else if (pDevice->byRFType == RF_UW2452) {
440 pDevice->abyBBVGA[0] = 0x14; 254 pDevice->abyBBVGA[0] = 0x14;
441 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData); 255 BBbReadEmbedded(pDevice, 0xE7, &byData);
442 if (byData == 0x18) { 256 if (byData == 0x18) {
443 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]); 257 BBbWriteEmbedded(pDevice, 0xE7, pDevice->abyBBVGA[0]);
444 BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0xD3); 258 BBbWriteEmbedded(pDevice, 0xE1, 0xD3);
445 } 259 }
446 } 260 }
447 BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x02); 261 BBbWriteEmbedded(pDevice, 0x88, 0x02);
448 bySlot = C_SLOT_LONG; 262 bySlot = C_SLOT_LONG;
449 bySIFS = C_SIFS_BG; 263 bySIFS = C_SIFS_BG;
450 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG; 264 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
451 byCWMaxMin = 0xA5; 265 byCWMaxMin = 0xA5;
452 } else {// PK_TYPE_11GA & PK_TYPE_11GB 266 } else { /* PK_TYPE_11GA & PK_TYPE_11GB */
453 if (pSupportRates == NULL) {
454 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesG;
455 pExtSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultExtSuppRatesG;
456 }
457 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G); 267 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
458 if (pDevice->byRFType == RF_AIROHA7230) { 268 if (pDevice->byRFType == RF_AIROHA7230) {
459 pDevice->abyBBVGA[0] = 0x1C; 269 pDevice->abyBBVGA[0] = 0x1C;
460 pDevice->abyBBVGA[2] = 0x00; 270 pDevice->abyBBVGA[2] = 0x00;
461 pDevice->abyBBVGA[3] = 0x00; 271 pDevice->abyBBVGA[3] = 0x00;
462 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData); 272 BBbReadEmbedded(pDevice, 0xE7, &byData);
463 if (byData == 0x20) 273 if (byData == 0x20)
464 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]); 274 BBbWriteEmbedded(pDevice, 0xE7, pDevice->abyBBVGA[0]);
465 275
466 } else if (pDevice->byRFType == RF_UW2452) { 276 } else if (pDevice->byRFType == RF_UW2452) {
467 pDevice->abyBBVGA[0] = 0x14; 277 pDevice->abyBBVGA[0] = 0x14;
468 BBbReadEmbedded(pDevice->PortOffset, 0xE7, &byData); 278 BBbReadEmbedded(pDevice, 0xE7, &byData);
469 if (byData == 0x18) { 279 if (byData == 0x18) {
470 BBbWriteEmbedded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]); 280 BBbWriteEmbedded(pDevice, 0xE7, pDevice->abyBBVGA[0]);
471 BBbWriteEmbedded(pDevice->PortOffset, 0xE1, 0xD3); 281 BBbWriteEmbedded(pDevice, 0xE1, 0xD3);
472 } 282 }
473 } 283 }
474 BBbWriteEmbedded(pDevice->PortOffset, 0x88, 0x08); 284 BBbWriteEmbedded(pDevice, 0x88, 0x08);
475 bySIFS = C_SIFS_BG; 285 bySIFS = C_SIFS_BG;
476 if (VNTWIFIbIsShortSlotTime(wCapInfo)) { 286
287 if (pDevice->bShortSlotTime) {
477 bySlot = C_SLOT_SHORT; 288 bySlot = C_SLOT_SHORT;
478 byDIFS = C_SIFS_BG + 2*C_SLOT_SHORT; 289 byDIFS = C_SIFS_BG + 2*C_SLOT_SHORT;
479 } else { 290 } else {
480 bySlot = C_SLOT_LONG; 291 bySlot = C_SLOT_LONG;
481 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG; 292 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
482 } 293 }
483 if (VNTWIFIbyGetMaxSupportRate(pSupportRates, pExtSupportRates) > RATE_11M)
484 byCWMaxMin = 0xA4;
485 else
486 byCWMaxMin = 0xA5;
487
488 if (pDevice->bProtectMode != VNTWIFIbIsProtectMode(byERPField)) {
489 pDevice->bProtectMode = VNTWIFIbIsProtectMode(byERPField);
490 if (pDevice->bProtectMode)
491 MACvEnableProtectMD(pDevice->PortOffset);
492 else
493 MACvDisableProtectMD(pDevice->PortOffset);
494 294
495 } 295 byCWMaxMin = 0xa4;
496 if (pDevice->bBarkerPreambleMd != VNTWIFIbIsBarkerMode(byERPField)) { 296
497 pDevice->bBarkerPreambleMd = VNTWIFIbIsBarkerMode(byERPField); 297 for (i = RATE_54M; i >= RATE_6M; i--) {
498 if (pDevice->bBarkerPreambleMd) 298 if (pDevice->basic_rates & ((u32)(0x1 << i))) {
499 MACvEnableBarkerPreambleMd(pDevice->PortOffset); 299 byCWMaxMin |= 0x1;
500 else 300 break;
501 MACvDisableBarkerPreambleMd(pDevice->PortOffset); 301 }
502 } 302 }
503 } 303 }
504 304
505 if (pDevice->byRFType == RF_RFMD2959) { 305 if (pDevice->byRFType == RF_RFMD2959) {
506 // bcs TX_PE will reserve 3 us 306 /*
507 // hardware's processing time here is 2 us. 307 * bcs TX_PE will reserve 3 us hardware's processing
308 * time here is 2 us.
309 */
508 bySIFS -= 3; 310 bySIFS -= 3;
509 byDIFS -= 3; 311 byDIFS -= 3;
510 //{{ RobertYu: 20041202 312 /*
511 //// TX_PE will reserve 3 us for MAX2829 A mode only, it is for better TX throughput 313 * TX_PE will reserve 3 us for MAX2829 A mode only, it is for
512 //// MAC will need 2 us to process, so the SIFS, DIFS can be shorter by 2 us. 314 * better TX throughput; MAC will need 2 us to process, so the
315 * SIFS, DIFS can be shorter by 2 us.
316 */
513 } 317 }
514 318
515 if (pDevice->bySIFS != bySIFS) { 319 if (pDevice->bySIFS != bySIFS) {
@@ -527,10 +331,6 @@ bool CARDbSetPhyParameter(struct vnt_private *pDevice, CARD_PHY_TYPE ePHYType,
527 if (pDevice->bySlot != bySlot) { 331 if (pDevice->bySlot != bySlot) {
528 pDevice->bySlot = bySlot; 332 pDevice->bySlot = bySlot;
529 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, pDevice->bySlot); 333 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, pDevice->bySlot);
530 if (pDevice->bySlot == C_SLOT_SHORT)
531 pDevice->bShortSlotTime = true;
532 else
533 pDevice->bShortSlotTime = false;
534 334
535 BBvSetShortSlotTime(pDevice); 335 BBvSetShortSlotTime(pDevice);
536 } 336 }
@@ -538,14 +338,11 @@ bool CARDbSetPhyParameter(struct vnt_private *pDevice, CARD_PHY_TYPE ePHYType,
538 pDevice->byCWMaxMin = byCWMaxMin; 338 pDevice->byCWMaxMin = byCWMaxMin;
539 VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, pDevice->byCWMaxMin); 339 VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, pDevice->byCWMaxMin);
540 } 340 }
541 if (VNTWIFIbIsShortPreamble(wCapInfo))
542 pDevice->byPreambleType = pDevice->byShortPreamble;
543 else
544 pDevice->byPreambleType = 0;
545 341
546 s_vSetRSPINF(pDevice, ePHYType, pSupportRates, pExtSupportRates); 342 pDevice->byPacketType = CARDbyGetPktType(pDevice);
547 pDevice->eCurrentPHYType = ePHYType; 343
548 // set for NDIS OID_802_11SUPPORTED_RATES 344 CARDvSetRSPINF(pDevice, bb_type);
345
549 return true; 346 return true;
550} 347}
551 348
@@ -563,7 +360,6 @@ bool CARDbSetPhyParameter(struct vnt_private *pDevice, CARD_PHY_TYPE ePHYType,
563 * none 360 * none
564 * 361 *
565 * Return Value: none 362 * Return Value: none
566 *
567 */ 363 */
568bool CARDbUpdateTSF(struct vnt_private *pDevice, unsigned char byRxRate, 364bool CARDbUpdateTSF(struct vnt_private *pDevice, unsigned char byRxRate,
569 u64 qwBSSTimestamp, u64 qwLocalTSF) 365 u64 qwBSSTimestamp, u64 qwLocalTSF)
@@ -572,8 +368,7 @@ bool CARDbUpdateTSF(struct vnt_private *pDevice, unsigned char byRxRate,
572 368
573 if (qwBSSTimestamp != qwLocalTSF) { 369 if (qwBSSTimestamp != qwLocalTSF) {
574 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF); 370 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
575 // adjust TSF 371 /* adjust TSF, HW's TSF add TSF Offset reg */
576 // HW's TSF add TSF Offset reg
577 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST, (u32)qwTSFOffset); 372 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST, (u32)qwTSFOffset);
578 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST + 4, (u32)(qwTSFOffset >> 32)); 373 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST + 4, (u32)(qwTSFOffset >> 32));
579 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TSFSYNCEN); 374 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TSFSYNCEN);
@@ -593,21 +388,20 @@ bool CARDbUpdateTSF(struct vnt_private *pDevice, unsigned char byRxRate,
593 * none 388 * none
594 * 389 *
595 * Return Value: true if succeed; otherwise false 390 * Return Value: true if succeed; otherwise false
596 *
597 */ 391 */
598bool CARDbSetBeaconPeriod(struct vnt_private *pDevice, 392bool CARDbSetBeaconPeriod(struct vnt_private *pDevice,
599 unsigned short wBeaconInterval) 393 unsigned short wBeaconInterval)
600{ 394{
601 u64 qwNextTBTT = 0; 395 u64 qwNextTBTT = 0;
602 396
603 CARDbGetCurrentTSF(pDevice->PortOffset, &qwNextTBTT); //Get Local TSF counter 397 CARDbGetCurrentTSF(pDevice, &qwNextTBTT); /* Get Local TSF counter */
604 398
605 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval); 399 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
606 400
607 // set HW beacon interval 401 /* set HW beacon interval */
608 VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, wBeaconInterval); 402 VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, wBeaconInterval);
609 pDevice->wBeaconInterval = wBeaconInterval; 403 pDevice->wBeaconInterval = wBeaconInterval;
610 // Set NextTBTT 404 /* Set NextTBTT */
611 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT, (u32)qwNextTBTT); 405 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT, (u32)qwNextTBTT);
612 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT + 4, (u32)(qwNextTBTT >> 32)); 406 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT + 4, (u32)(qwNextTBTT >> 32));
613 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN); 407 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
@@ -616,225 +410,6 @@ bool CARDbSetBeaconPeriod(struct vnt_private *pDevice,
616} 410}
617 411
618/* 412/*
619 * Description: Card Stop Hardware Tx
620 *
621 * Parameters:
622 * In:
623 * pDeviceHandler - The adapter to be set
624 * ePktType - Packet type to stop
625 * Out:
626 * none
627 *
628 * Return Value: true if all data packet complete; otherwise false.
629 *
630 */
631bool CARDbStopTxPacket(struct vnt_private *pDevice, CARD_PKT_TYPE ePktType)
632{
633
634 if (ePktType == PKT_TYPE_802_11_ALL) {
635 pDevice->bStopBeacon = true;
636 pDevice->bStopTx0Pkt = true;
637 pDevice->bStopDataPkt = true;
638 } else if (ePktType == PKT_TYPE_802_11_BCN) {
639 pDevice->bStopBeacon = true;
640 } else if (ePktType == PKT_TYPE_802_11_MNG) {
641 pDevice->bStopTx0Pkt = true;
642 } else if (ePktType == PKT_TYPE_802_11_DATA) {
643 pDevice->bStopDataPkt = true;
644 }
645
646 if (pDevice->bStopBeacon == true) {
647 if (pDevice->bIsBeaconBufReadySet == true) {
648 if (pDevice->cbBeaconBufReadySetCnt < WAIT_BEACON_TX_DOWN_TMO) {
649 pDevice->cbBeaconBufReadySetCnt++;
650 return false;
651 }
652 }
653 pDevice->bIsBeaconBufReadySet = false;
654 pDevice->cbBeaconBufReadySetCnt = 0;
655 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
656 }
657 // wait all TD0 complete
658 if (pDevice->bStopTx0Pkt == true) {
659 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0)
660 return false;
661 }
662 // wait all Data TD complete
663 if (pDevice->bStopDataPkt == true) {
664 if (pDevice->iTDUsed[TYPE_AC0DMA] != 0)
665 return false;
666 }
667
668 return true;
669}
670
671/*
672 * Description: Card Start Hardware Tx
673 *
674 * Parameters:
675 * In:
676 * pDeviceHandler - The adapter to be set
677 * ePktType - Packet type to start
678 * Out:
679 * none
680 *
681 * Return Value: true if success; false if failed.
682 *
683 */
684bool CARDbStartTxPacket(struct vnt_private *pDevice, CARD_PKT_TYPE ePktType)
685{
686
687 if (ePktType == PKT_TYPE_802_11_ALL) {
688 pDevice->bStopBeacon = false;
689 pDevice->bStopTx0Pkt = false;
690 pDevice->bStopDataPkt = false;
691 } else if (ePktType == PKT_TYPE_802_11_BCN) {
692 pDevice->bStopBeacon = false;
693 } else if (ePktType == PKT_TYPE_802_11_MNG) {
694 pDevice->bStopTx0Pkt = false;
695 } else if (ePktType == PKT_TYPE_802_11_DATA) {
696 pDevice->bStopDataPkt = false;
697 }
698
699 if ((pDevice->bStopBeacon == false) &&
700 (pDevice->bBeaconBufReady == true) &&
701 (pDevice->op_mode == NL80211_IFTYPE_ADHOC)) {
702 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
703 }
704
705 return true;
706}
707
708/*
709 * Description: Card Set BSSID value
710 *
711 * Parameters:
712 * In:
713 * pDeviceHandler - The adapter to be set
714 * pbyBSSID - pointer to BSSID field
715 * bAdhoc - flag to indicate IBSS
716 * Out:
717 * none
718 *
719 * Return Value: true if success; false if failed.
720 *
721 */
722bool CARDbSetBSSID(struct vnt_private *pDevice,
723 unsigned char *pbyBSSID, enum nl80211_iftype op_mode)
724{
725
726 MACvWriteBSSIDAddress(pDevice->PortOffset, pbyBSSID);
727 memcpy(pDevice->abyBSSID, pbyBSSID, WLAN_BSSID_LEN);
728 if (op_mode == NL80211_IFTYPE_ADHOC)
729 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
730 else
731 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
732
733 if (op_mode == NL80211_IFTYPE_AP)
734 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
735 else
736 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
737
738 if (op_mode == NL80211_IFTYPE_UNSPECIFIED) {
739 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
740 pDevice->bBSSIDFilter = false;
741 pDevice->byRxMode &= ~RCR_BSSID;
742 pr_debug("wcmd: rx_mode = %x\n", pDevice->byRxMode);
743 } else {
744 if (is_zero_ether_addr(pDevice->abyBSSID) == false) {
745 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
746 pDevice->bBSSIDFilter = true;
747 pDevice->byRxMode |= RCR_BSSID;
748 }
749 pr_debug("wmgr: rx_mode = %x\n", pDevice->byRxMode);
750 }
751 // Adopt BSS state in Adapter Device Object
752 pDevice->op_mode = op_mode;
753 return true;
754}
755
756/*
757 * Description: Card indicate status
758 *
759 * Parameters:
760 * In:
761 * pDeviceHandler - The adapter to be set
762 * eStatus - Status
763 * Out:
764 * none
765 *
766 * Return Value: true if success; false if failed.
767 *
768 */
769
770/*
771 * Description: Save Assoc info. contain in assoc. response frame
772 *
773 * Parameters:
774 * In:
775 * pDevice - The adapter to be set
776 * wCapabilityInfo - Capability information
777 * wStatus - Status code
778 * wAID - Assoc. ID
779 * uLen - Length of IEs
780 * pbyIEs - pointer to IEs
781 * Out:
782 * none
783 *
784 * Return Value: true if succeed; otherwise false
785 *
786 */
787bool CARDbSetTxDataRate(
788 struct vnt_private *pDevice,
789 unsigned short wDataRate
790)
791{
792
793 pDevice->wCurrentRate = wDataRate;
794 return true;
795}
796
797/*+
798 *
799 * Routine Description:
800 * Consider to power down when no more packets to tx or rx.
801 *
802 * Parameters:
803 * In:
804 * pDevice - The adapter to be set
805 * Out:
806 * none
807 *
808 * Return Value: true if power down success; otherwise false
809 *
810 -*/
811bool
812CARDbPowerDown(
813 struct vnt_private *pDevice
814)
815{
816 unsigned int uIdx;
817
818 // check if already in Doze mode
819 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
820 return true;
821
822 // Froce PSEN on
823 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
824
825 // check if all TD are empty,
826
827 for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx++) {
828 if (pDevice->iTDUsed[uIdx] != 0)
829 return false;
830 }
831
832 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_GO2DOZE);
833 pr_debug("Go to Doze ZZZZZZZZZZZZZZZ\n");
834 return true;
835}
836
837/*
838 * Description: Turn off Radio power 413 * Description: Turn off Radio power
839 * 414 *
840 * Parameters: 415 * Parameters:
@@ -844,7 +419,6 @@ CARDbPowerDown(
844 * none 419 * none
845 * 420 *
846 * Return Value: true if success; otherwise false 421 * Return Value: true if success; otherwise false
847 *
848 */ 422 */
849bool CARDbRadioPowerOff(struct vnt_private *pDevice) 423bool CARDbRadioPowerOff(struct vnt_private *pDevice)
850{ 424{
@@ -861,7 +435,7 @@ bool CARDbRadioPowerOff(struct vnt_private *pDevice)
861 435
862 case RF_AIROHA: 436 case RF_AIROHA:
863 case RF_AL2230S: 437 case RF_AL2230S:
864 case RF_AIROHA7230: //RobertYu:20050104 438 case RF_AIROHA7230:
865 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE2); 439 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE2);
866 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3); 440 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
867 break; 441 break;
@@ -870,12 +444,11 @@ bool CARDbRadioPowerOff(struct vnt_private *pDevice)
870 444
871 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON); 445 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
872 446
873 BBvSetDeepSleep(pDevice->PortOffset, pDevice->byLocalID); 447 BBvSetDeepSleep(pDevice, pDevice->byLocalID);
874 448
875 pDevice->bRadioOff = true; 449 pDevice->bRadioOff = true;
876 //2007-0409-03,<Add> by chester
877 pr_debug("chester power off\n"); 450 pr_debug("chester power off\n");
878 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue 451 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); /* LED issue */
879 return bResult; 452 return bResult;
880} 453}
881 454
@@ -889,7 +462,6 @@ bool CARDbRadioPowerOff(struct vnt_private *pDevice)
889 * none 462 * none
890 * 463 *
891 * Return Value: true if success; otherwise false 464 * Return Value: true if success; otherwise false
892 *
893 */ 465 */
894bool CARDbRadioPowerOn(struct vnt_private *pDevice) 466bool CARDbRadioPowerOn(struct vnt_private *pDevice)
895{ 467{
@@ -907,7 +479,7 @@ bool CARDbRadioPowerOn(struct vnt_private *pDevice)
907 pr_debug("chester pbRadioOff\n"); 479 pr_debug("chester pbRadioOff\n");
908 return true; } 480 return true; }
909 481
910 BBvExitDeepSleep(pDevice->PortOffset, pDevice->byLocalID); 482 BBvExitDeepSleep(pDevice, pDevice->byLocalID);
911 483
912 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON); 484 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
913 485
@@ -919,7 +491,7 @@ bool CARDbRadioPowerOn(struct vnt_private *pDevice)
919 491
920 case RF_AIROHA: 492 case RF_AIROHA:
921 case RF_AL2230S: 493 case RF_AL2230S:
922 case RF_AIROHA7230: //RobertYu:20050104 494 case RF_AIROHA7230:
923 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 | 495 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 |
924 SOFTPWRCTL_SWPE3)); 496 SOFTPWRCTL_SWPE3));
925 break; 497 break;
@@ -927,493 +499,11 @@ bool CARDbRadioPowerOn(struct vnt_private *pDevice)
927 } 499 }
928 500
929 pDevice->bRadioOff = false; 501 pDevice->bRadioOff = false;
930// 2007-0409-03,<Add> by chester
931 pr_debug("chester power on\n"); 502 pr_debug("chester power on\n");
932 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue 503 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); /* LED issue */
933 return bResult; 504 return bResult;
934} 505}
935 506
936bool CARDbRemoveKey(struct vnt_private *pDevice, unsigned char *pbyBSSID)
937{
938
939 KeybRemoveAllKey(&(pDevice->sKey), pbyBSSID, pDevice->PortOffset);
940 return true;
941}
942
943/*
944 *
945 * Description:
946 * Add BSSID in PMKID Candidate list.
947 *
948 * Parameters:
949 * In:
950 * hDeviceContext - device structure point
951 * pbyBSSID - BSSID address for adding
952 * wRSNCap - BSS's RSN capability
953 * Out:
954 * none
955 *
956 * Return Value: none.
957 *
958 -*/
959bool
960CARDbAdd_PMKID_Candidate(
961 struct vnt_private *pDevice,
962 unsigned char *pbyBSSID,
963 bool bRSNCapExist,
964 unsigned short wRSNCap
965)
966{
967 struct pmkid_candidate *pCandidateList;
968 unsigned int ii = 0;
969
970 pr_debug("bAdd_PMKID_Candidate START: (%d)\n",
971 (int)pDevice->gsPMKIDCandidate.NumCandidates);
972
973 if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST) {
974 pr_debug("vFlush_PMKID_Candidate: 3\n");
975 memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent));
976 }
977
978 for (ii = 0; ii < 6; ii++)
979 pr_debug("%02X ", *(pbyBSSID + ii));
980
981 pr_debug("\n");
982
983 // Update Old Candidate
984 for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
985 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
986 if (!memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) {
987 if (bRSNCapExist && (wRSNCap & BIT0))
988 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
989 else
990 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
991
992 return true;
993 }
994 }
995
996 // New Candidate
997 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates];
998 if (bRSNCapExist && (wRSNCap & BIT0))
999 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
1000 else
1001 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
1002
1003 memcpy(pCandidateList->BSSID, pbyBSSID, ETH_ALEN);
1004 pDevice->gsPMKIDCandidate.NumCandidates++;
1005 pr_debug("NumCandidates:%d\n",
1006 (int)pDevice->gsPMKIDCandidate.NumCandidates);
1007 return true;
1008}
1009
1010void *
1011CARDpGetCurrentAddress(
1012 struct vnt_private *pDevice
1013)
1014{
1015
1016 return pDevice->abyCurrentNetAddr;
1017}
1018
1019/*
1020 *
1021 * Description:
1022 * Start Spectrum Measure defined in 802.11h
1023 *
1024 * Parameters:
1025 * In:
1026 * hDeviceContext - device structure point
1027 * Out:
1028 * none
1029 *
1030 * Return Value: none.
1031 *
1032 -*/
1033bool
1034CARDbStartMeasure(
1035 struct vnt_private *pDevice,
1036 void *pvMeasureEIDs,
1037 unsigned int uNumOfMeasureEIDs
1038)
1039{
1040 PWLAN_IE_MEASURE_REQ pEID = (PWLAN_IE_MEASURE_REQ) pvMeasureEIDs;
1041 u64 qwCurrTSF;
1042 u64 qwStartTSF;
1043 bool bExpired = true;
1044 unsigned short wDuration = 0;
1045
1046 if ((pEID == NULL) ||
1047 (uNumOfMeasureEIDs == 0)) {
1048 return true;
1049 }
1050 CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
1051 if (pDevice->bMeasureInProgress == true) {
1052 pDevice->bMeasureInProgress = false;
1053 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
1054 MACvSelectPage1(pDevice->PortOffset);
1055 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
1056 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
1057 // clear measure control
1058 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
1059 MACvSelectPage0(pDevice->PortOffset);
1060 set_channel(pDevice, pDevice->byOrgChannel);
1061 MACvSelectPage1(pDevice->PortOffset);
1062 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
1063 MACvSelectPage0(pDevice->PortOffset);
1064 }
1065 pDevice->uNumOfMeasureEIDs = uNumOfMeasureEIDs;
1066
1067 do {
1068 pDevice->pCurrMeasureEID = pEID;
1069 pEID++;
1070 pDevice->uNumOfMeasureEIDs--;
1071
1072 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
1073 qwStartTSF = *((u64 *)(pDevice->pCurrMeasureEID->sReq.abyStartTime));
1074 wDuration = *((unsigned short *)(pDevice->pCurrMeasureEID->sReq.abyDuration));
1075 wDuration += 1; // 1 TU for channel switching
1076
1077 if (qwStartTSF == 0) {
1078 // start immediately by setting start TSF == current TSF + 2 TU
1079 qwStartTSF = qwCurrTSF + 2048;
1080
1081 bExpired = false;
1082 break;
1083 } else {
1084 // start at setting start TSF - 1TU(for channel switching)
1085 qwStartTSF -= 1024;
1086 }
1087
1088 if (qwCurrTSF < qwStartTSF) {
1089 bExpired = false;
1090 break;
1091 }
1092 VNTWIFIbMeasureReport(pDevice->pMgmt,
1093 false,
1094 pDevice->pCurrMeasureEID,
1095 MEASURE_MODE_LATE,
1096 pDevice->byBasicMap,
1097 pDevice->byCCAFraction,
1098 pDevice->abyRPIs
1099 );
1100 } else {
1101 // hardware do not support measure
1102 VNTWIFIbMeasureReport(pDevice->pMgmt,
1103 false,
1104 pDevice->pCurrMeasureEID,
1105 MEASURE_MODE_INCAPABLE,
1106 pDevice->byBasicMap,
1107 pDevice->byCCAFraction,
1108 pDevice->abyRPIs
1109 );
1110 }
1111 } while (pDevice->uNumOfMeasureEIDs != 0);
1112
1113 if (!bExpired) {
1114 MACvSelectPage1(pDevice->PortOffset);
1115 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART, (u32)qwStartTSF);
1116 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART + 4, (u32)(qwStartTSF >> 32));
1117 VNSvOutPortW(pDevice->PortOffset + MAC_REG_MSRDURATION, wDuration);
1118 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
1119 MACvSelectPage0(pDevice->PortOffset);
1120 } else {
1121 // all measure start time expired we should complete action
1122 VNTWIFIbMeasureReport(pDevice->pMgmt,
1123 true,
1124 NULL,
1125 0,
1126 pDevice->byBasicMap,
1127 pDevice->byCCAFraction,
1128 pDevice->abyRPIs
1129 );
1130 }
1131 return true;
1132}
1133
1134/*
1135 *
1136 * Description:
1137 * Do Channel Switch defined in 802.11h
1138 *
1139 * Parameters:
1140 * In:
1141 * hDeviceContext - device structure point
1142 * Out:
1143 * none
1144 *
1145 * Return Value: none.
1146 *
1147 -*/
1148bool
1149CARDbChannelSwitch(
1150 struct vnt_private *pDevice,
1151 unsigned char byMode,
1152 unsigned char byNewChannel,
1153 unsigned char byCount
1154)
1155{
1156 bool bResult = true;
1157
1158 if (byCount == 0) {
1159 bResult = set_channel(pDevice, byNewChannel);
1160 VNTWIFIbChannelSwitch(pDevice->pMgmt, byNewChannel);
1161 MACvSelectPage1(pDevice->PortOffset);
1162 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
1163 MACvSelectPage0(pDevice->PortOffset);
1164 return bResult;
1165 }
1166 pDevice->byChannelSwitchCount = byCount;
1167 pDevice->byNewChannel = byNewChannel;
1168 pDevice->bChannelSwitch = true;
1169 if (byMode == 1)
1170 bResult = CARDbStopTxPacket(pDevice, PKT_TYPE_802_11_ALL);
1171
1172 return bResult;
1173}
1174
1175/*
1176 *
1177 * Description:
1178 * Handle Quiet EID defined in 802.11h
1179 *
1180 * Parameters:
1181 * In:
1182 * hDeviceContext - device structure point
1183 * Out:
1184 * none
1185 *
1186 * Return Value: none.
1187 *
1188 -*/
1189bool
1190CARDbSetQuiet(
1191 struct vnt_private *pDevice,
1192 bool bResetQuiet,
1193 unsigned char byQuietCount,
1194 unsigned char byQuietPeriod,
1195 unsigned short wQuietDuration,
1196 unsigned short wQuietOffset
1197)
1198{
1199 unsigned int ii = 0;
1200
1201 if (bResetQuiet) {
1202 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1203 for (ii = 0; ii < MAX_QUIET_COUNT; ii++)
1204 pDevice->sQuiet[ii].bEnable = false;
1205
1206 pDevice->uQuietEnqueue = 0;
1207 pDevice->bEnableFirstQuiet = false;
1208 pDevice->bQuietEnable = false;
1209 pDevice->byQuietStartCount = byQuietCount;
1210 }
1211 if (pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable == false) {
1212 pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable = true;
1213 pDevice->sQuiet[pDevice->uQuietEnqueue].byPeriod = byQuietPeriod;
1214 pDevice->sQuiet[pDevice->uQuietEnqueue].wDuration = wQuietDuration;
1215 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime = (unsigned long) byQuietCount;
1216 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime *= pDevice->wBeaconInterval;
1217 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime += wQuietOffset;
1218 pDevice->uQuietEnqueue++;
1219 pDevice->uQuietEnqueue %= MAX_QUIET_COUNT;
1220 if (pDevice->byQuietStartCount < byQuietCount)
1221 pDevice->byQuietStartCount = byQuietCount;
1222 }
1223 return true;
1224}
1225
1226/*
1227 *
1228 * Description:
1229 * Do Quiet, It will be called by either ISR(after start)
1230 * or VNTWIFI(before start) so we do not need a SPINLOCK
1231 *
1232 * Parameters:
1233 * In:
1234 * hDeviceContext - device structure point
1235 * Out:
1236 * none
1237 *
1238 * Return Value: none.
1239 *
1240 -*/
1241bool
1242CARDbStartQuiet(
1243 struct vnt_private *pDevice
1244)
1245{
1246 unsigned int ii = 0;
1247 unsigned long dwStartTime = 0xFFFFFFFF;
1248 unsigned int uCurrentQuietIndex = 0;
1249 unsigned long dwNextTime = 0;
1250 unsigned long dwGap = 0;
1251 unsigned long dwDuration = 0;
1252
1253 for (ii = 0; ii < MAX_QUIET_COUNT; ii++) {
1254 if ((pDevice->sQuiet[ii].bEnable == true) &&
1255 (dwStartTime > pDevice->sQuiet[ii].dwStartTime)) {
1256 dwStartTime = pDevice->sQuiet[ii].dwStartTime;
1257 uCurrentQuietIndex = ii;
1258 }
1259 }
1260 if (dwStartTime == 0xFFFFFFFF) {
1261 // no more quiet
1262 pDevice->bQuietEnable = false;
1263 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1264 } else {
1265 if (pDevice->bQuietEnable == false) {
1266 // first quiet
1267 pDevice->byQuietStartCount--;
1268 dwNextTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1269 dwNextTime %= pDevice->wBeaconInterval;
1270 MACvSelectPage1(pDevice->PortOffset);
1271 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETINIT, (unsigned short) dwNextTime);
1272 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) pDevice->sQuiet[uCurrentQuietIndex].wDuration);
1273 if (pDevice->byQuietStartCount == 0) {
1274 pDevice->bEnableFirstQuiet = false;
1275 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1276 } else {
1277 pDevice->bEnableFirstQuiet = true;
1278 }
1279 MACvSelectPage0(pDevice->PortOffset);
1280 } else {
1281 if (pDevice->dwCurrentQuietEndTime > pDevice->sQuiet[uCurrentQuietIndex].dwStartTime) {
1282 // overlap with previous Quiet
1283 dwGap = pDevice->dwCurrentQuietEndTime - pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1284 if (dwGap >= pDevice->sQuiet[uCurrentQuietIndex].wDuration) {
1285 // return false to indicate next quiet expired, should call this function again
1286 return false;
1287 }
1288 dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration - dwGap;
1289 dwGap = 0;
1290 } else {
1291 dwGap = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime - pDevice->dwCurrentQuietEndTime;
1292 dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration;
1293 }
1294 // set GAP and Next duration
1295 MACvSelectPage1(pDevice->PortOffset);
1296 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETGAP, (unsigned short) dwGap);
1297 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (unsigned short) dwDuration);
1298 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_QUIETRPT);
1299 MACvSelectPage0(pDevice->PortOffset);
1300 }
1301 pDevice->bQuietEnable = true;
1302 pDevice->dwCurrentQuietEndTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1303 pDevice->dwCurrentQuietEndTime += pDevice->sQuiet[uCurrentQuietIndex].wDuration;
1304 if (pDevice->sQuiet[uCurrentQuietIndex].byPeriod == 0) {
1305 // not period disable current quiet element
1306 pDevice->sQuiet[uCurrentQuietIndex].bEnable = false;
1307 } else {
1308 // set next period start time
1309 dwNextTime = (unsigned long) pDevice->sQuiet[uCurrentQuietIndex].byPeriod;
1310 dwNextTime *= pDevice->wBeaconInterval;
1311 pDevice->sQuiet[uCurrentQuietIndex].dwStartTime = dwNextTime;
1312 }
1313 if (pDevice->dwCurrentQuietEndTime > 0x80010000) {
1314 // decreament all time to avoid wrap around
1315 for (ii = 0; ii < MAX_QUIET_COUNT; ii++) {
1316 if (pDevice->sQuiet[ii].bEnable == true)
1317 pDevice->sQuiet[ii].dwStartTime -= 0x80000000;
1318
1319 }
1320 pDevice->dwCurrentQuietEndTime -= 0x80000000;
1321 }
1322 }
1323 return true;
1324}
1325
1326/*
1327 *
1328 * Description:
1329 * Set Local Power Constraint
1330 *
1331 * Parameters:
1332 * In:
1333 * hDeviceContext - device structure point
1334 * Out:
1335 * none
1336 *
1337 * Return Value: none.
1338 *
1339 -*/
1340void
1341CARDvSetPowerConstraint(
1342 struct vnt_private *pDevice,
1343 unsigned char byChannel,
1344 char byPower
1345)
1346{
1347
1348 if (byChannel > CB_MAX_CHANNEL_24G) {
1349 if (pDevice->bCountryInfo5G == true)
1350 pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
1351
1352 } else {
1353 if (pDevice->bCountryInfo24G == true)
1354 pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
1355
1356 }
1357}
1358
1359/*
1360 *
1361 * Description:
1362 * Set Local Power Constraint
1363 *
1364 * Parameters:
1365 * In:
1366 * hDeviceContext - device structure point
1367 * Out:
1368 * none
1369 *
1370 * Return Value: none.
1371 *
1372 -*/
1373void
1374CARDvGetPowerCapability(
1375 struct vnt_private *pDevice,
1376 unsigned char *pbyMinPower,
1377 unsigned char *pbyMaxPower
1378)
1379{
1380 unsigned char byDec = 0;
1381
1382 *pbyMaxPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh];
1383 byDec = pDevice->abyOFDMPwrTbl[pDevice->byCurrentCh];
1384 if (pDevice->byRFType == RF_UW2452) {
1385 byDec *= 3;
1386 byDec >>= 1;
1387 } else {
1388 byDec <<= 1;
1389 }
1390 *pbyMinPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh] - byDec;
1391}
1392
1393/*
1394 *
1395 * Description:
1396 * Get Current Tx Power
1397 *
1398 * Parameters:
1399 * In:
1400 * hDeviceContext - device structure point
1401 * Out:
1402 * none
1403 *
1404 * Return Value: none.
1405 *
1406 */
1407char
1408CARDbyGetTransmitPower(
1409 struct vnt_private *pDevice
1410)
1411{
1412
1413 return pDevice->byCurPwrdBm;
1414}
1415
1416//xxx
1417void 507void
1418CARDvSafeResetTx( 508CARDvSafeResetTx(
1419 struct vnt_private *pDevice 509 struct vnt_private *pDevice
@@ -1422,7 +512,7 @@ CARDvSafeResetTx(
1422 unsigned int uu; 512 unsigned int uu;
1423 PSTxDesc pCurrTD; 513 PSTxDesc pCurrTD;
1424 514
1425 // initialize TD index 515 /* initialize TD index */
1426 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]); 516 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
1427 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]); 517 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
1428 518
@@ -1432,28 +522,27 @@ CARDvSafeResetTx(
1432 for (uu = 0; uu < pDevice->sOpts.nTxDescs[0]; uu++) { 522 for (uu = 0; uu < pDevice->sOpts.nTxDescs[0]; uu++) {
1433 pCurrTD = &(pDevice->apTD0Rings[uu]); 523 pCurrTD = &(pDevice->apTD0Rings[uu]);
1434 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST; 524 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
1435 // init all Tx Packet pointer to NULL 525 /* init all Tx Packet pointer to NULL */
1436 } 526 }
1437 for (uu = 0; uu < pDevice->sOpts.nTxDescs[1]; uu++) { 527 for (uu = 0; uu < pDevice->sOpts.nTxDescs[1]; uu++) {
1438 pCurrTD = &(pDevice->apTD1Rings[uu]); 528 pCurrTD = &(pDevice->apTD1Rings[uu]);
1439 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST; 529 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
1440 // init all Tx Packet pointer to NULL 530 /* init all Tx Packet pointer to NULL */
1441 } 531 }
1442 532
1443 // set MAC TD pointer 533 /* set MAC TD pointer */
1444 MACvSetCurrTXDescAddr(TYPE_TXDMA0, pDevice->PortOffset, 534 MACvSetCurrTXDescAddr(TYPE_TXDMA0, pDevice->PortOffset,
1445 (pDevice->td0_pool_dma)); 535 (pDevice->td0_pool_dma));
1446 536
1447 MACvSetCurrTXDescAddr(TYPE_AC0DMA, pDevice->PortOffset, 537 MACvSetCurrTXDescAddr(TYPE_AC0DMA, pDevice->PortOffset,
1448 (pDevice->td1_pool_dma)); 538 (pDevice->td1_pool_dma));
1449 539
1450 // set MAC Beacon TX pointer 540 /* set MAC Beacon TX pointer */
1451 MACvSetCurrBCNTxDescAddr(pDevice->PortOffset, 541 MACvSetCurrBCNTxDescAddr(pDevice->PortOffset,
1452 (pDevice->tx_beacon_dma)); 542 (pDevice->tx_beacon_dma));
1453} 543}
1454 544
1455/*+ 545/*
1456 *
1457 * Description: 546 * Description:
1458 * Reset Rx 547 * Reset Rx
1459 * 548 *
@@ -1464,8 +553,7 @@ CARDvSafeResetTx(
1464 * none 553 * none
1465 * 554 *
1466 * Return Value: none 555 * Return Value: none
1467 * 556 */
1468 -*/
1469void 557void
1470CARDvSafeResetRx( 558CARDvSafeResetRx(
1471 struct vnt_private *pDevice 559 struct vnt_private *pDevice
@@ -1474,11 +562,11 @@ CARDvSafeResetRx(
1474 unsigned int uu; 562 unsigned int uu;
1475 PSRxDesc pDesc; 563 PSRxDesc pDesc;
1476 564
1477 // initialize RD index 565 /* initialize RD index */
1478 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]); 566 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
1479 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]); 567 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
1480 568
1481 // init state, all RD is chip's 569 /* init state, all RD is chip's */
1482 for (uu = 0; uu < pDevice->sOpts.nRxDescs0; uu++) { 570 for (uu = 0; uu < pDevice->sOpts.nRxDescs0; uu++) {
1483 pDesc = &(pDevice->aRD0Ring[uu]); 571 pDesc = &(pDevice->aRD0Ring[uu]);
1484 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz); 572 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
@@ -1486,7 +574,7 @@ CARDvSafeResetRx(
1486 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz); 574 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
1487 } 575 }
1488 576
1489 // init state, all RD is chip's 577 /* init state, all RD is chip's */
1490 for (uu = 0; uu < pDevice->sOpts.nRxDescs1; uu++) { 578 for (uu = 0; uu < pDevice->sOpts.nRxDescs1; uu++) {
1491 pDesc = &(pDevice->aRD1Ring[uu]); 579 pDesc = &(pDevice->aRD1Ring[uu]);
1492 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz); 580 pDesc->m_rd0RD0.wResCount = (unsigned short)(pDevice->rx_buf_sz);
@@ -1494,13 +582,10 @@ CARDvSafeResetRx(
1494 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz); 582 pDesc->m_rd1RD1.wReqCount = (unsigned short)(pDevice->rx_buf_sz);
1495 } 583 }
1496 584
1497 pDevice->cbDFCB = CB_MAX_RX_FRAG; 585 /* set perPkt mode */
1498 pDevice->cbFreeDFCB = pDevice->cbDFCB;
1499
1500 // set perPkt mode
1501 MACvRx0PerPktMode(pDevice->PortOffset); 586 MACvRx0PerPktMode(pDevice->PortOffset);
1502 MACvRx1PerPktMode(pDevice->PortOffset); 587 MACvRx1PerPktMode(pDevice->PortOffset);
1503 // set MAC RD pointer 588 /* set MAC RD pointer */
1504 MACvSetCurrRx0DescAddr(pDevice->PortOffset, 589 MACvSetCurrRx0DescAddr(pDevice->PortOffset,
1505 pDevice->rd0_pool_dma); 590 pDevice->rd0_pool_dma);
1506 591
@@ -1519,7 +604,6 @@ CARDvSafeResetRx(
1519 * none 604 * none
1520 * 605 *
1521 * Return Value: response Control frame rate 606 * Return Value: response Control frame rate
1522 *
1523 */ 607 */
1524static unsigned short CARDwGetCCKControlRate(struct vnt_private *pDevice, 608static unsigned short CARDwGetCCKControlRate(struct vnt_private *pDevice,
1525 unsigned short wRateIdx) 609 unsigned short wRateIdx)
@@ -1527,7 +611,7 @@ static unsigned short CARDwGetCCKControlRate(struct vnt_private *pDevice,
1527 unsigned int ui = (unsigned int) wRateIdx; 611 unsigned int ui = (unsigned int) wRateIdx;
1528 612
1529 while (ui > RATE_1M) { 613 while (ui > RATE_1M) {
1530 if (pDevice->wBasicRate & ((unsigned short)1 << ui)) 614 if (pDevice->basic_rates & ((u32)0x1 << ui))
1531 return (unsigned short)ui; 615 return (unsigned short)ui;
1532 616
1533 ui--; 617 ui--;
@@ -1546,14 +630,13 @@ static unsigned short CARDwGetCCKControlRate(struct vnt_private *pDevice,
1546 * none 630 * none
1547 * 631 *
1548 * Return Value: response Control frame rate 632 * Return Value: response Control frame rate
1549 *
1550 */ 633 */
1551static unsigned short CARDwGetOFDMControlRate(struct vnt_private *pDevice, 634static unsigned short CARDwGetOFDMControlRate(struct vnt_private *pDevice,
1552 unsigned short wRateIdx) 635 unsigned short wRateIdx)
1553{ 636{
1554 unsigned int ui = (unsigned int) wRateIdx; 637 unsigned int ui = (unsigned int) wRateIdx;
1555 638
1556 pr_debug("BASIC RATE: %X\n", pDevice->wBasicRate); 639 pr_debug("BASIC RATE: %X\n", pDevice->basic_rates);
1557 640
1558 if (!CARDbIsOFDMinBasicRate((void *)pDevice)) { 641 if (!CARDbIsOFDMinBasicRate((void *)pDevice)) {
1559 pr_debug("CARDwGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx); 642 pr_debug("CARDwGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx);
@@ -1562,7 +645,7 @@ static unsigned short CARDwGetOFDMControlRate(struct vnt_private *pDevice,
1562 return wRateIdx; 645 return wRateIdx;
1563 } 646 }
1564 while (ui > RATE_11M) { 647 while (ui > RATE_11M) {
1565 if (pDevice->wBasicRate & ((unsigned short)1 << ui)) { 648 if (pDevice->basic_rates & ((u32)0x1 << ui)) {
1566 pr_debug("CARDwGetOFDMControlRate : %d\n", ui); 649 pr_debug("CARDwGetOFDMControlRate : %d\n", ui);
1567 return (unsigned short)ui; 650 return (unsigned short)ui;
1568 } 651 }
@@ -1582,14 +665,13 @@ static unsigned short CARDwGetOFDMControlRate(struct vnt_private *pDevice,
1582 * none 665 * none
1583 * 666 *
1584 * Return Value: None. 667 * Return Value: None.
1585 *
1586 */ 668 */
1587void CARDvSetRSPINF(struct vnt_private *pDevice, CARD_PHY_TYPE ePHYType) 669void CARDvSetRSPINF(struct vnt_private *pDevice, u8 bb_type)
1588{ 670{
1589 union vnt_phy_field_swap phy; 671 union vnt_phy_field_swap phy;
1590 unsigned char byTxRate, byRsvTime; //For OFDM 672 unsigned char byTxRate, byRsvTime; /* For OFDM */
1591 673
1592 //Set to Page1 674 /* Set to Page1 */
1593 MACvSelectPage1(pDevice->PortOffset); 675 MACvSelectPage1(pDevice->PortOffset);
1594 676
1595 /* RSPINF_b_1 */ 677 /* RSPINF_b_1 */
@@ -1629,136 +711,72 @@ void CARDvSetRSPINF(struct vnt_private *pDevice, CARD_PHY_TYPE ePHYType)
1629 711
1630 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, phy.field_write); 712 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, phy.field_write);
1631 713
1632 //RSPINF_a_6 714 /* RSPINF_a_6 */
1633 s_vCalculateOFDMRParameter(RATE_6M, 715 s_vCalculateOFDMRParameter(RATE_6M,
1634 ePHYType, 716 bb_type,
1635 &byTxRate, 717 &byTxRate,
1636 &byRsvTime); 718 &byRsvTime);
1637 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime)); 719 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate, byRsvTime));
1638 //RSPINF_a_9 720 /* RSPINF_a_9 */
1639 s_vCalculateOFDMRParameter(RATE_9M, 721 s_vCalculateOFDMRParameter(RATE_9M,
1640 ePHYType, 722 bb_type,
1641 &byTxRate, 723 &byTxRate,
1642 &byRsvTime); 724 &byRsvTime);
1643 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime)); 725 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate, byRsvTime));
1644 //RSPINF_a_12 726 /* RSPINF_a_12 */
1645 s_vCalculateOFDMRParameter(RATE_12M, 727 s_vCalculateOFDMRParameter(RATE_12M,
1646 ePHYType, 728 bb_type,
1647 &byTxRate, 729 &byTxRate,
1648 &byRsvTime); 730 &byRsvTime);
1649 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime)); 731 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate, byRsvTime));
1650 //RSPINF_a_18 732 /* RSPINF_a_18 */
1651 s_vCalculateOFDMRParameter(RATE_18M, 733 s_vCalculateOFDMRParameter(RATE_18M,
1652 ePHYType, 734 bb_type,
1653 &byTxRate, 735 &byTxRate,
1654 &byRsvTime); 736 &byRsvTime);
1655 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime)); 737 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate, byRsvTime));
1656 //RSPINF_a_24 738 /* RSPINF_a_24 */
1657 s_vCalculateOFDMRParameter(RATE_24M, 739 s_vCalculateOFDMRParameter(RATE_24M,
1658 ePHYType, 740 bb_type,
1659 &byTxRate, 741 &byTxRate,
1660 &byRsvTime); 742 &byRsvTime);
1661 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime)); 743 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate, byRsvTime));
1662 //RSPINF_a_36 744 /* RSPINF_a_36 */
1663 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_36M), 745 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_36M),
1664 ePHYType, 746 bb_type,
1665 &byTxRate, 747 &byTxRate,
1666 &byRsvTime); 748 &byRsvTime);
1667 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime)); 749 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate, byRsvTime));
1668 //RSPINF_a_48 750 /* RSPINF_a_48 */
1669 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_48M), 751 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_48M),
1670 ePHYType, 752 bb_type,
1671 &byTxRate, 753 &byTxRate,
1672 &byRsvTime); 754 &byRsvTime);
1673 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime)); 755 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate, byRsvTime));
1674 //RSPINF_a_54 756 /* RSPINF_a_54 */
1675 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M), 757 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
1676 ePHYType, 758 bb_type,
1677 &byTxRate, 759 &byTxRate,
1678 &byRsvTime); 760 &byRsvTime);
1679 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime)); 761 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate, byRsvTime));
1680 762 /* RSPINF_a_72 */
1681 //RSPINF_a_72
1682 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M), 763 s_vCalculateOFDMRParameter(CARDwGetOFDMControlRate((void *)pDevice, RATE_54M),
1683 ePHYType, 764 bb_type,
1684 &byTxRate, 765 &byTxRate,
1685 &byRsvTime); 766 &byRsvTime);
1686 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime)); 767 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate, byRsvTime));
1687 //Set to Page0 768 /* Set to Page0 */
1688 MACvSelectPage0(pDevice->PortOffset); 769 MACvSelectPage0(pDevice->PortOffset);
1689} 770}
1690 771
1691/*
1692 * Description: Update IFS
1693 *
1694 * Parameters:
1695 * In:
1696 * pDevice - The adapter to be set
1697 * Out:
1698 * none
1699 *
1700 * Return Value: None.
1701 *
1702 */
1703void vUpdateIFS(struct vnt_private *pDevice)
1704{
1705 /* Set SIFS, DIFS, EIFS, SlotTime, CwMin */
1706
1707 unsigned char byMaxMin = 0;
1708
1709 if (pDevice->byPacketType == PK_TYPE_11A) {//0000 0000 0000 0000,11a
1710 pDevice->uSlot = C_SLOT_SHORT;
1711 pDevice->uSIFS = C_SIFS_A;
1712 pDevice->uDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
1713 pDevice->uCwMin = C_CWMIN_A;
1714 byMaxMin = 4;
1715 } else if (pDevice->byPacketType == PK_TYPE_11B) {//0000 0001 0000 0000,11b
1716 pDevice->uSlot = C_SLOT_LONG;
1717 pDevice->uSIFS = C_SIFS_BG;
1718 pDevice->uDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
1719 pDevice->uCwMin = C_CWMIN_B;
1720 byMaxMin = 5;
1721 } else { // PK_TYPE_11GA & PK_TYPE_11GB
1722 pDevice->uSIFS = C_SIFS_BG;
1723 if (pDevice->bShortSlotTime)
1724 pDevice->uSlot = C_SLOT_SHORT;
1725 else
1726 pDevice->uSlot = C_SLOT_LONG;
1727
1728 pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot;
1729 if (pDevice->wBasicRate & 0x0150) { //0000 0001 0101 0000,24M,12M,6M
1730 pDevice->uCwMin = C_CWMIN_A;
1731 byMaxMin = 4;
1732 } else {
1733 pDevice->uCwMin = C_CWMIN_B;
1734 byMaxMin = 5;
1735 }
1736 }
1737
1738 pDevice->uCwMax = C_CWMAX;
1739 pDevice->uEIFS = C_EIFS;
1740 if (pDevice->byRFType == RF_RFMD2959) {
1741 // bcs TX_PE will reserve 3 us
1742 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)(pDevice->uSIFS - 3));
1743 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)(pDevice->uDIFS - 3));
1744 } else {
1745 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (unsigned char)pDevice->uSIFS);
1746 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (unsigned char)pDevice->uDIFS);
1747 }
1748 VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, (unsigned char)pDevice->uEIFS);
1749 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, (unsigned char)pDevice->uSlot);
1750 byMaxMin |= 0xA0;//1010 1111,C_CWMAX = 1023
1751 VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, (unsigned char)byMaxMin);
1752}
1753
1754void CARDvUpdateBasicTopRate(struct vnt_private *pDevice) 772void CARDvUpdateBasicTopRate(struct vnt_private *pDevice)
1755{ 773{
1756 unsigned char byTopOFDM = RATE_24M, byTopCCK = RATE_1M; 774 unsigned char byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
1757 unsigned char ii; 775 unsigned char ii;
1758 776
1759 //Determines the highest basic rate. 777 /* Determines the highest basic rate. */
1760 for (ii = RATE_54M; ii >= RATE_6M; ii--) { 778 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
1761 if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii))) { 779 if ((pDevice->basic_rates) & ((u32)(1 << ii))) {
1762 byTopOFDM = ii; 780 byTopOFDM = ii;
1763 break; 781 break;
1764 } 782 }
@@ -1766,7 +784,7 @@ void CARDvUpdateBasicTopRate(struct vnt_private *pDevice)
1766 pDevice->byTopOFDMBasicRate = byTopOFDM; 784 pDevice->byTopOFDMBasicRate = byTopOFDM;
1767 785
1768 for (ii = RATE_11M;; ii--) { 786 for (ii = RATE_11M;; ii--) {
1769 if ((pDevice->wBasicRate) & ((unsigned short)(1<<ii))) { 787 if ((pDevice->basic_rates) & ((u32)(1 << ii))) {
1770 byTopCCK = ii; 788 byTopCCK = ii;
1771 break; 789 break;
1772 } 790 }
@@ -1776,24 +794,12 @@ void CARDvUpdateBasicTopRate(struct vnt_private *pDevice)
1776 pDevice->byTopCCKBasicRate = byTopCCK; 794 pDevice->byTopCCKBasicRate = byTopCCK;
1777} 795}
1778 796
1779bool CARDbAddBasicRate(struct vnt_private *pDevice, unsigned short wRateIdx)
1780{
1781 unsigned short wRate = (unsigned short)(1<<wRateIdx);
1782
1783 pDevice->wBasicRate |= wRate;
1784
1785 //Determines the highest basic rate.
1786 CARDvUpdateBasicTopRate((void *)pDevice);
1787
1788 return true;
1789}
1790
1791bool CARDbIsOFDMinBasicRate(struct vnt_private *pDevice) 797bool CARDbIsOFDMinBasicRate(struct vnt_private *pDevice)
1792{ 798{
1793 int ii; 799 int ii;
1794 800
1795 for (ii = RATE_54M; ii >= RATE_6M; ii--) { 801 for (ii = RATE_54M; ii >= RATE_6M; ii--) {
1796 if ((pDevice->wBasicRate) & ((unsigned short)(1 << ii))) 802 if ((pDevice->basic_rates) & ((u32)(1 << ii)))
1797 return true; 803 return true;
1798 } 804 }
1799 return false; 805 return false;
@@ -1821,10 +827,11 @@ unsigned char CARDbyGetPktType(struct vnt_private *pDevice)
1821 * none 827 * none
1822 * 828 *
1823 * Return Value: none 829 * Return Value: none
1824 *
1825 */ 830 */
1826void CARDvSetLoopbackMode(void __iomem *dwIoBase, unsigned short wLoopbackMode) 831void CARDvSetLoopbackMode(struct vnt_private *priv, unsigned short wLoopbackMode)
1827{ 832{
833 void __iomem *dwIoBase = priv->PortOffset;
834
1828 switch (wLoopbackMode) { 835 switch (wLoopbackMode) {
1829 case CARD_LB_NONE: 836 case CARD_LB_NONE:
1830 case CARD_LB_MAC: 837 case CARD_LB_MAC:
@@ -1834,9 +841,9 @@ void CARDvSetLoopbackMode(void __iomem *dwIoBase, unsigned short wLoopbackMode)
1834 ASSERT(false); 841 ASSERT(false);
1835 break; 842 break;
1836 } 843 }
1837 // set MAC loopback 844 /* set MAC loopback */
1838 MACvSetLoopbackMode(dwIoBase, LOBYTE(wLoopbackMode)); 845 MACvSetLoopbackMode(dwIoBase, LOBYTE(wLoopbackMode));
1839 // set Baseband loopback 846 /* set Baseband loopback */
1840} 847}
1841 848
1842/* 849/*
@@ -1849,12 +856,11 @@ void CARDvSetLoopbackMode(void __iomem *dwIoBase, unsigned short wLoopbackMode)
1849 * none 856 * none
1850 * 857 *
1851 * Return Value: none 858 * Return Value: none
1852 *
1853 */ 859 */
1854bool CARDbSoftwareReset(struct vnt_private *pDevice) 860bool CARDbSoftwareReset(struct vnt_private *pDevice)
1855{ 861{
1856 862
1857 // reset MAC 863 /* reset MAC */
1858 if (!MACbSafeSoftwareReset(pDevice->PortOffset)) 864 if (!MACbSafeSoftwareReset(pDevice->PortOffset))
1859 return false; 865 return false;
1860 866
@@ -1874,7 +880,6 @@ bool CARDbSoftwareReset(struct vnt_private *pDevice)
1874 * none 880 * none
1875 * 881 *
1876 * Return Value: TSF Offset value 882 * Return Value: TSF Offset value
1877 *
1878 */ 883 */
1879u64 CARDqGetTSFOffset(unsigned char byRxRate, u64 qwTSF1, u64 qwTSF2) 884u64 CARDqGetTSFOffset(unsigned char byRxRate, u64 qwTSF1, u64 qwTSF2)
1880{ 885{
@@ -1901,10 +906,10 @@ u64 CARDqGetTSFOffset(unsigned char byRxRate, u64 qwTSF1, u64 qwTSF2)
1901 * qwCurrTSF - Current TSF counter 906 * qwCurrTSF - Current TSF counter
1902 * 907 *
1903 * Return Value: true if success; otherwise false 908 * Return Value: true if success; otherwise false
1904 *
1905 */ 909 */
1906bool CARDbGetCurrentTSF(void __iomem *dwIoBase, u64 *pqwCurrTSF) 910bool CARDbGetCurrentTSF(struct vnt_private *priv, u64 *pqwCurrTSF)
1907{ 911{
912 void __iomem *dwIoBase = priv->PortOffset;
1908 unsigned short ww; 913 unsigned short ww;
1909 unsigned char byData; 914 unsigned char byData;
1910 915
@@ -1934,17 +939,12 @@ bool CARDbGetCurrentTSF(void __iomem *dwIoBase, u64 *pqwCurrTSF)
1934 * qwCurrTSF - Current TSF counter 939 * qwCurrTSF - Current TSF counter
1935 * 940 *
1936 * Return Value: TSF value of next Beacon 941 * Return Value: TSF value of next Beacon
1937 *
1938 */ 942 */
1939u64 CARDqGetNextTBTT(u64 qwTSF, unsigned short wBeaconInterval) 943u64 CARDqGetNextTBTT(u64 qwTSF, unsigned short wBeaconInterval)
1940{ 944{
1941 u32 beacon_int; 945 u32 beacon_int;
1942 946
1943 beacon_int = wBeaconInterval * 1024; 947 beacon_int = wBeaconInterval * 1024;
1944
1945 /* Next TBTT =
1946 * ((local_current_TSF / beacon_interval) + 1) * beacon_interval
1947 */
1948 if (beacon_int) { 948 if (beacon_int) {
1949 do_div(qwTSF, beacon_int); 949 do_div(qwTSF, beacon_int);
1950 qwTSF += 1; 950 qwTSF += 1;
@@ -1966,16 +966,16 @@ u64 CARDqGetNextTBTT(u64 qwTSF, unsigned short wBeaconInterval)
1966 * none 966 * none
1967 * 967 *
1968 * Return Value: none 968 * Return Value: none
1969 *
1970 */ 969 */
1971void CARDvSetFirstNextTBTT(void __iomem *dwIoBase, unsigned short wBeaconInterval) 970void CARDvSetFirstNextTBTT(struct vnt_private *priv, unsigned short wBeaconInterval)
1972{ 971{
972 void __iomem *dwIoBase = priv->PortOffset;
1973 u64 qwNextTBTT = 0; 973 u64 qwNextTBTT = 0;
1974 974
1975 CARDbGetCurrentTSF(dwIoBase, &qwNextTBTT); //Get Local TSF counter 975 CARDbGetCurrentTSF(priv, &qwNextTBTT); /* Get Local TSF counter */
1976 976
1977 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval); 977 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
1978 // Set NextTBTT 978 /* Set NextTBTT */
1979 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, (u32)qwNextTBTT); 979 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, (u32)qwNextTBTT);
1980 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, (u32)(qwNextTBTT >> 32)); 980 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, (u32)(qwNextTBTT >> 32));
1981 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN); 981 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
@@ -1994,12 +994,13 @@ void CARDvSetFirstNextTBTT(void __iomem *dwIoBase, unsigned short wBeaconInterva
1994 * none 994 * none
1995 * 995 *
1996 * Return Value: none 996 * Return Value: none
1997 *
1998 */ 997 */
1999void CARDvUpdateNextTBTT(void __iomem *dwIoBase, u64 qwTSF, unsigned short wBeaconInterval) 998void CARDvUpdateNextTBTT(struct vnt_private *priv, u64 qwTSF, unsigned short wBeaconInterval)
2000{ 999{
1000 void __iomem *dwIoBase = priv->PortOffset;
1001
2001 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval); 1002 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
2002 // Set NextTBTT 1003 /* Set NextTBTT */
2003 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, (u32)qwTSF); 1004 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, (u32)qwTSF);
2004 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, (u32)(qwTSF >> 32)); 1005 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, (u32)(qwTSF >> 32));
2005 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN); 1006 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
diff --git a/drivers/staging/vt6655/card.h b/drivers/staging/vt6655/card.h
index 96f5b6c46e82..2dfc41952271 100644
--- a/drivers/staging/vt6655/card.h
+++ b/drivers/staging/vt6655/card.h
@@ -29,35 +29,28 @@
29#ifndef __CARD_H__ 29#ifndef __CARD_H__
30#define __CARD_H__ 30#define __CARD_H__
31 31
32#include "ttype.h"
33#include <linux/types.h> 32#include <linux/types.h>
34#include <linux/nl80211.h> 33#include <linux/nl80211.h>
35 34
36// 35/*
37// Loopback mode 36 * Loopback mode
38// 37 *
39// LOBYTE is MAC LB mode, HIBYTE is MII LB mode 38 * LOBYTE is MAC LB mode, HIBYTE is MII LB mode
39 */
40#define CARD_LB_NONE MAKEWORD(MAC_LB_NONE, 0) 40#define CARD_LB_NONE MAKEWORD(MAC_LB_NONE, 0)
41#define CARD_LB_MAC MAKEWORD(MAC_LB_INTERNAL, 0) // PHY must ISO, avoid MAC loopback packet go out 41#define CARD_LB_MAC MAKEWORD(MAC_LB_INTERNAL, 0) /* PHY must ISO, avoid MAC loopback packet go out */
42#define CARD_LB_PHY MAKEWORD(MAC_LB_EXT, 0) 42#define CARD_LB_PHY MAKEWORD(MAC_LB_EXT, 0)
43 43
44#define DEFAULT_MSDU_LIFETIME 512 // ms 44#define DEFAULT_MSDU_LIFETIME 512 /* ms */
45#define DEFAULT_MSDU_LIFETIME_RES_64us 8000 // 64us 45#define DEFAULT_MSDU_LIFETIME_RES_64us 8000 /* 64us */
46 46
47#define DEFAULT_MGN_LIFETIME 8 // ms 47#define DEFAULT_MGN_LIFETIME 8 /* ms */
48#define DEFAULT_MGN_LIFETIME_RES_64us 125 // 64us 48#define DEFAULT_MGN_LIFETIME_RES_64us 125 /* 64us */
49 49
50#define CB_MAX_CHANNEL_24G 14 50#define CB_MAX_CHANNEL_24G 14
51#define CB_MAX_CHANNEL_5G 42 51#define CB_MAX_CHANNEL_5G 42
52#define CB_MAX_CHANNEL (CB_MAX_CHANNEL_24G+CB_MAX_CHANNEL_5G) 52#define CB_MAX_CHANNEL (CB_MAX_CHANNEL_24G+CB_MAX_CHANNEL_5G)
53 53
54typedef enum _CARD_PHY_TYPE {
55 PHY_TYPE_AUTO,
56 PHY_TYPE_11B,
57 PHY_TYPE_11G,
58 PHY_TYPE_11A
59} CARD_PHY_TYPE, *PCARD_PHY_TYPE;
60
61typedef enum _CARD_PKT_TYPE { 54typedef enum _CARD_PKT_TYPE {
62 PKT_TYPE_802_11_BCN, 55 PKT_TYPE_802_11_BCN,
63 PKT_TYPE_802_11_MNG, 56 PKT_TYPE_802_11_MNG,
@@ -73,103 +66,24 @@ typedef enum _CARD_STATUS_TYPE {
73 66
74struct vnt_private; 67struct vnt_private;
75 68
76void CARDvSetRSPINF(struct vnt_private *, CARD_PHY_TYPE ePHYType); 69void CARDvSetRSPINF(struct vnt_private *, u8);
77void vUpdateIFS(struct vnt_private *);
78void CARDvUpdateBasicTopRate(struct vnt_private *); 70void CARDvUpdateBasicTopRate(struct vnt_private *);
79bool CARDbAddBasicRate(struct vnt_private *, unsigned short wRateIdx);
80bool CARDbIsOFDMinBasicRate(struct vnt_private *); 71bool CARDbIsOFDMinBasicRate(struct vnt_private *);
81void CARDvSetLoopbackMode(void __iomem *dwIoBase, unsigned short wLoopbackMode); 72void CARDvSetLoopbackMode(struct vnt_private *, unsigned short wLoopbackMode);
82bool CARDbSoftwareReset(struct vnt_private *); 73bool CARDbSoftwareReset(struct vnt_private *);
83void CARDvSetFirstNextTBTT(void __iomem *dwIoBase, unsigned short wBeaconInterval); 74void CARDvSetFirstNextTBTT(struct vnt_private *, unsigned short wBeaconInterval);
84void CARDvUpdateNextTBTT(void __iomem *dwIoBase, u64 qwTSF, unsigned short wBeaconInterval); 75void CARDvUpdateNextTBTT(struct vnt_private *, u64 qwTSF, unsigned short wBeaconInterval);
85bool CARDbGetCurrentTSF(void __iomem *dwIoBase, u64 *pqwCurrTSF); 76bool CARDbGetCurrentTSF(struct vnt_private *, u64 *pqwCurrTSF);
86u64 CARDqGetNextTBTT(u64 qwTSF, unsigned short wBeaconInterval); 77u64 CARDqGetNextTBTT(u64 qwTSF, unsigned short wBeaconInterval);
87u64 CARDqGetTSFOffset(unsigned char byRxRate, u64 qwTSF1, u64 qwTSF2); 78u64 CARDqGetTSFOffset(unsigned char byRxRate, u64 qwTSF1, u64 qwTSF2);
88bool CARDbSetTxPower(struct vnt_private *, unsigned long ulTxPower);
89unsigned char CARDbyGetPktType(struct vnt_private *); 79unsigned char CARDbyGetPktType(struct vnt_private *);
90void CARDvSafeResetTx(struct vnt_private *); 80void CARDvSafeResetTx(struct vnt_private *);
91void CARDvSafeResetRx(struct vnt_private *); 81void CARDvSafeResetRx(struct vnt_private *);
92bool CARDbRadioPowerOff(struct vnt_private *); 82bool CARDbRadioPowerOff(struct vnt_private *);
93bool CARDbRadioPowerOn(struct vnt_private *); 83bool CARDbRadioPowerOn(struct vnt_private *);
94bool CARDbIsShortPreamble(struct vnt_private *); 84bool CARDbSetPhyParameter(struct vnt_private *, u8);
95bool CARDbIsShorSlotTime(struct vnt_private *);
96bool CARDbSetPhyParameter(struct vnt_private *, CARD_PHY_TYPE ePHYType,
97 unsigned short wCapInfo, unsigned char byERPField,
98 void *pvSupportRateIEs, void *pvExtSupportRateIEs);
99bool CARDbUpdateTSF(struct vnt_private *, unsigned char byRxRate, 85bool CARDbUpdateTSF(struct vnt_private *, unsigned char byRxRate,
100 u64 qwBSSTimestamp, u64 qwLocalTSF); 86 u64 qwBSSTimestamp, u64 qwLocalTSF);
101bool CARDbStopTxPacket(struct vnt_private *, CARD_PKT_TYPE ePktType);
102bool CARDbStartTxPacket(struct vnt_private *, CARD_PKT_TYPE ePktType);
103bool CARDbSetBeaconPeriod(struct vnt_private *, unsigned short wBeaconInterval); 87bool CARDbSetBeaconPeriod(struct vnt_private *, unsigned short wBeaconInterval);
104bool CARDbSetBSSID(struct vnt_private *,
105 unsigned char *pbyBSSID, enum nl80211_iftype);
106
107bool CARDbPowerDown(struct vnt_private *);
108
109bool CARDbSetTxDataRate(struct vnt_private *, unsigned short wDataRate);
110
111bool CARDbRemoveKey(struct vnt_private *, unsigned char *pbyBSSID);
112
113bool
114CARDbAdd_PMKID_Candidate(
115 struct vnt_private *,
116 unsigned char *pbyBSSID,
117 bool bRSNCapExist,
118 unsigned short wRSNCap
119);
120
121void *
122CARDpGetCurrentAddress(
123 struct vnt_private *
124);
125
126bool
127CARDbStartMeasure(
128 struct vnt_private *,
129 void *pvMeasureEIDs,
130 unsigned int uNumOfMeasureEIDs
131);
132
133bool
134CARDbChannelSwitch(
135 struct vnt_private *,
136 unsigned char byMode,
137 unsigned char byNewChannel,
138 unsigned char byCount
139);
140
141bool
142CARDbSetQuiet(
143 struct vnt_private *,
144 bool bResetQuiet,
145 unsigned char byQuietCount,
146 unsigned char byQuietPeriod,
147 unsigned short wQuietDuration,
148 unsigned short wQuietOffset
149);
150
151bool
152CARDbStartQuiet(
153 struct vnt_private *
154);
155
156void
157CARDvSetPowerConstraint(
158 struct vnt_private *,
159 unsigned char byChannel,
160 char byPower
161);
162
163void
164CARDvGetPowerCapability(
165 struct vnt_private *,
166 unsigned char *pbyMinPower,
167 unsigned char *pbyMaxPower
168);
169
170char
171CARDbyGetTransmitPower(
172 struct vnt_private *
173);
174 88
175#endif // __CARD_H__ 89#endif /* __CARD_H__ */
diff --git a/drivers/staging/vt6655/channel.c b/drivers/staging/vt6655/channel.c
index 4ce964ba14b7..c8f739dd346e 100644
--- a/drivers/staging/vt6655/channel.c
+++ b/drivers/staging/vt6655/channel.c
@@ -21,494 +21,148 @@
21 */ 21 */
22 22
23#include "baseband.h" 23#include "baseband.h"
24#include "country.h"
25#include "channel.h" 24#include "channel.h"
26#include "device.h" 25#include "device.h"
27#include "rf.h" 26#include "rf.h"
28 27
29/*--------------------- Static Definitions -------------------------*/ 28static struct ieee80211_rate vnt_rates_bg[] = {
30 29 { .bitrate = 10, .hw_value = RATE_1M },
31#define CARD_MAX_CHANNEL_TBL 56 30 { .bitrate = 20, .hw_value = RATE_2M },
32 31 { .bitrate = 55, .hw_value = RATE_5M },
33/*--------------------- Static Variables --------------------------*/ 32 { .bitrate = 110, .hw_value = RATE_11M },
34 33 { .bitrate = 60, .hw_value = RATE_6M },
35static SChannelTblElement sChannelTbl[CARD_MAX_CHANNEL_TBL + 1] = 34 { .bitrate = 90, .hw_value = RATE_9M },
36{ 35 { .bitrate = 120, .hw_value = RATE_12M },
37 {0, 0, false, 0}, 36 { .bitrate = 180, .hw_value = RATE_18M },
38 {1, 2412, true, 0}, 37 { .bitrate = 240, .hw_value = RATE_24M },
39 {2, 2417, true, 0}, 38 { .bitrate = 360, .hw_value = RATE_36M },
40 {3, 2422, true, 0}, 39 { .bitrate = 480, .hw_value = RATE_48M },
41 {4, 2427, true, 0}, 40 { .bitrate = 540, .hw_value = RATE_54M },
42 {5, 2432, true, 0},
43 {6, 2437, true, 0},
44 {7, 2442, true, 0},
45 {8, 2447, true, 0},
46 {9, 2452, true, 0},
47 {10, 2457, true, 0},
48 {11, 2462, true, 0},
49 {12, 2467, true, 0},
50 {13, 2472, true, 0},
51 {14, 2484, true, 0},
52 {183, 4915, true, 0},
53 {184, 4920, true, 0},
54 {185, 4925, true, 0},
55 {187, 4935, true, 0},
56 {188, 4940, true, 0},
57 {189, 4945, true, 0},
58 {192, 4960, true, 0},
59 {196, 4980, true, 0},
60 {7, 5035, true, 0},
61 {8, 5040, true, 0},
62 {9, 5045, true, 0},
63 {11, 5055, true, 0},
64 {12, 5060, true, 0},
65 {16, 5080, true, 0},
66 {34, 5170, true, 0},
67 {36, 5180, true, 0},
68 {38, 5190, true, 0},
69 {40, 5200, true, 0},
70 {42, 5210, true, 0},
71 {44, 5220, true, 0},
72 {46, 5230, true, 0},
73 {48, 5240, true, 0},
74 {52, 5260, true, 0},
75 {56, 5280, true, 0},
76 {60, 5300, true, 0},
77 {64, 5320, true, 0},
78 {100, 5500, true, 0},
79 {104, 5520, true, 0},
80 {108, 5540, true, 0},
81 {112, 5560, true, 0},
82 {116, 5580, true, 0},
83 {120, 5600, true, 0},
84 {124, 5620, true, 0},
85 {128, 5640, true, 0},
86 {132, 5660, true, 0},
87 {136, 5680, true, 0},
88 {140, 5700, true, 0},
89 {149, 5745, true, 0},
90 {153, 5765, true, 0},
91 {157, 5785, true, 0},
92 {161, 5805, true, 0},
93 {165, 5825, true, 0}
94}; 41};
95 42
96/************************************************************************ 43static struct ieee80211_rate vnt_rates_a[] = {
97 * The Radar regulation rules for each country 44 { .bitrate = 60, .hw_value = RATE_6M },
98 ************************************************************************/ 45 { .bitrate = 90, .hw_value = RATE_9M },
99static struct 46 { .bitrate = 120, .hw_value = RATE_12M },
100{ 47 { .bitrate = 180, .hw_value = RATE_18M },
101 unsigned char byChannelCountryCode; /* The country code */ 48 { .bitrate = 240, .hw_value = RATE_24M },
102 char chCountryCode[2]; 49 { .bitrate = 360, .hw_value = RATE_36M },
103 unsigned char bChannelIdxList[CB_MAX_CHANNEL]; /* Available channels Index */ 50 { .bitrate = 480, .hw_value = RATE_48M },
104 unsigned char byPower[CB_MAX_CHANNEL]; 51 { .bitrate = 540, .hw_value = RATE_54M },
105} ChannelRuleTab[] =
106{
107/************************************************************************
108 * This table is based on Athero driver rules
109 ************************************************************************/
110/* Country Available channels, ended with 0 */
111/* 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 */
112 {CCODE_FCC, {'U' , 'S'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
113 , { 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 17, 0, 17, 0, 17, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
114 {CCODE_TELEC, {'J' , 'P'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
115 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 23, 0, 0, 23, 0, 23, 23, 0, 23, 0, 0, 23, 23, 23, 0, 23, 0, 23, 0, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
116 {CCODE_ETSI, {'E' , 'U'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
117 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
118 {CCODE_RESV3, {' ' , ' '}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
119 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
120 {CCODE_RESV4, {' ' , ' '}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
121 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
122 {CCODE_RESV5, {' ' , ' '}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
123 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
124 {CCODE_RESV6, {' ' , ' '}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
125 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
126 {CCODE_RESV7, {' ' , ' '}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
127 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
128 {CCODE_RESV8, {' ' , ' '}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
129 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
130 {CCODE_RESV9, {' ' , ' '}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
131 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
132 {CCODE_RESVa, {' ' , ' '}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
133 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
134 {CCODE_RESVb, {' ' , ' '}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
135 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
136 {CCODE_RESVc, {' ' , ' '}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
137 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
138 {CCODE_RESVd, {' ' , ' '}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
139 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
140 {CCODE_RESVe, {' ' , ' '}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
141 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
142 {CCODE_ALLBAND, {' ' , ' '}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
143 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
144 {CCODE_ALBANIA, {'A' , 'L'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
145 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
146 {CCODE_ALGERIA, {'D' , 'Z'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
147 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
148 {CCODE_ARGENTINA, {'A' , 'R'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0}
149 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 17, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 0} },
150 {CCODE_ARMENIA, {'A' , 'M'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
151 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 18, 0, 18, 0, 18, 18, 18, 18, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
152 {CCODE_AUSTRALIA, {'A' , 'U'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
153 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 0, 23, 0, 23, 0, 23, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
154 {CCODE_AUSTRIA, {'A' , 'T'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
155 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 15, 0, 15, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
156 {CCODE_AZERBAIJAN, {'A' , 'Z'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
157 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 18, 0, 18, 0, 18, 18, 18, 18, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
158 {CCODE_BAHRAIN, {'B' , 'H'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
159 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
160 {CCODE_BELARUS, {'B' , 'Y'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
161 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
162 {CCODE_BELGIUM, {'B' , 'E'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
163 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 18, 0, 18, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
164 {CCODE_BELIZE, {'B' , 'Z'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
165 , { 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
166 {CCODE_BOLIVIA, {'B' , 'O'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
167 , { 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
168 {CCODE_BRAZIL, {'B' , 'R'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
169 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
170 {CCODE_BRUNEI_DARUSSALAM, {'B' , 'N'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
171 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
172 {CCODE_BULGARIA, {'B' , 'G'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
173 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 0, 23, 0, 23, 0, 23, 23, 23, 0, 0, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 0, 0, 0, 0, 0} },
174 {CCODE_CANADA, {'C' , 'A'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
175 , { 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 17, 0, 17, 0, 17, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
176 {CCODE_CHILE, {'C' , 'L'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
177 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 17, 17, 17, 17} },
178 {CCODE_CHINA, {'C' , 'N'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
179 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
180 {CCODE_COLOMBIA, {'C' , 'O'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
181 , { 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 17, 0, 17, 0, 17, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
182 {CCODE_COSTA_RICA, {'C' , 'R'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
183 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
184 {CCODE_CROATIA, {'H' , 'R'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
185 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
186 {CCODE_CYPRUS, {'C' , 'Y'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
187 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
188 {CCODE_CZECH, {'C' , 'Z'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
189 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
190 {CCODE_DENMARK, {'D' , 'K'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
191 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
192 {CCODE_DOMINICAN_REPUBLIC, {'D' , 'O'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
193 , { 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 17, 0, 17, 0, 17, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
194 {CCODE_ECUADOR, {'E' , 'C'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
195 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
196 {CCODE_EGYPT, {'E' , 'G'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
197 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
198 {CCODE_EL_SALVADOR, {'S' , 'V'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
199 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
200 {CCODE_ESTONIA, {'E' , 'E'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
201 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
202 {CCODE_FINLAND, {'F' , 'I'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
203 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
204 {CCODE_FRANCE, {'F' , 'R'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
205 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
206 {CCODE_GERMANY, {'D' , 'E'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
207 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
208 {CCODE_GREECE, {'G' , 'R'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
209 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
210 {CCODE_GEORGIA, {'G' , 'E'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
211 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 18, 0, 18, 0, 18, 18, 18, 18, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
212 {CCODE_GUATEMALA, {'G' , 'T'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
213 , { 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 17, 0, 17, 0, 17, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
214 {CCODE_HONDURAS, {'H' , 'N'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
215 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
216 {CCODE_HONG_KONG, {'H' , 'K'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
217 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 0, 23, 0, 23, 0, 23, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
218 {CCODE_HUNGARY, {'H' , 'U'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
219 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 18, 0, 18, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
220 {CCODE_ICELAND, {'I' , 'S'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
221 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
222 {CCODE_INDIA, {'I' , 'N'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
223 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
224 {CCODE_INDONESIA, {'I' , 'D'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
225 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
226 {CCODE_IRAN, {'I' , 'R'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
227 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
228 {CCODE_IRELAND, {'I' , 'E'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
229 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
230 {CCODE_ITALY, {'I' , 'T'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
231 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
232 {CCODE_ISRAEL, {'I' , 'L'}, { 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
233 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
234 {CCODE_JAPAN, {'J' , 'P'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
235 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 0, 23, 0, 23, 0, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
236 {CCODE_JORDAN, {'J' , 'O'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
237 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
238 {CCODE_KAZAKHSTAN, {'K' , 'Z'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
239 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
240 {CCODE_KUWAIT, {'K' , 'W'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
241 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
242 {CCODE_LATVIA, {'L' , 'V'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
243 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
244 {CCODE_LEBANON, {'L' , 'B'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
245 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
246 {CCODE_LEICHTENSTEIN, {'L' , 'I'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
247 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 18, 0, 18, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
248 {CCODE_LITHUANIA, {'L' , 'T'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
249 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
250 {CCODE_LUXEMBURG, {'L' , 'U'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
251 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
252 {CCODE_MACAU, {'M' , 'O'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
253 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 0, 23, 0, 23, 0, 23, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
254 {CCODE_MACEDONIA, {'M' , 'K'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
255 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
256 {CCODE_MALTA, {'M' , 'T'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0}
257 , { 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 16, 0, 16, 0, 16, 16, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 16, 16, 16, 0} },
258 {CCODE_MALAYSIA, {'M' , 'Y'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
259 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
260 {CCODE_MEXICO, {'M' , 'X'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
261 , { 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 17, 0, 17, 0, 17, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
262 {CCODE_MONACO, {'M' , 'C'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
263 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 18, 0, 18, 0, 18, 18, 18, 18, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
264 {CCODE_MOROCCO, {'M' , 'A'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
265 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
266 {CCODE_NETHERLANDS, {'N' , 'L'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
267 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
268 {CCODE_NEW_ZEALAND, {'N' , 'Z'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
269 , { 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 0, 23, 0, 23, 0, 23, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
270 {CCODE_NORTH_KOREA, {'K' , 'P'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0}
271 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 23, 23, 23, 0} },
272 {CCODE_NORWAY, {'N' , 'O'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
273 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
274 {CCODE_OMAN, {'O' , 'M'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
275 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
276 {CCODE_PAKISTAN, {'P' , 'K'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
277 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
278 {CCODE_PANAMA, {'P' , 'A'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
279 , { 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 17, 0, 17, 0, 17, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
280 {CCODE_PERU, {'P' , 'E'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
281 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
282 {CCODE_PHILIPPINES, {'P' , 'H'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
283 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 17, 0, 17, 0, 17, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
284 {CCODE_POLAND, {'P' , 'L'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
285 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
286 {CCODE_PORTUGAL, {'P' , 'T'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
287 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
288 {CCODE_PUERTO_RICO, {'P' , 'R'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
289 , { 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 17, 0, 17, 0, 17, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
290 {CCODE_QATAR, {'Q' , 'A'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
291 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
292 {CCODE_ROMANIA, {'R' , 'O'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
293 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
294 {CCODE_RUSSIA, {'R' , 'U'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
295 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
296 {CCODE_SAUDI_ARABIA, {'S' , 'A'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
297 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
298 {CCODE_SINGAPORE, {'S' , 'G'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
299 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 20, 20, 20, 20} },
300 {CCODE_SLOVAKIA, {'S' , 'K'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0}
301 , { 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 16, 0, 16, 0, 16, 16, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 16, 16, 16, 0} },
302 {CCODE_SLOVENIA, {'S' , 'I'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
303 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
304 {CCODE_SOUTH_AFRICA, {'Z' , 'A'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
305 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
306 {CCODE_SOUTH_KOREA, {'K' , 'R'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0}
307 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 23, 23, 23, 0} },
308 {CCODE_SPAIN, {'E' , 'S'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0}
309 , { 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 16, 0, 16, 0, 16, 16, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 16, 16, 16, 0} },
310 {CCODE_SWEDEN, {'S' , 'E'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
311 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
312 {CCODE_SWITZERLAND, {'C' , 'H'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
313 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 18, 0, 18, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
314 {CCODE_SYRIA, {'S' , 'Y'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
315 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
316 {CCODE_TAIWAN, {'T' , 'W'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0}
317 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 17, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 0} },
318 {CCODE_THAILAND, {'T' , 'H'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0}
319 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 23, 23, 23, 0} },
320 {CCODE_TRINIDAD_TOBAGO, {'T' , 'T'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
321 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 18, 0, 18, 0, 18, 18, 18, 18, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
322 {CCODE_TUNISIA, {'T' , 'N'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
323 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
324 {CCODE_TURKEY, {'T' , 'R'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
325 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
326 {CCODE_UK, {'G' , 'B'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
327 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
328 {CCODE_UKRAINE, {'U' , 'A'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
329 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
330 {CCODE_UNITED_ARAB_EMIRATES, {'A' , 'E'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
331 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
332 {CCODE_UNITED_STATES, {'U' , 'S'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
333 , { 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 17, 0, 17, 0, 17, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
334 {CCODE_URUGUAY, {'U' , 'Y'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0}
335 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 23, 23, 23, 0} },
336 {CCODE_UZBEKISTAN, {'U' , 'Z'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
337 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
338 {CCODE_VENEZUELA, {'V' , 'E'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0}
339 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 23, 23, 23, 0} },
340 {CCODE_VIETNAM, {'V' , 'N'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
341 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
342 {CCODE_YEMEN, {'Y' , 'E'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
343 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
344 {CCODE_ZIMBABWE, {'Z' , 'W'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
345 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
346 {CCODE_JAPAN_W52_W53, {'J' , 'J'}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
347 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
348 {CCODE_MAX, {'U' , 'N'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
349 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }
350/* 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 */
351}; 52};
352 53
353/*--------------------- Export Functions --------------------------*/ 54static struct ieee80211_channel vnt_channels_2ghz[] = {
354 55 { .center_freq = 2412, .hw_value = 1 },
355/** 56 { .center_freq = 2417, .hw_value = 2 },
356 * is_channel_valid() - Is Country Channel Valid 57 { .center_freq = 2422, .hw_value = 3 },
357 * @ChanneIndex: defined as VT3253 MAC channel: 58 { .center_freq = 2427, .hw_value = 4 },
358 * 1 = 2.4G channel 1 59 { .center_freq = 2432, .hw_value = 5 },
359 * 2 = 2.4G channel 2 60 { .center_freq = 2437, .hw_value = 6 },
360 * ... 61 { .center_freq = 2442, .hw_value = 7 },
361 * 14 = 2.4G channel 14 62 { .center_freq = 2447, .hw_value = 8 },
362 * 15 = 4.9G channel 183 63 { .center_freq = 2452, .hw_value = 9 },
363 * 16 = 4.9G channel 184 64 { .center_freq = 2457, .hw_value = 10 },
364 * ..... 65 { .center_freq = 2462, .hw_value = 11 },
365 * Output: true if the specified 5GHz band is allowed to be used, 66 { .center_freq = 2467, .hw_value = 12 },
366 * false otherwise. 67 { .center_freq = 2472, .hw_value = 13 },
367 * 4.9G => Ch 183, 184, 185, 187, 188, 189, 192, 196 (Value:15 ~ 22) 68 { .center_freq = 2484, .hw_value = 14 }
368 * 69};
369 * 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64,
370 * 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 (Value 23 ~ 56)
371 */
372
373bool is_channel_valid(unsigned int ChannelIndex)
374{
375 bool bValid;
376
377 bValid = false;
378 /*
379 * If Channel Index is invalid, return invalid
380 */
381 if ((ChannelIndex > CB_MAX_CHANNEL) ||
382 (ChannelIndex == 0)) {
383 bValid = false;
384 goto exit;
385 }
386 70
387 bValid = sChannelTbl[ChannelIndex].bValid; 71static struct ieee80211_channel vnt_channels_5ghz[] = {
72 { .center_freq = 4915, .hw_value = 15 },
73 { .center_freq = 4920, .hw_value = 16 },
74 { .center_freq = 4925, .hw_value = 17 },
75 { .center_freq = 4935, .hw_value = 18 },
76 { .center_freq = 4940, .hw_value = 19 },
77 { .center_freq = 4945, .hw_value = 20 },
78 { .center_freq = 4960, .hw_value = 21 },
79 { .center_freq = 4980, .hw_value = 22 },
80 { .center_freq = 5035, .hw_value = 23 },
81 { .center_freq = 5040, .hw_value = 24 },
82 { .center_freq = 5045, .hw_value = 25 },
83 { .center_freq = 5055, .hw_value = 26 },
84 { .center_freq = 5060, .hw_value = 27 },
85 { .center_freq = 5080, .hw_value = 28 },
86 { .center_freq = 5170, .hw_value = 29 },
87 { .center_freq = 5180, .hw_value = 30 },
88 { .center_freq = 5190, .hw_value = 31 },
89 { .center_freq = 5200, .hw_value = 32 },
90 { .center_freq = 5210, .hw_value = 33 },
91 { .center_freq = 5220, .hw_value = 34 },
92 { .center_freq = 5230, .hw_value = 35 },
93 { .center_freq = 5240, .hw_value = 36 },
94 { .center_freq = 5260, .hw_value = 37 },
95 { .center_freq = 5280, .hw_value = 38 },
96 { .center_freq = 5300, .hw_value = 39 },
97 { .center_freq = 5320, .hw_value = 40 },
98 { .center_freq = 5500, .hw_value = 41 },
99 { .center_freq = 5520, .hw_value = 42 },
100 { .center_freq = 5540, .hw_value = 43 },
101 { .center_freq = 5560, .hw_value = 44 },
102 { .center_freq = 5580, .hw_value = 45 },
103 { .center_freq = 5600, .hw_value = 46 },
104 { .center_freq = 5620, .hw_value = 47 },
105 { .center_freq = 5640, .hw_value = 48 },
106 { .center_freq = 5660, .hw_value = 49 },
107 { .center_freq = 5680, .hw_value = 50 },
108 { .center_freq = 5700, .hw_value = 51 },
109 { .center_freq = 5745, .hw_value = 52 },
110 { .center_freq = 5765, .hw_value = 53 },
111 { .center_freq = 5785, .hw_value = 54 },
112 { .center_freq = 5805, .hw_value = 55 },
113 { .center_freq = 5825, .hw_value = 56 }
114};
388 115
389exit: 116static struct ieee80211_supported_band vnt_supported_2ghz_band = {
390 return bValid; 117 .channels = vnt_channels_2ghz,
391} 118 .n_channels = ARRAY_SIZE(vnt_channels_2ghz),
119 .bitrates = vnt_rates_bg,
120 .n_bitrates = ARRAY_SIZE(vnt_rates_bg),
121};
392 122
393/** 123static struct ieee80211_supported_band vnt_supported_5ghz_band = {
394 * channel_get_list() - Get Available Channel List for a given country 124 .channels = vnt_channels_5ghz,
395 * @CountryCode: The country code defined in country.h 125 .n_channels = ARRAY_SIZE(vnt_channels_5ghz),
396 * 126 .bitrates = vnt_rates_a,
397 * Output: 127 .n_bitrates = ARRAY_SIZE(vnt_rates_a),
398 * pbyChannelTable: (QWORD *) correspondent bit mask 128};
399 * of available channels
400 * 0x0000000000000001 means channel 1 is supported
401 * 0x0000000000000003 means channel 1,2 are supported
402 * 0x000000000000000F means channel 1,2,..15 are supported
403 */
404 129
405bool channel_get_list(unsigned int uCountryCodeIdx, unsigned char *pbyChannelTable) 130void vnt_init_bands(struct vnt_private *priv)
406{ 131{
407 if (uCountryCodeIdx >= CCODE_MAX) 132 struct ieee80211_channel *ch;
408 return false; 133 int i;
409
410 memcpy(pbyChannelTable, ChannelRuleTab[uCountryCodeIdx].bChannelIdxList, CB_MAX_CHANNEL);
411
412 return true;
413}
414 134
415void init_channel_table(void *pDeviceHandler) 135 switch (priv->byRFType) {
416{ 136 case RF_AIROHA7230:
417 struct vnt_private *pDevice = pDeviceHandler; 137 case RF_UW2452:
418 bool bMultiBand = false; 138 case RF_NOTHING:
419 unsigned int ii; 139 default:
140 ch = vnt_channels_5ghz;
420 141
421 for (ii = 1; ii <= CARD_MAX_CHANNEL_TBL; ii++) 142 for (i = 0; i < ARRAY_SIZE(vnt_channels_5ghz); i++) {
422 sChannelTbl[ii].bValid = false; 143 ch[i].max_power = 0x3f;
144 ch[i].flags = IEEE80211_CHAN_NO_HT40;
145 }
423 146
424 switch (pDevice->byRFType) { 147 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
148 &vnt_supported_5ghz_band;
149 /* fallthrough */
425 case RF_RFMD2959: 150 case RF_RFMD2959:
426 case RF_AIROHA: 151 case RF_AIROHA:
427 case RF_AL2230S: 152 case RF_AL2230S:
428 case RF_UW2451: 153 case RF_UW2451:
429 case RF_VT3226: 154 case RF_VT3226:
430 bMultiBand = false; 155 ch = vnt_channels_2ghz;
431 break;
432 case RF_AIROHA7230:
433 case RF_UW2452:
434 case RF_NOTHING:
435 default:
436 bMultiBand = true;
437 break;
438 }
439 156
440 if ((pDevice->dwDiagRefCount != 0) || pDevice->b11hEnable) { 157 for (i = 0; i < ARRAY_SIZE(vnt_channels_2ghz); i++) {
441 if (bMultiBand) { 158 ch[i].max_power = 0x3f;
442 for (ii = 0; ii < CARD_MAX_CHANNEL_TBL; ii++) { 159 ch[i].flags = IEEE80211_CHAN_NO_HT40;
443 sChannelTbl[ii + 1].bValid = true;
444 pDevice->abyRegPwr[ii + 1] = pDevice->abyOFDMDefaultPwr[ii + 1];
445 pDevice->abyLocalPwr[ii + 1] = pDevice->abyOFDMDefaultPwr[ii + 1];
446 }
447 for (ii = 0; ii < CHANNEL_MAX_24G; ii++) {
448 pDevice->abyRegPwr[ii + 1] = pDevice->abyCCKDefaultPwr[ii + 1];
449 pDevice->abyLocalPwr[ii + 1] = pDevice->abyCCKDefaultPwr[ii + 1];
450 }
451 } else {
452 for (ii = 0; ii < CHANNEL_MAX_24G; ii++) {
453 //2008-8-4 <add> by chester
454 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] != 0) {
455 sChannelTbl[ii + 1].bValid = true;
456 pDevice->abyRegPwr[ii + 1] = pDevice->abyCCKDefaultPwr[ii + 1];
457 pDevice->abyLocalPwr[ii + 1] = pDevice->abyCCKDefaultPwr[ii + 1];
458 }
459 }
460 } 160 }
461 } else if (pDevice->byZoneType <= CCODE_MAX) {
462 if (bMultiBand) {
463 for (ii = 0; ii < CARD_MAX_CHANNEL_TBL; ii++) {
464 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] != 0) {
465 sChannelTbl[ii + 1].bValid = true;
466 pDevice->abyRegPwr[ii + 1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
467 pDevice->abyLocalPwr[ii + 1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
468 }
469 }
470 } else {
471 for (ii = 0; ii < CHANNEL_MAX_24G; ii++) {
472 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] != 0) {
473 sChannelTbl[ii + 1].bValid = true;
474 pDevice->abyRegPwr[ii + 1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
475 pDevice->abyLocalPwr[ii + 1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
476 }
477 }
478 }
479 }
480 161
481 pr_info("Zone=[%d][%c][%c]!!\n", 162 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
482 pDevice->byZoneType, 163 &vnt_supported_2ghz_band;
483 ChannelRuleTab[pDevice->byZoneType].chCountryCode[0], 164 break;
484 ChannelRuleTab[pDevice->byZoneType].chCountryCode[1]);
485
486 for (ii = 0; ii < CARD_MAX_CHANNEL_TBL; ii++) {
487 if (pDevice->abyRegPwr[ii + 1] == 0)
488 pDevice->abyRegPwr[ii + 1] = pDevice->abyOFDMDefaultPwr[ii + 1];
489 if (pDevice->abyLocalPwr[ii + 1] == 0)
490 pDevice->abyLocalPwr[ii + 1] = pDevice->abyOFDMDefaultPwr[ii + 1];
491 }
492}
493
494unsigned char get_channel_mapping(void *pDeviceHandler, unsigned char byChannelNumber, CARD_PHY_TYPE ePhyType)
495{
496 unsigned int ii;
497
498 if ((ePhyType == PHY_TYPE_11B) || (ePhyType == PHY_TYPE_11G))
499 return byChannelNumber;
500
501 for (ii = (CB_MAX_CHANNEL_24G + 1); ii <= CB_MAX_CHANNEL;) {
502 if (sChannelTbl[ii].byChannelNumber == byChannelNumber)
503 return (unsigned char) ii;
504 ii++;
505 } 165 }
506 return 0;
507}
508
509unsigned char get_channel_number(void *pDeviceHandler, unsigned char byChannelIndex)
510{
511 return sChannelTbl[byChannelIndex].byChannelNumber;
512} 166}
513 167
514/** 168/**
@@ -528,37 +182,27 @@ bool set_channel(void *pDeviceHandler, unsigned int uConnectionChannel)
528 if (pDevice->byCurrentCh == uConnectionChannel) 182 if (pDevice->byCurrentCh == uConnectionChannel)
529 return bResult; 183 return bResult;
530 184
531 if (!sChannelTbl[uConnectionChannel].bValid) 185 /* clear NAV */
532 return false;
533
534 if ((uConnectionChannel > CB_MAX_CHANNEL_24G) &&
535 (pDevice->eCurrentPHYType != PHY_TYPE_11A)) {
536 CARDbSetPhyParameter(pDevice, PHY_TYPE_11A, 0, 0, NULL, NULL);
537 } else if ((uConnectionChannel <= CB_MAX_CHANNEL_24G) &&
538 (pDevice->eCurrentPHYType == PHY_TYPE_11A)) {
539 CARDbSetPhyParameter(pDevice, PHY_TYPE_11G, 0, 0, NULL, NULL);
540 }
541 // clear NAV
542 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MACCR, MACCR_CLRNAV); 186 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MACCR, MACCR_CLRNAV);
543 187
544 //{{ RobertYu: 20041202 188 /* TX_PE will reserve 3 us for MAX2829 A mode only, it is for better TX throughput */
545 //// TX_PE will reserve 3 us for MAX2829 A mode only, it is for better TX throughput
546 189
547 if (pDevice->byRFType == RF_AIROHA7230) 190 if (pDevice->byRFType == RF_AIROHA7230)
548 RFbAL7230SelectChannelPostProcess(pDevice->PortOffset, pDevice->byCurrentCh, (unsigned char)uConnectionChannel); 191 RFbAL7230SelectChannelPostProcess(pDevice, pDevice->byCurrentCh,
549 //}} RobertYu 192 (unsigned char)uConnectionChannel);
550 193
551 pDevice->byCurrentCh = (unsigned char)uConnectionChannel; 194 pDevice->byCurrentCh = (unsigned char)uConnectionChannel;
552 bResult &= RFbSelectChannel(pDevice->PortOffset, pDevice->byRFType, (unsigned char)uConnectionChannel); 195 bResult &= RFbSelectChannel(pDevice, pDevice->byRFType,
196 (unsigned char)uConnectionChannel);
553 197
554 // Init Synthesizer Table 198 /* Init Synthesizer Table */
555 if (pDevice->bEnablePSMode) 199 if (pDevice->bEnablePSMode)
556 RFvWriteWakeProgSyn(pDevice->PortOffset, pDevice->byRFType, uConnectionChannel); 200 RFvWriteWakeProgSyn(pDevice, pDevice->byRFType, uConnectionChannel);
557 201
558 BBvSoftwareReset(pDevice->PortOffset); 202 BBvSoftwareReset(pDevice);
559 203
560 if (pDevice->byLocalID > REV_ID_VT3253_B1) { 204 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
561 // set HW default power register 205 /* set HW default power register */
562 MACvSelectPage1(pDevice->PortOffset); 206 MACvSelectPage1(pDevice->PortOffset);
563 RFbSetPower(pDevice, RATE_1M, pDevice->byCurrentCh); 207 RFbSetPower(pDevice, RATE_1M, pDevice->byCurrentCh);
564 VNSvOutPortB(pDevice->PortOffset + MAC_REG_PWRCCK, pDevice->byCurPwr); 208 VNSvOutPortB(pDevice->PortOffset + MAC_REG_PWRCCK, pDevice->byCurPwr);
@@ -567,242 +211,10 @@ bool set_channel(void *pDeviceHandler, unsigned int uConnectionChannel)
567 MACvSelectPage0(pDevice->PortOffset); 211 MACvSelectPage0(pDevice->PortOffset);
568 } 212 }
569 213
570 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) 214 if (pDevice->byBBType == BB_TYPE_11B)
571 RFbSetPower(pDevice, RATE_1M, pDevice->byCurrentCh); 215 RFbSetPower(pDevice, RATE_1M, pDevice->byCurrentCh);
572 else 216 else
573 RFbSetPower(pDevice, RATE_6M, pDevice->byCurrentCh); 217 RFbSetPower(pDevice, RATE_6M, pDevice->byCurrentCh);
574 218
575 return bResult; 219 return bResult;
576} 220}
577
578/**
579 * set_country_info() - Set Channel Info of Country
580 *
581 * Return Value: none.
582 *
583 */
584
585void set_country_info(void *pDeviceHandler, CARD_PHY_TYPE ePHYType, void *pIE)
586{
587 struct vnt_private *pDevice = pDeviceHandler;
588 unsigned int ii = 0;
589 unsigned int uu = 0;
590 unsigned int step = 0;
591 unsigned int uNumOfCountryInfo = 0;
592 unsigned char byCh = 0;
593 PWLAN_IE_COUNTRY pIE_Country = (PWLAN_IE_COUNTRY) pIE;
594
595 uNumOfCountryInfo = (pIE_Country->len - 3);
596 uNumOfCountryInfo /= 3;
597
598 if (ePHYType == PHY_TYPE_11A) {
599 pDevice->bCountryInfo5G = true;
600 for (ii = CB_MAX_CHANNEL_24G + 1; ii <= CARD_MAX_CHANNEL_TBL; ii++)
601 sChannelTbl[ii].bValid = false;
602
603 step = 4;
604 } else {
605 pDevice->bCountryInfo24G = true;
606 for (ii = 1; ii <= CB_MAX_CHANNEL_24G; ii++)
607 sChannelTbl[ii].bValid = false;
608
609 step = 1;
610 }
611 pDevice->abyCountryCode[0] = pIE_Country->abyCountryString[0];
612 pDevice->abyCountryCode[1] = pIE_Country->abyCountryString[1];
613 pDevice->abyCountryCode[2] = pIE_Country->abyCountryString[2];
614
615 for (ii = 0; ii < uNumOfCountryInfo; ii++) {
616 for (uu = 0; uu < pIE_Country->abyCountryInfo[ii*3+1]; uu++) {
617 byCh = get_channel_mapping(pDevice, (unsigned char)(pIE_Country->abyCountryInfo[ii*3]+step*uu), ePHYType);
618 sChannelTbl[byCh].bValid = true;
619 pDevice->abyRegPwr[byCh] = pIE_Country->abyCountryInfo[ii*3+2];
620 }
621 }
622}
623
624/**
625 *
626 * set_support_channels() - Set Support Channels IE defined in 802.11h
627 *
628 * @hDeviceContext: device structure point
629 *
630 * Return Value: none.
631 *
632 */
633
634unsigned char set_support_channels(void *pDeviceHandler, unsigned char *pbyIEs)
635{
636 struct vnt_private *pDevice = pDeviceHandler;
637 unsigned int ii;
638 unsigned char byCount;
639 PWLAN_IE_SUPP_CH pIE = (PWLAN_IE_SUPP_CH) pbyIEs;
640 unsigned char *pbyChTupple;
641 unsigned char byLen = 0;
642
643 pIE->byElementID = WLAN_EID_SUPP_CH;
644 pIE->len = 0;
645 pbyChTupple = pIE->abyChannelTuple;
646 byLen = 2;
647 // lower band
648 byCount = 0;
649 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[28] == true) {
650 for (ii = 28; ii < 36; ii += 2) {
651 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] == true)
652 byCount++;
653 }
654
655 *pbyChTupple++ = 34;
656 *pbyChTupple++ = byCount;
657 byLen += 2;
658 } else if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[29] == true) {
659 for (ii = 29; ii < 36; ii += 2) {
660 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] == true)
661 byCount++;
662 }
663
664 *pbyChTupple++ = 36;
665 *pbyChTupple++ = byCount;
666 byLen += 2;
667 }
668 // middle band
669 byCount = 0;
670 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[36] == true) {
671 for (ii = 36; ii < 40; ii++) {
672 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] == true)
673 byCount++;
674 }
675
676 *pbyChTupple++ = 52;
677 *pbyChTupple++ = byCount;
678 byLen += 2;
679 }
680 // higher band
681 byCount = 0;
682 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[40] == true) {
683 for (ii = 40; ii < 51; ii++) {
684 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] == true)
685 byCount++;
686 }
687
688 *pbyChTupple++ = 100;
689 *pbyChTupple++ = byCount;
690 byLen += 2;
691 } else if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[51] == true) {
692 for (ii = 51; ii < 56; ii++) {
693 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] == true)
694 byCount++;
695 }
696
697 *pbyChTupple++ = 149;
698 *pbyChTupple++ = byCount;
699 byLen += 2;
700 }
701 pIE->len += (byLen - 2);
702 return byLen;
703}
704
705void set_country_IE(void *pDeviceHandler, void *pIE)
706{
707 struct vnt_private *pDevice = pDeviceHandler;
708 unsigned int ii;
709 PWLAN_IE_COUNTRY pIECountry = (PWLAN_IE_COUNTRY) pIE;
710
711 pIECountry->byElementID = WLAN_EID_COUNTRY;
712 pIECountry->len = 0;
713 pIECountry->abyCountryString[0] = ChannelRuleTab[pDevice->byZoneType].chCountryCode[0];
714 pIECountry->abyCountryString[1] = ChannelRuleTab[pDevice->byZoneType].chCountryCode[1];
715 pIECountry->abyCountryString[2] = ' ';
716 for (ii = CB_MAX_CHANNEL_24G; ii < CB_MAX_CHANNEL; ii++) {
717 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] != 0) {
718 pIECountry->abyCountryInfo[pIECountry->len++] = sChannelTbl[ii + 1].byChannelNumber;
719 pIECountry->abyCountryInfo[pIECountry->len++] = 1;
720 pIECountry->abyCountryInfo[pIECountry->len++] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
721 }
722 }
723 pIECountry->len += 3;
724}
725
726bool get_channel_map_info(void *pDeviceHandler, unsigned int uChannelIndex,
727 unsigned char *pbyChannelNumber, unsigned char *pbyMap)
728{
729 if (uChannelIndex > CB_MAX_CHANNEL)
730 return false;
731
732 *pbyChannelNumber = sChannelTbl[uChannelIndex].byChannelNumber;
733 *pbyMap = sChannelTbl[uChannelIndex].byMAP;
734 return sChannelTbl[uChannelIndex].bValid;
735}
736
737void set_channel_map_info(void *pDeviceHandler, unsigned int uChannelIndex,
738 unsigned char byMap)
739{
740 if (uChannelIndex > CB_MAX_CHANNEL)
741 return;
742
743 sChannelTbl[uChannelIndex].byMAP |= byMap;
744}
745
746void clear_channel_map_info(void *pDeviceHandler)
747{
748 unsigned int ii = 0;
749
750 for (ii = 1; ii <= CB_MAX_CHANNEL; ii++)
751 sChannelTbl[ii].byMAP = 0;
752}
753
754unsigned char auto_channel_select(void *pDeviceHandler, CARD_PHY_TYPE ePHYType)
755{
756 unsigned int ii = 0;
757 unsigned char byOptionChannel = 0;
758 int aiWeight[CB_MAX_CHANNEL_24G + 1] = {-1000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
759
760 if (ePHYType == PHY_TYPE_11A) {
761 for (ii = CB_MAX_CHANNEL_24G + 1; ii <= CB_MAX_CHANNEL; ii++) {
762 if (sChannelTbl[ii].bValid) {
763 if (byOptionChannel == 0)
764 byOptionChannel = (unsigned char) ii;
765
766 if (sChannelTbl[ii].byMAP == 0)
767 return (unsigned char) ii;
768 else if (!(sChannelTbl[ii].byMAP & 0x08))
769 byOptionChannel = (unsigned char) ii;
770 }
771 }
772 } else {
773 byOptionChannel = 0;
774 for (ii = 1; ii <= CB_MAX_CHANNEL_24G; ii++) {
775 if (sChannelTbl[ii].bValid) {
776 if (sChannelTbl[ii].byMAP == 0) {
777 aiWeight[ii] += 100;
778 } else if (sChannelTbl[ii].byMAP & 0x01) {
779 if (ii > 3)
780 aiWeight[ii - 3] -= 10;
781
782 if (ii > 2)
783 aiWeight[ii - 2] -= 20;
784
785 if (ii > 1)
786 aiWeight[ii - 1] -= 40;
787
788 aiWeight[ii] -= 80;
789 if (ii < CB_MAX_CHANNEL_24G)
790 aiWeight[ii + 1] -= 40;
791
792 if (ii < (CB_MAX_CHANNEL_24G - 1))
793 aiWeight[ii+2] -= 20;
794
795 if (ii < (CB_MAX_CHANNEL_24G - 2))
796 aiWeight[ii+3] -= 10;
797 }
798 }
799 }
800 for (ii = 1; ii <= CB_MAX_CHANNEL_24G; ii++) {
801 if (sChannelTbl[ii].bValid &&
802 (aiWeight[ii] > aiWeight[byOptionChannel])) {
803 byOptionChannel = (unsigned char) ii;
804 }
805 }
806 }
807 return byOptionChannel;
808}
diff --git a/drivers/staging/vt6655/channel.h b/drivers/staging/vt6655/channel.h
index 4f44c8a3d3cf..4f4264e23462 100644
--- a/drivers/staging/vt6655/channel.h
+++ b/drivers/staging/vt6655/channel.h
@@ -23,30 +23,10 @@
23#ifndef _CHANNEL_H_ 23#ifndef _CHANNEL_H_
24#define _CHANNEL_H_ 24#define _CHANNEL_H_
25 25
26#include "ttype.h"
27#include "card.h" 26#include "card.h"
28 27
29typedef struct tagSChannelTblElement { 28void vnt_init_bands(struct vnt_private *);
30 unsigned char byChannelNumber;
31 unsigned int uFrequency;
32 bool bValid;
33 unsigned char byMAP;
34} SChannelTblElement, *PSChannelTblElement;
35 29
36bool is_channel_valid(unsigned int CountryCode);
37void init_channel_table(void *pDeviceHandler);
38unsigned char get_channel_mapping(void *pDeviceHandler, unsigned char byChannelNumber, CARD_PHY_TYPE ePhyType);
39bool channel_get_list(unsigned int uCountryCodeIdx, unsigned char *pbyChannelTable);
40unsigned char get_channel_number(void *pDeviceHandler, unsigned char byChannelIndex);
41bool set_channel(void *pDeviceHandler, unsigned int uConnectionChannel); 30bool set_channel(void *pDeviceHandler, unsigned int uConnectionChannel);
42void set_country_info(void *pDeviceHandler, CARD_PHY_TYPE ePHYType, void *pIE);
43unsigned char set_support_channels(void *pDeviceHandler, unsigned char *pbyIEs);
44void set_country_IE(void *pDeviceHandler, void *pIE);
45bool get_channel_map_info(void *pDeviceHandler, unsigned int uChannelIndex,
46 unsigned char *pbyChannelNumber, unsigned char *pbyMap);
47void set_channel_map_info(void *pDeviceHandler, unsigned int uChannelIndex,
48 unsigned char byMap);
49void clear_channel_map_info(void *pDeviceHandler);
50unsigned char auto_channel_select(void *pDeviceHandler, CARD_PHY_TYPE ePHYType);
51 31
52#endif /* _CHANNEL_H_ */ 32#endif /* _CHANNEL_H_ */
diff --git a/drivers/staging/vt6655/country.h b/drivers/staging/vt6655/country.h
deleted file mode 100644
index 2365fb13b033..000000000000
--- a/drivers/staging/vt6655/country.h
+++ /dev/null
@@ -1,161 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: country.h
21 *
22 * Purpose: Country Code information
23 *
24 * Author: Lucas Lin
25 *
26 * Date: Dec 23, 2004
27 *
28 */
29
30#ifndef __COUNTRY_H__
31#define __COUNTRY_H__
32
33#include "ttype.h"
34
35/************************************************************************
36 * The definition here should be complied with the INF country order
37 * Please check with VNWL.inf/VNWL64.inf/VNWL*.inf
38 ************************************************************************/
39typedef enum _COUNTRY_CODE {
40 CCODE_FCC = 0,
41 CCODE_TELEC,
42 CCODE_ETSI,
43 CCODE_RESV3,
44 CCODE_RESV4,
45 CCODE_RESV5,
46 CCODE_RESV6,
47 CCODE_RESV7,
48 CCODE_RESV8,
49 CCODE_RESV9,
50 CCODE_RESVa,
51 CCODE_RESVb,
52 CCODE_RESVc,
53 CCODE_RESVd,
54 CCODE_RESVe,
55 CCODE_ALLBAND,
56 CCODE_ALBANIA,
57 CCODE_ALGERIA,
58 CCODE_ARGENTINA,
59 CCODE_ARMENIA,
60 CCODE_AUSTRALIA,
61 CCODE_AUSTRIA,
62 CCODE_AZERBAIJAN,
63 CCODE_BAHRAIN,
64 CCODE_BELARUS,
65 CCODE_BELGIUM,
66 CCODE_BELIZE,
67 CCODE_BOLIVIA,
68 CCODE_BRAZIL,
69 CCODE_BRUNEI_DARUSSALAM,
70 CCODE_BULGARIA,
71 CCODE_CANADA,
72 CCODE_CHILE,
73 CCODE_CHINA,
74 CCODE_COLOMBIA,
75 CCODE_COSTA_RICA,
76 CCODE_CROATIA,
77 CCODE_CYPRUS,
78 CCODE_CZECH,
79 CCODE_DENMARK,
80 CCODE_DOMINICAN_REPUBLIC,
81 CCODE_ECUADOR,
82 CCODE_EGYPT,
83 CCODE_EL_SALVADOR,
84 CCODE_ESTONIA,
85 CCODE_FINLAND,
86 CCODE_FRANCE,
87 CCODE_GERMANY,
88 CCODE_GREECE,
89 CCODE_GEORGIA,
90 CCODE_GUATEMALA,
91 CCODE_HONDURAS,
92 CCODE_HONG_KONG,
93 CCODE_HUNGARY,
94 CCODE_ICELAND,
95 CCODE_INDIA,
96 CCODE_INDONESIA,
97 CCODE_IRAN,
98 CCODE_IRELAND,
99 CCODE_ITALY,
100 CCODE_ISRAEL,
101 CCODE_JAPAN,
102 CCODE_JORDAN,
103 CCODE_KAZAKHSTAN,
104 CCODE_KUWAIT,
105 CCODE_LATVIA,
106 CCODE_LEBANON,
107 CCODE_LEICHTENSTEIN,
108 CCODE_LITHUANIA,
109 CCODE_LUXEMBURG,
110 CCODE_MACAU,
111 CCODE_MACEDONIA,
112 CCODE_MALTA,
113 CCODE_MALAYSIA,
114 CCODE_MEXICO,
115 CCODE_MONACO,
116 CCODE_MOROCCO,
117 CCODE_NETHERLANDS,
118 CCODE_NEW_ZEALAND,
119 CCODE_NORTH_KOREA,
120 CCODE_NORWAY,
121 CCODE_OMAN,
122 CCODE_PAKISTAN,
123 CCODE_PANAMA,
124 CCODE_PERU,
125 CCODE_PHILIPPINES,
126 CCODE_POLAND,
127 CCODE_PORTUGAL,
128 CCODE_PUERTO_RICO,
129 CCODE_QATAR,
130 CCODE_ROMANIA,
131 CCODE_RUSSIA,
132 CCODE_SAUDI_ARABIA,
133 CCODE_SINGAPORE,
134 CCODE_SLOVAKIA,
135 CCODE_SLOVENIA,
136 CCODE_SOUTH_AFRICA,
137 CCODE_SOUTH_KOREA,
138 CCODE_SPAIN,
139 CCODE_SWEDEN,
140 CCODE_SWITZERLAND,
141 CCODE_SYRIA,
142 CCODE_TAIWAN,
143 CCODE_THAILAND,
144 CCODE_TRINIDAD_TOBAGO,
145 CCODE_TUNISIA,
146 CCODE_TURKEY,
147 CCODE_UK,
148 CCODE_UKRAINE,
149 CCODE_UNITED_ARAB_EMIRATES,
150 CCODE_UNITED_STATES,
151 CCODE_URUGUAY,
152 CCODE_UZBEKISTAN,
153 CCODE_VENEZUELA,
154 CCODE_VIETNAM,
155 CCODE_YEMEN,
156 CCODE_ZIMBABWE,
157 CCODE_JAPAN_W52_W53,
158 CCODE_MAX
159} COUNTRY_CODE;
160
161#endif /* __COUNTRY_H__ */
diff --git a/drivers/staging/vt6655/datarate.c b/drivers/staging/vt6655/datarate.c
deleted file mode 100644
index 52907a4fae9d..000000000000
--- a/drivers/staging/vt6655/datarate.c
+++ /dev/null
@@ -1,410 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: datarate.c
20 *
21 * Purpose: Handles the auto fallback & data rates functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: July 17, 2002
26 *
27 * Functions:
28 * RATEvParseMaxRate - Parsing the highest basic & support rate in rate field of frame
29 * RATEvTxRateFallBack - Rate fallback Algorithm Implementaion
30 * RATEuSetIE- Set rate IE field.
31 *
32 * Revision History:
33 *
34 */
35
36#include "ttype.h"
37#include "tmacro.h"
38#include "mac.h"
39#include "80211mgr.h"
40#include "bssdb.h"
41#include "datarate.h"
42#include "card.h"
43#include "baseband.h"
44#include "srom.h"
45
46/*--------------------- Static Definitions -------------------------*/
47
48/*--------------------- Static Classes ----------------------------*/
49
50extern unsigned short TxRate_iwconfig; /* 2008-5-8 <add> by chester */
51/*--------------------- Static Variables --------------------------*/
52static const unsigned char acbyIERate[MAX_RATE] = {
530x02, 0x04, 0x0B, 0x16, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C
54};
55
56#define AUTORATE_TXOK_CNT 0x0400
57#define AUTORATE_TXFAIL_CNT 0x0064
58#define AUTORATE_TIMEOUT 10
59
60/*--------------------- Static Functions --------------------------*/
61
62void s_vResetCounter(
63 PKnownNodeDB psNodeDBTable
64);
65
66void
67s_vResetCounter(
68 PKnownNodeDB psNodeDBTable
69)
70{
71 unsigned char ii;
72
73 /* clear statistic counter for auto_rate */
74 for (ii = 0; ii <= MAX_RATE; ii++) {
75 psNodeDBTable->uTxOk[ii] = 0;
76 psNodeDBTable->uTxFail[ii] = 0;
77 }
78}
79
80/*--------------------- Export Variables --------------------------*/
81
82/*--------------------- Export Functions --------------------------*/
83
84/*+
85 *
86 * Description:
87 * Get RateIdx from the value in SuppRates IE or ExtSuppRates IE
88 *
89 * Parameters:
90 * In:
91 * unsigned char - Rate value in SuppRates IE or ExtSuppRates IE
92 * Out:
93 * none
94 *
95 * Return Value: RateIdx
96 *
97 -*/
98unsigned char
99DATARATEbyGetRateIdx(
100 unsigned char byRate
101)
102{
103 unsigned char ii;
104
105 /* Erase basicRate flag. */
106 byRate = byRate & 0x7F;/* 0111 1111 */
107
108 for (ii = 0; ii < MAX_RATE; ii++) {
109 if (acbyIERate[ii] == byRate)
110 return ii;
111 }
112 return 0;
113}
114
115/*+
116 *
117 * Routine Description:
118 * Rate fallback Algorithm Implementation
119 *
120 * Parameters:
121 * In:
122 * pDevice - Pointer to the adapter
123 * psNodeDBTable - Pointer to Node Data Base
124 * Out:
125 * none
126 *
127 * Return Value: none
128 *
129 -*/
130#define AUTORATE_TXCNT_THRESHOLD 20
131#define AUTORATE_INC_THRESHOLD 30
132
133/*+
134 *
135 * Description:
136 * Get RateIdx from the value in SuppRates IE or ExtSuppRates IE
137 *
138 * Parameters:
139 * In:
140 * unsigned char - Rate value in SuppRates IE or ExtSuppRates IE
141 * Out:
142 * none
143 *
144 * Return Value: RateIdx
145 *
146 -*/
147unsigned short
148wGetRateIdx(
149 unsigned char byRate
150)
151{
152 unsigned short ii;
153
154 /* Erase basicRate flag. */
155 byRate = byRate & 0x7F;/* 0111 1111 */
156
157 for (ii = 0; ii < MAX_RATE; ii++) {
158 if (acbyIERate[ii] == byRate)
159 return ii;
160 }
161
162 return 0;
163}
164
165/*+
166 *
167 * Description:
168 * Parsing the highest basic & support rate in rate field of frame.
169 *
170 * Parameters:
171 * In:
172 * pDevice - Pointer to the adapter
173 * pItemRates - Pointer to Rate field defined in 802.11 spec.
174 * pItemExtRates - Pointer to Extended Rate field defined in 802.11 spec.
175 * Out:
176 * pwMaxBasicRate - Maximum Basic Rate
177 * pwMaxSuppRate - Maximum Supported Rate
178 * pbyTopCCKRate - Maximum Basic Rate in CCK mode
179 * pbyTopOFDMRate - Maximum Basic Rate in OFDM mode
180 *
181 * Return Value: none
182 *
183 -*/
184void
185RATEvParseMaxRate(
186 void *pDeviceHandler,
187 PWLAN_IE_SUPP_RATES pItemRates,
188 PWLAN_IE_SUPP_RATES pItemExtRates,
189 bool bUpdateBasicRate,
190 unsigned short *pwMaxBasicRate,
191 unsigned short *pwMaxSuppRate,
192 unsigned short *pwSuppRate,
193 unsigned char *pbyTopCCKRate,
194 unsigned char *pbyTopOFDMRate
195)
196{
197 struct vnt_private *pDevice = pDeviceHandler;
198 unsigned int ii;
199 unsigned char byHighSuppRate = 0;
200 unsigned char byRate = 0;
201 unsigned short wOldBasicRate = pDevice->wBasicRate;
202 unsigned int uRateLen;
203
204 if (pItemRates == NULL)
205 return;
206
207 *pwSuppRate = 0;
208 uRateLen = pItemRates->len;
209
210 pr_debug("ParseMaxRate Len: %d\n", uRateLen);
211 if (pDevice->eCurrentPHYType != PHY_TYPE_11B) {
212 if (uRateLen > WLAN_RATES_MAXLEN)
213 uRateLen = WLAN_RATES_MAXLEN;
214 } else {
215 if (uRateLen > WLAN_RATES_MAXLEN_11B)
216 uRateLen = WLAN_RATES_MAXLEN_11B;
217 }
218
219 for (ii = 0; ii < uRateLen; ii++) {
220 byRate = (unsigned char)(pItemRates->abyRates[ii]);
221 if (WLAN_MGMT_IS_BASICRATE(byRate) && bUpdateBasicRate) {
222 /* Add to basic rate set, update pDevice->byTopCCKBasicRate and pDevice->byTopOFDMBasicRate */
223 CARDbAddBasicRate((void *)pDevice, wGetRateIdx(byRate));
224 pr_debug("ParseMaxRate AddBasicRate: %d\n",
225 wGetRateIdx(byRate));
226 }
227 byRate = (unsigned char)(pItemRates->abyRates[ii]&0x7F);
228 if (byHighSuppRate == 0)
229 byHighSuppRate = byRate;
230 if (byRate > byHighSuppRate)
231 byHighSuppRate = byRate;
232 *pwSuppRate |= (1<<wGetRateIdx(byRate));
233 }
234 if ((pItemExtRates != NULL) && (pItemExtRates->byElementID == WLAN_EID_EXTSUPP_RATES) &&
235 (pDevice->eCurrentPHYType != PHY_TYPE_11B)) {
236 unsigned int uExtRateLen = pItemExtRates->len;
237
238 if (uExtRateLen > WLAN_RATES_MAXLEN)
239 uExtRateLen = WLAN_RATES_MAXLEN;
240
241 for (ii = 0; ii < uExtRateLen; ii++) {
242 byRate = (unsigned char)(pItemExtRates->abyRates[ii]);
243 /* select highest basic rate */
244 if (WLAN_MGMT_IS_BASICRATE(pItemExtRates->abyRates[ii])) {
245 /* Add to basic rate set, update pDevice->byTopCCKBasicRate and pDevice->byTopOFDMBasicRate */
246 CARDbAddBasicRate((void *)pDevice, wGetRateIdx(byRate));
247 pr_debug("ParseMaxRate AddBasicRate: %d\n",
248 wGetRateIdx(byRate));
249 }
250 byRate = (unsigned char)(pItemExtRates->abyRates[ii]&0x7F);
251 if (byHighSuppRate == 0)
252 byHighSuppRate = byRate;
253 if (byRate > byHighSuppRate)
254 byHighSuppRate = byRate;
255 *pwSuppRate |= (1<<wGetRateIdx(byRate));
256 }
257 }
258
259 if ((pDevice->byPacketType == PK_TYPE_11GB) && CARDbIsOFDMinBasicRate((void *)pDevice))
260 pDevice->byPacketType = PK_TYPE_11GA;
261
262 *pbyTopCCKRate = pDevice->byTopCCKBasicRate;
263 *pbyTopOFDMRate = pDevice->byTopOFDMBasicRate;
264 *pwMaxSuppRate = wGetRateIdx(byHighSuppRate);
265 if ((pDevice->byPacketType == PK_TYPE_11B) || (pDevice->byPacketType == PK_TYPE_11GB))
266 *pwMaxBasicRate = pDevice->byTopCCKBasicRate;
267 else
268 *pwMaxBasicRate = pDevice->byTopOFDMBasicRate;
269 if (wOldBasicRate != pDevice->wBasicRate)
270 CARDvSetRSPINF((void *)pDevice, pDevice->eCurrentPHYType);
271
272 pr_debug("Exit ParseMaxRate\n");
273}
274
275/*+
276 *
277 * Routine Description:
278 * Rate fallback Algorithm Implementaion
279 *
280 * Parameters:
281 * In:
282 * pDevice - Pointer to the adapter
283 * psNodeDBTable - Pointer to Node Data Base
284 * Out:
285 * none
286 *
287 * Return Value: none
288 *
289 -*/
290#define AUTORATE_TXCNT_THRESHOLD 20
291#define AUTORATE_INC_THRESHOLD 30
292
293void
294RATEvTxRateFallBack(
295 void *pDeviceHandler,
296 PKnownNodeDB psNodeDBTable
297)
298{
299 struct vnt_private *pDevice = pDeviceHandler;
300 unsigned short wIdxDownRate = 0;
301 unsigned int ii;
302 bool bAutoRate[MAX_RATE] = {true, true, true, true, false, false, true, true, true, true, true, true};
303 unsigned long dwThroughputTbl[MAX_RATE] = {10, 20, 55, 110, 60, 90, 120, 180, 240, 360, 480, 540};
304 unsigned long dwThroughput = 0;
305 unsigned short wIdxUpRate = 0;
306 unsigned long dwTxDiff = 0;
307
308 if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING)
309 /* Don't do Fallback when scanning Channel */
310 return;
311
312 psNodeDBTable->uTimeCount++;
313
314 if (psNodeDBTable->uTxFail[MAX_RATE] > psNodeDBTable->uTxOk[MAX_RATE])
315 dwTxDiff = psNodeDBTable->uTxFail[MAX_RATE] - psNodeDBTable->uTxOk[MAX_RATE];
316
317 if ((psNodeDBTable->uTxOk[MAX_RATE] < AUTORATE_TXOK_CNT) &&
318 (dwTxDiff < AUTORATE_TXFAIL_CNT) &&
319 (psNodeDBTable->uTimeCount < AUTORATE_TIMEOUT)) {
320 return;
321 }
322
323 if (psNodeDBTable->uTimeCount >= AUTORATE_TIMEOUT)
324 psNodeDBTable->uTimeCount = 0;
325
326 for (ii = 0; ii < MAX_RATE; ii++) {
327 if (psNodeDBTable->wSuppRate & (0x0001<<ii)) {
328 if (bAutoRate[ii])
329 wIdxUpRate = (unsigned short) ii;
330
331 } else {
332 bAutoRate[ii] = false;
333 }
334 }
335
336 for (ii = 0; ii <= psNodeDBTable->wTxDataRate; ii++) {
337 if ((psNodeDBTable->uTxOk[ii] != 0) ||
338 (psNodeDBTable->uTxFail[ii] != 0)) {
339 dwThroughputTbl[ii] *= psNodeDBTable->uTxOk[ii];
340 if (ii < RATE_11M)
341 psNodeDBTable->uTxFail[ii] *= 4;
342
343 dwThroughputTbl[ii] /= (psNodeDBTable->uTxOk[ii] + psNodeDBTable->uTxFail[ii]);
344 }
345 }
346 dwThroughput = dwThroughputTbl[psNodeDBTable->wTxDataRate];
347
348 wIdxDownRate = psNodeDBTable->wTxDataRate;
349 for (ii = psNodeDBTable->wTxDataRate; ii > 0;) {
350 ii--;
351 if ((dwThroughputTbl[ii] > dwThroughput) && bAutoRate[ii]) {
352 dwThroughput = dwThroughputTbl[ii];
353 wIdxDownRate = (unsigned short) ii;
354 }
355 }
356 psNodeDBTable->wTxDataRate = wIdxDownRate;
357 if (psNodeDBTable->uTxOk[MAX_RATE]) {
358 if (psNodeDBTable->uTxOk[MAX_RATE] >
359 (psNodeDBTable->uTxFail[MAX_RATE] * 4)) {
360 psNodeDBTable->wTxDataRate = wIdxUpRate;
361 }
362 } else {
363 /* adhoc, if uTxOk =0 & uTxFail = 0 */
364 if (psNodeDBTable->uTxFail[MAX_RATE] == 0)
365 psNodeDBTable->wTxDataRate = wIdxUpRate;
366 }
367
368 /* 2008-5-8 <add> by chester */
369 TxRate_iwconfig = psNodeDBTable->wTxDataRate;
370 s_vResetCounter(psNodeDBTable);
371}
372
373/*+
374 *
375 * Description:
376 * This routine is used to assemble available Rate IE.
377 *
378 * Parameters:
379 * In:
380 * pDevice
381 * Out:
382 *
383 * Return Value: None
384 *
385 -*/
386unsigned char
387RATEuSetIE(
388 PWLAN_IE_SUPP_RATES pSrcRates,
389 PWLAN_IE_SUPP_RATES pDstRates,
390 unsigned int uRateLen
391)
392{
393 unsigned int ii, uu, uRateCnt = 0;
394
395 if ((pSrcRates == NULL) || (pDstRates == NULL))
396 return 0;
397
398 if (pSrcRates->len == 0)
399 return 0;
400
401 for (ii = 0; ii < uRateLen; ii++) {
402 for (uu = 0; uu < pSrcRates->len; uu++) {
403 if ((pSrcRates->abyRates[uu] & 0x7F) == acbyIERate[ii]) {
404 pDstRates->abyRates[uRateCnt++] = pSrcRates->abyRates[uu];
405 break;
406 }
407 }
408 }
409 return (unsigned char)uRateCnt;
410}
diff --git a/drivers/staging/vt6655/datarate.h b/drivers/staging/vt6655/datarate.h
deleted file mode 100644
index 0509c4fd2a42..000000000000
--- a/drivers/staging/vt6655/datarate.h
+++ /dev/null
@@ -1,78 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: datarate.h
21 *
22 * Purpose: Handles the auto fallback & data rates functions
23 *
24 * Author: Lyndon Chen
25 *
26 * Date: July 16, 2002
27 *
28 */
29#ifndef __DATARATE_H__
30#define __DATARATE_H__
31
32#define FALLBACK_PKT_COLLECT_TR_H 50
33#define FALLBACK_PKT_COLLECT_TR_L 10
34#define FALLBACK_POLL_SECOND 5
35#define FALLBACK_RECOVER_SECOND 30
36#define FALLBACK_THRESHOLD 15
37#define UPGRADE_THRESHOLD 5
38#define UPGRADE_CNT_THRD 3
39#define RETRY_TIMES_THRD_H 2
40#define RETRY_TIMES_THRD_L 1
41
42void
43RATEvParseMaxRate(
44 void *pDeviceHandler,
45 PWLAN_IE_SUPP_RATES pItemRates,
46 PWLAN_IE_SUPP_RATES pItemExtRates,
47 bool bUpdateBasicRate,
48 unsigned short *pwMaxBasicRate,
49 unsigned short *pwMaxSuppRate,
50 unsigned short *pwSuppRate,
51 unsigned char *pbyTopCCKRate,
52 unsigned char *pbyTopOFDMRate
53);
54
55void
56RATEvTxRateFallBack(
57 void *pDeviceHandler,
58 PKnownNodeDB psNodeDBTable
59);
60
61unsigned char
62RATEuSetIE(
63 PWLAN_IE_SUPP_RATES pSrcRates,
64 PWLAN_IE_SUPP_RATES pDstRates,
65 unsigned int uRateLen
66);
67
68unsigned short
69wGetRateIdx(
70 unsigned char byRate
71);
72
73unsigned char
74DATARATEbyGetRateIdx(
75 unsigned char byRate
76);
77
78#endif //__DATARATE_H__
diff --git a/drivers/staging/vt6655/desc.h b/drivers/staging/vt6655/desc.h
index 5a2bbd2047d8..758eeb2afd51 100644
--- a/drivers/staging/vt6655/desc.h
+++ b/drivers/staging/vt6655/desc.h
@@ -34,44 +34,34 @@
34#include <linux/types.h> 34#include <linux/types.h>
35#include <linux/mm.h> 35#include <linux/mm.h>
36#include "linux/ieee80211.h" 36#include "linux/ieee80211.h"
37#include "ttype.h"
38#include "tether.h"
39 37
40#define B_OWNED_BY_CHIP 1 38#define B_OWNED_BY_CHIP 1
41#define B_OWNED_BY_HOST 0 39#define B_OWNED_BY_HOST 0
42 40
43// 41/* Bits in the RSR register */
44// Bits in the RSR register
45//
46#define RSR_ADDRBROAD 0x80 42#define RSR_ADDRBROAD 0x80
47#define RSR_ADDRMULTI 0x40 43#define RSR_ADDRMULTI 0x40
48#define RSR_ADDRUNI 0x00 44#define RSR_ADDRUNI 0x00
49#define RSR_IVLDTYP 0x20 45#define RSR_IVLDTYP 0x20
50#define RSR_IVLDLEN 0x10 // invalid len (> 2312 byte) 46#define RSR_IVLDLEN 0x10 /* invalid len (> 2312 byte) */
51#define RSR_BSSIDOK 0x08 47#define RSR_BSSIDOK 0x08
52#define RSR_CRCOK 0x04 48#define RSR_CRCOK 0x04
53#define RSR_BCNSSIDOK 0x02 49#define RSR_BCNSSIDOK 0x02
54#define RSR_ADDROK 0x01 50#define RSR_ADDROK 0x01
55 51
56// 52/* Bits in the new RSR register */
57// Bits in the new RSR register
58//
59#define NEWRSR_DECRYPTOK 0x10 53#define NEWRSR_DECRYPTOK 0x10
60#define NEWRSR_CFPIND 0x08 54#define NEWRSR_CFPIND 0x08
61#define NEWRSR_HWUTSF 0x04 55#define NEWRSR_HWUTSF 0x04
62#define NEWRSR_BCNHITAID 0x02 56#define NEWRSR_BCNHITAID 0x02
63#define NEWRSR_BCNHITAID0 0x01 57#define NEWRSR_BCNHITAID0 0x01
64 58
65// 59/* Bits in the TSR0 register */
66// Bits in the TSR0 register
67//
68#define TSR0_PWRSTS1_2 0xC0 60#define TSR0_PWRSTS1_2 0xC0
69#define TSR0_PWRSTS7 0x20 61#define TSR0_PWRSTS7 0x20
70#define TSR0_NCR 0x1F 62#define TSR0_NCR 0x1F
71 63
72// 64/* Bits in the TSR1 register */
73// Bits in the TSR1 register
74//
75#define TSR1_TERR 0x80 65#define TSR1_TERR 0x80
76#define TSR1_PWRSTS4_6 0x70 66#define TSR1_PWRSTS4_6 0x70
77#define TSR1_RETRYTMO 0x08 67#define TSR1_RETRYTMO 0x08
@@ -79,16 +69,14 @@
79#define TSR1_PWRSTS3 0x02 69#define TSR1_PWRSTS3 0x02
80#define ACK_DATA 0x01 70#define ACK_DATA 0x01
81 71
82// 72/* Bits in the TCR register */
83// Bits in the TCR register 73#define EDMSDU 0x04 /* end of sdu */
84// 74#define TCR_EDP 0x02 /* end of packet */
85#define EDMSDU 0x04 // end of sdu 75#define TCR_STP 0x01 /* start of packet */
86#define TCR_EDP 0x02 // end of packet
87#define TCR_STP 0x01 // start of packet
88 76
89// max transmit or receive buffer size 77/* max transmit or receive buffer size */
90#define CB_MAX_BUF_SIZE 2900U 78#define CB_MAX_BUF_SIZE 2900U
91 // NOTE: must be multiple of 4 79 /* NOTE: must be multiple of 4 */
92#define CB_MAX_TX_BUF_SIZE CB_MAX_BUF_SIZE 80#define CB_MAX_TX_BUF_SIZE CB_MAX_BUF_SIZE
93#define CB_MAX_RX_BUF_SIZE_NORMAL CB_MAX_BUF_SIZE 81#define CB_MAX_RX_BUF_SIZE_NORMAL CB_MAX_BUF_SIZE
94 82
@@ -100,18 +88,21 @@
100#define CB_MIN_TX_DESC 16 88#define CB_MIN_TX_DESC 16
101 89
102#define CB_MAX_RECEIVED_PACKETS 16 90#define CB_MAX_RECEIVED_PACKETS 16
103 // limit our receive routine to indicating 91 /*
104 // this many at a time for 2 reasons: 92 * limit our receive routine to indicating
105 // 1. driver flow control to protocol layer 93 * this many at a time for 2 reasons:
106 // 2. limit the time used in ISR routine 94 * 1. driver flow control to protocol layer
95 * 2. limit the time used in ISR routine
96 */
107 97
108#define CB_EXTRA_RD_NUM 32 98#define CB_EXTRA_RD_NUM 32
109#define CB_RD_NUM 32 99#define CB_RD_NUM 32
110#define CB_TD_NUM 32 100#define CB_TD_NUM 32
111 101
112// max number of physical segments 102/*
113// in a single NDIS packet. Above this threshold, the packet 103 * max number of physical segments in a single NDIS packet. Above this
114// is copied into a single physically contiguous buffer 104 * threshold, the packet is copied into a single physically contiguous buffer
105 */
115#define CB_MAX_SEGMENT 4 106#define CB_MAX_SEGMENT 4
116 107
117#define CB_MIN_MAP_REG_NUM 4 108#define CB_MIN_MAP_REG_NUM 4
@@ -119,42 +110,13 @@
119 110
120#define CB_PROTOCOL_RESERVED_SECTION 16 111#define CB_PROTOCOL_RESERVED_SECTION 16
121 112
122// if retrys excess 15 times , tx will abort, and 113/*
123// if tx fifo underflow, tx will fail 114 * if retrys excess 15 times , tx will abort, and if tx fifo underflow,
124// we should try to resend it 115 * tx will fail, we should try to resend it
116 */
125#define CB_MAX_TX_ABORT_RETRY 3 117#define CB_MAX_TX_ABORT_RETRY 3
126 118
127#ifdef __BIG_ENDIAN 119/* WMAC definition FIFO Control */
128
129// WMAC definition FIFO Control
130#define FIFOCTL_AUTO_FB_1 0x0010
131#define FIFOCTL_AUTO_FB_0 0x0008
132#define FIFOCTL_GRPACK 0x0004
133#define FIFOCTL_11GA 0x0003
134#define FIFOCTL_11GB 0x0002
135#define FIFOCTL_11B 0x0001
136#define FIFOCTL_11A 0x0000
137#define FIFOCTL_RTS 0x8000
138#define FIFOCTL_ISDMA0 0x4000
139#define FIFOCTL_GENINT 0x2000
140#define FIFOCTL_TMOEN 0x1000
141#define FIFOCTL_LRETRY 0x0800
142#define FIFOCTL_CRCDIS 0x0400
143#define FIFOCTL_NEEDACK 0x0200
144#define FIFOCTL_LHEAD 0x0100
145
146//WMAC definition Frag Control
147#define FRAGCTL_AES 0x0003
148#define FRAGCTL_TKIP 0x0002
149#define FRAGCTL_LEGACY 0x0001
150#define FRAGCTL_NONENCRYPT 0x0000
151#define FRAGCTL_ENDFRAG 0x0300
152#define FRAGCTL_MIDFRAG 0x0200
153#define FRAGCTL_STAFRAG 0x0100
154#define FRAGCTL_NONFRAG 0x0000
155
156#else
157
158#define FIFOCTL_AUTO_FB_1 0x1000 120#define FIFOCTL_AUTO_FB_1 0x1000
159#define FIFOCTL_AUTO_FB_0 0x0800 121#define FIFOCTL_AUTO_FB_0 0x0800
160#define FIFOCTL_GRPACK 0x0400 122#define FIFOCTL_GRPACK 0x0400
@@ -171,7 +133,7 @@
171#define FIFOCTL_NEEDACK 0x0002 133#define FIFOCTL_NEEDACK 0x0002
172#define FIFOCTL_LHEAD 0x0001 134#define FIFOCTL_LHEAD 0x0001
173 135
174//WMAC definition Frag Control 136/* WMAC definition Frag Control */
175#define FRAGCTL_AES 0x0300 137#define FRAGCTL_AES 0x0300
176#define FRAGCTL_TKIP 0x0200 138#define FRAGCTL_TKIP 0x0200
177#define FRAGCTL_LEGACY 0x0100 139#define FRAGCTL_LEGACY 0x0100
@@ -181,8 +143,6 @@
181#define FRAGCTL_STAFRAG 0x0001 143#define FRAGCTL_STAFRAG 0x0001
182#define FRAGCTL_NONFRAG 0x0000 144#define FRAGCTL_NONFRAG 0x0000
183 145
184#endif
185
186#define TYPE_TXDMA0 0 146#define TYPE_TXDMA0 0
187#define TYPE_AC0DMA 1 147#define TYPE_AC0DMA 1
188#define TYPE_ATIMDMA 2 148#define TYPE_ATIMDMA 2
@@ -195,14 +155,17 @@
195#define TYPE_RXDMA1 1 155#define TYPE_RXDMA1 1
196#define TYPE_MAXRD 2 156#define TYPE_MAXRD 2
197 157
198// TD_INFO flags control bit 158/* TD_INFO flags control bit */
199#define TD_FLAGS_NETIF_SKB 0x01 // check if need release skb 159#define TD_FLAGS_NETIF_SKB 0x01 /* check if need release skb */
200#define TD_FLAGS_PRIV_SKB 0x02 // check if called from private skb(hostap) 160#define TD_FLAGS_PRIV_SKB 0x02 /* check if called from private skb (hostap) */
201#define TD_FLAGS_PS_RETRY 0x04 // check if PS STA frame re-transmit 161#define TD_FLAGS_PS_RETRY 0x04 /* check if PS STA frame re-transmit */
202 162
203// ref_sk_buff is used for mapping the skb structure between pre-built driver-obj & running kernel. 163/*
204// Since different kernel version (2.4x) may change skb structure, i.e. pre-built driver-obj 164 * ref_sk_buff is used for mapping the skb structure between pre-built
205// may link to older skb that leads error. 165 * driver-obj & running kernel. Since different kernel version (2.4x) may
166 * change skb structure, i.e. pre-built driver-obj may link to older skb that
167 * leads error.
168 */
206 169
207typedef struct tagDEVICE_RD_INFO { 170typedef struct tagDEVICE_RD_INFO {
208 struct sk_buff *skb; 171 struct sk_buff *skb;
@@ -242,9 +205,7 @@ typedef struct tagRDES1 {
242} __attribute__ ((__packed__)) 205} __attribute__ ((__packed__))
243SRDES1; 206SRDES1;
244 207
245// 208/* Rx descriptor*/
246// Rx descriptor
247//
248typedef struct tagSRxDesc { 209typedef struct tagSRxDesc {
249 volatile SRDES0 m_rd0RD0; 210 volatile SRDES0 m_rd0RD0;
250 volatile SRDES1 m_rd1RD1; 211 volatile SRDES1 m_rd1RD1;
@@ -292,6 +253,7 @@ typedef struct tagTDES1 {
292STDES1; 253STDES1;
293 254
294typedef struct tagDEVICE_TD_INFO { 255typedef struct tagDEVICE_TD_INFO {
256 void *mic_hdr;
295 struct sk_buff *skb; 257 struct sk_buff *skb;
296 unsigned char *buf; 258 unsigned char *buf;
297 dma_addr_t skb_dma; 259 dma_addr_t skb_dma;
@@ -302,9 +264,7 @@ typedef struct tagDEVICE_TD_INFO {
302 unsigned char byFlags; 264 unsigned char byFlags;
303} DEVICE_TD_INFO, *PDEVICE_TD_INFO; 265} DEVICE_TD_INFO, *PDEVICE_TD_INFO;
304 266
305// 267/* transmit descriptor */
306// transmit descriptor
307//
308typedef struct tagSTxDesc { 268typedef struct tagSTxDesc {
309 volatile STDES0 m_td0TD0; 269 volatile STDES0 m_td0TD0;
310 volatile STDES1 m_td1TD1; 270 volatile STDES1 m_td1TD1;
@@ -319,8 +279,8 @@ typedef const STxDesc *PCSTxDesc;
319typedef struct tagSTxSyncDesc { 279typedef struct tagSTxSyncDesc {
320 volatile STDES0 m_td0TD0; 280 volatile STDES0 m_td0TD0;
321 volatile STDES1 m_td1TD1; 281 volatile STDES1 m_td1TD1;
322 volatile u32 buff_addr; // pointer to logical buffer 282 volatile u32 buff_addr; /* pointer to logical buffer */
323 volatile u32 next_desc; // pointer to next logical descriptor 283 volatile u32 next_desc; /* pointer to next logical descriptor */
324 volatile unsigned short m_wFIFOCtl; 284 volatile unsigned short m_wFIFOCtl;
325 volatile unsigned short m_wTimeStamp; 285 volatile unsigned short m_wTimeStamp;
326 struct tagSTxSyncDesc *next __aligned(8); 286 struct tagSTxSyncDesc *next __aligned(8);
@@ -329,9 +289,7 @@ typedef struct tagSTxSyncDesc {
329STxSyncDesc, *PSTxSyncDesc; 289STxSyncDesc, *PSTxSyncDesc;
330typedef const STxSyncDesc *PCSTxSyncDesc; 290typedef const STxSyncDesc *PCSTxSyncDesc;
331 291
332// 292/* RsvTime buffer header */
333// RsvTime buffer header
334//
335typedef struct tagSRrvTime_atim { 293typedef struct tagSRrvTime_atim {
336 unsigned short wCTSTxRrvTime_ba; 294 unsigned short wCTSTxRrvTime_ba;
337 unsigned short wTxRrvTime_a; 295 unsigned short wTxRrvTime_a;
@@ -352,9 +310,7 @@ union vnt_phy_field_swap {
352 u32 field_write; 310 u32 field_write;
353}; 311};
354 312
355// 313/* Tx FIFO header */
356// Tx FIFO header
357//
358typedef struct tagSTxBufHead { 314typedef struct tagSTxBufHead {
359 u32 adwTxKey[4]; 315 u32 adwTxKey[4];
360 unsigned short wFIFOCtl; 316 unsigned short wFIFOCtl;
@@ -392,4 +348,4 @@ typedef struct tagSKeyEntry {
392} __attribute__ ((__packed__)) 348} __attribute__ ((__packed__))
393SKeyEntry; 349SKeyEntry;
394 350
395#endif // __DESC_H__ 351#endif /* __DESC_H__ */
diff --git a/drivers/staging/vt6655/device.h b/drivers/staging/vt6655/device.h
index ddd356aa7eaf..83efbfb57c79 100644
--- a/drivers/staging/vt6655/device.h
+++ b/drivers/staging/vt6655/device.h
@@ -50,40 +50,47 @@
50#include <linux/io.h> 50#include <linux/io.h>
51#include <linux/if.h> 51#include <linux/if.h>
52#include <linux/crc32.h> 52#include <linux/crc32.h>
53//#include <linux/config.h>
54#include <linux/uaccess.h> 53#include <linux/uaccess.h>
55#include <linux/proc_fs.h> 54#include <linux/proc_fs.h>
56#include <linux/inetdevice.h> 55#include <linux/inetdevice.h>
57#include <linux/reboot.h> 56#include <linux/reboot.h>
58#include <linux/ethtool.h> 57#include <linux/ethtool.h>
59/* Include Wireless Extension definition and check version - Jean II */ 58/* Include Wireless Extension definition and check version - Jean II */
59#include <net/mac80211.h>
60#include <linux/wireless.h> 60#include <linux/wireless.h>
61#include <net/iw_handler.h> // New driver API 61#include <net/iw_handler.h> /* New driver API */
62 62
63//2008-0409-07, <Add> by Einsn Liu
64#ifndef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT 63#ifndef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
65#define WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT 64#define WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
66#endif 65#endif
67 66
68// 67/* device specific */
69// device specific
70//
71 68
72#include "device_cfg.h" 69#include "device_cfg.h"
73#include "ttype.h" 70#include "card.h"
74#include "80211hdr.h"
75#include "tether.h"
76#include "wmgr.h"
77#include "wcmd.h"
78#include "mib.h" 71#include "mib.h"
79#include "srom.h" 72#include "srom.h"
80#include "rc4.h"
81#include "desc.h" 73#include "desc.h"
82#include "key.h" 74#include "key.h"
83#include "mac.h" 75#include "mac.h"
84 76
85/*--------------------- Export Definitions -------------------------*/ 77/*--------------------- Export Definitions -------------------------*/
86 78
79#define RATE_1M 0
80#define RATE_2M 1
81#define RATE_5M 2
82#define RATE_11M 3
83#define RATE_6M 4
84#define RATE_9M 5
85#define RATE_12M 6
86#define RATE_18M 7
87#define RATE_24M 8
88#define RATE_36M 9
89#define RATE_48M 10
90#define RATE_54M 11
91#define RATE_AUTO 12
92#define MAX_RATE 12
93
87#define MAC_MAX_CONTEXT_REG (256+128) 94#define MAC_MAX_CONTEXT_REG (256+128)
88 95
89#define MAX_MULTICAST_ADDRESS_NUM 32 96#define MAX_MULTICAST_ADDRESS_NUM 32
@@ -112,7 +119,7 @@
112#define FB_RATE0 0 119#define FB_RATE0 0
113#define FB_RATE1 1 120#define FB_RATE1 1
114 121
115// Antenna Mode 122/* Antenna Mode */
116#define ANT_A 0 123#define ANT_A 0
117#define ANT_B 1 124#define ANT_B 1
118#define ANT_DIVERSITY 2 125#define ANT_DIVERSITY 2
@@ -129,120 +136,28 @@
129#define RUN_AT(x) (jiffies+(x)) 136#define RUN_AT(x) (jiffies+(x))
130#endif 137#endif
131 138
132// DMA related 139#define MAKE_BEACON_RESERVED 10 /* (us) */
140
141/* DMA related */
133#define RESERV_AC0DMA 4 142#define RESERV_AC0DMA 4
134 143
135// BUILD OBJ mode 144/* BUILD OBJ mode */
136 145
137#define AVAIL_TD(p, q) ((p)->sOpts.nTxDescs[(q)] - ((p)->iTDUsed[(q)])) 146#define AVAIL_TD(p, q) ((p)->sOpts.nTxDescs[(q)] - ((p)->iTDUsed[(q)]))
138 147
139#define NUM 64 148#define NUM 64
140 149
141#define PRIVATE_Message 0 150/* 0:11A 1:11B 2:11G */
142 151#define BB_TYPE_11A 0
143/*--------------------- Export Types ------------------------------*/ 152#define BB_TYPE_11B 1
144 153#define BB_TYPE_11G 2
145#define PRINT_K(p, args...) \
146do { \
147 if (PRIVATE_Message) \
148 printk(p, ##args); \
149} while (0)
150 154
151//0:11A 1:11B 2:11G 155/* 0:11a, 1:11b, 2:11gb (only CCK in BasicRate), 3:11ga (OFDM in BasicRate) */
152typedef enum _VIA_BB_TYPE 156#define PK_TYPE_11A 0
153{ 157#define PK_TYPE_11B 1
154 BB_TYPE_11A = 0, 158#define PK_TYPE_11GB 2
155 BB_TYPE_11B, 159#define PK_TYPE_11GA 3
156 BB_TYPE_11G
157} VIA_BB_TYPE, *PVIA_BB_TYPE;
158
159//0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate)
160typedef enum _VIA_PKT_TYPE
161{
162 PK_TYPE_11A = 0,
163 PK_TYPE_11B,
164 PK_TYPE_11GB,
165 PK_TYPE_11GA
166} VIA_PKT_TYPE, *PVIA_PKT_TYPE;
167
168typedef enum __device_msg_level {
169 MSG_LEVEL_ERR = 0, //Errors that will cause abnormal operation.
170 MSG_LEVEL_NOTICE = 1, //Some errors need users to be notified.
171 MSG_LEVEL_INFO = 2, //Normal message.
172 MSG_LEVEL_VERBOSE = 3, //Will report all trival errors.
173 MSG_LEVEL_DEBUG = 4 //Only for debug purpose.
174} DEVICE_MSG_LEVEL, *PDEVICE_MSG_LEVEL;
175
176//++ NDIS related
177
178#define MAX_BSSIDINFO_4_PMKID 16
179#define MAX_PMKIDLIST 5
180//Flags for PMKID Candidate list structure
181#define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
182
183// PMKID Structures
184typedef unsigned char NDIS_802_11_PMKID_VALUE[16];
185
186typedef enum _NDIS_802_11_WEP_STATUS {
187 Ndis802_11WEPEnabled,
188 Ndis802_11Encryption1Enabled = Ndis802_11WEPEnabled,
189 Ndis802_11WEPDisabled,
190 Ndis802_11EncryptionDisabled = Ndis802_11WEPDisabled,
191 Ndis802_11WEPKeyAbsent,
192 Ndis802_11Encryption1KeyAbsent = Ndis802_11WEPKeyAbsent,
193 Ndis802_11WEPNotSupported,
194 Ndis802_11EncryptionNotSupported = Ndis802_11WEPNotSupported,
195 Ndis802_11Encryption2Enabled,
196 Ndis802_11Encryption2KeyAbsent,
197 Ndis802_11Encryption3Enabled,
198 Ndis802_11Encryption3KeyAbsent
199} NDIS_802_11_WEP_STATUS, *PNDIS_802_11_WEP_STATUS,
200 NDIS_802_11_ENCRYPTION_STATUS, *PNDIS_802_11_ENCRYPTION_STATUS;
201
202typedef enum _NDIS_802_11_STATUS_TYPE {
203 Ndis802_11StatusType_Authentication,
204 Ndis802_11StatusType_MediaStreamMode,
205 Ndis802_11StatusType_PMKID_CandidateList,
206 Ndis802_11StatusTypeMax // not a real type, defined as an upper bound
207} NDIS_802_11_STATUS_TYPE, *PNDIS_802_11_STATUS_TYPE;
208
209//Added new types for PMKID Candidate lists.
210struct pmkid_candidate {
211 NDIS_802_11_MAC_ADDRESS BSSID;
212 unsigned long Flags;
213};
214 160
215typedef struct _BSSID_INFO {
216 NDIS_802_11_MAC_ADDRESS BSSID;
217 NDIS_802_11_PMKID_VALUE PMKID;
218} BSSID_INFO, *PBSSID_INFO;
219
220typedef struct tagSPMKID {
221 unsigned long Length;
222 unsigned long BSSIDInfoCount;
223 BSSID_INFO BSSIDInfo[MAX_BSSIDINFO_4_PMKID];
224} SPMKID, *PSPMKID;
225
226typedef struct tagSPMKIDCandidateEvent {
227 NDIS_802_11_STATUS_TYPE StatusType;
228 unsigned long Version; // Version of the structure
229 unsigned long NumCandidates; // No. of pmkid candidates
230 struct pmkid_candidate CandidateList[MAX_PMKIDLIST];
231} SPMKIDCandidateEvent, *PSPMKIDCandidateEvent;
232
233//--
234
235//++ 802.11h related
236#define MAX_QUIET_COUNT 8
237
238typedef struct tagSQuietControl {
239 bool bEnable;
240 unsigned long dwStartTime;
241 unsigned char byPeriod;
242 unsigned short wDuration;
243} SQuietControl, *PSQuietControl;
244
245//--
246typedef struct __chip_info_tbl { 161typedef struct __chip_info_tbl {
247 CHIP_TYPE chip_id; 162 CHIP_TYPE chip_id;
248 char *name; 163 char *name;
@@ -256,34 +171,7 @@ typedef enum {
256 OWNED_BY_NIC = 1 171 OWNED_BY_NIC = 1
257} DEVICE_OWNER_TYPE, *PDEVICE_OWNER_TYPE; 172} DEVICE_OWNER_TYPE, *PDEVICE_OWNER_TYPE;
258 173
259// The receive duplicate detection cache entry 174/* flags for options */
260typedef struct tagSCacheEntry {
261 unsigned short wFmSequence;
262 unsigned char abyAddr2[ETH_ALEN];
263} SCacheEntry, *PSCacheEntry;
264
265typedef struct tagSCache {
266/* The receive cache is updated circularly. The next entry to be written is
267 * indexed by the "InPtr".
268 */
269 unsigned int uInPtr; // Place to use next
270 SCacheEntry asCacheEntry[DUPLICATE_RX_CACHE_LENGTH];
271} SCache, *PSCache;
272
273#define CB_MAX_RX_FRAG 64
274// DeFragment Control Block, used for collecting fragments prior to reassembly
275typedef struct tagSDeFragControlBlock {
276 unsigned short wSequence;
277 unsigned short wFragNum;
278 unsigned char abyAddr2[ETH_ALEN];
279 unsigned int uLifetime;
280 struct sk_buff *skb;
281 unsigned char *pbyRxBuffer;
282 unsigned int cbFrameLength;
283 bool bInUse;
284} SDeFragControlBlock, *PSDeFragControlBlock;
285
286//flags for options
287#define DEVICE_FLAGS_IP_ALIGN 0x00000001UL 175#define DEVICE_FLAGS_IP_ALIGN 0x00000001UL
288#define DEVICE_FLAGS_PREAMBLE_TYPE 0x00000002UL 176#define DEVICE_FLAGS_PREAMBLE_TYPE 0x00000002UL
289#define DEVICE_FLAGS_OP_MODE 0x00000004UL 177#define DEVICE_FLAGS_OP_MODE 0x00000004UL
@@ -291,15 +179,15 @@ typedef struct tagSDeFragControlBlock {
291#define DEVICE_FLAGS_80211h_MODE 0x00000010UL 179#define DEVICE_FLAGS_80211h_MODE 0x00000010UL
292#define DEVICE_FLAGS_DiversityANT 0x00000020UL 180#define DEVICE_FLAGS_DiversityANT 0x00000020UL
293 181
294//flags for driver status 182/* flags for driver status */
295#define DEVICE_FLAGS_OPENED 0x00010000UL 183#define DEVICE_FLAGS_OPENED 0x00010000UL
296#define DEVICE_FLAGS_WOL_ENABLED 0x00080000UL 184#define DEVICE_FLAGS_WOL_ENABLED 0x00080000UL
297//flags for capabilities 185/* flags for capabilities */
298#define DEVICE_FLAGS_TX_ALIGN 0x01000000UL 186#define DEVICE_FLAGS_TX_ALIGN 0x01000000UL
299#define DEVICE_FLAGS_HAVE_CAM 0x02000000UL 187#define DEVICE_FLAGS_HAVE_CAM 0x02000000UL
300#define DEVICE_FLAGS_FLOW_CTRL 0x04000000UL 188#define DEVICE_FLAGS_FLOW_CTRL 0x04000000UL
301 189
302//flags for MII status 190/* flags for MII status */
303#define DEVICE_LINK_FAIL 0x00000001UL 191#define DEVICE_LINK_FAIL 0x00000001UL
304#define DEVICE_SPEED_10 0x00000002UL 192#define DEVICE_SPEED_10 0x00000002UL
305#define DEVICE_SPEED_100 0x00000004UL 193#define DEVICE_SPEED_100 0x00000004UL
@@ -307,18 +195,14 @@ typedef struct tagSDeFragControlBlock {
307#define DEVICE_DUPLEX_FULL 0x00000010UL 195#define DEVICE_DUPLEX_FULL 0x00000010UL
308#define DEVICE_AUTONEG_ENABLE 0x00000020UL 196#define DEVICE_AUTONEG_ENABLE 0x00000020UL
309#define DEVICE_FORCED_BY_EEPROM 0x00000040UL 197#define DEVICE_FORCED_BY_EEPROM 0x00000040UL
310//for device_set_media_duplex 198/* for device_set_media_duplex */
311#define DEVICE_LINK_CHANGE 0x00000001UL 199#define DEVICE_LINK_CHANGE 0x00000001UL
312 200
313typedef struct __device_opt { 201typedef struct __device_opt {
314 int nRxDescs0; //Number of RX descriptors0 202 int nRxDescs0; /* Number of RX descriptors0 */
315 int nRxDescs1; //Number of RX descriptors1 203 int nRxDescs1; /* Number of RX descriptors1 */
316 int nTxDescs[2]; //Number of TX descriptors 0, 1 204 int nTxDescs[2]; /* Number of TX descriptors 0, 1 */
317 int int_works; //interrupt limits 205 int int_works; /* interrupt limits */
318 int rts_thresh; //rts threshold
319 int frag_thresh;
320 int data_rate;
321 int channel_num;
322 int short_retry; 206 int short_retry;
323 int long_retry; 207 int long_retry;
324 int bbp_type; 208 int bbp_type;
@@ -327,11 +211,16 @@ typedef struct __device_opt {
327 211
328struct vnt_private { 212struct vnt_private {
329 struct pci_dev *pcid; 213 struct pci_dev *pcid;
330 214 /* mac80211 */
331// netdev 215 struct ieee80211_hw *hw;
332 struct net_device *dev; 216 struct ieee80211_vif *vif;
333 217 unsigned long key_entry_inuse;
334//dma addr, rx/tx pool 218 u32 basic_rates;
219 u16 current_aid;
220 int mc_list_count;
221 u8 mac_hw;
222
223/* dma addr, rx/tx pool */
335 dma_addr_t pool_dma; 224 dma_addr_t pool_dma;
336 dma_addr_t rd0_pool_dma; 225 dma_addr_t rd0_pool_dma;
337 dma_addr_t rd1_pool_dma; 226 dma_addr_t rd1_pool_dma;
@@ -356,9 +245,12 @@ struct vnt_private {
356 u32 io_size; 245 u32 io_size;
357 246
358 unsigned char byRevId; 247 unsigned char byRevId;
248 unsigned char byRxMode;
359 unsigned short SubSystemID; 249 unsigned short SubSystemID;
360 unsigned short SubVendorID; 250 unsigned short SubVendorID;
361 251
252 spinlock_t lock;
253
362 int nTxQueues; 254 int nTxQueues;
363 volatile int iTDUsed[TYPE_MAXTD]; 255 volatile int iTDUsed[TYPE_MAXTD];
364 256
@@ -371,30 +263,18 @@ struct vnt_private {
371 volatile PSRxDesc aRD0Ring; 263 volatile PSRxDesc aRD0Ring;
372 volatile PSRxDesc aRD1Ring; 264 volatile PSRxDesc aRD1Ring;
373 volatile PSRxDesc pCurrRD[TYPE_MAXRD]; 265 volatile PSRxDesc pCurrRD[TYPE_MAXRD];
374 SCache sDupRxCache;
375
376 SDeFragControlBlock sRxDFCB[CB_MAX_RX_FRAG];
377 unsigned int cbDFCB;
378 unsigned int cbFreeDFCB;
379 unsigned int uCurrentDFCBIdx;
380 266
381 OPTIONS sOpts; 267 OPTIONS sOpts;
382 268
383 u32 flags; 269 u32 flags;
384 270
385 u32 rx_buf_sz; 271 u32 rx_buf_sz;
272 u8 rx_rate;
386 int multicast_limit; 273 int multicast_limit;
387 unsigned char byRxMode;
388
389 spinlock_t lock;
390
391 pid_t MLMEThr_pid;
392 struct completion notify;
393 struct semaphore mlme_semaphore;
394 274
395 u32 rx_bytes; 275 u32 rx_bytes;
396 276
397 // Version control 277 /* Version control */
398 unsigned char byLocalID; 278 unsigned char byLocalID;
399 unsigned char byRFType; 279 unsigned char byRFType;
400 280
@@ -402,20 +282,15 @@ struct vnt_private {
402 unsigned char byZoneType; 282 unsigned char byZoneType;
403 bool bZoneRegExist; 283 bool bZoneRegExist;
404 unsigned char byOriginalZonetype; 284 unsigned char byOriginalZonetype;
405 unsigned char abyMacContext[MAC_MAX_CONTEXT_REG];
406 bool bLinkPass; // link status: OK or fail
407 unsigned char abyCurrentNetAddr[ETH_ALEN];
408 285
409 // Adapter statistics 286 unsigned char abyCurrentNetAddr[ETH_ALEN]; __aligned(2)
287 bool bLinkPass; /* link status: OK or fail */
288
289 /* Adapter statistics */
410 SStatCounter scStatistic; 290 SStatCounter scStatistic;
411 // 802.11 counter 291 /* 802.11 counter */
412 SDot11Counters s802_11Counter; 292 SDot11Counters s802_11Counter;
413 293
414 // 802.11 management
415 PSMgmtObject pMgmt;
416 SMgmtObject sMgmtObj;
417
418 // 802.11 MAC specific
419 unsigned int uCurrRSSI; 294 unsigned int uCurrRSSI;
420 unsigned char byCurrSQ; 295 unsigned char byCurrSQ;
421 296
@@ -427,22 +302,25 @@ struct vnt_private {
427 bool bTxRxAntInv; 302 bool bTxRxAntInv;
428 303
429 unsigned char *pbyTmpBuff; 304 unsigned char *pbyTmpBuff;
430 unsigned int uSIFS; //Current SIFS 305 unsigned int uSIFS; /* Current SIFS */
431 unsigned int uDIFS; //Current DIFS 306 unsigned int uDIFS; /* Current DIFS */
432 unsigned int uEIFS; //Current EIFS 307 unsigned int uEIFS; /* Current EIFS */
433 unsigned int uSlot; //Current SlotTime 308 unsigned int uSlot; /* Current SlotTime */
434 unsigned int uCwMin; //Current CwMin 309 unsigned int uCwMin; /* Current CwMin */
435 unsigned int uCwMax; //CwMax is fixed on 1023. 310 unsigned int uCwMax; /* CwMax is fixed on 1023. */
436 // PHY parameter 311 /* PHY parameter */
437 unsigned char bySIFS; 312 unsigned char bySIFS;
438 unsigned char byDIFS; 313 unsigned char byDIFS;
439 unsigned char byEIFS; 314 unsigned char byEIFS;
440 unsigned char bySlot; 315 unsigned char bySlot;
441 unsigned char byCWMaxMin; 316 unsigned char byCWMaxMin;
442 CARD_PHY_TYPE eCurrentPHYType;
443 317
444 VIA_BB_TYPE byBBType; //0: 11A, 1:11B, 2:11G 318 u8 byBBType; /* 0:11A, 1:11B, 2:11G */
445 VIA_PKT_TYPE byPacketType; //0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate) 319 u8 byPacketType; /*
320 * 0:11a,1:11b,2:11gb (only CCK
321 * in BasicRate), 3:11ga (OFDM in
322 * Basic Rate)
323 */
446 unsigned short wBasicRate; 324 unsigned short wBasicRate;
447 unsigned char byACKRate; 325 unsigned char byACKRate;
448 unsigned char byTopOFDMBasicRate; 326 unsigned char byTopOFDMBasicRate;
@@ -450,28 +328,16 @@ struct vnt_private {
450 328
451 unsigned char byMinChannel; 329 unsigned char byMinChannel;
452 unsigned char byMaxChannel; 330 unsigned char byMaxChannel;
453 unsigned int uConnectionRate;
454 331
455 unsigned char byPreambleType; 332 unsigned char byPreambleType;
456 unsigned char byShortPreamble; 333 unsigned char byShortPreamble;
457 334
458 unsigned short wCurrentRate; 335 unsigned short wCurrentRate;
459 unsigned short wRTSThreshold;
460 unsigned short wFragmentationThreshold;
461 unsigned char byShortRetryLimit; 336 unsigned char byShortRetryLimit;
462 unsigned char byLongRetryLimit; 337 unsigned char byLongRetryLimit;
463 enum nl80211_iftype op_mode; 338 enum nl80211_iftype op_mode;
464 unsigned char byOpMode;
465 bool bBSSIDFilter; 339 bool bBSSIDFilter;
466 unsigned short wMaxTransmitMSDULifetime; 340 unsigned short wMaxTransmitMSDULifetime;
467 unsigned char abyBSSID[ETH_ALEN];
468 unsigned char abyDesireBSSID[ETH_ALEN];
469 unsigned short wACKDuration; // update while speed change
470 unsigned short wRTSTransmitLen; // update while speed change
471 unsigned char byRTSServiceField; // update while speed change
472 unsigned char byRTSSignalField; // update while speed change
473
474 unsigned long dwMaxReceiveLifetime; // dot11MaxReceiveLifetime
475 341
476 bool bEncryptionEnable; 342 bool bEncryptionEnable;
477 bool bLongHeader; 343 bool bLongHeader;
@@ -480,24 +346,20 @@ struct vnt_private {
480 bool bNonERPPresent; 346 bool bNonERPPresent;
481 bool bBarkerPreambleMd; 347 bool bBarkerPreambleMd;
482 348
483 unsigned char byERPFlag;
484 unsigned short wUseProtectCntDown;
485
486 bool bRadioControlOff; 349 bool bRadioControlOff;
487 bool bRadioOff; 350 bool bRadioOff;
488 bool bEnablePSMode; 351 bool bEnablePSMode;
489 unsigned short wListenInterval; 352 unsigned short wListenInterval;
490 bool bPWBitOn; 353 bool bPWBitOn;
491 WMAC_POWER_MODE ePSMode;
492 354
493 // GPIO Radio Control 355 /* GPIO Radio Control */
494 unsigned char byRadioCtl; 356 unsigned char byRadioCtl;
495 unsigned char byGPIO; 357 unsigned char byGPIO;
496 bool bHWRadioOff; 358 bool bHWRadioOff;
497 bool bPrvActive4RadioOFF; 359 bool bPrvActive4RadioOFF;
498 bool bGPIOBlockRead; 360 bool bGPIOBlockRead;
499 361
500 // Beacon related 362 /* Beacon related */
501 unsigned short wSeqCounter; 363 unsigned short wSeqCounter;
502 unsigned short wBCNBufLen; 364 unsigned short wBCNBufLen;
503 bool bBeaconBufReady; 365 bool bBeaconBufReady;
@@ -506,71 +368,12 @@ struct vnt_private {
506 unsigned int cbBeaconBufReadySetCnt; 368 unsigned int cbBeaconBufReadySetCnt;
507 bool bFixRate; 369 bool bFixRate;
508 unsigned char byCurrentCh; 370 unsigned char byCurrentCh;
509 unsigned int uScanTime;
510
511 CMD_STATE eCommandState;
512
513 CMD_CODE eCommand;
514 bool bBeaconTx;
515
516 bool bStopBeacon;
517 bool bStopDataPkt;
518 bool bStopTx0Pkt;
519 unsigned int uAutoReConnectTime;
520
521 // 802.11 counter
522
523 CMD_ITEM eCmdQueue[CMD_Q_SIZE];
524 unsigned int uCmdDequeueIdx;
525 unsigned int uCmdEnqueueIdx;
526 unsigned int cbFreeCmdQueue;
527 bool bCmdRunning;
528 bool bCmdClear;
529
530 bool bRoaming;
531 //WOW
532 unsigned char abyIPAddr[4];
533
534 unsigned long ulTxPower;
535 NDIS_802_11_WEP_STATUS eEncryptionStatus;
536 bool bTransmitKey;
537//2007-0925-01<Add>by MikeLiu
538//mike add :save old Encryption
539 NDIS_802_11_WEP_STATUS eOldEncryptionStatus;
540
541 SKeyManagement sKey;
542 unsigned long dwIVCounter;
543
544 u64 qwPacketNumber; /* For CCMP and TKIP as TSC(6 bytes) */
545 unsigned int uCurrentWEPMode;
546
547 RC4Ext SBox;
548 unsigned char abyPRNG[WLAN_WEPMAX_KEYLEN+3];
549 unsigned char byKeyIndex;
550 unsigned int uKeyLength;
551 unsigned char abyKey[WLAN_WEP232_KEYLEN];
552 371
553 bool bAES; 372 bool bAES;
554 unsigned char byCntMeasure;
555
556 // for AP mode
557 unsigned int uAssocCount;
558 bool bMoreData;
559
560 // QoS
561 bool bGrpAckPolicy;
562
563 // for OID_802_11_ASSOCIATION_INFORMATION
564 bool bAssocInfoSet;
565 373
566 unsigned char byAutoFBCtrl; 374 unsigned char byAutoFBCtrl;
567 375
568 bool bTxMICFail; 376 /* For Update BaseBand VGA Gain Offset */
569 bool bRxMICFail;
570
571 unsigned int uRATEIdx;
572
573 // For Update BaseBand VGA Gain Offset
574 bool bUpdateBBVGA; 377 bool bUpdateBBVGA;
575 unsigned int uBBVGADiffCount; 378 unsigned int uBBVGADiffCount;
576 unsigned char byBBVGANew; 379 unsigned char byBBVGANew;
@@ -581,24 +384,12 @@ struct vnt_private {
581 unsigned char byBBPreEDRSSI; 384 unsigned char byBBPreEDRSSI;
582 unsigned char byBBPreEDIndex; 385 unsigned char byBBPreEDIndex;
583 386
584 bool bRadioCmd;
585 unsigned long dwDiagRefCount; 387 unsigned long dwDiagRefCount;
586 388
587 // For FOE Tuning 389 /* For FOE Tuning */
588 unsigned char byFOETuning; 390 unsigned char byFOETuning;
589 391
590 // For Auto Power Tunning 392 /* For RF Power table */
591
592 unsigned char byAutoPwrTunning;
593 short sPSetPointCCK;
594 short sPSetPointOFDMG;
595 short sPSetPointOFDMA;
596 long lPFormulaOffset;
597 short sPThreshold;
598 char cAdjustStep;
599 char cMinTxAGC;
600
601 // For RF Power table
602 unsigned char byCCKPwr; 393 unsigned char byCCKPwr;
603 unsigned char byOFDMPwrG; 394 unsigned char byOFDMPwrG;
604 unsigned char byCurPwr; 395 unsigned char byCurPwr;
@@ -610,27 +401,12 @@ struct vnt_private {
610 char abyRegPwr[CB_MAX_CHANNEL+1]; 401 char abyRegPwr[CB_MAX_CHANNEL+1];
611 char abyLocalPwr[CB_MAX_CHANNEL+1]; 402 char abyLocalPwr[CB_MAX_CHANNEL+1];
612 403
613 // BaseBand Loopback Use 404 /* BaseBand Loopback Use */
614 unsigned char byBBCR4d; 405 unsigned char byBBCR4d;
615 unsigned char byBBCRc9; 406 unsigned char byBBCRc9;
616 unsigned char byBBCR88; 407 unsigned char byBBCR88;
617 unsigned char byBBCR09; 408 unsigned char byBBCR09;
618 409
619 // command timer
620 struct timer_list sTimerCommand;
621 struct timer_list sTimerTxData;
622 unsigned long nTxDataTimeCout;
623 bool fTxDataInSleep;
624 bool IsTxDataTrigger;
625
626#ifdef WPA_SM_Transtatus
627 bool fWPA_Authened; //is WPA/WPA-PSK or WPA2/WPA2-PSK authen??
628#endif
629 unsigned char byReAssocCount; //mike add:re-association retry times!
630 unsigned char byLinkWaitCount;
631
632 unsigned char abyNodeName[17];
633
634 bool bDiversityRegCtlON; 410 bool bDiversityRegCtlON;
635 bool bDiversityEnable; 411 bool bDiversityEnable;
636 unsigned long ulDiversityNValue; 412 unsigned long ulDiversityNValue;
@@ -640,13 +416,13 @@ struct vnt_private {
640 unsigned char byTMax3; 416 unsigned char byTMax3;
641 unsigned long ulSQ3TH; 417 unsigned long ulSQ3TH;
642 418
643// ANT diversity 419 /* ANT diversity */
644 unsigned long uDiversityCnt; 420 unsigned long uDiversityCnt;
645 unsigned char byAntennaState; 421 unsigned char byAntennaState;
646 unsigned long ulRatio_State0; 422 unsigned long ulRatio_State0;
647 unsigned long ulRatio_State1; 423 unsigned long ulRatio_State1;
648 424
649 //SQ3 functions for antenna diversity 425 /* SQ3 functions for antenna diversity */
650 struct timer_list TimerSQ3Tmax1; 426 struct timer_list TimerSQ3Tmax1;
651 struct timer_list TimerSQ3Tmax2; 427 struct timer_list TimerSQ3Tmax2;
652 struct timer_list TimerSQ3Tmax3; 428 struct timer_list TimerSQ3Tmax3;
@@ -654,86 +430,11 @@ struct vnt_private {
654 unsigned long uNumSQ3[MAX_RATE]; 430 unsigned long uNumSQ3[MAX_RATE];
655 unsigned short wAntDiversityMaxRate; 431 unsigned short wAntDiversityMaxRate;
656 432
657 SEthernetHeader sTxEthHeader; 433 unsigned char abyEEPROM[EEP_MAX_CONTEXT_SIZE]; /* unsigned long alignment */
658 SEthernetHeader sRxEthHeader;
659 unsigned char abyBroadcastAddr[ETH_ALEN];
660 unsigned char abySNAP_RFC1042[ETH_ALEN];
661 unsigned char abySNAP_Bridgetunnel[ETH_ALEN];
662 unsigned char abyEEPROM[EEP_MAX_CONTEXT_SIZE]; //unsigned long alignment
663 // Pre-Authentication & PMK cache
664 SPMKID gsPMKID;
665 SPMKIDCandidateEvent gsPMKIDCandidate;
666
667 // for 802.11h
668 bool b11hEnable;
669 unsigned char abyCountryCode[3];
670 // for 802.11h DFS
671 unsigned int uNumOfMeasureEIDs;
672 PWLAN_IE_MEASURE_REQ pCurrMeasureEID;
673 bool bMeasureInProgress;
674 unsigned char byOrgChannel;
675 unsigned char byOrgRCR;
676 unsigned long dwOrgMAR0;
677 unsigned long dwOrgMAR4;
678 unsigned char byBasicMap;
679 unsigned char byCCAFraction;
680 unsigned char abyRPIs[8];
681 unsigned long dwRPIs[8];
682 bool bChannelSwitch;
683 unsigned char byNewChannel;
684 unsigned char byChannelSwitchCount;
685 bool bQuietEnable;
686 bool bEnableFirstQuiet;
687 unsigned char byQuietStartCount;
688 unsigned int uQuietEnqueue;
689 unsigned long dwCurrentQuietEndTime;
690 SQuietControl sQuiet[MAX_QUIET_COUNT];
691 // for 802.11h TPC
692 bool bCountryInfo5G;
693 bool bCountryInfo24G;
694 434
695 unsigned short wBeaconInterval; 435 unsigned short wBeaconInterval;
696
697 //WPA supplicant deamon
698 struct net_device *wpadev;
699 bool bWPADEVUp;
700 struct sk_buff *skb;
701#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
702 unsigned int bwextcount;
703 bool bWPASuppWextEnabled;
704#endif
705
706 //--
707#ifdef HOSTAP
708 // user space daemon: hostapd, is used for HOSTAP
709 bool bEnableHostapd;
710 bool bEnable8021x;
711 bool bEnableHostWEP;
712 struct net_device *apdev;
713 int (*tx_80211)(struct sk_buff *skb, struct net_device *dev);
714#endif
715 unsigned int uChannel;
716 bool bMACSuspend;
717
718 struct iw_statistics wstats; // wireless stats
719 bool bCommit;
720}; 436};
721 437
722static inline bool device_get_ip(struct vnt_private *pInfo)
723{
724 struct in_device *in_dev = (struct in_device *)pInfo->dev->ip_ptr;
725 struct in_ifaddr *ifa;
726
727 if (in_dev != NULL) {
728 ifa = (struct in_ifaddr *)in_dev->ifa_list;
729 if (ifa != NULL) {
730 memcpy(pInfo->abyIPAddr, &ifa->ifa_address, 4);
731 return true;
732 }
733 }
734 return false;
735}
736
737static inline PDEVICE_RD_INFO alloc_rd_info(void) 438static inline PDEVICE_RD_INFO alloc_rd_info(void)
738{ 439{
739 return kzalloc(sizeof(DEVICE_RD_INFO), GFP_ATOMIC); 440 return kzalloc(sizeof(DEVICE_RD_INFO), GFP_ATOMIC);
@@ -743,13 +444,4 @@ static inline PDEVICE_TD_INFO alloc_td_info(void)
743{ 444{
744 return kzalloc(sizeof(DEVICE_TD_INFO), GFP_ATOMIC); 445 return kzalloc(sizeof(DEVICE_TD_INFO), GFP_ATOMIC);
745} 446}
746
747/*--------------------- Export Functions --------------------------*/
748
749bool device_dma0_xmit(struct vnt_private *pDevice,
750 struct sk_buff *skb, unsigned int uNodeIndex);
751bool device_alloc_frag_buf(struct vnt_private *pDevice,
752 PSDeFragControlBlock pDeF);
753int Config_FileOperation(struct vnt_private *pDevice,
754 bool fwrite, unsigned char *Parameter);
755#endif 447#endif
diff --git a/drivers/staging/vt6655/device_cfg.h b/drivers/staging/vt6655/device_cfg.h
index 7221824e4f23..a4a8a8489e0b 100644
--- a/drivers/staging/vt6655/device_cfg.h
+++ b/drivers/staging/vt6655/device_cfg.h
@@ -29,8 +29,6 @@
29 29
30#include <linux/types.h> 30#include <linux/types.h>
31 31
32#include "ttype.h"
33
34typedef 32typedef
35struct _version { 33struct _version {
36 unsigned char major; 34 unsigned char major;
diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/device_main.c
index 54e16f40d8ed..83e4162c0094 100644
--- a/drivers/staging/vt6655/device_main.c
+++ b/drivers/staging/vt6655/device_main.c
@@ -32,27 +32,16 @@
32 * device_free_info - device structure resource free function 32 * device_free_info - device structure resource free function
33 * device_get_pci_info - get allocated pci io/mem resource 33 * device_get_pci_info - get allocated pci io/mem resource
34 * device_print_info - print out resource 34 * device_print_info - print out resource
35 * device_open - allocate dma/descripter resource & initial mac/bbp function
36 * device_xmit - asynchrous data tx function
37 * device_intr - interrupt handle function 35 * device_intr - interrupt handle function
38 * device_set_multi - set mac filter
39 * device_ioctl - ioctl entry
40 * device_close - shutdown mac/bbp & free dma/descripter resource
41 * device_rx_srv - rx service function 36 * device_rx_srv - rx service function
42 * device_receive_frame - rx data function
43 * device_alloc_rx_buf - rx buffer pre-allocated function 37 * device_alloc_rx_buf - rx buffer pre-allocated function
44 * device_alloc_frag_buf - rx fragement pre-allocated function
45 * device_free_tx_buf - free tx buffer function 38 * device_free_tx_buf - free tx buffer function
46 * device_free_frag_buf- free de-fragement buffer
47 * device_dma0_tx_80211- tx 802.11 frame via dma0
48 * device_dma0_xmit- tx PS bufferred frame via dma0
49 * device_init_rd0_ring- initial rd dma0 ring 39 * device_init_rd0_ring- initial rd dma0 ring
50 * device_init_rd1_ring- initial rd dma1 ring 40 * device_init_rd1_ring- initial rd dma1 ring
51 * device_init_td0_ring- initial tx dma0 ring buffer 41 * device_init_td0_ring- initial tx dma0 ring buffer
52 * device_init_td1_ring- initial tx dma1 ring buffer 42 * device_init_td1_ring- initial tx dma1 ring buffer
53 * device_init_registers- initial MAC & BBP & RF internal registers. 43 * device_init_registers- initial MAC & BBP & RF internal registers.
54 * device_init_rings- initial tx/rx ring buffer 44 * device_init_rings- initial tx/rx ring buffer
55 * device_init_defrag_cb- initial & allocate de-fragement buffer.
56 * device_free_rings- free all allocated ring buffer 45 * device_free_rings- free all allocated ring buffer
57 * device_tx_srv- tx interrupt service function 46 * device_tx_srv- tx interrupt service function
58 * 47 *
@@ -66,24 +55,10 @@
66#include "channel.h" 55#include "channel.h"
67#include "baseband.h" 56#include "baseband.h"
68#include "mac.h" 57#include "mac.h"
69#include "tether.h"
70#include "wmgr.h"
71#include "wctl.h"
72#include "power.h" 58#include "power.h"
73#include "wcmd.h"
74#include "iocmd.h"
75#include "tcrc.h"
76#include "rxtx.h" 59#include "rxtx.h"
77#include "wroute.h"
78#include "bssdb.h"
79#include "hostap.h"
80#include "wpactl.h"
81#include "ioctl.h"
82#include "iwctl.h"
83#include "dpc.h" 60#include "dpc.h"
84#include "datarate.h"
85#include "rf.h" 61#include "rf.h"
86#include "iowpa.h"
87#include <linux/delay.h> 62#include <linux/delay.h>
88#include <linux/kthread.h> 63#include <linux/kthread.h>
89#include <linux/slab.h> 64#include <linux/slab.h>
@@ -118,89 +93,16 @@ DEVICE_PARAM(TxDescriptors0, "Number of transmit descriptors0");
118#define TX_DESC_DEF1 64 93#define TX_DESC_DEF1 64
119DEVICE_PARAM(TxDescriptors1, "Number of transmit descriptors1"); 94DEVICE_PARAM(TxDescriptors1, "Number of transmit descriptors1");
120 95
121#define IP_ALIG_DEF 0
122/* IP_byte_align[] is used for IP header unsigned long byte aligned
123 0: indicate the IP header won't be unsigned long byte aligned.(Default) .
124 1: indicate the IP header will be unsigned long byte aligned.
125 In some environment, the IP header should be unsigned long byte aligned,
126 or the packet will be droped when we receive it. (eg: IPVS)
127*/
128DEVICE_PARAM(IP_byte_align, "Enable IP header dword aligned");
129
130#define INT_WORKS_DEF 20 96#define INT_WORKS_DEF 20
131#define INT_WORKS_MIN 10 97#define INT_WORKS_MIN 10
132#define INT_WORKS_MAX 64 98#define INT_WORKS_MAX 64
133 99
134DEVICE_PARAM(int_works, "Number of packets per interrupt services"); 100DEVICE_PARAM(int_works, "Number of packets per interrupt services");
135 101
136#define CHANNEL_MIN 1
137#define CHANNEL_MAX 14
138#define CHANNEL_DEF 6
139
140DEVICE_PARAM(Channel, "Channel number");
141
142/* PreambleType[] is the preamble length used for transmit.
143 0: indicate allows long preamble type
144 1: indicate allows short preamble type
145*/
146
147#define PREAMBLE_TYPE_DEF 1
148
149DEVICE_PARAM(PreambleType, "Preamble Type");
150
151#define RTS_THRESH_MIN 512
152#define RTS_THRESH_MAX 2347
153#define RTS_THRESH_DEF 2347 102#define RTS_THRESH_DEF 2347
154 103
155DEVICE_PARAM(RTSThreshold, "RTS threshold");
156
157#define FRAG_THRESH_MIN 256
158#define FRAG_THRESH_MAX 2346
159#define FRAG_THRESH_DEF 2346 104#define FRAG_THRESH_DEF 2346
160 105
161DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
162
163#define DATA_RATE_MIN 0
164#define DATA_RATE_MAX 13
165#define DATA_RATE_DEF 13
166/* datarate[] index
167 0: indicate 1 Mbps 0x02
168 1: indicate 2 Mbps 0x04
169 2: indicate 5.5 Mbps 0x0B
170 3: indicate 11 Mbps 0x16
171 4: indicate 6 Mbps 0x0c
172 5: indicate 9 Mbps 0x12
173 6: indicate 12 Mbps 0x18
174 7: indicate 18 Mbps 0x24
175 8: indicate 24 Mbps 0x30
176 9: indicate 36 Mbps 0x48
177 10: indicate 48 Mbps 0x60
178 11: indicate 54 Mbps 0x6c
179 12: indicate 72 Mbps 0x90
180 13: indicate auto rate
181*/
182
183DEVICE_PARAM(ConnectionRate, "Connection data rate");
184
185#define OP_MODE_DEF 0
186
187DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
188
189/* OpMode[] is used for transmit.
190 0: indicate infrastruct mode used
191 1: indicate adhoc mode used
192 2: indicate AP mode used
193*/
194
195/* PSMode[]
196 0: indicate disable power saving mode
197 1: indicate enable power saving mode
198*/
199
200#define PS_MODE_DEF 0
201
202DEVICE_PARAM(PSMode, "Power saving mode");
203
204#define SHORT_RETRY_MIN 0 106#define SHORT_RETRY_MIN 0
205#define SHORT_RETRY_MAX 31 107#define SHORT_RETRY_MAX 31
206#define SHORT_RETRY_DEF 8 108#define SHORT_RETRY_DEF 8
@@ -224,20 +126,6 @@ DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
224 126
225DEVICE_PARAM(BasebandType, "baseband type"); 127DEVICE_PARAM(BasebandType, "baseband type");
226 128
227/* 80211hEnable[]
228 0: indicate disable 802.11h
229 1: indicate enable 802.11h
230*/
231
232#define X80211h_MODE_DEF 0
233
234DEVICE_PARAM(b80211hEnable, "802.11h mode");
235
236/* 80211hEnable[]
237 0: indicate disable 802.11h
238 1: indicate enable 802.11h
239*/
240
241#define DIVERSITY_ANT_DEF 0 129#define DIVERSITY_ANT_DEF 0
242 130
243DEVICE_PARAM(bDiversityANTEnable, "ANT diversity mode"); 131DEVICE_PARAM(bDiversityANTEnable, "ANT diversity mode");
@@ -265,17 +153,10 @@ static void device_free_info(struct vnt_private *pDevice);
265static bool device_get_pci_info(struct vnt_private *, struct pci_dev *pcid); 153static bool device_get_pci_info(struct vnt_private *, struct pci_dev *pcid);
266static void device_print_info(struct vnt_private *pDevice); 154static void device_print_info(struct vnt_private *pDevice);
267static void device_init_diversity_timer(struct vnt_private *pDevice); 155static void device_init_diversity_timer(struct vnt_private *pDevice);
268static int device_open(struct net_device *dev);
269static int device_xmit(struct sk_buff *skb, struct net_device *dev);
270static irqreturn_t device_intr(int irq, void *dev_instance); 156static irqreturn_t device_intr(int irq, void *dev_instance);
271static void device_set_multi(struct net_device *dev);
272static int device_close(struct net_device *dev);
273static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
274 157
275#ifdef CONFIG_PM 158#ifdef CONFIG_PM
276static int device_notify_reboot(struct notifier_block *, unsigned long event, void *ptr); 159static int device_notify_reboot(struct notifier_block *, unsigned long event, void *ptr);
277static int viawget_suspend(struct pci_dev *pcid, pm_message_t state);
278static int viawget_resume(struct pci_dev *pcid);
279static struct notifier_block device_notifier = { 160static struct notifier_block device_notifier = {
280 .notifier_call = device_notify_reboot, 161 .notifier_call = device_notify_reboot,
281 .next = NULL, 162 .next = NULL,
@@ -285,15 +166,9 @@ static struct notifier_block device_notifier = {
285 166
286static void device_init_rd0_ring(struct vnt_private *pDevice); 167static void device_init_rd0_ring(struct vnt_private *pDevice);
287static void device_init_rd1_ring(struct vnt_private *pDevice); 168static void device_init_rd1_ring(struct vnt_private *pDevice);
288static void device_init_defrag_cb(struct vnt_private *pDevice);
289static void device_init_td0_ring(struct vnt_private *pDevice); 169static void device_init_td0_ring(struct vnt_private *pDevice);
290static void device_init_td1_ring(struct vnt_private *pDevice); 170static void device_init_td1_ring(struct vnt_private *pDevice);
291 171
292static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev);
293//2008-0714<Add>by Mike Liu
294static bool device_release_WPADEV(struct vnt_private *pDevice);
295
296static int ethtool_ioctl(struct net_device *dev, void __user *useraddr);
297static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx); 172static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx);
298static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx); 173static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx);
299static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pDesc); 174static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pDesc);
@@ -304,9 +179,6 @@ static void device_free_td1_ring(struct vnt_private *pDevice);
304static void device_free_rd0_ring(struct vnt_private *pDevice); 179static void device_free_rd0_ring(struct vnt_private *pDevice);
305static void device_free_rd1_ring(struct vnt_private *pDevice); 180static void device_free_rd1_ring(struct vnt_private *pDevice);
306static void device_free_rings(struct vnt_private *pDevice); 181static void device_free_rings(struct vnt_private *pDevice);
307static void device_free_frag_buf(struct vnt_private *pDevice);
308static int Config_FileGetParameter(unsigned char *string,
309 unsigned char *dest, unsigned char *source);
310 182
311/*--------------------- Export Variables --------------------------*/ 183/*--------------------- Export Variables --------------------------*/
312 184
@@ -339,124 +211,50 @@ static void device_get_options(struct vnt_private *pDevice)
339 pOpts->nRxDescs1 = RX_DESC_DEF1; 211 pOpts->nRxDescs1 = RX_DESC_DEF1;
340 pOpts->nTxDescs[0] = TX_DESC_DEF0; 212 pOpts->nTxDescs[0] = TX_DESC_DEF0;
341 pOpts->nTxDescs[1] = TX_DESC_DEF1; 213 pOpts->nTxDescs[1] = TX_DESC_DEF1;
342 pOpts->flags |= DEVICE_FLAGS_IP_ALIGN;
343 pOpts->int_works = INT_WORKS_DEF; 214 pOpts->int_works = INT_WORKS_DEF;
344 pOpts->rts_thresh = RTS_THRESH_DEF;
345 pOpts->frag_thresh = FRAG_THRESH_DEF;
346 pOpts->data_rate = DATA_RATE_DEF;
347 pOpts->channel_num = CHANNEL_DEF;
348 215
349 pOpts->flags |= DEVICE_FLAGS_PREAMBLE_TYPE;
350 pOpts->flags |= DEVICE_FLAGS_OP_MODE;
351 pOpts->short_retry = SHORT_RETRY_DEF; 216 pOpts->short_retry = SHORT_RETRY_DEF;
352 pOpts->long_retry = LONG_RETRY_DEF; 217 pOpts->long_retry = LONG_RETRY_DEF;
353 pOpts->bbp_type = BBP_TYPE_DEF; 218 pOpts->bbp_type = BBP_TYPE_DEF;
354 pOpts->flags |= DEVICE_FLAGS_80211h_MODE;
355 pOpts->flags |= DEVICE_FLAGS_DiversityANT; 219 pOpts->flags |= DEVICE_FLAGS_DiversityANT;
356} 220}
357 221
358static void 222static void
359device_set_options(struct vnt_private *pDevice) 223device_set_options(struct vnt_private *pDevice)
360{ 224{
361 unsigned char abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
362 unsigned char abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
363 unsigned char abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
364
365 memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, ETH_ALEN);
366 memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, ETH_ALEN);
367 memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, ETH_ALEN);
368
369 pDevice->uChannel = pDevice->sOpts.channel_num;
370 pDevice->wRTSThreshold = pDevice->sOpts.rts_thresh;
371 pDevice->wFragmentationThreshold = pDevice->sOpts.frag_thresh;
372 pDevice->byShortRetryLimit = pDevice->sOpts.short_retry; 225 pDevice->byShortRetryLimit = pDevice->sOpts.short_retry;
373 pDevice->byLongRetryLimit = pDevice->sOpts.long_retry; 226 pDevice->byLongRetryLimit = pDevice->sOpts.long_retry;
374 pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
375 pDevice->byShortPreamble = (pDevice->sOpts.flags & DEVICE_FLAGS_PREAMBLE_TYPE) ? 1 : 0;
376 pDevice->byOpMode = (pDevice->sOpts.flags & DEVICE_FLAGS_OP_MODE) ? 1 : 0;
377 pDevice->ePSMode = (pDevice->sOpts.flags & DEVICE_FLAGS_PS_MODE) ? 1 : 0;
378 pDevice->b11hEnable = (pDevice->sOpts.flags & DEVICE_FLAGS_80211h_MODE) ? 1 : 0;
379 pDevice->bDiversityRegCtlON = (pDevice->sOpts.flags & DEVICE_FLAGS_DiversityANT) ? 1 : 0; 227 pDevice->bDiversityRegCtlON = (pDevice->sOpts.flags & DEVICE_FLAGS_DiversityANT) ? 1 : 0;
380 pDevice->uConnectionRate = pDevice->sOpts.data_rate;
381 if (pDevice->uConnectionRate < RATE_AUTO)
382 pDevice->bFixRate = true;
383 pDevice->byBBType = pDevice->sOpts.bbp_type; 228 pDevice->byBBType = pDevice->sOpts.bbp_type;
384 pDevice->byPacketType = (VIA_PKT_TYPE)pDevice->byBBType; 229 pDevice->byPacketType = pDevice->byBBType;
385 pDevice->byAutoFBCtrl = AUTO_FB_0; 230 pDevice->byAutoFBCtrl = AUTO_FB_0;
386 pDevice->bUpdateBBVGA = true; 231 pDevice->bUpdateBBVGA = true;
387 pDevice->byFOETuning = 0;
388 pDevice->byPreambleType = 0; 232 pDevice->byPreambleType = 0;
389 233
390 pr_debug(" uChannel= %d\n", (int)pDevice->uChannel);
391 pr_debug(" byOpMode= %d\n", (int)pDevice->byOpMode);
392 pr_debug(" ePSMode= %d\n", (int)pDevice->ePSMode);
393 pr_debug(" wRTSThreshold= %d\n", (int)pDevice->wRTSThreshold);
394 pr_debug(" byShortRetryLimit= %d\n", (int)pDevice->byShortRetryLimit); 234 pr_debug(" byShortRetryLimit= %d\n", (int)pDevice->byShortRetryLimit);
395 pr_debug(" byLongRetryLimit= %d\n", (int)pDevice->byLongRetryLimit); 235 pr_debug(" byLongRetryLimit= %d\n", (int)pDevice->byLongRetryLimit);
396 pr_debug(" byPreambleType= %d\n", (int)pDevice->byPreambleType); 236 pr_debug(" byPreambleType= %d\n", (int)pDevice->byPreambleType);
397 pr_debug(" byShortPreamble= %d\n", (int)pDevice->byShortPreamble); 237 pr_debug(" byShortPreamble= %d\n", (int)pDevice->byShortPreamble);
398 pr_debug(" uConnectionRate= %d\n", (int)pDevice->uConnectionRate);
399 pr_debug(" byBBType= %d\n", (int)pDevice->byBBType); 238 pr_debug(" byBBType= %d\n", (int)pDevice->byBBType);
400 pr_debug(" pDevice->b11hEnable= %d\n", (int)pDevice->b11hEnable);
401 pr_debug(" pDevice->bDiversityRegCtlON= %d\n", 239 pr_debug(" pDevice->bDiversityRegCtlON= %d\n",
402 (int)pDevice->bDiversityRegCtlON); 240 (int)pDevice->bDiversityRegCtlON);
403} 241}
404 242
405static void s_vCompleteCurrentMeasure(struct vnt_private *pDevice,
406 unsigned char byResult)
407{
408 unsigned int ii;
409 unsigned long dwDuration = 0;
410 unsigned char byRPI0 = 0;
411
412 for (ii = 1; ii < 8; ii++) {
413 pDevice->dwRPIs[ii] *= 255;
414 dwDuration |= *((unsigned short *)(pDevice->pCurrMeasureEID->sReq.abyDuration));
415 dwDuration <<= 10;
416 pDevice->dwRPIs[ii] /= dwDuration;
417 pDevice->abyRPIs[ii] = (unsigned char)pDevice->dwRPIs[ii];
418 byRPI0 += pDevice->abyRPIs[ii];
419 }
420 pDevice->abyRPIs[0] = (0xFF - byRPI0);
421
422 if (pDevice->uNumOfMeasureEIDs == 0) {
423 VNTWIFIbMeasureReport(pDevice->pMgmt,
424 true,
425 pDevice->pCurrMeasureEID,
426 byResult,
427 pDevice->byBasicMap,
428 pDevice->byCCAFraction,
429 pDevice->abyRPIs
430 );
431 } else {
432 VNTWIFIbMeasureReport(pDevice->pMgmt,
433 false,
434 pDevice->pCurrMeasureEID,
435 byResult,
436 pDevice->byBasicMap,
437 pDevice->byCCAFraction,
438 pDevice->abyRPIs
439 );
440 CARDbStartMeasure(pDevice, pDevice->pCurrMeasureEID++, pDevice->uNumOfMeasureEIDs);
441 }
442}
443
444// 243//
445// Initialisation of MAC & BBP registers 244// Initialisation of MAC & BBP registers
446// 245//
447 246
448static void device_init_registers(struct vnt_private *pDevice) 247static void device_init_registers(struct vnt_private *pDevice)
449{ 248{
249 unsigned long flags;
450 unsigned int ii; 250 unsigned int ii;
451 unsigned char byValue; 251 unsigned char byValue;
452 unsigned char byValue1; 252 unsigned char byValue1;
453 unsigned char byCCKPwrdBm = 0; 253 unsigned char byCCKPwrdBm = 0;
454 unsigned char byOFDMPwrdBm = 0; 254 unsigned char byOFDMPwrdBm = 0;
455 int zonetype = 0;
456 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
457 255
458 MACbShutdown(pDevice->PortOffset); 256 MACbShutdown(pDevice->PortOffset);
459 BBvSoftwareReset(pDevice->PortOffset); 257 BBvSoftwareReset(pDevice);
460 258
461 /* Do MACbSoftwareReset in MACvInitialize */ 259 /* Do MACbSoftwareReset in MACvInitialize */
462 MACbSoftwareReset(pDevice->PortOffset); 260 MACbSoftwareReset(pDevice->PortOffset);
@@ -481,11 +279,11 @@ static void device_init_registers(struct vnt_private *pDevice)
481 /* Get Local ID */ 279 /* Get Local ID */
482 VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &pDevice->byLocalID); 280 VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &pDevice->byLocalID);
483 281
484 spin_lock_irq(&pDevice->lock); 282 spin_lock_irqsave(&pDevice->lock, flags);
485 283
486 SROMvReadAllContents(pDevice->PortOffset, pDevice->abyEEPROM); 284 SROMvReadAllContents(pDevice->PortOffset, pDevice->abyEEPROM);
487 285
488 spin_unlock_irq(&pDevice->lock); 286 spin_unlock_irqrestore(&pDevice->lock, flags);
489 287
490 /* Get Channel range */ 288 /* Get Channel range */
491 pDevice->byMinChannel = 1; 289 pDevice->byMinChannel = 1;
@@ -558,41 +356,6 @@ static void device_init_registers(struct vnt_private *pDevice)
558 356
559 /* zonetype initial */ 357 /* zonetype initial */
560 pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE]; 358 pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
561 zonetype = Config_FileOperation(pDevice, false, NULL);
562
563 if (zonetype >= 0) {
564 if ((zonetype == 0) &&
565 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x00)) {
566 /* for USA */
567 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0;
568 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0B;
569
570 pr_debug("Init Zone Type :USA\n");
571 } else if ((zonetype == 1) &&
572 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x01)) {
573 /* for Japan */
574 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x01;
575 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
576 } else if ((zonetype == 2) &&
577 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x02)) {
578 /* for Europe */
579 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x02;
580 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
581
582 pr_debug("Init Zone Type :Europe\n");
583 } else {
584 if (zonetype != pDevice->abyEEPROM[EEP_OFS_ZONETYPE])
585 pr_debug("zonetype in file[%02x] mismatch with in EEPROM[%02x]\n",
586 zonetype,
587 pDevice->abyEEPROM[EEP_OFS_ZONETYPE]);
588 else
589 pr_debug("Read Zonetype file success,use default zonetype setting[%02x]\n",
590 zonetype);
591 }
592 } else {
593 pr_debug("Read Zonetype file fail,use default zonetype setting[%02x]\n",
594 SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ZONETYPE));
595 }
596 359
597 /* Get RFType */ 360 /* Get RFType */
598 pDevice->byRFType = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RFTYPE); 361 pDevice->byRFType = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RFTYPE);
@@ -636,14 +399,9 @@ static void device_init_registers(struct vnt_private *pDevice)
636 } 399 }
637 400
638 /* recover 12,13 ,14channel for EUROPE by 11 channel */ 401 /* recover 12,13 ,14channel for EUROPE by 11 channel */
639 if (((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) || 402 for (ii = 11; ii < 14; ii++) {
640 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe)) && 403 pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
641 (pDevice->byOriginalZonetype == ZoneType_USA)) { 404 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
642 for (ii = 11; ii < 14; ii++) {
643 pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
644 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
645
646 }
647 } 405 }
648 406
649 /* Load OFDM A Power Table */ 407 /* Load OFDM A Power Table */
@@ -657,8 +415,6 @@ static void device_init_registers(struct vnt_private *pDevice)
657 (unsigned char)(ii + EEP_OFS_OFDMA_PWR_dBm)); 415 (unsigned char)(ii + EEP_OFS_OFDMA_PWR_dBm));
658 } 416 }
659 417
660 init_channel_table((void *)pDevice);
661
662 if (pDevice->byLocalID > REV_ID_VT3253_B1) { 418 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
663 MACvSelectPage1(pDevice->PortOffset); 419 MACvSelectPage1(pDevice->PortOffset);
664 420
@@ -690,21 +446,12 @@ static void device_init_registers(struct vnt_private *pDevice)
690 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]); 446 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
691 } 447 }
692 448
693 BBvSetRxAntennaMode(pDevice->PortOffset, pDevice->byRxAntennaMode); 449 BBvSetRxAntennaMode(pDevice, pDevice->byRxAntennaMode);
694 BBvSetTxAntennaMode(pDevice->PortOffset, pDevice->byTxAntennaMode); 450 BBvSetTxAntennaMode(pDevice, pDevice->byTxAntennaMode);
695
696 pDevice->byCurrentCh = 0;
697 451
698 /* Set BB and packet type at the same time. */ 452 /* Set BB and packet type at the same time. */
699 /* Set Short Slot Time, xIFS, and RSPINF. */ 453 /* Set Short Slot Time, xIFS, and RSPINF. */
700 if (pDevice->uConnectionRate == RATE_AUTO) 454 pDevice->wCurrentRate = RATE_54M;
701 pDevice->wCurrentRate = RATE_54M;
702 else
703 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
704
705 /* default G Mode */
706 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_11G);
707 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_AUTO);
708 455
709 pDevice->bRadioOff = false; 456 pDevice->bRadioOff = false;
710 457
@@ -726,8 +473,6 @@ static void device_init_registers(struct vnt_private *pDevice)
726 if (pDevice->bHWRadioOff || pDevice->bRadioControlOff) 473 if (pDevice->bHWRadioOff || pDevice->bRadioControlOff)
727 CARDbRadioPowerOff(pDevice); 474 CARDbRadioPowerOff(pDevice);
728 475
729 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
730
731 /* get Permanent network address */ 476 /* get Permanent network address */
732 SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr); 477 SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
733 pr_debug("Network address = %pM\n", pDevice->abyCurrentNetAddr); 478 pr_debug("Network address = %pM\n", pDevice->abyCurrentNetAddr);
@@ -740,223 +485,39 @@ static void device_init_registers(struct vnt_private *pDevice)
740 if (pDevice->byLocalID <= REV_ID_VT3253_A1) 485 if (pDevice->byLocalID <= REV_ID_VT3253_A1)
741 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR); 486 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR);
742 487
743 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
744
745 /* Turn On Rx DMA */ 488 /* Turn On Rx DMA */
746 MACvReceive0(pDevice->PortOffset); 489 MACvReceive0(pDevice->PortOffset);
747 MACvReceive1(pDevice->PortOffset); 490 MACvReceive1(pDevice->PortOffset);
748 491
749 /* start the adapter */ 492 /* start the adapter */
750 MACvStart(pDevice->PortOffset); 493 MACvStart(pDevice->PortOffset);
751
752 netif_stop_queue(pDevice->dev);
753} 494}
754 495
755static void device_init_diversity_timer(struct vnt_private *pDevice) 496static void device_init_diversity_timer(struct vnt_private *pDevice)
756{ 497{
757 init_timer(&pDevice->TimerSQ3Tmax1); 498 init_timer(&pDevice->TimerSQ3Tmax1);
758 pDevice->TimerSQ3Tmax1.data = (unsigned long) pDevice; 499 pDevice->TimerSQ3Tmax1.data = (unsigned long) pDevice;
759 pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack; 500 pDevice->TimerSQ3Tmax1.function = TimerSQ3CallBack;
760 pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ); 501 pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
761 502
762 init_timer(&pDevice->TimerSQ3Tmax2); 503 init_timer(&pDevice->TimerSQ3Tmax2);
763 pDevice->TimerSQ3Tmax2.data = (unsigned long) pDevice; 504 pDevice->TimerSQ3Tmax2.data = (unsigned long) pDevice;
764 pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack; 505 pDevice->TimerSQ3Tmax2.function = TimerSQ3CallBack;
765 pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ); 506 pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
766 507
767 init_timer(&pDevice->TimerSQ3Tmax3); 508 init_timer(&pDevice->TimerSQ3Tmax3);
768 pDevice->TimerSQ3Tmax3.data = (unsigned long) pDevice; 509 pDevice->TimerSQ3Tmax3.data = (unsigned long) pDevice;
769 pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerState1CallBack; 510 pDevice->TimerSQ3Tmax3.function = TimerState1CallBack;
770 pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ); 511 pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
771} 512}
772 513
773static bool device_release_WPADEV(struct vnt_private *pDevice)
774{
775 viawget_wpa_header *wpahdr;
776 int ii = 0;
777
778 //send device close to wpa_supplicnat layer
779 if (pDevice->bWPADEVUp) {
780 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
781 wpahdr->type = VIAWGET_DEVICECLOSE_MSG;
782 wpahdr->resp_ie_len = 0;
783 wpahdr->req_ie_len = 0;
784 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
785 pDevice->skb->dev = pDevice->wpadev;
786 skb_reset_mac_header(pDevice->skb);
787 pDevice->skb->pkt_type = PACKET_HOST;
788 pDevice->skb->protocol = htons(ETH_P_802_2);
789 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
790 netif_rx(pDevice->skb);
791 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
792
793 while (pDevice->bWPADEVUp) {
794 set_current_state(TASK_UNINTERRUPTIBLE);
795 schedule_timeout(HZ / 20); //wait 50ms
796 ii++;
797 if (ii > 20)
798 break;
799 }
800 }
801 return true;
802}
803
804static const struct net_device_ops device_netdev_ops = {
805 .ndo_open = device_open,
806 .ndo_stop = device_close,
807 .ndo_do_ioctl = device_ioctl,
808 .ndo_start_xmit = device_xmit,
809 .ndo_set_rx_mode = device_set_multi,
810};
811
812static int
813vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
814{
815 static bool bFirst = true;
816 struct net_device *dev = NULL;
817 PCHIP_INFO pChip_info = (PCHIP_INFO)ent->driver_data;
818 struct vnt_private *pDevice;
819 int rc;
820
821 dev = alloc_etherdev(sizeof(*pDevice));
822
823 pDevice = netdev_priv(dev);
824
825 if (dev == NULL) {
826 pr_err(DEVICE_NAME ": allocate net device failed\n");
827 return -ENOMEM;
828 }
829
830 // Chain it all together
831 SET_NETDEV_DEV(dev, &pcid->dev);
832
833 if (bFirst) {
834 pr_notice("%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
835 pr_notice("Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
836 bFirst = false;
837 }
838
839 vt6655_init_info(pcid, &pDevice, pChip_info);
840 pDevice->dev = dev;
841
842 if (pci_enable_device(pcid)) {
843 device_free_info(pDevice);
844 return -ENODEV;
845 }
846 dev->irq = pcid->irq;
847
848#ifdef DEBUG
849 pr_debug("Before get pci_info memaddr is %x\n", pDevice->memaddr);
850#endif
851 if (!device_get_pci_info(pDevice, pcid)) {
852 pr_err(DEVICE_NAME ": Failed to find PCI device.\n");
853 device_free_info(pDevice);
854 return -ENODEV;
855 }
856
857#if 1
858
859#ifdef DEBUG
860
861 pr_debug("after get pci_info memaddr is %x, io addr is %x,io_size is %d\n", pDevice->memaddr, pDevice->ioaddr, pDevice->io_size);
862 {
863 int i;
864 u32 bar, len;
865 u32 address[] = {
866 PCI_BASE_ADDRESS_0,
867 PCI_BASE_ADDRESS_1,
868 PCI_BASE_ADDRESS_2,
869 PCI_BASE_ADDRESS_3,
870 PCI_BASE_ADDRESS_4,
871 PCI_BASE_ADDRESS_5,
872 0};
873 for (i = 0; address[i]; i++) {
874 pci_read_config_dword(pcid, address[i], &bar);
875 pr_debug("bar %d is %x\n", i, bar);
876 if (!bar) {
877 pr_debug("bar %d not implemented\n", i);
878 continue;
879 }
880 if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
881 /* This is IO */
882
883 len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xFFFF);
884 len = len & ~(len - 1);
885
886 pr_debug("IO space: len in IO %x, BAR %d\n", len, i);
887 } else {
888 len = bar & 0xFFFFFFF0;
889 len = ~len + 1;
890
891 pr_debug("len in MEM %x, BAR %d\n", len, i);
892 }
893 }
894 }
895#endif
896
897#endif
898
899 pDevice->PortOffset = ioremap(pDevice->memaddr & PCI_BASE_ADDRESS_MEM_MASK, pDevice->io_size);
900
901 if (pDevice->PortOffset == NULL) {
902 pr_err(DEVICE_NAME ": Failed to IO remapping ..\n");
903 device_free_info(pDevice);
904 return -ENODEV;
905 }
906
907 rc = pci_request_regions(pcid, DEVICE_NAME);
908 if (rc) {
909 pr_err(DEVICE_NAME ": Failed to find PCI device\n");
910 device_free_info(pDevice);
911 return -ENODEV;
912 }
913
914 dev->base_addr = pDevice->ioaddr;
915 // do reset
916 if (!MACbSoftwareReset(pDevice->PortOffset)) {
917 pr_err(DEVICE_NAME ": Failed to access MAC hardware..\n");
918 device_free_info(pDevice);
919 return -ENODEV;
920 }
921 // initial to reload eeprom
922 MACvInitialize(pDevice->PortOffset);
923 MACvReadEtherAddress(pDevice->PortOffset, dev->dev_addr);
924
925 device_get_options(pDevice);
926 device_set_options(pDevice);
927 //Mask out the options cannot be set to the chip
928 pDevice->sOpts.flags &= pChip_info->flags;
929
930 //Enable the chip specified capabilities
931 pDevice->flags = pDevice->sOpts.flags | (pChip_info->flags & 0xFF000000UL);
932 pDevice->tx_80211 = device_dma0_tx_80211;
933 pDevice->sMgmtObj.pAdapter = (void *)pDevice;
934 pDevice->pMgmt = &(pDevice->sMgmtObj);
935
936 dev->irq = pcid->irq;
937 dev->netdev_ops = &device_netdev_ops;
938
939 dev->wireless_handlers = (struct iw_handler_def *)&iwctl_handler_def;
940
941 rc = register_netdev(dev);
942 if (rc) {
943 pr_err(DEVICE_NAME " Failed to register netdev\n");
944 device_free_info(pDevice);
945 return -ENODEV;
946 }
947 device_print_info(pDevice);
948 pci_set_drvdata(pcid, pDevice);
949 return 0;
950}
951
952static void device_print_info(struct vnt_private *pDevice) 514static void device_print_info(struct vnt_private *pDevice)
953{ 515{
954 struct net_device *dev = pDevice->dev; 516 dev_info(&pDevice->pcid->dev, "%s\n", get_chip_name(pDevice->chip_id));
955 517
956 pr_info("%s: %s\n", dev->name, get_chip_name(pDevice->chip_id)); 518 dev_info(&pDevice->pcid->dev, "MAC=%pM IO=0x%lx Mem=0x%lx IRQ=%d\n",
957 pr_info("%s: MAC=%pM IO=0x%lx Mem=0x%lx IRQ=%d\n", 519 pDevice->abyCurrentNetAddr, (unsigned long)pDevice->ioaddr,
958 dev->name, dev->dev_addr, (unsigned long)pDevice->ioaddr, 520 (unsigned long)pDevice->PortOffset, pDevice->pcid->irq);
959 (unsigned long)pDevice->PortOffset, pDevice->dev->irq);
960} 521}
961 522
962static void vt6655_init_info(struct pci_dev *pcid, 523static void vt6655_init_info(struct pci_dev *pcid,
@@ -1003,31 +564,20 @@ static bool device_get_pci_info(struct vnt_private *pDevice,
1003 564
1004static void device_free_info(struct vnt_private *pDevice) 565static void device_free_info(struct vnt_private *pDevice)
1005{ 566{
1006 struct net_device *dev = pDevice->dev; 567 if (!pDevice)
1007 568 return;
1008 ASSERT(pDevice);
1009//2008-0714-01<Add>by chester
1010 device_release_WPADEV(pDevice);
1011
1012//2008-07-21-01<Add>by MikeLiu
1013//unregister wpadev
1014 if (wpa_set_wpadev(pDevice, 0) != 0)
1015 pr_err("unregister wpadev fail?\n");
1016 569
1017#ifdef HOSTAP 570 if (pDevice->mac_hw)
1018 if (dev) 571 ieee80211_unregister_hw(pDevice->hw);
1019 vt6655_hostap_set_hostapd(pDevice, 0, 0);
1020#endif
1021 if (dev)
1022 unregister_netdev(dev);
1023 572
1024 if (pDevice->PortOffset) 573 if (pDevice->PortOffset)
1025 iounmap(pDevice->PortOffset); 574 iounmap(pDevice->PortOffset);
1026 575
1027 if (pDevice->pcid) 576 if (pDevice->pcid)
1028 pci_release_regions(pDevice->pcid); 577 pci_release_regions(pDevice->pcid);
1029 if (dev) 578
1030 free_netdev(dev); 579 if (pDevice->hw)
580 ieee80211_free_hw(pDevice->hw);
1031} 581}
1032 582
1033static bool device_init_rings(struct vnt_private *pDevice) 583static bool device_init_rings(struct vnt_private *pDevice)
@@ -1176,21 +726,6 @@ static void device_init_rd1_ring(struct vnt_private *pDevice)
1176 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]); 726 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
1177} 727}
1178 728
1179static void device_init_defrag_cb(struct vnt_private *pDevice)
1180{
1181 int i;
1182 PSDeFragControlBlock pDeF;
1183
1184 /* Init the fragment ctl entries */
1185 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1186 pDeF = &(pDevice->sRxDFCB[i]);
1187 if (!device_alloc_frag_buf(pDevice, pDeF))
1188 dev_err(&pDevice->pcid->dev, "can not alloc frag bufs\n");
1189 }
1190 pDevice->cbDFCB = CB_MAX_RX_FRAG;
1191 pDevice->cbFreeDFCB = pDevice->cbDFCB;
1192}
1193
1194static void device_free_rd0_ring(struct vnt_private *pDevice) 729static void device_free_rd0_ring(struct vnt_private *pDevice)
1195{ 730{
1196 int i; 731 int i;
@@ -1204,7 +739,7 @@ static void device_free_rd0_ring(struct vnt_private *pDevice)
1204 739
1205 dev_kfree_skb(pRDInfo->skb); 740 dev_kfree_skb(pRDInfo->skb);
1206 741
1207 kfree((void *)pDesc->pRDInfo); 742 kfree(pDesc->pRDInfo);
1208 } 743 }
1209} 744}
1210 745
@@ -1221,21 +756,7 @@ static void device_free_rd1_ring(struct vnt_private *pDevice)
1221 756
1222 dev_kfree_skb(pRDInfo->skb); 757 dev_kfree_skb(pRDInfo->skb);
1223 758
1224 kfree((void *)pDesc->pRDInfo); 759 kfree(pDesc->pRDInfo);
1225 }
1226}
1227
1228static void device_free_frag_buf(struct vnt_private *pDevice)
1229{
1230 PSDeFragControlBlock pDeF;
1231 int i;
1232
1233 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1234 pDeF = &(pDevice->sRxDFCB[i]);
1235
1236 if (pDeF->skb)
1237 dev_kfree_skb(pDeF->skb);
1238
1239 } 760 }
1240} 761}
1241 762
@@ -1305,7 +826,7 @@ static void device_free_td0_ring(struct vnt_private *pDevice)
1305 if (pTDInfo->skb) 826 if (pTDInfo->skb)
1306 dev_kfree_skb(pTDInfo->skb); 827 dev_kfree_skb(pTDInfo->skb);
1307 828
1308 kfree((void *)pDesc->pTDInfo); 829 kfree(pDesc->pTDInfo);
1309 } 830 }
1310} 831}
1311 832
@@ -1324,7 +845,7 @@ static void device_free_td1_ring(struct vnt_private *pDevice)
1324 if (pTDInfo->skb) 845 if (pTDInfo->skb)
1325 dev_kfree_skb(pTDInfo->skb); 846 dev_kfree_skb(pTDInfo->skb);
1326 847
1327 kfree((void *)pDesc->pTDInfo); 848 kfree(pDesc->pTDInfo);
1328 } 849 }
1329} 850}
1330 851
@@ -1340,7 +861,7 @@ static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx)
1340 pRD = pRD->next) { 861 pRD = pRD->next) {
1341 if (works++ > 15) 862 if (works++ > 15)
1342 break; 863 break;
1343 if (device_receive_frame(pDevice, pRD)) { 864 if (vnt_receive_frame(pDevice, pRD)) {
1344 if (!device_alloc_rx_buf(pDevice, pRD)) { 865 if (!device_alloc_rx_buf(pDevice, pRD)) {
1345 dev_err(&pDevice->pcid->dev, 866 dev_err(&pDevice->pcid->dev,
1346 "can not allocate rx buf\n"); 867 "can not allocate rx buf\n");
@@ -1348,7 +869,6 @@ static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx)
1348 } 869 }
1349 } 870 }
1350 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC; 871 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1351 pDevice->dev->last_rx = jiffies;
1352 } 872 }
1353 873
1354 pDevice->pCurrRD[uIdx] = pRD; 874 pDevice->pCurrRD[uIdx] = pRD;
@@ -1364,9 +884,12 @@ static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pRD)
1364 if (pRDInfo->skb == NULL) 884 if (pRDInfo->skb == NULL)
1365 return false; 885 return false;
1366 ASSERT(pRDInfo->skb); 886 ASSERT(pRDInfo->skb);
1367 pRDInfo->skb->dev = pDevice->dev; 887
1368 pRDInfo->skb_dma = pci_map_single(pDevice->pcid, skb_tail_pointer(pRDInfo->skb), 888 pRDInfo->skb_dma =
1369 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE); 889 pci_map_single(pDevice->pcid,
890 skb_put(pRDInfo->skb, skb_tailroom(pRDInfo->skb)),
891 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
892
1370 *((unsigned int *)&(pRD->m_rd0RD0)) = 0; /* FIX cast */ 893 *((unsigned int *)&(pRD->m_rd0RD0)) = 0; /* FIX cast */
1371 894
1372 pRD->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz); 895 pRD->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
@@ -1377,31 +900,84 @@ static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pRD)
1377 return true; 900 return true;
1378} 901}
1379 902
1380bool device_alloc_frag_buf(struct vnt_private *pDevice, 903static const u8 fallback_rate0[5][5] = {
1381 PSDeFragControlBlock pDeF) 904 {RATE_18M, RATE_18M, RATE_12M, RATE_12M, RATE_12M},
905 {RATE_24M, RATE_24M, RATE_18M, RATE_12M, RATE_12M},
906 {RATE_36M, RATE_36M, RATE_24M, RATE_18M, RATE_18M},
907 {RATE_48M, RATE_48M, RATE_36M, RATE_24M, RATE_24M},
908 {RATE_54M, RATE_54M, RATE_48M, RATE_36M, RATE_36M}
909};
910
911static const u8 fallback_rate1[5][5] = {
912 {RATE_18M, RATE_18M, RATE_12M, RATE_6M, RATE_6M},
913 {RATE_24M, RATE_24M, RATE_18M, RATE_6M, RATE_6M},
914 {RATE_36M, RATE_36M, RATE_24M, RATE_12M, RATE_12M},
915 {RATE_48M, RATE_48M, RATE_24M, RATE_12M, RATE_12M},
916 {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M}
917};
918
919static int vnt_int_report_rate(struct vnt_private *priv,
920 PDEVICE_TD_INFO context, u8 tsr0, u8 tsr1)
1382{ 921{
1383 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz); 922 struct vnt_tx_fifo_head *fifo_head;
1384 if (pDeF->skb == NULL) 923 struct ieee80211_tx_info *info;
1385 return false; 924 struct ieee80211_rate *rate;
1386 ASSERT(pDeF->skb); 925 u16 fb_option;
1387 pDeF->skb->dev = pDevice->dev; 926 u8 tx_retry = (tsr0 & TSR0_NCR);
927 s8 idx;
928
929 if (!context)
930 return -ENOMEM;
1388 931
1389 return true; 932 if (!context->skb)
933 return -EINVAL;
934
935 fifo_head = (struct vnt_tx_fifo_head *)context->buf;
936 fb_option = (le16_to_cpu(fifo_head->fifo_ctl) &
937 (FIFOCTL_AUTO_FB_0 | FIFOCTL_AUTO_FB_1));
938
939 info = IEEE80211_SKB_CB(context->skb);
940 idx = info->control.rates[0].idx;
941
942 if (fb_option && !(tsr1 & TSR1_TERR)) {
943 u8 tx_rate;
944 u8 retry = tx_retry;
945
946 rate = ieee80211_get_tx_rate(priv->hw, info);
947 tx_rate = rate->hw_value - RATE_18M;
948
949 if (retry > 4)
950 retry = 4;
951
952 if (fb_option & FIFOCTL_AUTO_FB_0)
953 tx_rate = fallback_rate0[tx_rate][retry];
954 else if (fb_option & FIFOCTL_AUTO_FB_1)
955 tx_rate = fallback_rate1[tx_rate][retry];
956
957 if (info->band == IEEE80211_BAND_5GHZ)
958 idx = tx_rate - RATE_6M;
959 else
960 idx = tx_rate;
961 }
962
963 ieee80211_tx_info_clear_status(info);
964
965 info->status.rates[0].count = tx_retry;
966
967 if (!(tsr1 & TSR1_TERR)) {
968 info->status.rates[0].idx = idx;
969 info->flags |= IEEE80211_TX_STAT_ACK;
970 }
971
972 return 0;
1390} 973}
1391 974
1392static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx) 975static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx)
1393{ 976{
1394 PSTxDesc pTD; 977 PSTxDesc pTD;
1395 bool bFull = false;
1396 int works = 0; 978 int works = 0;
1397 unsigned char byTsr0; 979 unsigned char byTsr0;
1398 unsigned char byTsr1; 980 unsigned char byTsr1;
1399 unsigned int uFrameSize, uFIFOHeaderSize;
1400 PSTxBufHead pTxBufHead;
1401 struct net_device_stats *pStats = &pDevice->dev->stats;
1402 struct sk_buff *skb;
1403 unsigned int uNodeIndex;
1404 PSMgmtObject pMgmt = pDevice->pMgmt;
1405 981
1406 for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] > 0; pTD = pTD->next) { 982 for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] > 0; pTD = pTD->next) {
1407 if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC) 983 if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC)
@@ -1415,22 +991,8 @@ static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx)
1415 //Only the status of first TD in the chain is correct 991 //Only the status of first TD in the chain is correct
1416 if (pTD->m_td1TD1.byTCR & TCR_STP) { 992 if (pTD->m_td1TD1.byTCR & TCR_STP) {
1417 if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) { 993 if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) {
1418 uFIFOHeaderSize = pTD->pTDInfo->dwHeaderLength; 994
1419 uFrameSize = pTD->pTDInfo->dwReqCount - uFIFOHeaderSize; 995 vnt_int_report_rate(pDevice, pTD->pTDInfo, byTsr0, byTsr1);
1420 pTxBufHead = (PSTxBufHead) (pTD->pTDInfo->buf);
1421 // Update the statistics based on the Transmit status
1422 // now, we DONT check TSR0_CDH
1423
1424 STAvUpdateTDStatCounter(&pDevice->scStatistic,
1425 byTsr0, byTsr1,
1426 (unsigned char *)(pTD->pTDInfo->buf + uFIFOHeaderSize),
1427 uFrameSize, uIdx);
1428
1429 BSSvUpdateNodeTxCounter(pDevice,
1430 byTsr0, byTsr1,
1431 (unsigned char *)(pTD->pTDInfo->buf),
1432 uFIFOHeaderSize
1433 );
1434 996
1435 if (!(byTsr1 & TSR1_TERR)) { 997 if (!(byTsr1 & TSR1_TERR)) {
1436 if (byTsr0 != 0) { 998 if (byTsr0 != 0) {
@@ -1438,28 +1000,9 @@ static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx)
1438 (int)uIdx, byTsr1, 1000 (int)uIdx, byTsr1,
1439 byTsr0); 1001 byTsr0);
1440 } 1002 }
1441 if ((pTxBufHead->wFragCtl & FRAGCTL_ENDFRAG) != FRAGCTL_NONFRAG)
1442 pDevice->s802_11Counter.TransmittedFragmentCount++;
1443
1444 pStats->tx_packets++;
1445 pStats->tx_bytes += pTD->pTDInfo->skb->len;
1446 } else { 1003 } else {
1447 pr_debug(" Tx[%d] dropped & tsr1[%02X] tsr0[%02X]\n", 1004 pr_debug(" Tx[%d] dropped & tsr1[%02X] tsr0[%02X]\n",
1448 (int)uIdx, byTsr1, byTsr0); 1005 (int)uIdx, byTsr1, byTsr0);
1449 pStats->tx_errors++;
1450 pStats->tx_dropped++;
1451 }
1452 }
1453
1454 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1455 if (pDevice->bEnableHostapd) {
1456 pr_debug("tx call back netif..\n");
1457 skb = pTD->pTDInfo->skb;
1458 skb->dev = pDevice->apdev;
1459 skb_reset_mac_header(skb);
1460 skb->pkt_type = PACKET_OTHERHOST;
1461 memset(skb->cb, 0, sizeof(skb->cb));
1462 netif_rx(skb);
1463 } 1006 }
1464 } 1007 }
1465 1008
@@ -1468,49 +1011,12 @@ static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx)
1468 pr_debug(" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X]\n", 1011 pr_debug(" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X]\n",
1469 (int)uIdx, byTsr1, byTsr0); 1012 (int)uIdx, byTsr1, byTsr0);
1470 } 1013 }
1471
1472
1473 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
1474 (pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)) {
1475 unsigned short wAID;
1476 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1477
1478 skb = pTD->pTDInfo->skb;
1479 if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data), &uNodeIndex)) {
1480 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1481 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1482 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1483 // set tx map
1484 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1485 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1486 pTD->pTDInfo->byFlags &= ~(TD_FLAGS_NETIF_SKB);
1487 pr_debug("tx_srv:tx fail re-queue sta index= %d, QueCnt= %d\n",
1488 (int)uNodeIndex,
1489 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt);
1490 pStats->tx_errors--;
1491 pStats->tx_dropped--;
1492 }
1493 }
1494 }
1495 } 1014 }
1496 device_free_tx_buf(pDevice, pTD); 1015 device_free_tx_buf(pDevice, pTD);
1497 pDevice->iTDUsed[uIdx]--; 1016 pDevice->iTDUsed[uIdx]--;
1498 } 1017 }
1499 } 1018 }
1500 1019
1501 if (uIdx == TYPE_AC0DMA) {
1502 // RESERV_AC0DMA reserved for relay
1503
1504 if (AVAIL_TD(pDevice, uIdx) < RESERV_AC0DMA) {
1505 bFull = true;
1506 pr_debug(" AC0DMA is Full = %d\n",
1507 pDevice->iTDUsed[uIdx]);
1508 }
1509 if (netif_queue_stopped(pDevice->dev) && !bFull)
1510 netif_wake_queue(pDevice->dev);
1511
1512 }
1513
1514 pDevice->apTailTD[uIdx] = pTD; 1020 pDevice->apTailTD[uIdx] = pTD;
1515 1021
1516 return works; 1022 return works;
@@ -1521,10 +1027,6 @@ static void device_error(struct vnt_private *pDevice, unsigned short status)
1521 if (status & ISR_FETALERR) { 1027 if (status & ISR_FETALERR) {
1522 dev_err(&pDevice->pcid->dev, "Hardware fatal error\n"); 1028 dev_err(&pDevice->pcid->dev, "Hardware fatal error\n");
1523 1029
1524 netif_stop_queue(pDevice->dev);
1525 del_timer(&pDevice->sTimerCommand);
1526 del_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1527 pDevice->bCmdRunning = false;
1528 MACbShutdown(pDevice->PortOffset); 1030 MACbShutdown(pDevice->PortOffset);
1529 return; 1031 return;
1530 } 1032 }
@@ -1541,7 +1043,9 @@ static void device_free_tx_buf(struct vnt_private *pDevice, PSTxDesc pDesc)
1541 PCI_DMA_TODEVICE); 1043 PCI_DMA_TODEVICE);
1542 } 1044 }
1543 1045
1544 if ((pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) 1046 if (pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)
1047 ieee80211_tx_status_irqsafe(pDevice->hw, skb);
1048 else
1545 dev_kfree_skb_irq(skb); 1049 dev_kfree_skb_irq(skb);
1546 1050
1547 pTDInfo->skb_dma = 0; 1051 pTDInfo->skb_dma = 0;
@@ -1549,671 +1053,13 @@ static void device_free_tx_buf(struct vnt_private *pDevice, PSTxDesc pDesc)
1549 pTDInfo->byFlags = 0; 1053 pTDInfo->byFlags = 0;
1550} 1054}
1551 1055
1552static int device_open(struct net_device *dev)
1553{
1554 struct vnt_private *pDevice = netdev_priv(dev);
1555 int i;
1556#ifdef WPA_SM_Transtatus
1557 extern SWPAResult wpa_Result;
1558#endif
1559
1560 pDevice->rx_buf_sz = PKT_BUF_SZ;
1561 if (!device_init_rings(pDevice))
1562 return -ENOMEM;
1563
1564//2008-5-13 <add> by chester
1565 i = request_irq(pDevice->pcid->irq, &device_intr, IRQF_SHARED, dev->name, dev);
1566 if (i)
1567 return i;
1568
1569#ifdef WPA_SM_Transtatus
1570 memset(wpa_Result.ifname, 0, sizeof(wpa_Result.ifname));
1571 wpa_Result.proto = 0;
1572 wpa_Result.key_mgmt = 0;
1573 wpa_Result.eap_type = 0;
1574 wpa_Result.authenticated = false;
1575 pDevice->fWPA_Authened = false;
1576#endif
1577 pr_debug("call device init rd0 ring\n");
1578 device_init_rd0_ring(pDevice);
1579 device_init_rd1_ring(pDevice);
1580 device_init_defrag_cb(pDevice);
1581 device_init_td0_ring(pDevice);
1582 device_init_td1_ring(pDevice);
1583
1584 if (pDevice->bDiversityRegCtlON)
1585 device_init_diversity_timer(pDevice);
1586
1587 vMgrObjectInit(pDevice);
1588 vMgrTimerInit(pDevice);
1589
1590 pr_debug("call device_init_registers\n");
1591 device_init_registers(pDevice);
1592
1593 MACvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
1594 memcpy(pDevice->pMgmt->abyMACAddr, pDevice->abyCurrentNetAddr, ETH_ALEN);
1595 device_set_multi(pDevice->dev);
1596
1597 // Init for Key Management
1598 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
1599 add_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1600
1601#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1602 pDevice->bwextcount = 0;
1603 pDevice->bWPASuppWextEnabled = false;
1604#endif
1605 pDevice->byReAssocCount = 0;
1606 pDevice->bWPADEVUp = false;
1607 // Patch: if WEP key already set by iwconfig but device not yet open
1608 if (pDevice->bEncryptionEnable && pDevice->bTransmitKey) {
1609 KeybSetDefaultKey(&(pDevice->sKey),
1610 (unsigned long)(pDevice->byKeyIndex | (1 << 31)),
1611 pDevice->uKeyLength,
1612 NULL,
1613 pDevice->abyKey,
1614 KEY_CTL_WEP,
1615 pDevice->PortOffset,
1616 pDevice->byLocalID
1617 );
1618 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1619 }
1620
1621 pr_debug("call MACvIntEnable\n");
1622 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
1623
1624 if (pDevice->pMgmt->eConfigMode == WMAC_CONFIG_AP) {
1625 bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
1626 } else {
1627 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1628 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
1629 }
1630 pDevice->flags |= DEVICE_FLAGS_OPENED;
1631
1632 pr_debug("device_open success..\n");
1633 return 0;
1634}
1635
1636static int device_close(struct net_device *dev)
1637{
1638 struct vnt_private *pDevice = netdev_priv(dev);
1639 PSMgmtObject pMgmt = pDevice->pMgmt;
1640//2007-1121-02<Add>by EinsnLiu
1641 if (pDevice->bLinkPass) {
1642 bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
1643 mdelay(30);
1644 }
1645
1646 del_timer(&pDevice->sTimerTxData);
1647 del_timer(&pDevice->sTimerCommand);
1648 del_timer(&pMgmt->sTimerSecondCallback);
1649 if (pDevice->bDiversityRegCtlON) {
1650 del_timer(&pDevice->TimerSQ3Tmax1);
1651 del_timer(&pDevice->TimerSQ3Tmax2);
1652 del_timer(&pDevice->TimerSQ3Tmax3);
1653 }
1654
1655 netif_stop_queue(dev);
1656 pDevice->bCmdRunning = false;
1657 MACbShutdown(pDevice->PortOffset);
1658 MACbSoftwareReset(pDevice->PortOffset);
1659 CARDbRadioPowerOff(pDevice);
1660
1661 pDevice->bLinkPass = false;
1662 memset(pMgmt->abyCurrBSSID, 0, 6);
1663 pMgmt->eCurrState = WMAC_STATE_IDLE;
1664 device_free_td0_ring(pDevice);
1665 device_free_td1_ring(pDevice);
1666 device_free_rd0_ring(pDevice);
1667 device_free_rd1_ring(pDevice);
1668 device_free_frag_buf(pDevice);
1669 device_free_rings(pDevice);
1670 BSSvClearNodeDBTable(pDevice, 0);
1671 free_irq(dev->irq, dev);
1672 pDevice->flags &= (~DEVICE_FLAGS_OPENED);
1673 //2008-0714-01<Add>by chester
1674 device_release_WPADEV(pDevice);
1675
1676 pr_debug("device_close..\n");
1677 return 0;
1678}
1679
1680static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev)
1681{
1682 struct vnt_private *pDevice = netdev_priv(dev);
1683 unsigned char *pbMPDU;
1684 unsigned int cbMPDULen = 0;
1685
1686 pr_debug("device_dma0_tx_80211\n");
1687 spin_lock_irq(&pDevice->lock);
1688
1689 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
1690 pr_debug("device_dma0_tx_80211, td0 <=0\n");
1691 dev_kfree_skb_irq(skb);
1692 spin_unlock_irq(&pDevice->lock);
1693 return 0;
1694 }
1695
1696 if (pDevice->bStopTx0Pkt) {
1697 dev_kfree_skb_irq(skb);
1698 spin_unlock_irq(&pDevice->lock);
1699 return 0;
1700 }
1701
1702 cbMPDULen = skb->len;
1703 pbMPDU = skb->data;
1704
1705 vDMA0_tx_80211(pDevice, skb, pbMPDU, cbMPDULen);
1706
1707 spin_unlock_irq(&pDevice->lock);
1708
1709 return 0;
1710}
1711
1712bool device_dma0_xmit(struct vnt_private *pDevice,
1713 struct sk_buff *skb, unsigned int uNodeIndex)
1714{
1715 PSMgmtObject pMgmt = pDevice->pMgmt;
1716 PSTxDesc pHeadTD, pLastTD;
1717 unsigned int cbFrameBodySize;
1718 unsigned int uMACfragNum;
1719 unsigned char byPktType;
1720 bool bNeedEncryption = false;
1721 PSKeyItem pTransmitKey = NULL;
1722 unsigned int cbHeaderSize;
1723 unsigned int ii;
1724 SKeyItem STempKey;
1725
1726 if (pDevice->bStopTx0Pkt) {
1727 dev_kfree_skb_irq(skb);
1728 return false;
1729 }
1730
1731 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
1732 dev_kfree_skb_irq(skb);
1733 pr_debug("device_dma0_xmit, td0 <=0\n");
1734 return false;
1735 }
1736
1737 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1738 if (pDevice->uAssocCount == 0) {
1739 dev_kfree_skb_irq(skb);
1740 pr_debug("device_dma0_xmit, assocCount = 0\n");
1741 return false;
1742 }
1743 }
1744
1745 pHeadTD = pDevice->apCurrTD[TYPE_TXDMA0];
1746
1747 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
1748
1749 memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)(skb->data), ETH_HLEN);
1750 cbFrameBodySize = skb->len - ETH_HLEN;
1751
1752 // 802.1H
1753 if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN)
1754 cbFrameBodySize += 8;
1755
1756 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
1757
1758 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_TXDMA0)) {
1759 dev_kfree_skb_irq(skb);
1760 return false;
1761 }
1762 byPktType = (unsigned char)pDevice->byPacketType;
1763
1764 if (pDevice->bFixRate) {
1765 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
1766 if (pDevice->uConnectionRate >= RATE_11M)
1767 pDevice->wCurrentRate = RATE_11M;
1768 else
1769 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
1770 } else {
1771 if (pDevice->uConnectionRate >= RATE_54M)
1772 pDevice->wCurrentRate = RATE_54M;
1773 else
1774 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
1775 }
1776 } else {
1777 pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
1778 }
1779
1780 //preamble type
1781 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble)
1782 pDevice->byPreambleType = pDevice->byShortPreamble;
1783 else
1784 pDevice->byPreambleType = PREAMBLE_LONG;
1785
1786 pr_debug("dma0: pDevice->wCurrentRate = %d\n", pDevice->wCurrentRate);
1787
1788 if (pDevice->wCurrentRate <= RATE_11M) {
1789 byPktType = PK_TYPE_11B;
1790 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
1791 byPktType = PK_TYPE_11A;
1792 } else {
1793 if (pDevice->bProtectMode)
1794 byPktType = PK_TYPE_11GB;
1795 else
1796 byPktType = PK_TYPE_11GA;
1797 }
1798
1799 if (pDevice->bEncryptionEnable)
1800 bNeedEncryption = true;
1801
1802 if (pDevice->bEnableHostWEP) {
1803 pTransmitKey = &STempKey;
1804 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1805 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1806 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
1807 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
1808 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
1809 memcpy(pTransmitKey->abyKey,
1810 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
1811 pTransmitKey->uKeyLength
1812 );
1813 }
1814 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
1815 cbFrameBodySize, TYPE_TXDMA0, pHeadTD,
1816 &pDevice->sTxEthHeader, (unsigned char *)skb->data, pTransmitKey, uNodeIndex,
1817 &uMACfragNum,
1818 &cbHeaderSize
1819 );
1820
1821 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
1822 // Disable PS
1823 MACbPSWakeup(pDevice->PortOffset);
1824 }
1825
1826 pDevice->bPWBitOn = false;
1827
1828 pLastTD = pHeadTD;
1829 for (ii = 0; ii < uMACfragNum; ii++) {
1830 // Poll Transmit the adapter
1831 wmb();
1832 pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
1833 wmb();
1834 if (ii == (uMACfragNum - 1))
1835 pLastTD = pHeadTD;
1836 pHeadTD = pHeadTD->next;
1837 }
1838
1839 // Save the information needed by the tx interrupt handler
1840 // to complete the Send request
1841 pLastTD->pTDInfo->skb = skb;
1842 pLastTD->pTDInfo->byFlags = 0;
1843 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
1844
1845 pDevice->apCurrTD[TYPE_TXDMA0] = pHeadTD;
1846
1847 MACvTransmit0(pDevice->PortOffset);
1848
1849 return true;
1850}
1851
1852//TYPE_AC0DMA data tx
1853static int device_xmit(struct sk_buff *skb, struct net_device *dev) {
1854 struct vnt_private *pDevice = netdev_priv(dev);
1855 PSMgmtObject pMgmt = pDevice->pMgmt;
1856 PSTxDesc pHeadTD, pLastTD;
1857 unsigned int uNodeIndex = 0;
1858 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1859 unsigned short wAID;
1860 unsigned int uMACfragNum = 1;
1861 unsigned int cbFrameBodySize;
1862 unsigned char byPktType;
1863 unsigned int cbHeaderSize;
1864 bool bNeedEncryption = false;
1865 PSKeyItem pTransmitKey = NULL;
1866 SKeyItem STempKey;
1867 unsigned int ii;
1868 bool bTKIP_UseGTK = false;
1869 bool bNeedDeAuth = false;
1870 unsigned char *pbyBSSID;
1871 bool bNodeExist = false;
1872
1873 spin_lock_irq(&pDevice->lock);
1874 if (!pDevice->bLinkPass) {
1875 dev_kfree_skb_irq(skb);
1876 spin_unlock_irq(&pDevice->lock);
1877 return 0;
1878 }
1879
1880 if (pDevice->bStopDataPkt) {
1881 dev_kfree_skb_irq(skb);
1882 spin_unlock_irq(&pDevice->lock);
1883 return 0;
1884 }
1885
1886 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1887 if (pDevice->uAssocCount == 0) {
1888 dev_kfree_skb_irq(skb);
1889 spin_unlock_irq(&pDevice->lock);
1890 return 0;
1891 }
1892 if (is_multicast_ether_addr((unsigned char *)(skb->data))) {
1893 uNodeIndex = 0;
1894 bNodeExist = true;
1895 if (pMgmt->sNodeDBTable[0].bPSEnable) {
1896 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
1897 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
1898 // set tx map
1899 pMgmt->abyPSTxMap[0] |= byMask[0];
1900 spin_unlock_irq(&pDevice->lock);
1901 return 0;
1902 }
1903 } else {
1904 if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data), &uNodeIndex)) {
1905 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1906 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1907 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1908 // set tx map
1909 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1910 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1911 pr_debug("Set:pMgmt->abyPSTxMap[%d]= %d\n",
1912 (wAID >> 3),
1913 pMgmt->abyPSTxMap[wAID >> 3]);
1914 spin_unlock_irq(&pDevice->lock);
1915 return 0;
1916 }
1917
1918 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble)
1919 pDevice->byPreambleType = pDevice->byShortPreamble;
1920 else
1921 pDevice->byPreambleType = PREAMBLE_LONG;
1922
1923 bNodeExist = true;
1924
1925 }
1926 }
1927
1928 if (!bNodeExist) {
1929 pr_debug("Unknown STA not found in node DB\n");
1930 dev_kfree_skb_irq(skb);
1931 spin_unlock_irq(&pDevice->lock);
1932 return 0;
1933 }
1934 }
1935
1936 pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
1937
1938 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
1939
1940 memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)(skb->data), ETH_HLEN);
1941 cbFrameBodySize = skb->len - ETH_HLEN;
1942 // 802.1H
1943 if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN)
1944 cbFrameBodySize += 8;
1945
1946 if (pDevice->bEncryptionEnable) {
1947 bNeedEncryption = true;
1948 // get Transmit key
1949 do {
1950 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
1951 (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
1952 pbyBSSID = pDevice->abyBSSID;
1953 // get pairwise key
1954 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
1955 // get group key
1956 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
1957 bTKIP_UseGTK = true;
1958 pr_debug("Get GTK\n");
1959 break;
1960 }
1961 } else {
1962 pr_debug("Get PTK\n");
1963 break;
1964 }
1965 } else if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1966 pbyBSSID = pDevice->sTxEthHeader.abyDstAddr; //TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1
1967 pr_debug("IBSS Serach Key:\n");
1968 for (ii = 0; ii < 6; ii++)
1969 pr_debug("%x\n", *(pbyBSSID+ii));
1970 pr_debug("\n");
1971
1972 // get pairwise key
1973 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
1974 break;
1975 }
1976 // get group key
1977 pbyBSSID = pDevice->abyBroadcastAddr;
1978 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
1979 pTransmitKey = NULL;
1980 if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)
1981 pr_debug("IBSS and KEY is NULL. [%d]\n",
1982 pDevice->pMgmt->eCurrMode);
1983 else
1984 pr_debug("NOT IBSS and KEY is NULL. [%d]\n",
1985 pDevice->pMgmt->eCurrMode);
1986 } else {
1987 bTKIP_UseGTK = true;
1988 pr_debug("Get GTK\n");
1989 }
1990 } while (false);
1991 }
1992
1993 if (pDevice->bEnableHostWEP) {
1994 pr_debug("acdma0: STA index %d\n", uNodeIndex);
1995 if (pDevice->bEncryptionEnable) {
1996 pTransmitKey = &STempKey;
1997 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1998 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1999 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2000 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2001 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2002 memcpy(pTransmitKey->abyKey,
2003 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2004 pTransmitKey->uKeyLength
2005 );
2006 }
2007 }
2008
2009 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
2010
2011 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_AC0DMA)) {
2012 pr_debug("uMACfragNum > AVAIL_TD(TYPE_AC0DMA) = %d\n",
2013 uMACfragNum);
2014 dev_kfree_skb_irq(skb);
2015 spin_unlock_irq(&pDevice->lock);
2016 return 0;
2017 }
2018
2019 if (pTransmitKey != NULL) {
2020 if ((pTransmitKey->byCipherSuite == KEY_CTL_WEP) &&
2021 (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN)) {
2022 uMACfragNum = 1; //WEP256 doesn't support fragment
2023 }
2024 }
2025
2026 byPktType = (unsigned char)pDevice->byPacketType;
2027
2028 if (pDevice->bFixRate) {
2029 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
2030 if (pDevice->uConnectionRate >= RATE_11M)
2031 pDevice->wCurrentRate = RATE_11M;
2032 else
2033 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
2034 } else {
2035 if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
2036 (pDevice->uConnectionRate <= RATE_6M)) {
2037 pDevice->wCurrentRate = RATE_6M;
2038 } else {
2039 if (pDevice->uConnectionRate >= RATE_54M)
2040 pDevice->wCurrentRate = RATE_54M;
2041 else
2042 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
2043
2044 }
2045 }
2046 pDevice->byACKRate = (unsigned char) pDevice->wCurrentRate;
2047 pDevice->byTopCCKBasicRate = RATE_1M;
2048 pDevice->byTopOFDMBasicRate = RATE_6M;
2049 } else {
2050 //auto rate
2051 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2052 if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
2053 pDevice->wCurrentRate = RATE_1M;
2054 pDevice->byACKRate = RATE_1M;
2055 pDevice->byTopCCKBasicRate = RATE_1M;
2056 pDevice->byTopOFDMBasicRate = RATE_6M;
2057 } else {
2058 pDevice->wCurrentRate = RATE_6M;
2059 pDevice->byACKRate = RATE_6M;
2060 pDevice->byTopCCKBasicRate = RATE_1M;
2061 pDevice->byTopOFDMBasicRate = RATE_6M;
2062 }
2063 } else {
2064 VNTWIFIvGetTxRate(pDevice->pMgmt,
2065 pDevice->sTxEthHeader.abyDstAddr,
2066 &(pDevice->wCurrentRate),
2067 &(pDevice->byACKRate),
2068 &(pDevice->byTopCCKBasicRate),
2069 &(pDevice->byTopOFDMBasicRate));
2070
2071 }
2072 }
2073
2074
2075 if (pDevice->wCurrentRate <= RATE_11M) {
2076 byPktType = PK_TYPE_11B;
2077 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2078 byPktType = PK_TYPE_11A;
2079 } else {
2080 if (pDevice->bProtectMode)
2081 byPktType = PK_TYPE_11GB;
2082 else
2083 byPktType = PK_TYPE_11GA;
2084 }
2085
2086 if (bNeedEncryption) {
2087 pr_debug("ntohs Pkt Type=%04x\n",
2088 ntohs(pDevice->sTxEthHeader.wType));
2089 if ((pDevice->sTxEthHeader.wType) == TYPE_PKT_802_1x) {
2090 bNeedEncryption = false;
2091 pr_debug("Pkt Type=%04x\n",
2092 (pDevice->sTxEthHeader.wType));
2093 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2094 if (pTransmitKey == NULL) {
2095 pr_debug("Don't Find TX KEY\n");
2096 } else {
2097 if (bTKIP_UseGTK) {
2098 pr_debug("error: KEY is GTK!!~~\n");
2099 } else {
2100 pr_debug("Find PTK [%lX]\n",
2101 pTransmitKey->dwKeyIndex);
2102 bNeedEncryption = true;
2103 }
2104 }
2105 }
2106
2107 if (pDevice->byCntMeasure == 2) {
2108 bNeedDeAuth = true;
2109 pDevice->s802_11Counter.TKIPCounterMeasuresInvoked++;
2110 }
2111
2112 if (pDevice->bEnableHostWEP) {
2113 if ((uNodeIndex != 0) &&
2114 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
2115 pr_debug("Find PTK [%lX]\n",
2116 pTransmitKey->dwKeyIndex);
2117 bNeedEncryption = true;
2118 }
2119 }
2120 } else {
2121 if (pTransmitKey == NULL) {
2122 pr_debug("return no tx key\n");
2123 dev_kfree_skb_irq(skb);
2124 spin_unlock_irq(&pDevice->lock);
2125 return 0;
2126 }
2127 }
2128 }
2129
2130 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
2131 cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
2132 &pDevice->sTxEthHeader, (unsigned char *)skb->data, pTransmitKey, uNodeIndex,
2133 &uMACfragNum,
2134 &cbHeaderSize
2135 );
2136
2137 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2138 // Disable PS
2139 MACbPSWakeup(pDevice->PortOffset);
2140 }
2141 pDevice->bPWBitOn = false;
2142
2143 pLastTD = pHeadTD;
2144 for (ii = 0; ii < uMACfragNum; ii++) {
2145 // Poll Transmit the adapter
2146 wmb();
2147 pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
2148 wmb();
2149 if (ii == uMACfragNum - 1)
2150 pLastTD = pHeadTD;
2151 pHeadTD = pHeadTD->next;
2152 }
2153
2154 // Save the information needed by the tx interrupt handler
2155 // to complete the Send request
2156 pLastTD->pTDInfo->skb = skb;
2157 pLastTD->pTDInfo->byFlags = 0;
2158 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
2159 pDevice->nTxDataTimeCout = 0; //2008-8-21 chester <add> for send null packet
2160
2161 if (AVAIL_TD(pDevice, TYPE_AC0DMA) <= 1)
2162 netif_stop_queue(dev);
2163
2164 pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
2165
2166 if (pDevice->bFixRate)
2167 pr_debug("FixRate:Rate is %d,TxPower is %d\n", pDevice->wCurrentRate, pDevice->byCurPwr);
2168
2169 {
2170 unsigned char Protocol_Version; //802.1x Authentication
2171 unsigned char Packet_Type; //802.1x Authentication
2172 unsigned char Descriptor_type;
2173 unsigned short Key_info;
2174 bool bTxeapol_key = false;
2175
2176 Protocol_Version = skb->data[ETH_HLEN];
2177 Packet_Type = skb->data[ETH_HLEN+1];
2178 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2179 Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]);
2180 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2181 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2182 (Packet_Type == 3)) { //802.1x OR eapol-key challenge frame transfer
2183 bTxeapol_key = true;
2184 if ((Descriptor_type == 254) || (Descriptor_type == 2)) { //WPA or RSN
2185 if (!(Key_info & BIT3) && //group-key challenge
2186 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2187 pDevice->fWPA_Authened = true;
2188 if (Descriptor_type == 254)
2189 pr_debug("WPA ");
2190 else
2191 pr_debug("WPA2 ");
2192 pr_debug("Authentication completed!!\n");
2193 }
2194 }
2195 }
2196 }
2197 }
2198
2199 MACvTransmitAC0(pDevice->PortOffset);
2200
2201 dev->trans_start = jiffies;
2202
2203 spin_unlock_irq(&pDevice->lock);
2204 return 0;
2205}
2206
2207static irqreturn_t device_intr(int irq, void *dev_instance) 1056static irqreturn_t device_intr(int irq, void *dev_instance)
2208{ 1057{
2209 struct net_device *dev = dev_instance; 1058 struct vnt_private *pDevice = dev_instance;
2210 struct vnt_private *pDevice = netdev_priv(dev);
2211 int max_count = 0; 1059 int max_count = 0;
2212 unsigned long dwMIBCounter = 0; 1060 unsigned long dwMIBCounter = 0;
2213 PSMgmtObject pMgmt = pDevice->pMgmt;
2214 unsigned char byOrgPageSel = 0; 1061 unsigned char byOrgPageSel = 0;
2215 int handled = 0; 1062 int handled = 0;
2216 unsigned char byData = 0;
2217 int ii = 0; 1063 int ii = 0;
2218 unsigned long flags; 1064 unsigned long flags;
2219 1065
@@ -2256,96 +1102,13 @@ static irqreturn_t device_intr(int irq, void *dev_instance)
2256 device_error(pDevice, pDevice->dwIsr); 1102 device_error(pDevice, pDevice->dwIsr);
2257 } 1103 }
2258 1104
2259 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
2260 if (pDevice->dwIsr & ISR_MEASURESTART) {
2261 // 802.11h measure start
2262 pDevice->byOrgChannel = pDevice->byCurrentCh;
2263 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byOrgRCR));
2264 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, (RCR_RXALLTYPE | RCR_UNICAST | RCR_BROADCAST | RCR_MULTICAST | RCR_WPAERR));
2265 MACvSelectPage1(pDevice->PortOffset);
2266 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR0, &(pDevice->dwOrgMAR0));
2267 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR4, &(pDevice->dwOrgMAR4));
2268 MACvSelectPage0(pDevice->PortOffset);
2269 //xxxx
2270 if (set_channel(pDevice, pDevice->pCurrMeasureEID->sReq.byChannel)) {
2271 pDevice->bMeasureInProgress = true;
2272 MACvSelectPage1(pDevice->PortOffset);
2273 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_READY);
2274 MACvSelectPage0(pDevice->PortOffset);
2275 pDevice->byBasicMap = 0;
2276 pDevice->byCCAFraction = 0;
2277 for (ii = 0; ii < 8; ii++)
2278 pDevice->dwRPIs[ii] = 0;
2279
2280 } else {
2281 // can not measure because set channel fail
2282 // clear measure control
2283 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2284 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_INCAPABLE);
2285 MACvSelectPage1(pDevice->PortOffset);
2286 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2287 MACvSelectPage0(pDevice->PortOffset);
2288 }
2289 }
2290 if (pDevice->dwIsr & ISR_MEASUREEND) {
2291 // 802.11h measure end
2292 pDevice->bMeasureInProgress = false;
2293 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
2294 MACvSelectPage1(pDevice->PortOffset);
2295 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
2296 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
2297 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRBBSTS, &byData);
2298 pDevice->byBasicMap |= (byData >> 4);
2299 VNSvInPortB(pDevice->PortOffset + MAC_REG_CCAFRACTION, &pDevice->byCCAFraction);
2300 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRCTL, &byData);
2301 // clear measure control
2302 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2303 MACvSelectPage0(pDevice->PortOffset);
2304 set_channel(pDevice, pDevice->byOrgChannel);
2305 MACvSelectPage1(pDevice->PortOffset);
2306 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2307 MACvSelectPage0(pDevice->PortOffset);
2308 if (byData & MSRCTL_FINISH) {
2309 // measure success
2310 s_vCompleteCurrentMeasure(pDevice, 0);
2311 } else {
2312 // can not measure because not ready before end of measure time
2313 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_LATE);
2314 }
2315 }
2316 if (pDevice->dwIsr & ISR_QUIETSTART) {
2317 do {
2318 ;
2319 } while (!CARDbStartQuiet(pDevice));
2320 }
2321 }
2322
2323 if (pDevice->dwIsr & ISR_TBTT) { 1105 if (pDevice->dwIsr & ISR_TBTT) {
2324 if (pDevice->bEnableFirstQuiet) { 1106 if (pDevice->vif &&
2325 pDevice->byQuietStartCount--; 1107 pDevice->op_mode != NL80211_IFTYPE_ADHOC) {
2326 if (pDevice->byQuietStartCount == 0) { 1108 if (pDevice->bUpdateBBVGA &&
2327 pDevice->bEnableFirstQuiet = false; 1109 !(pDevice->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) &&
2328 MACvSelectPage1(pDevice->PortOffset); 1110 pDevice->vif->bss_conf.assoc &&
2329 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN)); 1111 pDevice->uCurrRSSI) {
2330 MACvSelectPage0(pDevice->PortOffset);
2331 }
2332 }
2333 if (pDevice->bChannelSwitch &&
2334 (pDevice->op_mode == NL80211_IFTYPE_STATION)) {
2335 pDevice->byChannelSwitchCount--;
2336 if (pDevice->byChannelSwitchCount == 0) {
2337 pDevice->bChannelSwitch = false;
2338 set_channel(pDevice, pDevice->byNewChannel);
2339 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2340 MACvSelectPage1(pDevice->PortOffset);
2341 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2342 MACvSelectPage0(pDevice->PortOffset);
2343 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2344
2345 }
2346 }
2347 if (pDevice->op_mode != NL80211_IFTYPE_ADHOC) {
2348 if ((pDevice->bUpdateBBVGA) && pDevice->bLinkPass && (pDevice->uCurrRSSI != 0)) {
2349 long ldBm; 1112 long ldBm;
2350 1113
2351 RFvRSSITodBm(pDevice, (unsigned char) pDevice->uCurrRSSI, &ldBm); 1114 RFvRSSITodBm(pDevice, (unsigned char) pDevice->uCurrRSSI, &ldBm);
@@ -2384,10 +1147,11 @@ static irqreturn_t device_intr(int irq, void *dev_instance)
2384 if (pDevice->bEnablePSMode) 1147 if (pDevice->bEnablePSMode)
2385 PSbIsNextTBTTWakeUp((void *)pDevice); 1148 PSbIsNextTBTTWakeUp((void *)pDevice);
2386 1149
2387 if ((pDevice->op_mode == NL80211_IFTYPE_AP) || 1150 if ((pDevice->op_mode == NL80211_IFTYPE_AP ||
2388 (pDevice->op_mode == NL80211_IFTYPE_ADHOC)) { 1151 pDevice->op_mode == NL80211_IFTYPE_ADHOC) &&
1152 pDevice->vif->bss_conf.enable_beacon) {
2389 MACvOneShotTimer1MicroSec(pDevice->PortOffset, 1153 MACvOneShotTimer1MicroSec(pDevice->PortOffset,
2390 (pMgmt->wIBSSBeaconPeriod - MAKE_BEACON_RESERVED) << 10); 1154 (pDevice->vif->bss_conf.beacon_int - MAKE_BEACON_RESERVED) << 10);
2391 } 1155 }
2392 1156
2393 /* TODO: adhoc PS mode */ 1157 /* TODO: adhoc PS mode */
@@ -2400,34 +1164,7 @@ static irqreturn_t device_intr(int irq, void *dev_instance)
2400 pDevice->cbBeaconBufReadySetCnt = 0; 1164 pDevice->cbBeaconBufReadySetCnt = 0;
2401 } 1165 }
2402 1166
2403 if (pDevice->op_mode == NL80211_IFTYPE_AP) {
2404 if (pMgmt->byDTIMCount > 0) {
2405 pMgmt->byDTIMCount--;
2406 pMgmt->sNodeDBTable[0].bRxPSPoll = false;
2407 } else {
2408 if (pMgmt->byDTIMCount == 0) {
2409 // check if mutltcast tx bufferring
2410 pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
2411 pMgmt->sNodeDBTable[0].bRxPSPoll = true;
2412 bScheduleCommand((void *)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
2413 }
2414 }
2415 }
2416 pDevice->bBeaconSent = true; 1167 pDevice->bBeaconSent = true;
2417
2418 if (pDevice->bChannelSwitch) {
2419 pDevice->byChannelSwitchCount--;
2420 if (pDevice->byChannelSwitchCount == 0) {
2421 pDevice->bChannelSwitch = false;
2422 set_channel(pDevice, pDevice->byNewChannel);
2423 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2424 MACvSelectPage1(pDevice->PortOffset);
2425 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2426 MACvSelectPage0(pDevice->PortOffset);
2427 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2428 }
2429 }
2430
2431 } 1168 }
2432 1169
2433 if (pDevice->dwIsr & ISR_RXDMA0) 1170 if (pDevice->dwIsr & ISR_RXDMA0)
@@ -2443,14 +1180,18 @@ static irqreturn_t device_intr(int irq, void *dev_instance)
2443 max_count += device_tx_srv(pDevice, TYPE_AC0DMA); 1180 max_count += device_tx_srv(pDevice, TYPE_AC0DMA);
2444 1181
2445 if (pDevice->dwIsr & ISR_SOFTTIMER1) { 1182 if (pDevice->dwIsr & ISR_SOFTTIMER1) {
2446 if (pDevice->op_mode == NL80211_IFTYPE_AP) { 1183 if (pDevice->vif) {
2447 if (pDevice->bShortSlotTime) 1184 if (pDevice->vif->bss_conf.enable_beacon)
2448 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1); 1185 vnt_beacon_make(pDevice, pDevice->vif);
2449 else
2450 pMgmt->wCurrCapInfo &= ~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1));
2451 } 1186 }
2452 bMgrPrepareBeaconToSend(pDevice, pMgmt); 1187 }
2453 pDevice->byCntMeasure = 0; 1188
1189 /* If both buffers available wake the queue */
1190 if (pDevice->vif) {
1191 if (AVAIL_TD(pDevice, TYPE_TXDMA0) &&
1192 AVAIL_TD(pDevice, TYPE_AC0DMA) &&
1193 ieee80211_queue_stopped(pDevice->hw, 0))
1194 ieee80211_wake_queues(pDevice->hw);
2454 } 1195 }
2455 1196
2456 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr); 1197 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
@@ -2472,550 +1213,655 @@ static irqreturn_t device_intr(int irq, void *dev_instance)
2472 return IRQ_RETVAL(handled); 1213 return IRQ_RETVAL(handled);
2473} 1214}
2474 1215
2475//2008-8-4 <add> by chester 1216static int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
2476static int Config_FileGetParameter(unsigned char *string,
2477 unsigned char *dest, unsigned char *source)
2478{ 1217{
2479 unsigned char buf1[100]; 1218 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2480 int source_len = strlen(source); 1219 PSTxDesc head_td;
1220 u32 dma_idx = TYPE_AC0DMA;
1221 unsigned long flags;
2481 1222
2482 memset(buf1, 0, 100); 1223 spin_lock_irqsave(&priv->lock, flags);
2483 strcat(buf1, string);
2484 strcat(buf1, "=");
2485 source += strlen(buf1);
2486 1224
2487 memcpy(dest, source, source_len - strlen(buf1)); 1225 if (!ieee80211_is_data(hdr->frame_control))
2488 return true; 1226 dma_idx = TYPE_TXDMA0;
2489}
2490 1227
2491int Config_FileOperation(struct vnt_private *pDevice, 1228 if (AVAIL_TD(priv, dma_idx) < 1) {
2492 bool fwrite, unsigned char *Parameter) 1229 spin_unlock_irqrestore(&priv->lock, flags);
2493{ 1230 return -ENOMEM;
2494 unsigned char *buffer = kmalloc(1024, GFP_KERNEL);
2495 unsigned char tmpbuffer[20];
2496 struct file *file;
2497 int result = 0;
2498
2499 if (!buffer) {
2500 pr_err("allocate mem for file fail?\n");
2501 return -1;
2502 }
2503 file = filp_open(CONFIG_PATH, O_RDONLY, 0);
2504 if (IS_ERR(file)) {
2505 kfree(buffer);
2506 pr_err("Config_FileOperation:open file fail?\n");
2507 return -1;
2508 } 1231 }
2509 1232
2510 if (kernel_read(file, 0, buffer, 1024) < 0) { 1233 head_td = priv->apCurrTD[dma_idx];
2511 pr_err("read file error?\n");
2512 result = -1;
2513 goto error1;
2514 }
2515 1234
2516 if (Config_FileGetParameter("ZONETYPE", tmpbuffer, buffer) != true) { 1235 head_td->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
2517 pr_err("get parameter error?\n");
2518 result = -1;
2519 goto error1;
2520 }
2521 1236
2522 if (memcmp(tmpbuffer, "USA", 3) == 0) { 1237 head_td->pTDInfo->skb = skb;
2523 result = ZoneType_USA; 1238
2524 } else if (memcmp(tmpbuffer, "JAPAN", 5) == 0) { 1239 priv->iTDUsed[dma_idx]++;
2525 result = ZoneType_Japan; 1240
2526 } else if (memcmp(tmpbuffer, "EUROPE", 5) == 0) { 1241 /* Take ownership */
2527 result = ZoneType_Europe; 1242 wmb();
2528 } else { 1243 head_td->m_td0TD0.f1Owner = OWNED_BY_NIC;
2529 result = -1; 1244
2530 pr_err("Unknown Zonetype[%s]?\n", tmpbuffer); 1245 /* get Next */
2531 } 1246 wmb();
1247 priv->apCurrTD[dma_idx] = head_td->next;
1248
1249 spin_unlock_irqrestore(&priv->lock, flags);
1250
1251 vnt_generate_fifo_header(priv, dma_idx, head_td, skb);
1252
1253 if (MACbIsRegBitsOn(priv->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
1254 MACbPSWakeup(priv->PortOffset);
1255
1256 spin_lock_irqsave(&priv->lock, flags);
2532 1257
2533error1: 1258 priv->bPWBitOn = false;
2534 kfree(buffer); 1259
2535 fput(file); 1260 head_td->pTDInfo->byFlags = TD_FLAGS_NETIF_SKB;
2536 return result; 1261
1262 if (dma_idx == TYPE_AC0DMA)
1263 MACvTransmitAC0(priv->PortOffset);
1264 else
1265 MACvTransmit0(priv->PortOffset);
1266
1267 spin_unlock_irqrestore(&priv->lock, flags);
1268
1269 return 0;
2537} 1270}
2538 1271
2539static void device_set_multi(struct net_device *dev) { 1272static void vnt_tx_80211(struct ieee80211_hw *hw,
2540 struct vnt_private *pDevice = netdev_priv(dev); 1273 struct ieee80211_tx_control *control,
2541 PSMgmtObject pMgmt = pDevice->pMgmt; 1274 struct sk_buff *skb)
2542 u32 mc_filter[2]; 1275{
2543 struct netdev_hw_addr *ha; 1276 struct vnt_private *priv = hw->priv;
2544 1277
2545 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byRxMode)); 1278 ieee80211_stop_queues(hw);
2546 1279
2547 if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */ 1280 if (vnt_tx_packet(priv, skb)) {
2548 pr_notice("%s: Promiscuous mode enabled\n", dev->name); 1281 ieee80211_free_txskb(hw, skb);
2549 /* Unconditionally log net taps. */
2550 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
2551 } else if ((netdev_mc_count(dev) > pDevice->multicast_limit)
2552 || (dev->flags & IFF_ALLMULTI)) {
2553 MACvSelectPage1(pDevice->PortOffset);
2554 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, 0xffffffff);
2555 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, 0xffffffff);
2556 MACvSelectPage0(pDevice->PortOffset);
2557 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2558 } else {
2559 memset(mc_filter, 0, sizeof(mc_filter));
2560 netdev_for_each_mc_addr(ha, dev) {
2561 int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
2562 1282
2563 mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31)); 1283 ieee80211_wake_queues(hw);
2564 }
2565 MACvSelectPage1(pDevice->PortOffset);
2566 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, mc_filter[0]);
2567 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, mc_filter[1]);
2568 MACvSelectPage0(pDevice->PortOffset);
2569 pDevice->byRxMode &= ~(RCR_UNICAST);
2570 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2571 } 1284 }
1285}
1286
1287static int vnt_start(struct ieee80211_hw *hw)
1288{
1289 struct vnt_private *priv = hw->priv;
1290 int ret;
2572 1291
2573 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) { 1292 priv->rx_buf_sz = PKT_BUF_SZ;
2574 // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac. 1293 if (!device_init_rings(priv))
2575 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST); 1294 return -ENOMEM;
2576 pDevice->byRxMode &= ~(RCR_UNICAST); 1295
1296 ret = request_irq(priv->pcid->irq, &device_intr,
1297 IRQF_SHARED, "vt6655", priv);
1298 if (ret) {
1299 dev_dbg(&priv->pcid->dev, "failed to start irq\n");
1300 return ret;
2577 } 1301 }
2578 1302
2579 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byRxMode); 1303 dev_dbg(&priv->pcid->dev, "call device init rd0 ring\n");
2580 pr_debug("pDevice->byRxMode = %x\n", pDevice->byRxMode); 1304 device_init_rd0_ring(priv);
1305 device_init_rd1_ring(priv);
1306 device_init_td0_ring(priv);
1307 device_init_td1_ring(priv);
1308
1309 device_init_registers(priv);
1310
1311 dev_dbg(&priv->pcid->dev, "call MACvIntEnable\n");
1312 MACvIntEnable(priv->PortOffset, IMR_MASK_VALUE);
1313
1314 ieee80211_wake_queues(hw);
1315
1316 return 0;
2581} 1317}
2582 1318
2583static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) 1319static void vnt_stop(struct ieee80211_hw *hw)
2584{ 1320{
2585 struct vnt_private *pDevice = netdev_priv(dev); 1321 struct vnt_private *priv = hw->priv;
2586 struct iwreq *wrq = (struct iwreq *)rq;
2587 int rc = 0;
2588 PSMgmtObject pMgmt = pDevice->pMgmt;
2589 PSCmdRequest pReq;
2590
2591 if (pMgmt == NULL) {
2592 rc = -EFAULT;
2593 return rc;
2594 }
2595 1322
2596 switch (cmd) { 1323 ieee80211_stop_queues(hw);
2597 case SIOCGIWNAME: 1324
2598 rc = iwctl_giwname(dev, NULL, (char *)&(wrq->u.name), NULL); 1325 MACbShutdown(priv->PortOffset);
2599 break; 1326 MACbSoftwareReset(priv->PortOffset);
1327 CARDbRadioPowerOff(priv);
1328
1329 device_free_td0_ring(priv);
1330 device_free_td1_ring(priv);
1331 device_free_rd0_ring(priv);
1332 device_free_rd1_ring(priv);
1333 device_free_rings(priv);
1334
1335 free_irq(priv->pcid->irq, priv);
1336}
1337
1338static int vnt_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1339{
1340 struct vnt_private *priv = hw->priv;
1341
1342 priv->vif = vif;
2600 1343
2601 case SIOCGIWNWID: //0x8b03 support 1344 switch (vif->type) {
2602 rc = -EOPNOTSUPP; 1345 case NL80211_IFTYPE_STATION:
1346 if (priv->bDiversityRegCtlON)
1347 device_init_diversity_timer(priv);
2603 break; 1348 break;
1349 case NL80211_IFTYPE_ADHOC:
1350 MACvRegBitsOff(priv->PortOffset, MAC_REG_RCR, RCR_UNICAST);
1351
1352 MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
2604 1353
2605 // Set frequency/channel
2606 case SIOCSIWFREQ:
2607 rc = iwctl_siwfreq(dev, NULL, &(wrq->u.freq), NULL);
2608 break; 1354 break;
1355 case NL80211_IFTYPE_AP:
1356 MACvRegBitsOff(priv->PortOffset, MAC_REG_RCR, RCR_UNICAST);
1357
1358 MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
2609 1359
2610 // Get frequency/channel
2611 case SIOCGIWFREQ:
2612 rc = iwctl_giwfreq(dev, NULL, &(wrq->u.freq), NULL);
2613 break; 1360 break;
1361 default:
1362 return -EOPNOTSUPP;
1363 }
2614 1364
2615 // Set desired network name (ESSID) 1365 priv->op_mode = vif->type;
2616 case SIOCSIWESSID:
2617 1366
2618 { 1367 return 0;
2619 char essid[IW_ESSID_MAX_SIZE+1]; 1368}
2620 1369
2621 if (wrq->u.essid.length > IW_ESSID_MAX_SIZE) { 1370static void vnt_remove_interface(struct ieee80211_hw *hw,
2622 rc = -E2BIG; 1371 struct ieee80211_vif *vif)
2623 break; 1372{
2624 } 1373 struct vnt_private *priv = hw->priv;
2625 if (copy_from_user(essid, wrq->u.essid.pointer, 1374
2626 wrq->u.essid.length)) { 1375 switch (vif->type) {
2627 rc = -EFAULT; 1376 case NL80211_IFTYPE_STATION:
2628 break; 1377 if (priv->bDiversityRegCtlON) {
1378 del_timer(&priv->TimerSQ3Tmax1);
1379 del_timer(&priv->TimerSQ3Tmax2);
1380 del_timer(&priv->TimerSQ3Tmax3);
2629 } 1381 }
2630 rc = iwctl_siwessid(dev, NULL, 1382 break;
2631 &(wrq->u.essid), essid); 1383 case NL80211_IFTYPE_ADHOC:
1384 MACvRegBitsOff(priv->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
1385 MACvRegBitsOff(priv->PortOffset,
1386 MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1387 MACvRegBitsOff(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
1388 break;
1389 case NL80211_IFTYPE_AP:
1390 MACvRegBitsOff(priv->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
1391 MACvRegBitsOff(priv->PortOffset,
1392 MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1393 MACvRegBitsOff(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
1394 break;
1395 default:
1396 break;
2632 } 1397 }
2633 break;
2634 1398
2635 // Get current network name (ESSID) 1399 priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
2636 case SIOCGIWESSID: 1400}
2637 1401
2638 { 1402
2639 char essid[IW_ESSID_MAX_SIZE+1]; 1403static int vnt_config(struct ieee80211_hw *hw, u32 changed)
2640 1404{
2641 if (wrq->u.essid.pointer) 1405 struct vnt_private *priv = hw->priv;
2642 rc = iwctl_giwessid(dev, NULL, 1406 struct ieee80211_conf *conf = &hw->conf;
2643 &(wrq->u.essid), essid); 1407 u8 bb_type;
2644 if (copy_to_user(wrq->u.essid.pointer, 1408
2645 essid, 1409 if (changed & IEEE80211_CONF_CHANGE_PS) {
2646 wrq->u.essid.length)) 1410 if (conf->flags & IEEE80211_CONF_PS)
2647 rc = -EFAULT; 1411 PSvEnablePowerSaving(priv, conf->listen_interval);
1412 else
1413 PSvDisablePowerSaving(priv);
2648 } 1414 }
2649 break;
2650 1415
2651 case SIOCSIWAP: 1416 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) ||
1417 (conf->flags & IEEE80211_CONF_OFFCHANNEL)) {
1418 set_channel(priv, conf->chandef.chan->hw_value);
2652 1419
2653 rc = iwctl_siwap(dev, NULL, &(wrq->u.ap_addr), NULL); 1420 if (conf->chandef.chan->band == IEEE80211_BAND_5GHZ)
2654 break; 1421 bb_type = BB_TYPE_11A;
1422 else
1423 bb_type = BB_TYPE_11G;
2655 1424
2656 // Get current Access Point (BSSID) 1425 if (priv->byBBType != bb_type) {
2657 case SIOCGIWAP: 1426 priv->byBBType = bb_type;
2658 rc = iwctl_giwap(dev, NULL, &(wrq->u.ap_addr), NULL);
2659 break;
2660 1427
2661 // Set desired station name 1428 CARDbSetPhyParameter(priv, priv->byBBType);
2662 case SIOCSIWNICKN: 1429 }
2663 pr_debug(" SIOCSIWNICKN\n"); 1430 }
2664 rc = -EOPNOTSUPP;
2665 break;
2666 1431
2667 // Get current station name 1432 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2668 case SIOCGIWNICKN: 1433 if (priv->byBBType == BB_TYPE_11B)
2669 pr_debug(" SIOCGIWNICKN\n"); 1434 priv->wCurrentRate = RATE_1M;
2670 rc = -EOPNOTSUPP; 1435 else
2671 break; 1436 priv->wCurrentRate = RATE_54M;
2672 1437
2673 // Set the desired bit-rate 1438 RFbSetPower(priv, priv->wCurrentRate,
2674 case SIOCSIWRATE: 1439 conf->chandef.chan->hw_value);
2675 rc = iwctl_siwrate(dev, NULL, &(wrq->u.bitrate), NULL); 1440 }
2676 break; 1441
1442 return 0;
1443}
2677 1444
2678 // Get the current bit-rate 1445static void vnt_bss_info_changed(struct ieee80211_hw *hw,
2679 case SIOCGIWRATE: 1446 struct ieee80211_vif *vif, struct ieee80211_bss_conf *conf,
1447 u32 changed)
1448{
1449 struct vnt_private *priv = hw->priv;
2680 1450
2681 rc = iwctl_giwrate(dev, NULL, &(wrq->u.bitrate), NULL); 1451 priv->current_aid = conf->aid;
2682 break;
2683 1452
2684 // Set the desired RTS threshold 1453 if (changed & BSS_CHANGED_BSSID)
2685 case SIOCSIWRTS: 1454 MACvWriteBSSIDAddress(priv->PortOffset, (u8 *)conf->bssid);
2686 1455
2687 rc = iwctl_siwrts(dev, NULL, &(wrq->u.rts), NULL); 1456 if (changed & BSS_CHANGED_BASIC_RATES) {
2688 break; 1457 priv->basic_rates = conf->basic_rates;
2689 1458
2690 // Get the current RTS threshold 1459 CARDvUpdateBasicTopRate(priv);
2691 case SIOCGIWRTS:
2692 1460
2693 rc = iwctl_giwrts(dev, NULL, &(wrq->u.rts), NULL); 1461 dev_dbg(&priv->pcid->dev,
2694 break; 1462 "basic rates %x\n", conf->basic_rates);
1463 }
2695 1464
2696 // Set the desired fragmentation threshold 1465 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2697 case SIOCSIWFRAG: 1466 if (conf->use_short_preamble) {
1467 MACvEnableBarkerPreambleMd(priv->PortOffset);
1468 priv->byPreambleType = true;
1469 } else {
1470 MACvDisableBarkerPreambleMd(priv->PortOffset);
1471 priv->byPreambleType = false;
1472 }
1473 }
2698 1474
2699 rc = iwctl_siwfrag(dev, NULL, &(wrq->u.frag), NULL); 1475 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2700 break; 1476 if (conf->use_cts_prot)
1477 MACvEnableProtectMD(priv->PortOffset);
1478 else
1479 MACvDisableProtectMD(priv->PortOffset);
1480 }
2701 1481
2702 // Get the current fragmentation threshold 1482 if (changed & BSS_CHANGED_ERP_SLOT) {
2703 case SIOCGIWFRAG: 1483 if (conf->use_short_slot)
1484 priv->bShortSlotTime = true;
1485 else
1486 priv->bShortSlotTime = false;
2704 1487
2705 rc = iwctl_giwfrag(dev, NULL, &(wrq->u.frag), NULL); 1488 CARDbSetPhyParameter(priv, priv->byBBType);
2706 break; 1489 BBvSetVGAGainOffset(priv, priv->abyBBVGA[0]);
1490 }
2707 1491
2708 // Set mode of operation 1492 if (changed & BSS_CHANGED_TXPOWER)
2709 case SIOCSIWMODE: 1493 RFbSetPower(priv, priv->wCurrentRate,
2710 rc = iwctl_siwmode(dev, NULL, &(wrq->u.mode), NULL); 1494 conf->chandef.chan->hw_value);
2711 break;
2712 1495
2713 // Get mode of operation 1496 if (changed & BSS_CHANGED_BEACON_ENABLED) {
2714 case SIOCGIWMODE: 1497 dev_dbg(&priv->pcid->dev,
2715 rc = iwctl_giwmode(dev, NULL, &(wrq->u.mode), NULL); 1498 "Beacon enable %d\n", conf->enable_beacon);
2716 break;
2717 1499
2718 // Set WEP keys and mode 1500 if (conf->enable_beacon) {
2719 case SIOCSIWENCODE: { 1501 vnt_beacon_enable(priv, vif, conf);
2720 char abyKey[WLAN_WEP232_KEYLEN];
2721 1502
2722 if (wrq->u.encoding.pointer) { 1503 MACvRegBitsOn(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
2723 if (wrq->u.encoding.length > WLAN_WEP232_KEYLEN) { 1504 } else {
2724 rc = -E2BIG; 1505 MACvRegBitsOff(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
2725 break;
2726 }
2727 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
2728 if (copy_from_user(abyKey,
2729 wrq->u.encoding.pointer,
2730 wrq->u.encoding.length)) {
2731 rc = -EFAULT;
2732 break;
2733 }
2734 } else if (wrq->u.encoding.length != 0) {
2735 rc = -EINVAL;
2736 break;
2737 } 1506 }
2738 rc = iwctl_siwencode(dev, NULL, &(wrq->u.encoding), abyKey);
2739 } 1507 }
2740 break;
2741 1508
2742 // Get the WEP keys and mode 1509 if (changed & BSS_CHANGED_ASSOC && priv->op_mode != NL80211_IFTYPE_AP) {
2743 case SIOCGIWENCODE: 1510 if (conf->assoc) {
1511 CARDbUpdateTSF(priv, conf->beacon_rate->hw_value,
1512 conf->sync_device_ts, conf->sync_tsf);
2744 1513
2745 if (!capable(CAP_NET_ADMIN)) { 1514 CARDbSetBeaconPeriod(priv, conf->beacon_int);
2746 rc = -EPERM; 1515
2747 break; 1516 CARDvSetFirstNextTBTT(priv, conf->beacon_int);
1517 } else {
1518 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL,
1519 TFTCTL_TSFCNTRST);
1520 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL,
1521 TFTCTL_TSFCNTREN);
2748 } 1522 }
2749 { 1523 }
2750 char abyKey[WLAN_WEP232_KEYLEN]; 1524}
2751 1525
2752 rc = iwctl_giwencode(dev, NULL, &(wrq->u.encoding), abyKey); 1526static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
2753 if (rc != 0) 1527 struct netdev_hw_addr_list *mc_list)
2754 break; 1528{
2755 if (wrq->u.encoding.pointer) { 1529 struct vnt_private *priv = hw->priv;
2756 if (copy_to_user(wrq->u.encoding.pointer, 1530 struct netdev_hw_addr *ha;
2757 abyKey, 1531 u64 mc_filter = 0;
2758 wrq->u.encoding.length)) 1532 u32 bit_nr = 0;
2759 rc = -EFAULT; 1533
1534 netdev_hw_addr_list_for_each(ha, mc_list) {
1535 bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
1536
1537 mc_filter |= 1ULL << (bit_nr & 0x3f);
1538 }
1539
1540 priv->mc_list_count = mc_list->count;
1541
1542 return mc_filter;
1543}
1544
1545static void vnt_configure(struct ieee80211_hw *hw,
1546 unsigned int changed_flags, unsigned int *total_flags, u64 multicast)
1547{
1548 struct vnt_private *priv = hw->priv;
1549 u8 rx_mode = 0;
1550
1551 *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_PROMISC_IN_BSS |
1552 FIF_BCN_PRBRESP_PROMISC;
1553
1554 VNSvInPortB(priv->PortOffset + MAC_REG_RCR, &rx_mode);
1555
1556 dev_dbg(&priv->pcid->dev, "rx mode in = %x\n", rx_mode);
1557
1558 if (changed_flags & FIF_PROMISC_IN_BSS) {
1559 /* unconditionally log net taps */
1560 if (*total_flags & FIF_PROMISC_IN_BSS)
1561 rx_mode |= RCR_UNICAST;
1562 else
1563 rx_mode &= ~RCR_UNICAST;
1564 }
1565
1566 if (changed_flags & FIF_ALLMULTI) {
1567 if (*total_flags & FIF_ALLMULTI) {
1568 if (priv->mc_list_count > 2) {
1569 MACvSelectPage1(priv->PortOffset);
1570
1571 VNSvOutPortD(priv->PortOffset +
1572 MAC_REG_MAR0, 0xffffffff);
1573 VNSvOutPortD(priv->PortOffset +
1574 MAC_REG_MAR0 + 4, 0xffffffff);
1575
1576 MACvSelectPage0(priv->PortOffset);
1577 } else {
1578 MACvSelectPage1(priv->PortOffset);
1579
1580 VNSvOutPortD(priv->PortOffset +
1581 MAC_REG_MAR0, (u32)multicast);
1582 VNSvOutPortD(priv->PortOffset +
1583 MAC_REG_MAR0 + 4,
1584 (u32)(multicast >> 32));
1585
1586 MACvSelectPage0(priv->PortOffset);
2760 } 1587 }
1588
1589 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
1590 } else {
1591 rx_mode &= ~(RCR_MULTICAST | RCR_BROADCAST);
2761 } 1592 }
2762 break; 1593 }
2763 1594
2764 // Get the current Tx-Power 1595 if (changed_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) {
2765 case SIOCGIWTXPOW: 1596 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
2766 pr_debug(" SIOCGIWTXPOW\n");
2767 rc = -EOPNOTSUPP;
2768 break;
2769 1597
2770 case SIOCSIWTXPOW: 1598 if (*total_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC))
2771 pr_debug(" SIOCSIWTXPOW\n"); 1599 rx_mode &= ~RCR_BSSID;
2772 rc = -EOPNOTSUPP; 1600 else
2773 break; 1601 rx_mode |= RCR_BSSID;
1602 }
2774 1603
2775 case SIOCSIWRETRY: 1604 VNSvOutPortB(priv->PortOffset + MAC_REG_RCR, rx_mode);
2776 1605
2777 rc = iwctl_siwretry(dev, NULL, &(wrq->u.retry), NULL); 1606 dev_dbg(&priv->pcid->dev, "rx mode out= %x\n", rx_mode);
2778 break; 1607}
2779 1608
2780 case SIOCGIWRETRY: 1609static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
1610 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
1611 struct ieee80211_key_conf *key)
1612{
1613 struct vnt_private *priv = hw->priv;
2781 1614
2782 rc = iwctl_giwretry(dev, NULL, &(wrq->u.retry), NULL); 1615 switch (cmd) {
1616 case SET_KEY:
1617 if (vnt_set_keys(hw, sta, vif, key))
1618 return -EOPNOTSUPP;
2783 break; 1619 break;
1620 case DISABLE_KEY:
1621 if (test_bit(key->hw_key_idx, &priv->key_entry_inuse))
1622 clear_bit(key->hw_key_idx, &priv->key_entry_inuse);
1623 default:
1624 break;
1625 }
2784 1626
2785 // Get range of parameters 1627 return 0;
2786 case SIOCGIWRANGE: 1628}
2787 1629
2788 { 1630static u64 vnt_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
2789 struct iw_range range; 1631{
1632 struct vnt_private *priv = hw->priv;
1633 u64 tsf;
2790 1634
2791 rc = iwctl_giwrange(dev, NULL, &(wrq->u.data), (char *)&range); 1635 CARDbGetCurrentTSF(priv, &tsf);
2792 if (copy_to_user(wrq->u.data.pointer, &range, sizeof(struct iw_range)))
2793 rc = -EFAULT;
2794 }
2795 1636
2796 break; 1637 return tsf;
1638}
2797 1639
2798 case SIOCGIWPOWER: 1640static void vnt_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1641 u64 tsf)
1642{
1643 struct vnt_private *priv = hw->priv;
2799 1644
2800 rc = iwctl_giwpower(dev, NULL, &(wrq->u.power), NULL); 1645 CARDvUpdateNextTBTT(priv, tsf, vif->bss_conf.beacon_int);
2801 break; 1646}
2802 1647
2803 case SIOCSIWPOWER: 1648static void vnt_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1649{
1650 struct vnt_private *priv = hw->priv;
2804 1651
2805 rc = iwctl_siwpower(dev, NULL, &(wrq->u.power), NULL); 1652 /* reset TSF counter */
2806 break; 1653 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
1654}
2807 1655
2808 case SIOCGIWSENS: 1656static const struct ieee80211_ops vnt_mac_ops = {
1657 .tx = vnt_tx_80211,
1658 .start = vnt_start,
1659 .stop = vnt_stop,
1660 .add_interface = vnt_add_interface,
1661 .remove_interface = vnt_remove_interface,
1662 .config = vnt_config,
1663 .bss_info_changed = vnt_bss_info_changed,
1664 .prepare_multicast = vnt_prepare_multicast,
1665 .configure_filter = vnt_configure,
1666 .set_key = vnt_set_key,
1667 .get_tsf = vnt_get_tsf,
1668 .set_tsf = vnt_set_tsf,
1669 .reset_tsf = vnt_reset_tsf,
1670};
2809 1671
2810 rc = iwctl_giwsens(dev, NULL, &(wrq->u.sens), NULL); 1672int vnt_init(struct vnt_private *priv)
2811 break; 1673{
1674 SET_IEEE80211_PERM_ADDR(priv->hw, priv->abyCurrentNetAddr);
2812 1675
2813 case SIOCSIWSENS: 1676 vnt_init_bands(priv);
2814 pr_debug(" SIOCSIWSENS\n");
2815 rc = -EOPNOTSUPP;
2816 break;
2817 1677
2818 case SIOCGIWAPLIST: { 1678 if (ieee80211_register_hw(priv->hw))
2819 char buffer[IW_MAX_AP * (sizeof(struct sockaddr) + sizeof(struct iw_quality))]; 1679 return -ENODEV;
2820
2821 if (wrq->u.data.pointer) {
2822 rc = iwctl_giwaplist(dev, NULL, &(wrq->u.data), buffer);
2823 if (rc == 0) {
2824 if (copy_to_user(wrq->u.data.pointer,
2825 buffer,
2826 (wrq->u.data.length * (sizeof(struct sockaddr) + sizeof(struct iw_quality)))
2827 ))
2828 rc = -EFAULT;
2829 }
2830 }
2831 }
2832 break;
2833 1680
2834#ifdef WIRELESS_SPY 1681 priv->mac_hw = true;
2835 // Set the spy list
2836 case SIOCSIWSPY:
2837 1682
2838 pr_debug(" SIOCSIWSPY\n"); 1683 CARDbRadioPowerOff(priv);
2839 rc = -EOPNOTSUPP;
2840 break;
2841 1684
2842 // Get the spy list 1685 return 0;
2843 case SIOCGIWSPY: 1686}
2844 1687
2845 pr_debug(" SIOCGIWSPY\n"); 1688static int
2846 rc = -EOPNOTSUPP; 1689vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
2847 break; 1690{
1691 PCHIP_INFO pChip_info = (PCHIP_INFO)ent->driver_data;
1692 struct vnt_private *priv;
1693 struct ieee80211_hw *hw;
1694 struct wiphy *wiphy;
1695 int rc;
2848 1696
2849#endif // WIRELESS_SPY 1697 dev_notice(&pcid->dev,
1698 "%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
2850 1699
2851 case SIOCGIWPRIV: 1700 dev_notice(&pcid->dev,
2852 pr_debug(" SIOCGIWPRIV\n"); 1701 "Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
2853 rc = -EOPNOTSUPP;
2854 break;
2855 1702
2856//2008-0409-07, <Add> by Einsn Liu 1703 hw = ieee80211_alloc_hw(sizeof(*priv), &vnt_mac_ops);
2857#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT 1704 if (!hw) {
2858 case SIOCSIWAUTH: 1705 dev_err(&pcid->dev, "could not register ieee80211_hw\n");
2859 pr_debug(" SIOCSIWAUTH\n"); 1706 return -ENOMEM;
2860 rc = iwctl_siwauth(dev, NULL, &(wrq->u.param), NULL); 1707 }
2861 break;
2862 1708
2863 case SIOCGIWAUTH: 1709 priv = hw->priv;
2864 pr_debug(" SIOCGIWAUTH\n");
2865 rc = iwctl_giwauth(dev, NULL, &(wrq->u.param), NULL);
2866 break;
2867 1710
2868 case SIOCSIWGENIE: 1711 vt6655_init_info(pcid, &priv, pChip_info);
2869 pr_debug(" SIOCSIWGENIE\n");
2870 rc = iwctl_siwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
2871 break;
2872 1712
2873 case SIOCGIWGENIE: 1713 priv->hw = hw;
2874 pr_debug(" SIOCGIWGENIE\n");
2875 rc = iwctl_giwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
2876 break;
2877 1714
2878 case SIOCSIWENCODEEXT: { 1715 SET_IEEE80211_DEV(priv->hw, &pcid->dev);
2879 char extra[sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1];
2880 1716
2881 pr_debug(" SIOCSIWENCODEEXT\n"); 1717 if (pci_enable_device(pcid)) {
2882 if (wrq->u.encoding.pointer) { 1718 device_free_info(priv);
2883 memset(extra, 0, sizeof(struct iw_encode_ext)+MAX_KEY_LEN + 1); 1719 return -ENODEV;
2884 if (wrq->u.encoding.length > (sizeof(struct iw_encode_ext) + MAX_KEY_LEN)) {
2885 rc = -E2BIG;
2886 break;
2887 }
2888 if (copy_from_user(extra, wrq->u.encoding.pointer, wrq->u.encoding.length)) {
2889 rc = -EFAULT;
2890 break;
2891 }
2892 } else if (wrq->u.encoding.length != 0) {
2893 rc = -EINVAL;
2894 break;
2895 }
2896 rc = iwctl_siwencodeext(dev, NULL, &(wrq->u.encoding), extra);
2897 } 1720 }
2898 break;
2899 1721
2900 case SIOCGIWENCODEEXT: 1722 dev_dbg(&pcid->dev,
2901 pr_debug(" SIOCGIWENCODEEXT\n"); 1723 "Before get pci_info memaddr is %x\n", priv->memaddr);
2902 rc = iwctl_giwencodeext(dev, NULL, &(wrq->u.encoding), NULL);
2903 break;
2904 1724
2905 case SIOCSIWMLME: 1725 if (!device_get_pci_info(priv, pcid)) {
2906 pr_debug(" SIOCSIWMLME\n"); 1726 dev_err(&pcid->dev, ": Failed to find PCI device.\n");
2907 rc = iwctl_siwmlme(dev, NULL, &(wrq->u.data), wrq->u.data.pointer); 1727 device_free_info(priv);
2908 break; 1728 return -ENODEV;
1729 }
2909 1730
2910#endif // #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT 1731#ifdef DEBUG
2911//End Add -- //2008-0409-07, <Add> by Einsn Liu 1732 dev_dbg(&pcid->dev,
1733 "after get pci_info memaddr is %x, io addr is %x,io_size is %d\n",
1734 priv->memaddr, priv->ioaddr, priv->io_size);
1735 {
1736 int i;
1737 u32 bar, len;
1738 u32 address[] = {
1739 PCI_BASE_ADDRESS_0,
1740 PCI_BASE_ADDRESS_1,
1741 PCI_BASE_ADDRESS_2,
1742 PCI_BASE_ADDRESS_3,
1743 PCI_BASE_ADDRESS_4,
1744 PCI_BASE_ADDRESS_5,
1745 0};
1746 for (i = 0; address[i]; i++) {
1747 pci_read_config_dword(pcid, address[i], &bar);
2912 1748
2913 case IOCTL_CMD_TEST: 1749 dev_dbg(&pcid->dev, "bar %d is %x\n", i, bar);
2914 1750
2915 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) { 1751 if (!bar) {
2916 rc = -EFAULT; 1752 dev_dbg(&pcid->dev,
2917 break; 1753 "bar %d not implemented\n", i);
2918 } else { 1754 continue;
2919 rc = 0; 1755 }
2920 }
2921 pReq = (PSCmdRequest)rq;
2922 pReq->wResult = MAGIC_CODE;
2923 break;
2924 1756
2925 case IOCTL_CMD_SET: 1757 if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
1758 /* This is IO */
2926 1759
2927#ifdef SndEvt_ToAPI 1760 len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xffff);
2928 if ((((PSCmdRequest)rq)->wCmdCode != WLAN_CMD_SET_EVT) && 1761 len = len & ~(len - 1);
2929 !(pDevice->flags & DEVICE_FLAGS_OPENED)) 1762
2930#else 1763 dev_dbg(&pcid->dev,
2931 if (!(pDevice->flags & DEVICE_FLAGS_OPENED) && 1764 "IO space: len in IO %x, BAR %d\n",
2932 (((PSCmdRequest)rq)->wCmdCode != WLAN_CMD_SET_WPA)) 1765 len, i);
2933#endif
2934 {
2935 rc = -EFAULT;
2936 break;
2937 } else { 1766 } else {
2938 rc = 0; 1767 len = bar & 0xfffffff0;
1768 len = ~len + 1;
1769
1770 dev_dbg(&pcid->dev,
1771 "len in MEM %x, BAR %d\n", len, i);
2939 } 1772 }
1773 }
1774 }
1775#endif
2940 1776
2941 if (test_and_set_bit(0, (void *)&(pMgmt->uCmdBusy))) 1777 priv->PortOffset = ioremap(priv->memaddr & PCI_BASE_ADDRESS_MEM_MASK,
2942 return -EBUSY; 1778 priv->io_size);
1779 if (!priv->PortOffset) {
1780 dev_err(&pcid->dev, ": Failed to IO remapping ..\n");
1781 device_free_info(priv);
1782 return -ENODEV;
1783 }
2943 1784
2944 rc = private_ioctl(pDevice, rq); 1785 rc = pci_request_regions(pcid, DEVICE_NAME);
2945 clear_bit(0, (void *)&(pMgmt->uCmdBusy)); 1786 if (rc) {
2946 break; 1787 dev_err(&pcid->dev, ": Failed to find PCI device\n");
1788 device_free_info(priv);
1789 return -ENODEV;
1790 }
2947 1791
2948 case IOCTL_CMD_HOSTAPD: 1792 /* do reset */
1793 if (!MACbSoftwareReset(priv->PortOffset)) {
1794 dev_err(&pcid->dev, ": Failed to access MAC hardware..\n");
1795 device_free_info(priv);
1796 return -ENODEV;
1797 }
1798 /* initial to reload eeprom */
1799 MACvInitialize(priv->PortOffset);
1800 MACvReadEtherAddress(priv->PortOffset, priv->abyCurrentNetAddr);
2949 1801
2950 rc = vt6655_hostap_ioctl(pDevice, &wrq->u.data); 1802 device_get_options(priv);
2951 break; 1803 device_set_options(priv);
1804 /* Mask out the options cannot be set to the chip */
1805 priv->sOpts.flags &= pChip_info->flags;
2952 1806
2953 case IOCTL_CMD_WPA: 1807 /* Enable the chip specified capabilities */
1808 priv->flags = priv->sOpts.flags | (pChip_info->flags & 0xff000000UL);
2954 1809
2955 rc = wpa_ioctl(pDevice, &wrq->u.data); 1810 wiphy = priv->hw->wiphy;
2956 break;
2957 1811
2958 case SIOCETHTOOL: 1812 wiphy->frag_threshold = FRAG_THRESH_DEF;
2959 return ethtool_ioctl(dev, rq->ifr_data); 1813 wiphy->rts_threshold = RTS_THRESH_DEF;
2960 // All other calls are currently unsupported 1814 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1815 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP);
2961 1816
2962 default: 1817 priv->hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
2963 rc = -EOPNOTSUPP; 1818 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
2964 pr_debug("Ioctl command not support..%x\n", cmd); 1819 IEEE80211_HW_SIGNAL_DBM |
1820 IEEE80211_HW_TIMING_BEACON_ONLY;
2965 1821
2966 } 1822 priv->hw->max_signal = 100;
2967 1823
2968 if (pDevice->bCommit) { 1824 if (vnt_init(priv))
2969 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) { 1825 return -ENODEV;
2970 netif_stop_queue(pDevice->dev);
2971 spin_lock_irq(&pDevice->lock);
2972 bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
2973 spin_unlock_irq(&pDevice->lock);
2974 } else {
2975 pr_debug("Commit the settings\n");
2976 spin_lock_irq(&pDevice->lock);
2977 pDevice->bLinkPass = false;
2978 memset(pMgmt->abyCurrBSSID, 0, 6);
2979 pMgmt->eCurrState = WMAC_STATE_IDLE;
2980 netif_stop_queue(pDevice->dev);
2981#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2982 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
2983 if (!pDevice->bWPASuppWextEnabled)
2984#endif
2985 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
2986 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
2987 spin_unlock_irq(&pDevice->lock);
2988 }
2989 pDevice->bCommit = false;
2990 }
2991 1826
2992 return rc; 1827 device_print_info(priv);
1828 pci_set_drvdata(pcid, priv);
1829
1830 return 0;
2993} 1831}
2994 1832
2995static int ethtool_ioctl(struct net_device *dev, void __user *useraddr) 1833/*------------------------------------------------------------------*/
1834
1835#ifdef CONFIG_PM
1836static int vt6655_suspend(struct pci_dev *pcid, pm_message_t state)
2996{ 1837{
2997 u32 ethcmd; 1838 struct vnt_private *priv = pci_get_drvdata(pcid);
1839 unsigned long flags;
2998 1840
2999 if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd))) 1841 spin_lock_irqsave(&priv->lock, flags);
3000 return -EFAULT;
3001 1842
3002 switch (ethcmd) { 1843 pci_save_state(pcid);
3003 case ETHTOOL_GDRVINFO: {
3004 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
3005 1844
3006 strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1); 1845 MACbShutdown(priv->PortOffset);
3007 strncpy(info.version, DEVICE_VERSION, sizeof(info.version)-1);
3008 if (copy_to_user(useraddr, &info, sizeof(info)))
3009 return -EFAULT;
3010 return 0;
3011 }
3012 1846
3013 } 1847 pci_disable_device(pcid);
1848 pci_set_power_state(pcid, pci_choose_state(pcid, state));
1849
1850 spin_unlock_irqrestore(&priv->lock, flags);
3014 1851
3015 return -EOPNOTSUPP; 1852 return 0;
3016} 1853}
3017 1854
3018/*------------------------------------------------------------------*/ 1855static int vt6655_resume(struct pci_dev *pcid)
1856{
1857
1858 pci_set_power_state(pcid, PCI_D0);
1859 pci_enable_wake(pcid, PCI_D0, 0);
1860 pci_restore_state(pcid);
1861
1862 return 0;
1863}
1864#endif
3019 1865
3020MODULE_DEVICE_TABLE(pci, vt6655_pci_id_table); 1866MODULE_DEVICE_TABLE(pci, vt6655_pci_id_table);
3021 1867
@@ -3025,8 +1871,8 @@ static struct pci_driver device_driver = {
3025 .probe = vt6655_probe, 1871 .probe = vt6655_probe,
3026 .remove = vt6655_remove, 1872 .remove = vt6655_remove,
3027#ifdef CONFIG_PM 1873#ifdef CONFIG_PM
3028 .suspend = viawget_suspend, 1874 .suspend = vt6655_suspend,
3029 .resume = viawget_resume, 1875 .resume = vt6655_resume,
3030#endif 1876#endif
3031}; 1877};
3032 1878
@@ -3067,75 +1913,10 @@ device_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
3067 for_each_pci_dev(pdev) { 1913 for_each_pci_dev(pdev) {
3068 if (pci_dev_driver(pdev) == &device_driver) { 1914 if (pci_dev_driver(pdev) == &device_driver) {
3069 if (pci_get_drvdata(pdev)) 1915 if (pci_get_drvdata(pdev))
3070 viawget_suspend(pdev, PMSG_HIBERNATE); 1916 vt6655_suspend(pdev, PMSG_HIBERNATE);
3071 } 1917 }
3072 } 1918 }
3073 } 1919 }
3074 return NOTIFY_DONE; 1920 return NOTIFY_DONE;
3075} 1921}
3076
3077static int
3078viawget_suspend(struct pci_dev *pcid, pm_message_t state)
3079{
3080 int power_status; // to silence the compiler
3081
3082 struct vnt_private *pDevice = pci_get_drvdata(pcid);
3083 PSMgmtObject pMgmt = pDevice->pMgmt;
3084
3085 netif_stop_queue(pDevice->dev);
3086 spin_lock_irq(&pDevice->lock);
3087 pci_save_state(pcid);
3088 del_timer(&pDevice->sTimerCommand);
3089 del_timer(&pMgmt->sTimerSecondCallback);
3090 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
3091 pDevice->uCmdDequeueIdx = 0;
3092 pDevice->uCmdEnqueueIdx = 0;
3093 pDevice->bCmdRunning = false;
3094 MACbShutdown(pDevice->PortOffset);
3095 MACvSaveContext(pDevice->PortOffset, pDevice->abyMacContext);
3096 pDevice->bLinkPass = false;
3097 memset(pMgmt->abyCurrBSSID, 0, 6);
3098 pMgmt->eCurrState = WMAC_STATE_IDLE;
3099 pci_disable_device(pcid);
3100 power_status = pci_set_power_state(pcid, pci_choose_state(pcid, state));
3101 spin_unlock_irq(&pDevice->lock);
3102 return 0;
3103}
3104
3105static int
3106viawget_resume(struct pci_dev *pcid)
3107{
3108 struct vnt_private *pDevice = pci_get_drvdata(pcid);
3109 PSMgmtObject pMgmt = pDevice->pMgmt;
3110 int power_status; // to silence the compiler
3111
3112 power_status = pci_set_power_state(pcid, PCI_D0);
3113 power_status = pci_enable_wake(pcid, PCI_D0, 0);
3114 pci_restore_state(pcid);
3115 if (netif_running(pDevice->dev)) {
3116 spin_lock_irq(&pDevice->lock);
3117 MACvRestoreContext(pDevice->PortOffset, pDevice->abyMacContext);
3118 device_init_registers(pDevice);
3119 if (pMgmt->sNodeDBTable[0].bActive) { // Assoc with BSS
3120 pMgmt->sNodeDBTable[0].bActive = false;
3121 pDevice->bLinkPass = false;
3122 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
3123 // In Adhoc, BSS state set back to started.
3124 pMgmt->eCurrState = WMAC_STATE_STARTED;
3125 } else {
3126 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
3127 pMgmt->eCurrState = WMAC_STATE_IDLE;
3128 }
3129 }
3130 init_timer(&pMgmt->sTimerSecondCallback);
3131 init_timer(&pDevice->sTimerCommand);
3132 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
3133 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
3134 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
3135 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
3136 spin_unlock_irq(&pDevice->lock);
3137 }
3138 return 0;
3139}
3140
3141#endif 1922#endif
diff --git a/drivers/staging/vt6655/dpc.c b/drivers/staging/vt6655/dpc.c
index 8515b8c80801..977683cb7391 100644
--- a/drivers/staging/vt6655/dpc.c
+++ b/drivers/staging/vt6655/dpc.c
@@ -25,1289 +25,135 @@
25 * Date: May 20, 2003 25 * Date: May 20, 2003
26 * 26 *
27 * Functions: 27 * Functions:
28 * device_receive_frame - Rcv 802.11 frame function
29 * s_bAPModeRxCtl- AP Rcv frame filer Ctl.
30 * s_bAPModeRxData- AP Rcv data frame handle
31 * s_bHandleRxEncryption- Rcv decrypted data via on-fly
32 * s_bHostWepRxEncryption- Rcv encrypted data via host
33 * s_byGetRateIdx- get rate index
34 * s_vGetDASA- get data offset
35 * s_vProcessRxMACHeader- Rcv 802.11 and translate to 802.3
36 * 28 *
37 * Revision History: 29 * Revision History:
38 * 30 *
39 */ 31 */
40 32
41#include "device.h" 33#include "device.h"
42#include "rxtx.h"
43#include "tether.h"
44#include "card.h"
45#include "bssdb.h"
46#include "mac.h"
47#include "baseband.h" 34#include "baseband.h"
48#include "michael.h"
49#include "tkip.h"
50#include "tcrc.h"
51#include "wctl.h"
52#include "wroute.h"
53#include "hostap.h"
54#include "rf.h" 35#include "rf.h"
55#include "iowpa.h"
56#include "aes_ccmp.h"
57#include "dpc.h" 36#include "dpc.h"
58 37
59/*--------------------- Static Definitions -------------------------*/ 38static bool vnt_rx_data(struct vnt_private *priv, struct sk_buff *skb,
60 39 u16 bytes_received)
61/*--------------------- Static Classes ----------------------------*/
62
63/*--------------------- Static Variables --------------------------*/
64static const unsigned char acbyRxRate[MAX_RATE] =
65{2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
66
67/*--------------------- Static Functions --------------------------*/
68
69/*--------------------- Static Definitions -------------------------*/
70
71/*--------------------- Static Functions --------------------------*/
72
73static unsigned char s_byGetRateIdx(unsigned char byRate);
74
75static void
76s_vGetDASA(unsigned char *pbyRxBufferAddr, unsigned int *pcbHeaderSize,
77 PSEthernetHeader psEthHeader);
78
79static void
80s_vProcessRxMACHeader(struct vnt_private *pDevice, unsigned char *pbyRxBufferAddr,
81 unsigned int cbPacketSize, bool bIsWEP, bool bExtIV,
82 unsigned int *pcbHeadSize);
83
84static bool s_bAPModeRxCtl(
85 struct vnt_private *pDevice,
86 unsigned char *pbyFrame,
87 int iSANodeIndex
88);
89
90static bool s_bAPModeRxData(
91 struct vnt_private *pDevice,
92 struct sk_buff *skb,
93 unsigned int FrameSize,
94 unsigned int cbHeaderOffset,
95 int iSANodeIndex,
96 int iDANodeIndex
97);
98
99static bool s_bHandleRxEncryption(
100 struct vnt_private *pDevice,
101 unsigned char *pbyFrame,
102 unsigned int FrameSize,
103 unsigned char *pbyRsr,
104 unsigned char *pbyNewRsr,
105 PSKeyItem *pKeyOut,
106 bool *pbExtIV,
107 unsigned short *pwRxTSC15_0,
108 unsigned long *pdwRxTSC47_16
109);
110
111static bool s_bHostWepRxEncryption(
112
113 struct vnt_private *pDevice,
114 unsigned char *pbyFrame,
115 unsigned int FrameSize,
116 unsigned char *pbyRsr,
117 bool bOnFly,
118 PSKeyItem pKey,
119 unsigned char *pbyNewRsr,
120 bool *pbExtIV,
121 unsigned short *pwRxTSC15_0,
122 unsigned long *pdwRxTSC47_16
123
124);
125
126/*--------------------- Export Variables --------------------------*/
127
128/*+
129 *
130 * Description:
131 * Translate Rcv 802.11 header to 802.3 header with Rx buffer
132 *
133 * Parameters:
134 * In:
135 * pDevice
136 * dwRxBufferAddr - Address of Rcv Buffer
137 * cbPacketSize - Rcv Packet size
138 * bIsWEP - If Rcv with WEP
139 * Out:
140 * pcbHeaderSize - 802.11 header size
141 *
142 * Return Value: None
143 *
144 -*/
145static void
146s_vProcessRxMACHeader(struct vnt_private *pDevice,
147 unsigned char *pbyRxBufferAddr,
148 unsigned int cbPacketSize, bool bIsWEP, bool bExtIV,
149 unsigned int *pcbHeadSize)
150{ 40{
151 unsigned char *pbyRxBuffer; 41 struct ieee80211_hw *hw = priv->hw;
152 unsigned int cbHeaderSize = 0; 42 struct ieee80211_supported_band *sband;
153 unsigned short *pwType; 43 struct ieee80211_rx_status rx_status = { 0 };
154 PS802_11Header pMACHeader; 44 struct ieee80211_hdr *hdr;
155 int ii; 45 __le16 fc;
156 46 u8 *rsr, *new_rsr, *rssi;
157 pMACHeader = (PS802_11Header) (pbyRxBufferAddr + cbHeaderSize); 47 __le64 *tsf_time;
158 48 u16 frame_size;
159 s_vGetDASA((unsigned char *)pMACHeader, &cbHeaderSize, &pDevice->sRxEthHeader); 49 int ii, r;
160 50 u8 *rx_sts, *rx_rate, *sq;
161 if (bIsWEP) { 51 u8 *skb_data;
162 if (bExtIV) { 52 u8 rate_idx = 0;
163 // strip IV&ExtIV , add 8 byte 53 u8 rate[MAX_RATE] = {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
164 cbHeaderSize += (WLAN_HDR_ADDR3_LEN + 8); 54 long rx_dbm;
165 } else { 55
166 // strip IV , add 4 byte 56 /* [31:16]RcvByteCount ( not include 4-byte Status ) */
167 cbHeaderSize += (WLAN_HDR_ADDR3_LEN + 4); 57 frame_size = le16_to_cpu(*((__le16 *)(skb->data + 2)));
168 } 58 if (frame_size > 2346 || frame_size < 14) {
169 } else { 59 dev_dbg(&priv->pcid->dev, "------- WRONG Length 1\n");
170 cbHeaderSize += WLAN_HDR_ADDR3_LEN;
171 }
172
173 pbyRxBuffer = (unsigned char *)(pbyRxBufferAddr + cbHeaderSize);
174 if (ether_addr_equal(pbyRxBuffer, pDevice->abySNAP_Bridgetunnel)) {
175 cbHeaderSize += 6;
176 } else if (ether_addr_equal(pbyRxBuffer, pDevice->abySNAP_RFC1042)) {
177 cbHeaderSize += 6;
178 pwType = (unsigned short *)(pbyRxBufferAddr + cbHeaderSize);
179 if ((*pwType != TYPE_PKT_IPX) && (*pwType != cpu_to_le16(0xF380))) {
180 } else {
181 cbHeaderSize -= 8;
182 pwType = (unsigned short *)(pbyRxBufferAddr + cbHeaderSize);
183 if (bIsWEP) {
184 if (bExtIV)
185 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 8); // 8 is IV&ExtIV
186 else
187 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 4); // 4 is IV
188
189 } else {
190 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN);
191 }
192 }
193 } else {
194 cbHeaderSize -= 2;
195 pwType = (unsigned short *)(pbyRxBufferAddr + cbHeaderSize);
196 if (bIsWEP) {
197 if (bExtIV)
198 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 8); // 8 is IV&ExtIV
199 else
200 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 4); // 4 is IV
201
202 } else {
203 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN);
204 }
205 }
206
207 cbHeaderSize -= (ETH_ALEN * 2);
208 pbyRxBuffer = (unsigned char *)(pbyRxBufferAddr + cbHeaderSize);
209 for (ii = 0; ii < ETH_ALEN; ii++)
210 *pbyRxBuffer++ = pDevice->sRxEthHeader.abyDstAddr[ii];
211 for (ii = 0; ii < ETH_ALEN; ii++)
212 *pbyRxBuffer++ = pDevice->sRxEthHeader.abySrcAddr[ii];
213
214 *pcbHeadSize = cbHeaderSize;
215}
216
217static unsigned char s_byGetRateIdx(unsigned char byRate)
218{
219 unsigned char byRateIdx;
220
221 for (byRateIdx = 0; byRateIdx < MAX_RATE; byRateIdx++) {
222 if (acbyRxRate[byRateIdx % MAX_RATE] == byRate)
223 return byRateIdx;
224 }
225
226 return 0;
227}
228
229static void
230s_vGetDASA(unsigned char *pbyRxBufferAddr, unsigned int *pcbHeaderSize,
231 PSEthernetHeader psEthHeader)
232{
233 unsigned int cbHeaderSize = 0;
234 PS802_11Header pMACHeader;
235 int ii;
236
237 pMACHeader = (PS802_11Header) (pbyRxBufferAddr + cbHeaderSize);
238
239 if ((pMACHeader->wFrameCtl & FC_TODS) == 0) {
240 if (pMACHeader->wFrameCtl & FC_FROMDS) {
241 for (ii = 0; ii < ETH_ALEN; ii++) {
242 psEthHeader->abyDstAddr[ii] = pMACHeader->abyAddr1[ii];
243 psEthHeader->abySrcAddr[ii] = pMACHeader->abyAddr3[ii];
244 }
245 } else {
246 // IBSS mode
247 for (ii = 0; ii < ETH_ALEN; ii++) {
248 psEthHeader->abyDstAddr[ii] = pMACHeader->abyAddr1[ii];
249 psEthHeader->abySrcAddr[ii] = pMACHeader->abyAddr2[ii];
250 }
251 }
252 } else {
253 // Is AP mode..
254 if (pMACHeader->wFrameCtl & FC_FROMDS) {
255 for (ii = 0; ii < ETH_ALEN; ii++) {
256 psEthHeader->abyDstAddr[ii] = pMACHeader->abyAddr3[ii];
257 psEthHeader->abySrcAddr[ii] = pMACHeader->abyAddr4[ii];
258 cbHeaderSize += 6;
259 }
260 } else {
261 for (ii = 0; ii < ETH_ALEN; ii++) {
262 psEthHeader->abyDstAddr[ii] = pMACHeader->abyAddr3[ii];
263 psEthHeader->abySrcAddr[ii] = pMACHeader->abyAddr2[ii];
264 }
265 }
266 }
267 *pcbHeaderSize = cbHeaderSize;
268}
269
270bool
271device_receive_frame(
272 struct vnt_private *pDevice,
273 PSRxDesc pCurrRD
274)
275{
276 PDEVICE_RD_INFO pRDInfo = pCurrRD->pRDInfo;
277 struct net_device_stats *pStats = &pDevice->dev->stats;
278 struct sk_buff *skb;
279 PSMgmtObject pMgmt = pDevice->pMgmt;
280 PSRxMgmtPacket pRxPacket = &(pDevice->pMgmt->sRxPacket);
281 PS802_11Header p802_11Header;
282 unsigned char *pbyRsr;
283 unsigned char *pbyNewRsr;
284 unsigned char *pbyRSSI;
285 __le64 *pqwTSFTime;
286 unsigned short *pwFrameSize;
287 unsigned char *pbyFrame;
288 bool bDeFragRx = false;
289 bool bIsWEP = false;
290 unsigned int cbHeaderOffset;
291 unsigned int FrameSize;
292 unsigned short wEtherType = 0;
293 int iSANodeIndex = -1;
294 int iDANodeIndex = -1;
295 unsigned int ii;
296 unsigned int cbIVOffset;
297 bool bExtIV = false;
298 unsigned char *pbyRxSts;
299 unsigned char *pbyRxRate;
300 unsigned char *pbySQ;
301 unsigned int cbHeaderSize;
302 PSKeyItem pKey = NULL;
303 unsigned short wRxTSC15_0 = 0;
304 unsigned long dwRxTSC47_16 = 0;
305 SKeyItem STempKey;
306 // 802.11h RPI
307 unsigned long dwDuration = 0;
308 long ldBm = 0;
309 long ldBmThreshold = 0;
310 PS802_11Header pMACHeader;
311 bool bRxeapol_key = false;
312
313 skb = pRDInfo->skb;
314
315 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
316 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
317
318 pwFrameSize = (unsigned short *)(skb->data + 2);
319 FrameSize = cpu_to_le16(pCurrRD->m_rd1RD1.wReqCount) - cpu_to_le16(pCurrRD->m_rd0RD0.wResCount);
320
321 // Max: 2312Payload + 30HD +4CRC + 2Padding + 4Len + 8TSF + 4RSR
322 // Min (ACK): 10HD +4CRC + 2Padding + 4Len + 8TSF + 4RSR
323 if ((FrameSize > 2364) || (FrameSize <= 32)) {
324 // Frame Size error drop this packet.
325 pr_debug("---------- WRONG Length 1\n");
326 return false;
327 }
328
329 pbyRxSts = (unsigned char *)(skb->data);
330 pbyRxRate = (unsigned char *)(skb->data + 1);
331 pbyRsr = (unsigned char *)(skb->data + FrameSize - 1);
332 pbyRSSI = (unsigned char *)(skb->data + FrameSize - 2);
333 pbyNewRsr = (unsigned char *)(skb->data + FrameSize - 3);
334 pbySQ = (unsigned char *)(skb->data + FrameSize - 4);
335 pqwTSFTime = (__le64 *)(skb->data + FrameSize - 12);
336 pbyFrame = (unsigned char *)(skb->data + 4);
337
338 // get packet size
339 FrameSize = cpu_to_le16(*pwFrameSize);
340
341 if ((FrameSize > 2346)|(FrameSize < 14)) { // Max: 2312Payload + 30HD +4CRC
342 // Min: 14 bytes ACK
343 pr_debug("---------- WRONG Length 2\n");
344 return false;
345 }
346
347 // update receive statistic counter
348 STAvUpdateRDStatCounter(&pDevice->scStatistic,
349 *pbyRsr,
350 *pbyNewRsr,
351 *pbyRxRate,
352 pbyFrame,
353 FrameSize);
354
355 pMACHeader = (PS802_11Header)((unsigned char *)(skb->data) + 8);
356
357 if (pDevice->bMeasureInProgress) {
358 if ((*pbyRsr & RSR_CRCOK) != 0)
359 pDevice->byBasicMap |= 0x01;
360
361 dwDuration = (FrameSize << 4);
362 dwDuration /= acbyRxRate[*pbyRxRate%MAX_RATE];
363 if (*pbyRxRate <= RATE_11M) {
364 if (*pbyRxSts & 0x01) {
365 // long preamble
366 dwDuration += 192;
367 } else {
368 // short preamble
369 dwDuration += 96;
370 }
371 } else {
372 dwDuration += 16;
373 }
374 RFvRSSITodBm(pDevice, *pbyRSSI, &ldBm);
375 ldBmThreshold = -57;
376 for (ii = 7; ii > 0;) {
377 if (ldBm > ldBmThreshold)
378 break;
379
380 ldBmThreshold -= 5;
381 ii--;
382 }
383 pDevice->dwRPIs[ii] += dwDuration;
384 return false;
385 }
386
387 if (!is_multicast_ether_addr(pbyFrame)) {
388 if (WCTLbIsDuplicate(&(pDevice->sDupRxCache), (PS802_11Header)(skb->data + 4))) {
389 pDevice->s802_11Counter.FrameDuplicateCount++;
390 return false;
391 }
392 }
393
394 // Use for TKIP MIC
395 s_vGetDASA(skb->data+4, &cbHeaderSize, &pDevice->sRxEthHeader);
396
397 // filter packet send from myself
398 if (ether_addr_equal(pDevice->sRxEthHeader.abySrcAddr,
399 pDevice->abyCurrentNetAddr))
400 return false;
401
402 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) || (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
403 if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) {
404 p802_11Header = (PS802_11Header)(pbyFrame);
405 // get SA NodeIndex
406 if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(p802_11Header->abyAddr2), &iSANodeIndex)) {
407 pMgmt->sNodeDBTable[iSANodeIndex].ulLastRxJiffer = jiffies;
408 pMgmt->sNodeDBTable[iSANodeIndex].uInActiveCount = 0;
409 }
410 }
411 }
412
413 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
414 if (s_bAPModeRxCtl(pDevice, pbyFrame, iSANodeIndex))
415 return false;
416 }
417
418 if (IS_FC_WEP(pbyFrame)) {
419 bool bRxDecryOK = false;
420
421 pr_debug("rx WEP pkt\n");
422 bIsWEP = true;
423 if ((pDevice->bEnableHostWEP) && (iSANodeIndex >= 0)) {
424 pKey = &STempKey;
425 pKey->byCipherSuite = pMgmt->sNodeDBTable[iSANodeIndex].byCipherSuite;
426 pKey->dwKeyIndex = pMgmt->sNodeDBTable[iSANodeIndex].dwKeyIndex;
427 pKey->uKeyLength = pMgmt->sNodeDBTable[iSANodeIndex].uWepKeyLength;
428 pKey->dwTSC47_16 = pMgmt->sNodeDBTable[iSANodeIndex].dwTSC47_16;
429 pKey->wTSC15_0 = pMgmt->sNodeDBTable[iSANodeIndex].wTSC15_0;
430 memcpy(pKey->abyKey,
431 &pMgmt->sNodeDBTable[iSANodeIndex].abyWepKey[0],
432 pKey->uKeyLength
433);
434
435 bRxDecryOK = s_bHostWepRxEncryption(pDevice,
436 pbyFrame,
437 FrameSize,
438 pbyRsr,
439 pMgmt->sNodeDBTable[iSANodeIndex].bOnFly,
440 pKey,
441 pbyNewRsr,
442 &bExtIV,
443 &wRxTSC15_0,
444 &dwRxTSC47_16);
445 } else {
446 bRxDecryOK = s_bHandleRxEncryption(pDevice,
447 pbyFrame,
448 FrameSize,
449 pbyRsr,
450 pbyNewRsr,
451 &pKey,
452 &bExtIV,
453 &wRxTSC15_0,
454 &dwRxTSC47_16);
455 }
456
457 if (bRxDecryOK) {
458 if ((*pbyNewRsr & NEWRSR_DECRYPTOK) == 0) {
459 pr_debug("ICV Fail\n");
460 if ((pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
461 (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
462 (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) ||
463 (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
464 (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
465 if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP))
466 pDevice->s802_11Counter.TKIPICVErrors++;
467 else if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_CCMP))
468 pDevice->s802_11Counter.CCMPDecryptErrors++;
469 }
470 return false;
471 }
472 } else {
473 pr_debug("WEP Func Fail\n");
474 return false;
475 }
476 if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_CCMP))
477 FrameSize -= 8; // Message Integrity Code
478 else
479 FrameSize -= 4; // 4 is ICV
480 }
481
482 //
483 // RX OK
484 //
485 //remove the CRC length
486 FrameSize -= ETH_FCS_LEN;
487
488 if ((!(*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI))) && // unicast address
489 (IS_FRAGMENT_PKT((skb->data+4)))
490) {
491 // defragment
492 bDeFragRx = WCTLbHandleFragment(pDevice, (PS802_11Header)(skb->data+4), FrameSize, bIsWEP, bExtIV);
493 pDevice->s802_11Counter.ReceivedFragmentCount++;
494 if (bDeFragRx) {
495 // defrag complete
496 skb = pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].skb;
497 FrameSize = pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength;
498
499 } else {
500 return false;
501 }
502 }
503
504// Management & Control frame Handle
505 if ((IS_TYPE_DATA((skb->data+4))) == false) {
506 // Handle Control & Manage Frame
507
508 if (IS_TYPE_MGMT((skb->data+4))) {
509 unsigned char *pbyData1;
510 unsigned char *pbyData2;
511
512 pRxPacket->p80211Header = (PUWLAN_80211HDR)(skb->data+4);
513 pRxPacket->cbMPDULen = FrameSize;
514 pRxPacket->uRSSI = *pbyRSSI;
515 pRxPacket->bySQ = *pbySQ;
516 pRxPacket->qwLocalTSF = le64_to_cpu(*pqwTSFTime);
517 if (bIsWEP) {
518 // strip IV
519 pbyData1 = WLAN_HDR_A3_DATA_PTR(skb->data+4);
520 pbyData2 = WLAN_HDR_A3_DATA_PTR(skb->data+4) + 4;
521 for (ii = 0; ii < (FrameSize - 4); ii++) {
522 *pbyData1 = *pbyData2;
523 pbyData1++;
524 pbyData2++;
525 }
526 }
527 pRxPacket->byRxRate = s_byGetRateIdx(*pbyRxRate);
528 pRxPacket->byRxChannel = (*pbyRxSts) >> 2;
529
530 vMgrRxManagePacket((void *)pDevice, pDevice->pMgmt, pRxPacket);
531
532 // hostap Deamon handle 802.11 management
533 if (pDevice->bEnableHostapd) {
534 skb->dev = pDevice->apdev;
535 skb->data += 4;
536 skb->tail += 4;
537 skb_put(skb, FrameSize);
538 skb_reset_mac_header(skb);
539 skb->pkt_type = PACKET_OTHERHOST;
540 skb->protocol = htons(ETH_P_802_2);
541 memset(skb->cb, 0, sizeof(skb->cb));
542 netif_rx(skb);
543 return true;
544 }
545 }
546
547 return false; 60 return false;
548 } else {
549 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
550 //In AP mode, hw only check addr1(BSSID or RA) if equal to local MAC.
551 if (!(*pbyRsr & RSR_BSSIDOK)) {
552 if (bDeFragRx) {
553 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
554 pr_err("%s: can not alloc more frag bufs\n",
555 pDevice->dev->name);
556 }
557 }
558 return false;
559 }
560 } else {
561 // discard DATA packet while not associate || BSSID error
562 if (!pDevice->bLinkPass || !(*pbyRsr & RSR_BSSIDOK)) {
563 if (bDeFragRx) {
564 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
565 pr_err("%s: can not alloc more frag bufs\n",
566 pDevice->dev->name);
567 }
568 }
569 return false;
570 }
571 //mike add:station mode check eapol-key challenge--->
572 {
573 unsigned char Protocol_Version; //802.1x Authentication
574 unsigned char Packet_Type; //802.1x Authentication
575
576 if (bIsWEP)
577 cbIVOffset = 8;
578 else
579 cbIVOffset = 0;
580 wEtherType = (skb->data[cbIVOffset + 8 + 24 + 6] << 8) |
581 skb->data[cbIVOffset + 8 + 24 + 6 + 1];
582 Protocol_Version = skb->data[cbIVOffset + 8 + 24 + 6 + 1 + 1];
583 Packet_Type = skb->data[cbIVOffset + 8 + 24 + 6 + 1 + 1 + 1];
584 if (wEtherType == ETH_P_PAE) { //Protocol Type in LLC-Header
585 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
586 (Packet_Type == 3)) { //802.1x OR eapol-key challenge frame receive
587 bRxeapol_key = true;
588 }
589 }
590 }
591 //mike add:station mode check eapol-key challenge<---
592 }
593 }
594
595// Data frame Handle
596
597 if (pDevice->bEnablePSMode) {
598 if (!IS_FC_MOREDATA((skb->data+4))) {
599 if (pDevice->pMgmt->bInTIMWake == true)
600 pDevice->pMgmt->bInTIMWake = false;
601 }
602 }
603
604 // Now it only supports 802.11g Infrastructure Mode, and support rate must up to 54 Mbps
605 if (pDevice->bDiversityEnable && (FrameSize > 50) &&
606 (pDevice->op_mode == NL80211_IFTYPE_STATION) &&
607 pDevice->bLinkPass) {
608 BBvAntennaDiversity(pDevice, s_byGetRateIdx(*pbyRxRate), 0);
609 }
610
611 if (pDevice->byLocalID != REV_ID_VT3253_B1)
612 pDevice->uCurrRSSI = *pbyRSSI;
613
614 pDevice->byCurrSQ = *pbySQ;
615
616 if ((*pbyRSSI != 0) &&
617 (pMgmt->pCurrBSS != NULL)) {
618 RFvRSSITodBm(pDevice, *pbyRSSI, &ldBm);
619 // Monitor if RSSI is too strong.
620 pMgmt->pCurrBSS->byRSSIStatCnt++;
621 pMgmt->pCurrBSS->byRSSIStatCnt %= RSSI_STAT_COUNT;
622 pMgmt->pCurrBSS->ldBmAverage[pMgmt->pCurrBSS->byRSSIStatCnt] = ldBm;
623 for (ii = 0; ii < RSSI_STAT_COUNT; ii++)
624 if (pMgmt->pCurrBSS->ldBmAverage[ii] != 0)
625 pMgmt->pCurrBSS->ldBmMAX = max(pMgmt->pCurrBSS->ldBmAverage[ii], ldBm);
626
627 } 61 }
628 62
629 // ----------------------------------------------- 63 skb_data = (u8 *)skb->data;
630 64
631 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && pDevice->bEnable8021x) { 65 rx_sts = skb_data;
632 unsigned char abyMacHdr[24]; 66 rx_rate = skb_data + 1;
633 67
634 // Only 802.1x packet incoming allowed 68 sband = hw->wiphy->bands[hw->conf.chandef.chan->band];
635 if (bIsWEP)
636 cbIVOffset = 8;
637 else
638 cbIVOffset = 0;
639 wEtherType = (skb->data[cbIVOffset + 4 + 24 + 6] << 8) |
640 skb->data[cbIVOffset + 4 + 24 + 6 + 1];
641 69
642 pr_debug("wEtherType = %04x\n", wEtherType); 70 for (r = RATE_1M; r < MAX_RATE; r++) {
643 if (wEtherType == ETH_P_PAE) { 71 if (*rx_rate == rate[r])
644 skb->dev = pDevice->apdev; 72 break;
645
646 if (bIsWEP) {
647 // strip IV header(8)
648 memcpy(&abyMacHdr[0], (skb->data + 4), 24);
649 memcpy((skb->data + 4 + cbIVOffset), &abyMacHdr[0], 24);
650 }
651 skb->data += (cbIVOffset + 4);
652 skb->tail += (cbIVOffset + 4);
653 skb_put(skb, FrameSize);
654 skb_reset_mac_header(skb);
655
656 skb->pkt_type = PACKET_OTHERHOST;
657 skb->protocol = htons(ETH_P_802_2);
658 memset(skb->cb, 0, sizeof(skb->cb));
659 netif_rx(skb);
660 return true;
661
662 }
663 // check if 802.1x authorized
664 if (!(pMgmt->sNodeDBTable[iSANodeIndex].dwFlags & WLAN_STA_AUTHORIZED))
665 return false;
666 } 73 }
667 74
668 if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) { 75 priv->rx_rate = r;
669 if (bIsWEP)
670 FrameSize -= 8; //MIC
671 }
672
673 //--------------------------------------------------------------------------------
674 // Soft MIC
675 if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) {
676 if (bIsWEP) {
677 __le32 *pdwMIC_L;
678 __le32 *pdwMIC_R;
679 __le32 dwMIC_Priority;
680 __le32 dwMICKey0 = 0, dwMICKey1 = 0;
681 u32 dwLocalMIC_L = 0;
682 u32 dwLocalMIC_R = 0;
683 viawget_wpa_header *wpahdr;
684
685 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
686 dwMICKey0 = cpu_to_le32(*(u32 *)(&pKey->abyKey[24]));
687 dwMICKey1 = cpu_to_le32(*(u32 *)(&pKey->abyKey[28]));
688 } else {
689 if (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
690 dwMICKey0 = cpu_to_le32(*(u32 *)(&pKey->abyKey[16]));
691 dwMICKey1 = cpu_to_le32(*(u32 *)(&pKey->abyKey[20]));
692 } else if ((pKey->dwKeyIndex & BIT28) == 0) {
693 dwMICKey0 = cpu_to_le32(*(u32 *)(&pKey->abyKey[16]));
694 dwMICKey1 = cpu_to_le32(*(u32 *)(&pKey->abyKey[20]));
695 } else {
696 dwMICKey0 = cpu_to_le32(*(u32 *)(&pKey->abyKey[24]));
697 dwMICKey1 = cpu_to_le32(*(u32 *)(&pKey->abyKey[28]));
698 }
699 }
700
701 MIC_vInit(dwMICKey0, dwMICKey1);
702 MIC_vAppend((unsigned char *)&(pDevice->sRxEthHeader.abyDstAddr[0]), 12);
703 dwMIC_Priority = 0;
704 MIC_vAppend((unsigned char *)&dwMIC_Priority, 4);
705 // 4 is Rcv buffer header, 24 is MAC Header, and 8 is IV and Ext IV.
706 MIC_vAppend((unsigned char *)(skb->data + 4 + WLAN_HDR_ADDR3_LEN + 8),
707 FrameSize - WLAN_HDR_ADDR3_LEN - 8);
708 MIC_vGetMIC(&dwLocalMIC_L, &dwLocalMIC_R);
709 MIC_vUnInit();
710
711 pdwMIC_L = (__le32 *)(skb->data + 4 + FrameSize);
712 pdwMIC_R = (__le32 *)(skb->data + 4 + FrameSize + 4);
713
714 if ((le32_to_cpu(*pdwMIC_L) != dwLocalMIC_L) ||
715 (le32_to_cpu(*pdwMIC_R) != dwLocalMIC_R) ||
716 pDevice->bRxMICFail) {
717 pr_debug("MIC comparison is fail!\n");
718 pDevice->bRxMICFail = false;
719 pDevice->s802_11Counter.TKIPLocalMICFailures++;
720 if (bDeFragRx) {
721 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
722 pr_err("%s: can not alloc more frag bufs\n",
723 pDevice->dev->name);
724 }
725 }
726 //2008-0409-07, <Add> by Einsn Liu
727#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
728 //send event to wpa_supplicant
729 {
730 union iwreq_data wrqu;
731 struct iw_michaelmicfailure ev;
732 int keyidx = pbyFrame[cbHeaderSize+3] >> 6; //top two-bits
733
734 memset(&ev, 0, sizeof(ev));
735 ev.flags = keyidx & IW_MICFAILURE_KEY_ID;
736 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
737 (pMgmt->eCurrState == WMAC_STATE_ASSOC) &&
738 (*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) == 0) {
739 ev.flags |= IW_MICFAILURE_PAIRWISE;
740 } else {
741 ev.flags |= IW_MICFAILURE_GROUP;
742 }
743
744 ev.src_addr.sa_family = ARPHRD_ETHER;
745 memcpy(ev.src_addr.sa_data, pMACHeader->abyAddr2, ETH_ALEN);
746 memset(&wrqu, 0, sizeof(wrqu));
747 wrqu.data.length = sizeof(ev);
748 wireless_send_event(pDevice->dev, IWEVMICHAELMICFAILURE, &wrqu, (char *)&ev);
749
750 }
751#endif
752 76
753 if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) { 77 for (ii = 0; ii < sband->n_bitrates; ii++) {
754 wpahdr = (viawget_wpa_header *)pDevice->skb->data; 78 if (sband->bitrates[ii].hw_value == r) {
755 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && 79 rate_idx = ii;
756 (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC) && 80 break;
757 (*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) == 0) {
758 wpahdr->type = VIAWGET_PTK_MIC_MSG;
759 } else {
760 wpahdr->type = VIAWGET_GTK_MIC_MSG;
761 }
762 wpahdr->resp_ie_len = 0;
763 wpahdr->req_ie_len = 0;
764 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
765 pDevice->skb->dev = pDevice->wpadev;
766 skb_reset_mac_header(pDevice->skb);
767 pDevice->skb->pkt_type = PACKET_HOST;
768 pDevice->skb->protocol = htons(ETH_P_802_2);
769 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
770 netif_rx(pDevice->skb);
771 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
772 }
773
774 return false;
775
776 }
777 }
778 } //---end of SOFT MIC-----------------------------------------------------------------------
779
780 // ++++++++++ Reply Counter Check +++++++++++++
781
782 if ((pKey != NULL) && ((pKey->byCipherSuite == KEY_CTL_TKIP) ||
783 (pKey->byCipherSuite == KEY_CTL_CCMP))) {
784 if (bIsWEP) {
785 unsigned short wLocalTSC15_0 = 0;
786 unsigned long dwLocalTSC47_16 = 0;
787 unsigned long long RSC = 0;
788 // endian issues
789 RSC = *((unsigned long long *)&(pKey->KeyRSC));
790 wLocalTSC15_0 = (unsigned short)RSC;
791 dwLocalTSC47_16 = (unsigned long)(RSC>>16);
792
793 RSC = dwRxTSC47_16;
794 RSC <<= 16;
795 RSC += wRxTSC15_0;
796 pKey->KeyRSC = RSC;
797
798 if ((pDevice->sMgmtObj.eCurrMode == WMAC_MODE_ESS_STA) &&
799 (pDevice->sMgmtObj.eCurrState == WMAC_STATE_ASSOC)) {
800 // check RSC
801 if ((wRxTSC15_0 < wLocalTSC15_0) &&
802 (dwRxTSC47_16 <= dwLocalTSC47_16) &&
803 !((dwRxTSC47_16 == 0) && (dwLocalTSC47_16 == 0xFFFFFFFF))) {
804 pr_debug("TSC is illegal~~!\n ");
805 if (pKey->byCipherSuite == KEY_CTL_TKIP)
806 pDevice->s802_11Counter.TKIPReplays++;
807 else
808 pDevice->s802_11Counter.CCMPReplays++;
809
810 if (bDeFragRx) {
811 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
812 pr_err("%s: can not alloc more frag bufs\n",
813 pDevice->dev->name);
814 }
815 }
816 return false;
817 }
818 }
819 }
820 } // ----- End of Reply Counter Check --------------------------
821
822 s_vProcessRxMACHeader(pDevice, (unsigned char *)(skb->data+4), FrameSize, bIsWEP, bExtIV, &cbHeaderOffset);
823 FrameSize -= cbHeaderOffset;
824 cbHeaderOffset += 4; // 4 is Rcv buffer header
825
826 // Null data, framesize = 14
827 if (FrameSize < 15)
828 return false;
829
830 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
831 if (!s_bAPModeRxData(pDevice,
832 skb,
833 FrameSize,
834 cbHeaderOffset,
835 iSANodeIndex,
836 iDANodeIndex
837)) {
838 if (bDeFragRx) {
839 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
840 pr_err("%s: can not alloc more frag bufs\n",
841 pDevice->dev->name);
842 }
843 }
844 return false;
845 } 81 }
846 } 82 }
847 83
848 skb->data += cbHeaderOffset; 84 if (ii == sband->n_bitrates) {
849 skb->tail += cbHeaderOffset; 85 dev_dbg(&priv->pcid->dev, "Wrong RxRate %x\n", *rx_rate);
850 skb_put(skb, FrameSize);
851 skb->protocol = eth_type_trans(skb, skb->dev);
852
853 //drop frame not met IEEE 802.3
854
855 skb->ip_summed = CHECKSUM_NONE;
856 pStats->rx_bytes += skb->len;
857 pStats->rx_packets++;
858 netif_rx(skb);
859
860 if (bDeFragRx) {
861 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
862 pr_err("%s: can not alloc more frag bufs\n",
863 pDevice->dev->name);
864 }
865 return false; 86 return false;
866 } 87 }
867 88
868 return true; 89 tsf_time = (__le64 *)(skb_data + bytes_received - 12);
869} 90 sq = skb_data + bytes_received - 4;
870 91 new_rsr = skb_data + bytes_received - 3;
871static bool s_bAPModeRxCtl( 92 rssi = skb_data + bytes_received - 2;
872 struct vnt_private *pDevice, 93 rsr = skb_data + bytes_received - 1;
873 unsigned char *pbyFrame,
874 int iSANodeIndex
875)
876{
877 PS802_11Header p802_11Header;
878 CMD_STATUS Status;
879 PSMgmtObject pMgmt = pDevice->pMgmt;
880
881 if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) {
882 p802_11Header = (PS802_11Header)(pbyFrame);
883 if (!IS_TYPE_MGMT(pbyFrame)) {
884 // Data & PS-Poll packet
885 // check frame class
886 if (iSANodeIndex > 0) {
887 // frame class 3 fliter & checking
888 if (pMgmt->sNodeDBTable[iSANodeIndex].eNodeState < NODE_AUTH) {
889 // send deauth notification
890 // reason = (6) class 2 received from nonauth sta
891 vMgrDeAuthenBeginSta(pDevice,
892 pMgmt,
893 (unsigned char *)(p802_11Header->abyAddr2),
894 (WLAN_MGMT_REASON_CLASS2_NONAUTH),
895 &Status
896);
897 pr_debug("dpc: send vMgrDeAuthenBeginSta 1\n");
898 return true;
899 }
900 if (pMgmt->sNodeDBTable[iSANodeIndex].eNodeState < NODE_ASSOC) {
901 // send deassoc notification
902 // reason = (7) class 3 received from nonassoc sta
903 vMgrDisassocBeginSta(pDevice,
904 pMgmt,
905 (unsigned char *)(p802_11Header->abyAddr2),
906 (WLAN_MGMT_REASON_CLASS3_NONASSOC),
907 &Status
908);
909 pr_debug("dpc: send vMgrDisassocBeginSta 2\n");
910 return true;
911 }
912
913 if (pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable) {
914 // delcare received ps-poll event
915 if (IS_CTL_PSPOLL(pbyFrame)) {
916 pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = true;
917 bScheduleCommand((void *)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
918 pr_debug("dpc: WLAN_CMD_RX_PSPOLL 1\n");
919 } else {
920 // check Data PS state
921 // if PW bit off, send out all PS bufferring packets.
922 if (!IS_FC_POWERMGT(pbyFrame)) {
923 pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = false;
924 pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = true;
925 bScheduleCommand((void *)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
926 pr_debug("dpc: WLAN_CMD_RX_PSPOLL 2\n");
927 }
928 }
929 } else {
930 if (IS_FC_POWERMGT(pbyFrame)) {
931 pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = true;
932 // Once if STA in PS state, enable multicast bufferring
933 pMgmt->sNodeDBTable[0].bPSEnable = true;
934 } else {
935 // clear all pending PS frame.
936 if (pMgmt->sNodeDBTable[iSANodeIndex].wEnQueueCnt > 0) {
937 pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = false;
938 pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = true;
939 bScheduleCommand((void *)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
940 pr_debug("dpc: WLAN_CMD_RX_PSPOLL 3\n");
941
942 }
943 }
944 }
945 } else {
946 vMgrDeAuthenBeginSta(pDevice,
947 pMgmt,
948 (unsigned char *)(p802_11Header->abyAddr2),
949 (WLAN_MGMT_REASON_CLASS2_NONAUTH),
950 &Status
951);
952 pr_debug("dpc: send vMgrDeAuthenBeginSta 3\n");
953 pr_debug("BSSID:%pM\n",
954 p802_11Header->abyAddr3);
955 pr_debug("ADDR2:%pM\n",
956 p802_11Header->abyAddr2);
957 pr_debug("ADDR1:%pM\n",
958 p802_11Header->abyAddr1);
959 pr_debug("dpc: wFrameCtl= %x\n",
960 p802_11Header->wFrameCtl);
961 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byRxMode));
962 pr_debug("dpc:pDevice->byRxMode = %x\n",
963 pDevice->byRxMode);
964 return true;
965 }
966 }
967 }
968 return false;
969}
970
971static bool s_bHandleRxEncryption(
972 struct vnt_private *pDevice,
973 unsigned char *pbyFrame,
974 unsigned int FrameSize,
975 unsigned char *pbyRsr,
976 unsigned char *pbyNewRsr,
977 PSKeyItem *pKeyOut,
978 bool *pbExtIV,
979 unsigned short *pwRxTSC15_0,
980 unsigned long *pdwRxTSC47_16
981)
982{
983 unsigned int PayloadLen = FrameSize;
984 unsigned char *pbyIV;
985 unsigned char byKeyIdx;
986 PSKeyItem pKey = NULL;
987 unsigned char byDecMode = KEY_CTL_WEP;
988 PSMgmtObject pMgmt = pDevice->pMgmt;
989 94
990 *pwRxTSC15_0 = 0; 95 RFvRSSITodBm(priv, *rssi, &rx_dbm);
991 *pdwRxTSC47_16 = 0;
992 96
993 pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN; 97 priv->byBBPreEDRSSI = (u8)rx_dbm + 1;
994 if (WLAN_GET_FC_TODS(*(unsigned short *)pbyFrame) && 98 priv->uCurrRSSI = *rssi;
995 WLAN_GET_FC_FROMDS(*(unsigned short *)pbyFrame)) {
996 pbyIV += 6; // 6 is 802.11 address4
997 PayloadLen -= 6;
998 }
999 byKeyIdx = (*(pbyIV+3) & 0xc0);
1000 byKeyIdx >>= 6;
1001 pr_debug("\nKeyIdx: %d\n", byKeyIdx);
1002 99
1003 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA) || 100 skb_pull(skb, 4);
1004 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) || 101 skb_trim(skb, frame_size);
1005 (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) ||
1006 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
1007 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
1008 if (((*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) == 0) &&
1009 (pDevice->pMgmt->byCSSPK != KEY_CTL_NONE)) {
1010 // unicast pkt use pairwise key
1011 pr_debug("unicast pkt\n");
1012 if (KeybGetKey(&(pDevice->sKey), pDevice->abyBSSID, 0xFFFFFFFF, &pKey) == true) {
1013 if (pDevice->pMgmt->byCSSPK == KEY_CTL_TKIP)
1014 byDecMode = KEY_CTL_TKIP;
1015 else if (pDevice->pMgmt->byCSSPK == KEY_CTL_CCMP)
1016 byDecMode = KEY_CTL_CCMP;
1017 }
1018 pr_debug("unicast pkt: %d, %p\n", byDecMode, pKey);
1019 } else {
1020 // use group key
1021 KeybGetKey(&(pDevice->sKey), pDevice->abyBSSID, byKeyIdx, &pKey);
1022 if (pDevice->pMgmt->byCSSGK == KEY_CTL_TKIP)
1023 byDecMode = KEY_CTL_TKIP;
1024 else if (pDevice->pMgmt->byCSSGK == KEY_CTL_CCMP)
1025 byDecMode = KEY_CTL_CCMP;
1026 pr_debug("group pkt: %d, %d, %p\n",
1027 byKeyIdx, byDecMode, pKey);
1028 }
1029 }
1030 // our WEP only support Default Key
1031 if (pKey == NULL) {
1032 // use default group key
1033 KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, byKeyIdx, &pKey);
1034 if (pDevice->pMgmt->byCSSGK == KEY_CTL_TKIP)
1035 byDecMode = KEY_CTL_TKIP;
1036 else if (pDevice->pMgmt->byCSSGK == KEY_CTL_CCMP)
1037 byDecMode = KEY_CTL_CCMP;
1038 }
1039 *pKeyOut = pKey;
1040 102
1041 pr_debug("AES:%d %d %d\n", 103 rx_status.mactime = le64_to_cpu(*tsf_time);
1042 pDevice->pMgmt->byCSSPK, pDevice->pMgmt->byCSSGK, byDecMode); 104 rx_status.band = hw->conf.chandef.chan->band;
105 rx_status.signal = rx_dbm;
106 rx_status.flag = 0;
107 rx_status.freq = hw->conf.chandef.chan->center_freq;
1043 108
1044 if (pKey == NULL) { 109 hdr = (struct ieee80211_hdr *)(skb->data);
1045 pr_debug("pKey == NULL\n"); 110 fc = hdr->frame_control;
1046 111
1047 return false; 112 rx_status.rate_idx = rate_idx;
1048 }
1049 if (byDecMode != pKey->byCipherSuite) {
1050 113
1051 *pKeyOut = NULL; 114 if (ieee80211_has_protected(fc)) {
1052 return false; 115 if (priv->byLocalID > REV_ID_VT3253_A1)
116 rx_status.flag = RX_FLAG_DECRYPTED;
1053 } 117 }
1054 if (byDecMode == KEY_CTL_WEP) {
1055 // handle WEP
1056 if ((pDevice->byLocalID <= REV_ID_VT3253_A1) ||
1057 (((PSKeyTable)(pKey->pvKeyTable))->bSoftWEP == true)) {
1058 // Software WEP
1059 // 1. 3253A
1060 // 2. WEP 256
1061
1062 PayloadLen -= (WLAN_HDR_ADDR3_LEN + 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
1063 memcpy(pDevice->abyPRNG, pbyIV, 3);
1064 memcpy(pDevice->abyPRNG + 3, pKey->abyKey, pKey->uKeyLength);
1065 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pKey->uKeyLength + 3);
1066 rc4_encrypt(&pDevice->SBox, pbyIV+4, pbyIV+4, PayloadLen);
1067
1068 if (ETHbIsBufferCrc32Ok(pbyIV+4, PayloadLen))
1069 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1070
1071 }
1072 } else if ((byDecMode == KEY_CTL_TKIP) ||
1073 (byDecMode == KEY_CTL_CCMP)) {
1074 // TKIP/AES
1075
1076 PayloadLen -= (WLAN_HDR_ADDR3_LEN + 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
1077 *pdwRxTSC47_16 = cpu_to_le32(*(unsigned long *)(pbyIV + 4));
1078 pr_debug("ExtIV: %lx\n", *pdwRxTSC47_16);
1079 if (byDecMode == KEY_CTL_TKIP)
1080 *pwRxTSC15_0 = cpu_to_le16(MAKEWORD(*(pbyIV + 2), *pbyIV));
1081 else
1082 *pwRxTSC15_0 = cpu_to_le16(*(unsigned short *)pbyIV);
1083
1084 pr_debug("TSC0_15: %x\n", *pwRxTSC15_0);
1085
1086 if ((byDecMode == KEY_CTL_TKIP) &&
1087 (pDevice->byLocalID <= REV_ID_VT3253_A1)) {
1088 // Software TKIP
1089 // 1. 3253 A
1090 PS802_11Header pMACHeader = (PS802_11Header)(pbyFrame);
1091
1092 TKIPvMixKey(pKey->abyKey, pMACHeader->abyAddr2, *pwRxTSC15_0, *pdwRxTSC47_16, pDevice->abyPRNG);
1093 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
1094 rc4_encrypt(&pDevice->SBox, pbyIV+8, pbyIV+8, PayloadLen);
1095 if (ETHbIsBufferCrc32Ok(pbyIV+8, PayloadLen)) {
1096 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1097 pr_debug("ICV OK!\n");
1098 } else {
1099 pr_debug("ICV FAIL!!!\n");
1100 pr_debug("PayloadLen = %d\n", PayloadLen);
1101 }
1102 }
1103 }// end of TKIP/AES
1104
1105 if ((*(pbyIV+3) & 0x20) != 0)
1106 *pbExtIV = true;
1107 return true;
1108}
1109
1110static bool s_bHostWepRxEncryption(
1111 struct vnt_private *pDevice,
1112 unsigned char *pbyFrame,
1113 unsigned int FrameSize,
1114 unsigned char *pbyRsr,
1115 bool bOnFly,
1116 PSKeyItem pKey,
1117 unsigned char *pbyNewRsr,
1118 bool *pbExtIV,
1119 unsigned short *pwRxTSC15_0,
1120 unsigned long *pdwRxTSC47_16
1121)
1122{
1123 unsigned int PayloadLen = FrameSize;
1124 unsigned char *pbyIV;
1125 unsigned char byKeyIdx;
1126 unsigned char byDecMode = KEY_CTL_WEP;
1127 PS802_11Header pMACHeader;
1128 118
1129 *pwRxTSC15_0 = 0; 119 if (priv->vif && priv->bDiversityEnable) {
1130 *pdwRxTSC47_16 = 0; 120 if (ieee80211_is_data(fc) &&
1131 121 (frame_size > 50) && priv->vif->bss_conf.assoc)
1132 pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN; 122 BBvAntennaDiversity(priv, priv->rx_rate, 0);
1133 if (WLAN_GET_FC_TODS(*(unsigned short *)pbyFrame) &&
1134 WLAN_GET_FC_FROMDS(*(unsigned short *)pbyFrame)) {
1135 pbyIV += 6; // 6 is 802.11 address4
1136 PayloadLen -= 6;
1137 } 123 }
1138 byKeyIdx = (*(pbyIV+3) & 0xc0);
1139 byKeyIdx >>= 6;
1140 pr_debug("\nKeyIdx: %d\n", byKeyIdx);
1141
1142 if (pDevice->pMgmt->byCSSGK == KEY_CTL_TKIP)
1143 byDecMode = KEY_CTL_TKIP;
1144 else if (pDevice->pMgmt->byCSSGK == KEY_CTL_CCMP)
1145 byDecMode = KEY_CTL_CCMP;
1146
1147 pr_debug("AES:%d %d %d\n",
1148 pDevice->pMgmt->byCSSPK, pDevice->pMgmt->byCSSGK, byDecMode);
1149
1150 if (byDecMode != pKey->byCipherSuite)
1151 return false;
1152
1153 if (byDecMode == KEY_CTL_WEP) {
1154 // handle WEP
1155 pr_debug("byDecMode == KEY_CTL_WEP\n");
1156
1157 if ((pDevice->byLocalID <= REV_ID_VT3253_A1) ||
1158 (((PSKeyTable)(pKey->pvKeyTable))->bSoftWEP == true) ||
1159 !bOnFly) {
1160 // Software WEP
1161 // 1. 3253A
1162 // 2. WEP 256
1163 // 3. NotOnFly
1164 124
1165 PayloadLen -= (WLAN_HDR_ADDR3_LEN + 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc 125 memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, sizeof(rx_status));
1166 memcpy(pDevice->abyPRNG, pbyIV, 3);
1167 memcpy(pDevice->abyPRNG + 3, pKey->abyKey, pKey->uKeyLength);
1168 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pKey->uKeyLength + 3);
1169 rc4_encrypt(&pDevice->SBox, pbyIV+4, pbyIV+4, PayloadLen);
1170 126
1171 if (ETHbIsBufferCrc32Ok(pbyIV+4, PayloadLen)) 127 ieee80211_rx_irqsafe(priv->hw, skb);
1172 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1173 128
1174 }
1175 } else if ((byDecMode == KEY_CTL_TKIP) ||
1176 (byDecMode == KEY_CTL_CCMP)) {
1177 // TKIP/AES
1178
1179 PayloadLen -= (WLAN_HDR_ADDR3_LEN + 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
1180 *pdwRxTSC47_16 = cpu_to_le32(*(unsigned long *)(pbyIV + 4));
1181 pr_debug("ExtIV: %lx\n", *pdwRxTSC47_16);
1182
1183 if (byDecMode == KEY_CTL_TKIP)
1184 *pwRxTSC15_0 = cpu_to_le16(MAKEWORD(*(pbyIV+2), *pbyIV));
1185 else
1186 *pwRxTSC15_0 = cpu_to_le16(*(unsigned short *)pbyIV);
1187
1188 pr_debug("TSC0_15: %x\n", *pwRxTSC15_0);
1189
1190 if (byDecMode == KEY_CTL_TKIP) {
1191 if ((pDevice->byLocalID <= REV_ID_VT3253_A1) || !bOnFly) {
1192 // Software TKIP
1193 // 1. 3253 A
1194 // 2. NotOnFly
1195 pr_debug("soft KEY_CTL_TKIP\n");
1196 pMACHeader = (PS802_11Header)(pbyFrame);
1197 TKIPvMixKey(pKey->abyKey, pMACHeader->abyAddr2, *pwRxTSC15_0, *pdwRxTSC47_16, pDevice->abyPRNG);
1198 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
1199 rc4_encrypt(&pDevice->SBox, pbyIV+8, pbyIV+8, PayloadLen);
1200 if (ETHbIsBufferCrc32Ok(pbyIV+8, PayloadLen)) {
1201 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1202 pr_debug("ICV OK!\n");
1203 } else {
1204 pr_debug("ICV FAIL!!!\n");
1205 pr_debug("PayloadLen = %d\n",
1206 PayloadLen);
1207 }
1208 }
1209 }
1210
1211 if (byDecMode == KEY_CTL_CCMP) {
1212 if (!bOnFly) {
1213 // Software CCMP
1214 // NotOnFly
1215 pr_debug("soft KEY_CTL_CCMP\n");
1216 if (AESbGenCCMP(pKey->abyKey, pbyFrame, FrameSize)) {
1217 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1218 pr_debug("CCMP MIC compare OK!\n");
1219 } else {
1220 pr_debug("CCMP MIC fail!\n");
1221 }
1222 }
1223 }
1224
1225 }// end of TKIP/AES
1226
1227 if ((*(pbyIV+3) & 0x20) != 0)
1228 *pbExtIV = true;
1229 return true; 129 return true;
1230} 130}
1231 131
1232static bool s_bAPModeRxData( 132bool vnt_receive_frame(struct vnt_private *priv, PSRxDesc curr_rd)
1233 struct vnt_private *pDevice,
1234 struct sk_buff *skb,
1235 unsigned int FrameSize,
1236 unsigned int cbHeaderOffset,
1237 int iSANodeIndex,
1238 int iDANodeIndex
1239)
1240{ 133{
1241 PSMgmtObject pMgmt = pDevice->pMgmt; 134 PDEVICE_RD_INFO rd_info = curr_rd->pRDInfo;
1242 bool bRelayAndForward = false; 135 struct sk_buff *skb;
1243 bool bRelayOnly = false; 136 u16 frame_size;
1244 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1245 unsigned short wAID;
1246
1247 struct sk_buff *skbcpy = NULL;
1248 137
1249 if (FrameSize > CB_MAX_BUF_SIZE) 138 skb = rd_info->skb;
1250 return false;
1251 // check DA
1252 if (is_multicast_ether_addr((unsigned char *)(skb->data+cbHeaderOffset))) {
1253 if (pMgmt->sNodeDBTable[0].bPSEnable) {
1254 skbcpy = dev_alloc_skb((int)pDevice->rx_buf_sz);
1255 139
1256 // if any node in PS mode, buffer packet until DTIM. 140 pci_unmap_single(priv->pcid, rd_info->skb_dma,
1257 if (skbcpy == NULL) { 141 priv->rx_buf_sz, PCI_DMA_FROMDEVICE);
1258 pr_info("relay multicast no skb available\n");
1259 } else {
1260 skbcpy->dev = pDevice->dev;
1261 skbcpy->len = FrameSize;
1262 memcpy(skbcpy->data, skb->data+cbHeaderOffset, FrameSize);
1263 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skbcpy);
1264 142
1265 pMgmt->sNodeDBTable[0].wEnQueueCnt++; 143 frame_size = le16_to_cpu(curr_rd->m_rd1RD1.wReqCount)
1266 // set tx map 144 - cpu_to_le16(curr_rd->m_rd0RD0.wResCount);
1267 pMgmt->abyPSTxMap[0] |= byMask[0];
1268 }
1269 } else {
1270 bRelayAndForward = true;
1271 }
1272 } else {
1273 // check if relay
1274 if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data+cbHeaderOffset), &iDANodeIndex)) {
1275 if (pMgmt->sNodeDBTable[iDANodeIndex].eNodeState >= NODE_ASSOC) {
1276 if (pMgmt->sNodeDBTable[iDANodeIndex].bPSEnable) {
1277 // queue this skb until next PS tx, and then release.
1278 145
1279 skb->data += cbHeaderOffset; 146 if ((frame_size > 2364) || (frame_size < 33)) {
1280 skb->tail += cbHeaderOffset; 147 /* Frame Size error drop this packet.*/
1281 skb_put(skb, FrameSize); 148 dev_dbg(&priv->pcid->dev, "Wrong frame size %d\n", frame_size);
1282 skb_queue_tail(&pMgmt->sNodeDBTable[iDANodeIndex].sTxPSQueue, skb); 149 dev_kfree_skb_irq(skb);
1283 pMgmt->sNodeDBTable[iDANodeIndex].wEnQueueCnt++; 150 return true;
1284 wAID = pMgmt->sNodeDBTable[iDANodeIndex].wAID;
1285 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1286 pr_debug("relay: index= %d, pMgmt->abyPSTxMap[%d]= %d\n",
1287 iDANodeIndex, (wAID >> 3),
1288 pMgmt->abyPSTxMap[wAID >> 3]);
1289 return true;
1290 } else {
1291 bRelayOnly = true;
1292 }
1293 }
1294 }
1295 } 151 }
1296 152
1297 if (bRelayOnly || bRelayAndForward) { 153 if (vnt_rx_data(priv, skb, frame_size))
1298 // relay this packet right now 154 return true;
1299 if (bRelayAndForward)
1300 iDANodeIndex = 0;
1301 155
1302 if ((pDevice->uAssocCount > 1) && (iDANodeIndex >= 0)) 156 dev_kfree_skb_irq(skb);
1303 ROUTEbRelay(pDevice, (unsigned char *)(skb->data + cbHeaderOffset), FrameSize, (unsigned int)iDANodeIndex);
1304
1305 if (bRelayOnly)
1306 return false;
1307 }
1308 // none associate, don't forward
1309 if (pDevice->uAssocCount == 0)
1310 return false;
1311 157
1312 return true; 158 return true;
1313} 159}
diff --git a/drivers/staging/vt6655/dpc.h b/drivers/staging/vt6655/dpc.h
index a068b846b1be..ad495719a251 100644
--- a/drivers/staging/vt6655/dpc.h
+++ b/drivers/staging/vt6655/dpc.h
@@ -29,14 +29,8 @@
29#ifndef __DPC_H__ 29#ifndef __DPC_H__
30#define __DPC_H__ 30#define __DPC_H__
31 31
32#include "ttype.h"
33#include "device.h" 32#include "device.h"
34#include "wcmd.h"
35 33
36bool 34bool vnt_receive_frame(struct vnt_private *priv, PSRxDesc curr_rd);
37device_receive_frame(
38 struct vnt_private *,
39 PSRxDesc pCurrRD
40);
41 35
42#endif // __RXTX_H__ 36#endif /* __RXTX_H__ */
diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
deleted file mode 100644
index ae0dade229d8..000000000000
--- a/drivers/staging/vt6655/hostap.c
+++ /dev/null
@@ -1,765 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: hostap.c
20 *
21 * Purpose: handle hostap deamon ioctl input/out functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: Oct. 20, 2003
26 *
27 * Functions:
28 *
29 * Revision History:
30 *
31 */
32
33#include "hostap.h"
34#include "iocmd.h"
35#include "mac.h"
36#include "card.h"
37#include "baseband.h"
38#include "wpactl.h"
39#include "key.h"
40
41#define VIAWGET_HOSTAPD_MAX_BUF_SIZE 1024
42#define HOSTAP_CRYPT_FLAG_SET_TX_KEY BIT0
43#define HOSTAP_CRYPT_ERR_UNKNOWN_ADDR 3
44#define HOSTAP_CRYPT_ERR_KEY_SET_FAILED 5
45
46/*--------------------- Static Definitions -------------------------*/
47
48/*--------------------- Static Classes ----------------------------*/
49
50/*--------------------- Static Functions --------------------------*/
51
52/*--------------------- Export Variables --------------------------*/
53
54/*
55 * Description:
56 * register net_device (AP) for hostap deamon
57 *
58 * Parameters:
59 * In:
60 * pDevice -
61 * rtnl_locked -
62 * Out:
63 *
64 * Return Value:
65 *
66 */
67
68static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
69{
70 struct vnt_private *apdev_priv;
71 struct net_device *dev = pDevice->dev;
72 int ret;
73 const struct net_device_ops apdev_netdev_ops = {
74 .ndo_start_xmit = pDevice->tx_80211,
75 };
76
77 pr_debug("%s: Enabling hostapd mode\n", dev->name);
78
79 pDevice->apdev = alloc_etherdev(sizeof(*apdev_priv));
80 if (pDevice->apdev == NULL)
81 return -ENOMEM;
82
83 apdev_priv = netdev_priv(pDevice->apdev);
84 *apdev_priv = *pDevice;
85 eth_hw_addr_inherit(pDevice->apdev, dev);
86
87 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
88
89 pDevice->apdev->type = ARPHRD_IEEE80211;
90
91 pDevice->apdev->base_addr = dev->base_addr;
92 pDevice->apdev->irq = dev->irq;
93 pDevice->apdev->mem_start = dev->mem_start;
94 pDevice->apdev->mem_end = dev->mem_end;
95 sprintf(pDevice->apdev->name, "%sap", dev->name);
96 if (rtnl_locked)
97 ret = register_netdevice(pDevice->apdev);
98 else
99 ret = register_netdev(pDevice->apdev);
100 if (ret) {
101 pr_debug("%s: register_netdevice(AP) failed!\n",
102 dev->name);
103 free_netdev(pDevice->apdev);
104 pDevice->apdev = NULL;
105 return -1;
106 }
107
108 pr_debug("%s: Registered netdevice %s for AP management\n",
109 dev->name, pDevice->apdev->name);
110
111 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
112
113 return 0;
114}
115
116/*
117 * Description:
118 * unregister net_device(AP)
119 *
120 * Parameters:
121 * In:
122 * pDevice -
123 * rtnl_locked -
124 * Out:
125 *
126 * Return Value:
127 *
128 */
129
130static int hostap_disable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
131{
132 pr_debug("%s: disabling hostapd mode\n", pDevice->dev->name);
133
134 if (pDevice->apdev && pDevice->apdev->name && pDevice->apdev->name[0]) {
135 if (rtnl_locked)
136 unregister_netdevice(pDevice->apdev);
137 else
138 unregister_netdev(pDevice->apdev);
139 pr_debug("%s: Netdevice %s unregistered\n",
140 pDevice->dev->name, pDevice->apdev->name);
141 }
142 if (pDevice->apdev)
143 free_netdev(pDevice->apdev);
144 pDevice->apdev = NULL;
145 pDevice->bEnable8021x = false;
146 pDevice->bEnableHostWEP = false;
147 pDevice->bEncryptionEnable = false;
148
149/* 4.2007-0118-03,<Add> by EinsnLiu */
150/* execute some clear work */
151 pDevice->pMgmt->byCSSPK = KEY_CTL_NONE;
152 pDevice->pMgmt->byCSSGK = KEY_CTL_NONE;
153 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
154
155 return 0;
156}
157
158/*
159 * Description:
160 * Set enable/disable hostapd mode
161 *
162 * Parameters:
163 * In:
164 * pDevice -
165 * rtnl_locked -
166 * Out:
167 *
168 * Return Value:
169 *
170 */
171
172int vt6655_hostap_set_hostapd(struct vnt_private *pDevice,
173 int val, int rtnl_locked)
174{
175 if (val < 0 || val > 1)
176 return -EINVAL;
177
178 if (pDevice->bEnableHostapd == val)
179 return 0;
180
181 pDevice->bEnableHostapd = val;
182
183 if (val)
184 return hostap_enable_hostapd(pDevice, rtnl_locked);
185 else
186 return hostap_disable_hostapd(pDevice, rtnl_locked);
187}
188
189/*
190 * Description:
191 * remove station function supported for hostap deamon
192 *
193 * Parameters:
194 * In:
195 * pDevice -
196 * param -
197 * Out:
198 *
199 * Return Value:
200 *
201 */
202static int hostap_remove_sta(struct vnt_private *pDevice,
203 struct viawget_hostapd_param *param)
204{
205 unsigned int uNodeIndex;
206
207 if (BSSDBbIsSTAInNodeDB(pDevice->pMgmt, param->sta_addr, &uNodeIndex))
208 BSSvRemoveOneNode(pDevice, uNodeIndex);
209 else
210 return -ENOENT;
211
212 return 0;
213}
214
215/*
216 * Description:
217 * add a station from hostap deamon
218 *
219 * Parameters:
220 * In:
221 * pDevice -
222 * param -
223 * Out:
224 *
225 * Return Value:
226 *
227 */
228static int hostap_add_sta(struct vnt_private *pDevice,
229 struct viawget_hostapd_param *param)
230{
231 PSMgmtObject pMgmt = pDevice->pMgmt;
232 unsigned int uNodeIndex;
233
234 if (!BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex))
235 BSSvCreateOneNode(pDevice, &uNodeIndex);
236
237 memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, param->sta_addr, WLAN_ADDR_LEN);
238 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
239 pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = param->u.add_sta.capability;
240/* TODO listenInterval */
241 pMgmt->sNodeDBTable[uNodeIndex].bPSEnable = false;
242 pMgmt->sNodeDBTable[uNodeIndex].bySuppRate = param->u.add_sta.tx_supp_rates;
243
244 /* set max tx rate */
245 pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
246 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
247 /* set max basic rate */
248 pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate = RATE_2M;
249 /* Todo: check sta preamble, if ap can't support, set status code */
250 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
251 WLAN_GET_CAP_INFO_SHORTPREAMBLE(pMgmt->sNodeDBTable[uNodeIndex].wCapInfo);
252
253 pMgmt->sNodeDBTable[uNodeIndex].wAID = (unsigned short)param->u.add_sta.aid;
254
255 pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer = jiffies;
256
257 pr_debug("Add STA AID= %d\n", pMgmt->sNodeDBTable[uNodeIndex].wAID);
258 pr_debug("MAC=%pM\n", param->sta_addr);
259 pr_debug("Max Support rate = %d\n",
260 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
261
262 return 0;
263}
264
265/*
266 * Description:
267 * get station info
268 *
269 * Parameters:
270 * In:
271 * pDevice -
272 * param -
273 * Out:
274 *
275 * Return Value:
276 *
277 */
278
279static int hostap_get_info_sta(struct vnt_private *pDevice,
280 struct viawget_hostapd_param *param)
281{
282 PSMgmtObject pMgmt = pDevice->pMgmt;
283 unsigned int uNodeIndex;
284
285 if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) {
286 param->u.get_info_sta.inactive_sec =
287 (jiffies - pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer) / HZ;
288 } else {
289 return -ENOENT;
290 }
291
292 return 0;
293}
294
295/*
296 * Description:
297 * set station flag
298 *
299 * Parameters:
300 * In:
301 * pDevice -
302 * param -
303 * Out:
304 *
305 * Return Value:
306 *
307 */
308static int hostap_set_flags_sta(struct vnt_private *pDevice,
309 struct viawget_hostapd_param *param)
310{
311 PSMgmtObject pMgmt = pDevice->pMgmt;
312 unsigned int uNodeIndex;
313
314 if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) {
315 pMgmt->sNodeDBTable[uNodeIndex].dwFlags |= param->u.set_flags_sta.flags_or;
316 pMgmt->sNodeDBTable[uNodeIndex].dwFlags &= param->u.set_flags_sta.flags_and;
317 pr_debug(" dwFlags = %x\n",
318 (unsigned int)pMgmt->sNodeDBTable[uNodeIndex].dwFlags);
319 } else {
320 return -ENOENT;
321 }
322
323 return 0;
324}
325
326/*
327 * Description:
328 * set generic element (wpa ie)
329 *
330 * Parameters:
331 * In:
332 * pDevice -
333 * param -
334 * Out:
335 *
336 * Return Value:
337 *
338 */
339static int hostap_set_generic_element(struct vnt_private *pDevice,
340 struct viawget_hostapd_param *param)
341{
342 PSMgmtObject pMgmt = pDevice->pMgmt;
343
344 if (param->u.generic_elem.len > sizeof(pMgmt->abyWPAIE))
345 return -EINVAL;
346
347 memcpy(pMgmt->abyWPAIE,
348 param->u.generic_elem.data,
349 param->u.generic_elem.len
350 );
351
352 pMgmt->wWPAIELen = param->u.generic_elem.len;
353
354 pr_debug("pMgmt->wWPAIELen = %d\n", pMgmt->wWPAIELen);
355
356 /* disable wpa */
357 if (pMgmt->wWPAIELen == 0) {
358 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
359 pr_debug(" No WPAIE, Disable WPA\n");
360 } else {
361 /* enable wpa */
362 if ((pMgmt->abyWPAIE[0] == WLAN_EID_RSN_WPA) ||
363 (pMgmt->abyWPAIE[0] == WLAN_EID_RSN)) {
364 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
365 pr_debug("Set WPAIE enable WPA\n");
366 } else
367 return -EINVAL;
368 }
369
370 return 0;
371}
372
373/*
374 * Description:
375 * flush station nodes table.
376 *
377 * Parameters:
378 * In:
379 * pDevice -
380 * Out:
381 *
382 * Return Value:
383 *
384 */
385
386static void hostap_flush_sta(struct vnt_private *pDevice)
387{
388 /* reserved node index =0 for multicast node. */
389 BSSvClearNodeDBTable(pDevice, 1);
390 pDevice->uAssocCount = 0;
391}
392
393/*
394 * Description:
395 * set each stations encryption key
396 *
397 * Parameters:
398 * In:
399 * pDevice -
400 * param -
401 * Out:
402 *
403 * Return Value:
404 *
405 */
406static int hostap_set_encryption(struct vnt_private *pDevice,
407 struct viawget_hostapd_param *param,
408 int param_len)
409{
410 PSMgmtObject pMgmt = pDevice->pMgmt;
411 unsigned long dwKeyIndex = 0;
412 unsigned char abyKey[MAX_KEY_LEN];
413 unsigned char abySeq[MAX_KEY_LEN];
414 u64 KeyRSC;
415 unsigned char byKeyDecMode = KEY_CTL_WEP;
416 int iNodeIndex = -1;
417 int ii;
418 bool bKeyTableFull = false;
419 unsigned short wKeyCtl = 0;
420
421 param->u.crypt.err = 0;
422
423 if (param->u.crypt.alg > WPA_ALG_CCMP)
424 return -EINVAL;
425
426 if ((param->u.crypt.idx > 3) || (param->u.crypt.key_len > MAX_KEY_LEN)) {
427 param->u.crypt.err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
428 pr_debug(" HOSTAP_CRYPT_ERR_KEY_SET_FAILED\n");
429 return -EINVAL;
430 }
431
432 if (is_broadcast_ether_addr(param->sta_addr)) {
433 if (param->u.crypt.idx >= MAX_GROUP_KEY)
434 return -EINVAL;
435 iNodeIndex = 0;
436
437 } else {
438 if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &iNodeIndex) == false) {
439 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
440 pr_debug(" HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n");
441 return -EINVAL;
442 }
443 }
444 pr_debug(" hostap_set_encryption: sta_index %d\n", iNodeIndex);
445 pr_debug(" hostap_set_encryption: alg %d\n", param->u.crypt.alg);
446
447 if (param->u.crypt.alg == WPA_ALG_NONE) {
448 if (pMgmt->sNodeDBTable[iNodeIndex].bOnFly) {
449 if (!KeybRemoveKey(&(pDevice->sKey),
450 param->sta_addr,
451 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex,
452 pDevice->PortOffset)) {
453 pr_debug("KeybRemoveKey fail\n");
454 }
455 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false;
456 }
457 pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = 0;
458 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = 0;
459 pMgmt->sNodeDBTable[iNodeIndex].uWepKeyLength = 0;
460 pMgmt->sNodeDBTable[iNodeIndex].KeyRSC = 0;
461 pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0;
462 pMgmt->sNodeDBTable[iNodeIndex].wTSC15_0 = 0;
463 pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = 0;
464 memset(&pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
465 0,
466 MAX_KEY_LEN
467);
468
469 return 0;
470 }
471
472 memcpy(abyKey, param->u.crypt.key, param->u.crypt.key_len);
473 /* copy to node key tbl */
474 pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = param->u.crypt.idx;
475 pMgmt->sNodeDBTable[iNodeIndex].uWepKeyLength = param->u.crypt.key_len;
476 memcpy(&pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
477 param->u.crypt.key,
478 param->u.crypt.key_len
479);
480
481 dwKeyIndex = (unsigned long)(param->u.crypt.idx);
482 if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) {
483 pDevice->byKeyIndex = (unsigned char)dwKeyIndex;
484 pDevice->bTransmitKey = true;
485 dwKeyIndex |= (1 << 31);
486 }
487
488 if (param->u.crypt.alg == WPA_ALG_WEP) {
489 if ((pDevice->bEnable8021x == false) || (iNodeIndex == 0)) {
490 KeybSetDefaultKey(&(pDevice->sKey),
491 dwKeyIndex & ~(BIT30 | USE_KEYRSC),
492 param->u.crypt.key_len,
493 NULL,
494 abyKey,
495 KEY_CTL_WEP,
496 pDevice->PortOffset,
497 pDevice->byLocalID);
498
499 } else {
500 /* 8021x enable, individual key */
501 dwKeyIndex |= (1 << 30); /* set pairwise key */
502 if (KeybSetKey(&(pDevice->sKey),
503 &param->sta_addr[0],
504 dwKeyIndex & ~(USE_KEYRSC),
505 param->u.crypt.key_len,
506 (u64 *) &KeyRSC,
507 (unsigned char *)abyKey,
508 KEY_CTL_WEP,
509 pDevice->PortOffset,
510 pDevice->byLocalID)) {
511 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true;
512
513 } else {
514 /* Key Table Full */
515 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false;
516 bKeyTableFull = true;
517 }
518 }
519 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
520 pDevice->bEncryptionEnable = true;
521 pMgmt->byCSSPK = KEY_CTL_WEP;
522 pMgmt->byCSSGK = KEY_CTL_WEP;
523 pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = KEY_CTL_WEP;
524 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex;
525 return 0;
526 }
527
528 if (param->u.crypt.seq) {
529 memcpy(&abySeq, param->u.crypt.seq, 8);
530 for (ii = 0; ii < 8; ii++)
531 KeyRSC |= (u64)abySeq[ii] << (ii * 8);
532
533 dwKeyIndex |= 1 << 29;
534 pMgmt->sNodeDBTable[iNodeIndex].KeyRSC = KeyRSC;
535 }
536
537 if (param->u.crypt.alg == WPA_ALG_TKIP) {
538 if (param->u.crypt.key_len != MAX_KEY_LEN)
539 return -EINVAL;
540 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
541 byKeyDecMode = KEY_CTL_TKIP;
542 pMgmt->byCSSPK = KEY_CTL_TKIP;
543 pMgmt->byCSSGK = KEY_CTL_TKIP;
544 }
545
546 if (param->u.crypt.alg == WPA_ALG_CCMP) {
547 if ((param->u.crypt.key_len != AES_KEY_LEN) ||
548 (pDevice->byLocalID <= REV_ID_VT3253_A1))
549 return -EINVAL;
550 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
551 byKeyDecMode = KEY_CTL_CCMP;
552 pMgmt->byCSSPK = KEY_CTL_CCMP;
553 pMgmt->byCSSGK = KEY_CTL_CCMP;
554 }
555
556 if (iNodeIndex == 0) {
557 KeybSetDefaultKey(&(pDevice->sKey),
558 dwKeyIndex,
559 param->u.crypt.key_len,
560 (u64 *) &KeyRSC,
561 abyKey,
562 byKeyDecMode,
563 pDevice->PortOffset,
564 pDevice->byLocalID);
565 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true;
566
567 } else {
568 dwKeyIndex |= (1 << 30); /* set pairwise key */
569 if (KeybSetKey(&(pDevice->sKey),
570 &param->sta_addr[0],
571 dwKeyIndex,
572 param->u.crypt.key_len,
573 (u64 *) &KeyRSC,
574 (unsigned char *)abyKey,
575 byKeyDecMode,
576 pDevice->PortOffset,
577 pDevice->byLocalID)) {
578 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = true;
579
580 } else {
581 /* Key Table Full */
582 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = false;
583 bKeyTableFull = true;
584 pr_debug(" Key Table Full\n");
585 }
586
587 }
588
589 if (bKeyTableFull) {
590 wKeyCtl &= 0x7F00; /* clear all key control filed */
591 wKeyCtl |= (byKeyDecMode << 4);
592 wKeyCtl |= (byKeyDecMode);
593 wKeyCtl |= 0x0044; /* use group key for all address */
594 wKeyCtl |= 0x4000; /* disable KeyTable[MAX_KEY_TABLE-1] on-fly to genernate rx int */
595 MACvSetDefaultKeyCtl(pDevice->PortOffset, wKeyCtl, MAX_KEY_TABLE-1, pDevice->byLocalID);
596 }
597
598 pr_debug(" Set key sta_index= %d\n", iNodeIndex);
599 pr_debug(" tx_index=%d len=%d\n",
600 param->u.crypt.idx, param->u.crypt.key_len);
601 pr_debug(" key=%x-%x-%x-%x-%x-xxxxx\n",
602 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
603 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[1],
604 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[2],
605 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[3],
606 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[4]);
607
608 /* set wep key */
609 pDevice->bEncryptionEnable = true;
610 pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = byKeyDecMode;
611 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex;
612 pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0;
613 pMgmt->sNodeDBTable[iNodeIndex].wTSC15_0 = 0;
614
615 return 0;
616}
617
618/*
619 * Description:
620 * get each stations encryption key
621 *
622 * Parameters:
623 * In:
624 * pDevice -
625 * param -
626 * Out:
627 *
628 * Return Value:
629 *
630 */
631static int hostap_get_encryption(struct vnt_private *pDevice,
632 struct viawget_hostapd_param *param,
633 int param_len)
634{
635 PSMgmtObject pMgmt = pDevice->pMgmt;
636 int ii;
637 int iNodeIndex = 0;
638
639 param->u.crypt.err = 0;
640
641 if (is_broadcast_ether_addr(param->sta_addr)) {
642 iNodeIndex = 0;
643 } else {
644 if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &iNodeIndex) == false) {
645 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
646 pr_debug("hostap_get_encryption: HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n");
647 return -EINVAL;
648 }
649 }
650 pr_debug("hostap_get_encryption: %d\n", iNodeIndex);
651 memset(param->u.crypt.seq, 0, 8);
652 for (ii = 0; ii < 8; ii++)
653 param->u.crypt.seq[ii] = (unsigned char)pMgmt->sNodeDBTable[iNodeIndex].KeyRSC >> (ii * 8);
654
655 return 0;
656}
657
658/*
659 * Description:
660 * vt6655_hostap_ioctl main function supported for hostap deamon.
661 *
662 * Parameters:
663 * In:
664 * pDevice -
665 * iw_point -
666 * Out:
667 *
668 * Return Value:
669 *
670 */
671int vt6655_hostap_ioctl(struct vnt_private *pDevice, struct iw_point *p)
672{
673 struct viawget_hostapd_param *param;
674 int ret = 0;
675 int ap_ioctl = 0;
676
677 if (p->length < sizeof(struct viawget_hostapd_param) ||
678 p->length > VIAWGET_HOSTAPD_MAX_BUF_SIZE || !p->pointer)
679 return -EINVAL;
680
681 param = kmalloc((int)p->length, GFP_KERNEL);
682 if (param == NULL)
683 return -ENOMEM;
684
685 if (copy_from_user(param, p->pointer, p->length)) {
686 ret = -EFAULT;
687 goto out;
688 }
689
690 switch (param->cmd) {
691 case VIAWGET_HOSTAPD_SET_ENCRYPTION:
692 pr_debug("VIAWGET_HOSTAPD_SET_ENCRYPTION\n");
693 spin_lock_irq(&pDevice->lock);
694 ret = hostap_set_encryption(pDevice, param, p->length);
695 spin_unlock_irq(&pDevice->lock);
696 break;
697 case VIAWGET_HOSTAPD_GET_ENCRYPTION:
698 pr_debug("VIAWGET_HOSTAPD_GET_ENCRYPTION\n");
699 spin_lock_irq(&pDevice->lock);
700 ret = hostap_get_encryption(pDevice, param, p->length);
701 spin_unlock_irq(&pDevice->lock);
702 break;
703 case VIAWGET_HOSTAPD_SET_ASSOC_AP_ADDR:
704 pr_debug("VIAWGET_HOSTAPD_SET_ASSOC_AP_ADDR\n");
705 ret = -EOPNOTSUPP;
706 goto out;
707 case VIAWGET_HOSTAPD_FLUSH:
708 pr_debug("VIAWGET_HOSTAPD_FLUSH\n");
709 spin_lock_irq(&pDevice->lock);
710 hostap_flush_sta(pDevice);
711 spin_unlock_irq(&pDevice->lock);
712 break;
713 case VIAWGET_HOSTAPD_ADD_STA:
714 pr_debug("VIAWGET_HOSTAPD_ADD_STA\n");
715 spin_lock_irq(&pDevice->lock);
716 ret = hostap_add_sta(pDevice, param);
717 spin_unlock_irq(&pDevice->lock);
718 break;
719 case VIAWGET_HOSTAPD_REMOVE_STA:
720 pr_debug("VIAWGET_HOSTAPD_REMOVE_STA\n");
721 spin_lock_irq(&pDevice->lock);
722 ret = hostap_remove_sta(pDevice, param);
723 spin_unlock_irq(&pDevice->lock);
724 break;
725 case VIAWGET_HOSTAPD_GET_INFO_STA:
726 pr_debug("VIAWGET_HOSTAPD_GET_INFO_STA\n");
727 ret = hostap_get_info_sta(pDevice, param);
728 ap_ioctl = 1;
729 break;
730 case VIAWGET_HOSTAPD_SET_FLAGS_STA:
731 pr_debug("VIAWGET_HOSTAPD_SET_FLAGS_STA\n");
732 ret = hostap_set_flags_sta(pDevice, param);
733 break;
734 case VIAWGET_HOSTAPD_MLME:
735 pr_debug("VIAWGET_HOSTAPD_MLME\n");
736 ret = -EOPNOTSUPP;
737 goto out;
738 case VIAWGET_HOSTAPD_SET_GENERIC_ELEMENT:
739 pr_debug("VIAWGET_HOSTAPD_SET_GENERIC_ELEMENT\n");
740 ret = hostap_set_generic_element(pDevice, param);
741 break;
742 case VIAWGET_HOSTAPD_SCAN_REQ:
743 pr_debug("VIAWGET_HOSTAPD_SCAN_REQ\n");
744 ret = -EOPNOTSUPP;
745 goto out;
746 case VIAWGET_HOSTAPD_STA_CLEAR_STATS:
747 pr_debug("VIAWGET_HOSTAPD_STA_CLEAR_STATS\n");
748 ret = -EOPNOTSUPP;
749 goto out;
750 default:
751 pr_debug("vt6655_hostap_ioctl: unknown cmd=%d\n",
752 (int)param->cmd);
753 ret = -EOPNOTSUPP;
754 goto out;
755 }
756
757 if ((ret == 0) && ap_ioctl) {
758 if (copy_to_user(p->pointer, param, p->length))
759 ret = -EFAULT;
760 }
761
762out:
763 kfree(param);
764 return ret;
765}
diff --git a/drivers/staging/vt6655/hostap.h b/drivers/staging/vt6655/hostap.h
deleted file mode 100644
index 17df4e403fcf..000000000000
--- a/drivers/staging/vt6655/hostap.h
+++ /dev/null
@@ -1,58 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: hostap.h
20 *
21 * Purpose:
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 21, 2003
26 *
27 */
28
29#ifndef __HOSTAP_H__
30#define __HOSTAP_H__
31
32#include "device.h"
33
34#define WLAN_RATE_1M BIT0
35#define WLAN_RATE_2M BIT1
36#define WLAN_RATE_5M5 BIT2
37#define WLAN_RATE_11M BIT3
38#define WLAN_RATE_6M BIT4
39#define WLAN_RATE_9M BIT5
40#define WLAN_RATE_12M BIT6
41#define WLAN_RATE_18M BIT7
42#define WLAN_RATE_24M BIT8
43#define WLAN_RATE_36M BIT9
44#define WLAN_RATE_48M BIT10
45#define WLAN_RATE_54M BIT11
46
47#ifndef ETH_P_PAE
48#define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
49#endif /* ETH_P_PAE */
50
51#ifndef ARPHRD_IEEE80211
52#define ARPHRD_IEEE80211 801
53#endif
54
55int vt6655_hostap_set_hostapd(struct vnt_private *, int val, int rtnl_locked);
56int vt6655_hostap_ioctl(struct vnt_private *, struct iw_point *p);
57
58#endif // __HOSTAP_H__
diff --git a/drivers/staging/vt6655/iocmd.h b/drivers/staging/vt6655/iocmd.h
deleted file mode 100644
index a665cfd8a482..000000000000
--- a/drivers/staging/vt6655/iocmd.h
+++ /dev/null
@@ -1,408 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: iocmd.h
20 *
21 * Purpose: Handles the viawget ioctl private interface functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 8, 2002
26 *
27 */
28
29#ifndef __IOCMD_H__
30#define __IOCMD_H__
31
32#include "ttype.h"
33
34// ioctl Command code
35#define MAGIC_CODE 0x3142
36#define IOCTL_CMD_TEST (SIOCDEVPRIVATE + 0)
37#define IOCTL_CMD_SET (SIOCDEVPRIVATE + 1)
38#define IOCTL_CMD_HOSTAPD (SIOCDEVPRIVATE + 2)
39#define IOCTL_CMD_WPA (SIOCDEVPRIVATE + 3)
40
41typedef enum tagWMAC_CMD {
42 WLAN_CMD_BSS_SCAN,
43 WLAN_CMD_BSS_JOIN,
44 WLAN_CMD_DISASSOC,
45 WLAN_CMD_SET_WEP,
46 WLAN_CMD_GET_LINK,
47 WLAN_CMD_GET_LISTLEN,
48 WLAN_CMD_GET_LIST,
49 WLAN_CMD_GET_MIB,
50 WLAN_CMD_GET_STAT,
51 WLAN_CMD_STOP_MAC,
52 WLAN_CMD_START_MAC,
53 WLAN_CMD_AP_START,
54 WLAN_CMD_SET_HOSTAPD,
55 WLAN_CMD_SET_HOSTAPD_STA,
56 WLAN_CMD_SET_802_1X,
57 WLAN_CMD_SET_HOST_WEP,
58 WLAN_CMD_SET_WPA,
59 WLAN_CMD_GET_NODE_CNT,
60 WLAN_CMD_ZONETYPE_SET,
61 WLAN_CMD_GET_NODE_LIST
62} WMAC_CMD, *PWMAC_CMD;
63
64typedef enum tagWZONETYPE {
65 ZoneType_USA = 0,
66 ZoneType_Japan = 1,
67 ZoneType_Europe = 2
68} WZONETYPE;
69
70#define ADHOC 0
71#define INFRA 1
72#define BOTH 2
73#define AP 3
74
75#define ADHOC_STARTED 1
76#define ADHOC_JOINTED 2
77
78#define PHY80211a 0
79#define PHY80211b 1
80#define PHY80211g 2
81
82#define SSID_ID 0
83#define SSID_MAXLEN 32
84#define BSSID_LEN 6
85#define WEP_NKEYS 4
86#define WEP_KEYMAXLEN 29
87#define WEP_40BIT_LEN 5
88#define WEP_104BIT_LEN 13
89#define WEP_232BIT_LEN 16
90
91// Ioctl interface structure
92// Command structure
93//
94#pragma pack(1)
95typedef struct tagSCmdRequest {
96 u8 name[16];
97 void __user *data;
98 u16 wResult;
99 u16 wCmdCode;
100} SCmdRequest, *PSCmdRequest;
101
102//
103// Scan
104//
105
106typedef struct tagSCmdScan {
107 u8 ssid[SSID_MAXLEN + 2];
108} SCmdScan, *PSCmdScan;
109
110//
111// BSS Join
112//
113
114typedef struct tagSCmdBSSJoin {
115 u16 wBSSType;
116 u16 wBBPType;
117 u8 ssid[SSID_MAXLEN + 2];
118 u32 uChannel;
119 bool bPSEnable;
120 bool bShareKeyAuth;
121} SCmdBSSJoin, *PSCmdBSSJoin;
122
123//
124// Zonetype Setting
125//
126
127typedef struct tagSCmdZoneTypeSet {
128 bool bWrite;
129 WZONETYPE ZoneType;
130} SCmdZoneTypeSet, *PSCmdZoneTypeSet;
131
132#ifdef WPA_SM_Transtatus
133typedef struct tagSWPAResult {
134 char ifname[100];
135 u8 proto;
136 u8 key_mgmt;
137 u8 eap_type;
138 bool authenticated;
139} SWPAResult, *PSWPAResult;
140#endif
141
142typedef struct tagSCmdStartAP {
143 u16 wBSSType;
144 u16 wBBPType;
145 u8 ssid[SSID_MAXLEN + 2];
146 u32 uChannel;
147 u32 uBeaconInt;
148 bool bShareKeyAuth;
149 u8 byBasicRate;
150} SCmdStartAP, *PSCmdStartAP;
151
152typedef struct tagSCmdSetWEP {
153 bool bEnableWep;
154 u8 byKeyIndex;
155 u8 abyWepKey[WEP_NKEYS][WEP_KEYMAXLEN];
156 bool bWepKeyAvailable[WEP_NKEYS];
157 u32 auWepKeyLength[WEP_NKEYS];
158} SCmdSetWEP, *PSCmdSetWEP;
159
160typedef struct tagSBSSIDItem {
161 u32 uChannel;
162 u8 abyBSSID[BSSID_LEN];
163 u8 abySSID[SSID_MAXLEN + 1];
164 u8 byNetType;
165 u16 wBeaconInterval;
166 u16 wCapInfo; // for address of byNetType at align 4
167
168 bool bWEPOn;
169 u32 uRSSI;
170} SBSSIDItem;
171
172typedef struct tagSBSSIDList {
173 u32 uItem;
174 SBSSIDItem sBSSIDList[0];
175} SBSSIDList, *PSBSSIDList;
176
177typedef struct tagSCmdLinkStatus {
178 bool bLink;
179 u16 wBSSType;
180 u8 byState;
181 u8 abyBSSID[BSSID_LEN];
182 u8 abySSID[SSID_MAXLEN + 2];
183 u32 uChannel;
184 u32 uLinkRate;
185} SCmdLinkStatus, *PSCmdLinkStatus;
186
187//
188// 802.11 counter
189//
190typedef struct tagSDot11MIBCount {
191 u32 TransmittedFragmentCount;
192 u32 MulticastTransmittedFrameCount;
193 u32 FailedCount;
194 u32 RetryCount;
195 u32 MultipleRetryCount;
196 u32 RTSSuccessCount;
197 u32 RTSFailureCount;
198 u32 ACKFailureCount;
199 u32 FrameDuplicateCount;
200 u32 ReceivedFragmentCount;
201 u32 MulticastReceivedFrameCount;
202 u32 FCSErrorCount;
203} SDot11MIBCount, *PSDot11MIBCount;
204
205//
206// statistic counter
207//
208typedef struct tagSStatMIBCount {
209 //
210 // ISR status count
211 //
212 u32 dwIsrTx0OK;
213 u32 dwIsrTx1OK;
214 u32 dwIsrBeaconTxOK;
215 u32 dwIsrRxOK;
216 u32 dwIsrTBTTInt;
217 u32 dwIsrSTIMERInt;
218 u32 dwIsrUnrecoverableError;
219 u32 dwIsrSoftInterrupt;
220 u32 dwIsrRxNoBuf;
221
222 u32 dwIsrUnknown;
223
224 // RSR status count
225 //
226 u32 dwRsrFrmAlgnErr;
227 u32 dwRsrErr;
228 u32 dwRsrCRCErr;
229 u32 dwRsrCRCOk;
230 u32 dwRsrBSSIDOk;
231 u32 dwRsrADDROk;
232 u32 dwRsrICVOk;
233 u32 dwNewRsrShortPreamble;
234 u32 dwRsrLong;
235 u32 dwRsrRunt;
236
237 u32 dwRsrRxControl;
238 u32 dwRsrRxData;
239 u32 dwRsrRxManage;
240
241 u32 dwRsrRxPacket;
242 u32 dwRsrRxOctet;
243 u32 dwRsrBroadcast;
244 u32 dwRsrMulticast;
245 u32 dwRsrDirected;
246 // 64-bit OID
247 u32 ullRsrOK;
248
249 // for some optional OIDs (64 bits) and DMI support
250 u32 ullRxBroadcastBytes;
251 u32 ullRxMulticastBytes;
252 u32 ullRxDirectedBytes;
253 u32 ullRxBroadcastFrames;
254 u32 ullRxMulticastFrames;
255 u32 ullRxDirectedFrames;
256
257 u32 dwRsrRxFragment;
258 u32 dwRsrRxFrmLen64;
259 u32 dwRsrRxFrmLen65_127;
260 u32 dwRsrRxFrmLen128_255;
261 u32 dwRsrRxFrmLen256_511;
262 u32 dwRsrRxFrmLen512_1023;
263 u32 dwRsrRxFrmLen1024_1518;
264
265 // TSR0,1 status count
266 //
267 u32 dwTsrTotalRetry[2]; // total collision retry count
268 u32 dwTsrOnceRetry[2]; // this packet only occur one collision
269 u32 dwTsrMoreThanOnceRetry[2]; // this packet occur more than one collision
270 u32 dwTsrRetry[2]; // this packet has ever occur collision,
271 // that is (dwTsrOnceCollision0 + dwTsrMoreThanOnceCollision0)
272 u32 dwTsrACKData[2];
273 u32 dwTsrErr[2];
274 u32 dwAllTsrOK[2];
275 u32 dwTsrRetryTimeout[2];
276 u32 dwTsrTransmitTimeout[2];
277
278 u32 dwTsrTxPacket[2];
279 u32 dwTsrTxOctet[2];
280 u32 dwTsrBroadcast[2];
281 u32 dwTsrMulticast[2];
282 u32 dwTsrDirected[2];
283
284 // RD/TD count
285 u32 dwCntRxFrmLength;
286 u32 dwCntTxBufLength;
287
288 u8 abyCntRxPattern[16];
289 u8 abyCntTxPattern[16];
290
291 // Software check....
292 u32 dwCntRxDataErr; // rx buffer data software compare CRC err count
293 u32 dwCntDecryptErr; // rx buffer data software compare CRC err count
294 u32 dwCntRxICVErr; // rx buffer data software compare CRC err count
295 u32 idxRxErrorDesc; // index for rx data error RD
296
297 // 64-bit OID
298 u32 ullTsrOK[2];
299
300 // for some optional OIDs (64 bits) and DMI support
301 u32 ullTxBroadcastFrames[2];
302 u32 ullTxMulticastFrames[2];
303 u32 ullTxDirectedFrames[2];
304 u32 ullTxBroadcastBytes[2];
305 u32 ullTxMulticastBytes[2];
306 u32 ullTxDirectedBytes[2];
307} SStatMIBCount, *PSStatMIBCount;
308
309typedef struct tagSNodeItem {
310 // STA info
311 u16 wAID;
312 u8 abyMACAddr[6];
313 u16 wTxDataRate;
314 u16 wInActiveCount;
315 u16 wEnQueueCnt;
316 u16 wFlags;
317 bool bPWBitOn;
318 u8 byKeyIndex;
319 u16 wWepKeyLength;
320 u8 abyWepKey[WEP_KEYMAXLEN];
321 // Auto rate fallback vars
322 bool bIsInFallback;
323 u32 uTxFailures;
324 u32 uTxAttempts;
325 u16 wFailureRatio;
326} SNodeItem;
327
328typedef struct tagSNodeList {
329 u32 uItem;
330 SNodeItem sNodeList[0];
331} SNodeList, *PSNodeList;
332
333typedef struct tagSCmdValue {
334 u32 dwValue;
335} SCmdValue, *PSCmdValue;
336
337//
338// hostapd & viawget ioctl related
339//
340
341enum {
342 VIAWGET_HOSTAPD_FLUSH = 1,
343 VIAWGET_HOSTAPD_ADD_STA = 2,
344 VIAWGET_HOSTAPD_REMOVE_STA = 3,
345 VIAWGET_HOSTAPD_GET_INFO_STA = 4,
346 VIAWGET_HOSTAPD_SET_ENCRYPTION = 5,
347 VIAWGET_HOSTAPD_GET_ENCRYPTION = 6,
348 VIAWGET_HOSTAPD_SET_FLAGS_STA = 7,
349 VIAWGET_HOSTAPD_SET_ASSOC_AP_ADDR = 8,
350 VIAWGET_HOSTAPD_SET_GENERIC_ELEMENT = 9,
351 VIAWGET_HOSTAPD_MLME = 10,
352 VIAWGET_HOSTAPD_SCAN_REQ = 11,
353 VIAWGET_HOSTAPD_STA_CLEAR_STATS = 12,
354};
355
356#define VIAWGET_HOSTAPD_GENERIC_ELEMENT_HDR_LEN \
357 ((int)(&((struct viawget_hostapd_param *)0)->u.generic_elem.data))
358
359// Maximum length for algorithm names (-1 for nul termination) used in ioctl()
360
361struct viawget_hostapd_param {
362 u32 cmd;
363 u8 sta_addr[6];
364 union {
365 struct {
366 u16 aid;
367 u16 capability;
368 u8 tx_supp_rates;
369 } add_sta;
370 struct {
371 u32 inactive_sec;
372 } get_info_sta;
373 struct {
374 u8 alg;
375 u32 flags;
376 u32 err;
377 u8 idx;
378 u8 seq[8];
379 u16 key_len;
380 u8 key[0];
381 } crypt;
382 struct {
383 u32 flags_and;
384 u32 flags_or;
385 } set_flags_sta;
386 struct {
387 u16 rid;
388 u16 len;
389 u8 data[0];
390 } rid;
391 struct {
392 u8 len;
393 u8 data[0];
394 } generic_elem;
395 struct {
396 u16 cmd;
397 u16 reason_code;
398 } mlme;
399 struct {
400 u8 ssid_len;
401 u8 ssid[32];
402 } scan_req;
403 } u;
404};
405
406#pragma pack()
407
408#endif //__IOCMD_H__
diff --git a/drivers/staging/vt6655/ioctl.c b/drivers/staging/vt6655/ioctl.c
deleted file mode 100644
index 970e80d92fb9..000000000000
--- a/drivers/staging/vt6655/ioctl.c
+++ /dev/null
@@ -1,658 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: ioctl.c
20 *
21 * Purpose: private ioctl functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: Auguest 20, 2003
26 *
27 * Functions:
28 *
29 * Revision History:
30 *
31 */
32
33#include "ioctl.h"
34#include "iocmd.h"
35#include "mac.h"
36#include "card.h"
37#include "hostap.h"
38#include "wpactl.h"
39#include "rf.h"
40
41#ifdef WPA_SM_Transtatus
42SWPAResult wpa_Result;
43#endif
44
45int private_ioctl(struct vnt_private *pDevice, struct ifreq *rq)
46{
47 PSCmdRequest pReq = (PSCmdRequest)rq;
48 PSMgmtObject pMgmt = pDevice->pMgmt;
49 int result = 0;
50 PWLAN_IE_SSID pItemSSID;
51 SCmdBSSJoin sJoinCmd;
52 SCmdZoneTypeSet sZoneTypeCmd;
53 SCmdScan sScanCmd;
54 SCmdStartAP sStartAPCmd;
55 SCmdSetWEP sWEPCmd;
56 SCmdValue sValue;
57 SBSSIDList sList;
58 SNodeList sNodeList;
59 PSBSSIDList pList;
60 PSNodeList pNodeList;
61 unsigned int cbListCount;
62 PKnownBSS pBSS;
63 PKnownNodeDB pNode;
64 unsigned int ii, jj;
65 unsigned char abySuppRates[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
66 unsigned char abyNullAddr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
67 unsigned long dwKeyIndex = 0;
68 unsigned char abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
69 long ldBm;
70
71 pReq->wResult = 0;
72
73 switch (pReq->wCmdCode) {
74 case WLAN_CMD_BSS_SCAN:
75 pr_debug("WLAN_CMD_BSS_SCAN..begin\n");
76 if (copy_from_user(&sScanCmd, pReq->data, sizeof(SCmdScan))) {
77 result = -EFAULT;
78 break;
79 }
80
81 pItemSSID = (PWLAN_IE_SSID)sScanCmd.ssid;
82 if (pItemSSID->len > WLAN_SSID_MAXLEN + 1)
83 return -EINVAL;
84 if (pItemSSID->len != 0) {
85 memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
86 memcpy(abyScanSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN);
87 }
88
89 if (pDevice->bMACSuspend == true) {
90 if (pDevice->bRadioOff == true)
91 CARDbRadioPowerOn(pDevice);
92 vMgrTimerInit(pDevice);
93 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
94 add_timer(&pMgmt->sTimerSecondCallback);
95 pDevice->bMACSuspend = false;
96 }
97 spin_lock_irq(&pDevice->lock);
98 if (memcmp(pMgmt->abyCurrBSSID, &abyNullAddr[0], 6) == 0)
99 BSSvClearBSSList((void *)pDevice, false);
100 else
101 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
102
103 if (pItemSSID->len != 0)
104 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
105 else
106 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
107 spin_unlock_irq(&pDevice->lock);
108 break;
109
110 case WLAN_CMD_ZONETYPE_SET:
111 /* mike add :can't support. */
112 result = -EOPNOTSUPP;
113 break;
114
115 if (copy_from_user(&sZoneTypeCmd, pReq->data, sizeof(SCmdZoneTypeSet))) {
116 result = -EFAULT;
117 break;
118 }
119
120 if (sZoneTypeCmd.bWrite == true) {
121 /* write zonetype */
122 if (sZoneTypeCmd.ZoneType == ZoneType_USA) {
123 /* set to USA */
124 pr_debug("set_ZoneType:USA\n");
125 } else if (sZoneTypeCmd.ZoneType == ZoneType_Japan) {
126 /* set to Japan */
127 pr_debug("set_ZoneType:Japan\n");
128 } else if (sZoneTypeCmd.ZoneType == ZoneType_Europe) {
129 /* set to Europe */
130 pr_debug("set_ZoneType:Europe\n");
131 }
132 } else {
133 /* read zonetype */
134 unsigned char zonetype = 0;
135
136 if (zonetype == 0x00) { /* USA */
137 sZoneTypeCmd.ZoneType = ZoneType_USA;
138 } else if (zonetype == 0x01) { /* Japan */
139 sZoneTypeCmd.ZoneType = ZoneType_Japan;
140 } else if (zonetype == 0x02) { /* Europe */
141 sZoneTypeCmd.ZoneType = ZoneType_Europe;
142 } else { /* Unknown ZoneType */
143 pr_err("Error:ZoneType[%x] Unknown ???\n", zonetype);
144 result = -EFAULT;
145 break;
146 }
147 if (copy_to_user(pReq->data, &sZoneTypeCmd, sizeof(SCmdZoneTypeSet))) {
148 result = -EFAULT;
149 break;
150 }
151 }
152 break;
153
154 case WLAN_CMD_BSS_JOIN:
155 if (pDevice->bMACSuspend == true) {
156 if (pDevice->bRadioOff == true)
157 CARDbRadioPowerOn(pDevice);
158 vMgrTimerInit(pDevice);
159 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
160 add_timer(&pMgmt->sTimerSecondCallback);
161 pDevice->bMACSuspend = false;
162 }
163
164 if (copy_from_user(&sJoinCmd, pReq->data, sizeof(SCmdBSSJoin))) {
165 result = -EFAULT;
166 break;
167 }
168
169 pItemSSID = (PWLAN_IE_SSID)sJoinCmd.ssid;
170 if (pItemSSID->len > WLAN_SSID_MAXLEN + 1)
171 return -EINVAL;
172 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
173 memcpy(pMgmt->abyDesireSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN);
174 if (sJoinCmd.wBSSType == ADHOC) {
175 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
176 pr_debug("ioct set to adhoc mode\n");
177 } else {
178 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
179 pr_debug("ioct set to STA mode\n");
180 }
181 if (sJoinCmd.bPSEnable == true) {
182 pDevice->ePSMode = WMAC_POWER_FAST;
183 pMgmt->wListenInterval = 2;
184 pr_debug("Power Saving On\n");
185 } else {
186 pDevice->ePSMode = WMAC_POWER_CAM;
187 pMgmt->wListenInterval = 1;
188 pr_debug("Power Saving Off\n");
189 }
190
191 if (sJoinCmd.bShareKeyAuth == true) {
192 pMgmt->bShareKeyAlgorithm = true;
193 pr_debug("Share Key\n");
194 } else {
195 pMgmt->bShareKeyAlgorithm = false;
196 pr_debug("Open System\n");
197 }
198 pDevice->uChannel = sJoinCmd.uChannel;
199 netif_stop_queue(pDevice->dev);
200 spin_lock_irq(&pDevice->lock);
201 pMgmt->eCurrState = WMAC_STATE_IDLE;
202 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
203 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
204 spin_unlock_irq(&pDevice->lock);
205 break;
206
207 case WLAN_CMD_SET_WEP:
208 pr_debug("WLAN_CMD_SET_WEP Key\n");
209 memset(&sWEPCmd, 0, sizeof(SCmdSetWEP));
210 if (copy_from_user(&sWEPCmd, pReq->data, sizeof(SCmdSetWEP))) {
211 result = -EFAULT;
212 break;
213 }
214 if (sWEPCmd.bEnableWep != true) {
215 pDevice->bEncryptionEnable = false;
216 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
217 MACvDisableDefaultKey(pDevice->PortOffset);
218 pr_debug("WEP function disable\n");
219 break;
220 }
221
222 for (ii = 0; ii < WLAN_WEP_NKEYS; ii++) {
223 if (sWEPCmd.bWepKeyAvailable[ii]) {
224 if (ii == sWEPCmd.byKeyIndex)
225 dwKeyIndex = ii | (1 << 31);
226 else
227 dwKeyIndex = ii;
228
229 KeybSetDefaultKey(&(pDevice->sKey),
230 dwKeyIndex,
231 sWEPCmd.auWepKeyLength[ii],
232 NULL,
233 (unsigned char *)&sWEPCmd.abyWepKey[ii][0],
234 KEY_CTL_WEP,
235 pDevice->PortOffset,
236 pDevice->byLocalID);
237 }
238 }
239 pDevice->byKeyIndex = sWEPCmd.byKeyIndex;
240 pDevice->bTransmitKey = true;
241 pDevice->bEncryptionEnable = true;
242 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
243 break;
244
245 case WLAN_CMD_GET_LINK: {
246 SCmdLinkStatus sLinkStatus;
247
248 pr_debug("WLAN_CMD_GET_LINK status\n");
249
250 memset(&sLinkStatus, 0, sizeof(sLinkStatus));
251
252 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)
253 sLinkStatus.wBSSType = ADHOC;
254 else
255 sLinkStatus.wBSSType = INFRA;
256
257 if (pMgmt->eCurrState == WMAC_STATE_JOINTED)
258 sLinkStatus.byState = ADHOC_JOINTED;
259 else
260 sLinkStatus.byState = ADHOC_STARTED;
261
262 sLinkStatus.uChannel = pMgmt->uCurrChannel;
263 if (pDevice->bLinkPass == true) {
264 sLinkStatus.bLink = true;
265 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
266 memcpy(sLinkStatus.abySSID, pItemSSID->abySSID, pItemSSID->len);
267 memcpy(sLinkStatus.abyBSSID, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
268 sLinkStatus.uLinkRate = pMgmt->sNodeDBTable[0].wTxDataRate;
269 pr_debug(" Link Success!\n");
270 } else {
271 sLinkStatus.bLink = false;
272 sLinkStatus.uLinkRate = 0;
273 }
274 if (copy_to_user(pReq->data, &sLinkStatus, sizeof(SCmdLinkStatus))) {
275 result = -EFAULT;
276 break;
277 }
278 break;
279 }
280 case WLAN_CMD_GET_LISTLEN:
281 cbListCount = 0;
282 pBSS = &(pMgmt->sBSSList[0]);
283 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
284 pBSS = &(pMgmt->sBSSList[ii]);
285 if (!pBSS->bActive)
286 continue;
287 cbListCount++;
288 }
289 sList.uItem = cbListCount;
290 if (copy_to_user(pReq->data, &sList, sizeof(SBSSIDList))) {
291 result = -EFAULT;
292 break;
293 }
294 pReq->wResult = 0;
295 break;
296
297 case WLAN_CMD_GET_LIST:
298 if (copy_from_user(&sList, pReq->data, sizeof(SBSSIDList))) {
299 result = -EFAULT;
300 break;
301 }
302 if (sList.uItem > (ULONG_MAX - sizeof(SBSSIDList)) / sizeof(SBSSIDItem)) {
303 result = -EINVAL;
304 break;
305 }
306 pList = (PSBSSIDList)kmalloc(sizeof(SBSSIDList) + (sList.uItem * sizeof(SBSSIDItem)),
307 GFP_ATOMIC);
308 if (pList == NULL) {
309 result = -ENOMEM;
310 break;
311 }
312 pList->uItem = sList.uItem;
313 pBSS = &(pMgmt->sBSSList[0]);
314 for (ii = 0, jj = 0; jj < MAX_BSS_NUM; jj++) {
315 pBSS = &(pMgmt->sBSSList[jj]);
316 if (pBSS->bActive) {
317 pList->sBSSIDList[ii].uChannel = pBSS->uChannel;
318 pList->sBSSIDList[ii].wBeaconInterval = pBSS->wBeaconInterval;
319 pList->sBSSIDList[ii].wCapInfo = pBSS->wCapInfo;
320 RFvRSSITodBm(pDevice, (unsigned char)(pBSS->uRSSI), &ldBm);
321 pList->sBSSIDList[ii].uRSSI = (unsigned int)ldBm;
322 memcpy(pList->sBSSIDList[ii].abyBSSID, pBSS->abyBSSID, WLAN_BSSID_LEN);
323 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
324 memset(pList->sBSSIDList[ii].abySSID, 0, WLAN_SSID_MAXLEN + 1);
325 memcpy(pList->sBSSIDList[ii].abySSID, pItemSSID->abySSID, pItemSSID->len);
326 if (WLAN_GET_CAP_INFO_ESS(pBSS->wCapInfo))
327 pList->sBSSIDList[ii].byNetType = INFRA;
328 else
329 pList->sBSSIDList[ii].byNetType = ADHOC;
330
331 if (WLAN_GET_CAP_INFO_PRIVACY(pBSS->wCapInfo))
332 pList->sBSSIDList[ii].bWEPOn = true;
333 else
334 pList->sBSSIDList[ii].bWEPOn = false;
335
336 ii++;
337 if (ii >= pList->uItem)
338 break;
339 }
340 }
341
342 if (copy_to_user(pReq->data, pList, sizeof(SBSSIDList) + (sList.uItem * sizeof(SBSSIDItem)))) {
343 result = -EFAULT;
344 break;
345 }
346 kfree(pList);
347 pReq->wResult = 0;
348 break;
349
350 case WLAN_CMD_GET_MIB:
351 if (copy_to_user(pReq->data, &(pDevice->s802_11Counter), sizeof(SDot11MIBCount))) {
352 result = -EFAULT;
353 break;
354 }
355 break;
356
357 case WLAN_CMD_GET_STAT:
358 if (copy_to_user(pReq->data, &(pDevice->scStatistic), sizeof(SStatCounter))) {
359 result = -EFAULT;
360 break;
361 }
362 break;
363
364 case WLAN_CMD_STOP_MAC:
365 pr_debug("WLAN_CMD_STOP_MAC\n");
366 netif_stop_queue(pDevice->dev);
367
368 spin_lock_irq(&pDevice->lock);
369 if (pDevice->bRadioOff == false)
370 CARDbRadioPowerOff(pDevice);
371
372 pDevice->bLinkPass = false;
373 memset(pMgmt->abyCurrBSSID, 0, 6);
374 pMgmt->eCurrState = WMAC_STATE_IDLE;
375 del_timer(&pDevice->sTimerCommand);
376 del_timer(&pMgmt->sTimerSecondCallback);
377 pDevice->bCmdRunning = false;
378 pDevice->bMACSuspend = true;
379 MACvIntDisable(pDevice->PortOffset);
380 spin_unlock_irq(&pDevice->lock);
381 break;
382
383 case WLAN_CMD_START_MAC:
384 pr_debug("WLAN_CMD_START_MAC\n");
385
386 if (pDevice->bMACSuspend == true) {
387 if (pDevice->bRadioOff == true)
388 CARDbRadioPowerOn(pDevice);
389 vMgrTimerInit(pDevice);
390 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
391 add_timer(&pMgmt->sTimerSecondCallback);
392 pDevice->bMACSuspend = false;
393 }
394 break;
395
396 case WLAN_CMD_SET_HOSTAPD:
397 pr_debug("WLAN_CMD_SET_HOSTAPD\n");
398
399 if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
400 result = -EFAULT;
401 break;
402 }
403 if (sValue.dwValue == 1) {
404 if (vt6655_hostap_set_hostapd(pDevice, 1, 1) == 0) {
405 pr_debug("Enable HOSTAP\n");
406 } else {
407 result = -EFAULT;
408 break;
409 }
410 } else {
411 vt6655_hostap_set_hostapd(pDevice, 0, 1);
412 pr_debug("Disable HOSTAP\n");
413 }
414 break;
415
416 case WLAN_CMD_SET_HOSTAPD_STA:
417 pr_debug("WLAN_CMD_SET_HOSTAPD_STA\n");
418 break;
419
420 case WLAN_CMD_SET_802_1X:
421 pr_debug("WLAN_CMD_SET_802_1X\n");
422 if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
423 result = -EFAULT;
424 break;
425 }
426
427 if (sValue.dwValue == 1) {
428 pDevice->bEnable8021x = true;
429 pr_debug("Enable 802.1x\n");
430 } else {
431 pDevice->bEnable8021x = false;
432 pr_debug("Disable 802.1x\n");
433 }
434 break;
435
436 case WLAN_CMD_SET_HOST_WEP:
437 pr_debug("WLAN_CMD_SET_HOST_WEP\n");
438 if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
439 result = -EFAULT;
440 break;
441 }
442
443 if (sValue.dwValue == 1) {
444 pDevice->bEnableHostWEP = true;
445 pr_debug("Enable HostWEP\n");
446 } else {
447 pDevice->bEnableHostWEP = false;
448 pr_debug("Disable HostWEP\n");
449 }
450 break;
451
452 case WLAN_CMD_SET_WPA:
453 pr_debug("WLAN_CMD_SET_WPA\n");
454
455 if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
456 result = -EFAULT;
457 break;
458 }
459 if (sValue.dwValue == 1) {
460 pr_debug("up wpadev\n");
461 eth_hw_addr_inherit(pDevice->wpadev, pDevice->dev);
462 pDevice->bWPADEVUp = true;
463 } else {
464 pr_debug("close wpadev\n");
465 pDevice->bWPADEVUp = false;
466 }
467 break;
468
469 case WLAN_CMD_AP_START:
470 pr_debug("WLAN_CMD_AP_START\n");
471 if (pDevice->bRadioOff == true) {
472 CARDbRadioPowerOn(pDevice);
473 vMgrTimerInit(pDevice);
474 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
475 add_timer(&pMgmt->sTimerSecondCallback);
476 }
477 if (copy_from_user(&sStartAPCmd, pReq->data, sizeof(SCmdStartAP))) {
478 result = -EFAULT;
479 break;
480 }
481
482 if (sStartAPCmd.wBSSType == AP) {
483 pMgmt->eConfigMode = WMAC_CONFIG_AP;
484 pr_debug("ioct set to AP mode\n");
485 } else {
486 pr_debug("ioct BSS type not set to AP mode\n");
487 result = -EFAULT;
488 break;
489 }
490
491 if (sStartAPCmd.wBBPType == PHY80211g)
492 pMgmt->byAPBBType = PHY_TYPE_11G;
493 else if (sStartAPCmd.wBBPType == PHY80211a)
494 pMgmt->byAPBBType = PHY_TYPE_11A;
495 else
496 pMgmt->byAPBBType = PHY_TYPE_11B;
497
498 pItemSSID = (PWLAN_IE_SSID)sStartAPCmd.ssid;
499 if (pItemSSID->len > WLAN_SSID_MAXLEN + 1)
500 return -EINVAL;
501 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
502 memcpy(pMgmt->abyDesireSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN);
503
504 if ((sStartAPCmd.uChannel > 0) && (sStartAPCmd.uChannel <= 14))
505 pDevice->uChannel = sStartAPCmd.uChannel;
506
507 if ((sStartAPCmd.uBeaconInt >= 20) && (sStartAPCmd.uBeaconInt <= 1000))
508 pMgmt->wIBSSBeaconPeriod = sStartAPCmd.uBeaconInt;
509 else
510 pMgmt->wIBSSBeaconPeriod = 100;
511
512 if (sStartAPCmd.bShareKeyAuth == true) {
513 pMgmt->bShareKeyAlgorithm = true;
514 pr_debug("Share Key\n");
515 } else {
516 pMgmt->bShareKeyAlgorithm = false;
517 pr_debug("Open System\n");
518 }
519 memcpy(pMgmt->abyIBSSSuppRates, abySuppRates, 6);
520
521 if (sStartAPCmd.byBasicRate & BIT3) {
522 pMgmt->abyIBSSSuppRates[2] |= BIT7;
523 pMgmt->abyIBSSSuppRates[3] |= BIT7;
524 pMgmt->abyIBSSSuppRates[4] |= BIT7;
525 pMgmt->abyIBSSSuppRates[5] |= BIT7;
526 } else if (sStartAPCmd.byBasicRate & BIT2) {
527 pMgmt->abyIBSSSuppRates[2] |= BIT7;
528 pMgmt->abyIBSSSuppRates[3] |= BIT7;
529 pMgmt->abyIBSSSuppRates[4] |= BIT7;
530 } else if (sStartAPCmd.byBasicRate & BIT1) {
531 pMgmt->abyIBSSSuppRates[2] |= BIT7;
532 pMgmt->abyIBSSSuppRates[3] |= BIT7;
533 } else if (sStartAPCmd.byBasicRate & BIT1) {
534 pMgmt->abyIBSSSuppRates[2] |= BIT7;
535 } else {
536 /* default 1,2M */
537 pMgmt->abyIBSSSuppRates[2] |= BIT7;
538 pMgmt->abyIBSSSuppRates[3] |= BIT7;
539 }
540
541 pr_debug("Support Rate= %*ph\n",
542 4, pMgmt->abyIBSSSuppRates + 2);
543
544 netif_stop_queue(pDevice->dev);
545 spin_lock_irq(&pDevice->lock);
546 bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
547 spin_unlock_irq(&pDevice->lock);
548 break;
549
550 case WLAN_CMD_GET_NODE_CNT:
551 cbListCount = 0;
552 pNode = &(pMgmt->sNodeDBTable[0]);
553 for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
554 pNode = &(pMgmt->sNodeDBTable[ii]);
555 if (!pNode->bActive)
556 continue;
557 cbListCount++;
558 }
559
560 sNodeList.uItem = cbListCount;
561 if (copy_to_user(pReq->data, &sNodeList, sizeof(SNodeList))) {
562 result = -EFAULT;
563 break;
564 }
565 pReq->wResult = 0;
566 break;
567
568 case WLAN_CMD_GET_NODE_LIST:
569 if (copy_from_user(&sNodeList, pReq->data, sizeof(SNodeList))) {
570 result = -EFAULT;
571 break;
572 }
573 if (sNodeList.uItem > (ULONG_MAX - sizeof(SNodeList)) / sizeof(SNodeItem)) {
574 result = -EINVAL;
575 break;
576 }
577 pNodeList = (PSNodeList)kmalloc(sizeof(SNodeList) + (sNodeList.uItem * sizeof(SNodeItem)),
578 GFP_ATOMIC);
579 if (pNodeList == NULL) {
580 result = -ENOMEM;
581 break;
582 }
583 pNodeList->uItem = sNodeList.uItem;
584 pNode = &(pMgmt->sNodeDBTable[0]);
585 for (ii = 0, jj = 0; ii < (MAX_NODE_NUM + 1); ii++) {
586 pNode = &(pMgmt->sNodeDBTable[ii]);
587 if (pNode->bActive) {
588 pNodeList->sNodeList[jj].wAID = pNode->wAID;
589 memcpy(pNodeList->sNodeList[jj].abyMACAddr, pNode->abyMACAddr, WLAN_ADDR_LEN);
590 pNodeList->sNodeList[jj].wTxDataRate = pNode->wTxDataRate;
591 pNodeList->sNodeList[jj].wInActiveCount = (unsigned short)pNode->uInActiveCount;
592 pNodeList->sNodeList[jj].wEnQueueCnt = (unsigned short)pNode->wEnQueueCnt;
593 pNodeList->sNodeList[jj].wFlags = (unsigned short)pNode->dwFlags;
594 pNodeList->sNodeList[jj].bPWBitOn = pNode->bPSEnable;
595 pNodeList->sNodeList[jj].byKeyIndex = pNode->byKeyIndex;
596 pNodeList->sNodeList[jj].wWepKeyLength = pNode->uWepKeyLength;
597 memcpy(&(pNodeList->sNodeList[jj].abyWepKey[0]), &(pNode->abyWepKey[0]), WEP_KEYMAXLEN);
598 pr_debug("key= %2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
599 pNodeList->sNodeList[jj].abyWepKey[0],
600 pNodeList->sNodeList[jj].abyWepKey[1],
601 pNodeList->sNodeList[jj].abyWepKey[2],
602 pNodeList->sNodeList[jj].abyWepKey[3],
603 pNodeList->sNodeList[jj].abyWepKey[4]);
604 pNodeList->sNodeList[jj].bIsInFallback = pNode->bIsInFallback;
605 pNodeList->sNodeList[jj].uTxFailures = pNode->uTxFailures;
606 pNodeList->sNodeList[jj].uTxAttempts = pNode->uTxAttempts;
607 pNodeList->sNodeList[jj].wFailureRatio = (unsigned short)pNode->uFailureRatio;
608 jj++;
609 if (jj >= pNodeList->uItem)
610 break;
611 }
612 }
613 if (copy_to_user(pReq->data, pNodeList, sizeof(SNodeList) + (sNodeList.uItem * sizeof(SNodeItem)))) {
614 result = -EFAULT;
615 break;
616 }
617 kfree(pNodeList);
618 pReq->wResult = 0;
619 break;
620
621#ifdef WPA_SM_Transtatus
622 case 0xFF:
623 memset(wpa_Result.ifname, 0, sizeof(wpa_Result.ifname));
624 wpa_Result.proto = 0;
625 wpa_Result.key_mgmt = 0;
626 wpa_Result.eap_type = 0;
627 wpa_Result.authenticated = false;
628 pDevice->fWPA_Authened = false;
629 if (copy_from_user(&wpa_Result, pReq->data, sizeof(wpa_Result))) {
630 result = -EFAULT;
631 break;
632 }
633
634 if (wpa_Result.authenticated == true) {
635#ifdef SndEvt_ToAPI
636 {
637 union iwreq_data wrqu;
638
639 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
640
641 memset(&wrqu, 0, sizeof(wrqu));
642 wrqu.data.flags = RT_WPACONNECTED_EVENT_FLAG;
643 wrqu.data.length = pItemSSID->len;
644 wireless_send_event(pDevice->dev, IWEVCUSTOM, &wrqu, pItemSSID->abySSID);
645 }
646#endif
647 pDevice->fWPA_Authened = true; /* is successful peer to wpa_Result.authenticated? */
648 }
649 pReq->wResult = 0;
650 break;
651#endif
652
653 default:
654 pr_debug("Private command not support..\n");
655 }
656
657 return result;
658}
diff --git a/drivers/staging/vt6655/ioctl.h b/drivers/staging/vt6655/ioctl.h
deleted file mode 100644
index 2dc5a5743e8d..000000000000
--- a/drivers/staging/vt6655/ioctl.h
+++ /dev/null
@@ -1,36 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: hostap.h
20 *
21 * Purpose:
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 21, 2003
26 *
27 */
28
29#ifndef __IOCTL_H__
30#define __IOCTL_H__
31
32#include "device.h"
33
34int private_ioctl(struct vnt_private *, struct ifreq *rq);
35
36#endif // __IOCTL_H__
diff --git a/drivers/staging/vt6655/iowpa.h b/drivers/staging/vt6655/iowpa.h
deleted file mode 100644
index fe4b22ed49f4..000000000000
--- a/drivers/staging/vt6655/iowpa.h
+++ /dev/null
@@ -1,130 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: iowpa.h
20 *
21 * Purpose: Handles wpa supplicant ioctl interface
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 8, 2002
26 *
27 */
28
29#ifndef __IOWPA_H__
30#define __IOWPA_H__
31
32#define WPA_IE_LEN 64
33
34//WPA related
35
36enum {
37 VIAWGET_SET_WPA = 1,
38 VIAWGET_SET_KEY = 2,
39 VIAWGET_SET_SCAN = 3,
40 VIAWGET_GET_SCAN = 4,
41 VIAWGET_GET_SSID = 5,
42 VIAWGET_GET_BSSID = 6,
43 VIAWGET_SET_DROP_UNENCRYPT = 7,
44 VIAWGET_SET_DEAUTHENTICATE = 8,
45 VIAWGET_SET_ASSOCIATE = 9,
46 VIAWGET_SET_DISASSOCIATE = 10
47};
48
49enum {
50 VIAWGET_ASSOC_MSG = 1,
51 VIAWGET_DISASSOC_MSG = 2,
52 VIAWGET_PTK_MIC_MSG = 3,
53 VIAWGET_GTK_MIC_MSG = 4,
54 VIAWGET_CCKM_ROAM_MSG = 5,
55 VIAWGET_DEVICECLOSE_MSG = 6
56};
57
58#pragma pack(1)
59typedef struct viawget_wpa_header {
60 u8 type;
61 u16 req_ie_len;
62 u16 resp_ie_len;
63} viawget_wpa_header;
64
65struct viawget_wpa_param {
66 u32 cmd;
67 u8 addr[6];
68 union {
69 struct {
70 u8 len;
71 u8 data[0];
72 } generic_elem;
73
74 struct {
75 u8 bssid[6];
76 u8 ssid[32];
77 u8 ssid_len;
78 u8 __user *wpa_ie;
79 u16 wpa_ie_len;
80 int pairwise_suite;
81 int group_suite;
82 int key_mgmt_suite;
83 int auth_alg;
84 int mode;
85
86 } wpa_associate;
87
88 struct {
89 int alg_name;
90 u16 key_index;
91 u16 set_tx;
92 u8 *seq;
93 u16 seq_len;
94 u8 *key;
95 u16 key_len;
96 } wpa_key;
97
98 struct {
99 u8 ssid_len;
100 u8 ssid[32];
101 } scan_req;
102
103 struct {
104 u16 scan_count;
105 u8 __user *buf;
106 } scan_results;
107
108 } u;
109};
110
111#pragma pack(1)
112struct viawget_scan_result {
113 u8 bssid[6];
114 u8 ssid[32];
115 u16 ssid_len;
116 u8 wpa_ie[WPA_IE_LEN];
117 u16 wpa_ie_len;
118 u8 rsn_ie[WPA_IE_LEN];
119 u16 rsn_ie_len;
120 int freq; // MHz
121 int caps; // e.g. privacy
122 int qual; // signal quality
123 int noise;
124 int level;
125 int maxrate;
126};
127
128#pragma pack()
129
130#endif //__IOWPA_H__
diff --git a/drivers/staging/vt6655/iwctl.c b/drivers/staging/vt6655/iwctl.c
deleted file mode 100644
index 14a62bdae278..000000000000
--- a/drivers/staging/vt6655/iwctl.c
+++ /dev/null
@@ -1,1937 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: iwctl.c
20 *
21 * Purpose: wireless ext & ioctl functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: July 5, 2006
26 *
27 * Functions:
28 *
29 * Revision History:
30 *
31 */
32
33#include "device.h"
34#include "ioctl.h"
35#include "iocmd.h"
36#include "iwctl.h"
37#include "mac.h"
38#include "card.h"
39#include "hostap.h"
40#include "power.h"
41#include "rf.h"
42
43#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
44#include "iowpa.h"
45#include "wpactl.h"
46#endif
47
48#include <net/iw_handler.h>
49extern unsigned short TxRate_iwconfig;//2008-5-8 <add> by chester
50
51/*--------------------- Static Definitions -------------------------*/
52
53//2008-0409-07, <Add> by Einsn Liu
54#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
55#define SUPPORTED_WIRELESS_EXT 18
56#else
57#define SUPPORTED_WIRELESS_EXT 17
58#endif
59
60static const long frequency_list[] = {
61 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
62 4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
63 5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240,
64 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
65 5700, 5745, 5765, 5785, 5805, 5825
66};
67
68/*--------------------- Static Classes ----------------------------*/
69/*--------------------- Static Variables --------------------------*/
70/*--------------------- Static Functions --------------------------*/
71
72/*--------------------- Export Variables --------------------------*/
73
74struct iw_statistics *iwctl_get_wireless_stats(struct net_device *dev)
75{
76 struct vnt_private *pDevice = netdev_priv(dev);
77 long ldBm;
78
79 pDevice->wstats.status = pDevice->op_mode;
80#ifdef Calcu_LinkQual
81 if (pDevice->scStatistic.LinkQuality > 100)
82 pDevice->scStatistic.LinkQuality = 100;
83 pDevice->wstats.qual.qual = (unsigned char)pDevice->scStatistic.LinkQuality;
84#else
85 pDevice->wstats.qual.qual = pDevice->byCurrSQ;
86#endif
87 RFvRSSITodBm(pDevice, (unsigned char)(pDevice->uCurrRSSI), &ldBm);
88 pDevice->wstats.qual.level = ldBm;
89 pDevice->wstats.qual.noise = 0;
90 pDevice->wstats.qual.updated = 1;
91 pDevice->wstats.discard.nwid = 0;
92 pDevice->wstats.discard.code = 0;
93 pDevice->wstats.discard.fragment = 0;
94 pDevice->wstats.discard.retries = (unsigned long)pDevice->scStatistic.dwTsrErr;
95 pDevice->wstats.discard.misc = 0;
96 pDevice->wstats.miss.beacon = 0;
97
98 return &pDevice->wstats;
99}
100
101/*------------------------------------------------------------------*/
102
103static int iwctl_commit(struct net_device *dev,
104 struct iw_request_info *info,
105 void *wrq,
106 char *extra)
107{
108 pr_debug(" SIOCSIWCOMMIT\n");
109
110 return 0;
111}
112/*
113 * Wireless Handler : get protocol name
114 */
115
116int iwctl_giwname(struct net_device *dev,
117 struct iw_request_info *info,
118 char *wrq,
119 char *extra)
120{
121 strcpy(wrq, "802.11-a/b/g");
122 return 0;
123}
124
125/*
126 * Wireless Handler : set scan
127 */
128
129static int iwctl_siwscan(struct net_device *dev,
130 struct iw_request_info *info,
131 struct iw_point *wrq,
132 char *extra)
133{
134 struct vnt_private *pDevice = netdev_priv(dev);
135 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
136 struct iw_scan_req *req = (struct iw_scan_req *)extra;
137 unsigned char abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
138 PWLAN_IE_SSID pItemSSID = NULL;
139
140 pr_debug(" SIOCSIWSCAN\n");
141
142 if (pDevice->byReAssocCount > 0) { //reject scan when re-associating!
143//send scan event to wpa_Supplicant
144 union iwreq_data wrqu;
145
146 PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
147 memset(&wrqu, 0, sizeof(wrqu));
148 wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
149 return 0;
150 }
151
152 spin_lock_irq(&pDevice->lock);
153 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
154
155//mike add: active scan OR passive scan OR desire_ssid scan
156 if (wrq->length == sizeof(struct iw_scan_req)) {
157 if (wrq->flags & IW_SCAN_THIS_ESSID) { //desire_ssid scan
158 memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
159 pItemSSID = (PWLAN_IE_SSID)abyScanSSID;
160 pItemSSID->byElementID = WLAN_EID_SSID;
161 memcpy(pItemSSID->abySSID, req->essid, (int)req->essid_len);
162 if (pItemSSID->abySSID[req->essid_len - 1] == '\0') {
163 if (req->essid_len > 0)
164 pItemSSID->len = req->essid_len - 1;
165 } else
166 pItemSSID->len = req->essid_len;
167 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
168 PRINT_K("SIOCSIWSCAN:[desired_ssid=%s,len=%d]\n", ((PWLAN_IE_SSID)abyScanSSID)->abySSID,
169 ((PWLAN_IE_SSID)abyScanSSID)->len);
170 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
171 spin_unlock_irq(&pDevice->lock);
172
173 return 0;
174 } else if (req->scan_type == IW_SCAN_TYPE_PASSIVE) { //passive scan
175 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
176 }
177 } else { //active scan
178 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
179 }
180
181 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
182 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
183 spin_unlock_irq(&pDevice->lock);
184
185 return 0;
186}
187
188/*
189 * Wireless Handler : get scan results
190 */
191
192static int iwctl_giwscan(struct net_device *dev,
193 struct iw_request_info *info,
194 struct iw_point *wrq,
195 char *extra)
196{
197 int ii, jj, kk;
198 struct vnt_private *pDevice = netdev_priv(dev);
199 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
200 PKnownBSS pBSS;
201 PWLAN_IE_SSID pItemSSID;
202 PWLAN_IE_SUPP_RATES pSuppRates, pExtSuppRates;
203 char *current_ev = extra;
204 char *end_buf = extra + IW_SCAN_MAX_DATA;
205 char *current_val = NULL;
206 struct iw_event iwe;
207 long ldBm;
208 char buf[MAX_WPA_IE_LEN * 2 + 30];
209
210 pr_debug(" SIOCGIWSCAN\n");
211
212 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
213 // In scanning..
214 return -EAGAIN;
215 }
216 pBSS = &(pMgmt->sBSSList[0]);
217 for (ii = 0, jj = 0; jj < MAX_BSS_NUM; jj++) {
218 if (current_ev >= end_buf)
219 break;
220 pBSS = &(pMgmt->sBSSList[jj]);
221 if (pBSS->bActive) {
222 //ADD mac address
223 memset(&iwe, 0, sizeof(iwe));
224 iwe.cmd = SIOCGIWAP;
225 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
226 memcpy(iwe.u.ap_addr.sa_data, pBSS->abyBSSID, WLAN_BSSID_LEN);
227 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
228 //ADD ssid
229 memset(&iwe, 0, sizeof(iwe));
230 iwe.cmd = SIOCGIWESSID;
231 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
232 iwe.u.data.length = pItemSSID->len;
233 iwe.u.data.flags = 1;
234 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pItemSSID->abySSID);
235 //ADD mode
236 memset(&iwe, 0, sizeof(iwe));
237 iwe.cmd = SIOCGIWMODE;
238 if (WLAN_GET_CAP_INFO_ESS(pBSS->wCapInfo))
239 iwe.u.mode = IW_MODE_INFRA;
240 else
241 iwe.u.mode = IW_MODE_ADHOC;
242
243 iwe.len = IW_EV_UINT_LEN;
244 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
245 //ADD frequency
246 pSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abySuppRates;
247 pExtSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abyExtSuppRates;
248 memset(&iwe, 0, sizeof(iwe));
249 iwe.cmd = SIOCGIWFREQ;
250 iwe.u.freq.m = pBSS->uChannel;
251 iwe.u.freq.e = 0;
252 iwe.u.freq.i = 0;
253 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
254 //2008-0409-04, <Add> by Einsn Liu
255 {
256 int f = (int)pBSS->uChannel - 1;
257
258 if (f < 0)f = 0;
259 iwe.u.freq.m = frequency_list[f] * 100000;
260 iwe.u.freq.e = 1;
261 }
262 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
263 //ADD quality
264 memset(&iwe, 0, sizeof(iwe));
265 iwe.cmd = IWEVQUAL;
266 RFvRSSITodBm(pDevice, (unsigned char)(pBSS->uRSSI), &ldBm);
267 iwe.u.qual.level = ldBm;
268 iwe.u.qual.noise = 0;
269//2008-0409-01, <Add> by Einsn Liu
270 if (-ldBm < 50)
271 iwe.u.qual.qual = 100;
272 else if (-ldBm > 90)
273 iwe.u.qual.qual = 0;
274 else
275 iwe.u.qual.qual = (40 - (-ldBm - 50)) * 100 / 40;
276
277 iwe.u.qual.updated = 7;
278
279 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
280
281 memset(&iwe, 0, sizeof(iwe));
282 iwe.cmd = SIOCGIWENCODE;
283 iwe.u.data.length = 0;
284 if (WLAN_GET_CAP_INFO_PRIVACY(pBSS->wCapInfo))
285 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
286 else
287 iwe.u.data.flags = IW_ENCODE_DISABLED;
288
289 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pItemSSID->abySSID);
290
291 memset(&iwe, 0, sizeof(iwe));
292 iwe.cmd = SIOCGIWRATE;
293 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
294 current_val = current_ev + IW_EV_LCP_LEN;
295
296 for (kk = 0; kk < 12; kk++) {
297 if (pSuppRates->abyRates[kk] == 0)
298 break;
299 // Bit rate given in 500 kb/s units (+ 0x80)
300 iwe.u.bitrate.value = ((pSuppRates->abyRates[kk] & 0x7f) * 500000);
301 current_val = iwe_stream_add_value(info, current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
302 }
303 for (kk = 0; kk < 8; kk++) {
304 if (pExtSuppRates->abyRates[kk] == 0)
305 break;
306 // Bit rate given in 500 kb/s units (+ 0x80)
307 iwe.u.bitrate.value = ((pExtSuppRates->abyRates[kk] & 0x7f) * 500000);
308 current_val = iwe_stream_add_value(info, current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
309 }
310
311 if ((current_val - current_ev) > IW_EV_LCP_LEN)
312 current_ev = current_val;
313
314 memset(&iwe, 0, sizeof(iwe));
315 iwe.cmd = IWEVCUSTOM;
316 sprintf(buf, "bcn_int=%d", pBSS->wBeaconInterval);
317 iwe.u.data.length = strlen(buf);
318 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, buf);
319
320 if ((pBSS->wWPALen > 0) && (pBSS->wWPALen <= MAX_WPA_IE_LEN)) {
321 memset(&iwe, 0, sizeof(iwe));
322 iwe.cmd = IWEVGENIE;
323 iwe.u.data.length = pBSS->wWPALen;
324 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pBSS->byWPAIE);
325 }
326
327 if ((pBSS->wRSNLen > 0) && (pBSS->wRSNLen <= MAX_WPA_IE_LEN)) {
328 memset(&iwe, 0, sizeof(iwe));
329 iwe.cmd = IWEVGENIE;
330 iwe.u.data.length = pBSS->wRSNLen;
331 current_ev = iwe_stream_add_point(info, current_ev, end_buf, &iwe, pBSS->byRSNIE);
332 }
333
334 }
335 }// for
336
337 wrq->length = current_ev - extra;
338 return 0;
339}
340
341/*
342 * Wireless Handler : set frequency or channel
343 */
344
345int iwctl_siwfreq(struct net_device *dev,
346 struct iw_request_info *info,
347 struct iw_freq *wrq,
348 char *extra)
349{
350 struct vnt_private *pDevice = netdev_priv(dev);
351 int rc = 0;
352
353 pr_debug(" SIOCSIWFREQ\n");
354
355 // If setting by frequency, convert to a channel
356 if ((wrq->e == 1) &&
357 (wrq->m >= (int) 2.412e8) &&
358 (wrq->m <= (int) 2.487e8)) {
359 int f = wrq->m / 100000;
360 int c = 0;
361
362 while ((c < 14) && (f != frequency_list[c]))
363 c++;
364 wrq->e = 0;
365 wrq->m = c + 1;
366 }
367 // Setting by channel number
368 if ((wrq->m > 14) || (wrq->e > 0))
369 rc = -EOPNOTSUPP;
370 else {
371 int channel = wrq->m;
372
373 if ((channel < 1) || (channel > 14)) {
374 pr_debug("%s: New channel value of %d is invalid!\n",
375 dev->name, wrq->m);
376 rc = -EINVAL;
377 } else {
378 // Yes ! We can set it !!!
379 pr_debug(" Set to channel = %d\n", channel);
380 pDevice->uChannel = channel;
381 //2007-0207-04,<Add> by EinsnLiu
382 //Make change effect at once
383 pDevice->bCommit = true;
384 }
385 }
386
387 return rc;
388}
389
390/*
391 * Wireless Handler : get frequency or channel
392 */
393
394int iwctl_giwfreq(struct net_device *dev,
395 struct iw_request_info *info,
396 struct iw_freq *wrq,
397 char *extra)
398{
399 struct vnt_private *pDevice = netdev_priv(dev);
400 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
401
402 pr_debug(" SIOCGIWFREQ\n");
403
404#ifdef WEXT_USECHANNELS
405 wrq->m = (int)pMgmt->uCurrChannel;
406 wrq->e = 0;
407#else
408 {
409 int f = (int)pMgmt->uCurrChannel - 1;
410
411 if (f < 0)
412 f = 0;
413 wrq->m = frequency_list[f] * 100000;
414 wrq->e = 1;
415 }
416#endif
417
418 return 0;
419}
420
421/*
422 * Wireless Handler : set operation mode
423 */
424
425int iwctl_siwmode(struct net_device *dev,
426 struct iw_request_info *info,
427 __u32 *wmode,
428 char *extra)
429{
430 struct vnt_private *pDevice = netdev_priv(dev);
431 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
432 int rc = 0;
433
434 pr_debug(" SIOCSIWMODE\n");
435
436 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP && pDevice->bEnableHostapd) {
437 pr_debug("Can't set operation mode, hostapd is running\n");
438 return rc;
439 }
440
441 switch (*wmode) {
442 case IW_MODE_ADHOC:
443 if (pMgmt->eConfigMode != WMAC_CONFIG_IBSS_STA) {
444 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
445 if (pDevice->flags & DEVICE_FLAGS_OPENED)
446 pDevice->bCommit = true;
447
448 }
449 pr_debug("set mode to ad-hoc\n");
450 break;
451 case IW_MODE_AUTO:
452 case IW_MODE_INFRA:
453 if (pMgmt->eConfigMode != WMAC_CONFIG_ESS_STA) {
454 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
455 if (pDevice->flags & DEVICE_FLAGS_OPENED)
456 pDevice->bCommit = true;
457
458 }
459 pr_debug("set mode to infrastructure\n");
460 break;
461 case IW_MODE_MASTER:
462
463 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
464 rc = -EOPNOTSUPP;
465 break;
466
467 if (pMgmt->eConfigMode != WMAC_CONFIG_AP) {
468 pMgmt->eConfigMode = WMAC_CONFIG_AP;
469 if (pDevice->flags & DEVICE_FLAGS_OPENED)
470 pDevice->bCommit = true;
471
472 }
473 pr_debug("set mode to Access Point\n");
474 break;
475
476 case IW_MODE_REPEAT:
477 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
478 rc = -EOPNOTSUPP;
479 break;
480 default:
481 rc = -EINVAL;
482 }
483
484 return rc;
485}
486
487/*
488 * Wireless Handler : get operation mode
489 */
490
491int iwctl_giwmode(struct net_device *dev,
492 struct iw_request_info *info,
493 __u32 *wmode,
494 char *extra)
495{
496 struct vnt_private *pDevice = netdev_priv(dev);
497 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
498
499 pr_debug(" SIOCGIWMODE\n");
500 // If not managed, assume it's ad-hoc
501 switch (pMgmt->eConfigMode) {
502 case WMAC_CONFIG_ESS_STA:
503 *wmode = IW_MODE_INFRA;
504 break;
505 case WMAC_CONFIG_IBSS_STA:
506 *wmode = IW_MODE_ADHOC;
507 break;
508 case WMAC_CONFIG_AUTO:
509 *wmode = IW_MODE_INFRA;
510 break;
511 case WMAC_CONFIG_AP:
512 *wmode = IW_MODE_MASTER;
513 break;
514 default:
515 *wmode = IW_MODE_ADHOC;
516 }
517
518 return 0;
519}
520
521/*
522 * Wireless Handler : get capability range
523 */
524
525int iwctl_giwrange(struct net_device *dev,
526 struct iw_request_info *info,
527 struct iw_point *wrq,
528 char *extra)
529{
530 struct iw_range *range = (struct iw_range *)extra;
531 int i, k;
532 unsigned char abySupportedRates[13] = {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
533
534 pr_debug(" SIOCGIWRANGE\n");
535 if (wrq->pointer) {
536 wrq->length = sizeof(struct iw_range);
537 memset(range, 0, sizeof(struct iw_range));
538 range->min_nwid = 0x0000;
539 range->max_nwid = 0x0000;
540 range->num_channels = 14;
541 // Should be based on cap_rid.country to give only
542 // what the current card support
543 k = 0;
544 for (i = 0; i < 14; i++) {
545 range->freq[k].i = i + 1; // List index
546 range->freq[k].m = frequency_list[i] * 100000;
547 range->freq[k++].e = 1; // Values in table in MHz -> * 10^5 * 10
548 }
549 range->num_frequency = k;
550 // Hum... Should put the right values there
551#ifdef Calcu_LinkQual
552 range->max_qual.qual = 100;
553#else
554 range->max_qual.qual = 255;
555#endif
556 range->max_qual.level = 0;
557 range->max_qual.noise = 0;
558 range->sensitivity = 255;
559
560 for (i = 0; i < 13; i++) {
561 range->bitrate[i] = abySupportedRates[i] * 500000;
562 if (range->bitrate[i] == 0)
563 break;
564 }
565 range->num_bitrates = i;
566
567 // Set an indication of the max TCP throughput
568 // in bit/s that we can expect using this interface.
569 // May be use for QoS stuff... Jean II
570 if (i > 2)
571 range->throughput = 5 * 1000 * 1000;
572 else
573 range->throughput = 1.5 * 1000 * 1000;
574
575 range->min_rts = 0;
576 range->max_rts = 2312;
577 range->min_frag = 256;
578 range->max_frag = 2312;
579
580 // the encoding capabilities
581 range->num_encoding_sizes = 3;
582 // 64(40) bits WEP
583 range->encoding_size[0] = 5;
584 // 128(104) bits WEP
585 range->encoding_size[1] = 13;
586 // 256 bits for WPA-PSK
587 range->encoding_size[2] = 32;
588 // 4 keys are allowed
589 range->max_encoding_tokens = 4;
590
591 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
592 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
593
594 range->min_pmp = 0;
595 range->max_pmp = 1000000;// 1 secs
596 range->min_pmt = 0;
597 range->max_pmt = 1000000;// 1 secs
598 range->pmp_flags = IW_POWER_PERIOD;
599 range->pmt_flags = IW_POWER_TIMEOUT;
600 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
601
602 // Transmit Power - values are in mW
603
604 range->txpower[0] = 100;
605 range->num_txpower = 1;
606 range->txpower_capa = IW_TXPOW_MWATT;
607 range->we_version_source = SUPPORTED_WIRELESS_EXT;
608 range->we_version_compiled = WIRELESS_EXT;
609 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
610 range->retry_flags = IW_RETRY_LIMIT;
611 range->r_time_flags = IW_RETRY_LIFETIME;
612 range->min_retry = 1;
613 range->max_retry = 65535;
614 range->min_r_time = 1024;
615 range->max_r_time = 65535 * 1024;
616 // Experimental measurements - boundary 11/5.5 Mb/s
617 // Note : with or without the (local->rssi), results
618 // are somewhat different. - Jean II
619 range->avg_qual.qual = 6;
620 range->avg_qual.level = 176; // -80 dBm
621 range->avg_qual.noise = 0;
622 }
623
624 return 0;
625}
626
627/*
628 * Wireless Handler : set ap mac address
629 */
630
631int iwctl_siwap(struct net_device *dev,
632 struct iw_request_info *info,
633 struct sockaddr *wrq,
634 char *extra)
635{
636 struct vnt_private *pDevice = netdev_priv(dev);
637 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
638 int rc = 0;
639 unsigned char ZeroBSSID[WLAN_BSSID_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
640
641 pr_debug(" SIOCSIWAP\n");
642 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
643 // In scanning..
644 pr_debug("SIOCSIWAP(??)-->In scanning..\n");
645 }
646 if (wrq->sa_family != ARPHRD_ETHER)
647 rc = -EINVAL;
648 else {
649 memcpy(pMgmt->abyDesireBSSID, wrq->sa_data, 6);
650 //2008-0409-05, <Add> by Einsn Liu
651 if ((pDevice->bLinkPass == true) &&
652 (memcmp(pMgmt->abyDesireBSSID, pMgmt->abyCurrBSSID, 6) == 0)) {
653 return rc;
654 }
655 //mike :add
656 if ((is_broadcast_ether_addr(pMgmt->abyDesireBSSID)) ||
657 (memcmp(pMgmt->abyDesireBSSID, ZeroBSSID, 6) == 0)) {
658 PRINT_K("SIOCSIWAP:invalid desired BSSID return!\n");
659 return rc;
660 }
661 //mike add: if desired AP is hidden ssid(there are two same BSSID in list),
662 // then ignore,because you don't known which one to be connect with??
663 {
664 unsigned int ii, uSameBssidNum = 0;
665
666 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
667 if (pMgmt->sBSSList[ii].bActive &&
668 ether_addr_equal(pMgmt->sBSSList[ii].abyBSSID,
669 pMgmt->abyDesireBSSID)) {
670 uSameBssidNum++;
671 }
672 }
673 if (uSameBssidNum >= 2) { //hit: desired AP is in hidden ssid mode!!!
674 PRINT_K("SIOCSIWAP:ignore for desired AP in hidden mode\n");
675 return rc;
676 }
677 }
678
679 if (pDevice->flags & DEVICE_FLAGS_OPENED)
680 pDevice->bCommit = true;
681
682 }
683 return rc;
684}
685
686/*
687 * Wireless Handler : get ap mac address
688 */
689
690int iwctl_giwap(struct net_device *dev,
691 struct iw_request_info *info,
692 struct sockaddr *wrq,
693 char *extra)
694{
695 struct vnt_private *pDevice = netdev_priv(dev);
696 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
697
698 pr_debug(" SIOCGIWAP\n");
699
700 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
701 //2008-0410,<Modify> by Einsn Liu
702 if ((pDevice->bLinkPass == false) && (pMgmt->eCurrMode != WMAC_MODE_ESS_AP))
703 memset(wrq->sa_data, 0, 6);
704
705 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)
706 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
707
708 wrq->sa_family = ARPHRD_ETHER;
709
710 return 0;
711}
712
713/*
714 * Wireless Handler : get ap list
715 */
716
717int iwctl_giwaplist(struct net_device *dev,
718 struct iw_request_info *info,
719 struct iw_point *wrq,
720 char *extra)
721{
722 int ii, jj, rc = 0;
723 struct sockaddr *sock = NULL;
724 struct sockaddr *s = NULL;
725 struct iw_quality *qual = NULL;
726 struct iw_quality *q = NULL;
727 PKnownBSS pBSS = NULL;
728
729 struct vnt_private *pDevice = netdev_priv(dev);
730 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
731
732 pr_debug(" SIOCGIWAPLIST\n");
733
734 if (!capable(CAP_NET_ADMIN)) {
735 rc = -EPERM;
736 goto exit;
737 }
738
739 if (!wrq->pointer)
740 goto exit;
741
742 sock = kmalloc_array(IW_MAX_AP, sizeof(struct sockaddr), GFP_KERNEL);
743 if (!sock) {
744 rc = -ENOMEM;
745 goto exit;
746 }
747
748 qual = kmalloc_array(IW_MAX_AP, sizeof(struct iw_quality), GFP_KERNEL);
749 if (!qual) {
750 rc = -ENOMEM;
751 goto exit;
752 }
753
754 for (ii = 0, jj = 0; ii < MAX_BSS_NUM; ii++) {
755 pBSS = &(pMgmt->sBSSList[ii]);
756
757 if (!pBSS->bActive)
758 continue;
759 if (jj >= IW_MAX_AP)
760 break;
761
762 s = &sock[jj];
763 q = &qual[jj];
764
765 memcpy(s->sa_data, pBSS->abyBSSID, 6);
766 s->sa_family = ARPHRD_ETHER;
767 q->level = pBSS->uRSSI;
768 q->qual = 0;
769 q->noise = 0;
770 q->updated = 2;
771 jj++;
772 }
773
774 wrq->flags = 1; /* Should be define'd */
775 wrq->length = jj;
776 memcpy(extra, sock, sizeof(struct sockaddr) * jj);
777 memcpy(extra + sizeof(struct sockaddr) * jj,
778 qual,
779 sizeof(struct iw_quality) * jj);
780exit:
781 kfree(sock);
782 kfree(qual);
783 return rc;
784}
785
786/*
787 * Wireless Handler : set essid
788 */
789
790int iwctl_siwessid(struct net_device *dev,
791 struct iw_request_info *info,
792 struct iw_point *wrq,
793 char *extra)
794{
795 struct vnt_private *pDevice = netdev_priv(dev);
796 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
797 PWLAN_IE_SSID pItemSSID;
798 //2008-0409-05, <Add> by Einsn Liu
799 unsigned char len;
800
801 pr_debug(" SIOCSIWESSID\n");
802 pDevice->fWPA_Authened = false;
803 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
804 // In scanning..
805 pr_debug("SIOCSIWESSID(??)-->In scanning..\n");
806 }
807 // Check if we asked for `any'
808 if (wrq->flags == 0) {
809 // Just send an empty SSID list
810 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
811 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
812 PRINT_K("set essid to 'any'\n");
813#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
814 return 0;
815#endif
816 } else {
817 // Set the SSID
818 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
819 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
820 pItemSSID->byElementID = WLAN_EID_SSID;
821
822 memcpy(pItemSSID->abySSID, extra, wrq->length);
823 if (pItemSSID->abySSID[wrq->length - 1] == '\0') {
824 if (wrq->length > 0)
825 pItemSSID->len = wrq->length - 1;
826 } else
827 pItemSSID->len = wrq->length;
828 pr_debug("set essid to %s\n", pItemSSID->abySSID);
829 //2008-0409-05, <Add> by Einsn Liu
830 len = (pItemSSID->len > ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) ? pItemSSID->len : ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len;
831 if ((pDevice->bLinkPass == true) &&
832 (memcmp(pItemSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID, len) == 0))
833 return 0;
834
835 //mike:need clear desiredBSSID
836 if (pItemSSID->len == 0) {
837 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
838 return 0;
839 }
840
841#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
842 //Wext wil order another command of siwap to link with desired AP,
843 //so here need not associate??
844 if (pDevice->bWPASuppWextEnabled == true) {
845 /*******search if in hidden ssid mode ****/
846 {
847 PKnownBSS pCurr = NULL;
848 unsigned char abyTmpDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
849 unsigned int ii, uSameBssidNum = 0;
850
851 memcpy(abyTmpDesireSSID, pMgmt->abyDesireSSID, sizeof(abyTmpDesireSSID));
852 pCurr = BSSpSearchBSSList(pDevice,
853 NULL,
854 abyTmpDesireSSID,
855 pMgmt->eConfigPHYMode
856);
857
858 if (pCurr == NULL) {
859 PRINT_K("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
860 vResetCommandTimer((void *)pDevice);
861 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
862 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
863 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
864 } else { //mike:to find out if that desired SSID is a hidden-ssid AP ,
865 // by means of judging if there are two same BSSID exist in list ?
866 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
867 if (pMgmt->sBSSList[ii].bActive &&
868 ether_addr_equal(pMgmt->sBSSList[ii].abyBSSID,
869 pCurr->abyBSSID)) {
870 uSameBssidNum++;
871 }
872 }
873 if (uSameBssidNum >= 2) { //hit: desired AP is in hidden ssid mode!!!
874 pr_debug("SIOCSIWESSID:hidden ssid directly associate.......\n");
875 vResetCommandTimer((void *)pDevice);
876 pMgmt->eScanType = WMAC_SCAN_PASSIVE; //this scan type,you'll submit scan result!
877 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
878 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
879 }
880 }
881 }
882 return 0;
883 }
884#endif
885
886 pr_debug("set essid = %s\n", pItemSSID->abySSID);
887 }
888
889 if (pDevice->flags & DEVICE_FLAGS_OPENED)
890 pDevice->bCommit = true;
891
892 return 0;
893}
894
895/*
896 * Wireless Handler : get essid
897 */
898
899int iwctl_giwessid(struct net_device *dev,
900 struct iw_request_info *info,
901 struct iw_point *wrq,
902 char *extra)
903{
904 struct vnt_private *pDevice = netdev_priv(dev);
905 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
906 PWLAN_IE_SSID pItemSSID;
907
908 pr_debug(" SIOCGIWESSID\n");
909
910 // Note : if wrq->u.data.flags != 0, we should
911 // get the relevant SSID from the SSID list...
912
913 // Get the current SSID
914 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
915 memcpy(extra, pItemSSID->abySSID , pItemSSID->len);
916 extra[pItemSSID->len] = '\0';
917 wrq->length = pItemSSID->len + 1;
918 //2008-0409-03, <Add> by Einsn Liu
919 wrq->length = pItemSSID->len;
920 wrq->flags = 1; // active
921
922 return 0;
923}
924
925/*
926 * Wireless Handler : set data rate
927 */
928
929int iwctl_siwrate(struct net_device *dev,
930 struct iw_request_info *info,
931 struct iw_param *wrq,
932 char *extra)
933{
934 struct vnt_private *pDevice = netdev_priv(dev);
935 int rc = 0;
936 u8 brate = 0;
937 int i;
938 unsigned char abySupportedRates[13] = {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
939
940 pr_debug(" SIOCSIWRATE\n");
941 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
942 rc = -EINVAL;
943 return rc;
944 }
945
946 // First : get a valid bit rate value
947
948 // Which type of value
949 if ((wrq->value < 13) &&
950 (wrq->value >= 0)) {
951 // Setting by rate index
952 // Find value in the magic rate table
953 brate = wrq->value;
954 } else {
955 // Setting by frequency value
956 u8 normvalue = (u8) (wrq->value/500000);
957
958 // Check if rate is valid
959 for (i = 0; i < 13; i++) {
960 if (normvalue == abySupportedRates[i]) {
961 brate = i;
962 break;
963 }
964 }
965 }
966 // -1 designed the max rate (mostly auto mode)
967 if (wrq->value == -1) {
968 // Get the highest available rate
969 for (i = 0; i < 13; i++) {
970 if (abySupportedRates[i] == 0)
971 break;
972 }
973 if (i != 0)
974 brate = i - 1;
975
976 }
977 // Check that it is valid
978 // brate is index of abySupportedRates[]
979 if (brate > 13) {
980 rc = -EINVAL;
981 return rc;
982 }
983
984 // Now, check if we want a fixed or auto value
985 if (wrq->fixed != 0) {
986 // Fixed mode
987 // One rate, fixed
988 pr_debug("Rate Fix\n");
989 pDevice->bFixRate = true;
990 if ((pDevice->byBBType == BB_TYPE_11B) && (brate > 3)) {
991 pDevice->uConnectionRate = 3;
992 } else {
993 pDevice->uConnectionRate = brate;
994 pr_debug("Fixed to Rate %d\n",
995 pDevice->uConnectionRate);
996 }
997
998 } else {
999 pDevice->bFixRate = false;
1000 pDevice->uConnectionRate = 13;
1001 pr_debug("auto rate:connection_rate is 13\n");
1002 }
1003
1004 return rc;
1005}
1006
1007/*
1008 * Wireless Handler : get data rate
1009 */
1010
1011int iwctl_giwrate(struct net_device *dev,
1012 struct iw_request_info *info,
1013 struct iw_param *wrq,
1014 char *extra)
1015{
1016 struct vnt_private *pDevice = netdev_priv(dev);
1017//2007-0118-05,<Mark> by EinsnLiu
1018//Mark the unnecessary sentences.
1019// PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1020
1021 pr_debug(" SIOCGIWRATE\n");
1022 {
1023 unsigned char abySupportedRates[13] = {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
1024 int brate = 0;
1025//2008-5-8 <modify> by chester
1026 if (pDevice->bLinkPass) {
1027 if (pDevice->bFixRate == true) {
1028 if (pDevice->uConnectionRate < 13) {
1029 brate = abySupportedRates[pDevice->uConnectionRate];
1030 } else {
1031 if (pDevice->byBBType == BB_TYPE_11B)
1032 brate = 0x16;
1033 if (pDevice->byBBType == BB_TYPE_11G)
1034 brate = 0x6C;
1035 if (pDevice->byBBType == BB_TYPE_11A)
1036 brate = 0x6C;
1037 }
1038 } else {
1039 brate = abySupportedRates[TxRate_iwconfig];
1040 }
1041 } else brate = 0;
1042
1043 wrq->value = brate * 500000;
1044 // If more than one rate, set auto
1045 if (pDevice->bFixRate == true)
1046 wrq->fixed = true;
1047 }
1048
1049 return 0;
1050}
1051
1052/*
1053 * Wireless Handler : set rts threshold
1054 */
1055
1056int iwctl_siwrts(struct net_device *dev,
1057 struct iw_request_info *info,
1058 struct iw_param *wrq,
1059 char *extra)
1060{
1061 struct vnt_private *pDevice = netdev_priv(dev);
1062 int rc = 0;
1063
1064 pr_debug(" SIOCSIWRTS\n");
1065
1066 {
1067 int rthr = wrq->value;
1068
1069 if (wrq->disabled)
1070 rthr = 2312;
1071
1072 if ((rthr < 0) || (rthr > 2312))
1073 rc = -EINVAL;
1074 else
1075 pDevice->wRTSThreshold = rthr;
1076 }
1077
1078 return 0;
1079}
1080
1081/*
1082 * Wireless Handler : get rts
1083 */
1084
1085int iwctl_giwrts(struct net_device *dev,
1086 struct iw_request_info *info,
1087 struct iw_param *wrq,
1088 char *extra)
1089{
1090 struct vnt_private *pDevice = netdev_priv(dev);
1091
1092 pr_debug(" SIOCGIWRTS\n");
1093 wrq->value = pDevice->wRTSThreshold;
1094 wrq->disabled = (wrq->value >= 2312);
1095 wrq->fixed = 1;
1096
1097 return 0;
1098}
1099
1100/*
1101 * Wireless Handler : set fragment threshold
1102 */
1103
1104int iwctl_siwfrag(struct net_device *dev,
1105 struct iw_request_info *info,
1106 struct iw_param *wrq,
1107 char *extra)
1108{
1109 struct vnt_private *pDevice = netdev_priv(dev);
1110 int rc = 0;
1111 int fthr = wrq->value;
1112
1113 pr_debug(" SIOCSIWFRAG\n");
1114
1115 if (wrq->disabled)
1116 fthr = 2312;
1117 if ((fthr < 256) || (fthr > 2312)) {
1118 rc = -EINVAL;
1119 } else {
1120 fthr &= ~0x1; // Get an even value
1121 pDevice->wFragmentationThreshold = (u16)fthr;
1122 }
1123
1124 return rc;
1125}
1126
1127/*
1128 * Wireless Handler : get fragment threshold
1129 */
1130
1131int iwctl_giwfrag(struct net_device *dev,
1132 struct iw_request_info *info,
1133 struct iw_param *wrq,
1134 char *extra)
1135{
1136 struct vnt_private *pDevice = netdev_priv(dev);
1137
1138 pr_debug(" SIOCGIWFRAG\n");
1139 wrq->value = pDevice->wFragmentationThreshold;
1140 wrq->disabled = (wrq->value >= 2312);
1141 wrq->fixed = 1;
1142
1143 return 0;
1144}
1145
1146/*
1147 * Wireless Handler : set retry threshold
1148 */
1149int iwctl_siwretry(struct net_device *dev,
1150 struct iw_request_info *info,
1151 struct iw_param *wrq,
1152 char *extra)
1153{
1154 struct vnt_private *pDevice = netdev_priv(dev);
1155 int rc = 0;
1156
1157 pr_debug(" SIOCSIWRETRY\n");
1158
1159 if (wrq->disabled) {
1160 rc = -EINVAL;
1161 return rc;
1162 }
1163
1164 if (wrq->flags & IW_RETRY_LIMIT) {
1165 if (wrq->flags & IW_RETRY_MAX)
1166 pDevice->byLongRetryLimit = wrq->value;
1167 else if (wrq->flags & IW_RETRY_MIN)
1168 pDevice->byShortRetryLimit = wrq->value;
1169 else {
1170 // No modifier : set both
1171 pDevice->byShortRetryLimit = wrq->value;
1172 pDevice->byLongRetryLimit = wrq->value;
1173 }
1174 }
1175 if (wrq->flags & IW_RETRY_LIFETIME)
1176 pDevice->wMaxTransmitMSDULifetime = wrq->value;
1177
1178 return rc;
1179}
1180
1181/*
1182 * Wireless Handler : get retry threshold
1183 */
1184int iwctl_giwretry(struct net_device *dev,
1185 struct iw_request_info *info,
1186 struct iw_param *wrq,
1187 char *extra)
1188{
1189 struct vnt_private *pDevice = netdev_priv(dev);
1190
1191 pr_debug(" SIOCGIWRETRY\n");
1192 wrq->disabled = 0; // Can't be disabled
1193
1194 // Note : by default, display the min retry number
1195 if ((wrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1196 wrq->flags = IW_RETRY_LIFETIME;
1197 wrq->value = (int)pDevice->wMaxTransmitMSDULifetime; //ms
1198 } else if ((wrq->flags & IW_RETRY_MAX)) {
1199 wrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1200 wrq->value = (int)pDevice->byLongRetryLimit;
1201 } else {
1202 wrq->flags = IW_RETRY_LIMIT;
1203 wrq->value = (int)pDevice->byShortRetryLimit;
1204 if ((int)pDevice->byShortRetryLimit != (int)pDevice->byLongRetryLimit)
1205 wrq->flags |= IW_RETRY_MIN;
1206 }
1207
1208 return 0;
1209}
1210
1211/*
1212 * Wireless Handler : set encode mode
1213 */
1214int iwctl_siwencode(struct net_device *dev,
1215 struct iw_request_info *info,
1216 struct iw_point *wrq,
1217 char *extra)
1218{
1219 struct vnt_private *pDevice = netdev_priv(dev);
1220 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1221 unsigned long dwKeyIndex = (unsigned long)(wrq->flags & IW_ENCODE_INDEX);
1222 int ii, uu, rc = 0;
1223 int index = (wrq->flags & IW_ENCODE_INDEX);
1224
1225//2007-0207-07,<Modify> by EinsnLiu
1226//There are some problems when using iwconfig encode/key command to set the WEP key.
1227//I almost rewrite this function.
1228//now it support:(assume the wireless interface's name is eth0)
1229//iwconfig eth0 key [1] 1122334455 open /*set key stirng to index 1,and driver using key index is set to 1*/
1230//iwconfig eth0 key [3] /*set driver using key index to 3,the key string no change */
1231//iwconfig eth0 key 1122334455 /*set key string to driver using index*/
1232//iwconfig eth0 key restricted /*enable share key*/
1233
1234 PSKeyTable pkeytab;
1235
1236 pr_debug(" SIOCSIWENCODE\n");
1237
1238 if ((wrq->flags & IW_ENCODE_DISABLED) == 0) {
1239 //Not disable encryption
1240
1241 if (dwKeyIndex > WLAN_WEP_NKEYS) {
1242 rc = -EINVAL;
1243 return rc;
1244 }
1245
1246 if (dwKeyIndex < 1 && ((wrq->flags & IW_ENCODE_NOKEY) == 0)) {//set default key
1247 if (pDevice->byKeyIndex < WLAN_WEP_NKEYS)
1248 dwKeyIndex = pDevice->byKeyIndex;
1249 else
1250 dwKeyIndex = 0;
1251 } else {
1252 dwKeyIndex--;
1253 }
1254
1255 // Check the size of the key
1256 if (wrq->length > WLAN_WEP232_KEYLEN) {
1257 rc = -EINVAL;
1258 return rc;
1259 }
1260
1261 if (wrq->length > 0) {//have key
1262
1263 if (wrq->length == WLAN_WEP232_KEYLEN) {
1264 pr_debug("Set 232 bit wep key\n");
1265 } else if (wrq->length == WLAN_WEP104_KEYLEN) {
1266 pr_debug("Set 104 bit wep key\n");
1267 } else if (wrq->length == WLAN_WEP40_KEYLEN) {
1268 pr_debug("Set 40 bit wep key, index= %d\n",
1269 (int)dwKeyIndex);
1270 } else {//no support length
1271 rc = -EINVAL;
1272 return rc;
1273 }
1274 memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN);
1275 memcpy(pDevice->abyKey, extra, wrq->length);
1276
1277 pr_debug("abyKey: ");
1278 for (ii = 0; ii < wrq->length; ii++)
1279 pr_debug("%02x ", pDevice->abyKey[ii]);
1280
1281 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1282 spin_lock_irq(&pDevice->lock);
1283 KeybSetDefaultKey(&(pDevice->sKey),
1284 (unsigned long)(dwKeyIndex | (1 << 31)),
1285 wrq->length,
1286 NULL,
1287 pDevice->abyKey,
1288 KEY_CTL_WEP,
1289 pDevice->PortOffset,
1290 pDevice->byLocalID
1291);
1292 spin_unlock_irq(&pDevice->lock);
1293 }
1294 pDevice->byKeyIndex = (unsigned char)dwKeyIndex;
1295 pDevice->uKeyLength = wrq->length;
1296 pDevice->bTransmitKey = true;
1297 pDevice->bEncryptionEnable = true;
1298 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1299
1300 } else if (index > 0) {
1301 //when the length is 0 the request only changes the default transmit key index
1302 //check the new key if it has a non zero length
1303 if (pDevice->bEncryptionEnable == false) {
1304 rc = -EINVAL;
1305 return rc;
1306 }
1307 pr_debug("Just set Default key Index:\n");
1308 pkeytab = &(pDevice->sKey.KeyTable[MAX_KEY_TABLE - 1]);
1309 if (pkeytab->GroupKey[(unsigned char)dwKeyIndex].uKeyLength == 0) {
1310 pr_debug("Default key len is 0\n");
1311 rc = -EINVAL;
1312 return rc;
1313 }
1314 pDevice->byKeyIndex = (unsigned char)dwKeyIndex;
1315 pkeytab->dwGTKeyIndex = dwKeyIndex | (1 << 31);
1316 pkeytab->GroupKey[(unsigned char)dwKeyIndex].dwKeyIndex = dwKeyIndex | (1 << 31);
1317 }
1318
1319 } else {//disable the key
1320 pr_debug("Disable WEP function\n");
1321 if (pDevice->bEncryptionEnable == false)
1322 return 0;
1323 pMgmt->bShareKeyAlgorithm = false;
1324 pDevice->bEncryptionEnable = false;
1325 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1326 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1327 spin_lock_irq(&pDevice->lock);
1328 for (uu = 0; uu < MAX_KEY_TABLE; uu++)
1329 MACvDisableKeyEntry(pDevice->PortOffset, uu);
1330 spin_unlock_irq(&pDevice->lock);
1331 }
1332 }
1333//End Modify,Einsn
1334
1335 if (wrq->flags & IW_ENCODE_RESTRICTED) {
1336 pr_debug("Enable WEP & ShareKey System\n");
1337 pMgmt->bShareKeyAlgorithm = true;
1338 }
1339 if (wrq->flags & IW_ENCODE_OPEN) {
1340 pr_debug("Enable WEP & Open System\n");
1341 pMgmt->bShareKeyAlgorithm = false;
1342 }
1343 return rc;
1344}
1345
1346int iwctl_giwencode(struct net_device *dev,
1347 struct iw_request_info *info,
1348 struct iw_point *wrq,
1349 char *extra)
1350{
1351 struct vnt_private *pDevice = netdev_priv(dev);
1352 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1353 char abyKey[WLAN_WEP232_KEYLEN];
1354
1355 unsigned int index = (unsigned int)(wrq->flags & IW_ENCODE_INDEX);
1356 PSKeyItem pKey = NULL;
1357
1358 pr_debug(" SIOCGIWENCODE\n");
1359
1360 if (index > WLAN_WEP_NKEYS)
1361 return -EINVAL;
1362
1363 if (index < 1) {//get default key
1364 if (pDevice->byKeyIndex < WLAN_WEP_NKEYS)
1365 index = pDevice->byKeyIndex;
1366 else
1367 index = 0;
1368 } else {
1369 index--;
1370 }
1371
1372 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
1373 // Check encryption mode
1374 wrq->flags = IW_ENCODE_NOKEY;
1375 // Is WEP enabled ???
1376 if (pDevice->bEncryptionEnable)
1377 wrq->flags |= IW_ENCODE_ENABLED;
1378 else
1379 wrq->flags |= IW_ENCODE_DISABLED;
1380
1381 if (pMgmt->bShareKeyAlgorithm)
1382 wrq->flags |= IW_ENCODE_RESTRICTED;
1383 else
1384 wrq->flags |= IW_ENCODE_OPEN;
1385 wrq->length = 0;
1386
1387 if ((index == 0) && (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled ||
1388 pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)) {//get wpa pairwise key
1389 if (KeybGetKey(&(pDevice->sKey), pMgmt->abyCurrBSSID, 0xffffffff, &pKey)) {
1390 wrq->length = pKey->uKeyLength;
1391 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1392 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1393 }
1394 } else if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (unsigned char)index , &pKey)) {
1395 wrq->length = pKey->uKeyLength;
1396 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1397 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1398 }
1399
1400 wrq->flags |= index+1;
1401
1402 return 0;
1403}
1404
1405/*
1406 * Wireless Handler : set power mode
1407 */
1408int iwctl_siwpower(struct net_device *dev,
1409 struct iw_request_info *info,
1410 struct iw_param *wrq,
1411 char *extra)
1412{
1413 struct vnt_private *pDevice = netdev_priv(dev);
1414 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1415 int rc = 0;
1416
1417 pr_debug(" SIOCSIWPOWER\n");
1418
1419 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
1420 rc = -EINVAL;
1421 return rc;
1422 }
1423
1424 if (wrq->disabled) {
1425 pDevice->ePSMode = WMAC_POWER_CAM;
1426 PSvDisablePowerSaving(pDevice);
1427 return rc;
1428 }
1429 if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1430 pDevice->ePSMode = WMAC_POWER_FAST;
1431 PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
1432
1433 } else if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
1434 pDevice->ePSMode = WMAC_POWER_FAST;
1435 PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
1436 }
1437 switch (wrq->flags & IW_POWER_MODE) {
1438 case IW_POWER_UNICAST_R:
1439 pr_debug(" SIOCSIWPOWER: IW_POWER_UNICAST_R\n");
1440 rc = -EINVAL;
1441 break;
1442 case IW_POWER_ALL_R:
1443 pr_debug(" SIOCSIWPOWER: IW_POWER_ALL_R\n");
1444 rc = -EINVAL;
1445 case IW_POWER_ON:
1446 pr_debug(" SIOCSIWPOWER: IW_POWER_ON\n");
1447 break;
1448 default:
1449 rc = -EINVAL;
1450 }
1451
1452 return rc;
1453}
1454
1455/*
1456 * Wireless Handler : get power mode
1457 */
1458int iwctl_giwpower(struct net_device *dev,
1459 struct iw_request_info *info,
1460 struct iw_param *wrq,
1461 char *extra)
1462{
1463 struct vnt_private *pDevice = netdev_priv(dev);
1464 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1465 int mode = pDevice->ePSMode;
1466
1467 pr_debug(" SIOCGIWPOWER\n");
1468
1469 wrq->disabled = (mode == WMAC_POWER_CAM);
1470 if (wrq->disabled)
1471 return 0;
1472
1473 if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1474 wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10);
1475 wrq->flags = IW_POWER_TIMEOUT;
1476 } else {
1477 wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10);
1478 wrq->flags = IW_POWER_PERIOD;
1479 }
1480 wrq->flags |= IW_POWER_ALL_R;
1481
1482 return 0;
1483}
1484
1485/*
1486 * Wireless Handler : get Sensitivity
1487 */
1488int iwctl_giwsens(struct net_device *dev,
1489 struct iw_request_info *info,
1490 struct iw_param *wrq,
1491 char *extra)
1492{
1493 struct vnt_private *pDevice = netdev_priv(dev);
1494 long ldBm;
1495
1496 pr_debug(" SIOCGIWSENS\n");
1497 if (pDevice->bLinkPass == true) {
1498 RFvRSSITodBm(pDevice, (unsigned char)(pDevice->uCurrRSSI), &ldBm);
1499 wrq->value = ldBm;
1500 } else {
1501 wrq->value = 0;
1502 }
1503 wrq->disabled = (wrq->value == 0);
1504 wrq->fixed = 1;
1505
1506 return 0;
1507}
1508
1509//2008-0409-07, <Add> by Einsn Liu
1510#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1511
1512int iwctl_siwauth(struct net_device *dev,
1513 struct iw_request_info *info,
1514 struct iw_param *wrq,
1515 char *extra)
1516{
1517 struct vnt_private *pDevice = netdev_priv(dev);
1518 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1519 int ret = 0;
1520 static int wpa_version = 0; //must be static to save the last value,einsn liu
1521 static int pairwise = 0;
1522
1523 pr_debug(" SIOCSIWAUTH\n");
1524 switch (wrq->flags & IW_AUTH_INDEX) {
1525 case IW_AUTH_WPA_VERSION:
1526 wpa_version = wrq->value;
1527 if (wrq->value == IW_AUTH_WPA_VERSION_DISABLED)
1528 PRINT_K("iwctl_siwauth:set WPADEV to disable at 1??????\n");
1529 else if (wrq->value == IW_AUTH_WPA_VERSION_WPA)
1530 PRINT_K("iwctl_siwauth:set WPADEV to WPA1******\n");
1531 else
1532 PRINT_K("iwctl_siwauth:set WPADEV to WPA2******\n");
1533
1534 break;
1535 case IW_AUTH_CIPHER_PAIRWISE:
1536 pairwise = wrq->value;
1537 if (pairwise == IW_AUTH_CIPHER_CCMP)
1538 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1539 else if (pairwise == IW_AUTH_CIPHER_TKIP)
1540 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1541 else if (pairwise == IW_AUTH_CIPHER_WEP40 || pairwise == IW_AUTH_CIPHER_WEP104)
1542 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1543 else if (pairwise == IW_AUTH_CIPHER_NONE)
1544 ; /* do nothing,einsn liu */
1545 else
1546 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1547
1548 break;
1549 case IW_AUTH_CIPHER_GROUP:
1550 if (wpa_version == IW_AUTH_WPA_VERSION_DISABLED)
1551 break;
1552 if (pairwise == IW_AUTH_CIPHER_NONE) {
1553 if (wrq->value == IW_AUTH_CIPHER_CCMP)
1554 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1555 else
1556 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1557 }
1558 break;
1559 case IW_AUTH_KEY_MGMT:
1560
1561 if (wpa_version == IW_AUTH_WPA_VERSION_WPA2) {
1562 if (wrq->value == IW_AUTH_KEY_MGMT_PSK)
1563 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
1564 else
1565 pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
1566 } else if (wpa_version == IW_AUTH_WPA_VERSION_WPA) {
1567 if (wrq->value == 0)
1568 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
1569 else if (wrq->value == IW_AUTH_KEY_MGMT_PSK)
1570 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
1571 else
1572 pMgmt->eAuthenMode = WMAC_AUTH_WPA;
1573 }
1574
1575 break;
1576 case IW_AUTH_TKIP_COUNTERMEASURES:
1577 break; /* FIXME */
1578 case IW_AUTH_DROP_UNENCRYPTED:
1579 break;
1580 case IW_AUTH_80211_AUTH_ALG:
1581 if (wrq->value == IW_AUTH_ALG_OPEN_SYSTEM)
1582 pMgmt->bShareKeyAlgorithm = false;
1583 else if (wrq->value == IW_AUTH_ALG_SHARED_KEY)
1584 pMgmt->bShareKeyAlgorithm = true;
1585
1586 break;
1587 case IW_AUTH_WPA_ENABLED:
1588 break;
1589 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1590 break;
1591 case IW_AUTH_ROAMING_CONTROL:
1592 ret = -EOPNOTSUPP;
1593 break;
1594 case IW_AUTH_PRIVACY_INVOKED:
1595 pDevice->bEncryptionEnable = !!wrq->value;
1596 if (pDevice->bEncryptionEnable == false) {
1597 wpa_version = 0;
1598 pairwise = 0;
1599 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1600 pMgmt->bShareKeyAlgorithm = false;
1601 pMgmt->eAuthenMode = false;
1602 }
1603
1604 break;
1605 default:
1606 ret = -EOPNOTSUPP;
1607 break;
1608 }
1609
1610 return ret;
1611}
1612
1613int iwctl_giwauth(struct net_device *dev,
1614 struct iw_request_info *info,
1615 struct iw_param *wrq,
1616 char *extra)
1617{
1618 return -EOPNOTSUPP;
1619}
1620
1621int iwctl_siwgenie(struct net_device *dev,
1622 struct iw_request_info *info,
1623 struct iw_point *wrq,
1624 char __user *extra)
1625{
1626 struct vnt_private *pDevice = netdev_priv(dev);
1627 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1628 int ret = 0;
1629 char length;
1630
1631 if (wrq->length) {
1632 if (wrq->length < 2)
1633 return -EINVAL;
1634
1635 ret = get_user(length, extra + 1);
1636 if (ret)
1637 return ret;
1638
1639 if (length + 2 != wrq->length)
1640 return -EINVAL;
1641
1642 if (wrq->length > MAX_WPA_IE_LEN) {
1643 ret = -ENOMEM;
1644 goto out;
1645 }
1646 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1647 if (copy_from_user(pMgmt->abyWPAIE, extra, wrq->length)) {
1648 ret = -EFAULT;
1649 goto out;
1650 }
1651 pMgmt->wWPAIELen = wrq->length;
1652 } else {
1653 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
1654 pMgmt->wWPAIELen = 0;
1655 }
1656
1657out://not completely ...not necessary in wpa_supplicant 0.5.8
1658 return ret;
1659}
1660
1661int iwctl_giwgenie(struct net_device *dev,
1662 struct iw_request_info *info,
1663 struct iw_point *wrq,
1664 char __user *extra)
1665{
1666 struct vnt_private *pDevice = netdev_priv(dev);
1667 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1668 int ret = 0;
1669 int space = wrq->length;
1670
1671 wrq->length = 0;
1672 if (pMgmt->wWPAIELen > 0) {
1673 wrq->length = pMgmt->wWPAIELen;
1674 if (pMgmt->wWPAIELen <= space) {
1675 if (copy_to_user(extra, pMgmt->abyWPAIE, pMgmt->wWPAIELen))
1676 ret = -EFAULT;
1677
1678 } else {
1679 ret = -E2BIG;
1680 }
1681 }
1682
1683 return ret;
1684}
1685
1686int iwctl_siwencodeext(struct net_device *dev,
1687 struct iw_request_info *info,
1688 struct iw_point *wrq,
1689 char *extra)
1690{
1691 struct vnt_private *pDevice = netdev_priv(dev);
1692 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1693 struct viawget_wpa_param *param = NULL;
1694//original member
1695 enum wpa_alg alg_name;
1696 u8 addr[6];
1697 int key_idx, set_tx = 0;
1698 u8 seq[IW_ENCODE_SEQ_MAX_SIZE];
1699 u8 key[64];
1700 size_t seq_len = 0, key_len = 0;
1701
1702 u8 key_array[64];
1703 int ret = 0;
1704
1705 PRINT_K("SIOCSIWENCODEEXT......\n");
1706
1707 param = kzalloc(sizeof(*param), GFP_KERNEL);
1708 if (param == NULL)
1709 return -ENOMEM;
1710
1711//recover alg_name
1712 switch (ext->alg) {
1713 case IW_ENCODE_ALG_NONE:
1714 alg_name = WPA_ALG_NONE;
1715 break;
1716 case IW_ENCODE_ALG_WEP:
1717 alg_name = WPA_ALG_WEP;
1718 break;
1719 case IW_ENCODE_ALG_TKIP:
1720 alg_name = WPA_ALG_TKIP;
1721 break;
1722 case IW_ENCODE_ALG_CCMP:
1723 alg_name = WPA_ALG_CCMP;
1724 break;
1725 default:
1726 PRINT_K("Unknown alg = %d\n", ext->alg);
1727 ret = -ENOMEM;
1728 goto error;
1729 }
1730//recover addr
1731 memcpy(addr, ext->addr.sa_data, ETH_ALEN);
1732//recover key_idx
1733 key_idx = (wrq->flags&IW_ENCODE_INDEX) - 1;
1734//recover set_tx
1735 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
1736 set_tx = 1;
1737//recover seq,seq_len
1738 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
1739 seq_len = IW_ENCODE_SEQ_MAX_SIZE;
1740 memcpy(seq, ext->rx_seq, seq_len);
1741 }
1742//recover key,key_len
1743 if (ext->key_len) {
1744 key_len = ext->key_len;
1745 memcpy(key, &ext->key[0], key_len);
1746 }
1747
1748 memset(key_array, 0, 64);
1749 if (key_len > 0) {
1750 memcpy(key_array, key, key_len);
1751 if (key_len == 32) {
1752 // notice ! the oder
1753 memcpy(&key_array[16], &key[24], 8);
1754 memcpy(&key_array[24], &key[16], 8);
1755 }
1756 }
1757
1758/**************Translate iw_encode_ext to viawget_wpa_param****************/
1759 memcpy(param->addr, addr, ETH_ALEN);
1760 param->u.wpa_key.alg_name = (int)alg_name;
1761 param->u.wpa_key.set_tx = set_tx;
1762 param->u.wpa_key.key_index = key_idx;
1763 param->u.wpa_key.key_len = key_len;
1764 param->u.wpa_key.key = (u8 *)key_array;
1765 param->u.wpa_key.seq = (u8 *)seq;
1766 param->u.wpa_key.seq_len = seq_len;
1767
1768//****set if current action is Network Manager count??
1769//****this method is so foolish,but there is no other way???
1770 if (param->u.wpa_key.alg_name == WPA_ALG_NONE) {
1771 if (param->u.wpa_key.key_index == 0)
1772 pDevice->bwextcount++;
1773
1774 if ((pDevice->bwextcount == 1) && (param->u.wpa_key.key_index == 1))
1775 pDevice->bwextcount++;
1776
1777 if ((pDevice->bwextcount == 2) && (param->u.wpa_key.key_index == 2))
1778 pDevice->bwextcount++;
1779
1780 if ((pDevice->bwextcount == 3) && (param->u.wpa_key.key_index == 3))
1781 pDevice->bwextcount++;
1782
1783 }
1784 if (pDevice->bwextcount == 4) {
1785 pr_debug("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n");
1786 pDevice->bwextcount = 0;
1787 pDevice->bWPASuppWextEnabled = true;
1788 }
1789//******
1790
1791 spin_lock_irq(&pDevice->lock);
1792 ret = wpa_set_keys(pDevice, param, true);
1793 spin_unlock_irq(&pDevice->lock);
1794
1795error:
1796 kfree(param);
1797 return ret;
1798}
1799
1800int iwctl_giwencodeext(struct net_device *dev,
1801 struct iw_request_info *info,
1802 struct iw_point *wrq,
1803 char *extra)
1804{
1805 return -EOPNOTSUPP;
1806}
1807
1808int iwctl_siwmlme(struct net_device *dev,
1809 struct iw_request_info *info,
1810 struct iw_point *wrq,
1811 char __user *extra)
1812{
1813 struct vnt_private *pDevice = netdev_priv(dev);
1814 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1815 struct iw_mlme mime;
1816
1817 int ret = 0;
1818
1819 ret = copy_from_user(&mime, extra, sizeof(mime));
1820 if (ret)
1821 return -EFAULT;
1822
1823 if (memcmp(pMgmt->abyCurrBSSID, mime.addr.sa_data, ETH_ALEN)) {
1824 ret = -EINVAL;
1825 return ret;
1826 }
1827 switch (mime.cmd) {
1828 case IW_MLME_DEAUTH:
1829 //this command seems to be not complete,please test it --einsnliu
1830 //bScheduleCommand((void *) pDevice, WLAN_CMD_DEAUTH, (unsigned char *)&reason);
1831 break;
1832 case IW_MLME_DISASSOC:
1833 if (pDevice->bLinkPass == true) {
1834 pr_debug("iwctl_siwmlme--->send DISASSOCIATE\n");
1835 //clear related flags
1836 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
1837 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
1838 bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
1839 }
1840 break;
1841 default:
1842 ret = -EOPNOTSUPP;
1843 }
1844
1845 return ret;
1846}
1847
1848#endif
1849
1850/*------------------------------------------------------------------*/
1851/*
1852 * Structures to export the Wireless Handlers
1853 */
1854
1855static const iw_handler iwctl_handler[] =
1856{
1857 (iw_handler) iwctl_commit, // SIOCSIWCOMMIT
1858 (iw_handler) NULL, // SIOCGIWNAME
1859 (iw_handler) NULL, // SIOCSIWNWID
1860 (iw_handler) NULL, // SIOCGIWNWID
1861 (iw_handler) NULL, // SIOCSIWFREQ
1862 (iw_handler) NULL, // SIOCGIWFREQ
1863 (iw_handler) NULL, // SIOCSIWMODE
1864 (iw_handler) NULL, // SIOCGIWMODE
1865 (iw_handler) NULL, // SIOCSIWSENS
1866 (iw_handler) NULL, // SIOCGIWSENS
1867 (iw_handler) NULL, // SIOCSIWRANGE
1868 (iw_handler) iwctl_giwrange, // SIOCGIWRANGE
1869 (iw_handler) NULL, // SIOCSIWPRIV
1870 (iw_handler) NULL, // SIOCGIWPRIV
1871 (iw_handler) NULL, // SIOCSIWSTATS
1872 (iw_handler) NULL, // SIOCGIWSTATS
1873 (iw_handler) NULL, // SIOCSIWSPY
1874 (iw_handler) NULL, // SIOCGIWSPY
1875 (iw_handler) NULL, // -- hole --
1876 (iw_handler) NULL, // -- hole --
1877 (iw_handler) NULL, // SIOCSIWAP
1878 (iw_handler) NULL, // SIOCGIWAP
1879 (iw_handler) NULL, // -- hole -- 0x16
1880 (iw_handler) NULL, // SIOCGIWAPLIST
1881 (iw_handler) iwctl_siwscan, // SIOCSIWSCAN
1882 (iw_handler) iwctl_giwscan, // SIOCGIWSCAN
1883 (iw_handler) NULL, // SIOCSIWESSID
1884 (iw_handler) NULL, // SIOCGIWESSID
1885 (iw_handler) NULL, // SIOCSIWNICKN
1886 (iw_handler) NULL, // SIOCGIWNICKN
1887 (iw_handler) NULL, // -- hole --
1888 (iw_handler) NULL, // -- hole --
1889 (iw_handler) NULL, // SIOCSIWRATE 0x20
1890 (iw_handler) NULL, // SIOCGIWRATE
1891 (iw_handler) NULL, // SIOCSIWRTS
1892 (iw_handler) NULL, // SIOCGIWRTS
1893 (iw_handler) NULL, // SIOCSIWFRAG
1894 (iw_handler) NULL, // SIOCGIWFRAG
1895 (iw_handler) NULL, // SIOCSIWTXPOW
1896 (iw_handler) NULL, // SIOCGIWTXPOW
1897 (iw_handler) NULL, // SIOCSIWRETRY
1898 (iw_handler) NULL, // SIOCGIWRETRY
1899 (iw_handler) NULL, // SIOCSIWENCODE
1900 (iw_handler) NULL, // SIOCGIWENCODE
1901 (iw_handler) NULL, // SIOCSIWPOWER
1902 (iw_handler) NULL, // SIOCGIWPOWER
1903
1904//2008-0409-07, <Add> by Einsn Liu
1905 (iw_handler) NULL, // -- hole --
1906 (iw_handler) NULL, // -- hole --
1907 (iw_handler) NULL, // SIOCSIWGENIE
1908 (iw_handler) NULL, // SIOCGIWGENIE
1909 (iw_handler) NULL, // SIOCSIWAUTH
1910 (iw_handler) NULL, // SIOCGIWAUTH
1911 (iw_handler) NULL, // SIOCSIWENCODEEXT
1912 (iw_handler) NULL, // SIOCGIWENCODEEXT
1913 (iw_handler) NULL, // SIOCSIWPMKSA
1914 (iw_handler) NULL, // -- hole --
1915};
1916
1917static const iw_handler iwctl_private_handler[] =
1918{
1919 NULL, // SIOCIWFIRSTPRIV
1920};
1921
1922struct iw_priv_args iwctl_private_args[] = {
1923 { IOCTL_CMD_SET,
1924 IW_PRIV_TYPE_CHAR | 1024, 0,
1925 "set"},
1926};
1927
1928const struct iw_handler_def iwctl_handler_def =
1929{
1930 .get_wireless_stats = &iwctl_get_wireless_stats,
1931 .num_standard = sizeof(iwctl_handler)/sizeof(iw_handler),
1932 .num_private = 0,
1933 .num_private_args = 0,
1934 .standard = (iw_handler *)iwctl_handler,
1935 .private = NULL,
1936 .private_args = NULL,
1937};
diff --git a/drivers/staging/vt6655/iwctl.h b/drivers/staging/vt6655/iwctl.h
deleted file mode 100644
index 7dd63102182d..000000000000
--- a/drivers/staging/vt6655/iwctl.h
+++ /dev/null
@@ -1,206 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: iwctl.h
20 *
21 * Purpose:
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 21, 2004
26 *
27 */
28
29#ifndef __IWCTL_H__
30#define __IWCTL_H__
31
32#include "device.h"
33
34/*--------------------- Export Definitions -------------------------*/
35
36/*--------------------- Export Classes ----------------------------*/
37
38/*--------------------- Export Variables --------------------------*/
39
40/*--------------------- Export Functions --------------------------*/
41
42struct iw_statistics *iwctl_get_wireless_stats(struct net_device *dev);
43
44int iwctl_siwap(struct net_device *dev,
45 struct iw_request_info *info,
46 struct sockaddr *wrq,
47 char *extra);
48
49int iwctl_giwrange(struct net_device *dev,
50 struct iw_request_info *info,
51 struct iw_point *wrq,
52 char *extra);
53
54int iwctl_giwmode(struct net_device *dev,
55 struct iw_request_info *info,
56 __u32 *wmode,
57 char *extra);
58
59int iwctl_siwmode(struct net_device *dev,
60 struct iw_request_info *info,
61 __u32 *wmode,
62 char *extra);
63
64int iwctl_giwfreq(struct net_device *dev,
65 struct iw_request_info *info,
66 struct iw_freq *wrq,
67 char *extra);
68
69int iwctl_siwfreq(struct net_device *dev,
70 struct iw_request_info *info,
71 struct iw_freq *wrq,
72 char *extra);
73
74int iwctl_giwname(struct net_device *dev,
75 struct iw_request_info *info,
76 char *wrq,
77 char *extra);
78
79int iwctl_giwsens(struct net_device *dev,
80 struct iw_request_info *info,
81 struct iw_param *wrq,
82 char *extra);
83
84int iwctl_giwap(struct net_device *dev,
85 struct iw_request_info *info,
86 struct sockaddr *wrq,
87 char *extra);
88
89int iwctl_giwaplist(struct net_device *dev,
90 struct iw_request_info *info,
91 struct iw_point *wrq,
92 char *extra);
93
94int iwctl_siwessid(struct net_device *dev,
95 struct iw_request_info *info,
96 struct iw_point *wrq,
97 char *extra);
98
99int iwctl_giwessid(struct net_device *dev,
100 struct iw_request_info *info,
101 struct iw_point *wrq,
102 char *extra);
103
104int iwctl_siwrate(struct net_device *dev,
105 struct iw_request_info *info,
106 struct iw_param *wrq,
107 char *extra);
108
109int iwctl_giwrate(struct net_device *dev,
110 struct iw_request_info *info,
111 struct iw_param *wrq,
112 char *extra);
113
114int iwctl_siwrts(struct net_device *dev,
115 struct iw_request_info *info,
116 struct iw_param *wrq,
117 char *extra);
118
119int iwctl_giwrts(struct net_device *dev,
120 struct iw_request_info *info,
121 struct iw_param *wrq,
122 char *extra);
123
124int iwctl_siwfrag(struct net_device *dev,
125 struct iw_request_info *info,
126 struct iw_param *wrq,
127 char *extra);
128
129int iwctl_giwfrag(struct net_device *dev,
130 struct iw_request_info *info,
131 struct iw_param *wrq,
132 char *extra);
133
134int iwctl_siwretry(struct net_device *dev,
135 struct iw_request_info *info,
136 struct iw_param *wrq,
137 char *extra);
138
139int iwctl_giwretry(struct net_device *dev,
140 struct iw_request_info *info,
141 struct iw_param *wrq,
142 char *extra);
143
144int iwctl_siwencode(struct net_device *dev,
145 struct iw_request_info *info,
146 struct iw_point *wrq,
147 char *extra);
148
149int iwctl_giwencode(struct net_device *dev,
150 struct iw_request_info *info,
151 struct iw_point *wrq,
152 char *extra);
153
154int iwctl_siwpower(struct net_device *dev,
155 struct iw_request_info *info,
156 struct iw_param *wrq,
157 char *extra);
158
159int iwctl_giwpower(struct net_device *dev,
160 struct iw_request_info *info,
161 struct iw_param *wrq,
162 char *extra);
163
164//2008-0409-07, <Add> by Einsn Liu
165#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
166int iwctl_siwauth(struct net_device *dev,
167 struct iw_request_info *info,
168 struct iw_param *wrq,
169 char *extra);
170
171int iwctl_giwauth(struct net_device *dev,
172 struct iw_request_info *info,
173 struct iw_param *wrq,
174 char *extra);
175
176int iwctl_siwgenie(struct net_device *dev,
177 struct iw_request_info *info,
178 struct iw_point *wrq,
179 char __user *extra);
180
181int iwctl_giwgenie(struct net_device *dev,
182 struct iw_request_info *info,
183 struct iw_point *wrq,
184 char __user *extra);
185
186int iwctl_siwencodeext(struct net_device *dev,
187 struct iw_request_info *info,
188 struct iw_point *wrq,
189 char *extra);
190
191int iwctl_giwencodeext(struct net_device *dev,
192 struct iw_request_info *info,
193 struct iw_point *wrq,
194 char *extra);
195
196int iwctl_siwmlme(struct net_device *dev,
197 struct iw_request_info *info,
198 struct iw_point *wrq,
199 char __user *extra);
200#endif // #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
201//End Add -- //2008-0409-07, <Add> by Einsn Liu
202
203extern const struct iw_handler_def iwctl_handler_def;
204extern struct iw_priv_args iwctl_private_args[];
205
206#endif // __IWCTL_H__
diff --git a/drivers/staging/vt6655/key.c b/drivers/staging/vt6655/key.c
index 211afae306c7..f2b3fea90533 100644
--- a/drivers/staging/vt6655/key.c
+++ b/drivers/staging/vt6655/key.c
@@ -25,770 +25,144 @@
25 * 25 *
26 * Date: May 29, 2003 26 * Date: May 29, 2003
27 * 27 *
28 * Functions:
29 * KeyvInitTable - Init Key management table
30 * KeybGetKey - Get Key from table
31 * KeybSetKey - Set Key to table
32 * KeybRemoveKey - Remove Key from table
33 * KeybGetTransmitKey - Get Transmit Key from table
34 *
35 * Revision History:
36 *
37 */ 28 */
38 29
39#include "tmacro.h" 30#include "tmacro.h"
40#include "key.h" 31#include "key.h"
41#include "mac.h" 32#include "mac.h"
42 33
43/*--------------------- Static Definitions -------------------------*/ 34int vnt_key_init_table(struct vnt_private *priv)
44
45/*--------------------- Static Classes ----------------------------*/
46
47/*--------------------- Static Functions --------------------------*/
48
49/*--------------------- Export Variables --------------------------*/
50
51/*--------------------- Static Definitions -------------------------*/
52
53/*--------------------- Static Classes ----------------------------*/
54
55/*--------------------- Static Variables --------------------------*/
56
57/*--------------------- Static Functions --------------------------*/
58static void
59s_vCheckKeyTableValid(PSKeyManagement pTable, void __iomem *dwIoBase)
60{
61 int i;
62
63 for (i = 0; i < MAX_KEY_TABLE; i++) {
64 if (pTable->KeyTable[i].bInUse &&
65 !pTable->KeyTable[i].PairwiseKey.bKeyValid &&
66 !pTable->KeyTable[i].GroupKey[0].bKeyValid &&
67 !pTable->KeyTable[i].GroupKey[1].bKeyValid &&
68 !pTable->KeyTable[i].GroupKey[2].bKeyValid &&
69 !pTable->KeyTable[i].GroupKey[3].bKeyValid) {
70 pTable->KeyTable[i].bInUse = false;
71 pTable->KeyTable[i].wKeyCtl = 0;
72 pTable->KeyTable[i].bSoftWEP = false;
73 MACvDisableKeyEntry(dwIoBase, i);
74 }
75 }
76}
77
78/*--------------------- Export Functions --------------------------*/
79
80/*
81 * Description: Init Key management table
82 *
83 * Parameters:
84 * In:
85 * pTable - Pointer to Key table
86 * Out:
87 * none
88 *
89 * Return Value: none
90 *
91 */
92void KeyvInitTable(PSKeyManagement pTable, void __iomem *dwIoBase)
93{
94 int i;
95 int jj;
96
97 for (i = 0; i < MAX_KEY_TABLE; i++) {
98 pTable->KeyTable[i].bInUse = false;
99 pTable->KeyTable[i].PairwiseKey.bKeyValid = false;
100 pTable->KeyTable[i].PairwiseKey.pvKeyTable = (void *)&pTable->KeyTable[i];
101 for (jj = 0; jj < MAX_GROUP_KEY; jj++) {
102 pTable->KeyTable[i].GroupKey[jj].bKeyValid = false;
103 pTable->KeyTable[i].GroupKey[jj].pvKeyTable = (void *)&pTable->KeyTable[i];
104 }
105 pTable->KeyTable[i].wKeyCtl = 0;
106 pTable->KeyTable[i].dwGTKeyIndex = 0;
107 pTable->KeyTable[i].bSoftWEP = false;
108 MACvDisableKeyEntry(dwIoBase, i);
109 }
110}
111
112/*
113 * Description: Get Key from table
114 *
115 * Parameters:
116 * In:
117 * pTable - Pointer to Key table
118 * pbyBSSID - BSSID of Key
119 * dwKeyIndex - Key Index (0xFFFFFFFF means pairwise key)
120 * Out:
121 * pKey - Key return
122 *
123 * Return Value: true if found otherwise false
124 *
125 */
126bool KeybGetKey(
127 PSKeyManagement pTable,
128 unsigned char *pbyBSSID,
129 unsigned long dwKeyIndex,
130 PSKeyItem *pKey
131)
132{
133 int i;
134
135 pr_debug("KeybGetKey()\n");
136
137 *pKey = NULL;
138 for (i = 0; i < MAX_KEY_TABLE; i++) {
139 if (pTable->KeyTable[i].bInUse &&
140 ether_addr_equal(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
141 if (dwKeyIndex == 0xFFFFFFFF) {
142 if (pTable->KeyTable[i].PairwiseKey.bKeyValid) {
143 *pKey = &(pTable->KeyTable[i].PairwiseKey);
144 return true;
145 } else {
146 return false;
147 }
148 } else if (dwKeyIndex < MAX_GROUP_KEY) {
149 if (pTable->KeyTable[i].GroupKey[dwKeyIndex].bKeyValid) {
150 *pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex]);
151 return true;
152 } else {
153 return false;
154 }
155 } else {
156 return false;
157 }
158 }
159 }
160 return false;
161}
162
163/*
164 * Description: Set Key to table
165 *
166 * Parameters:
167 * In:
168 * pTable - Pointer to Key table
169 * pbyBSSID - BSSID of Key
170 * dwKeyIndex - Key index (reference to NDIS DDK)
171 * uKeyLength - Key length
172 * KeyRSC - Key RSC
173 * pbyKey - Pointer to key
174 * Out:
175 * none
176 *
177 * Return Value: true if success otherwise false
178 *
179 */
180bool KeybSetKey(
181 PSKeyManagement pTable,
182 unsigned char *pbyBSSID,
183 unsigned long dwKeyIndex,
184 unsigned long uKeyLength,
185 u64 *pKeyRSC,
186 unsigned char *pbyKey,
187 unsigned char byKeyDecMode,
188 void __iomem *dwIoBase,
189 unsigned char byLocalID
190)
191{
192 int i, j;
193 unsigned int ii;
194 PSKeyItem pKey;
195 unsigned int uKeyIdx;
196
197 pr_debug("Enter KeybSetKey: %lX\n", dwKeyIndex);
198
199 j = (MAX_KEY_TABLE-1);
200 for (i = 0; i < (MAX_KEY_TABLE - 1); i++) {
201 if (!pTable->KeyTable[i].bInUse && (j == (MAX_KEY_TABLE-1))) {
202 // found empty table
203 j = i;
204 }
205 if (pTable->KeyTable[i].bInUse &&
206 ether_addr_equal(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
207 // found table already exist
208 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
209 // Pairwise key
210 pKey = &(pTable->KeyTable[i].PairwiseKey);
211 pTable->KeyTable[i].wKeyCtl &= 0xFFF0; // clear pairwise key control filed
212 pTable->KeyTable[i].wKeyCtl |= byKeyDecMode;
213 uKeyIdx = 4; // use HW key entry 4 for pairwise key
214 } else {
215 // Group key
216 if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
217 return false;
218 pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]);
219 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
220 // Group transmit key
221 pTable->KeyTable[i].dwGTKeyIndex = dwKeyIndex;
222 pr_debug("Group transmit key(R)[%lX]: %d\n",
223 pTable->KeyTable[i].dwGTKeyIndex, i);
224 }
225 pTable->KeyTable[i].wKeyCtl &= 0xFF0F; // clear group key control filed
226 pTable->KeyTable[i].wKeyCtl |= (byKeyDecMode << 4);
227 pTable->KeyTable[i].wKeyCtl |= 0x0040; // use group key for group address
228 uKeyIdx = (dwKeyIndex & 0x000000FF);
229 }
230 pTable->KeyTable[i].wKeyCtl |= 0x8000; // enable on-fly
231
232 pKey->bKeyValid = true;
233 pKey->uKeyLength = uKeyLength;
234 pKey->dwKeyIndex = dwKeyIndex;
235 pKey->byCipherSuite = byKeyDecMode;
236 memcpy(pKey->abyKey, pbyKey, uKeyLength);
237 if (byKeyDecMode == KEY_CTL_WEP) {
238 if (uKeyLength == WLAN_WEP40_KEYLEN)
239 pKey->abyKey[15] &= 0x7F;
240 if (uKeyLength == WLAN_WEP104_KEYLEN)
241 pKey->abyKey[15] |= 0x80;
242 }
243 MACvSetKeyEntry(dwIoBase, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pbyBSSID, (u32 *)pKey->abyKey, byLocalID);
244
245 if ((dwKeyIndex & USE_KEYRSC) == 0) {
246 // RSC set by NIC
247 pKey->KeyRSC = 0;
248 } else {
249 pKey->KeyRSC = *pKeyRSC;
250 }
251 pKey->dwTSC47_16 = 0;
252 pKey->wTSC15_0 = 0;
253
254 pr_debug("KeybSetKey(R):\n");
255 pr_debug("pKey->bKeyValid: %d\n ", pKey->bKeyValid);
256 pr_debug("pKey->abyKey: ");
257 for (ii = 0; ii < pKey->uKeyLength; ii++)
258 pr_debug("%02x ", pKey->abyKey[ii]);
259
260 pr_debug("\n");
261
262 pr_debug("pKey->dwTSC47_16: %lx\n ", pKey->dwTSC47_16);
263 pr_debug("pKey->wTSC15_0: %x\n ", pKey->wTSC15_0);
264 pr_debug("pKey->dwKeyIndex: %lx\n ", pKey->dwKeyIndex);
265
266 return true;
267 }
268 }
269 if (j < (MAX_KEY_TABLE-1)) {
270 memcpy(pTable->KeyTable[j].abyBSSID, pbyBSSID, ETH_ALEN);
271 pTable->KeyTable[j].bInUse = true;
272 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
273 // Pairwise key
274 pKey = &(pTable->KeyTable[j].PairwiseKey);
275 pTable->KeyTable[j].wKeyCtl &= 0xFFF0; // clear pairwise key control filed
276 pTable->KeyTable[j].wKeyCtl |= byKeyDecMode;
277 uKeyIdx = 4; // use HW key entry 4 for pairwise key
278 } else {
279 // Group key
280 if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
281 return false;
282 pKey = &(pTable->KeyTable[j].GroupKey[dwKeyIndex & 0x000000FF]);
283 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
284 // Group transmit key
285 pTable->KeyTable[j].dwGTKeyIndex = dwKeyIndex;
286 pr_debug("Group transmit key(N)[%lX]: %d\n",
287 pTable->KeyTable[j].dwGTKeyIndex, j);
288 }
289 pTable->KeyTable[j].wKeyCtl &= 0xFF0F; // clear group key control filed
290 pTable->KeyTable[j].wKeyCtl |= (byKeyDecMode << 4);
291 pTable->KeyTable[j].wKeyCtl |= 0x0040; // use group key for group address
292 uKeyIdx = (dwKeyIndex & 0x000000FF);
293 }
294 pTable->KeyTable[j].wKeyCtl |= 0x8000; // enable on-fly
295
296 pKey->bKeyValid = true;
297 pKey->uKeyLength = uKeyLength;
298 pKey->dwKeyIndex = dwKeyIndex;
299 pKey->byCipherSuite = byKeyDecMode;
300 memcpy(pKey->abyKey, pbyKey, uKeyLength);
301 if (byKeyDecMode == KEY_CTL_WEP) {
302 if (uKeyLength == WLAN_WEP40_KEYLEN)
303 pKey->abyKey[15] &= 0x7F;
304 if (uKeyLength == WLAN_WEP104_KEYLEN)
305 pKey->abyKey[15] |= 0x80;
306 }
307 MACvSetKeyEntry(dwIoBase, pTable->KeyTable[j].wKeyCtl, j, uKeyIdx, pbyBSSID, (u32 *)pKey->abyKey, byLocalID);
308
309 if ((dwKeyIndex & USE_KEYRSC) == 0) {
310 // RSC set by NIC
311 pKey->KeyRSC = 0;
312 } else {
313 pKey->KeyRSC = *pKeyRSC;
314 }
315 pKey->dwTSC47_16 = 0;
316 pKey->wTSC15_0 = 0;
317
318 pr_debug("KeybSetKey(N):\n");
319 pr_debug("pKey->bKeyValid: %d\n ", pKey->bKeyValid);
320 pr_debug("pKey->uKeyLength: %d\n ", (int)pKey->uKeyLength);
321 pr_debug("pKey->abyKey: ");
322 for (ii = 0; ii < pKey->uKeyLength; ii++)
323 pr_debug("%02x ", pKey->abyKey[ii]);
324
325 pr_debug("\n");
326
327 pr_debug("pKey->dwTSC47_16: %lx\n ", pKey->dwTSC47_16);
328 pr_debug("pKey->wTSC15_0: %x\n ", pKey->wTSC15_0);
329 pr_debug("pKey->dwKeyIndex: %lx\n ", pKey->dwKeyIndex);
330
331 return true;
332 }
333 return false;
334}
335
336/*
337 * Description: Remove Key from table
338 *
339 * Parameters:
340 * In:
341 * pTable - Pointer to Key table
342 * pbyBSSID - BSSID of Key
343 * dwKeyIndex - Key Index (reference to NDIS DDK)
344 * Out:
345 * none
346 *
347 * Return Value: true if success otherwise false
348 *
349 */
350bool KeybRemoveKey(
351 PSKeyManagement pTable,
352 unsigned char *pbyBSSID,
353 unsigned long dwKeyIndex,
354 void __iomem *dwIoBase
355)
356{
357 int i;
358
359 if (is_broadcast_ether_addr(pbyBSSID)) {
360 // delete all keys
361 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
362 for (i = 0; i < MAX_KEY_TABLE; i++)
363 pTable->KeyTable[i].PairwiseKey.bKeyValid = false;
364
365 s_vCheckKeyTableValid(pTable, dwIoBase);
366 return true;
367 } else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
368 for (i = 0; i < MAX_KEY_TABLE; i++) {
369 pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false;
370 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) {
371 // remove Group transmit key
372 pTable->KeyTable[i].dwGTKeyIndex = 0;
373 }
374 }
375 s_vCheckKeyTableValid(pTable, dwIoBase);
376 return true;
377 } else {
378 return false;
379 }
380 }
381
382 for (i = 0; i < MAX_KEY_TABLE; i++) {
383 if (pTable->KeyTable[i].bInUse &&
384 ether_addr_equal(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
385 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
386 pTable->KeyTable[i].PairwiseKey.bKeyValid = false;
387 s_vCheckKeyTableValid(pTable, dwIoBase);
388 return true;
389 } else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
390 pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false;
391 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) {
392 // remove Group transmit key
393 pTable->KeyTable[i].dwGTKeyIndex = 0;
394 }
395 s_vCheckKeyTableValid(pTable, dwIoBase);
396 return true;
397 } else {
398 return false;
399 }
400 }
401 }
402 return false;
403}
404
405/*
406 * Description: Remove Key from table
407 *
408 * Parameters:
409 * In:
410 * pTable - Pointer to Key table
411 * pbyBSSID - BSSID of Key
412 * Out:
413 * none
414 *
415 * Return Value: true if success otherwise false
416 *
417 */
418bool KeybRemoveAllKey(
419 PSKeyManagement pTable,
420 unsigned char *pbyBSSID,
421 void __iomem *dwIoBase
422)
423{ 35{
424 int i, u; 36 u32 i;
425 37
426 for (i = 0; i < MAX_KEY_TABLE; i++) { 38 for (i = 0; i < MAX_KEY_TABLE; i++)
427 if (pTable->KeyTable[i].bInUse && 39 MACvDisableKeyEntry(priv->PortOffset, i);
428 ether_addr_equal(pTable->KeyTable[i].abyBSSID, pbyBSSID)) {
429 pTable->KeyTable[i].PairwiseKey.bKeyValid = false;
430 for (u = 0; u < MAX_GROUP_KEY; u++)
431 pTable->KeyTable[i].GroupKey[u].bKeyValid = false;
432 40
433 pTable->KeyTable[i].dwGTKeyIndex = 0; 41 return 0;
434 s_vCheckKeyTableValid(pTable, dwIoBase);
435 return true;
436 }
437 }
438 return false;
439} 42}
440 43
441/* 44static int vnt_set_keymode(struct ieee80211_hw *hw, u8 *mac_addr,
442 * Description: Remove WEP Key from table 45 struct ieee80211_key_conf *key, u32 key_type, u32 mode,
443 * 46 bool onfly_latch)
444 * Parameters:
445 * In:
446 * pTable - Pointer to Key table
447 * Out:
448 * none
449 *
450 * Return Value: true if success otherwise false
451 *
452 */
453void KeyvRemoveWEPKey(
454 PSKeyManagement pTable,
455 unsigned long dwKeyIndex,
456 void __iomem *dwIoBase
457)
458{ 47{
459 if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) { 48 struct vnt_private *priv = hw->priv;
460 if (pTable->KeyTable[MAX_KEY_TABLE-1].bInUse) { 49 u8 broadcast[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
461 if (pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].byCipherSuite == KEY_CTL_WEP) { 50 u16 key_mode = 0;
462 pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = false; 51 u32 entry = 0;
463 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex & 0x7FFFFFFF)) { 52 u8 *bssid;
464 // remove Group transmit key 53 u8 key_inx = key->keyidx;
465 pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex = 0; 54 u8 i;
466 } 55
56 if (mac_addr)
57 bssid = mac_addr;
58 else
59 bssid = &broadcast[0];
60
61 if (key_type != VNT_KEY_DEFAULTKEY) {
62 for (i = 0; i < (MAX_KEY_TABLE - 1); i++) {
63 if (!test_bit(i, &priv->key_entry_inuse)) {
64 set_bit(i, &priv->key_entry_inuse);
65
66 key->hw_key_idx = i;
67 entry = key->hw_key_idx;
68 break;
467 } 69 }
468 } 70 }
469 s_vCheckKeyTableValid(pTable, dwIoBase);
470 } 71 }
471}
472 72
473void KeyvRemoveAllWEPKey( 73 switch (key_type) {
474 PSKeyManagement pTable, 74 /* fallthrough */
475 void __iomem *dwIoBase 75 case VNT_KEY_DEFAULTKEY:
476) 76 /* default key last entry */
477{ 77 entry = MAX_KEY_TABLE - 1;
478 int i; 78 key->hw_key_idx = entry;
479 79 case VNT_KEY_ALLGROUP:
480 for (i = 0; i < MAX_GROUP_KEY; i++) 80 key_mode |= VNT_KEY_ALLGROUP;
481 KeyvRemoveWEPKey(pTable, i, dwIoBase); 81 if (onfly_latch)
82 key_mode |= VNT_KEY_ONFLY_ALL;
83 case VNT_KEY_GROUP_ADDRESS:
84 key_mode |= mode;
85 case VNT_KEY_GROUP:
86 key_mode |= (mode << 4);
87 key_mode |= VNT_KEY_GROUP;
88 break;
89 case VNT_KEY_PAIRWISE:
90 key_mode |= mode;
91 key_inx = 4;
92 break;
93 default:
94 return -EINVAL;
95 }
96
97 if (onfly_latch)
98 key_mode |= VNT_KEY_ONFLY;
99
100 if (mode == KEY_CTL_WEP) {
101 if (key->keylen == WLAN_KEY_LEN_WEP40)
102 key->key[15] &= 0x7f;
103 if (key->keylen == WLAN_KEY_LEN_WEP104)
104 key->key[15] |= 0x80;
105 }
106
107 MACvSetKeyEntry(priv->PortOffset, key_mode, entry, key_inx,
108 bssid, (u32 *)key->key, priv->byLocalID);
109
110 return 0;
482} 111}
483 112
484/* 113int vnt_set_keys(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
485 * Description: Get Transmit Key from table 114 struct ieee80211_vif *vif, struct ieee80211_key_conf *key)
486 *
487 * Parameters:
488 * In:
489 * pTable - Pointer to Key table
490 * pbyBSSID - BSSID of Key
491 * Out:
492 * pKey - Key return
493 *
494 * Return Value: true if found otherwise false
495 *
496 */
497bool KeybGetTransmitKey(
498 PSKeyManagement pTable,
499 unsigned char *pbyBSSID,
500 unsigned long dwKeyType,
501 PSKeyItem *pKey
502)
503{ 115{
504 int i, ii; 116 struct ieee80211_bss_conf *conf = &vif->bss_conf;
505 117 struct vnt_private *priv = hw->priv;
506 *pKey = NULL; 118 u8 *mac_addr = NULL;
507 for (i = 0; i < MAX_KEY_TABLE; i++) { 119 u8 key_dec_mode = 0;
508 if (pTable->KeyTable[i].bInUse && 120 int ret = 0;
509 ether_addr_equal(pTable->KeyTable[i].abyBSSID, pbyBSSID)) { 121 u32 u;
510 if (dwKeyType == PAIRWISE_KEY) {
511 if (pTable->KeyTable[i].PairwiseKey.bKeyValid) {
512 *pKey = &(pTable->KeyTable[i].PairwiseKey);
513
514 pr_debug("KeybGetTransmitKey:");
515 pr_debug("PAIRWISE_KEY: KeyTable.abyBSSID: ");
516 for (ii = 0; ii < 6; ii++)
517 pr_debug("%x ",
518 pTable->KeyTable[i].abyBSSID[ii]);
519
520 pr_debug("\n");
521 122
522 return true; 123 if (sta)
523 } else { 124 mac_addr = &sta->addr[0];
524 pr_debug("PairwiseKey.bKeyValid == false\n");
525 return false;
526 }
527 } // End of Type == PAIRWISE
528 else {
529 if (pTable->KeyTable[i].dwGTKeyIndex == 0) {
530 pr_debug("ERROR: dwGTKeyIndex == 0 !!!\n");
531 return false;
532 }
533 if (pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)].bKeyValid) {
534 *pKey = &(pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)]);
535
536 pr_debug("KeybGetTransmitKey:");
537 pr_debug("GROUP_KEY: KeyTable.abyBSSID\n");
538 for (ii = 0; ii < 6; ii++)
539 pr_debug("%x ",
540 pTable->KeyTable[i].abyBSSID[ii]);
541
542 pr_debug("\n");
543 pr_debug("dwGTKeyIndex: %lX\n",
544 pTable->KeyTable[i].dwGTKeyIndex);
545
546 return true;
547 } else {
548 pr_debug("GroupKey.bKeyValid == false\n");
549 return false;
550 }
551 } // End of Type = GROUP
552 } // BSSID match
553 }
554 pr_debug("ERROR: NO Match BSSID !!! ");
555 for (ii = 0; ii < 6; ii++)
556 pr_debug("%02x ", *(pbyBSSID+ii));
557
558 pr_debug("\n");
559 return false;
560}
561
562/*
563 * Description: Check Pairewise Key
564 *
565 * Parameters:
566 * In:
567 * pTable - Pointer to Key table
568 * Out:
569 * none
570 *
571 * Return Value: true if found otherwise false
572 *
573 */
574bool KeybCheckPairewiseKey(
575 PSKeyManagement pTable,
576 PSKeyItem *pKey
577)
578{
579 int i;
580 125
581 *pKey = NULL; 126 switch (key->cipher) {
582 for (i = 0; i < MAX_KEY_TABLE; i++) { 127 case 0:
583 if (pTable->KeyTable[i].bInUse && 128 for (u = 0 ; u < MAX_KEY_TABLE; u++)
584 pTable->KeyTable[i].PairwiseKey.bKeyValid) { 129 MACvDisableKeyEntry(priv->PortOffset, u);
585 *pKey = &(pTable->KeyTable[i].PairwiseKey); 130 return ret;
586 return true;
587 }
588 }
589 return false;
590}
591 131
592/* 132 case WLAN_CIPHER_SUITE_WEP40:
593 * Description: Set Key to table 133 case WLAN_CIPHER_SUITE_WEP104:
594 * 134 for (u = 0; u < MAX_KEY_TABLE; u++)
595 * Parameters: 135 MACvDisableKeyEntry(priv->PortOffset, u);
596 * In:
597 * pTable - Pointer to Key table
598 * dwKeyIndex - Key index (reference to NDIS DDK)
599 * uKeyLength - Key length
600 * KeyRSC - Key RSC
601 * pbyKey - Pointer to key
602 * Out:
603 * none
604 *
605 * Return Value: true if success otherwise false
606 *
607 */
608bool KeybSetDefaultKey(
609 PSKeyManagement pTable,
610 unsigned long dwKeyIndex,
611 unsigned long uKeyLength,
612 u64 *pKeyRSC,
613 unsigned char *pbyKey,
614 unsigned char byKeyDecMode,
615 void __iomem *dwIoBase,
616 unsigned char byLocalID
617)
618{
619 unsigned int ii;
620 PSKeyItem pKey;
621 unsigned int uKeyIdx;
622 136
623 pr_debug("Enter KeybSetDefaultKey: %1x, %d\n", 137 vnt_set_keymode(hw, mac_addr,
624 (int)dwKeyIndex, (int)uKeyLength); 138 key, VNT_KEY_DEFAULTKEY, KEY_CTL_WEP, true);
625 139
626 if ((dwKeyIndex & PAIRWISE_KEY) != 0) // Pairwise key 140 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
627 return false;
628 else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
629 return false;
630 141
631 if (uKeyLength > MAX_KEY_LEN) 142 return ret;
632 return false; 143 case WLAN_CIPHER_SUITE_TKIP:
144 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
145 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
633 146
634 pTable->KeyTable[MAX_KEY_TABLE - 1].bInUse = true; 147 key_dec_mode = KEY_CTL_TKIP;
635 for (ii = 0; ii < ETH_ALEN; ii++)
636 pTable->KeyTable[MAX_KEY_TABLE - 1].abyBSSID[ii] = 0xFF;
637 148
638 // Group key 149 break;
639 pKey = &(pTable->KeyTable[MAX_KEY_TABLE - 1].GroupKey[dwKeyIndex & 0x000000FF]); 150 case WLAN_CIPHER_SUITE_CCMP:
640 if ((dwKeyIndex & TRANSMIT_KEY) != 0) { 151 key_dec_mode = KEY_CTL_CCMP;
641 // Group transmit key
642 pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex = dwKeyIndex;
643 pr_debug("Group transmit key(R)[%lX]: %d\n",
644 pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex,
645 MAX_KEY_TABLE-1);
646 152
153 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
647 } 154 }
648 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl &= 0x7F00; // clear all key control filed
649 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= (byKeyDecMode << 4);
650 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= (byKeyDecMode);
651 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x0044; // use group key for all address
652 uKeyIdx = (dwKeyIndex & 0x000000FF);
653 155
654 if ((uKeyLength == WLAN_WEP232_KEYLEN) && 156 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
655 (byKeyDecMode == KEY_CTL_WEP)) { 157 vnt_set_keymode(hw, mac_addr,
656 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x4000; // disable on-fly disable address match 158 key, VNT_KEY_PAIRWISE, key_dec_mode, true);
657 pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP = true;
658 } else { 159 } else {
659 if (!pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP) 160 vnt_set_keymode(hw, mac_addr,
660 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0xC000; // enable on-fly disable address match 161 key, VNT_KEY_DEFAULTKEY, key_dec_mode, true);
661 }
662 162
663 pKey->bKeyValid = true; 163 vnt_set_keymode(hw, (u8 *)conf->bssid,
664 pKey->uKeyLength = uKeyLength; 164 key, VNT_KEY_GROUP_ADDRESS, key_dec_mode, true);
665 pKey->dwKeyIndex = dwKeyIndex;
666 pKey->byCipherSuite = byKeyDecMode;
667 memcpy(pKey->abyKey, pbyKey, uKeyLength);
668 if (byKeyDecMode == KEY_CTL_WEP) {
669 if (uKeyLength == WLAN_WEP40_KEYLEN)
670 pKey->abyKey[15] &= 0x7F;
671 if (uKeyLength == WLAN_WEP104_KEYLEN)
672 pKey->abyKey[15] |= 0x80;
673 }
674 MACvSetKeyEntry(dwIoBase, pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl, MAX_KEY_TABLE-1, uKeyIdx, pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID, (u32 *)pKey->abyKey, byLocalID);
675
676 if ((dwKeyIndex & USE_KEYRSC) == 0) {
677 // RSC set by NIC
678 pKey->KeyRSC = 0;
679 } else {
680 pKey->KeyRSC = *pKeyRSC;
681 } 165 }
682 pKey->dwTSC47_16 = 0;
683 pKey->wTSC15_0 = 0;
684
685 pr_debug("KeybSetKey(R):\n");
686 pr_debug("pKey->bKeyValid: %d\n", pKey->bKeyValid);
687 pr_debug("pKey->uKeyLength: %d\n", (int)pKey->uKeyLength);
688 pr_debug("pKey->abyKey:\n");
689 for (ii = 0; ii < pKey->uKeyLength; ii++)
690 pr_debug("%x", pKey->abyKey[ii]);
691
692 pr_debug("\n");
693
694 pr_debug("pKey->dwTSC47_16: %lx\n", pKey->dwTSC47_16);
695 pr_debug("pKey->wTSC15_0: %x\n", pKey->wTSC15_0);
696 pr_debug("pKey->dwKeyIndex: %lx\n", pKey->dwKeyIndex);
697
698 return true;
699}
700 166
701/* 167 return 0;
702 * Description: Set Key to table
703 *
704 * Parameters:
705 * In:
706 * pTable - Pointer to Key table
707 * dwKeyIndex - Key index (reference to NDIS DDK)
708 * uKeyLength - Key length
709 * KeyRSC - Key RSC
710 * pbyKey - Pointer to key
711 * Out:
712 * none
713 *
714 * Return Value: true if success otherwise false
715 *
716 */
717bool KeybSetAllGroupKey(
718 PSKeyManagement pTable,
719 unsigned long dwKeyIndex,
720 unsigned long uKeyLength,
721 u64 *pKeyRSC,
722 unsigned char *pbyKey,
723 unsigned char byKeyDecMode,
724 void __iomem *dwIoBase,
725 unsigned char byLocalID
726)
727{
728 int i;
729 unsigned int ii;
730 PSKeyItem pKey;
731 unsigned int uKeyIdx;
732
733 pr_debug("Enter KeybSetAllGroupKey: %lX\n", dwKeyIndex);
734
735 if ((dwKeyIndex & PAIRWISE_KEY) != 0) // Pairwise key
736 return false;
737 else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
738 return false;
739
740 for (i = 0; i < MAX_KEY_TABLE - 1; i++) {
741 if (pTable->KeyTable[i].bInUse) {
742 // found table already exist
743 // Group key
744 pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]);
745 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
746 // Group transmit key
747 pTable->KeyTable[i].dwGTKeyIndex = dwKeyIndex;
748 pr_debug("Group transmit key(R)[%lX]: %d\n",
749 pTable->KeyTable[i].dwGTKeyIndex, i);
750
751 }
752 pTable->KeyTable[i].wKeyCtl &= 0xFF0F; // clear group key control filed
753 pTable->KeyTable[i].wKeyCtl |= (byKeyDecMode << 4);
754 pTable->KeyTable[i].wKeyCtl |= 0x0040; // use group key for group address
755 uKeyIdx = (dwKeyIndex & 0x000000FF);
756
757 pTable->KeyTable[i].wKeyCtl |= 0x8000; // enable on-fly
758
759 pKey->bKeyValid = true;
760 pKey->uKeyLength = uKeyLength;
761 pKey->dwKeyIndex = dwKeyIndex;
762 pKey->byCipherSuite = byKeyDecMode;
763 memcpy(pKey->abyKey, pbyKey, uKeyLength);
764 if (byKeyDecMode == KEY_CTL_WEP) {
765 if (uKeyLength == WLAN_WEP40_KEYLEN)
766 pKey->abyKey[15] &= 0x7F;
767 if (uKeyLength == WLAN_WEP104_KEYLEN)
768 pKey->abyKey[15] |= 0x80;
769 }
770 MACvSetKeyEntry(dwIoBase, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pTable->KeyTable[i].abyBSSID, (u32 *)pKey->abyKey, byLocalID);
771
772 if ((dwKeyIndex & USE_KEYRSC) == 0) {
773 // RSC set by NIC
774 pKey->KeyRSC = 0;
775 } else {
776 pKey->KeyRSC = *pKeyRSC;
777 }
778 pKey->dwTSC47_16 = 0;
779 pKey->wTSC15_0 = 0;
780
781 pr_debug("KeybSetKey(R):\n");
782 pr_debug("pKey->bKeyValid: %d\n ", pKey->bKeyValid);
783 pr_debug("pKey->uKeyLength: %d\n ",
784 (int)pKey->uKeyLength);
785 pr_debug("pKey->abyKey: ");
786 for (ii = 0; ii < pKey->uKeyLength; ii++)
787 pr_debug("%02x ", pKey->abyKey[ii]);
788
789 pr_debug("\n");
790
791 } // (pTable->KeyTable[i].bInUse == true)
792 }
793 return true;
794} 168}
diff --git a/drivers/staging/vt6655/key.h b/drivers/staging/vt6655/key.h
index 44efe18315af..c01d4afb6ab8 100644
--- a/drivers/staging/vt6655/key.h
+++ b/drivers/staging/vt6655/key.h
@@ -30,9 +30,7 @@
30#ifndef __KEY_H__ 30#ifndef __KEY_H__
31#define __KEY_H__ 31#define __KEY_H__
32 32
33#include "ttype.h" 33#include <net/mac80211.h>
34#include "tether.h"
35#include "80211mgr.h"
36 34
37/*--------------------- Export Definitions -------------------------*/ 35/*--------------------- Export Definitions -------------------------*/
38#define MAX_GROUP_KEY 4 36#define MAX_GROUP_KEY 4
@@ -53,124 +51,19 @@
53#define KEY_CTL_CCMP 0x03 51#define KEY_CTL_CCMP 0x03
54#define KEY_CTL_INVALID 0xFF 52#define KEY_CTL_INVALID 0xFF
55 53
56typedef struct tagSKeyItem { 54#define VNT_KEY_DEFAULTKEY 0x1
57 bool bKeyValid; 55#define VNT_KEY_GROUP_ADDRESS 0x2
58 unsigned long uKeyLength; 56#define VNT_KEY_ALLGROUP 0x4
59 unsigned char abyKey[MAX_KEY_LEN]; 57#define VNT_KEY_GROUP 0x40
60 u64 KeyRSC; 58#define VNT_KEY_PAIRWISE 0x00
61 unsigned long dwTSC47_16; 59#define VNT_KEY_ONFLY 0x8000
62 unsigned short wTSC15_0; 60#define VNT_KEY_ONFLY_ALL 0x4000
63 unsigned char byCipherSuite;
64 unsigned char byReserved0;
65 unsigned long dwKeyIndex;
66 void *pvKeyTable;
67} SKeyItem, *PSKeyItem; //64
68 61
69typedef struct tagSKeyTable { 62struct vnt_private;
70 unsigned char abyBSSID[ETH_ALEN]; //6
71 unsigned char byReserved0[2]; //8
72 SKeyItem PairwiseKey;
73 SKeyItem GroupKey[MAX_GROUP_KEY]; //64*5 = 320, 320+8=328
74 unsigned long dwGTKeyIndex; // GroupTransmitKey Index
75 bool bInUse;
76 //2006-1116-01,<Modify> by NomadZhao
77 bool bSoftWEP;
78 unsigned short wKeyCtl; // for address of wKeyCtl at align 4
79 63
80 unsigned char byReserved1[6]; 64int vnt_key_init_table(struct vnt_private *);
81} SKeyTable, *PSKeyTable; //348
82 65
83typedef struct tagSKeyManagement { 66int vnt_set_keys(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
84 SKeyTable KeyTable[MAX_KEY_TABLE]; 67 struct ieee80211_vif *vif, struct ieee80211_key_conf *key);
85} SKeyManagement, *PSKeyManagement;
86
87/*--------------------- Export Types ------------------------------*/
88
89/*--------------------- Export Macros ------------------------------*/
90
91/*--------------------- Export Classes ----------------------------*/
92
93/*--------------------- Export Variables --------------------------*/
94
95/*--------------------- Export Functions --------------------------*/
96
97void KeyvInitTable(PSKeyManagement pTable, void __iomem *dwIoBase);
98
99bool KeybGetKey(
100 PSKeyManagement pTable,
101 unsigned char *pbyBSSID,
102 unsigned long dwKeyIndex,
103 PSKeyItem *pKey
104);
105
106bool KeybSetKey(
107 PSKeyManagement pTable,
108 unsigned char *pbyBSSID,
109 unsigned long dwKeyIndex,
110 unsigned long uKeyLength,
111 u64 *pKeyRSC,
112 unsigned char *pbyKey,
113 unsigned char byKeyDecMode,
114 void __iomem *dwIoBase,
115 unsigned char byLocalID
116);
117
118bool KeybSetDefaultKey(
119 PSKeyManagement pTable,
120 unsigned long dwKeyIndex,
121 unsigned long uKeyLength,
122 u64 *pKeyRSC,
123 unsigned char *pbyKey,
124 unsigned char byKeyDecMode,
125 void __iomem *dwIoBase,
126 unsigned char byLocalID
127);
128
129bool KeybRemoveKey(
130 PSKeyManagement pTable,
131 unsigned char *pbyBSSID,
132 unsigned long dwKeyIndex,
133 void __iomem *dwIoBase
134);
135
136bool KeybGetTransmitKey(
137 PSKeyManagement pTable,
138 unsigned char *pbyBSSID,
139 unsigned long dwKeyType,
140 PSKeyItem *pKey
141);
142
143bool KeybCheckPairewiseKey(
144 PSKeyManagement pTable,
145 PSKeyItem *pKey
146);
147
148bool KeybRemoveAllKey(
149 PSKeyManagement pTable,
150 unsigned char *pbyBSSID,
151 void __iomem *dwIoBase
152);
153
154void KeyvRemoveWEPKey(
155 PSKeyManagement pTable,
156 unsigned long dwKeyIndex,
157 void __iomem *dwIoBase
158);
159
160void KeyvRemoveAllWEPKey(
161 PSKeyManagement pTable,
162 void __iomem *dwIoBase
163);
164
165bool KeybSetAllGroupKey(
166 PSKeyManagement pTable,
167 unsigned long dwKeyIndex,
168 unsigned long uKeyLength,
169 u64 *pKeyRSC,
170 unsigned char *pbyKey,
171 unsigned char byKeyDecMode,
172 void __iomem *dwIoBase,
173 unsigned char byLocalID
174);
175 68
176#endif // __KEY_H__ 69#endif // __KEY_H__
diff --git a/drivers/staging/vt6655/mac.c b/drivers/staging/vt6655/mac.c
index e3b0b7f7ca85..8f0d652fea7c 100644
--- a/drivers/staging/vt6655/mac.c
+++ b/drivers/staging/vt6655/mac.c
@@ -26,30 +26,15 @@
26 * Date: May 21, 1996 26 * Date: May 21, 1996
27 * 27 *
28 * Functions: 28 * Functions:
29 * MACvReadAllRegs - Read All MAC Registers to buffer
30 * MACbIsRegBitsOn - Test if All test Bits On 29 * MACbIsRegBitsOn - Test if All test Bits On
31 * MACbIsRegBitsOff - Test if All test Bits Off 30 * MACbIsRegBitsOff - Test if All test Bits Off
32 * MACbIsIntDisable - Test if MAC interrupt disable 31 * MACbIsIntDisable - Test if MAC interrupt disable
33 * MACbyReadMultiAddr - Read Multicast Address Mask Pattern
34 * MACvWriteMultiAddr - Write Multicast Address Mask Pattern
35 * MACvSetMultiAddrByHash - Set Multicast Address Mask by Hash value
36 * MACvResetMultiAddrByHash - Clear Multicast Address Mask by Hash value
37 * MACvSetRxThreshold - Set Rx Threshold value
38 * MACvGetRxThreshold - Get Rx Threshold value
39 * MACvSetTxThreshold - Set Tx Threshold value
40 * MACvGetTxThreshold - Get Tx Threshold value
41 * MACvSetDmaLength - Set Dma Length value
42 * MACvGetDmaLength - Get Dma Length value
43 * MACvSetShortRetryLimit - Set 802.11 Short Retry limit 32 * MACvSetShortRetryLimit - Set 802.11 Short Retry limit
44 * MACvGetShortRetryLimit - Get 802.11 Short Retry limit 33 * MACvGetShortRetryLimit - Get 802.11 Short Retry limit
45 * MACvSetLongRetryLimit - Set 802.11 Long Retry limit 34 * MACvSetLongRetryLimit - Set 802.11 Long Retry limit
46 * MACvGetLongRetryLimit - Get 802.11 Long Retry limit
47 * MACvSetLoopbackMode - Set MAC Loopback Mode 35 * MACvSetLoopbackMode - Set MAC Loopback Mode
48 * MACbIsInLoopbackMode - Test if MAC in Loopback mode
49 * MACvSetPacketFilter - Set MAC Address Filter
50 * MACvSaveContext - Save Context of MAC Registers 36 * MACvSaveContext - Save Context of MAC Registers
51 * MACvRestoreContext - Restore Context of MAC Registers 37 * MACvRestoreContext - Restore Context of MAC Registers
52 * MACbCompareContext - Compare if values of MAC Registers same as Context
53 * MACbSoftwareReset - Software Reset MAC 38 * MACbSoftwareReset - Software Reset MAC
54 * MACbSafeRxOff - Turn Off MAC Rx 39 * MACbSafeRxOff - Turn Off MAC Rx
55 * MACbSafeTxOff - Turn Off MAC Tx 40 * MACbSafeTxOff - Turn Off MAC Tx
@@ -69,54 +54,8 @@
69 */ 54 */
70 55
71#include "tmacro.h" 56#include "tmacro.h"
72#include "tether.h"
73#include "mac.h" 57#include "mac.h"
74 58
75unsigned short TxRate_iwconfig;//2008-5-8 <add> by chester
76/*--------------------- Static Classes ----------------------------*/
77
78/*--------------------- Static Variables --------------------------*/
79
80/*--------------------- Static Functions --------------------------*/
81
82/*--------------------- Export Variables --------------------------*/
83
84/*--------------------- Export Functions --------------------------*/
85
86/*
87 * Description:
88 * Read All MAC Registers to buffer
89 *
90 * Parameters:
91 * In:
92 * dwIoBase - Base Address for MAC
93 * Out:
94 * pbyMacRegs - buffer to read
95 *
96 * Return Value: none
97 *
98 */
99void MACvReadAllRegs(void __iomem *dwIoBase, unsigned char *pbyMacRegs)
100{
101 int ii;
102
103 // read page0 register
104 for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE0; ii++) {
105 VNSvInPortB(dwIoBase + ii, pbyMacRegs);
106 pbyMacRegs++;
107 }
108
109 MACvSelectPage1(dwIoBase);
110
111 // read page1 register
112 for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE1; ii++) {
113 VNSvInPortB(dwIoBase + ii, pbyMacRegs);
114 pbyMacRegs++;
115 }
116
117 MACvSelectPage0(dwIoBase);
118}
119
120/* 59/*
121 * Description: 60 * Description:
122 * Test if all test bits on 61 * Test if all test bits on
@@ -189,252 +128,6 @@ bool MACbIsIntDisable(void __iomem *dwIoBase)
189 128
190/* 129/*
191 * Description: 130 * Description:
192 * Read MAC Multicast Address Mask
193 *
194 * Parameters:
195 * In:
196 * dwIoBase - Base Address for MAC
197 * uByteidx - Index of Mask
198 * Out:
199 * none
200 *
201 * Return Value: Mask Value read
202 *
203 */
204unsigned char MACbyReadMultiAddr(void __iomem *dwIoBase, unsigned int uByteIdx)
205{
206 unsigned char byData;
207
208 MACvSelectPage1(dwIoBase);
209 VNSvInPortB(dwIoBase + MAC_REG_MAR0 + uByteIdx, &byData);
210 MACvSelectPage0(dwIoBase);
211 return byData;
212}
213
214/*
215 * Description:
216 * Write MAC Multicast Address Mask
217 *
218 * Parameters:
219 * In:
220 * dwIoBase - Base Address for MAC
221 * uByteidx - Index of Mask
222 * byData - Mask Value to write
223 * Out:
224 * none
225 *
226 * Return Value: none
227 *
228 */
229void MACvWriteMultiAddr(void __iomem *dwIoBase, unsigned int uByteIdx, unsigned char byData)
230{
231 MACvSelectPage1(dwIoBase);
232 VNSvOutPortB(dwIoBase + MAC_REG_MAR0 + uByteIdx, byData);
233 MACvSelectPage0(dwIoBase);
234}
235
236/*
237 * Description:
238 * Set this hash index into multicast address register bit
239 *
240 * Parameters:
241 * In:
242 * dwIoBase - Base Address for MAC
243 * byHashIdx - Hash index to set
244 * Out:
245 * none
246 *
247 * Return Value: none
248 *
249 */
250void MACvSetMultiAddrByHash(void __iomem *dwIoBase, unsigned char byHashIdx)
251{
252 unsigned int uByteIdx;
253 unsigned char byBitMask;
254 unsigned char byOrgValue;
255
256 // calculate byte position
257 uByteIdx = byHashIdx / 8;
258 ASSERT(uByteIdx < 8);
259 // calculate bit position
260 byBitMask = 1;
261 byBitMask <<= (byHashIdx % 8);
262 // turn on the bit
263 byOrgValue = MACbyReadMultiAddr(dwIoBase, uByteIdx);
264 MACvWriteMultiAddr(dwIoBase, uByteIdx, (unsigned char)(byOrgValue | byBitMask));
265}
266
267/*
268 * Description:
269 * Reset this hash index into multicast address register bit
270 *
271 * Parameters:
272 * In:
273 * dwIoBase - Base Address for MAC
274 * byHashIdx - Hash index to clear
275 * Out:
276 * none
277 *
278 * Return Value: none
279 *
280 */
281void MACvResetMultiAddrByHash(void __iomem *dwIoBase, unsigned char byHashIdx)
282{
283 unsigned int uByteIdx;
284 unsigned char byBitMask;
285 unsigned char byOrgValue;
286
287 // calculate byte position
288 uByteIdx = byHashIdx / 8;
289 ASSERT(uByteIdx < 8);
290 // calculate bit position
291 byBitMask = 1;
292 byBitMask <<= (byHashIdx % 8);
293 // turn off the bit
294 byOrgValue = MACbyReadMultiAddr(dwIoBase, uByteIdx);
295 MACvWriteMultiAddr(dwIoBase, uByteIdx, (unsigned char)(byOrgValue & (~byBitMask)));
296}
297
298/*
299 * Description:
300 * Set Rx Threshold
301 *
302 * Parameters:
303 * In:
304 * dwIoBase - Base Address for MAC
305 * byThreshold - Threshold Value
306 * Out:
307 * none
308 *
309 * Return Value: none
310 *
311 */
312void MACvSetRxThreshold(void __iomem *dwIoBase, unsigned char byThreshold)
313{
314 unsigned char byOrgValue;
315
316 ASSERT(byThreshold < 4);
317
318 // set FCR0
319 VNSvInPortB(dwIoBase + MAC_REG_FCR0, &byOrgValue);
320 byOrgValue = (byOrgValue & 0xCF) | (byThreshold << 4);
321 VNSvOutPortB(dwIoBase + MAC_REG_FCR0, byOrgValue);
322}
323
324/*
325 * Description:
326 * Get Rx Threshold
327 *
328 * Parameters:
329 * In:
330 * dwIoBase - Base Address for MAC
331 * Out:
332 * pbyThreshold- Threshold Value Get
333 *
334 * Return Value: none
335 *
336 */
337void MACvGetRxThreshold(void __iomem *dwIoBase, unsigned char *pbyThreshold)
338{
339 // get FCR0
340 VNSvInPortB(dwIoBase + MAC_REG_FCR0, pbyThreshold);
341 *pbyThreshold = (*pbyThreshold >> 4) & 0x03;
342}
343
344/*
345 * Description:
346 * Set Tx Threshold
347 *
348 * Parameters:
349 * In:
350 * dwIoBase - Base Address for MAC
351 * byThreshold - Threshold Value
352 * Out:
353 * none
354 *
355 * Return Value: none
356 *
357 */
358void MACvSetTxThreshold(void __iomem *dwIoBase, unsigned char byThreshold)
359{
360 unsigned char byOrgValue;
361
362 ASSERT(byThreshold < 4);
363
364 // set FCR0
365 VNSvInPortB(dwIoBase + MAC_REG_FCR0, &byOrgValue);
366 byOrgValue = (byOrgValue & 0xF3) | (byThreshold << 2);
367 VNSvOutPortB(dwIoBase + MAC_REG_FCR0, byOrgValue);
368}
369
370/*
371 * Description:
372 * Get Tx Threshold
373 *
374 * Parameters:
375 * In:
376 * dwIoBase - Base Address for MAC
377 * Out:
378 * pbyThreshold- Threshold Value Get
379 *
380 * Return Value: none
381 *
382 */
383void MACvGetTxThreshold(void __iomem *dwIoBase, unsigned char *pbyThreshold)
384{
385 // get FCR0
386 VNSvInPortB(dwIoBase + MAC_REG_FCR0, pbyThreshold);
387 *pbyThreshold = (*pbyThreshold >> 2) & 0x03;
388}
389
390/*
391 * Description:
392 * Set Dma Length
393 *
394 * Parameters:
395 * In:
396 * dwIoBase - Base Address for MAC
397 * byDmaLength - Dma Length Value
398 * Out:
399 * none
400 *
401 * Return Value: none
402 *
403 */
404void MACvSetDmaLength(void __iomem *dwIoBase, unsigned char byDmaLength)
405{
406 unsigned char byOrgValue;
407
408 ASSERT(byDmaLength < 4);
409
410 // set FCR0
411 VNSvInPortB(dwIoBase + MAC_REG_FCR0, &byOrgValue);
412 byOrgValue = (byOrgValue & 0xFC) | byDmaLength;
413 VNSvOutPortB(dwIoBase + MAC_REG_FCR0, byOrgValue);
414}
415
416/*
417 * Description:
418 * Get Dma Length
419 *
420 * Parameters:
421 * In:
422 * dwIoBase - Base Address for MAC
423 * Out:
424 * pbyDmaLength- Dma Length Value Get
425 *
426 * Return Value: none
427 *
428 */
429void MACvGetDmaLength(void __iomem *dwIoBase, unsigned char *pbyDmaLength)
430{
431 // get FCR0
432 VNSvInPortB(dwIoBase + MAC_REG_FCR0, pbyDmaLength);
433 *pbyDmaLength &= 0x03;
434}
435
436/*
437 * Description:
438 * Set 802.11 Short Retry Limit 131 * Set 802.11 Short Retry Limit
439 * 132 *
440 * Parameters: 133 * Parameters:
@@ -494,25 +187,6 @@ void MACvSetLongRetryLimit(void __iomem *dwIoBase, unsigned char byRetryLimit)
494 187
495/* 188/*
496 * Description: 189 * Description:
497 * Get 802.11 Long Retry Limit
498 *
499 * Parameters:
500 * In:
501 * dwIoBase - Base Address for MAC
502 * Out:
503 * pbyRetryLimit - Retry Limit Get
504 *
505 * Return Value: none
506 *
507 */
508void MACvGetLongRetryLimit(void __iomem *dwIoBase, unsigned char *pbyRetryLimit)
509{
510 // get LRT
511 VNSvInPortB(dwIoBase + MAC_REG_LRT, pbyRetryLimit);
512}
513
514/*
515 * Description:
516 * Set MAC Loopback mode 190 * Set MAC Loopback mode
517 * 191 *
518 * Parameters: 192 * Parameters:
@@ -540,89 +214,6 @@ void MACvSetLoopbackMode(void __iomem *dwIoBase, unsigned char byLoopbackMode)
540 214
541/* 215/*
542 * Description: 216 * Description:
543 * Test if MAC in Loopback mode
544 *
545 * Parameters:
546 * In:
547 * dwIoBase - Base Address for MAC
548 * Out:
549 * none
550 *
551 * Return Value: true if in Loopback mode; otherwise false
552 *
553 */
554bool MACbIsInLoopbackMode(void __iomem *dwIoBase)
555{
556 unsigned char byOrgValue;
557
558 VNSvInPortB(dwIoBase + MAC_REG_TEST, &byOrgValue);
559 if (byOrgValue & (TEST_LBINT | TEST_LBEXT))
560 return true;
561 return false;
562}
563
564/*
565 * Description:
566 * Set MAC Address filter
567 *
568 * Parameters:
569 * In:
570 * dwIoBase - Base Address for MAC
571 * wFilterType - Filter Type
572 * Out:
573 * none
574 *
575 * Return Value: none
576 *
577 */
578void MACvSetPacketFilter(void __iomem *dwIoBase, unsigned short wFilterType)
579{
580 unsigned char byOldRCR;
581 unsigned char byNewRCR = 0;
582
583 // if only in DIRECTED mode, multicast-address will set to zero,
584 // but if other mode exist (e.g. PROMISCUOUS), multicast-address
585 // will be open
586 if (wFilterType & PKT_TYPE_DIRECTED) {
587 // set multicast address to accept none
588 MACvSelectPage1(dwIoBase);
589 VNSvOutPortD(dwIoBase + MAC_REG_MAR0, 0L);
590 VNSvOutPortD(dwIoBase + MAC_REG_MAR0 + sizeof(unsigned long), 0L);
591 MACvSelectPage0(dwIoBase);
592 }
593
594 if (wFilterType & (PKT_TYPE_PROMISCUOUS | PKT_TYPE_ALL_MULTICAST)) {
595 // set multicast address to accept all
596 MACvSelectPage1(dwIoBase);
597 VNSvOutPortD(dwIoBase + MAC_REG_MAR0, 0xFFFFFFFFL);
598 VNSvOutPortD(dwIoBase + MAC_REG_MAR0 + sizeof(unsigned long), 0xFFFFFFFFL);
599 MACvSelectPage0(dwIoBase);
600 }
601
602 if (wFilterType & PKT_TYPE_PROMISCUOUS) {
603 byNewRCR |= (RCR_RXALLTYPE | RCR_UNICAST | RCR_MULTICAST | RCR_BROADCAST);
604
605 byNewRCR &= ~RCR_BSSID;
606 }
607
608 if (wFilterType & (PKT_TYPE_ALL_MULTICAST | PKT_TYPE_MULTICAST))
609 byNewRCR |= RCR_MULTICAST;
610
611 if (wFilterType & PKT_TYPE_BROADCAST)
612 byNewRCR |= RCR_BROADCAST;
613
614 if (wFilterType & PKT_TYPE_ERROR_CRC)
615 byNewRCR |= RCR_ERRCRC;
616
617 VNSvInPortB(dwIoBase + MAC_REG_RCR, &byOldRCR);
618 if (byNewRCR != byOldRCR) {
619 // Modify the Receive Command Register
620 VNSvOutPortB(dwIoBase + MAC_REG_RCR, byNewRCR);
621 }
622}
623
624/*
625 * Description:
626 * Save MAC registers to context buffer 217 * Save MAC registers to context buffer
627 * 218 *
628 * Parameters: 219 * Parameters:
@@ -702,47 +293,6 @@ void MACvRestoreContext(void __iomem *dwIoBase, unsigned char *pbyCxtBuf)
702 293
703/* 294/*
704 * Description: 295 * Description:
705 * Compare if MAC registers same as context buffer
706 *
707 * Parameters:
708 * In:
709 * dwIoBase - Base Address for MAC
710 * pbyCxtBuf - Context buffer
711 * Out:
712 * none
713 *
714 * Return Value: true if all values are the same; otherwise false
715 *
716 */
717bool MACbCompareContext(void __iomem *dwIoBase, unsigned char *pbyCxtBuf)
718{
719 unsigned long dwData;
720
721 // compare MAC context to determine if this is a power lost init,
722 // return true for power remaining init, return false for power lost init
723
724 // compare CURR_RX_DESC_ADDR, CURR_TX_DESC_ADDR
725 VNSvInPortD(dwIoBase + MAC_REG_TXDMAPTR0, &dwData);
726 if (dwData != *(unsigned long *)(pbyCxtBuf + MAC_REG_TXDMAPTR0))
727 return false;
728
729 VNSvInPortD(dwIoBase + MAC_REG_AC0DMAPTR, &dwData);
730 if (dwData != *(unsigned long *)(pbyCxtBuf + MAC_REG_AC0DMAPTR))
731 return false;
732
733 VNSvInPortD(dwIoBase + MAC_REG_RXDMAPTR0, &dwData);
734 if (dwData != *(unsigned long *)(pbyCxtBuf + MAC_REG_RXDMAPTR0))
735 return false;
736
737 VNSvInPortD(dwIoBase + MAC_REG_RXDMAPTR1, &dwData);
738 if (dwData != *(unsigned long *)(pbyCxtBuf + MAC_REG_RXDMAPTR1))
739 return false;
740
741 return true;
742}
743
744/*
745 * Description:
746 * Software Reset MAC 296 * Software Reset MAC
747 * 297 *
748 * Parameters: 298 * Parameters:
@@ -1018,11 +568,6 @@ void MACvInitialize(void __iomem *dwIoBase)
1018 VNSvOutPortB(dwIoBase + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST); 568 VNSvOutPortB(dwIoBase + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
1019 // enable TSF counter 569 // enable TSF counter
1020 VNSvOutPortB(dwIoBase + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN); 570 VNSvOutPortB(dwIoBase + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1021
1022 // set packet filter
1023 // receive directed and broadcast address
1024
1025 MACvSetPacketFilter(dwIoBase, PKT_TYPE_DIRECTED | PKT_TYPE_BROADCAST);
1026} 571}
1027 572
1028/* 573/*
@@ -1234,27 +779,6 @@ void MACvTimer0MicroSDelay(void __iomem *dwIoBase, unsigned int uDelay)
1234 * Return Value: none 779 * Return Value: none
1235 * 780 *
1236 */ 781 */
1237void MACvOneShotTimer0MicroSec(void __iomem *dwIoBase, unsigned int uDelayTime)
1238{
1239 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
1240 VNSvOutPortD(dwIoBase + MAC_REG_TMDATA0, uDelayTime);
1241 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, (TMCTL_TMD | TMCTL_TE));
1242}
1243
1244/*
1245 * Description:
1246 * Micro Second One shot timer via MAC
1247 *
1248 * Parameters:
1249 * In:
1250 * dwIoBase - Base Address for MAC
1251 * uDelay - Delay time
1252 * Out:
1253 * none
1254 *
1255 * Return Value: none
1256 *
1257 */
1258void MACvOneShotTimer1MicroSec(void __iomem *dwIoBase, unsigned int uDelayTime) 782void MACvOneShotTimer1MicroSec(void __iomem *dwIoBase, unsigned int uDelayTime)
1259{ 783{
1260 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL1, 0); 784 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL1, 0);
@@ -1271,102 +795,6 @@ void MACvSetMISCFifo(void __iomem *dwIoBase, unsigned short wOffset, unsigned lo
1271 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE); 795 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1272} 796}
1273 797
1274bool MACbTxDMAOff(void __iomem *dwIoBase, unsigned int idx)
1275{
1276 unsigned char byData;
1277 unsigned int ww = 0;
1278
1279 if (idx == TYPE_TXDMA0) {
1280 VNSvOutPortB(dwIoBase + MAC_REG_TXDMACTL0+2, DMACTL_RUN);
1281 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1282 VNSvInPortB(dwIoBase + MAC_REG_TXDMACTL0, &byData);
1283 if (!(byData & DMACTL_RUN))
1284 break;
1285 }
1286 } else if (idx == TYPE_AC0DMA) {
1287 VNSvOutPortB(dwIoBase + MAC_REG_AC0DMACTL+2, DMACTL_RUN);
1288 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1289 VNSvInPortB(dwIoBase + MAC_REG_AC0DMACTL, &byData);
1290 if (!(byData & DMACTL_RUN))
1291 break;
1292 }
1293 }
1294 if (ww == W_MAX_TIMEOUT) {
1295 DBG_PORT80(0x29);
1296 pr_debug(" DBG_PORT80(0x29)\n");
1297 return false;
1298 }
1299 return true;
1300}
1301
1302void MACvClearBusSusInd(void __iomem *dwIoBase)
1303{
1304 unsigned long dwOrgValue;
1305 unsigned int ww;
1306 // check if BcnSusInd enabled
1307 VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);
1308 if (!(dwOrgValue & EnCFG_BcnSusInd))
1309 return;
1310 //Set BcnSusClr
1311 dwOrgValue = dwOrgValue | EnCFG_BcnSusClr;
1312 VNSvOutPortD(dwIoBase + MAC_REG_ENCFG, dwOrgValue);
1313 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1314 VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);
1315 if (!(dwOrgValue & EnCFG_BcnSusInd))
1316 break;
1317 }
1318 if (ww == W_MAX_TIMEOUT) {
1319 DBG_PORT80(0x33);
1320 pr_debug(" DBG_PORT80(0x33)\n");
1321 }
1322}
1323
1324void MACvEnableBusSusEn(void __iomem *dwIoBase)
1325{
1326 unsigned char byOrgValue;
1327 unsigned long dwOrgValue;
1328 unsigned int ww;
1329 // check if BcnSusInd enabled
1330 VNSvInPortB(dwIoBase + MAC_REG_CFG , &byOrgValue);
1331
1332 //Set BcnSusEn
1333 byOrgValue = byOrgValue | CFG_BCNSUSEN;
1334 VNSvOutPortB(dwIoBase + MAC_REG_ENCFG, byOrgValue);
1335 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1336 VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);
1337 if (dwOrgValue & EnCFG_BcnSusInd)
1338 break;
1339 }
1340 if (ww == W_MAX_TIMEOUT) {
1341 DBG_PORT80(0x34);
1342 pr_debug(" DBG_PORT80(0x34)\n");
1343 }
1344}
1345
1346bool MACbFlushSYNCFifo(void __iomem *dwIoBase)
1347{
1348 unsigned char byOrgValue;
1349 unsigned int ww;
1350 // Read MACCR
1351 VNSvInPortB(dwIoBase + MAC_REG_MACCR , &byOrgValue);
1352
1353 // Set SYNCFLUSH
1354 byOrgValue = byOrgValue | MACCR_SYNCFLUSH;
1355 VNSvOutPortB(dwIoBase + MAC_REG_MACCR, byOrgValue);
1356
1357 // Check if SyncFlushOK
1358 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1359 VNSvInPortB(dwIoBase + MAC_REG_MACCR , &byOrgValue);
1360 if (byOrgValue & MACCR_SYNCFLUSHOK)
1361 break;
1362 }
1363 if (ww == W_MAX_TIMEOUT) {
1364 DBG_PORT80(0x35);
1365 pr_debug(" DBG_PORT80(0x33)\n");
1366 }
1367 return true;
1368}
1369
1370bool MACbPSWakeup(void __iomem *dwIoBase) 798bool MACbPSWakeup(void __iomem *dwIoBase)
1371{ 799{
1372 unsigned char byOrgValue; 800 unsigned char byOrgValue;
@@ -1484,211 +912,3 @@ void MACvDisableKeyEntry(void __iomem *dwIoBase, unsigned int uEntryIdx)
1484 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, 0); 912 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, 0);
1485 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE); 913 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1486} 914}
1487
1488/*
1489 * Description:
1490 * Set the default Key (KeyEntry[10]) by MISCFIFO
1491 *
1492 * Parameters:
1493 * In:
1494 * dwIoBase - Base Address for MAC
1495 *
1496 * Out:
1497 * none
1498 *
1499 * Return Value: none
1500 *
1501 */
1502
1503void MACvSetDefaultKeyEntry(void __iomem *dwIoBase, unsigned int uKeyLen,
1504 unsigned int uKeyIdx, unsigned long *pdwKey, unsigned char byLocalID)
1505{
1506 unsigned short wOffset;
1507 unsigned long dwData;
1508 int ii;
1509
1510 if (byLocalID <= 1)
1511 return;
1512
1513 pr_debug("MACvSetDefaultKeyEntry\n");
1514 wOffset = MISCFIFO_KEYETRY0;
1515 wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
1516
1517 wOffset++;
1518 wOffset++;
1519 wOffset += (uKeyIdx * 4);
1520 // always push 128 bits
1521 for (ii = 0; ii < 3; ii++) {
1522 pr_debug("(%d) wOffset: %d, Data: %lX\n",
1523 ii, wOffset+ii, *pdwKey);
1524 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+ii);
1525 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, *pdwKey++);
1526 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1527 }
1528 dwData = *pdwKey;
1529 if (uKeyLen == WLAN_WEP104_KEYLEN)
1530 dwData |= 0x80000000;
1531
1532 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+3);
1533 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1534 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1535 pr_debug("End. wOffset: %d, Data: %lX\n", wOffset+3, dwData);
1536}
1537
1538/*
1539 * Description:
1540 * Enable default Key (KeyEntry[10]) by MISCFIFO
1541 *
1542 * Parameters:
1543 * In:
1544 * dwIoBase - Base Address for MAC
1545 *
1546 * Out:
1547 * none
1548 *
1549 * Return Value: none
1550 *
1551 */
1552/*
1553 void MACvEnableDefaultKey(void __iomem *dwIoBase, unsigned char byLocalID)
1554 {
1555 unsigned short wOffset;
1556 unsigned long dwData;
1557
1558 if (byLocalID <= 1)
1559 return;
1560
1561 wOffset = MISCFIFO_KEYETRY0;
1562 wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
1563
1564 dwData = 0xC0440000;
1565 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1566 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1567 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1568 pr_debug("MACvEnableDefaultKey: wOffset: %d, Data: %lX\n", wOffset, dwData);
1569
1570 }
1571*/
1572
1573/*
1574 * Description:
1575 * Disable default Key (KeyEntry[10]) by MISCFIFO
1576 *
1577 * Parameters:
1578 * In:
1579 * dwIoBase - Base Address for MAC
1580 *
1581 * Out:
1582 * none
1583 *
1584 * Return Value: none
1585 *
1586 */
1587void MACvDisableDefaultKey(void __iomem *dwIoBase)
1588{
1589 unsigned short wOffset;
1590 unsigned long dwData;
1591
1592 wOffset = MISCFIFO_KEYETRY0;
1593 wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
1594
1595 dwData = 0x0;
1596 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1597 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1598 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1599 pr_debug("MACvDisableDefaultKey: wOffset: %d, Data: %lX\n",
1600 wOffset, dwData);
1601}
1602
1603/*
1604 * Description:
1605 * Set the default TKIP Group Key (KeyEntry[10]) by MISCFIFO
1606 *
1607 * Parameters:
1608 * In:
1609 * dwIoBase - Base Address for MAC
1610 *
1611 * Out:
1612 * none
1613 *
1614 * Return Value: none
1615 *
1616 */
1617void MACvSetDefaultTKIPKeyEntry(void __iomem *dwIoBase, unsigned int uKeyLen,
1618 unsigned int uKeyIdx, unsigned long *pdwKey, unsigned char byLocalID)
1619{
1620 unsigned short wOffset;
1621 unsigned long dwData;
1622 int ii;
1623
1624 if (byLocalID <= 1)
1625 return;
1626
1627 pr_debug("MACvSetDefaultTKIPKeyEntry\n");
1628 wOffset = MISCFIFO_KEYETRY0;
1629 // Kyle test : change offset from 10 -> 0
1630 wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
1631
1632 dwData = 0xC0660000;
1633 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1634 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1635 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1636 wOffset++;
1637
1638 dwData = 0;
1639 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1640 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1641 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1642 wOffset++;
1643
1644 wOffset += (uKeyIdx * 4);
1645 pr_debug("1. wOffset: %d, Data: %lX, idx:%d\n",
1646 wOffset, *pdwKey, uKeyIdx);
1647 // always push 128 bits
1648 for (ii = 0; ii < 4; ii++) {
1649 pr_debug("2.(%d) wOffset: %d, Data: %lX\n",
1650 ii, wOffset+ii, *pdwKey);
1651 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+ii);
1652 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, *pdwKey++);
1653 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1654 }
1655}
1656
1657/*
1658 * Description:
1659 * Set the Key Control by MISCFIFO
1660 *
1661 * Parameters:
1662 * In:
1663 * dwIoBase - Base Address for MAC
1664 *
1665 * Out:
1666 * none
1667 *
1668 * Return Value: none
1669 *
1670 */
1671
1672void MACvSetDefaultKeyCtl(void __iomem *dwIoBase, unsigned short wKeyCtl, unsigned int uEntryIdx, unsigned char byLocalID)
1673{
1674 unsigned short wOffset;
1675 unsigned long dwData;
1676
1677 if (byLocalID <= 1)
1678 return;
1679
1680 pr_debug("MACvSetKeyEntry\n");
1681 wOffset = MISCFIFO_KEYETRY0;
1682 wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
1683
1684 dwData = 0;
1685 dwData |= wKeyCtl;
1686 dwData <<= 16;
1687 dwData |= 0xffff;
1688 pr_debug("1. wOffset: %d, Data: %lX, KeyCtl:%X\n",
1689 wOffset, dwData, wKeyCtl);
1690
1691 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1692 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1693 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1694}
diff --git a/drivers/staging/vt6655/mac.h b/drivers/staging/vt6655/mac.h
index 0bf93759b6af..e1e7e10435f6 100644
--- a/drivers/staging/vt6655/mac.h
+++ b/drivers/staging/vt6655/mac.h
@@ -34,7 +34,6 @@
34#ifndef __MAC_H__ 34#ifndef __MAC_H__
35#define __MAC_H__ 35#define __MAC_H__
36 36
37#include "ttype.h"
38#include "tmacro.h" 37#include "tmacro.h"
39#include "upc.h" 38#include "upc.h"
40 39
@@ -575,17 +574,6 @@
575#define MAC_LB_INTERNAL 0x01 // 574#define MAC_LB_INTERNAL 0x01 //
576#define MAC_LB_NONE 0x00 // 575#define MAC_LB_NONE 0x00 //
577 576
578// Ethernet address filter type
579#define PKT_TYPE_NONE 0x00 // turn off receiver
580#define PKT_TYPE_ALL_MULTICAST 0x80
581#define PKT_TYPE_PROMISCUOUS 0x40
582#define PKT_TYPE_DIRECTED 0x20 // obsolete, directed address is always accepted
583#define PKT_TYPE_BROADCAST 0x10
584#define PKT_TYPE_MULTICAST 0x08
585#define PKT_TYPE_ERROR_WPA 0x04
586#define PKT_TYPE_ERROR_CRC 0x02
587#define PKT_TYPE_BSSID 0x01
588
589#define Default_BI 0x200 577#define Default_BI 0x200
590 578
591// MiscFIFO Offset 579// MiscFIFO Offset
@@ -965,48 +953,20 @@ do { \
965#define MACvSetRFLE_LatchBase(dwIoBase) \ 953#define MACvSetRFLE_LatchBase(dwIoBase) \
966 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_RFLEOPT) 954 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_RFLEOPT)
967 955
968/*--------------------- Export Classes ----------------------------*/
969
970/*--------------------- Export Variables --------------------------*/
971
972/*--------------------- Export Functions --------------------------*/
973
974extern unsigned short TxRate_iwconfig;//2008-5-8 <add> by chester
975void MACvReadAllRegs(void __iomem *dwIoBase, unsigned char *pbyMacRegs);
976
977bool MACbIsRegBitsOn(void __iomem *dwIoBase, unsigned char byRegOfs, unsigned char byTestBits); 956bool MACbIsRegBitsOn(void __iomem *dwIoBase, unsigned char byRegOfs, unsigned char byTestBits);
978bool MACbIsRegBitsOff(void __iomem *dwIoBase, unsigned char byRegOfs, unsigned char byTestBits); 957bool MACbIsRegBitsOff(void __iomem *dwIoBase, unsigned char byRegOfs, unsigned char byTestBits);
979 958
980bool MACbIsIntDisable(void __iomem *dwIoBase); 959bool MACbIsIntDisable(void __iomem *dwIoBase);
981 960
982unsigned char MACbyReadMultiAddr(void __iomem *dwIoBase, unsigned int uByteIdx);
983void MACvWriteMultiAddr(void __iomem *dwIoBase, unsigned int uByteIdx, unsigned char byData);
984void MACvSetMultiAddrByHash(void __iomem *dwIoBase, unsigned char byHashIdx);
985void MACvResetMultiAddrByHash(void __iomem *dwIoBase, unsigned char byHashIdx);
986
987void MACvSetRxThreshold(void __iomem *dwIoBase, unsigned char byThreshold);
988void MACvGetRxThreshold(void __iomem *dwIoBase, unsigned char *pbyThreshold);
989
990void MACvSetTxThreshold(void __iomem *dwIoBase, unsigned char byThreshold);
991void MACvGetTxThreshold(void __iomem *dwIoBase, unsigned char *pbyThreshold);
992
993void MACvSetDmaLength(void __iomem *dwIoBase, unsigned char byDmaLength);
994void MACvGetDmaLength(void __iomem *dwIoBase, unsigned char *pbyDmaLength);
995
996void MACvSetShortRetryLimit(void __iomem *dwIoBase, unsigned char byRetryLimit); 961void MACvSetShortRetryLimit(void __iomem *dwIoBase, unsigned char byRetryLimit);
997void MACvGetShortRetryLimit(void __iomem *dwIoBase, unsigned char *pbyRetryLimit);
998 962
999void MACvSetLongRetryLimit(void __iomem *dwIoBase, unsigned char byRetryLimit); 963void MACvSetLongRetryLimit(void __iomem *dwIoBase, unsigned char byRetryLimit);
1000void MACvGetLongRetryLimit(void __iomem *dwIoBase, unsigned char *pbyRetryLimit); 964void MACvGetLongRetryLimit(void __iomem *dwIoBase, unsigned char *pbyRetryLimit);
1001 965
1002void MACvSetLoopbackMode(void __iomem *dwIoBase, unsigned char byLoopbackMode); 966void MACvSetLoopbackMode(void __iomem *dwIoBase, unsigned char byLoopbackMode);
1003bool MACbIsInLoopbackMode(void __iomem *dwIoBase);
1004
1005void MACvSetPacketFilter(void __iomem *dwIoBase, unsigned short wFilterType);
1006 967
1007void MACvSaveContext(void __iomem *dwIoBase, unsigned char *pbyCxtBuf); 968void MACvSaveContext(void __iomem *dwIoBase, unsigned char *pbyCxtBuf);
1008void MACvRestoreContext(void __iomem *dwIoBase, unsigned char *pbyCxtBuf); 969void MACvRestoreContext(void __iomem *dwIoBase, unsigned char *pbyCxtBuf);
1009bool MACbCompareContext(void __iomem *dwIoBase, unsigned char *pbyCxtBuf);
1010 970
1011bool MACbSoftwareReset(void __iomem *dwIoBase); 971bool MACbSoftwareReset(void __iomem *dwIoBase);
1012bool MACbSafeSoftwareReset(void __iomem *dwIoBase); 972bool MACbSafeSoftwareReset(void __iomem *dwIoBase);
@@ -1023,27 +983,14 @@ void MACvSetCurrAC0DescAddrEx(void __iomem *dwIoBase, unsigned long dwCurrDescAd
1023void MACvSetCurrSyncDescAddrEx(void __iomem *dwIoBase, unsigned long dwCurrDescAddr); 983void MACvSetCurrSyncDescAddrEx(void __iomem *dwIoBase, unsigned long dwCurrDescAddr);
1024void MACvSetCurrATIMDescAddrEx(void __iomem *dwIoBase, unsigned long dwCurrDescAddr); 984void MACvSetCurrATIMDescAddrEx(void __iomem *dwIoBase, unsigned long dwCurrDescAddr);
1025void MACvTimer0MicroSDelay(void __iomem *dwIoBase, unsigned int uDelay); 985void MACvTimer0MicroSDelay(void __iomem *dwIoBase, unsigned int uDelay);
1026void MACvOneShotTimer0MicroSec(void __iomem *dwIoBase, unsigned int uDelayTime);
1027void MACvOneShotTimer1MicroSec(void __iomem *dwIoBase, unsigned int uDelayTime); 986void MACvOneShotTimer1MicroSec(void __iomem *dwIoBase, unsigned int uDelayTime);
1028 987
1029void MACvSetMISCFifo(void __iomem *dwIoBase, unsigned short wOffset, unsigned long dwData); 988void MACvSetMISCFifo(void __iomem *dwIoBase, unsigned short wOffset, unsigned long dwData);
1030 989
1031bool MACbTxDMAOff(void __iomem *dwIoBase, unsigned int idx);
1032
1033void MACvClearBusSusInd(void __iomem *dwIoBase);
1034void MACvEnableBusSusEn(void __iomem *dwIoBase);
1035
1036bool MACbFlushSYNCFifo(void __iomem *dwIoBase);
1037bool MACbPSWakeup(void __iomem *dwIoBase); 990bool MACbPSWakeup(void __iomem *dwIoBase);
1038 991
1039void MACvSetKeyEntry(void __iomem *dwIoBase, unsigned short wKeyCtl, unsigned int uEntryIdx, 992void MACvSetKeyEntry(void __iomem *dwIoBase, unsigned short wKeyCtl, unsigned int uEntryIdx,
1040 unsigned int uKeyIdx, unsigned char *pbyAddr, u32 *pdwKey, unsigned char byLocalID); 993 unsigned int uKeyIdx, unsigned char *pbyAddr, u32 *pdwKey, unsigned char byLocalID);
1041void MACvDisableKeyEntry(void __iomem *dwIoBase, unsigned int uEntryIdx); 994void MACvDisableKeyEntry(void __iomem *dwIoBase, unsigned int uEntryIdx);
1042void MACvSetDefaultKeyEntry(void __iomem *dwIoBase, unsigned int uKeyLen,
1043 unsigned int uKeyIdx, unsigned long *pdwKey, unsigned char byLocalID);
1044void MACvDisableDefaultKey(void __iomem *dwIoBase);
1045void MACvSetDefaultTKIPKeyEntry(void __iomem *dwIoBase, unsigned int uKeyLen,
1046 unsigned int uKeyIdx, unsigned long *pdwKey, unsigned char byLocalID);
1047void MACvSetDefaultKeyCtl(void __iomem *dwIoBase, unsigned short wKeyCtl, unsigned int uEntryIdx, unsigned char byLocalID);
1048 995
1049#endif // __MAC_H__ 996#endif // __MAC_H__
diff --git a/drivers/staging/vt6655/mib.c b/drivers/staging/vt6655/mib.c
index 111c01877086..d2f351d19ff8 100644
--- a/drivers/staging/vt6655/mib.c
+++ b/drivers/staging/vt6655/mib.c
@@ -25,24 +25,15 @@
25 * Date: May 21, 1996 25 * Date: May 21, 1996
26 * 26 *
27 * Functions: 27 * Functions:
28 * STAvClearAllCounter - Clear All MIB Counter
29 * STAvUpdateIstStatCounter - Update ISR statistic counter 28 * STAvUpdateIstStatCounter - Update ISR statistic counter
30 * STAvUpdateRDStatCounter - Update Rx statistic counter
31 * STAvUpdateRDStatCounterEx - Update Rx statistic counter and copy rcv data
32 * STAvUpdateTDStatCounter - Update Tx statistic counter
33 * STAvUpdateTDStatCounterEx - Update Tx statistic counter and copy tx data
34 * STAvUpdate802_11Counter - Update 802.11 mib counter 29 * STAvUpdate802_11Counter - Update 802.11 mib counter
35 * 30 *
36 * Revision History: 31 * Revision History:
37 * 32 *
38 */ 33 */
39 34
40#include "upc.h"
41#include "mac.h" 35#include "mac.h"
42#include "tether.h"
43#include "mib.h" 36#include "mib.h"
44#include "wctl.h"
45#include "baseband.h"
46 37
47/*--------------------- Static Classes ----------------------------*/ 38/*--------------------- Static Classes ----------------------------*/
48 39
@@ -55,24 +46,6 @@
55/*--------------------- Export Functions --------------------------*/ 46/*--------------------- Export Functions --------------------------*/
56 47
57/* 48/*
58 * Description: Clear All Statistic Counter
59 *
60 * Parameters:
61 * In:
62 * pStatistic - Pointer to Statistic Counter Data Structure
63 * Out:
64 * none
65 *
66 * Return Value: none
67 *
68 */
69void STAvClearAllCounter(PSStatCounter pStatistic)
70{
71 // set memory to zero
72 memset(pStatistic, 0, sizeof(SStatCounter));
73}
74
75/*
76 * Description: Update Isr Statistic Counter 49 * Description: Update Isr Statistic Counter
77 * 50 *
78 * Parameters: 51 * Parameters:
@@ -139,373 +112,6 @@ void STAvUpdateIsrStatCounter(PSStatCounter pStatistic, unsigned long dwIsr)
139} 112}
140 113
141/* 114/*
142 * Description: Update Rx Statistic Counter
143 *
144 * Parameters:
145 * In:
146 * pStatistic - Pointer to Statistic Counter Data Structure
147 * byRSR - Rx Status
148 * byNewRSR - Rx Status
149 * pbyBuffer - Rx Buffer
150 * cbFrameLength - Rx Length
151 * Out:
152 * none
153 *
154 * Return Value: none
155 *
156 */
157void STAvUpdateRDStatCounter(PSStatCounter pStatistic,
158 unsigned char byRSR, unsigned char byNewRSR, unsigned char byRxRate,
159 unsigned char *pbyBuffer, unsigned int cbFrameLength)
160{
161 //need change
162 PS802_11Header pHeader = (PS802_11Header)pbyBuffer;
163
164 if (byRSR & RSR_ADDROK)
165 pStatistic->dwRsrADDROk++;
166 if (byRSR & RSR_CRCOK) {
167 pStatistic->dwRsrCRCOk++;
168
169 pStatistic->ullRsrOK++;
170
171 if (cbFrameLength >= ETH_ALEN) {
172 // update counters in case of successful transmit
173 if (byRSR & RSR_ADDRBROAD) {
174 pStatistic->ullRxBroadcastFrames++;
175 pStatistic->ullRxBroadcastBytes += (unsigned long long) cbFrameLength;
176 } else if (byRSR & RSR_ADDRMULTI) {
177 pStatistic->ullRxMulticastFrames++;
178 pStatistic->ullRxMulticastBytes += (unsigned long long) cbFrameLength;
179 } else {
180 pStatistic->ullRxDirectedFrames++;
181 pStatistic->ullRxDirectedBytes += (unsigned long long) cbFrameLength;
182 }
183 }
184 }
185
186 if (byRxRate == 22) {
187 pStatistic->CustomStat.ullRsr11M++;
188 if (byRSR & RSR_CRCOK)
189 pStatistic->CustomStat.ullRsr11MCRCOk++;
190
191 pr_debug("11M: ALL[%d], OK[%d]:[%02x]\n",
192 (int)pStatistic->CustomStat.ullRsr11M,
193 (int)pStatistic->CustomStat.ullRsr11MCRCOk, byRSR);
194 } else if (byRxRate == 11) {
195 pStatistic->CustomStat.ullRsr5M++;
196 if (byRSR & RSR_CRCOK)
197 pStatistic->CustomStat.ullRsr5MCRCOk++;
198
199 pr_debug(" 5M: ALL[%d], OK[%d]:[%02x]\n",
200 (int)pStatistic->CustomStat.ullRsr5M,
201 (int)pStatistic->CustomStat.ullRsr5MCRCOk, byRSR);
202 } else if (byRxRate == 4) {
203 pStatistic->CustomStat.ullRsr2M++;
204 if (byRSR & RSR_CRCOK)
205 pStatistic->CustomStat.ullRsr2MCRCOk++;
206
207 pr_debug(" 2M: ALL[%d], OK[%d]:[%02x]\n",
208 (int)pStatistic->CustomStat.ullRsr2M,
209 (int)pStatistic->CustomStat.ullRsr2MCRCOk, byRSR);
210 } else if (byRxRate == 2) {
211 pStatistic->CustomStat.ullRsr1M++;
212 if (byRSR & RSR_CRCOK)
213 pStatistic->CustomStat.ullRsr1MCRCOk++;
214
215 pr_debug(" 1M: ALL[%d], OK[%d]:[%02x]\n",
216 (int)pStatistic->CustomStat.ullRsr1M,
217 (int)pStatistic->CustomStat.ullRsr1MCRCOk, byRSR);
218 } else if (byRxRate == 12) {
219 pStatistic->CustomStat.ullRsr6M++;
220 if (byRSR & RSR_CRCOK)
221 pStatistic->CustomStat.ullRsr6MCRCOk++;
222
223 pr_debug(" 6M: ALL[%d], OK[%d]\n",
224 (int)pStatistic->CustomStat.ullRsr6M,
225 (int)pStatistic->CustomStat.ullRsr6MCRCOk);
226 } else if (byRxRate == 18) {
227 pStatistic->CustomStat.ullRsr9M++;
228 if (byRSR & RSR_CRCOK)
229 pStatistic->CustomStat.ullRsr9MCRCOk++;
230
231 pr_debug(" 9M: ALL[%d], OK[%d]\n",
232 (int)pStatistic->CustomStat.ullRsr9M,
233 (int)pStatistic->CustomStat.ullRsr9MCRCOk);
234 } else if (byRxRate == 24) {
235 pStatistic->CustomStat.ullRsr12M++;
236 if (byRSR & RSR_CRCOK)
237 pStatistic->CustomStat.ullRsr12MCRCOk++;
238
239 pr_debug("12M: ALL[%d], OK[%d]\n",
240 (int)pStatistic->CustomStat.ullRsr12M,
241 (int)pStatistic->CustomStat.ullRsr12MCRCOk);
242 } else if (byRxRate == 36) {
243 pStatistic->CustomStat.ullRsr18M++;
244 if (byRSR & RSR_CRCOK)
245 pStatistic->CustomStat.ullRsr18MCRCOk++;
246
247 pr_debug("18M: ALL[%d], OK[%d]\n",
248 (int)pStatistic->CustomStat.ullRsr18M,
249 (int)pStatistic->CustomStat.ullRsr18MCRCOk);
250 } else if (byRxRate == 48) {
251 pStatistic->CustomStat.ullRsr24M++;
252 if (byRSR & RSR_CRCOK)
253 pStatistic->CustomStat.ullRsr24MCRCOk++;
254
255 pr_debug("24M: ALL[%d], OK[%d]\n",
256 (int)pStatistic->CustomStat.ullRsr24M,
257 (int)pStatistic->CustomStat.ullRsr24MCRCOk);
258 } else if (byRxRate == 72) {
259 pStatistic->CustomStat.ullRsr36M++;
260 if (byRSR & RSR_CRCOK)
261 pStatistic->CustomStat.ullRsr36MCRCOk++;
262
263 pr_debug("36M: ALL[%d], OK[%d]\n",
264 (int)pStatistic->CustomStat.ullRsr36M,
265 (int)pStatistic->CustomStat.ullRsr36MCRCOk);
266 } else if (byRxRate == 96) {
267 pStatistic->CustomStat.ullRsr48M++;
268 if (byRSR & RSR_CRCOK)
269 pStatistic->CustomStat.ullRsr48MCRCOk++;
270
271 pr_debug("48M: ALL[%d], OK[%d]\n",
272 (int)pStatistic->CustomStat.ullRsr48M,
273 (int)pStatistic->CustomStat.ullRsr48MCRCOk);
274 } else if (byRxRate == 108) {
275 pStatistic->CustomStat.ullRsr54M++;
276 if (byRSR & RSR_CRCOK)
277 pStatistic->CustomStat.ullRsr54MCRCOk++;
278
279 pr_debug("54M: ALL[%d], OK[%d]\n",
280 (int)pStatistic->CustomStat.ullRsr54M,
281 (int)pStatistic->CustomStat.ullRsr54MCRCOk);
282 } else {
283 pr_debug("Unknown: Total[%d], CRCOK[%d]\n",
284 (int)pStatistic->dwRsrRxPacket+1,
285 (int)pStatistic->dwRsrCRCOk);
286 }
287
288 if (byRSR & RSR_BSSIDOK)
289 pStatistic->dwRsrBSSIDOk++;
290
291 if (byRSR & RSR_BCNSSIDOK)
292 pStatistic->dwRsrBCNSSIDOk++;
293 if (byRSR & RSR_IVLDLEN) //invalid len (> 2312 byte)
294 pStatistic->dwRsrLENErr++;
295 if (byRSR & RSR_IVLDTYP) //invalid packet type
296 pStatistic->dwRsrTYPErr++;
297 if (byRSR & (RSR_IVLDTYP | RSR_IVLDLEN))
298 pStatistic->dwRsrErr++;
299
300 if (byNewRSR & NEWRSR_DECRYPTOK)
301 pStatistic->dwNewRsrDECRYPTOK++;
302 if (byNewRSR & NEWRSR_CFPIND)
303 pStatistic->dwNewRsrCFP++;
304 if (byNewRSR & NEWRSR_HWUTSF)
305 pStatistic->dwNewRsrUTSF++;
306 if (byNewRSR & NEWRSR_BCNHITAID)
307 pStatistic->dwNewRsrHITAID++;
308 if (byNewRSR & NEWRSR_BCNHITAID0)
309 pStatistic->dwNewRsrHITAID0++;
310
311 // increase rx packet count
312 pStatistic->dwRsrRxPacket++;
313 pStatistic->dwRsrRxOctet += cbFrameLength;
314
315 if (IS_TYPE_DATA(pbyBuffer))
316 pStatistic->dwRsrRxData++;
317 else if (IS_TYPE_MGMT(pbyBuffer))
318 pStatistic->dwRsrRxManage++;
319 else if (IS_TYPE_CONTROL(pbyBuffer))
320 pStatistic->dwRsrRxControl++;
321
322 if (byRSR & RSR_ADDRBROAD)
323 pStatistic->dwRsrBroadcast++;
324 else if (byRSR & RSR_ADDRMULTI)
325 pStatistic->dwRsrMulticast++;
326 else
327 pStatistic->dwRsrDirected++;
328
329 if (WLAN_GET_FC_MOREFRAG(pHeader->wFrameCtl))
330 pStatistic->dwRsrRxFragment++;
331
332 if (cbFrameLength < ETH_ZLEN + 4)
333 pStatistic->dwRsrRunt++;
334 else if (cbFrameLength == ETH_ZLEN + 4)
335 pStatistic->dwRsrRxFrmLen64++;
336 else if ((65 <= cbFrameLength) && (cbFrameLength <= 127))
337 pStatistic->dwRsrRxFrmLen65_127++;
338 else if ((128 <= cbFrameLength) && (cbFrameLength <= 255))
339 pStatistic->dwRsrRxFrmLen128_255++;
340 else if ((256 <= cbFrameLength) && (cbFrameLength <= 511))
341 pStatistic->dwRsrRxFrmLen256_511++;
342 else if ((512 <= cbFrameLength) && (cbFrameLength <= 1023))
343 pStatistic->dwRsrRxFrmLen512_1023++;
344 else if ((1024 <= cbFrameLength) && (cbFrameLength <= ETH_FRAME_LEN + 4))
345 pStatistic->dwRsrRxFrmLen1024_1518++;
346 else if (cbFrameLength > ETH_FRAME_LEN + 4)
347 pStatistic->dwRsrLong++;
348}
349
350/*
351 * Description: Update Rx Statistic Counter and copy Rx buffer
352 *
353 * Parameters:
354 * In:
355 * pStatistic - Pointer to Statistic Counter Data Structure
356 * byRSR - Rx Status
357 * byNewRSR - Rx Status
358 * pbyBuffer - Rx Buffer
359 * cbFrameLength - Rx Length
360 * Out:
361 * none
362 *
363 * Return Value: none
364 *
365 */
366
367void
368STAvUpdateRDStatCounterEx(
369 PSStatCounter pStatistic,
370 unsigned char byRSR,
371 unsigned char byNewRSR,
372 unsigned char byRxRate,
373 unsigned char *pbyBuffer,
374 unsigned int cbFrameLength
375)
376{
377 STAvUpdateRDStatCounter(
378 pStatistic,
379 byRSR,
380 byNewRSR,
381 byRxRate,
382 pbyBuffer,
383 cbFrameLength
384);
385
386 // rx length
387 pStatistic->dwCntRxFrmLength = cbFrameLength;
388 // rx pattern, we just see 10 bytes for sample
389 memcpy(pStatistic->abyCntRxPattern, (unsigned char *)pbyBuffer, 10);
390}
391
392/*
393 * Description: Update Tx Statistic Counter
394 *
395 * Parameters:
396 * In:
397 * pStatistic - Pointer to Statistic Counter Data Structure
398 * byTSR0 - Tx Status
399 * byTSR1 - Tx Status
400 * pbyBuffer - Tx Buffer
401 * cbFrameLength - Tx Length
402 * uIdx - Index of Tx DMA
403 * Out:
404 * none
405 *
406 * Return Value: none
407 *
408 */
409void
410STAvUpdateTDStatCounter(
411 PSStatCounter pStatistic,
412 unsigned char byTSR0,
413 unsigned char byTSR1,
414 unsigned char *pbyBuffer,
415 unsigned int cbFrameLength,
416 unsigned int uIdx
417)
418{
419 PWLAN_80211HDR_A4 pHeader;
420 unsigned char *pbyDestAddr;
421 unsigned char byTSR0_NCR = byTSR0 & TSR0_NCR;
422
423 pHeader = (PWLAN_80211HDR_A4) pbyBuffer;
424 if (WLAN_GET_FC_TODS(pHeader->wFrameCtl) == 0)
425 pbyDestAddr = &(pHeader->abyAddr1[0]);
426 else
427 pbyDestAddr = &(pHeader->abyAddr3[0]);
428
429 // increase tx packet count
430 pStatistic->dwTsrTxPacket[uIdx]++;
431 pStatistic->dwTsrTxOctet[uIdx] += cbFrameLength;
432
433 if (byTSR0_NCR != 0) {
434 pStatistic->dwTsrRetry[uIdx]++;
435 pStatistic->dwTsrTotalRetry[uIdx] += byTSR0_NCR;
436
437 if (byTSR0_NCR == 1)
438 pStatistic->dwTsrOnceRetry[uIdx]++;
439 else
440 pStatistic->dwTsrMoreThanOnceRetry[uIdx]++;
441 }
442
443 if ((byTSR1&(TSR1_TERR|TSR1_RETRYTMO|TSR1_TMO|ACK_DATA)) == 0) {
444 pStatistic->ullTsrOK[uIdx]++;
445 pStatistic->CustomStat.ullTsrAllOK =
446 (pStatistic->ullTsrOK[TYPE_AC0DMA] + pStatistic->ullTsrOK[TYPE_TXDMA0]);
447 // update counters in case that successful transmit
448 if (is_broadcast_ether_addr(pbyDestAddr)) {
449 pStatistic->ullTxBroadcastFrames[uIdx]++;
450 pStatistic->ullTxBroadcastBytes[uIdx] += (unsigned long long) cbFrameLength;
451 } else if (is_multicast_ether_addr(pbyDestAddr)) {
452 pStatistic->ullTxMulticastFrames[uIdx]++;
453 pStatistic->ullTxMulticastBytes[uIdx] += (unsigned long long) cbFrameLength;
454 } else {
455 pStatistic->ullTxDirectedFrames[uIdx]++;
456 pStatistic->ullTxDirectedBytes[uIdx] += (unsigned long long) cbFrameLength;
457 }
458 } else {
459 if (byTSR1 & TSR1_TERR)
460 pStatistic->dwTsrErr[uIdx]++;
461 if (byTSR1 & TSR1_RETRYTMO)
462 pStatistic->dwTsrRetryTimeout[uIdx]++;
463 if (byTSR1 & TSR1_TMO)
464 pStatistic->dwTsrTransmitTimeout[uIdx]++;
465 if (byTSR1 & ACK_DATA)
466 pStatistic->dwTsrACKData[uIdx]++;
467 }
468
469 if (is_broadcast_ether_addr(pbyDestAddr))
470 pStatistic->dwTsrBroadcast[uIdx]++;
471 else if (is_multicast_ether_addr(pbyDestAddr))
472 pStatistic->dwTsrMulticast[uIdx]++;
473 else
474 pStatistic->dwTsrDirected[uIdx]++;
475}
476
477/*
478 * Description: Update Tx Statistic Counter and copy Tx buffer
479 *
480 * Parameters:
481 * In:
482 * pStatistic - Pointer to Statistic Counter Data Structure
483 * pbyBuffer - Tx Buffer
484 * cbFrameLength - Tx Length
485 * Out:
486 * none
487 *
488 * Return Value: none
489 *
490 */
491void
492STAvUpdateTDStatCounterEx(
493 PSStatCounter pStatistic,
494 unsigned char *pbyBuffer,
495 unsigned long cbFrameLength
496)
497{
498 unsigned int uPktLength;
499
500 uPktLength = (unsigned int)cbFrameLength;
501
502 // tx length
503 pStatistic->dwCntTxBufLength = uPktLength;
504 // tx pattern, we just see 16 bytes for sample
505 memcpy(pStatistic->abyCntTxPattern, pbyBuffer, 16);
506}
507
508/*
509 * Description: Update 802.11 mib counter 115 * Description: Update 802.11 mib counter
510 * 116 *
511 * Parameters: 117 * Parameters:
@@ -526,37 +132,8 @@ STAvUpdate802_11Counter(
526 unsigned long dwCounter 132 unsigned long dwCounter
527) 133)
528{ 134{
529 p802_11Counter->MulticastTransmittedFrameCount = (unsigned long long) (pStatistic->dwTsrBroadcast[TYPE_AC0DMA] +
530 pStatistic->dwTsrBroadcast[TYPE_TXDMA0] +
531 pStatistic->dwTsrMulticast[TYPE_AC0DMA] +
532 pStatistic->dwTsrMulticast[TYPE_TXDMA0]);
533 p802_11Counter->FailedCount = (unsigned long long) (pStatistic->dwTsrErr[TYPE_AC0DMA] + pStatistic->dwTsrErr[TYPE_TXDMA0]);
534 p802_11Counter->RetryCount = (unsigned long long) (pStatistic->dwTsrRetry[TYPE_AC0DMA] + pStatistic->dwTsrRetry[TYPE_TXDMA0]);
535 p802_11Counter->MultipleRetryCount = (unsigned long long) (pStatistic->dwTsrMoreThanOnceRetry[TYPE_AC0DMA] +
536 pStatistic->dwTsrMoreThanOnceRetry[TYPE_TXDMA0]);
537 p802_11Counter->RTSSuccessCount += (unsigned long long) (dwCounter & 0x000000ff); 135 p802_11Counter->RTSSuccessCount += (unsigned long long) (dwCounter & 0x000000ff);
538 p802_11Counter->RTSFailureCount += (unsigned long long) ((dwCounter & 0x0000ff00) >> 8); 136 p802_11Counter->RTSFailureCount += (unsigned long long) ((dwCounter & 0x0000ff00) >> 8);
539 p802_11Counter->ACKFailureCount += (unsigned long long) ((dwCounter & 0x00ff0000) >> 16); 137 p802_11Counter->ACKFailureCount += (unsigned long long) ((dwCounter & 0x00ff0000) >> 16);
540 p802_11Counter->FCSErrorCount += (unsigned long long) ((dwCounter & 0xff000000) >> 24); 138 p802_11Counter->FCSErrorCount += (unsigned long long) ((dwCounter & 0xff000000) >> 24);
541 p802_11Counter->MulticastReceivedFrameCount = (unsigned long long) (pStatistic->dwRsrBroadcast +
542 pStatistic->dwRsrMulticast);
543}
544
545/*
546 * Description: Clear 802.11 mib counter
547 *
548 * Parameters:
549 * In:
550 * p802_11Counter - Pointer to 802.11 mib counter
551 * Out:
552 * none
553 *
554 * Return Value: none
555 *
556 */
557void
558STAvClear802_11Counter(PSDot11Counters p802_11Counter)
559{
560 // set memory to zero
561 memset(p802_11Counter, 0, sizeof(SDot11Counters));
562} 139}
diff --git a/drivers/staging/vt6655/mib.h b/drivers/staging/vt6655/mib.h
index 732bddaf5b91..5cb59b8a1c7c 100644
--- a/drivers/staging/vt6655/mib.h
+++ b/drivers/staging/vt6655/mib.h
@@ -29,8 +29,6 @@
29#ifndef __MIB_H__ 29#ifndef __MIB_H__
30#define __MIB_H__ 30#define __MIB_H__
31 31
32#include "ttype.h"
33#include "tether.h"
34#include "desc.h" 32#include "desc.h"
35 33
36// 34//
@@ -38,136 +36,16 @@
38// 36//
39 37
40typedef struct tagSDot11Counters { 38typedef struct tagSDot11Counters {
41 unsigned long Length;
42 unsigned long long TransmittedFragmentCount;
43 unsigned long long MulticastTransmittedFrameCount;
44 unsigned long long FailedCount;
45 unsigned long long RetryCount;
46 unsigned long long MultipleRetryCount;
47 unsigned long long RTSSuccessCount; 39 unsigned long long RTSSuccessCount;
48 unsigned long long RTSFailureCount; 40 unsigned long long RTSFailureCount;
49 unsigned long long ACKFailureCount; 41 unsigned long long ACKFailureCount;
50 unsigned long long FrameDuplicateCount;
51 unsigned long long ReceivedFragmentCount;
52 unsigned long long MulticastReceivedFrameCount;
53 unsigned long long FCSErrorCount; 42 unsigned long long FCSErrorCount;
54 unsigned long long TKIPLocalMICFailures;
55 unsigned long long TKIPRemoteMICFailures;
56 unsigned long long TKIPICVErrors;
57 unsigned long long TKIPCounterMeasuresInvoked;
58 unsigned long long TKIPReplays;
59 unsigned long long CCMPFormatErrors;
60 unsigned long long CCMPReplays;
61 unsigned long long CCMPDecryptErrors;
62 unsigned long long FourWayHandshakeFailures;
63} SDot11Counters, *PSDot11Counters; 43} SDot11Counters, *PSDot11Counters;
64 44
65// 45//
66// MIB2 counter
67//
68typedef struct tagSMib2Counter {
69 long ifIndex;
70 char ifDescr[256];
71 long ifType;
72 long ifMtu;
73 unsigned long ifSpeed;
74 unsigned char ifPhysAddress[ETH_ALEN];
75 long ifAdminStatus;
76 long ifOperStatus;
77 unsigned long ifLastChange;
78 unsigned long ifInOctets;
79 unsigned long ifInUcastPkts;
80 unsigned long ifInNUcastPkts;
81 unsigned long ifInDiscards;
82 unsigned long ifInErrors;
83 unsigned long ifInUnknownProtos;
84 unsigned long ifOutOctets;
85 unsigned long ifOutUcastPkts;
86 unsigned long ifOutNUcastPkts;
87 unsigned long ifOutDiscards;
88 unsigned long ifOutErrors;
89 unsigned long ifOutQLen;
90 unsigned long ifSpecific;
91} SMib2Counter, *PSMib2Counter;
92
93// Value in the ifType entry
94#define WIRELESSLANIEEE80211b 6
95
96// Value in the ifAdminStatus/ifOperStatus entry
97#define UP 1
98#define DOWN 2
99#define TESTING 3
100
101//
102// RMON counter
103//
104typedef struct tagSRmonCounter {
105 long etherStatsIndex;
106 unsigned long etherStatsDataSource;
107 unsigned long etherStatsDropEvents;
108 unsigned long etherStatsOctets;
109 unsigned long etherStatsPkts;
110 unsigned long etherStatsBroadcastPkts;
111 unsigned long etherStatsMulticastPkts;
112 unsigned long etherStatsCRCAlignErrors;
113 unsigned long etherStatsUndersizePkts;
114 unsigned long etherStatsOversizePkts;
115 unsigned long etherStatsFragments;
116 unsigned long etherStatsJabbers;
117 unsigned long etherStatsCollisions;
118 unsigned long etherStatsPkt64Octets;
119 unsigned long etherStatsPkt65to127Octets;
120 unsigned long etherStatsPkt128to255Octets;
121 unsigned long etherStatsPkt256to511Octets;
122 unsigned long etherStatsPkt512to1023Octets;
123 unsigned long etherStatsPkt1024to1518Octets;
124 unsigned long etherStatsOwners;
125 unsigned long etherStatsStatus;
126} SRmonCounter, *PSRmonCounter;
127
128//
129// Custom counter
130//
131typedef struct tagSCustomCounters {
132 unsigned long Length;
133
134 unsigned long long ullTsrAllOK;
135
136 unsigned long long ullRsr11M;
137 unsigned long long ullRsr5M;
138 unsigned long long ullRsr2M;
139 unsigned long long ullRsr1M;
140
141 unsigned long long ullRsr11MCRCOk;
142 unsigned long long ullRsr5MCRCOk;
143 unsigned long long ullRsr2MCRCOk;
144 unsigned long long ullRsr1MCRCOk;
145
146 unsigned long long ullRsr54M;
147 unsigned long long ullRsr48M;
148 unsigned long long ullRsr36M;
149 unsigned long long ullRsr24M;
150 unsigned long long ullRsr18M;
151 unsigned long long ullRsr12M;
152 unsigned long long ullRsr9M;
153 unsigned long long ullRsr6M;
154
155 unsigned long long ullRsr54MCRCOk;
156 unsigned long long ullRsr48MCRCOk;
157 unsigned long long ullRsr36MCRCOk;
158 unsigned long long ullRsr24MCRCOk;
159 unsigned long long ullRsr18MCRCOk;
160 unsigned long long ullRsr12MCRCOk;
161 unsigned long long ullRsr9MCRCOk;
162 unsigned long long ullRsr6MCRCOk;
163} SCustomCounters, *PSCustomCounters;
164
165//
166// Custom counter 46// Custom counter
167// 47//
168typedef struct tagSISRCounters { 48typedef struct tagSISRCounters {
169 unsigned long Length;
170
171 unsigned long dwIsrTx0OK; 49 unsigned long dwIsrTx0OK;
172 unsigned long dwIsrAC0TxOK; 50 unsigned long dwIsrAC0TxOK;
173 unsigned long dwIsrBeaconTxOK; 51 unsigned long dwIsrBeaconTxOK;
@@ -183,161 +61,22 @@ typedef struct tagSISRCounters {
183 unsigned long dwIsrUnknown; 61 unsigned long dwIsrUnknown;
184 62
185 unsigned long dwIsrRx1OK; 63 unsigned long dwIsrRx1OK;
186 unsigned long dwIsrATIMTxOK;
187 unsigned long dwIsrSYNCTxOK;
188 unsigned long dwIsrCFPEnd;
189 unsigned long dwIsrATIMEnd;
190 unsigned long dwIsrSYNCFlushOK;
191 unsigned long dwIsrSTIMER1Int; 64 unsigned long dwIsrSTIMER1Int;
192} SISRCounters, *PSISRCounters; 65} SISRCounters, *PSISRCounters;
193 66
194// Value in the etherStatsStatus entry
195#define VALID 1
196#define CREATE_REQUEST 2
197#define UNDER_CREATION 3
198#define INVALID 4
199
200// 67//
201// statistic counter 68// statistic counter
202// 69//
203typedef struct tagSStatCounter { 70typedef struct tagSStatCounter {
204 // RSR status count
205 //
206 unsigned long dwRsrFrmAlgnErr;
207 unsigned long dwRsrErr;
208 unsigned long dwRsrCRCErr;
209 unsigned long dwRsrCRCOk;
210 unsigned long dwRsrBSSIDOk;
211 unsigned long dwRsrADDROk;
212 unsigned long dwRsrBCNSSIDOk;
213 unsigned long dwRsrLENErr;
214 unsigned long dwRsrTYPErr;
215
216 unsigned long dwNewRsrDECRYPTOK;
217 unsigned long dwNewRsrCFP;
218 unsigned long dwNewRsrUTSF;
219 unsigned long dwNewRsrHITAID;
220 unsigned long dwNewRsrHITAID0;
221
222 unsigned long dwRsrLong;
223 unsigned long dwRsrRunt;
224
225 unsigned long dwRsrRxControl;
226 unsigned long dwRsrRxData;
227 unsigned long dwRsrRxManage;
228
229 unsigned long dwRsrRxPacket;
230 unsigned long dwRsrRxOctet;
231 unsigned long dwRsrBroadcast;
232 unsigned long dwRsrMulticast;
233 unsigned long dwRsrDirected;
234 // 64-bit OID
235 unsigned long long ullRsrOK;
236
237 // for some optional OIDs (64 bits) and DMI support
238 unsigned long long ullRxBroadcastBytes;
239 unsigned long long ullRxMulticastBytes;
240 unsigned long long ullRxDirectedBytes;
241 unsigned long long ullRxBroadcastFrames;
242 unsigned long long ullRxMulticastFrames;
243 unsigned long long ullRxDirectedFrames;
244
245 unsigned long dwRsrRxFragment;
246 unsigned long dwRsrRxFrmLen64;
247 unsigned long dwRsrRxFrmLen65_127;
248 unsigned long dwRsrRxFrmLen128_255;
249 unsigned long dwRsrRxFrmLen256_511;
250 unsigned long dwRsrRxFrmLen512_1023;
251 unsigned long dwRsrRxFrmLen1024_1518;
252
253 // TSR status count
254 //
255 unsigned long dwTsrTotalRetry[TYPE_MAXTD]; // total collision retry count
256 unsigned long dwTsrOnceRetry[TYPE_MAXTD]; // this packet only occur one collision
257 unsigned long dwTsrMoreThanOnceRetry[TYPE_MAXTD]; // this packet occur more than one collision
258 unsigned long dwTsrRetry[TYPE_MAXTD]; // this packet has ever occur collision,
259 // that is (dwTsrOnceCollision0 + dwTsrMoreThanOnceCollision0)
260 unsigned long dwTsrACKData[TYPE_MAXTD];
261 unsigned long dwTsrErr[TYPE_MAXTD];
262 unsigned long dwAllTsrOK[TYPE_MAXTD];
263 unsigned long dwTsrRetryTimeout[TYPE_MAXTD];
264 unsigned long dwTsrTransmitTimeout[TYPE_MAXTD];
265
266 unsigned long dwTsrTxPacket[TYPE_MAXTD];
267 unsigned long dwTsrTxOctet[TYPE_MAXTD];
268 unsigned long dwTsrBroadcast[TYPE_MAXTD];
269 unsigned long dwTsrMulticast[TYPE_MAXTD];
270 unsigned long dwTsrDirected[TYPE_MAXTD];
271
272 // RD/TD count
273 unsigned long dwCntRxFrmLength;
274 unsigned long dwCntTxBufLength;
275
276 unsigned char abyCntRxPattern[16];
277 unsigned char abyCntTxPattern[16];
278
279 // Software check....
280 unsigned long dwCntRxDataErr; // rx buffer data software compare CRC err count
281 unsigned long dwCntDecryptErr; // rx buffer data software compare CRC err count
282 unsigned long dwCntRxICVErr; // rx buffer data software compare CRC err count
283 unsigned int idxRxErrorDesc[TYPE_MAXRD]; // index for rx data error RD
284
285 // 64-bit OID
286 unsigned long long ullTsrOK[TYPE_MAXTD];
287
288 // for some optional OIDs (64 bits) and DMI support
289 unsigned long long ullTxBroadcastFrames[TYPE_MAXTD];
290 unsigned long long ullTxMulticastFrames[TYPE_MAXTD];
291 unsigned long long ullTxDirectedFrames[TYPE_MAXTD];
292 unsigned long long ullTxBroadcastBytes[TYPE_MAXTD];
293 unsigned long long ullTxMulticastBytes[TYPE_MAXTD];
294 unsigned long long ullTxDirectedBytes[TYPE_MAXTD];
295
296 SISRCounters ISRStat; 71 SISRCounters ISRStat;
297
298 SCustomCounters CustomStat;
299
300#ifdef Calcu_LinkQual
301 //Tx count:
302 unsigned long TxNoRetryOkCount;
303 unsigned long TxRetryOkCount;
304 unsigned long TxFailCount;
305 //Rx count:
306 unsigned long RxOkCnt;
307 unsigned long RxFcsErrCnt;
308 //statistic
309 unsigned long SignalStren;
310 unsigned long LinkQuality;
311#endif
312} SStatCounter, *PSStatCounter; 72} SStatCounter, *PSStatCounter;
313 73
314void STAvClearAllCounter(PSStatCounter pStatistic);
315
316void STAvUpdateIsrStatCounter(PSStatCounter pStatistic, unsigned long dwIsr); 74void STAvUpdateIsrStatCounter(PSStatCounter pStatistic, unsigned long dwIsr);
317 75
318void STAvUpdateRDStatCounter(PSStatCounter pStatistic,
319 unsigned char byRSR, unsigned char byNewRSR, unsigned char byRxRate,
320 unsigned char *pbyBuffer, unsigned int cbFrameLength);
321
322void STAvUpdateRDStatCounterEx(PSStatCounter pStatistic,
323 unsigned char byRSR, unsigned char byNewRsr, unsigned char byRxRate,
324 unsigned char *pbyBuffer, unsigned int cbFrameLength);
325
326void STAvUpdateTDStatCounter(PSStatCounter pStatistic, unsigned char byTSR0, unsigned char byTSR1,
327 unsigned char *pbyBuffer, unsigned int cbFrameLength, unsigned int uIdx);
328
329void STAvUpdateTDStatCounterEx(
330 PSStatCounter pStatistic,
331 unsigned char *pbyBuffer,
332 unsigned long cbFrameLength
333);
334
335void STAvUpdate802_11Counter( 76void STAvUpdate802_11Counter(
336 PSDot11Counters p802_11Counter, 77 PSDot11Counters p802_11Counter,
337 PSStatCounter pStatistic, 78 PSStatCounter pStatistic,
338 unsigned long dwCounter 79 unsigned long dwCounter
339); 80);
340 81
341void STAvClear802_11Counter(PSDot11Counters p802_11Counter);
342
343#endif // __MIB_H__ 82#endif // __MIB_H__
diff --git a/drivers/staging/vt6655/michael.c b/drivers/staging/vt6655/michael.c
deleted file mode 100644
index edee48777aac..000000000000
--- a/drivers/staging/vt6655/michael.c
+++ /dev/null
@@ -1,148 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: michael.cpp
21 *
22 * Purpose: The implementation of LIST data structure.
23 *
24 * Author: Kyle Hsu
25 *
26 * Date: Sep 4, 2002
27 *
28 * Functions:
29 * s_dwGetUINT32 - Convert from unsigned char [] to unsigned long in a portable way
30 * s_vPutUINT32 - Convert from unsigned long to unsigned char [] in a portable way
31 * s_vClear - Reset the state to the empty message.
32 * s_vSetKey - Set the key.
33 * MIC_vInit - Set the key.
34 * s_vAppendByte - Append the byte to our word-sized buffer.
35 * MIC_vAppend - call s_vAppendByte.
36 * MIC_vGetMIC - Append the minimum padding and call s_vAppendByte.
37 *
38 * Revision History:
39 *
40 */
41
42#include "tmacro.h"
43#include "michael.h"
44
45/*--------------------- Static Definitions -------------------------*/
46
47/*--------------------- Static Variables --------------------------*/
48
49/*--------------------- Static Functions --------------------------*/
50
51static void s_vClear(void); // Clear the internal message,
52// resets the object to the state just after construction.
53static void s_vSetKey(u32 dwK0, u32 dwK1);
54static void s_vAppendByte(unsigned char b); // Add a single byte to the internal message
55
56/*--------------------- Export Variables --------------------------*/
57static u32 L, R; /* Current state */
58
59static u32 K0, K1; /* Key */
60static u32 M; /* Message accumulator (single word) */
61static unsigned int nBytesInM; // # bytes in M
62
63/*--------------------- Export Functions --------------------------*/
64
65static void s_vClear(void)
66{
67 // Reset the state to the empty message.
68 L = K0;
69 R = K1;
70 nBytesInM = 0;
71 M = 0;
72}
73
74static void s_vSetKey(u32 dwK0, u32 dwK1)
75{
76 // Set the key
77 K0 = dwK0;
78 K1 = dwK1;
79 // and reset the message
80 s_vClear();
81}
82
83static void s_vAppendByte(unsigned char b)
84{
85 // Append the byte to our word-sized buffer
86 M |= b << (8*nBytesInM);
87 nBytesInM++;
88 // Process the word if it is full.
89 if (nBytesInM >= 4) {
90 L ^= M;
91 R ^= ROL32(L, 17);
92 L += R;
93 R ^= ((L & 0xff00ff00) >> 8) | ((L & 0x00ff00ff) << 8);
94 L += R;
95 R ^= ROL32(L, 3);
96 L += R;
97 R ^= ROR32(L, 2);
98 L += R;
99 // Clear the buffer
100 M = 0;
101 nBytesInM = 0;
102 }
103}
104
105void MIC_vInit(u32 dwK0, u32 dwK1)
106{
107 // Set the key
108 s_vSetKey(dwK0, dwK1);
109}
110
111void MIC_vUnInit(void)
112{
113 // Wipe the key material
114 K0 = 0;
115 K1 = 0;
116
117 // And the other fields as well.
118 //Note that this sets (L,R) to (K0,K1) which is just fine.
119 s_vClear();
120}
121
122void MIC_vAppend(unsigned char *src, unsigned int nBytes)
123{
124 // This is simple
125 while (nBytes > 0) {
126 s_vAppendByte(*src++);
127 nBytes--;
128 }
129}
130
131void MIC_vGetMIC(u32 *pdwL, u32 *pdwR)
132{
133 // Append the minimum padding
134 s_vAppendByte(0x5a);
135 s_vAppendByte(0);
136 s_vAppendByte(0);
137 s_vAppendByte(0);
138 s_vAppendByte(0);
139 // and then zeroes until the length is a multiple of 4
140 while (nBytesInM != 0)
141 s_vAppendByte(0);
142
143 // The s_vAppendByte function has already computed the result.
144 *pdwL = L;
145 *pdwR = R;
146 // Reset to the empty message.
147 s_vClear();
148}
diff --git a/drivers/staging/vt6655/michael.h b/drivers/staging/vt6655/michael.h
deleted file mode 100644
index 86cb140e3087..000000000000
--- a/drivers/staging/vt6655/michael.h
+++ /dev/null
@@ -1,52 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: Michael.h
21 *
22 * Purpose: Reference implementation for Michael
23 * written by Niels Ferguson
24 *
25 * Author: Kyle Hsu
26 *
27 * Date: Jan 2, 2003
28 *
29 */
30
31#ifndef __MICHAEL_H__
32#define __MICHAEL_H__
33
34#include <linux/types.h>
35
36void MIC_vInit(u32 dwK0, u32 dwK1);
37
38void MIC_vUnInit(void);
39
40/* Append bytes to the message to be MICed */
41void MIC_vAppend(unsigned char *src, unsigned int nBytes);
42
43/* Get the MIC result. Destination should accept 8 bytes of result. */
44/* This also resets the message to empty. */
45void MIC_vGetMIC(u32 *pdwL, u32 *pdwR);
46
47/* Rotation functions on 32 bit values */
48#define ROL32(A, n) \
49 (((A) << (n)) | (((A)>>(32-(n))) & ((1UL << (n)) - 1)))
50#define ROR32(A, n) ROL32((A), 32-(n))
51
52#endif /*__MICHAEL_H__ */
diff --git a/drivers/staging/vt6655/power.c b/drivers/staging/vt6655/power.c
index 08241b917777..e826f07e91c0 100644
--- a/drivers/staging/vt6655/power.c
+++ b/drivers/staging/vt6655/power.c
@@ -37,13 +37,9 @@
37 * 37 *
38 */ 38 */
39 39
40#include "ttype.h"
41#include "mac.h" 40#include "mac.h"
42#include "device.h" 41#include "device.h"
43#include "wmgr.h"
44#include "power.h" 42#include "power.h"
45#include "wcmd.h"
46#include "rxtx.h"
47#include "card.h" 43#include "card.h"
48 44
49/*--------------------- Static Definitions -------------------------*/ 45/*--------------------- Static Definitions -------------------------*/
@@ -73,8 +69,7 @@ PSvEnablePowerSaving(
73) 69)
74{ 70{
75 struct vnt_private *pDevice = hDeviceContext; 71 struct vnt_private *pDevice = hDeviceContext;
76 PSMgmtObject pMgmt = pDevice->pMgmt; 72 u16 wAID = pDevice->current_aid | BIT(14) | BIT(15);
77 unsigned short wAID = pMgmt->wCurrAID | BIT14 | BIT15;
78 73
79 // set period of power up before TBTT 74 // set period of power up before TBTT
80 VNSvOutPortW(pDevice->PortOffset + MAC_REG_PWBT, C_PWBT); 75 VNSvOutPortW(pDevice->PortOffset + MAC_REG_PWBT, C_PWBT);
@@ -83,7 +78,9 @@ PSvEnablePowerSaving(
83 VNSvOutPortW(pDevice->PortOffset + MAC_REG_AIDATIM, wAID); 78 VNSvOutPortW(pDevice->PortOffset + MAC_REG_AIDATIM, wAID);
84 } else { 79 } else {
85 // set ATIM Window 80 // set ATIM Window
81#if 0 /* TODO atim window */
86 MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow); 82 MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow);
83#endif
87 } 84 }
88 // Set AutoSleep 85 // Set AutoSleep
89 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP); 86 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
@@ -95,22 +92,15 @@ PSvEnablePowerSaving(
95 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN); 92 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
96 // first time set listen next beacon 93 // first time set listen next beacon
97 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN); 94 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN);
98 pMgmt->wCountToWakeUp = wListenInterval;
99 } else { 95 } else {
100 // always listen beacon 96 // always listen beacon
101 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN); 97 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
102 pMgmt->wCountToWakeUp = 0;
103 } 98 }
104 99
105 // enable power saving hw function 100 // enable power saving hw function
106 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN); 101 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
107 pDevice->bEnablePSMode = true; 102 pDevice->bEnablePSMode = true;
108 103
109 /* We don't send null pkt in ad hoc mode since beacon will handle this. */
110 if (pDevice->op_mode != NL80211_IFTYPE_ADHOC &&
111 pDevice->op_mode == NL80211_IFTYPE_STATION)
112 PSbSendNullPacket(pDevice);
113
114 pDevice->bPWBitOn = true; 104 pDevice->bPWBitOn = true;
115 pr_debug("PS:Power Saving Mode Enable...\n"); 105 pr_debug("PS:Power Saving Mode Enable...\n");
116} 106}
@@ -143,182 +133,9 @@ PSvDisablePowerSaving(
143 133
144 pDevice->bEnablePSMode = false; 134 pDevice->bEnablePSMode = false;
145 135
146 if (pDevice->op_mode == NL80211_IFTYPE_STATION)
147 PSbSendNullPacket(pDevice);
148
149 pDevice->bPWBitOn = false; 136 pDevice->bPWBitOn = false;
150} 137}
151 138
152/*+
153 *
154 * Routine Description:
155 * Consider to power down when no more packets to tx or rx.
156 *
157 * Return Value:
158 * true, if power down success
159 * false, if fail
160 -*/
161
162bool
163PSbConsiderPowerDown(
164 void *hDeviceContext,
165 bool bCheckRxDMA,
166 bool bCheckCountToWakeUp
167)
168{
169 struct vnt_private *pDevice = hDeviceContext;
170 PSMgmtObject pMgmt = pDevice->pMgmt;
171 unsigned int uIdx;
172
173 // check if already in Doze mode
174 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
175 return true;
176
177 if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
178 // check if in TIM wake period
179 if (pMgmt->bInTIMWake)
180 return false;
181 }
182
183 // check scan state
184 if (pDevice->bCmdRunning)
185 return false;
186
187 // Force PSEN on
188 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
189
190 // check if all TD are empty,
191 for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx++) {
192 if (pDevice->iTDUsed[uIdx] != 0)
193 return false;
194 }
195
196 // check if rx isr is clear
197 if (bCheckRxDMA &&
198 ((pDevice->dwIsr & ISR_RXDMA0) != 0) &&
199 ((pDevice->dwIsr & ISR_RXDMA1) != 0)) {
200 return false;
201 }
202
203 if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
204 if (bCheckCountToWakeUp &&
205 (pMgmt->wCountToWakeUp == 0 || pMgmt->wCountToWakeUp == 1)) {
206 return false;
207 }
208 }
209
210 // no Tx, no Rx isr, now go to Doze
211 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_GO2DOZE);
212 pr_debug("Go to Doze ZZZZZZZZZZZZZZZ\n");
213 return true;
214}
215
216/*+
217 *
218 * Routine Description:
219 * Send PS-POLL packet
220 *
221 * Return Value:
222 * None.
223 *
224 -*/
225
226void
227PSvSendPSPOLL(
228 void *hDeviceContext
229)
230{
231 struct vnt_private *pDevice = hDeviceContext;
232 PSMgmtObject pMgmt = pDevice->pMgmt;
233 PSTxMgmtPacket pTxPacket = NULL;
234
235 memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_HDR_ADDR2_LEN);
236 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool;
237 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
238 pTxPacket->p80211Header->sA2.wFrameCtl = cpu_to_le16(
239 (
240 WLAN_SET_FC_FTYPE(WLAN_TYPE_CTL) |
241 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PSPOLL) |
242 WLAN_SET_FC_PWRMGT(0)
243));
244 pTxPacket->p80211Header->sA2.wDurationID = pMgmt->wCurrAID | BIT14 | BIT15;
245 memcpy(pTxPacket->p80211Header->sA2.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
246 memcpy(pTxPacket->p80211Header->sA2.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
247 pTxPacket->cbMPDULen = WLAN_HDR_ADDR2_LEN;
248 pTxPacket->cbPayloadLen = 0;
249 // send the frame
250 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING)
251 pr_debug("Send PS-Poll packet failed..\n");
252}
253
254/*+
255 *
256 * Routine Description:
257 * Send NULL packet to AP for notification power state of STA
258 *
259 * Return Value:
260 * None.
261 *
262 -*/
263bool
264PSbSendNullPacket(
265 void *hDeviceContext
266)
267{
268 struct vnt_private *pDevice = hDeviceContext;
269 PSTxMgmtPacket pTxPacket = NULL;
270 PSMgmtObject pMgmt = pDevice->pMgmt;
271 unsigned int uIdx;
272
273 if (!pDevice->bLinkPass)
274 return false;
275
276 if (!pDevice->bEnablePSMode && !pDevice->fTxDataInSleep)
277 return false;
278
279 if (pDevice->bEnablePSMode) {
280 for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx++) {
281 if (pDevice->iTDUsed[uIdx] != 0)
282 return false;
283 }
284 }
285
286 memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_NULLDATA_FR_MAXLEN);
287 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool;
288 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
289
290 if (pDevice->bEnablePSMode) {
291 pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16(
292 (
293 WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) |
294 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL) |
295 WLAN_SET_FC_PWRMGT(1)
296));
297 } else {
298 pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16(
299 (
300 WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) |
301 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL) |
302 WLAN_SET_FC_PWRMGT(0)
303));
304 }
305
306 if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA)
307 pTxPacket->p80211Header->sA3.wFrameCtl |= cpu_to_le16((unsigned short)WLAN_SET_FC_TODS(1));
308
309 memcpy(pTxPacket->p80211Header->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
310 memcpy(pTxPacket->p80211Header->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
311 memcpy(pTxPacket->p80211Header->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
312 pTxPacket->cbMPDULen = WLAN_HDR_ADDR3_LEN;
313 pTxPacket->cbPayloadLen = 0;
314 // send the frame
315 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
316 pr_debug("Send Null Packet failed !\n");
317 return false;
318 }
319
320 return true;
321}
322 139
323/*+ 140/*+
324 * 141 *
@@ -336,21 +153,14 @@ PSbIsNextTBTTWakeUp(
336) 153)
337{ 154{
338 struct vnt_private *pDevice = hDeviceContext; 155 struct vnt_private *pDevice = hDeviceContext;
339 PSMgmtObject pMgmt = pDevice->pMgmt; 156 struct ieee80211_hw *hw = pDevice->hw;
157 struct ieee80211_conf *conf = &hw->conf;
340 bool bWakeUp = false; 158 bool bWakeUp = false;
341 159
342 if (pMgmt->wListenInterval >= 2) { 160 if (conf->listen_interval == 1) {
343 if (pMgmt->wCountToWakeUp == 0) 161 /* Turn on wake up to listen next beacon */
344 pMgmt->wCountToWakeUp = pMgmt->wListenInterval; 162 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN);
345 163 bWakeUp = true;
346 pMgmt->wCountToWakeUp--;
347
348 if (pMgmt->wCountToWakeUp == 1) {
349 // Turn on wake up to listen next beacon
350 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN);
351 bWakeUp = true;
352 }
353
354 } 164 }
355 165
356 return bWakeUp; 166 return bWakeUp;
diff --git a/drivers/staging/vt6655/power.h b/drivers/staging/vt6655/power.h
index 936f171a6b19..1083341b2a47 100644
--- a/drivers/staging/vt6655/power.h
+++ b/drivers/staging/vt6655/power.h
@@ -33,13 +33,6 @@
33#define PS_FAST_INTERVAL 1 // Fast power saving listen interval 33#define PS_FAST_INTERVAL 1 // Fast power saving listen interval
34#define PS_MAX_INTERVAL 4 // MAX power saving listen interval 34#define PS_MAX_INTERVAL 4 // MAX power saving listen interval
35 35
36bool
37PSbConsiderPowerDown(
38 void *hDeviceContext,
39 bool bCheckRxDMA,
40 bool bCheckCountToWakeUp
41);
42
43void 36void
44PSvDisablePowerSaving( 37PSvDisablePowerSaving(
45 void *hDeviceContext 38 void *hDeviceContext
@@ -51,15 +44,6 @@ PSvEnablePowerSaving(
51 unsigned short wListenInterval 44 unsigned short wListenInterval
52); 45);
53 46
54void
55PSvSendPSPOLL(
56 void *hDeviceContext
57);
58
59bool
60PSbSendNullPacket(
61 void *hDeviceContext
62);
63 47
64bool 48bool
65PSbIsNextTBTTWakeUp( 49PSbIsNextTBTTWakeUp(
diff --git a/drivers/staging/vt6655/rc4.c b/drivers/staging/vt6655/rc4.c
deleted file mode 100644
index b7819bc702de..000000000000
--- a/drivers/staging/vt6655/rc4.c
+++ /dev/null
@@ -1,88 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: rc4.c
20 *
21 * Purpose:
22 *
23 * Functions:
24 *
25 * Revision History:
26 *
27 * Author: Kyle Hsu
28 *
29 * Date: Sep 4, 2002
30 *
31 */
32
33#include "rc4.h"
34
35void rc4_init(PRC4Ext pRC4, unsigned char *pbyKey, unsigned int cbKey_len)
36{
37 unsigned int ust1, ust2;
38 unsigned int keyindex;
39 unsigned int stateindex;
40 unsigned char *pbyst;
41 unsigned int idx;
42
43 pbyst = pRC4->abystate;
44 pRC4->ux = 0;
45 pRC4->uy = 0;
46 for (idx = 0; idx < 256; idx++)
47 pbyst[idx] = (unsigned char)idx;
48 keyindex = 0;
49 stateindex = 0;
50 for (idx = 0; idx < 256; idx++) {
51 ust1 = pbyst[idx];
52 stateindex = (stateindex + pbyKey[keyindex] + ust1) & 0xff;
53 ust2 = pbyst[stateindex];
54 pbyst[stateindex] = (unsigned char)ust1;
55 pbyst[idx] = (unsigned char)ust2;
56 if (++keyindex >= cbKey_len)
57 keyindex = 0;
58 }
59}
60
61unsigned int rc4_byte(PRC4Ext pRC4)
62{
63 unsigned int ux;
64 unsigned int uy;
65 unsigned int ustx, usty;
66 unsigned char *pbyst;
67
68 pbyst = pRC4->abystate;
69 ux = (pRC4->ux + 1) & 0xff;
70 ustx = pbyst[ux];
71 uy = (ustx + pRC4->uy) & 0xff;
72 usty = pbyst[uy];
73 pRC4->ux = ux;
74 pRC4->uy = uy;
75 pbyst[uy] = (unsigned char)ustx;
76 pbyst[ux] = (unsigned char)usty;
77
78 return pbyst[(ustx + usty) & 0xff];
79}
80
81void rc4_encrypt(PRC4Ext pRC4, unsigned char *pbyDest,
82 unsigned char *pbySrc, unsigned int cbData_len)
83{
84 unsigned int ii;
85
86 for (ii = 0; ii < cbData_len; ii++)
87 pbyDest[ii] = (unsigned char)(pbySrc[ii] ^ rc4_byte(pRC4));
88}
diff --git a/drivers/staging/vt6655/rc4.h b/drivers/staging/vt6655/rc4.h
deleted file mode 100644
index 74b2eed9bce3..000000000000
--- a/drivers/staging/vt6655/rc4.h
+++ /dev/null
@@ -1,47 +0,0 @@
1/*
2 * File: rc4.h
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * Purpose:
19 *
20 * Functions:
21 *
22 * Revision History:
23 *
24 * Author: Kyle Hsu
25 *
26 * Date: Sep 4, 2002
27 *
28 */
29
30#ifndef __RC4_H__
31#define __RC4_H__
32
33#include "ttype.h"
34
35/*--------------------- Export Definitions -------------------------*/
36/*--------------------- Export Types ------------------------------*/
37typedef struct {
38 unsigned int ux;
39 unsigned int uy;
40 unsigned char abystate[256];
41} RC4Ext, *PRC4Ext;
42
43void rc4_init(PRC4Ext pRC4, unsigned char *pbyKey, unsigned int cbKey_len);
44unsigned int rc4_byte(PRC4Ext pRC4);
45void rc4_encrypt(PRC4Ext pRC4, unsigned char *pbyDest, unsigned char *pbySrc, unsigned int cbData_len);
46
47#endif //__RC4_H__
diff --git a/drivers/staging/vt6655/rf.c b/drivers/staging/vt6655/rf.c
index e505af91bfd0..32ef99341e20 100644
--- a/drivers/staging/vt6655/rf.c
+++ b/drivers/staging/vt6655/rf.c
@@ -29,6 +29,8 @@
29 * IFRFbWriteEmbedded - Embedded write RF register via MAC 29 * IFRFbWriteEmbedded - Embedded write RF register via MAC
30 * 30 *
31 * Revision History: 31 * Revision History:
32 * RobertYu 2005
33 * chester 2008
32 * 34 *
33 */ 35 */
34 36
@@ -37,8 +39,6 @@
37#include "rf.h" 39#include "rf.h"
38#include "baseband.h" 40#include "baseband.h"
39 41
40/*--------------------- Static Definitions -------------------------*/
41
42#define BY_AL2230_REG_LEN 23 //24bit 42#define BY_AL2230_REG_LEN 23 //24bit
43#define CB_AL2230_INIT_SEQ 15 43#define CB_AL2230_INIT_SEQ 15
44#define SWITCH_CHANNEL_DELAY_AL2230 200 //us 44#define SWITCH_CHANNEL_DELAY_AL2230 200 //us
@@ -49,10 +49,6 @@
49#define SWITCH_CHANNEL_DELAY_AL7230 200 //us 49#define SWITCH_CHANNEL_DELAY_AL7230 200 //us
50#define AL7230_PWR_IDX_LEN 64 50#define AL7230_PWR_IDX_LEN 64
51 51
52/*--------------------- Static Classes ----------------------------*/
53
54/*--------------------- Static Variables --------------------------*/
55
56static const unsigned long dwAL2230InitTable[CB_AL2230_INIT_SEQ] = { 52static const unsigned long dwAL2230InitTable[CB_AL2230_INIT_SEQ] = {
57 0x03F79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // 53 0x03F79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
58 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // 54 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
@@ -172,7 +168,6 @@ static unsigned long dwAL2230PowerTable[AL2230_PWR_IDX_LEN] = {
172 0x0407F900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW 168 0x0407F900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW
173}; 169};
174 170
175//{{ RobertYu:20050104
176// 40MHz reference frequency 171// 40MHz reference frequency
177// Need to Pull PLLON(PE3) low when writing channel registers through 3-wire. 172// Need to Pull PLLON(PE3) low when writing channel registers through 3-wire.
178static const unsigned long dwAL7230InitTable[CB_AL7230_INIT_SEQ] = { 173static const unsigned long dwAL7230InitTable[CB_AL7230_INIT_SEQ] = {
@@ -408,9 +403,6 @@ static const unsigned long dwAL7230ChannelTable2[CB_MAX_CHANNEL] = {
408 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 161, Tf = 5805MHz (55) 403 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 161, Tf = 5805MHz (55)
409 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW // channel = 165, Tf = 5825MHz (56) 404 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW // channel = 165, Tf = 5825MHz (56)
410}; 405};
411//}} RobertYu
412
413/*--------------------- Static Functions --------------------------*/
414 406
415/* 407/*
416 * Description: AIROHA IFRF chip init function 408 * Description: AIROHA IFRF chip init function
@@ -424,137 +416,81 @@ static const unsigned long dwAL7230ChannelTable2[CB_MAX_CHANNEL] = {
424 * Return Value: true if succeeded; false if failed. 416 * Return Value: true if succeeded; false if failed.
425 * 417 *
426 */ 418 */
427static bool s_bAL7230Init(void __iomem *dwIoBase) 419static bool s_bAL7230Init(struct vnt_private *priv)
428{ 420{
421 void __iomem *dwIoBase = priv->PortOffset;
429 int ii; 422 int ii;
430 bool bResult; 423 bool bResult;
431 424
432 bResult = true; 425 bResult = true;
433 426
434 //3-wire control for normal mode 427 /* 3-wire control for normal mode */
435 VNSvOutPortB(dwIoBase + MAC_REG_SOFTPWRCTL, 0); 428 VNSvOutPortB(dwIoBase + MAC_REG_SOFTPWRCTL, 0);
436 429
437 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPECTI | 430 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPECTI |
438 SOFTPWRCTL_TXPEINV)); 431 SOFTPWRCTL_TXPEINV));
439 BBvPowerSaveModeOFF(dwIoBase); //RobertYu:20050106, have DC value for Calibration 432 BBvPowerSaveModeOFF(priv); /* RobertYu:20050106, have DC value for Calibration */
440 433
441 for (ii = 0; ii < CB_AL7230_INIT_SEQ; ii++) 434 for (ii = 0; ii < CB_AL7230_INIT_SEQ; ii++)
442 bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[ii]); 435 bResult &= IFRFbWriteEmbedded(priv, dwAL7230InitTable[ii]);
443 436
444 // PLL On 437 /* PLL On */
445 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3); 438 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
446 439
447 //Calibration 440 /* Calibration */
448 MACvTimer0MicroSDelay(dwIoBase, 150);//150us 441 MACvTimer0MicroSDelay(dwIoBase, 150);//150us
449 bResult &= IFRFbWriteEmbedded(dwIoBase, (0x9ABA8F00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW)); //TXDCOC:active, RCK:disable 442 /* TXDCOC:active, RCK:disable */
443 bResult &= IFRFbWriteEmbedded(priv, (0x9ABA8F00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW));
450 MACvTimer0MicroSDelay(dwIoBase, 30);//30us 444 MACvTimer0MicroSDelay(dwIoBase, 30);//30us
451 bResult &= IFRFbWriteEmbedded(dwIoBase, (0x3ABA8F00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW)); //TXDCOC:disable, RCK:active 445 /* TXDCOC:disable, RCK:active */
446 bResult &= IFRFbWriteEmbedded(priv, (0x3ABA8F00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW));
452 MACvTimer0MicroSDelay(dwIoBase, 30);//30us 447 MACvTimer0MicroSDelay(dwIoBase, 30);//30us
453 bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[CB_AL7230_INIT_SEQ-1]); //TXDCOC:disable, RCK:disable 448 /* TXDCOC:disable, RCK:disable */
449 bResult &= IFRFbWriteEmbedded(priv, dwAL7230InitTable[CB_AL7230_INIT_SEQ-1]);
454 450
455 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE3 | 451 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE3 |
456 SOFTPWRCTL_SWPE2 | 452 SOFTPWRCTL_SWPE2 |
457 SOFTPWRCTL_SWPECTI | 453 SOFTPWRCTL_SWPECTI |
458 SOFTPWRCTL_TXPEINV)); 454 SOFTPWRCTL_TXPEINV));
459 455
460 BBvPowerSaveModeON(dwIoBase); // RobertYu:20050106 456 BBvPowerSaveModeON(priv); /* RobertYu:20050106 */
461 457
462 // PE1: TX_ON, PE2: RX_ON, PE3: PLLON 458 /* PE1: TX_ON, PE2: RX_ON, PE3: PLLON */
463 //3-wire control for power saving mode 459 /* 3-wire control for power saving mode */
464 VNSvOutPortB(dwIoBase + MAC_REG_PSPWRSIG, (PSSIG_WPE3 | PSSIG_WPE2)); //1100 0000 460 VNSvOutPortB(dwIoBase + MAC_REG_PSPWRSIG, (PSSIG_WPE3 | PSSIG_WPE2)); //1100 0000
465 461
466 return bResult; 462 return bResult;
467} 463}
468 464
469// Need to Pull PLLON low when writing channel registers through 3-wire interface 465/* Need to Pull PLLON low when writing channel registers through
470static bool s_bAL7230SelectChannel(void __iomem *dwIoBase, unsigned char byChannel) 466 * 3-wire interface */
467static bool s_bAL7230SelectChannel(struct vnt_private *priv, unsigned char byChannel)
471{ 468{
469 void __iomem *dwIoBase = priv->PortOffset;
472 bool bResult; 470 bool bResult;
473 471
474 bResult = true; 472 bResult = true;
475 473
476 // PLLON Off 474 /* PLLON Off */
477 MACvWordRegBitsOff(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3); 475 MACvWordRegBitsOff(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
478 476
479 bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230ChannelTable0[byChannel - 1]); //Reg0 477 bResult &= IFRFbWriteEmbedded(priv, dwAL7230ChannelTable0[byChannel - 1]);
480 bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230ChannelTable1[byChannel - 1]); //Reg1 478 bResult &= IFRFbWriteEmbedded(priv, dwAL7230ChannelTable1[byChannel - 1]);
481 bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230ChannelTable2[byChannel - 1]); //Reg4 479 bResult &= IFRFbWriteEmbedded(priv, dwAL7230ChannelTable2[byChannel - 1]);
482 480
483 // PLLOn On 481 /* PLLOn On */
484 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3); 482 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
485 483
486 // Set Channel[7] = 0 to tell H/W channel is changing now. 484 /* Set Channel[7] = 0 to tell H/W channel is changing now. */
487 VNSvOutPortB(dwIoBase + MAC_REG_CHANNEL, (byChannel & 0x7F)); 485 VNSvOutPortB(dwIoBase + MAC_REG_CHANNEL, (byChannel & 0x7F));
488 MACvTimer0MicroSDelay(dwIoBase, SWITCH_CHANNEL_DELAY_AL7230); 486 MACvTimer0MicroSDelay(dwIoBase, SWITCH_CHANNEL_DELAY_AL7230);
489 // Set Channel[7] = 1 to tell H/W channel change is done. 487 /* Set Channel[7] = 1 to tell H/W channel change is done. */
490 VNSvOutPortB(dwIoBase + MAC_REG_CHANNEL, (byChannel | 0x80)); 488 VNSvOutPortB(dwIoBase + MAC_REG_CHANNEL, (byChannel | 0x80));
491 489
492 return bResult; 490 return bResult;
493} 491}
494 492
495/* 493/*
496 * Description: Select channel with UW2452 chip
497 *
498 * Parameters:
499 * In:
500 * dwIoBase - I/O base address
501 * uChannel - Channel number
502 * Out:
503 * none
504 *
505 * Return Value: true if succeeded; false if failed.
506 *
507 */
508
509//{{ RobertYu: 20041210
510/*
511 * Description: UW2452 IFRF chip init function
512 *
513 * Parameters:
514 * In:
515 * dwIoBase - I/O base address
516 * Out:
517 * none
518 *
519 * Return Value: true if succeeded; false if failed.
520 *
521 */
522
523//}} RobertYu
524////////////////////////////////////////////////////////////////////////////////
525
526/*
527 * Description: VT3226 IFRF chip init function
528 *
529 * Parameters:
530 * In:
531 * dwIoBase - I/O base address
532 * Out:
533 * none
534 *
535 * Return Value: true if succeeded; false if failed.
536 *
537 */
538
539/*
540 * Description: Select channel with VT3226 chip
541 *
542 * Parameters:
543 * In:
544 * dwIoBase - I/O base address
545 * uChannel - Channel number
546 * Out:
547 * none
548 *
549 * Return Value: true if succeeded; false if failed.
550 *
551 */
552
553/*--------------------- Export Variables --------------------------*/
554
555/*--------------------- Export Functions --------------------------*/
556
557/*
558 * Description: Write to IF/RF, by embedded programming 494 * Description: Write to IF/RF, by embedded programming
559 * 495 *
560 * Parameters: 496 * Parameters:
@@ -567,14 +503,15 @@ static bool s_bAL7230SelectChannel(void __iomem *dwIoBase, unsigned char byChann
567 * Return Value: true if succeeded; false if failed. 503 * Return Value: true if succeeded; false if failed.
568 * 504 *
569 */ 505 */
570bool IFRFbWriteEmbedded(void __iomem *dwIoBase, unsigned long dwData) 506bool IFRFbWriteEmbedded(struct vnt_private *priv, unsigned long dwData)
571{ 507{
508 void __iomem *dwIoBase = priv->PortOffset;
572 unsigned short ww; 509 unsigned short ww;
573 unsigned long dwValue; 510 unsigned long dwValue;
574 511
575 VNSvOutPortD(dwIoBase + MAC_REG_IFREGCTL, dwData); 512 VNSvOutPortD(dwIoBase + MAC_REG_IFREGCTL, dwData);
576 513
577 // W_MAX_TIMEOUT is the timeout period 514 /* W_MAX_TIMEOUT is the timeout period */
578 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) { 515 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
579 VNSvInPortD(dwIoBase + MAC_REG_IFREGCTL, &dwValue); 516 VNSvInPortD(dwIoBase + MAC_REG_IFREGCTL, &dwValue);
580 if (dwValue & IFREGCTL_DONE) 517 if (dwValue & IFREGCTL_DONE)
@@ -588,33 +525,6 @@ bool IFRFbWriteEmbedded(void __iomem *dwIoBase, unsigned long dwData)
588} 525}
589 526
590/* 527/*
591 * Description: RFMD RF2959 IFRF chip init function
592 *
593 * Parameters:
594 * In:
595 * dwIoBase - I/O base address
596 * Out:
597 * none
598 *
599 * Return Value: true if succeeded; false if failed.
600 *
601 */
602
603/*
604 * Description: Select channel with RFMD 2959 chip
605 *
606 * Parameters:
607 * In:
608 * dwIoBase - I/O base address
609 * uChannel - Channel number
610 * Out:
611 * none
612 *
613 * Return Value: true if succeeded; false if failed.
614 *
615 */
616
617/*
618 * Description: AIROHA IFRF chip init function 528 * Description: AIROHA IFRF chip init function
619 * 529 *
620 * Parameters: 530 * Parameters:
@@ -626,113 +536,70 @@ bool IFRFbWriteEmbedded(void __iomem *dwIoBase, unsigned long dwData)
626 * Return Value: true if succeeded; false if failed. 536 * Return Value: true if succeeded; false if failed.
627 * 537 *
628 */ 538 */
629static bool RFbAL2230Init(void __iomem *dwIoBase) 539static bool RFbAL2230Init(struct vnt_private *priv)
630{ 540{
541 void __iomem *dwIoBase = priv->PortOffset;
631 int ii; 542 int ii;
632 bool bResult; 543 bool bResult;
633 544
634 bResult = true; 545 bResult = true;
635 546
636 //3-wire control for normal mode 547 /* 3-wire control for normal mode */
637 VNSvOutPortB(dwIoBase + MAC_REG_SOFTPWRCTL, 0); 548 VNSvOutPortB(dwIoBase + MAC_REG_SOFTPWRCTL, 0);
638 549
639 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPECTI | 550 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPECTI |
640 SOFTPWRCTL_TXPEINV)); 551 SOFTPWRCTL_TXPEINV));
641//2008-8-21 chester <add> 552 /* PLL Off */
642 // PLL Off
643
644 MACvWordRegBitsOff(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3); 553 MACvWordRegBitsOff(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
645 554
646 //patch abnormal AL2230 frequency output 555 /* patch abnormal AL2230 frequency output */
647//2008-8-21 chester <add> 556 IFRFbWriteEmbedded(priv, (0x07168700+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW));
648 IFRFbWriteEmbedded(dwIoBase, (0x07168700+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW));
649 557
650 for (ii = 0; ii < CB_AL2230_INIT_SEQ; ii++) 558 for (ii = 0; ii < CB_AL2230_INIT_SEQ; ii++)
651 bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL2230InitTable[ii]); 559 bResult &= IFRFbWriteEmbedded(priv, dwAL2230InitTable[ii]);
652//2008-8-21 chester <add>
653 MACvTimer0MicroSDelay(dwIoBase, 30); //delay 30 us 560 MACvTimer0MicroSDelay(dwIoBase, 30); //delay 30 us
654 561
655 // PLL On 562 /* PLL On */
656 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3); 563 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
657 564
658 MACvTimer0MicroSDelay(dwIoBase, 150);//150us 565 MACvTimer0MicroSDelay(dwIoBase, 150);//150us
659 bResult &= IFRFbWriteEmbedded(dwIoBase, (0x00d80f00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW)); 566 bResult &= IFRFbWriteEmbedded(priv, (0x00d80f00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW));
660 MACvTimer0MicroSDelay(dwIoBase, 30);//30us 567 MACvTimer0MicroSDelay(dwIoBase, 30);//30us
661 bResult &= IFRFbWriteEmbedded(dwIoBase, (0x00780f00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW)); 568 bResult &= IFRFbWriteEmbedded(priv, (0x00780f00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW));
662 MACvTimer0MicroSDelay(dwIoBase, 30);//30us 569 MACvTimer0MicroSDelay(dwIoBase, 30);//30us
663 bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL2230InitTable[CB_AL2230_INIT_SEQ-1]); 570 bResult &= IFRFbWriteEmbedded(priv, dwAL2230InitTable[CB_AL2230_INIT_SEQ-1]);
664 571
665 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE3 | 572 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE3 |
666 SOFTPWRCTL_SWPE2 | 573 SOFTPWRCTL_SWPE2 |
667 SOFTPWRCTL_SWPECTI | 574 SOFTPWRCTL_SWPECTI |
668 SOFTPWRCTL_TXPEINV)); 575 SOFTPWRCTL_TXPEINV));
669 576
670 //3-wire control for power saving mode 577 /* 3-wire control for power saving mode */
671 VNSvOutPortB(dwIoBase + MAC_REG_PSPWRSIG, (PSSIG_WPE3 | PSSIG_WPE2)); //1100 0000 578 VNSvOutPortB(dwIoBase + MAC_REG_PSPWRSIG, (PSSIG_WPE3 | PSSIG_WPE2)); //1100 0000
672 579
673 return bResult; 580 return bResult;
674} 581}
675 582
676static bool RFbAL2230SelectChannel(void __iomem *dwIoBase, unsigned char byChannel) 583static bool RFbAL2230SelectChannel(struct vnt_private *priv, unsigned char byChannel)
677{ 584{
585 void __iomem *dwIoBase = priv->PortOffset;
678 bool bResult; 586 bool bResult;
679 587
680 bResult = true; 588 bResult = true;
681 589
682 bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL2230ChannelTable0[byChannel - 1]); 590 bResult &= IFRFbWriteEmbedded(priv, dwAL2230ChannelTable0[byChannel - 1]);
683 bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL2230ChannelTable1[byChannel - 1]); 591 bResult &= IFRFbWriteEmbedded(priv, dwAL2230ChannelTable1[byChannel - 1]);
684 592
685 // Set Channel[7] = 0 to tell H/W channel is changing now. 593 /* Set Channel[7] = 0 to tell H/W channel is changing now. */
686 VNSvOutPortB(dwIoBase + MAC_REG_CHANNEL, (byChannel & 0x7F)); 594 VNSvOutPortB(dwIoBase + MAC_REG_CHANNEL, (byChannel & 0x7F));
687 MACvTimer0MicroSDelay(dwIoBase, SWITCH_CHANNEL_DELAY_AL2230); 595 MACvTimer0MicroSDelay(dwIoBase, SWITCH_CHANNEL_DELAY_AL2230);
688 // Set Channel[7] = 1 to tell H/W channel change is done. 596 /* Set Channel[7] = 1 to tell H/W channel change is done. */
689 VNSvOutPortB(dwIoBase + MAC_REG_CHANNEL, (byChannel | 0x80)); 597 VNSvOutPortB(dwIoBase + MAC_REG_CHANNEL, (byChannel | 0x80));
690 598
691 return bResult; 599 return bResult;
692} 600}
693 601
694/* 602/*
695 * Description: UW2451 IFRF chip init function
696 *
697 * Parameters:
698 * In:
699 * dwIoBase - I/O base address
700 * Out:
701 * none
702 *
703 * Return Value: true if succeeded; false if failed.
704 *
705 */
706
707/*
708 * Description: Select channel with UW2451 chip
709 *
710 * Parameters:
711 * In:
712 * dwIoBase - I/O base address
713 * uChannel - Channel number
714 * Out:
715 * none
716 *
717 * Return Value: true if succeeded; false if failed.
718 *
719 */
720
721/*
722 * Description: Set sleep mode to UW2451 chip
723 *
724 * Parameters:
725 * In:
726 * dwIoBase - I/O base address
727 * uChannel - Channel number
728 * Out:
729 * none
730 *
731 * Return Value: true if succeeded; false if failed.
732 *
733 */
734
735/*
736 * Description: RF init function 603 * Description: RF init function
737 * 604 *
738 * Parameters: 605 * Parameters:
@@ -746,20 +613,20 @@ static bool RFbAL2230SelectChannel(void __iomem *dwIoBase, unsigned char byChann
746 * 613 *
747 */ 614 */
748bool RFbInit( 615bool RFbInit(
749 struct vnt_private *pDevice 616 struct vnt_private *priv
750) 617)
751{ 618{
752 bool bResult = true; 619 bool bResult = true;
753 620
754 switch (pDevice->byRFType) { 621 switch (priv->byRFType) {
755 case RF_AIROHA: 622 case RF_AIROHA:
756 case RF_AL2230S: 623 case RF_AL2230S:
757 pDevice->byMaxPwrLevel = AL2230_PWR_IDX_LEN; 624 priv->byMaxPwrLevel = AL2230_PWR_IDX_LEN;
758 bResult = RFbAL2230Init(pDevice->PortOffset); 625 bResult = RFbAL2230Init(priv);
759 break; 626 break;
760 case RF_AIROHA7230: 627 case RF_AIROHA7230:
761 pDevice->byMaxPwrLevel = AL7230_PWR_IDX_LEN; 628 priv->byMaxPwrLevel = AL7230_PWR_IDX_LEN;
762 bResult = s_bAL7230Init(pDevice->PortOffset); 629 bResult = s_bAL7230Init(priv);
763 break; 630 break;
764 case RF_NOTHING: 631 case RF_NOTHING:
765 bResult = true; 632 bResult = true;
@@ -784,18 +651,18 @@ bool RFbInit(
784 * Return Value: true if succeeded; false if failed. 651 * Return Value: true if succeeded; false if failed.
785 * 652 *
786 */ 653 */
787bool RFbSelectChannel(void __iomem *dwIoBase, unsigned char byRFType, unsigned char byChannel) 654bool RFbSelectChannel(struct vnt_private *priv, unsigned char byRFType, unsigned char byChannel)
788{ 655{
789 bool bResult = true; 656 bool bResult = true;
790 657
791 switch (byRFType) { 658 switch (byRFType) {
792 case RF_AIROHA: 659 case RF_AIROHA:
793 case RF_AL2230S: 660 case RF_AL2230S:
794 bResult = RFbAL2230SelectChannel(dwIoBase, byChannel); 661 bResult = RFbAL2230SelectChannel(priv, byChannel);
795 break; 662 break;
796 //{{ RobertYu: 20050104 663 //{{ RobertYu: 20050104
797 case RF_AIROHA7230: 664 case RF_AIROHA7230:
798 bResult = s_bAL7230SelectChannel(dwIoBase, byChannel); 665 bResult = s_bAL7230SelectChannel(priv, byChannel);
799 break; 666 break;
800 //}} RobertYu 667 //}} RobertYu
801 case RF_NOTHING: 668 case RF_NOTHING:
@@ -820,8 +687,9 @@ bool RFbSelectChannel(void __iomem *dwIoBase, unsigned char byRFType, unsigned c
820 * Return Value: None. 687 * Return Value: None.
821 * 688 *
822 */ 689 */
823bool RFvWriteWakeProgSyn(void __iomem *dwIoBase, unsigned char byRFType, unsigned int uChannel) 690bool RFvWriteWakeProgSyn(struct vnt_private *priv, unsigned char byRFType, unsigned int uChannel)
824{ 691{
692 void __iomem *dwIoBase = priv->PortOffset;
825 int ii; 693 int ii;
826 unsigned char byInitCount = 0; 694 unsigned char byInitCount = 0;
827 unsigned char bySleepCount = 0; 695 unsigned char bySleepCount = 0;
@@ -834,7 +702,8 @@ bool RFvWriteWakeProgSyn(void __iomem *dwIoBase, unsigned char byRFType, unsigne
834 if (uChannel > CB_MAX_CHANNEL_24G) 702 if (uChannel > CB_MAX_CHANNEL_24G)
835 return false; 703 return false;
836 704
837 byInitCount = CB_AL2230_INIT_SEQ + 2; // Init Reg + Channel Reg (2) 705 /* Init Reg + Channel Reg (2) */
706 byInitCount = CB_AL2230_INIT_SEQ + 2;
838 bySleepCount = 0; 707 bySleepCount = 0;
839 if (byInitCount > (MISCFIFO_SYNDATASIZE - bySleepCount)) 708 if (byInitCount > (MISCFIFO_SYNDATASIZE - bySleepCount))
840 return false; 709 return false;
@@ -847,10 +716,10 @@ bool RFvWriteWakeProgSyn(void __iomem *dwIoBase, unsigned char byRFType, unsigne
847 MACvSetMISCFifo(dwIoBase, (unsigned short)(MISCFIFO_SYNDATA_IDX + ii), dwAL2230ChannelTable1[uChannel-1]); 716 MACvSetMISCFifo(dwIoBase, (unsigned short)(MISCFIFO_SYNDATA_IDX + ii), dwAL2230ChannelTable1[uChannel-1]);
848 break; 717 break;
849 718
850 //{{ RobertYu: 20050104 719 /* Need to check, PLLON need to be low for channel setting */
851 // Need to check, PLLON need to be low for channel setting
852 case RF_AIROHA7230: 720 case RF_AIROHA7230:
853 byInitCount = CB_AL7230_INIT_SEQ + 3; // Init Reg + Channel Reg (3) 721 /* Init Reg + Channel Reg (3) */
722 byInitCount = CB_AL7230_INIT_SEQ + 3;
854 bySleepCount = 0; 723 bySleepCount = 0;
855 if (byInitCount > (MISCFIFO_SYNDATASIZE - bySleepCount)) 724 if (byInitCount > (MISCFIFO_SYNDATASIZE - bySleepCount))
856 return false; 725 return false;
@@ -869,7 +738,6 @@ bool RFvWriteWakeProgSyn(void __iomem *dwIoBase, unsigned char byRFType, unsigne
869 ii++; 738 ii++;
870 MACvSetMISCFifo(dwIoBase, (unsigned short)(MISCFIFO_SYNDATA_IDX + ii), dwAL7230ChannelTable2[uChannel-1]); 739 MACvSetMISCFifo(dwIoBase, (unsigned short)(MISCFIFO_SYNDATA_IDX + ii), dwAL7230ChannelTable2[uChannel-1]);
871 break; 740 break;
872 //}} RobertYu
873 741
874 case RF_NOTHING: 742 case RF_NOTHING:
875 return true; 743 return true;
@@ -897,7 +765,7 @@ bool RFvWriteWakeProgSyn(void __iomem *dwIoBase, unsigned char byRFType, unsigne
897 * 765 *
898 */ 766 */
899bool RFbSetPower( 767bool RFbSetPower(
900 struct vnt_private *pDevice, 768 struct vnt_private *priv,
901 unsigned int uRATE, 769 unsigned int uRATE,
902 unsigned int uCH 770 unsigned int uCH
903) 771)
@@ -907,7 +775,7 @@ bool RFbSetPower(
907 unsigned char byDec = 0; 775 unsigned char byDec = 0;
908 unsigned char byPwrdBm = 0; 776 unsigned char byPwrdBm = 0;
909 777
910 if (pDevice->dwDiagRefCount != 0) 778 if (priv->dwDiagRefCount != 0)
911 return true; 779 return true;
912 780
913 if ((uCH < 1) || (uCH > CB_MAX_CHANNEL)) 781 if ((uCH < 1) || (uCH > CB_MAX_CHANNEL))
@@ -918,22 +786,22 @@ bool RFbSetPower(
918 case RATE_2M: 786 case RATE_2M:
919 case RATE_5M: 787 case RATE_5M:
920 case RATE_11M: 788 case RATE_11M:
921 byPwr = pDevice->abyCCKPwrTbl[uCH]; 789 byPwr = priv->abyCCKPwrTbl[uCH];
922 byPwrdBm = pDevice->abyCCKDefaultPwr[uCH]; 790 byPwrdBm = priv->abyCCKDefaultPwr[uCH];
923 break; 791 break;
924 case RATE_6M: 792 case RATE_6M:
925 case RATE_9M: 793 case RATE_9M:
926 case RATE_18M: 794 case RATE_18M:
927 byPwr = pDevice->abyOFDMPwrTbl[uCH]; 795 byPwr = priv->abyOFDMPwrTbl[uCH];
928 if (pDevice->byRFType == RF_UW2452) 796 if (priv->byRFType == RF_UW2452)
929 byDec = byPwr + 14; 797 byDec = byPwr + 14;
930 else 798 else
931 byDec = byPwr + 10; 799 byDec = byPwr + 10;
932 800
933 if (byDec >= pDevice->byMaxPwrLevel) 801 if (byDec >= priv->byMaxPwrLevel)
934 byDec = pDevice->byMaxPwrLevel-1; 802 byDec = priv->byMaxPwrLevel-1;
935 803
936 if (pDevice->byRFType == RF_UW2452) { 804 if (priv->byRFType == RF_UW2452) {
937 byPwrdBm = byDec - byPwr; 805 byPwrdBm = byDec - byPwr;
938 byPwrdBm /= 3; 806 byPwrdBm /= 3;
939 } else { 807 } else {
@@ -941,24 +809,24 @@ bool RFbSetPower(
941 byPwrdBm >>= 1; 809 byPwrdBm >>= 1;
942 } 810 }
943 811
944 byPwrdBm += pDevice->abyOFDMDefaultPwr[uCH]; 812 byPwrdBm += priv->abyOFDMDefaultPwr[uCH];
945 byPwr = byDec; 813 byPwr = byDec;
946 break; 814 break;
947 case RATE_24M: 815 case RATE_24M:
948 case RATE_36M: 816 case RATE_36M:
949 case RATE_48M: 817 case RATE_48M:
950 case RATE_54M: 818 case RATE_54M:
951 byPwr = pDevice->abyOFDMPwrTbl[uCH]; 819 byPwr = priv->abyOFDMPwrTbl[uCH];
952 byPwrdBm = pDevice->abyOFDMDefaultPwr[uCH]; 820 byPwrdBm = priv->abyOFDMDefaultPwr[uCH];
953 break; 821 break;
954 } 822 }
955 823
956 if (pDevice->byCurPwr == byPwr) 824 if (priv->byCurPwr == byPwr)
957 return true; 825 return true;
958 826
959 bResult = RFbRawSetPower(pDevice, byPwr, uRATE); 827 bResult = RFbRawSetPower(priv, byPwr, uRATE);
960 if (bResult) 828 if (bResult)
961 pDevice->byCurPwr = byPwr; 829 priv->byCurPwr = byPwr;
962 830
963 return bResult; 831 return bResult;
964} 832}
@@ -978,7 +846,7 @@ bool RFbSetPower(
978 */ 846 */
979 847
980bool RFbRawSetPower( 848bool RFbRawSetPower(
981 struct vnt_private *pDevice, 849 struct vnt_private *priv,
982 unsigned char byPwr, 850 unsigned char byPwr,
983 unsigned int uRATE 851 unsigned int uRATE
984) 852)
@@ -986,37 +854,38 @@ bool RFbRawSetPower(
986 bool bResult = true; 854 bool bResult = true;
987 unsigned long dwMax7230Pwr = 0; 855 unsigned long dwMax7230Pwr = 0;
988 856
989 if (byPwr >= pDevice->byMaxPwrLevel) 857 if (byPwr >= priv->byMaxPwrLevel)
990 return false; 858 return false;
991 859
992 switch (pDevice->byRFType) { 860 switch (priv->byRFType) {
993 case RF_AIROHA: 861 case RF_AIROHA:
994 bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, dwAL2230PowerTable[byPwr]); 862 bResult &= IFRFbWriteEmbedded(priv, dwAL2230PowerTable[byPwr]);
995 if (uRATE <= RATE_11M) 863 if (uRATE <= RATE_11M)
996 bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, 0x0001B400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW); 864 bResult &= IFRFbWriteEmbedded(priv, 0x0001B400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
997 else 865 else
998 bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, 0x0005A400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW); 866 bResult &= IFRFbWriteEmbedded(priv, 0x0005A400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
999 867
1000 break; 868 break;
1001 869
1002 case RF_AL2230S: 870 case RF_AL2230S:
1003 bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, dwAL2230PowerTable[byPwr]); 871 bResult &= IFRFbWriteEmbedded(priv, dwAL2230PowerTable[byPwr]);
1004 if (uRATE <= RATE_11M) { 872 if (uRATE <= RATE_11M) {
1005 bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, 0x040C1400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW); 873 bResult &= IFRFbWriteEmbedded(priv, 0x040C1400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
1006 bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, 0x00299B00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW); 874 bResult &= IFRFbWriteEmbedded(priv, 0x00299B00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
1007 } else { 875 } else {
1008 bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, 0x0005A400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW); 876 bResult &= IFRFbWriteEmbedded(priv, 0x0005A400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
1009 bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, 0x00099B00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW); 877 bResult &= IFRFbWriteEmbedded(priv, 0x00099B00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
1010 } 878 }
1011 879
1012 break; 880 break;
1013 881
1014 case RF_AIROHA7230: 882 case RF_AIROHA7230:
1015 // 0x080F1B00 for 3 wire control TxGain(D10) and 0x31 as TX Gain value 883 /* 0x080F1B00 for 3 wire control TxGain(D10)
884 * and 0x31 as TX Gain value */
1016 dwMax7230Pwr = 0x080C0B00 | ((byPwr) << 12) | 885 dwMax7230Pwr = 0x080C0B00 | ((byPwr) << 12) |
1017 (BY_AL7230_REG_LEN << 3) | IFREGCTL_REGW; 886 (BY_AL7230_REG_LEN << 3) | IFREGCTL_REGW;
1018 887
1019 bResult &= IFRFbWriteEmbedded(pDevice->PortOffset, dwMax7230Pwr); 888 bResult &= IFRFbWriteEmbedded(priv, dwMax7230Pwr);
1020 break; 889 break;
1021 890
1022 default: 891 default:
@@ -1032,7 +901,7 @@ bool RFbRawSetPower(
1032 * 901 *
1033 * Parameters: 902 * Parameters:
1034 * In: 903 * In:
1035 * pDevice - The adapter to be translated 904 * priv - The adapter to be translated
1036 * byCurrRSSI - RSSI to be translated 905 * byCurrRSSI - RSSI to be translated
1037 * Out: 906 * Out:
1038 * pdwdbm - Translated dbm number 907 * pdwdbm - Translated dbm number
@@ -1042,7 +911,7 @@ bool RFbRawSetPower(
1042 -*/ 911 -*/
1043void 912void
1044RFvRSSITodBm( 913RFvRSSITodBm(
1045 struct vnt_private *pDevice, 914 struct vnt_private *priv,
1046 unsigned char byCurrRSSI, 915 unsigned char byCurrRSSI,
1047 long *pldBm 916 long *pldBm
1048 ) 917 )
@@ -1052,10 +921,10 @@ RFvRSSITodBm(
1052 long a = 0; 921 long a = 0;
1053 unsigned char abyAIROHARF[4] = {0, 18, 0, 40}; 922 unsigned char abyAIROHARF[4] = {0, 18, 0, 40};
1054 923
1055 switch (pDevice->byRFType) { 924 switch (priv->byRFType) {
1056 case RF_AIROHA: 925 case RF_AIROHA:
1057 case RF_AL2230S: 926 case RF_AL2230S:
1058 case RF_AIROHA7230: //RobertYu: 20040104 927 case RF_AIROHA7230:
1059 a = abyAIROHARF[byIdx]; 928 a = abyAIROHARF[byIdx];
1060 break; 929 break;
1061 default: 930 default:
@@ -1065,42 +934,38 @@ RFvRSSITodBm(
1065 *pldBm = -1 * (a + b * 2); 934 *pldBm = -1 * (a + b * 2);
1066} 935}
1067 936
1068//////////////////////////////////////////////////////////////////////////////// 937/* Post processing for the 11b/g and 11a.
1069//{{ RobertYu: 20050104 938 * for save time on changing Reg2,3,5,7,10,12,15 */
1070 939bool RFbAL7230SelectChannelPostProcess(struct vnt_private *priv,
1071// Post processing for the 11b/g and 11a. 940 unsigned char byOldChannel,
1072// for save time on changing Reg2,3,5,7,10,12,15 941 unsigned char byNewChannel)
1073bool RFbAL7230SelectChannelPostProcess(void __iomem *dwIoBase, unsigned char byOldChannel, unsigned char byNewChannel)
1074{ 942{
1075 bool bResult; 943 bool bResult;
1076 944
1077 bResult = true; 945 bResult = true;
1078 946
1079 // if change between 11 b/g and 11a need to update the following register 947 /* if change between 11 b/g and 11a need to update the following
1080 // Channel Index 1~14 948 * register
1081 949 * Channel Index 1~14 */
1082 if ((byOldChannel <= CB_MAX_CHANNEL_24G) && (byNewChannel > CB_MAX_CHANNEL_24G)) { 950 if ((byOldChannel <= CB_MAX_CHANNEL_24G) && (byNewChannel > CB_MAX_CHANNEL_24G)) {
1083 // Change from 2.4G to 5G 951 /* Change from 2.4G to 5G [Reg] */
1084 bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTableAMode[2]); //Reg2 952 bResult &= IFRFbWriteEmbedded(priv, dwAL7230InitTableAMode[2]);
1085 bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTableAMode[3]); //Reg3 953 bResult &= IFRFbWriteEmbedded(priv, dwAL7230InitTableAMode[3]);
1086 bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTableAMode[5]); //Reg5 954 bResult &= IFRFbWriteEmbedded(priv, dwAL7230InitTableAMode[5]);
1087 bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTableAMode[7]); //Reg7 955 bResult &= IFRFbWriteEmbedded(priv, dwAL7230InitTableAMode[7]);
1088 bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTableAMode[10]);//Reg10 956 bResult &= IFRFbWriteEmbedded(priv, dwAL7230InitTableAMode[10]);
1089 bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTableAMode[12]);//Reg12 957 bResult &= IFRFbWriteEmbedded(priv, dwAL7230InitTableAMode[12]);
1090 bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTableAMode[15]);//Reg15 958 bResult &= IFRFbWriteEmbedded(priv, dwAL7230InitTableAMode[15]);
1091 } else if ((byOldChannel > CB_MAX_CHANNEL_24G) && (byNewChannel <= CB_MAX_CHANNEL_24G)) { 959 } else if ((byOldChannel > CB_MAX_CHANNEL_24G) && (byNewChannel <= CB_MAX_CHANNEL_24G)) {
1092 // change from 5G to 2.4G 960 /* Change from 5G to 2.4G [Reg] */
1093 bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[2]); //Reg2 961 bResult &= IFRFbWriteEmbedded(priv, dwAL7230InitTable[2]);
1094 bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[3]); //Reg3 962 bResult &= IFRFbWriteEmbedded(priv, dwAL7230InitTable[3]);
1095 bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[5]); //Reg5 963 bResult &= IFRFbWriteEmbedded(priv, dwAL7230InitTable[5]);
1096 bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[7]); //Reg7 964 bResult &= IFRFbWriteEmbedded(priv, dwAL7230InitTable[7]);
1097 bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[10]);//Reg10 965 bResult &= IFRFbWriteEmbedded(priv, dwAL7230InitTable[10]);
1098 bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[12]);//Reg12 966 bResult &= IFRFbWriteEmbedded(priv, dwAL7230InitTable[12]);
1099 bResult &= IFRFbWriteEmbedded(dwIoBase, dwAL7230InitTable[15]);//Reg15 967 bResult &= IFRFbWriteEmbedded(priv, dwAL7230InitTable[15]);
1100 } 968 }
1101 969
1102 return bResult; 970 return bResult;
1103} 971}
1104
1105//}} RobertYu
1106////////////////////////////////////////////////////////////////////////////////
diff --git a/drivers/staging/vt6655/rf.h b/drivers/staging/vt6655/rf.h
index be4ef88b7666..8a6e2cfedaa5 100644
--- a/drivers/staging/vt6655/rf.h
+++ b/drivers/staging/vt6655/rf.h
@@ -30,7 +30,6 @@
30#ifndef __RF_H__ 30#ifndef __RF_H__
31#define __RF_H__ 31#define __RF_H__
32 32
33#include "ttype.h"
34#include "device.h" 33#include "device.h"
35 34
36/*--------------------- Export Definitions -------------------------*/ 35/*--------------------- Export Definitions -------------------------*/
@@ -74,12 +73,12 @@
74 73
75/*--------------------- Export Functions --------------------------*/ 74/*--------------------- Export Functions --------------------------*/
76 75
77bool IFRFbWriteEmbedded(void __iomem *dwIoBase, unsigned long dwData); 76bool IFRFbWriteEmbedded(struct vnt_private *, unsigned long dwData);
78bool RFbSelectChannel(void __iomem *dwIoBase, unsigned char byRFType, unsigned char byChannel); 77bool RFbSelectChannel(struct vnt_private *, unsigned char byRFType, unsigned char byChannel);
79bool RFbInit( 78bool RFbInit(
80 struct vnt_private * 79 struct vnt_private *
81); 80);
82bool RFvWriteWakeProgSyn(void __iomem *dwIoBase, unsigned char byRFType, unsigned int uChannel); 81bool RFvWriteWakeProgSyn(struct vnt_private *, unsigned char byRFType, unsigned int uChannel);
83bool RFbSetPower(struct vnt_private *, unsigned int uRATE, unsigned int uCH); 82bool RFbSetPower(struct vnt_private *, unsigned int uRATE, unsigned int uCH);
84bool RFbRawSetPower( 83bool RFbRawSetPower(
85 struct vnt_private *, 84 struct vnt_private *,
@@ -95,7 +94,7 @@ RFvRSSITodBm(
95); 94);
96 95
97//{{ RobertYu: 20050104 96//{{ RobertYu: 20050104
98bool RFbAL7230SelectChannelPostProcess(void __iomem *dwIoBase, unsigned char byOldChannel, unsigned char byNewChannel); 97bool RFbAL7230SelectChannelPostProcess(struct vnt_private *, unsigned char byOldChannel, unsigned char byNewChannel);
99//}} RobertYu 98//}} RobertYu
100 99
101#endif // __RF_H__ 100#endif // __RF_H__
diff --git a/drivers/staging/vt6655/rxtx.c b/drivers/staging/vt6655/rxtx.c
index 7a183f55e7eb..61c39dd7ad01 100644
--- a/drivers/staging/vt6655/rxtx.c
+++ b/drivers/staging/vt6655/rxtx.c
@@ -50,17 +50,9 @@
50 50
51#include "device.h" 51#include "device.h"
52#include "rxtx.h" 52#include "rxtx.h"
53#include "tether.h"
54#include "card.h" 53#include "card.h"
55#include "bssdb.h"
56#include "mac.h" 54#include "mac.h"
57#include "baseband.h" 55#include "baseband.h"
58#include "michael.h"
59#include "tkip.h"
60#include "tcrc.h"
61#include "wctl.h"
62#include "wroute.h"
63#include "hostap.h"
64#include "rf.h" 56#include "rf.h"
65 57
66/*--------------------- Static Definitions -------------------------*/ 58/*--------------------- Static Definitions -------------------------*/
@@ -105,19 +97,6 @@ static const unsigned short wFB_Opt1[2][5] = {
105#define DATADUR_A_F1 13 97#define DATADUR_A_F1 13
106 98
107/*--------------------- Static Functions --------------------------*/ 99/*--------------------- Static Functions --------------------------*/
108
109static
110void
111s_vFillTxKey(
112 struct vnt_private *pDevice,
113 unsigned char *pbyBuf,
114 unsigned char *pbyIVHead,
115 PSKeyItem pTransmitKey,
116 unsigned char *pbyHdrBuf,
117 unsigned short wPayloadLen,
118 unsigned char *pMICHDR
119);
120
121static 100static
122void 101void
123s_vFillRTSHead( 102s_vFillRTSHead(
@@ -127,7 +106,7 @@ s_vFillRTSHead(
127 unsigned int cbFrameLength, 106 unsigned int cbFrameLength,
128 bool bNeedAck, 107 bool bNeedAck,
129 bool bDisCRC, 108 bool bDisCRC,
130 PSEthernetHeader psEthHeader, 109 struct ieee80211_hdr *hdr,
131 unsigned short wCurrentRate, 110 unsigned short wCurrentRate,
132 unsigned char byFBOption 111 unsigned char byFBOption
133); 112);
@@ -144,26 +123,15 @@ s_vGenerateTxParameter(
144 unsigned int cbFrameSize, 123 unsigned int cbFrameSize,
145 bool bNeedACK, 124 bool bNeedACK,
146 unsigned int uDMAIdx, 125 unsigned int uDMAIdx,
147 PSEthernetHeader psEthHeader, 126 void *psEthHeader,
148 unsigned short wCurrentRate 127 unsigned short wCurrentRate
149); 128);
150 129
151static void s_vFillFragParameter(
152 struct vnt_private *pDevice,
153 unsigned char *pbyBuffer,
154 unsigned int uTxType,
155 void *pvtdCurr,
156 unsigned short wFragType,
157 unsigned int cbReqCount
158);
159
160static unsigned int 130static unsigned int
161s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType, 131s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType,
162 unsigned char *pbyTxBufferAddr, unsigned int cbFrameBodySize, 132 unsigned char *pbyTxBufferAddr,
163 unsigned int uDMAIdx, PSTxDesc pHeadTD, 133 unsigned int uDMAIdx, PSTxDesc pHeadTD,
164 PSEthernetHeader psEthHeader, unsigned char *pPacket, 134 unsigned int uNodeIndex);
165 bool bNeedEncrypt, PSKeyItem pTransmitKey,
166 unsigned int uNodeIndex, unsigned int *puMACfragNum);
167 135
168static 136static
169__le16 137__le16
@@ -178,165 +146,12 @@ s_uFillDataHead(
178 unsigned int cbLastFragmentSize, 146 unsigned int cbLastFragmentSize,
179 unsigned int uMACfragNum, 147 unsigned int uMACfragNum,
180 unsigned char byFBOption, 148 unsigned char byFBOption,
181 unsigned short wCurrentRate 149 unsigned short wCurrentRate,
150 bool is_pspoll
182); 151);
183 152
184/*--------------------- Export Variables --------------------------*/ 153/*--------------------- Export Variables --------------------------*/
185 154
186static
187void
188s_vFillTxKey(
189 struct vnt_private *pDevice,
190 unsigned char *pbyBuf,
191 unsigned char *pbyIVHead,
192 PSKeyItem pTransmitKey,
193 unsigned char *pbyHdrBuf,
194 unsigned short wPayloadLen,
195 unsigned char *pMICHDR
196)
197{
198 struct vnt_mic_hdr *mic_hdr = (struct vnt_mic_hdr *)pMICHDR;
199 unsigned long *pdwIV = (unsigned long *)pbyIVHead;
200 unsigned long *pdwExtIV = (unsigned long *)((unsigned char *)pbyIVHead+4);
201 PS802_11Header pMACHeader = (PS802_11Header)pbyHdrBuf;
202 unsigned long dwRevIVCounter;
203 unsigned char byKeyIndex = 0;
204
205 //Fill TXKEY
206 if (pTransmitKey == NULL)
207 return;
208
209 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
210 *pdwIV = pDevice->dwIVCounter;
211 byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
212
213 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
214 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
215 memcpy(pDevice->abyPRNG, (unsigned char *)&(dwRevIVCounter), 3);
216 memcpy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
217 } else {
218 memcpy(pbyBuf, (unsigned char *)&(dwRevIVCounter), 3);
219 memcpy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
220 if (pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
221 memcpy(pbyBuf+8, (unsigned char *)&(dwRevIVCounter), 3);
222 memcpy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
223 }
224 memcpy(pDevice->abyPRNG, pbyBuf, 16);
225 }
226 // Append IV after Mac Header
227 *pdwIV &= WEP_IV_MASK;//00000000 11111111 11111111 11111111
228 *pdwIV |= (unsigned long)byKeyIndex << 30;
229 *pdwIV = cpu_to_le32(*pdwIV);
230 pDevice->dwIVCounter++;
231 if (pDevice->dwIVCounter > WEP_IV_MASK)
232 pDevice->dwIVCounter = 0;
233
234 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
235 pTransmitKey->wTSC15_0++;
236 if (pTransmitKey->wTSC15_0 == 0)
237 pTransmitKey->dwTSC47_16++;
238
239 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
240 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
241 memcpy(pbyBuf, pDevice->abyPRNG, 16);
242 // Make IV
243 memcpy(pdwIV, pDevice->abyPRNG, 3);
244
245 *(pbyIVHead+3) = (unsigned char)(((byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
246 // Append IV&ExtIV after Mac Header
247 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
248 pr_debug("vFillTxKey()---- pdwExtIV: %lx\n", *pdwExtIV);
249
250 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
251 pTransmitKey->wTSC15_0++;
252 if (pTransmitKey->wTSC15_0 == 0)
253 pTransmitKey->dwTSC47_16++;
254
255 memcpy(pbyBuf, pTransmitKey->abyKey, 16);
256
257 // Make IV
258 *pdwIV = 0;
259 *(pbyIVHead+3) = (unsigned char)(((byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
260 *pdwIV |= cpu_to_le16((unsigned short)(pTransmitKey->wTSC15_0));
261 //Append IV&ExtIV after Mac Header
262 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
263
264 /* MICHDR0 */
265 mic_hdr->id = 0x59;
266 mic_hdr->tx_priority = 0;
267 memcpy(mic_hdr->mic_addr2, pMACHeader->abyAddr2, ETH_ALEN);
268
269 /* ccmp pn big endian order */
270 mic_hdr->ccmp_pn[0] = (u8)(pTransmitKey->dwTSC47_16 >> 24);
271 mic_hdr->ccmp_pn[1] = (u8)(pTransmitKey->dwTSC47_16 >> 16);
272 mic_hdr->ccmp_pn[2] = (u8)(pTransmitKey->dwTSC47_16 >> 8);
273 mic_hdr->ccmp_pn[3] = (u8)pTransmitKey->dwTSC47_16;
274 mic_hdr->ccmp_pn[4] = (u8)(pTransmitKey->wTSC15_0 >> 8);
275 mic_hdr->ccmp_pn[5] = (u8)pTransmitKey->wTSC15_0;
276
277 /* MICHDR1 */
278 mic_hdr->payload_len = cpu_to_be16(wPayloadLen);
279
280 if (pDevice->bLongHeader)
281 mic_hdr->hlen = cpu_to_be16(28);
282 else
283 mic_hdr->hlen = cpu_to_be16(22);
284
285 memcpy(mic_hdr->addr1, pMACHeader->abyAddr1, ETH_ALEN);
286 memcpy(mic_hdr->addr2, pMACHeader->abyAddr2, ETH_ALEN);
287
288 /* MICHDR2 */
289 memcpy(mic_hdr->addr3, pMACHeader->abyAddr3, ETH_ALEN);
290 mic_hdr->frame_control =
291 cpu_to_le16(pMACHeader->wFrameCtl & 0xc78f);
292 mic_hdr->seq_ctrl = cpu_to_le16(pMACHeader->wSeqCtl & 0xf);
293
294 if (pDevice->bLongHeader)
295 memcpy(mic_hdr->addr4, pMACHeader->abyAddr4, ETH_ALEN);
296 }
297}
298
299static
300void
301s_vSWencryption(
302 struct vnt_private *pDevice,
303 PSKeyItem pTransmitKey,
304 unsigned char *pbyPayloadHead,
305 unsigned short wPayloadSize
306)
307{
308 unsigned int cbICVlen = 4;
309 unsigned long dwICV = 0xFFFFFFFFL;
310 unsigned long *pdwICV;
311
312 if (pTransmitKey == NULL)
313 return;
314
315 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
316 //=======================================================================
317 // Append ICV after payload
318 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
319 pdwICV = (unsigned long *)(pbyPayloadHead + wPayloadSize);
320 // finally, we must invert dwCRC to get the correct answer
321 *pdwICV = cpu_to_le32(~dwICV);
322 // RC4 encryption
323 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
324 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
325 //=======================================================================
326 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
327 //=======================================================================
328 //Append ICV after payload
329 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
330 pdwICV = (unsigned long *)(pbyPayloadHead + wPayloadSize);
331 // finally, we must invert dwCRC to get the correct answer
332 *pdwICV = cpu_to_le32(~dwICV);
333 // RC4 encryption
334 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
335 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
336 //=======================================================================
337 }
338}
339
340static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate) 155static __le16 vnt_time_stamp_off(struct vnt_private *priv, u16 rate)
341{ 156{
342 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2] 157 return cpu_to_le16(wTimeStampOff[priv->byPreambleType % 2]
@@ -683,7 +498,8 @@ s_uFillDataHead(
683 unsigned int cbLastFragmentSize, 498 unsigned int cbLastFragmentSize,
684 unsigned int uMACfragNum, 499 unsigned int uMACfragNum,
685 unsigned char byFBOption, 500 unsigned char byFBOption,
686 unsigned short wCurrentRate 501 unsigned short wCurrentRate,
502 bool is_pspoll
687) 503)
688{ 504{
689 505
@@ -702,15 +518,24 @@ s_uFillDataHead(
702 pDevice->byTopCCKBasicRate, 518 pDevice->byTopCCKBasicRate,
703 PK_TYPE_11B, &buf->b); 519 PK_TYPE_11B, &buf->b);
704 520
705 /* Get Duration and TimeStamp */ 521 if (is_pspoll) {
706 buf->duration_a = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, 522 __le16 dur = cpu_to_le16(pDevice->current_aid | BIT(14) | BIT(15));
707 byPktType, wCurrentRate, bNeedAck, uFragIdx, 523
708 cbLastFragmentSize, uMACfragNum, 524 buf->duration_a = dur;
709 byFBOption)); 525 buf->duration_b = dur;
710 buf->duration_b = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, 526 } else {
711 PK_TYPE_11B, pDevice->byTopCCKBasicRate, 527 /* Get Duration and TimeStamp */
712 bNeedAck, uFragIdx, cbLastFragmentSize, 528 buf->duration_a =
713 uMACfragNum, byFBOption)); 529 cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength,
530 byPktType, wCurrentRate, bNeedAck, uFragIdx,
531 cbLastFragmentSize, uMACfragNum,
532 byFBOption));
533 buf->duration_b =
534 cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength,
535 PK_TYPE_11B, pDevice->byTopCCKBasicRate,
536 bNeedAck, uFragIdx, cbLastFragmentSize,
537 uMACfragNum, byFBOption));
538 }
714 539
715 buf->time_stamp_off_a = vnt_time_stamp_off(pDevice, wCurrentRate); 540 buf->time_stamp_off_a = vnt_time_stamp_off(pDevice, wCurrentRate);
716 buf->time_stamp_off_b = vnt_time_stamp_off(pDevice, pDevice->byTopCCKBasicRate); 541 buf->time_stamp_off_b = vnt_time_stamp_off(pDevice, pDevice->byTopCCKBasicRate);
@@ -764,11 +589,18 @@ s_uFillDataHead(
764 vnt_get_phy_field(pDevice, cbFrameLength, wCurrentRate, 589 vnt_get_phy_field(pDevice, cbFrameLength, wCurrentRate,
765 byPktType, &buf->ab); 590 byPktType, &buf->ab);
766 591
767 /* Get Duration and TimeStampOff */ 592 if (is_pspoll) {
768 buf->duration = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType, 593 __le16 dur = cpu_to_le16(pDevice->current_aid | BIT(14) | BIT(15));
594
595 buf->duration = dur;
596 } else {
597 /* Get Duration and TimeStampOff */
598 buf->duration =
599 cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
769 wCurrentRate, bNeedAck, uFragIdx, 600 wCurrentRate, bNeedAck, uFragIdx,
770 cbLastFragmentSize, uMACfragNum, 601 cbLastFragmentSize, uMACfragNum,
771 byFBOption)); 602 byFBOption));
603 }
772 604
773 buf->time_stamp_off = vnt_time_stamp_off(pDevice, wCurrentRate); 605 buf->time_stamp_off = vnt_time_stamp_off(pDevice, wCurrentRate);
774 return buf->duration; 606 return buf->duration;
@@ -778,17 +610,27 @@ s_uFillDataHead(
778 /* Get SignalField, ServiceField & Length */ 610 /* Get SignalField, ServiceField & Length */
779 vnt_get_phy_field(pDevice, cbFrameLength, wCurrentRate, 611 vnt_get_phy_field(pDevice, cbFrameLength, wCurrentRate,
780 byPktType, &buf->ab); 612 byPktType, &buf->ab);
781 /* Get Duration and TimeStampOff */ 613
782 buf->duration = cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, byPktType, 614 if (is_pspoll) {
615 __le16 dur = cpu_to_le16(pDevice->current_aid | BIT(14) | BIT(15));
616
617 buf->duration = dur;
618 } else {
619 /* Get Duration and TimeStampOff */
620 buf->duration =
621 cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, byPktType,
783 wCurrentRate, bNeedAck, uFragIdx, 622 wCurrentRate, bNeedAck, uFragIdx,
784 cbLastFragmentSize, uMACfragNum, 623 cbLastFragmentSize, uMACfragNum,
785 byFBOption)); 624 byFBOption));
625 }
626
786 buf->time_stamp_off = vnt_time_stamp_off(pDevice, wCurrentRate); 627 buf->time_stamp_off = vnt_time_stamp_off(pDevice, wCurrentRate);
787 return buf->duration; 628 return buf->duration;
788 } 629 }
789 return 0; 630 return 0;
790} 631}
791 632
633
792static 634static
793void 635void
794s_vFillRTSHead( 636s_vFillRTSHead(
@@ -798,7 +640,7 @@ s_vFillRTSHead(
798 unsigned int cbFrameLength, 640 unsigned int cbFrameLength,
799 bool bNeedAck, 641 bool bNeedAck,
800 bool bDisCRC, 642 bool bDisCRC,
801 PSEthernetHeader psEthHeader, 643 struct ieee80211_hdr *hdr,
802 unsigned short wCurrentRate, 644 unsigned short wCurrentRate,
803 unsigned char byFBOption 645 unsigned char byFBOption
804) 646)
@@ -850,18 +692,8 @@ s_vFillRTSHead(
850 cpu_to_le16(IEEE80211_FTYPE_CTL | 692 cpu_to_le16(IEEE80211_FTYPE_CTL |
851 IEEE80211_STYPE_RTS); 693 IEEE80211_STYPE_RTS);
852 694
853 695 ether_addr_copy(buf->data.ra, hdr->addr1);
854 if ((pDevice->op_mode == NL80211_IFTYPE_ADHOC) || 696 ether_addr_copy(buf->data.ta, hdr->addr2);
855 (pDevice->op_mode == NL80211_IFTYPE_AP)) {
856 memcpy(&buf->data.ra, psEthHeader->abyDstAddr, ETH_ALEN);
857 } else {
858 memcpy(&buf->data.ra, pDevice->abyBSSID, ETH_ALEN);
859 }
860 if (pDevice->op_mode == NL80211_IFTYPE_AP)
861 memcpy(&buf->data.ta, pDevice->abyBSSID, ETH_ALEN);
862 else
863 memcpy(&buf->data.ta, psEthHeader->abySrcAddr, ETH_ALEN);
864
865 } else { 697 } else {
866 struct vnt_rts_g_fb *buf = pvRTS; 698 struct vnt_rts_g_fb *buf = pvRTS;
867 /* Get SignalField, ServiceField & Length */ 699 /* Get SignalField, ServiceField & Length */
@@ -914,19 +746,8 @@ s_vFillRTSHead(
914 cpu_to_le16(IEEE80211_FTYPE_CTL | 746 cpu_to_le16(IEEE80211_FTYPE_CTL |
915 IEEE80211_STYPE_RTS); 747 IEEE80211_STYPE_RTS);
916 748
917 749 ether_addr_copy(buf->data.ra, hdr->addr1);
918 if ((pDevice->op_mode == NL80211_IFTYPE_ADHOC) || 750 ether_addr_copy(buf->data.ta, hdr->addr2);
919 (pDevice->op_mode == NL80211_IFTYPE_AP)) {
920 memcpy(&buf->data.ra, psEthHeader->abyDstAddr, ETH_ALEN);
921 } else {
922 memcpy(&buf->data.ra, pDevice->abyBSSID, ETH_ALEN);
923 }
924
925 if (pDevice->op_mode == NL80211_IFTYPE_AP)
926 memcpy(&buf->data.ta, pDevice->abyBSSID, ETH_ALEN);
927 else
928 memcpy(&buf->data.ta, psEthHeader->abySrcAddr, ETH_ALEN);
929
930 } // if (byFBOption == AUTO_FB_NONE) 751 } // if (byFBOption == AUTO_FB_NONE)
931 } else if (byPktType == PK_TYPE_11A) { 752 } else if (byPktType == PK_TYPE_11A) {
932 if (byFBOption == AUTO_FB_NONE) { 753 if (byFBOption == AUTO_FB_NONE) {
@@ -947,19 +768,8 @@ s_vFillRTSHead(
947 cpu_to_le16(IEEE80211_FTYPE_CTL | 768 cpu_to_le16(IEEE80211_FTYPE_CTL |
948 IEEE80211_STYPE_RTS); 769 IEEE80211_STYPE_RTS);
949 770
950 771 ether_addr_copy(buf->data.ra, hdr->addr1);
951 if ((pDevice->op_mode == NL80211_IFTYPE_ADHOC) || 772 ether_addr_copy(buf->data.ta, hdr->addr2);
952 (pDevice->op_mode == NL80211_IFTYPE_AP)) {
953 memcpy(&buf->data.ra, psEthHeader->abyDstAddr, ETH_ALEN);
954 } else {
955 memcpy(&buf->data.ra, pDevice->abyBSSID, ETH_ALEN);
956 }
957
958 if (pDevice->op_mode == NL80211_IFTYPE_AP)
959 memcpy(&buf->data.ta, pDevice->abyBSSID, ETH_ALEN);
960 else
961 memcpy(&buf->data.ta, psEthHeader->abySrcAddr, ETH_ALEN);
962
963 } else { 773 } else {
964 struct vnt_rts_a_fb *buf = pvRTS; 774 struct vnt_rts_a_fb *buf = pvRTS;
965 /* Get SignalField, ServiceField & Length */ 775 /* Get SignalField, ServiceField & Length */
@@ -988,16 +798,8 @@ s_vFillRTSHead(
988 cpu_to_le16(IEEE80211_FTYPE_CTL | 798 cpu_to_le16(IEEE80211_FTYPE_CTL |
989 IEEE80211_STYPE_RTS); 799 IEEE80211_STYPE_RTS);
990 800
991 if ((pDevice->op_mode == NL80211_IFTYPE_ADHOC) || 801 ether_addr_copy(buf->data.ra, hdr->addr1);
992 (pDevice->op_mode == NL80211_IFTYPE_AP)) { 802 ether_addr_copy(buf->data.ta, hdr->addr2);
993 memcpy(&buf->data.ra, psEthHeader->abyDstAddr, ETH_ALEN);
994 } else {
995 memcpy(&buf->data.ra, pDevice->abyBSSID, ETH_ALEN);
996 }
997 if (pDevice->op_mode == NL80211_IFTYPE_AP)
998 memcpy(&buf->data.ta, pDevice->abyBSSID, ETH_ALEN);
999 else
1000 memcpy(&buf->data.ta, psEthHeader->abySrcAddr, ETH_ALEN);
1001 } 803 }
1002 } else if (byPktType == PK_TYPE_11B) { 804 } else if (byPktType == PK_TYPE_11B) {
1003 struct vnt_rts_ab *buf = pvRTS; 805 struct vnt_rts_ab *buf = pvRTS;
@@ -1016,17 +818,8 @@ s_vFillRTSHead(
1016 buf->data.frame_control = 818 buf->data.frame_control =
1017 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS); 819 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
1018 820
1019 if ((pDevice->op_mode == NL80211_IFTYPE_ADHOC) || 821 ether_addr_copy(buf->data.ra, hdr->addr1);
1020 (pDevice->op_mode == NL80211_IFTYPE_AP)) { 822 ether_addr_copy(buf->data.ta, hdr->addr2);
1021 memcpy(&buf->data.ra, psEthHeader->abyDstAddr, ETH_ALEN);
1022 } else {
1023 memcpy(&buf->data.ra, pDevice->abyBSSID, ETH_ALEN);
1024 }
1025
1026 if (pDevice->op_mode == NL80211_IFTYPE_AP)
1027 memcpy(&buf->data.ta, pDevice->abyBSSID, ETH_ALEN);
1028 else
1029 memcpy(&buf->data.ta, psEthHeader->abySrcAddr, ETH_ALEN);
1030 } 823 }
1031} 824}
1032 825
@@ -1093,7 +886,8 @@ s_vFillCTSHead(
1093 886
1094 buf->reserved2 = 0x0; 887 buf->reserved2 = 0x0;
1095 888
1096 memcpy(&buf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN); 889 ether_addr_copy(buf->data.ra,
890 pDevice->abyCurrentNetAddr);
1097 } else { //if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA) 891 } else { //if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA)
1098 struct vnt_cts *buf = pvCTS; 892 struct vnt_cts *buf = pvCTS;
1099 /* Get SignalField, ServiceField & Length */ 893 /* Get SignalField, ServiceField & Length */
@@ -1116,7 +910,8 @@ s_vFillCTSHead(
1116 IEEE80211_STYPE_CTS); 910 IEEE80211_STYPE_CTS);
1117 911
1118 buf->reserved2 = 0x0; 912 buf->reserved2 = 0x0;
1119 memcpy(&buf->data.ra, pDevice->abyCurrentNetAddr, ETH_ALEN); 913 ether_addr_copy(buf->data.ra,
914 pDevice->abyCurrentNetAddr);
1120 } 915 }
1121 } 916 }
1122} 917}
@@ -1156,11 +951,10 @@ s_vGenerateTxParameter(
1156 unsigned int cbFrameSize, 951 unsigned int cbFrameSize,
1157 bool bNeedACK, 952 bool bNeedACK,
1158 unsigned int uDMAIdx, 953 unsigned int uDMAIdx,
1159 PSEthernetHeader psEthHeader, 954 void *psEthHeader,
1160 unsigned short wCurrentRate 955 unsigned short wCurrentRate
1161) 956)
1162{ 957{
1163 unsigned int cbMACHdLen = WLAN_HDR_ADDR3_LEN; //24
1164 unsigned short wFifoCtl; 958 unsigned short wFifoCtl;
1165 bool bDisCRC = false; 959 bool bDisCRC = false;
1166 unsigned char byFBOption = AUTO_FB_NONE; 960 unsigned char byFBOption = AUTO_FB_NONE;
@@ -1178,9 +972,6 @@ s_vGenerateTxParameter(
1178 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) 972 else if (wFifoCtl & FIFOCTL_AUTO_FB_1)
1179 byFBOption = AUTO_FB_1; 973 byFBOption = AUTO_FB_1;
1180 974
1181 if (pDevice->bLongHeader)
1182 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1183
1184 if (!pvRrvTime) 975 if (!pvRrvTime)
1185 return; 976 return;
1186 977
@@ -1237,90 +1028,30 @@ s_vGenerateTxParameter(
1237 } 1028 }
1238} 1029}
1239 1030
1240static
1241void
1242s_vFillFragParameter(
1243 struct vnt_private *pDevice,
1244 unsigned char *pbyBuffer,
1245 unsigned int uTxType,
1246 void *pvtdCurr,
1247 unsigned short wFragType,
1248 unsigned int cbReqCount
1249)
1250{
1251 PSTxBufHead pTxBufHead = (PSTxBufHead) pbyBuffer;
1252
1253 if (uTxType == TYPE_SYNCDMA) {
1254 PSTxSyncDesc ptdCurr = (PSTxSyncDesc)pvtdCurr;
1255
1256 //Set FIFOCtl & TimeStamp in TxSyncDesc
1257 ptdCurr->m_wFIFOCtl = pTxBufHead->wFIFOCtl;
1258 ptdCurr->m_wTimeStamp = pTxBufHead->wTimeStamp;
1259 //Set TSR1 & ReqCount in TxDescHead
1260 ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((unsigned short)(cbReqCount));
1261 if (wFragType == FRAGCTL_ENDFRAG) //Last Fragmentation
1262 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
1263 else
1264 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP);
1265 } else {
1266 PSTxDesc ptdCurr = (PSTxDesc)pvtdCurr;
1267 //Set TSR1 & ReqCount in TxDescHead
1268 ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((unsigned short)(cbReqCount));
1269 if (wFragType == FRAGCTL_ENDFRAG) //Last Fragmentation
1270 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
1271 else
1272 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP);
1273 }
1274
1275 pTxBufHead->wFragCtl |= (unsigned short)wFragType;//0x0001; //0000 0000 0000 0001
1276}
1277
1278static unsigned int 1031static unsigned int
1279s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType, 1032s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType,
1280 unsigned char *pbyTxBufferAddr, unsigned int cbFrameBodySize, 1033 unsigned char *pbyTxBufferAddr,
1281 unsigned int uDMAIdx, PSTxDesc pHeadTD, 1034 unsigned int uDMAIdx, PSTxDesc pHeadTD,
1282 PSEthernetHeader psEthHeader, unsigned char *pPacket, 1035 unsigned int is_pspoll)
1283 bool bNeedEncrypt, PSKeyItem pTransmitKey,
1284 unsigned int uNodeIndex, unsigned int *puMACfragNum)
1285{ 1036{
1286 unsigned int cbMACHdLen; 1037 PDEVICE_TD_INFO td_info = pHeadTD->pTDInfo;
1038 struct sk_buff *skb = td_info->skb;
1039 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1040 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1041 struct vnt_tx_fifo_head *tx_buffer_head =
1042 (struct vnt_tx_fifo_head *)td_info->buf;
1043 u16 fifo_ctl = le16_to_cpu(tx_buffer_head->fifo_ctl);
1287 unsigned int cbFrameSize; 1044 unsigned int cbFrameSize;
1288 unsigned int cbFragmentSize; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
1289 unsigned int cbFragPayloadSize;
1290 unsigned int cbLastFragmentSize; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
1291 unsigned int cbLastFragPayloadSize;
1292 unsigned int uFragIdx;
1293 unsigned char *pbyPayloadHead;
1294 unsigned char *pbyIVHead;
1295 unsigned char *pbyMacHdr;
1296 unsigned short wFragType; //00:Non-Frag, 01:Start, 10:Mid, 11:Last
1297 __le16 uDuration; 1045 __le16 uDuration;
1298 unsigned char *pbyBuffer; 1046 unsigned char *pbyBuffer;
1299 unsigned int cbIVlen = 0;
1300 unsigned int cbICVlen = 0;
1301 unsigned int cbMIClen = 0;
1302 unsigned int cbFCSlen = 4;
1303 unsigned int cb802_1_H_len = 0;
1304 unsigned int uLength = 0; 1047 unsigned int uLength = 0;
1305 unsigned int uTmpLen = 0;
1306 unsigned int cbMICHDR = 0; 1048 unsigned int cbMICHDR = 0;
1307 u32 dwMICKey0, dwMICKey1;
1308 u32 dwMIC_Priority;
1309 u32 *pdwMIC_L;
1310 u32 *pdwMIC_R;
1311 u32 dwSafeMIC_L, dwSafeMIC_R; /* Fix "Last Frag Size" < "MIC length". */
1312 bool bMIC2Frag = false;
1313 unsigned int uMICFragLen = 0;
1314 unsigned int uMACfragNum = 1; 1049 unsigned int uMACfragNum = 1;
1315 unsigned int uPadding = 0; 1050 unsigned int uPadding = 0;
1316 unsigned int cbReqCount = 0; 1051 unsigned int cbReqCount = 0;
1317 1052 bool bNeedACK = (bool)(fifo_ctl & FIFOCTL_NEEDACK);
1318 bool bNeedACK; 1053 bool bRTS = (bool)(fifo_ctl & FIFOCTL_RTS);
1319 bool bRTS;
1320 bool bIsAdhoc;
1321 unsigned char *pbyType;
1322 PSTxDesc ptdCurr; 1054 PSTxDesc ptdCurr;
1323 PSTxBufHead psTxBufHd = (PSTxBufHead) pbyTxBufferAddr;
1324 unsigned int cbHeaderLength = 0; 1055 unsigned int cbHeaderLength = 0;
1325 void *pvRrvTime; 1056 void *pvRrvTime;
1326 struct vnt_mic_hdr *pMICHDR; 1057 struct vnt_mic_hdr *pMICHDR;
@@ -1328,72 +1059,35 @@ s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType,
1328 void *pvCTS; 1059 void *pvCTS;
1329 void *pvTxDataHd; 1060 void *pvTxDataHd;
1330 unsigned short wTxBufSize; // FFinfo size 1061 unsigned short wTxBufSize; // FFinfo size
1331 unsigned int uTotalCopyLength = 0;
1332 unsigned char byFBOption = AUTO_FB_NONE; 1062 unsigned char byFBOption = AUTO_FB_NONE;
1333 bool bIsWEP256 = false;
1334 PSMgmtObject pMgmt = pDevice->pMgmt;
1335 1063
1336 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL; 1064 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1337 1065
1338 if ((pDevice->op_mode == NL80211_IFTYPE_ADHOC) || 1066 cbFrameSize = skb->len + 4;
1339 (pDevice->op_mode == NL80211_IFTYPE_AP)) {
1340 if (is_multicast_ether_addr(&(psEthHeader->abyDstAddr[0])))
1341 bNeedACK = false;
1342 else
1343 bNeedACK = true;
1344 bIsAdhoc = true;
1345 } else {
1346 // MSDUs in Infra mode always need ACK
1347 bNeedACK = true;
1348 bIsAdhoc = false;
1349 }
1350 1067
1351 if (pDevice->bLongHeader) 1068 if (info->control.hw_key) {
1352 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6; 1069 switch (info->control.hw_key->cipher) {
1353 else 1070 case WLAN_CIPHER_SUITE_CCMP:
1354 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1355
1356 if ((bNeedEncrypt == true) && (pTransmitKey != NULL)) {
1357 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1358 cbIVlen = 4;
1359 cbICVlen = 4;
1360 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN)
1361 bIsWEP256 = true;
1362 }
1363 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1364 cbIVlen = 8;//IV+ExtIV
1365 cbMIClen = 8;
1366 cbICVlen = 4;
1367 }
1368 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1369 cbIVlen = 8;//RSN Header
1370 cbICVlen = 8;//MIC
1371 cbMICHDR = sizeof(struct vnt_mic_hdr); 1071 cbMICHDR = sizeof(struct vnt_mic_hdr);
1072 default:
1073 break;
1372 } 1074 }
1075
1076 cbFrameSize += info->control.hw_key->icv_len;
1077
1373 if (pDevice->byLocalID > REV_ID_VT3253_A1) { 1078 if (pDevice->byLocalID > REV_ID_VT3253_A1) {
1374 //MAC Header should be padding 0 to DW alignment. 1079 //MAC Header should be padding 0 to DW alignment.
1375 uPadding = 4 - (cbMACHdLen%4); 1080 uPadding = 4 - (ieee80211_get_hdrlen_from_skb(skb) % 4);
1376 uPadding %= 4; 1081 uPadding %= 4;
1377 } 1082 }
1378 } 1083 }
1379 1084
1380 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1381
1382 if ((bNeedACK == false) ||
1383 (cbFrameSize < pDevice->wRTSThreshold) ||
1384 ((cbFrameSize >= pDevice->wFragmentationThreshold) && (pDevice->wFragmentationThreshold <= pDevice->wRTSThreshold))
1385) {
1386 bRTS = false;
1387 } else {
1388 bRTS = true;
1389 psTxBufHd->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1390 }
1391 // 1085 //
1392 // Use for AUTO FALL BACK 1086 // Use for AUTO FALL BACK
1393 // 1087 //
1394 if (psTxBufHd->wFIFOCtl & FIFOCTL_AUTO_FB_0) 1088 if (fifo_ctl & FIFOCTL_AUTO_FB_0)
1395 byFBOption = AUTO_FB_0; 1089 byFBOption = AUTO_FB_0;
1396 else if (psTxBufHd->wFIFOCtl & FIFOCTL_AUTO_FB_1) 1090 else if (fifo_ctl & FIFOCTL_AUTO_FB_1)
1397 byFBOption = AUTO_FB_1; 1091 byFBOption = AUTO_FB_1;
1398 1092
1399 ////////////////////////////////////////////////////// 1093 //////////////////////////////////////////////////////
@@ -1487,1477 +1181,345 @@ s_cbFillTxBufHead(struct vnt_private *pDevice, unsigned char byPktType,
1487 } 1181 }
1488 } // Auto Fall Back 1182 } // Auto Fall Back
1489 } 1183 }
1490 memset((void *)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderLength - wTxBufSize));
1491
1492//////////////////////////////////////////////////////////////////
1493 if ((bNeedEncrypt == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1494 if (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
1495 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1496 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1497 } else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
1498 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
1499 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
1500 } else {
1501 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[24]);
1502 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[28]);
1503 }
1504 // DO Software Michael
1505 MIC_vInit(dwMICKey0, dwMICKey1);
1506 MIC_vAppend((unsigned char *)&(psEthHeader->abyDstAddr[0]), 12);
1507 dwMIC_Priority = 0;
1508 MIC_vAppend((unsigned char *)&dwMIC_Priority, 4);
1509 pr_debug("MIC KEY: %X, %X\n", dwMICKey0, dwMICKey1);
1510 }
1511
1512///////////////////////////////////////////////////////////////////
1513
1514 pbyMacHdr = (unsigned char *)(pbyTxBufferAddr + cbHeaderLength);
1515 pbyPayloadHead = (unsigned char *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
1516 pbyIVHead = (unsigned char *)(pbyMacHdr + cbMACHdLen + uPadding);
1517
1518 if ((cbFrameSize > pDevice->wFragmentationThreshold) && (bNeedACK == true) && (bIsWEP256 == false)) {
1519 // Fragmentation
1520 // FragThreshold = Fragment size(Hdr+(IV)+fragment payload+(MIC)+(ICV)+FCS)
1521 cbFragmentSize = pDevice->wFragmentationThreshold;
1522 cbFragPayloadSize = cbFragmentSize - cbMACHdLen - cbIVlen - cbICVlen - cbFCSlen;
1523 //FragNum = (FrameSize-(Hdr+FCS))/(Fragment Size -(Hrd+FCS)))
1524 uMACfragNum = (unsigned short) ((cbFrameBodySize + cbMIClen) / cbFragPayloadSize);
1525 cbLastFragPayloadSize = (cbFrameBodySize + cbMIClen) % cbFragPayloadSize;
1526 if (cbLastFragPayloadSize == 0)
1527 cbLastFragPayloadSize = cbFragPayloadSize;
1528 else
1529 uMACfragNum++;
1530
1531 //[Hdr+(IV)+last fragment payload+(MIC)+(ICV)+FCS]
1532 cbLastFragmentSize = cbMACHdLen + cbLastFragPayloadSize + cbIVlen + cbICVlen + cbFCSlen;
1533
1534 for (uFragIdx = 0; uFragIdx < uMACfragNum; uFragIdx++) {
1535 if (uFragIdx == 0) {
1536 //=========================
1537 // Start Fragmentation
1538 //=========================
1539 pr_debug("Start Fragmentation...\n");
1540 wFragType = FRAGCTL_STAFRAG;
1541
1542 //Fill FIFO,RrvTime,RTS,and CTS
1543 s_vGenerateTxParameter(pDevice, byPktType, (void *)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
1544 cbFragmentSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
1545 //Fill DataHead
1546 uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFragmentSize, uDMAIdx, bNeedACK,
1547 uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption, pDevice->wCurrentRate);
1548 // Generate TX MAC Header
1549 vGenerateMACHeader(pDevice, pbyMacHdr, uDuration, psEthHeader, bNeedEncrypt,
1550 wFragType, uDMAIdx, uFragIdx);
1551
1552 if (bNeedEncrypt == true) {
1553 //Fill TXKEY
1554 s_vFillTxKey(pDevice, (unsigned char *)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
1555 pbyMacHdr, (unsigned short)cbFragPayloadSize, (unsigned char *)pMICHDR);
1556 //Fill IV(ExtIV,RSNHDR)
1557 if (pDevice->bEnableHostWEP) {
1558 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1559 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1560 }
1561 }
1562
1563 // 802.1H
1564 if (ntohs(psEthHeader->wType) > ETH_DATA_LEN) {
1565 if ((psEthHeader->wType == TYPE_PKT_IPX) ||
1566 (psEthHeader->wType == cpu_to_le16(0xF380))) {
1567 memcpy((unsigned char *)(pbyPayloadHead), &pDevice->abySNAP_Bridgetunnel[0], 6);
1568 } else {
1569 memcpy((unsigned char *)(pbyPayloadHead), &pDevice->abySNAP_RFC1042[0], 6);
1570 }
1571 pbyType = (unsigned char *)(pbyPayloadHead + 6);
1572 memcpy(pbyType, &(psEthHeader->wType), sizeof(unsigned short));
1573 cb802_1_H_len = 8;
1574 }
1575
1576 cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cbFragPayloadSize;
1577 //---------------------------
1578 // S/W or H/W Encryption
1579 //---------------------------
1580 pbyBuffer = (unsigned char *)pHeadTD->pTDInfo->buf;
1581
1582 uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cb802_1_H_len;
1583 //copy TxBufferHeader + MacHeader to desc
1584 memcpy(pbyBuffer, (void *)psTxBufHd, uLength);
1585
1586 // Copy the Packet into a tx Buffer
1587 memcpy((pbyBuffer + uLength), (pPacket + 14), (cbFragPayloadSize - cb802_1_H_len));
1588
1589 uTotalCopyLength += cbFragPayloadSize - cb802_1_H_len;
1590
1591 if ((bNeedEncrypt == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1592 pr_debug("Start MIC: %d\n",
1593 cbFragPayloadSize);
1594 MIC_vAppend((pbyBuffer + uLength - cb802_1_H_len), cbFragPayloadSize);
1595
1596 }
1597
1598 //---------------------------
1599 // S/W Encryption
1600 //---------------------------
1601 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
1602 if (bNeedEncrypt) {
1603 s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength - cb802_1_H_len), (unsigned short)cbFragPayloadSize);
1604 cbReqCount += cbICVlen;
1605 }
1606 }
1607
1608 ptdCurr = (PSTxDesc)pHeadTD;
1609 //--------------------
1610 //1.Set TSR1 & ReqCount in TxDescHead
1611 //2.Set FragCtl in TxBufferHead
1612 //3.Set Frame Control
1613 //4.Set Sequence Control
1614 //5.Get S/W generate FCS
1615 //--------------------
1616 s_vFillFragParameter(pDevice, pbyBuffer, uDMAIdx, (void *)ptdCurr, wFragType, cbReqCount);
1617
1618 ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
1619 ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
1620 ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
1621 ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
1622 pDevice->iTDUsed[uDMAIdx]++;
1623 pHeadTD = ptdCurr->next;
1624 } else if (uFragIdx == (uMACfragNum-1)) {
1625 //=========================
1626 // Last Fragmentation
1627 //=========================
1628 pr_debug("Last Fragmentation...\n");
1629
1630 wFragType = FRAGCTL_ENDFRAG;
1631
1632 //Fill FIFO,RrvTime,RTS,and CTS
1633 s_vGenerateTxParameter(pDevice, byPktType, (void *)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
1634 cbLastFragmentSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
1635 //Fill DataHead
1636 uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbLastFragmentSize, uDMAIdx, bNeedACK,
1637 uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption, pDevice->wCurrentRate);
1638
1639 // Generate TX MAC Header
1640 vGenerateMACHeader(pDevice, pbyMacHdr, uDuration, psEthHeader, bNeedEncrypt,
1641 wFragType, uDMAIdx, uFragIdx);
1642
1643 if (bNeedEncrypt == true) {
1644 //Fill TXKEY
1645 s_vFillTxKey(pDevice, (unsigned char *)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
1646 pbyMacHdr, (unsigned short)cbLastFragPayloadSize, (unsigned char *)pMICHDR);
1647
1648 if (pDevice->bEnableHostWEP) {
1649 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1650 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1651 }
1652
1653 }
1654
1655 cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cbLastFragPayloadSize;
1656 //---------------------------
1657 // S/W or H/W Encryption
1658 //---------------------------
1659
1660 pbyBuffer = (unsigned char *)pHeadTD->pTDInfo->buf;
1661
1662 uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen;
1663
1664 //copy TxBufferHeader + MacHeader to desc
1665 memcpy(pbyBuffer, (void *)psTxBufHd, uLength);
1666
1667 // Copy the Packet into a tx Buffer
1668 if (bMIC2Frag == false) {
1669 memcpy((pbyBuffer + uLength),
1670 (pPacket + 14 + uTotalCopyLength),
1671 (cbLastFragPayloadSize - cbMIClen)
1672);
1673 //TODO check uTmpLen !
1674 uTmpLen = cbLastFragPayloadSize - cbMIClen;
1675
1676 }
1677 if ((bNeedEncrypt == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1678 pr_debug("LAST: uMICFragLen:%d, cbLastFragPayloadSize:%d, uTmpLen:%d\n",
1679 uMICFragLen,
1680 cbLastFragPayloadSize,
1681 uTmpLen);
1682
1683 if (bMIC2Frag == false) {
1684 if (uTmpLen != 0)
1685 MIC_vAppend((pbyBuffer + uLength), uTmpLen);
1686 pdwMIC_L = (u32 *)(pbyBuffer + uLength + uTmpLen);
1687 pdwMIC_R = (u32 *)(pbyBuffer + uLength + uTmpLen + 4);
1688 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1689 pr_debug("Last MIC:%X, %X\n",
1690 *pdwMIC_L, *pdwMIC_R);
1691 } else {
1692 if (uMICFragLen >= 4) {
1693 memcpy((pbyBuffer + uLength), ((unsigned char *)&dwSafeMIC_R + (uMICFragLen - 4)),
1694 (cbMIClen - uMICFragLen));
1695 pr_debug("LAST: uMICFragLen >= 4: %X, %d\n",
1696 *(unsigned char *)((unsigned char *)&dwSafeMIC_R + (uMICFragLen - 4)),
1697 (cbMIClen - uMICFragLen));
1698
1699 } else {
1700 memcpy((pbyBuffer + uLength), ((unsigned char *)&dwSafeMIC_L + uMICFragLen),
1701 (4 - uMICFragLen));
1702 memcpy((pbyBuffer + uLength + (4 - uMICFragLen)), &dwSafeMIC_R, 4);
1703 pr_debug("LAST: uMICFragLen < 4: %X, %d\n",
1704 *(unsigned char *)((unsigned char *)&dwSafeMIC_R + uMICFragLen - 4),
1705 (cbMIClen - uMICFragLen));
1706 }
1707 }
1708 MIC_vUnInit();
1709 } else {
1710 ASSERT(uTmpLen == (cbLastFragPayloadSize - cbMIClen));
1711 }
1712
1713 //---------------------------
1714 // S/W Encryption
1715 //---------------------------
1716 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
1717 if (bNeedEncrypt) {
1718 s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength), (unsigned short)cbLastFragPayloadSize);
1719 cbReqCount += cbICVlen;
1720 }
1721 }
1722
1723 ptdCurr = (PSTxDesc)pHeadTD;
1724
1725 //--------------------
1726 //1.Set TSR1 & ReqCount in TxDescHead
1727 //2.Set FragCtl in TxBufferHead
1728 //3.Set Frame Control
1729 //4.Set Sequence Control
1730 //5.Get S/W generate FCS
1731 //--------------------
1732
1733 s_vFillFragParameter(pDevice, pbyBuffer, uDMAIdx, (void *)ptdCurr, wFragType, cbReqCount);
1734
1735 ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
1736 ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
1737 ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
1738 ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
1739 pDevice->iTDUsed[uDMAIdx]++;
1740 pHeadTD = ptdCurr->next;
1741
1742 } else {
1743 //=========================
1744 // Middle Fragmentation
1745 //=========================
1746 pr_debug("Middle Fragmentation...\n");
1747
1748 wFragType = FRAGCTL_MIDFRAG;
1749
1750 //Fill FIFO,RrvTime,RTS,and CTS
1751 s_vGenerateTxParameter(pDevice, byPktType, (void *)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
1752 cbFragmentSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
1753 //Fill DataHead
1754 uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFragmentSize, uDMAIdx, bNeedACK,
1755 uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption, pDevice->wCurrentRate);
1756
1757 // Generate TX MAC Header
1758 vGenerateMACHeader(pDevice, pbyMacHdr, uDuration, psEthHeader, bNeedEncrypt,
1759 wFragType, uDMAIdx, uFragIdx);
1760
1761 if (bNeedEncrypt == true) {
1762 //Fill TXKEY
1763 s_vFillTxKey(pDevice, (unsigned char *)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
1764 pbyMacHdr, (unsigned short)cbFragPayloadSize, (unsigned char *)pMICHDR);
1765
1766 if (pDevice->bEnableHostWEP) {
1767 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1768 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1769 }
1770 }
1771
1772 cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cbFragPayloadSize;
1773 //---------------------------
1774 // S/W or H/W Encryption
1775 //---------------------------
1776
1777 pbyBuffer = (unsigned char *)pHeadTD->pTDInfo->buf;
1778 uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen;
1779
1780 //copy TxBufferHeader + MacHeader to desc
1781 memcpy(pbyBuffer, (void *)psTxBufHd, uLength);
1782
1783 // Copy the Packet into a tx Buffer
1784 memcpy((pbyBuffer + uLength),
1785 (pPacket + 14 + uTotalCopyLength),
1786 cbFragPayloadSize
1787);
1788 uTmpLen = cbFragPayloadSize;
1789
1790 uTotalCopyLength += uTmpLen;
1791
1792 if ((bNeedEncrypt == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1793 MIC_vAppend((pbyBuffer + uLength), uTmpLen);
1794
1795 if (uTmpLen < cbFragPayloadSize) {
1796 bMIC2Frag = true;
1797 uMICFragLen = cbFragPayloadSize - uTmpLen;
1798 ASSERT(uMICFragLen < cbMIClen);
1799
1800 pdwMIC_L = (u32 *)(pbyBuffer + uLength + uTmpLen);
1801 pdwMIC_R = (u32 *)(pbyBuffer + uLength + uTmpLen + 4);
1802 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1803 dwSafeMIC_L = *pdwMIC_L;
1804 dwSafeMIC_R = *pdwMIC_R;
1805
1806 pr_debug("MIDDLE: uMICFragLen:%d, cbFragPayloadSize:%d, uTmpLen:%d\n",
1807 uMICFragLen,
1808 cbFragPayloadSize,
1809 uTmpLen);
1810 pr_debug("Fill MIC in Middle frag [%d]\n",
1811 uMICFragLen);
1812 pr_debug("Get MIC:%X, %X\n",
1813 *pdwMIC_L, *pdwMIC_R);
1814 }
1815 pr_debug("Middle frag len: %d\n",
1816 uTmpLen);
1817
1818 } else {
1819 ASSERT(uTmpLen == (cbFragPayloadSize));
1820 }
1821
1822 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
1823 if (bNeedEncrypt) {
1824 s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength), (unsigned short)cbFragPayloadSize);
1825 cbReqCount += cbICVlen;
1826 }
1827 }
1828
1829 ptdCurr = (PSTxDesc)pHeadTD;
1830
1831 //--------------------
1832 //1.Set TSR1 & ReqCount in TxDescHead
1833 //2.Set FragCtl in TxBufferHead
1834 //3.Set Frame Control
1835 //4.Set Sequence Control
1836 //5.Get S/W generate FCS
1837 //--------------------
1838
1839 s_vFillFragParameter(pDevice, pbyBuffer, uDMAIdx, (void *)ptdCurr, wFragType, cbReqCount);
1840
1841 ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
1842 ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
1843 ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
1844 ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
1845 pDevice->iTDUsed[uDMAIdx]++;
1846 pHeadTD = ptdCurr->next;
1847 }
1848 } // for (uMACfragNum)
1849 } else {
1850 //=========================
1851 // No Fragmentation
1852 //=========================
1853 wFragType = FRAGCTL_NONFRAG;
1854
1855 //Set FragCtl in TxBufferHead
1856 psTxBufHd->wFragCtl |= (unsigned short)wFragType;
1857
1858 //Fill FIFO,RrvTime,RTS,and CTS
1859 s_vGenerateTxParameter(pDevice, byPktType, (void *)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
1860 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
1861 //Fill DataHead
1862 uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
1863 0, 0, uMACfragNum, byFBOption, pDevice->wCurrentRate);
1864
1865 // Generate TX MAC Header
1866 vGenerateMACHeader(pDevice, pbyMacHdr, uDuration, psEthHeader, bNeedEncrypt,
1867 wFragType, uDMAIdx, 0);
1868
1869 if (bNeedEncrypt == true) {
1870 //Fill TXKEY
1871 s_vFillTxKey(pDevice, (unsigned char *)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
1872 pbyMacHdr, (unsigned short)cbFrameBodySize, (unsigned char *)pMICHDR);
1873
1874 if (pDevice->bEnableHostWEP) {
1875 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1876 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1877 }
1878 }
1879
1880 // 802.1H
1881 if (ntohs(psEthHeader->wType) > ETH_DATA_LEN) {
1882 if ((psEthHeader->wType == TYPE_PKT_IPX) ||
1883 (psEthHeader->wType == cpu_to_le16(0xF380))) {
1884 memcpy((unsigned char *)(pbyPayloadHead), &pDevice->abySNAP_Bridgetunnel[0], 6);
1885 } else {
1886 memcpy((unsigned char *)(pbyPayloadHead), &pDevice->abySNAP_RFC1042[0], 6);
1887 }
1888 pbyType = (unsigned char *)(pbyPayloadHead + 6);
1889 memcpy(pbyType, &(psEthHeader->wType), sizeof(unsigned short));
1890 cb802_1_H_len = 8;
1891 }
1892
1893 cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen);
1894 //---------------------------
1895 // S/W or H/W Encryption
1896 //---------------------------
1897 pbyBuffer = (unsigned char *)pHeadTD->pTDInfo->buf;
1898 uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cb802_1_H_len;
1899 1184
1900 //copy TxBufferHeader + MacHeader to desc 1185 td_info->mic_hdr = pMICHDR;
1901 memcpy(pbyBuffer, (void *)psTxBufHd, uLength);
1902 1186
1903 // Copy the Packet into a tx Buffer 1187 memset((void *)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderLength - wTxBufSize));
1904 memcpy((pbyBuffer + uLength),
1905 (pPacket + 14),
1906 cbFrameBodySize - cb802_1_H_len
1907);
1908
1909 if ((bNeedEncrypt == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1910 pr_debug("Length:%d, %d\n",
1911 cbFrameBodySize - cb802_1_H_len, uLength);
1912
1913 MIC_vAppend((pbyBuffer + uLength - cb802_1_H_len), cbFrameBodySize);
1914
1915 pdwMIC_L = (u32 *)(pbyBuffer + uLength - cb802_1_H_len + cbFrameBodySize);
1916 pdwMIC_R = (u32 *)(pbyBuffer + uLength - cb802_1_H_len + cbFrameBodySize + 4);
1917
1918 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1919 MIC_vUnInit();
1920
1921 if (pDevice->bTxMICFail == true) {
1922 *pdwMIC_L = 0;
1923 *pdwMIC_R = 0;
1924 pDevice->bTxMICFail = false;
1925 }
1926 1188
1927 pr_debug("uLength: %d, %d\n", uLength, cbFrameBodySize); 1189 /* Fill FIFO,RrvTime,RTS,and CTS */
1928 pr_debug("cbReqCount:%d, %d, %d, %d\n", 1190 s_vGenerateTxParameter(pDevice, byPktType, tx_buffer_head, pvRrvTime, pvRTS, pvCTS,
1929 cbReqCount, cbHeaderLength, uPadding, cbIVlen); 1191 cbFrameSize, bNeedACK, uDMAIdx, hdr, pDevice->wCurrentRate);
1930 pr_debug("MIC:%x, %x\n", *pdwMIC_L, *pdwMIC_R); 1192 /* Fill DataHead */
1193 uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
1194 0, 0, uMACfragNum, byFBOption, pDevice->wCurrentRate, is_pspoll);
1931 1195
1932 } 1196 hdr->duration_id = uDuration;
1933 1197
1934 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) { 1198 cbReqCount = cbHeaderLength + uPadding + skb->len;
1935 if (bNeedEncrypt) { 1199 pbyBuffer = (unsigned char *)pHeadTD->pTDInfo->buf;
1936 s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength - cb802_1_H_len), 1200 uLength = cbHeaderLength + uPadding;
1937 (unsigned short)(cbFrameBodySize + cbMIClen));
1938 cbReqCount += cbICVlen;
1939 }
1940 }
1941 1201
1942 ptdCurr = (PSTxDesc)pHeadTD; 1202 /* Copy the Packet into a tx Buffer */
1203 memcpy((pbyBuffer + uLength), skb->data, skb->len);
1943 1204
1944 ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding; 1205 ptdCurr = (PSTxDesc)pHeadTD;
1945 ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
1946 ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
1947 ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
1948 //Set TSR1 & ReqCount in TxDescHead
1949 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
1950 ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((unsigned short)(cbReqCount));
1951 1206
1952 pDevice->iTDUsed[uDMAIdx]++; 1207 ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
1953 1208 ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
1954 } 1209 ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
1955 *puMACfragNum = uMACfragNum; 1210 ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
1211 /* Set TSR1 & ReqCount in TxDescHead */
1212 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
1213 ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((unsigned short)(cbReqCount));
1956 1214
1957 return cbHeaderLength; 1215 return cbHeaderLength;
1958} 1216}
1959 1217
1960void 1218static void vnt_fill_txkey(struct ieee80211_hdr *hdr, u8 *key_buffer,
1961vGenerateFIFOHeader(struct vnt_private *pDevice, unsigned char byPktType, 1219 struct ieee80211_key_conf *tx_key,
1962 unsigned char *pbyTxBufferAddr, bool bNeedEncrypt, 1220 struct sk_buff *skb, u16 payload_len,
1963 unsigned int cbPayloadSize, unsigned int uDMAIdx, 1221 struct vnt_mic_hdr *mic_hdr)
1964 PSTxDesc pHeadTD, PSEthernetHeader psEthHeader, unsigned char *pPacket,
1965 PSKeyItem pTransmitKey, unsigned int uNodeIndex, unsigned int *puMACfragNum,
1966 unsigned int *pcbHeaderSize)
1967{ 1222{
1968 unsigned int wTxBufSize; // FFinfo size 1223 struct ieee80211_key_seq seq;
1969 bool bNeedACK; 1224 u8 *iv = ((u8 *)hdr + ieee80211_get_hdrlen_from_skb(skb));
1970 bool bIsAdhoc; 1225
1971 unsigned short cbMacHdLen; 1226 /* strip header and icv len from payload */
1972 PSTxBufHead pTxBufHead = (PSTxBufHead) pbyTxBufferAddr; 1227 payload_len -= ieee80211_get_hdrlen_from_skb(skb);
1973 1228 payload_len -= tx_key->icv_len;
1974 wTxBufSize = sizeof(STxBufHead); 1229
1975 1230 switch (tx_key->cipher) {
1976 memset(pTxBufHead, 0, wTxBufSize); 1231 case WLAN_CIPHER_SUITE_WEP40:
1977 //Set FIFOCTL_NEEDACK 1232 case WLAN_CIPHER_SUITE_WEP104:
1978 1233 memcpy(key_buffer, iv, 3);
1979 if ((pDevice->op_mode == NL80211_IFTYPE_ADHOC) || 1234 memcpy(key_buffer + 3, tx_key->key, tx_key->keylen);
1980 (pDevice->op_mode == NL80211_IFTYPE_AP)) { 1235
1981 if (is_multicast_ether_addr(&(psEthHeader->abyDstAddr[0]))) { 1236 if (tx_key->keylen == WLAN_KEY_LEN_WEP40) {
1982 bNeedACK = false; 1237 memcpy(key_buffer + 8, iv, 3);
1983 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK); 1238 memcpy(key_buffer + 11,
1984 } else { 1239 tx_key->key, WLAN_KEY_LEN_WEP40);
1985 bNeedACK = true;
1986 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1987 } 1240 }
1988 bIsAdhoc = true;
1989 } else {
1990 // MSDUs in Infra mode always need ACK
1991 bNeedACK = true;
1992 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
1993 bIsAdhoc = false;
1994 }
1995
1996 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
1997 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
1998
1999 //Set FIFOCTL_LHEAD
2000 if (pDevice->bLongHeader)
2001 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
2002 1241
2003 //Set FIFOCTL_GENINT 1242 break;
2004 1243 case WLAN_CIPHER_SUITE_TKIP:
2005 pTxBufHead->wFIFOCtl |= FIFOCTL_GENINT; 1244 ieee80211_get_tkip_p2k(tx_key, skb, key_buffer);
2006
2007 //Set FIFOCTL_ISDMA0
2008 if (TYPE_TXDMA0 == uDMAIdx)
2009 pTxBufHead->wFIFOCtl |= FIFOCTL_ISDMA0;
2010
2011 //Set FRAGCTL_MACHDCNT
2012 if (pDevice->bLongHeader)
2013 cbMacHdLen = WLAN_HDR_ADDR3_LEN + 6;
2014 else
2015 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2016
2017 pTxBufHead->wFragCtl |= cpu_to_le16((unsigned short)(cbMacHdLen << 10));
2018
2019 //Set packet type
2020 if (byPktType == PK_TYPE_11A) //0000 0000 0000 0000
2021 ;
2022 else if (byPktType == PK_TYPE_11B) //0000 0001 0000 0000
2023 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2024 else if (byPktType == PK_TYPE_11GB) //0000 0010 0000 0000
2025 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
2026 else if (byPktType == PK_TYPE_11GA) //0000 0011 0000 0000
2027 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
2028
2029 //Set FIFOCTL_GrpAckPolicy
2030 if (pDevice->bGrpAckPolicy == true) //0000 0100 0000 0000
2031 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2032
2033 //Set Auto Fallback Ctl
2034 if (pDevice->wCurrentRate >= RATE_18M) {
2035 if (pDevice->byAutoFBCtrl == AUTO_FB_0)
2036 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
2037 else if (pDevice->byAutoFBCtrl == AUTO_FB_1)
2038 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
2039 }
2040
2041 //Set FRAGCTL_WEPTYP
2042 pDevice->bAES = false;
2043
2044 //Set FRAGCTL_WEPTYP
2045 if (pDevice->byLocalID > REV_ID_VT3253_A1) {
2046 if ((bNeedEncrypt) && (pTransmitKey != NULL)) { //WEP enabled
2047 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
2048 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2049 } else if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
2050 if (pTransmitKey->uKeyLength != WLAN_WEP232_KEYLEN)
2051 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2052 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
2053 pTxBufHead->wFragCtl |= FRAGCTL_AES;
2054 }
2055 }
2056 }
2057
2058 RFbSetPower(pDevice, pDevice->wCurrentRate, pDevice->byCurrentCh);
2059
2060 pTxBufHead->byTxPower = pDevice->byCurPwr;
2061
2062 *pcbHeaderSize = s_cbFillTxBufHead(pDevice, byPktType, pbyTxBufferAddr, cbPayloadSize,
2063 uDMAIdx, pHeadTD, psEthHeader, pPacket, bNeedEncrypt,
2064 pTransmitKey, uNodeIndex, puMACfragNum);
2065}
2066 1245
2067/*+ 1246 break;
2068 * 1247 case WLAN_CIPHER_SUITE_CCMP:
2069 * Description:
2070 * Translate 802.3 to 802.11 header
2071 *
2072 * Parameters:
2073 * In:
2074 * pDevice - Pointer to adapter
2075 * dwTxBufferAddr - Transmit Buffer
2076 * pPacket - Packet from upper layer
2077 * cbPacketSize - Transmit Data Length
2078 * Out:
2079 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
2080 * pcbAppendPayload - size of append payload for 802.1H translation
2081 *
2082 * Return Value: none
2083 *
2084 -*/
2085 1248
2086void 1249 if (!mic_hdr)
2087vGenerateMACHeader( 1250 return;
2088 struct vnt_private *pDevice,
2089 unsigned char *pbyBufferAddr,
2090 __le16 wDuration,
2091 PSEthernetHeader psEthHeader,
2092 bool bNeedEncrypt,
2093 unsigned short wFragType,
2094 unsigned int uDMAIdx,
2095 unsigned int uFragIdx
2096)
2097{
2098 PS802_11Header pMACHeader = (PS802_11Header)pbyBufferAddr;
2099 1251
2100 memset(pMACHeader, 0, (sizeof(S802_11Header))); 1252 mic_hdr->id = 0x59;
1253 mic_hdr->payload_len = cpu_to_be16(payload_len);
1254 ether_addr_copy(mic_hdr->mic_addr2, hdr->addr2);
2101 1255
2102 if (uDMAIdx == TYPE_ATIMDMA) 1256 ieee80211_get_key_tx_seq(tx_key, &seq);
2103 pMACHeader->wFrameCtl = TYPE_802_11_ATIM;
2104 else
2105 pMACHeader->wFrameCtl = TYPE_802_11_DATA;
2106 1257
2107 if (pDevice->op_mode == NL80211_IFTYPE_AP) { 1258 memcpy(mic_hdr->ccmp_pn, seq.ccmp.pn, IEEE80211_CCMP_PN_LEN);
2108 memcpy(&(pMACHeader->abyAddr1[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
2109 memcpy(&(pMACHeader->abyAddr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
2110 memcpy(&(pMACHeader->abyAddr3[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
2111 pMACHeader->wFrameCtl |= FC_FROMDS;
2112 } else {
2113 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
2114 memcpy(&(pMACHeader->abyAddr1[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
2115 memcpy(&(pMACHeader->abyAddr2[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
2116 memcpy(&(pMACHeader->abyAddr3[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
2117 } else {
2118 memcpy(&(pMACHeader->abyAddr3[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
2119 memcpy(&(pMACHeader->abyAddr2[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
2120 memcpy(&(pMACHeader->abyAddr1[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
2121 pMACHeader->wFrameCtl |= FC_TODS;
2122 }
2123 }
2124 1259
2125 if (bNeedEncrypt) 1260 if (ieee80211_has_a4(hdr->frame_control))
2126 pMACHeader->wFrameCtl |= cpu_to_le16((unsigned short)WLAN_SET_FC_ISWEP(1)); 1261 mic_hdr->hlen = cpu_to_be16(28);
1262 else
1263 mic_hdr->hlen = cpu_to_be16(22);
2127 1264
2128 pMACHeader->wDurationID = le16_to_cpu(wDuration); 1265 ether_addr_copy(mic_hdr->addr1, hdr->addr1);
1266 ether_addr_copy(mic_hdr->addr2, hdr->addr2);
1267 ether_addr_copy(mic_hdr->addr3, hdr->addr3);
2129 1268
2130 if (pDevice->bLongHeader) { 1269 mic_hdr->frame_control = cpu_to_le16(
2131 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr; 1270 le16_to_cpu(hdr->frame_control) & 0xc78f);
1271 mic_hdr->seq_ctrl = cpu_to_le16(
1272 le16_to_cpu(hdr->seq_ctrl) & 0xf);
2132 1273
2133 pMACHeader->wFrameCtl |= (FC_TODS | FC_FROMDS); 1274 if (ieee80211_has_a4(hdr->frame_control))
2134 memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN); 1275 ether_addr_copy(mic_hdr->addr4, hdr->addr4);
2135 }
2136 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2137 1276
2138 //Set FragNumber in Sequence Control 1277 memcpy(key_buffer, tx_key->key, WLAN_KEY_LEN_CCMP);
2139 pMACHeader->wSeqCtl |= cpu_to_le16((unsigned short)uFragIdx);
2140 1278
2141 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) { 1279 break;
2142 pDevice->wSeqCounter++; 1280 default:
2143 if (pDevice->wSeqCounter > 0x0fff) 1281 break;
2144 pDevice->wSeqCounter = 0;
2145 } 1282 }
2146
2147 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) //StartFrag or MidFrag
2148 pMACHeader->wFrameCtl |= FC_MOREFRAG;
2149} 1283}
2150 1284
2151CMD_STATUS csMgmt_xmit(struct vnt_private *pDevice, PSTxMgmtPacket pPacket) 1285int vnt_generate_fifo_header(struct vnt_private *priv, u32 dma_idx,
1286 PSTxDesc head_td, struct sk_buff *skb)
2152{ 1287{
2153 PSTxDesc pFrstTD; 1288 PDEVICE_TD_INFO td_info = head_td->pTDInfo;
2154 unsigned char byPktType; 1289 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
2155 unsigned char *pbyTxBufferAddr; 1290 struct ieee80211_tx_rate *tx_rate = &info->control.rates[0];
2156 void *pvRTS; 1291 struct ieee80211_rate *rate;
2157 struct vnt_cts *pCTS; 1292 struct ieee80211_key_conf *tx_key;
2158 void *pvTxDataHd; 1293 struct ieee80211_hdr *hdr;
2159 unsigned int uDuration; 1294 struct vnt_tx_fifo_head *tx_buffer_head =
2160 unsigned int cbReqCount; 1295 (struct vnt_tx_fifo_head *)td_info->buf;
2161 PS802_11Header pMACHeader; 1296 u16 tx_body_size = skb->len, current_rate;
2162 unsigned int cbHeaderSize; 1297 u8 pkt_type;
2163 unsigned int cbFrameBodySize; 1298 bool is_pspoll = false;
2164 bool bNeedACK; 1299
2165 bool bIsPSPOLL = false; 1300 memset(tx_buffer_head, 0, sizeof(*tx_buffer_head));
2166 PSTxBufHead pTxBufHead; 1301
2167 unsigned int cbFrameSize; 1302 hdr = (struct ieee80211_hdr *)(skb->data);
2168 unsigned int cbIVlen = 0; 1303
2169 unsigned int cbICVlen = 0; 1304 rate = ieee80211_get_tx_rate(priv->hw, info);
2170 unsigned int cbMIClen = 0; 1305
2171 unsigned int cbFCSlen = 4; 1306 current_rate = rate->hw_value;
2172 unsigned int uPadding = 0; 1307 if (priv->wCurrentRate != current_rate &&
2173 unsigned short wTxBufSize; 1308 !(priv->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) {
2174 unsigned int cbMacHdLen; 1309 priv->wCurrentRate = current_rate;
2175 SEthernetHeader sEthHeader; 1310
2176 void *pvRrvTime; 1311 RFbSetPower(priv, priv->wCurrentRate,
2177 void *pMICHDR; 1312 priv->hw->conf.chandef.chan->hw_value);
2178 PSMgmtObject pMgmt = pDevice->pMgmt;
2179 unsigned short wCurrentRate = RATE_1M;
2180
2181 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0)
2182 return CMD_STATUS_RESOURCES;
2183
2184 pFrstTD = pDevice->apCurrTD[TYPE_TXDMA0];
2185 pbyTxBufferAddr = (unsigned char *)pFrstTD->pTDInfo->buf;
2186 cbFrameBodySize = pPacket->cbPayloadLen;
2187 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
2188 wTxBufSize = sizeof(STxBufHead);
2189 memset(pTxBufHead, 0, wTxBufSize);
2190
2191 if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2192 wCurrentRate = RATE_6M;
2193 byPktType = PK_TYPE_11A;
2194 } else {
2195 wCurrentRate = RATE_1M;
2196 byPktType = PK_TYPE_11B;
2197 } 1313 }
2198 1314
2199 // SetPower will cause error power TX state for OFDM Date packet in TX buffer. 1315 if (current_rate > RATE_11M)
2200 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability. 1316 pkt_type = (u8)priv->byPacketType;
2201 // And cmd timer will wait data pkt TX finish before scanning so it's OK
2202 // to set power here.
2203 if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING)
2204 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
2205 else 1317 else
2206 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel); 1318 pkt_type = PK_TYPE_11B;
2207 1319
2208 pTxBufHead->byTxPower = pDevice->byCurPwr; 1320 /*Set fifo controls */
2209 //+++++++++++++++++++++ Patch VT3253 A1 performance +++++++++++++++++++++++++++ 1321 if (pkt_type == PK_TYPE_11A)
2210 if (pDevice->byFOETuning) { 1322 tx_buffer_head->fifo_ctl = 0;
2211 if ((pPacket->p80211Header->sA3.wFrameCtl & TYPE_DATE_NULL) == TYPE_DATE_NULL) { 1323 else if (pkt_type == PK_TYPE_11B)
2212 wCurrentRate = RATE_24M; 1324 tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11B);
2213 byPktType = PK_TYPE_11GA; 1325 else if (pkt_type == PK_TYPE_11GB)
2214 } 1326 tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11GB);
2215 } 1327 else if (pkt_type == PK_TYPE_11GA)
2216 1328 tx_buffer_head->fifo_ctl = cpu_to_le16(FIFOCTL_11GA);
2217 //Set packet type 1329
2218 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000 1330 /* generate interrupt */
2219 pTxBufHead->wFIFOCtl = 0; 1331 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_GENINT);
2220 } else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000 1332
2221 pTxBufHead->wFIFOCtl |= FIFOCTL_11B; 1333 if (!ieee80211_is_data(hdr->frame_control)) {
2222 } else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000 1334 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_TMOEN);
2223 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB; 1335 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_ISDMA0);
2224 } else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000 1336 tx_buffer_head->time_stamp =
2225 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA; 1337 cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
1338 } else {
1339 tx_buffer_head->time_stamp =
1340 cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
2226 } 1341 }
2227 1342
2228 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN; 1343 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
2229 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us); 1344 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_NEEDACK);
2230 1345
2231 if (is_multicast_ether_addr(&(pPacket->p80211Header->sA3.abyAddr1[0]))) 1346 if (ieee80211_has_retry(hdr->frame_control))
2232 bNeedACK = false; 1347 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_LRETRY);
2233 else {
2234 bNeedACK = true;
2235 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2236 }
2237 1348
2238 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) || 1349 if (tx_rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
2239 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) { 1350 priv->byPreambleType = PREAMBLE_SHORT;
2240 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY; 1351 else
2241 } 1352 priv->byPreambleType = PREAMBLE_LONG;
2242 1353
2243 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0); 1354 if (tx_rate->flags & IEEE80211_TX_RC_USE_RTS_CTS)
1355 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_RTS);
2244 1356
2245 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) { 1357 if (ieee80211_has_a4(hdr->frame_control)) {
2246 bIsPSPOLL = true; 1358 tx_buffer_head->fifo_ctl |= cpu_to_le16(FIFOCTL_LHEAD);
2247 cbMacHdLen = WLAN_HDR_ADDR2_LEN; 1359 priv->bLongHeader = true;
2248 } else {
2249 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2250 } 1360 }
2251 1361
2252 //Set FRAGCTL_MACHDCNT 1362 if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER)
2253 pTxBufHead->wFragCtl |= cpu_to_le16((unsigned short)(cbMacHdLen << 10)); 1363 is_pspoll = true;
2254 1364
2255 // Notes: 1365 tx_buffer_head->frag_ctl =
2256 // Although spec says MMPDU can be fragmented; In most cases, 1366 cpu_to_le16(ieee80211_get_hdrlen_from_skb(skb) << 10);
2257 // no one will send a MMPDU under fragmentation. With RTS may occur. 1367
2258 pDevice->bAES = false; //Set FRAGCTL_WEPTYP 1368 if (info->control.hw_key) {
2259 1369 tx_key = info->control.hw_key;
2260 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) { 1370
2261 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) { 1371 switch (info->control.hw_key->cipher) {
2262 cbIVlen = 4; 1372 case WLAN_CIPHER_SUITE_WEP40:
2263 cbICVlen = 4; 1373 case WLAN_CIPHER_SUITE_WEP104:
2264 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY; 1374 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_LEGACY);
2265 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) { 1375 break;
2266 cbIVlen = 8;//IV+ExtIV 1376 case WLAN_CIPHER_SUITE_TKIP:
2267 cbMIClen = 8; 1377 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_TKIP);
2268 cbICVlen = 4; 1378 break;
2269 pTxBufHead->wFragCtl |= FRAGCTL_TKIP; 1379 case WLAN_CIPHER_SUITE_CCMP:
2270 //We need to get seed here for filling TxKey entry. 1380 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_AES);
2271 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) { 1381 default:
2272 cbIVlen = 8;//RSN Header 1382 break;
2273 cbICVlen = 8;//MIC
2274 pTxBufHead->wFragCtl |= FRAGCTL_AES;
2275 pDevice->bAES = true;
2276 } 1383 }
2277 //MAC Header should be padding 0 to DW alignment.
2278 uPadding = 4 - (cbMacHdLen%4);
2279 uPadding %= 4;
2280 } 1384 }
2281 1385
2282 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen; 1386 tx_buffer_head->current_rate = cpu_to_le16(current_rate);
2283
2284 //Set FIFOCTL_GrpAckPolicy
2285 if (pDevice->bGrpAckPolicy == true) //0000 0100 0000 0000
2286 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2287 1387
2288 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter() 1388 /* legacy rates TODO use ieee80211_tx_rate */
1389 if (current_rate >= RATE_18M && ieee80211_is_data(hdr->frame_control)) {
1390 if (priv->byAutoFBCtrl == AUTO_FB_0)
1391 tx_buffer_head->fifo_ctl |=
1392 cpu_to_le16(FIFOCTL_AUTO_FB_0);
1393 else if (priv->byAutoFBCtrl == AUTO_FB_1)
1394 tx_buffer_head->fifo_ctl |=
1395 cpu_to_le16(FIFOCTL_AUTO_FB_1);
2289 1396
2290 //Set RrvTime/RTS/CTS Buffer
2291 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
2292 pvRrvTime = (void *) (pbyTxBufferAddr + wTxBufSize);
2293 pMICHDR = NULL;
2294 pvRTS = NULL;
2295 pCTS = (struct vnt_cts *)(pbyTxBufferAddr + wTxBufSize +
2296 sizeof(struct vnt_rrv_time_cts));
2297 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize +
2298 sizeof(struct vnt_rrv_time_cts) + sizeof(struct vnt_cts));
2299 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
2300 sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
2301 } else { // 802.11a/b packet
2302 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize);
2303 pMICHDR = NULL;
2304 pvRTS = NULL;
2305 pCTS = NULL;
2306 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize +
2307 sizeof(struct vnt_rrv_time_ab));
2308 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
2309 sizeof(struct vnt_tx_datahead_ab);
2310 } 1397 }
2311 1398
2312 memset((void *)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderSize - wTxBufSize)); 1399 tx_buffer_head->frag_ctl |= cpu_to_le16(FRAGCTL_NONFRAG);
2313
2314 memcpy(&(sEthHeader.abyDstAddr[0]), &(pPacket->p80211Header->sA3.abyAddr1[0]), ETH_ALEN);
2315 memcpy(&(sEthHeader.abySrcAddr[0]), &(pPacket->p80211Header->sA3.abyAddr2[0]), ETH_ALEN);
2316 //=========================
2317 // No Fragmentation
2318 //=========================
2319 pTxBufHead->wFragCtl |= (unsigned short)FRAGCTL_NONFRAG;
2320
2321 //Fill FIFO,RrvTime,RTS,and CTS
2322 s_vGenerateTxParameter(pDevice, byPktType, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
2323 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, wCurrentRate);
2324
2325 //Fill DataHead
2326 uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
2327 0, 0, 1, AUTO_FB_NONE, wCurrentRate);
2328
2329 pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
2330
2331 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
2332
2333 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
2334 unsigned char *pbyIVHead;
2335 unsigned char *pbyPayloadHead;
2336 unsigned char *pbyBSSID;
2337 PSKeyItem pTransmitKey = NULL;
2338
2339 pbyIVHead = (unsigned char *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
2340 pbyPayloadHead = (unsigned char *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
2341
2342 //Fill TXKEY
2343 //Kyle: Need fix: TKIP and AES did't encrypt Mnt Packet.
2344 //s_vFillTxKey(pDevice, (unsigned char *)pTxBufHead->adwTxKey, NULL);
2345
2346 //Fill IV(ExtIV,RSNHDR)
2347 //s_vFillPrePayload(pDevice, pbyIVHead, NULL);
2348 //---------------------------
2349 // S/W or H/W Encryption
2350 //---------------------------
2351 do {
2352 if ((pDevice->op_mode == NL80211_IFTYPE_STATION) &&
2353 (pDevice->bLinkPass == true)) {
2354 pbyBSSID = pDevice->abyBSSID;
2355 // get pairwise key
2356 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
2357 // get group key
2358 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2359 pr_debug("Get GTK\n");
2360 break;
2361 }
2362 } else {
2363 pr_debug("Get PTK\n");
2364 break;
2365 }
2366 }
2367 // get group key
2368 pbyBSSID = pDevice->abyBroadcastAddr;
2369 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
2370 pTransmitKey = NULL;
2371 pr_debug("KEY is NULL. OP Mode[%d]\n",
2372 pDevice->op_mode);
2373 } else {
2374 pr_debug("Get GTK\n");
2375 }
2376 } while (false);
2377 //Fill TXKEY
2378 s_vFillTxKey(pDevice, (unsigned char *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
2379 (unsigned char *)pMACHeader, (unsigned short)cbFrameBodySize, NULL);
2380
2381 memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
2382 memcpy(pbyPayloadHead, ((unsigned char *)(pPacket->p80211Header) + cbMacHdLen),
2383 cbFrameBodySize);
2384 } else {
2385 // Copy the Packet into a tx Buffer
2386 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
2387 }
2388 1400
2389 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4); 1401 s_cbFillTxBufHead(priv, pkt_type, (u8 *)tx_buffer_head,
2390 pDevice->wSeqCounter++; 1402 dma_idx, head_td, is_pspoll);
2391 if (pDevice->wSeqCounter > 0x0fff)
2392 pDevice->wSeqCounter = 0;
2393
2394 if (bIsPSPOLL) {
2395 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2396 // of FIFO control header.
2397 // This will cause AID-field of PS-POLL packet to be incorrect (Because PS-POLL's AID field is
2398 // in the same place of other packet's Duration-field).
2399 // And it will cause Cisco-AP to issue Disassociation-packet
2400 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2401 ((struct vnt_tx_datahead_g *)pvTxDataHd)->duration_a = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2402 ((struct vnt_tx_datahead_g *)pvTxDataHd)->duration_b = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2403 } else {
2404 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->duration = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2405 }
2406 }
2407 1403
2408 // first TD is the only TD 1404 if (info->control.hw_key) {
2409 //Set TSR1 & ReqCount in TxDescHead 1405 tx_key = info->control.hw_key;
2410 pFrstTD->m_td1TD1.byTCR = (TCR_STP | TCR_EDP | EDMSDU); 1406 if (tx_key->keylen > 0)
2411 pFrstTD->pTDInfo->skb_dma = pFrstTD->pTDInfo->buf_dma; 1407 vnt_fill_txkey(hdr, tx_buffer_head->tx_key,
2412 pFrstTD->m_td1TD1.wReqCount = cpu_to_le16((unsigned short)(cbReqCount)); 1408 tx_key, skb, tx_body_size, td_info->mic_hdr);
2413 pFrstTD->buff_addr = cpu_to_le32(pFrstTD->pTDInfo->skb_dma);
2414 pFrstTD->pTDInfo->byFlags = 0;
2415
2416 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2417 // Disable PS
2418 MACbPSWakeup(pDevice->PortOffset);
2419 } 1409 }
2420 pDevice->bPWBitOn = false;
2421
2422 wmb();
2423 pFrstTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
2424 wmb();
2425
2426 pDevice->iTDUsed[TYPE_TXDMA0]++;
2427
2428 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 1)
2429 pr_debug(" available td0 <= 1\n");
2430
2431 pDevice->apCurrTD[TYPE_TXDMA0] = pFrstTD->next;
2432
2433 pDevice->nTxDataTimeCout = 0; //2008-8-21 chester <add> for send null packet
2434 1410
2435 // Poll Transmit the adapter 1411 return 0;
2436 MACvTransmit0(pDevice->PortOffset);
2437
2438 return CMD_STATUS_PENDING;
2439} 1412}
2440 1413
2441CMD_STATUS csBeacon_xmit(struct vnt_private *pDevice, PSTxMgmtPacket pPacket) 1414static int vnt_beacon_xmit(struct vnt_private *priv,
1415 struct sk_buff *skb)
2442{ 1416{
2443 unsigned char byPktType;
2444 unsigned char *pbyBuffer = (unsigned char *)pDevice->tx_beacon_bufs;
2445 unsigned int cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
2446 unsigned int cbHeaderSize = 0;
2447 struct vnt_tx_short_buf_head *short_head = 1417 struct vnt_tx_short_buf_head *short_head =
2448 (struct vnt_tx_short_buf_head *)pbyBuffer; 1418 (struct vnt_tx_short_buf_head *)priv->tx_beacon_bufs;
2449 PS802_11Header pMACHeader; 1419 struct ieee80211_mgmt *mgmt_hdr = (struct ieee80211_mgmt *)
2450 unsigned short wCurrentRate; 1420 (priv->tx_beacon_bufs + sizeof(*short_head));
2451 1421 struct ieee80211_tx_info *info;
2452 memset(short_head, 0, sizeof(*short_head)); 1422 u32 frame_size = skb->len + 4;
1423 u16 current_rate;
2453 1424
2454 if (pDevice->eCurrentPHYType == PHY_TYPE_11A) { 1425 memset(priv->tx_beacon_bufs, 0, sizeof(*short_head));
2455 wCurrentRate = RATE_6M;
2456 byPktType = PK_TYPE_11A;
2457 } else {
2458 wCurrentRate = RATE_2M;
2459 byPktType = PK_TYPE_11B;
2460 }
2461 1426
2462 //Set Preamble type always long 1427 if (priv->byBBType == BB_TYPE_11A) {
2463 pDevice->byPreambleType = PREAMBLE_LONG; 1428 current_rate = RATE_6M;
2464 1429
2465 /* Set FIFOCTL_GENINT */ 1430 /* Get SignalField,ServiceField,Length */
2466 short_head->fifo_ctl |= cpu_to_le16(FIFOCTL_GENINT); 1431 vnt_get_phy_field(priv, frame_size, current_rate,
2467 1432 PK_TYPE_11A, &short_head->ab);
2468 /* Set packet type & Get Duration */
2469 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
2470 short_head->duration =
2471 cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_A,
2472 cbFrameSize, byPktType, wCurrentRate, false,
2473 0, 0, 1, AUTO_FB_NONE));
2474 } else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
2475 short_head->fifo_ctl |= cpu_to_le16(FIFOCTL_11B);
2476 1433
1434 /* Get Duration and TimeStampOff */
2477 short_head->duration = 1435 short_head->duration =
2478 cpu_to_le16((u16)s_uGetDataDuration(pDevice, DATADUR_B, 1436 cpu_to_le16((u16)s_uGetDataDuration(priv, DATADUR_B,
2479 cbFrameSize, byPktType, wCurrentRate, false, 1437 frame_size, PK_TYPE_11A, current_rate,
2480 0, 0, 1, AUTO_FB_NONE)); 1438 false, 0, 0, 1, AUTO_FB_NONE));
2481 }
2482
2483 vnt_get_phy_field(pDevice, cbFrameSize,
2484 wCurrentRate, byPktType, &short_head->ab);
2485
2486 /* Get TimeStampOff */
2487 short_head->time_stamp_off = vnt_time_stamp_off(pDevice, wCurrentRate);
2488 cbHeaderSize = sizeof(struct vnt_tx_short_buf_head);
2489
2490 //Generate Beacon Header
2491 pMACHeader = (PS802_11Header)(pbyBuffer + cbHeaderSize);
2492 memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
2493
2494 pMACHeader->wDurationID = 0;
2495 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2496 pDevice->wSeqCounter++;
2497 if (pDevice->wSeqCounter > 0x0fff)
2498 pDevice->wSeqCounter = 0;
2499
2500 // Set Beacon buffer length
2501 pDevice->wBCNBufLen = pPacket->cbMPDULen + cbHeaderSize;
2502
2503 MACvSetCurrBCNTxDescAddr(pDevice->PortOffset, (pDevice->tx_beacon_dma));
2504
2505 MACvSetCurrBCNLength(pDevice->PortOffset, pDevice->wBCNBufLen);
2506 // Set auto Transmit on
2507 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
2508 // Poll Transmit the adapter
2509 MACvTransmitBCN(pDevice->PortOffset);
2510
2511 return CMD_STATUS_PENDING;
2512}
2513
2514unsigned int
2515cbGetFragCount(
2516 struct vnt_private *pDevice,
2517 PSKeyItem pTransmitKey,
2518 unsigned int cbFrameBodySize,
2519 PSEthernetHeader psEthHeader
2520)
2521{
2522 unsigned int cbMACHdLen;
2523 unsigned int cbFrameSize;
2524 unsigned int cbFragmentSize; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
2525 unsigned int cbFragPayloadSize;
2526 unsigned int cbLastFragPayloadSize;
2527 unsigned int cbIVlen = 0;
2528 unsigned int cbICVlen = 0;
2529 unsigned int cbMIClen = 0;
2530 unsigned int cbFCSlen = 4;
2531 unsigned int uMACfragNum = 1;
2532 bool bNeedACK;
2533
2534 if ((pDevice->op_mode == NL80211_IFTYPE_ADHOC) ||
2535 (pDevice->op_mode == NL80211_IFTYPE_AP)) {
2536 if (is_multicast_ether_addr(&(psEthHeader->abyDstAddr[0])))
2537 bNeedACK = false;
2538 else
2539 bNeedACK = true;
2540 } else {
2541 // MSDUs in Infra mode always need ACK
2542 bNeedACK = true;
2543 }
2544
2545 if (pDevice->bLongHeader)
2546 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
2547 else
2548 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
2549
2550 if (pDevice->bEncryptionEnable == true) {
2551 if (pTransmitKey == NULL) {
2552 if ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) ||
2553 (pDevice->pMgmt->eAuthenMode < WMAC_AUTH_WPA)) {
2554 cbIVlen = 4;
2555 cbICVlen = 4;
2556 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2557 cbIVlen = 8;//IV+ExtIV
2558 cbMIClen = 8;
2559 cbICVlen = 4;
2560 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2561 cbIVlen = 8;//RSN Header
2562 cbICVlen = 8;//MIC
2563 }
2564 } else if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
2565 cbIVlen = 4;
2566 cbICVlen = 4;
2567 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
2568 cbIVlen = 8;//IV+ExtIV
2569 cbMIClen = 8;
2570 cbICVlen = 4;
2571 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
2572 cbIVlen = 8;//RSN Header
2573 cbICVlen = 8;//MIC
2574 }
2575 }
2576
2577 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
2578
2579 if ((cbFrameSize > pDevice->wFragmentationThreshold) && (bNeedACK == true)) {
2580 // Fragmentation
2581 cbFragmentSize = pDevice->wFragmentationThreshold;
2582 cbFragPayloadSize = cbFragmentSize - cbMACHdLen - cbIVlen - cbICVlen - cbFCSlen;
2583 uMACfragNum = (unsigned short) ((cbFrameBodySize + cbMIClen) / cbFragPayloadSize);
2584 cbLastFragPayloadSize = (cbFrameBodySize + cbMIClen) % cbFragPayloadSize;
2585 if (cbLastFragPayloadSize == 0)
2586 cbLastFragPayloadSize = cbFragPayloadSize;
2587 else
2588 uMACfragNum++;
2589 }
2590 return uMACfragNum;
2591}
2592
2593void vDMA0_tx_80211(struct vnt_private *pDevice, struct sk_buff *skb,
2594 unsigned char *pbMPDU, unsigned int cbMPDULen)
2595{
2596 PSTxDesc pFrstTD;
2597 unsigned char byPktType;
2598 unsigned char *pbyTxBufferAddr;
2599 void *pvRTS;
2600 void *pvCTS;
2601 void *pvTxDataHd;
2602 unsigned int uDuration;
2603 unsigned int cbReqCount;
2604 PS802_11Header pMACHeader;
2605 unsigned int cbHeaderSize;
2606 unsigned int cbFrameBodySize;
2607 bool bNeedACK;
2608 bool bIsPSPOLL = false;
2609 PSTxBufHead pTxBufHead;
2610 unsigned int cbFrameSize;
2611 unsigned int cbIVlen = 0;
2612 unsigned int cbICVlen = 0;
2613 unsigned int cbMIClen = 0;
2614 unsigned int cbFCSlen = 4;
2615 unsigned int uPadding = 0;
2616 unsigned int cbMICHDR = 0;
2617 unsigned int uLength = 0;
2618 u32 dwMICKey0, dwMICKey1;
2619 u32 dwMIC_Priority;
2620 u32 *pdwMIC_L;
2621 u32 *pdwMIC_R;
2622 unsigned short wTxBufSize;
2623 unsigned int cbMacHdLen;
2624 SEthernetHeader sEthHeader;
2625 void *pvRrvTime;
2626 void *pMICHDR;
2627 PSMgmtObject pMgmt = pDevice->pMgmt;
2628 unsigned short wCurrentRate = RATE_1M;
2629 PUWLAN_80211HDR p80211Header;
2630 unsigned int uNodeIndex = 0;
2631 bool bNodeExist = false;
2632 SKeyItem STempKey;
2633 PSKeyItem pTransmitKey = NULL;
2634 unsigned char *pbyIVHead;
2635 unsigned char *pbyPayloadHead;
2636 unsigned char *pbyMacHdr;
2637
2638 unsigned int cbExtSuppRate = 0;
2639
2640 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
2641
2642 if (cbMPDULen <= WLAN_HDR_ADDR3_LEN)
2643 cbFrameBodySize = 0;
2644 else
2645 cbFrameBodySize = cbMPDULen - WLAN_HDR_ADDR3_LEN;
2646
2647 p80211Header = (PUWLAN_80211HDR)pbMPDU;
2648 1439
2649 pFrstTD = pDevice->apCurrTD[TYPE_TXDMA0]; 1440 short_head->time_stamp_off =
2650 pbyTxBufferAddr = (unsigned char *)pFrstTD->pTDInfo->buf; 1441 vnt_time_stamp_off(priv, current_rate);
2651 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
2652 wTxBufSize = sizeof(STxBufHead);
2653 memset(pTxBufHead, 0, wTxBufSize);
2654
2655 if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2656 wCurrentRate = RATE_6M;
2657 byPktType = PK_TYPE_11A;
2658 } else { 1442 } else {
2659 wCurrentRate = RATE_1M; 1443 current_rate = RATE_1M;
2660 byPktType = PK_TYPE_11B; 1444 short_head->fifo_ctl |= cpu_to_le16(FIFOCTL_11B);
2661 }
2662
2663 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
2664 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
2665 // And cmd timer will wait data pkt TX to finish before scanning so it's OK
2666 // to set power here.
2667 if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING)
2668 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
2669 else
2670 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
2671
2672 pTxBufHead->byTxPower = pDevice->byCurPwr;
2673
2674 //+++++++++++++++++++++ Patch VT3253 A1 performance +++++++++++++++++++++++++++
2675 if (pDevice->byFOETuning) {
2676 if ((p80211Header->sA3.wFrameCtl & TYPE_DATE_NULL) == TYPE_DATE_NULL) {
2677 wCurrentRate = RATE_24M;
2678 byPktType = PK_TYPE_11GA;
2679 }
2680 }
2681
2682 pr_debug("vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x\n",
2683 p80211Header->sA3.wFrameCtl);
2684
2685 //Set packet type
2686 if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
2687 pTxBufHead->wFIFOCtl = 0;
2688 } else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
2689 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2690 } else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
2691 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
2692 } else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
2693 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
2694 }
2695
2696 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
2697 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
2698
2699 if (is_multicast_ether_addr(&(p80211Header->sA3.abyAddr1[0]))) {
2700 bNeedACK = false;
2701 if (pDevice->bEnableHostWEP) {
2702 uNodeIndex = 0;
2703 bNodeExist = true;
2704 }
2705 } else {
2706 if (pDevice->bEnableHostWEP) {
2707 if (BSSDBbIsSTAInNodeDB(pDevice->pMgmt, (unsigned char *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
2708 bNodeExist = true;
2709 }
2710 bNeedACK = true;
2711 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2712 }
2713
2714 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
2715 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
2716 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
2717 }
2718
2719 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
2720
2721 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
2722 bIsPSPOLL = true;
2723 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
2724 } else {
2725 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2726 }
2727
2728 // hostapd deamon ext support rate patch
2729 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
2730 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2731 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
2732 1445
2733 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) 1446 /* Get SignalField,ServiceField,Length */
2734 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN; 1447 vnt_get_phy_field(priv, frame_size, current_rate,
1448 PK_TYPE_11B, &short_head->ab);
2735 1449
2736 if (cbExtSuppRate > 0) 1450 /* Get Duration and TimeStampOff */
2737 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES; 1451 short_head->duration =
2738 } 1452 cpu_to_le16((u16)s_uGetDataDuration(priv, DATADUR_B,
1453 frame_size, PK_TYPE_11B, current_rate,
1454 false, 0, 0, 1, AUTO_FB_NONE));
2739 1455
2740 //Set FRAGCTL_MACHDCNT 1456 short_head->time_stamp_off =
2741 pTxBufHead->wFragCtl |= cpu_to_le16((unsigned short)cbMacHdLen << 10); 1457 vnt_time_stamp_off(priv, current_rate);
2742
2743 // Notes:
2744 // Although spec says MMPDU can be fragmented; In most cases,
2745 // no one will send a MMPDU under fragmentation. With RTS may occur.
2746 pDevice->bAES = false; //Set FRAGCTL_WEPTYP
2747
2748 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
2749 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2750 cbIVlen = 4;
2751 cbICVlen = 4;
2752 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2753 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2754 cbIVlen = 8;//IV+ExtIV
2755 cbMIClen = 8;
2756 cbICVlen = 4;
2757 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2758 //We need to get seed here for filling TxKey entry.
2759 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2760 cbIVlen = 8;//RSN Header
2761 cbICVlen = 8;//MIC
2762 cbMICHDR = sizeof(struct vnt_mic_hdr);
2763 pTxBufHead->wFragCtl |= FRAGCTL_AES;
2764 pDevice->bAES = true;
2765 }
2766 //MAC Header should be padding 0 to DW alignment.
2767 uPadding = 4 - (cbMacHdLen%4);
2768 uPadding %= 4;
2769 } 1458 }
2770 1459
2771 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate; 1460 short_head->fifo_ctl |= cpu_to_le16(FIFOCTL_GENINT);
2772
2773 //Set FIFOCTL_GrpAckPolicy
2774 if (pDevice->bGrpAckPolicy == true) //0000 0100 0000 0000
2775 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2776
2777 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2778 1461
2779 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet 1462 /* Copy Beacon */
1463 memcpy(mgmt_hdr, skb->data, skb->len);
2780 1464
2781 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize); 1465 /* time stamp always 0 */
2782 pMICHDR = (struct vnt_mic_hdr *)(pbyTxBufferAddr + wTxBufSize + 1466 mgmt_hdr->u.beacon.timestamp = 0;
2783 sizeof(struct vnt_rrv_time_cts));
2784 pvRTS = NULL;
2785 pvCTS = (struct vnt_cts *)(pbyTxBufferAddr + wTxBufSize +
2786 sizeof(struct vnt_rrv_time_cts) + cbMICHDR);
2787 pvTxDataHd = (void *)(pbyTxBufferAddr + wTxBufSize +
2788 sizeof(struct vnt_rrv_time_cts) + cbMICHDR + sizeof(struct vnt_cts));
2789 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_cts) +
2790 cbMICHDR + sizeof(struct vnt_cts) + sizeof(struct vnt_tx_datahead_g);
2791 1467
2792 } else {//802.11a/b packet 1468 info = IEEE80211_SKB_CB(skb);
2793 1469 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
2794 pvRrvTime = (void *)(pbyTxBufferAddr + wTxBufSize); 1470 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)mgmt_hdr;
2795 pMICHDR = (struct vnt_mic_hdr *) (pbyTxBufferAddr +
2796 wTxBufSize + sizeof(struct vnt_rrv_time_ab));
2797 pvRTS = NULL;
2798 pvCTS = NULL;
2799 pvTxDataHd = (void *)(pbyTxBufferAddr +
2800 wTxBufSize + sizeof(struct vnt_rrv_time_ab) + cbMICHDR);
2801 cbHeaderSize = wTxBufSize + sizeof(struct vnt_rrv_time_ab) +
2802 cbMICHDR + sizeof(struct vnt_tx_datahead_ab);
2803 1471
1472 hdr->duration_id = 0;
1473 hdr->seq_ctrl = cpu_to_le16(priv->wSeqCounter << 4);
2804 } 1474 }
2805 1475
2806 memset((void *)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderSize - wTxBufSize)); 1476 priv->wSeqCounter++;
2807 memcpy(&(sEthHeader.abyDstAddr[0]), &(p80211Header->sA3.abyAddr1[0]), ETH_ALEN); 1477 if (priv->wSeqCounter > 0x0fff)
2808 memcpy(&(sEthHeader.abySrcAddr[0]), &(p80211Header->sA3.abyAddr2[0]), ETH_ALEN); 1478 priv->wSeqCounter = 0;
2809 //=========================
2810 // No Fragmentation
2811 //=========================
2812 pTxBufHead->wFragCtl |= (unsigned short)FRAGCTL_NONFRAG;
2813
2814 //Fill FIFO,RrvTime,RTS,and CTS
2815 s_vGenerateTxParameter(pDevice, byPktType, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
2816 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, wCurrentRate);
2817 1479
2818 //Fill DataHead 1480 priv->wBCNBufLen = sizeof(*short_head) + skb->len;
2819 uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
2820 0, 0, 1, AUTO_FB_NONE, wCurrentRate);
2821 1481
2822 pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize); 1482 MACvSetCurrBCNTxDescAddr(priv->PortOffset, priv->tx_beacon_dma);
2823 1483
2824 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate; 1484 MACvSetCurrBCNLength(priv->PortOffset, priv->wBCNBufLen);
1485 /* Set auto Transmit on */
1486 MACvRegBitsOn(priv->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
1487 /* Poll Transmit the adapter */
1488 MACvTransmitBCN(priv->PortOffset);
2825 1489
2826 pbyMacHdr = (unsigned char *)(pbyTxBufferAddr + cbHeaderSize); 1490 return 0;
2827 pbyPayloadHead = (unsigned char *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen); 1491}
2828 pbyIVHead = (unsigned char *)(pbyMacHdr + cbMacHdLen + uPadding);
2829 1492
2830 // Copy the Packet into a tx Buffer 1493int vnt_beacon_make(struct vnt_private *priv, struct ieee80211_vif *vif)
2831 memcpy(pbyMacHdr, pbMPDU, cbMacHdLen); 1494{
1495 struct sk_buff *beacon;
2832 1496
2833 // version set to 0, patch for hostapd deamon 1497 beacon = ieee80211_beacon_get(priv->hw, vif);
2834 pMACHeader->wFrameCtl &= cpu_to_le16(0xfffc); 1498 if (!beacon)
2835 memcpy(pbyPayloadHead, (pbMPDU + cbMacHdLen), cbFrameBodySize); 1499 return -ENOMEM;
2836 1500
2837 // replace support rate, patch for hostapd deamon(only support 11M) 1501 if (vnt_beacon_xmit(priv, beacon)) {
2838 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) { 1502 ieee80211_free_txskb(priv->hw, beacon);
2839 if (cbExtSuppRate != 0) { 1503 return -ENODEV;
2840 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
2841 memcpy((pbyPayloadHead + cbFrameBodySize),
2842 pMgmt->abyCurrSuppRates,
2843 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
2844);
2845 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
2846 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
2847 pMgmt->abyCurrExtSuppRates,
2848 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
2849);
2850 }
2851 } 1504 }
2852 1505
2853 // Set wep 1506 return 0;
2854 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) { 1507}
2855 if (pDevice->bEnableHostWEP) {
2856 pTransmitKey = &STempKey;
2857 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2858 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2859 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2860 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2861 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2862 memcpy(pTransmitKey->abyKey,
2863 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2864 pTransmitKey->uKeyLength
2865);
2866 }
2867
2868 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
2869 dwMICKey0 = *(u32 *)(&pTransmitKey->abyKey[16]);
2870 dwMICKey1 = *(u32 *)(&pTransmitKey->abyKey[20]);
2871
2872 // DO Software Michael
2873 MIC_vInit(dwMICKey0, dwMICKey1);
2874 MIC_vAppend((unsigned char *)&(sEthHeader.abyDstAddr[0]), 12);
2875 dwMIC_Priority = 0;
2876 MIC_vAppend((unsigned char *)&dwMIC_Priority, 4);
2877 pr_debug("DMA0_tx_8021:MIC KEY: %X, %X\n",
2878 dwMICKey0, dwMICKey1);
2879
2880 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
2881
2882 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
2883
2884 pdwMIC_L = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
2885 pdwMIC_R = (u32 *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
2886
2887 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2888 MIC_vUnInit();
2889
2890 if (pDevice->bTxMICFail == true) {
2891 *pdwMIC_L = 0;
2892 *pdwMIC_R = 0;
2893 pDevice->bTxMICFail = false;
2894 }
2895
2896 pr_debug("uLength: %d, %d\n", uLength, cbFrameBodySize);
2897 pr_debug("cbReqCount:%d, %d, %d, %d\n",
2898 cbReqCount, cbHeaderSize, uPadding, cbIVlen);
2899 pr_debug("MIC:%x, %x\n", *pdwMIC_L, *pdwMIC_R);
2900
2901 }
2902
2903 s_vFillTxKey(pDevice, (unsigned char *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
2904 pbyMacHdr, (unsigned short)cbFrameBodySize, (unsigned char *)pMICHDR);
2905
2906 if (pDevice->bEnableHostWEP) {
2907 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2908 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2909 }
2910
2911 if ((pDevice->byLocalID <= REV_ID_VT3253_A1))
2912 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (unsigned short)(cbFrameBodySize + cbMIClen));
2913 }
2914 1508
2915 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4); 1509int vnt_beacon_enable(struct vnt_private *priv, struct ieee80211_vif *vif,
2916 pDevice->wSeqCounter++; 1510 struct ieee80211_bss_conf *conf)
2917 if (pDevice->wSeqCounter > 0x0fff) 1511{
2918 pDevice->wSeqCounter = 0; 1512 int ret;
2919
2920 if (bIsPSPOLL) {
2921 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2922 // of FIFO control header.
2923 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2924 // in the same place of other packet's Duration-field).
2925 // And it will cause Cisco-AP to issue Disassociation-packet
2926 if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
2927 ((struct vnt_tx_datahead_g *)pvTxDataHd)->duration_a = cpu_to_le16(p80211Header->sA2.wDurationID);
2928 ((struct vnt_tx_datahead_g *)pvTxDataHd)->duration_b = cpu_to_le16(p80211Header->sA2.wDurationID);
2929 } else {
2930 ((struct vnt_tx_datahead_ab *)pvTxDataHd)->duration = cpu_to_le16(p80211Header->sA2.wDurationID);
2931 }
2932 }
2933 1513
2934 // first TD is the only TD 1514 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
2935 //Set TSR1 & ReqCount in TxDescHead
2936 pFrstTD->pTDInfo->skb = skb;
2937 pFrstTD->m_td1TD1.byTCR = (TCR_STP | TCR_EDP | EDMSDU);
2938 pFrstTD->pTDInfo->skb_dma = pFrstTD->pTDInfo->buf_dma;
2939 pFrstTD->m_td1TD1.wReqCount = cpu_to_le16(cbReqCount);
2940 pFrstTD->buff_addr = cpu_to_le32(pFrstTD->pTDInfo->skb_dma);
2941 pFrstTD->pTDInfo->byFlags = 0;
2942 pFrstTD->pTDInfo->byFlags |= TD_FLAGS_PRIV_SKB;
2943
2944 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2945 // Disable PS
2946 MACbPSWakeup(pDevice->PortOffset);
2947 }
2948 pDevice->bPWBitOn = false;
2949 1515
2950 wmb(); 1516 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
2951 pFrstTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
2952 wmb();
2953 1517
2954 pDevice->iTDUsed[TYPE_TXDMA0]++; 1518 CARDvSetFirstNextTBTT(priv, conf->beacon_int);
2955 1519
2956 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 1) 1520 CARDbSetBeaconPeriod(priv, conf->beacon_int);
2957 pr_debug(" available td0 <= 1\n");
2958 1521
2959 pDevice->apCurrTD[TYPE_TXDMA0] = pFrstTD->next; 1522 ret = vnt_beacon_make(priv, vif);
2960 1523
2961 // Poll Transmit the adapter 1524 return ret;
2962 MACvTransmit0(pDevice->PortOffset);
2963} 1525}
diff --git a/drivers/staging/vt6655/rxtx.h b/drivers/staging/vt6655/rxtx.h
index 8ee62887dee5..b9bd1639b13e 100644
--- a/drivers/staging/vt6655/rxtx.h
+++ b/drivers/staging/vt6655/rxtx.h
@@ -29,9 +29,11 @@
29#ifndef __RXTX_H__ 29#ifndef __RXTX_H__
30#define __RXTX_H__ 30#define __RXTX_H__
31 31
32#include "ttype.h"
33#include "device.h" 32#include "device.h"
34#include "wcmd.h" 33
34#define DEFAULT_MSDU_LIFETIME_RES_64us 8000 /* 64us */
35#define DEFAULT_MGN_LIFETIME_RES_64us 125 /* 64us */
36
35 37
36/*--------------------- Export Definitions -------------------------*/ 38/*--------------------- Export Definitions -------------------------*/
37 39
@@ -173,6 +175,14 @@ struct vnt_cts_fb {
173 u16 reserved2; 175 u16 reserved2;
174} __packed; 176} __packed;
175 177
178struct vnt_tx_fifo_head {
179 u8 tx_key[WLAN_KEY_LEN_CCMP];
180 __le16 fifo_ctl;
181 __le16 time_stamp;
182 __le16 frag_ctl;
183 __le16 current_rate;
184} __packed;
185
176struct vnt_tx_short_buf_head { 186struct vnt_tx_short_buf_head {
177 __le16 fifo_ctl; 187 __le16 fifo_ctl;
178 u16 time_stamp; 188 u16 time_stamp;
@@ -181,38 +191,10 @@ struct vnt_tx_short_buf_head {
181 __le16 time_stamp_off; 191 __le16 time_stamp_off;
182} __packed; 192} __packed;
183 193
184void 194int vnt_generate_fifo_header(struct vnt_private *, u32,
185vGenerateMACHeader( 195 PSTxDesc head_td, struct sk_buff *);
186 struct vnt_private *, 196int vnt_beacon_make(struct vnt_private *, struct ieee80211_vif *);
187 unsigned char *pbyBufferAddr, 197int vnt_beacon_enable(struct vnt_private *, struct ieee80211_vif *,
188 unsigned short wDuration, 198 struct ieee80211_bss_conf *);
189 PSEthernetHeader psEthHeader,
190 bool bNeedEncrypt,
191 unsigned short wFragType,
192 unsigned int uDMAIdx,
193 unsigned int uFragIdx
194);
195
196unsigned int
197cbGetFragCount(
198 struct vnt_private *,
199 PSKeyItem pTransmitKey,
200 unsigned int cbFrameBodySize,
201 PSEthernetHeader psEthHeader
202);
203
204void
205vGenerateFIFOHeader(struct vnt_private *, unsigned char byPktTyp,
206 unsigned char *pbyTxBufferAddr, bool bNeedEncrypt,
207 unsigned int cbPayloadSize, unsigned int uDMAIdx,
208 PSTxDesc pHeadTD, PSEthernetHeader psEthHeader,
209 unsigned char *pPacket, PSKeyItem pTransmitKey,
210 unsigned int uNodeIndex, unsigned int *puMACfragNum,
211 unsigned int *pcbHeaderSize);
212
213void vDMA0_tx_80211(struct vnt_private *, struct sk_buff *skb,
214 unsigned char *pbMPDU, unsigned int cbMPDULen);
215CMD_STATUS csMgmt_xmit(struct vnt_private *, PSTxMgmtPacket pPacket);
216CMD_STATUS csBeacon_xmit(struct vnt_private *, PSTxMgmtPacket pPacket);
217 199
218#endif // __RXTX_H__ 200#endif // __RXTX_H__
diff --git a/drivers/staging/vt6655/srom.c b/drivers/staging/vt6655/srom.c
index 5396e5832c22..9ec49e653b61 100644
--- a/drivers/staging/vt6655/srom.c
+++ b/drivers/staging/vt6655/srom.c
@@ -44,7 +44,6 @@
44 44
45#include "upc.h" 45#include "upc.h"
46#include "tmacro.h" 46#include "tmacro.h"
47#include "tether.h"
48#include "mac.h" 47#include "mac.h"
49#include "srom.h" 48#include "srom.h"
50 49
@@ -108,144 +107,6 @@ unsigned char SROMbyReadEmbedded(void __iomem *dwIoBase, unsigned char byContntO
108} 107}
109 108
110/* 109/*
111 * Description: Write a byte to EEPROM, by MAC I2C
112 *
113 * Parameters:
114 * In:
115 * dwIoBase - I/O base address
116 * byContntOffset - address of EEPROM
117 * wData - data to write
118 * Out:
119 * none
120 *
121 * Return Value: true if succeeded; false if failed.
122 *
123 */
124bool SROMbWriteEmbedded(void __iomem *dwIoBase, unsigned char byContntOffset, unsigned char byData)
125{
126 unsigned short wDelay, wNoACK;
127 unsigned char byWait;
128
129 unsigned char byOrg;
130
131 VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg);
132 /* turn off hardware retry for getting NACK */
133 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY)));
134 for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) {
135 VNSvOutPortB(dwIoBase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID);
136 VNSvOutPortB(dwIoBase + MAC_REG_I2MTGAD, byContntOffset);
137 VNSvOutPortB(dwIoBase + MAC_REG_I2MDOPT, byData);
138
139 /* issue write command */
140 VNSvOutPortB(dwIoBase + MAC_REG_I2MCSR, I2MCSR_EEMW);
141 /* wait DONE be set */
142 for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) {
143 VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait);
144 if (byWait & (I2MCSR_DONE | I2MCSR_NACK))
145 break;
146 PCAvDelayByIO(CB_DELAY_LOOP_WAIT);
147 }
148
149 if ((wDelay < W_MAX_TIMEOUT) &&
150 (!(byWait & I2MCSR_NACK))) {
151 break;
152 }
153 }
154 if (wNoACK == W_MAX_I2CRETRY) {
155 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
156 return false;
157 }
158 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
159 return true;
160}
161
162/*
163 * Description: Turn bits on in eeprom
164 *
165 * Parameters:
166 * In:
167 * dwIoBase - I/O base address
168 * byContntOffset - address of EEPROM
169 * byBits - bits to turn on
170 * Out:
171 * none
172 *
173 * Return Value: none
174 *
175 */
176void SROMvRegBitsOn(void __iomem *dwIoBase, unsigned char byContntOffset, unsigned char byBits)
177{
178 unsigned char byOrgData;
179
180 byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
181 SROMbWriteEmbedded(dwIoBase, byContntOffset, (unsigned char)(byOrgData | byBits));
182}
183
184/*
185 * Description: Turn bits off in eeprom
186 *
187 * Parameters:
188 * In:
189 * dwIoBase - I/O base address
190 * byContntOffset - address of EEPROM
191 * byBits - bits to turn off
192 * Out:
193 * none
194 *
195 */
196void SROMvRegBitsOff(void __iomem *dwIoBase, unsigned char byContntOffset, unsigned char byBits)
197{
198 unsigned char byOrgData;
199
200 byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
201 SROMbWriteEmbedded(dwIoBase, byContntOffset, (unsigned char)(byOrgData & (~byBits)));
202}
203
204/*
205 * Description: Test if bits on in eeprom
206 *
207 * Parameters:
208 * In:
209 * dwIoBase - I/O base address
210 * byContntOffset - address of EEPROM
211 * byTestBits - bits to test
212 * Out:
213 * none
214 *
215 * Return Value: true if all test bits on; otherwise false
216 *
217 */
218bool SROMbIsRegBitsOn(void __iomem *dwIoBase, unsigned char byContntOffset, unsigned char byTestBits)
219{
220 unsigned char byOrgData;
221
222 byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
223 return (byOrgData & byTestBits) == byTestBits;
224}
225
226/*
227 * Description: Test if bits off in eeprom
228 *
229 * Parameters:
230 * In:
231 * dwIoBase - I/O base address
232 * byContntOffset - address of EEPROM
233 * byTestBits - bits to test
234 * Out:
235 * none
236 *
237 * Return Value: true if all test bits off; otherwise false
238 *
239 */
240bool SROMbIsRegBitsOff(void __iomem *dwIoBase, unsigned char byContntOffset, unsigned char byTestBits)
241{
242 unsigned char byOrgData;
243
244 byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
245 return !(byOrgData & byTestBits);
246}
247
248/*
249 * Description: Read all contents of eeprom to buffer 110 * Description: Read all contents of eeprom to buffer
250 * 111 *
251 * Parameters: 112 * Parameters:
@@ -269,30 +130,6 @@ void SROMvReadAllContents(void __iomem *dwIoBase, unsigned char *pbyEepromRegs)
269} 130}
270 131
271/* 132/*
272 * Description: Write all contents of buffer to eeprom
273 *
274 * Parameters:
275 * In:
276 * dwIoBase - I/O base address
277 * pbyEepromRegs - EEPROM content Buffer
278 * Out:
279 * none
280 *
281 * Return Value: none
282 *
283 */
284void SROMvWriteAllContents(void __iomem *dwIoBase, unsigned char *pbyEepromRegs)
285{
286 int ii;
287
288 /* ii = Rom Address */
289 for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
290 SROMbWriteEmbedded(dwIoBase, (unsigned char)ii, *pbyEepromRegs);
291 pbyEepromRegs++;
292 }
293}
294
295/*
296 * Description: Read Ethernet Address from eeprom to buffer 133 * Description: Read Ethernet Address from eeprom to buffer
297 * 134 *
298 * Parameters: 135 * Parameters:
@@ -314,92 +151,3 @@ void SROMvReadEtherAddress(void __iomem *dwIoBase, unsigned char *pbyEtherAddres
314 pbyEtherAddress++; 151 pbyEtherAddress++;
315 } 152 }
316} 153}
317
318/*
319 * Description: Write Ethernet Address from buffer to eeprom
320 *
321 * Parameters:
322 * In:
323 * dwIoBase - I/O base address
324 * pbyEtherAddress - Ethernet Address buffer
325 * Out:
326 * none
327 *
328 * Return Value: none
329 *
330 */
331void SROMvWriteEtherAddress(void __iomem *dwIoBase, unsigned char *pbyEtherAddress)
332{
333 unsigned char ii;
334
335 /* ii = Rom Address */
336 for (ii = 0; ii < ETH_ALEN; ii++) {
337 SROMbWriteEmbedded(dwIoBase, ii, *pbyEtherAddress);
338 pbyEtherAddress++;
339 }
340}
341
342/*
343 * Description: Read Sub_VID and Sub_SysId from eeprom to buffer
344 *
345 * Parameters:
346 * In:
347 * dwIoBase - I/O base address
348 * Out:
349 * pdwSubSysVenId - Sub_VID and Sub_SysId read
350 *
351 * Return Value: none
352 *
353 */
354void SROMvReadSubSysVenId(void __iomem *dwIoBase, unsigned long *pdwSubSysVenId)
355{
356 unsigned char *pbyData;
357
358 pbyData = (unsigned char *)pdwSubSysVenId;
359 /* sub vendor */
360 *pbyData = SROMbyReadEmbedded(dwIoBase, 6);
361 *(pbyData+1) = SROMbyReadEmbedded(dwIoBase, 7);
362 /* sub system */
363 *(pbyData+2) = SROMbyReadEmbedded(dwIoBase, 8);
364 *(pbyData+3) = SROMbyReadEmbedded(dwIoBase, 9);
365}
366
367/*
368 * Description: Auto Load EEPROM to MAC register
369 *
370 * Parameters:
371 * In:
372 * dwIoBase - I/O base address
373 * Out:
374 * none
375 *
376 * Return Value: true if success; otherwise false
377 *
378 */
379bool SROMbAutoLoad(void __iomem *dwIoBase)
380{
381 unsigned char byWait;
382 int ii;
383
384 unsigned char byOrg;
385
386 VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg);
387 /* turn on hardware retry */
388 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg | I2MCFG_NORETRY));
389
390 MACvRegBitsOn(dwIoBase, MAC_REG_I2MCSR, I2MCSR_AUTOLD);
391
392 /* ii = Rom Address */
393 for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
394 MACvTimer0MicroSDelay(dwIoBase, CB_EEPROM_READBYTE_WAIT);
395 VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait);
396 if (!(byWait & I2MCSR_AUTOLD))
397 break;
398 }
399
400 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
401
402 if (ii == EEP_MAX_CONTEXT_SIZE)
403 return false;
404 return true;
405}
diff --git a/drivers/staging/vt6655/srom.h b/drivers/staging/vt6655/srom.h
index 3128e535bbd8..7d3e3ef9f17f 100644
--- a/drivers/staging/vt6655/srom.h
+++ b/drivers/staging/vt6655/srom.h
@@ -30,8 +30,6 @@
30#ifndef __SROM_H__ 30#ifndef __SROM_H__
31#define __SROM_H__ 31#define __SROM_H__
32 32
33#include "ttype.h"
34
35/*--------------------- Export Definitions -------------------------*/ 33/*--------------------- Export Definitions -------------------------*/
36 34
37#define EEP_MAX_CONTEXT_SIZE 256 35#define EEP_MAX_CONTEXT_SIZE 256
@@ -91,40 +89,6 @@
91 89
92/*--------------------- Export Types ------------------------------*/ 90/*--------------------- Export Types ------------------------------*/
93 91
94// AT24C02 eeprom contents
95// 2048 bits = 256 bytes = 128 words
96//
97typedef struct tagSSromReg {
98 unsigned char abyPAR[6]; // 0x00 (unsigned short)
99
100 unsigned short wSUB_VID; // 0x03 (unsigned short)
101 unsigned short wSUB_SID;
102
103 unsigned char byBCFG0; // 0x05 (unsigned short)
104 unsigned char byBCFG1;
105
106 unsigned char byFCR0; // 0x06 (unsigned short)
107 unsigned char byFCR1;
108 unsigned char byPMC0; // 0x07 (unsigned short)
109 unsigned char byPMC1;
110 unsigned char byMAXLAT; // 0x08 (unsigned short)
111 unsigned char byMINGNT;
112 unsigned char byCFG0; // 0x09 (unsigned short)
113 unsigned char byCFG1;
114 unsigned short wCISPTR; // 0x0A (unsigned short)
115 unsigned short wRsv0; // 0x0B (unsigned short)
116 unsigned short wRsv1; // 0x0C (unsigned short)
117 unsigned char byBBPAIR; // 0x0D (unsigned short)
118 unsigned char byRFTYPE;
119 unsigned char byMinChannel; // 0x0E (unsigned short)
120 unsigned char byMaxChannel;
121 unsigned char bySignature; // 0x0F (unsigned short)
122 unsigned char byCheckSum;
123
124 unsigned char abyReserved0[96]; // 0x10 (unsigned short)
125 unsigned char abyCIS[128]; // 0x80 (unsigned short)
126} SSromReg, *PSSromReg;
127
128/*--------------------- Export Macros ------------------------------*/ 92/*--------------------- Export Macros ------------------------------*/
129 93
130/*--------------------- Export Classes ----------------------------*/ 94/*--------------------- Export Classes ----------------------------*/
@@ -134,22 +98,9 @@ typedef struct tagSSromReg {
134/*--------------------- Export Functions --------------------------*/ 98/*--------------------- Export Functions --------------------------*/
135 99
136unsigned char SROMbyReadEmbedded(void __iomem *dwIoBase, unsigned char byContntOffset); 100unsigned char SROMbyReadEmbedded(void __iomem *dwIoBase, unsigned char byContntOffset);
137bool SROMbWriteEmbedded(void __iomem *dwIoBase, unsigned char byContntOffset, unsigned char byData);
138
139void SROMvRegBitsOn(void __iomem *dwIoBase, unsigned char byContntOffset, unsigned char byBits);
140void SROMvRegBitsOff(void __iomem *dwIoBase, unsigned char byContntOffset, unsigned char byBits);
141
142bool SROMbIsRegBitsOn(void __iomem *dwIoBase, unsigned char byContntOffset, unsigned char byTestBits);
143bool SROMbIsRegBitsOff(void __iomem *dwIoBase, unsigned char byContntOffset, unsigned char byTestBits);
144 101
145void SROMvReadAllContents(void __iomem *dwIoBase, unsigned char *pbyEepromRegs); 102void SROMvReadAllContents(void __iomem *dwIoBase, unsigned char *pbyEepromRegs);
146void SROMvWriteAllContents(void __iomem *dwIoBase, unsigned char *pbyEepromRegs);
147 103
148void SROMvReadEtherAddress(void __iomem *dwIoBase, unsigned char *pbyEtherAddress); 104void SROMvReadEtherAddress(void __iomem *dwIoBase, unsigned char *pbyEtherAddress);
149void SROMvWriteEtherAddress(void __iomem *dwIoBase, unsigned char *pbyEtherAddress);
150
151void SROMvReadSubSysVenId(void __iomem *dwIoBase, unsigned long *pdwSubSysVenId);
152
153bool SROMbAutoLoad(void __iomem *dwIoBase);
154 105
155#endif // __EEPROM_H__ 106#endif // __EEPROM_H__
diff --git a/drivers/staging/vt6655/tcrc.c b/drivers/staging/vt6655/tcrc.c
deleted file mode 100644
index ddc5efd040f9..000000000000
--- a/drivers/staging/vt6655/tcrc.c
+++ /dev/null
@@ -1,191 +0,0 @@
1/*
2 * Copyright (c) 2003 VIA Networking, Inc. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 *
19 * File: tcrc.c
20 *
21 * Purpose: Implement functions to calculate CRC
22 *
23 * Author: Tevin Chen
24 *
25 * Date: May 21, 1996
26 *
27 * Functions:
28 * CRCdwCrc32 -
29 * CRCdwGetCrc32 -
30 * CRCdwGetCrc32Ex -
31 *
32 * Revision History:
33 *
34 */
35
36#include "tcrc.h"
37
38/*--------------------- Static Definitions -------------------------*/
39
40/*--------------------- Static Classes ----------------------------*/
41
42/*--------------------- Static Variables --------------------------*/
43
44/* 32-bit CRC table */
45static const unsigned long s_adwCrc32Table[256] = {
46 0x00000000L, 0x77073096L, 0xEE0E612CL, 0x990951BAL,
47 0x076DC419L, 0x706AF48FL, 0xE963A535L, 0x9E6495A3L,
48 0x0EDB8832L, 0x79DCB8A4L, 0xE0D5E91EL, 0x97D2D988L,
49 0x09B64C2BL, 0x7EB17CBDL, 0xE7B82D07L, 0x90BF1D91L,
50 0x1DB71064L, 0x6AB020F2L, 0xF3B97148L, 0x84BE41DEL,
51 0x1ADAD47DL, 0x6DDDE4EBL, 0xF4D4B551L, 0x83D385C7L,
52 0x136C9856L, 0x646BA8C0L, 0xFD62F97AL, 0x8A65C9ECL,
53 0x14015C4FL, 0x63066CD9L, 0xFA0F3D63L, 0x8D080DF5L,
54 0x3B6E20C8L, 0x4C69105EL, 0xD56041E4L, 0xA2677172L,
55 0x3C03E4D1L, 0x4B04D447L, 0xD20D85FDL, 0xA50AB56BL,
56 0x35B5A8FAL, 0x42B2986CL, 0xDBBBC9D6L, 0xACBCF940L,
57 0x32D86CE3L, 0x45DF5C75L, 0xDCD60DCFL, 0xABD13D59L,
58 0x26D930ACL, 0x51DE003AL, 0xC8D75180L, 0xBFD06116L,
59 0x21B4F4B5L, 0x56B3C423L, 0xCFBA9599L, 0xB8BDA50FL,
60 0x2802B89EL, 0x5F058808L, 0xC60CD9B2L, 0xB10BE924L,
61 0x2F6F7C87L, 0x58684C11L, 0xC1611DABL, 0xB6662D3DL,
62 0x76DC4190L, 0x01DB7106L, 0x98D220BCL, 0xEFD5102AL,
63 0x71B18589L, 0x06B6B51FL, 0x9FBFE4A5L, 0xE8B8D433L,
64 0x7807C9A2L, 0x0F00F934L, 0x9609A88EL, 0xE10E9818L,
65 0x7F6A0DBBL, 0x086D3D2DL, 0x91646C97L, 0xE6635C01L,
66 0x6B6B51F4L, 0x1C6C6162L, 0x856530D8L, 0xF262004EL,
67 0x6C0695EDL, 0x1B01A57BL, 0x8208F4C1L, 0xF50FC457L,
68 0x65B0D9C6L, 0x12B7E950L, 0x8BBEB8EAL, 0xFCB9887CL,
69 0x62DD1DDFL, 0x15DA2D49L, 0x8CD37CF3L, 0xFBD44C65L,
70 0x4DB26158L, 0x3AB551CEL, 0xA3BC0074L, 0xD4BB30E2L,
71 0x4ADFA541L, 0x3DD895D7L, 0xA4D1C46DL, 0xD3D6F4FBL,
72 0x4369E96AL, 0x346ED9FCL, 0xAD678846L, 0xDA60B8D0L,
73 0x44042D73L, 0x33031DE5L, 0xAA0A4C5FL, 0xDD0D7CC9L,
74 0x5005713CL, 0x270241AAL, 0xBE0B1010L, 0xC90C2086L,
75 0x5768B525L, 0x206F85B3L, 0xB966D409L, 0xCE61E49FL,
76 0x5EDEF90EL, 0x29D9C998L, 0xB0D09822L, 0xC7D7A8B4L,
77 0x59B33D17L, 0x2EB40D81L, 0xB7BD5C3BL, 0xC0BA6CADL,
78 0xEDB88320L, 0x9ABFB3B6L, 0x03B6E20CL, 0x74B1D29AL,
79 0xEAD54739L, 0x9DD277AFL, 0x04DB2615L, 0x73DC1683L,
80 0xE3630B12L, 0x94643B84L, 0x0D6D6A3EL, 0x7A6A5AA8L,
81 0xE40ECF0BL, 0x9309FF9DL, 0x0A00AE27L, 0x7D079EB1L,
82 0xF00F9344L, 0x8708A3D2L, 0x1E01F268L, 0x6906C2FEL,
83 0xF762575DL, 0x806567CBL, 0x196C3671L, 0x6E6B06E7L,
84 0xFED41B76L, 0x89D32BE0L, 0x10DA7A5AL, 0x67DD4ACCL,
85 0xF9B9DF6FL, 0x8EBEEFF9L, 0x17B7BE43L, 0x60B08ED5L,
86 0xD6D6A3E8L, 0xA1D1937EL, 0x38D8C2C4L, 0x4FDFF252L,
87 0xD1BB67F1L, 0xA6BC5767L, 0x3FB506DDL, 0x48B2364BL,
88 0xD80D2BDAL, 0xAF0A1B4CL, 0x36034AF6L, 0x41047A60L,
89 0xDF60EFC3L, 0xA867DF55L, 0x316E8EEFL, 0x4669BE79L,
90 0xCB61B38CL, 0xBC66831AL, 0x256FD2A0L, 0x5268E236L,
91 0xCC0C7795L, 0xBB0B4703L, 0x220216B9L, 0x5505262FL,
92 0xC5BA3BBEL, 0xB2BD0B28L, 0x2BB45A92L, 0x5CB36A04L,
93 0xC2D7FFA7L, 0xB5D0CF31L, 0x2CD99E8BL, 0x5BDEAE1DL,
94 0x9B64C2B0L, 0xEC63F226L, 0x756AA39CL, 0x026D930AL,
95 0x9C0906A9L, 0xEB0E363FL, 0x72076785L, 0x05005713L,
96 0x95BF4A82L, 0xE2B87A14L, 0x7BB12BAEL, 0x0CB61B38L,
97 0x92D28E9BL, 0xE5D5BE0DL, 0x7CDCEFB7L, 0x0BDBDF21L,
98 0x86D3D2D4L, 0xF1D4E242L, 0x68DDB3F8L, 0x1FDA836EL,
99 0x81BE16CDL, 0xF6B9265BL, 0x6FB077E1L, 0x18B74777L,
100 0x88085AE6L, 0xFF0F6A70L, 0x66063BCAL, 0x11010B5CL,
101 0x8F659EFFL, 0xF862AE69L, 0x616BFFD3L, 0x166CCF45L,
102 0xA00AE278L, 0xD70DD2EEL, 0x4E048354L, 0x3903B3C2L,
103 0xA7672661L, 0xD06016F7L, 0x4969474DL, 0x3E6E77DBL,
104 0xAED16A4AL, 0xD9D65ADCL, 0x40DF0B66L, 0x37D83BF0L,
105 0xA9BCAE53L, 0xDEBB9EC5L, 0x47B2CF7FL, 0x30B5FFE9L,
106 0xBDBDF21CL, 0xCABAC28AL, 0x53B39330L, 0x24B4A3A6L,
107 0xBAD03605L, 0xCDD70693L, 0x54DE5729L, 0x23D967BFL,
108 0xB3667A2EL, 0xC4614AB8L, 0x5D681B02L, 0x2A6F2B94L,
109 0xB40BBE37L, 0xC30C8EA1L, 0x5A05DF1BL, 0x2D02EF8DL
110};
111
112/*--------------------- Static Functions --------------------------*/
113
114/*--------------------- Export Variables --------------------------*/
115
116/*+
117 *
118 * Description:
119 * Generate a CRC-32 from the data stream
120 *
121 * Parameters:
122 * In:
123 * pbyData - the data stream
124 * cbByte - the length of the stream
125 * dwCrcSeed - Seed for CRC32
126 * Out:
127 * none
128 *
129 * Return Value: CRC-32
130 *
131 -*/
132unsigned long CRCdwCrc32(unsigned char *pbyData, unsigned int cbByte, unsigned long dwCrcSeed)
133{
134 unsigned long dwCrc;
135
136 dwCrc = dwCrcSeed;
137 while (cbByte--) {
138 dwCrc = s_adwCrc32Table[(unsigned char)((dwCrc ^ (*pbyData)) & 0xFF)] ^ (dwCrc >> 8);
139 pbyData++;
140 }
141
142 return dwCrc;
143}
144
145/*+
146 *
147 * Description:
148 * To test CRC generator, input 8 bytes packet
149 * -- 0xff 0xff 0xff 0xff 0x00 0x00 0x00 0x00
150 * the generated CRC should be
151 * -- 0xff 0xff 0xff 0xff
152 *
153 * Parameters:
154 * In:
155 * pbyData - the data stream
156 * cbByte - the length of the stream
157 * Out:
158 * none
159 *
160 * Return Value: CRC-32
161 *
162 -*/
163unsigned long CRCdwGetCrc32(unsigned char *pbyData, unsigned int cbByte)
164{
165 return ~CRCdwCrc32(pbyData, cbByte, 0xFFFFFFFFL);
166}
167
168/*+
169 *
170 * Description:
171 *
172 * NOTE.... Because CRCdwGetCrc32Ex() is an iteration function,
173 * this means we will use the output of CRCdwGetCrc32Ex()
174 * to be a new argument to do next CRCdwGetCrc32Ex() calculation.
175 * Thus, the final result must be inverted to be the
176 * correct answer.
177 *
178 * Parameters:
179 * In:
180 * pbyData - the data stream
181 * cbByte - the length of the stream
182 * Out:
183 * none
184 *
185 * Return Value: CRC-32
186 *
187 -*/
188unsigned long CRCdwGetCrc32Ex(unsigned char *pbyData, unsigned int cbByte, unsigned long dwPreCRC)
189{
190 return CRCdwCrc32(pbyData, cbByte, dwPreCRC);
191}
diff --git a/drivers/staging/vt6655/tcrc.h b/drivers/staging/vt6655/tcrc.h
deleted file mode 100644
index 82b5ddafae55..000000000000
--- a/drivers/staging/vt6655/tcrc.h
+++ /dev/null
@@ -1,50 +0,0 @@
1/*
2 * Copyright (c) 2003 VIA Networking, Inc. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 *
19 * File: tcrc.h
20 *
21 * Purpose: Implement functions to calculate CRC
22 *
23 * Author: Tevin Chen
24 *
25 * Date: Jan. 28, 1997
26 *
27 */
28
29#ifndef __TCRC_H__
30#define __TCRC_H__
31
32#include "ttype.h"
33
34/*--------------------- Export Definitions -------------------------*/
35
36/*--------------------- Export Types ------------------------------*/
37
38/*--------------------- Export Macros ------------------------------*/
39
40/*--------------------- Export Classes ----------------------------*/
41
42/*--------------------- Export Variables --------------------------*/
43
44/*--------------------- Export Functions --------------------------*/
45
46unsigned long CRCdwCrc32(unsigned char *pbyData, unsigned int cbByte, unsigned long dwCrcSeed);
47unsigned long CRCdwGetCrc32(unsigned char *pbyData, unsigned int cbByte);
48unsigned long CRCdwGetCrc32Ex(unsigned char *pbyData, unsigned int cbByte, unsigned long dwPreCRC);
49
50#endif // __TCRC_H__
diff --git a/drivers/staging/vt6655/tether.c b/drivers/staging/vt6655/tether.c
deleted file mode 100644
index 1e7d3e2115a9..000000000000
--- a/drivers/staging/vt6655/tether.c
+++ /dev/null
@@ -1,105 +0,0 @@
1/*
2 * Copyright (c) 2003 VIA Networking, Inc. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 *
19 * File: tether.c
20 *
21 * Purpose:
22 *
23 * Author: Tevin Chen
24 *
25 * Date: May 21, 1996
26 *
27 * Functions:
28 * ETHbyGetHashIndexByCrc32 - Calculate multicast hash value by CRC32
29 * ETHbIsBufferCrc32Ok - Check CRC value of the buffer if Ok or not
30 *
31 * Revision History:
32 *
33 */
34
35#include "device.h"
36#include "tmacro.h"
37#include "tcrc.h"
38#include "tether.h"
39
40/*--------------------- Static Definitions -------------------------*/
41
42/*--------------------- Static Classes ----------------------------*/
43
44/*--------------------- Static Variables --------------------------*/
45
46/*--------------------- Static Functions --------------------------*/
47
48/*--------------------- Export Variables --------------------------*/
49
50/*
51 * Description: Calculate multicast hash value by CRC32
52 *
53 * Parameters:
54 * In:
55 * pbyMultiAddr - Multicast Address
56 * Out:
57 * none
58 *
59 * Return Value: Hash value
60 *
61 */
62unsigned char ETHbyGetHashIndexByCrc32(unsigned char *pbyMultiAddr)
63{
64 int ii;
65 unsigned char byTmpHash;
66 unsigned char byHash = 0;
67
68 // get the least 6-bits from CRC generator
69 byTmpHash = (unsigned char)(CRCdwCrc32(pbyMultiAddr, ETH_ALEN,
70 0xFFFFFFFFL) & 0x3F);
71 // reverse most bit to least bit
72 for (ii = 0; ii < (sizeof(byTmpHash) * 8); ii++) {
73 byHash <<= 1;
74 if (byTmpHash & 0x01)
75 byHash |= 1;
76 byTmpHash >>= 1;
77 }
78
79 // adjust 6-bits to the right most
80 return byHash >> 2;
81}
82
83/*
84 * Description: Check CRC value of the buffer if Ok or not
85 *
86 * Parameters:
87 * In:
88 * pbyBuffer - pointer of buffer (normally is rx buffer)
89 * cbFrameLength - length of buffer, including CRC portion
90 * Out:
91 * none
92 *
93 * Return Value: true if ok; false if error.
94 *
95 */
96bool ETHbIsBufferCrc32Ok(unsigned char *pbyBuffer, unsigned int cbFrameLength)
97{
98 unsigned long dwCRC;
99
100 dwCRC = CRCdwGetCrc32(pbyBuffer, cbFrameLength - 4);
101 if (cpu_to_le32(*((unsigned long *)(pbyBuffer + cbFrameLength - 4))) != dwCRC)
102 return false;
103
104 return true;
105}
diff --git a/drivers/staging/vt6655/tether.h b/drivers/staging/vt6655/tether.h
deleted file mode 100644
index 94cc8830d8cc..000000000000
--- a/drivers/staging/vt6655/tether.h
+++ /dev/null
@@ -1,192 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: tether.h
20 *
21 * Purpose:
22 *
23 * Author: Tevin Chen
24 *
25 * Date: Jan. 28, 1997
26 *
27 */
28
29#ifndef __TETHER_H__
30#define __TETHER_H__
31
32#include <linux/etherdevice.h>
33#include "ttype.h"
34
35/*--------------------- Export Definitions -------------------------*/
36//
37// constants
38//
39#define U_ETHER_ADDR_STR_LEN (ETH_ALEN * 2 + 1)
40// Ethernet address string length
41
42#define MAX_LOOKAHEAD_SIZE ETH_FRAME_LEN
43
44#define U_MULTI_ADDR_LEN 8 // multicast address length
45
46#ifdef __BIG_ENDIAN
47
48#define TYPE_PKT_IP 0x0800 //
49#define TYPE_PKT_ARP 0x0806 //
50#define TYPE_PKT_RARP 0x8035 //
51#define TYPE_PKT_IPX 0x8137 //
52#define TYPE_PKT_802_1x 0x888e
53#define TYPE_PKT_PreAuth 0x88C7
54
55#define TYPE_PKT_PING_M_REQ 0x8011 // master reguest
56#define TYPE_PKT_PING_S_GNT 0x8022 // slave grant
57#define TYPE_PKT_PING_M 0x8077 // pingpong master packet
58#define TYPE_PKT_PING_S 0x8088 // pingpong slave packet
59#define TYPE_PKT_WOL_M_REQ 0x8033 // WOL waker request
60#define TYPE_PKT_WOL_S_GNT 0x8044 // WOL sleeper grant
61#define TYPE_MGMT_PROBE_RSP 0x5000
62#define TYPE_PKT_VNT_DIAG 0x8011 // Diag Pkt
63#define TYPE_PKT_VNT_PER 0x8888 // Diag PER Pkt
64//
65// wFrameCtl field in the S802_11Header
66//
67// NOTE....
68// in network byte order, high byte is going first
69#define FC_TODS 0x0001
70#define FC_FROMDS 0x0002
71#define FC_MOREFRAG 0x0004
72#define FC_RETRY 0x0008
73#define FC_POWERMGT 0x0010
74#define FC_MOREDATA 0x0020
75#define FC_WEP 0x0040
76#define TYPE_802_11_ATIM 0x9000
77
78#define TYPE_802_11_DATA 0x0800
79#define TYPE_802_11_CTL 0x0400
80#define TYPE_802_11_MGMT 0x0000
81#define TYPE_802_11_MASK 0x0C00
82#define TYPE_SUBTYPE_MASK 0xFC00
83#define TYPE_802_11_NODATA 0x4000
84#define TYPE_DATE_NULL 0x4800
85
86#define TYPE_CTL_PSPOLL 0xa400
87#define TYPE_CTL_RTS 0xb400
88#define TYPE_CTL_CTS 0xc400
89#define TYPE_CTL_ACK 0xd400
90
91#else //if LITTLE_ENDIAN
92//
93// wType field in the SEthernetHeader
94//
95// NOTE....
96// in network byte order, high byte is going first
97#define TYPE_PKT_IP 0x0008 //
98#define TYPE_PKT_ARP 0x0608 //
99#define TYPE_PKT_RARP 0x3580 //
100#define TYPE_PKT_IPX 0x3781 //
101
102#define TYPE_PKT_802_1x 0x8e88
103#define TYPE_PKT_PreAuth 0xC788
104
105#define TYPE_PKT_PING_M_REQ 0x1180 // master reguest
106#define TYPE_PKT_PING_S_GNT 0x2280 // slave grant
107#define TYPE_PKT_PING_M 0x7780 // pingpong master packet
108#define TYPE_PKT_PING_S 0x8880 // pingpong slave packet
109#define TYPE_PKT_WOL_M_REQ 0x3380 // WOL waker request
110#define TYPE_PKT_WOL_S_GNT 0x4480 // WOL sleeper grant
111#define TYPE_MGMT_PROBE_RSP 0x0050
112#define TYPE_PKT_VNT_DIAG 0x1180 // Diag Pkt
113#define TYPE_PKT_VNT_PER 0x8888 // Diag PER Pkt
114//
115// wFrameCtl field in the S802_11Header
116//
117// NOTE....
118// in network byte order, high byte is going first
119#define FC_TODS 0x0100
120#define FC_FROMDS 0x0200
121#define FC_MOREFRAG 0x0400
122#define FC_RETRY 0x0800
123#define FC_POWERMGT 0x1000
124#define FC_MOREDATA 0x2000
125#define FC_WEP 0x4000
126#define TYPE_802_11_ATIM 0x0090
127
128#define TYPE_802_11_DATA 0x0008
129#define TYPE_802_11_CTL 0x0004
130#define TYPE_802_11_MGMT 0x0000
131#define TYPE_802_11_MASK 0x000C
132#define TYPE_SUBTYPE_MASK 0x00FC
133#define TYPE_802_11_NODATA 0x0040
134#define TYPE_DATE_NULL 0x0048
135
136#define TYPE_CTL_PSPOLL 0x00a4
137#define TYPE_CTL_RTS 0x00b4
138#define TYPE_CTL_CTS 0x00c4
139#define TYPE_CTL_ACK 0x00d4
140
141#endif //#ifdef __BIG_ENDIAN
142
143#define WEP_IV_MASK 0x00FFFFFF
144
145/*--------------------- Export Types ------------------------------*/
146//
147// Ethernet packet
148//
149typedef struct tagSEthernetHeader {
150 unsigned char abyDstAddr[ETH_ALEN];
151 unsigned char abySrcAddr[ETH_ALEN];
152 unsigned short wType;
153} __attribute__ ((__packed__))
154SEthernetHeader, *PSEthernetHeader;
155
156//
157// 802_3 packet
158//
159typedef struct tagS802_3Header {
160 unsigned char abyDstAddr[ETH_ALEN];
161 unsigned char abySrcAddr[ETH_ALEN];
162 unsigned short wLen;
163} __attribute__ ((__packed__))
164S802_3Header, *PS802_3Header;
165
166//
167// 802_11 packet
168//
169typedef struct tagS802_11Header {
170 unsigned short wFrameCtl;
171 unsigned short wDurationID;
172 unsigned char abyAddr1[ETH_ALEN];
173 unsigned char abyAddr2[ETH_ALEN];
174 unsigned char abyAddr3[ETH_ALEN];
175 unsigned short wSeqCtl;
176 unsigned char abyAddr4[ETH_ALEN];
177} __attribute__ ((__packed__))
178S802_11Header, *PS802_11Header;
179
180/*--------------------- Export Macros ------------------------------*/
181
182/*--------------------- Export Classes ----------------------------*/
183
184/*--------------------- Export Variables --------------------------*/
185
186/*--------------------- Export Functions --------------------------*/
187
188unsigned char ETHbyGetHashIndexByCrc32(unsigned char *pbyMultiAddr);
189//unsigned char ETHbyGetHashIndexByCrc(unsigned char *pbyMultiAddr);
190bool ETHbIsBufferCrc32Ok(unsigned char *pbyBuffer, unsigned int cbFrameLength);
191
192#endif // __TETHER_H__
diff --git a/drivers/staging/vt6655/tkip.c b/drivers/staging/vt6655/tkip.c
deleted file mode 100644
index f758d021c60e..000000000000
--- a/drivers/staging/vt6655/tkip.c
+++ /dev/null
@@ -1,268 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: tkip.c
21 *
22 * Purpose: Implement functions for 802.11i TKIP
23 *
24 * Author: Jerry Chen
25 *
26 * Date: Mar. 11, 2003
27 *
28 * Functions:
29 * TKIPvMixKey - Get TKIP RC4 Key from TK,TA, and TSC
30 *
31 * Revision History:
32 *
33 */
34
35#include "tmacro.h"
36#include "tkip.h"
37
38/*--------------------- Static Definitions -------------------------*/
39
40/*--------------------- Static Classes ----------------------------*/
41
42/*--------------------- Static Variables --------------------------*/
43
44/*--------------------- Static Functions --------------------------*/
45
46/*--------------------- Export Variables --------------------------*/
47
48/*--------------------- Static Definitions -------------------------*/
49
50/*--------------------- Static Classes ----------------------------*/
51
52/*--------------------- Static Variables --------------------------*/
53
54/* The Sbox is reduced to 2 16-bit wide tables, each with 256 entries. */
55/* The 2nd table is the same as the 1st but with the upper and lower */
56/* bytes swapped. To allow an endian tolerant implementation, the byte */
57/* halves have been expressed independently here. */
58static const unsigned char TKIP_Sbox_Lower[256] = {
59 0xA5, 0x84, 0x99, 0x8D, 0x0D, 0xBD, 0xB1, 0x54,
60 0x50, 0x03, 0xA9, 0x7D, 0x19, 0x62, 0xE6, 0x9A,
61 0x45, 0x9D, 0x40, 0x87, 0x15, 0xEB, 0xC9, 0x0B,
62 0xEC, 0x67, 0xFD, 0xEA, 0xBF, 0xF7, 0x96, 0x5B,
63 0xC2, 0x1C, 0xAE, 0x6A, 0x5A, 0x41, 0x02, 0x4F,
64 0x5C, 0xF4, 0x34, 0x08, 0x93, 0x73, 0x53, 0x3F,
65 0x0C, 0x52, 0x65, 0x5E, 0x28, 0xA1, 0x0F, 0xB5,
66 0x09, 0x36, 0x9B, 0x3D, 0x26, 0x69, 0xCD, 0x9F,
67 0x1B, 0x9E, 0x74, 0x2E, 0x2D, 0xB2, 0xEE, 0xFB,
68 0xF6, 0x4D, 0x61, 0xCE, 0x7B, 0x3E, 0x71, 0x97,
69 0xF5, 0x68, 0x00, 0x2C, 0x60, 0x1F, 0xC8, 0xED,
70 0xBE, 0x46, 0xD9, 0x4B, 0xDE, 0xD4, 0xE8, 0x4A,
71 0x6B, 0x2A, 0xE5, 0x16, 0xC5, 0xD7, 0x55, 0x94,
72 0xCF, 0x10, 0x06, 0x81, 0xF0, 0x44, 0xBA, 0xE3,
73 0xF3, 0xFE, 0xC0, 0x8A, 0xAD, 0xBC, 0x48, 0x04,
74 0xDF, 0xC1, 0x75, 0x63, 0x30, 0x1A, 0x0E, 0x6D,
75 0x4C, 0x14, 0x35, 0x2F, 0xE1, 0xA2, 0xCC, 0x39,
76 0x57, 0xF2, 0x82, 0x47, 0xAC, 0xE7, 0x2B, 0x95,
77 0xA0, 0x98, 0xD1, 0x7F, 0x66, 0x7E, 0xAB, 0x83,
78 0xCA, 0x29, 0xD3, 0x3C, 0x79, 0xE2, 0x1D, 0x76,
79 0x3B, 0x56, 0x4E, 0x1E, 0xDB, 0x0A, 0x6C, 0xE4,
80 0x5D, 0x6E, 0xEF, 0xA6, 0xA8, 0xA4, 0x37, 0x8B,
81 0x32, 0x43, 0x59, 0xB7, 0x8C, 0x64, 0xD2, 0xE0,
82 0xB4, 0xFA, 0x07, 0x25, 0xAF, 0x8E, 0xE9, 0x18,
83 0xD5, 0x88, 0x6F, 0x72, 0x24, 0xF1, 0xC7, 0x51,
84 0x23, 0x7C, 0x9C, 0x21, 0xDD, 0xDC, 0x86, 0x85,
85 0x90, 0x42, 0xC4, 0xAA, 0xD8, 0x05, 0x01, 0x12,
86 0xA3, 0x5F, 0xF9, 0xD0, 0x91, 0x58, 0x27, 0xB9,
87 0x38, 0x13, 0xB3, 0x33, 0xBB, 0x70, 0x89, 0xA7,
88 0xB6, 0x22, 0x92, 0x20, 0x49, 0xFF, 0x78, 0x7A,
89 0x8F, 0xF8, 0x80, 0x17, 0xDA, 0x31, 0xC6, 0xB8,
90 0xC3, 0xB0, 0x77, 0x11, 0xCB, 0xFC, 0xD6, 0x3A
91};
92
93static const unsigned char TKIP_Sbox_Upper[256] = {
94 0xC6, 0xF8, 0xEE, 0xF6, 0xFF, 0xD6, 0xDE, 0x91,
95 0x60, 0x02, 0xCE, 0x56, 0xE7, 0xB5, 0x4D, 0xEC,
96 0x8F, 0x1F, 0x89, 0xFA, 0xEF, 0xB2, 0x8E, 0xFB,
97 0x41, 0xB3, 0x5F, 0x45, 0x23, 0x53, 0xE4, 0x9B,
98 0x75, 0xE1, 0x3D, 0x4C, 0x6C, 0x7E, 0xF5, 0x83,
99 0x68, 0x51, 0xD1, 0xF9, 0xE2, 0xAB, 0x62, 0x2A,
100 0x08, 0x95, 0x46, 0x9D, 0x30, 0x37, 0x0A, 0x2F,
101 0x0E, 0x24, 0x1B, 0xDF, 0xCD, 0x4E, 0x7F, 0xEA,
102 0x12, 0x1D, 0x58, 0x34, 0x36, 0xDC, 0xB4, 0x5B,
103 0xA4, 0x76, 0xB7, 0x7D, 0x52, 0xDD, 0x5E, 0x13,
104 0xA6, 0xB9, 0x00, 0xC1, 0x40, 0xE3, 0x79, 0xB6,
105 0xD4, 0x8D, 0x67, 0x72, 0x94, 0x98, 0xB0, 0x85,
106 0xBB, 0xC5, 0x4F, 0xED, 0x86, 0x9A, 0x66, 0x11,
107 0x8A, 0xE9, 0x04, 0xFE, 0xA0, 0x78, 0x25, 0x4B,
108 0xA2, 0x5D, 0x80, 0x05, 0x3F, 0x21, 0x70, 0xF1,
109 0x63, 0x77, 0xAF, 0x42, 0x20, 0xE5, 0xFD, 0xBF,
110 0x81, 0x18, 0x26, 0xC3, 0xBE, 0x35, 0x88, 0x2E,
111 0x93, 0x55, 0xFC, 0x7A, 0xC8, 0xBA, 0x32, 0xE6,
112 0xC0, 0x19, 0x9E, 0xA3, 0x44, 0x54, 0x3B, 0x0B,
113 0x8C, 0xC7, 0x6B, 0x28, 0xA7, 0xBC, 0x16, 0xAD,
114 0xDB, 0x64, 0x74, 0x14, 0x92, 0x0C, 0x48, 0xB8,
115 0x9F, 0xBD, 0x43, 0xC4, 0x39, 0x31, 0xD3, 0xF2,
116 0xD5, 0x8B, 0x6E, 0xDA, 0x01, 0xB1, 0x9C, 0x49,
117 0xD8, 0xAC, 0xF3, 0xCF, 0xCA, 0xF4, 0x47, 0x10,
118 0x6F, 0xF0, 0x4A, 0x5C, 0x38, 0x57, 0x73, 0x97,
119 0xCB, 0xA1, 0xE8, 0x3E, 0x96, 0x61, 0x0D, 0x0F,
120 0xE0, 0x7C, 0x71, 0xCC, 0x90, 0x06, 0xF7, 0x1C,
121 0xC2, 0x6A, 0xAE, 0x69, 0x17, 0x99, 0x3A, 0x27,
122 0xD9, 0xEB, 0x2B, 0x22, 0xD2, 0xA9, 0x07, 0x33,
123 0x2D, 0x3C, 0x15, 0xC9, 0x87, 0xAA, 0x50, 0xA5,
124 0x03, 0x59, 0x09, 0x1A, 0x65, 0xD7, 0x84, 0xD0,
125 0x82, 0x29, 0x5A, 0x1E, 0x7B, 0xA8, 0x6D, 0x2C
126};
127
128//STKIPKeyManagement sTKIPKeyTable[MAX_TKIP_KEY];
129
130/*--------------------- Static Functions --------------------------*/
131unsigned int tkip_sbox(unsigned int index);
132unsigned int rotr1(unsigned int a);
133
134/*--------------------- Export Variables --------------------------*/
135
136/************************************************************/
137/* tkip_sbox() */
138/* Returns a 16 bit value from a 64K entry table. The Table */
139/* is synthesized from two 256 entry byte wide tables. */
140/************************************************************/
141unsigned int tkip_sbox(unsigned int index)
142{
143 unsigned int index_low;
144 unsigned int index_high;
145 unsigned int left, right;
146
147 index_low = (index % 256);
148 index_high = ((index >> 8) % 256);
149
150 left = TKIP_Sbox_Lower[index_low] + (TKIP_Sbox_Upper[index_low] * 256);
151 right = TKIP_Sbox_Upper[index_high] + (TKIP_Sbox_Lower[index_high] * 256);
152
153 return left ^ right;
154};
155
156unsigned int rotr1(unsigned int a)
157{
158 unsigned int b;
159
160 if ((a & 0x01) == 0x01)
161 b = (a >> 1) | 0x8000;
162 else
163 b = (a >> 1) & 0x7fff;
164
165 b = b % 65536;
166 return b;
167}
168
169/*
170 * Description: Calculate RC4Key fom TK, TA, and TSC
171 *
172 * Parameters:
173 * In:
174 * pbyTKey - TKey
175 * pbyTA - TA
176 * dwTSC - TSC
177 * Out:
178 * pbyRC4Key - RC4Key
179 *
180 * Return Value: none
181 *
182 */
183void TKIPvMixKey(
184 unsigned char *pbyTKey,
185 unsigned char *pbyTA,
186 unsigned short wTSC15_0,
187 unsigned long dwTSC47_16,
188 unsigned char *pbyRC4Key
189)
190{
191 unsigned int p1k[5];
192 unsigned int tsc0, tsc1, tsc2;
193 unsigned int ppk0, ppk1, ppk2, ppk3, ppk4, ppk5;
194 unsigned long int pnl, pnh;
195
196 int i, j;
197
198 pnl = wTSC15_0;
199 pnh = dwTSC47_16;
200
201 tsc0 = (unsigned int)((pnh >> 16) % 65536); /* msb */
202 tsc1 = (unsigned int)(pnh % 65536);
203 tsc2 = (unsigned int)(pnl % 65536); /* lsb */
204
205 /* Phase 1, step 1 */
206 p1k[0] = tsc1;
207 p1k[1] = tsc0;
208 p1k[2] = (unsigned int)(pbyTA[0] + (pbyTA[1]*256));
209 p1k[3] = (unsigned int)(pbyTA[2] + (pbyTA[3]*256));
210 p1k[4] = (unsigned int)(pbyTA[4] + (pbyTA[5]*256));
211
212 /* Phase 1, step 2 */
213 for (i = 0; i < 8; i++) {
214 j = 2 * (i & 1);
215 p1k[0] = (p1k[0] + tkip_sbox((p1k[4] ^ ((256*pbyTKey[1+j]) + pbyTKey[j])) % 65536)) % 65536;
216 p1k[1] = (p1k[1] + tkip_sbox((p1k[0] ^ ((256*pbyTKey[5+j]) + pbyTKey[4+j])) % 65536)) % 65536;
217 p1k[2] = (p1k[2] + tkip_sbox((p1k[1] ^ ((256*pbyTKey[9+j]) + pbyTKey[8+j])) % 65536)) % 65536;
218 p1k[3] = (p1k[3] + tkip_sbox((p1k[2] ^ ((256*pbyTKey[13+j]) + pbyTKey[12+j])) % 65536)) % 65536;
219 p1k[4] = (p1k[4] + tkip_sbox((p1k[3] ^ (((256*pbyTKey[1+j]) + pbyTKey[j]))) % 65536)) % 65536;
220 p1k[4] = (p1k[4] + i) % 65536;
221 }
222 /* Phase 2, Step 1 */
223 ppk0 = p1k[0];
224 ppk1 = p1k[1];
225 ppk2 = p1k[2];
226 ppk3 = p1k[3];
227 ppk4 = p1k[4];
228 ppk5 = (p1k[4] + tsc2) % 65536;
229
230 /* Phase2, Step 2 */
231 ppk0 = ppk0 + tkip_sbox((ppk5 ^ ((256*pbyTKey[1]) + pbyTKey[0])) % 65536);
232 ppk1 = ppk1 + tkip_sbox((ppk0 ^ ((256*pbyTKey[3]) + pbyTKey[2])) % 65536);
233 ppk2 = ppk2 + tkip_sbox((ppk1 ^ ((256*pbyTKey[5]) + pbyTKey[4])) % 65536);
234 ppk3 = ppk3 + tkip_sbox((ppk2 ^ ((256*pbyTKey[7]) + pbyTKey[6])) % 65536);
235 ppk4 = ppk4 + tkip_sbox((ppk3 ^ ((256*pbyTKey[9]) + pbyTKey[8])) % 65536);
236 ppk5 = ppk5 + tkip_sbox((ppk4 ^ ((256*pbyTKey[11]) + pbyTKey[10])) % 65536);
237
238 ppk0 = ppk0 + rotr1(ppk5 ^ ((256*pbyTKey[13]) + pbyTKey[12]));
239 ppk1 = ppk1 + rotr1(ppk0 ^ ((256*pbyTKey[15]) + pbyTKey[14]));
240 ppk2 = ppk2 + rotr1(ppk1);
241 ppk3 = ppk3 + rotr1(ppk2);
242 ppk4 = ppk4 + rotr1(ppk3);
243 ppk5 = ppk5 + rotr1(ppk4);
244
245 /* Phase 2, Step 3 */
246 pbyRC4Key[0] = (tsc2 >> 8) % 256;
247 pbyRC4Key[1] = (((tsc2 >> 8) % 256) | 0x20) & 0x7f;
248 pbyRC4Key[2] = tsc2 % 256;
249 pbyRC4Key[3] = ((ppk5 ^ ((256*pbyTKey[1]) + pbyTKey[0])) >> 1) % 256;
250
251 pbyRC4Key[4] = ppk0 % 256;
252 pbyRC4Key[5] = (ppk0 >> 8) % 256;
253
254 pbyRC4Key[6] = ppk1 % 256;
255 pbyRC4Key[7] = (ppk1 >> 8) % 256;
256
257 pbyRC4Key[8] = ppk2 % 256;
258 pbyRC4Key[9] = (ppk2 >> 8) % 256;
259
260 pbyRC4Key[10] = ppk3 % 256;
261 pbyRC4Key[11] = (ppk3 >> 8) % 256;
262
263 pbyRC4Key[12] = ppk4 % 256;
264 pbyRC4Key[13] = (ppk4 >> 8) % 256;
265
266 pbyRC4Key[14] = ppk5 % 256;
267 pbyRC4Key[15] = (ppk5 >> 8) % 256;
268}
diff --git a/drivers/staging/vt6655/tkip.h b/drivers/staging/vt6655/tkip.h
deleted file mode 100644
index 3b6357ac6dee..000000000000
--- a/drivers/staging/vt6655/tkip.h
+++ /dev/null
@@ -1,57 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: tkip.h
21 *
22 * Purpose: Implement functions for 802.11i TKIP
23 *
24 * Author: Jerry Chen
25 *
26 * Date: Mar. 11, 2003
27 *
28 */
29
30#ifndef __TKIP_H__
31#define __TKIP_H__
32
33#include "ttype.h"
34#include "tether.h"
35
36/*--------------------- Export Definitions -------------------------*/
37#define TKIP_KEY_LEN 16
38
39/*--------------------- Export Types ------------------------------*/
40
41/*--------------------- Export Macros ------------------------------*/
42
43/*--------------------- Export Classes ----------------------------*/
44
45/*--------------------- Export Variables --------------------------*/
46
47/*--------------------- Export Functions --------------------------*/
48
49void TKIPvMixKey(
50 unsigned char *pbyTKey,
51 unsigned char *pbyTA,
52 unsigned short wTSC15_0,
53 unsigned long dwTSC47_16,
54 unsigned char *pbyRC4Key
55);
56
57#endif // __TKIP_H__
diff --git a/drivers/staging/vt6655/tmacro.h b/drivers/staging/vt6655/tmacro.h
index 59c6e72f993a..607b78f7a6a0 100644
--- a/drivers/staging/vt6655/tmacro.h
+++ b/drivers/staging/vt6655/tmacro.h
@@ -29,8 +29,6 @@
29#ifndef __TMACRO_H__ 29#ifndef __TMACRO_H__
30#define __TMACRO_H__ 30#define __TMACRO_H__
31 31
32#include "ttype.h"
33
34/****** Common helper macros ***********************************************/ 32/****** Common helper macros ***********************************************/
35 33
36#if !defined(LOBYTE) 34#if !defined(LOBYTE)
diff --git a/drivers/staging/vt6655/ttype.h b/drivers/staging/vt6655/ttype.h
deleted file mode 100644
index 747ef62ec9be..000000000000
--- a/drivers/staging/vt6655/ttype.h
+++ /dev/null
@@ -1,42 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: ttype.h
20 *
21 * Purpose: define basic common types and macros
22 *
23 * Author: Tevin Chen
24 *
25 * Date: May 21, 1996
26 *
27 */
28
29#ifndef __TTYPE_H__
30#define __TTYPE_H__
31
32/******* Common definitions and typedefs ***********************************/
33
34#ifndef WPA_SM_Transtatus
35#define WPA_SM_Transtatus
36#endif
37
38#ifndef Calcu_LinkQual
39#define Calcu_LinkQual
40#endif
41
42#endif // __TTYPE_H__
diff --git a/drivers/staging/vt6655/upc.h b/drivers/staging/vt6655/upc.h
index c5c889cade25..c53703a772f5 100644
--- a/drivers/staging/vt6655/upc.h
+++ b/drivers/staging/vt6655/upc.h
@@ -30,7 +30,6 @@
30#define __UPC_H__ 30#define __UPC_H__
31 31
32#include "device.h" 32#include "device.h"
33#include "ttype.h"
34 33
35/*--------------------- Export Definitions -------------------------*/ 34/*--------------------- Export Definitions -------------------------*/
36 35
diff --git a/drivers/staging/vt6655/vntconfiguration.dat b/drivers/staging/vt6655/vntconfiguration.dat
deleted file mode 100644
index 0064ddce7c11..000000000000
--- a/drivers/staging/vt6655/vntconfiguration.dat
+++ /dev/null
@@ -1 +0,0 @@
1ZONETYPE=EUROPE \ No newline at end of file
diff --git a/drivers/staging/vt6655/vntwifi.c b/drivers/staging/vt6655/vntwifi.c
deleted file mode 100644
index 59f66fe47352..000000000000
--- a/drivers/staging/vt6655/vntwifi.c
+++ /dev/null
@@ -1,700 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: vntwifi.c
21 *
22 * Purpose: export functions for vntwifi lib
23 *
24 * Functions:
25 *
26 * Revision History:
27 *
28 * Author: Yiching Chen
29 *
30 * Date: feb. 2, 2005
31 *
32 */
33
34#include "vntwifi.h"
35#include "IEEE11h.h"
36#include "country.h"
37#include "device.h"
38#include "wmgr.h"
39#include "datarate.h"
40
41/*--------------------- Static Definitions -------------------------*/
42
43/*--------------------- Static Classes ----------------------------*/
44
45/*--------------------- Static Variables --------------------------*/
46
47/*--------------------- Static Functions --------------------------*/
48
49/*--------------------- Export Variables --------------------------*/
50
51/*--------------------- Export Functions --------------------------*/
52
53/*+
54 *
55 * Description:
56 * Set Operation Mode
57 *
58 * Parameters:
59 * In:
60 * pMgmtHandle - pointer to management object
61 * eOPMode - Operation Mode
62 * Out:
63 * none
64 *
65 * Return Value: none
66 *
67 -*/
68void
69VNTWIFIvSetOPMode(
70 void *pMgmtHandle,
71 WMAC_CONFIG_MODE eOPMode
72)
73{
74 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
75
76 pMgmt->eConfigMode = eOPMode;
77}
78
79/*+
80 *
81 * Description:
82 * Set Operation Mode
83 *
84 * Parameters:
85 * In:
86 * pMgmtHandle - pointer to management object
87 * wBeaconPeriod - Beacon Period
88 * wATIMWindow - ATIM window
89 * uChannel - channel number
90 * Out:
91 * none
92 *
93 * Return Value: none
94 *
95 -*/
96void
97VNTWIFIvSetIBSSParameter(
98 void *pMgmtHandle,
99 unsigned short wBeaconPeriod,
100 unsigned short wATIMWindow,
101 unsigned int uChannel
102)
103{
104 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
105
106 pMgmt->wIBSSBeaconPeriod = wBeaconPeriod;
107 pMgmt->wIBSSATIMWindow = wATIMWindow;
108 pMgmt->uIBSSChannel = uChannel;
109}
110
111/*+
112 *
113 * Description:
114 * Get current SSID
115 *
116 * Parameters:
117 * In:
118 * pMgmtHandle - pointer to management object
119 * Out:
120 * none
121 *
122 * Return Value: current SSID pointer.
123 *
124 -*/
125PWLAN_IE_SSID
126VNTWIFIpGetCurrentSSID(
127 void *pMgmtHandle
128)
129{
130 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
131
132 return (PWLAN_IE_SSID) pMgmt->abyCurrSSID;
133}
134
135/*+
136 *
137 * Description:
138 * Get current link channel
139 *
140 * Parameters:
141 * In:
142 * pMgmtHandle - pointer to management object
143 * Out:
144 * none
145 *
146 * Return Value: current Channel.
147 *
148 -*/
149unsigned int
150VNTWIFIpGetCurrentChannel(
151 void *pMgmtHandle
152)
153{
154 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
155
156 if (pMgmtHandle != NULL)
157 return pMgmt->uCurrChannel;
158
159 return 0;
160}
161
162/*+
163 *
164 * Description:
165 * Get current Assoc ID
166 *
167 * Parameters:
168 * In:
169 * pMgmtHandle - pointer to management object
170 * Out:
171 * none
172 *
173 * Return Value: current Assoc ID
174 *
175 -*/
176unsigned short
177VNTWIFIwGetAssocID(
178 void *pMgmtHandle
179)
180{
181 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
182
183 return pMgmt->wCurrAID;
184}
185
186/*+
187 *
188 * Description:
189 * This routine return max support rate of IES
190 *
191 * Parameters:
192 * In:
193 * pSupportRateIEs
194 * pExtSupportRateIEs
195 *
196 * Out:
197 *
198 * Return Value: max support rate
199 *
200 -*/
201unsigned char
202VNTWIFIbyGetMaxSupportRate(
203 PWLAN_IE_SUPP_RATES pSupportRateIEs,
204 PWLAN_IE_SUPP_RATES pExtSupportRateIEs
205)
206{
207 unsigned char byMaxSupportRate = RATE_1M;
208 unsigned char bySupportRate = RATE_1M;
209 unsigned int ii = 0;
210
211 if (pSupportRateIEs) {
212 for (ii = 0; ii < pSupportRateIEs->len; ii++) {
213 bySupportRate = DATARATEbyGetRateIdx(pSupportRateIEs->abyRates[ii]);
214 if (bySupportRate > byMaxSupportRate)
215 byMaxSupportRate = bySupportRate;
216
217 }
218 }
219 if (pExtSupportRateIEs) {
220 for (ii = 0; ii < pExtSupportRateIEs->len; ii++) {
221 bySupportRate = DATARATEbyGetRateIdx(pExtSupportRateIEs->abyRates[ii]);
222 if (bySupportRate > byMaxSupportRate)
223 byMaxSupportRate = bySupportRate;
224
225 }
226 }
227
228 return byMaxSupportRate;
229}
230
231/*+
232 *
233 * Description:
234 * This routine return data rate of ACK packtet
235 *
236 * Parameters:
237 * In:
238 * byRxDataRate
239 * pSupportRateIEs
240 * pExtSupportRateIEs
241 *
242 * Out:
243 *
244 * Return Value: max support rate
245 *
246 -*/
247unsigned char
248VNTWIFIbyGetACKTxRate(
249 unsigned char byRxDataRate,
250 PWLAN_IE_SUPP_RATES pSupportRateIEs,
251 PWLAN_IE_SUPP_RATES pExtSupportRateIEs
252)
253{
254 unsigned char byMaxAckRate;
255 unsigned char byBasicRate;
256 unsigned int ii;
257
258 if (byRxDataRate <= RATE_11M) {
259 byMaxAckRate = RATE_1M;
260 } else {
261 /* 24M is mandatory for 802.11a and 802.11g */
262 byMaxAckRate = RATE_24M;
263 }
264 if (pSupportRateIEs) {
265 for (ii = 0; ii < pSupportRateIEs->len; ii++) {
266 if (pSupportRateIEs->abyRates[ii] & 0x80) {
267 byBasicRate = DATARATEbyGetRateIdx(pSupportRateIEs->abyRates[ii]);
268 if ((byBasicRate <= byRxDataRate) &&
269 (byBasicRate > byMaxAckRate)) {
270 byMaxAckRate = byBasicRate;
271 }
272 }
273 }
274 }
275 if (pExtSupportRateIEs) {
276 for (ii = 0; ii < pExtSupportRateIEs->len; ii++) {
277 if (pExtSupportRateIEs->abyRates[ii] & 0x80) {
278 byBasicRate = DATARATEbyGetRateIdx(pExtSupportRateIEs->abyRates[ii]);
279 if ((byBasicRate <= byRxDataRate) &&
280 (byBasicRate > byMaxAckRate)) {
281 byMaxAckRate = byBasicRate;
282 }
283 }
284 }
285 }
286
287 return byMaxAckRate;
288}
289
290/*+
291 *
292 * Description:
293 * Set Authentication Mode
294 *
295 * Parameters:
296 * In:
297 * pMgmtHandle - pointer to management object
298 * eAuthMode - Authentication mode
299 * Out:
300 * none
301 *
302 * Return Value: none
303 *
304 -*/
305void
306VNTWIFIvSetAuthenticationMode(
307 void *pMgmtHandle,
308 WMAC_AUTHENTICATION_MODE eAuthMode
309)
310{
311 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
312
313 pMgmt->eAuthenMode = eAuthMode;
314 if ((eAuthMode == WMAC_AUTH_SHAREKEY) ||
315 (eAuthMode == WMAC_AUTH_AUTO)) {
316 pMgmt->bShareKeyAlgorithm = true;
317 } else {
318 pMgmt->bShareKeyAlgorithm = false;
319 }
320}
321
322/*+
323 *
324 * Description:
325 * Set Encryption Mode
326 *
327 * Parameters:
328 * In:
329 * pMgmtHandle - pointer to management object
330 * eAuthMode - Authentication mode
331 * Out:
332 * none
333 *
334 * Return Value: none
335 *
336 -*/
337void
338VNTWIFIvSetEncryptionMode(
339 void *pMgmtHandle,
340 WMAC_ENCRYPTION_MODE eEncryptionMode
341)
342{
343 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
344
345 pMgmt->eEncryptionMode = eEncryptionMode;
346 if ((eEncryptionMode == WMAC_ENCRYPTION_WEPEnabled) ||
347 (eEncryptionMode == WMAC_ENCRYPTION_TKIPEnabled) ||
348 (eEncryptionMode == WMAC_ENCRYPTION_AESEnabled)) {
349 pMgmt->bPrivacyInvoked = true;
350 } else {
351 pMgmt->bPrivacyInvoked = false;
352 }
353}
354
355bool
356VNTWIFIbConfigPhyMode(
357 void *pMgmtHandle,
358 CARD_PHY_TYPE ePhyType
359)
360{
361 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
362
363 if ((ePhyType != PHY_TYPE_AUTO) &&
364 (ePhyType != pMgmt->eCurrentPHYMode)) {
365 if (CARDbSetPhyParameter(pMgmt->pAdapter, ePhyType, 0, 0, NULL, NULL) == true)
366 pMgmt->eCurrentPHYMode = ePhyType;
367 else
368 return false;
369 }
370 pMgmt->eConfigPHYMode = ePhyType;
371 return true;
372}
373
374void
375VNTWIFIbGetConfigPhyMode(
376 void *pMgmtHandle,
377 void *pePhyType
378)
379{
380 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
381
382 if ((pMgmt != NULL) && (pePhyType != NULL))
383 *(PCARD_PHY_TYPE)pePhyType = pMgmt->eConfigPHYMode;
384}
385
386/*+
387 *
388 * Description:
389 * Clear BSS List Database except current assoc BSS
390 *
391 * Parameters:
392 * In:
393 * pMgmtHandle - Management Object structure
394 * bLinkPass - Current Link status
395 * Out:
396 *
397 * Return Value: None.
398 *
399 -*/
400
401/*+
402 *
403 * Description:
404 * Query BSS List in management database
405 *
406 * Parameters:
407 * In:
408 * pMgmtHandle - Management Object structure
409 * Out:
410 * puBSSCount - BSS count
411 * pvFirstBSS - pointer to first BSS
412 *
413 * Return Value: None.
414 *
415 -*/
416
417void
418VNTWIFIvQueryBSSList(void *pMgmtHandle, unsigned int *puBSSCount, void **pvFirstBSS)
419{
420 unsigned int ii = 0;
421 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
422 PKnownBSS pBSS = NULL;
423 unsigned int uCount = 0;
424
425 *pvFirstBSS = NULL;
426
427 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
428 pBSS = &(pMgmt->sBSSList[ii]);
429 if (!pBSS->bActive)
430 continue;
431
432 if (*pvFirstBSS == NULL)
433 *pvFirstBSS = &(pMgmt->sBSSList[ii]);
434
435 uCount++;
436 }
437 *puBSSCount = uCount;
438}
439
440void
441VNTWIFIvGetNextBSS(
442 void *pMgmtHandle,
443 void *pvCurrentBSS,
444 void **pvNextBSS
445)
446{
447 PKnownBSS pBSS = (PKnownBSS) pvCurrentBSS;
448 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
449
450 *pvNextBSS = NULL;
451
452 while (*pvNextBSS == NULL) {
453 pBSS++;
454 if (pBSS > &(pMgmt->sBSSList[MAX_BSS_NUM]))
455 return;
456
457 if (pBSS->bActive == true) {
458 *pvNextBSS = pBSS;
459 return;
460 }
461 }
462}
463
464/*+
465 *
466 * Description:
467 * Update Tx attemps, Tx failure counter in Node DB
468 *
469 * In:
470 * Out:
471 * none
472 *
473 * Return Value: none
474 *
475 -*/
476void
477VNTWIFIvUpdateNodeTxCounter(
478 void *pMgmtHandle,
479 unsigned char *pbyDestAddress,
480 bool bTxOk,
481 unsigned short wRate,
482 unsigned char *pbyTxFailCount
483)
484{
485 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
486 unsigned int uNodeIndex = 0;
487 unsigned int ii;
488
489 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
490 (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
491 if (BSSDBbIsSTAInNodeDB(pMgmt, pbyDestAddress, &uNodeIndex) == false)
492 return;
493 }
494
495 pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts++;
496 if (bTxOk) {
497 /* transmit success, TxAttempts at least plus one */
498 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[MAX_RATE]++;
499 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[wRate]++;
500 } else {
501 pMgmt->sNodeDBTable[uNodeIndex].uTxFailures++;
502 }
503 pMgmt->sNodeDBTable[uNodeIndex].uTxRetry += pbyTxFailCount[MAX_RATE];
504 for (ii = 0; ii < MAX_RATE; ii++)
505 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[ii] += pbyTxFailCount[ii];
506}
507
508void
509VNTWIFIvGetTxRate(
510 void *pMgmtHandle,
511 unsigned char *pbyDestAddress,
512 unsigned short *pwTxDataRate,
513 unsigned char *pbyACKRate,
514 unsigned char *pbyCCKBasicRate,
515 unsigned char *pbyOFDMBasicRate
516)
517{
518 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
519 unsigned int uNodeIndex = 0;
520 unsigned short wTxDataRate = RATE_1M;
521 unsigned char byACKRate = RATE_1M;
522 unsigned char byCCKBasicRate = RATE_1M;
523 unsigned char byOFDMBasicRate = RATE_24M;
524 PWLAN_IE_SUPP_RATES pSupportRateIEs = NULL;
525 PWLAN_IE_SUPP_RATES pExtSupportRateIEs = NULL;
526
527 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
528 (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
529 /* Adhoc Tx rate decided from node DB */
530 if (BSSDBbIsSTAInNodeDB(pMgmt, pbyDestAddress, &uNodeIndex)) {
531 wTxDataRate = (pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate);
532 pSupportRateIEs = (PWLAN_IE_SUPP_RATES) (pMgmt->sNodeDBTable[uNodeIndex].abyCurrSuppRates);
533 pExtSupportRateIEs = (PWLAN_IE_SUPP_RATES) (pMgmt->sNodeDBTable[uNodeIndex].abyCurrExtSuppRates);
534 } else {
535 if (pMgmt->eCurrentPHYMode != PHY_TYPE_11A)
536 wTxDataRate = RATE_2M;
537 else
538 wTxDataRate = RATE_24M;
539
540 pSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrSuppRates;
541 pExtSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrExtSuppRates;
542 }
543 } else { /* Infrastructure: rate decided from AP Node, index = 0 */
544
545 wTxDataRate = (pMgmt->sNodeDBTable[0].wTxDataRate);
546
547 pSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrSuppRates;
548 pExtSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrExtSuppRates;
549 }
550 byACKRate = VNTWIFIbyGetACKTxRate((unsigned char) wTxDataRate,
551 pSupportRateIEs,
552 pExtSupportRateIEs
553);
554 if (byACKRate > (unsigned char) wTxDataRate)
555 byACKRate = (unsigned char) wTxDataRate;
556
557 byCCKBasicRate = VNTWIFIbyGetACKTxRate(RATE_11M,
558 pSupportRateIEs,
559 pExtSupportRateIEs
560);
561 byOFDMBasicRate = VNTWIFIbyGetACKTxRate(RATE_54M,
562 pSupportRateIEs,
563 pExtSupportRateIEs
564);
565 *pwTxDataRate = wTxDataRate;
566 *pbyACKRate = byACKRate;
567 *pbyCCKBasicRate = byCCKBasicRate;
568 *pbyOFDMBasicRate = byOFDMBasicRate;
569}
570
571unsigned char
572VNTWIFIbyGetKeyCypher(
573 void *pMgmtHandle,
574 bool bGroupKey
575)
576{
577 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
578
579 if (bGroupKey)
580 return pMgmt->byCSSGK;
581 else
582 return pMgmt->byCSSPK;
583}
584
585bool
586VNTWIFIbSetPMKIDCache(
587 void *pMgmtObject,
588 unsigned long ulCount,
589 void *pPMKIDInfo
590)
591{
592 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
593
594 if (ulCount > MAX_PMKID_CACHE)
595 return false;
596
597 pMgmt->gsPMKIDCache.BSSIDInfoCount = ulCount;
598 memcpy(pMgmt->gsPMKIDCache.BSSIDInfo, pPMKIDInfo, (ulCount*sizeof(PMKIDInfo)));
599 return true;
600}
601
602unsigned short
603VNTWIFIwGetMaxSupportRate(
604 void *pMgmtObject
605)
606{
607 unsigned short wRate = RATE_54M;
608 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
609
610 for (wRate = RATE_54M; wRate > RATE_1M; wRate--) {
611 if (pMgmt->sNodeDBTable[0].wSuppRate & (1<<wRate))
612 return wRate;
613 }
614
615 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11A)
616 return RATE_6M;
617 else
618 return RATE_1M;
619}
620
621void
622VNTWIFIvSet11h(
623 void *pMgmtObject,
624 bool b11hEnable
625)
626{
627 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
628
629 pMgmt->b11hEnable = b11hEnable;
630}
631
632bool
633VNTWIFIbMeasureReport(
634 void *pMgmtObject,
635 bool bEndOfReport,
636 void *pvMeasureEID,
637 unsigned char byReportMode,
638 unsigned char byBasicMap,
639 unsigned char byCCAFraction,
640 unsigned char *pbyRPIs
641)
642{
643 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
644 unsigned char *pbyCurrentEID = (unsigned char *)(pMgmt->pCurrMeasureEIDRep);
645
646 if ((pvMeasureEID != NULL) &&
647 (pMgmt->uLengthOfRepEIDs < (WLAN_A3FR_MAXLEN - sizeof(MEASEURE_REP) - sizeof(WLAN_80211HDR_A3) - 3))
648) {
649 pMgmt->pCurrMeasureEIDRep->byElementID = WLAN_EID_MEASURE_REP;
650 pMgmt->pCurrMeasureEIDRep->len = 3;
651 pMgmt->pCurrMeasureEIDRep->byToken = ((PWLAN_IE_MEASURE_REQ)pvMeasureEID)->byToken;
652 pMgmt->pCurrMeasureEIDRep->byMode = byReportMode;
653 pMgmt->pCurrMeasureEIDRep->byType = ((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->byType;
654 switch (pMgmt->pCurrMeasureEIDRep->byType) {
655 case MEASURE_TYPE_BASIC:
656 pMgmt->pCurrMeasureEIDRep->len += sizeof(MEASEURE_REP_BASIC);
657 memcpy(&(pMgmt->pCurrMeasureEIDRep->sRep.sBasic),
658 &(((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->sReq),
659 sizeof(MEASEURE_REQ));
660 pMgmt->pCurrMeasureEIDRep->sRep.sBasic.byMap = byBasicMap;
661 break;
662 case MEASURE_TYPE_CCA:
663 pMgmt->pCurrMeasureEIDRep->len += sizeof(MEASEURE_REP_CCA);
664 memcpy(&(pMgmt->pCurrMeasureEIDRep->sRep.sCCA),
665 &(((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->sReq),
666 sizeof(MEASEURE_REQ));
667 pMgmt->pCurrMeasureEIDRep->sRep.sCCA.byCCABusyFraction = byCCAFraction;
668 break;
669 case MEASURE_TYPE_RPI:
670 pMgmt->pCurrMeasureEIDRep->len += sizeof(MEASEURE_REP_RPI);
671 memcpy(&(pMgmt->pCurrMeasureEIDRep->sRep.sRPI),
672 &(((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->sReq),
673 sizeof(MEASEURE_REQ));
674 memcpy(pMgmt->pCurrMeasureEIDRep->sRep.sRPI.abyRPIdensity, pbyRPIs, 8);
675 break;
676 default:
677 break;
678 }
679 pbyCurrentEID += (2 + pMgmt->pCurrMeasureEIDRep->len);
680 pMgmt->uLengthOfRepEIDs += (2 + pMgmt->pCurrMeasureEIDRep->len);
681 pMgmt->pCurrMeasureEIDRep = (PWLAN_IE_MEASURE_REP) pbyCurrentEID;
682 }
683 if (bEndOfReport)
684 IEEE11hbMSRRepTx(pMgmt);
685
686 return true;
687}
688
689bool
690VNTWIFIbChannelSwitch(
691 void *pMgmtObject,
692 unsigned char byNewChannel
693)
694{
695 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
696
697 pMgmt->uCurrChannel = byNewChannel;
698 pMgmt->bSwitchChannel = false;
699 return true;
700}
diff --git a/drivers/staging/vt6655/vntwifi.h b/drivers/staging/vt6655/vntwifi.h
deleted file mode 100644
index 880b8ab109be..000000000000
--- a/drivers/staging/vt6655/vntwifi.h
+++ /dev/null
@@ -1,273 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: vntwifi.h
21 *
22 * Purpose: export VNT Host WiFi library function
23 *
24 * Author: Yiching Chen
25 *
26 * Date: Jan 7, 2004
27 *
28 */
29
30#ifndef __VNTWIFI_H__
31#define __VNTWIFI_H__
32
33#include "ttype.h"
34#include "80211mgr.h"
35#include "card.h"
36#include "wpa2.h"
37
38/*--------------------- Export Definitions -------------------------*/
39#define RATE_1M 0
40#define RATE_2M 1
41#define RATE_5M 2
42#define RATE_11M 3
43#define RATE_6M 4
44#define RATE_9M 5
45#define RATE_12M 6
46#define RATE_18M 7
47#define RATE_24M 8
48#define RATE_36M 9
49#define RATE_48M 10
50#define RATE_54M 11
51#define RATE_AUTO 12
52#define MAX_RATE 12
53
54// key CipherSuite
55#define KEY_CTL_WEP 0x00
56#define KEY_CTL_NONE 0x01
57#define KEY_CTL_TKIP 0x02
58#define KEY_CTL_CCMP 0x03
59#define KEY_CTL_INVALID 0xFF
60
61#define CHANNEL_MAX_24G 14
62
63#define MAX_BSS_NUM 42
64
65// Pre-configured Authenticaiton Mode (from XP)
66typedef enum tagWMAC_AUTHENTICATION_MODE {
67 WMAC_AUTH_OPEN,
68 WMAC_AUTH_SHAREKEY,
69 WMAC_AUTH_AUTO,
70 WMAC_AUTH_WPA,
71 WMAC_AUTH_WPAPSK,
72 WMAC_AUTH_WPANONE,
73 WMAC_AUTH_WPA2,
74 WMAC_AUTH_WPA2PSK,
75 WMAC_AUTH_MAX // Not a real mode, defined as upper bound
76} WMAC_AUTHENTICATION_MODE, *PWMAC_AUTHENTICATION_MODE;
77
78typedef enum tagWMAC_ENCRYPTION_MODE {
79 WMAC_ENCRYPTION_WEPEnabled,
80 WMAC_ENCRYPTION_WEPDisabled,
81 WMAC_ENCRYPTION_WEPKeyAbsent,
82 WMAC_ENCRYPTION_WEPNotSupported,
83 WMAC_ENCRYPTION_TKIPEnabled,
84 WMAC_ENCRYPTION_TKIPKeyAbsent,
85 WMAC_ENCRYPTION_AESEnabled,
86 WMAC_ENCRYPTION_AESKeyAbsent
87} WMAC_ENCRYPTION_MODE, *PWMAC_ENCRYPTION_MODE;
88
89// Pre-configured Mode (from XP)
90
91typedef enum tagWMAC_CONFIG_MODE {
92 WMAC_CONFIG_ESS_STA = 0,
93 WMAC_CONFIG_IBSS_STA,
94 WMAC_CONFIG_AUTO,
95 WMAC_CONFIG_AP
96} WMAC_CONFIG_MODE, *PWMAC_CONFIG_MODE;
97
98typedef enum tagWMAC_POWER_MODE {
99 WMAC_POWER_CAM,
100 WMAC_POWER_FAST,
101 WMAC_POWER_MAX
102} WMAC_POWER_MODE, *PWMAC_POWER_MODE;
103
104#define VNTWIFIbIsShortSlotTime(wCapInfo) \
105 WLAN_GET_CAP_INFO_SHORTSLOTTIME(wCapInfo) \
106
107#define VNTWIFIbIsProtectMode(byERP) \
108 ((byERP & WLAN_EID_ERP_USE_PROTECTION) != 0) \
109
110#define VNTWIFIbIsBarkerMode(byERP) \
111 ((byERP & WLAN_EID_ERP_BARKER_MODE) != 0) \
112
113#define VNTWIFIbIsShortPreamble(wCapInfo) \
114 WLAN_GET_CAP_INFO_SHORTPREAMBLE(wCapInfo) \
115
116#define VNTWIFIbIsEncryption(wCapInfo) \
117 WLAN_GET_CAP_INFO_PRIVACY(wCapInfo) \
118
119#define VNTWIFIbIsESS(wCapInfo) \
120 WLAN_GET_CAP_INFO_ESS(wCapInfo) \
121
122/*--------------------- Export Classes ----------------------------*/
123
124/*--------------------- Export Variables --------------------------*/
125
126/*--------------------- Export Types ------------------------------*/
127
128/*--------------------- Export Functions --------------------------*/
129
130void
131VNTWIFIvSetIBSSParameter(
132 void *pMgmtHandle,
133 unsigned short wBeaconPeriod,
134 unsigned short wATIMWindow,
135 unsigned int uChannel
136);
137
138void
139VNTWIFIvSetOPMode(
140 void *pMgmtHandle,
141 WMAC_CONFIG_MODE eOPMode
142);
143
144PWLAN_IE_SSID
145VNTWIFIpGetCurrentSSID(
146 void *pMgmtHandle
147);
148
149unsigned int
150VNTWIFIpGetCurrentChannel(
151 void *pMgmtHandle
152);
153
154unsigned short
155VNTWIFIwGetAssocID(
156 void *pMgmtHandle
157);
158
159unsigned char
160VNTWIFIbyGetMaxSupportRate(
161 PWLAN_IE_SUPP_RATES pSupportRateIEs,
162 PWLAN_IE_SUPP_RATES pExtSupportRateIEs
163);
164
165unsigned char
166VNTWIFIbyGetACKTxRate(
167 unsigned char byRxDataRate,
168 PWLAN_IE_SUPP_RATES pSupportRateIEs,
169 PWLAN_IE_SUPP_RATES pExtSupportRateIEs
170);
171
172void
173VNTWIFIvSetAuthenticationMode(
174 void *pMgmtHandle,
175 WMAC_AUTHENTICATION_MODE eAuthMode
176);
177
178void
179VNTWIFIvSetEncryptionMode(
180 void *pMgmtHandle,
181 WMAC_ENCRYPTION_MODE eEncryptionMode
182);
183
184bool
185VNTWIFIbConfigPhyMode(
186 void *pMgmtHandle,
187 CARD_PHY_TYPE ePhyType
188);
189
190void
191VNTWIFIbGetConfigPhyMode(
192 void *pMgmtHandle,
193 void *pePhyType
194);
195
196void
197VNTWIFIvQueryBSSList(void *pMgmtHandle, unsigned int *puBSSCount,
198 void **pvFirstBSS);
199
200void
201VNTWIFIvGetNextBSS(
202 void *pMgmtHandle,
203 void *pvCurrentBSS,
204 void **pvNextBSS
205);
206
207void
208VNTWIFIvUpdateNodeTxCounter(
209 void *pMgmtHandle,
210 unsigned char *pbyDestAddress,
211 bool bTxOk,
212 unsigned short wRate,
213 unsigned char *pbyTxFailCount
214);
215
216void
217VNTWIFIvGetTxRate(
218 void *pMgmtHandle,
219 unsigned char *pbyDestAddress,
220 unsigned short *pwTxDataRate,
221 unsigned char *pbyACKRate,
222 unsigned char *pbyCCKBasicRate,
223 unsigned char *pbyOFDMBasicRate
224);
225
226unsigned char
227VNTWIFIbyGetKeyCypher(
228 void *pMgmtHandle,
229 bool bGroupKey
230);
231
232bool
233VNTWIFIbSetPMKIDCache(
234 void *pMgmtObject,
235 unsigned long ulCount,
236 void *pPMKIDInfo
237);
238
239bool
240VNTWIFIbCommandRunning(
241 void *pMgmtObject
242);
243
244unsigned short
245VNTWIFIwGetMaxSupportRate(
246 void *pMgmtObject
247);
248
249// for 802.11h
250void
251VNTWIFIvSet11h(
252 void *pMgmtObject,
253 bool b11hEnable
254);
255
256bool
257VNTWIFIbMeasureReport(
258 void *pMgmtObject,
259 bool bEndOfReport,
260 void *pvMeasureEID,
261 unsigned char byReportMode,
262 unsigned char byBasicMap,
263 unsigned char byCCAFraction,
264 unsigned char *pbyRPIs
265);
266
267bool
268VNTWIFIbChannelSwitch(
269 void *pMgmtObject,
270 unsigned char byNewChannel
271);
272
273#endif //__VNTWIFI_H__
diff --git a/drivers/staging/vt6655/wcmd.c b/drivers/staging/vt6655/wcmd.c
deleted file mode 100644
index 985e1b99362d..000000000000
--- a/drivers/staging/vt6655/wcmd.c
+++ /dev/null
@@ -1,1023 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: wcmd.c
20 *
21 * Purpose: Handles the management command interface functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 8, 2003
26 *
27 * Functions:
28 * s_vProbeChannel - Active scan channel
29 * s_MgrMakeProbeRequest - Make ProbeRequest packet
30 * CommandTimer - Timer function to handle command
31 * s_bCommandComplete - Command Complete function
32 * bScheduleCommand - Push Command and wait Command Scheduler to do
33 * vCommandTimer- Command call back functions
34 * vCommandTimerWait- Call back timer
35 * bClearBSSID_SCAN- Clear BSSID_SCAN cmd in CMD Queue
36 *
37 * Revision History:
38 *
39 */
40
41#include "ttype.h"
42#include "tmacro.h"
43#include "device.h"
44#include "mac.h"
45#include "card.h"
46#include "80211hdr.h"
47#include "wcmd.h"
48#include "wmgr.h"
49#include "power.h"
50#include "wctl.h"
51#include "baseband.h"
52#include "rxtx.h"
53#include "rf.h"
54#include "iowpa.h"
55#include "channel.h"
56
57/*--------------------- Static Definitions -------------------------*/
58
59/*--------------------- Static Classes ----------------------------*/
60
61/*--------------------- Static Functions --------------------------*/
62
63static
64void
65s_vProbeChannel(
66 struct vnt_private *pDevice
67);
68
69static
70PSTxMgmtPacket
71s_MgrMakeProbeRequest(
72 struct vnt_private *pDevice,
73 PSMgmtObject pMgmt,
74 unsigned char *pScanBSSID,
75 PWLAN_IE_SSID pSSID,
76 PWLAN_IE_SUPP_RATES pCurrRates,
77 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
78);
79
80static
81bool
82s_bCommandComplete(
83 struct vnt_private *pDevice
84);
85
86/*--------------------- Export Variables --------------------------*/
87
88/*--------------------- Export Functions --------------------------*/
89
90/*
91 * Description:
92 * Stop AdHoc beacon during scan process
93 *
94 * Parameters:
95 * In:
96 * pDevice - Pointer to the adapter
97 * Out:
98 * none
99 *
100 * Return Value: none
101 *
102 */
103static
104void
105vAdHocBeaconStop(struct vnt_private *pDevice)
106{
107 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
108 bool bStop;
109
110 /*
111 * temporarily stop Beacon packet for AdHoc Server
112 * if all of the following conditions are met:
113 * (1) STA is in AdHoc mode
114 * (2) VT3253 is programmed as automatic Beacon Transmitting
115 * (3) One of the following conditions is met
116 * (3.1) AdHoc channel is in B/G band and the
117 * current scan channel is in A band
118 * or
119 * (3.2) AdHoc channel is in A mode
120 */
121 bStop = false;
122 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
123 (pMgmt->eCurrState >= WMAC_STATE_STARTED)) {
124 if ((pMgmt->uIBSSChannel <= CB_MAX_CHANNEL_24G) &&
125 (pMgmt->uScanChannel > CB_MAX_CHANNEL_24G)) {
126 bStop = true;
127 }
128 if (pMgmt->uIBSSChannel > CB_MAX_CHANNEL_24G)
129 bStop = true;
130
131 }
132
133 if (bStop)
134 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
135} /* vAdHocBeaconStop */
136
137/*
138 * Description:
139 * Restart AdHoc beacon after scan process complete
140 *
141 * Parameters:
142 * In:
143 * pDevice - Pointer to the adapter
144 * Out:
145 * none
146 *
147 * Return Value: none
148 *
149 */
150static
151void
152vAdHocBeaconRestart(struct vnt_private *pDevice)
153{
154 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
155
156 /*
157 * Restart Beacon packet for AdHoc Server
158 * if all of the following coditions are met:
159 * (1) STA is in AdHoc mode
160 * (2) VT3253 is programmed as automatic Beacon Transmitting
161 */
162 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
163 (pMgmt->eCurrState >= WMAC_STATE_STARTED)) {
164 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
165 }
166}
167
168/*+
169 *
170 * Routine Description:
171 * Prepare and send probe request management frames.
172 *
173 *
174 * Return Value:
175 * none.
176 *
177 -*/
178
179static
180void
181s_vProbeChannel(
182 struct vnt_private *pDevice
183)
184{
185 //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
186 unsigned char abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
187 unsigned char abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
188 //6M, 9M, 12M, 48M
189 unsigned char abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
190 unsigned char abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
191 unsigned char *pbyRate;
192 PSTxMgmtPacket pTxPacket;
193 PSMgmtObject pMgmt = pDevice->pMgmt;
194 unsigned int ii;
195
196 if (pDevice->eCurrentPHYType == PHY_TYPE_11A)
197 pbyRate = &abyCurrSuppRatesA[0];
198 else if (pDevice->eCurrentPHYType == PHY_TYPE_11B)
199 pbyRate = &abyCurrSuppRatesB[0];
200 else
201 pbyRate = &abyCurrSuppRatesG[0];
202
203 // build an assocreq frame and send it
204 pTxPacket = s_MgrMakeProbeRequest
205 (
206 pDevice,
207 pMgmt,
208 pMgmt->abyScanBSSID,
209 (PWLAN_IE_SSID)pMgmt->abyScanSSID,
210 (PWLAN_IE_SUPP_RATES)pbyRate,
211 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRatesG
212 );
213
214 if (pTxPacket != NULL) {
215 for (ii = 0; ii < 2; ii++) {
216 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING)
217 pr_debug("Probe request sending fail..\n");
218 else
219 pr_debug("Probe request is sending..\n");
220 }
221 }
222}
223
224/*+
225 *
226 * Routine Description:
227 * Constructs an probe request frame
228 *
229 *
230 * Return Value:
231 * A ptr to Tx frame or NULL on allocation failure
232 *
233 -*/
234
235static PSTxMgmtPacket
236s_MgrMakeProbeRequest(
237 struct vnt_private *pDevice,
238 PSMgmtObject pMgmt,
239 unsigned char *pScanBSSID,
240 PWLAN_IE_SSID pSSID,
241 PWLAN_IE_SUPP_RATES pCurrRates,
242 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
243
244)
245{
246 PSTxMgmtPacket pTxPacket = NULL;
247 WLAN_FR_PROBEREQ sFrame;
248
249 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
250 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_PROBEREQ_FR_MAXLEN);
251 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
252 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
253 sFrame.len = WLAN_PROBEREQ_FR_MAXLEN;
254 vMgrEncodeProbeRequest(&sFrame);
255 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
256 (
257 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
258 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PROBEREQ)
259));
260 memcpy(sFrame.pHdr->sA3.abyAddr1, pScanBSSID, WLAN_ADDR_LEN);
261 memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
262 memcpy(sFrame.pHdr->sA3.abyAddr3, pScanBSSID, WLAN_BSSID_LEN);
263 // Copy the SSID, pSSID->len=0 indicate broadcast SSID
264 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
265 sFrame.len += pSSID->len + WLAN_IEHDR_LEN;
266 memcpy(sFrame.pSSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
267 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
268 sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
269 memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
270 // Copy the extension rate set
271 if (pDevice->eCurrentPHYType == PHY_TYPE_11G) {
272 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
273 sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
274 memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
275 }
276 pTxPacket->cbMPDULen = sFrame.len;
277 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
278
279 return pTxPacket;
280}
281
282void
283vCommandTimerWait(
284 void *hDeviceContext,
285 unsigned int MSecond
286)
287{
288 struct vnt_private *pDevice = hDeviceContext;
289
290 init_timer(&pDevice->sTimerCommand);
291 pDevice->sTimerCommand.data = (unsigned long) pDevice;
292 pDevice->sTimerCommand.function = (TimerFunction)vCommandTimer;
293 // RUN_AT :1 msec ~= (HZ/1024)
294 pDevice->sTimerCommand.expires = (unsigned int)RUN_AT((MSecond * HZ) >> 10);
295 add_timer(&pDevice->sTimerCommand);
296}
297
298void
299vCommandTimer(
300 void *hDeviceContext
301)
302{
303 struct vnt_private *pDevice = hDeviceContext;
304 PSMgmtObject pMgmt = pDevice->pMgmt;
305 PWLAN_IE_SSID pItemSSID;
306 PWLAN_IE_SSID pItemSSIDCurr;
307 CMD_STATUS Status;
308 unsigned int ii;
309 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
310 struct sk_buff *skb;
311
312 if (pDevice->dwDiagRefCount != 0)
313 return;
314 if (!pDevice->bCmdRunning)
315 return;
316
317 spin_lock_irq(&pDevice->lock);
318
319 switch (pDevice->eCommandState) {
320 case WLAN_CMD_SCAN_START:
321
322 pDevice->byReAssocCount = 0;
323 if (pDevice->bRadioOff) {
324 s_bCommandComplete(pDevice);
325 spin_unlock_irq(&pDevice->lock);
326 return;
327 }
328
329 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
330 s_bCommandComplete(pDevice);
331 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, NL80211_IFTYPE_AP);
332 spin_unlock_irq(&pDevice->lock);
333 return;
334 }
335
336 pr_debug("eCommandState= WLAN_CMD_SCAN_START\n");
337 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyScanSSID;
338 // wait all Data TD complete
339 if (pDevice->iTDUsed[TYPE_AC0DMA] != 0) {
340 spin_unlock_irq(&pDevice->lock);
341 vCommandTimerWait((void *)pDevice, 10);
342 return;
343 }
344
345 if (pMgmt->uScanChannel == 0) {
346 pMgmt->uScanChannel = pDevice->byMinChannel;
347 // Set Baseband to be more sensitive.
348
349 }
350 if (pMgmt->uScanChannel > pDevice->byMaxChannel) {
351 pMgmt->eScanState = WMAC_NO_SCANNING;
352
353 // Set Baseband's sensitivity back.
354 // Set channel back
355 set_channel(pMgmt->pAdapter, pMgmt->uCurrChannel);
356 pr_debug("Scanning, set back to channel: [%d]\n",
357 pMgmt->uCurrChannel);
358 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)
359 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, NL80211_IFTYPE_ADHOC);
360 else
361 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, NL80211_IFTYPE_STATION);
362
363 vAdHocBeaconRestart(pDevice);
364 s_bCommandComplete(pDevice);
365
366 } else {
367//2008-8-4 <add> by chester
368 if (!is_channel_valid(pMgmt->uScanChannel)) {
369 pr_debug("Invalid channel pMgmt->uScanChannel = %d\n",
370 pMgmt->uScanChannel);
371 s_bCommandComplete(pDevice);
372 spin_unlock_irq(&pDevice->lock);
373 return;
374 }
375 if (pMgmt->uScanChannel == pDevice->byMinChannel) {
376 pMgmt->abyScanBSSID[0] = 0xFF;
377 pMgmt->abyScanBSSID[1] = 0xFF;
378 pMgmt->abyScanBSSID[2] = 0xFF;
379 pMgmt->abyScanBSSID[3] = 0xFF;
380 pMgmt->abyScanBSSID[4] = 0xFF;
381 pMgmt->abyScanBSSID[5] = 0xFF;
382 pItemSSID->byElementID = WLAN_EID_SSID;
383 pMgmt->eScanState = WMAC_IS_SCANNING;
384
385 }
386
387 vAdHocBeaconStop(pDevice);
388
389 if (set_channel(pMgmt->pAdapter, pMgmt->uScanChannel))
390 pr_debug("SCAN Channel: %d\n",
391 pMgmt->uScanChannel);
392 else
393 pr_debug("SET SCAN Channel Fail: %d\n",
394 pMgmt->uScanChannel);
395
396 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, NL80211_IFTYPE_UNSPECIFIED);
397 pMgmt->uScanChannel++;
398//2008-8-4 <modify> by chester
399 if (!is_channel_valid(pMgmt->uScanChannel) &&
400 pMgmt->uScanChannel <= pDevice->byMaxChannel) {
401 pMgmt->uScanChannel = pDevice->byMaxChannel + 1;
402 pMgmt->eCommandState = WLAN_CMD_SCAN_END;
403
404 }
405
406 if (!pMgmt->b11hEnable ||
407 (pMgmt->uScanChannel < CB_MAX_CHANNEL_24G)) {
408 s_vProbeChannel(pDevice);
409 spin_unlock_irq(&pDevice->lock);
410 vCommandTimerWait((void *)pDevice, WCMD_ACTIVE_SCAN_TIME);
411 return;
412 } else {
413 spin_unlock_irq(&pDevice->lock);
414 vCommandTimerWait((void *)pDevice, WCMD_PASSIVE_SCAN_TIME);
415 return;
416 }
417
418 }
419
420 break;
421
422 case WLAN_CMD_SCAN_END:
423
424 // Set Baseband's sensitivity back.
425 // Set channel back
426 set_channel(pMgmt->pAdapter, pMgmt->uCurrChannel);
427 pr_debug("Scanning, set back to channel: [%d]\n",
428 pMgmt->uCurrChannel);
429 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)
430 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, NL80211_IFTYPE_ADHOC);
431 else
432 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, NL80211_IFTYPE_STATION);
433
434 pMgmt->eScanState = WMAC_NO_SCANNING;
435 vAdHocBeaconRestart(pDevice);
436//2008-0409-07, <Add> by Einsn Liu
437#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
438 if (pMgmt->eScanType == WMAC_SCAN_PASSIVE) {
439 //send scan event to wpa_Supplicant
440 union iwreq_data wrqu;
441
442 memset(&wrqu, 0, sizeof(wrqu));
443 wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
444 }
445#endif
446 s_bCommandComplete(pDevice);
447 break;
448
449 case WLAN_CMD_DISASSOCIATE_START:
450 pDevice->byReAssocCount = 0;
451 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
452 (pMgmt->eCurrState != WMAC_STATE_ASSOC)) {
453 s_bCommandComplete(pDevice);
454 spin_unlock_irq(&pDevice->lock);
455 return;
456 } else {
457 pr_debug("Send Disassociation Packet..\n");
458 // reason = 8 : disassoc because sta has left
459 vMgrDisassocBeginSta((void *)pDevice, pMgmt, pMgmt->abyCurrBSSID, (8), &Status);
460 pDevice->bLinkPass = false;
461 // unlock command busy
462 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
463 pItemSSID->len = 0;
464 memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
465 pMgmt->eCurrState = WMAC_STATE_IDLE;
466 pMgmt->sNodeDBTable[0].bActive = false;
467 }
468 netif_stop_queue(pDevice->dev);
469 pDevice->eCommandState = WLAN_DISASSOCIATE_WAIT;
470 // wait all Control TD complete
471 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0) {
472 vCommandTimerWait((void *)pDevice, 10);
473 spin_unlock_irq(&pDevice->lock);
474 return;
475 }
476 pr_debug(" CARDbRadioPowerOff\n");
477 //2008-09-02 <mark> by chester
478 s_bCommandComplete(pDevice);
479 break;
480
481 case WLAN_DISASSOCIATE_WAIT:
482 // wait all Control TD complete
483 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0) {
484 vCommandTimerWait((void *)pDevice, 10);
485 spin_unlock_irq(&pDevice->lock);
486 return;
487 }
488//2008-09-02 <mark> by chester
489 s_bCommandComplete(pDevice);
490 break;
491
492 case WLAN_CMD_SSID_START:
493 pDevice->byReAssocCount = 0;
494 if (pDevice->bRadioOff) {
495 s_bCommandComplete(pDevice);
496 spin_unlock_irq(&pDevice->lock);
497 return;
498 }
499 pr_debug("chester-abyDesireSSID=%s\n", ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID);
500 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
501 pItemSSIDCurr = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
502 pr_debug(" cmd: desire ssid = %s\n", pItemSSID->abySSID);
503 pr_debug(" cmd: curr ssid = %s\n", pItemSSIDCurr->abySSID);
504
505 if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
506 pr_debug(" Cmd pMgmt->eCurrState == WMAC_STATE_ASSOC\n");
507 pr_debug(" pItemSSID->len =%d\n", pItemSSID->len);
508 pr_debug(" pItemSSIDCurr->len = %d\n",
509 pItemSSIDCurr->len);
510 pr_debug(" desire ssid = %s\n", pItemSSID->abySSID);
511 pr_debug(" curr ssid = %s\n", pItemSSIDCurr->abySSID);
512 }
513
514 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
515 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
516 if (pItemSSID->len == pItemSSIDCurr->len) {
517 if (memcmp(pItemSSID->abySSID, pItemSSIDCurr->abySSID, pItemSSID->len) == 0) {
518 s_bCommandComplete(pDevice);
519 spin_unlock_irq(&pDevice->lock);
520 return;
521 }
522 }
523
524 netif_stop_queue(pDevice->dev);
525 pDevice->bLinkPass = false;
526 }
527 // set initial state
528 pMgmt->eCurrState = WMAC_STATE_IDLE;
529 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
530 PSvDisablePowerSaving((void *)pDevice);
531 BSSvClearNodeDBTable(pDevice, 0);
532
533 vMgrJoinBSSBegin((void *)pDevice, &Status);
534 // if Infra mode
535 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED)) {
536 // Call mgr to begin the deauthentication
537 // reason = (3) because sta has left ESS
538 if (pMgmt->eCurrState >= WMAC_STATE_AUTH)
539 vMgrDeAuthenBeginSta((void *)pDevice, pMgmt, pMgmt->abyCurrBSSID, (3), &Status);
540
541 // Call mgr to begin the authentication
542 vMgrAuthenBeginSta((void *)pDevice, pMgmt, &Status);
543 if (Status == CMD_STATUS_SUCCESS) {
544 pDevice->byLinkWaitCount = 0;
545 pDevice->eCommandState = WLAN_AUTHENTICATE_WAIT;
546 vCommandTimerWait((void *)pDevice, AUTHENTICATE_TIMEOUT);
547 spin_unlock_irq(&pDevice->lock);
548 pr_debug(" Set eCommandState = WLAN_AUTHENTICATE_WAIT\n");
549 return;
550 }
551 }
552 // if Adhoc mode
553 else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
554 if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
555 if (netif_queue_stopped(pDevice->dev))
556 netif_wake_queue(pDevice->dev);
557
558 pDevice->bLinkPass = true;
559
560 pMgmt->sNodeDBTable[0].bActive = true;
561 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
562 bClearBSSID_SCAN(pDevice);
563 } else {
564 // start own IBSS
565 vMgrCreateOwnIBSS((void *)pDevice, &Status);
566 if (Status != CMD_STATUS_SUCCESS)
567 pr_debug(" WLAN_CMD_IBSS_CREATE fail !\n");
568
569 BSSvAddMulticastNode(pDevice);
570 }
571 }
572 // if SSID not found
573 else if (pMgmt->eCurrMode == WMAC_MODE_STANDBY) {
574 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA ||
575 pMgmt->eConfigMode == WMAC_CONFIG_AUTO) {
576 // start own IBSS
577 vMgrCreateOwnIBSS((void *)pDevice, &Status);
578 if (Status != CMD_STATUS_SUCCESS)
579 pr_debug(" WLAN_CMD_IBSS_CREATE fail !\n");
580
581 BSSvAddMulticastNode(pDevice);
582 if (netif_queue_stopped(pDevice->dev))
583 netif_wake_queue(pDevice->dev);
584
585 pDevice->bLinkPass = true;
586 } else {
587 pr_debug("Disconnect SSID none\n");
588#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
589 {
590 union iwreq_data wrqu;
591
592 memset(&wrqu, 0, sizeof(wrqu));
593 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
594 pr_debug("wireless_send_event--->SIOCGIWAP(disassociated:vMgrJoinBSSBegin Fail !!)\n");
595 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
596 }
597#endif
598
599 }
600 }
601 s_bCommandComplete(pDevice);
602 break;
603
604 case WLAN_AUTHENTICATE_WAIT:
605 pr_debug("eCommandState == WLAN_AUTHENTICATE_WAIT\n");
606 if (pMgmt->eCurrState == WMAC_STATE_AUTH) {
607 // Call mgr to begin the association
608 pDevice->byLinkWaitCount = 0;
609 pr_debug("eCurrState == WMAC_STATE_AUTH\n");
610 vMgrAssocBeginSta((void *)pDevice, pMgmt, &Status);
611 if (Status == CMD_STATUS_SUCCESS) {
612 pDevice->byLinkWaitCount = 0;
613 pr_debug("eCommandState = WLAN_ASSOCIATE_WAIT\n");
614 pDevice->eCommandState = WLAN_ASSOCIATE_WAIT;
615 vCommandTimerWait((void *)pDevice, ASSOCIATE_TIMEOUT);
616 spin_unlock_irq(&pDevice->lock);
617 return;
618 }
619 }
620
621 else if (pMgmt->eCurrState < WMAC_STATE_AUTHPENDING) {
622 pr_debug("WLAN_AUTHENTICATE_WAIT:Authen Fail???\n");
623 } else if (pDevice->byLinkWaitCount <= 4) { //mike add:wait another 2 sec if authenticated_frame delay!
624 pDevice->byLinkWaitCount++;
625 pr_debug("WLAN_AUTHENTICATE_WAIT:wait %d times!!\n", pDevice->byLinkWaitCount);
626 spin_unlock_irq(&pDevice->lock);
627 vCommandTimerWait((void *)pDevice, AUTHENTICATE_TIMEOUT/2);
628 return;
629 }
630 pDevice->byLinkWaitCount = 0;
631 s_bCommandComplete(pDevice);
632 break;
633
634 case WLAN_ASSOCIATE_WAIT:
635 if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
636 pr_debug("eCurrState == WMAC_STATE_ASSOC\n");
637 if (pDevice->ePSMode != WMAC_POWER_CAM)
638 PSvEnablePowerSaving((void *)pDevice, pMgmt->wListenInterval);
639
640 if (pMgmt->eAuthenMode >= WMAC_AUTH_WPA)
641 KeybRemoveAllKey(&(pDevice->sKey), pDevice->abyBSSID, pDevice->PortOffset);
642
643 pDevice->bLinkPass = true;
644 pDevice->byLinkWaitCount = 0;
645 pDevice->byReAssocCount = 0;
646 bClearBSSID_SCAN(pDevice);
647 if (pDevice->byFOETuning) {
648 BBvSetFOE(pDevice->PortOffset);
649 PSbSendNullPacket(pDevice);
650 }
651 if (netif_queue_stopped(pDevice->dev))
652 netif_wake_queue(pDevice->dev);
653
654 if (pDevice->IsTxDataTrigger) { //TxDataTimer is not triggered at the first time
655 del_timer(&pDevice->sTimerTxData);
656 init_timer(&pDevice->sTimerTxData);
657 pDevice->sTimerTxData.data = (unsigned long) pDevice;
658 pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData;
659 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
660 pDevice->fTxDataInSleep = false;
661 pDevice->nTxDataTimeCout = 0;
662 }
663
664 pDevice->IsTxDataTrigger = true;
665 add_timer(&pDevice->sTimerTxData);
666
667 } else if (pMgmt->eCurrState < WMAC_STATE_ASSOCPENDING) {
668 printk("WLAN_ASSOCIATE_WAIT:Association Fail???\n");
669 } else if (pDevice->byLinkWaitCount <= 4) { //mike add:wait another 2 sec if associated_frame delay!
670 pDevice->byLinkWaitCount++;
671 pr_debug("WLAN_ASSOCIATE_WAIT:wait %d times!!\n", pDevice->byLinkWaitCount);
672 spin_unlock_irq(&pDevice->lock);
673 vCommandTimerWait((void *)pDevice, ASSOCIATE_TIMEOUT/2);
674 return;
675 }
676 pDevice->byLinkWaitCount = 0;
677
678 s_bCommandComplete(pDevice);
679 break;
680
681 case WLAN_CMD_AP_MODE_START:
682 pr_debug("eCommandState == WLAN_CMD_AP_MODE_START\n");
683
684 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
685 del_timer(&pMgmt->sTimerSecondCallback);
686 pMgmt->eCurrState = WMAC_STATE_IDLE;
687 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
688 pDevice->bLinkPass = false;
689 if (pDevice->bEnableHostWEP)
690 BSSvClearNodeDBTable(pDevice, 1);
691 else
692 BSSvClearNodeDBTable(pDevice, 0);
693 pDevice->uAssocCount = 0;
694 pMgmt->eCurrState = WMAC_STATE_IDLE;
695 pDevice->bFixRate = false;
696
697 vMgrCreateOwnIBSS((void *)pDevice, &Status);
698 if (Status != CMD_STATUS_SUCCESS)
699 pr_debug(" vMgrCreateOwnIBSS fail !\n");
700
701 // alway turn off unicast bit
702 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_UNICAST);
703 pDevice->byRxMode &= ~RCR_UNICAST;
704 pr_debug("wcmd: rx_mode = %x\n", pDevice->byRxMode);
705 BSSvAddMulticastNode(pDevice);
706 if (netif_queue_stopped(pDevice->dev))
707 netif_wake_queue(pDevice->dev);
708
709 pDevice->bLinkPass = true;
710 add_timer(&pMgmt->sTimerSecondCallback);
711 }
712 s_bCommandComplete(pDevice);
713 break;
714
715 case WLAN_CMD_TX_PSPACKET_START:
716 // DTIM Multicast tx
717 if (pMgmt->sNodeDBTable[0].bRxPSPoll) {
718 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[0].sTxPSQueue)) != NULL) {
719 if (skb_queue_empty(&pMgmt->sNodeDBTable[0].sTxPSQueue)) {
720 pMgmt->abyPSTxMap[0] &= ~byMask[0];
721 pDevice->bMoreData = false;
722 } else {
723 pDevice->bMoreData = true;
724 }
725 if (!device_dma0_xmit(pDevice, skb, 0))
726 pr_debug("Multicast ps tx fail\n");
727
728 pMgmt->sNodeDBTable[0].wEnQueueCnt--;
729 }
730 }
731
732 // PS nodes tx
733 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
734 if (pMgmt->sNodeDBTable[ii].bActive &&
735 pMgmt->sNodeDBTable[ii].bRxPSPoll) {
736 pr_debug("Index=%d Enqueu Cnt= %d\n",
737 ii,
738 pMgmt->sNodeDBTable[ii].wEnQueueCnt);
739 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL) {
740 if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
741 // clear tx map
742 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
743 ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
744 pDevice->bMoreData = false;
745 } else {
746 pDevice->bMoreData = true;
747 }
748 if (!device_dma0_xmit(pDevice, skb, ii))
749 pr_debug("sta ps tx fail\n");
750
751 pMgmt->sNodeDBTable[ii].wEnQueueCnt--;
752 // check if sta ps enabled, and wait next pspoll.
753 // if sta ps disable, then send all pending buffers.
754 if (pMgmt->sNodeDBTable[ii].bPSEnable)
755 break;
756 }
757 if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
758 // clear tx map
759 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
760 ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
761 pr_debug("Index=%d PS queue clear\n",
762 ii);
763 }
764 pMgmt->sNodeDBTable[ii].bRxPSPoll = false;
765 }
766 }
767
768 s_bCommandComplete(pDevice);
769 break;
770
771 case WLAN_CMD_RADIO_START:
772 pr_debug("eCommandState == WLAN_CMD_RADIO_START\n");
773 if (pDevice->bRadioCmd)
774 CARDbRadioPowerOn(pDevice);
775 else
776 CARDbRadioPowerOff(pDevice);
777
778 s_bCommandComplete(pDevice);
779 break;
780
781 case WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE:
782 // wait all TD complete
783 if (pDevice->iTDUsed[TYPE_AC0DMA] != 0) {
784 vCommandTimerWait((void *)pDevice, 10);
785 spin_unlock_irq(&pDevice->lock);
786 return;
787 }
788 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0) {
789 vCommandTimerWait((void *)pDevice, 10);
790 spin_unlock_irq(&pDevice->lock);
791 return;
792 }
793 pDevice->byBBVGACurrent = pDevice->byBBVGANew;
794 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
795 pr_debug("SetVGAGainOffset %02X\n", pDevice->byBBVGACurrent);
796 s_bCommandComplete(pDevice);
797 break;
798
799 default:
800 s_bCommandComplete(pDevice);
801 break;
802
803 } //switch
804 spin_unlock_irq(&pDevice->lock);
805}
806
807static
808bool
809s_bCommandComplete(
810 struct vnt_private *pDevice
811)
812{
813 PWLAN_IE_SSID pSSID;
814 bool bRadioCmd = false;
815 bool bForceSCAN = true;
816 PSMgmtObject pMgmt = pDevice->pMgmt;
817
818 pDevice->eCommandState = WLAN_CMD_IDLE;
819 if (pDevice->cbFreeCmdQueue == CMD_Q_SIZE) {
820 //Command Queue Empty
821 pDevice->bCmdRunning = false;
822 return true;
823 } else {
824 pDevice->eCommand = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].eCmd;
825 pSSID = (PWLAN_IE_SSID)pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].abyCmdDesireSSID;
826 bRadioCmd = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bRadioCmd;
827 bForceSCAN = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bForceSCAN;
828 ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdDequeueIdx, CMD_Q_SIZE);
829 pDevice->cbFreeCmdQueue++;
830 pDevice->bCmdRunning = true;
831 switch (pDevice->eCommand) {
832 case WLAN_CMD_BSSID_SCAN:
833 pr_debug("eCommandState= WLAN_CMD_BSSID_SCAN\n");
834 pDevice->eCommandState = WLAN_CMD_SCAN_START;
835 pMgmt->uScanChannel = 0;
836 if (pSSID->len != 0)
837 memcpy(pMgmt->abyScanSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
838 else
839 memset(pMgmt->abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
840
841 break;
842 case WLAN_CMD_SSID:
843 pDevice->eCommandState = WLAN_CMD_SSID_START;
844 if (pSSID->len > WLAN_SSID_MAXLEN)
845 pSSID->len = WLAN_SSID_MAXLEN;
846 if (pSSID->len != 0)
847 memcpy(pDevice->pMgmt->abyDesireSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
848 pr_debug("eCommandState= WLAN_CMD_SSID_START\n");
849 break;
850 case WLAN_CMD_DISASSOCIATE:
851 pDevice->eCommandState = WLAN_CMD_DISASSOCIATE_START;
852 break;
853 case WLAN_CMD_RX_PSPOLL:
854 pDevice->eCommandState = WLAN_CMD_TX_PSPACKET_START;
855 break;
856 case WLAN_CMD_RUN_AP:
857 pDevice->eCommandState = WLAN_CMD_AP_MODE_START;
858 break;
859 case WLAN_CMD_RADIO:
860 pDevice->eCommandState = WLAN_CMD_RADIO_START;
861 pDevice->bRadioCmd = bRadioCmd;
862 break;
863 case WLAN_CMD_CHANGE_BBSENSITIVITY:
864 pDevice->eCommandState = WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE;
865 break;
866
867 default:
868 break;
869
870 }
871
872 vCommandTimerWait((void *)pDevice, 0);
873 }
874
875 return true;
876}
877
878bool bScheduleCommand(
879 void *hDeviceContext,
880 CMD_CODE eCommand,
881 unsigned char *pbyItem0
882)
883{
884 struct vnt_private *pDevice = hDeviceContext;
885
886 if (pDevice->cbFreeCmdQueue == 0)
887 return false;
888
889 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].eCmd = eCommand;
890 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = true;
891 memset(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID, 0 , WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
892
893 if (pbyItem0 != NULL) {
894 switch (eCommand) {
895 case WLAN_CMD_BSSID_SCAN:
896 memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
897 pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
898 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = false;
899 break;
900
901 case WLAN_CMD_SSID:
902 memcpy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
903 pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
904 break;
905
906 case WLAN_CMD_DISASSOCIATE:
907 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bNeedRadioOFF = *((int *)pbyItem0);
908 break;
909
910 case WLAN_CMD_RX_PSPOLL:
911 break;
912
913 case WLAN_CMD_RADIO:
914 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bRadioCmd = *((int *)pbyItem0);
915 break;
916
917 case WLAN_CMD_CHANGE_BBSENSITIVITY:
918 pDevice->eCommandState = WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE;
919 break;
920
921 default:
922 break;
923 }
924 }
925
926 ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdEnqueueIdx, CMD_Q_SIZE);
927 pDevice->cbFreeCmdQueue--;
928
929 if (!pDevice->bCmdRunning)
930 s_bCommandComplete(pDevice);
931
932 return true;
933}
934
935/*
936 * Description:
937 * Clear BSSID_SCAN cmd in CMD Queue
938 *
939 * Parameters:
940 * In:
941 * hDeviceContext - Pointer to the adapter
942 * eCommand - Command
943 * Out:
944 * none
945 *
946 * Return Value: true if success; otherwise false
947 *
948 */
949bool bClearBSSID_SCAN(
950 void *hDeviceContext
951)
952{
953 struct vnt_private *pDevice = hDeviceContext;
954 unsigned int uCmdDequeueIdx = pDevice->uCmdDequeueIdx;
955 unsigned int ii;
956
957 if ((pDevice->cbFreeCmdQueue < CMD_Q_SIZE) && (uCmdDequeueIdx != pDevice->uCmdEnqueueIdx)) {
958 for (ii = 0; ii < (CMD_Q_SIZE - pDevice->cbFreeCmdQueue); ii++) {
959 if (pDevice->eCmdQueue[uCmdDequeueIdx].eCmd == WLAN_CMD_BSSID_SCAN)
960 pDevice->eCmdQueue[uCmdDequeueIdx].eCmd = WLAN_CMD_IDLE;
961 ADD_ONE_WITH_WRAP_AROUND(uCmdDequeueIdx, CMD_Q_SIZE);
962 if (uCmdDequeueIdx == pDevice->uCmdEnqueueIdx)
963 break;
964 }
965 }
966 return true;
967}
968
969//mike add:reset command timer
970void
971vResetCommandTimer(
972 void *hDeviceContext
973)
974{
975 struct vnt_private *pDevice = hDeviceContext;
976
977 //delete timer
978 del_timer(&pDevice->sTimerCommand);
979 //init timer
980 init_timer(&pDevice->sTimerCommand);
981 pDevice->sTimerCommand.data = (unsigned long) pDevice;
982 pDevice->sTimerCommand.function = (TimerFunction)vCommandTimer;
983 pDevice->sTimerCommand.expires = RUN_AT(HZ);
984 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
985 pDevice->uCmdDequeueIdx = 0;
986 pDevice->uCmdEnqueueIdx = 0;
987 pDevice->eCommandState = WLAN_CMD_IDLE;
988 pDevice->bCmdRunning = false;
989 pDevice->bCmdClear = false;
990}
991
992void
993BSSvSecondTxData(
994 void *hDeviceContext
995)
996{
997 struct vnt_private *pDevice = hDeviceContext;
998 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
999
1000 pDevice->nTxDataTimeCout++;
1001
1002 if (pDevice->nTxDataTimeCout < 4) //don't tx data if timer less than 40s
1003 {
1004 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
1005 add_timer(&pDevice->sTimerTxData);
1006 return;
1007 }
1008
1009 spin_lock_irq(&pDevice->lock);
1010
1011 /* open && sharekey linking */
1012 if ((pDevice->bLinkPass && (pMgmt->eAuthenMode < WMAC_AUTH_WPA)) ||
1013 pDevice->fWPA_Authened) { /* wpa linking */
1014 pDevice->fTxDataInSleep = true;
1015 PSbSendNullPacket(pDevice); /* send null packet */
1016 pDevice->fTxDataInSleep = false;
1017 }
1018
1019 spin_unlock_irq(&pDevice->lock);
1020
1021 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); /* 10s callback */
1022 add_timer(&pDevice->sTimerTxData);
1023}
diff --git a/drivers/staging/vt6655/wcmd.h b/drivers/staging/vt6655/wcmd.h
deleted file mode 100644
index 6ef04de69f37..000000000000
--- a/drivers/staging/vt6655/wcmd.h
+++ /dev/null
@@ -1,123 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: wcmd.h
20 *
21 * Purpose: Handles the management command interface functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 8, 2002
26 *
27 */
28
29#ifndef __WCMD_H__
30#define __WCMD_H__
31
32#include "ttype.h"
33#include "80211hdr.h"
34#include "80211mgr.h"
35
36#define AUTHENTICATE_TIMEOUT 1000
37#define ASSOCIATE_TIMEOUT 1000
38
39typedef enum tagCMD_CODE {
40 WLAN_CMD_BSSID_SCAN,
41 WLAN_CMD_SSID,
42 WLAN_CMD_DISASSOCIATE,
43 WLAN_CMD_DEAUTH,
44 WLAN_CMD_RX_PSPOLL,
45 WLAN_CMD_RADIO,
46 WLAN_CMD_CHANGE_BBSENSITIVITY,
47 WLAN_CMD_SETPOWER,
48 WLAN_CMD_TBTT_WAKEUP,
49 WLAN_CMD_BECON_SEND,
50 WLAN_CMD_CHANGE_ANTENNA,
51 WLAN_CMD_REMOVE_ALLKEY,
52 WLAN_CMD_MAC_DISPOWERSAVING,
53 WLAN_CMD_11H_CHSW,
54 WLAN_CMD_RUN_AP
55} CMD_CODE, *PCMD_CODE;
56
57#define CMD_Q_SIZE 32
58
59typedef enum tagCMD_STATUS {
60 CMD_STATUS_SUCCESS = 0,
61 CMD_STATUS_FAILURE,
62 CMD_STATUS_RESOURCES,
63 CMD_STATUS_TIMEOUT,
64 CMD_STATUS_PENDING
65} CMD_STATUS, *PCMD_STATUS;
66
67typedef struct tagCMD_ITEM {
68 CMD_CODE eCmd;
69 unsigned char abyCmdDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
70 bool bNeedRadioOFF;
71 unsigned short wDeAuthenReason;
72 bool bRadioCmd;
73 bool bForceSCAN;
74} CMD_ITEM, *PCMD_ITEM;
75
76typedef enum tagCMD_STATE {
77 WLAN_CMD_SCAN_START,
78 WLAN_CMD_SCAN_END,
79 WLAN_CMD_DISASSOCIATE_START,
80 WLAN_CMD_SSID_START,
81 WLAN_AUTHENTICATE_WAIT,
82 WLAN_ASSOCIATE_WAIT,
83 WLAN_DISASSOCIATE_WAIT,
84 WLAN_CMD_TX_PSPACKET_START,
85 WLAN_CMD_AP_MODE_START,
86 WLAN_CMD_RADIO_START,
87 WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE,
88 WLAN_CMD_IDLE
89} CMD_STATE, *PCMD_STATE;
90
91void
92vResetCommandTimer(
93 void *hDeviceContext
94);
95
96void
97vCommandTimer(
98 void *hDeviceContext
99);
100
101bool bClearBSSID_SCAN(
102 void *hDeviceContext
103);
104
105bool
106bScheduleCommand(
107 void *hDeviceContext,
108 CMD_CODE eCommand,
109 unsigned char *pbyItem0
110);
111
112void
113vCommandTimerWait(
114 void *hDeviceContext,
115 unsigned int MSecond
116);
117
118void
119BSSvSecondTxData(
120 void *hDeviceContext
121);
122
123#endif //__WCMD_H__
diff --git a/drivers/staging/vt6655/wctl.c b/drivers/staging/vt6655/wctl.c
deleted file mode 100644
index 5a54d98d985a..000000000000
--- a/drivers/staging/vt6655/wctl.c
+++ /dev/null
@@ -1,233 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: wctl.c
20 *
21 * Purpose: handle WMAC duplicate filter & defragment
22 *
23 * Author: Jerry Chen
24 *
25 * Date: Jun. 27, 2002
26 *
27 * Functions:
28 * WCTLbIsDuplicate - Test if duplicate packet
29 * WCTLuSearchDFCB - Search DeFragment Control Database
30 * WCTLuInsertDFCB - Insert DeFragment Control Database
31 * WCTLbHandleFragment - Handle received fragment packet
32 *
33 * Revision History:
34 *
35 */
36
37#include "wctl.h"
38#include "device.h"
39#include "card.h"
40
41/*--------------------- Static Definitions -------------------------*/
42
43/*--------------------- Static Classes ----------------------------*/
44
45/*--------------------- Static Variables --------------------------*/
46
47/*--------------------- Static Functions --------------------------*/
48
49/*--------------------- Export Variables --------------------------*/
50
51/*
52 * Description:
53 * Scan Rx cache. Return true if packet is duplicate, else
54 * inserts in receive cache and returns false.
55 *
56 * Parameters:
57 * In:
58 * pCache - Receive packets history
59 * pMACHeader - 802.11 MAC Header of received packet
60 * Out:
61 * none
62 *
63 * Return Value: true if packet duplicate; otherwise false
64 *
65 */
66
67bool WCTLbIsDuplicate(PSCache pCache, PS802_11Header pMACHeader)
68{
69 unsigned int uIndex;
70 unsigned int ii;
71 PSCacheEntry pCacheEntry;
72
73 if (IS_FC_RETRY(pMACHeader)) {
74 uIndex = pCache->uInPtr;
75 for (ii = 0; ii < DUPLICATE_RX_CACHE_LENGTH; ii++) {
76 pCacheEntry = &(pCache->asCacheEntry[uIndex]);
77 if ((pCacheEntry->wFmSequence == pMACHeader->wSeqCtl) &&
78 ether_addr_equal(pCacheEntry->abyAddr2,
79 pMACHeader->abyAddr2)) {
80 /* Duplicate match */
81 return true;
82 }
83 ADD_ONE_WITH_WRAP_AROUND(uIndex, DUPLICATE_RX_CACHE_LENGTH);
84 }
85 }
86 /* Not fount in cache - insert */
87 pCacheEntry = &pCache->asCacheEntry[pCache->uInPtr];
88 pCacheEntry->wFmSequence = pMACHeader->wSeqCtl;
89 memcpy(&(pCacheEntry->abyAddr2[0]), &(pMACHeader->abyAddr2[0]), ETH_ALEN);
90 ADD_ONE_WITH_WRAP_AROUND(pCache->uInPtr, DUPLICATE_RX_CACHE_LENGTH);
91 return false;
92}
93
94/*
95 * Description:
96 * Found if sequence number of received fragment packet in Defragment Database
97 *
98 * Parameters:
99 * In:
100 * pDevice - Pointer to adapter
101 * pMACHeader - 802.11 MAC Header of received packet
102 * Out:
103 * none
104 *
105 * Return Value: index number in Defragment Database
106 *
107 */
108unsigned int WCTLuSearchDFCB(struct vnt_private *pDevice,
109 PS802_11Header pMACHeader)
110{
111 unsigned int ii;
112
113 for (ii = 0; ii < pDevice->cbDFCB; ii++) {
114 if (pDevice->sRxDFCB[ii].bInUse &&
115 ether_addr_equal(pDevice->sRxDFCB[ii].abyAddr2,
116 pMACHeader->abyAddr2)) {
117 return ii;
118 }
119 }
120 return pDevice->cbDFCB;
121}
122
123/*
124 * Description:
125 * Insert received fragment packet in Defragment Database
126 *
127 * Parameters:
128 * In:
129 * pDevice - Pointer to adapter
130 * pMACHeader - 802.11 MAC Header of received packet
131 * Out:
132 * none
133 *
134 * Return Value: index number in Defragment Database
135 *
136 */
137unsigned int WCTLuInsertDFCB(struct vnt_private *pDevice, PS802_11Header pMACHeader)
138{
139 unsigned int ii;
140
141 if (pDevice->cbFreeDFCB == 0)
142 return pDevice->cbDFCB;
143 for (ii = 0; ii < pDevice->cbDFCB; ii++) {
144 if (!pDevice->sRxDFCB[ii].bInUse) {
145 pDevice->cbFreeDFCB--;
146 pDevice->sRxDFCB[ii].uLifetime = pDevice->dwMaxReceiveLifetime;
147 pDevice->sRxDFCB[ii].bInUse = true;
148 pDevice->sRxDFCB[ii].wSequence = (pMACHeader->wSeqCtl >> 4);
149 pDevice->sRxDFCB[ii].wFragNum = (pMACHeader->wSeqCtl & 0x000F);
150 memcpy(&(pDevice->sRxDFCB[ii].abyAddr2[0]), &(pMACHeader->abyAddr2[0]), ETH_ALEN);
151 return ii;
152 }
153 }
154 return pDevice->cbDFCB;
155}
156
157/*
158 * Description:
159 * Handle received fragment packet
160 *
161 * Parameters:
162 * In:
163 * pDevice - Pointer to adapter
164 * pMACHeader - 802.11 MAC Header of received packet
165 * cbFrameLength - Frame length
166 * bWEP - is WEP packet
167 * Out:
168 * none
169 *
170 * Return Value: true if it is valid fragment packet and we have resource to defragment; otherwise false
171 *
172 */
173bool WCTLbHandleFragment(struct vnt_private *pDevice, PS802_11Header pMACHeader,
174 unsigned int cbFrameLength, bool bWEP, bool bExtIV)
175{
176 unsigned int uHeaderSize;
177
178 if (bWEP) {
179 uHeaderSize = 28;
180 if (bExtIV)
181 // ExtIV
182 uHeaderSize += 4;
183 } else {
184 uHeaderSize = 24;
185 }
186
187 if (IS_FIRST_FRAGMENT_PKT(pMACHeader)) {
188 pDevice->uCurrentDFCBIdx = WCTLuSearchDFCB(pDevice, pMACHeader);
189 if (pDevice->uCurrentDFCBIdx < pDevice->cbDFCB) {
190 // duplicate, we must flush previous DCB
191 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].uLifetime = pDevice->dwMaxReceiveLifetime;
192 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wSequence = (pMACHeader->wSeqCtl >> 4);
193 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum = (pMACHeader->wSeqCtl & 0x000F);
194 } else {
195 pDevice->uCurrentDFCBIdx = WCTLuInsertDFCB(pDevice, pMACHeader);
196 if (pDevice->uCurrentDFCBIdx == pDevice->cbDFCB)
197 return false;
198 }
199 // reserve 4 byte to match MAC RX Buffer
200 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer = (unsigned char *)(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].skb->data + 4);
201 memcpy(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer, pMACHeader, cbFrameLength);
202 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength = cbFrameLength;
203 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer += cbFrameLength;
204 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum++;
205 return false;
206 } else {
207 pDevice->uCurrentDFCBIdx = WCTLuSearchDFCB(pDevice, pMACHeader);
208 if (pDevice->uCurrentDFCBIdx != pDevice->cbDFCB) {
209 if ((pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wSequence == (pMACHeader->wSeqCtl >> 4)) &&
210 (pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum == (pMACHeader->wSeqCtl & 0x000F)) &&
211 ((pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength + cbFrameLength - uHeaderSize) < 2346)) {
212 memcpy(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer, ((unsigned char *)(pMACHeader) + uHeaderSize), (cbFrameLength - uHeaderSize));
213 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength += (cbFrameLength - uHeaderSize);
214 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer += (cbFrameLength - uHeaderSize);
215 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum++;
216 } else {
217 // seq error or frag # error flush DFCB
218 pDevice->cbFreeDFCB++;
219 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = false;
220 return false;
221 }
222 } else {
223 return false;
224 }
225 if (IS_LAST_FRAGMENT_PKT(pMACHeader)) {
226 //enq defragcontrolblock
227 pDevice->cbFreeDFCB++;
228 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = false;
229 return true;
230 }
231 return false;
232 }
233}
diff --git a/drivers/staging/vt6655/wctl.h b/drivers/staging/vt6655/wctl.h
deleted file mode 100644
index f0995d86f71f..000000000000
--- a/drivers/staging/vt6655/wctl.h
+++ /dev/null
@@ -1,105 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: wctl.h
20 *
21 * Purpose:
22 *
23 * Author: Jerry Chen
24 *
25 * Date: Jun. 27, 2002
26 *
27 */
28
29#ifndef __WCTL_H__
30#define __WCTL_H__
31
32#include "ttype.h"
33#include "tether.h"
34#include "device.h"
35
36/*--------------------- Export Definitions -------------------------*/
37
38#define IS_TYPE_DATA(pMACHeader) \
39 ((((PS802_11Header) pMACHeader)->wFrameCtl & TYPE_802_11_MASK) == TYPE_802_11_DATA)
40
41#define IS_TYPE_MGMT(pMACHeader) \
42 ((((PS802_11Header) pMACHeader)->wFrameCtl & TYPE_802_11_MASK) == TYPE_802_11_MGMT)
43
44#define IS_TYPE_CONTROL(pMACHeader) \
45 ((((PS802_11Header) pMACHeader)->wFrameCtl & TYPE_802_11_MASK) == TYPE_802_11_CTL)
46
47#define IS_FC_MOREDATA(pMACHeader) \
48 ((((PS802_11Header) pMACHeader)->wFrameCtl & FC_MOREDATA) == FC_MOREDATA)
49
50#define IS_FC_POWERMGT(pMACHeader) \
51 ((((PS802_11Header) pMACHeader)->wFrameCtl & FC_POWERMGT) == FC_POWERMGT)
52
53#define IS_FC_RETRY(pMACHeader) \
54 ((((PS802_11Header) pMACHeader)->wFrameCtl & FC_RETRY) == FC_RETRY)
55
56#define IS_FC_WEP(pMACHeader) \
57 ((((PS802_11Header) pMACHeader)->wFrameCtl & FC_WEP) == FC_WEP)
58
59#ifdef __BIG_ENDIAN
60
61#define IS_FRAGMENT_PKT(pMACHeader) \
62 (((((PS802_11Header) pMACHeader)->wFrameCtl & FC_MOREFRAG) != 0) | \
63 ((((PS802_11Header) pMACHeader)->wSeqCtl & 0x0F00) != 0))
64
65#define IS_FIRST_FRAGMENT_PKT(pMACHeader) \
66 ((((PS802_11Header) pMACHeader)->wSeqCtl & 0x0F00) == 0)
67
68#else
69
70#define IS_FRAGMENT_PKT(pMACHeader) \
71 (((((PS802_11Header) pMACHeader)->wFrameCtl & FC_MOREFRAG) != 0) | \
72 ((((PS802_11Header) pMACHeader)->wSeqCtl & 0x000F) != 0))
73
74#define IS_FIRST_FRAGMENT_PKT(pMACHeader) \
75 ((((PS802_11Header) pMACHeader)->wSeqCtl & 0x000F) == 0)
76
77#endif//#ifdef __BIG_ENDIAN
78
79#define IS_LAST_FRAGMENT_PKT(pMACHeader) \
80 ((((PS802_11Header) pMACHeader)->wFrameCtl & FC_MOREFRAG) == 0)
81
82#define IS_CTL_PSPOLL(pMACHeader) \
83 ((((PS802_11Header) pMACHeader)->wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL)
84
85#define ADD_ONE_WITH_WRAP_AROUND(uVar, uModulo) \
86do { \
87 if ((uVar) >= ((uModulo) - 1)) \
88 (uVar) = 0; \
89 else \
90 (uVar)++; \
91} while (0)
92
93/*--------------------- Export Classes ----------------------------*/
94
95/*--------------------- Export Variables --------------------------*/
96
97/*--------------------- Export Functions --------------------------*/
98
99bool WCTLbIsDuplicate(PSCache pCache, PS802_11Header pMACHeader);
100bool WCTLbHandleFragment(struct vnt_private *, PS802_11Header pMACHeader,
101 unsigned int cbFrameLength, bool bWEP, bool bExtIV);
102unsigned int WCTLuSearchDFCB(struct vnt_private *, PS802_11Header pMACHeader);
103unsigned int WCTLuInsertDFCB(struct vnt_private *, PS802_11Header pMACHeader);
104
105#endif // __WCTL_H__
diff --git a/drivers/staging/vt6655/wmgr.c b/drivers/staging/vt6655/wmgr.c
deleted file mode 100644
index c73c39d7adfd..000000000000
--- a/drivers/staging/vt6655/wmgr.c
+++ /dev/null
@@ -1,4602 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: wmgr.c
21 *
22 * Purpose: Handles the 802.11 management functions
23 *
24 * Author: Lyndon Chen
25 *
26 * Date: May 8, 2002
27 *
28 * Functions:
29 * nsMgrObjectInitial - Initialize Management Object data structure
30 * vMgrObjectReset - Reset Management Object data structure
31 * vMgrAssocBeginSta - Start associate function
32 * vMgrReAssocBeginSta - Start reassociate function
33 * vMgrDisassocBeginSta - Start disassociate function
34 * s_vMgrRxAssocRequest - Handle Rcv associate_request
35 * s_vMgrRxAssocResponse - Handle Rcv associate_response
36 * vMrgAuthenBeginSta - Start authentication function
37 * vMgrDeAuthenDeginSta - Start deauthentication function
38 * s_vMgrRxAuthentication - Handle Rcv authentication
39 * s_vMgrRxAuthenSequence_1 - Handle Rcv authentication sequence 1
40 * s_vMgrRxAuthenSequence_2 - Handle Rcv authentication sequence 2
41 * s_vMgrRxAuthenSequence_3 - Handle Rcv authentication sequence 3
42 * s_vMgrRxAuthenSequence_4 - Handle Rcv authentication sequence 4
43 * s_vMgrRxDisassociation - Handle Rcv disassociation
44 * s_vMgrRxBeacon - Handle Rcv Beacon
45 * vMgrCreateOwnIBSS - Create ad_hoc IBSS or AP BSS
46 * vMgrJoinBSSBegin - Join BSS function
47 * s_vMgrSynchBSS - Synch & adopt BSS parameters
48 * s_MgrMakeBeacon - Create Baecon frame
49 * s_MgrMakeProbeResponse - Create Probe Response frame
50 * s_MgrMakeAssocRequest - Create Associate Request frame
51 * s_MgrMakeReAssocRequest - Create ReAssociate Request frame
52 * s_vMgrRxProbeResponse - Handle Rcv probe_response
53 * s_vMrgRxProbeRequest - Handle Rcv probe_request
54 * bMgrPrepareBeaconToSend - Prepare Beacon frame
55 * s_vMgrLogStatus - Log 802.11 Status
56 * vMgrRxManagePacket - Rcv management frame dispatch function
57 * s_vMgrFormatTIM- Assembler TIM field of beacon
58 * vMgrTimerInit- Initial 1-sec and command call back funtions
59 *
60 * Revision History:
61 *
62 */
63
64#include "tmacro.h"
65#include "desc.h"
66#include "device.h"
67#include "card.h"
68#include "channel.h"
69#include "80211hdr.h"
70#include "80211mgr.h"
71#include "wmgr.h"
72#include "wcmd.h"
73#include "mac.h"
74#include "bssdb.h"
75#include "power.h"
76#include "datarate.h"
77#include "baseband.h"
78#include "rxtx.h"
79#include "wpa.h"
80#include "rf.h"
81#include "iowpa.h"
82
83/*--------------------- Static Definitions -------------------------*/
84
85/*--------------------- Static Classes ----------------------------*/
86
87/*--------------------- Static Functions --------------------------*/
88//2008-8-4 <add> by chester
89static bool ChannelExceedZoneType(
90 struct vnt_private *pDevice,
91 unsigned char byCurrChannel
92);
93
94// Association/diassociation functions
95static
96PSTxMgmtPacket
97s_MgrMakeAssocRequest(
98 struct vnt_private *pDevice,
99 PSMgmtObject pMgmt,
100 unsigned char *pDAddr,
101 unsigned short wCurrCapInfo,
102 unsigned short wListenInterval,
103 PWLAN_IE_SSID pCurrSSID,
104 PWLAN_IE_SUPP_RATES pCurrRates,
105 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
106);
107
108static
109void
110s_vMgrRxAssocRequest(
111 struct vnt_private *pDevice,
112 PSMgmtObject pMgmt,
113 PSRxMgmtPacket pRxPacket,
114 unsigned int uNodeIndex
115);
116
117static
118PSTxMgmtPacket
119s_MgrMakeReAssocRequest(
120 struct vnt_private *pDevice,
121 PSMgmtObject pMgmt,
122 unsigned char *pDAddr,
123 unsigned short wCurrCapInfo,
124 unsigned short wListenInterval,
125 PWLAN_IE_SSID pCurrSSID,
126 PWLAN_IE_SUPP_RATES pCurrRates,
127 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
128);
129
130static
131void
132s_vMgrRxAssocResponse(
133 struct vnt_private *pDevice,
134 PSMgmtObject pMgmt,
135 PSRxMgmtPacket pRxPacket,
136 bool bReAssocType
137);
138
139static
140void
141s_vMgrRxDisassociation(
142 struct vnt_private *pDevice,
143 PSMgmtObject pMgmt,
144 PSRxMgmtPacket pRxPacket
145);
146
147// Authentication/deauthen functions
148static
149void
150s_vMgrRxAuthenSequence_1(
151 struct vnt_private *pDevice,
152 PSMgmtObject pMgmt,
153 PWLAN_FR_AUTHEN pFrame
154);
155
156static
157void
158s_vMgrRxAuthenSequence_2(
159 struct vnt_private *pDevice,
160 PSMgmtObject pMgmt,
161 PWLAN_FR_AUTHEN pFrame
162);
163
164static
165void
166s_vMgrRxAuthenSequence_3(
167 struct vnt_private *pDevice,
168 PSMgmtObject pMgmt,
169 PWLAN_FR_AUTHEN pFrame
170);
171
172static
173void
174s_vMgrRxAuthenSequence_4(
175 struct vnt_private *pDevice,
176 PSMgmtObject pMgmt,
177 PWLAN_FR_AUTHEN pFrame
178);
179
180static
181void
182s_vMgrRxAuthentication(
183 struct vnt_private *pDevice,
184 PSMgmtObject pMgmt,
185 PSRxMgmtPacket pRxPacket
186);
187
188static
189void
190s_vMgrRxDeauthentication(
191 struct vnt_private *pDevice,
192 PSMgmtObject pMgmt,
193 PSRxMgmtPacket pRxPacket
194);
195
196// Scan functions
197// probe request/response functions
198static
199void
200s_vMgrRxProbeRequest(
201 struct vnt_private *pDevice,
202 PSMgmtObject pMgmt,
203 PSRxMgmtPacket pRxPacket
204);
205
206static
207void
208s_vMgrRxProbeResponse(
209 struct vnt_private *pDevice,
210 PSMgmtObject pMgmt,
211 PSRxMgmtPacket pRxPacket
212);
213
214// beacon functions
215static
216void
217s_vMgrRxBeacon(
218 struct vnt_private *pDevice,
219 PSMgmtObject pMgmt,
220 PSRxMgmtPacket pRxPacket,
221 bool bInScan
222);
223
224static
225void
226s_vMgrFormatTIM(
227 PSMgmtObject pMgmt,
228 PWLAN_IE_TIM pTIM
229);
230
231static
232PSTxMgmtPacket
233s_MgrMakeBeacon(
234 struct vnt_private *pDevice,
235 PSMgmtObject pMgmt,
236 unsigned short wCurrCapInfo,
237 unsigned short wCurrBeaconPeriod,
238 unsigned int uCurrChannel,
239 unsigned short wCurrATIMWinodw,
240 PWLAN_IE_SSID pCurrSSID,
241 unsigned char *pCurrBSSID,
242 PWLAN_IE_SUPP_RATES pCurrSuppRates,
243 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
244);
245
246// Association response
247static
248PSTxMgmtPacket
249s_MgrMakeAssocResponse(
250 struct vnt_private *pDevice,
251 PSMgmtObject pMgmt,
252 unsigned short wCurrCapInfo,
253 unsigned short wAssocStatus,
254 unsigned short wAssocAID,
255 unsigned char *pDstAddr,
256 PWLAN_IE_SUPP_RATES pCurrSuppRates,
257 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
258);
259
260// ReAssociation response
261static
262PSTxMgmtPacket
263s_MgrMakeReAssocResponse(
264 struct vnt_private *pDevice,
265 PSMgmtObject pMgmt,
266 unsigned short wCurrCapInfo,
267 unsigned short wAssocStatus,
268 unsigned short wAssocAID,
269 unsigned char *pDstAddr,
270 PWLAN_IE_SUPP_RATES pCurrSuppRates,
271 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
272);
273
274// Probe response
275static
276PSTxMgmtPacket
277s_MgrMakeProbeResponse(
278 struct vnt_private *pDevice,
279 PSMgmtObject pMgmt,
280 unsigned short wCurrCapInfo,
281 unsigned short wCurrBeaconPeriod,
282 unsigned int uCurrChannel,
283 unsigned short wCurrATIMWinodw,
284 unsigned char *pDstAddr,
285 PWLAN_IE_SSID pCurrSSID,
286 unsigned char *pCurrBSSID,
287 PWLAN_IE_SUPP_RATES pCurrSuppRates,
288 PWLAN_IE_SUPP_RATES pCurrExtSuppRates,
289 unsigned char byPHYType
290);
291
292// received status
293static
294void
295s_vMgrLogStatus(
296 PSMgmtObject pMgmt,
297 unsigned short wStatus
298);
299
300static
301void
302s_vMgrSynchBSS(
303 struct vnt_private *pDevice,
304 unsigned int uBSSMode,
305 PKnownBSS pCurr,
306 PCMD_STATUS pStatus
307);
308
309static bool
310s_bCipherMatch(
311 PKnownBSS pBSSNode,
312 NDIS_802_11_ENCRYPTION_STATUS EncStatus,
313 unsigned char *pbyCCSPK,
314 unsigned char *pbyCCSGK
315);
316
317static void Encyption_Rebuild(
318 struct vnt_private *pDevice,
319 PKnownBSS pCurr
320);
321
322/*--------------------- Export Variables --------------------------*/
323
324/*--------------------- Export Functions --------------------------*/
325
326/*+
327 *
328 * Routine Description:
329 * Allocates and initializes the Management object.
330 *
331 * Return Value:
332 * Ndis_staus.
333 *
334 -*/
335
336void
337vMgrObjectInit(
338 void *hDeviceContext
339)
340{
341 struct vnt_private *pDevice = hDeviceContext;
342 PSMgmtObject pMgmt = pDevice->pMgmt;
343 int ii;
344
345 pMgmt->pbyPSPacketPool = &pMgmt->byPSPacketPool[0];
346 pMgmt->pbyMgmtPacketPool = &pMgmt->byMgmtPacketPool[0];
347 pMgmt->uCurrChannel = pDevice->uChannel;
348 for (ii = 0; ii < WLAN_BSSID_LEN; ii++)
349 pMgmt->abyDesireBSSID[ii] = 0xFF;
350
351 pMgmt->sAssocInfo.AssocInfo.Length = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
352 pMgmt->byCSSPK = KEY_CTL_NONE;
353 pMgmt->byCSSGK = KEY_CTL_NONE;
354 pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
355 BSSvClearBSSList((void *)pDevice, false);
356}
357
358/*+
359 *
360 * Routine Description:
361 * Initializes timer object
362 *
363 * Return Value:
364 * Ndis_staus.
365 *
366 -*/
367
368void
369vMgrTimerInit(
370 void *hDeviceContext
371)
372{
373 struct vnt_private *pDevice = hDeviceContext;
374 PSMgmtObject pMgmt = pDevice->pMgmt;
375
376 init_timer(&pMgmt->sTimerSecondCallback);
377 pMgmt->sTimerSecondCallback.data = (unsigned long) pDevice;
378 pMgmt->sTimerSecondCallback.function = (TimerFunction)BSSvSecondCallBack;
379 pMgmt->sTimerSecondCallback.expires = RUN_AT(HZ);
380
381 init_timer(&pDevice->sTimerCommand);
382 pDevice->sTimerCommand.data = (unsigned long) pDevice;
383 pDevice->sTimerCommand.function = (TimerFunction)vCommandTimer;
384 pDevice->sTimerCommand.expires = RUN_AT(HZ);
385
386 init_timer(&pDevice->sTimerTxData);
387 pDevice->sTimerTxData.data = (unsigned long) pDevice;
388 pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData;
389 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
390 pDevice->fTxDataInSleep = false;
391 pDevice->IsTxDataTrigger = false;
392 pDevice->nTxDataTimeCout = 0;
393
394 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
395 pDevice->uCmdDequeueIdx = 0;
396 pDevice->uCmdEnqueueIdx = 0;
397}
398
399/*+
400 *
401 * Routine Description:
402 * Reset the management object structure.
403 *
404 * Return Value:
405 * None.
406 *
407 -*/
408
409void
410vMgrObjectReset(
411 void *hDeviceContext
412)
413{
414 struct vnt_private *pDevice = hDeviceContext;
415 PSMgmtObject pMgmt = pDevice->pMgmt;
416
417 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
418 pMgmt->eCurrState = WMAC_STATE_IDLE;
419 pDevice->bEnablePSMode = false;
420 // TODO: timer
421}
422
423/*+
424 *
425 * Routine Description:
426 * Start the station association procedure. Namely, send an
427 * association request frame to the AP.
428 *
429 * Return Value:
430 * None.
431 *
432 -*/
433
434void
435vMgrAssocBeginSta(
436 void *hDeviceContext,
437 PSMgmtObject pMgmt,
438 PCMD_STATUS pStatus
439)
440{
441 struct vnt_private *pDevice = hDeviceContext;
442 PSTxMgmtPacket pTxPacket;
443
444 pMgmt->wCurrCapInfo = 0;
445 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
446 if (pDevice->bEncryptionEnable)
447 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
448
449 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
450 if (pMgmt->wListenInterval == 0)
451 pMgmt->wListenInterval = 1; // at least one.
452
453 // ERP Phy (802.11g) should support short preamble.
454 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
455 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
456 if (CARDbIsShorSlotTime(pMgmt->pAdapter))
457 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
458 } else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) {
459 if (CARDbIsShortPreamble(pMgmt->pAdapter))
460 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
461 }
462 if (pMgmt->b11hEnable)
463 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
464
465 /* build an assocreq frame and send it */
466 pTxPacket = s_MgrMakeAssocRequest
467 (
468 pDevice,
469 pMgmt,
470 pMgmt->abyCurrBSSID,
471 pMgmt->wCurrCapInfo,
472 pMgmt->wListenInterval,
473 (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
474 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
475 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
476);
477
478 if (pTxPacket != NULL) {
479 /* send the frame */
480 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
481 if (*pStatus == CMD_STATUS_PENDING) {
482 pMgmt->eCurrState = WMAC_STATE_ASSOCPENDING;
483 *pStatus = CMD_STATUS_SUCCESS;
484 }
485 } else {
486 *pStatus = CMD_STATUS_RESOURCES;
487 }
488}
489
490/*+
491 *
492 * Routine Description:
493 * Start the station re-association procedure.
494 *
495 * Return Value:
496 * None.
497 *
498 -*/
499
500void
501vMgrReAssocBeginSta(
502 void *hDeviceContext,
503 PSMgmtObject pMgmt,
504 PCMD_STATUS pStatus
505)
506{
507 struct vnt_private *pDevice = hDeviceContext;
508 PSTxMgmtPacket pTxPacket;
509
510 pMgmt->wCurrCapInfo = 0;
511 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
512 if (pDevice->bEncryptionEnable)
513 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
514
515 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
516
517 if (pMgmt->wListenInterval == 0)
518 pMgmt->wListenInterval = 1; // at least one.
519
520 // ERP Phy (802.11g) should support short preamble.
521 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
522 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
523 if (CARDbIsShorSlotTime(pMgmt->pAdapter))
524 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
525 } else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) {
526 if (CARDbIsShortPreamble(pMgmt->pAdapter))
527 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
528 }
529
530 if (pMgmt->b11hEnable)
531 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
532
533 pTxPacket = s_MgrMakeReAssocRequest
534 (
535 pDevice,
536 pMgmt,
537 pMgmt->abyCurrBSSID,
538 pMgmt->wCurrCapInfo,
539 pMgmt->wListenInterval,
540 (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
541 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
542 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
543);
544
545 if (pTxPacket != NULL) {
546 /* send the frame */
547 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
548 if (*pStatus != CMD_STATUS_PENDING)
549 pr_debug("Mgt:Reassociation tx failed\n");
550 else
551 pr_debug("Mgt:Reassociation tx sending\n");
552 }
553}
554
555/*+
556 *
557 * Routine Description:
558 * Send an dis-association request frame to the AP.
559 *
560 * Return Value:
561 * None.
562 *
563 -*/
564
565void
566vMgrDisassocBeginSta(
567 void *hDeviceContext,
568 PSMgmtObject pMgmt,
569 unsigned char *abyDestAddress,
570 unsigned short wReason,
571 PCMD_STATUS pStatus
572)
573{
574 struct vnt_private *pDevice = hDeviceContext;
575 PSTxMgmtPacket pTxPacket = NULL;
576 WLAN_FR_DISASSOC sFrame;
577
578 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
579 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_DISASSOC_FR_MAXLEN);
580 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
581
582 // Setup the sFrame structure
583 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
584 sFrame.len = WLAN_DISASSOC_FR_MAXLEN;
585
586 // format fixed field frame structure
587 vMgrEncodeDisassociation(&sFrame);
588
589 // Setup the header
590 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
591 (
592 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
593 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DISASSOC)
594));
595
596 memcpy(sFrame.pHdr->sA3.abyAddr1, abyDestAddress, WLAN_ADDR_LEN);
597 memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
598 memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
599
600 // Set reason code
601 *(sFrame.pwReason) = cpu_to_le16(wReason);
602 pTxPacket->cbMPDULen = sFrame.len;
603 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
604
605 // send the frame
606 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
607 if (*pStatus == CMD_STATUS_PENDING) {
608 pMgmt->eCurrState = WMAC_STATE_IDLE;
609 *pStatus = CMD_STATUS_SUCCESS;
610 }
611}
612
613/*+
614 *
615 * Routine Description:(AP function)
616 * Handle incoming station association request frames.
617 *
618 * Return Value:
619 * None.
620 *
621 -*/
622
623static
624void
625s_vMgrRxAssocRequest(
626 struct vnt_private *pDevice,
627 PSMgmtObject pMgmt,
628 PSRxMgmtPacket pRxPacket,
629 unsigned int uNodeIndex
630)
631{
632 WLAN_FR_ASSOCREQ sFrame;
633 CMD_STATUS Status;
634 PSTxMgmtPacket pTxPacket;
635 unsigned short wAssocStatus = 0;
636 unsigned short wAssocAID = 0;
637 unsigned int uRateLen = WLAN_RATES_MAXLEN;
638 unsigned char abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
639 unsigned char abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
640
641 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)
642 return;
643 // node index not found
644 if (!uNodeIndex)
645 return;
646
647 //check if node is authenticated
648 //decode the frame
649 memset(&sFrame, 0, sizeof(WLAN_FR_ASSOCREQ));
650 memset(abyCurrSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
651 memset(abyCurrExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
652 sFrame.len = pRxPacket->cbMPDULen;
653 sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
654
655 vMgrDecodeAssocRequest(&sFrame);
656
657 if (pMgmt->sNodeDBTable[uNodeIndex].eNodeState >= NODE_AUTH) {
658 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
659 pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo);
660 pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval);
661 pMgmt->sNodeDBTable[uNodeIndex].bPSEnable =
662 WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? true : false;
663 // Todo: check sta basic rate, if ap can't support, set status code
664 if (pDevice->eCurrentPHYType == PHY_TYPE_11B)
665 uRateLen = WLAN_RATES_MAXLEN_11B;
666
667 abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
668 abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
669 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
670 uRateLen);
671 abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
672 if (pDevice->eCurrentPHYType == PHY_TYPE_11G)
673 abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pExtSuppRates,
674 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
675 uRateLen);
676 else
677 abyCurrExtSuppRates[1] = 0;
678
679 RATEvParseMaxRate((void *)pDevice,
680 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
681 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
682 false, // do not change our basic rate
683 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
684 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
685 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
686 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
687 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
688);
689
690 // set max tx rate
691 pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
692 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
693
694 pr_debug("RxAssocRequest:wTxDataRate is %d\n", pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate);
695
696 // Todo: check sta preamble, if ap can't support, set status code
697 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
698 WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
699 pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime =
700 WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
701 pMgmt->sNodeDBTable[uNodeIndex].wAID = (unsigned short)uNodeIndex;
702 wAssocStatus = WLAN_MGMT_STATUS_SUCCESS;
703 wAssocAID = (unsigned short)uNodeIndex;
704 // check if ERP support
705 if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
706 pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
707
708 if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) {
709 // B only STA join
710 pDevice->bProtectMode = true;
711 pDevice->bNonERPPresent = true;
712 }
713 if (!pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble)
714 pDevice->bBarkerPreambleMd = true;
715
716 pr_info("Associate AID= %d\n", wAssocAID);
717 pr_info("MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
718 sFrame.pHdr->sA3.abyAddr2[0],
719 sFrame.pHdr->sA3.abyAddr2[1],
720 sFrame.pHdr->sA3.abyAddr2[2],
721 sFrame.pHdr->sA3.abyAddr2[3],
722 sFrame.pHdr->sA3.abyAddr2[4],
723 sFrame.pHdr->sA3.abyAddr2[5]
724 );
725 pr_info("Max Support rate = %d\n",
726 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
727 } else {
728 /* TODO: received STA under state1 handle */
729 return;
730 }
731
732 // assoc response reply..
733 pTxPacket = s_MgrMakeAssocResponse
734 (
735 pDevice,
736 pMgmt,
737 pMgmt->wCurrCapInfo,
738 wAssocStatus,
739 wAssocAID,
740 sFrame.pHdr->sA3.abyAddr2,
741 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
742 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
743);
744 if (pTxPacket != NULL) {
745 if (pDevice->bEnableHostapd)
746 return;
747
748 /* send the frame */
749 Status = csMgmt_xmit(pDevice, pTxPacket);
750 if (Status != CMD_STATUS_PENDING)
751 pr_debug("Mgt:Assoc response tx failed\n");
752 else
753 pr_debug("Mgt:Assoc response tx sending..\n");
754 }
755}
756
757/*+
758 *
759 * Description:(AP function)
760 * Handle incoming station re-association request frames.
761 *
762 * Parameters:
763 * In:
764 * pMgmt - Management Object structure
765 * pRxPacket - Received Packet
766 * Out:
767 * none
768 *
769 * Return Value: None.
770 *
771 -*/
772
773static
774void
775s_vMgrRxReAssocRequest(
776 struct vnt_private *pDevice,
777 PSMgmtObject pMgmt,
778 PSRxMgmtPacket pRxPacket,
779 unsigned int uNodeIndex
780)
781{
782 WLAN_FR_REASSOCREQ sFrame;
783 CMD_STATUS Status;
784 PSTxMgmtPacket pTxPacket;
785 unsigned short wAssocStatus = 0;
786 unsigned short wAssocAID = 0;
787 unsigned int uRateLen = WLAN_RATES_MAXLEN;
788 unsigned char abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
789 unsigned char abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
790
791 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)
792 return;
793 // node index not found
794 if (!uNodeIndex)
795 return;
796 //check if node is authenticated
797 //decode the frame
798 memset(&sFrame, 0, sizeof(WLAN_FR_REASSOCREQ));
799 sFrame.len = pRxPacket->cbMPDULen;
800 sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
801 vMgrDecodeReassocRequest(&sFrame);
802
803 if (pMgmt->sNodeDBTable[uNodeIndex].eNodeState >= NODE_AUTH) {
804 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
805 pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo);
806 pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval);
807 pMgmt->sNodeDBTable[uNodeIndex].bPSEnable =
808 WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? true : false;
809 // Todo: check sta basic rate, if ap can't support, set status code
810
811 if (pDevice->eCurrentPHYType == PHY_TYPE_11B)
812 uRateLen = WLAN_RATES_MAXLEN_11B;
813
814 abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
815 abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
816 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
817 uRateLen);
818 abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
819 if (pDevice->eCurrentPHYType == PHY_TYPE_11G) {
820 abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pExtSuppRates,
821 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
822 uRateLen);
823 } else {
824 abyCurrExtSuppRates[1] = 0;
825 }
826
827 RATEvParseMaxRate((void *)pDevice,
828 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
829 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
830 false, // do not change our basic rate
831 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
832 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
833 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
834 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
835 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
836);
837
838 // set max tx rate
839 pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
840 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
841
842 pr_debug("RxReAssocRequest:TxDataRate is %d\n", pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate);
843
844 // Todo: check sta preamble, if ap can't support, set status code
845 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
846 WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
847 pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime =
848 WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
849 pMgmt->sNodeDBTable[uNodeIndex].wAID = (unsigned short)uNodeIndex;
850 wAssocStatus = WLAN_MGMT_STATUS_SUCCESS;
851 wAssocAID = (unsigned short)uNodeIndex;
852
853 // if suppurt ERP
854 if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
855 pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
856
857 if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) {
858 // B only STA join
859 pDevice->bProtectMode = true;
860 pDevice->bNonERPPresent = true;
861 }
862 if (!pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble)
863 pDevice->bBarkerPreambleMd = true;
864
865 pr_info("Rx ReAssociate AID= %d\n", wAssocAID);
866 pr_info("MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
867 sFrame.pHdr->sA3.abyAddr2[0],
868 sFrame.pHdr->sA3.abyAddr2[1],
869 sFrame.pHdr->sA3.abyAddr2[2],
870 sFrame.pHdr->sA3.abyAddr2[3],
871 sFrame.pHdr->sA3.abyAddr2[4],
872 sFrame.pHdr->sA3.abyAddr2[5]
873 );
874 pr_info("Max Support rate = %d\n",
875 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
876
877 }
878
879 // assoc response reply..
880 pTxPacket = s_MgrMakeReAssocResponse
881 (
882 pDevice,
883 pMgmt,
884 pMgmt->wCurrCapInfo,
885 wAssocStatus,
886 wAssocAID,
887 sFrame.pHdr->sA3.abyAddr2,
888 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
889 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
890 );
891
892 if (pTxPacket != NULL) {
893 /* send the frame */
894 if (pDevice->bEnableHostapd)
895 return;
896
897 Status = csMgmt_xmit(pDevice, pTxPacket);
898 if (Status != CMD_STATUS_PENDING)
899 pr_debug("Mgt:ReAssoc response tx failed\n");
900 else
901 pr_debug("Mgt:ReAssoc response tx sending..\n");
902 }
903}
904
905/*+
906 *
907 * Routine Description:
908 * Handle incoming association response frames.
909 *
910 * Return Value:
911 * None.
912 *
913 -*/
914
915static
916void
917s_vMgrRxAssocResponse(
918 struct vnt_private *pDevice,
919 PSMgmtObject pMgmt,
920 PSRxMgmtPacket pRxPacket,
921 bool bReAssocType
922)
923{
924 WLAN_FR_ASSOCRESP sFrame;
925 PWLAN_IE_SSID pItemSSID;
926 unsigned char *pbyIEs;
927 viawget_wpa_header *wpahdr;
928
929 if (pMgmt->eCurrState == WMAC_STATE_ASSOCPENDING ||
930 pMgmt->eCurrState == WMAC_STATE_ASSOC) {
931 sFrame.len = pRxPacket->cbMPDULen;
932 sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
933 // decode the frame
934 vMgrDecodeAssocResponse(&sFrame);
935 if ((sFrame.pwCapInfo == NULL) ||
936 (sFrame.pwStatus == NULL) ||
937 (sFrame.pwAid == NULL) ||
938 (sFrame.pSuppRates == NULL)) {
939 DBG_PORT80(0xCC);
940 return;
941 }
942
943 pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.Capabilities = *(sFrame.pwCapInfo);
944 pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.StatusCode = *(sFrame.pwStatus);
945 pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.AssociationId = *(sFrame.pwAid);
946 pMgmt->sAssocInfo.AssocInfo.AvailableResponseFixedIEs |= 0x07;
947
948 pMgmt->sAssocInfo.AssocInfo.ResponseIELength = sFrame.len - 24 - 6;
949 pMgmt->sAssocInfo.AssocInfo.OffsetResponseIEs = pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs + pMgmt->sAssocInfo.AssocInfo.RequestIELength;
950 pbyIEs = pMgmt->sAssocInfo.abyIEs;
951 pbyIEs += pMgmt->sAssocInfo.AssocInfo.RequestIELength;
952 memcpy(pbyIEs, (sFrame.pBuf + 24 + 6), pMgmt->sAssocInfo.AssocInfo.ResponseIELength);
953
954 // save values and set current BSS state
955 if (cpu_to_le16((*(sFrame.pwStatus))) == WLAN_MGMT_STATUS_SUCCESS) {
956 // set AID
957 pMgmt->wCurrAID = cpu_to_le16((*(sFrame.pwAid)));
958 if ((pMgmt->wCurrAID >> 14) != (BIT0 | BIT1))
959 pr_debug("AID from AP, has two msb clear\n");
960
961 pr_info("Association Successful, AID=%d\n",
962 pMgmt->wCurrAID & ~(BIT14 | BIT15));
963 pMgmt->eCurrState = WMAC_STATE_ASSOC;
964 BSSvUpdateAPNode((void *)pDevice, sFrame.pwCapInfo, sFrame.pSuppRates, sFrame.pExtSuppRates);
965 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
966 pr_info("Link with AP(SSID): %s\n", pItemSSID->abySSID);
967 pDevice->bLinkPass = true;
968 pDevice->uBBVGADiffCount = 0;
969 if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
970 if (skb_tailroom(pDevice->skb) < (sizeof(viawget_wpa_header) + pMgmt->sAssocInfo.AssocInfo.ResponseIELength +
971 pMgmt->sAssocInfo.AssocInfo.RequestIELength)) { //data room not enough
972 dev_kfree_skb(pDevice->skb);
973 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
974 }
975 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
976 wpahdr->type = VIAWGET_ASSOC_MSG;
977 wpahdr->resp_ie_len = pMgmt->sAssocInfo.AssocInfo.ResponseIELength;
978 wpahdr->req_ie_len = pMgmt->sAssocInfo.AssocInfo.RequestIELength;
979 memcpy(pDevice->skb->data + sizeof(viawget_wpa_header), pMgmt->sAssocInfo.abyIEs, wpahdr->req_ie_len);
980 memcpy(pDevice->skb->data + sizeof(viawget_wpa_header) + wpahdr->req_ie_len,
981 pbyIEs,
982 wpahdr->resp_ie_len
983);
984 skb_put(pDevice->skb, sizeof(viawget_wpa_header) + wpahdr->resp_ie_len + wpahdr->req_ie_len);
985 pDevice->skb->dev = pDevice->wpadev;
986 skb_reset_mac_header(pDevice->skb);
987 pDevice->skb->pkt_type = PACKET_HOST;
988 pDevice->skb->protocol = htons(ETH_P_802_2);
989 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
990 netif_rx(pDevice->skb);
991 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
992 }
993
994//2008-0409-07, <Add> by Einsn Liu
995#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
996 {
997 unsigned char buf[512];
998 size_t len;
999 union iwreq_data wrqu;
1000 int we_event;
1001
1002 memset(buf, 0, 512);
1003
1004 len = pMgmt->sAssocInfo.AssocInfo.RequestIELength;
1005 if (len) {
1006 memcpy(buf, pMgmt->sAssocInfo.abyIEs, len);
1007 memset(&wrqu, 0, sizeof(wrqu));
1008 wrqu.data.length = len;
1009 we_event = IWEVASSOCREQIE;
1010 wireless_send_event(pDevice->dev, we_event, &wrqu, buf);
1011 }
1012
1013 memset(buf, 0, 512);
1014 len = pMgmt->sAssocInfo.AssocInfo.ResponseIELength;
1015
1016 if (len) {
1017 memcpy(buf, pbyIEs, len);
1018 memset(&wrqu, 0, sizeof(wrqu));
1019 wrqu.data.length = len;
1020 we_event = IWEVASSOCRESPIE;
1021 wireless_send_event(pDevice->dev, we_event, &wrqu, buf);
1022 }
1023
1024 memset(&wrqu, 0, sizeof(wrqu));
1025 memcpy(wrqu.ap_addr.sa_data, &pMgmt->abyCurrBSSID[0], ETH_ALEN);
1026 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1027 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1028 }
1029#endif //#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1030//End Add -- //2008-0409-07, <Add> by Einsn Liu
1031 } else {
1032 if (bReAssocType) {
1033 pMgmt->eCurrState = WMAC_STATE_IDLE;
1034 } else {
1035 // jump back to the auth state and indicate the error
1036 pMgmt->eCurrState = WMAC_STATE_AUTH;
1037 }
1038 s_vMgrLogStatus(pMgmt, cpu_to_le16((*(sFrame.pwStatus))));
1039 }
1040
1041 }
1042
1043#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1044//need clear flags related to Networkmanager
1045
1046 pDevice->bwextcount = 0;
1047 pDevice->bWPASuppWextEnabled = false;
1048#endif
1049
1050 if (pMgmt->eCurrState == WMAC_STATE_ASSOC)
1051 timer_expire(pDevice->sTimerCommand, 0);
1052}
1053
1054/*+
1055 *
1056 * Routine Description:
1057 * Start the station authentication procedure. Namely, send an
1058 * authentication frame to the AP.
1059 *
1060 * Return Value:
1061 * None.
1062 *
1063 -*/
1064
1065void
1066vMgrAuthenBeginSta(
1067 void *hDeviceContext,
1068 PSMgmtObject pMgmt,
1069 PCMD_STATUS pStatus
1070)
1071{
1072 struct vnt_private *pDevice = hDeviceContext;
1073 WLAN_FR_AUTHEN sFrame;
1074 PSTxMgmtPacket pTxPacket = NULL;
1075
1076 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
1077 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN);
1078 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
1079 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
1080 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
1081 vMgrEncodeAuthen(&sFrame);
1082 /* insert values */
1083 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
1084 (
1085 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
1086 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)
1087));
1088 memcpy(sFrame.pHdr->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
1089 memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
1090 memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1091 if (pMgmt->bShareKeyAlgorithm)
1092 *(sFrame.pwAuthAlgorithm) = cpu_to_le16(WLAN_AUTH_ALG_SHAREDKEY);
1093 else
1094 *(sFrame.pwAuthAlgorithm) = cpu_to_le16(WLAN_AUTH_ALG_OPENSYSTEM);
1095
1096 *(sFrame.pwAuthSequence) = cpu_to_le16(1);
1097 /* Adjust the length fields */
1098 pTxPacket->cbMPDULen = sFrame.len;
1099 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
1100
1101 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
1102 if (*pStatus == CMD_STATUS_PENDING) {
1103 pMgmt->eCurrState = WMAC_STATE_AUTHPENDING;
1104 *pStatus = CMD_STATUS_SUCCESS;
1105 }
1106}
1107
1108/*+
1109 *
1110 * Routine Description:
1111 * Start the station(AP) deauthentication procedure. Namely, send an
1112 * deauthentication frame to the AP or Sta.
1113 *
1114 * Return Value:
1115 * None.
1116 *
1117 -*/
1118
1119void
1120vMgrDeAuthenBeginSta(
1121 void *hDeviceContext,
1122 PSMgmtObject pMgmt,
1123 unsigned char *abyDestAddress,
1124 unsigned short wReason,
1125 PCMD_STATUS pStatus
1126)
1127{
1128 struct vnt_private *pDevice = hDeviceContext;
1129 WLAN_FR_DEAUTHEN sFrame;
1130 PSTxMgmtPacket pTxPacket = NULL;
1131
1132 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
1133 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_DEAUTHEN_FR_MAXLEN);
1134 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
1135 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
1136 sFrame.len = WLAN_DEAUTHEN_FR_MAXLEN;
1137 vMgrEncodeDeauthen(&sFrame);
1138 /* insert values */
1139 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
1140 (
1141 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
1142 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DEAUTHEN)
1143));
1144
1145 memcpy(sFrame.pHdr->sA3.abyAddr1, abyDestAddress, WLAN_ADDR_LEN);
1146 memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
1147 memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1148
1149 *(sFrame.pwReason) = cpu_to_le16(wReason); // deauthen. bcs left BSS
1150 /* Adjust the length fields */
1151 pTxPacket->cbMPDULen = sFrame.len;
1152 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
1153
1154 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
1155 if (*pStatus == CMD_STATUS_PENDING)
1156 *pStatus = CMD_STATUS_SUCCESS;
1157}
1158
1159/*+
1160 *
1161 * Routine Description:
1162 * Handle incoming authentication frames.
1163 *
1164 * Return Value:
1165 * None.
1166 *
1167 -*/
1168
1169static
1170void
1171s_vMgrRxAuthentication(
1172 struct vnt_private *pDevice,
1173 PSMgmtObject pMgmt,
1174 PSRxMgmtPacket pRxPacket
1175)
1176{
1177 WLAN_FR_AUTHEN sFrame;
1178
1179 // we better be an AP or a STA in AUTHPENDING otherwise ignore
1180 if (!(pMgmt->eCurrMode == WMAC_MODE_ESS_AP ||
1181 pMgmt->eCurrState == WMAC_STATE_AUTHPENDING)) {
1182 return;
1183 }
1184
1185 // decode the frame
1186 sFrame.len = pRxPacket->cbMPDULen;
1187 sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
1188 vMgrDecodeAuthen(&sFrame);
1189 switch (cpu_to_le16((*(sFrame.pwAuthSequence)))) {
1190 case 1:
1191 //AP function
1192 s_vMgrRxAuthenSequence_1(pDevice, pMgmt, &sFrame);
1193 break;
1194 case 2:
1195 s_vMgrRxAuthenSequence_2(pDevice, pMgmt, &sFrame);
1196 break;
1197 case 3:
1198 //AP function
1199 s_vMgrRxAuthenSequence_3(pDevice, pMgmt, &sFrame);
1200 break;
1201 case 4:
1202 s_vMgrRxAuthenSequence_4(pDevice, pMgmt, &sFrame);
1203 break;
1204 default:
1205 pr_debug("Auth Sequence error, seq = %d\n",
1206 cpu_to_le16((*(sFrame.pwAuthSequence))));
1207 break;
1208 }
1209}
1210
1211/*+
1212 *
1213 * Routine Description:
1214 * Handles incoming authen frames with sequence 1. Currently
1215 * assumes we're an AP. So far, no one appears to use authentication
1216 * in Ad-Hoc mode.
1217 *
1218 * Return Value:
1219 * None.
1220 *
1221 -*/
1222
1223static
1224void
1225s_vMgrRxAuthenSequence_1(
1226 struct vnt_private *pDevice,
1227 PSMgmtObject pMgmt,
1228 PWLAN_FR_AUTHEN pFrame
1229)
1230{
1231 PSTxMgmtPacket pTxPacket = NULL;
1232 unsigned int uNodeIndex;
1233 WLAN_FR_AUTHEN sFrame;
1234 PSKeyItem pTransmitKey;
1235
1236 // Insert a Node entry
1237 if (!BSSDBbIsSTAInNodeDB(pMgmt, pFrame->pHdr->sA3.abyAddr2, &uNodeIndex)) {
1238 BSSvCreateOneNode(pDevice, &uNodeIndex);
1239 memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, pFrame->pHdr->sA3.abyAddr2,
1240 WLAN_ADDR_LEN);
1241 }
1242
1243 if (pMgmt->bShareKeyAlgorithm) {
1244 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_KNOWN;
1245 pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence = 1;
1246 } else {
1247 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_AUTH;
1248 }
1249
1250 // send auth reply
1251 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
1252 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN);
1253 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
1254 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
1255 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
1256 // format buffer structure
1257 vMgrEncodeAuthen(&sFrame);
1258 // insert values
1259 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
1260 (
1261 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
1262 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
1263 WLAN_SET_FC_ISWEP(0)
1264));
1265 memcpy(sFrame.pHdr->sA3.abyAddr1, pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
1266 memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
1267 memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1268 *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
1269 *(sFrame.pwAuthSequence) = cpu_to_le16(2);
1270
1271 if (cpu_to_le16(*(pFrame->pwAuthAlgorithm)) == WLAN_AUTH_ALG_SHAREDKEY) {
1272 if (pMgmt->bShareKeyAlgorithm)
1273 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
1274 else
1275 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG);
1276 } else {
1277 if (pMgmt->bShareKeyAlgorithm)
1278 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG);
1279 else
1280 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
1281 }
1282
1283 if (pMgmt->bShareKeyAlgorithm &&
1284 (cpu_to_le16(*(sFrame.pwStatus)) == WLAN_MGMT_STATUS_SUCCESS)) {
1285 sFrame.pChallenge = (PWLAN_IE_CHALLENGE)(sFrame.pBuf + sFrame.len);
1286 sFrame.len += WLAN_CHALLENGE_IE_LEN;
1287 sFrame.pChallenge->byElementID = WLAN_EID_CHALLENGE;
1288 sFrame.pChallenge->len = WLAN_CHALLENGE_LEN;
1289 memset(pMgmt->abyChallenge, 0, WLAN_CHALLENGE_LEN);
1290 // get group key
1291 if (KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, GROUP_KEY, &pTransmitKey) == true) {
1292 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength+3);
1293 rc4_encrypt(&pDevice->SBox, pMgmt->abyChallenge, pMgmt->abyChallenge, WLAN_CHALLENGE_LEN);
1294 }
1295 memcpy(sFrame.pChallenge->abyChallenge, pMgmt->abyChallenge , WLAN_CHALLENGE_LEN);
1296 }
1297
1298 /* Adjust the length fields */
1299 pTxPacket->cbMPDULen = sFrame.len;
1300 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
1301 // send the frame
1302 if (pDevice->bEnableHostapd)
1303 return;
1304
1305 pr_debug("Mgt:Authreq_reply sequence_1 tx..\n");
1306 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING)
1307 pr_debug("Mgt:Authreq_reply sequence_1 tx failed\n");
1308}
1309
1310/*+
1311 *
1312 * Routine Description:
1313 * Handles incoming auth frames with sequence number 2. Currently
1314 * assumes we're a station.
1315 *
1316 *
1317 * Return Value:
1318 * None.
1319 *
1320 -*/
1321
1322static
1323void
1324s_vMgrRxAuthenSequence_2(
1325 struct vnt_private *pDevice,
1326 PSMgmtObject pMgmt,
1327 PWLAN_FR_AUTHEN pFrame
1328)
1329{
1330 WLAN_FR_AUTHEN sFrame;
1331 PSTxMgmtPacket pTxPacket = NULL;
1332
1333 switch (cpu_to_le16((*(pFrame->pwAuthAlgorithm)))) {
1334 case WLAN_AUTH_ALG_OPENSYSTEM:
1335 if (cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS) {
1336 pr_info("802.11 Authen (OPEN) Successful\n");
1337 pMgmt->eCurrState = WMAC_STATE_AUTH;
1338 timer_expire(pDevice->sTimerCommand, 0);
1339 } else {
1340 pr_info("802.11 Authen (OPEN) Failed\n");
1341 s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))));
1342 pMgmt->eCurrState = WMAC_STATE_IDLE;
1343 }
1344
1345 break;
1346
1347 case WLAN_AUTH_ALG_SHAREDKEY:
1348
1349 if (cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS) {
1350 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
1351 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN);
1352 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
1353 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
1354 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
1355 // format buffer structure
1356 vMgrEncodeAuthen(&sFrame);
1357 // insert values
1358 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
1359 (
1360 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
1361 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
1362 WLAN_SET_FC_ISWEP(1)
1363));
1364 memcpy(sFrame.pHdr->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1365 memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
1366 memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1367 *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
1368 *(sFrame.pwAuthSequence) = cpu_to_le16(3);
1369 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
1370 sFrame.pChallenge = (PWLAN_IE_CHALLENGE)(sFrame.pBuf + sFrame.len);
1371 sFrame.len += WLAN_CHALLENGE_IE_LEN;
1372 sFrame.pChallenge->byElementID = WLAN_EID_CHALLENGE;
1373 sFrame.pChallenge->len = WLAN_CHALLENGE_LEN;
1374 memcpy(sFrame.pChallenge->abyChallenge, pFrame->pChallenge->abyChallenge, WLAN_CHALLENGE_LEN);
1375 // Adjust the length fields
1376 pTxPacket->cbMPDULen = sFrame.len;
1377 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
1378 // send the frame
1379 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING)
1380 pr_debug("Mgt:Auth_reply sequence_2 tx failed\n");
1381
1382 pr_debug("Mgt:Auth_reply sequence_2 tx ...\n");
1383 } else {
1384 pr_debug("Mgt:rx Auth_reply sequence_2 status error ...\n");
1385 s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))));
1386 }
1387 break;
1388 default:
1389 pr_debug("Mgt: rx auth.seq = 2 unknown AuthAlgorithm=%d\n",
1390 cpu_to_le16((*(pFrame->pwAuthAlgorithm))));
1391 break;
1392 }
1393}
1394
1395/*+
1396 *
1397 * Routine Description:
1398 * Handles incoming authen frames with sequence 3. Currently
1399 * assumes we're an AP. This function assumes the frame has
1400 * already been successfully decrypted.
1401 *
1402 *
1403 * Return Value:
1404 * None.
1405 *
1406 -*/
1407
1408static
1409void
1410s_vMgrRxAuthenSequence_3(
1411 struct vnt_private *pDevice,
1412 PSMgmtObject pMgmt,
1413 PWLAN_FR_AUTHEN pFrame
1414)
1415{
1416 PSTxMgmtPacket pTxPacket = NULL;
1417 unsigned int uStatusCode = 0;
1418 unsigned int uNodeIndex = 0;
1419 WLAN_FR_AUTHEN sFrame;
1420
1421 if (!WLAN_GET_FC_ISWEP(pFrame->pHdr->sA3.wFrameCtl)) {
1422 uStatusCode = WLAN_MGMT_STATUS_CHALLENGE_FAIL;
1423 goto reply;
1424 }
1425 if (BSSDBbIsSTAInNodeDB(pMgmt, pFrame->pHdr->sA3.abyAddr2, &uNodeIndex)) {
1426 if (pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence != 1) {
1427 uStatusCode = WLAN_MGMT_STATUS_RX_AUTH_NOSEQ;
1428 goto reply;
1429 }
1430 if (memcmp(pMgmt->abyChallenge, pFrame->pChallenge->abyChallenge, WLAN_CHALLENGE_LEN) != 0) {
1431 uStatusCode = WLAN_MGMT_STATUS_CHALLENGE_FAIL;
1432 goto reply;
1433 }
1434 } else {
1435 uStatusCode = WLAN_MGMT_STATUS_UNSPEC_FAILURE;
1436 goto reply;
1437 }
1438
1439 if (uNodeIndex) {
1440 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_AUTH;
1441 pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence = 0;
1442 }
1443 uStatusCode = WLAN_MGMT_STATUS_SUCCESS;
1444 pr_debug("Challenge text check ok..\n");
1445
1446reply:
1447 // send auth reply
1448 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
1449 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN);
1450 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
1451 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
1452 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
1453 // format buffer structure
1454 vMgrEncodeAuthen(&sFrame);
1455 /* insert values */
1456 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
1457 (
1458 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
1459 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
1460 WLAN_SET_FC_ISWEP(0)
1461));
1462 memcpy(sFrame.pHdr->sA3.abyAddr1, pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
1463 memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
1464 memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1465 *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
1466 *(sFrame.pwAuthSequence) = cpu_to_le16(4);
1467 *(sFrame.pwStatus) = cpu_to_le16(uStatusCode);
1468
1469 /* Adjust the length fields */
1470 pTxPacket->cbMPDULen = sFrame.len;
1471 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
1472 // send the frame
1473 if (pDevice->bEnableHostapd)
1474 return;
1475
1476 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING)
1477 pr_debug("Mgt:Authreq_reply sequence_4 tx failed\n");
1478}
1479
1480/*+
1481 *
1482 * Routine Description:
1483 * Handles incoming authen frames with sequence 4
1484 *
1485 *
1486 * Return Value:
1487 * None.
1488 *
1489 -*/
1490static
1491void
1492s_vMgrRxAuthenSequence_4(
1493 struct vnt_private *pDevice,
1494 PSMgmtObject pMgmt,
1495 PWLAN_FR_AUTHEN pFrame
1496)
1497{
1498 if (cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS) {
1499 pr_info("802.11 Authen (SHAREDKEY) Successful\n");
1500 pMgmt->eCurrState = WMAC_STATE_AUTH;
1501 timer_expire(pDevice->sTimerCommand, 0);
1502 } else{
1503 pr_info("802.11 Authen (SHAREDKEY) Failed\n");
1504 s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))));
1505 pMgmt->eCurrState = WMAC_STATE_IDLE;
1506 }
1507}
1508
1509/*+
1510 *
1511 * Routine Description:
1512 * Handles incoming disassociation frames
1513 *
1514 *
1515 * Return Value:
1516 * None.
1517 *
1518 -*/
1519
1520static
1521void
1522s_vMgrRxDisassociation(
1523 struct vnt_private *pDevice,
1524 PSMgmtObject pMgmt,
1525 PSRxMgmtPacket pRxPacket
1526)
1527{
1528 WLAN_FR_DISASSOC sFrame;
1529 unsigned int uNodeIndex = 0;
1530 viawget_wpa_header *wpahdr;
1531
1532 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1533 // if is acting an AP..
1534 // a STA is leaving this BSS..
1535 sFrame.len = pRxPacket->cbMPDULen;
1536 sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
1537 if (BSSDBbIsSTAInNodeDB(pMgmt, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex))
1538 BSSvRemoveOneNode(pDevice, uNodeIndex);
1539 else
1540 pr_debug("Rx disassoc, sta not found\n");
1541
1542 } else if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) {
1543 sFrame.len = pRxPacket->cbMPDULen;
1544 sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
1545 vMgrDecodeDisassociation(&sFrame);
1546 pr_info("AP disassociated me, reason=%d\n",
1547 cpu_to_le16(*(sFrame.pwReason)));
1548 //TODO: do something let upper layer know or
1549 //try to send associate packet again because of inactivity timeout
1550 if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
1551 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
1552 wpahdr->type = VIAWGET_DISASSOC_MSG;
1553 wpahdr->resp_ie_len = 0;
1554 wpahdr->req_ie_len = 0;
1555 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
1556 pDevice->skb->dev = pDevice->wpadev;
1557 skb_reset_mac_header(pDevice->skb);
1558
1559 pDevice->skb->pkt_type = PACKET_HOST;
1560 pDevice->skb->protocol = htons(ETH_P_802_2);
1561 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
1562 netif_rx(pDevice->skb);
1563 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1564 }
1565
1566#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1567 {
1568 union iwreq_data wrqu;
1569
1570 memset(&wrqu, 0, sizeof(wrqu));
1571 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1572 pr_debug("wireless_send_event--->SIOCGIWAP(disassociated)\n");
1573 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1574 }
1575#endif
1576 }
1577 /* else, ignore it */
1578}
1579
1580/*+
1581 *
1582 * Routine Description:
1583 * Handles incoming deauthentication frames
1584 *
1585 *
1586 * Return Value:
1587 * None.
1588 *
1589 -*/
1590
1591static
1592void
1593s_vMgrRxDeauthentication(
1594 struct vnt_private *pDevice,
1595 PSMgmtObject pMgmt,
1596 PSRxMgmtPacket pRxPacket
1597)
1598{
1599 WLAN_FR_DEAUTHEN sFrame;
1600 unsigned int uNodeIndex = 0;
1601 viawget_wpa_header *wpahdr;
1602
1603 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1604 //Todo:
1605 // if is acting an AP..
1606 // a STA is leaving this BSS..
1607 sFrame.len = pRxPacket->cbMPDULen;
1608 sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
1609 if (BSSDBbIsSTAInNodeDB(pMgmt, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex))
1610 BSSvRemoveOneNode(pDevice, uNodeIndex);
1611 else
1612 pr_info("Rx deauth, sta not found\n");
1613 } else {
1614 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) {
1615 sFrame.len = pRxPacket->cbMPDULen;
1616 sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
1617 vMgrDecodeDeauthen(&sFrame);
1618 pr_info("AP deauthed me, reason=%d\n",
1619 cpu_to_le16((*(sFrame.pwReason))));
1620 // TODO: update BSS list for specific BSSID if pre-authentication case
1621 if (ether_addr_equal(sFrame.pHdr->sA3.abyAddr3,
1622 pMgmt->abyCurrBSSID)) {
1623 if (pMgmt->eCurrState >= WMAC_STATE_AUTHPENDING) {
1624 pMgmt->sNodeDBTable[0].bActive = false;
1625 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1626 pMgmt->eCurrState = WMAC_STATE_IDLE;
1627 netif_stop_queue(pDevice->dev);
1628 pDevice->bLinkPass = false;
1629 }
1630 }
1631
1632 if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
1633 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
1634 wpahdr->type = VIAWGET_DISASSOC_MSG;
1635 wpahdr->resp_ie_len = 0;
1636 wpahdr->req_ie_len = 0;
1637 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
1638 pDevice->skb->dev = pDevice->wpadev;
1639 skb_reset_mac_header(pDevice->skb);
1640 pDevice->skb->pkt_type = PACKET_HOST;
1641 pDevice->skb->protocol = htons(ETH_P_802_2);
1642 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
1643 netif_rx(pDevice->skb);
1644 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1645 }
1646
1647#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1648 {
1649 union iwreq_data wrqu;
1650
1651 memset(&wrqu, 0, sizeof(wrqu));
1652 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1653 PRINT_K("wireless_send_event--->SIOCGIWAP(disauthen)\n");
1654 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1655 }
1656#endif
1657
1658 }
1659 /* else, ignore it. TODO: IBSS authentication service
1660 would be implemented here */
1661 }
1662}
1663
1664//2008-8-4 <add> by chester
1665/*+
1666 *
1667 * Routine Description:
1668 * check if current channel is match ZoneType.
1669 *for USA:1~11;
1670 * Japan:1~13;
1671 * Europe:1~13
1672 * Return Value:
1673 * True:exceed;
1674 * False:normal case
1675 -*/
1676static bool
1677ChannelExceedZoneType(
1678 struct vnt_private *pDevice,
1679 unsigned char byCurrChannel
1680)
1681{
1682 bool exceed = false;
1683
1684 switch (pDevice->byZoneType) {
1685 case 0x00: //USA:1~11
1686 if ((byCurrChannel < 1) || (byCurrChannel > 11))
1687 exceed = true;
1688 break;
1689 case 0x01: //Japan:1~13
1690 case 0x02: //Europe:1~13
1691 if ((byCurrChannel < 1) || (byCurrChannel > 13))
1692 exceed = true;
1693 break;
1694 default: //reserve for other zonetype
1695 break;
1696 }
1697
1698 return exceed;
1699}
1700
1701/*+
1702 *
1703 * Routine Description:
1704 * Handles and analysis incoming beacon frames.
1705 *
1706 *
1707 * Return Value:
1708 * None.
1709 *
1710 -*/
1711
1712static
1713void
1714s_vMgrRxBeacon(
1715 struct vnt_private *pDevice,
1716 PSMgmtObject pMgmt,
1717 PSRxMgmtPacket pRxPacket,
1718 bool bInScan
1719)
1720{
1721 PKnownBSS pBSSList;
1722 WLAN_FR_BEACON sFrame;
1723 u64 qwTSFOffset;
1724 bool bIsBSSIDEqual = false;
1725 bool bIsSSIDEqual = false;
1726 bool bTSFLargeDiff = false;
1727 bool bTSFOffsetPostive = false;
1728 bool bUpdateTSF = false;
1729 bool bIsAPBeacon = false;
1730 bool bIsChannelEqual = false;
1731 unsigned int uLocateByteIndex;
1732 unsigned char byTIMBitOn = 0;
1733 unsigned short wAIDNumber = 0;
1734 unsigned int uNodeIndex;
1735 u64 qwTimestamp, qwLocalTSF;
1736 u64 qwCurrTSF;
1737 unsigned short wStartIndex = 0;
1738 unsigned short wAIDIndex = 0;
1739 unsigned char byCurrChannel = pRxPacket->byRxChannel;
1740 ERPObject sERP;
1741 unsigned int uRateLen = WLAN_RATES_MAXLEN;
1742 bool bChannelHit = false;
1743 bool bUpdatePhyParameter = false;
1744 unsigned char byIEChannel = 0;
1745
1746 memset(&sFrame, 0, sizeof(WLAN_FR_BEACON));
1747 sFrame.len = pRxPacket->cbMPDULen;
1748 sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
1749
1750 // decode the beacon frame
1751 vMgrDecodeBeacon(&sFrame);
1752
1753 if ((sFrame.pwBeaconInterval == NULL) ||
1754 (sFrame.pwCapInfo == NULL) ||
1755 (sFrame.pSSID == NULL) ||
1756 (sFrame.pSuppRates == NULL)) {
1757 pr_debug("Rx beacon frame error\n");
1758 return;
1759 }
1760
1761 if (sFrame.pDSParms != NULL) {
1762 if (byCurrChannel > CB_MAX_CHANNEL_24G) {
1763 // channel remapping to
1764 byIEChannel = get_channel_mapping(pDevice, sFrame.pDSParms->byCurrChannel, PHY_TYPE_11A);
1765 } else {
1766 byIEChannel = sFrame.pDSParms->byCurrChannel;
1767 }
1768 if (byCurrChannel != byIEChannel) {
1769 // adjust channel info. bcs we rcv adjacent channel packets
1770 bChannelHit = false;
1771 byCurrChannel = byIEChannel;
1772 }
1773 } else {
1774 // no DS channel info
1775 bChannelHit = true;
1776 }
1777//2008-0730-01<Add>by MikeLiu
1778 if (ChannelExceedZoneType(pDevice, byCurrChannel))
1779 return;
1780
1781 if (sFrame.pERP != NULL) {
1782 sERP.byERP = sFrame.pERP->byContext;
1783 sERP.bERPExist = true;
1784
1785 } else {
1786 sERP.bERPExist = false;
1787 sERP.byERP = 0;
1788 }
1789
1790 pBSSList = BSSpAddrIsInBSSList((void *)pDevice, sFrame.pHdr->sA3.abyAddr3, sFrame.pSSID);
1791 if (pBSSList == NULL) {
1792 pr_debug("Beacon/insert: RxChannel = : %d\n", byCurrChannel);
1793 BSSbInsertToBSSList((void *)pDevice,
1794 sFrame.pHdr->sA3.abyAddr3,
1795 *sFrame.pqwTimestamp,
1796 *sFrame.pwBeaconInterval,
1797 *sFrame.pwCapInfo,
1798 byCurrChannel,
1799 sFrame.pSSID,
1800 sFrame.pSuppRates,
1801 sFrame.pExtSuppRates,
1802 &sERP,
1803 sFrame.pRSN,
1804 sFrame.pRSNWPA,
1805 sFrame.pIE_Country,
1806 sFrame.pIE_Quiet,
1807 sFrame.len - WLAN_HDR_ADDR3_LEN,
1808 sFrame.pHdr->sA4.abyAddr4, // payload of beacon
1809 (void *)pRxPacket
1810);
1811 } else {
1812 BSSbUpdateToBSSList((void *)pDevice,
1813 *sFrame.pqwTimestamp,
1814 *sFrame.pwBeaconInterval,
1815 *sFrame.pwCapInfo,
1816 byCurrChannel,
1817 bChannelHit,
1818 sFrame.pSSID,
1819 sFrame.pSuppRates,
1820 sFrame.pExtSuppRates,
1821 &sERP,
1822 sFrame.pRSN,
1823 sFrame.pRSNWPA,
1824 sFrame.pIE_Country,
1825 sFrame.pIE_Quiet,
1826 pBSSList,
1827 sFrame.len - WLAN_HDR_ADDR3_LEN,
1828 sFrame.pHdr->sA4.abyAddr4, // payload of probresponse
1829 (void *)pRxPacket
1830);
1831
1832 }
1833
1834 if (bInScan)
1835 return;
1836
1837 if (byCurrChannel == (unsigned char)pMgmt->uCurrChannel)
1838 bIsChannelEqual = true;
1839
1840 if (bIsChannelEqual && (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
1841 // if rx beacon without ERP field
1842 if (sERP.bERPExist) {
1843 if (WLAN_GET_ERP_USE_PROTECTION(sERP.byERP)) {
1844 pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
1845 pDevice->wUseProtectCntDown = USE_PROTECT_PERIOD;
1846 }
1847 } else {
1848 pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
1849 pDevice->wUseProtectCntDown = USE_PROTECT_PERIOD;
1850 }
1851
1852 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1853 if (!WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo))
1854 pDevice->byERPFlag |= WLAN_SET_ERP_BARKER_MODE(1);
1855 if (!sERP.bERPExist)
1856 pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
1857 }
1858
1859 // set to MAC&BBP
1860 if (WLAN_GET_ERP_USE_PROTECTION(pDevice->byERPFlag)) {
1861 if (!pDevice->bProtectMode) {
1862 MACvEnableProtectMD(pDevice->PortOffset);
1863 pDevice->bProtectMode = true;
1864 }
1865 }
1866 }
1867
1868 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)
1869 return;
1870
1871 // check if BSSID the same
1872 if (memcmp(sFrame.pHdr->sA3.abyAddr3,
1873 pMgmt->abyCurrBSSID,
1874 WLAN_BSSID_LEN) == 0) {
1875 bIsBSSIDEqual = true;
1876
1877// 2008-05-21 <add> by Richardtai
1878 pDevice->uCurrRSSI = pRxPacket->uRSSI;
1879 pDevice->byCurrSQ = pRxPacket->bySQ;
1880
1881 if (pMgmt->sNodeDBTable[0].uInActiveCount != 0)
1882 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
1883 }
1884 // check if SSID the same
1885 if (sFrame.pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) {
1886 if (memcmp(sFrame.pSSID->abySSID,
1887 ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,
1888 sFrame.pSSID->len
1889) == 0) {
1890 bIsSSIDEqual = true;
1891 }
1892 }
1893
1894 if (WLAN_GET_CAP_INFO_ESS(*sFrame.pwCapInfo) &&
1895 bIsBSSIDEqual &&
1896 bIsSSIDEqual &&
1897 (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
1898 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
1899 // add state check to prevent reconnect fail since we'll receive Beacon
1900
1901 bIsAPBeacon = true;
1902
1903 if (pBSSList != NULL) {
1904 // Compare PHY parameter setting
1905 if (pMgmt->wCurrCapInfo != pBSSList->wCapInfo) {
1906 bUpdatePhyParameter = true;
1907 pMgmt->wCurrCapInfo = pBSSList->wCapInfo;
1908 }
1909 if (sFrame.pERP != NULL) {
1910 if ((sFrame.pERP->byElementID == WLAN_EID_ERP) &&
1911 (pMgmt->byERPContext != sFrame.pERP->byContext)) {
1912 bUpdatePhyParameter = true;
1913 pMgmt->byERPContext = sFrame.pERP->byContext;
1914 }
1915 }
1916 //
1917 // Basic Rate Set may change dynamically
1918 //
1919 if (pBSSList->eNetworkTypeInUse == PHY_TYPE_11B)
1920 uRateLen = WLAN_RATES_MAXLEN_11B;
1921
1922 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pBSSList->abySuppRates,
1923 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1924 uRateLen);
1925 pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pBSSList->abyExtSuppRates,
1926 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
1927 uRateLen);
1928 RATEvParseMaxRate((void *)pDevice,
1929 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1930 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
1931 true,
1932 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
1933 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
1934 &(pMgmt->sNodeDBTable[0].wSuppRate),
1935 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
1936 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
1937 );
1938 if (bUpdatePhyParameter) {
1939 CARDbSetPhyParameter(pMgmt->pAdapter,
1940 pMgmt->eCurrentPHYMode,
1941 pMgmt->wCurrCapInfo,
1942 pMgmt->byERPContext,
1943 pMgmt->abyCurrSuppRates,
1944 pMgmt->abyCurrExtSuppRates
1945 );
1946 }
1947 if (sFrame.pIE_PowerConstraint != NULL) {
1948 CARDvSetPowerConstraint(pMgmt->pAdapter,
1949 (unsigned char) pBSSList->uChannel,
1950 sFrame.pIE_PowerConstraint->byPower
1951);
1952 }
1953 if (sFrame.pIE_CHSW != NULL) {
1954 CARDbChannelSwitch(pMgmt->pAdapter,
1955 sFrame.pIE_CHSW->byMode,
1956 get_channel_mapping(pMgmt->pAdapter, sFrame.pIE_CHSW->byMode, pMgmt->eCurrentPHYMode),
1957 sFrame.pIE_CHSW->byCount
1958 );
1959
1960 } else if (!bIsChannelEqual) {
1961 set_channel(pMgmt->pAdapter, pBSSList->uChannel);
1962 }
1963 }
1964 }
1965
1966// pr_debug("Beacon 2\n");
1967 // check if CF field exists
1968 if (WLAN_GET_CAP_INFO_ESS(*sFrame.pwCapInfo)) {
1969 if (sFrame.pCFParms->wCFPDurRemaining > 0) {
1970 // TODO: deal with CFP period to set NAV
1971 }
1972 }
1973
1974 qwTimestamp = le64_to_cpu(*sFrame.pqwTimestamp);
1975 qwLocalTSF = pRxPacket->qwLocalTSF;
1976
1977 // check if beacon TSF larger or small than our local TSF
1978 if (qwTimestamp >= qwLocalTSF)
1979 bTSFOffsetPostive = true;
1980 else
1981 bTSFOffsetPostive = false;
1982
1983 if (bTSFOffsetPostive)
1984 qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwTimestamp), (qwLocalTSF));
1985 else
1986 qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwLocalTSF), (qwTimestamp));
1987
1988 if (qwTSFOffset > TRIVIAL_SYNC_DIFFERENCE)
1989 bTSFLargeDiff = true;
1990
1991 // if infra mode
1992 if (bIsAPBeacon) {
1993 // Infra mode: Local TSF always follow AP's TSF if Difference huge.
1994 if (bTSFLargeDiff)
1995 bUpdateTSF = true;
1996
1997 if (pDevice->bEnablePSMode && (sFrame.pTIM != NULL)) {
1998 // deal with DTIM, analysis TIM
1999 pMgmt->bMulticastTIM = WLAN_MGMT_IS_MULTICAST_TIM(sFrame.pTIM->byBitMapCtl) ? true : false;
2000 pMgmt->byDTIMCount = sFrame.pTIM->byDTIMCount;
2001 pMgmt->byDTIMPeriod = sFrame.pTIM->byDTIMPeriod;
2002 wAIDNumber = pMgmt->wCurrAID & ~(BIT14|BIT15);
2003
2004 // check if AID in TIM field bit on
2005 // wStartIndex = N1
2006 wStartIndex = WLAN_MGMT_GET_TIM_OFFSET(sFrame.pTIM->byBitMapCtl) << 1;
2007 // AIDIndex = N2
2008 wAIDIndex = (wAIDNumber >> 3);
2009 if ((wAIDNumber > 0) && (wAIDIndex >= wStartIndex)) {
2010 uLocateByteIndex = wAIDIndex - wStartIndex;
2011 // len = byDTIMCount + byDTIMPeriod + byDTIMPeriod + byVirtBitMap[0~250]
2012 if (sFrame.pTIM->len >= (uLocateByteIndex + 4)) {
2013 byTIMBitOn = (0x01) << ((wAIDNumber) % 8);
2014 pMgmt->bInTIM = sFrame.pTIM->byVirtBitMap[uLocateByteIndex] & byTIMBitOn ? true : false;
2015 } else {
2016 pMgmt->bInTIM = false;
2017 }
2018 } else {
2019 pMgmt->bInTIM = false;
2020 }
2021
2022 if (pMgmt->bInTIM ||
2023 (pMgmt->bMulticastTIM && (pMgmt->byDTIMCount == 0))) {
2024 pMgmt->bInTIMWake = true;
2025 // send out ps-poll packet
2026
2027 if (pMgmt->bInTIM)
2028 PSvSendPSPOLL(pDevice);
2029
2030 } else {
2031 pMgmt->bInTIMWake = false;
2032 pr_debug("BCN: Not In TIM..\n");
2033 if (!pDevice->bPWBitOn) {
2034 pr_debug("BCN: Send Null Packet\n");
2035 if (PSbSendNullPacket(pDevice))
2036 pDevice->bPWBitOn = true;
2037 }
2038 if (PSbConsiderPowerDown(pDevice, false, false))
2039 pr_debug("BCN: Power down now...\n");
2040 }
2041
2042 }
2043
2044 }
2045 // if adhoc mode
2046 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && !bIsAPBeacon && bIsChannelEqual) {
2047 if (bIsBSSIDEqual) {
2048 // Use sNodeDBTable[0].uInActiveCount as IBSS beacons received count.
2049 if (pMgmt->sNodeDBTable[0].uInActiveCount != 0)
2050 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
2051
2052 // adhoc mode:TSF updated only when beacon larger than local TSF
2053 if (bTSFLargeDiff && bTSFOffsetPostive &&
2054 (pMgmt->eCurrState == WMAC_STATE_JOINTED))
2055 bUpdateTSF = true;
2056
2057 // During dpc, already in spinlocked.
2058 if (BSSDBbIsSTAInNodeDB(pMgmt, sFrame.pHdr->sA3.abyAddr2, &uNodeIndex)) {
2059 // Update the STA, (Technically the Beacons of all the IBSS nodes
2060 // should be identical, but that's not happening in practice.
2061 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
2062 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2063 WLAN_RATES_MAXLEN_11B);
2064 RATEvParseMaxRate((void *)pDevice,
2065 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2066 NULL,
2067 true,
2068 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
2069 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
2070 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
2071 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
2072 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
2073 );
2074 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
2075 pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
2076 pMgmt->sNodeDBTable[uNodeIndex].uInActiveCount = 0;
2077 } else {
2078 // Todo, initial Node content
2079 BSSvCreateOneNode(pDevice, &uNodeIndex);
2080
2081 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
2082 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2083 WLAN_RATES_MAXLEN_11B);
2084 RATEvParseMaxRate((void *)pDevice,
2085 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2086 NULL,
2087 true,
2088 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
2089 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
2090 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
2091 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
2092 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
2093 );
2094
2095 memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, sFrame.pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
2096 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
2097 pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate = pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
2098 {
2099 pr_debug("s_vMgrRxBeacon:TxDataRate is %d,Index is %d\n", pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate, uNodeIndex);
2100 }
2101 }
2102
2103 // if other stations joined, indicate connection to upper layer..
2104 if (pMgmt->eCurrState == WMAC_STATE_STARTED) {
2105 pr_debug("Current IBSS State: [Started]........to: [Jointed]\n");
2106 pMgmt->eCurrState = WMAC_STATE_JOINTED;
2107 pDevice->bLinkPass = true;
2108 if (netif_queue_stopped(pDevice->dev))
2109 netif_wake_queue(pDevice->dev);
2110
2111 pMgmt->sNodeDBTable[0].bActive = true;
2112 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
2113
2114 }
2115 } else if (bIsSSIDEqual) {
2116 // See other adhoc sta with the same SSID but BSSID is different.
2117 // adpot this vars only when TSF larger then us.
2118 if (bTSFLargeDiff && bTSFOffsetPostive) {
2119 // we don't support ATIM under adhoc mode
2120 // if (sFrame.pIBSSParms->wATIMWindow == 0) {
2121 // adpot this vars
2122 // TODO: check sFrame cap if privacy on, and support rate syn
2123 memcpy(pMgmt->abyCurrBSSID, sFrame.pHdr->sA3.abyAddr3, WLAN_BSSID_LEN);
2124 memcpy(pDevice->abyBSSID, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
2125 pMgmt->wCurrATIMWindow = cpu_to_le16(sFrame.pIBSSParms->wATIMWindow);
2126 pMgmt->wCurrBeaconPeriod = cpu_to_le16(*sFrame.pwBeaconInterval);
2127 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
2128 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2129 WLAN_RATES_MAXLEN_11B);
2130 // set HW beacon interval and re-synchronizing....
2131 pr_debug("Rejoining to Other Adhoc group with same SSID........\n");
2132 VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, pMgmt->wCurrBeaconPeriod);
2133 CARDbUpdateTSF(pDevice, pRxPacket->byRxRate, qwTimestamp, qwLocalTSF);
2134 CARDvUpdateNextTBTT(pDevice->PortOffset, qwTimestamp, pMgmt->wCurrBeaconPeriod);
2135 // Turn off bssid filter to avoid filter others adhoc station which bssid is different.
2136 MACvWriteBSSIDAddress(pDevice->PortOffset, pMgmt->abyCurrBSSID);
2137
2138 CARDbSetPhyParameter(pMgmt->pAdapter,
2139 pMgmt->eCurrentPHYMode,
2140 pMgmt->wCurrCapInfo,
2141 pMgmt->byERPContext,
2142 pMgmt->abyCurrSuppRates,
2143 pMgmt->abyCurrExtSuppRates);
2144
2145 // Prepare beacon frame
2146 bMgrPrepareBeaconToSend((void *)pDevice, pMgmt);
2147 }
2148 }
2149 }
2150 // endian issue ???
2151 // Update TSF
2152if (bUpdateTSF) {
2153 CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
2154 CARDbUpdateTSF(pDevice, pRxPacket->byRxRate, qwTimestamp, pRxPacket->qwLocalTSF);
2155 CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
2156 CARDvUpdateNextTBTT(pDevice->PortOffset, qwTimestamp, pMgmt->wCurrBeaconPeriod);
2157 }
2158}
2159
2160/*+
2161 *
2162 * Routine Description:
2163 * Instructs the hw to create a bss using the supplied
2164 * attributes. Note that this implementation only supports Ad-Hoc
2165 * BSS creation.
2166 *
2167 *
2168 * Return Value:
2169 * CMD_STATUS
2170 *
2171 -*/
2172void
2173vMgrCreateOwnIBSS(
2174 void *hDeviceContext,
2175 PCMD_STATUS pStatus
2176)
2177{
2178 struct vnt_private *pDevice = hDeviceContext;
2179 PSMgmtObject pMgmt = pDevice->pMgmt;
2180 unsigned short wMaxBasicRate;
2181 unsigned short wMaxSuppRate;
2182 unsigned char byTopCCKBasicRate;
2183 unsigned char byTopOFDMBasicRate;
2184 u64 qwCurrTSF;
2185 unsigned int ii;
2186 unsigned char abyRATE[] = {0x82, 0x84, 0x8B, 0x96, 0x24, 0x30, 0x48, 0x6C, 0x0C, 0x12, 0x18, 0x60};
2187 unsigned char abyCCK_RATE[] = {0x82, 0x84, 0x8B, 0x96};
2188 unsigned char abyOFDM_RATE[] = {0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
2189 unsigned short wSuppRate;
2190
2191 pr_debug("Create Basic Service Set .......\n");
2192
2193 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
2194 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) &&
2195 (pDevice->eEncryptionStatus != Ndis802_11Encryption2Enabled) &&
2196 (pDevice->eEncryptionStatus != Ndis802_11Encryption3Enabled)) {
2197 // encryption mode error
2198 *pStatus = CMD_STATUS_FAILURE;
2199 return;
2200 }
2201 }
2202
2203 pMgmt->abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
2204 pMgmt->abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
2205
2206 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2207 pMgmt->eCurrentPHYMode = pMgmt->byAPBBType;
2208 } else {
2209 if (pDevice->byBBType == BB_TYPE_11G)
2210 pMgmt->eCurrentPHYMode = PHY_TYPE_11G;
2211 if (pDevice->byBBType == BB_TYPE_11B)
2212 pMgmt->eCurrentPHYMode = PHY_TYPE_11B;
2213 if (pDevice->byBBType == BB_TYPE_11A)
2214 pMgmt->eCurrentPHYMode = PHY_TYPE_11A;
2215 }
2216
2217 if (pMgmt->eCurrentPHYMode != PHY_TYPE_11A) {
2218 pMgmt->abyCurrSuppRates[1] = WLAN_RATES_MAXLEN_11B;
2219 pMgmt->abyCurrExtSuppRates[1] = 0;
2220 for (ii = 0; ii < 4; ii++)
2221 pMgmt->abyCurrSuppRates[2+ii] = abyRATE[ii];
2222 } else {
2223 pMgmt->abyCurrSuppRates[1] = 8;
2224 pMgmt->abyCurrExtSuppRates[1] = 0;
2225 for (ii = 0; ii < 8; ii++)
2226 pMgmt->abyCurrSuppRates[2+ii] = abyRATE[ii];
2227 }
2228
2229 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
2230 pMgmt->abyCurrSuppRates[1] = 8;
2231 pMgmt->abyCurrExtSuppRates[1] = 4;
2232 for (ii = 0; ii < 4; ii++)
2233 pMgmt->abyCurrSuppRates[2+ii] = abyCCK_RATE[ii];
2234 for (ii = 4; ii < 8; ii++)
2235 pMgmt->abyCurrSuppRates[2+ii] = abyOFDM_RATE[ii-4];
2236 for (ii = 0; ii < 4; ii++)
2237 pMgmt->abyCurrExtSuppRates[2+ii] = abyOFDM_RATE[ii+4];
2238 }
2239
2240 // Disable Protect Mode
2241 pDevice->bProtectMode = false;
2242 MACvDisableProtectMD(pDevice->PortOffset);
2243
2244 pDevice->bBarkerPreambleMd = false;
2245 MACvDisableBarkerPreambleMd(pDevice->PortOffset);
2246
2247 // Kyle Test 2003.11.04
2248
2249 // set HW beacon interval
2250 if (pMgmt->wIBSSBeaconPeriod == 0)
2251 pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
2252
2253 CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
2254 // clear TSF counter
2255 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
2256 // enable TSF counter
2257 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
2258
2259 // set Next TBTT
2260 CARDvSetFirstNextTBTT(pDevice->PortOffset, pMgmt->wIBSSBeaconPeriod);
2261
2262 pMgmt->uIBSSChannel = pDevice->uChannel;
2263
2264 if (pMgmt->uIBSSChannel == 0)
2265 pMgmt->uIBSSChannel = DEFAULT_IBSS_CHANNEL;
2266
2267 // set basic rate
2268
2269 RATEvParseMaxRate((void *)pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2270 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates, true,
2271 &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
2272 &byTopCCKBasicRate, &byTopOFDMBasicRate);
2273
2274 if (pMgmt->eConfigMode == WMAC_CONFIG_AP)
2275 pMgmt->eCurrMode = WMAC_MODE_ESS_AP;
2276
2277 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
2278 memcpy(pMgmt->abyIBSSDFSOwner, pDevice->abyCurrentNetAddr, 6);
2279 pMgmt->byIBSSDFSRecovery = 10;
2280 pMgmt->eCurrMode = WMAC_MODE_IBSS_STA;
2281 }
2282
2283 // Adopt pre-configured IBSS vars to current vars
2284 pMgmt->eCurrState = WMAC_STATE_STARTED;
2285 pMgmt->wCurrBeaconPeriod = pMgmt->wIBSSBeaconPeriod;
2286 pMgmt->uCurrChannel = pMgmt->uIBSSChannel;
2287 pMgmt->wCurrATIMWindow = pMgmt->wIBSSATIMWindow;
2288 MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow);
2289 pDevice->uCurrRSSI = 0;
2290 pDevice->byCurrSQ = 0;
2291 memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
2292 memcpy(pMgmt->abyCurrSSID,
2293 pMgmt->abyDesireSSID,
2294 ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len + WLAN_IEHDR_LEN
2295);
2296
2297 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2298 // AP mode BSSID = MAC addr
2299 memcpy(pMgmt->abyCurrBSSID, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
2300 pr_info("AP beacon created BSSID:%pM\n",
2301 pMgmt->abyCurrBSSID);
2302 }
2303
2304 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2305 // BSSID selected must be randomized as spec 11.1.3
2306 pMgmt->abyCurrBSSID[5] = (u8) (qwCurrTSF & 0x000000ff);
2307 pMgmt->abyCurrBSSID[4] = (u8) ((qwCurrTSF & 0x0000ff00) >> 8);
2308 pMgmt->abyCurrBSSID[3] = (u8) ((qwCurrTSF & 0x00ff0000) >> 16);
2309 pMgmt->abyCurrBSSID[2] = (u8) ((qwCurrTSF & 0x00000ff0) >> 4);
2310 pMgmt->abyCurrBSSID[1] = (u8) ((qwCurrTSF & 0x000ff000) >> 12);
2311 pMgmt->abyCurrBSSID[0] = (u8) ((qwCurrTSF & 0x0ff00000) >> 20);
2312 pMgmt->abyCurrBSSID[5] ^= pMgmt->abyMACAddr[0];
2313 pMgmt->abyCurrBSSID[4] ^= pMgmt->abyMACAddr[1];
2314 pMgmt->abyCurrBSSID[3] ^= pMgmt->abyMACAddr[2];
2315 pMgmt->abyCurrBSSID[2] ^= pMgmt->abyMACAddr[3];
2316 pMgmt->abyCurrBSSID[1] ^= pMgmt->abyMACAddr[4];
2317 pMgmt->abyCurrBSSID[0] ^= pMgmt->abyMACAddr[5];
2318 pMgmt->abyCurrBSSID[0] &= ~IEEE_ADDR_GROUP;
2319 pMgmt->abyCurrBSSID[0] |= IEEE_ADDR_UNIVERSAL;
2320
2321 pr_info("Adhoc beacon created bssid:%pM\n",
2322 pMgmt->abyCurrBSSID);
2323 }
2324
2325 // Set Capability Info
2326 pMgmt->wCurrCapInfo = 0;
2327
2328 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2329 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
2330 pMgmt->byDTIMPeriod = DEFAULT_DTIM_PERIOD;
2331 pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
2332 }
2333
2334 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)
2335 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_IBSS(1);
2336
2337 if (pDevice->bEncryptionEnable) {
2338 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
2339 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
2340 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2341 pMgmt->byCSSPK = KEY_CTL_CCMP;
2342 pMgmt->byCSSGK = KEY_CTL_CCMP;
2343 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2344 pMgmt->byCSSPK = KEY_CTL_TKIP;
2345 pMgmt->byCSSGK = KEY_CTL_TKIP;
2346 } else {
2347 pMgmt->byCSSPK = KEY_CTL_NONE;
2348 pMgmt->byCSSGK = KEY_CTL_WEP;
2349 }
2350 } else {
2351 pMgmt->byCSSPK = KEY_CTL_WEP;
2352 pMgmt->byCSSGK = KEY_CTL_WEP;
2353 }
2354 }
2355
2356 pMgmt->byERPContext = 0;
2357
2358 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2359 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, NL80211_IFTYPE_AP);
2360 } else {
2361 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, NL80211_IFTYPE_ADHOC);
2362 }
2363
2364 CARDbSetPhyParameter(pMgmt->pAdapter,
2365 pMgmt->eCurrentPHYMode,
2366 pMgmt->wCurrCapInfo,
2367 pMgmt->byERPContext,
2368 pMgmt->abyCurrSuppRates,
2369 pMgmt->abyCurrExtSuppRates
2370 );
2371
2372 CARDbSetBeaconPeriod(pMgmt->pAdapter, pMgmt->wIBSSBeaconPeriod);
2373 // set channel and clear NAV
2374 set_channel(pMgmt->pAdapter, pMgmt->uIBSSChannel);
2375 pMgmt->uCurrChannel = pMgmt->uIBSSChannel;
2376
2377 if (CARDbIsShortPreamble(pMgmt->pAdapter))
2378 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
2379 else
2380 pMgmt->wCurrCapInfo &= (~WLAN_SET_CAP_INFO_SHORTPREAMBLE(1));
2381
2382 if (pMgmt->b11hEnable &&
2383 (pMgmt->eCurrentPHYMode == PHY_TYPE_11A)) {
2384 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
2385 } else {
2386 pMgmt->wCurrCapInfo &= (~WLAN_SET_CAP_INFO_SPECTRUMMNG(1));
2387 }
2388
2389 pMgmt->eCurrState = WMAC_STATE_STARTED;
2390 // Prepare beacon to send
2391 if (bMgrPrepareBeaconToSend((void *)pDevice, pMgmt))
2392 *pStatus = CMD_STATUS_SUCCESS;
2393}
2394
2395/*+
2396 *
2397 * Routine Description:
2398 * Instructs wmac to join a bss using the supplied attributes.
2399 * The arguments may the BSSID or SSID and the rest of the
2400 * attributes are obtained from the scan result of known bss list.
2401 *
2402 *
2403 * Return Value:
2404 * None.
2405 *
2406 -*/
2407
2408void
2409vMgrJoinBSSBegin(
2410 void *hDeviceContext,
2411 PCMD_STATUS pStatus
2412)
2413{
2414 struct vnt_private *pDevice = hDeviceContext;
2415 PSMgmtObject pMgmt = pDevice->pMgmt;
2416 PKnownBSS pCurr = NULL;
2417 unsigned int ii, uu;
2418 PWLAN_IE_SUPP_RATES pItemRates = NULL;
2419 PWLAN_IE_SUPP_RATES pItemExtRates = NULL;
2420 PWLAN_IE_SSID pItemSSID;
2421 unsigned int uRateLen = WLAN_RATES_MAXLEN;
2422 unsigned short wMaxBasicRate = RATE_1M;
2423 unsigned short wMaxSuppRate = RATE_1M;
2424 unsigned short wSuppRate;
2425 unsigned char byTopCCKBasicRate = RATE_1M;
2426 unsigned char byTopOFDMBasicRate = RATE_1M;
2427
2428 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
2429 if (pMgmt->sBSSList[ii].bActive)
2430 break;
2431 }
2432
2433 if (ii == MAX_BSS_NUM) {
2434 *pStatus = CMD_STATUS_RESOURCES;
2435 pr_info("BSS finding:BSS list is empty\n");
2436 return;
2437 }
2438
2439 // Search known BSS list for prefer BSSID or SSID
2440
2441 pCurr = BSSpSearchBSSList(pDevice,
2442 pMgmt->abyDesireBSSID,
2443 pMgmt->abyDesireSSID,
2444 pMgmt->eConfigPHYMode
2445);
2446
2447 if (pCurr == NULL) {
2448 *pStatus = CMD_STATUS_RESOURCES;
2449 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
2450 pr_info("Scanning [%s] not found, disconnected !\n",
2451 pItemSSID->abySSID);
2452 return;
2453 }
2454
2455 pr_info("AP(BSS) finding:Found a AP(BSS)..\n");
2456 if (WLAN_GET_CAP_INFO_ESS(cpu_to_le16(pCurr->wCapInfo))) {
2457 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA) || (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)) {
2458 // patch for CISCO migration mode
2459 }
2460
2461#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2462 Encyption_Rebuild(pDevice, pCurr);
2463#endif
2464 // Infrastructure BSS
2465 s_vMgrSynchBSS(pDevice,
2466 WMAC_MODE_ESS_STA,
2467 pCurr,
2468 pStatus
2469);
2470
2471 if (*pStatus == CMD_STATUS_SUCCESS) {
2472 // Adopt this BSS state vars in Mgmt Object
2473 pMgmt->uCurrChannel = pCurr->uChannel;
2474
2475 memset(pMgmt->abyCurrSuppRates, 0 , WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
2476 memset(pMgmt->abyCurrExtSuppRates, 0 , WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
2477
2478 if (pCurr->eNetworkTypeInUse == PHY_TYPE_11B)
2479 uRateLen = WLAN_RATES_MAXLEN_11B;
2480
2481 pItemRates = (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates;
2482 pItemExtRates = (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates;
2483
2484 // Parse Support Rate IE
2485 pItemRates->byElementID = WLAN_EID_SUPP_RATES;
2486 pItemRates->len = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abySuppRates,
2487 pItemRates,
2488 uRateLen);
2489
2490 // Parse Extension Support Rate IE
2491 pItemExtRates->byElementID = WLAN_EID_EXTSUPP_RATES;
2492 pItemExtRates->len = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abyExtSuppRates,
2493 pItemExtRates,
2494 uRateLen);
2495 // Stuffing Rate IE
2496 if ((pItemExtRates->len > 0) && (pItemRates->len < 8)) {
2497 for (ii = 0; ii < (unsigned int)(8 - pItemRates->len);) {
2498 pItemRates->abyRates[pItemRates->len + ii] = pItemExtRates->abyRates[ii];
2499 ii++;
2500 if (pItemExtRates->len <= ii)
2501 break;
2502 }
2503 pItemRates->len += (unsigned char)ii;
2504 if (pItemExtRates->len - ii > 0) {
2505 pItemExtRates->len -= (unsigned char)ii;
2506 for (uu = 0; uu < pItemExtRates->len; uu++)
2507 pItemExtRates->abyRates[uu] = pItemExtRates->abyRates[uu + ii];
2508 } else {
2509 pItemExtRates->len = 0;
2510 }
2511 }
2512
2513 RATEvParseMaxRate((void *)pDevice, pItemRates, pItemExtRates, true,
2514 &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
2515 &byTopCCKBasicRate, &byTopOFDMBasicRate);
2516
2517 // TODO: deal with if wCapInfo the privacy is on, but station WEP is off
2518 // TODO: deal with if wCapInfo the PS-Pollable is on.
2519 pMgmt->wCurrBeaconPeriod = pCurr->wBeaconInterval;
2520 memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
2521 memcpy(pMgmt->abyCurrBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
2522 memcpy(pMgmt->abyCurrSSID, pCurr->abySSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
2523
2524 pMgmt->eCurrMode = WMAC_MODE_ESS_STA;
2525
2526 pMgmt->eCurrState = WMAC_STATE_JOINTED;
2527
2528 // Add current BSS to Candidate list
2529 // This should only works for WPA2 BSS, and WPA2 BSS check must be done before.
2530 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
2531 bool bResult = bAdd_PMKID_Candidate((void *)pDevice, pMgmt->abyCurrBSSID, &pCurr->sRSNCapObj);
2532
2533 pr_debug("bAdd_PMKID_Candidate: 1(%d)\n",
2534 bResult);
2535 if (!bResult) {
2536 vFlush_PMKID_Candidate((void *)pDevice);
2537 pr_debug("vFlush_PMKID_Candidate: 4\n");
2538 bAdd_PMKID_Candidate((void *)pDevice, pMgmt->abyCurrBSSID, &pCurr->sRSNCapObj);
2539 }
2540 }
2541
2542 // Preamble type auto-switch: if AP can receive short-preamble cap,
2543 // we can turn on too.
2544
2545 pr_debug("Join ESS\n");
2546
2547 pr_debug("End of Join AP -- A/B/G Action\n");
2548 } else {
2549 pMgmt->eCurrState = WMAC_STATE_IDLE;
2550 }
2551
2552 } else {
2553 // ad-hoc mode BSS
2554 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
2555 if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2556 if (!WPA_SearchRSN(0, WPA_TKIP, pCurr)) {
2557 // encryption mode error
2558 pMgmt->eCurrState = WMAC_STATE_IDLE;
2559 return;
2560 }
2561 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2562 if (!WPA_SearchRSN(0, WPA_AESCCMP, pCurr)) {
2563 // encryption mode error
2564 pMgmt->eCurrState = WMAC_STATE_IDLE;
2565 return;
2566 }
2567 } else {
2568 // encryption mode error
2569 pMgmt->eCurrState = WMAC_STATE_IDLE;
2570 return;
2571 }
2572 }
2573
2574 s_vMgrSynchBSS(pDevice,
2575 WMAC_MODE_IBSS_STA,
2576 pCurr,
2577 pStatus
2578);
2579
2580 if (*pStatus == CMD_STATUS_SUCCESS) {
2581 // Adopt this BSS state vars in Mgmt Object
2582 // TODO: check if CapInfo privacy on, but we don't..
2583 pMgmt->uCurrChannel = pCurr->uChannel;
2584
2585 // Parse Support Rate IE
2586 pMgmt->abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
2587 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abySuppRates,
2588 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2589 WLAN_RATES_MAXLEN_11B);
2590 // set basic rate
2591 RATEvParseMaxRate((void *)pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2592 NULL, true, &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
2593 &byTopCCKBasicRate, &byTopOFDMBasicRate);
2594
2595 pMgmt->wCurrCapInfo = pCurr->wCapInfo;
2596 pMgmt->wCurrBeaconPeriod = pCurr->wBeaconInterval;
2597 memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN);
2598 memcpy(pMgmt->abyCurrBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
2599 memcpy(pMgmt->abyCurrSSID, pCurr->abySSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN);
2600 MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow);
2601 pMgmt->eCurrMode = WMAC_MODE_IBSS_STA;
2602
2603 pMgmt->eCurrState = WMAC_STATE_STARTED;
2604
2605 pr_debug("Join IBSS ok:%pM\n",
2606 pMgmt->abyCurrBSSID);
2607 // Preamble type auto-switch: if AP can receive short-preamble cap,
2608 // and if registry setting is short preamble we can turn on too.
2609
2610 // Prepare beacon
2611 bMgrPrepareBeaconToSend((void *)pDevice, pMgmt);
2612 } else {
2613 pMgmt->eCurrState = WMAC_STATE_IDLE;
2614 }
2615 }
2616}
2617
2618/*+
2619 *
2620 * Routine Description:
2621 * Set HW to synchronize a specific BSS from known BSS list.
2622 *
2623 *
2624 * Return Value:
2625 * PCM_STATUS
2626 *
2627 -*/
2628static
2629void
2630s_vMgrSynchBSS(
2631 struct vnt_private *pDevice,
2632 unsigned int uBSSMode,
2633 PKnownBSS pCurr,
2634 PCMD_STATUS pStatus
2635)
2636{
2637 CARD_PHY_TYPE ePhyType = PHY_TYPE_11B;
2638 PSMgmtObject pMgmt = pDevice->pMgmt;
2639
2640 //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
2641 unsigned char abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
2642 unsigned char abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
2643 //6M, 9M, 12M, 48M
2644 unsigned char abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
2645 unsigned char abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
2646
2647 *pStatus = CMD_STATUS_FAILURE;
2648
2649 if (!s_bCipherMatch(pCurr,
2650 pDevice->eEncryptionStatus,
2651 &(pMgmt->byCSSPK),
2652 &(pMgmt->byCSSGK))) {
2653 pr_debug("s_bCipherMatch Fail .......\n");
2654 return;
2655 }
2656
2657 pMgmt->pCurrBSS = pCurr;
2658
2659 // if previous mode is IBSS.
2660 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2661 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_BCNDMACTL, BEACON_READY);
2662 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
2663 }
2664
2665 // Init the BSS informations
2666 pDevice->bProtectMode = false;
2667 MACvDisableProtectMD(pDevice->PortOffset);
2668 pDevice->bBarkerPreambleMd = false;
2669 MACvDisableBarkerPreambleMd(pDevice->PortOffset);
2670 pDevice->bNonERPPresent = false;
2671 pDevice->byPreambleType = 0;
2672 pDevice->wBasicRate = 0;
2673 // Set Basic Rate
2674 CARDbAddBasicRate((void *)pDevice, RATE_1M);
2675 // calculate TSF offset
2676 // TSF Offset = Received Timestamp TSF - Marked Local's TSF
2677 CARDbUpdateTSF(pDevice, pCurr->byRxRate, pCurr->qwBSSTimestamp, pCurr->qwLocalTSF);
2678
2679 CARDbSetBeaconPeriod(pDevice, pCurr->wBeaconInterval);
2680
2681 // set Next TBTT
2682 // Next TBTT = ((local_current_TSF / beacon_interval) + 1) * beacon_interval
2683 CARDvSetFirstNextTBTT(pDevice->PortOffset, pCurr->wBeaconInterval);
2684
2685 // set BSSID
2686 MACvWriteBSSIDAddress(pDevice->PortOffset, pCurr->abyBSSID);
2687
2688 MACvReadBSSIDAddress(pDevice->PortOffset, pMgmt->abyCurrBSSID);
2689
2690 pr_debug("Sync:set CurrBSSID address = %pM\n", pMgmt->abyCurrBSSID);
2691
2692 if (pCurr->eNetworkTypeInUse == PHY_TYPE_11A) {
2693 if ((pMgmt->eConfigPHYMode == PHY_TYPE_11A) ||
2694 (pMgmt->eConfigPHYMode == PHY_TYPE_AUTO)) {
2695 ePhyType = PHY_TYPE_11A;
2696 } else {
2697 return;
2698 }
2699 } else if (pCurr->eNetworkTypeInUse == PHY_TYPE_11B) {
2700 if ((pMgmt->eConfigPHYMode == PHY_TYPE_11B) ||
2701 (pMgmt->eConfigPHYMode == PHY_TYPE_11G) ||
2702 (pMgmt->eConfigPHYMode == PHY_TYPE_AUTO)) {
2703 ePhyType = PHY_TYPE_11B;
2704 } else {
2705 return;
2706 }
2707 } else {
2708 if ((pMgmt->eConfigPHYMode == PHY_TYPE_11G) ||
2709 (pMgmt->eConfigPHYMode == PHY_TYPE_AUTO)) {
2710 ePhyType = PHY_TYPE_11G;
2711 } else if (pMgmt->eConfigPHYMode == PHY_TYPE_11B) {
2712 ePhyType = PHY_TYPE_11B;
2713 } else {
2714 return;
2715 }
2716 }
2717
2718 if (ePhyType == PHY_TYPE_11A) {
2719 memcpy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesA[0], sizeof(abyCurrSuppRatesA));
2720 pMgmt->abyCurrExtSuppRates[1] = 0;
2721 } else if (ePhyType == PHY_TYPE_11B) {
2722 memcpy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesB[0], sizeof(abyCurrSuppRatesB));
2723 pMgmt->abyCurrExtSuppRates[1] = 0;
2724 } else {
2725 memcpy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesG[0], sizeof(abyCurrSuppRatesG));
2726 memcpy(pMgmt->abyCurrExtSuppRates, &abyCurrExtSuppRatesG[0], sizeof(abyCurrExtSuppRatesG));
2727 }
2728
2729 if (WLAN_GET_CAP_INFO_ESS(pCurr->wCapInfo)) {
2730 CARDbSetBSSID(pMgmt->pAdapter, pCurr->abyBSSID, NL80211_IFTYPE_STATION);
2731 // Add current BSS to Candidate list
2732 // This should only works for WPA2 BSS, and WPA2 BSS check must be done before.
2733 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)
2734 CARDbAdd_PMKID_Candidate(pMgmt->pAdapter, pMgmt->abyCurrBSSID, pCurr->sRSNCapObj.bRSNCapExist, pCurr->sRSNCapObj.wRSNCap);
2735 } else {
2736 CARDbSetBSSID(pMgmt->pAdapter, pCurr->abyBSSID, NL80211_IFTYPE_ADHOC);
2737 }
2738
2739 if (!CARDbSetPhyParameter(pMgmt->pAdapter,
2740 ePhyType,
2741 pCurr->wCapInfo,
2742 pCurr->sERP.byERP,
2743 pMgmt->abyCurrSuppRates,
2744 pMgmt->abyCurrExtSuppRates)) {
2745 pr_debug("<----s_bSynchBSS Set Phy Mode Fail [%d]\n", ePhyType);
2746 return;
2747 }
2748 // set channel and clear NAV
2749 if (!set_channel(pMgmt->pAdapter, pCurr->uChannel)) {
2750 pr_debug("<----s_bSynchBSS Set Channel [%d]\n",
2751 pCurr->uChannel);
2752 return;
2753 }
2754
2755 pMgmt->uCurrChannel = pCurr->uChannel;
2756 pMgmt->eCurrentPHYMode = ePhyType;
2757 pMgmt->byERPContext = pCurr->sERP.byERP;
2758 pr_debug("Sync:Set to channel = [%d]\n", (int)pCurr->uChannel);
2759
2760 *pStatus = CMD_STATUS_SUCCESS;
2761
2762 return;
2763};
2764
2765//mike add: fix NetworkManager 0.7.0 hidden ssid mode in WPA encryption
2766// ,need reset eAuthenMode and eEncryptionStatus
2767static void Encyption_Rebuild(
2768 struct vnt_private *pDevice,
2769 PKnownBSS pCurr
2770)
2771{
2772 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
2773
2774 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) || //networkmanager 0.7.0 does not give the pairwise-key selection,
2775 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) { // so we need re-select it according to real pairwise-key info.
2776 if (pCurr->bWPAValid) { //WPA-PSK
2777 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
2778 if (pCurr->abyPKType[0] == WPA_TKIP) {
2779 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; //TKIP
2780 PRINT_K("Encyption_Rebuild--->ssid reset config to [WPAPSK-TKIP]\n");
2781 } else if (pCurr->abyPKType[0] == WPA_AESCCMP) {
2782 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled; //AES
2783 PRINT_K("Encyption_Rebuild--->ssid reset config to [WPAPSK-AES]\n");
2784 }
2785 } else if (pCurr->bWPA2Valid) { //WPA2-PSK
2786 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
2787 if (pCurr->abyCSSPK[0] == WLAN_11i_CSS_TKIP) {
2788 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; //TKIP
2789 PRINT_K("Encyption_Rebuild--->ssid reset config to [WPA2PSK-TKIP]\n");
2790 } else if (pCurr->abyCSSPK[0] == WLAN_11i_CSS_CCMP) {
2791 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled; //AES
2792 PRINT_K("Encyption_Rebuild--->ssid reset config to [WPA2PSK-AES]\n");
2793 }
2794 }
2795 }
2796}
2797
2798/*+
2799 *
2800 * Routine Description:
2801 * Format TIM field
2802 *
2803 *
2804 * Return Value:
2805 * void
2806 *
2807 -*/
2808
2809static
2810void
2811s_vMgrFormatTIM(
2812 PSMgmtObject pMgmt,
2813 PWLAN_IE_TIM pTIM
2814)
2815{
2816 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2817 unsigned char byMap;
2818 unsigned int ii, jj;
2819 bool bStartFound = false;
2820 bool bMulticast = false;
2821 unsigned short wStartIndex = 0;
2822 unsigned short wEndIndex = 0;
2823
2824 // Find size of partial virtual bitmap
2825 for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
2826 byMap = pMgmt->abyPSTxMap[ii];
2827 if (!ii) {
2828 // Mask out the broadcast bit which is indicated separately.
2829 bMulticast = (byMap & byMask[0]) != 0;
2830 if (bMulticast)
2831 pMgmt->sNodeDBTable[0].bRxPSPoll = true;
2832
2833 byMap = 0;
2834 }
2835 if (byMap) {
2836 if (!bStartFound) {
2837 bStartFound = true;
2838 wStartIndex = ii;
2839 }
2840 wEndIndex = ii;
2841 }
2842 }
2843
2844 // Round start index down to nearest even number
2845 wStartIndex &= ~BIT0;
2846
2847 // Round end index up to nearest even number
2848 wEndIndex = ((wEndIndex + 1) & ~BIT0);
2849
2850 // Size of element payload
2851
2852 pTIM->len = 3 + (wEndIndex - wStartIndex) + 1;
2853
2854 // Fill in the Fixed parts of the TIM
2855 pTIM->byDTIMCount = pMgmt->byDTIMCount;
2856 pTIM->byDTIMPeriod = pMgmt->byDTIMPeriod;
2857 pTIM->byBitMapCtl = (bMulticast ? TIM_MULTICAST_MASK : 0) |
2858 (((wStartIndex >> 1) << 1) & TIM_BITMAPOFFSET_MASK);
2859
2860 // Append variable part of TIM
2861
2862 for (ii = wStartIndex, jj = 0; ii <= wEndIndex; ii++, jj++)
2863 pTIM->byVirtBitMap[jj] = pMgmt->abyPSTxMap[ii];
2864
2865 // Aid = 0 don't used.
2866 pTIM->byVirtBitMap[0] &= ~BIT0;
2867}
2868
2869/*+
2870 *
2871 * Routine Description:
2872 * Constructs an Beacon frame(Ad-hoc mode)
2873 *
2874 *
2875 * Return Value:
2876 * PTR to frame; or NULL on allocation failure
2877 *
2878 -*/
2879
2880static
2881PSTxMgmtPacket
2882s_MgrMakeBeacon(
2883 struct vnt_private *pDevice,
2884 PSMgmtObject pMgmt,
2885 unsigned short wCurrCapInfo,
2886 unsigned short wCurrBeaconPeriod,
2887 unsigned int uCurrChannel,
2888 unsigned short wCurrATIMWinodw,
2889 PWLAN_IE_SSID pCurrSSID,
2890 unsigned char *pCurrBSSID,
2891 PWLAN_IE_SUPP_RATES pCurrSuppRates,
2892 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
2893)
2894{
2895 PSTxMgmtPacket pTxPacket = NULL;
2896 WLAN_FR_BEACON sFrame;
2897 unsigned char abyBroadcastAddr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
2898 unsigned char *pbyBuffer;
2899 unsigned int uLength = 0;
2900 PWLAN_IE_IBSS_DFS pIBSSDFS = NULL;
2901 unsigned int ii;
2902
2903 // prepare beacon frame
2904 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
2905 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_BEACON_FR_MAXLEN);
2906 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
2907 // Setup the sFrame structure.
2908 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
2909 sFrame.len = WLAN_BEACON_FR_MAXLEN;
2910 vMgrEncodeBeacon(&sFrame);
2911 // Setup the header
2912 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
2913 (
2914 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
2915 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_BEACON)
2916));
2917
2918 if (pDevice->bEnablePSMode)
2919 sFrame.pHdr->sA3.wFrameCtl |= cpu_to_le16((unsigned short)WLAN_SET_FC_PWRMGT(1));
2920
2921 memcpy(sFrame.pHdr->sA3.abyAddr1, abyBroadcastAddr, WLAN_ADDR_LEN);
2922 memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
2923 memcpy(sFrame.pHdr->sA3.abyAddr3, pCurrBSSID, WLAN_BSSID_LEN);
2924 *sFrame.pwBeaconInterval = cpu_to_le16(wCurrBeaconPeriod);
2925 *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
2926 // Copy SSID
2927 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
2928 sFrame.len += ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len + WLAN_IEHDR_LEN;
2929 memcpy(sFrame.pSSID,
2930 pCurrSSID,
2931 ((PWLAN_IE_SSID)pCurrSSID)->len + WLAN_IEHDR_LEN
2932);
2933 // Copy the rate set
2934 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
2935 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
2936 memcpy(sFrame.pSuppRates,
2937 pCurrSuppRates,
2938 ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
2939);
2940 // DS parameter
2941 if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
2942 sFrame.pDSParms = (PWLAN_IE_DS_PARMS)(sFrame.pBuf + sFrame.len);
2943 sFrame.len += (1) + WLAN_IEHDR_LEN;
2944 sFrame.pDSParms->byElementID = WLAN_EID_DS_PARMS;
2945 sFrame.pDSParms->len = 1;
2946 sFrame.pDSParms->byCurrChannel = (unsigned char)uCurrChannel;
2947 }
2948 // TIM field
2949 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2950 sFrame.pTIM = (PWLAN_IE_TIM)(sFrame.pBuf + sFrame.len);
2951 sFrame.pTIM->byElementID = WLAN_EID_TIM;
2952 s_vMgrFormatTIM(pMgmt, sFrame.pTIM);
2953 sFrame.len += (WLAN_IEHDR_LEN + sFrame.pTIM->len);
2954 }
2955
2956 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2957 // IBSS parameter
2958 sFrame.pIBSSParms = (PWLAN_IE_IBSS_PARMS)(sFrame.pBuf + sFrame.len);
2959 sFrame.len += (2) + WLAN_IEHDR_LEN;
2960 sFrame.pIBSSParms->byElementID = WLAN_EID_IBSS_PARMS;
2961 sFrame.pIBSSParms->len = 2;
2962 sFrame.pIBSSParms->wATIMWindow = wCurrATIMWinodw;
2963 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
2964 /* RSN parameter */
2965 sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
2966 sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
2967 sFrame.pRSNWPA->len = 12;
2968 sFrame.pRSNWPA->abyOUI[0] = 0x00;
2969 sFrame.pRSNWPA->abyOUI[1] = 0x50;
2970 sFrame.pRSNWPA->abyOUI[2] = 0xf2;
2971 sFrame.pRSNWPA->abyOUI[3] = 0x01;
2972 sFrame.pRSNWPA->wVersion = 1;
2973 sFrame.pRSNWPA->abyMulticast[0] = 0x00;
2974 sFrame.pRSNWPA->abyMulticast[1] = 0x50;
2975 sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
2976 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)
2977 sFrame.pRSNWPA->abyMulticast[3] = 0x04;//AES
2978 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled)
2979 sFrame.pRSNWPA->abyMulticast[3] = 0x02;//TKIP
2980 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled)
2981 sFrame.pRSNWPA->abyMulticast[3] = 0x01;//WEP40
2982 else
2983 sFrame.pRSNWPA->abyMulticast[3] = 0x00;//NONE
2984
2985 // Pairwise Key Cipher Suite
2986 sFrame.pRSNWPA->wPKCount = 0;
2987 // Auth Key Management Suite
2988 *((unsigned short *)(sFrame.pBuf + sFrame.len + sFrame.pRSNWPA->len)) = 0;
2989 sFrame.pRSNWPA->len += 2;
2990
2991 // RSN Capabilities
2992 *((unsigned short *)(sFrame.pBuf + sFrame.len + sFrame.pRSNWPA->len)) = 0;
2993 sFrame.pRSNWPA->len += 2;
2994 sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
2995 }
2996 }
2997
2998 if (pMgmt->b11hEnable && (pMgmt->eCurrentPHYMode == PHY_TYPE_11A)) {
2999 // Country IE
3000 pbyBuffer = (unsigned char *)(sFrame.pBuf + sFrame.len);
3001 set_country_IE(pMgmt->pAdapter, pbyBuffer);
3002 set_country_info(pMgmt->pAdapter, PHY_TYPE_11A, pbyBuffer);
3003 uLength += ((PWLAN_IE_COUNTRY) pbyBuffer)->len + WLAN_IEHDR_LEN;
3004 pbyBuffer += (((PWLAN_IE_COUNTRY) pbyBuffer)->len + WLAN_IEHDR_LEN);
3005 // Power Constrain IE
3006 ((PWLAN_IE_PW_CONST) pbyBuffer)->byElementID = WLAN_EID_PWR_CONSTRAINT;
3007 ((PWLAN_IE_PW_CONST) pbyBuffer)->len = 1;
3008 ((PWLAN_IE_PW_CONST) pbyBuffer)->byPower = 0;
3009 pbyBuffer += (1) + WLAN_IEHDR_LEN;
3010 uLength += (1) + WLAN_IEHDR_LEN;
3011 if (pMgmt->bSwitchChannel) {
3012 // Channel Switch IE
3013 ((PWLAN_IE_CH_SW) pbyBuffer)->byElementID = WLAN_EID_CH_SWITCH;
3014 ((PWLAN_IE_CH_SW) pbyBuffer)->len = 3;
3015 ((PWLAN_IE_CH_SW) pbyBuffer)->byMode = 1;
3016 ((PWLAN_IE_CH_SW) pbyBuffer)->byChannel = get_channel_number(pMgmt->pAdapter, pMgmt->byNewChannel);
3017 ((PWLAN_IE_CH_SW) pbyBuffer)->byCount = 0;
3018 pbyBuffer += (3) + WLAN_IEHDR_LEN;
3019 uLength += (3) + WLAN_IEHDR_LEN;
3020 }
3021 // TPC report
3022 ((PWLAN_IE_TPC_REP) pbyBuffer)->byElementID = WLAN_EID_TPC_REP;
3023 ((PWLAN_IE_TPC_REP) pbyBuffer)->len = 2;
3024 ((PWLAN_IE_TPC_REP) pbyBuffer)->byTxPower = CARDbyGetTransmitPower(pMgmt->pAdapter);
3025 ((PWLAN_IE_TPC_REP) pbyBuffer)->byLinkMargin = 0;
3026 pbyBuffer += (2) + WLAN_IEHDR_LEN;
3027 uLength += (2) + WLAN_IEHDR_LEN;
3028 // IBSS DFS
3029 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) {
3030 pIBSSDFS = (PWLAN_IE_IBSS_DFS) pbyBuffer;
3031 pIBSSDFS->byElementID = WLAN_EID_IBSS_DFS;
3032 pIBSSDFS->len = 7;
3033 memcpy(pIBSSDFS->abyDFSOwner,
3034 pMgmt->abyIBSSDFSOwner,
3035 6);
3036 pIBSSDFS->byDFSRecovery = pMgmt->byIBSSDFSRecovery;
3037 pbyBuffer += (7) + WLAN_IEHDR_LEN;
3038 uLength += (7) + WLAN_IEHDR_LEN;
3039 for (ii = CB_MAX_CHANNEL_24G+1; ii <= CB_MAX_CHANNEL; ii++) {
3040 if (get_channel_map_info(pMgmt->pAdapter, ii, pbyBuffer, pbyBuffer+1)) {
3041 pbyBuffer += 2;
3042 uLength += 2;
3043 pIBSSDFS->len += 2;
3044 }
3045 }
3046 }
3047 sFrame.len += uLength;
3048 }
3049
3050 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
3051 sFrame.pERP = (PWLAN_IE_ERP)(sFrame.pBuf + sFrame.len);
3052 sFrame.len += 1 + WLAN_IEHDR_LEN;
3053 sFrame.pERP->byElementID = WLAN_EID_ERP;
3054 sFrame.pERP->len = 1;
3055 sFrame.pERP->byContext = 0;
3056 if (pDevice->bProtectMode)
3057 sFrame.pERP->byContext |= WLAN_EID_ERP_USE_PROTECTION;
3058 if (pDevice->bNonERPPresent)
3059 sFrame.pERP->byContext |= WLAN_EID_ERP_NONERP_PRESENT;
3060 if (pDevice->bBarkerPreambleMd)
3061 sFrame.pERP->byContext |= WLAN_EID_ERP_BARKER_MODE;
3062 }
3063 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
3064 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3065 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
3066 memcpy(sFrame.pExtSuppRates,
3067 pCurrExtSuppRates,
3068 ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
3069);
3070 }
3071 // hostapd wpa/wpa2 IE
3072 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && pDevice->bEnableHostapd) {
3073 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
3074 if (pMgmt->wWPAIELen != 0) {
3075 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
3076 memcpy(sFrame.pRSN, pMgmt->abyWPAIE, pMgmt->wWPAIELen);
3077 sFrame.len += pMgmt->wWPAIELen;
3078 }
3079 }
3080 }
3081
3082 /* Adjust the length fields */
3083 pTxPacket->cbMPDULen = sFrame.len;
3084 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3085
3086 return pTxPacket;
3087}
3088
3089/*+
3090 *
3091 * Routine Description:
3092 * Constructs an Prob-response frame
3093 *
3094 *
3095 * Return Value:
3096 * PTR to frame; or NULL on allocation failure
3097 *
3098 -*/
3099
3100static PSTxMgmtPacket
3101s_MgrMakeProbeResponse(
3102 struct vnt_private *pDevice,
3103 PSMgmtObject pMgmt,
3104 unsigned short wCurrCapInfo,
3105 unsigned short wCurrBeaconPeriod,
3106 unsigned int uCurrChannel,
3107 unsigned short wCurrATIMWinodw,
3108 unsigned char *pDstAddr,
3109 PWLAN_IE_SSID pCurrSSID,
3110 unsigned char *pCurrBSSID,
3111 PWLAN_IE_SUPP_RATES pCurrSuppRates,
3112 PWLAN_IE_SUPP_RATES pCurrExtSuppRates,
3113 unsigned char byPHYType
3114)
3115{
3116 PSTxMgmtPacket pTxPacket = NULL;
3117 WLAN_FR_PROBERESP sFrame;
3118 unsigned char *pbyBuffer;
3119 unsigned int uLength = 0;
3120 PWLAN_IE_IBSS_DFS pIBSSDFS = NULL;
3121 unsigned int ii;
3122
3123 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
3124 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_PROBERESP_FR_MAXLEN);
3125 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
3126 // Setup the sFrame structure.
3127 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
3128 sFrame.len = WLAN_PROBERESP_FR_MAXLEN;
3129 vMgrEncodeProbeResponse(&sFrame);
3130 // Setup the header
3131 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
3132 (
3133 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3134 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PROBERESP)
3135));
3136 memcpy(sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
3137 memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3138 memcpy(sFrame.pHdr->sA3.abyAddr3, pCurrBSSID, WLAN_BSSID_LEN);
3139 *sFrame.pwBeaconInterval = cpu_to_le16(wCurrBeaconPeriod);
3140 *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
3141
3142 if (byPHYType == BB_TYPE_11B)
3143 *sFrame.pwCapInfo &= cpu_to_le16((unsigned short)~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1)));
3144
3145 // Copy SSID
3146 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
3147 sFrame.len += ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len + WLAN_IEHDR_LEN;
3148 memcpy(sFrame.pSSID,
3149 pCurrSSID,
3150 ((PWLAN_IE_SSID)pCurrSSID)->len + WLAN_IEHDR_LEN
3151);
3152 // Copy the rate set
3153 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3154
3155 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
3156 memcpy(sFrame.pSuppRates,
3157 pCurrSuppRates,
3158 ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
3159);
3160
3161 // DS parameter
3162 if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
3163 sFrame.pDSParms = (PWLAN_IE_DS_PARMS)(sFrame.pBuf + sFrame.len);
3164 sFrame.len += (1) + WLAN_IEHDR_LEN;
3165 sFrame.pDSParms->byElementID = WLAN_EID_DS_PARMS;
3166 sFrame.pDSParms->len = 1;
3167 sFrame.pDSParms->byCurrChannel = (unsigned char)uCurrChannel;
3168 }
3169
3170 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) {
3171 // IBSS parameter
3172 sFrame.pIBSSParms = (PWLAN_IE_IBSS_PARMS)(sFrame.pBuf + sFrame.len);
3173 sFrame.len += (2) + WLAN_IEHDR_LEN;
3174 sFrame.pIBSSParms->byElementID = WLAN_EID_IBSS_PARMS;
3175 sFrame.pIBSSParms->len = 2;
3176 sFrame.pIBSSParms->wATIMWindow = 0;
3177 }
3178 if (pDevice->eCurrentPHYType == PHY_TYPE_11G) {
3179 sFrame.pERP = (PWLAN_IE_ERP)(sFrame.pBuf + sFrame.len);
3180 sFrame.len += 1 + WLAN_IEHDR_LEN;
3181 sFrame.pERP->byElementID = WLAN_EID_ERP;
3182 sFrame.pERP->len = 1;
3183 sFrame.pERP->byContext = 0;
3184 if (pDevice->bProtectMode)
3185 sFrame.pERP->byContext |= WLAN_EID_ERP_USE_PROTECTION;
3186 if (pDevice->bNonERPPresent)
3187 sFrame.pERP->byContext |= WLAN_EID_ERP_NONERP_PRESENT;
3188 if (pDevice->bBarkerPreambleMd)
3189 sFrame.pERP->byContext |= WLAN_EID_ERP_BARKER_MODE;
3190 }
3191
3192 if (pMgmt->b11hEnable && (pMgmt->eCurrentPHYMode == PHY_TYPE_11A)) {
3193 // Country IE
3194 pbyBuffer = (unsigned char *)(sFrame.pBuf + sFrame.len);
3195 set_country_IE(pMgmt->pAdapter, pbyBuffer);
3196 set_country_info(pMgmt->pAdapter, PHY_TYPE_11A, pbyBuffer);
3197 uLength += ((PWLAN_IE_COUNTRY) pbyBuffer)->len + WLAN_IEHDR_LEN;
3198 pbyBuffer += (((PWLAN_IE_COUNTRY) pbyBuffer)->len + WLAN_IEHDR_LEN);
3199 // Power Constrain IE
3200 ((PWLAN_IE_PW_CONST) pbyBuffer)->byElementID = WLAN_EID_PWR_CONSTRAINT;
3201 ((PWLAN_IE_PW_CONST) pbyBuffer)->len = 1;
3202 ((PWLAN_IE_PW_CONST) pbyBuffer)->byPower = 0;
3203 pbyBuffer += (1) + WLAN_IEHDR_LEN;
3204 uLength += (1) + WLAN_IEHDR_LEN;
3205 if (pMgmt->bSwitchChannel) {
3206 // Channel Switch IE
3207 ((PWLAN_IE_CH_SW) pbyBuffer)->byElementID = WLAN_EID_CH_SWITCH;
3208 ((PWLAN_IE_CH_SW) pbyBuffer)->len = 3;
3209 ((PWLAN_IE_CH_SW) pbyBuffer)->byMode = 1;
3210 ((PWLAN_IE_CH_SW) pbyBuffer)->byChannel = get_channel_number(pMgmt->pAdapter, pMgmt->byNewChannel);
3211 ((PWLAN_IE_CH_SW) pbyBuffer)->byCount = 0;
3212 pbyBuffer += (3) + WLAN_IEHDR_LEN;
3213 uLength += (3) + WLAN_IEHDR_LEN;
3214 }
3215 // TPC report
3216 ((PWLAN_IE_TPC_REP) pbyBuffer)->byElementID = WLAN_EID_TPC_REP;
3217 ((PWLAN_IE_TPC_REP) pbyBuffer)->len = 2;
3218 ((PWLAN_IE_TPC_REP) pbyBuffer)->byTxPower = CARDbyGetTransmitPower(pMgmt->pAdapter);
3219 ((PWLAN_IE_TPC_REP) pbyBuffer)->byLinkMargin = 0;
3220 pbyBuffer += (2) + WLAN_IEHDR_LEN;
3221 uLength += (2) + WLAN_IEHDR_LEN;
3222 // IBSS DFS
3223 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) {
3224 pIBSSDFS = (PWLAN_IE_IBSS_DFS) pbyBuffer;
3225 pIBSSDFS->byElementID = WLAN_EID_IBSS_DFS;
3226 pIBSSDFS->len = 7;
3227 memcpy(pIBSSDFS->abyDFSOwner,
3228 pMgmt->abyIBSSDFSOwner,
3229 6);
3230 pIBSSDFS->byDFSRecovery = pMgmt->byIBSSDFSRecovery;
3231 pbyBuffer += (7) + WLAN_IEHDR_LEN;
3232 uLength += (7) + WLAN_IEHDR_LEN;
3233 for (ii = CB_MAX_CHANNEL_24G + 1; ii <= CB_MAX_CHANNEL; ii++) {
3234 if (get_channel_map_info(pMgmt->pAdapter, ii, pbyBuffer, pbyBuffer+1)) {
3235 pbyBuffer += 2;
3236 uLength += 2;
3237 pIBSSDFS->len += 2;
3238 }
3239 }
3240 }
3241 sFrame.len += uLength;
3242 }
3243
3244 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
3245 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3246 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
3247 memcpy(sFrame.pExtSuppRates,
3248 pCurrExtSuppRates,
3249 ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
3250);
3251 }
3252
3253 // hostapd wpa/wpa2 IE
3254 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && pDevice->bEnableHostapd) {
3255 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
3256 if (pMgmt->wWPAIELen != 0) {
3257 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
3258 memcpy(sFrame.pRSN, pMgmt->abyWPAIE, pMgmt->wWPAIELen);
3259 sFrame.len += pMgmt->wWPAIELen;
3260 }
3261 }
3262 }
3263
3264 // Adjust the length fields
3265 pTxPacket->cbMPDULen = sFrame.len;
3266 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3267
3268 return pTxPacket;
3269}
3270
3271/*+
3272 *
3273 * Routine Description:
3274 * Constructs an association request frame
3275 *
3276 *
3277 * Return Value:
3278 * A ptr to frame or NULL on allocation failure
3279 *
3280 -*/
3281
3282static PSTxMgmtPacket
3283s_MgrMakeAssocRequest(
3284 struct vnt_private *pDevice,
3285 PSMgmtObject pMgmt,
3286 unsigned char *pDAddr,
3287 unsigned short wCurrCapInfo,
3288 unsigned short wListenInterval,
3289 PWLAN_IE_SSID pCurrSSID,
3290 PWLAN_IE_SUPP_RATES pCurrRates,
3291 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
3292)
3293{
3294 PSTxMgmtPacket pTxPacket = NULL;
3295 WLAN_FR_ASSOCREQ sFrame;
3296 unsigned char *pbyIEs;
3297 unsigned char *pbyRSN;
3298
3299 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
3300 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_ASSOCREQ_FR_MAXLEN);
3301 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
3302 // Setup the sFrame structure.
3303 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
3304 sFrame.len = WLAN_ASSOCREQ_FR_MAXLEN;
3305 // format fixed field frame structure
3306 vMgrEncodeAssocRequest(&sFrame);
3307 // Setup the header
3308 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
3309 (
3310 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3311 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ASSOCREQ)
3312));
3313 memcpy(sFrame.pHdr->sA3.abyAddr1, pDAddr, WLAN_ADDR_LEN);
3314 memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3315 memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
3316
3317 // Set the capability and listen interval
3318 *(sFrame.pwCapInfo) = cpu_to_le16(wCurrCapInfo);
3319 *(sFrame.pwListenInterval) = cpu_to_le16(wListenInterval);
3320
3321 // sFrame.len point to end of fixed field
3322 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
3323 sFrame.len += pCurrSSID->len + WLAN_IEHDR_LEN;
3324 memcpy(sFrame.pSSID, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
3325
3326 pMgmt->sAssocInfo.AssocInfo.RequestIELength = pCurrSSID->len + WLAN_IEHDR_LEN;
3327 pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
3328 pbyIEs = pMgmt->sAssocInfo.abyIEs;
3329 memcpy(pbyIEs, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
3330 pbyIEs += pCurrSSID->len + WLAN_IEHDR_LEN;
3331
3332 // Copy the rate set
3333 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3334 if ((pDevice->eCurrentPHYType == PHY_TYPE_11B) && (pCurrRates->len > 4))
3335 sFrame.len += 4 + WLAN_IEHDR_LEN;
3336 else
3337 sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
3338 memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
3339
3340 // Copy the extension rate set
3341 if ((pDevice->eCurrentPHYType == PHY_TYPE_11G) && (pCurrExtSuppRates->len > 0)) {
3342 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3343 sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
3344 memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
3345 }
3346
3347 pMgmt->sAssocInfo.AssocInfo.RequestIELength += pCurrRates->len + WLAN_IEHDR_LEN;
3348 memcpy(pbyIEs, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
3349 pbyIEs += pCurrRates->len + WLAN_IEHDR_LEN;
3350
3351 // for 802.11h
3352 if (pMgmt->b11hEnable) {
3353 if (sFrame.pCurrPowerCap == NULL) {
3354 sFrame.pCurrPowerCap = (PWLAN_IE_PW_CAP)(sFrame.pBuf + sFrame.len);
3355 sFrame.len += (2 + WLAN_IEHDR_LEN);
3356 sFrame.pCurrPowerCap->byElementID = WLAN_EID_PWR_CAPABILITY;
3357 sFrame.pCurrPowerCap->len = 2;
3358 CARDvGetPowerCapability(pMgmt->pAdapter,
3359 &(sFrame.pCurrPowerCap->byMinPower),
3360 &(sFrame.pCurrPowerCap->byMaxPower)
3361);
3362 }
3363 if (sFrame.pCurrSuppCh == NULL) {
3364 sFrame.pCurrSuppCh = (PWLAN_IE_SUPP_CH)(sFrame.pBuf + sFrame.len);
3365 sFrame.len += set_support_channels(pMgmt->pAdapter, (unsigned char *)sFrame.pCurrSuppCh);
3366 }
3367 }
3368
3369 if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
3370 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
3371 (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE)) &&
3372 (pMgmt->pCurrBSS != NULL)) {
3373 /* WPA IE */
3374 sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
3375 sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
3376 sFrame.pRSNWPA->len = 16;
3377 sFrame.pRSNWPA->abyOUI[0] = 0x00;
3378 sFrame.pRSNWPA->abyOUI[1] = 0x50;
3379 sFrame.pRSNWPA->abyOUI[2] = 0xf2;
3380 sFrame.pRSNWPA->abyOUI[3] = 0x01;
3381 sFrame.pRSNWPA->wVersion = 1;
3382 //Group Key Cipher Suite
3383 sFrame.pRSNWPA->abyMulticast[0] = 0x00;
3384 sFrame.pRSNWPA->abyMulticast[1] = 0x50;
3385 sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
3386 if (pMgmt->byCSSGK == KEY_CTL_WEP)
3387 sFrame.pRSNWPA->abyMulticast[3] = pMgmt->pCurrBSS->byGKType;
3388 else if (pMgmt->byCSSGK == KEY_CTL_TKIP)
3389 sFrame.pRSNWPA->abyMulticast[3] = WPA_TKIP;
3390 else if (pMgmt->byCSSGK == KEY_CTL_CCMP)
3391 sFrame.pRSNWPA->abyMulticast[3] = WPA_AESCCMP;
3392 else
3393 sFrame.pRSNWPA->abyMulticast[3] = WPA_NONE;
3394
3395 // Pairwise Key Cipher Suite
3396 sFrame.pRSNWPA->wPKCount = 1;
3397 sFrame.pRSNWPA->PKSList[0].abyOUI[0] = 0x00;
3398 sFrame.pRSNWPA->PKSList[0].abyOUI[1] = 0x50;
3399 sFrame.pRSNWPA->PKSList[0].abyOUI[2] = 0xf2;
3400 if (pMgmt->byCSSPK == KEY_CTL_TKIP)
3401 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_TKIP;
3402 else if (pMgmt->byCSSPK == KEY_CTL_CCMP)
3403 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_AESCCMP;
3404 else
3405 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_NONE;
3406
3407 // Auth Key Management Suite
3408 pbyRSN = (unsigned char *)(sFrame.pBuf + sFrame.len + 2 + sFrame.pRSNWPA->len);
3409 *pbyRSN++ = 0x01;
3410 *pbyRSN++ = 0x00;
3411 *pbyRSN++ = 0x00;
3412
3413 *pbyRSN++ = 0x50;
3414 *pbyRSN++ = 0xf2;
3415 if (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)
3416 *pbyRSN++ = WPA_AUTH_PSK;
3417 else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA)
3418 *pbyRSN++ = WPA_AUTH_IEEE802_1X;
3419 else
3420 *pbyRSN++ = WPA_NONE;
3421
3422 sFrame.pRSNWPA->len += 6;
3423
3424 // RSN Capabilities
3425
3426 *pbyRSN++ = 0x00;
3427 *pbyRSN++ = 0x00;
3428 sFrame.pRSNWPA->len += 2;
3429
3430 sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3431 // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
3432 pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3433 memcpy(pbyIEs, sFrame.pRSNWPA, sFrame.pRSNWPA->len + WLAN_IEHDR_LEN);
3434 pbyIEs += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3435
3436 } else if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
3437 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
3438 (pMgmt->pCurrBSS != NULL)) {
3439 unsigned int ii;
3440 unsigned short *pwPMKID;
3441
3442 // WPA IE
3443 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
3444 sFrame.pRSN->byElementID = WLAN_EID_RSN;
3445 sFrame.pRSN->len = 6; //Version(2)+GK(4)
3446 sFrame.pRSN->wVersion = 1;
3447 //Group Key Cipher Suite
3448 sFrame.pRSN->abyRSN[0] = 0x00;
3449 sFrame.pRSN->abyRSN[1] = 0x0F;
3450 sFrame.pRSN->abyRSN[2] = 0xAC;
3451 if (pMgmt->byCSSGK == KEY_CTL_WEP)
3452 sFrame.pRSN->abyRSN[3] = pMgmt->pCurrBSS->byCSSGK;
3453 else if (pMgmt->byCSSGK == KEY_CTL_TKIP)
3454 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_TKIP;
3455 else if (pMgmt->byCSSGK == KEY_CTL_CCMP)
3456 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_CCMP;
3457 else
3458 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_UNKNOWN;
3459
3460 // Pairwise Key Cipher Suite
3461 sFrame.pRSN->abyRSN[4] = 1;
3462 sFrame.pRSN->abyRSN[5] = 0;
3463 sFrame.pRSN->abyRSN[6] = 0x00;
3464 sFrame.pRSN->abyRSN[7] = 0x0F;
3465 sFrame.pRSN->abyRSN[8] = 0xAC;
3466 if (pMgmt->byCSSPK == KEY_CTL_TKIP)
3467 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_TKIP;
3468 else if (pMgmt->byCSSPK == KEY_CTL_CCMP)
3469 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_CCMP;
3470 else if (pMgmt->byCSSPK == KEY_CTL_NONE)
3471 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_USE_GROUP;
3472 else
3473 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_UNKNOWN;
3474
3475 sFrame.pRSN->len += 6;
3476
3477 // Auth Key Management Suite
3478 sFrame.pRSN->abyRSN[10] = 1;
3479 sFrame.pRSN->abyRSN[11] = 0;
3480 sFrame.pRSN->abyRSN[12] = 0x00;
3481 sFrame.pRSN->abyRSN[13] = 0x0F;
3482 sFrame.pRSN->abyRSN[14] = 0xAC;
3483 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)
3484 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_PSK;
3485 else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)
3486 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_802_1X;
3487 else
3488 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_UNKNOWN;
3489
3490 sFrame.pRSN->len += 6;
3491
3492 // RSN Capabilities
3493 if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist) {
3494 memcpy(&sFrame.pRSN->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
3495 } else {
3496 sFrame.pRSN->abyRSN[16] = 0;
3497 sFrame.pRSN->abyRSN[17] = 0;
3498 }
3499 sFrame.pRSN->len += 2;
3500
3501 if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && pDevice->bRoaming && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
3502 // RSN PMKID
3503 pbyRSN = &sFrame.pRSN->abyRSN[18];
3504 pwPMKID = (unsigned short *)pbyRSN; // Point to PMKID count
3505 *pwPMKID = 0; // Initialize PMKID count
3506 pbyRSN += 2; // Point to PMKID list
3507 for (ii = 0; ii < pDevice->gsPMKID.BSSIDInfoCount; ii++) {
3508 if (!memcmp(&pDevice->gsPMKID.BSSIDInfo[ii].BSSID[0], pMgmt->abyCurrBSSID, ETH_ALEN)) {
3509 (*pwPMKID)++;
3510 memcpy(pbyRSN, pDevice->gsPMKID.BSSIDInfo[ii].PMKID, 16);
3511 pbyRSN += 16;
3512 }
3513 }
3514 if (*pwPMKID != 0)
3515 sFrame.pRSN->len += (2 + (*pwPMKID)*16);
3516 }
3517
3518 sFrame.len += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3519 // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
3520 pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3521 memcpy(pbyIEs, sFrame.pRSN, sFrame.pRSN->len + WLAN_IEHDR_LEN);
3522 pbyIEs += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3523 }
3524
3525 // Adjust the length fields
3526 pTxPacket->cbMPDULen = sFrame.len;
3527 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3528 return pTxPacket;
3529}
3530
3531/*+
3532 *
3533 * Routine Description:
3534 * Constructs an re-association request frame
3535 *
3536 *
3537 * Return Value:
3538 * A ptr to frame or NULL on allocation failure
3539 *
3540 -*/
3541
3542static PSTxMgmtPacket
3543s_MgrMakeReAssocRequest(
3544 struct vnt_private *pDevice,
3545 PSMgmtObject pMgmt,
3546 unsigned char *pDAddr,
3547 unsigned short wCurrCapInfo,
3548 unsigned short wListenInterval,
3549 PWLAN_IE_SSID pCurrSSID,
3550 PWLAN_IE_SUPP_RATES pCurrRates,
3551 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
3552)
3553{
3554 PSTxMgmtPacket pTxPacket = NULL;
3555 WLAN_FR_REASSOCREQ sFrame;
3556 unsigned char *pbyIEs;
3557 unsigned char *pbyRSN;
3558
3559 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
3560 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_REASSOCREQ_FR_MAXLEN);
3561 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
3562 /* Setup the sFrame structure. */
3563 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
3564 sFrame.len = WLAN_REASSOCREQ_FR_MAXLEN;
3565
3566 // format fixed field frame structure
3567 vMgrEncodeReassocRequest(&sFrame);
3568
3569 /* Setup the header */
3570 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
3571 (
3572 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3573 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_REASSOCREQ)
3574));
3575 memcpy(sFrame.pHdr->sA3.abyAddr1, pDAddr, WLAN_ADDR_LEN);
3576 memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3577 memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
3578
3579 /* Set the capability and listen interval */
3580 *(sFrame.pwCapInfo) = cpu_to_le16(wCurrCapInfo);
3581 *(sFrame.pwListenInterval) = cpu_to_le16(wListenInterval);
3582
3583 memcpy(sFrame.pAddrCurrAP, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
3584 /* Copy the SSID */
3585 /* sFrame.len point to end of fixed field */
3586 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
3587 sFrame.len += pCurrSSID->len + WLAN_IEHDR_LEN;
3588 memcpy(sFrame.pSSID, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
3589
3590 pMgmt->sAssocInfo.AssocInfo.RequestIELength = pCurrSSID->len + WLAN_IEHDR_LEN;
3591 pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
3592 pbyIEs = pMgmt->sAssocInfo.abyIEs;
3593 memcpy(pbyIEs, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
3594 pbyIEs += pCurrSSID->len + WLAN_IEHDR_LEN;
3595
3596 /* Copy the rate set */
3597 /* sFrame.len point to end of SSID */
3598 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3599 sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
3600 memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
3601
3602 // Copy the extension rate set
3603 if ((pMgmt->eCurrentPHYMode == PHY_TYPE_11G) && (pCurrExtSuppRates->len > 0)) {
3604 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3605 sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
3606 memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
3607 }
3608
3609 pMgmt->sAssocInfo.AssocInfo.RequestIELength += pCurrRates->len + WLAN_IEHDR_LEN;
3610 memcpy(pbyIEs, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
3611 pbyIEs += pCurrRates->len + WLAN_IEHDR_LEN;
3612
3613 if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
3614 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
3615 (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE)) &&
3616 (pMgmt->pCurrBSS != NULL)) {
3617 /* WPA IE */
3618 sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
3619 sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
3620 sFrame.pRSNWPA->len = 16;
3621 sFrame.pRSNWPA->abyOUI[0] = 0x00;
3622 sFrame.pRSNWPA->abyOUI[1] = 0x50;
3623 sFrame.pRSNWPA->abyOUI[2] = 0xf2;
3624 sFrame.pRSNWPA->abyOUI[3] = 0x01;
3625 sFrame.pRSNWPA->wVersion = 1;
3626 //Group Key Cipher Suite
3627 sFrame.pRSNWPA->abyMulticast[0] = 0x00;
3628 sFrame.pRSNWPA->abyMulticast[1] = 0x50;
3629 sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
3630 if (pMgmt->byCSSGK == KEY_CTL_WEP)
3631 sFrame.pRSNWPA->abyMulticast[3] = pMgmt->pCurrBSS->byGKType;
3632 else if (pMgmt->byCSSGK == KEY_CTL_TKIP)
3633 sFrame.pRSNWPA->abyMulticast[3] = WPA_TKIP;
3634 else if (pMgmt->byCSSGK == KEY_CTL_CCMP)
3635 sFrame.pRSNWPA->abyMulticast[3] = WPA_AESCCMP;
3636 else
3637 sFrame.pRSNWPA->abyMulticast[3] = WPA_NONE;
3638
3639 // Pairwise Key Cipher Suite
3640 sFrame.pRSNWPA->wPKCount = 1;
3641 sFrame.pRSNWPA->PKSList[0].abyOUI[0] = 0x00;
3642 sFrame.pRSNWPA->PKSList[0].abyOUI[1] = 0x50;
3643 sFrame.pRSNWPA->PKSList[0].abyOUI[2] = 0xf2;
3644 if (pMgmt->byCSSPK == KEY_CTL_TKIP)
3645 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_TKIP;
3646 else if (pMgmt->byCSSPK == KEY_CTL_CCMP)
3647 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_AESCCMP;
3648 else
3649 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_NONE;
3650
3651 // Auth Key Management Suite
3652 pbyRSN = (unsigned char *)(sFrame.pBuf + sFrame.len + 2 + sFrame.pRSNWPA->len);
3653 *pbyRSN++ = 0x01;
3654 *pbyRSN++ = 0x00;
3655 *pbyRSN++ = 0x00;
3656
3657 *pbyRSN++ = 0x50;
3658 *pbyRSN++ = 0xf2;
3659 if (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)
3660 *pbyRSN++ = WPA_AUTH_PSK;
3661 else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA)
3662 *pbyRSN++ = WPA_AUTH_IEEE802_1X;
3663 else
3664 *pbyRSN++ = WPA_NONE;
3665
3666 sFrame.pRSNWPA->len += 6;
3667
3668 // RSN Capabilities
3669 *pbyRSN++ = 0x00;
3670 *pbyRSN++ = 0x00;
3671 sFrame.pRSNWPA->len += 2;
3672
3673 sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3674 // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
3675 pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3676 memcpy(pbyIEs, sFrame.pRSNWPA, sFrame.pRSNWPA->len + WLAN_IEHDR_LEN);
3677 pbyIEs += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3678
3679 } else if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
3680 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
3681 (pMgmt->pCurrBSS != NULL)) {
3682 unsigned int ii;
3683 unsigned short *pwPMKID;
3684
3685 /* WPA IE */
3686 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
3687 sFrame.pRSN->byElementID = WLAN_EID_RSN;
3688 sFrame.pRSN->len = 6; //Version(2)+GK(4)
3689 sFrame.pRSN->wVersion = 1;
3690 //Group Key Cipher Suite
3691 sFrame.pRSN->abyRSN[0] = 0x00;
3692 sFrame.pRSN->abyRSN[1] = 0x0F;
3693 sFrame.pRSN->abyRSN[2] = 0xAC;
3694 if (pMgmt->byCSSGK == KEY_CTL_WEP)
3695 sFrame.pRSN->abyRSN[3] = pMgmt->pCurrBSS->byCSSGK;
3696 else if (pMgmt->byCSSGK == KEY_CTL_TKIP)
3697 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_TKIP;
3698 else if (pMgmt->byCSSGK == KEY_CTL_CCMP)
3699 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_CCMP;
3700 else
3701 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_UNKNOWN;
3702
3703 // Pairwise Key Cipher Suite
3704 sFrame.pRSN->abyRSN[4] = 1;
3705 sFrame.pRSN->abyRSN[5] = 0;
3706 sFrame.pRSN->abyRSN[6] = 0x00;
3707 sFrame.pRSN->abyRSN[7] = 0x0F;
3708 sFrame.pRSN->abyRSN[8] = 0xAC;
3709 if (pMgmt->byCSSPK == KEY_CTL_TKIP)
3710 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_TKIP;
3711 else if (pMgmt->byCSSPK == KEY_CTL_CCMP)
3712 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_CCMP;
3713 else if (pMgmt->byCSSPK == KEY_CTL_NONE)
3714 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_USE_GROUP;
3715 else
3716 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_UNKNOWN;
3717
3718 sFrame.pRSN->len += 6;
3719
3720 // Auth Key Management Suite
3721 sFrame.pRSN->abyRSN[10] = 1;
3722 sFrame.pRSN->abyRSN[11] = 0;
3723 sFrame.pRSN->abyRSN[12] = 0x00;
3724 sFrame.pRSN->abyRSN[13] = 0x0F;
3725 sFrame.pRSN->abyRSN[14] = 0xAC;
3726 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)
3727 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_PSK;
3728 else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)
3729 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_802_1X;
3730 else
3731 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_UNKNOWN;
3732
3733 sFrame.pRSN->len += 6;
3734
3735 // RSN Capabilities
3736 if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist) {
3737 memcpy(&sFrame.pRSN->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
3738 } else {
3739 sFrame.pRSN->abyRSN[16] = 0;
3740 sFrame.pRSN->abyRSN[17] = 0;
3741 }
3742 sFrame.pRSN->len += 2;
3743
3744 if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && pDevice->bRoaming && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
3745 // RSN PMKID
3746 pbyRSN = &sFrame.pRSN->abyRSN[18];
3747 pwPMKID = (unsigned short *)pbyRSN; // Point to PMKID count
3748 *pwPMKID = 0; // Initialize PMKID count
3749 pbyRSN += 2; // Point to PMKID list
3750 for (ii = 0; ii < pDevice->gsPMKID.BSSIDInfoCount; ii++) {
3751 if (!memcmp(&pDevice->gsPMKID.BSSIDInfo[ii].BSSID[0], pMgmt->abyCurrBSSID, ETH_ALEN)) {
3752 (*pwPMKID)++;
3753 memcpy(pbyRSN, pDevice->gsPMKID.BSSIDInfo[ii].PMKID, 16);
3754 pbyRSN += 16;
3755 }
3756 }
3757
3758 if (*pwPMKID != 0)
3759 sFrame.pRSN->len += (2 + (*pwPMKID) * 16);
3760 }
3761
3762 sFrame.len += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3763 // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
3764 pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3765 memcpy(pbyIEs, sFrame.pRSN, sFrame.pRSN->len + WLAN_IEHDR_LEN);
3766 pbyIEs += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3767 }
3768
3769 /* Adjust the length fields */
3770 pTxPacket->cbMPDULen = sFrame.len;
3771 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3772
3773 return pTxPacket;
3774}
3775
3776/*+
3777 *
3778 * Routine Description:
3779 * Constructs an assoc-response frame
3780 *
3781 *
3782 * Return Value:
3783 * PTR to frame; or NULL on allocation failure
3784 *
3785 -*/
3786
3787static PSTxMgmtPacket
3788s_MgrMakeAssocResponse(
3789 struct vnt_private *pDevice,
3790 PSMgmtObject pMgmt,
3791 unsigned short wCurrCapInfo,
3792 unsigned short wAssocStatus,
3793 unsigned short wAssocAID,
3794 unsigned char *pDstAddr,
3795 PWLAN_IE_SUPP_RATES pCurrSuppRates,
3796 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
3797)
3798{
3799 PSTxMgmtPacket pTxPacket = NULL;
3800 WLAN_FR_ASSOCRESP sFrame;
3801
3802 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
3803 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_ASSOCREQ_FR_MAXLEN);
3804 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
3805 // Setup the sFrame structure
3806 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
3807 sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN;
3808 vMgrEncodeAssocResponse(&sFrame);
3809 // Setup the header
3810 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
3811 (
3812 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3813 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ASSOCRESP)
3814));
3815 memcpy(sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
3816 memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3817 memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
3818
3819 *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
3820 *sFrame.pwStatus = cpu_to_le16(wAssocStatus);
3821 *sFrame.pwAid = cpu_to_le16((unsigned short)(wAssocAID | BIT14 | BIT15));
3822
3823 // Copy the rate set
3824 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3825 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
3826 memcpy(sFrame.pSuppRates,
3827 pCurrSuppRates,
3828 ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
3829);
3830
3831 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
3832 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3833 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
3834 memcpy(sFrame.pExtSuppRates,
3835 pCurrExtSuppRates,
3836 ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
3837);
3838 }
3839
3840 // Adjust the length fields
3841 pTxPacket->cbMPDULen = sFrame.len;
3842 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3843
3844 return pTxPacket;
3845}
3846
3847/*+
3848 *
3849 * Routine Description:
3850 * Constructs an reassoc-response frame
3851 *
3852 *
3853 * Return Value:
3854 * PTR to frame; or NULL on allocation failure
3855 *
3856 -*/
3857
3858static PSTxMgmtPacket
3859s_MgrMakeReAssocResponse(
3860 struct vnt_private *pDevice,
3861 PSMgmtObject pMgmt,
3862 unsigned short wCurrCapInfo,
3863 unsigned short wAssocStatus,
3864 unsigned short wAssocAID,
3865 unsigned char *pDstAddr,
3866 PWLAN_IE_SUPP_RATES pCurrSuppRates,
3867 PWLAN_IE_SUPP_RATES pCurrExtSuppRates
3868)
3869{
3870 PSTxMgmtPacket pTxPacket = NULL;
3871 WLAN_FR_REASSOCRESP sFrame;
3872
3873 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
3874 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_ASSOCREQ_FR_MAXLEN);
3875 pTxPacket->p80211Header = (PUWLAN_80211HDR)((unsigned char *)pTxPacket + sizeof(STxMgmtPacket));
3876 // Setup the sFrame structure
3877 sFrame.pBuf = (unsigned char *)pTxPacket->p80211Header;
3878 sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN;
3879 vMgrEncodeReassocResponse(&sFrame);
3880 // Setup the header
3881 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
3882 (
3883 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3884 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_REASSOCRESP)
3885));
3886 memcpy(sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
3887 memcpy(sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3888 memcpy(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
3889
3890 *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
3891 *sFrame.pwStatus = cpu_to_le16(wAssocStatus);
3892 *sFrame.pwAid = cpu_to_le16((unsigned short)(wAssocAID | BIT14 | BIT15));
3893
3894 // Copy the rate set
3895 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3896 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
3897 memcpy(sFrame.pSuppRates,
3898 pCurrSuppRates,
3899 ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
3900);
3901
3902 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
3903 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3904 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
3905 memcpy(sFrame.pExtSuppRates,
3906 pCurrExtSuppRates,
3907 ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
3908);
3909 }
3910
3911 // Adjust the length fields
3912 pTxPacket->cbMPDULen = sFrame.len;
3913 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3914
3915 return pTxPacket;
3916}
3917
3918/*+
3919 *
3920 * Routine Description:
3921 * Handles probe response management frames.
3922 *
3923 *
3924 * Return Value:
3925 * none.
3926 *
3927 -*/
3928
3929static
3930void
3931s_vMgrRxProbeResponse(
3932 struct vnt_private *pDevice,
3933 PSMgmtObject pMgmt,
3934 PSRxMgmtPacket pRxPacket
3935)
3936{
3937 PKnownBSS pBSSList = NULL;
3938 WLAN_FR_PROBERESP sFrame;
3939 unsigned char byCurrChannel = pRxPacket->byRxChannel;
3940 ERPObject sERP;
3941 unsigned char byIEChannel = 0;
3942 bool bChannelHit = true;
3943
3944 memset(&sFrame, 0, sizeof(WLAN_FR_PROBERESP));
3945 // decode the frame
3946 sFrame.len = pRxPacket->cbMPDULen;
3947 sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
3948 vMgrDecodeProbeResponse(&sFrame);
3949
3950 if ((sFrame.pqwTimestamp == NULL) ||
3951 (sFrame.pwBeaconInterval == NULL) ||
3952 (sFrame.pwCapInfo == NULL) ||
3953 (sFrame.pSSID == NULL) ||
3954 (sFrame.pSuppRates == NULL)) {
3955 pr_debug("Probe resp:Fail addr:[%p]\n",
3956 pRxPacket->p80211Header);
3957 DBG_PORT80(0xCC);
3958 return;
3959 }
3960
3961 if (sFrame.pSSID->len == 0)
3962 pr_debug("Rx Probe resp: SSID len = 0\n");
3963
3964 if (sFrame.pDSParms != NULL) {
3965 if (byCurrChannel > CB_MAX_CHANNEL_24G) {
3966 // channel remapping to
3967 byIEChannel = get_channel_mapping(pMgmt->pAdapter, sFrame.pDSParms->byCurrChannel, PHY_TYPE_11A);
3968 } else {
3969 byIEChannel = sFrame.pDSParms->byCurrChannel;
3970 }
3971 if (byCurrChannel != byIEChannel) {
3972 // adjust channel info. bcs we rcv adjacent channel packets
3973 bChannelHit = false;
3974 byCurrChannel = byIEChannel;
3975 }
3976 } else {
3977 // no DS channel info
3978 bChannelHit = true;
3979 }
3980
3981//2008-0730-01<Add>by MikeLiu
3982 if (ChannelExceedZoneType(pDevice, byCurrChannel))
3983 return;
3984
3985 if (sFrame.pERP != NULL) {
3986 sERP.byERP = sFrame.pERP->byContext;
3987 sERP.bERPExist = true;
3988 } else {
3989 sERP.bERPExist = false;
3990 sERP.byERP = 0;
3991 }
3992
3993 // update or insert the bss
3994 pBSSList = BSSpAddrIsInBSSList((void *)pDevice, sFrame.pHdr->sA3.abyAddr3, sFrame.pSSID);
3995 if (pBSSList) {
3996 BSSbUpdateToBSSList((void *)pDevice,
3997 *sFrame.pqwTimestamp,
3998 *sFrame.pwBeaconInterval,
3999 *sFrame.pwCapInfo,
4000 byCurrChannel,
4001 bChannelHit,
4002 sFrame.pSSID,
4003 sFrame.pSuppRates,
4004 sFrame.pExtSuppRates,
4005 &sERP,
4006 sFrame.pRSN,
4007 sFrame.pRSNWPA,
4008 sFrame.pIE_Country,
4009 sFrame.pIE_Quiet,
4010 pBSSList,
4011 sFrame.len - WLAN_HDR_ADDR3_LEN,
4012 sFrame.pHdr->sA4.abyAddr4, // payload of probresponse
4013 (void *)pRxPacket
4014);
4015 } else {
4016 pr_debug("Probe resp/insert: RxChannel = : %d\n",
4017 byCurrChannel);
4018 BSSbInsertToBSSList((void *)pDevice,
4019 sFrame.pHdr->sA3.abyAddr3,
4020 *sFrame.pqwTimestamp,
4021 *sFrame.pwBeaconInterval,
4022 *sFrame.pwCapInfo,
4023 byCurrChannel,
4024 sFrame.pSSID,
4025 sFrame.pSuppRates,
4026 sFrame.pExtSuppRates,
4027 &sERP,
4028 sFrame.pRSN,
4029 sFrame.pRSNWPA,
4030 sFrame.pIE_Country,
4031 sFrame.pIE_Quiet,
4032 sFrame.len - WLAN_HDR_ADDR3_LEN,
4033 sFrame.pHdr->sA4.abyAddr4, // payload of beacon
4034 (void *)pRxPacket
4035);
4036 }
4037}
4038
4039/*+
4040 *
4041 * Routine Description:(AP)or(Ad-hoc STA)
4042 * Handles probe request management frames.
4043 *
4044 *
4045 * Return Value:
4046 * none.
4047 *
4048 -*/
4049
4050static
4051void
4052s_vMgrRxProbeRequest(
4053 struct vnt_private *pDevice,
4054 PSMgmtObject pMgmt,
4055 PSRxMgmtPacket pRxPacket
4056)
4057{
4058 WLAN_FR_PROBEREQ sFrame;
4059 CMD_STATUS Status;
4060 PSTxMgmtPacket pTxPacket;
4061 unsigned char byPHYType = BB_TYPE_11B;
4062
4063 // STA in Ad-hoc mode: when latest TBTT beacon transmit success,
4064 // STA have to response this request.
4065 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
4066 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && pDevice->bBeaconSent)) {
4067 memset(&sFrame, 0, sizeof(WLAN_FR_PROBEREQ));
4068 // decode the frame
4069 sFrame.len = pRxPacket->cbMPDULen;
4070 sFrame.pBuf = (unsigned char *)pRxPacket->p80211Header;
4071 vMgrDecodeProbeRequest(&sFrame);
4072
4073 if (sFrame.pSSID->len != 0) {
4074 if (sFrame.pSSID->len != ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len)
4075 return;
4076 if (memcmp(sFrame.pSSID->abySSID,
4077 ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,
4078 ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) != 0) {
4079 return;
4080 }
4081 }
4082
4083 if ((sFrame.pSuppRates->len > 4) || (sFrame.pExtSuppRates != NULL))
4084 byPHYType = BB_TYPE_11G;
4085
4086 // Probe response reply..
4087 pTxPacket = s_MgrMakeProbeResponse
4088 (
4089 pDevice,
4090 pMgmt,
4091 pMgmt->wCurrCapInfo,
4092 pMgmt->wCurrBeaconPeriod,
4093 pMgmt->uCurrChannel,
4094 0,
4095 sFrame.pHdr->sA3.abyAddr2,
4096 (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
4097 (unsigned char *)pMgmt->abyCurrBSSID,
4098 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
4099 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
4100 byPHYType
4101);
4102 if (pTxPacket != NULL) {
4103 /* send the frame */
4104 Status = csMgmt_xmit(pDevice, pTxPacket);
4105 if (Status != CMD_STATUS_PENDING)
4106 pr_debug("Mgt:Probe response tx failed\n");
4107 }
4108 }
4109}
4110
4111/*+
4112 *
4113 * Routine Description:
4114 *
4115 * Entry point for the reception and handling of 802.11 management
4116 * frames. Makes a determination of the frame type and then calls
4117 * the appropriate function.
4118 *
4119 *
4120 * Return Value:
4121 * none.
4122 *
4123 -*/
4124
4125void
4126vMgrRxManagePacket(
4127 void *hDeviceContext,
4128 PSMgmtObject pMgmt,
4129 PSRxMgmtPacket pRxPacket
4130)
4131{
4132 struct vnt_private *pDevice = hDeviceContext;
4133 bool bInScan = false;
4134 unsigned int uNodeIndex = 0;
4135 NODE_STATE eNodeState = 0;
4136 CMD_STATUS Status;
4137
4138 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
4139 if (BSSDBbIsSTAInNodeDB(pMgmt, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex))
4140 eNodeState = pMgmt->sNodeDBTable[uNodeIndex].eNodeState;
4141 }
4142
4143 switch (WLAN_GET_FC_FSTYPE((pRxPacket->p80211Header->sA3.wFrameCtl))) {
4144 case WLAN_FSTYPE_ASSOCREQ:
4145 // Frame Clase = 2
4146 pr_debug("rx assocreq\n");
4147 if (eNodeState < NODE_AUTH) {
4148 // send deauth notification
4149 // reason = (6) class 2 received from nonauth sta
4150 vMgrDeAuthenBeginSta(pDevice,
4151 pMgmt,
4152 pRxPacket->p80211Header->sA3.abyAddr2,
4153 (6),
4154 &Status
4155);
4156 pr_debug("wmgr: send vMgrDeAuthenBeginSta 1\n");
4157 } else {
4158 s_vMgrRxAssocRequest(pDevice, pMgmt, pRxPacket, uNodeIndex);
4159 }
4160 break;
4161
4162 case WLAN_FSTYPE_ASSOCRESP:
4163 // Frame Clase = 2
4164 pr_debug("rx assocresp1\n");
4165 s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, false);
4166 pr_debug("rx assocresp2\n");
4167 break;
4168
4169 case WLAN_FSTYPE_REASSOCREQ:
4170 // Frame Clase = 2
4171 pr_debug("rx reassocreq\n");
4172 // Todo: reassoc
4173 if (eNodeState < NODE_AUTH) {
4174 // send deauth notification
4175 // reason = (6) class 2 received from nonauth sta
4176 vMgrDeAuthenBeginSta(pDevice,
4177 pMgmt,
4178 pRxPacket->p80211Header->sA3.abyAddr2,
4179 (6),
4180 &Status
4181);
4182 pr_debug("wmgr: send vMgrDeAuthenBeginSta 2\n");
4183
4184 }
4185 s_vMgrRxReAssocRequest(pDevice, pMgmt, pRxPacket, uNodeIndex);
4186 break;
4187
4188 case WLAN_FSTYPE_REASSOCRESP:
4189 // Frame Clase = 2
4190 pr_debug("rx reassocresp\n");
4191 s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, true);
4192 break;
4193
4194 case WLAN_FSTYPE_PROBEREQ:
4195 // Frame Clase = 0
4196 s_vMgrRxProbeRequest(pDevice, pMgmt, pRxPacket);
4197 break;
4198
4199 case WLAN_FSTYPE_PROBERESP:
4200 // Frame Clase = 0
4201 pr_debug("rx proberesp\n");
4202
4203 s_vMgrRxProbeResponse(pDevice, pMgmt, pRxPacket);
4204 break;
4205
4206 case WLAN_FSTYPE_BEACON:
4207 // Frame Clase = 0
4208 if (pMgmt->eScanState != WMAC_NO_SCANNING)
4209 bInScan = true;
4210
4211 s_vMgrRxBeacon(pDevice, pMgmt, pRxPacket, bInScan);
4212 break;
4213
4214 case WLAN_FSTYPE_ATIM:
4215 // Frame Clase = 1
4216 pr_debug("rx atim\n");
4217 break;
4218
4219 case WLAN_FSTYPE_DISASSOC:
4220 // Frame Clase = 2
4221 pr_debug("rx disassoc\n");
4222 if (eNodeState < NODE_AUTH) {
4223 // send deauth notification
4224 // reason = (6) class 2 received from nonauth sta
4225 vMgrDeAuthenBeginSta(pDevice,
4226 pMgmt,
4227 pRxPacket->p80211Header->sA3.abyAddr2,
4228 (6),
4229 &Status
4230);
4231 pr_debug("wmgr: send vMgrDeAuthenBeginSta 3\n");
4232 }
4233 s_vMgrRxDisassociation(pDevice, pMgmt, pRxPacket);
4234 break;
4235
4236 case WLAN_FSTYPE_AUTHEN:
4237 // Frame Clase = 1
4238 pr_debug("rx authen\n");
4239 s_vMgrRxAuthentication(pDevice, pMgmt, pRxPacket);
4240 break;
4241
4242 case WLAN_FSTYPE_DEAUTHEN:
4243 // Frame Clase = 1
4244 pr_debug("rx deauthen\n");
4245 s_vMgrRxDeauthentication(pDevice, pMgmt, pRxPacket);
4246 break;
4247
4248 default:
4249 pr_debug("rx unknown mgmt\n");
4250 }
4251}
4252
4253/*+
4254 *
4255 * Routine Description:
4256 *
4257 *
4258 * Prepare beacon to send
4259 *
4260 * Return Value:
4261 * true if success; false if failed.
4262 *
4263 -*/
4264bool
4265bMgrPrepareBeaconToSend(
4266 void *hDeviceContext,
4267 PSMgmtObject pMgmt
4268)
4269{
4270 struct vnt_private *pDevice = hDeviceContext;
4271 PSTxMgmtPacket pTxPacket;
4272
4273 if (pDevice->bEncryptionEnable || pDevice->bEnable8021x)
4274 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
4275 else
4276 pMgmt->wCurrCapInfo &= ~WLAN_SET_CAP_INFO_PRIVACY(1);
4277
4278 pTxPacket = s_MgrMakeBeacon
4279 (
4280 pDevice,
4281 pMgmt,
4282 pMgmt->wCurrCapInfo,
4283 pMgmt->wCurrBeaconPeriod,
4284 pMgmt->uCurrChannel,
4285 pMgmt->wCurrATIMWindow,
4286 (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
4287 (unsigned char *)pMgmt->abyCurrBSSID,
4288 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
4289 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
4290);
4291
4292 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
4293 (pMgmt->abyCurrBSSID[0] == 0))
4294 return false;
4295
4296 csBeacon_xmit(pDevice, pTxPacket);
4297
4298 return true;
4299}
4300
4301/*+
4302 *
4303 * Routine Description:
4304 *
4305 * Log a warning message based on the contents of the Status
4306 * Code field of an 802.11 management frame. Defines are
4307 * derived from 802.11-1997 SPEC.
4308 *
4309 * Return Value:
4310 * none.
4311 *
4312 -*/
4313static
4314void
4315s_vMgrLogStatus(
4316 PSMgmtObject pMgmt,
4317 unsigned short wStatus
4318)
4319{
4320 switch (wStatus) {
4321 case WLAN_MGMT_STATUS_UNSPEC_FAILURE:
4322 pr_info("Status code == Unspecified error\n");
4323 break;
4324 case WLAN_MGMT_STATUS_CAPS_UNSUPPORTED:
4325 pr_info("Status code == Can't support all requested capabilities\n");
4326 break;
4327 case WLAN_MGMT_STATUS_REASSOC_NO_ASSOC:
4328 pr_info("Status code == Reassoc denied, can't confirm original Association\n");
4329 break;
4330 case WLAN_MGMT_STATUS_ASSOC_DENIED_UNSPEC:
4331 pr_info("Status code == Assoc denied, undefine in spec\n");
4332 break;
4333 case WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG:
4334 pr_info("Status code == Peer doesn't support authen algorithm\n");
4335 break;
4336 case WLAN_MGMT_STATUS_RX_AUTH_NOSEQ:
4337 pr_info("Status code == Authen frame received out of sequence\n");
4338 break;
4339 case WLAN_MGMT_STATUS_CHALLENGE_FAIL:
4340 pr_info("Status code == Authen rejected, challenge failure\n");
4341 break;
4342 case WLAN_MGMT_STATUS_AUTH_TIMEOUT:
4343 pr_info("Status code == Authen rejected, timeout waiting for next frame\n");
4344 break;
4345 case WLAN_MGMT_STATUS_ASSOC_DENIED_BUSY:
4346 pr_info("Status code == Assoc denied, AP too busy\n");
4347 break;
4348 case WLAN_MGMT_STATUS_ASSOC_DENIED_RATES:
4349 pr_info("Status code == Assoc denied, we haven't enough basic rates\n");
4350 break;
4351 case WLAN_MGMT_STATUS_ASSOC_DENIED_SHORTPREAMBLE:
4352 pr_info("Status code == Assoc denied, we do not support short preamble\n");
4353 break;
4354 case WLAN_MGMT_STATUS_ASSOC_DENIED_PBCC:
4355 pr_info("Status code == Assoc denied, we do not support PBCC\n");
4356 break;
4357 case WLAN_MGMT_STATUS_ASSOC_DENIED_AGILITY:
4358 pr_info("Status code == Assoc denied, we do not support channel agility\n");
4359 break;
4360 default:
4361 pr_info("Unknown status code %d\n", wStatus);
4362 break;
4363 }
4364}
4365
4366/*
4367 *
4368 * Description:
4369 * Add BSSID in PMKID Candidate list.
4370 *
4371 * Parameters:
4372 * In:
4373 * hDeviceContext - device structure point
4374 * pbyBSSID - BSSID address for adding
4375 * wRSNCap - BSS's RSN capability
4376 * Out:
4377 * none
4378 *
4379 * Return Value: none.
4380 *
4381 -*/
4382bool
4383bAdd_PMKID_Candidate(
4384 void *hDeviceContext,
4385 unsigned char *pbyBSSID,
4386 PSRSNCapObject psRSNCapObj
4387)
4388{
4389 struct vnt_private *pDevice = hDeviceContext;
4390 struct pmkid_candidate *pCandidateList;
4391 unsigned int ii = 0;
4392
4393 pr_debug("bAdd_PMKID_Candidate START: (%d)\n",
4394 (int)pDevice->gsPMKIDCandidate.NumCandidates);
4395
4396 if ((pDevice == NULL) || (pbyBSSID == NULL) || (psRSNCapObj == NULL))
4397 return false;
4398
4399 if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST)
4400 return false;
4401
4402 // Update Old Candidate
4403 for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
4404 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
4405 if (!memcmp(pCandidateList->BSSID, pbyBSSID, ETH_ALEN)) {
4406 if (psRSNCapObj->bRSNCapExist && (psRSNCapObj->wRSNCap & BIT0))
4407 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
4408 else
4409 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
4410
4411 return true;
4412 }
4413 }
4414
4415 // New Candidate
4416 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates];
4417 if (psRSNCapObj->bRSNCapExist && (psRSNCapObj->wRSNCap & BIT0))
4418 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
4419 else
4420 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
4421
4422 memcpy(pCandidateList->BSSID, pbyBSSID, ETH_ALEN);
4423 pDevice->gsPMKIDCandidate.NumCandidates++;
4424 pr_debug("NumCandidates:%d\n",
4425 (int)pDevice->gsPMKIDCandidate.NumCandidates);
4426 return true;
4427}
4428
4429/*
4430 *
4431 * Description:
4432 * Flush PMKID Candidate list.
4433 *
4434 * Parameters:
4435 * In:
4436 * hDeviceContext - device structure point
4437 * Out:
4438 * none
4439 *
4440 * Return Value: none.
4441 *
4442 -*/
4443void
4444vFlush_PMKID_Candidate(
4445 void *hDeviceContext
4446)
4447{
4448 struct vnt_private *pDevice = hDeviceContext;
4449
4450 if (pDevice == NULL)
4451 return;
4452
4453 memset(&pDevice->gsPMKIDCandidate, 0, sizeof(SPMKIDCandidateEvent));
4454}
4455
4456static bool
4457s_bCipherMatch(
4458 PKnownBSS pBSSNode,
4459 NDIS_802_11_ENCRYPTION_STATUS EncStatus,
4460 unsigned char *pbyCCSPK,
4461 unsigned char *pbyCCSGK
4462)
4463{
4464 unsigned char byMulticastCipher = KEY_CTL_INVALID;
4465 unsigned char byCipherMask = 0x00;
4466 int i;
4467
4468 if (pBSSNode == NULL)
4469 return false;
4470
4471 // check cap. of BSS
4472 if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
4473 (EncStatus == Ndis802_11Encryption1Enabled)) {
4474 // default is WEP only
4475 byMulticastCipher = KEY_CTL_WEP;
4476 }
4477
4478 if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
4479 pBSSNode->bWPA2Valid &&
4480 //20080123-01,<Add> by Einsn Liu
4481 ((EncStatus == Ndis802_11Encryption3Enabled) || (EncStatus == Ndis802_11Encryption2Enabled))) {
4482 //WPA2
4483 // check Group Key Cipher
4484 if ((pBSSNode->byCSSGK == WLAN_11i_CSS_WEP40) ||
4485 (pBSSNode->byCSSGK == WLAN_11i_CSS_WEP104)) {
4486 byMulticastCipher = KEY_CTL_WEP;
4487 } else if (pBSSNode->byCSSGK == WLAN_11i_CSS_TKIP) {
4488 byMulticastCipher = KEY_CTL_TKIP;
4489 } else if (pBSSNode->byCSSGK == WLAN_11i_CSS_CCMP) {
4490 byMulticastCipher = KEY_CTL_CCMP;
4491 } else {
4492 byMulticastCipher = KEY_CTL_INVALID;
4493 }
4494
4495 // check Pairwise Key Cipher
4496 for (i = 0; i < pBSSNode->wCSSPKCount; i++) {
4497 if ((pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_WEP40) ||
4498 (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_WEP104)) {
4499 // this should not happen as defined 802.11i
4500 byCipherMask |= 0x01;
4501 } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_TKIP) {
4502 byCipherMask |= 0x02;
4503 } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_CCMP) {
4504 byCipherMask |= 0x04;
4505 } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_USE_GROUP) {
4506 // use group key only ignore all others
4507 byCipherMask = 0;
4508 i = pBSSNode->wCSSPKCount;
4509 }
4510 }
4511
4512 } else if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
4513 pBSSNode->bWPAValid &&
4514 ((EncStatus == Ndis802_11Encryption3Enabled) || (EncStatus == Ndis802_11Encryption2Enabled))) {
4515 //WPA
4516 // check Group Key Cipher
4517 if ((pBSSNode->byGKType == WPA_WEP40) ||
4518 (pBSSNode->byGKType == WPA_WEP104)) {
4519 byMulticastCipher = KEY_CTL_WEP;
4520 } else if (pBSSNode->byGKType == WPA_TKIP) {
4521 byMulticastCipher = KEY_CTL_TKIP;
4522 } else if (pBSSNode->byGKType == WPA_AESCCMP) {
4523 byMulticastCipher = KEY_CTL_CCMP;
4524 } else {
4525 byMulticastCipher = KEY_CTL_INVALID;
4526 }
4527
4528 // check Pairwise Key Cipher
4529 for (i = 0; i < pBSSNode->wPKCount; i++) {
4530 if (pBSSNode->abyPKType[i] == WPA_TKIP) {
4531 byCipherMask |= 0x02;
4532 } else if (pBSSNode->abyPKType[i] == WPA_AESCCMP) {
4533 byCipherMask |= 0x04;
4534 } else if (pBSSNode->abyPKType[i] == WPA_NONE) {
4535 // use group key only ignore all others
4536 byCipherMask = 0;
4537 i = pBSSNode->wPKCount;
4538 }
4539 }
4540 }
4541
4542 pr_debug("%d, %d, %d, %d, EncStatus:%d\n",
4543 byMulticastCipher, byCipherMask,
4544 pBSSNode->bWPAValid, pBSSNode->bWPA2Valid, EncStatus);
4545
4546 // mask our cap. with BSS
4547 if (EncStatus == Ndis802_11Encryption1Enabled) {
4548 // For supporting Cisco migration mode, don't care pairwise key cipher
4549 if ((byMulticastCipher == KEY_CTL_WEP) &&
4550 (byCipherMask == 0)) {
4551 *pbyCCSGK = KEY_CTL_WEP;
4552 *pbyCCSPK = KEY_CTL_NONE;
4553 return true;
4554 } else {
4555 return false;
4556 }
4557
4558 } else if (EncStatus == Ndis802_11Encryption2Enabled) {
4559 if ((byMulticastCipher == KEY_CTL_TKIP) &&
4560 (byCipherMask == 0)) {
4561 *pbyCCSGK = KEY_CTL_TKIP;
4562 *pbyCCSPK = KEY_CTL_NONE;
4563 return true;
4564 } else if ((byMulticastCipher == KEY_CTL_WEP) &&
4565 ((byCipherMask & 0x02) != 0)) {
4566 *pbyCCSGK = KEY_CTL_WEP;
4567 *pbyCCSPK = KEY_CTL_TKIP;
4568 return true;
4569 } else if ((byMulticastCipher == KEY_CTL_TKIP) &&
4570 ((byCipherMask & 0x02) != 0)) {
4571 *pbyCCSGK = KEY_CTL_TKIP;
4572 *pbyCCSPK = KEY_CTL_TKIP;
4573 return true;
4574 } else {
4575 return false;
4576 }
4577 } else if (EncStatus == Ndis802_11Encryption3Enabled) {
4578 if ((byMulticastCipher == KEY_CTL_CCMP) &&
4579 (byCipherMask == 0)) {
4580 // When CCMP is enable, "Use group cipher suite" shall not be a valid option.
4581 return false;
4582 } else if ((byMulticastCipher == KEY_CTL_WEP) &&
4583 ((byCipherMask & 0x04) != 0)) {
4584 *pbyCCSGK = KEY_CTL_WEP;
4585 *pbyCCSPK = KEY_CTL_CCMP;
4586 return true;
4587 } else if ((byMulticastCipher == KEY_CTL_TKIP) &&
4588 ((byCipherMask & 0x04) != 0)) {
4589 *pbyCCSGK = KEY_CTL_TKIP;
4590 *pbyCCSPK = KEY_CTL_CCMP;
4591 return true;
4592 } else if ((byMulticastCipher == KEY_CTL_CCMP) &&
4593 ((byCipherMask & 0x04) != 0)) {
4594 *pbyCCSGK = KEY_CTL_CCMP;
4595 *pbyCCSPK = KEY_CTL_CCMP;
4596 return true;
4597 } else {
4598 return false;
4599 }
4600 }
4601 return true;
4602}
diff --git a/drivers/staging/vt6655/wmgr.h b/drivers/staging/vt6655/wmgr.h
deleted file mode 100644
index ce939b30ac2a..000000000000
--- a/drivers/staging/vt6655/wmgr.h
+++ /dev/null
@@ -1,420 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: wmgr.h
21 *
22 * Purpose:
23 *
24 * Author: lyndon chen
25 *
26 * Date: Jan 2, 2003
27 *
28 * Functions:
29 *
30 * Revision History:
31 *
32 */
33
34#ifndef __WMGR_H__
35#define __WMGR_H__
36
37#include "ttype.h"
38#include "80211mgr.h"
39#include "80211hdr.h"
40#include "wcmd.h"
41#include "bssdb.h"
42#include "wpa2.h"
43#include "vntwifi.h"
44#include "card.h"
45
46/*--------------------- Export Definitions -------------------------*/
47
48// Scan time
49#define PROBE_DELAY 100 // (us)
50#define SWITCH_CHANNEL_DELAY 200 // (us)
51#define WLAN_SCAN_MINITIME 25 // (ms)
52#define WLAN_SCAN_MAXTIME 100 // (ms)
53#define TRIVIAL_SYNC_DIFFERENCE 0 // (us)
54#define DEFAULT_IBSS_BI 100 // (ms)
55
56#define WCMD_ACTIVE_SCAN_TIME 50 //(ms)
57#define WCMD_PASSIVE_SCAN_TIME 100 //(ms)
58
59#define DEFAULT_MSDU_LIFETIME 512 // ms
60#define DEFAULT_MSDU_LIFETIME_RES_64us 8000 // 64us
61
62#define DEFAULT_MGN_LIFETIME 8 // ms
63#define DEFAULT_MGN_LIFETIME_RES_64us 125 // 64us
64
65#define MAKE_BEACON_RESERVED 10 //(us)
66
67#define TIM_MULTICAST_MASK 0x01
68#define TIM_BITMAPOFFSET_MASK 0xFE
69#define DEFAULT_DTIM_PERIOD 1
70
71#define AP_LONG_RETRY_LIMIT 4
72
73#define DEFAULT_IBSS_CHANNEL 6 //2.4G
74
75/*--------------------- Export Classes ----------------------------*/
76
77/*--------------------- Export Variables --------------------------*/
78
79/*--------------------- Export Types ------------------------------*/
80#define timer_expire(timer, next_tick) mod_timer(&timer, RUN_AT(next_tick))
81typedef void (*TimerFunction)(unsigned long);
82
83//+++ NDIS related
84
85typedef unsigned char NDIS_802_11_MAC_ADDRESS[6];
86typedef struct _NDIS_802_11_AI_REQFI {
87 unsigned short Capabilities;
88 unsigned short ListenInterval;
89 NDIS_802_11_MAC_ADDRESS CurrentAPAddress;
90} NDIS_802_11_AI_REQFI, *PNDIS_802_11_AI_REQFI;
91
92typedef struct _NDIS_802_11_AI_RESFI {
93 unsigned short Capabilities;
94 unsigned short StatusCode;
95 unsigned short AssociationId;
96} NDIS_802_11_AI_RESFI, *PNDIS_802_11_AI_RESFI;
97
98typedef struct _NDIS_802_11_ASSOCIATION_INFORMATION {
99 unsigned long Length;
100 unsigned short AvailableRequestFixedIEs;
101 NDIS_802_11_AI_REQFI RequestFixedIEs;
102 unsigned long RequestIELength;
103 unsigned long OffsetRequestIEs;
104 unsigned short AvailableResponseFixedIEs;
105 NDIS_802_11_AI_RESFI ResponseFixedIEs;
106 unsigned long ResponseIELength;
107 unsigned long OffsetResponseIEs;
108} NDIS_802_11_ASSOCIATION_INFORMATION, *PNDIS_802_11_ASSOCIATION_INFORMATION;
109
110typedef struct tagSAssocInfo {
111 NDIS_802_11_ASSOCIATION_INFORMATION AssocInfo;
112 unsigned char abyIEs[WLAN_BEACON_FR_MAXLEN+WLAN_BEACON_FR_MAXLEN];
113 // store ReqIEs set by OID_802_11_ASSOCIATION_INFORMATION
114 unsigned long RequestIELength;
115 unsigned char abyReqIEs[WLAN_BEACON_FR_MAXLEN];
116} SAssocInfo, *PSAssocInfo;
117//---
118
119typedef enum tagWMAC_SCAN_TYPE {
120 WMAC_SCAN_ACTIVE,
121 WMAC_SCAN_PASSIVE,
122 WMAC_SCAN_HYBRID
123} WMAC_SCAN_TYPE, *PWMAC_SCAN_TYPE;
124
125typedef enum tagWMAC_SCAN_STATE {
126 WMAC_NO_SCANNING,
127 WMAC_IS_SCANNING,
128 WMAC_IS_PROBEPENDING
129} WMAC_SCAN_STATE, *PWMAC_SCAN_STATE;
130
131// Notes:
132// Basic Service Set state explained as following:
133// WMAC_STATE_IDLE : no BSS is selected (Adhoc or Infra)
134// WMAC_STATE_STARTED : no BSS is selected, start own IBSS (Adhoc only)
135// WMAC_STATE_JOINTED : BSS is selected and synchronized (Adhoc or Infra)
136// WMAC_STATE_AUTHPENDING : Authentication pending (Infra)
137// WMAC_STATE_AUTH : Authenticated (Infra)
138// WMAC_STATE_ASSOCPENDING : Association pending (Infra)
139// WMAC_STATE_ASSOC : Associated (Infra)
140
141typedef enum tagWMAC_BSS_STATE {
142 WMAC_STATE_IDLE,
143 WMAC_STATE_STARTED,
144 WMAC_STATE_JOINTED,
145 WMAC_STATE_AUTHPENDING,
146 WMAC_STATE_AUTH,
147 WMAC_STATE_ASSOCPENDING,
148 WMAC_STATE_ASSOC
149} WMAC_BSS_STATE, *PWMAC_BSS_STATE;
150
151// WMAC selected running mode
152typedef enum tagWMAC_CURRENT_MODE {
153 WMAC_MODE_STANDBY,
154 WMAC_MODE_ESS_STA,
155 WMAC_MODE_IBSS_STA,
156 WMAC_MODE_ESS_AP
157} WMAC_CURRENT_MODE, *PWMAC_CURRENT_MODE;
158
159/*
160 typedef enum tagWMAC_POWER_MODE {
161 WMAC_POWER_CAM,
162 WMAC_POWER_FAST,
163 WMAC_POWER_MAX
164
165 } WMAC_POWER_MODE, *PWMAC_POWER_MODE;
166*/
167
168// Tx Management Packet descriptor
169typedef struct tagSTxMgmtPacket {
170 PUWLAN_80211HDR p80211Header;
171 unsigned int cbMPDULen;
172 unsigned int cbPayloadLen;
173} STxMgmtPacket, *PSTxMgmtPacket;
174
175// Rx Management Packet descriptor
176typedef struct tagSRxMgmtPacket {
177 PUWLAN_80211HDR p80211Header;
178 u64 qwLocalTSF;
179 unsigned int cbMPDULen;
180 unsigned int cbPayloadLen;
181 unsigned int uRSSI;
182 unsigned char bySQ;
183 unsigned char byRxRate;
184 unsigned char byRxChannel;
185} SRxMgmtPacket, *PSRxMgmtPacket;
186
187typedef struct tagSMgmtObject {
188 void *pAdapter;
189 // MAC address
190 unsigned char abyMACAddr[WLAN_ADDR_LEN];
191
192 // Configuration Mode
193 WMAC_CONFIG_MODE eConfigMode; // MAC pre-configed mode
194 CARD_PHY_TYPE eCurrentPHYMode;
195 CARD_PHY_TYPE eConfigPHYMode;
196
197 // Operation state variables
198 WMAC_CURRENT_MODE eCurrMode; // MAC current connection mode
199 WMAC_BSS_STATE eCurrState; // MAC current BSS state
200
201 PKnownBSS pCurrBSS;
202 unsigned char byCSSGK;
203 unsigned char byCSSPK;
204
205 // Current state vars
206 unsigned int uCurrChannel;
207 unsigned char abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
208 unsigned char abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
209 unsigned char abyCurrSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
210 unsigned char abyCurrBSSID[WLAN_BSSID_LEN];
211 unsigned short wCurrCapInfo;
212 unsigned short wCurrAID;
213 unsigned short wCurrATIMWindow;
214 unsigned short wCurrBeaconPeriod;
215 bool bIsDS;
216 unsigned char byERPContext;
217
218 CMD_STATE eCommandState;
219 unsigned int uScanChannel;
220
221 // Desire joining BSS vars
222 unsigned char abyDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
223 unsigned char abyDesireBSSID[WLAN_BSSID_LEN];
224
225 // Adhoc or AP configuration vars
226 unsigned short wIBSSBeaconPeriod;
227 unsigned short wIBSSATIMWindow;
228 unsigned int uIBSSChannel;
229 unsigned char abyIBSSSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
230 unsigned char byAPBBType;
231 unsigned char abyWPAIE[MAX_WPA_IE_LEN];
232 unsigned short wWPAIELen;
233
234 unsigned int uAssocCount;
235 bool bMoreData;
236
237 // Scan state vars
238 WMAC_SCAN_STATE eScanState;
239 WMAC_SCAN_TYPE eScanType;
240 unsigned int uScanStartCh;
241 unsigned int uScanEndCh;
242 unsigned short wScanSteps;
243 unsigned int uScanBSSType;
244 // Desire scanning vars
245 unsigned char abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
246 unsigned char abyScanBSSID[WLAN_BSSID_LEN];
247
248 // Privacy
249 WMAC_AUTHENTICATION_MODE eAuthenMode;
250 WMAC_ENCRYPTION_MODE eEncryptionMode;
251 bool bShareKeyAlgorithm;
252 unsigned char abyChallenge[WLAN_CHALLENGE_LEN];
253 bool bPrivacyInvoked;
254
255 // Received beacon state vars
256 bool bInTIM;
257 bool bMulticastTIM;
258 unsigned char byDTIMCount;
259 unsigned char byDTIMPeriod;
260
261 // Power saving state vars
262 WMAC_POWER_MODE ePSMode;
263 unsigned short wListenInterval;
264 unsigned short wCountToWakeUp;
265 bool bInTIMWake;
266 unsigned char *pbyPSPacketPool;
267 unsigned char byPSPacketPool[sizeof(STxMgmtPacket) + WLAN_NULLDATA_FR_MAXLEN];
268 bool bRxBeaconInTBTTWake;
269 unsigned char abyPSTxMap[MAX_NODE_NUM + 1];
270
271 // management command related
272 unsigned int uCmdBusy;
273 unsigned int uCmdHostAPBusy;
274
275 // management packet pool
276 unsigned char *pbyMgmtPacketPool;
277 unsigned char byMgmtPacketPool[sizeof(STxMgmtPacket) + WLAN_A3FR_MAXLEN];
278
279 // One second callback timer
280 struct timer_list sTimerSecondCallback;
281
282 // Temporarily Rx Mgmt Packet Descriptor
283 SRxMgmtPacket sRxPacket;
284
285 // link list of known bss's (scan results)
286 KnownBSS sBSSList[MAX_BSS_NUM];
287
288 // table list of known node
289 // sNodeDBList[0] is reserved for AP under Infra mode
290 // sNodeDBList[0] is reserved for Multicast under adhoc/AP mode
291 KnownNodeDB sNodeDBTable[MAX_NODE_NUM + 1];
292
293 // WPA2 PMKID Cache
294 SPMKIDCache gsPMKIDCache;
295 bool bRoaming;
296
297 // rate fall back vars
298
299 // associate info
300 SAssocInfo sAssocInfo;
301
302 // for 802.11h
303 bool b11hEnable;
304 bool bSwitchChannel;
305 unsigned char byNewChannel;
306 PWLAN_IE_MEASURE_REP pCurrMeasureEIDRep;
307 unsigned int uLengthOfRepEIDs;
308 unsigned char abyCurrentMSRReq[sizeof(STxMgmtPacket) + WLAN_A3FR_MAXLEN];
309 unsigned char abyCurrentMSRRep[sizeof(STxMgmtPacket) + WLAN_A3FR_MAXLEN];
310 unsigned char abyIECountry[WLAN_A3FR_MAXLEN];
311 unsigned char abyIBSSDFSOwner[6];
312 unsigned char byIBSSDFSRecovery;
313
314 struct sk_buff skb;
315} SMgmtObject, *PSMgmtObject;
316
317/*--------------------- Export Macros ------------------------------*/
318
319/*--------------------- Export Functions --------------------------*/
320
321void
322vMgrObjectInit(
323 void *hDeviceContext
324);
325
326void
327vMgrTimerInit(
328 void *hDeviceContext
329);
330
331void
332vMgrObjectReset(
333 void *hDeviceContext
334);
335
336void
337vMgrAssocBeginSta(
338 void *hDeviceContext,
339 PSMgmtObject pMgmt,
340 PCMD_STATUS pStatus
341);
342
343void
344vMgrReAssocBeginSta(
345 void *hDeviceContext,
346 PSMgmtObject pMgmt,
347 PCMD_STATUS pStatus
348);
349
350void
351vMgrDisassocBeginSta(
352 void *hDeviceContext,
353 PSMgmtObject pMgmt,
354 unsigned char *abyDestAddress,
355 unsigned short wReason,
356 PCMD_STATUS pStatus
357);
358
359void
360vMgrAuthenBeginSta(
361 void *hDeviceContext,
362 PSMgmtObject pMgmt,
363 PCMD_STATUS pStatus
364);
365
366void
367vMgrCreateOwnIBSS(
368 void *hDeviceContext,
369 PCMD_STATUS pStatus
370);
371
372void
373vMgrJoinBSSBegin(
374 void *hDeviceContext,
375 PCMD_STATUS pStatus
376);
377
378void
379vMgrRxManagePacket(
380 void *hDeviceContext,
381 PSMgmtObject pMgmt,
382 PSRxMgmtPacket pRxPacket
383);
384
385/*
386 void
387 vMgrScanBegin(
388 void *hDeviceContext,
389 PCMD_STATUS pStatus
390);
391*/
392
393void
394vMgrDeAuthenBeginSta(
395 void *hDeviceContext,
396 PSMgmtObject pMgmt,
397 unsigned char *abyDestAddress,
398 unsigned short wReason,
399 PCMD_STATUS pStatus
400);
401
402bool
403bMgrPrepareBeaconToSend(
404 void *hDeviceContext,
405 PSMgmtObject pMgmt
406);
407
408bool
409bAdd_PMKID_Candidate(
410 void *hDeviceContext,
411 unsigned char *pbyBSSID,
412 PSRSNCapObject psRSNCapObj
413);
414
415void
416vFlush_PMKID_Candidate(
417 void *hDeviceContext
418);
419
420#endif // __WMGR_H__
diff --git a/drivers/staging/vt6655/wpa.c b/drivers/staging/vt6655/wpa.c
deleted file mode 100644
index 5d4eca8512af..000000000000
--- a/drivers/staging/vt6655/wpa.c
+++ /dev/null
@@ -1,300 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: wpa.c
21 *
22 * Purpose: Handles the Basic Service Set & Node Database functions
23 *
24 * Functions:
25 * WPA_ParseRSN - Parse RSN IE.
26 *
27 * Revision History:
28 *
29 * Author: Kyle Hsu
30 *
31 * Date: July 14, 2003
32 *
33 */
34
35#include "ttype.h"
36#include "tmacro.h"
37#include "tether.h"
38#include "device.h"
39#include "80211hdr.h"
40#include "bssdb.h"
41#include "wmgr.h"
42#include "wpa.h"
43#include "80211mgr.h"
44
45/*--------------------- Static Variables --------------------------*/
46static const unsigned char abyOUI00[4] = { 0x00, 0x50, 0xf2, 0x00 };
47static const unsigned char abyOUI01[4] = { 0x00, 0x50, 0xf2, 0x01 };
48static const unsigned char abyOUI02[4] = { 0x00, 0x50, 0xf2, 0x02 };
49static const unsigned char abyOUI03[4] = { 0x00, 0x50, 0xf2, 0x03 };
50static const unsigned char abyOUI04[4] = { 0x00, 0x50, 0xf2, 0x04 };
51static const unsigned char abyOUI05[4] = { 0x00, 0x50, 0xf2, 0x05 };
52
53/*+
54 *
55 * Description:
56 * Clear RSN information in BSSList.
57 *
58 * Parameters:
59 * In:
60 * pBSSList - BSS list.
61 * Out:
62 * none
63 *
64 * Return Value: none.
65 *
66 -*/
67
68void
69WPA_ClearRSN(
70 PKnownBSS pBSSList
71)
72{
73 int ii;
74
75 pBSSList->byGKType = WPA_TKIP;
76 for (ii = 0; ii < 4; ii++)
77 pBSSList->abyPKType[ii] = WPA_TKIP;
78 pBSSList->wPKCount = 0;
79 for (ii = 0; ii < 4; ii++)
80 pBSSList->abyAuthType[ii] = WPA_AUTH_IEEE802_1X;
81 pBSSList->wAuthCount = 0;
82 pBSSList->byDefaultK_as_PK = 0;
83 pBSSList->byReplayIdx = 0;
84 pBSSList->sRSNCapObj.bRSNCapExist = false;
85 pBSSList->sRSNCapObj.wRSNCap = 0;
86 pBSSList->bWPAValid = false;
87}
88
89/*+
90 *
91 * Description:
92 * Parse RSN IE.
93 *
94 * Parameters:
95 * In:
96 * pBSSList - BSS list.
97 * pRSN - Pointer to the RSN IE.
98 * Out:
99 * none
100 *
101 * Return Value: none.
102 *
103 -*/
104void
105WPA_ParseRSN(
106 PKnownBSS pBSSList,
107 PWLAN_IE_RSN_EXT pRSN
108)
109{
110 PWLAN_IE_RSN_AUTH pIE_RSN_Auth = NULL;
111 int i, j, m, n = 0;
112 unsigned char *pbyCaps;
113
114 WPA_ClearRSN(pBSSList);
115
116 pr_debug("WPA_ParseRSN: [%d]\n", pRSN->len);
117
118 // information element header makes sense
119 if ((pRSN->len >= 6) // oui1(4)+ver(2)
120 && (pRSN->byElementID == WLAN_EID_RSN_WPA) && !memcmp(pRSN->abyOUI, abyOUI01, 4)
121 && (pRSN->wVersion == 1)) {
122 pr_debug("Legal RSN\n");
123 // update each variable if pRSN is long enough to contain the variable
124 if (pRSN->len >= 10) {
125 //OUI1(4)+ver(2)+GKSuite(4)
126 if (!memcmp(pRSN->abyMulticast, abyOUI01, 4))
127 pBSSList->byGKType = WPA_WEP40;
128 else if (!memcmp(pRSN->abyMulticast, abyOUI02, 4))
129 pBSSList->byGKType = WPA_TKIP;
130 else if (!memcmp(pRSN->abyMulticast, abyOUI03, 4))
131 pBSSList->byGKType = WPA_AESWRAP;
132 else if (!memcmp(pRSN->abyMulticast, abyOUI04, 4))
133 pBSSList->byGKType = WPA_AESCCMP;
134 else if (!memcmp(pRSN->abyMulticast, abyOUI05, 4))
135 pBSSList->byGKType = WPA_WEP104;
136 else
137 // any vendor checks here
138 pBSSList->byGKType = WPA_NONE;
139
140 pr_debug("byGKType: %x\n", pBSSList->byGKType);
141 }
142
143 if (pRSN->len >= 12) {
144 //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)
145 j = 0;
146 pr_debug("wPKCount: %d, sizeof(pBSSList->abyPKType): %zu\n",
147 pRSN->wPKCount, sizeof(pBSSList->abyPKType));
148 for (i = 0; (i < pRSN->wPKCount) && (j < ARRAY_SIZE(pBSSList->abyPKType)); i++) {
149 if (pRSN->len >= 12+i*4+4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*i)
150 if (!memcmp(pRSN->PKSList[i].abyOUI, abyOUI00, 4))
151 pBSSList->abyPKType[j++] = WPA_NONE;
152 else if (!memcmp(pRSN->PKSList[i].abyOUI, abyOUI02, 4))
153 pBSSList->abyPKType[j++] = WPA_TKIP;
154 else if (!memcmp(pRSN->PKSList[i].abyOUI, abyOUI03, 4))
155 pBSSList->abyPKType[j++] = WPA_AESWRAP;
156 else if (!memcmp(pRSN->PKSList[i].abyOUI, abyOUI04, 4))
157 pBSSList->abyPKType[j++] = WPA_AESCCMP;
158 else
159 // any vendor checks here
160 ;
161 } else
162 break;
163 }
164 pBSSList->wPKCount = (unsigned short)j;
165 pr_debug("wPKCount: %d\n", pBSSList->wPKCount);
166 }
167
168 m = pRSN->wPKCount;
169 pr_debug("m: %d\n", m);
170 pr_debug("14+m*4: %d\n", 14+m*4);
171
172 if (pRSN->len >= 14+m*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)
173 // overlay IE_RSN_Auth structure into correct place
174 pIE_RSN_Auth = (PWLAN_IE_RSN_AUTH) pRSN->PKSList[m].abyOUI;
175 j = 0;
176 pr_debug("wAuthCount: %d, sizeof(pBSSList->abyAuthType): %zu\n",
177 pIE_RSN_Auth->wAuthCount,
178 sizeof(pBSSList->abyAuthType));
179 for (i = 0; (i < pIE_RSN_Auth->wAuthCount) && (j < ARRAY_SIZE(pBSSList->abyAuthType)); i++) {
180 if (pRSN->len >= 14+4+(m+i)*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)+AKS(4*i)
181 if (!memcmp(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI01, 4))
182 pBSSList->abyAuthType[j++] = WPA_AUTH_IEEE802_1X;
183 else if (!memcmp(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI02, 4))
184 pBSSList->abyAuthType[j++] = WPA_AUTH_PSK;
185 else
186 // any vendor checks here
187 ;
188 } else
189 break;
190
191 }
192 if (j > 0)
193 pBSSList->wAuthCount = (unsigned short)j;
194 pr_debug("wAuthCount: %d\n", pBSSList->wAuthCount);
195 }
196
197 if (pIE_RSN_Auth != NULL) {
198 n = pIE_RSN_Auth->wAuthCount;
199
200 pr_debug("n: %d\n", n);
201 pr_debug("14+4+(m+n)*4: %d\n", 14+4+(m+n)*4);
202
203 if (pRSN->len+2 >= 14+4+(m+n)*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)+AKS(4*n)+Cap(2)
204 pbyCaps = (unsigned char *)pIE_RSN_Auth->AuthKSList[n].abyOUI;
205 pBSSList->byDefaultK_as_PK = (*pbyCaps) & WPA_GROUPFLAG;
206 pBSSList->byReplayIdx = 2 << ((*pbyCaps >> WPA_REPLAYBITSSHIFT) & WPA_REPLAYBITS);
207 pBSSList->sRSNCapObj.bRSNCapExist = true;
208 pBSSList->sRSNCapObj.wRSNCap = *(unsigned short *)pbyCaps;
209 }
210 }
211 pBSSList->bWPAValid = true;
212 }
213}
214
215/*+
216 *
217 * Description:
218 * Search RSN information in BSSList.
219 *
220 * Parameters:
221 * In:
222 * byCmd - Search type
223 * byEncrypt- Encrypt Type
224 * pBSSList - BSS list
225 * Out:
226 * none
227 *
228 * Return Value: none.
229 *
230 -*/
231bool
232WPA_SearchRSN(
233 unsigned char byCmd,
234 unsigned char byEncrypt,
235 PKnownBSS pBSSList
236)
237{
238 int ii;
239 unsigned char byPKType = WPA_NONE;
240
241 if (!pBSSList->bWPAValid)
242 return false;
243
244 switch (byCmd) {
245 case 0:
246
247 if (byEncrypt != pBSSList->byGKType)
248 return false;
249
250 if (pBSSList->wPKCount > 0) {
251 for (ii = 0; ii < pBSSList->wPKCount; ii++) {
252 if (pBSSList->abyPKType[ii] == WPA_AESCCMP)
253 byPKType = WPA_AESCCMP;
254 else if ((pBSSList->abyPKType[ii] == WPA_TKIP) && (byPKType != WPA_AESCCMP))
255 byPKType = WPA_TKIP;
256 else if ((pBSSList->abyPKType[ii] == WPA_WEP40) && (byPKType != WPA_AESCCMP) && (byPKType != WPA_TKIP))
257 byPKType = WPA_WEP40;
258 else if ((pBSSList->abyPKType[ii] == WPA_WEP104) && (byPKType != WPA_AESCCMP) && (byPKType != WPA_TKIP))
259 byPKType = WPA_WEP104;
260 }
261 if (byEncrypt != byPKType)
262 return false;
263 }
264 return true;
265
266 default:
267 break;
268 }
269 return false;
270}
271
272/*+
273 *
274 * Description:
275 * Check if RSN IE makes sense.
276 *
277 * Parameters:
278 * In:
279 * pRSN - Pointer to the RSN IE.
280 * Out:
281 * none
282 *
283 * Return Value: none.
284 *
285 -*/
286bool
287WPAb_Is_RSN(
288 PWLAN_IE_RSN_EXT pRSN
289)
290{
291 if (pRSN == NULL)
292 return false;
293
294 if ((pRSN->len >= 6) && // oui1(4)+ver(2)
295 (pRSN->byElementID == WLAN_EID_RSN_WPA) && !memcmp(pRSN->abyOUI, abyOUI01, 4) &&
296 (pRSN->wVersion == 1)) {
297 return true;
298 } else
299 return false;
300}
diff --git a/drivers/staging/vt6655/wpa.h b/drivers/staging/vt6655/wpa.h
deleted file mode 100644
index 1d1918a12641..000000000000
--- a/drivers/staging/vt6655/wpa.h
+++ /dev/null
@@ -1,83 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: wpa.h
21 *
22 * Purpose: Defines the macros, types, and functions for dealing
23 * with WPA informations.
24 *
25 * Author: Kyle Hsu
26 *
27 * Date: Jul 14, 2003
28 *
29 */
30
31#ifndef __WPA_H__
32#define __WPA_H__
33
34#include "ttype.h"
35#include "80211hdr.h"
36
37/*--------------------- Export Definitions -------------------------*/
38
39#define WPA_NONE 0
40#define WPA_WEP40 1
41#define WPA_TKIP 2
42#define WPA_AESWRAP 3
43#define WPA_AESCCMP 4
44#define WPA_WEP104 5
45#define WPA_AUTH_IEEE802_1X 1
46#define WPA_AUTH_PSK 2
47
48#define WPA_GROUPFLAG 0x02
49#define WPA_REPLAYBITSSHIFT 2
50#define WPA_REPLAYBITS 0x03
51
52/*--------------------- Export Classes ----------------------------*/
53
54/*--------------------- Export Variables --------------------------*/
55
56/*--------------------- Export Types ------------------------------*/
57
58/*--------------------- Export Functions --------------------------*/
59
60void
61WPA_ClearRSN(
62 PKnownBSS pBSSList
63);
64
65void
66WPA_ParseRSN(
67 PKnownBSS pBSSList,
68 PWLAN_IE_RSN_EXT pRSN
69);
70
71bool
72WPA_SearchRSN(
73 unsigned char byCmd,
74 unsigned char byEncrypt,
75 PKnownBSS pBSSList
76);
77
78bool
79WPAb_Is_RSN(
80 PWLAN_IE_RSN_EXT pRSN
81);
82
83#endif // __WPA_H__
diff --git a/drivers/staging/vt6655/wpa2.c b/drivers/staging/vt6655/wpa2.c
deleted file mode 100644
index bb335ef51172..000000000000
--- a/drivers/staging/vt6655/wpa2.c
+++ /dev/null
@@ -1,359 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: wpa2.c
21 *
22 * Purpose: Handles the Basic Service Set & Node Database functions
23 *
24 * Functions:
25 *
26 * Revision History:
27 *
28 * Author: Yiching Chen
29 *
30 * Date: Oct. 4, 2004
31 *
32 */
33
34#include "wpa2.h"
35#include "device.h"
36#include "wmgr.h"
37
38/*--------------------- Static Classes ----------------------------*/
39
40/*--------------------- Static Variables --------------------------*/
41
42static const unsigned char abyOUIGK[4] = { 0x00, 0x0F, 0xAC, 0x00 };
43static const unsigned char abyOUIWEP40[4] = { 0x00, 0x0F, 0xAC, 0x01 };
44static const unsigned char abyOUIWEP104[4] = { 0x00, 0x0F, 0xAC, 0x05 };
45static const unsigned char abyOUITKIP[4] = { 0x00, 0x0F, 0xAC, 0x02 };
46static const unsigned char abyOUICCMP[4] = { 0x00, 0x0F, 0xAC, 0x04 };
47
48static const unsigned char abyOUI8021X[4] = { 0x00, 0x0F, 0xAC, 0x01 };
49static const unsigned char abyOUIPSK[4] = { 0x00, 0x0F, 0xAC, 0x02 };
50
51/*--------------------- Static Functions --------------------------*/
52
53/*--------------------- Export Variables --------------------------*/
54
55/*--------------------- Export Functions --------------------------*/
56
57/*+
58 *
59 * Description:
60 * Clear RSN information in BSSList.
61 *
62 * Parameters:
63 * In:
64 * pBSSNode - BSS list.
65 * Out:
66 * none
67 *
68 * Return Value: none.
69 *
70 -*/
71void
72WPA2_ClearRSN(
73 PKnownBSS pBSSNode
74)
75{
76 int ii;
77
78 pBSSNode->bWPA2Valid = false;
79
80 pBSSNode->byCSSGK = WLAN_11i_CSS_CCMP;
81 for (ii = 0; ii < 4; ii++)
82 pBSSNode->abyCSSPK[ii] = WLAN_11i_CSS_CCMP;
83 pBSSNode->wCSSPKCount = 1;
84 for (ii = 0; ii < 4; ii++)
85 pBSSNode->abyAKMSSAuthType[ii] = WLAN_11i_AKMSS_802_1X;
86 pBSSNode->wAKMSSAuthCount = 1;
87 pBSSNode->sRSNCapObj.bRSNCapExist = false;
88 pBSSNode->sRSNCapObj.wRSNCap = 0;
89}
90
91/*+
92 *
93 * Description:
94 * Parse RSN IE.
95 *
96 * Parameters:
97 * In:
98 * pBSSNode - BSS list.
99 * pRSN - Pointer to the RSN IE.
100 * Out:
101 * none
102 *
103 * Return Value: none.
104 *
105 -*/
106void
107WPA2vParseRSN(
108 PKnownBSS pBSSNode,
109 PWLAN_IE_RSN pRSN
110)
111{
112 int i, j;
113 unsigned short m = 0, n = 0;
114 unsigned char *pbyOUI;
115 bool bUseGK = false;
116
117 pr_debug("WPA2_ParseRSN: [%d]\n", pRSN->len);
118
119 WPA2_ClearRSN(pBSSNode);
120
121 if (pRSN->len == 2) { // ver(2)
122 if ((pRSN->byElementID == WLAN_EID_RSN) && (pRSN->wVersion == 1))
123 pBSSNode->bWPA2Valid = true;
124
125 return;
126 }
127
128 if (pRSN->len < 6) { // ver(2) + GK(4)
129 // invalid CSS, P802.11i/D10.0, p31
130 return;
131 }
132
133 // information element header makes sense
134 if ((pRSN->byElementID == WLAN_EID_RSN) &&
135 (pRSN->wVersion == 1)) {
136 pr_debug("Legal 802.11i RSN\n");
137
138 pbyOUI = &(pRSN->abyRSN[0]);
139 if (!memcmp(pbyOUI, abyOUIWEP40, 4))
140 pBSSNode->byCSSGK = WLAN_11i_CSS_WEP40;
141 else if (!memcmp(pbyOUI, abyOUITKIP, 4))
142 pBSSNode->byCSSGK = WLAN_11i_CSS_TKIP;
143 else if (!memcmp(pbyOUI, abyOUICCMP, 4))
144 pBSSNode->byCSSGK = WLAN_11i_CSS_CCMP;
145 else if (!memcmp(pbyOUI, abyOUIWEP104, 4))
146 pBSSNode->byCSSGK = WLAN_11i_CSS_WEP104;
147 else if (!memcmp(pbyOUI, abyOUIGK, 4)) {
148 // invalid CSS, P802.11i/D10.0, p32
149 return;
150 } else
151 // any vendor checks here
152 pBSSNode->byCSSGK = WLAN_11i_CSS_UNKNOWN;
153
154 pr_debug("802.11i CSS: %X\n", pBSSNode->byCSSGK);
155
156 if (pRSN->len == 6) {
157 pBSSNode->bWPA2Valid = true;
158 return;
159 }
160
161 if (pRSN->len >= 8) { // ver(2) + GK(4) + PK count(2)
162 pBSSNode->wCSSPKCount = *((unsigned short *)&(pRSN->abyRSN[4]));
163 j = 0;
164 pbyOUI = &(pRSN->abyRSN[6]);
165
166 for (i = 0; (i < pBSSNode->wCSSPKCount) && (j < sizeof(pBSSNode->abyCSSPK)/sizeof(unsigned char)); i++) {
167 if (pRSN->len >= 8+i*4+4) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*i)
168 if (!memcmp(pbyOUI, abyOUIGK, 4)) {
169 pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_USE_GROUP;
170 bUseGK = true;
171 } else if (!memcmp(pbyOUI, abyOUIWEP40, 4)) {
172 // Invalid CSS, continue to parsing
173 } else if (!memcmp(pbyOUI, abyOUITKIP, 4)) {
174 if (pBSSNode->byCSSGK != WLAN_11i_CSS_CCMP)
175 pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_TKIP;
176 else
177 ; // Invalid CSS, continue to parsing
178 } else if (!memcmp(pbyOUI, abyOUICCMP, 4)) {
179 pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_CCMP;
180 } else if (!memcmp(pbyOUI, abyOUIWEP104, 4)) {
181 // Invalid CSS, continue to parsing
182 } else {
183 // any vendor checks here
184 pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_UNKNOWN;
185 }
186 pbyOUI += 4;
187 pr_debug("abyCSSPK[%d]: %X\n",
188 j-1, pBSSNode->abyCSSPK[j-1]);
189 } else
190 break;
191 } //for
192
193 if (bUseGK) {
194 if (j != 1) {
195 // invalid CSS, This should be only PK CSS.
196 return;
197 }
198 if (pBSSNode->byCSSGK == WLAN_11i_CSS_CCMP) {
199 // invalid CSS, If CCMP is enable , PK can't be CSSGK.
200 return;
201 }
202 }
203 if ((pBSSNode->wCSSPKCount != 0) && (j == 0)) {
204 // invalid CSS, No valid PK.
205 return;
206 }
207 pBSSNode->wCSSPKCount = (unsigned short)j;
208 pr_debug("wCSSPKCount: %d\n", pBSSNode->wCSSPKCount);
209 }
210
211 m = *((unsigned short *)&(pRSN->abyRSN[4]));
212
213 if (pRSN->len >= 10+m*4) { // ver(2) + GK(4) + PK count(2) + PKS(4*m) + AKMSS count(2)
214 pBSSNode->wAKMSSAuthCount = *((unsigned short *)&(pRSN->abyRSN[6+4*m]));
215 j = 0;
216 pbyOUI = &(pRSN->abyRSN[8+4*m]);
217 for (i = 0; (i < pBSSNode->wAKMSSAuthCount) && (j < sizeof(pBSSNode->abyAKMSSAuthType)/sizeof(unsigned char)); i++) {
218 if (pRSN->len >= 10+(m+i)*4+4) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*m)+AKMSS(2)+AKS(4*i)
219 if (!memcmp(pbyOUI, abyOUI8021X, 4))
220 pBSSNode->abyAKMSSAuthType[j++] = WLAN_11i_AKMSS_802_1X;
221 else if (!memcmp(pbyOUI, abyOUIPSK, 4))
222 pBSSNode->abyAKMSSAuthType[j++] = WLAN_11i_AKMSS_PSK;
223 else
224 // any vendor checks here
225 pBSSNode->abyAKMSSAuthType[j++] = WLAN_11i_AKMSS_UNKNOWN;
226 pr_debug("abyAKMSSAuthType[%d]: %X\n",
227 j-1,
228 pBSSNode->abyAKMSSAuthType[j-1]);
229 } else
230 break;
231 }
232 pBSSNode->wAKMSSAuthCount = (unsigned short)j;
233 pr_debug("wAKMSSAuthCount: %d\n",
234 pBSSNode->wAKMSSAuthCount);
235
236 n = *((unsigned short *)&(pRSN->abyRSN[6+4*m]));
237 if (pRSN->len >= 12 + 4 * m + 4 * n) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*m)+AKMSSCnt(2)+AKMSS(4*n)+Cap(2)
238 pBSSNode->sRSNCapObj.bRSNCapExist = true;
239 pBSSNode->sRSNCapObj.wRSNCap = *((unsigned short *)&(pRSN->abyRSN[8+4*m+4*n]));
240 }
241 }
242 //ignore PMKID lists bcs only (Re)Assocrequest has this field
243 pBSSNode->bWPA2Valid = true;
244 }
245}
246
247/*+
248 *
249 * Description:
250 * Set WPA IEs
251 *
252 * Parameters:
253 * In:
254 * pMgmtHandle - Pointer to management object
255 * Out:
256 * pRSNIEs - Pointer to the RSN IE to set.
257 *
258 * Return Value: length of IEs.
259 *
260 -*/
261unsigned int
262WPA2uSetIEs(
263 void *pMgmtHandle,
264 PWLAN_IE_RSN pRSNIEs
265)
266{
267 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtHandle;
268 unsigned char *pbyBuffer = NULL;
269 unsigned int ii = 0;
270 unsigned short *pwPMKID = NULL;
271
272 if (pRSNIEs == NULL)
273 return 0;
274
275 if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
276 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
277 (pMgmt->pCurrBSS != NULL)) {
278 /* WPA2 IE */
279 pbyBuffer = (unsigned char *)pRSNIEs;
280 pRSNIEs->byElementID = WLAN_EID_RSN;
281 pRSNIEs->len = 6; //Version(2)+GK(4)
282 pRSNIEs->wVersion = 1;
283 //Group Key Cipher Suite
284 pRSNIEs->abyRSN[0] = 0x00;
285 pRSNIEs->abyRSN[1] = 0x0F;
286 pRSNIEs->abyRSN[2] = 0xAC;
287 if (pMgmt->byCSSGK == KEY_CTL_WEP)
288 pRSNIEs->abyRSN[3] = pMgmt->pCurrBSS->byCSSGK;
289 else if (pMgmt->byCSSGK == KEY_CTL_TKIP)
290 pRSNIEs->abyRSN[3] = WLAN_11i_CSS_TKIP;
291 else if (pMgmt->byCSSGK == KEY_CTL_CCMP)
292 pRSNIEs->abyRSN[3] = WLAN_11i_CSS_CCMP;
293 else
294 pRSNIEs->abyRSN[3] = WLAN_11i_CSS_UNKNOWN;
295
296 // Pairwise Key Cipher Suite
297 pRSNIEs->abyRSN[4] = 1;
298 pRSNIEs->abyRSN[5] = 0;
299 pRSNIEs->abyRSN[6] = 0x00;
300 pRSNIEs->abyRSN[7] = 0x0F;
301 pRSNIEs->abyRSN[8] = 0xAC;
302 if (pMgmt->byCSSPK == KEY_CTL_TKIP)
303 pRSNIEs->abyRSN[9] = WLAN_11i_CSS_TKIP;
304 else if (pMgmt->byCSSPK == KEY_CTL_CCMP)
305 pRSNIEs->abyRSN[9] = WLAN_11i_CSS_CCMP;
306 else if (pMgmt->byCSSPK == KEY_CTL_NONE)
307 pRSNIEs->abyRSN[9] = WLAN_11i_CSS_USE_GROUP;
308 else
309 pRSNIEs->abyRSN[9] = WLAN_11i_CSS_UNKNOWN;
310
311 pRSNIEs->len += 6;
312
313 // Auth Key Management Suite
314 pRSNIEs->abyRSN[10] = 1;
315 pRSNIEs->abyRSN[11] = 0;
316 pRSNIEs->abyRSN[12] = 0x00;
317 pRSNIEs->abyRSN[13] = 0x0F;
318 pRSNIEs->abyRSN[14] = 0xAC;
319 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)
320 pRSNIEs->abyRSN[15] = WLAN_11i_AKMSS_PSK;
321 else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)
322 pRSNIEs->abyRSN[15] = WLAN_11i_AKMSS_802_1X;
323 else
324 pRSNIEs->abyRSN[15] = WLAN_11i_AKMSS_UNKNOWN;
325
326 pRSNIEs->len += 6;
327
328 // RSN Capabilities
329 if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == true) {
330 memcpy(&pRSNIEs->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
331 } else {
332 pRSNIEs->abyRSN[16] = 0;
333 pRSNIEs->abyRSN[17] = 0;
334 }
335 pRSNIEs->len += 2;
336
337 if ((pMgmt->gsPMKIDCache.BSSIDInfoCount > 0) &&
338 pMgmt->bRoaming &&
339 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
340 // RSN PMKID
341 pwPMKID = (unsigned short *)(&pRSNIEs->abyRSN[18]); // Point to PMKID count
342 *pwPMKID = 0; // Initialize PMKID count
343 pbyBuffer = &pRSNIEs->abyRSN[20]; // Point to PMKID list
344 for (ii = 0; ii < pMgmt->gsPMKIDCache.BSSIDInfoCount; ii++) {
345 if (!memcmp(&pMgmt->gsPMKIDCache.BSSIDInfo[ii].abyBSSID[0], pMgmt->abyCurrBSSID, ETH_ALEN)) {
346 (*pwPMKID)++;
347 memcpy(pbyBuffer, pMgmt->gsPMKIDCache.BSSIDInfo[ii].abyPMKID, 16);
348 pbyBuffer += 16;
349 }
350 }
351 if (*pwPMKID != 0)
352 pRSNIEs->len += (2 + (*pwPMKID)*16);
353 else
354 pbyBuffer = &pRSNIEs->abyRSN[18];
355 }
356 return pRSNIEs->len + WLAN_IEHDR_LEN;
357 }
358 return 0;
359}
diff --git a/drivers/staging/vt6655/wpa2.h b/drivers/staging/vt6655/wpa2.h
deleted file mode 100644
index 2d0bd2e515f3..000000000000
--- a/drivers/staging/vt6655/wpa2.h
+++ /dev/null
@@ -1,77 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: wpa2.h
21 *
22 * Purpose: Defines the macros, types, and functions for dealing
23 * with WPA2 informations.
24 *
25 * Author: Yiching Chen
26 *
27 * Date: Oct. 4, 2004
28 *
29 */
30
31#ifndef __WPA2_H__
32#define __WPA2_H__
33
34#include "ttype.h"
35#include "80211mgr.h"
36#include "80211hdr.h"
37#include "bssdb.h"
38
39/*--------------------- Export Definitions -------------------------*/
40#define MAX_PMKID_CACHE 16
41
42typedef struct tagsPMKIDInfo {
43 unsigned char abyBSSID[6];
44 unsigned char abyPMKID[16];
45} PMKIDInfo, *PPMKIDInfo;
46
47typedef struct tagSPMKIDCache {
48 unsigned long BSSIDInfoCount;
49 PMKIDInfo BSSIDInfo[MAX_PMKID_CACHE];
50} SPMKIDCache, *PSPMKIDCache;
51
52/*--------------------- Export Classes ----------------------------*/
53
54/*--------------------- Export Variables --------------------------*/
55
56/*--------------------- Export Types ------------------------------*/
57
58/*--------------------- Export Functions --------------------------*/
59
60void
61WPA2_ClearRSN(
62 PKnownBSS pBSSNode
63);
64
65void
66WPA2vParseRSN(
67 PKnownBSS pBSSNode,
68 PWLAN_IE_RSN pRSN
69);
70
71unsigned int
72WPA2uSetIEs(
73 void *pMgmtHandle,
74 PWLAN_IE_RSN pRSNIEs
75);
76
77#endif // __WPA2_H__
diff --git a/drivers/staging/vt6655/wpactl.c b/drivers/staging/vt6655/wpactl.c
deleted file mode 100644
index dab1e8078652..000000000000
--- a/drivers/staging/vt6655/wpactl.c
+++ /dev/null
@@ -1,896 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: wpactl.c
21 *
22 * Purpose: handle wpa supplicant ioctl input/out functions
23 *
24 * Author: Lyndon Chen
25 *
26 * Date: Oct. 20, 2003
27 *
28 * Functions:
29 *
30 * Revision History:
31 *
32 */
33
34#include "wpactl.h"
35#include "key.h"
36#include "mac.h"
37#include "device.h"
38#include "wmgr.h"
39#include "iocmd.h"
40#include "iowpa.h"
41#include "rf.h"
42
43/*--------------------- Static Definitions -------------------------*/
44
45#define VIAWGET_WPA_MAX_BUF_SIZE 1024
46
47static const int frequency_list[] = {
48 2412, 2417, 2422, 2427, 2432, 2437, 2442,
49 2447, 2452, 2457, 2462, 2467, 2472, 2484
50};
51/*--------------------- Static Classes ----------------------------*/
52
53/*--------------------- Static Functions --------------------------*/
54
55/*--------------------- Export Variables --------------------------*/
56static void wpadev_setup(struct net_device *dev)
57{
58 dev->type = ARPHRD_IEEE80211;
59 dev->hard_header_len = ETH_HLEN;
60 dev->mtu = 2048;
61 dev->addr_len = ETH_ALEN;
62 dev->tx_queue_len = 1000;
63
64 memset(dev->broadcast, 0xFF, ETH_ALEN);
65
66 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
67}
68
69/*
70 * Description:
71 * register netdev for wpa supplicant daemon
72 *
73 * Parameters:
74 * In:
75 * pDevice -
76 * enable -
77 * Out:
78 *
79 * Return Value:
80 *
81 */
82
83static int wpa_init_wpadev(struct vnt_private *pDevice)
84{
85 struct vnt_private *wpadev_priv;
86 struct net_device *dev = pDevice->dev;
87 int ret = 0;
88
89 pDevice->wpadev = alloc_netdev(sizeof(*wpadev_priv), "vntwpa",
90 NET_NAME_UNKNOWN, wpadev_setup);
91 if (pDevice->wpadev == NULL)
92 return -ENOMEM;
93
94 wpadev_priv = netdev_priv(pDevice->wpadev);
95 *wpadev_priv = *pDevice;
96 eth_hw_addr_inherit(pDevice->wpadev, dev);
97 pDevice->wpadev->base_addr = dev->base_addr;
98 pDevice->wpadev->irq = dev->irq;
99 pDevice->wpadev->mem_start = dev->mem_start;
100 pDevice->wpadev->mem_end = dev->mem_end;
101 ret = register_netdev(pDevice->wpadev);
102 if (ret) {
103 pr_debug("%s: register_netdev(WPA) failed!\n", dev->name);
104 free_netdev(pDevice->wpadev);
105 return -1;
106 }
107
108 if (pDevice->skb == NULL) {
109 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
110 if (pDevice->skb == NULL)
111 return -ENOMEM;
112 }
113
114 pr_debug("%s: Registered netdev %s for WPA management\n",
115 dev->name, pDevice->wpadev->name);
116
117 return 0;
118}
119
120/*
121 * Description:
122 * unregister net_device (wpadev)
123 *
124 * Parameters:
125 * In:
126 * pDevice -
127 * Out:
128 *
129 * Return Value:
130 *
131 */
132
133static int wpa_release_wpadev(struct vnt_private *pDevice)
134{
135 if (pDevice->skb) {
136 dev_kfree_skb(pDevice->skb);
137 pDevice->skb = NULL;
138 }
139
140 if (pDevice->wpadev) {
141 pr_debug("%s: Netdevice %s unregistered\n",
142 pDevice->dev->name, pDevice->wpadev->name);
143 unregister_netdev(pDevice->wpadev);
144 free_netdev(pDevice->wpadev);
145 pDevice->wpadev = NULL;
146 }
147
148 return 0;
149}
150
151/*
152 * Description:
153 * Set enable/disable dev for wpa supplicant daemon
154 *
155 * Parameters:
156 * In:
157 * pDevice -
158 * val -
159 * Out:
160 *
161 * Return Value:
162 *
163 */
164
165int wpa_set_wpadev(struct vnt_private *pDevice, int val)
166{
167 if (val)
168 return wpa_init_wpadev(pDevice);
169 else
170 return wpa_release_wpadev(pDevice);
171}
172
173/*
174 * Description:
175 * Set WPA algorithm & keys
176 *
177 * Parameters:
178 * In:
179 * pDevice -
180 * param -
181 * Out:
182 *
183 * Return Value:
184 *
185 */
186
187int wpa_set_keys(struct vnt_private *pDevice, void *ctx,
188 bool fcpfkernel) __must_hold(&pDevice->lock)
189{
190 struct viawget_wpa_param *param = ctx;
191 PSMgmtObject pMgmt = pDevice->pMgmt;
192 unsigned long dwKeyIndex = 0;
193 unsigned char abyKey[MAX_KEY_LEN];
194 unsigned char abySeq[MAX_KEY_LEN];
195 u64 KeyRSC;
196 unsigned char byKeyDecMode = KEY_CTL_WEP;
197 int ret = 0;
198 int uu, ii;
199
200 if (param->u.wpa_key.alg_name > WPA_ALG_CCMP ||
201 param->u.wpa_key.key_len > MAX_KEY_LEN ||
202 param->u.wpa_key.seq_len > MAX_KEY_LEN)
203 return -EINVAL;
204
205 pr_debug("param->u.wpa_key.alg_name = %d\n", param->u.wpa_key.alg_name);
206 if (param->u.wpa_key.alg_name == WPA_ALG_NONE) {
207 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
208 pDevice->bEncryptionEnable = false;
209 pDevice->byKeyIndex = 0;
210 pDevice->bTransmitKey = false;
211 KeyvRemoveAllWEPKey(&(pDevice->sKey), pDevice->PortOffset);
212 for (uu = 0; uu < MAX_KEY_TABLE; uu++)
213 MACvDisableKeyEntry(pDevice->PortOffset, uu);
214
215 return ret;
216 }
217
218 if (param->u.wpa_key.key && fcpfkernel) {
219 memcpy(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len);
220 } else {
221 spin_unlock_irq(&pDevice->lock);
222 if (param->u.wpa_key.key &&
223 copy_from_user(&abyKey[0],
224 (void __user *)param->u.wpa_key.key,
225 param->u.wpa_key.key_len)) {
226 spin_lock_irq(&pDevice->lock);
227 return -EINVAL;
228 }
229 spin_lock_irq(&pDevice->lock);
230 }
231
232 dwKeyIndex = (unsigned long)(param->u.wpa_key.key_index);
233
234 if (param->u.wpa_key.alg_name == WPA_ALG_WEP) {
235 if (dwKeyIndex > 3) {
236 return -EINVAL;
237 } else {
238 if (param->u.wpa_key.set_tx) {
239 pDevice->byKeyIndex = (unsigned char)dwKeyIndex;
240 pDevice->bTransmitKey = true;
241 dwKeyIndex |= (1 << 31);
242 }
243 KeybSetDefaultKey(&(pDevice->sKey),
244 dwKeyIndex & ~(BIT30 | USE_KEYRSC),
245 param->u.wpa_key.key_len,
246 NULL,
247 abyKey,
248 KEY_CTL_WEP,
249 pDevice->PortOffset,
250 pDevice->byLocalID);
251
252 }
253 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
254 pDevice->bEncryptionEnable = true;
255 return ret;
256 }
257
258 if (param->u.wpa_key.seq && fcpfkernel) {
259 memcpy(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len);
260 } else {
261 spin_unlock_irq(&pDevice->lock);
262 if (param->u.wpa_key.seq &&
263 copy_from_user(&abySeq[0],
264 (void __user *)param->u.wpa_key.seq,
265 param->u.wpa_key.seq_len)) {
266 spin_lock_irq(&pDevice->lock);
267 return -EINVAL;
268 }
269 spin_lock_irq(&pDevice->lock);
270 }
271
272 if (param->u.wpa_key.seq_len > 0) {
273 for (ii = 0; ii < param->u.wpa_key.seq_len; ii++) {
274 if (ii < 4)
275 KeyRSC |= (u64)(abySeq[ii] << (ii * 8));
276 else
277 KeyRSC |= (u64)(abySeq[ii] << ((ii-4) * 8));
278 }
279 dwKeyIndex |= 1 << 29;
280 }
281
282 if (param->u.wpa_key.key_index >= MAX_GROUP_KEY) {
283 pr_debug("return dwKeyIndex > 3\n");
284 return -EINVAL;
285 }
286
287 if (param->u.wpa_key.alg_name == WPA_ALG_TKIP)
288 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
289
290 if (param->u.wpa_key.alg_name == WPA_ALG_CCMP)
291 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
292
293 if (param->u.wpa_key.set_tx)
294 dwKeyIndex |= (1 << 31);
295
296 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)
297 byKeyDecMode = KEY_CTL_CCMP;
298 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled)
299 byKeyDecMode = KEY_CTL_TKIP;
300 else
301 byKeyDecMode = KEY_CTL_WEP;
302
303 /* Fix HCT test that set 256 bits KEY and Ndis802_11Encryption3Enabled */
304 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
305 if (param->u.wpa_key.key_len == MAX_KEY_LEN)
306 byKeyDecMode = KEY_CTL_TKIP;
307 else if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
308 byKeyDecMode = KEY_CTL_WEP;
309 else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
310 byKeyDecMode = KEY_CTL_WEP;
311 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
312 if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
313 byKeyDecMode = KEY_CTL_WEP;
314 else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
315 byKeyDecMode = KEY_CTL_WEP;
316 }
317
318 /* Check TKIP key length */
319 if ((byKeyDecMode == KEY_CTL_TKIP) &&
320 (param->u.wpa_key.key_len != MAX_KEY_LEN)) {
321 /* TKIP Key must be 256 bits */
322 pr_debug("return- TKIP Key must be 256 bits!\n");
323 return -EINVAL;
324 }
325 /* Check AES key length */
326 if ((byKeyDecMode == KEY_CTL_CCMP) &&
327 (param->u.wpa_key.key_len != AES_KEY_LEN)) {
328 /* AES Key must be 128 bits */
329 return -EINVAL;
330 }
331
332 /* spin_lock_irq(&pDevice->lock); */
333 if (is_broadcast_ether_addr(&param->addr[0]) || (param->addr == NULL)) {
334 /* If is_broadcast_ether_addr, set the key as every key entry's group key. */
335 pr_debug("Groupe Key Assign\n");
336
337 if (KeybSetAllGroupKey(&(pDevice->sKey),
338 dwKeyIndex,
339 param->u.wpa_key.key_len,
340 (u64 *) &KeyRSC,
341 (unsigned char *)abyKey,
342 byKeyDecMode,
343 pDevice->PortOffset,
344 pDevice->byLocalID) &&
345 KeybSetDefaultKey(&(pDevice->sKey),
346 dwKeyIndex,
347 param->u.wpa_key.key_len,
348 (u64 *) &KeyRSC,
349 (unsigned char *)abyKey,
350 byKeyDecMode,
351 pDevice->PortOffset,
352 pDevice->byLocalID)) {
353 pr_debug("GROUP Key Assign\n");
354
355 } else {
356 return -EINVAL;
357 }
358
359 } else {
360 pr_debug("Pairwise Key Assign\n");
361 /* BSSID not 0xffffffffffff */
362 /* Pairwise Key can't be WEP */
363 if (byKeyDecMode == KEY_CTL_WEP) {
364 pr_debug("Pairwise Key can't be WEP\n");
365 return -EINVAL;
366 }
367
368 dwKeyIndex |= (1 << 30); /* set pairwise key */
369 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA)
370 return -EINVAL;
371
372 if (KeybSetKey(&(pDevice->sKey),
373 &param->addr[0],
374 dwKeyIndex,
375 param->u.wpa_key.key_len,
376 (u64 *) &KeyRSC,
377 (unsigned char *)abyKey,
378 byKeyDecMode,
379 pDevice->PortOffset,
380 pDevice->byLocalID)) {
381 pr_debug("Pairwise Key Set\n");
382
383 } else {
384 /* Key Table Full */
385 return -EINVAL;
386 }
387 } /* BSSID not 0xffffffffffff */
388 if ((ret == 0) && ((param->u.wpa_key.set_tx) != 0)) {
389 pDevice->byKeyIndex = (unsigned char)param->u.wpa_key.key_index;
390 pDevice->bTransmitKey = true;
391 }
392 pDevice->bEncryptionEnable = true;
393
394 return ret;
395}
396
397/*
398 * Description:
399 * enable wpa auth & mode
400 *
401 * Parameters:
402 * In:
403 * pDevice -
404 * param -
405 * Out:
406 *
407 * Return Value:
408 *
409 */
410
411static int wpa_set_wpa(struct vnt_private *pDevice,
412 struct viawget_wpa_param *param)
413{
414 PSMgmtObject pMgmt = pDevice->pMgmt;
415
416 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
417 pMgmt->bShareKeyAlgorithm = false;
418
419 return 0;
420}
421
422/*
423 * Description:
424 * set disassociate
425 *
426 * Parameters:
427 * In:
428 * pDevice -
429 * param -
430 * Out:
431 *
432 * Return Value:
433 *
434 */
435
436static int wpa_set_disassociate(struct vnt_private *pDevice,
437 struct viawget_wpa_param *param)
438{
439 PSMgmtObject pMgmt = pDevice->pMgmt;
440
441 spin_lock_irq(&pDevice->lock);
442 if (pDevice->bLinkPass) {
443 if (!memcmp(param->addr, pMgmt->abyCurrBSSID, 6))
444 bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
445 }
446 spin_unlock_irq(&pDevice->lock);
447
448 return 0;
449}
450
451/*
452 * Description:
453 * enable scan process
454 *
455 * Parameters:
456 * In:
457 * pDevice -
458 * param -
459 * Out:
460 *
461 * Return Value:
462 *
463 */
464
465static int wpa_set_scan(struct vnt_private *pDevice,
466 struct viawget_wpa_param *param)
467{
468 spin_lock_irq(&pDevice->lock);
469 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
470 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
471 spin_unlock_irq(&pDevice->lock);
472
473 return 0;
474}
475
476/*
477 * Description:
478 * get bssid
479 *
480 * Parameters:
481 * In:
482 * pDevice -
483 * param -
484 * Out:
485 *
486 * Return Value:
487 *
488 */
489
490static int wpa_get_bssid(struct vnt_private *pDevice,
491 struct viawget_wpa_param *param)
492{
493 PSMgmtObject pMgmt = pDevice->pMgmt;
494
495 memcpy(param->u.wpa_associate.bssid, pMgmt->abyCurrBSSID , 6);
496
497 return 0;
498}
499
500/*
501 * Description:
502 * get bssid
503 *
504 * Parameters:
505 * In:
506 * pDevice -
507 * param -
508 * Out:
509 *
510 * Return Value:
511 *
512 */
513
514static int wpa_get_ssid(struct vnt_private *pDevice,
515 struct viawget_wpa_param *param)
516{
517 PSMgmtObject pMgmt = pDevice->pMgmt;
518 PWLAN_IE_SSID pItemSSID;
519
520 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
521
522 memcpy(param->u.wpa_associate.ssid, pItemSSID->abySSID , pItemSSID->len);
523 param->u.wpa_associate.ssid_len = pItemSSID->len;
524
525 return 0;
526}
527
528/*
529 * Description:
530 * get scan results
531 *
532 * Parameters:
533 * In:
534 * pDevice -
535 * param -
536 * Out:
537 *
538 * Return Value:
539 *
540 */
541
542static int wpa_get_scan(struct vnt_private *pDevice,
543 struct viawget_wpa_param *param)
544{
545 struct viawget_scan_result *scan_buf;
546 PSMgmtObject pMgmt = pDevice->pMgmt;
547 PWLAN_IE_SSID pItemSSID;
548 PKnownBSS pBSS;
549 unsigned char *pBuf;
550 int ret = 0;
551 u16 count = 0;
552 u16 ii, jj;
553#if 1
554
555 unsigned char *ptempBSS;
556
557 ptempBSS = kmalloc(sizeof(KnownBSS), GFP_ATOMIC);
558
559 if (ptempBSS == NULL) {
560 pr_err("bubble sort kmalloc memory fail@@@\n");
561
562 ret = -ENOMEM;
563
564 return ret;
565
566 }
567
568 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
569 for (jj = 0; jj < MAX_BSS_NUM - ii - 1; jj++) {
570 if ((pMgmt->sBSSList[jj].bActive != true) ||
571
572 ((pMgmt->sBSSList[jj].uRSSI > pMgmt->sBSSList[jj + 1].uRSSI) && (pMgmt->sBSSList[jj + 1].bActive != false))) {
573 memcpy(ptempBSS, &pMgmt->sBSSList[jj], sizeof(KnownBSS));
574
575 memcpy(&pMgmt->sBSSList[jj], &pMgmt->sBSSList[jj + 1], sizeof(KnownBSS));
576
577 memcpy(&pMgmt->sBSSList[jj + 1], ptempBSS, sizeof(KnownBSS));
578
579 }
580
581 }
582
583 }
584
585 kfree(ptempBSS);
586#endif
587
588//******mike:bubble sort by stronger RSSI*****//
589
590 count = 0;
591 pBSS = &(pMgmt->sBSSList[0]);
592 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
593 pBSS = &(pMgmt->sBSSList[ii]);
594 if (!pBSS->bActive)
595 continue;
596 count++;
597 }
598
599 pBuf = kcalloc(count, sizeof(struct viawget_scan_result), GFP_ATOMIC);
600
601 if (pBuf == NULL) {
602 ret = -ENOMEM;
603 return ret;
604 }
605 scan_buf = (struct viawget_scan_result *)pBuf;
606 pBSS = &(pMgmt->sBSSList[0]);
607 for (ii = 0, jj = 0; ii < MAX_BSS_NUM; ii++) {
608 pBSS = &(pMgmt->sBSSList[ii]);
609 if (pBSS->bActive) {
610 if (jj >= count)
611 break;
612 memcpy(scan_buf->bssid, pBSS->abyBSSID, WLAN_BSSID_LEN);
613 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
614 memcpy(scan_buf->ssid, pItemSSID->abySSID, pItemSSID->len);
615 scan_buf->ssid_len = pItemSSID->len;
616 scan_buf->freq = frequency_list[pBSS->uChannel-1];
617 scan_buf->caps = pBSS->wCapInfo;
618
619 if (pBSS->wWPALen != 0) {
620 scan_buf->wpa_ie_len = pBSS->wWPALen;
621 memcpy(scan_buf->wpa_ie, pBSS->byWPAIE, pBSS->wWPALen);
622 }
623 if (pBSS->wRSNLen != 0) {
624 scan_buf->rsn_ie_len = pBSS->wRSNLen;
625 memcpy(scan_buf->rsn_ie, pBSS->byRSNIE, pBSS->wRSNLen);
626 }
627 scan_buf = (struct viawget_scan_result *)((unsigned char *)scan_buf + sizeof(struct viawget_scan_result));
628 jj++;
629 }
630 }
631
632 if (jj < count)
633 count = jj;
634
635 if (copy_to_user(param->u.scan_results.buf, pBuf, sizeof(struct viawget_scan_result) * count))
636 ret = -EFAULT;
637
638 param->u.scan_results.scan_count = count;
639 pr_debug(" param->u.scan_results.scan_count = %d\n", count);
640
641 kfree(pBuf);
642 return ret;
643}
644
645/*
646 * Description:
647 * set associate with AP
648 *
649 * Parameters:
650 * In:
651 * pDevice -
652 * param -
653 * Out:
654 *
655 * Return Value:
656 *
657 */
658
659static int wpa_set_associate(struct vnt_private *pDevice,
660 struct viawget_wpa_param *param)
661{
662 PSMgmtObject pMgmt = pDevice->pMgmt;
663 PWLAN_IE_SSID pItemSSID;
664 unsigned char abyNullAddr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
665 unsigned char abyWPAIE[64];
666 bool bWepEnabled = false;
667
668 /* set key type & algorithm */
669 pr_debug("pairwise_suite = %d\n",
670 param->u.wpa_associate.pairwise_suite);
671 pr_debug("group_suite = %d\n", param->u.wpa_associate.group_suite);
672 pr_debug("key_mgmt_suite = %d\n",
673 param->u.wpa_associate.key_mgmt_suite);
674 pr_debug("auth_alg = %d\n", param->u.wpa_associate.auth_alg);
675 pr_debug("mode = %d\n", param->u.wpa_associate.mode);
676 pr_debug("wpa_ie_len = %d\n", param->u.wpa_associate.wpa_ie_len);
677
678 if (param->u.wpa_associate.wpa_ie_len) {
679 if (!param->u.wpa_associate.wpa_ie)
680 return -EINVAL;
681 if (param->u.wpa_associate.wpa_ie_len > sizeof(abyWPAIE))
682 return -EINVAL;
683 if (copy_from_user(&abyWPAIE[0], param->u.wpa_associate.wpa_ie, param->u.wpa_associate.wpa_ie_len))
684 return -EFAULT;
685 }
686
687 if (param->u.wpa_associate.mode == 1)
688 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
689 else
690 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
691 /* set ssid */
692 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
693 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
694 pItemSSID->byElementID = WLAN_EID_SSID;
695 pItemSSID->len = param->u.wpa_associate.ssid_len;
696 memcpy(pItemSSID->abySSID, param->u.wpa_associate.ssid, pItemSSID->len);
697 /* set bssid */
698 if (memcmp(param->u.wpa_associate.bssid, &abyNullAddr[0], 6) != 0)
699 memcpy(pMgmt->abyDesireBSSID, param->u.wpa_associate.bssid, 6);
700 else
701 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pItemSSID->abySSID);
702
703 if (param->u.wpa_associate.wpa_ie_len == 0) {
704 if (param->u.wpa_associate.auth_alg & AUTH_ALG_SHARED_KEY)
705 pMgmt->eAuthenMode = WMAC_AUTH_SHAREKEY;
706 else
707 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
708 } else if (abyWPAIE[0] == RSN_INFO_ELEM) {
709 if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
710 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
711 else
712 pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
713 } else {
714 if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_WPA_NONE)
715 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
716 else if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
717 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
718 else
719 pMgmt->eAuthenMode = WMAC_AUTH_WPA;
720 }
721
722 switch (param->u.wpa_associate.pairwise_suite) {
723 case CIPHER_CCMP:
724 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
725 break;
726 case CIPHER_TKIP:
727 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
728 break;
729 case CIPHER_WEP40:
730 case CIPHER_WEP104:
731 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
732 bWepEnabled = true;
733 break;
734 case CIPHER_NONE:
735 if (param->u.wpa_associate.group_suite == CIPHER_CCMP)
736 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
737 else
738 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
739 break;
740 default:
741 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
742 }
743
744//DavidWang add for WPA_supplicant support open/share mode
745
746 if (pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) {
747 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
748 pMgmt->bShareKeyAlgorithm = true;
749 } else if (pMgmt->eAuthenMode == WMAC_AUTH_OPEN) {
750 if (!bWepEnabled) pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
751 else pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
752 }
753//mike save old encryption status
754 pDevice->eOldEncryptionStatus = pDevice->eEncryptionStatus;
755
756 if (pDevice->eEncryptionStatus != Ndis802_11EncryptionDisabled)
757 pDevice->bEncryptionEnable = true;
758 else
759 pDevice->bEncryptionEnable = false;
760 if (!((pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) ||
761 ((pMgmt->eAuthenMode == WMAC_AUTH_OPEN) && bWepEnabled))) //DavidWang //20080717-06,<Modify> by chester//Not to initial WEP
762 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
763 spin_lock_irq(&pDevice->lock);
764 pDevice->bLinkPass = false;
765 memset(pMgmt->abyCurrBSSID, 0, 6);
766 pMgmt->eCurrState = WMAC_STATE_IDLE;
767 netif_stop_queue(pDevice->dev);
768 //20080701-02,<Add> by Mike Liu
769/*******search if ap_scan=2 ,which is associating request in hidden ssid mode ****/
770 {
771 PKnownBSS pCurr = NULL;
772
773 pCurr = BSSpSearchBSSList(pDevice,
774 pMgmt->abyDesireBSSID,
775 pMgmt->abyDesireSSID,
776 pMgmt->eConfigPHYMode
777);
778
779 if (pCurr == NULL) {
780 pr_debug("wpa_set_associate---->hidden mode site survey before associate.......\n");
781 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
782 }
783 }
784/****************************************************************/
785 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
786 spin_unlock_irq(&pDevice->lock);
787
788 return 0;
789}
790
791/*
792 * Description:
793 * wpa_ioctl main function supported for wpa supplicant
794 *
795 * Parameters:
796 * In:
797 * pDevice -
798 * iw_point -
799 * Out:
800 *
801 * Return Value:
802 *
803 */
804
805int wpa_ioctl(struct vnt_private *pDevice, struct iw_point *p)
806{
807 struct viawget_wpa_param *param;
808 int ret = 0;
809 int wpa_ioctl = 0;
810
811 if (p->length < sizeof(struct viawget_wpa_param) ||
812 p->length > VIAWGET_WPA_MAX_BUF_SIZE || !p->pointer)
813 return -EINVAL;
814
815 param = kmalloc((int)p->length, GFP_KERNEL);
816 if (param == NULL)
817 return -ENOMEM;
818
819 if (copy_from_user(param, p->pointer, p->length)) {
820 ret = -EFAULT;
821 goto out;
822 }
823
824 switch (param->cmd) {
825 case VIAWGET_SET_WPA:
826 ret = wpa_set_wpa(pDevice, param);
827 pr_debug("VIAWGET_SET_WPA\n");
828 break;
829
830 case VIAWGET_SET_KEY:
831 pr_debug("VIAWGET_SET_KEY\n");
832 spin_lock_irq(&pDevice->lock);
833 ret = wpa_set_keys(pDevice, param, false);
834 spin_unlock_irq(&pDevice->lock);
835 break;
836
837 case VIAWGET_SET_SCAN:
838 pr_debug("VIAWGET_SET_SCAN\n");
839 ret = wpa_set_scan(pDevice, param);
840 break;
841
842 case VIAWGET_GET_SCAN:
843 pr_debug("VIAWGET_GET_SCAN\n");
844 ret = wpa_get_scan(pDevice, param);
845 wpa_ioctl = 1;
846 break;
847
848 case VIAWGET_GET_SSID:
849 pr_debug("VIAWGET_GET_SSID\n");
850 ret = wpa_get_ssid(pDevice, param);
851 wpa_ioctl = 1;
852 break;
853
854 case VIAWGET_GET_BSSID:
855 pr_debug("VIAWGET_GET_BSSID\n");
856 ret = wpa_get_bssid(pDevice, param);
857 wpa_ioctl = 1;
858 break;
859
860 case VIAWGET_SET_ASSOCIATE:
861 pr_debug("VIAWGET_SET_ASSOCIATE\n");
862 ret = wpa_set_associate(pDevice, param);
863 break;
864
865 case VIAWGET_SET_DISASSOCIATE:
866 pr_debug("VIAWGET_SET_DISASSOCIATE\n");
867 ret = wpa_set_disassociate(pDevice, param);
868 break;
869
870 case VIAWGET_SET_DROP_UNENCRYPT:
871 pr_debug("VIAWGET_SET_DROP_UNENCRYPT\n");
872 break;
873
874 case VIAWGET_SET_DEAUTHENTICATE:
875 pr_debug("VIAWGET_SET_DEAUTHENTICATE\n");
876 break;
877
878 default:
879 pr_debug("wpa_ioctl: unknown cmd=%d\n",
880 param->cmd);
881 ret = -EOPNOTSUPP;
882 goto out;
883 }
884
885 if ((ret == 0) && wpa_ioctl) {
886 if (copy_to_user(p->pointer, param, p->length)) {
887 ret = -EFAULT;
888 goto out;
889 }
890 }
891
892out:
893 kfree(param);
894
895 return ret;
896}
diff --git a/drivers/staging/vt6655/wpactl.h b/drivers/staging/vt6655/wpactl.h
deleted file mode 100644
index c1b4a7292061..000000000000
--- a/drivers/staging/vt6655/wpactl.h
+++ /dev/null
@@ -1,64 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: wpactl.h
20 *
21 * Purpose:
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: March 1, 2005
26 *
27 */
28
29#ifndef __WPACTL_H__
30#define __WPACTL_H__
31
32#include "device.h"
33#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
34#include "iowpa.h"
35#endif
36
37/*--------------------- Export Definitions -------------------------*/
38
39//WPA related
40
41enum wpa_alg { WPA_ALG_NONE, WPA_ALG_WEP, WPA_ALG_TKIP, WPA_ALG_CCMP };
42enum wpa_cipher { CIPHER_NONE, CIPHER_WEP40, CIPHER_TKIP, CIPHER_CCMP,
43 CIPHER_WEP104 };
44enum wpa_key_mgmt { KEY_MGMT_802_1X, KEY_MGMT_CCKM, KEY_MGMT_PSK, KEY_MGMT_NONE,
45 KEY_MGMT_802_1X_NO_WPA, KEY_MGMT_WPA_NONE };
46
47#define AUTH_ALG_OPEN_SYSTEM 0x01
48#define AUTH_ALG_SHARED_KEY 0x02
49#define AUTH_ALG_LEAP 0x04
50
51#define GENERIC_INFO_ELEM 0xdd
52#define RSN_INFO_ELEM 0x30
53
54/*--------------------- Export Classes ----------------------------*/
55
56/*--------------------- Export Variables --------------------------*/
57
58/*--------------------- Export Functions --------------------------*/
59
60int wpa_set_wpadev(struct vnt_private *, int val);
61int wpa_ioctl(struct vnt_private *, struct iw_point *p);
62int wpa_set_keys(struct vnt_private *, void *ctx, bool fcpfkernel);
63
64#endif // __WPACL_H__
diff --git a/drivers/staging/vt6655/wroute.c b/drivers/staging/vt6655/wroute.c
deleted file mode 100644
index d1171fa3446e..000000000000
--- a/drivers/staging/vt6655/wroute.c
+++ /dev/null
@@ -1,187 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: wroute.c
20 *
21 * Purpose: handle WMAC frame relay & filtering
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 20, 2003
26 *
27 * Functions:
28 * ROUTEbRelay - Relay packet
29 *
30 * Revision History:
31 *
32 */
33
34#include "mac.h"
35#include "tcrc.h"
36#include "rxtx.h"
37#include "wroute.h"
38#include "card.h"
39#include "baseband.h"
40
41/*--------------------- Static Definitions -------------------------*/
42
43/*--------------------- Static Classes ----------------------------*/
44
45/*--------------------- Static Functions --------------------------*/
46
47/*--------------------- Export Variables --------------------------*/
48
49/*
50 * Description:
51 * Relay packet. Return true if packet is copy to DMA1
52 *
53 * Parameters:
54 * In:
55 * pDevice -
56 * pbySkbData - rx packet skb data
57 * Out:
58 * true, false
59 *
60 * Return Value: true if packet duplicate; otherwise false
61 *
62 */
63bool ROUTEbRelay(struct vnt_private *pDevice, unsigned char *pbySkbData,
64 unsigned int uDataLen, unsigned int uNodeIndex)
65{
66 PSMgmtObject pMgmt = pDevice->pMgmt;
67 PSTxDesc pHeadTD, pLastTD;
68 unsigned int cbFrameBodySize;
69 unsigned int uMACfragNum;
70 unsigned char byPktType;
71 bool bNeedEncryption = false;
72 SKeyItem STempKey;
73 PSKeyItem pTransmitKey = NULL;
74 unsigned int cbHeaderSize;
75 unsigned int ii;
76 unsigned char *pbyBSSID;
77
78 if (AVAIL_TD(pDevice, TYPE_AC0DMA) <= 0) {
79 pr_debug("Relay can't allocate TD1..\n");
80 return false;
81 }
82
83 pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
84
85 pHeadTD->m_td1TD1.byTCR = (TCR_EDP | TCR_STP);
86
87 memcpy(pDevice->sTxEthHeader.abyDstAddr, pbySkbData, ETH_HLEN);
88
89 cbFrameBodySize = uDataLen - ETH_HLEN;
90
91 if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN)
92 cbFrameBodySize += 8;
93
94 if (pDevice->bEncryptionEnable == true) {
95 bNeedEncryption = true;
96
97 // get group key
98 pbyBSSID = pDevice->abyBroadcastAddr;
99 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID,
100 GROUP_KEY, &pTransmitKey) == false) {
101 pTransmitKey = NULL;
102 pr_debug("KEY is NULL. [%d]\n",
103 pDevice->pMgmt->eCurrMode);
104 } else {
105 pr_debug("Get GTK\n");
106 }
107 }
108
109 if (pDevice->bEnableHostWEP) {
110 if (uNodeIndex < MAX_NODE_NUM + 1) {
111 pTransmitKey = &STempKey;
112 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
113 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
114 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
115 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
116 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
117 memcpy(pTransmitKey->abyKey,
118 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
119 pTransmitKey->uKeyLength);
120 }
121 }
122
123 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey,
124 cbFrameBodySize, &pDevice->sTxEthHeader);
125
126 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_AC0DMA))
127 return false;
128
129 byPktType = pDevice->byPacketType;
130
131 if (pDevice->bFixRate) {
132 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
133 if (pDevice->uConnectionRate >= RATE_11M)
134 pDevice->wCurrentRate = RATE_11M;
135 else
136 pDevice->wCurrentRate = pDevice->uConnectionRate;
137 } else {
138 if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
139 (pDevice->uConnectionRate <= RATE_6M)) {
140 pDevice->wCurrentRate = RATE_6M;
141 } else {
142 if (pDevice->uConnectionRate >= RATE_54M)
143 pDevice->wCurrentRate = RATE_54M;
144 else
145 pDevice->wCurrentRate = pDevice->uConnectionRate;
146 }
147 }
148 } else {
149 pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
150 }
151
152 if (pDevice->wCurrentRate <= RATE_11M)
153 byPktType = PK_TYPE_11B;
154
155 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff,
156 bNeedEncryption, cbFrameBodySize, TYPE_AC0DMA,
157 pHeadTD, &pDevice->sTxEthHeader, pbySkbData,
158 pTransmitKey, uNodeIndex, &uMACfragNum,
159 &cbHeaderSize);
160
161 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
162 // Disable PS
163 MACbPSWakeup(pDevice->PortOffset);
164 }
165
166 pDevice->bPWBitOn = false;
167
168 pLastTD = pHeadTD;
169 for (ii = 0; ii < uMACfragNum; ii++) {
170 // Poll Transmit the adapter
171 wmb();
172 pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
173 wmb();
174 if (ii == (uMACfragNum - 1))
175 pLastTD = pHeadTD;
176 pHeadTD = pHeadTD->next;
177 }
178
179 pLastTD->pTDInfo->skb = NULL;
180 pLastTD->pTDInfo->byFlags = 0;
181
182 pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
183
184 MACvTransmitAC0(pDevice->PortOffset);
185
186 return true;
187}
diff --git a/drivers/staging/vt6655/wroute.h b/drivers/staging/vt6655/wroute.h
deleted file mode 100644
index e59eec955cac..000000000000
--- a/drivers/staging/vt6655/wroute.h
+++ /dev/null
@@ -1,45 +0,0 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: wroute.h
20 *
21 * Purpose:
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 21, 2003
26 *
27 */
28
29#ifndef __WROUTE_H__
30#define __WROUTE_H__
31
32#include "device.h"
33
34/*--------------------- Export Definitions -------------------------*/
35
36/*--------------------- Export Classes ----------------------------*/
37
38/*--------------------- Export Variables --------------------------*/
39
40/*--------------------- Export Functions --------------------------*/
41
42bool ROUTEbRelay(struct vnt_private *pDevice, unsigned char *pbySkbData,
43 unsigned int uDataLen, unsigned int uNodeIndex);
44
45#endif /* __WROUTE_H__ */
diff --git a/drivers/staging/vt6656/main_usb.c b/drivers/staging/vt6656/main_usb.c
index dbc311c3dc37..b95d5b1efcc7 100644
--- a/drivers/staging/vt6656/main_usb.c
+++ b/drivers/staging/vt6656/main_usb.c
@@ -431,11 +431,8 @@ static bool vnt_alloc_bufs(struct vnt_private *priv)
431 for (ii = 0; ii < priv->num_tx_context; ii++) { 431 for (ii = 0; ii < priv->num_tx_context; ii++) {
432 tx_context = kmalloc(sizeof(struct vnt_usb_send_context), 432 tx_context = kmalloc(sizeof(struct vnt_usb_send_context),
433 GFP_KERNEL); 433 GFP_KERNEL);
434 if (tx_context == NULL) { 434 if (tx_context == NULL)
435 dev_err(&priv->usb->dev,
436 "allocate tx usb context failed\n");
437 goto free_tx; 435 goto free_tx;
438 }
439 436
440 priv->tx_context[ii] = tx_context; 437 priv->tx_context[ii] = tx_context;
441 tx_context->priv = priv; 438 tx_context->priv = priv;
@@ -471,10 +468,8 @@ static bool vnt_alloc_bufs(struct vnt_private *priv)
471 } 468 }
472 469
473 rcb->skb = dev_alloc_skb(priv->rx_buf_sz); 470 rcb->skb = dev_alloc_skb(priv->rx_buf_sz);
474 if (rcb->skb == NULL) { 471 if (rcb->skb == NULL)
475 dev_err(&priv->usb->dev, "Failed to alloc rx skb\n");
476 goto free_rx_tx; 472 goto free_rx_tx;
477 }
478 473
479 rcb->in_use = false; 474 rcb->in_use = false;
480 475
@@ -491,7 +486,6 @@ static bool vnt_alloc_bufs(struct vnt_private *priv)
491 486
492 priv->int_buf.data_buf = kmalloc(MAX_INTERRUPT_SIZE, GFP_KERNEL); 487 priv->int_buf.data_buf = kmalloc(MAX_INTERRUPT_SIZE, GFP_KERNEL);
493 if (priv->int_buf.data_buf == NULL) { 488 if (priv->int_buf.data_buf == NULL) {
494 dev_err(&priv->usb->dev, "Failed to alloc int buf\n");
495 usb_free_urb(priv->interrupt_urb); 489 usb_free_urb(priv->interrupt_urb);
496 goto free_rx_tx; 490 goto free_rx_tx;
497 } 491 }
diff --git a/drivers/staging/wlan-ng/hfa384x.h b/drivers/staging/wlan-ng/hfa384x.h
index 1f2c78cc0086..20d146b61ba7 100644
--- a/drivers/staging/wlan-ng/hfa384x.h
+++ b/drivers/staging/wlan-ng/hfa384x.h
@@ -1376,6 +1376,7 @@ int hfa384x_drvr_setconfig(hfa384x_t *hw, u16 rid, void *buf, u16 len);
1376static inline int hfa384x_drvr_getconfig16(hfa384x_t *hw, u16 rid, void *val) 1376static inline int hfa384x_drvr_getconfig16(hfa384x_t *hw, u16 rid, void *val)
1377{ 1377{
1378 int result = 0; 1378 int result = 0;
1379
1379 result = hfa384x_drvr_getconfig(hw, rid, val, sizeof(u16)); 1380 result = hfa384x_drvr_getconfig(hw, rid, val, sizeof(u16));
1380 if (result == 0) 1381 if (result == 0)
1381 *((u16 *) val) = le16_to_cpu(*((u16 *) val)); 1382 *((u16 *) val) = le16_to_cpu(*((u16 *) val));
@@ -1385,6 +1386,7 @@ static inline int hfa384x_drvr_getconfig16(hfa384x_t *hw, u16 rid, void *val)
1385static inline int hfa384x_drvr_setconfig16(hfa384x_t *hw, u16 rid, u16 val) 1386static inline int hfa384x_drvr_setconfig16(hfa384x_t *hw, u16 rid, u16 val)
1386{ 1387{
1387 u16 value = cpu_to_le16(val); 1388 u16 value = cpu_to_le16(val);
1389
1388 return hfa384x_drvr_setconfig(hw, rid, &value, sizeof(value)); 1390 return hfa384x_drvr_setconfig(hw, rid, &value, sizeof(value));
1389} 1391}
1390 1392
@@ -1402,6 +1404,7 @@ static inline int
1402hfa384x_drvr_setconfig16_async(hfa384x_t *hw, u16 rid, u16 val) 1404hfa384x_drvr_setconfig16_async(hfa384x_t *hw, u16 rid, u16 val)
1403{ 1405{
1404 u16 value = cpu_to_le16(val); 1406 u16 value = cpu_to_le16(val);
1407
1405 return hfa384x_drvr_setconfig_async(hw, rid, &value, sizeof(value), 1408 return hfa384x_drvr_setconfig_async(hw, rid, &value, sizeof(value),
1406 NULL, NULL); 1409 NULL, NULL);
1407} 1410}
diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
index 898bde73c59a..55d2f563e308 100644
--- a/drivers/staging/wlan-ng/hfa384x_usb.c
+++ b/drivers/staging/wlan-ng/hfa384x_usb.c
@@ -3583,12 +3583,8 @@ static void hfa384x_int_rxmonitor(wlandevice_t *wlandev,
3583 } 3583 }
3584 3584
3585 skb = dev_alloc_skb(skblen); 3585 skb = dev_alloc_skb(skblen);
3586 if (skb == NULL) { 3586 if (skb == NULL)
3587 netdev_err(hw->wlandev->netdev,
3588 "alloc_skb failed trying to allocate %d bytes\n",
3589 skblen);
3590 return; 3587 return;
3591 }
3592 3588
3593 /* only prepend the prism header if in the right mode */ 3589 /* only prepend the prism header if in the right mode */
3594 if ((wlandev->netdev->type == ARPHRD_IEEE80211_PRISM) && 3590 if ((wlandev->netdev->type == ARPHRD_IEEE80211_PRISM) &&
diff --git a/drivers/staging/wlan-ng/p80211conv.c b/drivers/staging/wlan-ng/p80211conv.c
index 3b5468c64fde..7eaaf9a63503 100644
--- a/drivers/staging/wlan-ng/p80211conv.c
+++ b/drivers/staging/wlan-ng/p80211conv.c
@@ -107,7 +107,7 @@ int skb_ether_to_p80211(wlandevice_t *wlandev, u32 ethconv,
107 struct p80211_metawep *p80211_wep) 107 struct p80211_metawep *p80211_wep)
108{ 108{
109 109
110 u16 fc; 110 __le16 fc;
111 u16 proto; 111 u16 proto;
112 struct wlan_ethhdr e_hdr; 112 struct wlan_ethhdr e_hdr;
113 struct wlan_llc *e_llc; 113 struct wlan_llc *e_llc;
diff --git a/drivers/staging/wlan-ng/p80211hdr.h b/drivers/staging/wlan-ng/p80211hdr.h
index 66b5e201d418..79d9b20b364d 100644
--- a/drivers/staging/wlan-ng/p80211hdr.h
+++ b/drivers/staging/wlan-ng/p80211hdr.h
@@ -148,7 +148,7 @@
148/* Generic 802.11 Header types */ 148/* Generic 802.11 Header types */
149 149
150struct p80211_hdr_a3 { 150struct p80211_hdr_a3 {
151 u16 fc; 151 __le16 fc;
152 u16 dur; 152 u16 dur;
153 u8 a1[ETH_ALEN]; 153 u8 a1[ETH_ALEN];
154 u8 a2[ETH_ALEN]; 154 u8 a2[ETH_ALEN];
diff --git a/drivers/staging/wlan-ng/p80211netdev.c b/drivers/staging/wlan-ng/p80211netdev.c
index 2dd9bf8a6e18..a9c1e0bafa62 100644
--- a/drivers/staging/wlan-ng/p80211netdev.c
+++ b/drivers/staging/wlan-ng/p80211netdev.c
@@ -358,7 +358,7 @@ static int p80211knetdev_hard_start_xmit(struct sk_buff *skb,
358 * and return success . 358 * and return success .
359 * TODO: we need a saner way to handle this 359 * TODO: we need a saner way to handle this
360 */ 360 */
361 if (skb->protocol != ETH_P_80211_RAW) { 361 if (be16_to_cpu(skb->protocol) != ETH_P_80211_RAW) {
362 netif_start_queue(wlandev->netdev); 362 netif_start_queue(wlandev->netdev);
363 netdev_notice(netdev, "Tx attempt prior to association, frame dropped.\n"); 363 netdev_notice(netdev, "Tx attempt prior to association, frame dropped.\n");
364 netdev->stats.tx_dropped++; 364 netdev->stats.tx_dropped++;
@@ -369,7 +369,7 @@ static int p80211knetdev_hard_start_xmit(struct sk_buff *skb,
369 } 369 }
370 370
371 /* Check for raw transmits */ 371 /* Check for raw transmits */
372 if (skb->protocol == ETH_P_80211_RAW) { 372 if (be16_to_cpu(skb->protocol) == ETH_P_80211_RAW) {
373 if (!capable(CAP_NET_ADMIN)) { 373 if (!capable(CAP_NET_ADMIN)) {
374 result = 1; 374 result = 1;
375 goto failed; 375 goto failed;
diff --git a/drivers/staging/wlan-ng/prism2fw.c b/drivers/staging/wlan-ng/prism2fw.c
index 6c38f797d1ab..9408644cc8b8 100644
--- a/drivers/staging/wlan-ng/prism2fw.c
+++ b/drivers/staging/wlan-ng/prism2fw.c
@@ -238,7 +238,8 @@ static int prism2_fwtry(struct usb_device *udev, wlandevice_t *wlandev)
238* 0 - success 238* 0 - success
239* ~0 - failure 239* ~0 - failure
240----------------------------------------------------------------*/ 240----------------------------------------------------------------*/
241static int prism2_fwapply(const struct ihex_binrec *rfptr, wlandevice_t *wlandev) 241static int prism2_fwapply(const struct ihex_binrec *rfptr,
242 wlandevice_t *wlandev)
242{ 243{
243 signed int result = 0; 244 signed int result = 0;
244 struct p80211msg_dot11req_mibget getmsg; 245 struct p80211msg_dot11req_mibget getmsg;
@@ -986,8 +987,8 @@ static int writeimage(wlandevice_t *wlandev, struct imgchunk *fchunk,
986 u32 currlen; 987 u32 currlen;
987 u32 currdaddr; 988 u32 currdaddr;
988 989
989 rstmsg = kmalloc(sizeof(*rstmsg), GFP_KERNEL); 990 rstmsg = kzalloc(sizeof(*rstmsg), GFP_KERNEL);
990 rwrmsg = kmalloc(sizeof(*rwrmsg), GFP_KERNEL); 991 rwrmsg = kzalloc(sizeof(*rwrmsg), GFP_KERNEL);
991 if (!rstmsg || !rwrmsg) { 992 if (!rstmsg || !rwrmsg) {
992 kfree(rstmsg); 993 kfree(rstmsg);
993 kfree(rwrmsg); 994 kfree(rwrmsg);
@@ -997,7 +998,6 @@ static int writeimage(wlandevice_t *wlandev, struct imgchunk *fchunk,
997 } 998 }
998 999
999 /* Initialize the messages */ 1000 /* Initialize the messages */
1000 memset(rstmsg, 0, sizeof(*rstmsg));
1001 strcpy(rstmsg->devname, wlandev->name); 1001 strcpy(rstmsg->devname, wlandev->name);
1002 rstmsg->msgcode = DIDmsg_p2req_ramdl_state; 1002 rstmsg->msgcode = DIDmsg_p2req_ramdl_state;
1003 rstmsg->msglen = sizeof(*rstmsg); 1003 rstmsg->msglen = sizeof(*rstmsg);
@@ -1011,7 +1011,6 @@ static int writeimage(wlandevice_t *wlandev, struct imgchunk *fchunk,
1011 rstmsg->exeaddr.len = sizeof(u32); 1011 rstmsg->exeaddr.len = sizeof(u32);
1012 rstmsg->resultcode.len = sizeof(u32); 1012 rstmsg->resultcode.len = sizeof(u32);
1013 1013
1014 memset(rwrmsg, 0, sizeof(*rwrmsg));
1015 strcpy(rwrmsg->devname, wlandev->name); 1014 strcpy(rwrmsg->devname, wlandev->name);
1016 rwrmsg->msgcode = DIDmsg_p2req_ramdl_write; 1015 rwrmsg->msgcode = DIDmsg_p2req_ramdl_write;
1017 rwrmsg->msglen = sizeof(*rwrmsg); 1016 rwrmsg->msglen = sizeof(*rwrmsg);
diff --git a/drivers/staging/xgifb/XGI_main_26.c b/drivers/staging/xgifb/XGI_main_26.c
index be7778b59118..709d49e7f3c9 100644
--- a/drivers/staging/xgifb/XGI_main_26.c
+++ b/drivers/staging/xgifb/XGI_main_26.c
@@ -2012,7 +2012,7 @@ static int xgifb_probe(struct pci_dev *pdev,
2012 XGIfb_get_fix(&fb_info->fix, -1, fb_info); 2012 XGIfb_get_fix(&fb_info->fix, -1, fb_info);
2013 fb_info->pseudo_palette = xgifb_info->pseudo_palette; 2013 fb_info->pseudo_palette = xgifb_info->pseudo_palette;
2014 2014
2015 fb_alloc_cmap(&fb_info->cmap, 256 , 0); 2015 fb_alloc_cmap(&fb_info->cmap, 256, 0);
2016 2016
2017#ifdef CONFIG_MTRR 2017#ifdef CONFIG_MTRR
2018 xgifb_info->mtrr = mtrr_add(xgifb_info->video_base, 2018 xgifb_info->mtrr = mtrr_add(xgifb_info->video_base,
diff --git a/drivers/staging/xgifb/vb_def.h b/drivers/staging/xgifb/vb_def.h
index 481eb174fdf0..d9524a2e9ce4 100644
--- a/drivers/staging/xgifb/vb_def.h
+++ b/drivers/staging/xgifb/vb_def.h
@@ -7,7 +7,6 @@
7#define SupportCRT2in301C 0x0100 /* for 301C */ 7#define SupportCRT2in301C 0x0100 /* for 301C */
8#define SetCHTVOverScan 0x8000 8#define SetCHTVOverScan 0x8000
9 9
10#define Panel_320x480 0x07 /*fstn*/
11#define PanelResInfo 0x1F /* CR36 Panel Type/LCDResInfo */ 10#define PanelResInfo 0x1F /* CR36 Panel Type/LCDResInfo */
12#define Panel_1024x768x75 0x22 11#define Panel_1024x768x75 0x22
13#define Panel_1280x1024x75 0x23 12#define Panel_1280x1024x75 0x23
diff --git a/drivers/staging/xgifb/vb_setmode.c b/drivers/staging/xgifb/vb_setmode.c
index d5f49d2a8db3..1f6f699e238c 100644
--- a/drivers/staging/xgifb/vb_setmode.c
+++ b/drivers/staging/xgifb/vb_setmode.c
@@ -4135,7 +4135,7 @@ static void XGI_SetGroup4(unsigned short ModeIdIndex,
4135 tempax -= 1; 4135 tempax -= 1;
4136 4136
4137 temp = (tempax & 0xFF00) >> 8; 4137 temp = (tempax & 0xFF00) >> 8;
4138 temp = ((temp & 0x0003) << 4); 4138 temp = (temp & 0x0003) << 4;
4139 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp); 4139 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
4140 temp = (tempax & 0x00FF); 4140 temp = (tempax & 0x00FF);
4141 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp); 4141 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
diff --git a/drivers/staging/xgifb/vb_util.c b/drivers/staging/xgifb/vb_util.c
index 1b452f8b6274..be3437ca339e 100644
--- a/drivers/staging/xgifb/vb_util.c
+++ b/drivers/staging/xgifb/vb_util.c
@@ -9,11 +9,8 @@ void xgifb_reg_set(unsigned long port, u8 index, u8 data)
9 9
10u8 xgifb_reg_get(unsigned long port, u8 index) 10u8 xgifb_reg_get(unsigned long port, u8 index)
11{ 11{
12 u8 data;
13
14 outb(index, port); 12 outb(index, port);
15 data = inb(port + 1); 13 return inb(port + 1);
16 return data;
17} 14}
18 15
19void xgifb_reg_and_or(unsigned long port, u8 index, 16void xgifb_reg_and_or(unsigned long port, u8 index,
diff --git a/include/linux/iio/common/st_sensors.h b/include/linux/iio/common/st_sensors.h
index d8257ab60bac..2c476acb87d9 100644
--- a/include/linux/iio/common/st_sensors.h
+++ b/include/linux/iio/common/st_sensors.h
@@ -164,7 +164,7 @@ struct st_sensor_transfer_function {
164}; 164};
165 165
166/** 166/**
167 * struct st_sensors - ST sensors list 167 * struct st_sensor_settings - ST specific sensor settings
168 * @wai: Contents of WhoAmI register. 168 * @wai: Contents of WhoAmI register.
169 * @sensors_supported: List of supported sensors by struct itself. 169 * @sensors_supported: List of supported sensors by struct itself.
170 * @ch: IIO channels for the sensor. 170 * @ch: IIO channels for the sensor.
@@ -177,7 +177,7 @@ struct st_sensor_transfer_function {
177 * @multi_read_bit: Use or not particular bit for [I2C/SPI] multi-read. 177 * @multi_read_bit: Use or not particular bit for [I2C/SPI] multi-read.
178 * @bootime: samples to discard when sensor passing from power-down to power-up. 178 * @bootime: samples to discard when sensor passing from power-down to power-up.
179 */ 179 */
180struct st_sensors { 180struct st_sensor_settings {
181 u8 wai; 181 u8 wai;
182 char sensors_supported[ST_SENSORS_MAX_4WAI][ST_SENSORS_MAX_NAME]; 182 char sensors_supported[ST_SENSORS_MAX_4WAI][ST_SENSORS_MAX_NAME];
183 struct iio_chan_spec *ch; 183 struct iio_chan_spec *ch;
@@ -196,7 +196,7 @@ struct st_sensors {
196 * struct st_sensor_data - ST sensor device status 196 * struct st_sensor_data - ST sensor device status
197 * @dev: Pointer to instance of struct device (I2C or SPI). 197 * @dev: Pointer to instance of struct device (I2C or SPI).
198 * @trig: The trigger in use by the core driver. 198 * @trig: The trigger in use by the core driver.
199 * @sensor: Pointer to the current sensor struct in use. 199 * @sensor_settings: Pointer to the specific sensor settings in use.
200 * @current_fullscale: Maximum range of measure by the sensor. 200 * @current_fullscale: Maximum range of measure by the sensor.
201 * @vdd: Pointer to sensor's Vdd power supply 201 * @vdd: Pointer to sensor's Vdd power supply
202 * @vdd_io: Pointer to sensor's Vdd-IO power supply 202 * @vdd_io: Pointer to sensor's Vdd-IO power supply
@@ -213,7 +213,7 @@ struct st_sensors {
213struct st_sensor_data { 213struct st_sensor_data {
214 struct device *dev; 214 struct device *dev;
215 struct iio_trigger *trig; 215 struct iio_trigger *trig;
216 struct st_sensors *sensor; 216 struct st_sensor_settings *sensor_settings;
217 struct st_sensor_fullscale_avl *current_fullscale; 217 struct st_sensor_fullscale_avl *current_fullscale;
218 struct regulator *vdd; 218 struct regulator *vdd;
219 struct regulator *vdd_io; 219 struct regulator *vdd_io;
@@ -279,7 +279,7 @@ int st_sensors_read_info_raw(struct iio_dev *indio_dev,
279 struct iio_chan_spec const *ch, int *val); 279 struct iio_chan_spec const *ch, int *val);
280 280
281int st_sensors_check_device_support(struct iio_dev *indio_dev, 281int st_sensors_check_device_support(struct iio_dev *indio_dev,
282 int num_sensors_list, const struct st_sensors *sensors); 282 int num_sensors_list, const struct st_sensor_settings *sensor_settings);
283 283
284ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev, 284ssize_t st_sensors_sysfs_sampling_frequency_avail(struct device *dev,
285 struct device_attribute *attr, char *buf); 285 struct device_attribute *attr, char *buf);
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index 15dc6bc2bdd2..3642ce7ef512 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -13,6 +13,7 @@
13#include <linux/device.h> 13#include <linux/device.h>
14#include <linux/cdev.h> 14#include <linux/cdev.h>
15#include <linux/iio/types.h> 15#include <linux/iio/types.h>
16#include <linux/of.h>
16/* IIO TODO LIST */ 17/* IIO TODO LIST */
17/* 18/*
18 * Provide means of adjusting timer accuracy. 19 * Provide means of adjusting timer accuracy.
@@ -326,6 +327,11 @@ struct iio_dev;
326 * @update_scan_mode: function to configure device and scan buffer when 327 * @update_scan_mode: function to configure device and scan buffer when
327 * channels have changed 328 * channels have changed
328 * @debugfs_reg_access: function to read or write register value of device 329 * @debugfs_reg_access: function to read or write register value of device
330 * @of_xlate: function pointer to obtain channel specifier index.
331 * When #iio-cells is greater than '0', the driver could
332 * provide a custom of_xlate function that reads the
333 * *args* and returns the appropriate index in registered
334 * IIO channels array.
329 **/ 335 **/
330struct iio_info { 336struct iio_info {
331 struct module *driver_module; 337 struct module *driver_module;
@@ -385,6 +391,8 @@ struct iio_info {
385 int (*debugfs_reg_access)(struct iio_dev *indio_dev, 391 int (*debugfs_reg_access)(struct iio_dev *indio_dev,
386 unsigned reg, unsigned writeval, 392 unsigned reg, unsigned writeval,
387 unsigned *readval); 393 unsigned *readval);
394 int (*of_xlate)(struct iio_dev *indio_dev,
395 const struct of_phandle_args *iiospec);
388}; 396};
389 397
390/** 398/**
diff --git a/include/uapi/linux/Kbuild b/include/uapi/linux/Kbuild
index d8e1716707ba..cea258f1d9d2 100644
--- a/include/uapi/linux/Kbuild
+++ b/include/uapi/linux/Kbuild
@@ -1,4 +1,5 @@
1# UAPI Header export list 1# UAPI Header export list
2header-y += android/
2header-y += byteorder/ 3header-y += byteorder/
3header-y += can/ 4header-y += can/
4header-y += caif/ 5header-y += caif/
diff --git a/include/uapi/linux/android/Kbuild b/include/uapi/linux/android/Kbuild
new file mode 100644
index 000000000000..ca011eec252a
--- /dev/null
+++ b/include/uapi/linux/android/Kbuild
@@ -0,0 +1,2 @@
1# UAPI Header export list
2header-y += binder.h
diff --git a/drivers/staging/android/uapi/binder.h b/include/uapi/linux/android/binder.h
index dba4cef3a8d3..41420e341e75 100644
--- a/drivers/staging/android/uapi/binder.h
+++ b/include/uapi/linux/android/binder.h
@@ -20,6 +20,7 @@
20#ifndef _UAPI_LINUX_BINDER_H 20#ifndef _UAPI_LINUX_BINDER_H
21#define _UAPI_LINUX_BINDER_H 21#define _UAPI_LINUX_BINDER_H
22 22
23#include <linux/types.h>
23#include <linux/ioctl.h> 24#include <linux/ioctl.h>
24 25
25#define B_PACK_CHARS(c1, c2, c3, c4) \ 26#define B_PACK_CHARS(c1, c2, c3, c4) \